hono-takibi 0.26.0 → 0.28.0
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.js +12 -15
- package/dist/core/docs/index.d.ts +2 -4
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +3 -5
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +4 -6
- package/dist/core/rpc/index.js +6 -7
- package/dist/core/type/index.d.ts +3 -5
- package/dist/core/type/index.js +4 -5
- package/dist/{core-FnayWJZV.js → core-D141ZWzp.js} +61 -77
- package/dist/{docs-D8ivFJrR.js → docs-CDFG1tXT.js} +20 -16
- package/dist/{emit-uwlZZeRM.js → emit-CqkT9T4Q.js} +3 -4
- package/dist/{file-K6j5IJXi.js → file-Bip_L0oR.js} +1 -2
- package/dist/{format-CuHABcKC.js → format-BF7SbaMP.js} +3 -5
- package/dist/generator/zod-openapi-hono/openapi/index.d.ts +2 -4
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/guard-BH6yBr0M.js +332 -0
- package/dist/{hooks-DJHtFXnM.js → hooks-CKIK30qr.js} +9 -10
- package/dist/{index-D3apEdjU.d.ts → index-8HyUtaew.d.ts} +2 -4
- package/dist/{index-BNrSddFB.d.ts → index-DqcEtGVl.d.ts} +4 -15
- package/dist/{index-B3ze4n_I.d.ts → index-DvZscmYm.d.ts} +0 -2
- package/dist/{index-D_gf3Xzx.d.ts → index-sZ1C8djg.d.ts} +0 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -5
- package/dist/{openapi-CU23GKuM.js → openapi-imhqgahL.js} +132 -88
- package/dist/{openapi-t_u-tF52.js → openapi-tYYvoKiU.js} +2 -3
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/{rpc-CSZ3hBkn.js → rpc-GDi7a_Ep.js} +3 -6
- package/dist/{shared-BvbKZMJK.js → shared-CyBkG8gM.js} +12 -10
- package/dist/{utils-Bw0Q2Ozg.js → utils-CDLiYepO.js} +50 -254
- package/dist/vite-plugin/index.d.ts +1 -3
- package/dist/vite-plugin/index.js +6 -8
- package/package.json +5 -5
- package/dist/constants-hwmOoQfI.js +0 -103
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as fmt } from "./format-
|
|
2
|
-
import { n as mkdir, o as writeFile } from "./file-
|
|
1
|
+
import { n as fmt } from "./format-BF7SbaMP.js";
|
|
2
|
+
import { n as mkdir, o as writeFile } from "./file-Bip_L0oR.js";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
|
-
|
|
4
|
+
// src/emit/index.ts
|
|
5
5
|
/** Formats generated source and writes it to `output`, creating `dir` on the way. */
|
|
6
6
|
function emit(code, dir, output) {
|
|
7
7
|
return Effect.gen(function* () {
|
|
@@ -9,5 +9,4 @@ function emit(code, dir, output) {
|
|
|
9
9
|
yield* writeFile(output, formatted);
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
//#endregion
|
|
13
12
|
export { emit as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, FileSystem } from "effect";
|
|
2
|
-
|
|
2
|
+
// src/file/index.ts
|
|
3
3
|
function unlink(path) {
|
|
4
4
|
return Effect.gen(function* () {
|
|
5
5
|
yield* (yield* FileSystem.FileSystem).remove(path, { force: true });
|
|
@@ -32,5 +32,4 @@ function writeFile(path, data) {
|
|
|
32
32
|
yield* fs.writeFileString(path, data);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
//#endregion
|
|
36
35
|
export { unlink as a, readdir as i, mkdir as n, writeFile as o, readFile as r, exists as t };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
2
|
import { Context, Data, Effect } from "effect";
|
|
3
3
|
import { format } from "oxfmt";
|
|
4
|
-
|
|
4
|
+
// src/error/index.ts
|
|
5
5
|
var GenerateError = class extends Data.TaggedError("GenerateError") {};
|
|
6
6
|
var FormatError = class extends Data.TaggedError("FormatError") {};
|
|
7
|
-
|
|
8
|
-
//#region src/format/index.ts
|
|
7
|
+
// src/format/index.ts
|
|
9
8
|
var format_exports = /* @__PURE__ */ __exportAll({
|
|
10
9
|
FormatOptions: () => FormatOptions,
|
|
11
10
|
fmt: () => fmt
|
|
@@ -30,5 +29,4 @@ function fmt(input) {
|
|
|
30
29
|
return code;
|
|
31
30
|
});
|
|
32
31
|
}
|
|
33
|
-
//#endregion
|
|
34
32
|
export { GenerateError as i, fmt as n, format_exports as r, FormatOptions as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../../index-
|
|
2
|
-
//#region src/generator/zod-openapi-hono/openapi/index.d.ts
|
|
1
|
+
import { t as OpenAPI } from "../../../index-DvZscmYm.js";
|
|
3
2
|
export declare function zodOpenAPIHono(document: OpenAPI, options?: {
|
|
4
3
|
readonly readonly?: boolean;
|
|
5
4
|
readonly exportSchemas?: boolean;
|
|
@@ -17,5 +16,4 @@ export declare function zodOpenAPIHono(document: OpenAPI, options?: {
|
|
|
17
16
|
readonly exportPathItems?: boolean;
|
|
18
17
|
readonly exportMediaTypes?: boolean;
|
|
19
18
|
readonly exportMediaTypesTypes?: boolean;
|
|
20
|
-
}): string;
|
|
21
|
-
//#endregion
|
|
19
|
+
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as zodOpenAPIHono } from "../../../openapi-
|
|
1
|
+
export { t as zodOpenAPIHono } from "../../../openapi-imhqgahL.js";
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// src/constants/index.ts
|
|
2
|
+
/** The kinds of the OpenAPI Components Object, in declaration and config-field order. */
|
|
3
|
+
const COMPONENT_NAMES = [
|
|
4
|
+
"schemas",
|
|
5
|
+
"responses",
|
|
6
|
+
"parameters",
|
|
7
|
+
"examples",
|
|
8
|
+
"requestBodies",
|
|
9
|
+
"headers",
|
|
10
|
+
"securitySchemes",
|
|
11
|
+
"links",
|
|
12
|
+
"callbacks",
|
|
13
|
+
"pathItems",
|
|
14
|
+
"mediaTypes"
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* What the identifier of a component is suffixed with, by section: `#/components/schemas/User`
|
|
18
|
+
* is `UserSchema`. A security scheme is named by `security` requirements, not by `$ref`.
|
|
19
|
+
*/
|
|
20
|
+
const COMPONENT_SUFFIXES = {
|
|
21
|
+
schemas: "Schema",
|
|
22
|
+
parameters: "ParamsSchema",
|
|
23
|
+
headers: "HeaderSchema",
|
|
24
|
+
securitySchemes: "SecurityScheme",
|
|
25
|
+
requestBodies: "RequestBody",
|
|
26
|
+
responses: "Response",
|
|
27
|
+
examples: "Example",
|
|
28
|
+
links: "Link",
|
|
29
|
+
callbacks: "Callback",
|
|
30
|
+
pathItems: "PathItem",
|
|
31
|
+
mediaTypes: "MediaTypeSchema"
|
|
32
|
+
};
|
|
33
|
+
/** The extensions of an input document: OpenAPI as YAML (`.yaml` or `.yml`) or JSON, or a TypeSpec entry. */
|
|
34
|
+
const INPUT_EXTENSIONS = [
|
|
35
|
+
".yaml",
|
|
36
|
+
".yml",
|
|
37
|
+
".json",
|
|
38
|
+
".tsp"
|
|
39
|
+
];
|
|
40
|
+
/** A JavaScript identifier that can be written bare: as a binding, or a key or member access. */
|
|
41
|
+
const IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
42
|
+
/**
|
|
43
|
+
* A message option written as an arrow function, `(issue) => ...`, rather than as text.
|
|
44
|
+
* Such a message is spliced into the generated code as an expression instead of a string.
|
|
45
|
+
*/
|
|
46
|
+
const ARROW_FUNCTION_PATTERN = /^\s*\(.*?\)\s*=>/u;
|
|
47
|
+
/** The media type of a JSON body, the default of a request or response body. */
|
|
48
|
+
const JSON_MEDIA_TYPE = "application/json";
|
|
49
|
+
/** The media type of a plain-text body. */
|
|
50
|
+
const TEXT_MEDIA_TYPE = "text/plain";
|
|
51
|
+
/** The media type of a URL-encoded form body. */
|
|
52
|
+
const FORM_URLENCODED_MEDIA_TYPE = "application/x-www-form-urlencoded";
|
|
53
|
+
/** The media type of a multipart form body. */
|
|
54
|
+
const MULTIPART_MEDIA_TYPE = "multipart/form-data";
|
|
55
|
+
/** The media type of an opaque binary body. */
|
|
56
|
+
const OCTET_STREAM_MEDIA_TYPE = "application/octet-stream";
|
|
57
|
+
/** The media types of a form body: every field arrives as text, or as a file. */
|
|
58
|
+
const FORM_MEDIA_TYPES = ["application/x-www-form-urlencoded", "multipart/form-data"];
|
|
59
|
+
/** The `$ref` prefix of each kind of component: `#/components/schemas/` for `schemas`. */
|
|
60
|
+
const COMPONENT_REF_PREFIX = {
|
|
61
|
+
schemas: "#/components/schemas/",
|
|
62
|
+
responses: "#/components/responses/",
|
|
63
|
+
parameters: "#/components/parameters/",
|
|
64
|
+
examples: "#/components/examples/",
|
|
65
|
+
requestBodies: "#/components/requestBodies/",
|
|
66
|
+
headers: "#/components/headers/",
|
|
67
|
+
securitySchemes: "#/components/securitySchemes/",
|
|
68
|
+
links: "#/components/links/",
|
|
69
|
+
callbacks: "#/components/callbacks/",
|
|
70
|
+
pathItems: "#/components/pathItems/",
|
|
71
|
+
mediaTypes: "#/components/mediaTypes/"
|
|
72
|
+
};
|
|
73
|
+
/** The query libraries the hooks are generated for, each a config key of its own. */
|
|
74
|
+
const HOOK_LIBRARIES = [
|
|
75
|
+
"swr",
|
|
76
|
+
"tanstack-query",
|
|
77
|
+
"preact-query",
|
|
78
|
+
"solid-query",
|
|
79
|
+
"vue-query",
|
|
80
|
+
"svelte-query",
|
|
81
|
+
"angular-query"
|
|
82
|
+
];
|
|
83
|
+
/**
|
|
84
|
+
* The HTTP methods an OpenAPI path item can hold, in the order the specification lists
|
|
85
|
+
* them: OpenAPI 3.2 adds `query`. Operations of one path are generated in this order.
|
|
86
|
+
*/
|
|
87
|
+
const HTTP_METHODS = [
|
|
88
|
+
"get",
|
|
89
|
+
"put",
|
|
90
|
+
"post",
|
|
91
|
+
"delete",
|
|
92
|
+
"options",
|
|
93
|
+
"head",
|
|
94
|
+
"patch",
|
|
95
|
+
"trace",
|
|
96
|
+
"query"
|
|
97
|
+
];
|
|
98
|
+
// src/guard/index.ts
|
|
99
|
+
function isRecord(v) {
|
|
100
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
101
|
+
}
|
|
102
|
+
function isHttpMethod(method) {
|
|
103
|
+
return HTTP_METHODS.some((candidate) => candidate === method);
|
|
104
|
+
}
|
|
105
|
+
function isValidIdent(str) {
|
|
106
|
+
return IDENTIFIER_PATTERN.test(str);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* An input document: a path by its extension, or an `http(s)` URL whatever its path (a
|
|
110
|
+
* document served without an extension is OpenAPI by content).
|
|
111
|
+
*/
|
|
112
|
+
function isInputPath(v) {
|
|
113
|
+
return typeof v === "string" && (INPUT_EXTENSIONS.some((extension) => v.endsWith(extension)) || /^https?:\/\//u.test(v));
|
|
114
|
+
}
|
|
115
|
+
function isOpenAPIPaths(v) {
|
|
116
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
117
|
+
return Object.values(v).every((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry));
|
|
118
|
+
}
|
|
119
|
+
function isRefObject(v) {
|
|
120
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "$ref" in v && typeof v.$ref === "string";
|
|
121
|
+
}
|
|
122
|
+
function isStringRef(v) {
|
|
123
|
+
return "$ref" in v && typeof v.$ref === "string";
|
|
124
|
+
}
|
|
125
|
+
function isRefOnly(s) {
|
|
126
|
+
return s.$ref !== void 0 && Object.keys(s).length === 1;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* OpenAPI 3.2 §4.25: `discriminator` "MUST NOT change the validation outcome of the
|
|
130
|
+
* schema". A branch can therefore be routed by key only when the key alone already
|
|
131
|
+
* decides it: a bare object head that requires the discriminating property and pins it
|
|
132
|
+
* to string literals. Zod reads that key off `_zod.propValues`, which only a plain
|
|
133
|
+
* `z.object(...)` carries — an intersection, a union, a record, `.nullable()` and
|
|
134
|
+
* `.default()` all report nothing — so every other shape fails closed.
|
|
135
|
+
*/
|
|
136
|
+
function isDiscriminableBranch(branch, discriminator) {
|
|
137
|
+
if (branch.allOf || branch.anyOf || branch.oneOf || branch.not) return false;
|
|
138
|
+
if (branch.type !== "object" || typeof branch.additionalProperties === "object") return false;
|
|
139
|
+
if (branch.nullable === true || branch.default !== void 0) return false;
|
|
140
|
+
if (!(Array.isArray(branch.required) && branch.required.includes(discriminator))) return false;
|
|
141
|
+
const property = branch.properties?.[discriminator];
|
|
142
|
+
if (property === void 0 || typeof property === "boolean") return false;
|
|
143
|
+
if (typeof property.const === "string") return true;
|
|
144
|
+
return Array.isArray(property.enum) && property.enum.length > 0 && property.enum.every((v) => typeof v === "string");
|
|
145
|
+
}
|
|
146
|
+
function isParameterRef(ref) {
|
|
147
|
+
return ref.startsWith(COMPONENT_REF_PREFIX.parameters);
|
|
148
|
+
}
|
|
149
|
+
function isPathItemRef(ref) {
|
|
150
|
+
return ref.startsWith(COMPONENT_REF_PREFIX.pathItems);
|
|
151
|
+
}
|
|
152
|
+
function isParameterObject(v) {
|
|
153
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
154
|
+
if (!("name" in v) || typeof v.name !== "string") return false;
|
|
155
|
+
if (!("in" in v)) return false;
|
|
156
|
+
const pos = v.in;
|
|
157
|
+
return pos === "path" || pos === "query" || pos === "header" || pos === "cookie";
|
|
158
|
+
}
|
|
159
|
+
function isParameter(v) {
|
|
160
|
+
return typeof v === "object" && v !== null && "name" in v && "in" in v && ("schema" in v || "content" in v);
|
|
161
|
+
}
|
|
162
|
+
function isParameterArray(v) {
|
|
163
|
+
return Array.isArray(v);
|
|
164
|
+
}
|
|
165
|
+
function isOperationLike(v) {
|
|
166
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "responses" in v;
|
|
167
|
+
}
|
|
168
|
+
function isOperation(v) {
|
|
169
|
+
return typeof v === "object" && v !== null && "responses" in v;
|
|
170
|
+
}
|
|
171
|
+
function isSchemaProperty(v) {
|
|
172
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "schema" in v;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* JSON Schema 2020-12 §10.3.1.2: `items` may be a single schema, a tuple of
|
|
176
|
+
* schemas, or a boolean schema. Narrows the union to the single-schema form.
|
|
177
|
+
*/
|
|
178
|
+
function isSingleSchema(items) {
|
|
179
|
+
return typeof items === "object" && !Array.isArray(items);
|
|
180
|
+
}
|
|
181
|
+
function isSchemaArray(v) {
|
|
182
|
+
return Array.isArray(v);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* JSON Schema 2020-12 §4.3.2 / §10.3.1.2 type guard for schema-vs-boolean
|
|
186
|
+
* discrimination. `items`, `additionalProperties`, `unevaluatedItems`, and
|
|
187
|
+
* `unevaluatedProperties` may be either an object schema or a boolean schema
|
|
188
|
+
* (`true` = pass-through, `false` = reject). This narrows the union to the
|
|
189
|
+
* object form so callers can recurse without `as` casts.
|
|
190
|
+
*/
|
|
191
|
+
function isSchemaObject(v) {
|
|
192
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
193
|
+
}
|
|
194
|
+
function isMediaWithSchema(v) {
|
|
195
|
+
return typeof v === "object" && v !== null && "schema" in v;
|
|
196
|
+
}
|
|
197
|
+
function isMedia(v) {
|
|
198
|
+
return isRecord(v) && "schema" in v;
|
|
199
|
+
}
|
|
200
|
+
function isCallbacks(v) {
|
|
201
|
+
return typeof v === "object" && v !== null && !("$ref" in v);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Narrows a `paths` entry to a Path Item Object. Unlike `isPathItem` this keeps
|
|
205
|
+
* `$ref` path items (OpenAPI 3.2 §4.8.9 allows `$ref` on a Path Item Object);
|
|
206
|
+
* callers resolve them against `components.pathItems`.
|
|
207
|
+
*/
|
|
208
|
+
function isPathItemEntry(v) {
|
|
209
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
210
|
+
}
|
|
211
|
+
function isPathItem(v) {
|
|
212
|
+
return typeof v === "object" && v !== null && !("$ref" in v);
|
|
213
|
+
}
|
|
214
|
+
function isHeader(v) {
|
|
215
|
+
return typeof v === "object" && v !== null && !("$ref" in v);
|
|
216
|
+
}
|
|
217
|
+
function isRequestBody(v) {
|
|
218
|
+
return typeof v === "object" && v !== null && ("content" in v || "required" in v || "description" in v);
|
|
219
|
+
}
|
|
220
|
+
function isSecurityScheme(v) {
|
|
221
|
+
return typeof v === "object" && v !== null && !("$ref" in v);
|
|
222
|
+
}
|
|
223
|
+
function isSecurityArray(v) {
|
|
224
|
+
return Array.isArray(v);
|
|
225
|
+
}
|
|
226
|
+
function isResponses(v) {
|
|
227
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
228
|
+
return "$ref" in v || "description" in v || "content" in v || "headers" in v || "links" in v;
|
|
229
|
+
}
|
|
230
|
+
const TYPELESS_KEYWORDS = [
|
|
231
|
+
"required",
|
|
232
|
+
"properties",
|
|
233
|
+
"additionalProperties",
|
|
234
|
+
"patternProperties",
|
|
235
|
+
"propertyNames",
|
|
236
|
+
"minProperties",
|
|
237
|
+
"maxProperties",
|
|
238
|
+
"dependentRequired",
|
|
239
|
+
"dependentSchemas",
|
|
240
|
+
"unevaluatedProperties",
|
|
241
|
+
"minItems",
|
|
242
|
+
"maxItems",
|
|
243
|
+
"uniqueItems",
|
|
244
|
+
"items",
|
|
245
|
+
"prefixItems",
|
|
246
|
+
"contains",
|
|
247
|
+
"minContains",
|
|
248
|
+
"maxContains",
|
|
249
|
+
"unevaluatedItems",
|
|
250
|
+
"minLength",
|
|
251
|
+
"maxLength",
|
|
252
|
+
"pattern",
|
|
253
|
+
"minimum",
|
|
254
|
+
"maximum",
|
|
255
|
+
"exclusiveMinimum",
|
|
256
|
+
"exclusiveMaximum",
|
|
257
|
+
"multipleOf",
|
|
258
|
+
"enum",
|
|
259
|
+
"const",
|
|
260
|
+
"allOf",
|
|
261
|
+
"anyOf",
|
|
262
|
+
"oneOf",
|
|
263
|
+
"not",
|
|
264
|
+
"if",
|
|
265
|
+
"then",
|
|
266
|
+
"else"
|
|
267
|
+
];
|
|
268
|
+
function hasTypelessConstraint(schema) {
|
|
269
|
+
return TYPELESS_KEYWORDS.some((k) => schema[k] !== void 0);
|
|
270
|
+
}
|
|
271
|
+
const OBJECT_KEYWORDS = /* @__PURE__ */ new Set([
|
|
272
|
+
"required",
|
|
273
|
+
"properties",
|
|
274
|
+
"additionalProperties",
|
|
275
|
+
"patternProperties",
|
|
276
|
+
"propertyNames",
|
|
277
|
+
"minProperties",
|
|
278
|
+
"maxProperties",
|
|
279
|
+
"dependentRequired",
|
|
280
|
+
"dependentSchemas",
|
|
281
|
+
"unevaluatedProperties"
|
|
282
|
+
]);
|
|
283
|
+
/**
|
|
284
|
+
* Whether a schema with no `type` is an object in all but name: it declares `properties`
|
|
285
|
+
* or `additionalProperties`, and no keyword of another kind (`minLength`, `items`). Such
|
|
286
|
+
* a schema is emitted as `z.object()` rather than checked by hand on `z.unknown()`, which
|
|
287
|
+
* is what the type writer already takes it for (#385).
|
|
288
|
+
*/
|
|
289
|
+
function isUntypedObject(schema) {
|
|
290
|
+
return schema.type === void 0 && (schema.properties !== void 0 || schema.additionalProperties !== void 0) && TYPELESS_KEYWORDS.every((k) => schema[k] === void 0 || OBJECT_KEYWORDS.has(k));
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Whether a `time` takes an offset. `time` is an RFC 3339 full-time, `12:34:56Z` or
|
|
294
|
+
* `12:34:56+09:00`, and `z.iso.time()` takes neither. `x-isoOffset: false` asks for that.
|
|
295
|
+
*/
|
|
296
|
+
function isOffsetTime(schema) {
|
|
297
|
+
return schema.format === "time" && schema["x-isoOffset"] !== false;
|
|
298
|
+
}
|
|
299
|
+
function hasNumericConstraint(schema) {
|
|
300
|
+
return schema.minimum !== void 0 || schema.maximum !== void 0 || schema.exclusiveMinimum !== void 0 || schema.exclusiveMaximum !== void 0 || schema.multipleOf !== void 0;
|
|
301
|
+
}
|
|
302
|
+
function hasNotProperty(v) {
|
|
303
|
+
return typeof v === "object" && v !== null && "not" in v;
|
|
304
|
+
}
|
|
305
|
+
function isExamplesInput(v) {
|
|
306
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && Object.values(v).every((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry));
|
|
307
|
+
}
|
|
308
|
+
function hasNoUserChain(schema) {
|
|
309
|
+
return schema["x-preprocess"] === void 0 && schema["x-transform"] === void 0 && schema["x-pipe"] === void 0 && schema["x-codec"] === void 0;
|
|
310
|
+
}
|
|
311
|
+
function hasRequestBodyContent(operation) {
|
|
312
|
+
if (typeof operation !== "object" || operation === null) return false;
|
|
313
|
+
if (!("requestBody" in operation)) return false;
|
|
314
|
+
if (typeof operation.requestBody !== "object" || operation.requestBody === null) return false;
|
|
315
|
+
return "content" in operation.requestBody;
|
|
316
|
+
}
|
|
317
|
+
function isInlineMedia(media) {
|
|
318
|
+
return !("$ref" in media);
|
|
319
|
+
}
|
|
320
|
+
function hasNoContentResponse(operation) {
|
|
321
|
+
const responses = operation.responses;
|
|
322
|
+
if (!isRecord(responses)) return false;
|
|
323
|
+
return Object.keys(responses).some((status) => {
|
|
324
|
+
const code = Number.parseInt(status, 10);
|
|
325
|
+
return !Number.isNaN(code) && [204, 205].includes(code);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/** Whether a parameter is named like something every object inherits. */
|
|
329
|
+
function isInheritedName(parameter) {
|
|
330
|
+
return parameter.in !== "path" && parameter.name in Object.prototype;
|
|
331
|
+
}
|
|
332
|
+
export { MULTIPART_MEDIA_TYPE as $, isRefOnly as A, isUntypedObject as B, isParameterObject as C, isPathItemRef as D, isPathItemEntry as E, isSchemaProperty as F, COMPONENT_SUFFIXES as G, ARROW_FUNCTION_PATTERN as H, isSecurityArray as I, HOOK_LIBRARIES as J, FORM_MEDIA_TYPES as K, isSecurityScheme as L, isResponses as M, isSchemaArray as N, isRecord as O, isSchemaObject as P, JSON_MEDIA_TYPE as Q, isSingleSchema as R, isParameterArray as S, isPathItem as T, COMPONENT_NAMES as U, isValidIdent as V, COMPONENT_REF_PREFIX as W, IDENTIFIER_PATTERN as X, HTTP_METHODS as Y, INPUT_EXTENSIONS as Z, isOffsetTime as _, hasRequestBodyContent as a, isOperationLike as b, isDiscriminableBranch as c, isHttpMethod as d, OCTET_STREAM_MEDIA_TYPE as et, isInheritedName as f, isMediaWithSchema as g, isMedia as h, hasNumericConstraint as i, isRequestBody as j, isRefObject as k, isExamplesInput as l, isInputPath as m, hasNoUserChain as n, hasTypelessConstraint as o, isInlineMedia as p, FORM_URLENCODED_MEDIA_TYPE as q, hasNotProperty as r, isCallbacks as s, hasNoContentResponse as t, TEXT_MEDIA_TYPE as tt, isHeader as u, isOpenAPIPaths as v, isParameterRef as w, isParameter as x, isOperation as y, isStringRef as z };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as GenerateError } from "./format-
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-
|
|
5
|
-
import { t as emit } from "./emit-
|
|
1
|
+
import { O as isRecord, Y as HTTP_METHODS, b as isOperationLike, t as hasNoContentResponse, v as isOpenAPIPaths } from "./guard-BH6yBr0M.js";
|
|
2
|
+
import { i as GenerateError } from "./format-BF7SbaMP.js";
|
|
3
|
+
import { _ as routeName, n as capitalize, y as toIdentifierPascalCase } from "./utils-CDLiYepO.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-GDi7a_Ep.js";
|
|
5
|
+
import { t as emit } from "./emit-CqkT9T4Q.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
|
|
8
|
+
// src/helper/query.ts
|
|
9
9
|
function makeHookTail(tail, kind) {
|
|
10
10
|
return tail ? {
|
|
11
11
|
sig: `,${tail.name}?:${tail[kind]}`,
|
|
@@ -249,7 +249,8 @@ function makeQueryHookCode(hookName, keyGetterName, optionsGetterName, runtimeAc
|
|
|
249
249
|
const argsSig = hasArgs ? `args:MaybeRefOrGetter<${argsType}>,` : "";
|
|
250
250
|
const fetcherCall = hasArgs ? `parseResponse(${runtimeAccess}(toValue(args),{...clientOptions,init:{...clientOptions?.init,signal}}))` : `parseResponse(${runtimeAccess}(undefined,{...clientOptions,init:{...clientOptions?.init,signal}}))`;
|
|
251
251
|
const vueKeyCall = hasArgs ? makeVueReactiveKey(keyCall) : keyCall;
|
|
252
|
-
|
|
252
|
+
const queryTypeArgs = `${responseType},TError,TData,ReturnType<typeof ${keyGetterName}>`;
|
|
253
|
+
return `export function ${hookName}${generics}(${argsSig}options?:${optionsType}${tail.sig}){const{query:queryOptions,options:clientOptions}=options??{};return ${config.queryFn}<${queryTypeArgs}>({...queryOptions,queryKey:${vueKeyCall},queryFn({signal}){return ${fetcherCall}}}${tail.arg})}`;
|
|
253
254
|
}
|
|
254
255
|
const argsSig = hasArgs ? `args:${argsType},` : "";
|
|
255
256
|
if (useFactory) {
|
|
@@ -603,8 +604,7 @@ function makeQueryHooks(openAPI, output, importPath, config, clientName = "clien
|
|
|
603
604
|
return `Generated ${config.frameworkName.toLowerCase().replaceAll(" ", "-")} hooks written to ${output}`;
|
|
604
605
|
});
|
|
605
606
|
}
|
|
606
|
-
|
|
607
|
-
//#region src/core/hooks/index.ts
|
|
607
|
+
// src/core/hooks/index.ts
|
|
608
608
|
const DEFAULT_ERROR = "DefaultError";
|
|
609
609
|
const QUERY_CLIENT_TAIL = {
|
|
610
610
|
name: "queryClient",
|
|
@@ -755,5 +755,4 @@ const HOOK_CONFIGS = {
|
|
|
755
755
|
function hooks(openAPI, output, importPath, library, options) {
|
|
756
756
|
return makeQueryHooks(openAPI, output, importPath, HOOK_CONFIGS[library], options?.clientName, options?.grouping, options?.basePath);
|
|
757
757
|
}
|
|
758
|
-
//#endregion
|
|
759
758
|
export { hooks as t };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import "./index-
|
|
1
|
+
import "./index-DqcEtGVl.js";
|
|
2
|
+
import "./index-DvZscmYm.js";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
|
-
//#region src/helper/group.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* The group an operation belongs to. Every operation belongs to one: the resource its path
|
|
7
6
|
* or tag names, or `root`. What divides an application depends on how the template writes
|
|
8
7
|
* it.
|
|
9
8
|
*/
|
|
10
9
|
type Grouping = (path: string, tags: readonly string[] | undefined) => string;
|
|
11
|
-
//#endregion
|
|
12
10
|
export { Grouping as t };
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { Effect, FileSystem, Schema } from "effect";
|
|
2
2
|
import { FormatConfig } from "oxfmt";
|
|
3
|
-
//#region src/constants/index.d.ts
|
|
4
|
-
/** The extensions of an input document: OpenAPI as YAML (`.yaml` or `.yml`) or JSON, or a TypeSpec entry. */
|
|
5
|
-
declare const INPUT_EXTENSIONS: readonly ['.yaml', '.yml', '.json', '.tsp'];
|
|
6
|
-
/**
|
|
7
|
-
* An input document: a path by its extension, or an `http(s)` URL whatever its path (a
|
|
8
|
-
* document served without an extension is OpenAPI by content).
|
|
9
|
-
*/
|
|
10
|
-
type InputPath = `${string}${(typeof INPUT_EXTENSIONS)[number]}` | `http://${string}` | `https://${string}`;
|
|
11
3
|
/** The query libraries the hooks are generated for, each a config key of its own. */
|
|
12
4
|
declare const HOOK_LIBRARIES: readonly ['swr', 'tanstack-query', 'preact-query', 'solid-query', 'vue-query', 'svelte-query', 'angular-query'];
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/config/index.d.ts
|
|
15
5
|
declare const ConfigSchema: Schema.decodeTo<Schema.toType<Schema.Struct<{
|
|
16
|
-
readonly input: Schema.declare
|
|
6
|
+
readonly input: Schema.declare<`${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`, `${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`>;
|
|
17
7
|
readonly output: Schema.optionalKey<Schema.declare<`${string}.ts`, `${string}.ts`>>;
|
|
18
8
|
readonly basePath: Schema.withDecodingDefault<Schema.String, never>;
|
|
19
9
|
readonly readonly: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -227,7 +217,7 @@ declare const ConfigSchema: Schema.decodeTo<Schema.toType<Schema.Struct<{
|
|
|
227
217
|
readonly baseUrl: Schema.optionalKey<Schema.String>;
|
|
228
218
|
}>]>>;
|
|
229
219
|
}>>, Schema.Struct<{
|
|
230
|
-
readonly input: Schema.declare
|
|
220
|
+
readonly input: Schema.declare<`${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`, `${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`>;
|
|
231
221
|
readonly output: Schema.optionalKey<Schema.declare<`${string}.ts`, `${string}.ts`>>;
|
|
232
222
|
readonly basePath: Schema.withDecodingDefault<Schema.String, never>;
|
|
233
223
|
readonly readonly: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -448,7 +438,7 @@ declare const ConfigError_base: Schema.Class<ConfigError, Schema.TaggedStruct<"C
|
|
|
448
438
|
}>, import("effect/Cause").YieldableError>;
|
|
449
439
|
declare class ConfigError extends ConfigError_base {}
|
|
450
440
|
declare function parseConfig(config: unknown): Effect.Effect<{
|
|
451
|
-
readonly input:
|
|
441
|
+
readonly input: `${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`;
|
|
452
442
|
readonly output?: `${string}.ts`;
|
|
453
443
|
readonly basePath: string;
|
|
454
444
|
readonly readonly?: boolean;
|
|
@@ -663,7 +653,7 @@ declare function parseConfig(config: unknown): Effect.Effect<{
|
|
|
663
653
|
};
|
|
664
654
|
}, ConfigError, never>;
|
|
665
655
|
declare function readConfig(configPath?: string, reload?: boolean): Effect.Effect<{
|
|
666
|
-
readonly input:
|
|
656
|
+
readonly input: `${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`;
|
|
667
657
|
readonly output?: `${string}.ts`;
|
|
668
658
|
readonly basePath: string;
|
|
669
659
|
readonly readonly?: boolean;
|
|
@@ -904,5 +894,4 @@ type ConfigInput = (Base & {
|
|
|
904
894
|
readonly client: Client;
|
|
905
895
|
} & Callers);
|
|
906
896
|
declare function defineConfig(config: ConfigInput): ConfigInput;
|
|
907
|
-
//#endregion
|
|
908
897
|
export { parseConfig as a, defineConfig as i, ConfigError as n, readConfig as o, ConfigInput as r, Config as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
//#region src/openapi/index.d.ts
|
|
3
2
|
type OpenAPI = {
|
|
4
3
|
readonly openapi?: string;
|
|
5
4
|
readonly $self?: string;
|
|
@@ -522,5 +521,4 @@ type Media = {
|
|
|
522
521
|
type Callbacks = {
|
|
523
522
|
readonly [k: string]: PathItem;
|
|
524
523
|
};
|
|
525
|
-
//#endregion
|
|
526
524
|
export { OpenAPI as t };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/error/index.d.ts
|
|
2
1
|
declare const GenerateError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
3
2
|
readonly _tag: "GenerateError";
|
|
4
3
|
} & Readonly<A>;
|
|
@@ -11,5 +10,4 @@ declare const FormatError_base: new <A extends Record<string, any> = {}>(args: i
|
|
|
11
10
|
declare class FormatError extends FormatError_base<{
|
|
12
11
|
readonly message: string;
|
|
13
12
|
}> {}
|
|
14
|
-
//#endregion
|
|
15
13
|
export { GenerateError as n, FormatError as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as parseConfig, i as defineConfig, n as ConfigError, o as readConfig, r as ConfigInput, t as Config } from "./index-
|
|
1
|
+
import { a as parseConfig, i as defineConfig, n as ConfigError, o as readConfig, r as ConfigInput, t as Config } from "./index-DqcEtGVl.js";
|
|
2
2
|
export { Config, ConfigError, ConfigInput, defineConfig, parseConfig, readConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as HOOK_LIBRARIES, U as COMPONENT_NAMES, X as IDENTIFIER_PATTERN, m as isInputPath } from "./guard-BH6yBr0M.js";
|
|
2
2
|
import { Effect, FileSystem, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
3
3
|
import { posix, resolve } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
|
-
|
|
5
|
+
// src/config/index.ts
|
|
6
6
|
const ConfigSchema = Schema.Struct({
|
|
7
7
|
input: Schema.declare(isInputPath, { message: "must be .yaml | .yml | .json | .tsp, or an http(s) URL" }).annotate({
|
|
8
8
|
title: "Input document",
|
|
@@ -701,7 +701,7 @@ const ConfigSchema = Schema.Struct({
|
|
|
701
701
|
if (v.client !== void 0) return true;
|
|
702
702
|
const missing = ["rpc", ...HOOK_LIBRARIES].find((kind) => v[kind] !== void 0);
|
|
703
703
|
return missing === void 0 ? true : `${missing} needs client: rpc and the hooks call the client the client block generates, with template.`;
|
|
704
|
-
}
|
|
704
|
+
}), Schema.makeFilter((v) => !(v.output && v.routes), { message: "output and routes are mutually exclusive. Use output for single-file mode, or routes for separate route output." }), Schema.makeFilter((v) => !(v.template?.define === true && v.routes), { message: "template.define and routes are mutually exclusive. define derives routes/ next to the app entry (output, default src/index.ts)." }), Schema.makeFilter((v) => !(v.template?.define === true && v.output !== void 0 && !(v.output === "index.ts" || v.output.endsWith("/index.ts"))), { message: "with template.define, output is the app entry and must be an index.ts file (e.g. ./src/index.ts), or omitted to default to src/index.ts. Other names collide with the derived routes/ directory." }), Schema.makeFilter((v) => !(v.template?.define === true && v.components !== void 0 && COMPONENT_NAMES.some((k) => v.components?.[k] !== void 0)), { message: "with template.define, per-type component outputs (components.schemas, components.responses, ...) are not supported. Use components.output for a single components file." }), Schema.makeFilter((v) => {
|
|
705
705
|
if (v.template?.define !== true || v.components?.output === void 0) return true;
|
|
706
706
|
const componentsOutput = v.components.output.replace(/^\.\//u, "");
|
|
707
707
|
const container = componentsOutput.endsWith("/index.ts") ? componentsOutput.slice(0, -9) : componentsOutput;
|
|
@@ -734,7 +734,7 @@ const ConfigSchema = Schema.Struct({
|
|
|
734
734
|
seen.set(key, field);
|
|
735
735
|
}
|
|
736
736
|
return true;
|
|
737
|
-
}
|
|
737
|
+
})).annotate({
|
|
738
738
|
title: "hono-takibi config",
|
|
739
739
|
description: "Everything `hono-takibi` generates from one OpenAPI or TypeSpec document. Only `input` is required; each remaining field opts one generator in."
|
|
740
740
|
});
|
|
@@ -776,5 +776,4 @@ function readConfig(configPath, reload = false) {
|
|
|
776
776
|
function defineConfig(config) {
|
|
777
777
|
return config;
|
|
778
778
|
}
|
|
779
|
-
//#endregion
|
|
780
779
|
export { ConfigError, defineConfig, parseConfig, readConfig };
|