asphodelos 0.3.0 → 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 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
  ```
@@ -58,7 +61,7 @@ GLOBAL FLAGS
58
61
  --help, -h Show help information
59
62
  --version, -v Show version information
60
63
  --wizard Start wizard mode for a command
61
- --completions <bash|zsh|fish|sh> Print shell completion script (choices: bash, zsh, fish, sh)
64
+ --completions <bash|zsh|fish|powershell|sh|pwsh> Print shell completion script (choices: bash, zsh, fish, powershell, sh, pwsh)
62
65
  --log-level <all|trace|debug|info|warn|warning|error|fatal|none> Sets the minimum log level (choices: all, trace, debug, info, warn, warning, error, fatal, none)
63
66
 
64
67
  EXAMPLES
@@ -129,6 +132,7 @@ src/
129
132
  ```ts
130
133
  // src/index.ts
131
134
  import { Elysia } from 'elysia'
135
+
132
136
  import { elysia } from './modules/elysia'
133
137
 
134
138
  export const app = new Elysia().use(elysia)
@@ -142,6 +146,7 @@ if (import.meta.main) {
142
146
  ```ts
143
147
  // src/modules/elysia/index.ts
144
148
  import { Elysia } from 'elysia'
149
+
145
150
  import { ElysiaModel } from './model'
146
151
 
147
152
  export const elysia = new Elysia().get('/elysia', () => {}, {
@@ -183,7 +188,7 @@ export default defineConfig({
183
188
  })
184
189
  ```
185
190
 
186
- - **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
187
192
  of `input` — a `$ref` or a TypeSpec import can reach a sibling file — and every file the document
188
193
  reads from outside that directory.
189
194
  - **When it regenerates**: a config save always regenerates. A document save regenerates only when
@@ -225,6 +230,7 @@ export default defineConfig({
225
230
  ```ts
226
231
  // src/lib/client.ts
227
232
  import { treaty } from '@elysiajs/eden'
233
+
228
234
  import type { app } from '../index'
229
235
 
230
236
  const origin = import.meta.env.VITE_API_URL!
@@ -647,6 +653,51 @@ round-tripped through OpenAPI but emit no code.
647
653
  Elysia already coerces query / path / header / cookie values and JSON bodies, so these only make
648
654
  the intent explicit in a body. Do not add them to parameters.
649
655
 
656
+ A `multipart/form-data` or `application/x-www-form-urlencoded` body carries every field as text,
657
+ so a `number` or `boolean` declared in one is generated as `t.Numeric()` / `t.BooleanString()`
658
+ without being asked, and an array as `t.ArrayQuery()`, which reads a field sent once as well as
659
+ one repeated; `integer` fields are read from text by `t.Integer()` as they are. A form body that
660
+ references a component schema takes a copy of that schema, read from text the same way; the
661
+ component itself stays typed for the JSON bodies that share it.
662
+
663
+ Wherever a value arrives as text — a query, path, header or cookie parameter, or a form field — a
664
+ `number` or `boolean` `enum` or `const` accepts the spelling of each member beside the member and
665
+ reads it into the literal (`?level=2` reaches the handler as `2`, typed `1 | 2 | 3`), and a nullable
666
+ `integer`, `number` or `boolean` reads the word `null` as `null`. A nullable `string` keeps the word
667
+ as text. An array header or cookie is one comma-separated value, read by `t.ArrayQuery()`.
668
+
669
+ A parameter declared with `content` instead of `schema` takes the schema of its one document; an
670
+ `application/json` document is read as one JSON value (`t.ObjectString()` / `t.ArrayString()`). A
671
+ `pipeDelimited` or `spaceDelimited` query array is split on its separator, and a repeated name is
672
+ read too; the elements are decoded with TypeBox's `Value` (`@sinclair/typebox`, a peer dependency
673
+ of Elysia), which the model file then imports. `deepObject` and an exploded object parameter are
674
+ read only as one JSON-encoded value.
675
+
676
+ Where a parameter or a form field references a component that is not an object (`$ref` to a
677
+ `boolean`, a numeric `enum`, an array, …), the generated schema uses a copy of the component, read
678
+ from text the same way; the component itself stays typed for the JSON bodies that share it.
679
+
680
+ ### String Formats
681
+
682
+ Elysia validates `date`, `time`, `date-time`, `duration`, `uri`, `url`, `email`, `hostname`,
683
+ `ipv4`, `ipv6`, `uuid`, `byte` and the JSON-pointer formats itself. These others are checked with
684
+ a `pattern`, the regular expression Zod checks them with (combined with the schema's own `pattern`
685
+ when it has one):
686
+
687
+ `uuidv1`–`uuidv8`, `guid`, `hex`, `base64`, `base64url`, `nanoid`, `cuid2`, `ulid`, `ksuid`, `xid`,
688
+ `cidrv4`, `cidrv6`, `mac`, `e164`, `httpUrl`.
689
+
690
+ `password` is a UI hint and is dropped. Any other format — `creditCard`, `iban` and `currencyCode`
691
+ need a checksum or a list, `emoji` a Unicode property escape TypeBox does not compile — is left off
692
+ the schema with a warning, so the string is not validated against it.
693
+
694
+ Elysia removes undeclared keys before validating (`normalize`, on by default), so an
695
+ `additionalProperties: false` object never sees an extra key and drops it instead of rejecting it.
696
+ Create the app with `new Elysia({ normalize: false })` to have such a key rejected.
697
+
698
+ A header parameter is keyed by its lower-case name (`X-Request-Id` becomes `x-request-id`), which
699
+ is how Elysia hands headers to the handler.
700
+
650
701
  ### Unsupported Extensions
651
702
 
652
703
  `x-refine`, `x-superRefine`, `x-prefault` (use `default`), `x-decode` / `x-encode` (use
@@ -664,7 +715,8 @@ Lint and tests run from the repository root:
664
715
  ```bash
665
716
  bun run check # format check, lint, type check, tests, then the client suite
666
717
  bun run fix # autofix formatting, oxlint, markdownlint and textlint
667
- bun run lint # oxlint, markdownlint, textlint, cspell, secretlint, actionlint
718
+ bun run lint # oxlint, knip, markdownlint, textlint, cspell, secretlint, actionlint
719
+ bun run knip # unused files, dependencies and exports, then the same over shipped code only
668
720
  bun run test # unit tests
669
721
  bun run test:clients # build, then compile and run the generated hooks under test/
670
722
  bun run test:pack # build, pack, and install the tarball with npm into an empty project
package/dist/cli.d.mts CHANGED
@@ -1 +1 @@
1
- export { };
1
+ export {}
package/dist/cli.mjs CHANGED
@@ -3,17 +3,20 @@ import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
3
3
  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
- //#region package.json
7
- var version = "0.3.0";
6
+ // package.json
7
+ var version = "0.3.2";
8
8
  var description = "Asphodelos is a code generator from OpenAPI to Elysia";
9
- //#endregion
10
- //#region src/cli/index.ts
9
+ // src/cli/index.ts
11
10
  const COMMAND_NAME = "asphodelos";
12
11
  /** Config file `asphodelos` picks up from the working directory when `--config` is omitted. */
13
12
  const DEFAULT_CONFIG_FILE = "asphodelos.config.ts";
14
- /** 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
+ */
15
17
  const INPUT_EXTENSIONS = [
16
18
  ".yaml",
19
+ ".yml",
17
20
  ".json",
18
21
  ".tsp"
19
22
  ];
@@ -30,7 +33,7 @@ const commandLine = {
30
33
  *
31
34
  * The config module is loaded here rather than at module scope, with the rest of the pipeline:
32
35
  * `--help`, `--version`, `--completions` and every rejected command line must not pay for the
33
- * OpenAPI parser, the TypeSpec compiler and ts-morph. After the first pass the loader answers
36
+ * OpenAPI parser, the TypeSpec compiler and oxc-parser. After the first pass the loader answers
34
37
  * from cache, so a watch tick pays nothing.
35
38
  */
36
39
  function loadConfig(configPath, reload) {
@@ -43,9 +46,9 @@ function loadConfig(configPath, reload) {
43
46
  function runJobs(config) {
44
47
  return Effect.gen(function* () {
45
48
  const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob }] = yield* Effect.promise(() => Promise.all([
46
- import("./openapi-C8b6Ibiu.mjs").then((n) => n.t),
47
- import("./format-B0W7HIAg.mjs").then((n) => n.r),
48
- import("./shared-Becl66EY.mjs").then((n) => n.s)
49
+ import("./openapi-4yNuDK_n.mjs").then((n) => n.t),
50
+ import("./format-DC258z--.mjs").then((n) => n.r),
51
+ import("./shared-nkpRcjdg.mjs").then((n) => n.s)
49
52
  ]));
50
53
  const jobs = makeJob(yield* parseOpenAPI(config.input), config);
51
54
  yield* cleanSplitOutputs(jobs);
@@ -83,7 +86,7 @@ function reportJobs(config, previous) {
83
86
  onFailure: (error) => Console.error(`❌ ${error.message}`),
84
87
  onSuccess: (report) => Console.log(report)
85
88
  }));
86
- const { outsideSources } = yield* Effect.promise(() => import("./shared-Becl66EY.mjs").then((n) => n.s));
89
+ const { outsideSources } = yield* Effect.promise(() => import("./shared-nkpRcjdg.mjs").then((n) => n.s));
87
90
  const inputDirectory = path.dirname(path.resolve(config.input));
88
91
  return {
89
92
  inputDirectory,
@@ -159,6 +162,12 @@ function outsideEvents(outside) {
159
162
  *
160
163
  * Changes are debounced because one save is several filesystem events — an editor writes,
161
164
  * renames and touches — and a round per event would race itself.
165
+ *
166
+ * A watcher starts a moment after the round announces it, and a directory created or removed in
167
+ * between raises no event on it. So where the input directory lives is also polled: when the
168
+ * closest existing directory is no longer `watched`, the round ends as it would on the event,
169
+ * and a watcher on a directory that vanished before it started is dropped rather than failing
170
+ * the session.
162
171
  */
163
172
  function watchRound(configPath, target, watched) {
164
173
  return Effect.gen(function* () {
@@ -167,12 +176,13 @@ function watchRound(configPath, target, watched) {
167
176
  const configFile = path.basename(configPath);
168
177
  const nextTarget = yield* Ref.make(target);
169
178
  const configEvents = fs.watch(path.dirname(configPath)).pipe(Stream.filter((event) => event.path === configFile));
170
- const inputEvents = target === void 0 || watched === void 0 ? [] : [watched === target.inputDirectory ? fs.watch(target.inputDirectory, { recursive: true }).pipe(Stream.filter((event) => INPUT_EXTENSIONS.some((extension) => event.path.endsWith(extension)))) : fs.watch(watched).pipe(Stream.filter((event) => event.path === path.relative(watched, target.inputDirectory).split(path.sep)[0]))];
179
+ const inputEvents = target === void 0 || watched === void 0 ? [] : [watched === target.inputDirectory ? fs.watch(target.inputDirectory, { recursive: true }).pipe(Stream.filter((event) => INPUT_EXTENSIONS.some((extension) => event.path.endsWith(extension))), Stream.ignore) : fs.watch(watched).pipe(Stream.filter((event) => event.path === path.relative(watched, target.inputDirectory).split(path.sep)[0]), Stream.ignore)];
180
+ const relocated = target === void 0 || watched === void 0 ? Stream.empty : Stream.tick("500 millis").pipe(Stream.mapEffect(() => nearestExisting(target.inputDirectory)), Stream.filter((place) => place !== watched));
171
181
  yield* Stream.mergeAll([
172
182
  configEvents,
173
183
  ...inputEvents,
174
184
  ...yield* outsideEvents(target?.outside ?? [])
175
- ], { concurrency: "unbounded" }).pipe(Stream.debounce("200 millis"), Stream.runForEachWhile(() => watchPass(configPath, target, watched, nextTarget)));
185
+ ], { concurrency: "unbounded" }).pipe(Stream.merge(relocated), Stream.debounce("200 millis"), Stream.runForEachWhile(() => watchPass(configPath, target, watched, nextTarget)));
176
186
  return yield* Ref.get(nextTarget);
177
187
  });
178
188
  }
@@ -257,8 +267,6 @@ function makeCli() {
257
267
  function asphodelos() {
258
268
  return Command.run(makeCli(), { version });
259
269
  }
260
- //#endregion
261
- //#region src/index.ts
270
+ // src/index.ts
262
271
  NodeRuntime.runMain(asphodelos().pipe(Effect.provide(NodeServices.layer)));
263
- //#endregion
264
272
  export {};
@@ -1,7 +1,7 @@
1
- import { t as __exportAll } from "./rolldown-runtime-wcPFST8Q.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.mjs";
2
2
  import { Context, Data, Effect } from "effect";
3
3
  import { format } from "oxfmt";
4
- //#region src/format/index.ts
4
+ // src/format/index.ts
5
5
  var format_exports = /* @__PURE__ */ __exportAll({
6
6
  FormatError: () => FormatError,
7
7
  FormatOptions: () => FormatOptions,
@@ -44,5 +44,4 @@ function fmt(input) {
44
44
  return collapseImportGaps(code);
45
45
  });
46
46
  }
47
- //#endregion
48
47
  export { fmt as n, format_exports as r, FormatOptions as t };