@contractspec/lib.contracts-transformers 3.7.6 → 3.7.10

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/README.md CHANGED
@@ -1,95 +1,63 @@
1
1
  # @contractspec/lib.contracts-transformers
2
2
 
3
- Website: https://contractspec.io/
3
+ Website: https://contractspec.io
4
4
 
5
+ **Contract format transformations: import/export between ContractSpec and external formats (OpenAPI, AsyncAPI, etc.).**
5
6
 
6
- Contract format transformations: bidirectional import/export between ContractSpec and external API specification formats.
7
+ ## What It Provides
7
8
 
8
- ## Supported Formats
9
-
10
- - **OpenAPI 3.x** - Import from and export to OpenAPI specifications (JSON/YAML, URL/file)
9
+ - **Layer**: lib.
10
+ - **Consumers**: `lib.contracts-spec`, bundles, CLI.
11
+ - Related ContractSpec packages include `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
12
+ - Related ContractSpec packages include `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
11
13
 
12
14
  ## Installation
13
15
 
14
- ```bash
15
- bun add @contractspec/lib.contracts-transformers
16
- ```
17
-
18
- ## Usage
19
-
20
- ### Export ContractSpec to OpenAPI
21
-
22
- ```typescript
23
- import { openApiForRegistry } from '@contractspec/lib.contracts-transformers/openapi';
24
- import { OperationSpecRegistry } from '@contractspec/lib.contracts-spec';
25
-
26
- const registry = new OperationSpecRegistry();
27
- // ... register your specs ...
16
+ `npm install @contractspec/lib.contracts-transformers`
28
17
 
29
- const openApiDoc = openApiForRegistry(registry, {
30
- title: 'My API',
31
- version: '1.0.0',
32
- description: 'API generated from ContractSpec',
33
- servers: [{ url: 'https://api.example.com' }],
34
- });
35
- ```
18
+ or
36
19
 
37
- ### Import from OpenAPI
20
+ `bun add @contractspec/lib.contracts-transformers`
38
21
 
39
- ```typescript
40
- import { parseOpenApi, importFromOpenApi } from '@contractspec/lib.contracts-transformers/openapi';
41
-
42
- // Parse OpenAPI from file or URL
43
- const openApiDoc = await parseOpenApi('./api.yaml');
44
- // Or from URL
45
- const openApiDoc = await parseOpenApi('https://api.example.com/openapi.json');
46
-
47
- // Convert to ContractSpec specs
48
- const importResult = importFromOpenApi(openApiDoc, {
49
- prefix: 'myApi',
50
- tags: ['users', 'orders'], // Optional: filter by tags
51
- exclude: ['deprecated_endpoint'], // Optional: exclude by operationId
52
- schemaFormat: 'contractspec', // Optional: 'contractspec' | 'zod' | 'json-schema' | 'graphql'
53
- });
54
-
55
- // importResult contains generated spec code as strings
56
- for (const spec of importResult.specs) {
57
- console.log(spec.name, spec.code);
58
- }
59
- ```
22
+ ## Usage
60
23
 
61
- ### Diff ContractSpec vs OpenAPI
24
+ Import the root entrypoint from `@contractspec/lib.contracts-transformers`, or choose a documented subpath when you only need one part of the package surface.
62
25
 
63
- ```typescript
64
- import { diffSpecs } from '@contractspec/lib.contracts-transformers/openapi';
26
+ ## Architecture
65
27
 
66
- const diffs = diffSpecs(existingSpecs, importedSpecs);
28
+ - `src/common` is part of the package's public or composition surface.
29
+ - `src/index.ts` is the root public barrel and package entrypoint.
30
+ - `src/openapi` is part of the package's public or composition surface.
67
31
 
68
- for (const diff of diffs) {
69
- console.log(`${diff.operationId}: ${diff.changes.length} changes`);
70
- for (const change of diff.changes) {
71
- console.log(` - ${change.path}: ${change.type}`);
72
- }
73
- }
74
- ```
32
+ ## Public Entry Points
75
33
 
76
- ## Architecture
34
+ - Export `.` resolves through `./src/index.ts`.
35
+ - Export `./common` resolves through `./src/common/index.ts`.
36
+ - Export `./openapi` resolves through `./src/openapi/index.ts`.
77
37
 
78
- This library is organized by format:
38
+ ## Local Commands
79
39
 
80
- - `openapi/` - OpenAPI 3.x transformations
81
- - `parser.ts` - Parse OpenAPI from JSON/YAML/URL
82
- - `importer.ts` - Convert OpenAPI to ContractSpec
83
- - `exporter.ts` - Convert ContractSpec to OpenAPI
84
- - `differ.ts` - Diff specs for sync operations
85
- - `schema-converter.ts` - JSON Schema <-> SchemaModel conversion
86
- - `common/` - Shared utilities and types
40
+ - `bun run dev` contractspec-bun-build dev
41
+ - `bun run build` bun run prebuild && bun run build:bundle && bun run build:types
42
+ - `bun run test` bun test
43
+ - `bun run lint` bun lint:fix
44
+ - `bun run lint:check` biome check .
45
+ - `bun run lint:fix` biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
46
+ - `bun run typecheck` tsc --noEmit
47
+ - `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
48
+ - `bun run publish:pkg:canary` — bun publish:pkg --tag canary
49
+ - `bun run clean` — rimraf dist .turbo
50
+ - `bun run build:bundle` — contractspec-bun-build transpile
51
+ - `bun run build:types` — contractspec-bun-build types
52
+ - `bun run prebuild` — contractspec-bun-build prebuild
87
53
 
88
- ## Future Formats
54
+ ## Recent Updates
89
55
 
90
- The library is designed to be extensible for additional formats:
56
+ - Replace eslint+prettier by biomejs to optimize speed.
91
57
 
92
- - AsyncAPI (event-driven APIs)
93
- - gRPC/Protobuf
94
- - GraphQL Schema
58
+ ## Notes
95
59
 
60
+ - Core logic must be pure functions with no I/O.
61
+ - Preserve original transport metadata (path/query/header params) for accurate round-trips.
62
+ - Track provenance — where specs came from — for sync operations.
63
+ - `@contractspec/lib.contracts-spec` re-exports this library for existing consumers; avoid breaking that contract.