@kosmojs/api 0.0.20 → 0.0.21
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/LICENSE +21 -0
- package/package.json +11 -18
- package/pkg/debug.d.ts +16 -0
- package/pkg/errors/index.d.ts +21 -0
- package/pkg/errors/index.js +8 -4
- package/pkg/errors/index.js.map +2 -2
- package/pkg/errors/types.d.ts +43 -0
- package/pkg/index.d.ts +3 -0
- package/pkg/index.js +49 -225
- package/pkg/index.js.map +4 -4
- package/pkg/routes.d.ts +5 -0
- package/pkg/types.d.ts +285 -0
- package/pkg/bodyparser/index.js +0 -111
- package/pkg/bodyparser/index.js.map +0 -7
- package/pkg/queryparser/index.js +0 -37
- package/pkg/queryparser/index.js.map +0 -7
- package/pkg/src/app.d.ts +0 -3
- package/pkg/src/bodyparser/config.d.ts +0 -10
- package/pkg/src/bodyparser/index.d.ts +0 -14
- package/pkg/src/bodyparser/types.d.ts +0 -39
- package/pkg/src/debug.d.ts +0 -10
- package/pkg/src/errors/index.d.ts +0 -18
- package/pkg/src/index.d.ts +0 -5
- package/pkg/src/queryparser/index.d.ts +0 -5
- package/pkg/src/router.d.ts +0 -7
- package/pkg/src/types.d.ts +0 -133
- package/pkg/src/use.d.ts +0 -2
- package/pkg/test/createRouterRoutes/params.test.d.ts +0 -1
- package/pkg/test/createRouterRoutes/routeMiddleware.test.d.ts +0 -1
- package/pkg/test/createRouterRoutes/useWrappers.test.d.ts +0 -1
- package/pkg/test/defineRoute.test.d.ts +0 -1
- package/pkg/test/index.d.ts +0 -7
- package/pkg/test/use.test.d.ts +0 -1
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Options as FormidableOptions } from "formidable";
|
|
2
|
-
export type TrimOption = Array<string>;
|
|
3
|
-
export type Trimmer = (fields: Record<string, unknown>) => Record<string, unknown>;
|
|
4
|
-
type GenericOptions = {
|
|
5
|
-
limit?: number;
|
|
6
|
-
trim?: TrimOption;
|
|
7
|
-
};
|
|
8
|
-
export type JsonOptions = FormidableOptions & GenericOptions;
|
|
9
|
-
export type FormOptions = FormidableOptions & GenericOptions & {
|
|
10
|
-
uploadDir?: string;
|
|
11
|
-
multipart?: boolean;
|
|
12
|
-
urlencoded?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type RawOptions = {
|
|
15
|
-
/**
|
|
16
|
-
* The byte limit of the body.
|
|
17
|
-
* If the body ends up being larger than this limit, a 413 error code is returned.
|
|
18
|
-
* */
|
|
19
|
-
limit?: number;
|
|
20
|
-
/**
|
|
21
|
-
* The length of the stream.
|
|
22
|
-
* If the contents of the stream do not add up to this length,
|
|
23
|
-
* an 400 error code is returned
|
|
24
|
-
* */
|
|
25
|
-
length?: number;
|
|
26
|
-
/**
|
|
27
|
-
* The encoding to use to decode the body into a string.
|
|
28
|
-
* By default, a Buffer instance will be returned when no encoding is specified.
|
|
29
|
-
* utf-8 would decode as plain text.
|
|
30
|
-
* use any encoding supported by iconv-lite.
|
|
31
|
-
* */
|
|
32
|
-
encoding?: string;
|
|
33
|
-
/**
|
|
34
|
-
* zlib options
|
|
35
|
-
* */
|
|
36
|
-
chunkSize?: number;
|
|
37
|
-
};
|
|
38
|
-
export type Options = JsonOptions | FormOptions | RawOptions;
|
|
39
|
-
export {};
|
package/pkg/src/debug.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { HandlerDefinition, MiddlewareDefinition, RouterRoute } from "./types";
|
|
2
|
-
declare const _default: (entry: {
|
|
3
|
-
name: string;
|
|
4
|
-
path: string;
|
|
5
|
-
file: string;
|
|
6
|
-
methods: Array<string>;
|
|
7
|
-
middleware: Array<MiddlewareDefinition>;
|
|
8
|
-
handler: HandlerDefinition;
|
|
9
|
-
}) => RouterRoute["debug"];
|
|
10
|
-
export default _default;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ValidationErrorData, ValidationErrorEntry, ValidationErrorScope } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
* Standardized error wrapper used by validation generators.
|
|
4
|
-
*
|
|
5
|
-
* Instances of this class are thrown whenever validation fails,
|
|
6
|
-
* carrying both the error scope (e.g. `"params"`, `"payload"`)
|
|
7
|
-
* and the list of validation error details.
|
|
8
|
-
* */
|
|
9
|
-
export declare class ValidationError extends Error {
|
|
10
|
-
scope: ValidationErrorScope;
|
|
11
|
-
errors: Array<ValidationErrorEntry>;
|
|
12
|
-
errorMessage: string;
|
|
13
|
-
errorSummary: string;
|
|
14
|
-
constructor([scope, { errors, errorMessage, errorSummary }]: [
|
|
15
|
-
ValidationErrorScope,
|
|
16
|
-
ValidationErrorData
|
|
17
|
-
]);
|
|
18
|
-
}
|
package/pkg/src/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type Koa from "koa";
|
|
2
|
-
import type { IParseOptions, IStringifyOptions } from "qs";
|
|
3
|
-
import type { DefaultContext, DefaultState } from "../types";
|
|
4
|
-
declare const _default: <T extends InstanceType<typeof Koa<DefaultState, DefaultContext>> = never>(app: T, _parseOptions?: IParseOptions, _stringifyOptions?: IStringifyOptions) => T;
|
|
5
|
-
export default _default;
|
package/pkg/src/router.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import Router from "@koa/router";
|
|
2
|
-
import type { DefineRoute, MiddlewareDefinition, RouterOptions, RouterRoute, RouterRouteSource } from "./types";
|
|
3
|
-
export declare const defineRoute: DefineRoute;
|
|
4
|
-
export declare const createRouter: (options?: RouterOptions) => Router<import("koa").DefaultState, import("koa").DefaultContext>;
|
|
5
|
-
export declare const createRouterRoutes: (routeSources: Array<RouterRouteSource>, { coreMiddleware, }: {
|
|
6
|
-
coreMiddleware: Array<MiddlewareDefinition>;
|
|
7
|
-
}) => Array<RouterRoute>;
|
package/pkg/src/types.d.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import type { RouterContext, RouterMiddleware } from "@koa/router";
|
|
2
|
-
import type { Next } from "koa";
|
|
3
|
-
declare module "koa" {
|
|
4
|
-
interface Request {
|
|
5
|
-
body?: unknown;
|
|
6
|
-
rawBody: string;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export interface DefaultState {
|
|
10
|
-
}
|
|
11
|
-
export interface DefaultContext {
|
|
12
|
-
}
|
|
13
|
-
export declare enum HTTPMethods {
|
|
14
|
-
HEAD = "HEAD",
|
|
15
|
-
OPTIONS = "OPTIONS",
|
|
16
|
-
GET = "GET",
|
|
17
|
-
PUT = "PUT",
|
|
18
|
-
PATCH = "PATCH",
|
|
19
|
-
POST = "POST",
|
|
20
|
-
DELETE = "DELETE"
|
|
21
|
-
}
|
|
22
|
-
export type HTTPMethod = keyof typeof HTTPMethods;
|
|
23
|
-
export type ParameterizedContext<ParamsT, StateT, ContextT, PayloadT = unknown, ResponseT = unknown> = RouterContext<DefaultState & StateT, DefaultContext & ContextT & {
|
|
24
|
-
typedParams: ParamsT;
|
|
25
|
-
payload: PayloadT;
|
|
26
|
-
}, ResponseT>;
|
|
27
|
-
export type ParameterizedMiddleware<ParamsT = {}, StateT = {}, ContextT = {}> = (ctx: ParameterizedContext<ParamsT, StateT, ContextT>, next: Next) => Promise<void> | void;
|
|
28
|
-
export type RouteHandler<ParamsT, StateT, ContextT, PayloadT = unknown, ResponseT = unknown> = (ctx: ParameterizedContext<ParamsT, StateT, ContextT, PayloadT, ResponseT>, next: Next) => Promise<void> | void;
|
|
29
|
-
export type MiddlewareDefinition = {
|
|
30
|
-
kind: "middleware";
|
|
31
|
-
middleware: Array<ParameterizedMiddleware>;
|
|
32
|
-
options?: UseOptions | undefined;
|
|
33
|
-
};
|
|
34
|
-
export type HandlerDefinition = {
|
|
35
|
-
kind: "handler";
|
|
36
|
-
middleware: Array<ParameterizedMiddleware>;
|
|
37
|
-
method: HTTPMethod;
|
|
38
|
-
};
|
|
39
|
-
export type RouteDefinitionItem = MiddlewareDefinition | HandlerDefinition;
|
|
40
|
-
export type DefineRouteHelpers<ParamsT, StateT, ContextT, OptionalHandlers = undefined> = {
|
|
41
|
-
use: (middleware: ParameterizedMiddleware<ParamsT, StateT, ContextT> | Array<ParameterizedMiddleware<ParamsT, StateT, ContextT>>, options?: UseOptions) => RouteDefinitionItem;
|
|
42
|
-
} & {
|
|
43
|
-
[M in HTTPMethod]: M extends OptionalHandlers ? <PayloadT = unknown, ResponseT = unknown>(handler?: RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT> | Array<RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT>>) => RouteDefinitionItem : <PayloadT = unknown, ResponseT = unknown>(handler: RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT> | Array<RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT>>) => RouteDefinitionItem;
|
|
44
|
-
};
|
|
45
|
-
export type DefineRoute = <ParamsT = Record<string, string>, StateT = object, ContextT = object>(factory: (helpers: DefineRouteHelpers<ParamsT, StateT, ContextT>) => Array<RouteDefinitionItem>) => Array<RouteDefinitionItem>;
|
|
46
|
-
export interface UseSlots {
|
|
47
|
-
errorHandler: string;
|
|
48
|
-
params: string;
|
|
49
|
-
validateParams: string;
|
|
50
|
-
bodyparser: string;
|
|
51
|
-
payload: string;
|
|
52
|
-
validatePayload: string;
|
|
53
|
-
validateResponse: string;
|
|
54
|
-
}
|
|
55
|
-
export type UseOptions = {
|
|
56
|
-
on?: Array<HTTPMethod>;
|
|
57
|
-
slot?: keyof UseSlots;
|
|
58
|
-
debug?: string | undefined;
|
|
59
|
-
};
|
|
60
|
-
export type Use = <StateT = DefaultState, ContextT = DefaultContext>(middleware: ParameterizedMiddleware<Record<string, string>, StateT, ContextT> | Array<ParameterizedMiddleware<Record<string, string>, StateT, ContextT>>, options?: UseOptions) => MiddlewareDefinition;
|
|
61
|
-
export type RouterRouteSource = {
|
|
62
|
-
name: string;
|
|
63
|
-
path: string;
|
|
64
|
-
file: string;
|
|
65
|
-
useWrappers: [...a: Array<MiddlewareDefinition>];
|
|
66
|
-
definitionItems: Array<RouteDefinitionItem>;
|
|
67
|
-
params: Array<[name: string, isRest?: boolean]>;
|
|
68
|
-
numericParams: Array<string>;
|
|
69
|
-
validationSchemas: ValidationSchemas;
|
|
70
|
-
meta?: Record<string, unknown>;
|
|
71
|
-
};
|
|
72
|
-
export type RouterRoute = {
|
|
73
|
-
name: string;
|
|
74
|
-
path: string;
|
|
75
|
-
file: string;
|
|
76
|
-
methods: Array<string>;
|
|
77
|
-
middleware: Array<RouterMiddleware>;
|
|
78
|
-
debug: {
|
|
79
|
-
headline: string;
|
|
80
|
-
methods: string;
|
|
81
|
-
middleware: string;
|
|
82
|
-
handler: string;
|
|
83
|
-
full: string;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
import type Koa from "koa";
|
|
87
|
-
export type App = Koa<DefaultState, DefaultContext>;
|
|
88
|
-
export type AppOptions = ConstructorParameters<typeof import("koa")>[0];
|
|
89
|
-
export type Router = import("@koa/router").Router<DefaultState, DefaultContext>;
|
|
90
|
-
export type RouterOptions = import("@koa/router").RouterOptions;
|
|
91
|
-
export type DevMiddlewareFactory = (app: App) => (req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, next: () => Promise<void>) => Promise<void>;
|
|
92
|
-
export type TeardownHandler = (app: App) => void | Promise<void>;
|
|
93
|
-
export type ValidationSchema = {
|
|
94
|
-
check: (data: unknown) => boolean;
|
|
95
|
-
errors: (data: unknown) => Array<ValidationErrorEntry>;
|
|
96
|
-
errorMessage: (data: unknown) => string;
|
|
97
|
-
errorSummary: (data: unknown) => string;
|
|
98
|
-
validate: (data: unknown) => void;
|
|
99
|
-
};
|
|
100
|
-
export type ValidationSchemas<Extend = object> = {
|
|
101
|
-
params?: ValidationSchema & Extend;
|
|
102
|
-
payload?: Record<string, ValidationSchema & Extend>;
|
|
103
|
-
response?: Record<string, ValidationSchema & Extend>;
|
|
104
|
-
};
|
|
105
|
-
export type ValidationErrorScope = "params" | "payload" | "response";
|
|
106
|
-
/**
|
|
107
|
-
* Shape of individual validation errors emitted by generators.
|
|
108
|
-
*/
|
|
109
|
-
export type ValidationErrorEntry = {
|
|
110
|
-
/** JSON Schema keyword that triggered the error (e.g. `format`, `maxItems`, `maxLength`). */
|
|
111
|
-
keyword: string;
|
|
112
|
-
/** JSON Pointer–style path to the invalid field (matches JSON Schema `instancePath`). */
|
|
113
|
-
path: string;
|
|
114
|
-
/** Human-readable error message. */
|
|
115
|
-
message: string;
|
|
116
|
-
/** Constraint parameters (e.g. `{ limit: 5 }`, `{ format: "email" }`). */
|
|
117
|
-
params?: Record<string, unknown>;
|
|
118
|
-
/** Optional error code for i18n/l10n or custom handling. */
|
|
119
|
-
code?: string;
|
|
120
|
-
};
|
|
121
|
-
export type ValidationErrorData = {
|
|
122
|
-
errors: Array<ValidationErrorEntry>;
|
|
123
|
-
/**
|
|
124
|
-
* Formats errors into a single human-readable message.
|
|
125
|
-
* @example: Validation failed: user: missing required properties: "email", "name"; password: must be at least 8 characters long
|
|
126
|
-
*/
|
|
127
|
-
errorMessage: string;
|
|
128
|
-
/**
|
|
129
|
-
* Gets a simple error summary for quick feedback.
|
|
130
|
-
* @example: 2 validation errors found across 2 fields
|
|
131
|
-
*/
|
|
132
|
-
errorSummary: string;
|
|
133
|
-
};
|
package/pkg/src/use.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/pkg/test/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import Koa, { type Context, type Next } from "koa";
|
|
2
|
-
import { type MiddlewareDefinition, type RouterRouteSource } from "../src/types";
|
|
3
|
-
export declare const defaultMethods: string[];
|
|
4
|
-
export declare const middlewareStackBuilder: (a: Array<Partial<RouterRouteSource>>, b: {
|
|
5
|
-
coreMiddleware?: Array<MiddlewareDefinition>;
|
|
6
|
-
}) => import("../src/types").RouterRoute[];
|
|
7
|
-
export declare const runMiddleware: <T = any>(middleware: Array<(ctx: T, next: Next) => void | Promise<void>>, ctxOverrides?: Partial<Context>) => Promise<Koa.ParameterizedContext<Koa.DefaultState, Koa.DefaultContext, unknown>>;
|
package/pkg/test/use.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|