asphodelos 0.3.1 → 0.3.3

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/README.md CHANGED
@@ -35,6 +35,9 @@ export default defineConfig({
35
35
  })
36
36
  ```
37
37
 
38
+ `input` takes a `.yaml` / `.yml` / `.json` OpenAPI document, a `.tsp` TypeSpec entry, or an
39
+ `http(s)` URL that serves an OpenAPI document.
40
+
38
41
  ```bash
39
42
  bunx asphodelos
40
43
  ```
@@ -185,7 +188,7 @@ export default defineConfig({
185
188
  })
186
189
  ```
187
190
 
188
- - **What it watches**: `asphodelos.config.ts`, every `.yaml` / `.json` / `.tsp` in the directory
191
+ - **What it watches**: `asphodelos.config.ts`, every `.yaml` / `.yml` / `.json` / `.tsp` in the directory
189
192
  of `input` — a `$ref` or a TypeSpec import can reach a sibling file — and every file the document
190
193
  reads from outside that directory.
191
194
  - **When it regenerates**: a config save always regenerates. A document save regenerates only when
package/dist/cli.mjs CHANGED
@@ -4,15 +4,19 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
4
4
  import { Console, Effect, FileSystem, Option, Path, Ref, Stream } from "effect";
5
5
  import { CliError, Command, Flag } from "effect/cli";
6
6
  // package.json
7
- var version = "0.3.1";
7
+ var version = "0.3.3";
8
8
  var description = "Asphodelos is a code generator from OpenAPI to Elysia";
9
9
  // src/cli/index.ts
10
10
  const COMMAND_NAME = "asphodelos";
11
11
  /** Config file `asphodelos` picks up from the working directory when `--config` is omitted. */
12
12
  const DEFAULT_CONFIG_FILE = "asphodelos.config.ts";
13
- /** Extensions a change has to carry to be worth regenerating for. */
13
+ /**
14
+ * Extensions a change has to carry to be worth regenerating for: `INPUT_EXTENSIONS` in the
15
+ * config module, restated so the command line does not load that module before it needs it.
16
+ */
14
17
  const INPUT_EXTENSIONS = [
15
18
  ".yaml",
19
+ ".yml",
16
20
  ".json",
17
21
  ".tsp"
18
22
  ];
@@ -42,9 +46,9 @@ function loadConfig(configPath, reload) {
42
46
  function runJobs(config) {
43
47
  return Effect.gen(function* () {
44
48
  const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob }] = yield* Effect.promise(() => Promise.all([
45
- import("./openapi-CX7Yc6lR.mjs").then((n) => n.t),
49
+ import("./openapi-4yNuDK_n.mjs").then((n) => n.t),
46
50
  import("./format-DC258z--.mjs").then((n) => n.r),
47
- import("./shared-nkpRcjdg.mjs").then((n) => n.s)
51
+ import("./shared-CgKK5PYq.mjs").then((n) => n.s)
48
52
  ]));
49
53
  const jobs = makeJob(yield* parseOpenAPI(config.input), config);
50
54
  yield* cleanSplitOutputs(jobs);
@@ -82,7 +86,7 @@ function reportJobs(config, previous) {
82
86
  onFailure: (error) => Console.error(`❌ ${error.message}`),
83
87
  onSuccess: (report) => Console.log(report)
84
88
  }));
85
- const { outsideSources } = yield* Effect.promise(() => import("./shared-nkpRcjdg.mjs").then((n) => n.s));
89
+ const { outsideSources } = yield* Effect.promise(() => import("./shared-CgKK5PYq.mjs").then((n) => n.s));
86
90
  const inputDirectory = path.dirname(path.resolve(config.input));
87
91
  return {
88
92
  inputDirectory,
package/dist/index.d.mts CHANGED
@@ -20,8 +20,10 @@ declare const ConfigError_base: Schema.Class<ConfigError, Schema.TaggedStruct<"C
20
20
  * (`FormatError`, `GenerateError`, `OpenAPIError`) stay plain `Data.TaggedError`.
21
21
  */
22
22
  export declare class ConfigError extends ConfigError_base {}
23
+ /** Extensions an input document is recognized by, and that a change has to carry to be worth regenerating for. */
24
+ export declare const INPUT_EXTENSIONS: readonly ['.yaml', '.yml', '.json', '.tsp'];
23
25
  declare const ConfigSchema: Schema.Struct<{
24
- readonly input: Schema.declare<`${string}.json` | `${string}.tsp` | `${string}.yaml`, `${string}.json` | `${string}.tsp` | `${string}.yaml`>;
26
+ 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}`>;
25
27
  readonly output: Schema.optionalKey<Schema.declare<`${string}.ts`, `${string}.ts`>>;
26
28
  readonly prefix: Schema.optionalKey<Schema.String>;
27
29
  readonly format: Schema.optionalKey<Schema.declare<FormatConfig, FormatConfig>>;
@@ -275,7 +277,7 @@ export type Config = typeof ConfigSchema.Type;
275
277
  * naming the field that is wrong matters more than listing every consequence of it.
276
278
  */
277
279
  export declare function parseConfig(config: unknown): Effect.Effect<{
278
- readonly input: `${string}.json` | `${string}.tsp` | `${string}.yaml`;
280
+ readonly input: `${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`;
279
281
  readonly output?: `${string}.ts` | undefined;
280
282
  readonly prefix?: string | undefined;
281
283
  readonly format?: FormatConfig | undefined;
@@ -507,7 +509,7 @@ export declare function parseConfig(config: unknown): Effect.Effect<{
507
509
  * behind.
508
510
  */
509
511
  export declare function readConfig(configPath?: string, reload?: boolean): Effect.Effect<{
510
- readonly input: `${string}.json` | `${string}.tsp` | `${string}.yaml`;
512
+ readonly input: `${string}.json` | `${string}.tsp` | `${string}.yaml` | `${string}.yml` | `http://${string}` | `https://${string}`;
511
513
  readonly output?: `${string}.ts` | undefined;
512
514
  readonly prefix?: string | undefined;
513
515
  readonly format?: FormatConfig | undefined;
package/dist/index.mjs CHANGED
@@ -53,17 +53,28 @@ var ConfigError = class extends Schema.TaggedError()("ConfigError", {
53
53
  * say which extensions are meant.
54
54
  */
55
55
  const TypeScriptPathSchema = Schema.declare(Schema.is(Schema.TemplateLiteral([Schema.String, ".ts"])), { message: "must be .ts file" });
56
- const InputSchema = Schema.declare(Schema.is(Schema.TemplateLiteral([Schema.String, Schema.Literals([
56
+ /** Extensions an input document is recognized by, and that a change has to carry to be worth regenerating for. */
57
+ const INPUT_EXTENSIONS = [
57
58
  ".yaml",
59
+ ".yml",
58
60
  ".json",
59
61
  ".tsp"
60
- ])])), { message: "must be .yaml | .json | .tsp" }).annotate({
62
+ ];
63
+ /**
64
+ * An input document: a path by its extension, or an `http(s)` URL whatever its path (a
65
+ * document served without an extension is OpenAPI by content).
66
+ */
67
+ function isInputPath(v) {
68
+ return typeof v === "string" && (INPUT_EXTENSIONS.some((extension) => v.endsWith(extension)) || /^https?:\/\//u.test(v));
69
+ }
70
+ const InputSchema = Schema.declare(isInputPath, { message: "must be .yaml | .yml | .json | .tsp, or an http(s) URL" }).annotate({
61
71
  title: "Input document",
62
- description: "OpenAPI or TypeSpec entry document that every generator reads.",
72
+ description: "OpenAPI or TypeSpec entry document that every generator reads: a file by its extension, or an http(s) URL.",
63
73
  examples: [
64
74
  "openapi.yaml",
65
75
  "./spec/openapi.json",
66
- "./spec/main.tsp"
76
+ "./spec/main.tsp",
77
+ "https://example.com/openapi"
67
78
  ]
68
79
  });
69
80
  /** Milliseconds, bounded so a mock cannot be configured to hang a request. */
@@ -527,4 +538,4 @@ function readConfig(configPath, reload = false) {
527
538
  function defineConfig(config) {
528
539
  return config;
529
540
  }
530
- export { COMPONENT_KINDS, ConfigError, HOOK_KINDS, defineConfig, parseConfig, readConfig };
541
+ export { COMPONENT_KINDS, ConfigError, HOOK_KINDS, INPUT_EXTENSIONS, defineConfig, parseConfig, readConfig };
@@ -2,9 +2,13 @@ import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.mjs";
2
2
  import { Data, Effect } from "effect";
3
3
  import path from "node:path";
4
4
  import SwaggerParser from "@apidevtools/swagger-parser";
5
- import { NodeHost, compile } from "@typespec/compiler";
6
- import { getOpenAPI3 } from "@typespec/openapi3";
7
5
  // src/openapi/index.ts
6
+ /**
7
+ * Uses `bundle()` to resolve external $refs while preserving internal ones, so a split document
8
+ * folds into one whose components are still referenced by name.
9
+ *
10
+ * @see https://apitools.dev/swagger-parser/docs/
11
+ */
8
12
  var openapi_exports = /* @__PURE__ */ __exportAll({ parseOpenAPI: () => parseOpenAPI });
9
13
  /** The document could not be read, compiled or parsed into an OpenAPI object. */
10
14
  var OpenAPIError = class extends Data.TaggedError("OpenAPIError") {};
@@ -12,6 +16,7 @@ function parseOpenAPI(input) {
12
16
  return Effect.tryPromise({
13
17
  try: async () => {
14
18
  if (!input.endsWith(".tsp")) return await SwaggerParser.bundle(input);
19
+ const [{ compile, NodeHost }, { getOpenAPI3 }] = await Promise.all([import("@typespec/compiler"), import("@typespec/openapi3")]);
15
20
  const program = await compile(NodeHost, path.resolve(input), { noEmit: true });
16
21
  if (program.diagnostics.length > 0) throw new Error(`TypeSpec compile failed:\n${program.diagnostics.map((diagnostic) => diagnostic.message).join("\n")}`);
17
22
  const [record] = await getOpenAPI3(program);
@@ -19,7 +24,11 @@ function parseOpenAPI(input) {
19
24
  if (!document) throw new Error(`TypeSpec emitted no OpenAPI document: ${input}`);
20
25
  return document;
21
26
  },
22
- catch: (error) => new OpenAPIError({ message: error instanceof Error ? error.message : String(error) })
27
+ catch: (error) => {
28
+ if (!(error instanceof Error)) return new OpenAPIError({ message: String(error) });
29
+ const code = "ioErrorCode" in error ? error.ioErrorCode : void 0;
30
+ return new OpenAPIError({ message: (!error.message.trim() || error.message.trimEnd().endsWith(":")) && typeof code === "string" && code ? `${error.message}${code}` : error.message });
31
+ }
23
32
  });
24
33
  }
25
34
  export { parseOpenAPI as n, openapi_exports as t };
@@ -2726,10 +2726,13 @@ function successType(operation) {
2726
2726
  const ok = Object.entries(operation.responses ?? {}).find(([status]) => status.startsWith("2"));
2727
2727
  if (!ok) return { dataT: "void" };
2728
2728
  const info = responseInfo(ok[1]);
2729
- if (info.ref) return {
2730
- dataT: pascalCase(info.ref),
2731
- importName: pascalCase(info.ref)
2732
- };
2729
+ if (info.ref) {
2730
+ const ident = `${pascalCase(info.ref)}Schema`;
2731
+ return {
2732
+ dataT: `Static<typeof ${ident}>`,
2733
+ importName: ident
2734
+ };
2735
+ }
2733
2736
  if (info.void) return { dataT: "void" };
2734
2737
  return { dataT: "unknown" };
2735
2738
  }
@@ -3137,7 +3140,7 @@ function headerCode(config, client, importPath, body, fetchTypes, schemasImport)
3137
3140
  if (vue.length > 0) lines.push(`import { ${vue.join(", ")} } from 'vue'`);
3138
3141
  if (names("MaybeRefOrGetter")) lines.push("import type { MaybeRefOrGetter } from 'vue'");
3139
3142
  }
3140
- if (fetchTypes.length > 0) lines.push(`import type { ${fetchTypes.join(", ")} } from '${schemasImport}'`);
3143
+ if (fetchTypes.length > 0) lines.push("import type { Static } from 'elysia'", `import type { ${fetchTypes.join(", ")} } from '${schemasImport}'`);
3141
3144
  lines.push(`import { ${client} } from '${importPath}'`);
3142
3145
  return `${lines.join("\n")}\n\n`;
3143
3146
  }
@@ -1,19 +1,13 @@
1
- import { parseConfig } from "../index.mjs";
1
+ import { INPUT_EXTENSIONS, parseConfig } from "../index.mjs";
2
2
  import { t as FormatOptions } from "../format-DC258z--.mjs";
3
- import { a as makeJob, c as fileSystemLayer, i as jobTargets, n as isInsideDirectory, o as outsideSources, r as isUserCodeJob, t as cleanSplitOutputs } from "../shared-nkpRcjdg.mjs";
4
- import { n as parseOpenAPI } from "../openapi-CX7Yc6lR.mjs";
3
+ import { a as makeJob, c as fileSystemLayer, i as jobTargets, n as isInsideDirectory, o as outsideSources, r as isUserCodeJob, t as cleanSplitOutputs } from "../shared-CgKK5PYq.mjs";
4
+ import { n as parseOpenAPI } from "../openapi-4yNuDK_n.mjs";
5
5
  import { Effect, FileSystem, Result } from "effect";
6
6
  import path from "node:path";
7
7
  import crypto from "node:crypto";
8
8
  // src/vite-plugin/index.ts
9
9
  /** The config file the plugin reads, from the directory Vite was started in. */
10
10
  const CONFIG_FILE = "asphodelos.config.ts";
11
- /** Extensions a change has to carry to be worth regenerating for — the set `--watch` reacts to. */
12
- const INPUT_EXTENSIONS = [
13
- ".yaml",
14
- ".json",
15
- ".tsp"
16
- ];
17
11
  /**
18
12
  * How long a burst of filesystem events is let settle before a pass runs.
19
13
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asphodelos",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Asphodelos is a code generator from OpenAPI to Elysia",
5
5
  "keywords": [
6
6
  "elysia",