zod-codegen 1.6.3 → 1.7.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/.github/workflows/ci.yml +50 -48
- package/.github/workflows/release.yml +13 -3
- package/.husky/commit-msg +1 -1
- package/.husky/pre-commit +1 -1
- package/.lintstagedrc.json +5 -1
- package/.nvmrc +1 -1
- package/.prettierrc.json +12 -5
- package/CHANGELOG.md +11 -0
- package/CONTRIBUTING.md +12 -12
- package/EXAMPLES.md +135 -57
- package/PERFORMANCE.md +4 -4
- package/README.md +87 -64
- package/SECURITY.md +1 -1
- package/dist/src/cli.js +11 -18
- package/dist/src/generator.d.ts +2 -2
- package/dist/src/generator.d.ts.map +1 -1
- package/dist/src/generator.js +5 -3
- package/dist/src/interfaces/code-generator.d.ts.map +1 -1
- package/dist/src/services/code-generator.service.d.ts +3 -1
- package/dist/src/services/code-generator.service.d.ts.map +1 -1
- package/dist/src/services/code-generator.service.js +236 -219
- package/dist/src/services/file-reader.service.d.ts.map +1 -1
- package/dist/src/services/file-reader.service.js +1 -1
- package/dist/src/services/file-writer.service.d.ts.map +1 -1
- package/dist/src/services/file-writer.service.js +2 -2
- package/dist/src/services/import-builder.service.d.ts.map +1 -1
- package/dist/src/services/import-builder.service.js +3 -3
- package/dist/src/services/type-builder.service.d.ts.map +1 -1
- package/dist/src/types/generator-options.d.ts.map +1 -1
- package/dist/src/types/openapi.d.ts.map +1 -1
- package/dist/src/types/openapi.js +20 -20
- package/dist/src/utils/error-handler.d.ts.map +1 -1
- package/dist/src/utils/naming-convention.d.ts.map +1 -1
- package/dist/src/utils/naming-convention.js +6 -3
- package/dist/src/utils/signal-handler.d.ts.map +1 -1
- package/dist/tests/integration/cli-comprehensive.test.d.ts +2 -0
- package/dist/tests/integration/cli-comprehensive.test.d.ts.map +1 -0
- package/dist/tests/integration/cli-comprehensive.test.js +110 -0
- package/dist/tests/integration/cli.test.d.ts +2 -0
- package/dist/tests/integration/cli.test.d.ts.map +1 -0
- package/dist/tests/integration/cli.test.js +25 -0
- package/dist/tests/integration/error-scenarios.test.d.ts +2 -0
- package/dist/tests/integration/error-scenarios.test.d.ts.map +1 -0
- package/dist/tests/integration/error-scenarios.test.js +169 -0
- package/dist/tests/integration/snapshots.test.d.ts +2 -0
- package/dist/tests/integration/snapshots.test.d.ts.map +1 -0
- package/dist/tests/integration/snapshots.test.js +100 -0
- package/dist/tests/unit/code-generator-edge-cases.test.d.ts +2 -0
- package/dist/tests/unit/code-generator-edge-cases.test.d.ts.map +1 -0
- package/dist/tests/unit/code-generator-edge-cases.test.js +506 -0
- package/dist/tests/unit/code-generator.test.d.ts +2 -0
- package/dist/tests/unit/code-generator.test.d.ts.map +1 -0
- package/dist/tests/unit/code-generator.test.js +1364 -0
- package/dist/tests/unit/file-reader.test.d.ts +2 -0
- package/dist/tests/unit/file-reader.test.d.ts.map +1 -0
- package/dist/tests/unit/file-reader.test.js +125 -0
- package/dist/tests/unit/generator.test.d.ts +2 -0
- package/dist/tests/unit/generator.test.d.ts.map +1 -0
- package/dist/tests/unit/generator.test.js +119 -0
- package/dist/tests/unit/naming-convention.test.d.ts +2 -0
- package/dist/tests/unit/naming-convention.test.d.ts.map +1 -0
- package/dist/tests/unit/naming-convention.test.js +256 -0
- package/dist/tests/unit/reporter.test.d.ts +2 -0
- package/dist/tests/unit/reporter.test.d.ts.map +1 -0
- package/dist/tests/unit/reporter.test.js +44 -0
- package/dist/tests/unit/type-builder.test.d.ts +2 -0
- package/dist/tests/unit/type-builder.test.d.ts.map +1 -0
- package/dist/tests/unit/type-builder.test.js +108 -0
- package/dist/vitest.config.d.ts.map +1 -1
- package/dist/vitest.config.js +10 -20
- package/eslint.config.mjs +38 -28
- package/examples/.gitkeep +1 -1
- package/examples/README.md +4 -2
- package/examples/petstore/README.md +18 -17
- package/examples/petstore/{type.ts → api.ts} +158 -74
- package/examples/petstore/authenticated-usage.ts +6 -4
- package/examples/petstore/basic-usage.ts +4 -3
- package/examples/petstore/error-handling-usage.ts +84 -0
- package/examples/petstore/retry-handler-usage.ts +11 -18
- package/examples/petstore/server-variables-usage.ts +10 -10
- package/examples/pokeapi/README.md +8 -8
- package/examples/pokeapi/api.ts +218 -0
- package/examples/pokeapi/basic-usage.ts +3 -2
- package/examples/pokeapi/custom-client.ts +5 -4
- package/package.json +17 -21
- package/src/cli.ts +20 -25
- package/src/generator.ts +13 -11
- package/src/interfaces/code-generator.ts +1 -1
- package/src/services/code-generator.service.ts +799 -1120
- package/src/services/file-reader.service.ts +6 -5
- package/src/services/file-writer.service.ts +7 -7
- package/src/services/import-builder.service.ts +9 -13
- package/src/services/type-builder.service.ts +8 -19
- package/src/types/generator-options.ts +1 -1
- package/src/types/openapi.ts +22 -22
- package/src/utils/error-handler.ts +2 -2
- package/src/utils/naming-convention.ts +13 -10
- package/src/utils/reporter.ts +2 -2
- package/src/utils/signal-handler.ts +7 -8
- package/tests/integration/cli-comprehensive.test.ts +38 -32
- package/tests/integration/cli.test.ts +5 -5
- package/tests/integration/error-scenarios.test.ts +20 -26
- package/tests/integration/snapshots.test.ts +19 -23
- package/tests/unit/code-generator-edge-cases.test.ts +133 -133
- package/tests/unit/code-generator.test.ts +431 -330
- package/tests/unit/file-reader.test.ts +14 -14
- package/tests/unit/generator.test.ts +30 -18
- package/tests/unit/naming-convention.test.ts +27 -27
- package/tests/unit/type-builder.test.ts +2 -2
- package/tsconfig.json +5 -3
- package/vitest.config.ts +11 -21
- package/dist/scripts/update-manifest.d.ts +0 -14
- package/dist/scripts/update-manifest.d.ts.map +0 -1
- package/dist/scripts/update-manifest.js +0 -33
- package/dist/src/assets/manifest.json +0 -5
- package/examples/pokeapi/type.ts +0 -109
- package/generated/type.ts +0 -371
- package/scripts/update-manifest.ts +0 -49
- package/src/assets/manifest.json +0 -5
package/generated/type.ts
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
-
// Built with zod-codegen@1.6.3
|
|
3
|
-
// Latest edit: Thu, 22 Jan 2026 16:08:32 GMT
|
|
4
|
-
// Source file: ./samples/swagger-petstore.yaml
|
|
5
|
-
/* eslint-disable */
|
|
6
|
-
// @ts-nocheck
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// Imports
|
|
10
|
-
;
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
|
|
13
|
-
// Explicit type declarations
|
|
14
|
-
;
|
|
15
|
-
export interface Order {
|
|
16
|
-
id?: number;
|
|
17
|
-
petId?: number;
|
|
18
|
-
quantity?: number;
|
|
19
|
-
shipDate?: string;
|
|
20
|
-
status?: 'placed' | 'approved' | 'delivered';
|
|
21
|
-
complete?: boolean;
|
|
22
|
-
}
|
|
23
|
-
export interface Address {
|
|
24
|
-
street?: string;
|
|
25
|
-
city?: string;
|
|
26
|
-
state?: string;
|
|
27
|
-
zip?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface Customer {
|
|
30
|
-
id?: number;
|
|
31
|
-
username?: string;
|
|
32
|
-
address?: Address[];
|
|
33
|
-
}
|
|
34
|
-
export interface Category {
|
|
35
|
-
id?: number;
|
|
36
|
-
name?: string;
|
|
37
|
-
}
|
|
38
|
-
export interface User {
|
|
39
|
-
id?: number;
|
|
40
|
-
username?: string;
|
|
41
|
-
firstName?: string;
|
|
42
|
-
lastName?: string;
|
|
43
|
-
email?: string;
|
|
44
|
-
password?: string;
|
|
45
|
-
phone?: string;
|
|
46
|
-
userStatus?: number;
|
|
47
|
-
}
|
|
48
|
-
export interface Tag {
|
|
49
|
-
id?: number;
|
|
50
|
-
name?: string;
|
|
51
|
-
}
|
|
52
|
-
export interface Pet {
|
|
53
|
-
id?: number;
|
|
54
|
-
name: string;
|
|
55
|
-
category?: Category;
|
|
56
|
-
photoUrls: string[];
|
|
57
|
-
tags?: Tag[];
|
|
58
|
-
status?: 'available' | 'pending' | 'sold';
|
|
59
|
-
}
|
|
60
|
-
export interface ApiResponse {
|
|
61
|
-
code?: number;
|
|
62
|
-
type?: string;
|
|
63
|
-
message?: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Components schemas
|
|
67
|
-
;
|
|
68
|
-
export const Order: z.ZodType<Order> = z.object({
|
|
69
|
-
id: z.number().int().optional(),
|
|
70
|
-
petId: z.number().int().optional(),
|
|
71
|
-
quantity: z.number().int().optional(),
|
|
72
|
-
shipDate: z.iso.datetime({
|
|
73
|
-
local: true
|
|
74
|
-
}).optional(),
|
|
75
|
-
status: z.enum(['placed', 'approved', 'delivered']).optional(),
|
|
76
|
-
complete: z.boolean().optional()
|
|
77
|
-
});
|
|
78
|
-
export const Address: z.ZodType<Address> = z.object({
|
|
79
|
-
street: z.string().optional(),
|
|
80
|
-
city: z.string().optional(),
|
|
81
|
-
state: z.string().optional(),
|
|
82
|
-
zip: z.string().optional()
|
|
83
|
-
});
|
|
84
|
-
export const Customer: z.ZodType<Customer> = z.object({
|
|
85
|
-
id: z.number().int().optional(),
|
|
86
|
-
username: z.string().optional(),
|
|
87
|
-
address: z.array(Address).optional()
|
|
88
|
-
});
|
|
89
|
-
export const Category: z.ZodType<Category> = z.object({
|
|
90
|
-
id: z.number().int().optional(),
|
|
91
|
-
name: z.string().optional()
|
|
92
|
-
});
|
|
93
|
-
export const User: z.ZodType<User> = z.object({
|
|
94
|
-
id: z.number().int().optional(),
|
|
95
|
-
username: z.string().optional(),
|
|
96
|
-
firstName: z.string().optional(),
|
|
97
|
-
lastName: z.string().optional(),
|
|
98
|
-
email: z.string().optional(),
|
|
99
|
-
password: z.string().optional(),
|
|
100
|
-
phone: z.string().optional(),
|
|
101
|
-
userStatus: z.number().int().optional()
|
|
102
|
-
});
|
|
103
|
-
export const Tag: z.ZodType<Tag> = z.object({
|
|
104
|
-
id: z.number().int().optional(),
|
|
105
|
-
name: z.string().optional()
|
|
106
|
-
});
|
|
107
|
-
export const Pet: z.ZodType<Pet> = z.object({
|
|
108
|
-
id: z.number().int().optional(),
|
|
109
|
-
name: z.string(),
|
|
110
|
-
category: Category.optional(),
|
|
111
|
-
photoUrls: z.array(z.string()),
|
|
112
|
-
tags: z.array(Tag).optional(),
|
|
113
|
-
status: z.enum(['available', 'pending', 'sold']).optional()
|
|
114
|
-
});
|
|
115
|
-
export const ApiResponse: z.ZodType<ApiResponse> = z.object({
|
|
116
|
-
code: z.number().int().optional(),
|
|
117
|
-
type: z.string().optional(),
|
|
118
|
-
message: z.string().optional()
|
|
119
|
-
});
|
|
120
|
-
export const serverConfigurations = [{
|
|
121
|
-
url: 'https://petstore3.swagger.io/api/v3'
|
|
122
|
-
}];
|
|
123
|
-
export const defaultBaseUrl = 'https://petstore3.swagger.io/api/v3';
|
|
124
|
-
export type ClientOptions = {
|
|
125
|
-
baseUrl?: string;
|
|
126
|
-
serverIndex?: number;
|
|
127
|
-
serverVariables?: Record<string, string>;
|
|
128
|
-
};
|
|
129
|
-
function resolveServerUrl(serverIndex?: number | undefined, serverVariables?: Record<string, string> = {}): string {
|
|
130
|
-
const configs = [{
|
|
131
|
-
url: 'https://petstore3.swagger.io/api/v3'
|
|
132
|
-
}];
|
|
133
|
-
const idx = serverIndex ?? 0;
|
|
134
|
-
if (idx < configs.length) {
|
|
135
|
-
const config = configs[idx];
|
|
136
|
-
let url = config.url;
|
|
137
|
-
if (config.variables && serverVariables) {
|
|
138
|
-
for (const [key, value] of Object.entries(serverVariables)) {
|
|
139
|
-
url = url.replace(new RegExp("\\{" + key + "\\}", "g"), value);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return url;
|
|
143
|
-
}
|
|
144
|
-
return 'https://petstore3.swagger.io/api/v3';
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Client class
|
|
148
|
-
;
|
|
149
|
-
export default class SwaggerPetstoreOpenAPI30 {
|
|
150
|
-
readonly #baseUrl: string;
|
|
151
|
-
constructor(options: ClientOptions) {
|
|
152
|
-
const resolvedUrl = options.baseUrl !== null ? options.baseUrl : resolveServerUrl(options.serverIndex, options.serverVariables);
|
|
153
|
-
this.#baseUrl = resolvedUrl;
|
|
154
|
-
}
|
|
155
|
-
protected getBaseRequestOptions(): Partial<Omit<RequestInit, 'method' | 'body'>> {
|
|
156
|
-
return {};
|
|
157
|
-
}
|
|
158
|
-
protected async handleResponse<T>(response: Response, method: string, path: string, options: _params___Record_string__string___number___boolean___data___unknown__contentType___string__headers___Record_string__string__): Promise<Response> {
|
|
159
|
-
return response;
|
|
160
|
-
}
|
|
161
|
-
protected async makeRequest<T>(method: string, path: string, options: _params___Record_string__string___number___boolean___data___unknown__contentType___string__headers___Record_string__string__ = {}): Promise<T> {
|
|
162
|
-
const baseUrl = new URL(path, this.#baseUrl);
|
|
163
|
-
const url = options.params && Object.keys(options.params).length > 0 ? (() => {
|
|
164
|
-
Object.entries(options.params).filter(([, value]) => value !== undefined).forEach(([key, value]) => { baseUrl.searchParams.set(key, String(value)); });
|
|
165
|
-
return baseUrl.toString();
|
|
166
|
-
})() : baseUrl.toString();
|
|
167
|
-
const baseOptions = this.getBaseRequestOptions();
|
|
168
|
-
const contentType = options.contentType === 'application/x-www-form-urlencoded' ? 'application/x-www-form-urlencoded' : 'application/json';
|
|
169
|
-
const baseHeaders = baseOptions.headers !== undefined ? baseOptions.headers : {};
|
|
170
|
-
const headers = Object.assign({}, baseHeaders, { 'Content-Type': contentType }, options.headers !== undefined ? options.headers : {});
|
|
171
|
-
const body = options.data !== undefined ? options.contentType === 'application/x-www-form-urlencoded' ? (() => { const params = new URLSearchParams(); Object.entries(options.data).forEach(([key, value]) => { params.set(key, String(value)); }); return params.toString(); })() : JSON.stringify(options.data) : null;
|
|
172
|
-
const rawResponse = await fetch(url, Object.assign({}, baseOptions, { method, headers: headers, body: body }));
|
|
173
|
-
const response = await this.handleResponse<T>(rawResponse, method, path, options);
|
|
174
|
-
if (!response.ok)
|
|
175
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
176
|
-
return await response.json();
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Add a new pet to the store
|
|
180
|
-
* @param body Create a new pet in the store
|
|
181
|
-
* @returns {Pet}
|
|
182
|
-
*/
|
|
183
|
-
async addPet(body: Pet): Promise<Pet> {
|
|
184
|
-
return Pet.parse(await this.makeRequest('POST', '/pet', { data: body, contentType: 'application/x-www-form-urlencoded' }));
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Update an existing pet
|
|
188
|
-
*
|
|
189
|
-
* Update an existing pet by Id
|
|
190
|
-
* @param body Update an existent pet in the store
|
|
191
|
-
* @returns {Pet}
|
|
192
|
-
*/
|
|
193
|
-
async updatePet(body: Pet): Promise<Pet> {
|
|
194
|
-
return Pet.parse(await this.makeRequest('PUT', '/pet', { data: body, contentType: 'application/x-www-form-urlencoded' }));
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Finds Pets by status
|
|
198
|
-
*
|
|
199
|
-
* Multiple status values can be provided with comma separated strings
|
|
200
|
-
*
|
|
201
|
-
* @param status Status values that need to be considered for filter
|
|
202
|
-
* @returns {Pet[]}
|
|
203
|
-
*/
|
|
204
|
-
async findPetsByStatus(status?: string): Promise<Pet[]> {
|
|
205
|
-
return await this.makeRequest('GET', '/pet/findByStatus', { params: { 'status': status } });
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Finds Pets by tags
|
|
209
|
-
*
|
|
210
|
-
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
211
|
-
*
|
|
212
|
-
* @param tags Tags to filter by
|
|
213
|
-
* @returns {Pet[]}
|
|
214
|
-
*/
|
|
215
|
-
async findPetsByTags(tags?: string[]): Promise<Pet[]> {
|
|
216
|
-
return await this.makeRequest('GET', '/pet/findByTags', { params: { 'tags': tags } });
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Find pet by ID
|
|
220
|
-
*
|
|
221
|
-
* Returns a single pet
|
|
222
|
-
*
|
|
223
|
-
* @param petId ID of pet to return
|
|
224
|
-
* @returns {Pet}
|
|
225
|
-
*/
|
|
226
|
-
async getPetById(petId: number): Promise<Pet> {
|
|
227
|
-
return Pet.parse(await this.makeRequest('GET', `/pet/${petId}`, {}));
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Updates a pet in the store with form data
|
|
231
|
-
*
|
|
232
|
-
* @param petId ID of pet that needs to be updated
|
|
233
|
-
* @param name Name of pet that needs to be updated
|
|
234
|
-
* @param status Status of pet that needs to be updated
|
|
235
|
-
* @returns {void}
|
|
236
|
-
*/
|
|
237
|
-
async updatePetWithForm(petId: number, name?: string, status?: string): Promise<void> {
|
|
238
|
-
return await this.makeRequest('POST', `/pet/${petId}`, { params: { 'name': name, 'status': status } });
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Deletes a pet
|
|
242
|
-
*
|
|
243
|
-
* delete a pet
|
|
244
|
-
*
|
|
245
|
-
* @param api_key
|
|
246
|
-
* @param petId Pet id to delete
|
|
247
|
-
* @returns {void}
|
|
248
|
-
*/
|
|
249
|
-
async deletePet(petId: number): Promise<void> {
|
|
250
|
-
return await this.makeRequest('DELETE', `/pet/${petId}`, {});
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* uploads an image
|
|
254
|
-
*
|
|
255
|
-
* @param petId ID of pet to update
|
|
256
|
-
* @param additionalMetadata Additional Metadata
|
|
257
|
-
* @param body
|
|
258
|
-
* @returns {ApiResponse}
|
|
259
|
-
*/
|
|
260
|
-
async uploadFile(petId: number, additionalMetadata?: string): Promise<ApiResponse> {
|
|
261
|
-
return ApiResponse.parse(await this.makeRequest('POST', `/pet/${petId}/uploadImage`, { params: { 'additionalMetadata': additionalMetadata } }));
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Returns pet inventories by status
|
|
265
|
-
*
|
|
266
|
-
* Returns a map of status codes to quantities
|
|
267
|
-
* @returns {Record<string, unknown>}
|
|
268
|
-
*/
|
|
269
|
-
async getInventory(): Promise<Record<string, unknown>> {
|
|
270
|
-
return await this.makeRequest('GET', '/store/inventory', {});
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Place an order for a pet
|
|
274
|
-
*
|
|
275
|
-
* Place a new order in the store
|
|
276
|
-
* @param body
|
|
277
|
-
* @returns {Order}
|
|
278
|
-
*/
|
|
279
|
-
async placeOrder(body?: Order): Promise<Order> {
|
|
280
|
-
return Order.parse(await this.makeRequest('POST', '/store/order', { data: body, contentType: 'application/x-www-form-urlencoded' }));
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Find purchase order by ID
|
|
284
|
-
*
|
|
285
|
-
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
|
|
286
|
-
*
|
|
287
|
-
* @param orderId ID of order that needs to be fetched
|
|
288
|
-
* @returns {Order}
|
|
289
|
-
*/
|
|
290
|
-
async getOrderById(orderId: number): Promise<Order> {
|
|
291
|
-
return Order.parse(await this.makeRequest('GET', `/store/order/${orderId}`, {}));
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Delete purchase order by ID
|
|
295
|
-
*
|
|
296
|
-
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
|
297
|
-
*
|
|
298
|
-
* @param orderId ID of the order that needs to be deleted
|
|
299
|
-
* @returns {void}
|
|
300
|
-
*/
|
|
301
|
-
async deleteOrder(orderId: number): Promise<void> {
|
|
302
|
-
return await this.makeRequest('DELETE', `/store/order/${orderId}`, {});
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Create user
|
|
306
|
-
*
|
|
307
|
-
* This can only be done by the logged in user.
|
|
308
|
-
* @param body Created user object
|
|
309
|
-
* @returns {User}
|
|
310
|
-
*/
|
|
311
|
-
async createUser(body?: User): Promise<User> {
|
|
312
|
-
return User.parse(await this.makeRequest('POST', '/user', { data: body, contentType: 'application/x-www-form-urlencoded' }));
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Creates list of users with given input array
|
|
316
|
-
* @param body
|
|
317
|
-
* @returns {User}
|
|
318
|
-
*/
|
|
319
|
-
async createUsersWithListInput(body?: User[]): Promise<User> {
|
|
320
|
-
return User.parse(await this.makeRequest('POST', '/user/createWithList', { data: body }));
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Logs user into the system
|
|
324
|
-
*
|
|
325
|
-
* @param username The user name for login
|
|
326
|
-
* @param password The password for login in clear text
|
|
327
|
-
* @returns {string}
|
|
328
|
-
*/
|
|
329
|
-
async loginUser(username?: string, password?: string): Promise<string> {
|
|
330
|
-
return await this.makeRequest('GET', '/user/login', { params: { 'username': username, 'password': password } });
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Logs out current logged in user session
|
|
334
|
-
* @returns {void}
|
|
335
|
-
*/
|
|
336
|
-
async logoutUser(): Promise<void> {
|
|
337
|
-
return await this.makeRequest('GET', '/user/logout', {});
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Get user by user name
|
|
341
|
-
*
|
|
342
|
-
* @param username The name that needs to be fetched. Use user1 for testing.
|
|
343
|
-
* @returns {User}
|
|
344
|
-
*/
|
|
345
|
-
async getUserByName(username: string): Promise<User> {
|
|
346
|
-
return User.parse(await this.makeRequest('GET', `/user/${username}`, {}));
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Update user
|
|
350
|
-
*
|
|
351
|
-
* This can only be done by the logged in user.
|
|
352
|
-
*
|
|
353
|
-
* @param username name that need to be deleted
|
|
354
|
-
* @param body Update an existent user in the store
|
|
355
|
-
* @returns {void}
|
|
356
|
-
*/
|
|
357
|
-
async updateUser(username: string, body?: User): Promise<void> {
|
|
358
|
-
return await this.makeRequest('PUT', `/user/${username}`, { data: body, contentType: 'application/x-www-form-urlencoded' });
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Delete user
|
|
362
|
-
*
|
|
363
|
-
* This can only be done by the logged in user.
|
|
364
|
-
*
|
|
365
|
-
* @param username The name that needs to be deleted
|
|
366
|
-
* @returns {void}
|
|
367
|
-
*/
|
|
368
|
-
async deleteUser(username: string): Promise<void> {
|
|
369
|
-
return await this.makeRequest('DELETE', `/user/${username}`, {});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {readFileSync, writeFileSync} from 'node:fs';
|
|
2
|
-
import {dirname, resolve} from 'node:path';
|
|
3
|
-
import {fileURLToPath} from 'node:url';
|
|
4
|
-
import {z} from 'zod';
|
|
5
|
-
|
|
6
|
-
interface PackageJson {
|
|
7
|
-
name: string;
|
|
8
|
-
version: string;
|
|
9
|
-
description: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Type guard for the package.json object
|
|
14
|
-
*
|
|
15
|
-
* @param input Unknown input
|
|
16
|
-
* @returns true if the input is an event object
|
|
17
|
-
*/
|
|
18
|
-
export function isPackageJson(input: unknown): input is PackageJson {
|
|
19
|
-
const event = z
|
|
20
|
-
.object({
|
|
21
|
-
name: z.string(),
|
|
22
|
-
version: z.string(),
|
|
23
|
-
description: z.string(),
|
|
24
|
-
})
|
|
25
|
-
.strict()
|
|
26
|
-
.catchall(z.any())
|
|
27
|
-
.required();
|
|
28
|
-
|
|
29
|
-
const {success} = event.safeParse(input);
|
|
30
|
-
|
|
31
|
-
return success;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
35
|
-
const sourcePath = resolve(__dirname, '..', 'package.json');
|
|
36
|
-
|
|
37
|
-
const data: unknown = JSON.parse(readFileSync(sourcePath, 'utf8'));
|
|
38
|
-
|
|
39
|
-
if (!isPackageJson(data)) {
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const {name, version, description} = data;
|
|
44
|
-
|
|
45
|
-
const targetPath = resolve(__dirname, '..', 'src', 'assets', 'manifest.json');
|
|
46
|
-
|
|
47
|
-
writeFileSync(targetPath, JSON.stringify({name, version, description}, null, 2));
|
|
48
|
-
|
|
49
|
-
process.exit(0);
|