zenko 0.3.0-beta.1 → 0.3.0-beta.2
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/cli.d.mts +1 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +63 -0
- package/dist/{treaty-ZSSJQYZa.d.cts → treaty-DM77ZhDU.d.mts} +3 -19
- package/dist/treaty-NM6Hf8S8.d.cts +68 -0
- package/dist/treaty.d.cts +1 -1
- package/dist/treaty.d.mts +2 -0
- package/dist/types-BM-Q_QIk.d.cts +19 -0
- package/dist/types-ByqlZjPK.d.mts +19 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +15 -5
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as PathFn, i as OperationErrors, n as HeaderFn, r as OperationDefinition, s as SecurityRequirement } from "./types-BM-Q_QIk.cjs";
|
|
2
|
+
import { a as RouteNode, i as TreatyRoutesConstraint, n as LeafCall, r as TreatyClient, s as TreatyResult, t as createTreatyClient } from "./treaty-NM6Hf8S8.cjs";
|
|
2
3
|
|
|
3
4
|
//#region src/zenko.d.ts
|
|
4
5
|
type OpenAPISpec = {
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { a as PathFn, i as OperationErrors, n as HeaderFn, r as OperationDefinition, s as SecurityRequirement } from "./types-ByqlZjPK.mjs";
|
|
2
|
+
import { a as RouteNode, i as TreatyRoutesConstraint, n as LeafCall, r as TreatyClient, s as TreatyResult, t as createTreatyClient } from "./treaty-DM77ZhDU.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/zenko.d.ts
|
|
5
|
+
type OpenAPISpec = {
|
|
6
|
+
openapi: string;
|
|
7
|
+
info: unknown;
|
|
8
|
+
paths: Record<string, Record<string, unknown>>;
|
|
9
|
+
webhooks?: Record<string, Record<string, unknown>>;
|
|
10
|
+
security?: Record<string, string[]>[];
|
|
11
|
+
components?: {
|
|
12
|
+
schemas?: Record<string, unknown>;
|
|
13
|
+
parameters?: Record<string, unknown>;
|
|
14
|
+
securitySchemes?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type TypesHelperMode = "package" | "inline" | "file";
|
|
18
|
+
type TypesConfig = {
|
|
19
|
+
emit?: boolean;
|
|
20
|
+
helpers?: TypesHelperMode;
|
|
21
|
+
helpersOutput?: string;
|
|
22
|
+
treeShake?: boolean;
|
|
23
|
+
optionalType?: "optional" | "nullable" | "nullish";
|
|
24
|
+
operationTypeSuffix?: string;
|
|
25
|
+
};
|
|
26
|
+
type EnumConfig = {
|
|
27
|
+
open?: boolean | string[];
|
|
28
|
+
unknownPrefix?: string;
|
|
29
|
+
};
|
|
30
|
+
type GenerateOptions = {
|
|
31
|
+
strictDates?: boolean;
|
|
32
|
+
strictNumeric?: boolean;
|
|
33
|
+
dateTimeOffset?: boolean | string[];
|
|
34
|
+
types?: TypesConfig;
|
|
35
|
+
operationIds?: string[];
|
|
36
|
+
openEnums?: boolean | string[] | EnumConfig;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Generates TypeScript client code from an OpenAPI specification.
|
|
40
|
+
*
|
|
41
|
+
* @param spec - The OpenAPI specification object.
|
|
42
|
+
* @param options - Configuration options controlling code generation behavior.
|
|
43
|
+
* @returns Generated TypeScript code as a string.
|
|
44
|
+
*/
|
|
45
|
+
declare function generate(spec: OpenAPISpec, options?: GenerateOptions): string;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/utils/treaty-tree.d.ts
|
|
48
|
+
type OperationMeta = {
|
|
49
|
+
method: string;
|
|
50
|
+
path: string;
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/treaty-generator.d.ts
|
|
54
|
+
declare function generateTreatyModuleFromMetadata(metadata: Record<string, OperationMeta>, options: {
|
|
55
|
+
importPath: string;
|
|
56
|
+
}): string;
|
|
57
|
+
declare function generateTreatyModule(options: {
|
|
58
|
+
inputFile: string;
|
|
59
|
+
importPath: string;
|
|
60
|
+
}): Promise<string>;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { type GenerateOptions, type HeaderFn, type LeafCall, type OpenAPISpec, type OperationDefinition, type OperationErrors, type PathFn, type RouteNode, type SecurityRequirement, type TreatyClient, type TreatyResult, type TreatyRoutesConstraint, type TypesConfig, createTreatyClient, generate, generateTreatyModule, generateTreatyModuleFromMetadata };
|
|
63
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
+
import { i as OperationErrors, o as RequestMethod, r as OperationDefinition, s as SecurityRequirement, t as AnyHeaderFn } from "./types-ByqlZjPK.mjs";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
type PathFn<TArgs extends unknown[] = []> = (...args: TArgs) => string;
|
|
5
|
-
type RequestMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
|
|
6
|
-
type HeaderFn<TArgs extends unknown[] = [], TResult = Record<string, unknown> | Record<string, never>> = (...args: TArgs) => TResult;
|
|
7
|
-
type AnyHeaderFn = HeaderFn<any, unknown> | (() => unknown);
|
|
8
|
-
type OperationErrors<TError = unknown> = TError extends Record<string, unknown> ? TError : Record<string, TError>;
|
|
9
|
-
type SecurityRequirement = Readonly<Record<string, readonly string[]>>;
|
|
10
|
-
type OperationDefinition<TMethod extends RequestMethod, TPath extends (...args: any[]) => string, TRequest = undefined, TResponse = undefined, THeaders extends AnyHeaderFn | undefined = undefined, TErrors extends OperationErrors | undefined = undefined, TSecurity extends readonly SecurityRequirement[] | undefined = undefined> = {
|
|
11
|
-
method: TMethod;
|
|
12
|
-
path: TPath;
|
|
13
|
-
request?: TRequest;
|
|
14
|
-
response?: TResponse;
|
|
15
|
-
headers?: THeaders;
|
|
16
|
-
errors?: TErrors;
|
|
17
|
-
security?: TSecurity;
|
|
18
|
-
};
|
|
19
|
-
//#endregion
|
|
20
4
|
//#region src/treaty-types.d.ts
|
|
21
5
|
/** Nested route tree: segments, `:param` keys, and HTTP method leaves (see `isLeaf` in treaty runtime). */
|
|
22
6
|
type RouteNode = Record<string, unknown>;
|
|
@@ -80,5 +64,5 @@ declare function createTreatyClient<const R extends TreatyRoutesConstraint>(conf
|
|
|
80
64
|
fetch?: typeof fetch;
|
|
81
65
|
}): TreatyClient<R>;
|
|
82
66
|
//#endregion
|
|
83
|
-
export { RouteNode as a, TreatySuccess as c,
|
|
84
|
-
//# sourceMappingURL=treaty-
|
|
67
|
+
export { RouteNode as a, TreatySuccess as c, TreatyRoutesConstraint as i, LeafCall as n, TreatyFailure as o, TreatyClient as r, TreatyResult as s, createTreatyClient as t };
|
|
68
|
+
//# sourceMappingURL=treaty-DM77ZhDU.d.mts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { i as OperationErrors, o as RequestMethod, r as OperationDefinition, s as SecurityRequirement, t as AnyHeaderFn } from "./types-BM-Q_QIk.cjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/treaty-types.d.ts
|
|
5
|
+
/** Nested route tree: segments, `:param` keys, and HTTP method leaves (see `isLeaf` in treaty runtime). */
|
|
6
|
+
type RouteNode = Record<string, unknown>;
|
|
7
|
+
type TreatySuccess<T> = {
|
|
8
|
+
data: T;
|
|
9
|
+
error: null;
|
|
10
|
+
response: Response;
|
|
11
|
+
status: number;
|
|
12
|
+
headers: Headers;
|
|
13
|
+
};
|
|
14
|
+
type TreatyFailure = {
|
|
15
|
+
data: null;
|
|
16
|
+
error: {
|
|
17
|
+
status: number;
|
|
18
|
+
body: unknown;
|
|
19
|
+
};
|
|
20
|
+
response: Response;
|
|
21
|
+
status: number;
|
|
22
|
+
headers: Headers;
|
|
23
|
+
};
|
|
24
|
+
type TreatyResult<T> = TreatySuccess<T> | TreatyFailure;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/treaty-infer.d.ts
|
|
27
|
+
type AnyOperationDefinition = OperationDefinition<RequestMethod, (...args: any[]) => string, unknown, unknown, AnyHeaderFn | undefined, OperationErrors | undefined, readonly SecurityRequirement[] | undefined>;
|
|
28
|
+
type TreatyMethodOptions = RequestInit & {
|
|
29
|
+
query?: Record<string, unknown>;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
};
|
|
32
|
+
type InferZodOutput<Schema> = Schema extends z.ZodType ? z.infer<Schema> : unknown;
|
|
33
|
+
type InferZodInput<Schema> = Schema extends z.ZodType ? z.input<Schema> : unknown;
|
|
34
|
+
type SuccessData<Op extends AnyOperationDefinition> = NonNullable<Op["response"]> extends z.ZodType ? InferZodOutput<NonNullable<Op["response"]>> : unknown;
|
|
35
|
+
/**
|
|
36
|
+
* Structural check: `Op["method"] extends "get" | "head"` is wrong when `method` is
|
|
37
|
+
* typed as `RequestMethod` (union) — it would match the GET branch incorrectly.
|
|
38
|
+
*/
|
|
39
|
+
type LeafCall<Op extends AnyOperationDefinition> = Op extends {
|
|
40
|
+
method: "get" | "head";
|
|
41
|
+
} ? (opts?: {
|
|
42
|
+
query?: Record<string, unknown>;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
}) => Promise<TreatyResult<SuccessData<Op>>> : Op extends {
|
|
45
|
+
request: infer Req;
|
|
46
|
+
} ? Req extends z.ZodType ? (body: InferZodInput<Req>, init?: TreatyMethodOptions) => Promise<TreatyResult<SuccessData<Op>>> : (body?: unknown, init?: TreatyMethodOptions) => Promise<TreatyResult<SuccessData<Op>>> : (body?: unknown, init?: TreatyMethodOptions) => Promise<TreatyResult<SuccessData<Op>>>;
|
|
47
|
+
type LeafMethods<R> = { [K in keyof R as K extends symbol ? never : R[K] extends AnyOperationDefinition ? K : never]: R[K] extends AnyOperationDefinition ? LeafCall<R[K]> : never };
|
|
48
|
+
type DynamicParamKey<R> = Extract<keyof R, `:${string}`>;
|
|
49
|
+
type ParamRecord<K extends `:${string}`> = K extends `:${infer Name}` ? { [P in Name]: string | number } : never;
|
|
50
|
+
type DynamicBranch<R> = [DynamicParamKey<R>] extends [never] ? unknown : DynamicParamKey<R> extends infer K extends `:${string}` ? K extends keyof R ? (params: ParamRecord<K>) => TreatyClient<R[K]> : never : unknown;
|
|
51
|
+
type StaticSegmentChildren<R> = { [K in keyof R as K extends symbol ? never : K extends `:${string}` ? never : R[K] extends AnyOperationDefinition ? never : R[K] extends Record<string, unknown> ? K : never]: R[K] extends Record<string, unknown> ? TreatyClient<R[K]> : never };
|
|
52
|
+
/**
|
|
53
|
+
* Inferred Eden-style client for a nested `treatyRoutes` object whose leaves are
|
|
54
|
+
* {@link OperationDefinition} values (Zod-typed `request` / `response`).
|
|
55
|
+
*/
|
|
56
|
+
type TreatyClient<R> = LeafMethods<R> & StaticSegmentChildren<R> & DynamicBranch<R>;
|
|
57
|
+
/** Permissive input constraint for `createTreatyClient` — inference comes from `routes`. */
|
|
58
|
+
type TreatyRoutesConstraint = Record<string, unknown>;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/treaty.d.ts
|
|
61
|
+
declare function createTreatyClient<const R extends TreatyRoutesConstraint>(config: {
|
|
62
|
+
baseUrl: string;
|
|
63
|
+
routes: R;
|
|
64
|
+
fetch?: typeof fetch;
|
|
65
|
+
}): TreatyClient<R>;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { RouteNode as a, TreatySuccess as c, TreatyRoutesConstraint as i, LeafCall as n, TreatyFailure as o, TreatyClient as r, TreatyResult as s, createTreatyClient as t };
|
|
68
|
+
//# sourceMappingURL=treaty-NM6Hf8S8.d.cts.map
|
package/dist/treaty.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RouteNode, c as TreatySuccess, i as TreatyRoutesConstraint, n as LeafCall, o as TreatyFailure, r as TreatyClient, s as TreatyResult, t as createTreatyClient } from "./treaty-
|
|
1
|
+
import { a as RouteNode, c as TreatySuccess, i as TreatyRoutesConstraint, n as LeafCall, o as TreatyFailure, r as TreatyClient, s as TreatyResult, t as createTreatyClient } from "./treaty-NM6Hf8S8.cjs";
|
|
2
2
|
export { LeafCall, RouteNode, TreatyClient, TreatyFailure, TreatyResult, TreatyRoutesConstraint, TreatySuccess, createTreatyClient };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as RouteNode, c as TreatySuccess, i as TreatyRoutesConstraint, n as LeafCall, o as TreatyFailure, r as TreatyClient, s as TreatyResult, t as createTreatyClient } from "./treaty-DM77ZhDU.mjs";
|
|
2
|
+
export { LeafCall, RouteNode, TreatyClient, TreatyFailure, TreatyResult, TreatyRoutesConstraint, TreatySuccess, createTreatyClient };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type PathFn<TArgs extends unknown[] = []> = (...args: TArgs) => string;
|
|
3
|
+
type RequestMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
|
|
4
|
+
type HeaderFn<TArgs extends unknown[] = [], TResult = Record<string, unknown> | Record<string, never>> = (...args: TArgs) => TResult;
|
|
5
|
+
type AnyHeaderFn = HeaderFn<any, unknown> | (() => unknown);
|
|
6
|
+
type OperationErrors<TError = unknown> = TError extends Record<string, unknown> ? TError : Record<string, TError>;
|
|
7
|
+
type SecurityRequirement = Readonly<Record<string, readonly string[]>>;
|
|
8
|
+
type OperationDefinition<TMethod extends RequestMethod, TPath extends (...args: any[]) => string, TRequest = undefined, TResponse = undefined, THeaders extends AnyHeaderFn | undefined = undefined, TErrors extends OperationErrors | undefined = undefined, TSecurity extends readonly SecurityRequirement[] | undefined = undefined> = {
|
|
9
|
+
method: TMethod;
|
|
10
|
+
path: TPath;
|
|
11
|
+
request?: TRequest;
|
|
12
|
+
response?: TResponse;
|
|
13
|
+
headers?: THeaders;
|
|
14
|
+
errors?: TErrors;
|
|
15
|
+
security?: TSecurity;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PathFn as a, OperationErrors as i, HeaderFn as n, RequestMethod as o, OperationDefinition as r, SecurityRequirement as s, AnyHeaderFn as t };
|
|
19
|
+
//# sourceMappingURL=types-BM-Q_QIk.d.cts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type PathFn<TArgs extends unknown[] = []> = (...args: TArgs) => string;
|
|
3
|
+
type RequestMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
|
|
4
|
+
type HeaderFn<TArgs extends unknown[] = [], TResult = Record<string, unknown> | Record<string, never>> = (...args: TArgs) => TResult;
|
|
5
|
+
type AnyHeaderFn = HeaderFn<any, unknown> | (() => unknown);
|
|
6
|
+
type OperationErrors<TError = unknown> = TError extends Record<string, unknown> ? TError : Record<string, TError>;
|
|
7
|
+
type SecurityRequirement = Readonly<Record<string, readonly string[]>>;
|
|
8
|
+
type OperationDefinition<TMethod extends RequestMethod, TPath extends (...args: any[]) => string, TRequest = undefined, TResponse = undefined, THeaders extends AnyHeaderFn | undefined = undefined, TErrors extends OperationErrors | undefined = undefined, TSecurity extends readonly SecurityRequirement[] | undefined = undefined> = {
|
|
9
|
+
method: TMethod;
|
|
10
|
+
path: TPath;
|
|
11
|
+
request?: TRequest;
|
|
12
|
+
response?: TResponse;
|
|
13
|
+
headers?: THeaders;
|
|
14
|
+
errors?: TErrors;
|
|
15
|
+
security?: TSecurity;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PathFn as a, OperationErrors as i, HeaderFn as n, RequestMethod as o, OperationDefinition as r, SecurityRequirement as s, AnyHeaderFn as t };
|
|
19
|
+
//# sourceMappingURL=types-ByqlZjPK.d.mts.map
|
package/dist/types.cjs
ADDED
|
File without changes
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PathFn, i as OperationErrors, n as HeaderFn, o as RequestMethod, r as OperationDefinition, s as SecurityRequirement, t as AnyHeaderFn } from "./types-BM-Q_QIk.cjs";
|
|
2
|
+
export { AnyHeaderFn, HeaderFn, OperationDefinition, OperationErrors, PathFn, RequestMethod, SecurityRequirement };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PathFn, i as OperationErrors, n as HeaderFn, o as RequestMethod, r as OperationDefinition, s as SecurityRequirement, t as AnyHeaderFn } from "./types-ByqlZjPK.mjs";
|
|
2
|
+
export { AnyHeaderFn, HeaderFn, OperationDefinition, OperationErrors, PathFn, RequestMethod, SecurityRequirement };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenko",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.2",
|
|
4
4
|
"description": "Generate TypeScript types and path functions from OpenAPI specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -29,28 +29,38 @@
|
|
|
29
29
|
"README.md",
|
|
30
30
|
"dist/**/*.cjs",
|
|
31
31
|
"dist/**/*.d.cts",
|
|
32
|
+
"dist/**/*.d.mts",
|
|
32
33
|
"dist/**/*.d.ts",
|
|
33
34
|
"dist/**/*.mjs"
|
|
34
35
|
],
|
|
35
36
|
"type": "module",
|
|
36
37
|
"main": "dist/index.cjs",
|
|
37
38
|
"module": "dist/index.mjs",
|
|
38
|
-
"types": "dist/index.d.
|
|
39
|
+
"types": "./dist/index.d.mts",
|
|
39
40
|
"exports": {
|
|
40
41
|
".": {
|
|
41
|
-
"types":
|
|
42
|
+
"types": {
|
|
43
|
+
"import": "./dist/index.d.mts",
|
|
44
|
+
"require": "./dist/index.d.cts"
|
|
45
|
+
},
|
|
42
46
|
"bun": "./dist/index.mjs",
|
|
43
47
|
"import": "./dist/index.mjs",
|
|
44
48
|
"require": "./dist/index.cjs"
|
|
45
49
|
},
|
|
46
50
|
"./types": {
|
|
47
|
-
"types":
|
|
51
|
+
"types": {
|
|
52
|
+
"import": "./dist/types.d.mts",
|
|
53
|
+
"require": "./dist/types.d.cts"
|
|
54
|
+
},
|
|
48
55
|
"bun": "./dist/types.mjs",
|
|
49
56
|
"import": "./dist/types.mjs",
|
|
50
57
|
"require": "./dist/types.cjs"
|
|
51
58
|
},
|
|
52
59
|
"./treaty": {
|
|
53
|
-
"types":
|
|
60
|
+
"types": {
|
|
61
|
+
"import": "./dist/treaty.d.mts",
|
|
62
|
+
"require": "./dist/treaty.d.cts"
|
|
63
|
+
},
|
|
54
64
|
"bun": "./dist/treaty.mjs",
|
|
55
65
|
"import": "./dist/treaty.mjs",
|
|
56
66
|
"require": "./dist/treaty.cjs"
|