I guess it builds now?
This commit is contained in:
parent
ac9c21d58e
commit
a06c8a3883
@ -16,14 +16,20 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export interface FieldErrorResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
errors: Record<string, ObjectErrorContent>;
|
||||
}
|
||||
|
||||
export function FieldErrors(
|
||||
fields: Record<string, { code?: string; message: string }>,
|
||||
) {
|
||||
export type ErrorContent = { code: string; message: string };
|
||||
export type ObjectErrorContent = { _errors: ErrorContent[] };
|
||||
|
||||
export function FieldErrors(fields: Record<string, { code?: string; message: string }>) {
|
||||
return new FieldError(
|
||||
50035,
|
||||
"Invalid Form Body",
|
||||
fields.map(({ message, code }) => ({
|
||||
fields.map<ErrorContent, ObjectErrorContent>(({ message, code }) => ({
|
||||
_errors: [
|
||||
{
|
||||
message,
|
||||
|
||||
@ -6,10 +6,10 @@ import assert from "node:assert/strict";
|
||||
|
||||
describe("Object extensions", () => {
|
||||
it("forEach", async () => {
|
||||
const obj = { a: 1, b: 2, c: 3 };
|
||||
const obj: { [index:string]: number } = { a: 1, b: 2, c: 3 };
|
||||
const keys: string[] = [];
|
||||
const values: number[] = [];
|
||||
obj.forEach((value, key) => {
|
||||
obj.forEach<number>((value, key, _) => {
|
||||
keys.push(key);
|
||||
values.push(value);
|
||||
});
|
||||
|
||||
@ -1,31 +1,34 @@
|
||||
declare global {
|
||||
interface Object {
|
||||
forEach(callback: (value: unknown, key: string, object: unknown) => void): void;
|
||||
map<T>(callback: (value: unknown, key: string, object: unknown) => T): object;
|
||||
forEach<T>(callback: (value: T, key: string, object: { [index: string]: T }) => void): void;
|
||||
map<SV, TV>(callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV };
|
||||
}
|
||||
}
|
||||
|
||||
export function objectForEach<T>(obj: never, callback: (value: T, key: string, object: unknown) => void): void {
|
||||
export function objectForEach<T>(obj: { [index: string]: T }, callback: (value: T, key: string, object: { [index: string]: T }) => void): void {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
callback(obj[key], key, obj);
|
||||
});
|
||||
}
|
||||
|
||||
export function objectMap<T>(obj: object, callback: (value: unknown, key: string, object: unknown) => T): T[] {
|
||||
return Object.keys(obj).map((key) => {
|
||||
return callback(obj[key], key, obj);
|
||||
export function objectMap<SV, TV>(srcObj: { [index: string]: SV }, callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV } {
|
||||
if (typeof callback !== "function") throw new TypeError(`${callback} is not a function`);
|
||||
const obj: { [index: string]: TV } = {};
|
||||
Object.keys(srcObj).forEach((key) => {
|
||||
obj[key] = callback(srcObj[key], key, srcObj);
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (!Object.prototype.forEach)
|
||||
Object.defineProperty(Object.prototype, "forEach", {
|
||||
value: objectForEach,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
writable: true,
|
||||
});
|
||||
if (!Object.prototype.map)
|
||||
Object.defineProperty(Object.prototype, "map", {
|
||||
value: objectMap,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
});
|
||||
writable: true,
|
||||
});
|
||||
|
||||
@ -2,7 +2,7 @@ import express, { Application, NextFunction, Request, Response, Router } from "e
|
||||
import { traverseDirectory } from "./Utils";
|
||||
import { Server as HTTPServer } from "http";
|
||||
import { HTTPError } from "./HTTPError";
|
||||
import "express-async-errors";
|
||||
// import "express-async-errors";
|
||||
import bodyParser from "body-parser";
|
||||
// import helmet from "helmet";
|
||||
import http from "http";
|
||||
|
||||
Reference in New Issue
Block a user