schemantic 0.3.0 → 0.4.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/CHANGELOG.md +204 -174
- package/LICENSE +21 -21
- package/README.md +88 -830
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +185 -61
- package/dist/cli/index.js.map +1 -1
- package/dist/core/configuration.d.ts +6 -0
- package/dist/core/configuration.d.ts.map +1 -0
- package/dist/core/configuration.js +64 -0
- package/dist/core/configuration.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/output-writer.d.ts +7 -0
- package/dist/core/output-writer.d.ts.map +1 -0
- package/dist/core/output-writer.js +255 -0
- package/dist/core/output-writer.js.map +1 -0
- package/dist/core/schemantic.d.ts +8 -2
- package/dist/core/schemantic.d.ts.map +1 -1
- package/dist/core/schemantic.js +196 -71
- package/dist/core/schemantic.js.map +1 -1
- package/dist/generators/api-client-generator.d.ts +10 -20
- package/dist/generators/api-client-generator.d.ts.map +1 -1
- package/dist/generators/api-client-generator.js +374 -424
- package/dist/generators/api-client-generator.js.map +1 -1
- package/dist/generators/base.d.ts.map +1 -1
- package/dist/generators/base.js +7 -25
- package/dist/generators/base.js.map +1 -1
- package/dist/generators/enum-generator.d.ts.map +1 -1
- package/dist/generators/enum-generator.js +30 -3
- package/dist/generators/enum-generator.js.map +1 -1
- package/dist/generators/hook-generator.d.ts +3 -17
- package/dist/generators/hook-generator.d.ts.map +1 -1
- package/dist/generators/hook-generator.js +51 -445
- package/dist/generators/hook-generator.js.map +1 -1
- package/dist/generators/naming.d.ts +10 -0
- package/dist/generators/naming.d.ts.map +1 -0
- package/dist/generators/naming.js +331 -0
- package/dist/generators/naming.js.map +1 -0
- package/dist/generators/object-generator.d.ts +0 -4
- package/dist/generators/object-generator.d.ts.map +1 -1
- package/dist/generators/object-generator.js +13 -101
- package/dist/generators/object-generator.js.map +1 -1
- package/dist/generators/primitive-generator.d.ts +1 -13
- package/dist/generators/primitive-generator.d.ts.map +1 -1
- package/dist/generators/primitive-generator.js +11 -76
- package/dist/generators/primitive-generator.js.map +1 -1
- package/dist/generators/projections.d.ts +10 -0
- package/dist/generators/projections.d.ts.map +1 -0
- package/dist/generators/projections.js +65 -0
- package/dist/generators/projections.js.map +1 -0
- package/dist/generators/schema-type.d.ts +23 -0
- package/dist/generators/schema-type.d.ts.map +1 -0
- package/dist/generators/schema-type.js +233 -0
- package/dist/generators/schema-type.js.map +1 -0
- package/dist/parsers/base.d.ts +2 -0
- package/dist/parsers/base.d.ts.map +1 -1
- package/dist/parsers/base.js +12 -2
- package/dist/parsers/base.js.map +1 -1
- package/dist/parsers/factory.d.ts.map +1 -1
- package/dist/parsers/factory.js +2 -1
- package/dist/parsers/factory.js.map +1 -1
- package/dist/parsers/openapi.d.ts +4 -0
- package/dist/parsers/openapi.d.ts.map +1 -1
- package/dist/parsers/openapi.js +107 -20
- package/dist/parsers/openapi.js.map +1 -1
- package/dist/plugins/branded-types.d.ts.map +1 -1
- package/dist/plugins/branded-types.js +231 -365
- package/dist/plugins/branded-types.js.map +1 -1
- package/dist/plugins/builtin.d.ts.map +1 -1
- package/dist/plugins/builtin.js +6 -141
- package/dist/plugins/builtin.js.map +1 -1
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +17 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/loader.d.ts +5 -1
- package/dist/plugins/loader.d.ts.map +1 -1
- package/dist/plugins/loader.js +42 -5
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/plugins/manager.js +7 -7
- package/dist/plugins/manager.js.map +1 -1
- package/dist/plugins/performance-monitoring.d.ts +31 -1
- package/dist/plugins/performance-monitoring.d.ts.map +1 -1
- package/dist/plugins/performance-monitoring.js +146 -207
- package/dist/plugins/performance-monitoring.js.map +1 -1
- package/dist/plugins/request-deduplication.d.ts.map +1 -1
- package/dist/plugins/request-deduplication.js +151 -586
- package/dist/plugins/request-deduplication.js.map +1 -1
- package/dist/plugins/zod-validation.d.ts +23 -15
- package/dist/plugins/zod-validation.d.ts.map +1 -1
- package/dist/plugins/zod-validation.js +392 -268
- package/dist/plugins/zod-validation.js.map +1 -1
- package/dist/types/core.d.ts +20 -3
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js +2 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types/openapi.d.ts +14 -1
- package/dist/types/openapi.d.ts.map +1 -1
- package/docs/ADVANCED_PLUGINS_IMPLEMENTATION.md +24 -355
- package/docs/ADVANCED_PLUGIN_DEVELOPMENT.md +33 -309
- package/docs/API.md +80 -601
- package/docs/AUDIT.md +49 -0
- package/docs/CONFIGURATION.md +81 -715
- package/docs/FASTAPI_TUTORIAL.md +109 -1497
- package/docs/NAMING_MIGRATION.md +59 -0
- package/docs/PLUGINS.md +49 -687
- package/docs/PLUGIN_DEVELOPMENT.md +53 -720
- package/docs/REAUDIT.md +399 -0
- package/docs/RELEASING.md +88 -0
- package/docs/REMEDIATION.md +58 -0
- package/docs/superpowers/plans/2026-10-10-audit-remediation.md +113 -0
- package/package.json +114 -95
- package/dist/__tests__/setup.d.ts +0 -6
- package/dist/__tests__/setup.d.ts.map +0 -1
- package/dist/__tests__/setup.js +0 -30
- package/dist/__tests__/setup.js.map +0 -1
- package/dist/__tests__/test-config.d.ts +0 -36
- package/dist/__tests__/test-config.d.ts.map +0 -1
- package/dist/__tests__/test-config.js +0 -562
- package/dist/__tests__/test-config.js.map +0 -1
|
@@ -1,309 +1,33 @@
|
|
|
1
|
-
# Advanced
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### Phase 1: Foundation Plugins (Schema Enhancement)
|
|
36
|
-
|
|
37
|
-
#### 1.1 Zod Validation Plugin
|
|
38
|
-
|
|
39
|
-
**Purpose**: Generate Zod schemas from OpenAPI specifications for runtime validation
|
|
40
|
-
|
|
41
|
-
**Architecture Considerations**:
|
|
42
|
-
|
|
43
|
-
- Type-level validation mapping
|
|
44
|
-
- Performance optimization through schema caching
|
|
45
|
-
- Integration with request/response pipelines
|
|
46
|
-
|
|
47
|
-
#### 1.2 Performance Monitoring Plugin
|
|
48
|
-
|
|
49
|
-
**Purpose**: Add instrumentation and performance tracking to generated clients
|
|
50
|
-
|
|
51
|
-
**Architecture Considerations**:
|
|
52
|
-
|
|
53
|
-
- Request timing collection
|
|
54
|
-
- Bundle size analysis
|
|
55
|
-
- Memory usage profiling
|
|
56
|
-
|
|
57
|
-
### Phase 2: Type System Enhancement Plugins
|
|
58
|
-
|
|
59
|
-
#### 2.1 Branded Types Plugin
|
|
60
|
-
|
|
61
|
-
**Purpose**: Generate branded types for compile-time safety guarantees
|
|
62
|
-
|
|
63
|
-
**Architecture Considerations**:
|
|
64
|
-
|
|
65
|
-
- Phantom type parameter implementation
|
|
66
|
-
- Runtime type guard generation
|
|
67
|
-
- Brand preservation through transformation chains
|
|
68
|
-
|
|
69
|
-
#### 2.2 Request Deduplication Plugin
|
|
70
|
-
|
|
71
|
-
**Purpose**: Implement intelligent request deduplication at the client level
|
|
72
|
-
|
|
73
|
-
**Architecture Considerations**:
|
|
74
|
-
|
|
75
|
-
- Request fingerprinting algorithms
|
|
76
|
-
- Cache invalidation strategies
|
|
77
|
-
- Memory management for pending requests
|
|
78
|
-
|
|
79
|
-
### Phase 3: Developer Experience Plugins
|
|
80
|
-
|
|
81
|
-
#### 3.1 Schema Synchronization Plugin
|
|
82
|
-
|
|
83
|
-
**Purpose**: Real-time schema change detection and type regeneration
|
|
84
|
-
|
|
85
|
-
**Architecture Considerations**:
|
|
86
|
-
|
|
87
|
-
- File system watching integration
|
|
88
|
-
- Incremental regeneration algorithms
|
|
89
|
-
- Change impact analysis
|
|
90
|
-
|
|
91
|
-
#### 3.2 Bundle Optimization Plugin
|
|
92
|
-
|
|
93
|
-
**Purpose**: Tree-shakable endpoint generation and bundle size optimization
|
|
94
|
-
|
|
95
|
-
**Architecture Considerations**:
|
|
96
|
-
|
|
97
|
-
- Endpoint modularization strategies
|
|
98
|
-
- Dead code elimination support
|
|
99
|
-
- Dependency graph optimization
|
|
100
|
-
|
|
101
|
-
## Implementation Standards
|
|
102
|
-
|
|
103
|
-
### Plugin Structure Template
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
export const advancedPlugin: SchemanticPlugin = {
|
|
107
|
-
name: "advanced-feature",
|
|
108
|
-
version: "1.0.0",
|
|
109
|
-
description: "Advanced feature implementation with performance optimizations",
|
|
110
|
-
|
|
111
|
-
// Lifecycle hooks with error handling
|
|
112
|
-
beforeGeneration: async (context: GenerationContext) => {
|
|
113
|
-
// Pre-generation setup and validation
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
// Schema transformation with caching
|
|
117
|
-
transformSchema: (schema: ResolvedSchema, context: GenerationContext) => {
|
|
118
|
-
// Schema enhancement with performance considerations
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
// Type generation with sophisticated patterns
|
|
122
|
-
afterTypeGeneration: async (
|
|
123
|
-
typeName: string,
|
|
124
|
-
generatedType: GeneratedType,
|
|
125
|
-
context: GenerationContext
|
|
126
|
-
) => {
|
|
127
|
-
// Type enhancement with advanced TypeScript patterns
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
// Client generation with optimization
|
|
131
|
-
afterClientGeneration: async (
|
|
132
|
-
generatedClient: GeneratedApiClient,
|
|
133
|
-
context: GenerationContext
|
|
134
|
-
) => {
|
|
135
|
-
// Client enhancement with performance optimizations
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Error Handling Standards
|
|
141
|
-
|
|
142
|
-
All plugins must implement comprehensive error handling:
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
try {
|
|
146
|
-
// Plugin logic
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.warn(`Plugin ${plugin.name} operation failed:`, error);
|
|
149
|
-
// Graceful degradation strategy
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Performance Monitoring
|
|
154
|
-
|
|
155
|
-
All plugins should include performance tracking:
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
const startTime = performance.now();
|
|
159
|
-
// Plugin operations
|
|
160
|
-
const endTime = performance.now();
|
|
161
|
-
context.statistics.pluginTiming[plugin.name] = endTime - startTime;
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## Testing Strategy
|
|
165
|
-
|
|
166
|
-
### Unit Testing Requirements
|
|
167
|
-
|
|
168
|
-
Each plugin must include:
|
|
169
|
-
|
|
170
|
-
- Schema transformation tests
|
|
171
|
-
- Type generation verification
|
|
172
|
-
- Performance benchmark tests
|
|
173
|
-
- Error condition handling
|
|
174
|
-
|
|
175
|
-
### Integration Testing
|
|
176
|
-
|
|
177
|
-
Plugin combinations must be tested for:
|
|
178
|
-
|
|
179
|
-
- Interaction conflicts
|
|
180
|
-
- Performance impact
|
|
181
|
-
- Output correctness
|
|
182
|
-
|
|
183
|
-
## Documentation Standards
|
|
184
|
-
|
|
185
|
-
### Plugin Documentation Requirements
|
|
186
|
-
|
|
187
|
-
Each plugin must include:
|
|
188
|
-
|
|
189
|
-
- Purpose and use cases
|
|
190
|
-
- Configuration options
|
|
191
|
-
- Performance characteristics
|
|
192
|
-
- Integration considerations
|
|
193
|
-
- Migration guidelines
|
|
194
|
-
|
|
195
|
-
### API Documentation
|
|
196
|
-
|
|
197
|
-
All generated code must include:
|
|
198
|
-
|
|
199
|
-
- JSDoc comments
|
|
200
|
-
- Type annotations
|
|
201
|
-
- Usage examples
|
|
202
|
-
- Performance notes
|
|
203
|
-
|
|
204
|
-
## Deployment Considerations
|
|
205
|
-
|
|
206
|
-
### Plugin Distribution
|
|
207
|
-
|
|
208
|
-
Plugins can be distributed as:
|
|
209
|
-
|
|
210
|
-
- Built-in plugins (core functionality)
|
|
211
|
-
- External NPM packages
|
|
212
|
-
- Custom project plugins
|
|
213
|
-
|
|
214
|
-
### Configuration Management
|
|
215
|
-
|
|
216
|
-
Plugin configuration follows the standard pattern:
|
|
217
|
-
|
|
218
|
-
```typescript
|
|
219
|
-
{
|
|
220
|
-
plugins: [
|
|
221
|
-
{
|
|
222
|
-
name: "zod-validation",
|
|
223
|
-
enabled: true,
|
|
224
|
-
options: {
|
|
225
|
-
strictMode: true,
|
|
226
|
-
cacheSchemas: true,
|
|
227
|
-
optimizeBundle: true,
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
];
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
## Advanced Implementation Patterns
|
|
235
|
-
|
|
236
|
-
### 1. Lazy Evaluation Strategies
|
|
237
|
-
|
|
238
|
-
Implement lazy evaluation for expensive operations:
|
|
239
|
-
|
|
240
|
-
```typescript
|
|
241
|
-
const lazyValidator = createLazyValidator(() =>
|
|
242
|
-
generateValidationSchema(schema)
|
|
243
|
-
);
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### 2. Memoization Patterns
|
|
247
|
-
|
|
248
|
-
Cache expensive computations:
|
|
249
|
-
|
|
250
|
-
```typescript
|
|
251
|
-
const memoizedTransform = memoize(
|
|
252
|
-
(schema: ResolvedSchema) => transformSchema(schema),
|
|
253
|
-
(schema) => JSON.stringify(schema)
|
|
254
|
-
);
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### 3. Pipeline Composition
|
|
258
|
-
|
|
259
|
-
Enable plugin composition:
|
|
260
|
-
|
|
261
|
-
```typescript
|
|
262
|
-
const pipeline = compose(
|
|
263
|
-
zodValidationPlugin,
|
|
264
|
-
performanceMonitoringPlugin,
|
|
265
|
-
bundleOptimizationPlugin
|
|
266
|
-
);
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
## Performance Optimization Guidelines
|
|
270
|
-
|
|
271
|
-
### Memory Management
|
|
272
|
-
|
|
273
|
-
- Use WeakMap for temporary associations
|
|
274
|
-
- Implement proper cleanup in lifecycle hooks
|
|
275
|
-
- Monitor memory usage in long-running processes
|
|
276
|
-
|
|
277
|
-
### CPU Optimization
|
|
278
|
-
|
|
279
|
-
- Implement efficient algorithms for schema traversal
|
|
280
|
-
- Use worker threads for CPU-intensive operations
|
|
281
|
-
- Cache computed results appropriately
|
|
282
|
-
|
|
283
|
-
### Bundle Size Optimization
|
|
284
|
-
|
|
285
|
-
- Generate tree-shakable modules
|
|
286
|
-
- Implement code splitting strategies
|
|
287
|
-
- Optimize import/export patterns
|
|
288
|
-
|
|
289
|
-
## Future Enhancement Roadmap
|
|
290
|
-
|
|
291
|
-
### Planned Advanced Features
|
|
292
|
-
|
|
293
|
-
1. **GraphQL Bridge Plugin**: Transform REST endpoints into GraphQL-compatible resolvers
|
|
294
|
-
2. **State Machine Integration**: Generate XState machines for complex API workflows
|
|
295
|
-
3. **Real-time Sync Plugin**: WebSocket-based schema synchronization
|
|
296
|
-
4. **AI-Powered Optimization**: Machine learning-based performance recommendations
|
|
297
|
-
|
|
298
|
-
### Research Areas
|
|
299
|
-
|
|
300
|
-
1. **Advanced Type Inference**: Improved type inference from schema patterns
|
|
301
|
-
2. **Cross-Platform Generation**: Support for additional target languages
|
|
302
|
-
3. **Security Enhancement**: Automated security vulnerability detection
|
|
303
|
-
4. **Performance Prediction**: Predictive performance analysis
|
|
304
|
-
|
|
305
|
-
## Conclusion
|
|
306
|
-
|
|
307
|
-
This advanced plugin development framework provides the foundation for sophisticated code generation capabilities that extend far beyond basic OpenAPI type generation. The focus on performance, type safety, and developer experience positions Schemantic as a comprehensive development environment integration tool rather than just a code generator.
|
|
308
|
-
|
|
309
|
-
The plugin architecture enables ecosystem partnerships and network effects that can drive adoption through developer tooling integrations and community contributions.
|
|
1
|
+
# Advanced plugin development
|
|
2
|
+
|
|
3
|
+
Start with the [current plugin interface](PLUGIN_DEVELOPMENT.md). Advanced plugins use that same interface; there is no separate extension API for CLI commands, runtime transport interception, or arbitrary file-write hooks.
|
|
4
|
+
|
|
5
|
+
A generated runtime helper and a generator-process utility are different APIs. Helpers embedded in generated clients are imported from generated files. Public plugin factories/analysis utilities are imported from `schemantic`; do not instruct consumers to import blocked `schemantic/dist/...` paths.
|
|
6
|
+
|
|
7
|
+
## Design contracts
|
|
8
|
+
|
|
9
|
+
- Validation helpers must enforce their documented schema constraints and preserve input data when permissive mode is requested. A cast or shallow object check is not schema validation.
|
|
10
|
+
- Every emitted identifier/import/export must participate in the output graph. Shared declarations must be emitted once. Disabled features must not leave dangling imports/exports.
|
|
11
|
+
- Caching must include every response-affecting request field and explicit session scope. Custom identities need a collision/tenant policy; do not log secret header values.
|
|
12
|
+
- Runtime callbacks belong in factories/constructors. JSON config can carry serializable data only.
|
|
13
|
+
- Timing data must come from observed calls. Source length and synthetic dependency estimates are not real bundle sizes or measured application speedups.
|
|
14
|
+
- Lifecycle failures must fail generation before published output is replaced. Plugins should not write unrelated user files during hooks.
|
|
15
|
+
|
|
16
|
+
## Validation memoization
|
|
17
|
+
|
|
18
|
+
The public utility has a data-first signature:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { memoizedValidation } from 'schemantic';
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
|
|
24
|
+
const schema = z.object({ id: z.number().int() });
|
|
25
|
+
const value = memoizedValidation({ id: 1 }, schema);
|
|
26
|
+
console.log(value.id);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This utility runs in the process that calls it. It does not automatically validate generated endpoint responses or guarantee that generation-time schema memoization is bounded. Cache keys must include schema/version/input context; use the public clear/stat utilities according to their actual implementation.
|
|
30
|
+
|
|
31
|
+
## Acceptance evidence
|
|
32
|
+
|
|
33
|
+
Generate output with multiple schemas and feature switches, compile under strict bundler and NodeNext settings, then execute the generated helpers. Include invalid validator inputs, overlapping calls, tenant separation, expiry, and disabled helper imports. Keep empirical measurements separate from feature assertions. See [advanced capability boundaries](ADVANCED_PLUGINS_IMPLEMENTATION.md).
|