osury 1.1.0 → 1.2.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/dist/osury.mjs +4041 -0
- package/package.json +6 -20
- package/bin/osury.mjs +0 -547
- package/src/BackendReScript.res.mjs +0 -157
- package/src/Codegen.res.mjs +0 -160
- package/src/CodegenHelpers.res.mjs +0 -233
- package/src/CodegenShims.res.mjs +0 -44
- package/src/CodegenTransforms.res.mjs +0 -794
- package/src/CodegenTypes.res.mjs +0 -187
- package/src/DomainBackend.res.mjs +0 -41
- package/src/DomainConfig.res.mjs +0 -206
- package/src/DomainGen.res.mjs +0 -53
- package/src/DomainIR.res.mjs +0 -2
- package/src/Errors.res.mjs +0 -106
- package/src/IR.res.mjs +0 -2
- package/src/IRGen.res.mjs +0 -367
- package/src/OpenAPIParser.res.mjs +0 -726
- package/src/Schema.gen.tsx +0 -28
- package/src/Schema.res.mjs +0 -877
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as Core__Array from "@rescript/core/src/Core__Array.res.mjs";
|
|
4
|
-
import * as Core__Option from "@rescript/core/src/Core__Option.res.mjs";
|
|
5
|
-
|
|
6
|
-
function quoteTag(tag) {
|
|
7
|
-
let needsQuoting = tag === "" || tag.split("").some(c => {
|
|
8
|
-
let code = c.charCodeAt(0);
|
|
9
|
-
return !(code >= 97.0 && code <= 122.0 || code >= 65.0 && code <= 90.0 || code >= 48.0 && code <= 57.0 || code === 95.0);
|
|
10
|
-
});
|
|
11
|
-
if (needsQuoting) {
|
|
12
|
-
return `"` + tag + `"`;
|
|
13
|
-
} else {
|
|
14
|
-
return tag;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function printPrimitive(p) {
|
|
19
|
-
switch (p) {
|
|
20
|
-
case "PString" :
|
|
21
|
-
return "string";
|
|
22
|
-
case "PFloat" :
|
|
23
|
-
return "float";
|
|
24
|
-
case "PInt" :
|
|
25
|
-
return "int";
|
|
26
|
-
case "PBool" :
|
|
27
|
-
return "bool";
|
|
28
|
-
case "PUnit" :
|
|
29
|
-
return "unit";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function printType(t) {
|
|
34
|
-
if (typeof t !== "object") {
|
|
35
|
-
return "@s.matches(S.json) JSON.t";
|
|
36
|
-
}
|
|
37
|
-
switch (t.TAG) {
|
|
38
|
-
case "Primitive" :
|
|
39
|
-
return printPrimitive(t._0);
|
|
40
|
-
case "Option" :
|
|
41
|
-
return `option<` + printType(t._0) + `>`;
|
|
42
|
-
case "Nullable" :
|
|
43
|
-
return `Nullable.t<` + printType(t._0) + `>`;
|
|
44
|
-
case "Array" :
|
|
45
|
-
return `array<` + printType(t._0) + `>`;
|
|
46
|
-
case "Dict" :
|
|
47
|
-
return `Dict.t<` + printType(t._0) + `>`;
|
|
48
|
-
case "Named" :
|
|
49
|
-
return t._0;
|
|
50
|
-
case "Enum" :
|
|
51
|
-
let variants = t._0.map(v => `#` + quoteTag(v)).join(" | ");
|
|
52
|
-
return `[` + variants + `]`;
|
|
53
|
-
case "InlineRecord" :
|
|
54
|
-
return printRecord(t._0);
|
|
55
|
-
case "InlineVariant" :
|
|
56
|
-
return printVariantCases(t._0);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function printField(field) {
|
|
61
|
-
let typeStr = printType(field.type_);
|
|
62
|
-
let fieldType = Core__Array.reduce(field.annotations, typeStr, (acc, ann) => {
|
|
63
|
-
if (typeof ann !== "object" && ann === "SNull") {
|
|
64
|
-
return `@s.null ` + acc;
|
|
65
|
-
} else {
|
|
66
|
-
return acc;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
let asAttr = Core__Option.getOr(Core__Array.findMap(field.annotations, ann => {
|
|
70
|
-
if (typeof ann !== "object" || ann.TAG !== "As") {
|
|
71
|
-
return;
|
|
72
|
-
} else {
|
|
73
|
-
return `@as("` + ann._0 + `") `;
|
|
74
|
-
}
|
|
75
|
-
}), "");
|
|
76
|
-
return asAttr + field.name + `: ` + fieldType;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function printRecord(fields) {
|
|
80
|
-
if (fields.length === 0) {
|
|
81
|
-
return "{}";
|
|
82
|
-
}
|
|
83
|
-
let fieldStrs = fields.map(printField);
|
|
84
|
-
return `{\n ` + fieldStrs.join(",\n ") + `\n}`;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function printVariantCase(c) {
|
|
88
|
-
let payloadStr = printType(c.payload);
|
|
89
|
-
return c.tag + `(` + payloadStr + `)`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function printVariantCases(cases) {
|
|
93
|
-
let caseStrs = cases.map(printVariantCase);
|
|
94
|
-
return `[` + caseStrs.map(c => `#` + quoteTag(c)).join(" | ") + `]`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function printAnnotation(ann) {
|
|
98
|
-
if (typeof ann === "object") {
|
|
99
|
-
if (ann.TAG === "Tag") {
|
|
100
|
-
return `@tag("` + ann._0 + `")`;
|
|
101
|
-
} else {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
switch (ann) {
|
|
106
|
-
case "GenType" :
|
|
107
|
-
return "@genType";
|
|
108
|
-
case "Schema" :
|
|
109
|
-
return "@schema";
|
|
110
|
-
case "Unboxed" :
|
|
111
|
-
return "@unboxed";
|
|
112
|
-
case "SNull" :
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function printAnnotations(annotations) {
|
|
118
|
-
return Core__Array.filterMap(annotations, printAnnotation).join("\n");
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function printTypeDef(typeDef) {
|
|
122
|
-
let annotations = printAnnotations(typeDef.annotations);
|
|
123
|
-
let fields = typeDef.kind;
|
|
124
|
-
let body;
|
|
125
|
-
switch (fields.TAG) {
|
|
126
|
-
case "RecordDef" :
|
|
127
|
-
body = printRecord(fields._0);
|
|
128
|
-
break;
|
|
129
|
-
case "VariantDef" :
|
|
130
|
-
body = fields._0.map(printVariantCase).join(" | ");
|
|
131
|
-
break;
|
|
132
|
-
case "AliasDef" :
|
|
133
|
-
body = printType(fields._0);
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
return annotations + `\ntype ` + typeDef.name + ` = ` + body;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function print(module_) {
|
|
140
|
-
let typeDefs = module_.types.map(printTypeDef).join("\n\n");
|
|
141
|
-
return module_.preamble + "\n\n" + typeDefs;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export {
|
|
145
|
-
quoteTag,
|
|
146
|
-
printPrimitive,
|
|
147
|
-
printType,
|
|
148
|
-
printField,
|
|
149
|
-
printRecord,
|
|
150
|
-
printVariantCase,
|
|
151
|
-
printVariantCases,
|
|
152
|
-
printAnnotation,
|
|
153
|
-
printAnnotations,
|
|
154
|
-
printTypeDef,
|
|
155
|
-
print,
|
|
156
|
-
}
|
|
157
|
-
/* No side effect */
|
package/src/Codegen.res.mjs
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as IRGen from "./IRGen.res.mjs";
|
|
4
|
-
import * as Errors from "./Errors.res.mjs";
|
|
5
|
-
import * as CodegenShims from "./CodegenShims.res.mjs";
|
|
6
|
-
import * as CodegenTypes from "./CodegenTypes.res.mjs";
|
|
7
|
-
import * as CodegenHelpers from "./CodegenHelpers.res.mjs";
|
|
8
|
-
import * as BackendReScript from "./BackendReScript.res.mjs";
|
|
9
|
-
import * as CodegenTransforms from "./CodegenTransforms.res.mjs";
|
|
10
|
-
|
|
11
|
-
function generateModuleWithDiagnostics(schemas) {
|
|
12
|
-
let irModule = IRGen.generate(schemas);
|
|
13
|
-
if (irModule.TAG !== "Ok") {
|
|
14
|
-
return {
|
|
15
|
-
TAG: "Error",
|
|
16
|
-
_0: irModule._0
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
let irModule$1 = irModule._0;
|
|
20
|
-
let code = BackendReScript.print(irModule$1);
|
|
21
|
-
return {
|
|
22
|
-
TAG: "Ok",
|
|
23
|
-
_0: {
|
|
24
|
-
code: code,
|
|
25
|
-
warnings: irModule$1.warnings
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function generateModule(schemas) {
|
|
31
|
-
let result = generateModuleWithDiagnostics(schemas);
|
|
32
|
-
if (result.TAG === "Ok") {
|
|
33
|
-
let result$1 = result._0;
|
|
34
|
-
result$1.warnings.forEach(w => {
|
|
35
|
-
console.log(w);
|
|
36
|
-
});
|
|
37
|
-
return result$1.code;
|
|
38
|
-
}
|
|
39
|
-
result._0.forEach(e => {
|
|
40
|
-
console.error(Errors.formatError(e));
|
|
41
|
-
});
|
|
42
|
-
return "";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let lcFirst = CodegenHelpers.lcFirst;
|
|
46
|
-
|
|
47
|
-
let ucFirst = CodegenHelpers.ucFirst;
|
|
48
|
-
|
|
49
|
-
let reservedKeywords = CodegenHelpers.reservedKeywords;
|
|
50
|
-
|
|
51
|
-
let isReservedKeyword = CodegenHelpers.isReservedKeyword;
|
|
52
|
-
|
|
53
|
-
let isOptionalType = CodegenHelpers.isOptionalType;
|
|
54
|
-
|
|
55
|
-
let isNullableType = CodegenHelpers.isNullableType;
|
|
56
|
-
|
|
57
|
-
let getTagForType = CodegenHelpers.getTagForType;
|
|
58
|
-
|
|
59
|
-
let hasUnion = CodegenHelpers.hasUnion;
|
|
60
|
-
|
|
61
|
-
let isPrimitiveOnlyUnion = CodegenHelpers.isPrimitiveOnlyUnion;
|
|
62
|
-
|
|
63
|
-
let collectInlineEnums = CodegenTransforms.collectInlineEnums;
|
|
64
|
-
|
|
65
|
-
let resolveEnumNames = CodegenTransforms.resolveEnumNames;
|
|
66
|
-
|
|
67
|
-
let camelize = CodegenTransforms.camelize;
|
|
68
|
-
|
|
69
|
-
let replaceInlineEnums = CodegenTransforms.replaceInlineEnums;
|
|
70
|
-
|
|
71
|
-
let buildExtractedEnumSchemas = CodegenTransforms.buildExtractedEnumSchemas;
|
|
72
|
-
|
|
73
|
-
let isRefPlusDictUnion = CodegenTransforms.isRefPlusDictUnion;
|
|
74
|
-
|
|
75
|
-
let isPrimitivePlusDictUnion = CodegenTransforms.isPrimitivePlusDictUnion;
|
|
76
|
-
|
|
77
|
-
let getUnionName = CodegenTransforms.getUnionName;
|
|
78
|
-
|
|
79
|
-
let getPolyVariantName = CodegenTransforms.getPolyVariantName;
|
|
80
|
-
|
|
81
|
-
let extractUnions = CodegenTransforms.extractUnions;
|
|
82
|
-
|
|
83
|
-
let extractUnionsFromType = CodegenTransforms.extractUnionsFromType;
|
|
84
|
-
|
|
85
|
-
let replaceUnions = CodegenTransforms.replaceUnions;
|
|
86
|
-
|
|
87
|
-
let replaceUnionInType = CodegenTransforms.replaceUnionInType;
|
|
88
|
-
|
|
89
|
-
let getDependencies = CodegenTransforms.getDependencies;
|
|
90
|
-
|
|
91
|
-
let topologicalSort = CodegenTransforms.topologicalSort;
|
|
92
|
-
|
|
93
|
-
let buildSkipSchemaSet = CodegenTransforms.buildSkipSchemaSet;
|
|
94
|
-
|
|
95
|
-
let collectUnionWarnings = CodegenTransforms.collectUnionWarnings;
|
|
96
|
-
|
|
97
|
-
let validateUnionDiscriminators = CodegenTransforms.validateUnionDiscriminators;
|
|
98
|
-
|
|
99
|
-
let generateType = CodegenTypes.generateType;
|
|
100
|
-
|
|
101
|
-
let generateTypeDef = CodegenTypes.generateTypeDef;
|
|
102
|
-
|
|
103
|
-
let generateTypeDefWithSkipSet = CodegenTypes.generateTypeDefWithSkipSet;
|
|
104
|
-
|
|
105
|
-
let generateVariantBody = CodegenTypes.generateVariantBody;
|
|
106
|
-
|
|
107
|
-
let generateInlineVariantBody = CodegenTypes.generateInlineVariantBody;
|
|
108
|
-
|
|
109
|
-
let generateInlineRecord = CodegenTypes.generateInlineRecord;
|
|
110
|
-
|
|
111
|
-
let generateDictShim = CodegenShims.generateDictShim;
|
|
112
|
-
|
|
113
|
-
let generateJsonShim = CodegenShims.generateJsonShim;
|
|
114
|
-
|
|
115
|
-
let generateNullableShim = CodegenShims.generateNullableShim;
|
|
116
|
-
|
|
117
|
-
let generateNullableModule = CodegenShims.generateNullableModule;
|
|
118
|
-
|
|
119
|
-
export {
|
|
120
|
-
lcFirst,
|
|
121
|
-
ucFirst,
|
|
122
|
-
reservedKeywords,
|
|
123
|
-
isReservedKeyword,
|
|
124
|
-
isOptionalType,
|
|
125
|
-
isNullableType,
|
|
126
|
-
getTagForType,
|
|
127
|
-
hasUnion,
|
|
128
|
-
isPrimitiveOnlyUnion,
|
|
129
|
-
collectInlineEnums,
|
|
130
|
-
resolveEnumNames,
|
|
131
|
-
camelize,
|
|
132
|
-
replaceInlineEnums,
|
|
133
|
-
buildExtractedEnumSchemas,
|
|
134
|
-
isRefPlusDictUnion,
|
|
135
|
-
isPrimitivePlusDictUnion,
|
|
136
|
-
getUnionName,
|
|
137
|
-
getPolyVariantName,
|
|
138
|
-
extractUnions,
|
|
139
|
-
extractUnionsFromType,
|
|
140
|
-
replaceUnions,
|
|
141
|
-
replaceUnionInType,
|
|
142
|
-
getDependencies,
|
|
143
|
-
topologicalSort,
|
|
144
|
-
buildSkipSchemaSet,
|
|
145
|
-
collectUnionWarnings,
|
|
146
|
-
validateUnionDiscriminators,
|
|
147
|
-
generateType,
|
|
148
|
-
generateTypeDef,
|
|
149
|
-
generateTypeDefWithSkipSet,
|
|
150
|
-
generateVariantBody,
|
|
151
|
-
generateInlineVariantBody,
|
|
152
|
-
generateInlineRecord,
|
|
153
|
-
generateDictShim,
|
|
154
|
-
generateJsonShim,
|
|
155
|
-
generateNullableShim,
|
|
156
|
-
generateNullableModule,
|
|
157
|
-
generateModuleWithDiagnostics,
|
|
158
|
-
generateModule,
|
|
159
|
-
}
|
|
160
|
-
/* No side effect */
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let reservedKeywords = [
|
|
5
|
-
"type",
|
|
6
|
-
"let",
|
|
7
|
-
"rec",
|
|
8
|
-
"and",
|
|
9
|
-
"as",
|
|
10
|
-
"open",
|
|
11
|
-
"include",
|
|
12
|
-
"module",
|
|
13
|
-
"sig",
|
|
14
|
-
"struct",
|
|
15
|
-
"exception",
|
|
16
|
-
"external",
|
|
17
|
-
"if",
|
|
18
|
-
"else",
|
|
19
|
-
"switch",
|
|
20
|
-
"while",
|
|
21
|
-
"for",
|
|
22
|
-
"try",
|
|
23
|
-
"catch",
|
|
24
|
-
"when",
|
|
25
|
-
"true",
|
|
26
|
-
"false",
|
|
27
|
-
"assert",
|
|
28
|
-
"lazy",
|
|
29
|
-
"constraint",
|
|
30
|
-
"functor",
|
|
31
|
-
"class",
|
|
32
|
-
"method",
|
|
33
|
-
"object",
|
|
34
|
-
"private",
|
|
35
|
-
"public",
|
|
36
|
-
"virtual",
|
|
37
|
-
"mutable",
|
|
38
|
-
"new",
|
|
39
|
-
"inherit",
|
|
40
|
-
"initializer",
|
|
41
|
-
"val",
|
|
42
|
-
"with",
|
|
43
|
-
"match",
|
|
44
|
-
"of",
|
|
45
|
-
"fun",
|
|
46
|
-
"function",
|
|
47
|
-
"in",
|
|
48
|
-
"do",
|
|
49
|
-
"done",
|
|
50
|
-
"begin",
|
|
51
|
-
"end",
|
|
52
|
-
"then",
|
|
53
|
-
"to",
|
|
54
|
-
"downto",
|
|
55
|
-
"or",
|
|
56
|
-
"land",
|
|
57
|
-
"lor",
|
|
58
|
-
"lxor",
|
|
59
|
-
"lsl",
|
|
60
|
-
"lsr",
|
|
61
|
-
"asr",
|
|
62
|
-
"mod",
|
|
63
|
-
"await",
|
|
64
|
-
"async"
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
function isReservedKeyword(name) {
|
|
68
|
-
return reservedKeywords.includes(name);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function lcFirst(s) {
|
|
72
|
-
if (s.length === 0) {
|
|
73
|
-
return s;
|
|
74
|
-
}
|
|
75
|
-
let first = s.charAt(0).toLowerCase();
|
|
76
|
-
let rest = s.slice(1);
|
|
77
|
-
return first + rest;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function ucFirst(s) {
|
|
81
|
-
if (s.length === 0) {
|
|
82
|
-
return s;
|
|
83
|
-
}
|
|
84
|
-
let first = s.charAt(0).toUpperCase();
|
|
85
|
-
let rest = s.slice(1);
|
|
86
|
-
return first + rest;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function isOptionalType(schema) {
|
|
90
|
-
if (typeof schema !== "object") {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
switch (schema._tag) {
|
|
94
|
-
case "Optional" :
|
|
95
|
-
case "Nullable" :
|
|
96
|
-
return true;
|
|
97
|
-
default:
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function isNullableType(schema) {
|
|
103
|
-
if (typeof schema !== "object") {
|
|
104
|
-
return false;
|
|
105
|
-
} else {
|
|
106
|
-
return schema._tag === "Nullable";
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function getTagForType(t) {
|
|
111
|
-
if (typeof t !== "object") {
|
|
112
|
-
switch (t) {
|
|
113
|
-
case "String" :
|
|
114
|
-
return "String";
|
|
115
|
-
case "Number" :
|
|
116
|
-
return "Float";
|
|
117
|
-
case "Integer" :
|
|
118
|
-
return "Int";
|
|
119
|
-
case "Boolean" :
|
|
120
|
-
return "Bool";
|
|
121
|
-
case "Null" :
|
|
122
|
-
return "Null";
|
|
123
|
-
case "Unknown" :
|
|
124
|
-
return "Unknown";
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
switch (t._tag) {
|
|
128
|
-
case "Optional" :
|
|
129
|
-
return `Option` + getTagForType(t._0);
|
|
130
|
-
case "Nullable" :
|
|
131
|
-
return `Null` + getTagForType(t._0);
|
|
132
|
-
case "Object" :
|
|
133
|
-
return "Object";
|
|
134
|
-
case "Array" :
|
|
135
|
-
return `Array` + getTagForType(t._0);
|
|
136
|
-
case "Ref" :
|
|
137
|
-
return ucFirst(t._0);
|
|
138
|
-
case "Enum" :
|
|
139
|
-
return "Enum";
|
|
140
|
-
case "PolyVariant" :
|
|
141
|
-
return "Variant";
|
|
142
|
-
case "Dict" :
|
|
143
|
-
return "Dict";
|
|
144
|
-
case "Union" :
|
|
145
|
-
return "Union";
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function hasUnion(_schema) {
|
|
151
|
-
while (true) {
|
|
152
|
-
let schema = _schema;
|
|
153
|
-
if (typeof schema !== "object") {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
switch (schema._tag) {
|
|
157
|
-
case "Object" :
|
|
158
|
-
return schema._0.some(f => hasUnion(f.type));
|
|
159
|
-
case "PolyVariant" :
|
|
160
|
-
return schema._0.some(c => hasUnion(c.payload));
|
|
161
|
-
case "Optional" :
|
|
162
|
-
case "Nullable" :
|
|
163
|
-
case "Array" :
|
|
164
|
-
case "Dict" :
|
|
165
|
-
_schema = schema._0;
|
|
166
|
-
continue;
|
|
167
|
-
case "Union" :
|
|
168
|
-
return true;
|
|
169
|
-
default:
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function hasUnknown(_schema) {
|
|
176
|
-
while (true) {
|
|
177
|
-
let schema = _schema;
|
|
178
|
-
if (typeof schema !== "object") {
|
|
179
|
-
return schema === "Unknown";
|
|
180
|
-
}
|
|
181
|
-
switch (schema._tag) {
|
|
182
|
-
case "Object" :
|
|
183
|
-
return schema._0.some(f => hasUnknown(f.type));
|
|
184
|
-
case "PolyVariant" :
|
|
185
|
-
return schema._0.some(c => hasUnknown(c.payload));
|
|
186
|
-
case "Optional" :
|
|
187
|
-
case "Nullable" :
|
|
188
|
-
case "Array" :
|
|
189
|
-
case "Dict" :
|
|
190
|
-
_schema = schema._0;
|
|
191
|
-
continue;
|
|
192
|
-
default:
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function isPrimitiveOnlyUnion(types) {
|
|
199
|
-
let allPrimitive = types.every(t => {
|
|
200
|
-
if (typeof t === "object") {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
switch (t) {
|
|
204
|
-
case "String" :
|
|
205
|
-
case "Number" :
|
|
206
|
-
case "Integer" :
|
|
207
|
-
case "Boolean" :
|
|
208
|
-
return true;
|
|
209
|
-
default:
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
if (!allPrimitive) {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
let hasFloat = types.some(t => t === "Number");
|
|
217
|
-
let hasInt = types.some(t => t === "Integer");
|
|
218
|
-
return !(hasFloat && hasInt);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export {
|
|
222
|
-
reservedKeywords,
|
|
223
|
-
isReservedKeyword,
|
|
224
|
-
lcFirst,
|
|
225
|
-
ucFirst,
|
|
226
|
-
isOptionalType,
|
|
227
|
-
isNullableType,
|
|
228
|
-
getTagForType,
|
|
229
|
-
hasUnion,
|
|
230
|
-
hasUnknown,
|
|
231
|
-
isPrimitiveOnlyUnion,
|
|
232
|
-
}
|
|
233
|
-
/* No side effect */
|
package/src/CodegenShims.res.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function generateDictShim() {
|
|
5
|
-
return `// Generated by osury - Dict type shim for @genType
|
|
6
|
-
export type t<T> = { [key: string]: T };
|
|
7
|
-
`;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function generateNullableShim() {
|
|
11
|
-
return `/**
|
|
12
|
-
* Type shim for ReScript Nullable.t
|
|
13
|
-
*
|
|
14
|
-
* This file is generated by osury (not by ReScript/genType).
|
|
15
|
-
* It maps ReScript's option<T> to TypeScript's T | null for JSON nullable fields.
|
|
16
|
-
*
|
|
17
|
-
* ReScript side: Nullable.t<T> = option<T> (works with sury's S.null schema)
|
|
18
|
-
* TypeScript side: t<T> = T | null (correct JSON null representation)
|
|
19
|
-
*/
|
|
20
|
-
export type t<T> = T | null;
|
|
21
|
-
`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function generateJsonShim() {
|
|
25
|
-
return `// Generated by osury - JSON type shim for @genType
|
|
26
|
-
export type t = unknown;
|
|
27
|
-
`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function generateNullableModule() {
|
|
31
|
-
return `// Generated by osury - Nullable type for JSON null values
|
|
32
|
-
// This is option<T> internally but maps to T | null in TypeScript via shim
|
|
33
|
-
@genType.import(("./Nullable.shim.ts", "t"))
|
|
34
|
-
type t<'a> = option<'a>
|
|
35
|
-
`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export {
|
|
39
|
-
generateDictShim,
|
|
40
|
-
generateNullableShim,
|
|
41
|
-
generateJsonShim,
|
|
42
|
-
generateNullableModule,
|
|
43
|
-
}
|
|
44
|
-
/* No side effect */
|