asphodelos 0.0.1 → 0.3.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/README.md +209 -127
- package/dist/cli.mjs +184 -119
- package/dist/index.d.mts +323 -561
- package/dist/index.mjs +392 -66
- package/dist/openapi-C8b6Ibiu.mjs +26 -0
- package/dist/{core-DS3sAabb.mjs → shared-Becl66EY.mjs} +1041 -743
- package/dist/vite-plugin/index.mjs +37 -18
- package/package.json +11 -16
- package/dist/openapi-B4aAnx4P.mjs +0 -40
- package/dist/shared-CrbXsFUJ.mjs +0 -221
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
import { Effect, FileSystem, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
2
|
-
import { resolve } from "node:path";
|
|
2
|
+
import { posix, resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
//#region src/config/index.ts
|
|
5
|
+
/** OpenAPI 3.x Components Object kinds, in declaration / config-field order. */
|
|
6
|
+
const COMPONENT_KINDS = [
|
|
7
|
+
"schemas",
|
|
8
|
+
"responses",
|
|
9
|
+
"parameters",
|
|
10
|
+
"examples",
|
|
11
|
+
"requestBodies",
|
|
12
|
+
"headers",
|
|
13
|
+
"securitySchemes",
|
|
14
|
+
"links",
|
|
15
|
+
"callbacks",
|
|
16
|
+
"pathItems",
|
|
17
|
+
"mediaTypes"
|
|
18
|
+
];
|
|
19
|
+
/** The client libraries a hooks file can be generated for, in config-field order. */
|
|
20
|
+
const HOOK_KINDS = [
|
|
21
|
+
"swr",
|
|
22
|
+
"tanstack-query",
|
|
23
|
+
"preact-query",
|
|
24
|
+
"solid-query",
|
|
25
|
+
"vue-query",
|
|
26
|
+
"svelte-query",
|
|
27
|
+
"angular-query"
|
|
28
|
+
];
|
|
5
29
|
/**
|
|
6
30
|
* The config file is missing, is not a module with a default export, or does not validate.
|
|
7
31
|
*
|
|
@@ -14,8 +38,11 @@ import { pathToFileURL } from "node:url";
|
|
|
14
38
|
* (`FormatError`, `GenerateError`, `OpenAPIError`) stay plain `Data.TaggedError`.
|
|
15
39
|
*/
|
|
16
40
|
var ConfigError = class extends Schema.TaggedError()("ConfigError", {
|
|
17
|
-
message: Schema.String
|
|
18
|
-
|
|
41
|
+
message: Schema.String.annotate({
|
|
42
|
+
description: "The sentence printed to the caller, naming the field that is wrong.",
|
|
43
|
+
examples: ["Invalid config: eden.import: must be a module specifier"]
|
|
44
|
+
}),
|
|
45
|
+
notFound: Schema.optionalKey(Schema.Boolean.annotate({ description: "There is no config file at all, as opposed to one that does not validate." }))
|
|
19
46
|
}) {};
|
|
20
47
|
/**
|
|
21
48
|
* A path constrained to a set of extensions.
|
|
@@ -30,7 +57,15 @@ const InputSchema = Schema.declare(Schema.is(Schema.TemplateLiteral([Schema.Stri
|
|
|
30
57
|
".yaml",
|
|
31
58
|
".json",
|
|
32
59
|
".tsp"
|
|
33
|
-
])])), { message: "must be .yaml | .json | .tsp" })
|
|
60
|
+
])])), { message: "must be .yaml | .json | .tsp" }).annotate({
|
|
61
|
+
title: "Input document",
|
|
62
|
+
description: "OpenAPI or TypeSpec entry document that every generator reads.",
|
|
63
|
+
examples: [
|
|
64
|
+
"openapi.yaml",
|
|
65
|
+
"./spec/openapi.json",
|
|
66
|
+
"./spec/main.tsp"
|
|
67
|
+
]
|
|
68
|
+
});
|
|
34
69
|
/** Milliseconds, bounded so a mock cannot be configured to hang a request. */
|
|
35
70
|
const DelayMsSchema = Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(6e4));
|
|
36
71
|
/** A faker seed: faker hashes it with Mersenne Twister, which takes a 32-bit unsigned integer. */
|
|
@@ -41,11 +76,36 @@ const ArrayLengthSchema = Schema.Number.check(Schema.isInt(), Schema.isGreaterTh
|
|
|
41
76
|
const FileOutputSchema = Schema.String.pipe(Schema.decodeTo(Schema.String, SchemaTransformation.transform({
|
|
42
77
|
decode: (v) => v.endsWith(".ts") ? v : `${v}/index.ts`,
|
|
43
78
|
encode: (v) => v
|
|
44
|
-
})))
|
|
79
|
+
}))).annotate({
|
|
80
|
+
title: "Output file",
|
|
81
|
+
description: "Single file that receives every generated entry. A directory path is normalized to `<dir>/index.ts`.",
|
|
82
|
+
examples: ["./src/swr.ts", "./src/swr"]
|
|
83
|
+
});
|
|
84
|
+
const ImportSchema = Schema.String.check(Schema.isPattern(/^[^\s'"`\\]+$/u, { message: "must be a module specifier, with no whitespace or quotes" })).annotate({
|
|
85
|
+
title: "Import specifier",
|
|
86
|
+
description: "Module specifier the generated file imports from.",
|
|
87
|
+
examples: [
|
|
88
|
+
"@packages/schemas",
|
|
89
|
+
"../lib",
|
|
90
|
+
"."
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* An option that is gone, kept as a key so a config written for an earlier version is told what
|
|
95
|
+
* replaced it rather than silently losing the key.
|
|
96
|
+
*/
|
|
97
|
+
function removed(message) {
|
|
98
|
+
return Schema.optionalKey(Schema.Never.annotate({ message }));
|
|
99
|
+
}
|
|
100
|
+
/** The `import` and `client` of a file that calls the client: both gone, the generated client being the one it imports. */
|
|
101
|
+
const CLIENT_CONSUMER_REMOVED = {
|
|
102
|
+
import: removed("import was removed: the file imports the client the top-level `client` block generates — relatively, through `pathAlias`, or by `client.package` from another package. Delete the import and add client: { output }."),
|
|
103
|
+
client: removed("client was removed: the generated client is exported as `client`. Delete the name.")
|
|
104
|
+
};
|
|
45
105
|
/**
|
|
46
|
-
* Every
|
|
47
|
-
* a directory, anything else writes a single file. Only those two fields differ, so the rest
|
|
48
|
-
* written once and spread into both branches.
|
|
106
|
+
* Every component target is the same two-branch union: `split: true` writes one file per entry
|
|
107
|
+
* into a directory, anything else writes a single file. Only those two fields differ, so the rest
|
|
108
|
+
* is written once and spread into both branches.
|
|
49
109
|
*
|
|
50
110
|
* `Schema.Union` resolves members in order and each member pins `split` to a literal, so a member
|
|
51
111
|
* is only reachable through its own discriminant — the failure reported is the one inside the
|
|
@@ -53,68 +113,252 @@ const FileOutputSchema = Schema.String.pipe(Schema.decodeTo(Schema.String, Schem
|
|
|
53
113
|
*/
|
|
54
114
|
function splitUnion(shared) {
|
|
55
115
|
return Schema.Union([Schema.Struct({
|
|
56
|
-
split: Schema.Literal(true),
|
|
57
|
-
output: Schema.String.check(Schema.isPattern(/^(?!.*\.ts$).+/u, { message: "split mode requires directory, not .ts file" }))
|
|
116
|
+
split: Schema.Literal(true).annotate({ description: "Write one file per entry into `output` rather than a single file." }),
|
|
117
|
+
output: Schema.String.check(Schema.isPattern(/^(?!.*\.ts$).+/u, { message: "split mode requires directory, not .ts file" })).annotate({
|
|
118
|
+
title: "Output directory",
|
|
119
|
+
description: "Directory that takes one file per entry and an `index.ts` barrel.",
|
|
120
|
+
examples: ["./src/components/schemas"]
|
|
121
|
+
}),
|
|
58
122
|
...shared
|
|
59
123
|
}), Schema.Struct({
|
|
60
|
-
split: Schema.Literal(false).pipe(Schema.withDecodingDefault(Effect.succeed(false))),
|
|
124
|
+
split: Schema.Literal(false).pipe(Schema.withDecodingDefault(Effect.succeed(false))).annotate({ description: "Write a single file (default)." }),
|
|
61
125
|
output: FileOutputSchema,
|
|
62
126
|
...shared
|
|
63
127
|
})]);
|
|
64
128
|
}
|
|
65
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The name the generated files in other packages import an output by: the package it is published
|
|
131
|
+
* as. Files in its own package import it relatively, or through the alias.
|
|
132
|
+
*/
|
|
133
|
+
const PackageSchema = ImportSchema.annotate({
|
|
134
|
+
title: "Package name",
|
|
135
|
+
description: "The name the generated files in other packages import this output by — the package it is published as, whose entry is this file or its barrel. Files in the same package import it relatively or through `pathAlias`. Left out, a file in another package is refused.",
|
|
136
|
+
examples: ["@packages/schemas"]
|
|
137
|
+
});
|
|
138
|
+
const SECTION_IMPORT_REMOVED = removed("import was removed: a section is imported relatively, through `pathAlias`, or by its `package` from another package. Delete the import.");
|
|
139
|
+
const OutputSchema = splitUnion({
|
|
140
|
+
import: SECTION_IMPORT_REMOVED,
|
|
141
|
+
package: Schema.optionalKey(PackageSchema)
|
|
142
|
+
});
|
|
66
143
|
const ExportTypesOutputSchema = splitUnion({
|
|
67
|
-
import:
|
|
68
|
-
|
|
144
|
+
import: SECTION_IMPORT_REMOVED,
|
|
145
|
+
package: Schema.optionalKey(PackageSchema),
|
|
146
|
+
exportTypes: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))).annotate({ description: "Also export the TypeScript type inferred from each generated schema." })
|
|
147
|
+
});
|
|
148
|
+
/**
|
|
149
|
+
* What the generated client is created with.
|
|
150
|
+
*
|
|
151
|
+
* A URL written into the file, an environment variable read when the client is created, or a
|
|
152
|
+
* property of an environment a module exports. The member that names a module stands first: the
|
|
153
|
+
* other would accept the object as well and leave `import` out.
|
|
154
|
+
*/
|
|
155
|
+
const BaseUrlSchema = Schema.Union([Schema.Struct({
|
|
156
|
+
import: ImportSchema.annotate({
|
|
157
|
+
title: "Import specifier",
|
|
158
|
+
description: "The module the base URL is read from, written into the client file as it stands: one that validates its environment and exports it.",
|
|
159
|
+
examples: ["@/env", "../env"]
|
|
160
|
+
}),
|
|
161
|
+
value: Schema.String.check(Schema.isPattern(/^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*$/u, { message: "must be an export of the module, with the property read from it: `env.API_URL`" })).annotate({
|
|
162
|
+
title: "Value",
|
|
163
|
+
description: "The expression the client is created with, as it is written: the export of `import` followed by the property read from it. `env.API_URL` imports `env` and reads `env.API_URL`; `apiUrl` imports and uses `apiUrl` itself.",
|
|
164
|
+
examples: ["env.API_URL", "apiUrl"]
|
|
165
|
+
})
|
|
166
|
+
}), Schema.Struct({
|
|
167
|
+
env: Schema.String.check(Schema.isPattern(/^[A-Za-z_][A-Za-z0-9_]*$/u, { message: "must be the name of an environment variable" })).annotate({
|
|
168
|
+
title: "Environment variable",
|
|
169
|
+
description: "The variable the base URL is read from when the client is created, asserted to be set: `process.env.API_URL!`.",
|
|
170
|
+
examples: ["VITE_API_URL", "API_URL"]
|
|
171
|
+
}),
|
|
172
|
+
source: Schema.Literals(["import.meta.env", "process.env"]).pipe(Schema.withDecodingDefault(Effect.succeed("import.meta.env"))).annotate({
|
|
173
|
+
title: "Where the variable is read from",
|
|
174
|
+
description: "`import.meta.env` for code a bundler such as Vite builds, `process.env` for code Node.js or Bun runs.",
|
|
175
|
+
examples: ["import.meta.env", "process.env"]
|
|
176
|
+
})
|
|
177
|
+
})]).annotate({
|
|
178
|
+
title: "Base URL",
|
|
179
|
+
description: "What the client is created with, `treaty<typeof app>(baseUrl)`: an environment variable read when the client is created, or a value a module exports. Never a URL written into the file — the address is the environment's to say.",
|
|
180
|
+
examples: [{
|
|
181
|
+
env: "VITE_API_URL",
|
|
182
|
+
source: "import.meta.env"
|
|
183
|
+
}, {
|
|
184
|
+
import: "@/env",
|
|
185
|
+
value: "env.API_URL"
|
|
186
|
+
}]
|
|
187
|
+
});
|
|
188
|
+
const ClientOutputSchema = Schema.Struct({
|
|
189
|
+
output: TypeScriptPathSchema.annotate({
|
|
190
|
+
title: "Client output file",
|
|
191
|
+
description: "The `.ts` file the client is written to.",
|
|
192
|
+
examples: ["./src/client.ts"]
|
|
193
|
+
}),
|
|
194
|
+
import: removed("import was removed: a client in another package imports the app by the top-level `package`, the name the app entry is published as. Delete the import and set package."),
|
|
195
|
+
package: Schema.optionalKey(ImportSchema.annotate({
|
|
196
|
+
title: "Package name",
|
|
197
|
+
description: "The name the generated files in other packages import the client by — the package it is published as, whose entry is the client or its barrel. Files in the client's own package import it relatively or through the alias. Left out, a file outside that package is refused.",
|
|
198
|
+
examples: ["@packages/client"]
|
|
199
|
+
})),
|
|
200
|
+
baseUrl: BaseUrlSchema,
|
|
201
|
+
sameOrigin: Schema.optionalKey(Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))).annotate({
|
|
202
|
+
title: "Same origin in the browser",
|
|
203
|
+
description: "In a browser the client sends its requests to the page's own origin, `window.location.origin`, and `baseUrl` is for code that runs without a window: a server render, a loader, a script. For an app a host framework such as TanStack Start or Next.js serves beside its pages, where the API shares the origin and CORS has nothing to allow. Needs the DOM lib."
|
|
204
|
+
}))
|
|
205
|
+
}).annotate({
|
|
206
|
+
title: "Eden Treaty client",
|
|
207
|
+
description: "The Eden Treaty client of the generated app, `treaty<typeof app>(baseUrl)`, typed by a type-only import of the app entry so the server never reaches a browser bundle. `eden` and the hooks import it unless they name an `import` of their own. Needs `@elysiajs/eden` in the project.",
|
|
208
|
+
examples: [{
|
|
209
|
+
output: "./src/client.ts",
|
|
210
|
+
baseUrl: {
|
|
211
|
+
env: "VITE_API_URL",
|
|
212
|
+
source: "import.meta.env"
|
|
213
|
+
},
|
|
214
|
+
sameOrigin: true
|
|
215
|
+
}, {
|
|
216
|
+
output: "../client/src/lib/client.ts",
|
|
217
|
+
baseUrl: {
|
|
218
|
+
env: "API_URL",
|
|
219
|
+
source: "process.env"
|
|
220
|
+
},
|
|
221
|
+
package: "@packages/client"
|
|
222
|
+
}]
|
|
69
223
|
});
|
|
70
|
-
const HooksSchema =
|
|
71
|
-
|
|
72
|
-
|
|
224
|
+
const HooksSchema = Schema.Struct({
|
|
225
|
+
output: FileOutputSchema,
|
|
226
|
+
...CLIENT_CONSUMER_REMOVED,
|
|
227
|
+
split: removed("split was removed: the hooks are always generated into a single file. Set output to a .ts file path and delete the directory the previous run wrote.")
|
|
73
228
|
});
|
|
74
229
|
const ComponentsSchema = Schema.Struct({
|
|
75
|
-
output: Schema.optionalKey(TypeScriptPathSchema
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
230
|
+
output: Schema.optionalKey(TypeScriptPathSchema.annotate({
|
|
231
|
+
title: "Single-file components output",
|
|
232
|
+
description: "Every component section in one file. Mutually exclusive with the per-type fields below.",
|
|
233
|
+
examples: ["./src/components/index.ts"]
|
|
234
|
+
})),
|
|
235
|
+
package: Schema.optionalKey(PackageSchema),
|
|
236
|
+
schemas: Schema.optionalKey(ExportTypesOutputSchema.annotate({
|
|
237
|
+
title: "Schemas output",
|
|
238
|
+
description: "Destination for `components.schemas`."
|
|
239
|
+
})),
|
|
240
|
+
responses: Schema.optionalKey(ExportTypesOutputSchema.annotate({
|
|
241
|
+
title: "Responses output",
|
|
242
|
+
description: "Destination for `components.responses`."
|
|
243
|
+
})),
|
|
244
|
+
parameters: Schema.optionalKey(ExportTypesOutputSchema.annotate({
|
|
245
|
+
title: "Parameters output",
|
|
246
|
+
description: "Destination for `components.parameters`."
|
|
247
|
+
})),
|
|
248
|
+
examples: Schema.optionalKey(OutputSchema.annotate({
|
|
249
|
+
title: "Examples output",
|
|
250
|
+
description: "Destination for `components.examples`."
|
|
251
|
+
})),
|
|
252
|
+
requestBodies: Schema.optionalKey(ExportTypesOutputSchema.annotate({
|
|
253
|
+
title: "Request bodies output",
|
|
254
|
+
description: "Destination for `components.requestBodies`."
|
|
255
|
+
})),
|
|
256
|
+
headers: Schema.optionalKey(ExportTypesOutputSchema.annotate({
|
|
257
|
+
title: "Headers output",
|
|
258
|
+
description: "Destination for `components.headers`."
|
|
259
|
+
})),
|
|
260
|
+
securitySchemes: Schema.optionalKey(OutputSchema.annotate({
|
|
261
|
+
title: "Security schemes output",
|
|
262
|
+
description: "Destination for `components.securitySchemes`."
|
|
263
|
+
})),
|
|
264
|
+
links: Schema.optionalKey(OutputSchema.annotate({
|
|
265
|
+
title: "Links output",
|
|
266
|
+
description: "Destination for `components.links`."
|
|
267
|
+
})),
|
|
268
|
+
callbacks: Schema.optionalKey(OutputSchema.annotate({
|
|
269
|
+
title: "Callbacks output",
|
|
270
|
+
description: "Destination for `components.callbacks`."
|
|
271
|
+
})),
|
|
272
|
+
pathItems: Schema.optionalKey(OutputSchema.annotate({
|
|
273
|
+
title: "Path items output",
|
|
274
|
+
description: "Destination for `components.pathItems`."
|
|
275
|
+
})),
|
|
276
|
+
mediaTypes: Schema.optionalKey(ExportTypesOutputSchema.annotate({
|
|
277
|
+
title: "Media types output",
|
|
278
|
+
description: "Destination for `components.mediaTypes`."
|
|
279
|
+
}))
|
|
280
|
+
}).check(Schema.makeFilter((components) => components.output === void 0 || COMPONENT_KINDS.every((kind) => components[kind] === void 0) ? void 0 : "output cannot be combined with per-type component outputs. Use either a single 'output' or per-type configs."), Schema.makeFilter(({ output, package: name }) => name === void 0 || output !== void 0 ? void 0 : "package names the single-file output: set output, or name the package on each section.")).annotate({
|
|
281
|
+
title: "Components outputs",
|
|
282
|
+
description: "Where `components.*` is written: one file for every section, or a target per section. Left out, each section the document has goes to `components/<section>.ts` beside the app entry."
|
|
283
|
+
});
|
|
88
284
|
const ConfigSchema = Schema.Struct({
|
|
89
285
|
input: InputSchema,
|
|
90
|
-
output: Schema.optionalKey(TypeScriptPathSchema
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
286
|
+
output: Schema.optionalKey(TypeScriptPathSchema.annotate({
|
|
287
|
+
title: "App entry",
|
|
288
|
+
description: "The Elysia app entry; its directory takes `modules/` and the default `components/`. `src/index.ts` when left out.",
|
|
289
|
+
examples: ["./src/index.ts", "./server/index.ts"]
|
|
290
|
+
})),
|
|
291
|
+
prefix: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^\/[^\s'"`\\]*$/u, { message: "must start with '/' and contain no whitespace or quotes" })).annotate({
|
|
292
|
+
title: "Prefix",
|
|
293
|
+
description: "Prefix the generated app is mounted on, emitted as `new Elysia({ prefix })`. Elysia wants the leading slash.",
|
|
294
|
+
examples: ["/api", "/api/v1"]
|
|
295
|
+
})),
|
|
296
|
+
format: Schema.optionalKey(Schema.declare((u) => typeof u === "object" && u !== null, { message: "must be an oxfmt config object" }).annotate({
|
|
297
|
+
title: "Formatter options",
|
|
298
|
+
description: "oxfmt `FormatConfig` applied to every generated file. Defaults to printWidth 100, single quotes, no semicolons.",
|
|
299
|
+
examples: [{
|
|
300
|
+
printWidth: 80,
|
|
301
|
+
semi: true
|
|
302
|
+
}]
|
|
303
|
+
})),
|
|
304
|
+
port: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^\d{1,5}$/u, { message: "must be a port number" })).pipe(Schema.withDecodingDefault(Effect.succeed("3000"))).annotate({
|
|
305
|
+
title: "Port",
|
|
306
|
+
description: "Port the app entry listens on when it is run directly, `3000` when left out.",
|
|
307
|
+
examples: ["3000", "8080"]
|
|
308
|
+
})),
|
|
309
|
+
pathAlias: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[^\s'"`\\]+$/u, { message: "must be an import prefix, with no whitespace or quotes" })).annotate({
|
|
310
|
+
title: "Path alias",
|
|
311
|
+
description: "Import prefix the generated files use for each other instead of relative paths. It stands for the app entry's directory, so with `@/` and `src/index.ts` the entry is `@/index` and `src/client.ts` is `@/client`; a file outside that directory is still imported relatively. Map it in tsconfig: `\"paths\": { \"@/*\": [\"./src/*\"] }`.",
|
|
312
|
+
examples: ["@/", "~/"]
|
|
313
|
+
})),
|
|
314
|
+
integration: Schema.optionalKey(Schema.Boolean.annotate({ description: "Leave `.listen()` out of the app entry: a host framework owns the server." })),
|
|
315
|
+
package: Schema.optionalKey(PackageSchema.annotate({
|
|
316
|
+
title: "App package name",
|
|
317
|
+
description: "The name the app entry's package is published as. A client written into another package imports `app` by it; left out, such a client is refused.",
|
|
318
|
+
examples: ["@packages/elysia"]
|
|
319
|
+
})),
|
|
320
|
+
readonly: Schema.optionalKey(Schema.Boolean.annotate({ description: "Wrap every top-level generated schema in `t.Readonly(...)`." })),
|
|
97
321
|
components: Schema.optionalKey(ComponentsSchema),
|
|
322
|
+
client: Schema.optionalKey(ClientOutputSchema),
|
|
98
323
|
eden: Schema.optionalKey(Schema.Struct({
|
|
99
|
-
output: Schema.String,
|
|
100
|
-
import: Schema.String,
|
|
101
|
-
client: Schema.String.pipe(Schema.withDecodingDefault(Effect.succeed("client"))),
|
|
102
|
-
docs: Schema.optionalKey(Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))))
|
|
103
|
-
})),
|
|
104
|
-
types: Schema.optionalKey(Schema.Struct({ output: TypeScriptPathSchema })),
|
|
105
|
-
test: Schema.optionalKey(Schema.Union([Schema.Struct({
|
|
106
|
-
split: Schema.Literal(true),
|
|
107
|
-
pathAlias: Schema.optionalKey(Schema.String)
|
|
108
|
-
}), Schema.Struct({
|
|
109
|
-
split: Schema.Literal(false).pipe(Schema.withDecodingDefault(Effect.succeed(false))),
|
|
110
324
|
output: FileOutputSchema,
|
|
111
|
-
|
|
112
|
-
|
|
325
|
+
...CLIENT_CONSUMER_REMOVED,
|
|
326
|
+
docs: removed("docs was removed: the wrappers carry no JSDoc. Delete the option.")
|
|
327
|
+
}).annotate({
|
|
328
|
+
title: "Eden wrappers output",
|
|
329
|
+
description: "Typed function wrappers around the generated Eden Treaty client, one per operation. Needs `client`.",
|
|
330
|
+
examples: [{ output: "./src/eden.ts" }]
|
|
331
|
+
})),
|
|
332
|
+
types: Schema.optionalKey(Schema.Struct({ output: TypeScriptPathSchema.annotate({
|
|
333
|
+
title: "Output file",
|
|
334
|
+
description: "The `.ts` file the `App` type is written to.",
|
|
335
|
+
examples: ["./src/types.ts"]
|
|
336
|
+
}) }).annotate({
|
|
337
|
+
title: "App type output",
|
|
338
|
+
description: "A self-contained `export type App` for `treaty<App>(...)` clients.",
|
|
339
|
+
examples: [{ output: "./src/types.ts" }]
|
|
340
|
+
})),
|
|
341
|
+
test: Schema.optionalKey(Schema.Never.annotate({ message: "test was removed: asphodelos no longer generates tests. Delete the block and the files the previous run wrote." })),
|
|
113
342
|
mock: Schema.optionalKey(Schema.Struct({
|
|
114
343
|
output: FileOutputSchema,
|
|
115
|
-
useExamples: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Literal("all")])),
|
|
116
|
-
seed: Schema.optionalKey(Schema.Union([SeedSchema, Schema.NonEmptyArray(SeedSchema)])
|
|
117
|
-
|
|
344
|
+
useExamples: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Literal("all")]).annotate({ description: "Answer with the response examples the document writes (default: true), or with `'all'` also the scalar example of every schema and property. `false` uses faker alone." })),
|
|
345
|
+
seed: Schema.optionalKey(Schema.Union([SeedSchema, Schema.NonEmptyArray(SeedSchema)]).annotate({
|
|
346
|
+
description: "Re-seeds faker at the start of every handler, so each route answers the same body on every request.",
|
|
347
|
+
examples: [42, [
|
|
348
|
+
1,
|
|
349
|
+
2,
|
|
350
|
+
3
|
|
351
|
+
]]
|
|
352
|
+
})),
|
|
353
|
+
locale: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[A-Za-z_]{1,40}$/u, { message: "must be a faker locale code such as 'ja', 'en' or 'zh_CN'" })).annotate({
|
|
354
|
+
title: "Faker locale",
|
|
355
|
+
description: "Passed straight through to `@faker-js/faker/locale/<locale>`.",
|
|
356
|
+
examples: [
|
|
357
|
+
"en",
|
|
358
|
+
"ja",
|
|
359
|
+
"zh_CN"
|
|
360
|
+
]
|
|
361
|
+
})),
|
|
118
362
|
delay: Schema.optionalKey(Schema.Union([
|
|
119
363
|
DelayMsSchema,
|
|
120
364
|
Schema.Literal(false),
|
|
@@ -122,19 +366,92 @@ const ConfigSchema = Schema.Struct({
|
|
|
122
366
|
min: DelayMsSchema,
|
|
123
367
|
max: DelayMsSchema
|
|
124
368
|
}).check(Schema.makeFilter(({ min, max }) => min <= max ? void 0 : "delay.min must be <= delay.max"))
|
|
125
|
-
])
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
369
|
+
]).annotate({
|
|
370
|
+
description: "A fixed number of milliseconds, a range to pick from, or `false` for no delay at all.",
|
|
371
|
+
examples: [
|
|
372
|
+
200,
|
|
373
|
+
{
|
|
374
|
+
min: 100,
|
|
375
|
+
max: 800
|
|
376
|
+
},
|
|
377
|
+
false
|
|
378
|
+
]
|
|
379
|
+
})),
|
|
380
|
+
arrayMin: Schema.optionalKey(ArrayLengthSchema.annotate({ description: "Fewest items a generated array holds when the schema sets no `minItems`." })),
|
|
381
|
+
arrayMax: Schema.optionalKey(ArrayLengthSchema.annotate({ description: "Most items a generated array holds when the schema sets no `maxItems`." }))
|
|
382
|
+
}).check(Schema.makeFilter(({ arrayMin, arrayMax }) => arrayMin === void 0 || arrayMax === void 0 || arrayMin <= arrayMax ? void 0 : "arrayMin must be <= arrayMax. Swap the values or remove one.")).annotate({
|
|
383
|
+
title: "Mock server output",
|
|
384
|
+
description: "A standalone Elysia server answering every operation with a faker body.",
|
|
385
|
+
examples: [{
|
|
386
|
+
output: "./src/mock.ts",
|
|
387
|
+
useExamples: true,
|
|
388
|
+
seed: 42,
|
|
389
|
+
delay: false
|
|
390
|
+
}]
|
|
391
|
+
})),
|
|
392
|
+
swr: Schema.optionalKey(HooksSchema.annotate({
|
|
393
|
+
title: "SWR hooks output",
|
|
394
|
+
description: "Generates `useSWR` / `useSWRMutation` hooks per operation.",
|
|
395
|
+
examples: [{ output: "./src/swr.ts" }]
|
|
396
|
+
})),
|
|
397
|
+
"tanstack-query": Schema.optionalKey(HooksSchema.annotate({
|
|
398
|
+
title: "TanStack Query hooks output",
|
|
399
|
+
description: "Generates `@tanstack/react-query` hooks per operation.",
|
|
400
|
+
examples: [{ output: "./src/tanstack-query.ts" }]
|
|
401
|
+
})),
|
|
402
|
+
"preact-query": Schema.optionalKey(HooksSchema.annotate({
|
|
403
|
+
title: "Preact Query hooks output",
|
|
404
|
+
description: "Generates `@tanstack/preact-query` hooks per operation.",
|
|
405
|
+
examples: [{ output: "./src/preact-query.ts" }]
|
|
406
|
+
})),
|
|
407
|
+
"solid-query": Schema.optionalKey(HooksSchema.annotate({
|
|
408
|
+
title: "Solid Query hooks output",
|
|
409
|
+
description: "Generates `@tanstack/solid-query` hooks per operation.",
|
|
410
|
+
examples: [{ output: "./src/solid-query.ts" }]
|
|
411
|
+
})),
|
|
412
|
+
"vue-query": Schema.optionalKey(HooksSchema.annotate({
|
|
413
|
+
title: "Vue Query hooks output",
|
|
414
|
+
description: "Generates `@tanstack/vue-query` hooks per operation.",
|
|
415
|
+
examples: [{ output: "./src/vue-query.ts" }]
|
|
416
|
+
})),
|
|
417
|
+
"svelte-query": Schema.optionalKey(HooksSchema.annotate({
|
|
418
|
+
title: "Svelte Query hooks output",
|
|
419
|
+
description: "Generates `@tanstack/svelte-query` hooks per operation.",
|
|
420
|
+
examples: [{ output: "./src/svelte-query.ts" }]
|
|
421
|
+
})),
|
|
422
|
+
"angular-query": Schema.optionalKey(HooksSchema.annotate({
|
|
423
|
+
title: "Angular Query hooks output",
|
|
424
|
+
description: "Generates `@tanstack/angular-query-experimental` hooks per operation.",
|
|
425
|
+
examples: [{ output: "./src/angular-query.ts" }]
|
|
426
|
+
}))
|
|
427
|
+
}).check(Schema.makeFilter((v) => {
|
|
428
|
+
const declared = [
|
|
429
|
+
["output", v.output ?? "src/index.ts"],
|
|
430
|
+
["components.output", v.components?.output],
|
|
431
|
+
...COMPONENT_KINDS.map((kind) => [`components.${kind}.output`, v.components?.[kind]?.output]),
|
|
432
|
+
["client.output", v.client?.output],
|
|
433
|
+
["eden.output", v.eden?.output],
|
|
434
|
+
["types.output", v.types?.output],
|
|
435
|
+
["mock.output", v.mock?.output],
|
|
436
|
+
...HOOK_KINDS.map((kind) => [`${kind}.output`, v[kind]?.output])
|
|
437
|
+
];
|
|
438
|
+
const seen = /* @__PURE__ */ new Map();
|
|
439
|
+
for (const [field, output] of declared) {
|
|
440
|
+
if (output === void 0) continue;
|
|
441
|
+
const key = posix.normalize(output).replace(/\/+$/u, "");
|
|
442
|
+
const first = seen.get(key);
|
|
443
|
+
if (first !== void 0) return `${field} and ${first} both write to ${output}. Give each generator its own output path.`;
|
|
444
|
+
seen.set(key, field);
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
447
|
+
}, { message: "every generator needs its own output path" }), Schema.makeFilter((v) => {
|
|
448
|
+
const [first] = [...v.eden ? ["eden"] : [], ...HOOK_KINDS.filter((kind) => v[kind] !== void 0)];
|
|
449
|
+
return v.client === void 0 && first !== void 0 ? `${first} needs the top-level client it imports: add client: { output }.` : true;
|
|
450
|
+
}, { message: "every file that calls the client needs the client to be generated" })).annotate({
|
|
451
|
+
title: "asphodelos config",
|
|
452
|
+
description: "Everything `asphodelos` generates from one OpenAPI or TypeSpec document. Only `input` is required; the app entry is always written, and each remaining field opts one generator in."
|
|
136
453
|
});
|
|
137
|
-
const decodeConfig = Schema.decodeUnknownEffect(ConfigSchema);
|
|
454
|
+
const decodeConfig = Schema.decodeUnknownEffect(ConfigSchema, { onExcessProperty: "error" });
|
|
138
455
|
const formatIssue = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
139
456
|
/**
|
|
140
457
|
* Validates an already-loaded config object.
|
|
@@ -195,8 +512,17 @@ function readConfig(configPath, reload = false) {
|
|
|
195
512
|
return yield* parseConfig(mod.default);
|
|
196
513
|
});
|
|
197
514
|
}
|
|
515
|
+
/**
|
|
516
|
+
* The config as it is typed.
|
|
517
|
+
*
|
|
518
|
+
* `ConfigInput` is the schema's own input type, so an option that was removed — typed `never` —
|
|
519
|
+
* and a value of the wrong shape fail here. The rules that need the whole config at once are
|
|
520
|
+
* `parseConfig`'s, reported when the config is read: an unknown key, two generators on one
|
|
521
|
+
* output, a prefix without its slash. The one exception is the client the hooks need, which is
|
|
522
|
+
* told on the hook's key.
|
|
523
|
+
*/
|
|
198
524
|
function defineConfig(config) {
|
|
199
525
|
return config;
|
|
200
526
|
}
|
|
201
527
|
//#endregion
|
|
202
|
-
export { ConfigError, defineConfig, parseConfig, readConfig };
|
|
528
|
+
export { COMPONENT_KINDS, ConfigError, HOOK_KINDS, defineConfig, parseConfig, readConfig };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-wcPFST8Q.mjs";
|
|
2
|
+
import { Data, Effect } from "effect";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
5
|
+
import { NodeHost, compile } from "@typespec/compiler";
|
|
6
|
+
import { getOpenAPI3 } from "@typespec/openapi3";
|
|
7
|
+
//#region src/openapi/index.ts
|
|
8
|
+
var openapi_exports = /* @__PURE__ */ __exportAll({ parseOpenAPI: () => parseOpenAPI });
|
|
9
|
+
/** The document could not be read, compiled or parsed into an OpenAPI object. */
|
|
10
|
+
var OpenAPIError = class extends Data.TaggedError("OpenAPIError") {};
|
|
11
|
+
function parseOpenAPI(input) {
|
|
12
|
+
return Effect.tryPromise({
|
|
13
|
+
try: async () => {
|
|
14
|
+
if (!input.endsWith(".tsp")) return await SwaggerParser.bundle(input);
|
|
15
|
+
const program = await compile(NodeHost, path.resolve(input), { noEmit: true });
|
|
16
|
+
if (program.diagnostics.length > 0) throw new Error(`TypeSpec compile failed:\n${program.diagnostics.map((d) => d.message).join("\n")}`);
|
|
17
|
+
const [record] = await getOpenAPI3(program);
|
|
18
|
+
const document = record && ("document" in record ? record.document : record.versions[0]?.document);
|
|
19
|
+
if (!document) throw new Error(`TypeSpec emitted no OpenAPI document: ${input}`);
|
|
20
|
+
return document;
|
|
21
|
+
},
|
|
22
|
+
catch: (error) => new OpenAPIError({ message: error instanceof Error ? error.message : String(error) })
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { parseOpenAPI as n, openapi_exports as t };
|