@kosmojs/api 0.0.11 → 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 +15 -18
- package/pkg/debug.d.ts +16 -0
- package/pkg/errors/index.d.ts +21 -0
- package/pkg/errors/index.js +23 -0
- package/pkg/errors/index.js.map +7 -0
- package/pkg/errors/types.d.ts +43 -0
- package/pkg/index.d.ts +3 -0
- package/pkg/index.js +49 -198
- package/pkg/index.js.map +3 -3
- 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 -2
- 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.d.ts +0 -19
- package/pkg/src/index.d.ts +0 -5
- package/pkg/src/queryparser/index.d.ts +0 -5
- package/pkg/src/router.d.ts +0 -6
- package/pkg/src/types.d.ts +0 -136
- package/pkg/src/use.d.ts +0 -2
- package/pkg/test/defineRoute.test.d.ts +0 -1
- package/pkg/test/index.d.ts +0 -5
- package/pkg/test/routerRoutesFactory/params.test.d.ts +0 -1
- package/pkg/test/routerRoutesFactory/routeMiddleware.test.d.ts +0 -1
- package/pkg/test/routerRoutesFactory/useWrappers.test.d.ts +0 -1
- package/pkg/test/use.test.d.ts +0 -1
package/pkg/src/types.d.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import type { RouterContext, RouterMiddleware, RouterOptions } 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 CreateApp = (options?: AppOptions) => App;
|
|
90
|
-
import type KoaRouter from "@koa/router";
|
|
91
|
-
export type Router = KoaRouter<DefaultState, DefaultContext>;
|
|
92
|
-
export type { RouterOptions };
|
|
93
|
-
export type CreateRouter = (options?: RouterOptions) => Router;
|
|
94
|
-
export type DevMiddlewareFactory = (app: App) => (req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, next: () => Promise<void>) => Promise<void>;
|
|
95
|
-
export type TeardownHandler = (app: App) => void | Promise<void>;
|
|
96
|
-
export type ValidationSchema = {
|
|
97
|
-
check: (data: unknown) => boolean;
|
|
98
|
-
errors: (data: unknown) => Array<ValidationErrorEntry>;
|
|
99
|
-
errorMessage: (data: unknown) => string;
|
|
100
|
-
errorSummary: (data: unknown) => string;
|
|
101
|
-
validate: (data: unknown) => void;
|
|
102
|
-
};
|
|
103
|
-
export type ValidationSchemas<Extend = object> = {
|
|
104
|
-
params?: ValidationSchema & Extend;
|
|
105
|
-
payload?: Record<string, ValidationSchema & Extend>;
|
|
106
|
-
response?: Record<string, ValidationSchema & Extend>;
|
|
107
|
-
};
|
|
108
|
-
export type ValidationErrorScope = "params" | "payload" | "response";
|
|
109
|
-
/**
|
|
110
|
-
* Shape of individual validation errors emitted by generators.
|
|
111
|
-
*/
|
|
112
|
-
export type ValidationErrorEntry = {
|
|
113
|
-
/** JSON Schema keyword that triggered the error (e.g. `format`, `maxItems`, `maxLength`). */
|
|
114
|
-
keyword: string;
|
|
115
|
-
/** JSON Pointer–style path to the invalid field (matches JSON Schema `instancePath`). */
|
|
116
|
-
path: string;
|
|
117
|
-
/** Human-readable error message. */
|
|
118
|
-
message: string;
|
|
119
|
-
/** Constraint parameters (e.g. `{ limit: 5 }`, `{ format: "email" }`). */
|
|
120
|
-
params?: Record<string, unknown>;
|
|
121
|
-
/** Optional error code for i18n/l10n or custom handling. */
|
|
122
|
-
code?: string;
|
|
123
|
-
};
|
|
124
|
-
export type ValidationErrorData = {
|
|
125
|
-
errors: Array<ValidationErrorEntry>;
|
|
126
|
-
/**
|
|
127
|
-
* Formats errors into a single human-readable message.
|
|
128
|
-
* @example: Validation failed: user: missing required properties: "email", "name"; password: must be at least 8 characters long
|
|
129
|
-
*/
|
|
130
|
-
errorMessage: string;
|
|
131
|
-
/**
|
|
132
|
-
* Gets a simple error summary for quick feedback.
|
|
133
|
-
* @example: 2 validation errors found across 2 fields
|
|
134
|
-
*/
|
|
135
|
-
errorSummary: string;
|
|
136
|
-
};
|
package/pkg/src/use.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/pkg/test/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type MiddlewareDefinition, type RouterRouteSource } from "../src/types";
|
|
2
|
-
export declare const defaultMethods: string[];
|
|
3
|
-
export declare const middlewareStackBuilder: (a: Array<Partial<RouterRouteSource>>, b: {
|
|
4
|
-
coreMiddleware?: Array<MiddlewareDefinition>;
|
|
5
|
-
}) => import("../src/types").RouterRoute[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/pkg/test/use.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|