zod-codegen 1.6.3 → 1.7.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.
Files changed (120) hide show
  1. package/.github/workflows/ci.yml +50 -48
  2. package/.github/workflows/release.yml +13 -3
  3. package/.husky/commit-msg +1 -1
  4. package/.husky/pre-commit +1 -1
  5. package/.lintstagedrc.json +5 -1
  6. package/.nvmrc +1 -1
  7. package/.prettierrc.json +12 -5
  8. package/CHANGELOG.md +17 -0
  9. package/CONTRIBUTING.md +12 -12
  10. package/EXAMPLES.md +135 -57
  11. package/PERFORMANCE.md +4 -4
  12. package/README.md +87 -64
  13. package/SECURITY.md +1 -1
  14. package/dist/src/cli.js +11 -18
  15. package/dist/src/generator.d.ts +2 -2
  16. package/dist/src/generator.d.ts.map +1 -1
  17. package/dist/src/generator.js +5 -3
  18. package/dist/src/interfaces/code-generator.d.ts.map +1 -1
  19. package/dist/src/services/code-generator.service.d.ts +3 -1
  20. package/dist/src/services/code-generator.service.d.ts.map +1 -1
  21. package/dist/src/services/code-generator.service.js +236 -219
  22. package/dist/src/services/file-reader.service.d.ts +2 -0
  23. package/dist/src/services/file-reader.service.d.ts.map +1 -1
  24. package/dist/src/services/file-reader.service.js +25 -11
  25. package/dist/src/services/file-writer.service.d.ts.map +1 -1
  26. package/dist/src/services/file-writer.service.js +2 -2
  27. package/dist/src/services/import-builder.service.d.ts.map +1 -1
  28. package/dist/src/services/import-builder.service.js +3 -3
  29. package/dist/src/services/type-builder.service.d.ts.map +1 -1
  30. package/dist/src/types/generator-options.d.ts.map +1 -1
  31. package/dist/src/types/openapi.d.ts.map +1 -1
  32. package/dist/src/types/openapi.js +20 -20
  33. package/dist/src/utils/error-handler.d.ts.map +1 -1
  34. package/dist/src/utils/naming-convention.d.ts.map +1 -1
  35. package/dist/src/utils/naming-convention.js +6 -3
  36. package/dist/src/utils/signal-handler.d.ts.map +1 -1
  37. package/dist/tests/integration/cli-comprehensive.test.d.ts +2 -0
  38. package/dist/tests/integration/cli-comprehensive.test.d.ts.map +1 -0
  39. package/dist/tests/integration/cli-comprehensive.test.js +123 -0
  40. package/dist/tests/integration/cli.test.d.ts +2 -0
  41. package/dist/tests/integration/cli.test.d.ts.map +1 -0
  42. package/dist/tests/integration/cli.test.js +25 -0
  43. package/dist/tests/integration/error-scenarios.test.d.ts +2 -0
  44. package/dist/tests/integration/error-scenarios.test.d.ts.map +1 -0
  45. package/dist/tests/integration/error-scenarios.test.js +169 -0
  46. package/dist/tests/integration/snapshots.test.d.ts +2 -0
  47. package/dist/tests/integration/snapshots.test.d.ts.map +1 -0
  48. package/dist/tests/integration/snapshots.test.js +100 -0
  49. package/dist/tests/unit/code-generator-edge-cases.test.d.ts +2 -0
  50. package/dist/tests/unit/code-generator-edge-cases.test.d.ts.map +1 -0
  51. package/dist/tests/unit/code-generator-edge-cases.test.js +506 -0
  52. package/dist/tests/unit/code-generator.test.d.ts +2 -0
  53. package/dist/tests/unit/code-generator.test.d.ts.map +1 -0
  54. package/dist/tests/unit/code-generator.test.js +1364 -0
  55. package/dist/tests/unit/file-reader.test.d.ts +2 -0
  56. package/dist/tests/unit/file-reader.test.d.ts.map +1 -0
  57. package/dist/tests/unit/file-reader.test.js +153 -0
  58. package/dist/tests/unit/generator.test.d.ts +2 -0
  59. package/dist/tests/unit/generator.test.d.ts.map +1 -0
  60. package/dist/tests/unit/generator.test.js +119 -0
  61. package/dist/tests/unit/naming-convention.test.d.ts +2 -0
  62. package/dist/tests/unit/naming-convention.test.d.ts.map +1 -0
  63. package/dist/tests/unit/naming-convention.test.js +256 -0
  64. package/dist/tests/unit/reporter.test.d.ts +2 -0
  65. package/dist/tests/unit/reporter.test.d.ts.map +1 -0
  66. package/dist/tests/unit/reporter.test.js +44 -0
  67. package/dist/tests/unit/type-builder.test.d.ts +2 -0
  68. package/dist/tests/unit/type-builder.test.d.ts.map +1 -0
  69. package/dist/tests/unit/type-builder.test.js +108 -0
  70. package/dist/vitest.config.d.ts.map +1 -1
  71. package/dist/vitest.config.js +10 -20
  72. package/eslint.config.mjs +38 -28
  73. package/examples/.gitkeep +1 -1
  74. package/examples/README.md +4 -2
  75. package/examples/petstore/README.md +18 -17
  76. package/examples/petstore/{type.ts → api.ts} +158 -74
  77. package/examples/petstore/authenticated-usage.ts +6 -4
  78. package/examples/petstore/basic-usage.ts +4 -3
  79. package/examples/petstore/error-handling-usage.ts +84 -0
  80. package/examples/petstore/retry-handler-usage.ts +11 -18
  81. package/examples/petstore/server-variables-usage.ts +10 -10
  82. package/examples/pokeapi/README.md +8 -8
  83. package/examples/pokeapi/api.ts +218 -0
  84. package/examples/pokeapi/basic-usage.ts +3 -2
  85. package/examples/pokeapi/custom-client.ts +5 -4
  86. package/package.json +17 -21
  87. package/src/cli.ts +20 -25
  88. package/src/generator.ts +13 -11
  89. package/src/interfaces/code-generator.ts +1 -1
  90. package/src/services/code-generator.service.ts +799 -1120
  91. package/src/services/file-reader.service.ts +35 -15
  92. package/src/services/file-writer.service.ts +7 -7
  93. package/src/services/import-builder.service.ts +9 -13
  94. package/src/services/type-builder.service.ts +8 -19
  95. package/src/types/generator-options.ts +1 -1
  96. package/src/types/openapi.ts +22 -22
  97. package/src/utils/error-handler.ts +2 -2
  98. package/src/utils/naming-convention.ts +13 -10
  99. package/src/utils/reporter.ts +2 -2
  100. package/src/utils/signal-handler.ts +7 -8
  101. package/tests/integration/cli-comprehensive.test.ts +53 -31
  102. package/tests/integration/cli.test.ts +5 -5
  103. package/tests/integration/error-scenarios.test.ts +20 -26
  104. package/tests/integration/snapshots.test.ts +19 -23
  105. package/tests/unit/code-generator-edge-cases.test.ts +133 -133
  106. package/tests/unit/code-generator.test.ts +431 -330
  107. package/tests/unit/file-reader.test.ts +58 -18
  108. package/tests/unit/generator.test.ts +30 -18
  109. package/tests/unit/naming-convention.test.ts +27 -27
  110. package/tests/unit/type-builder.test.ts +2 -2
  111. package/tsconfig.json +5 -3
  112. package/vitest.config.ts +11 -21
  113. package/dist/scripts/update-manifest.d.ts +0 -14
  114. package/dist/scripts/update-manifest.d.ts.map +0 -1
  115. package/dist/scripts/update-manifest.js +0 -33
  116. package/dist/src/assets/manifest.json +0 -5
  117. package/examples/pokeapi/type.ts +0 -109
  118. package/generated/type.ts +0 -371
  119. package/scripts/update-manifest.ts +0 -49
  120. package/src/assets/manifest.json +0 -5
@@ -1,109 +0,0 @@
1
- // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
- // Built with zod-codegen@1.0.1
3
- // Latest edit: Thu, 13 Nov 2025 13:32:35 GMT
4
- // Source file: ./samples/pokeapi-openapi.json
5
- /* eslint-disable */
6
- // @ts-nocheck
7
-
8
- // Imports
9
- import {z} from 'zod';
10
-
11
- // Components schemas
12
- export const NamedAPIResource = z.object({
13
- name: z.string(),
14
- url: z.string().url(),
15
- });
16
- export const PokemonType = z.object({
17
- slot: z.number().int().optional(),
18
- type: NamedAPIResource.optional(),
19
- });
20
- export const PokemonAbility = z.object({
21
- ability: NamedAPIResource.optional(),
22
- is_hidden: z.boolean().optional(),
23
- slot: z.number().int().optional(),
24
- });
25
- export const PokemonSprites = z.object({
26
- front_default: z.string().url().optional(),
27
- front_shiny: z.string().url().optional(),
28
- back_default: z.string().url().optional(),
29
- back_shiny: z.string().url().optional(),
30
- });
31
- export const Pokemon = z.object({
32
- id: z.number().int(),
33
- name: z.string(),
34
- height: z.number().int().optional(),
35
- weight: z.number().int().optional(),
36
- base_experience: z.number().int().optional(),
37
- types: z.array(PokemonType).optional(),
38
- abilities: z.array(PokemonAbility).optional(),
39
- sprites: PokemonSprites.optional(),
40
- });
41
- export const PokemonListResponse = z.object({
42
- count: z.number().int(),
43
- next: z.string().url().optional(),
44
- previous: z.string().url().optional(),
45
- results: z.array(NamedAPIResource),
46
- });
47
- export const defaultBaseUrl = 'https://pokeapi.co/api/v2';
48
-
49
- // Client class
50
- export class PokAPI {
51
- readonly #baseUrl: string;
52
- constructor(baseUrl: string = defaultBaseUrl, _?: unknown) {
53
- this.#baseUrl = baseUrl;
54
- }
55
- protected getBaseRequestOptions(): Partial<Omit<RequestInit, 'method' | 'body'>> {
56
- return {};
57
- }
58
- async #makeRequest<T>(
59
- method: string,
60
- path: string,
61
- options: _params___Record_string__string___number___boolean___data___unknown__contentType___string__headers___Record_string__string__ = {},
62
- ): Promise<T> {
63
- const baseUrl = `${this.#baseUrl}${path}`;
64
- const url =
65
- options.params && Object.keys(options.params).length > 0
66
- ? (() => {
67
- Object.entries(options.params).forEach(([key, value]) => {
68
- new URL(baseUrl).searchParams.set(key, String(value));
69
- });
70
- return new URL(baseUrl).toString();
71
- })()
72
- : new URL(baseUrl).toString();
73
- const baseOptions = this.getBaseRequestOptions();
74
- const contentType =
75
- options.contentType === 'application/x-www-form-urlencoded'
76
- ? 'application/x-www-form-urlencoded'
77
- : 'application/json';
78
- const baseHeaders = baseOptions.headers !== undefined ? baseOptions.headers : {};
79
- const headers = Object.assign(
80
- {},
81
- baseHeaders,
82
- {'Content-Type': contentType},
83
- options.headers !== undefined ? options.headers : {},
84
- );
85
- const body =
86
- options.data !== undefined
87
- ? options.contentType === 'application/x-www-form-urlencoded'
88
- ? (() => {
89
- const params = new URLSearchParams();
90
- Object.entries(options.data).forEach(([key, value]) => {
91
- params.set(key, String(value));
92
- });
93
- return params.toString();
94
- })()
95
- : JSON.stringify(options.data)
96
- : null;
97
- const response = await fetch(url, Object.assign({}, baseOptions, {method, headers: headers, body: body}));
98
- if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`);
99
- return await response.json();
100
- }
101
- async getPokemonById(id: string): Promise<Pokemon> {
102
- return Pokemon.parse(await this.#makeRequest('GET', `/pokemon/${id}`, {}));
103
- }
104
- async getPokemonList(limit?: number, offset?: number): Promise<PokemonListResponse> {
105
- return PokemonListResponse.parse(
106
- await this.#makeRequest('GET', '/pokemon', {params: {limit: limit, offset: offset}}),
107
- );
108
- }
109
- }
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);
@@ -1,5 +0,0 @@
1
- {
2
- "name": "zod-codegen",
3
- "version": "1.5.0",
4
- "description": "A powerful TypeScript code generator that creates Zod schemas and type-safe clients from OpenAPI specifications"
5
- }