@nattyjs/core 0.0.1-beta.30 → 0.0.1-beta.32

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/dist/index.cjs CHANGED
@@ -128,22 +128,26 @@ function initializeModule(config) {
128
128
  }
129
129
  }
130
130
 
131
- function getPreResponseBody(body) {
131
+ function getPreResponseBody(body, isBuffer = false) {
132
132
  let bodyInfo;
133
133
  if (body) {
134
- if (common.isObject(body) || Array.isArray(body))
135
- bodyInfo = { json: body };
136
- const typeText = typeof body;
137
- switch (typeText) {
138
- case "string":
139
- bodyInfo = { string: body };
140
- break;
141
- case "number":
142
- bodyInfo = { number: body };
143
- break;
144
- case "boolean":
145
- bodyInfo = { boolean: body };
146
- break;
134
+ if (isBuffer)
135
+ bodyInfo = { buffer: body };
136
+ else {
137
+ if (common.isObject(body) || Array.isArray(body))
138
+ bodyInfo = { json: body };
139
+ const typeText = typeof body;
140
+ switch (typeText) {
141
+ case "string":
142
+ bodyInfo = { string: body };
143
+ break;
144
+ case "number":
145
+ bodyInfo = { number: body };
146
+ break;
147
+ case "boolean":
148
+ bodyInfo = { boolean: body };
149
+ break;
150
+ }
147
151
  }
148
152
  }
149
153
  return bodyInfo;
@@ -157,6 +161,7 @@ class HttpResponse {
157
161
  }
158
162
  setValues(responseInit) {
159
163
  if (responseInit) {
164
+ this._isBuffer = responseInit.isBuffer;
160
165
  if (responseInit.headers)
161
166
  for (const [key, value] of Object.entries(responseInit.headers))
162
167
  this.headers.append(key, value);
@@ -188,7 +193,7 @@ class HttpResponse {
188
193
  return this._body;
189
194
  }
190
195
  set body(value) {
191
- this._body = getPreResponseBody(value);
196
+ this._body = getPreResponseBody(value, this._isBuffer);
192
197
  }
193
198
  write(responseInit) {
194
199
  this.setValues(responseInit);
@@ -1242,6 +1247,16 @@ function badRequest(value, response) {
1242
1247
  return new BadRequestResult(value || common.BLANK, response);
1243
1248
  }
1244
1249
 
1250
+ class FileResult extends BaseResult {
1251
+ constructor(value, response) {
1252
+ super({ ...{ isBuffer: true, body: value }, ...{ status: HttpStatusCode.success } }, response);
1253
+ this.value = value;
1254
+ }
1255
+ }
1256
+ function fileResult(value, response) {
1257
+ return new FileResult(value || common.BLANK, response);
1258
+ }
1259
+
1245
1260
  function base(params, type, additionaConfig) {
1246
1261
  decoratorStateContainer.register(params, type, additionaConfig);
1247
1262
  }
@@ -1292,6 +1307,7 @@ exports.BaseController = BaseController;
1292
1307
  exports.CreateProblemDetail = CreateProblemDetail;
1293
1308
  exports.CreatedResult = CreatedResult;
1294
1309
  exports.Delete = Delete;
1310
+ exports.FileResult = FileResult;
1295
1311
  exports.ForbiddenAccessException = ForbiddenAccessException;
1296
1312
  exports.ForbiddenAccessInfoResult = ForbiddenAccessInfoResult;
1297
1313
  exports.HttpBadRequestException = HttpBadRequestException;
@@ -1314,6 +1330,7 @@ exports.badRequest = badRequest;
1314
1330
  exports.created = created;
1315
1331
  exports.defineNattyConfig = defineNattyConfig;
1316
1332
  exports.entityContainer = entityContainer;
1333
+ exports.fileResult = fileResult;
1317
1334
  exports.filter = filter;
1318
1335
  exports.forbiddenAccessInfo = forbiddenAccessInfo;
1319
1336
  exports.get = get;
package/dist/index.d.ts CHANGED
@@ -139,6 +139,7 @@ type HttpRequestBodyInfo = {
139
139
  number?: number | number[];
140
140
  boolean?: boolean | boolean[];
141
141
  FormData?: FormData;
142
+ buffer?: any;
142
143
  ArrayBuffer?: ArrayBuffer;
143
144
  Blob?: Blob;
144
145
  json?: {
@@ -178,6 +179,7 @@ interface HttpResponseInit {
178
179
  headers?: HeadersInit;
179
180
  cookies?: Cookie[];
180
181
  enableContentNegotiation?: boolean;
182
+ isBuffer?: boolean;
181
183
  }
182
184
 
183
185
  interface ProblemDetail {
@@ -264,6 +266,7 @@ declare class HttpResponse {
264
266
  private _headers;
265
267
  private _body;
266
268
  private _status;
269
+ private _isBuffer;
267
270
  constructor(response?: HttpResponseInit);
268
271
  private setValues;
269
272
  addCookie(cookie: Cookie): void;
@@ -341,9 +344,9 @@ declare abstract class ParameterTypeConverter extends BaseResponse {
341
344
  };
342
345
  get types(): TypesInfo;
343
346
  getObjectTypeInfo(typeName: string): {
344
- path?: any;
345
- props?: TypeInfo[];
346
- values?: any[];
347
+ path?: string | any | Function;
348
+ props?: Array<TypeInfo>;
349
+ values?: Array<any>;
347
350
  };
348
351
  isArrayType(typeName: string): boolean;
349
352
  getTypeName(typeName: string): string;
@@ -435,6 +438,12 @@ declare class BadRequestResult extends BaseResult implements IHttpResult {
435
438
  }
436
439
  declare function badRequest(value?: ExceptionTypeInfo, response?: Pick<HttpResponseInit, "headers" | "cookies">): BadRequestResult;
437
440
 
441
+ declare class FileResult extends BaseResult {
442
+ value: any;
443
+ constructor(value: any, response?: Pick<HttpResponseInit, "headers" | "cookies">);
444
+ }
445
+ declare function fileResult(value?: any, response?: Pick<HttpResponseInit, "headers" | "cookies">): FileResult;
446
+
438
447
  declare class HttpException {
439
448
  private httpResponse;
440
449
  constructor(response: HttpResponseInit);
@@ -486,4 +495,4 @@ declare function authorize(permission: {
486
495
 
487
496
  declare function CreateProblemDetail(modelName: string, detail: any): ProblemDetail;
488
497
 
489
- export { $request, AbstractModelState, BadRequestResult, BaseController, BuildOptions, ClassTypeInfo, CreateProblemDetail, CreatedResult, Delete, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpModule, HttpNotFoundException, HttpResponse, HttpStatusCode, MethodInfo$1 as MethodInfo, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, ParameterInfo, RunOn, TypeInfo$1 as TypeInfo, UnauthorizedAccessException, anonymous, authenticationOnly, authorize, badRequest, created, defineNattyConfig, entityContainer, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, setEnvInfo, useFilter };
498
+ export { $request, AbstractModelState, BadRequestResult, BaseController, BuildOptions, ClassTypeInfo, CreateProblemDetail, CreatedResult, Delete, FileResult, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpModule, HttpNotFoundException, HttpResponse, HttpStatusCode, MethodInfo$1 as MethodInfo, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, ParameterInfo, RunOn, TypeInfo$1 as TypeInfo, UnauthorizedAccessException, anonymous, authenticationOnly, authorize, badRequest, created, defineNattyConfig, entityContainer, fileResult, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, setEnvInfo, useFilter };
package/dist/index.mjs CHANGED
@@ -126,22 +126,26 @@ function initializeModule(config) {
126
126
  }
127
127
  }
128
128
 
129
- function getPreResponseBody(body) {
129
+ function getPreResponseBody(body, isBuffer = false) {
130
130
  let bodyInfo;
131
131
  if (body) {
132
- if (isObject(body) || Array.isArray(body))
133
- bodyInfo = { json: body };
134
- const typeText = typeof body;
135
- switch (typeText) {
136
- case "string":
137
- bodyInfo = { string: body };
138
- break;
139
- case "number":
140
- bodyInfo = { number: body };
141
- break;
142
- case "boolean":
143
- bodyInfo = { boolean: body };
144
- break;
132
+ if (isBuffer)
133
+ bodyInfo = { buffer: body };
134
+ else {
135
+ if (isObject(body) || Array.isArray(body))
136
+ bodyInfo = { json: body };
137
+ const typeText = typeof body;
138
+ switch (typeText) {
139
+ case "string":
140
+ bodyInfo = { string: body };
141
+ break;
142
+ case "number":
143
+ bodyInfo = { number: body };
144
+ break;
145
+ case "boolean":
146
+ bodyInfo = { boolean: body };
147
+ break;
148
+ }
145
149
  }
146
150
  }
147
151
  return bodyInfo;
@@ -155,6 +159,7 @@ class HttpResponse {
155
159
  }
156
160
  setValues(responseInit) {
157
161
  if (responseInit) {
162
+ this._isBuffer = responseInit.isBuffer;
158
163
  if (responseInit.headers)
159
164
  for (const [key, value] of Object.entries(responseInit.headers))
160
165
  this.headers.append(key, value);
@@ -186,7 +191,7 @@ class HttpResponse {
186
191
  return this._body;
187
192
  }
188
193
  set body(value) {
189
- this._body = getPreResponseBody(value);
194
+ this._body = getPreResponseBody(value, this._isBuffer);
190
195
  }
191
196
  write(responseInit) {
192
197
  this.setValues(responseInit);
@@ -1240,6 +1245,16 @@ function badRequest(value, response) {
1240
1245
  return new BadRequestResult(value || BLANK$1, response);
1241
1246
  }
1242
1247
 
1248
+ class FileResult extends BaseResult {
1249
+ constructor(value, response) {
1250
+ super({ ...{ isBuffer: true, body: value }, ...{ status: HttpStatusCode.success } }, response);
1251
+ this.value = value;
1252
+ }
1253
+ }
1254
+ function fileResult(value, response) {
1255
+ return new FileResult(value || BLANK$1, response);
1256
+ }
1257
+
1243
1258
  function base(params, type, additionaConfig) {
1244
1259
  decoratorStateContainer.register(params, type, additionaConfig);
1245
1260
  }
@@ -1283,4 +1298,4 @@ function authorize(permission) {
1283
1298
  };
1284
1299
  }
1285
1300
 
1286
- export { $request, AbstractModelState, BadRequestResult, BaseController, CreateProblemDetail, CreatedResult, Delete, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpNotFoundException, HttpResponse, HttpStatusCode, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, RunOn, UnauthorizedAccessException, anonymous, authenticationOnly, authorize, badRequest, created, defineNattyConfig, entityContainer, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, setEnvInfo, useFilter };
1301
+ export { $request, AbstractModelState, BadRequestResult, BaseController, CreateProblemDetail, CreatedResult, Delete, FileResult, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpNotFoundException, HttpResponse, HttpStatusCode, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, RunOn, UnauthorizedAccessException, anonymous, authenticationOnly, authorize, badRequest, created, defineNattyConfig, entityContainer, fileResult, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, setEnvInfo, useFilter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/core",
3
- "version": "0.0.1-beta.30",
3
+ "version": "0.0.1-beta.32",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "tsyringe": "^4.7.0",
19
19
  "path-to-regexp": "6.2.1",
20
- "@nattyjs/common": "0.0.1-beta.30"
20
+ "@nattyjs/common": "0.0.1-beta.32"
21
21
  },
22
22
  "devDependencies": {
23
23
  "unbuild": "1.2.1"