osury 0.2.0 → 0.3.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/README.md +13 -3
- package/bin/osury.mjs +7 -0
- package/package.json +1 -1
- package/src/Codegen.res.mjs +9 -1
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@ Generate ReScript types with [Sury](https://github.com/DZakh/sury) schemas from
|
|
|
9
9
|
- `@genType` for TypeScript interop
|
|
10
10
|
- Union types extracted as proper variants with `@tag("_tag")`
|
|
11
11
|
- Automatic deduplication of identical union structures
|
|
12
|
+
- Generates `module S = Sury` alias (required by sury-ppx)
|
|
13
|
+
- Generates `Dict.gen.tsx` shim for TypeScript interop
|
|
12
14
|
|
|
13
15
|
## Installation
|
|
14
16
|
|
|
@@ -21,11 +23,12 @@ npm install -D osury
|
|
|
21
23
|
### CLI
|
|
22
24
|
|
|
23
25
|
```bash
|
|
24
|
-
# Generate to default ./Generated.res
|
|
26
|
+
# Generate to default ./Generated.res + ./Dict.gen.tsx
|
|
25
27
|
npx osury openapi.json
|
|
26
28
|
|
|
27
|
-
# Generate to specific
|
|
29
|
+
# Generate to specific directory
|
|
28
30
|
npx osury openapi.json src/API.res
|
|
31
|
+
# Creates: src/API.res + src/Dict.gen.tsx
|
|
29
32
|
|
|
30
33
|
# With explicit output flag
|
|
31
34
|
npx osury generate openapi.json -o src/Schema.res
|
|
@@ -57,8 +60,10 @@ Input:
|
|
|
57
60
|
}
|
|
58
61
|
```
|
|
59
62
|
|
|
60
|
-
Output:
|
|
63
|
+
Output (`Schema.res`):
|
|
61
64
|
```rescript
|
|
65
|
+
module S = Sury
|
|
66
|
+
|
|
62
67
|
@genType
|
|
63
68
|
@tag("_tag")
|
|
64
69
|
@schema
|
|
@@ -73,6 +78,11 @@ type user = {
|
|
|
73
78
|
}
|
|
74
79
|
```
|
|
75
80
|
|
|
81
|
+
Also generates `Dict.gen.tsx`:
|
|
82
|
+
```typescript
|
|
83
|
+
export type t<T> = { [key: string]: T };
|
|
84
|
+
```
|
|
85
|
+
|
|
76
86
|
## Generated Annotations
|
|
77
87
|
|
|
78
88
|
| Annotation | Purpose |
|
package/bin/osury.mjs
CHANGED
|
@@ -79,8 +79,15 @@ function generate(inputPath, outputPath) {
|
|
|
79
79
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// Write main ReScript file
|
|
82
83
|
fs.writeFileSync(outputPath, code);
|
|
84
|
+
|
|
85
|
+
// Write Dict.gen.tsx shim for @genType
|
|
86
|
+
const dictShimPath = path.join(outputDir || ".", "Dict.gen.tsx");
|
|
87
|
+
fs.writeFileSync(dictShimPath, Codegen.generateDictShim());
|
|
88
|
+
|
|
83
89
|
console.log(`Generated ${result._0.length} types to ${outputPath}`);
|
|
90
|
+
console.log(`Generated Dict shim to ${dictShimPath}`);
|
|
84
91
|
} else {
|
|
85
92
|
console.error("Parse errors:");
|
|
86
93
|
result._0.forEach((err) => {
|
package/package.json
CHANGED
package/src/Codegen.res.mjs
CHANGED
|
@@ -547,7 +547,14 @@ function generateModule(schemas) {
|
|
|
547
547
|
let allSchemas = uniqueUnions.concat(modifiedSchemas);
|
|
548
548
|
let sorted = topologicalSort(allSchemas);
|
|
549
549
|
let skipSet = {};
|
|
550
|
-
|
|
550
|
+
let typeDefs = sorted.map(s => generateTypeDefWithSkipSet(s, skipSet)).join("\n\n");
|
|
551
|
+
return "module S = Sury\n\n" + typeDefs;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function generateDictShim() {
|
|
555
|
+
return `// Generated by osury - Dict type shim for @genType
|
|
556
|
+
export type t<T> = { [key: string]: T };
|
|
557
|
+
`;
|
|
551
558
|
}
|
|
552
559
|
|
|
553
560
|
export {
|
|
@@ -574,5 +581,6 @@ export {
|
|
|
574
581
|
generateTypeDefWithSkipSet,
|
|
575
582
|
generateTypeDef,
|
|
576
583
|
generateModule,
|
|
584
|
+
generateDictShim,
|
|
577
585
|
}
|
|
578
586
|
/* No side effect */
|