osury 0.14.0 → 0.15.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/bin/osury.mjs +11 -3
- package/package.json +1 -1
- package/src/Codegen.res.mjs +26 -1
package/bin/osury.mjs
CHANGED
|
@@ -82,12 +82,20 @@ function generate(inputPath, outputPath) {
|
|
|
82
82
|
// Write main ReScript file
|
|
83
83
|
fs.writeFileSync(outputPath, code);
|
|
84
84
|
|
|
85
|
-
// Write Dict.gen.
|
|
86
|
-
const dictShimPath = path.join(outputDir || ".", "Dict.gen.
|
|
85
|
+
// Write Dict.gen.ts shim for @genType
|
|
86
|
+
const dictShimPath = path.join(outputDir || ".", "Dict.gen.ts");
|
|
87
87
|
fs.writeFileSync(dictShimPath, Codegen.generateDictShim());
|
|
88
88
|
|
|
89
|
+
// Write Nullable.res module (option<T> alias for sury compatibility)
|
|
90
|
+
const nullableResPath = path.join(outputDir || ".", "Nullable.res");
|
|
91
|
+
fs.writeFileSync(nullableResPath, Codegen.generateNullableModule());
|
|
92
|
+
|
|
93
|
+
// Write Nullable.shim.ts for @genType.import (maps to T | null)
|
|
94
|
+
const nullableShimPath = path.join(outputDir || ".", "Nullable.shim.ts");
|
|
95
|
+
fs.writeFileSync(nullableShimPath, Codegen.generateNullableShim());
|
|
96
|
+
|
|
89
97
|
console.log(`Generated ${result._0.length} types to ${outputPath}`);
|
|
90
|
-
console.log(`Generated
|
|
98
|
+
console.log(`Generated shims: ${dictShimPath}, ${nullableShimPath}`);
|
|
91
99
|
} else {
|
|
92
100
|
console.error("Parse errors:");
|
|
93
101
|
result._0.forEach((err) => {
|
package/package.json
CHANGED
package/src/Codegen.res.mjs
CHANGED
|
@@ -96,8 +96,9 @@ function generateType(schema) {
|
|
|
96
96
|
} else {
|
|
97
97
|
switch (schema._tag) {
|
|
98
98
|
case "Optional" :
|
|
99
|
-
case "Nullable" :
|
|
100
99
|
return `option<` + generateType(schema._0) + `>`;
|
|
100
|
+
case "Nullable" :
|
|
101
|
+
return `Nullable.t<` + generateType(schema._0) + `>`;
|
|
101
102
|
case "Object" :
|
|
102
103
|
return generateRecord(schema._0);
|
|
103
104
|
case "Array" :
|
|
@@ -784,6 +785,28 @@ export type t<T> = { [key: string]: T };
|
|
|
784
785
|
`;
|
|
785
786
|
}
|
|
786
787
|
|
|
788
|
+
function generateNullableShim() {
|
|
789
|
+
return `/**
|
|
790
|
+
* Type shim for ReScript Nullable.t
|
|
791
|
+
*
|
|
792
|
+
* This file is generated by osury (not by ReScript/genType).
|
|
793
|
+
* It maps ReScript's option<T> to TypeScript's T | null for JSON nullable fields.
|
|
794
|
+
*
|
|
795
|
+
* ReScript side: Nullable.t<T> = option<T> (works with sury's S.null schema)
|
|
796
|
+
* TypeScript side: t<T> = T | null (correct JSON null representation)
|
|
797
|
+
*/
|
|
798
|
+
export type t<T> = T | null;
|
|
799
|
+
`;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function generateNullableModule() {
|
|
803
|
+
return `// Generated by osury - Nullable type for JSON null values
|
|
804
|
+
// This is option<T> internally but maps to T | null in TypeScript via shim
|
|
805
|
+
@genType.import(("./Nullable.shim.ts", "t"))
|
|
806
|
+
type t<'a> = option<'a>
|
|
807
|
+
`;
|
|
808
|
+
}
|
|
809
|
+
|
|
787
810
|
export {
|
|
788
811
|
reservedKeywords,
|
|
789
812
|
isReservedKeyword,
|
|
@@ -816,5 +839,7 @@ export {
|
|
|
816
839
|
collectUnionWarnings,
|
|
817
840
|
generateModule,
|
|
818
841
|
generateDictShim,
|
|
842
|
+
generateNullableShim,
|
|
843
|
+
generateNullableModule,
|
|
819
844
|
}
|
|
820
845
|
/* No side effect */
|