Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

18h

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

18h - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

.eslintignore

4

dist/@types/http-method.d.ts

@@ -15,3 +15,3 @@ import { Context, Middleware } from "koa";

}
export declare type ExtendedContext<RequestBody extends ObjectShape | null = null, RouteParams = Record<string, string | undefined>> = OverrideRequest<RequestBody extends ObjectShape ? RecursivePartial<ObjectSchema<RequestBody>["__outputType"]> : {}, RouteParams>;
export declare type ExtendedContext<RequestBody extends ObjectShape | null = null, RouteParams = Record<string, string | undefined>> = OverrideRequest<RequestBody extends ObjectShape ? RecursivePartial<ObjectSchema<RequestBody>["__outputType"]> : Record<string, never>, RouteParams>;
export declare type RouteHandlerRules<ResponseBody = unknown, RequestBody extends ObjectShape | null = null, RouteParams = Record<string, string | undefined>> = {

@@ -26,3 +26,3 @@ handler(context: ExtendedContext<RequestBody, RouteParams>): Promise<RequestHandlerResult<ResponseBody>>;

} : {
validation: ObjectSchema<RequestBody extends ObjectShape ? RequestBody : {}>;
validation: ObjectSchema<RequestBody extends ObjectShape ? RequestBody : Record<string, never>>;
});

@@ -29,0 +29,0 @@ export declare type MethodName = "any" | "delete" | "get" | "delete" | "patch" | "post" | "put";

@@ -6,4 +6,4 @@ import { MethodController, MethodName } from "../@types/http-method";

[K in MethodName]?: object;
} | null = null, RouteParams extends Record<string, string | undefined> = {}> = AllowedMethods extends null ? Record<string, never> : {
} | null = null, RouteParams extends Record<string, string | undefined> = Record<string, never>> = AllowedMethods extends null ? Record<string, never> : {
[K in keyof AllowedMethods]: AllowedMethods[K] extends MethodController<infer A, infer B> ? MethodController<A, B, RouteParams> : unknown;
};

@@ -19,3 +19,3 @@ "use strict";

const { body = null, code = 200, headers = {}, } = yield rule.handler(context);
const errors = yield ((_a = rule.validation) === null || _a === void 0 ? void 0 : _a.validate((_b = context.request) === null || _b === void 0 ? void 0 : _b.body).catch(({ errors }) => errors));
const errors = (yield ((_a = rule.validation) === null || _a === void 0 ? void 0 : _a.validate((_b = context.request) === null || _b === void 0 ? void 0 : _b.body).catch(({ errors }) => errors)));
if (errors === null || errors === void 0 ? void 0 : errors.length) {

@@ -22,0 +22,0 @@ context.status = 400;

@@ -25,3 +25,3 @@ import { Context, Middleware } from "koa";

? RecursivePartial<ObjectSchema<RequestBody>["__outputType"]>
: {},
: Record<string, never>,
RouteParams

@@ -48,3 +48,3 @@ >;

validation: ObjectSchema<
RequestBody extends ObjectShape ? RequestBody : {}
RequestBody extends ObjectShape ? RequestBody : Record<string, never>
>;

@@ -51,0 +51,0 @@ });

export type RequestHandlerResult<ResponseBody> = {
headers?: Record<string, string | number | boolean>;
code?: number;
} & (ResponseBody extends null ? {
body?: never;
} : {
body: ResponseBody;
})
} & (ResponseBody extends null
? {
body?: never;
}
: {
body: ResponseBody;
});

@@ -8,3 +8,3 @@ import { MethodController, MethodName } from "@/@types/http-method";

AllowedMethods extends { [K in MethodName]?: object } | null = null,
RouteParams extends Record<string, string | undefined> = {}
RouteParams extends Record<string, string | undefined> = Record<string, never>
> = AllowedMethods extends null

@@ -11,0 +11,0 @@ ? Record<string, never>

@@ -45,3 +45,3 @@ import Koa, { Next } from "koa";

return async (context: ExtendedContext, next: Next) => {
await func(context as any, next);
await func(context, next);
await next();

@@ -52,6 +52,11 @@ };

if (typeof router[method as keyof typeof router] === "function")
(router[method as keyof typeof router] as Function)(
path,
...middlewareChain
);
(
router[method as keyof typeof router] as (
route: string,
...middleware: ((
context: ExtendedContext,
next: Next
) => Promise<void>)[]
) => void
)(path, ...middlewareChain);
}

@@ -58,0 +63,0 @@ };

@@ -70,3 +70,3 @@ import { join } from "path";

.join("/");
return { getRoute, path };

@@ -73,0 +73,0 @@ };

@@ -19,5 +19,5 @@ import { RouteController } from "@/@types/route-controller";

const errors: string[] = await rule.validation
const errors: string[] = (await rule.validation
?.validate(context.request?.body)
.catch(({ errors }: { errors: string[] }) => errors) as string[];
.catch(({ errors }: { errors: string[] }) => errors)) as string[];

@@ -24,0 +24,0 @@ if (errors?.length) {

{
"name": "18h",
"description": "A Next.js style dynamic API router for Koa-based APIs.",
"version": "2.1.1",
"repository": {
"url": "https://github.com/ridafkih/18h"
},
"version": "2.1.2",
"repository": {
"url": "https://github.com/ridafkih/18h"
},
"main": "dist/index.js",

@@ -12,3 +12,8 @@ "scripts": {

},
"keywords": ["dynamic", "api", "router", "koa"],
"keywords": [
"dynamic",
"api",
"router",
"koa"
],
"author": "Rida F'kih",

@@ -19,2 +24,7 @@ "license": "ISC",

"@types/node": "^17.0.31",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.6.2",
"ts-node": "^10.7.0",

@@ -21,0 +31,0 @@ "tsc-alias": "^1.6.7",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc