@appweaver/cli 1.3.0 → 1.3.1
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/package.json +1 -1
- package/skill/references/client.md +40 -6
package/package.json
CHANGED
|
@@ -73,13 +73,18 @@ Reads an OpenAPI v3 schema and generates TypeScript types and a typed client cla
|
|
|
73
73
|
`@maxLength`, `@minimum`, `@maximum`, `@pattern`, `@format`).
|
|
74
74
|
3. Deduplicates union types and extracts inline schemas to named exported types, including the ones carrying a
|
|
75
75
|
description (i.e. `PostQuerySort`).
|
|
76
|
-
4. Hoists the
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
4. Hoists the schemas the document repeats inline into a shared definition each, so the generated types declare them
|
|
77
|
+
once and reference them everywhere else. This covers the enums (every sortable field of every resource shares one
|
|
78
|
+
`SortDirection` rather than declaring an `asc | desc` enum of its own) and the value a filterable field accepts
|
|
79
|
+
(`QueryFilterValue`, built from the plain `QueryFilterScalar`), while every property keeps its own description.
|
|
80
|
+
5. Emits every enum as a constant object plus a type alias of its values, so both the member (`SortDirection.asc`) and
|
|
81
|
+
the plain literal (`'asc'`) are accepted wherever the enum is used. When the types are written to a declaration file
|
|
82
|
+
(`.d.ts`), the constant is declared rather than initialized, since such a file carries no runtime values.
|
|
83
|
+
6. Classifies all API paths into route groups: resources, auth, account, health, files, and custom.
|
|
84
|
+
7. Emits a typed client class extending `FetchClient<Paths>` with a getter for each route group. Resources with
|
|
80
85
|
unsupported operations are excluded at compile time using `Omit`.
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
8. Formats all output with Prettier.
|
|
87
|
+
9. Writes files with an autogenerated header comment.
|
|
83
88
|
|
|
84
89
|
**Examples:**
|
|
85
90
|
|
|
@@ -146,6 +151,35 @@ const sort: PostQuerySort = { createdAt: SortDirection.desc, title: SortDirectio
|
|
|
146
151
|
const posts = await client.post.query({ sort, page: 1, size: 20 });
|
|
147
152
|
```
|
|
148
153
|
|
|
154
|
+
Enums are generated as a constant object together with a type alias of its values, so the members and the raw literals
|
|
155
|
+
are interchangeable and no import is needed for the literal form:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
export const SortDirection = { asc: 'asc', desc: 'desc' } as const;
|
|
159
|
+
export type SortDirection = (typeof SortDirection)[keyof typeof SortDirection];
|
|
160
|
+
|
|
161
|
+
// Both are valid and equally type safe
|
|
162
|
+
const byMember: PostQuerySort = { createdAt: SortDirection.desc };
|
|
163
|
+
const byLiteral: PostQuerySort = { createdAt: 'desc' };
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The value a filterable field accepts is declared once as well, rather than being spelled out again for every field of
|
|
167
|
+
every resource. A scalar field references `QueryFilterValue`, and a relation field adds the filter of the related
|
|
168
|
+
resource to the plain values it accepts:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
export type QueryFilterScalar = string | number | boolean | null;
|
|
172
|
+
export type QueryFilterValue = QueryFilterScalar | QueryFilterScalar[] | QueryCondition;
|
|
173
|
+
|
|
174
|
+
export type PostQueryFilter = {
|
|
175
|
+
/** @description Filter by the title field */
|
|
176
|
+
title?: QueryFilterValue;
|
|
177
|
+
/** @description Filter by the author relation, matching an id, a list of ids, or a nested User filter */
|
|
178
|
+
author?: QueryFilterScalar | QueryFilterScalar[] | UserQueryFilter | UserQueryFilter[];
|
|
179
|
+
// ...
|
|
180
|
+
};
|
|
181
|
+
```
|
|
182
|
+
|
|
149
183
|
### Client file
|
|
150
184
|
|
|
151
185
|
```ts
|