hono-takibi 0.30.1 → 0.31.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 CHANGED
@@ -5,7 +5,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
5
5
  import { Console, Effect, FileSystem, Option, Path, Ref, Schema, Stream } from "effect";
6
6
  import { Argument, CliError, Command, Flag } from "effect/cli";
7
7
  // package.json
8
- var version = "0.30.1";
8
+ var version = "0.31.0";
9
9
  var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
10
10
  // src/cli/index.ts
11
11
  const COMMAND_NAME = "hono-takibi";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Runs a config as the CLI runs `hono-takibi.config.ts`, for a program that generates code
3
+ * itself: the config is checked as a config file's default export is, the document read, and
4
+ * every output written. Paths are taken from the working directory, as in a config file.
5
+ * Answers the lines the CLI would print; rejects with the message the CLI would print.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { generate } from 'hono-takibi/generate'
10
+ *
11
+ * await generate({ input: 'openapi.yaml', output: './src/index.ts', template: { define: true } })
12
+ * ```
13
+ */
14
+ export declare function generate(config: unknown): Promise<string>;
@@ -0,0 +1,34 @@
1
+ import { parseConfig } from "../index.js";
2
+ import { t as FormatOptions } from "../format-BF7SbaMP.js";
3
+ import { n as parseOpenAPI } from "../openapi-DCo11_TE.js";
4
+ import { a as packageRoots, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-Dj8C8Wcq.js";
5
+ import * as NodeServices from "@effect/platform-node/NodeServices";
6
+ import { Effect } from "effect";
7
+ // src/generate/index.ts
8
+ /**
9
+ * Runs a config as the CLI runs `hono-takibi.config.ts`, for a program that generates code
10
+ * itself: the config is checked as a config file's default export is, the document read, and
11
+ * every output written. Paths are taken from the working directory, as in a config file.
12
+ * Answers the lines the CLI would print; rejects with the message the CLI would print.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { generate } from 'hono-takibi/generate'
17
+ *
18
+ * await generate({ input: 'openapi.yaml', output: './src/index.ts', template: { define: true } })
19
+ * ```
20
+ */
21
+ function generate(config) {
22
+ return Effect.runPromise(generateProgram(config).pipe(Effect.mapError((error) => new Error(error.message)), Effect.provide(NodeServices.layer)));
23
+ }
24
+ /** The config checked, the document read and every output written. */
25
+ function generateProgram(config) {
26
+ return Effect.gen(function* () {
27
+ const parsed = yield* parseConfig(config);
28
+ const openAPI = yield* openAPI3(yield* parseOpenAPI(parsed.input), parsed.input);
29
+ const jobs = makeJob(openAPI, parsed, yield* packageRoots(openAPI, parsed));
30
+ yield* cleanSplitOutputs(jobs.filter((job) => job.split).map((job) => job.output));
31
+ return (yield* Effect.forEach(jobs, (job) => job.run(job.output), { concurrency: "unbounded" }).pipe(Effect.provideService(FormatOptions, parsed.format ?? {}))).filter((message) => message !== "").join("\n");
32
+ });
33
+ }
34
+ export { generate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi",
5
5
  "keywords": [
6
6
  "hono",
@@ -56,6 +56,10 @@
56
56
  "./docs": {
57
57
  "types": "./dist/core/docs/index.d.ts",
58
58
  "import": "./dist/core/docs/index.js"
59
+ },
60
+ "./generate": {
61
+ "types": "./dist/generate/index.d.ts",
62
+ "import": "./dist/generate/index.js"
59
63
  }
60
64
  },
61
65
  "dependencies": {