apiwork 0.0.2 → 0.0.4

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.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -4,16 +4,16 @@ import {
4
4
  } from "../chunk-7NDS6XB6.js";
5
5
  import {
6
6
  generate
7
- } from "../chunk-ZP6ZWEPI.js";
7
+ } from "../chunk-HDAQOD6F.js";
8
8
  import {
9
9
  generate as generate2
10
- } from "../chunk-4AJOYIJC.js";
10
+ } from "../chunk-XVH7TUYP.js";
11
11
  import {
12
12
  generate as generate3
13
- } from "../chunk-NQPUJJ3O.js";
13
+ } from "../chunk-6T7CXXXA.js";
14
14
  import {
15
15
  writeFiles
16
- } from "../chunk-QGKZLUZR.js";
16
+ } from "../chunk-KUY3DEBX.js";
17
17
  import "../chunk-MWFEILAW.js";
18
18
 
19
19
  // src/cli.ts
@@ -3,7 +3,7 @@ import {
3
3
  buildSchemas,
4
4
  buildScopeIndex,
5
5
  resolveGenerateOptions
6
- } from "./chunk-QGKZLUZR.js";
6
+ } from "./chunk-KUY3DEBX.js";
7
7
 
8
8
  // src/zod/generate.ts
9
9
  function generate(schema, options = {}) {
@@ -7,7 +7,7 @@ import {
7
7
  resolveDomainIdentifier,
8
8
  resolveEndpointIdentifier,
9
9
  resolveGenerateOptions
10
- } from "./chunk-QGKZLUZR.js";
10
+ } from "./chunk-KUY3DEBX.js";
11
11
  import {
12
12
  camelCase
13
13
  } from "./chunk-MWFEILAW.js";
@@ -63,7 +63,7 @@ var TYPE_MAP = {
63
63
  boolean: "z.boolean()",
64
64
  date: "z.iso.date()",
65
65
  datetime: "z.iso.datetime()",
66
- decimal: "z.number()",
66
+ decimal: "z.coerce.number()",
67
67
  integer: "z.number().int()",
68
68
  number: "z.number()",
69
69
  string: "z.string()",
@@ -288,7 +288,7 @@ function serializeDefault(param) {
288
288
  return "''";
289
289
  }
290
290
  if (typeof value === "string") {
291
- return `'${value}'`;
291
+ return param.type === "decimal" ? value : `'${value}'`;
292
292
  }
293
293
  if (typeof value === "boolean" || typeof value === "number") {
294
294
  return String(value);
@@ -660,7 +660,7 @@ function generateDefinitionType(parts) {
660
660
  if (parts.errorCodes.length > 0) {
661
661
  fields.push(`errors: ${typeName}Errors`);
662
662
  }
663
- return `export interface ${typeName} { ${fields.join("; ")} }`;
663
+ return `export interface ${typeName} { ${fields.join("; ")}; }`;
664
664
  }
665
665
  function generateActionSchemas(parts, lines, references, context) {
666
666
  const { typeName } = parts;
@@ -3,7 +3,7 @@ import {
3
3
  buildSchemas,
4
4
  buildScopeIndex,
5
5
  resolveGenerateOptions
6
- } from "./chunk-QGKZLUZR.js";
6
+ } from "./chunk-KUY3DEBX.js";
7
7
 
8
8
  // src/typescript/generate.ts
9
9
  function generate(schema, options = {}) {
@@ -0,0 +1,79 @@
1
+ import { S as Schema } from './options-BDcqBI1C.js';
2
+ export { A as Action, a as ActionMethod, b as ActionRequest, c as ActionResponse, d as ArrayParam, B as BinaryParam, e as BooleanParam, D as DateParam, f as DatetimeParam, g as DecimalParam, E as Enum, h as ErrorCode, F as FileCase, G as GenerateOptions, I as IdentifierSource, i as Info, j as InfoContact, k as InfoLicense, l as InfoServer, m as IntegerParam, L as LiteralParam, N as NumberParam, O as ObjectParam, n as ObjectType, P as Param, R as RecordParam, o as ReferenceParam, p as Resource, q as StringParam, T as TimeParam, r as Type, U as UnionParam, s as UnionType, t as UnknownParam, u as UuidParam } from './options-BDcqBI1C.js';
3
+
4
+ /**
5
+ * Thrown when an Apiwork schema fails to parse.
6
+ *
7
+ * The {@link Error.cause} property contains the underlying error, such as a
8
+ * network failure from `fetch` or a `SyntaxError` from invalid JSON.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { parse, ParseError } from 'apiwork';
13
+ *
14
+ * try {
15
+ * const schema = await parse.url('http://localhost:3000/api/v1/.apiwork');
16
+ * } catch (error) {
17
+ * if (error instanceof ParseError) {
18
+ * console.error(error.message);
19
+ * console.error(error.cause);
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ declare class ParseError extends Error {
25
+ constructor(message: string, options?: {
26
+ cause?: unknown;
27
+ });
28
+ }
29
+ /**
30
+ * Parses an Apiwork schema from raw JSON data.
31
+ *
32
+ * @param data - The raw schema data.
33
+ * @returns The parsed schema with camelCase keys.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { parse } from 'apiwork';
38
+ *
39
+ * const schema = parse(data);
40
+ * console.log(schema.basePath);
41
+ * ```
42
+ */
43
+ declare function parseData(data: unknown): Schema;
44
+ /**
45
+ * Fetches and parses an Apiwork schema from a URL.
46
+ *
47
+ * @param url - The URL to fetch the `.apiwork` JSON from.
48
+ * @returns The parsed schema with camelCase keys.
49
+ * @throws {@link ParseError} When the fetch fails, returns a non-OK status, or the response is not valid JSON.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { parse } from 'apiwork';
54
+ *
55
+ * const schema = await parse.url('http://localhost:3000/api/v1/.apiwork');
56
+ * ```
57
+ */
58
+ declare function parseUrl(url: string): Promise<Schema>;
59
+ /**
60
+ * Reads and parses an Apiwork schema from a file.
61
+ *
62
+ * @param path - The file path to the `.apiwork` JSON.
63
+ * @returns The parsed schema with camelCase keys.
64
+ * @throws {@link ParseError} When the file cannot be read or contains invalid JSON.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import { parse } from 'apiwork';
69
+ *
70
+ * const schema = await parse.file('./schema.apiwork');
71
+ * ```
72
+ */
73
+ declare function parseFile(path: string): Promise<Schema>;
74
+ declare const parse: typeof parseData & {
75
+ file: typeof parseFile;
76
+ url: typeof parseUrl;
77
+ };
78
+
79
+ export { ParseError, Schema, parse };
@@ -0,0 +1,392 @@
1
+ /**
2
+ * The top-level Apiwork schema representing an API.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { parse } from 'apiwork';
7
+ *
8
+ * const schema = await parse.url('http://localhost:3000/api/v1/.apiwork');
9
+ * console.log(schema.basePath); // '/api/v1'
10
+ * ```
11
+ */
12
+ interface Schema {
13
+ /** The API base path (e.g. `/api/v1`). */
14
+ basePath: string;
15
+ /** The named enum definitions. */
16
+ enums: Enum[];
17
+ /** The error codes the API may emit. */
18
+ errorCodes: ErrorCode[];
19
+ /** The stable 16-character identifier for the API. */
20
+ fingerprint: string;
21
+ /** The API metadata. `null` when unset. */
22
+ info: Info | null;
23
+ /** The locales the API supports. */
24
+ locales: string[];
25
+ /** The resources with nested actions. */
26
+ resources: Resource[];
27
+ /** The named type definitions in topological order. */
28
+ types: Type[];
29
+ }
30
+ /**
31
+ * A named type definition — either an object type or a discriminated union.
32
+ */
33
+ type Type = ObjectType | UnionType;
34
+ /**
35
+ * An object type definition with named fields.
36
+ */
37
+ interface ObjectType {
38
+ /** Whether the type is deprecated. */
39
+ deprecated: boolean;
40
+ /** The description from metadata. `null` when unset. */
41
+ description: string | null;
42
+ /** The example value. `null` when unset. */
43
+ example: unknown;
44
+ /** The names of types this type extends. */
45
+ extends: string[];
46
+ /** The type name. */
47
+ name: string;
48
+ /** Whether the type references itself transitively. */
49
+ recursive: boolean;
50
+ /** The scope the type lives in. `null` for global scope. */
51
+ scope: string | null;
52
+ /** The fields that make up the type. */
53
+ shape: Param[];
54
+ /** The type discriminator. */
55
+ type: 'object';
56
+ }
57
+ /**
58
+ * A discriminated union type with variants.
59
+ */
60
+ interface UnionType {
61
+ /** Whether the type is deprecated. */
62
+ deprecated: boolean;
63
+ /** The description from metadata. `null` when unset. */
64
+ description: string | null;
65
+ /** The discriminator field name. `null` for open unions. */
66
+ discriminator: string | null;
67
+ /** The example value. `null` when unset. */
68
+ example: unknown;
69
+ /** The type name. */
70
+ name: string;
71
+ /** Whether the type references itself transitively. */
72
+ recursive: boolean;
73
+ /** The scope the type lives in. `null` for global scope. */
74
+ scope: string | null;
75
+ /** The type discriminator. */
76
+ type: 'union';
77
+ /** The union variants. */
78
+ variants: Param[];
79
+ }
80
+ /**
81
+ * A parameter in a type shape, request, or response.
82
+ */
83
+ type Param = ArrayParam | BinaryParam | BooleanParam | DateParam | DatetimeParam | DecimalParam | IntegerParam | LiteralParam | NumberParam | ObjectParam | RecordParam | ReferenceParam | StringParam | TimeParam | UnionParam | UnknownParam | UuidParam;
84
+ interface ParamBase {
85
+ deprecated: boolean;
86
+ description: string | null;
87
+ name: string;
88
+ nullable: boolean;
89
+ optional: boolean;
90
+ }
91
+ interface ArrayParam extends ParamBase {
92
+ default?: unknown;
93
+ example: unknown;
94
+ max: number | null;
95
+ min: number | null;
96
+ of: Param | null;
97
+ type: 'array';
98
+ }
99
+ interface BinaryParam extends ParamBase {
100
+ default?: unknown;
101
+ enum: string | undefined;
102
+ example: unknown;
103
+ type: 'binary';
104
+ }
105
+ interface BooleanParam extends ParamBase {
106
+ default?: unknown;
107
+ enum: string | undefined;
108
+ example: unknown;
109
+ type: 'boolean';
110
+ }
111
+ interface DateParam extends ParamBase {
112
+ default?: unknown;
113
+ enum: string | undefined;
114
+ example: unknown;
115
+ type: 'date';
116
+ }
117
+ interface DatetimeParam extends ParamBase {
118
+ default?: unknown;
119
+ enum: string | undefined;
120
+ example: unknown;
121
+ type: 'datetime';
122
+ }
123
+ interface DecimalParam extends ParamBase {
124
+ default?: unknown;
125
+ enum: string | undefined;
126
+ example: unknown;
127
+ max: number | null;
128
+ min: number | null;
129
+ type: 'decimal';
130
+ }
131
+ interface IntegerParam extends ParamBase {
132
+ default?: unknown;
133
+ enum: string | undefined;
134
+ example: unknown;
135
+ format: string | null;
136
+ max: number | null;
137
+ min: number | null;
138
+ type: 'integer';
139
+ }
140
+ interface LiteralParam extends ParamBase {
141
+ type: 'literal';
142
+ value: unknown;
143
+ }
144
+ interface NumberParam extends ParamBase {
145
+ default?: unknown;
146
+ enum: string | undefined;
147
+ example: unknown;
148
+ max: number | null;
149
+ min: number | null;
150
+ type: 'number';
151
+ }
152
+ interface ObjectParam extends ParamBase {
153
+ partial: boolean;
154
+ shape: Param[];
155
+ type: 'object';
156
+ }
157
+ interface RecordParam extends ParamBase {
158
+ default?: unknown;
159
+ example: unknown;
160
+ of: Param | null;
161
+ type: 'record';
162
+ }
163
+ interface ReferenceParam extends ParamBase {
164
+ reference: string;
165
+ tag?: string;
166
+ type: 'reference';
167
+ }
168
+ interface StringParam extends ParamBase {
169
+ default?: unknown;
170
+ enum: string | undefined;
171
+ example: unknown;
172
+ format: string | null;
173
+ max: number | null;
174
+ min: number | null;
175
+ type: 'string';
176
+ }
177
+ interface TimeParam extends ParamBase {
178
+ default?: unknown;
179
+ enum: string | undefined;
180
+ example: unknown;
181
+ type: 'time';
182
+ }
183
+ interface UnionParam extends ParamBase {
184
+ discriminator: string | null;
185
+ type: 'union';
186
+ variants: Param[];
187
+ }
188
+ interface UnknownParam extends ParamBase {
189
+ type: 'unknown';
190
+ }
191
+ interface UuidParam extends ParamBase {
192
+ default?: unknown;
193
+ enum: string | undefined;
194
+ example: unknown;
195
+ type: 'uuid';
196
+ }
197
+ /**
198
+ * A resource grouping actions at a URL path.
199
+ */
200
+ interface Resource {
201
+ /** The actions the resource exposes. */
202
+ actions: Action[];
203
+ /** The resource identifier. */
204
+ identifier: string;
205
+ /** The resource name. */
206
+ name: string;
207
+ /** The identifiers of ancestor resources. */
208
+ parentIdentifiers: string[];
209
+ /** The URL path. */
210
+ path: string;
211
+ /** The nested resources. */
212
+ resources: Resource[];
213
+ /** The scope the resource lives in. `null` for global scope. */
214
+ scope: string | null;
215
+ }
216
+ /**
217
+ * The HTTP method of an action.
218
+ */
219
+ type ActionMethod = 'delete' | 'get' | 'patch' | 'post' | 'put';
220
+ /**
221
+ * An API action at a specific HTTP method and path.
222
+ */
223
+ interface Action {
224
+ /** Whether the action is deprecated. */
225
+ deprecated: boolean;
226
+ /** The description. `null` when unset. */
227
+ description: string | null;
228
+ /** The HTTP method. */
229
+ method: ActionMethod;
230
+ /** The action name. */
231
+ name: string;
232
+ /** The operation ID. `null` when unset. */
233
+ operationId: string | null;
234
+ /** The URL path. */
235
+ path: string;
236
+ /** The names of error codes the action may raise. */
237
+ raises: string[];
238
+ /** The request definition. */
239
+ request: ActionRequest;
240
+ /** The response definition. */
241
+ response: ActionResponse;
242
+ /** The summary. `null` when unset. */
243
+ summary: string | null;
244
+ /** The tags for grouping. */
245
+ tags: string[];
246
+ }
247
+ /**
248
+ * The request definition of an action.
249
+ */
250
+ interface ActionRequest {
251
+ /** The body parameters. */
252
+ body: Param[];
253
+ /** The description. `null` when unset. */
254
+ description: string | null;
255
+ /** The query parameters. */
256
+ query: Param[];
257
+ }
258
+ /**
259
+ * The response definition of an action.
260
+ */
261
+ interface ActionResponse {
262
+ /** The response body. `null` when the action returns no content. */
263
+ body: Param | null;
264
+ /** The description. `null` when unset. */
265
+ description: string | null;
266
+ /** Whether the action returns no content. */
267
+ noContent: boolean;
268
+ }
269
+ /**
270
+ * A named enum definition with string values.
271
+ */
272
+ interface Enum {
273
+ /** Whether the enum is deprecated. */
274
+ deprecated: boolean;
275
+ /** The description. `null` when unset. */
276
+ description: string | null;
277
+ /** The example value. `null` when unset. */
278
+ example: string | null;
279
+ /** The enum name. */
280
+ name: string;
281
+ /** The scope the enum lives in. `null` for global scope. */
282
+ scope: string | null;
283
+ /** The allowed values. */
284
+ values: string[];
285
+ }
286
+ /**
287
+ * An error code the API may emit.
288
+ */
289
+ interface ErrorCode {
290
+ /** The description. `null` when unset. */
291
+ description: string | null;
292
+ /** The error code name. */
293
+ name: string;
294
+ /** The HTTP status code. */
295
+ status: number;
296
+ }
297
+ /**
298
+ * The API metadata.
299
+ */
300
+ interface Info {
301
+ /** The contact info. `null` when unset. */
302
+ contact: InfoContact | null;
303
+ /** The description. `null` when unset. */
304
+ description: string | null;
305
+ /** The license info. `null` when unset. */
306
+ license: InfoLicense | null;
307
+ /** The server URLs. */
308
+ servers: InfoServer[];
309
+ /** The summary. `null` when unset. */
310
+ summary: string | null;
311
+ /** The terms of service URL. `null` when unset. */
312
+ termsOfService: string | null;
313
+ /** The API title. `null` when unset. */
314
+ title: string | null;
315
+ /** The API version. `null` when unset. */
316
+ version: string | null;
317
+ }
318
+ /**
319
+ * The contact info of an API.
320
+ */
321
+ interface InfoContact {
322
+ /** The contact email. `null` when unset. */
323
+ email: string | null;
324
+ /** The contact name. `null` when unset. */
325
+ name: string | null;
326
+ /** The contact URL. `null` when unset. */
327
+ url: string | null;
328
+ }
329
+ /**
330
+ * The license info of an API.
331
+ */
332
+ interface InfoLicense {
333
+ /** The license name. `null` when unset. */
334
+ name: string | null;
335
+ /** The license URL. `null` when unset. */
336
+ url: string | null;
337
+ }
338
+ /**
339
+ * A server URL of an API.
340
+ */
341
+ interface InfoServer {
342
+ /** The description. `null` when unset. */
343
+ description: string | null;
344
+ /** The server URL. `null` when unset. */
345
+ url: string | null;
346
+ }
347
+
348
+ /**
349
+ * The file name case format.
350
+ */
351
+ type FileCase = 'kebab' | 'camel' | 'pascal' | 'snake';
352
+ /**
353
+ * The source category of a generated identifier.
354
+ *
355
+ * - `'domain'` — types and schemas in `domains/` (scoped domain types).
356
+ * - `'api'` — types and schemas in `api.ts` (global domain types).
357
+ * - `'endpoint'` — types and schemas in `endpoints/` (request, response, definition).
358
+ * - `'client'` — sorbus-specific symbols: `Client`, `createClient`, `contract`.
359
+ *
360
+ * @see {@link GenerateOptions.transformIdentifier}
361
+ */
362
+ type IdentifierSource = 'domain' | 'api' | 'endpoint' | 'client';
363
+ /**
364
+ * Options shared by all code generators.
365
+ */
366
+ interface GenerateOptions {
367
+ /** The file name case format. Defaults to `'kebab'`. */
368
+ fileCase?: FileCase;
369
+ /** The import path extension (e.g., `'.js'` for Node ESM). Defaults to `''`. */
370
+ importExtension?: '' | '.js' | '.ts';
371
+ /**
372
+ * Transforms a generated identifier into a new name.
373
+ *
374
+ * Called for every domain type, endpoint type, and client symbol the
375
+ * generator emits. Return `identifier` unchanged to keep the default name.
376
+ *
377
+ * @param identifier - The default identifier the generator would emit.
378
+ * @param source - The source category of the identifier.
379
+ *
380
+ * @example
381
+ * ```ts
382
+ * transformIdentifier: (identifier, source) => {
383
+ * if (source === 'api') return `Api${identifier}`;
384
+ * if (source === 'client' && identifier === 'Client') return 'MyClient';
385
+ * return identifier;
386
+ * }
387
+ * ```
388
+ */
389
+ transformIdentifier?: (identifier: string, source: IdentifierSource) => string;
390
+ }
391
+
392
+ export type { Action as A, BinaryParam as B, DateParam as D, Enum as E, FileCase as F, GenerateOptions as G, IdentifierSource as I, LiteralParam as L, NumberParam as N, ObjectParam as O, Param as P, RecordParam as R, Schema as S, TimeParam as T, UnionParam as U, ActionMethod as a, ActionRequest as b, ActionResponse as c, ArrayParam as d, BooleanParam as e, DatetimeParam as f, DecimalParam as g, ErrorCode as h, Info as i, InfoContact as j, InfoLicense as k, InfoServer as l, IntegerParam as m, ObjectType as n, ReferenceParam as o, Resource as p, StringParam as q, Type as r, UnionType as s, UnknownParam as t, UuidParam as u };
@@ -0,0 +1,49 @@
1
+ import { G as GenerateOptions, S as Schema } from '../options-BDcqBI1C.js';
2
+
3
+ /**
4
+ * Options for the Sorbus generator.
5
+ */
6
+ interface SorbusGenerateOptions extends GenerateOptions {
7
+ /** TypeScript output configuration. */
8
+ typescript?: {
9
+ /** Target TypeScript major version. Defaults to `5`. */
10
+ version?: 5;
11
+ };
12
+ /** Target Sorbus major version. Defaults to `1`. */
13
+ version?: 1;
14
+ /** Zod output configuration. */
15
+ zod?: {
16
+ /** Target Zod major version. Defaults to `4`. */
17
+ version?: 4;
18
+ };
19
+ }
20
+ /**
21
+ * Generates Sorbus contract and client from the Apiwork schema.
22
+ *
23
+ * @param schema - The parsed schema.
24
+ * @param options - The generator options.
25
+ * @returns The generated files, keyed by file path.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { parse } from 'apiwork';
30
+ * import { generate } from 'apiwork/sorbus';
31
+ *
32
+ * const schema = await parse.url('http://localhost:3000/api/v1/.apiwork');
33
+ * const files = generate(schema, {
34
+ * version: 1,
35
+ * zod: { version: 4 },
36
+ * typescript: { version: 5 },
37
+ * fileCase: 'kebab',
38
+ * importExtension: '.js',
39
+ * transformIdentifier: (identifier, source) => {
40
+ * if (source === 'api') return `Api${identifier}`;
41
+ * if (source === 'client' && identifier === 'Client') return 'MyClient';
42
+ * return identifier;
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ declare function generate(schema: Schema, options?: SorbusGenerateOptions): Map<string, string>;
48
+
49
+ export { type SorbusGenerateOptions, generate };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generate
3
- } from "../chunk-ZP6ZWEPI.js";
4
- import "../chunk-QGKZLUZR.js";
3
+ } from "../chunk-HDAQOD6F.js";
4
+ import "../chunk-KUY3DEBX.js";
5
5
  import "../chunk-MWFEILAW.js";
6
6
  export {
7
7
  generate
@@ -0,0 +1,36 @@
1
+ import { G as GenerateOptions, S as Schema } from '../options-BDcqBI1C.js';
2
+
3
+ /**
4
+ * Options for the TypeScript generator.
5
+ */
6
+ interface TypescriptGenerateOptions extends GenerateOptions {
7
+ /** Target TypeScript major version. Defaults to `5`. */
8
+ version?: 5;
9
+ }
10
+ /**
11
+ * Generates TypeScript types from the Apiwork schema.
12
+ *
13
+ * @param schema - The parsed schema.
14
+ * @param options - The generator options.
15
+ * @returns The generated files, keyed by file path.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { parse } from 'apiwork';
20
+ * import { generate } from 'apiwork/typescript';
21
+ *
22
+ * const schema = await parse.url('http://localhost:3000/api/v1/.apiwork');
23
+ * const files = generate(schema, {
24
+ * version: 5,
25
+ * fileCase: 'kebab',
26
+ * importExtension: '.js',
27
+ * transformIdentifier: (identifier, source) => {
28
+ * if (source === 'api') return `Api${identifier}`;
29
+ * return identifier;
30
+ * },
31
+ * });
32
+ * ```
33
+ */
34
+ declare function generate(schema: Schema, options?: TypescriptGenerateOptions): Map<string, string>;
35
+
36
+ export { type TypescriptGenerateOptions, generate };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generate
3
- } from "../chunk-4AJOYIJC.js";
4
- import "../chunk-QGKZLUZR.js";
3
+ } from "../chunk-XVH7TUYP.js";
4
+ import "../chunk-KUY3DEBX.js";
5
5
  import "../chunk-MWFEILAW.js";
6
6
  export {
7
7
  generate
@@ -0,0 +1,42 @@
1
+ import { G as GenerateOptions, S as Schema } from '../options-BDcqBI1C.js';
2
+
3
+ /**
4
+ * Options for the Zod generator.
5
+ */
6
+ interface ZodGenerateOptions extends GenerateOptions {
7
+ /** TypeScript output configuration. */
8
+ typescript?: {
9
+ /** Target TypeScript major version. Defaults to `5`. */
10
+ version?: 5;
11
+ };
12
+ /** Target Zod major version. Defaults to `4`. */
13
+ version?: 4;
14
+ }
15
+ /**
16
+ * Generates Zod schemas from the Apiwork schema.
17
+ *
18
+ * @param schema - The parsed schema.
19
+ * @param options - The generator options.
20
+ * @returns The generated files, keyed by file path.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { parse } from 'apiwork';
25
+ * import { generate } from 'apiwork/zod';
26
+ *
27
+ * const schema = await parse.url('http://localhost:3000/api/v1/.apiwork');
28
+ * const files = generate(schema, {
29
+ * version: 4,
30
+ * typescript: { version: 5 },
31
+ * fileCase: 'kebab',
32
+ * importExtension: '.js',
33
+ * transformIdentifier: (identifier, source) => {
34
+ * if (source === 'api') return `Api${identifier}`;
35
+ * return identifier;
36
+ * },
37
+ * });
38
+ * ```
39
+ */
40
+ declare function generate(schema: Schema, options?: ZodGenerateOptions): Map<string, string>;
41
+
42
+ export { type ZodGenerateOptions, generate };
package/dist/zod/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generate
3
- } from "../chunk-NQPUJJ3O.js";
4
- import "../chunk-QGKZLUZR.js";
3
+ } from "../chunk-6T7CXXXA.js";
4
+ import "../chunk-KUY3DEBX.js";
5
5
  import "../chunk-MWFEILAW.js";
6
6
  export {
7
7
  generate
package/package.json CHANGED
@@ -11,6 +11,7 @@
11
11
  "@biomejs/biome": "2.4.12",
12
12
  "@skiftle/biome-config": "0.0.7",
13
13
  "@types/node": "25.6.0",
14
+ "lefthook": "2.1.2",
14
15
  "tsup": "8.5.1",
15
16
  "typescript": "6.0.2",
16
17
  "vitest": "4.1.4"
@@ -56,5 +57,5 @@
56
57
  "typecheck": "tsc --noEmit"
57
58
  },
58
59
  "type": "module",
59
- "version": "0.0.2"
60
+ "version": "0.0.4"
60
61
  }