@tahminator/sapling 2.0.0 → 2.0.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/dist/index.cjs +63 -24
- package/dist/index.d.cts +30 -11
- package/dist/index.d.mts +30 -11
- package/dist/index.mjs +52 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -237,6 +237,30 @@ var ResponseStatusError = class ResponseStatusError extends Error {
|
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
239
|
//#endregion
|
|
240
|
+
//#region src/helper/error/parse.ts
|
|
241
|
+
/**
|
|
242
|
+
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
243
|
+
*/
|
|
244
|
+
var ParserError = class ParserError extends ResponseStatusError {
|
|
245
|
+
constructor(location, issues, vendor) {
|
|
246
|
+
super(400, ParserError.formatMessage(location, issues, vendor));
|
|
247
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
248
|
+
}
|
|
249
|
+
static formatMessage(location, issues, vendor) {
|
|
250
|
+
const formatted = issues.map((i) => {
|
|
251
|
+
const path = Array.isArray(i.path) ? i.path.map((seg) => typeof seg === "object" && seg ? String(seg.key) : String(seg)).join(".") : "";
|
|
252
|
+
return path ? `${path}: ${i.message}` : i.message;
|
|
253
|
+
}).join("; ");
|
|
254
|
+
return `${vendor} failed to parse ${(() => {
|
|
255
|
+
switch (location) {
|
|
256
|
+
case "reqbody": return "request body";
|
|
257
|
+
case "reqparams": return "request params";
|
|
258
|
+
case "reqquery": return "request query";
|
|
259
|
+
}
|
|
260
|
+
})()}: ${formatted}`;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
//#endregion
|
|
240
264
|
//#region src/helper/sapling.ts
|
|
241
265
|
const settings = {
|
|
242
266
|
serialize: JSON.stringify,
|
|
@@ -479,30 +503,6 @@ function _resolve(ctor) {
|
|
|
479
503
|
return _InjectableRegistry.get(ctor);
|
|
480
504
|
}
|
|
481
505
|
//#endregion
|
|
482
|
-
//#region src/helper/error/exception.ts
|
|
483
|
-
/**
|
|
484
|
-
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
485
|
-
*/
|
|
486
|
-
var ParserError = class ParserError extends ResponseStatusError {
|
|
487
|
-
constructor(location, issues, vendor) {
|
|
488
|
-
super(400, ParserError.formatMessage(location, issues, vendor));
|
|
489
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
490
|
-
}
|
|
491
|
-
static formatMessage(location, issues, vendor) {
|
|
492
|
-
const formatted = issues.map((i) => {
|
|
493
|
-
const path = Array.isArray(i.path) ? i.path.map((seg) => typeof seg === "object" && seg ? String(seg.key) : String(seg)).join(".") : "";
|
|
494
|
-
return path ? `${path}: ${i.message}` : i.message;
|
|
495
|
-
}).join("; ");
|
|
496
|
-
return `${vendor} failed to parse ${(() => {
|
|
497
|
-
switch (location) {
|
|
498
|
-
case "reqbody": return "request body";
|
|
499
|
-
case "reqparams": return "request params";
|
|
500
|
-
case "reqquery": return "request query";
|
|
501
|
-
}
|
|
502
|
-
})()}: ${formatted}`;
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
//#endregion
|
|
506
506
|
//#region src/annotation/request.ts
|
|
507
507
|
const _requestSchemaStore = /* @__PURE__ */ new WeakMap();
|
|
508
508
|
function _getOrCreateRequestSchemaDefinition(ctor, fnName) {
|
|
@@ -721,8 +721,47 @@ function MiddlewareClass(...args) {
|
|
|
721
721
|
return Controller(...args);
|
|
722
722
|
}
|
|
723
723
|
//#endregion
|
|
724
|
+
//#region \0@oxc-project+runtime@0.127.0/helpers/decorate.js
|
|
725
|
+
function __decorate(decorators, target, key, desc) {
|
|
726
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
727
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
728
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
729
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
730
|
+
}
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region src/middleware/default/base.ts
|
|
733
|
+
let DefaultBaseErrorMiddleware = class DefaultBaseErrorMiddleware {
|
|
734
|
+
handle(err, _request, _response, _next) {
|
|
735
|
+
console.error("[Error]", err);
|
|
736
|
+
return ResponseEntity.status(500).body({ message: "Internal Server Error" });
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
__decorate([Middleware()], DefaultBaseErrorMiddleware.prototype, "handle", null);
|
|
740
|
+
DefaultBaseErrorMiddleware = __decorate([MiddlewareClass()], DefaultBaseErrorMiddleware);
|
|
741
|
+
//#endregion
|
|
742
|
+
//#region src/middleware/default/responsestatus.ts
|
|
743
|
+
let DefaultResponseStatusErrorMiddleware = class DefaultResponseStatusErrorMiddleware {
|
|
744
|
+
handle(err, _request, _response, _next) {
|
|
745
|
+
if (err instanceof ResponseStatusError) return ResponseEntity.status(err.status).body({ message: err.message });
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
__decorate([Middleware()], DefaultResponseStatusErrorMiddleware.prototype, "handle", null);
|
|
749
|
+
DefaultResponseStatusErrorMiddleware = __decorate([MiddlewareClass()], DefaultResponseStatusErrorMiddleware);
|
|
750
|
+
//#endregion
|
|
724
751
|
exports.Controller = Controller;
|
|
725
752
|
exports.DELETE = DELETE;
|
|
753
|
+
Object.defineProperty(exports, "DefaultBaseErrorMiddleware", {
|
|
754
|
+
enumerable: true,
|
|
755
|
+
get: function() {
|
|
756
|
+
return DefaultBaseErrorMiddleware;
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
Object.defineProperty(exports, "DefaultResponseStatusErrorMiddleware", {
|
|
760
|
+
enumerable: true,
|
|
761
|
+
get: function() {
|
|
762
|
+
return DefaultResponseStatusErrorMiddleware;
|
|
763
|
+
}
|
|
764
|
+
});
|
|
726
765
|
exports.GET = GET;
|
|
727
766
|
exports.HEAD = HEAD;
|
|
728
767
|
exports.Html404ErrorPage = Html404ErrorPage;
|
package/dist/index.d.cts
CHANGED
|
@@ -397,6 +397,16 @@ declare class ResponseStatusError extends Error {
|
|
|
397
397
|
constructor(status: HttpStatus, message?: string);
|
|
398
398
|
}
|
|
399
399
|
//#endregion
|
|
400
|
+
//#region src/helper/error/parse.d.ts
|
|
401
|
+
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery";
|
|
402
|
+
/**
|
|
403
|
+
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
404
|
+
*/
|
|
405
|
+
declare class ParserError extends ResponseStatusError {
|
|
406
|
+
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string);
|
|
407
|
+
private static formatMessage;
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
400
410
|
//#region src/helper/sapling.d.ts
|
|
401
411
|
/**
|
|
402
412
|
* Collection of utility functions which are essential for Sapling to function.
|
|
@@ -473,16 +483,6 @@ declare class Sapling {
|
|
|
473
483
|
static setDeserializeFn(this: void, fn: (value: string) => any): void;
|
|
474
484
|
}
|
|
475
485
|
//#endregion
|
|
476
|
-
//#region src/helper/error/exception.d.ts
|
|
477
|
-
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery";
|
|
478
|
-
/**
|
|
479
|
-
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
480
|
-
*/
|
|
481
|
-
declare class ParserError extends ResponseStatusError {
|
|
482
|
-
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string);
|
|
483
|
-
private static formatMessage;
|
|
484
|
-
}
|
|
485
|
-
//#endregion
|
|
486
486
|
//#region src/annotation/request.d.ts
|
|
487
487
|
type RequestSchemaDefinition = {
|
|
488
488
|
body?: StandardSchemaV1;
|
|
@@ -495,4 +495,23 @@ declare function RequestQuery(schema: StandardSchemaV1): MethodDecorator;
|
|
|
495
495
|
declare function _getRequestSchemas(ctor: Function, fnName: string): RequestSchemaDefinition | undefined;
|
|
496
496
|
declare function _parseOrThrow<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown, kind: ParserErrorLocation): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
497
497
|
//#endregion
|
|
498
|
-
|
|
498
|
+
//#region src/middleware/default/base.d.ts
|
|
499
|
+
/**
|
|
500
|
+
* This should be registered last in the middleware chain.
|
|
501
|
+
*
|
|
502
|
+
* All exception messages are hidden from the request by default.
|
|
503
|
+
*/
|
|
504
|
+
declare class DefaultBaseErrorMiddleware {
|
|
505
|
+
handle(err: unknown, _request: Request, _response: Response, _next: NextFunction): ResponseEntity<{
|
|
506
|
+
message: string;
|
|
507
|
+
}>;
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/middleware/default/responsestatus.d.ts
|
|
511
|
+
declare class DefaultResponseStatusErrorMiddleware {
|
|
512
|
+
handle(err: unknown, _request: Request, _response: Response, _next: NextFunction): ResponseEntity<{
|
|
513
|
+
message: string;
|
|
514
|
+
}> | undefined;
|
|
515
|
+
}
|
|
516
|
+
//#endregion
|
|
517
|
+
export { Class, Controller, DELETE, DefaultBaseErrorMiddleware, DefaultResponseStatusErrorMiddleware, ExpressMiddlewareFn, ExpressRouterMethodKey, ExpressRouterMethods, GET, HEAD, Html404ErrorPage, HttpHeaders, HttpStatus, Injectable, Middleware, MiddlewareClass, OPTIONS, PATCH, POST, PUT, ParserError, ParserErrorLocation, RedirectView, RequestBody, RequestParam, RequestQuery, ResponseEntity, ResponseEntityBuilder, ResponseStatusError, RouteDefinition, Sapling, _ControllerRegistry, _InjectableDeps, _InjectableRegistry, _Route, _getRequestSchemas, _getRoutes, _parseOrThrow, _resolve, methodResolve };
|
package/dist/index.d.mts
CHANGED
|
@@ -397,6 +397,16 @@ declare class ResponseStatusError extends Error {
|
|
|
397
397
|
constructor(status: HttpStatus, message?: string);
|
|
398
398
|
}
|
|
399
399
|
//#endregion
|
|
400
|
+
//#region src/helper/error/parse.d.ts
|
|
401
|
+
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery";
|
|
402
|
+
/**
|
|
403
|
+
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
404
|
+
*/
|
|
405
|
+
declare class ParserError extends ResponseStatusError {
|
|
406
|
+
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string);
|
|
407
|
+
private static formatMessage;
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
400
410
|
//#region src/helper/sapling.d.ts
|
|
401
411
|
/**
|
|
402
412
|
* Collection of utility functions which are essential for Sapling to function.
|
|
@@ -473,16 +483,6 @@ declare class Sapling {
|
|
|
473
483
|
static setDeserializeFn(this: void, fn: (value: string) => any): void;
|
|
474
484
|
}
|
|
475
485
|
//#endregion
|
|
476
|
-
//#region src/helper/error/exception.d.ts
|
|
477
|
-
type ParserErrorLocation = "reqbody" | "reqparams" | "reqquery";
|
|
478
|
-
/**
|
|
479
|
-
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
480
|
-
*/
|
|
481
|
-
declare class ParserError extends ResponseStatusError {
|
|
482
|
-
constructor(location: ParserErrorLocation, issues: readonly StandardSchemaV1.Issue[], vendor: string);
|
|
483
|
-
private static formatMessage;
|
|
484
|
-
}
|
|
485
|
-
//#endregion
|
|
486
486
|
//#region src/annotation/request.d.ts
|
|
487
487
|
type RequestSchemaDefinition = {
|
|
488
488
|
body?: StandardSchemaV1;
|
|
@@ -495,4 +495,23 @@ declare function RequestQuery(schema: StandardSchemaV1): MethodDecorator;
|
|
|
495
495
|
declare function _getRequestSchemas(ctor: Function, fnName: string): RequestSchemaDefinition | undefined;
|
|
496
496
|
declare function _parseOrThrow<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown, kind: ParserErrorLocation): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
497
497
|
//#endregion
|
|
498
|
-
|
|
498
|
+
//#region src/middleware/default/base.d.ts
|
|
499
|
+
/**
|
|
500
|
+
* This should be registered last in the middleware chain.
|
|
501
|
+
*
|
|
502
|
+
* All exception messages are hidden from the request by default.
|
|
503
|
+
*/
|
|
504
|
+
declare class DefaultBaseErrorMiddleware {
|
|
505
|
+
handle(err: unknown, _request: Request, _response: Response, _next: NextFunction): ResponseEntity<{
|
|
506
|
+
message: string;
|
|
507
|
+
}>;
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/middleware/default/responsestatus.d.ts
|
|
511
|
+
declare class DefaultResponseStatusErrorMiddleware {
|
|
512
|
+
handle(err: unknown, _request: Request, _response: Response, _next: NextFunction): ResponseEntity<{
|
|
513
|
+
message: string;
|
|
514
|
+
}> | undefined;
|
|
515
|
+
}
|
|
516
|
+
//#endregion
|
|
517
|
+
export { Class, Controller, DELETE, DefaultBaseErrorMiddleware, DefaultResponseStatusErrorMiddleware, ExpressMiddlewareFn, ExpressRouterMethodKey, ExpressRouterMethods, GET, HEAD, Html404ErrorPage, HttpHeaders, HttpStatus, Injectable, Middleware, MiddlewareClass, OPTIONS, PATCH, POST, PUT, ParserError, ParserErrorLocation, RedirectView, RequestBody, RequestParam, RequestQuery, ResponseEntity, ResponseEntityBuilder, ResponseStatusError, RouteDefinition, Sapling, _ControllerRegistry, _InjectableDeps, _InjectableRegistry, _Route, _getRequestSchemas, _getRoutes, _parseOrThrow, _resolve, methodResolve };
|
package/dist/index.mjs
CHANGED
|
@@ -213,6 +213,30 @@ var ResponseStatusError = class ResponseStatusError extends Error {
|
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
215
|
//#endregion
|
|
216
|
+
//#region src/helper/error/parse.ts
|
|
217
|
+
/**
|
|
218
|
+
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
219
|
+
*/
|
|
220
|
+
var ParserError = class ParserError extends ResponseStatusError {
|
|
221
|
+
constructor(location, issues, vendor) {
|
|
222
|
+
super(400, ParserError.formatMessage(location, issues, vendor));
|
|
223
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
224
|
+
}
|
|
225
|
+
static formatMessage(location, issues, vendor) {
|
|
226
|
+
const formatted = issues.map((i) => {
|
|
227
|
+
const path = Array.isArray(i.path) ? i.path.map((seg) => typeof seg === "object" && seg ? String(seg.key) : String(seg)).join(".") : "";
|
|
228
|
+
return path ? `${path}: ${i.message}` : i.message;
|
|
229
|
+
}).join("; ");
|
|
230
|
+
return `${vendor} failed to parse ${(() => {
|
|
231
|
+
switch (location) {
|
|
232
|
+
case "reqbody": return "request body";
|
|
233
|
+
case "reqparams": return "request params";
|
|
234
|
+
case "reqquery": return "request query";
|
|
235
|
+
}
|
|
236
|
+
})()}: ${formatted}`;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
//#endregion
|
|
216
240
|
//#region src/helper/sapling.ts
|
|
217
241
|
const settings = {
|
|
218
242
|
serialize: JSON.stringify,
|
|
@@ -455,30 +479,6 @@ function _resolve(ctor) {
|
|
|
455
479
|
return _InjectableRegistry.get(ctor);
|
|
456
480
|
}
|
|
457
481
|
//#endregion
|
|
458
|
-
//#region src/helper/error/exception.ts
|
|
459
|
-
/**
|
|
460
|
-
* This error should be thrown when some data cannot be parsed by a given schema.
|
|
461
|
-
*/
|
|
462
|
-
var ParserError = class ParserError extends ResponseStatusError {
|
|
463
|
-
constructor(location, issues, vendor) {
|
|
464
|
-
super(400, ParserError.formatMessage(location, issues, vendor));
|
|
465
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
466
|
-
}
|
|
467
|
-
static formatMessage(location, issues, vendor) {
|
|
468
|
-
const formatted = issues.map((i) => {
|
|
469
|
-
const path = Array.isArray(i.path) ? i.path.map((seg) => typeof seg === "object" && seg ? String(seg.key) : String(seg)).join(".") : "";
|
|
470
|
-
return path ? `${path}: ${i.message}` : i.message;
|
|
471
|
-
}).join("; ");
|
|
472
|
-
return `${vendor} failed to parse ${(() => {
|
|
473
|
-
switch (location) {
|
|
474
|
-
case "reqbody": return "request body";
|
|
475
|
-
case "reqparams": return "request params";
|
|
476
|
-
case "reqquery": return "request query";
|
|
477
|
-
}
|
|
478
|
-
})()}: ${formatted}`;
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
//#endregion
|
|
482
482
|
//#region src/annotation/request.ts
|
|
483
483
|
const _requestSchemaStore = /* @__PURE__ */ new WeakMap();
|
|
484
484
|
function _getOrCreateRequestSchemaDefinition(ctor, fnName) {
|
|
@@ -697,4 +697,31 @@ function MiddlewareClass(...args) {
|
|
|
697
697
|
return Controller(...args);
|
|
698
698
|
}
|
|
699
699
|
//#endregion
|
|
700
|
-
|
|
700
|
+
//#region \0@oxc-project+runtime@0.127.0/helpers/decorate.js
|
|
701
|
+
function __decorate(decorators, target, key, desc) {
|
|
702
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
703
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
704
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
705
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
706
|
+
}
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region src/middleware/default/base.ts
|
|
709
|
+
let DefaultBaseErrorMiddleware = class DefaultBaseErrorMiddleware {
|
|
710
|
+
handle(err, _request, _response, _next) {
|
|
711
|
+
console.error("[Error]", err);
|
|
712
|
+
return ResponseEntity.status(500).body({ message: "Internal Server Error" });
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
__decorate([Middleware()], DefaultBaseErrorMiddleware.prototype, "handle", null);
|
|
716
|
+
DefaultBaseErrorMiddleware = __decorate([MiddlewareClass()], DefaultBaseErrorMiddleware);
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region src/middleware/default/responsestatus.ts
|
|
719
|
+
let DefaultResponseStatusErrorMiddleware = class DefaultResponseStatusErrorMiddleware {
|
|
720
|
+
handle(err, _request, _response, _next) {
|
|
721
|
+
if (err instanceof ResponseStatusError) return ResponseEntity.status(err.status).body({ message: err.message });
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
__decorate([Middleware()], DefaultResponseStatusErrorMiddleware.prototype, "handle", null);
|
|
725
|
+
DefaultResponseStatusErrorMiddleware = __decorate([MiddlewareClass()], DefaultResponseStatusErrorMiddleware);
|
|
726
|
+
//#endregion
|
|
727
|
+
export { Controller, DELETE, DefaultBaseErrorMiddleware, DefaultResponseStatusErrorMiddleware, GET, HEAD, Html404ErrorPage, HttpStatus, Injectable, Middleware, MiddlewareClass, OPTIONS, PATCH, POST, PUT, ParserError, RedirectView, RequestBody, RequestParam, RequestQuery, ResponseEntity, ResponseEntityBuilder, ResponseStatusError, Sapling, _ControllerRegistry, _InjectableDeps, _InjectableRegistry, _Route, _getRequestSchemas, _getRoutes, _parseOrThrow, _resolve, methodResolve };
|