@moinax/orc 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 moinax
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # @moinax/orc
2
+
3
+ **O**penAPI **R**est **C**lient generator — generates typed TypeScript API clients from OpenAPI specs with Zod validation.
4
+
5
+ ## Features
6
+
7
+ - Generates typed TypeScript API clients from OpenAPI 3.x specs
8
+ - Zod schemas for all request/response types with full validation
9
+ - Resource-based architecture (`client.pets.getList()`, `client.pets.create()`)
10
+ - Automatic enum deduplication across schemas
11
+ - Pagination handling built-in
12
+ - Date transformation schemas (string ↔ Date via date-fns)
13
+ - Configurable via `orc.config.ts`
14
+ - Supports both URL and local file specs
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @moinax/orc zod
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ### 1. Create a config file
25
+
26
+ ```bash
27
+ npx orc init
28
+ ```
29
+
30
+ This creates `orc.config.ts`:
31
+
32
+ ```typescript
33
+ import { defineConfig } from '@moinax/orc/config';
34
+
35
+ export default defineConfig({
36
+ clients: [
37
+ {
38
+ name: 'MyApi',
39
+ spec: 'https://api.example.com/openapi.json',
40
+ output: 'src/lib/api/my-api-client',
41
+ },
42
+ ],
43
+ });
44
+ ```
45
+
46
+ ### 2. Generate clients
47
+
48
+ ```bash
49
+ npx orc generate
50
+ ```
51
+
52
+ ### 3. Use the generated client
53
+
54
+ ```typescript
55
+ import { MyApiClient } from './src/lib/api/my-api-client/generated';
56
+
57
+ const client = new MyApiClient('https://api.example.com', {
58
+ getAccessToken: async () => 'your-token',
59
+ });
60
+
61
+ // Typed, validated API calls
62
+ const { data, pagination } = await client.pet.getList({ page: 1, limit: 10 });
63
+ const pet = await client.pet.getDetail(petId);
64
+ const created = await client.pet.create({ name: 'Buddy', species: 'dog' });
65
+ ```
66
+
67
+ ## CLI
68
+
69
+ ```
70
+ orc generate # Generate all clients
71
+ orc generate --client MyApi # Generate a specific client
72
+ orc generate --client MyApi --spec <url> # Override spec URL
73
+ orc init # Scaffold config file
74
+ ```
75
+
76
+ ## Config Reference
77
+
78
+ ```typescript
79
+ import { defineConfig } from '@moinax/orc/config';
80
+
81
+ export default defineConfig({
82
+ // Optional: customize the import path for the runtime package
83
+ // Defaults to '@moinax/orc'
84
+ runtimePackage: '@moinax/orc',
85
+
86
+ clients: [
87
+ {
88
+ // Name used for the generated client class (e.g., MyApiClient)
89
+ name: 'MyApi',
90
+
91
+ // URL or local file path to the OpenAPI spec
92
+ spec: 'https://api.example.com/openapi.json',
93
+
94
+ // Output directory for generated files
95
+ output: 'src/lib/api/my-api-client',
96
+
97
+ // Optional: strip a prefix from all API paths
98
+ // Useful when the spec includes a base path like /public
99
+ stripPathPrefix: '/public',
100
+ },
101
+ ],
102
+ });
103
+ ```
104
+
105
+ ## Generated Output
106
+
107
+ For each client, orc generates:
108
+
109
+ ```
110
+ output/generated/
111
+ ├── schemas.ts # Zod schemas + TypeScript types
112
+ ├── MyApiClient.ts # Client class extending Client
113
+ ├── Resource.ts # Base resource class
114
+ ├── index.ts # Barrel exports
115
+ └── resources/
116
+ ├── index.ts # Resource exports
117
+ ├── Pets.resource.ts # Resource with typed methods
118
+ └── Owners.resource.ts
119
+ ```
120
+
121
+ ## Runtime
122
+
123
+ The package also exports the runtime that generated code depends on:
124
+
125
+ ```typescript
126
+ import {
127
+ Client, // Base HTTP client
128
+ Resource, // Base resource class
129
+ parseSchema, // Zod parse with partial fallback
130
+ ClientError, // HTTP error class
131
+ ParseError, // Zod validation error class
132
+ // Date transform schemas
133
+ stringToDateSchema,
134
+ stringToDaySchema,
135
+ dateToStringSchema,
136
+ dayToStringSchema,
137
+ } from '@moinax/orc';
138
+ ```
139
+
140
+ ### Client Options
141
+
142
+ ```typescript
143
+ const client = new MyApiClient('https://api.example.com', {
144
+ // Async function returning a bearer token
145
+ getAccessToken: async () => token,
146
+
147
+ // Custom response handler
148
+ responseHandler: async (response) => response,
149
+
150
+ // Logger (defaults to console)
151
+ logger: console,
152
+
153
+ // Number of retries for failed GET requests (5xx)
154
+ retries: 3,
155
+ });
156
+ ```
157
+
158
+ ## Development
159
+
160
+ ```bash
161
+ npm install
162
+ npm test # Run tests
163
+ npm run build # Build with tsup
164
+ npm run typecheck # Type check with tsc
165
+ ```
166
+
167
+ ## License
168
+
169
+ MIT