asphodelos 0.3.1 → 0.3.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/README.md +4 -1
- package/dist/cli.mjs +7 -3
- package/dist/index.d.mts +5 -3
- package/dist/index.mjs +16 -5
- package/dist/{openapi-CX7Yc6lR.mjs → openapi-4yNuDK_n.mjs} +12 -3
- package/dist/vite-plugin/index.mjs +2 -8
- package/package.json +1 -1
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.
|
|
7
|
+
var version = "0.3.2";
|
|
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
|
-
/**
|
|
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,7 +46,7 @@ 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-
|
|
49
|
+
import("./openapi-4yNuDK_n.mjs").then((n) => n.t),
|
|
46
50
|
import("./format-DC258z--.mjs").then((n) => n.r),
|
|
47
51
|
import("./shared-nkpRcjdg.mjs").then((n) => n.s)
|
|
48
52
|
]));
|
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
|
-
|
|
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
|
-
]
|
|
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) =>
|
|
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 };
|
|
@@ -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
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-
|
|
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
|
*
|