asphodelos 0.3.2 → 0.4.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 +6 -1
- package/dist/cli.mjs +3 -3
- package/dist/index.mjs +1 -1
- package/dist/{shared-nkpRcjdg.mjs → shared-27xlBR7-.mjs} +10 -19
- package/dist/vite-plugin/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -338,7 +338,7 @@ Every operation is named by its method and path: a GET on `/users/{id}` becomes
|
|
|
338
338
|
`getUsersIdQueryKey` and `getUsersIdQueryOptions` beside it; a POST on `/users` becomes
|
|
339
339
|
`usePostUsers`, with `getPostUsersMutationKey` and `getPostUsersMutationOptions`. Path parameters
|
|
340
340
|
come first, then one `options` object, then the library's own trailing argument (a `QueryClient`,
|
|
341
|
-
or Angular
|
|
341
|
+
or an accessor of one in Solid and Svelte; SWR and Angular Query take none):
|
|
342
342
|
|
|
343
343
|
```ts
|
|
344
344
|
const user = useUsersId(
|
|
@@ -358,6 +358,11 @@ your own over the generated one. SWR hooks take `{ swr, options }` instead, wher
|
|
|
358
358
|
`swrKey` (replaces the generated key) and `enabled` (a `false` turns the key into `null`), and
|
|
359
359
|
return the key they used beside SWR's result.
|
|
360
360
|
|
|
361
|
+
Angular Query hooks import `@tanstack/angular-query`, which needs Angular 20.1 or later. Projects
|
|
362
|
+
on the deprecated `@tanstack/angular-query-experimental` install `@tanstack/angular-query` in its
|
|
363
|
+
place before regenerating. The hooks take no `{ injector }` argument: outside an injection context,
|
|
364
|
+
wrap the call in Angular's `runInInjectionContext(injector, () => injectUsersId(...))`.
|
|
365
|
+
|
|
361
366
|
### Infinite Query (`x-pagination`)
|
|
362
367
|
|
|
363
368
|
Set `x-pagination: true` on a GET operation to generate infinite query hooks.
|
package/dist/cli.mjs
CHANGED
|
@@ -4,7 +4,7 @@ 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.
|
|
7
|
+
var version = "0.4.0";
|
|
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";
|
|
@@ -48,7 +48,7 @@ function runJobs(config) {
|
|
|
48
48
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob }] = yield* Effect.promise(() => Promise.all([
|
|
49
49
|
import("./openapi-4yNuDK_n.mjs").then((n) => n.t),
|
|
50
50
|
import("./format-DC258z--.mjs").then((n) => n.r),
|
|
51
|
-
import("./shared-
|
|
51
|
+
import("./shared-27xlBR7-.mjs").then((n) => n.s)
|
|
52
52
|
]));
|
|
53
53
|
const jobs = makeJob(yield* parseOpenAPI(config.input), config);
|
|
54
54
|
yield* cleanSplitOutputs(jobs);
|
|
@@ -86,7 +86,7 @@ function reportJobs(config, previous) {
|
|
|
86
86
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
87
87
|
onSuccess: (report) => Console.log(report)
|
|
88
88
|
}));
|
|
89
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
89
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-27xlBR7-.mjs").then((n) => n.s));
|
|
90
90
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
91
91
|
return {
|
|
92
92
|
inputDirectory,
|
package/dist/index.mjs
CHANGED
|
@@ -432,7 +432,7 @@ const ConfigSchema = Schema.Struct({
|
|
|
432
432
|
})),
|
|
433
433
|
"angular-query": Schema.optionalKey(HooksSchema.annotate({
|
|
434
434
|
title: "Angular Query hooks output",
|
|
435
|
-
description: "Generates `@tanstack/angular-query
|
|
435
|
+
description: "Generates `@tanstack/angular-query` hooks per operation (Angular 20.1 or later).",
|
|
436
436
|
examples: [{ output: "./src/angular-query.ts" }]
|
|
437
437
|
}))
|
|
438
438
|
}).check(Schema.makeFilter((v) => {
|
|
@@ -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)
|
|
2730
|
-
|
|
2731
|
-
|
|
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
|
}
|
|
@@ -3171,17 +3174,6 @@ const QUERY_CLIENT_ACCESSOR_TAIL = {
|
|
|
3171
3174
|
mutation: "() => QueryClient",
|
|
3172
3175
|
imports: ["QueryClient"]
|
|
3173
3176
|
};
|
|
3174
|
-
const INJECT_OPTIONS_TAIL = {
|
|
3175
|
-
name: "injectOptions",
|
|
3176
|
-
query: "InjectQueryOptions",
|
|
3177
|
-
infinite: "InjectInfiniteQueryOptions",
|
|
3178
|
-
mutation: "InjectMutationOptions",
|
|
3179
|
-
imports: [
|
|
3180
|
-
"InjectQueryOptions",
|
|
3181
|
-
"InjectInfiniteQueryOptions",
|
|
3182
|
-
"InjectMutationOptions"
|
|
3183
|
-
]
|
|
3184
|
-
};
|
|
3185
3177
|
const TANSTACK = {
|
|
3186
3178
|
label: "tanstack-query",
|
|
3187
3179
|
packageName: "@tanstack/react-query",
|
|
@@ -3262,7 +3254,7 @@ const HOOK_CONFIGS = {
|
|
|
3262
3254
|
},
|
|
3263
3255
|
"angular-query": {
|
|
3264
3256
|
label: "angular-query",
|
|
3265
|
-
packageName: "@tanstack/angular-query
|
|
3257
|
+
packageName: "@tanstack/angular-query",
|
|
3266
3258
|
hookPrefix: "inject",
|
|
3267
3259
|
queryFn: "injectQuery",
|
|
3268
3260
|
mutationFn: "injectMutation",
|
|
@@ -3270,8 +3262,7 @@ const HOOK_CONFIGS = {
|
|
|
3270
3262
|
useThunk: true,
|
|
3271
3263
|
queryOptionsType: "CreateQueryOptions",
|
|
3272
3264
|
mutationOptionsType: "CreateMutationOptions",
|
|
3273
|
-
infiniteOptionsType: "CreateInfiniteQueryOptions"
|
|
3274
|
-
hookTail: INJECT_OPTIONS_TAIL
|
|
3265
|
+
infiniteOptionsType: "CreateInfiniteQueryOptions"
|
|
3275
3266
|
}
|
|
3276
3267
|
};
|
|
3277
3268
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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-
|
|
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-27xlBR7-.mjs";
|
|
4
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";
|