osury 1.0.1 → 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 -724
- package/src/Schema.gen.tsx +0 -28
- package/src/Schema.res.mjs +0 -877
package/src/CodegenTypes.res.mjs
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as Core__Option from "@rescript/core/src/Core__Option.res.mjs";
|
|
4
|
-
import * as CodegenHelpers from "./CodegenHelpers.res.mjs";
|
|
5
|
-
|
|
6
|
-
function generateType(schema) {
|
|
7
|
-
if (typeof schema !== "object") {
|
|
8
|
-
switch (schema) {
|
|
9
|
-
case "String" :
|
|
10
|
-
return "string";
|
|
11
|
-
case "Number" :
|
|
12
|
-
return "float";
|
|
13
|
-
case "Integer" :
|
|
14
|
-
return "int";
|
|
15
|
-
case "Boolean" :
|
|
16
|
-
return "bool";
|
|
17
|
-
case "Null" :
|
|
18
|
-
return "unit";
|
|
19
|
-
case "Unknown" :
|
|
20
|
-
return "JSON.t";
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
switch (schema._tag) {
|
|
24
|
-
case "Optional" :
|
|
25
|
-
return `option<` + generateType(schema._0) + `>`;
|
|
26
|
-
case "Nullable" :
|
|
27
|
-
return `Nullable.t<` + generateType(schema._0) + `>`;
|
|
28
|
-
case "Object" :
|
|
29
|
-
return generateRecord(schema._0);
|
|
30
|
-
case "Array" :
|
|
31
|
-
return `array<` + generateType(schema._0) + `>`;
|
|
32
|
-
case "Ref" :
|
|
33
|
-
return CodegenHelpers.lcFirst(schema._0);
|
|
34
|
-
case "Enum" :
|
|
35
|
-
let variants = schema._0.map(v => `#` + v).join(" | ");
|
|
36
|
-
return `[` + variants + `]`;
|
|
37
|
-
case "PolyVariant" :
|
|
38
|
-
return generatePolyVariant(schema._0);
|
|
39
|
-
case "Dict" :
|
|
40
|
-
return `Dict.t<` + generateType(schema._0) + `>`;
|
|
41
|
-
case "Union" :
|
|
42
|
-
return generateUnion(schema._0);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function generateRecord(fields) {
|
|
48
|
-
if (fields.length === 0) {
|
|
49
|
-
return "{}";
|
|
50
|
-
}
|
|
51
|
-
let fieldStrs = fields.map(field => {
|
|
52
|
-
let typeStr = generateType(field.type);
|
|
53
|
-
let optionalType = field.required || CodegenHelpers.isOptionalType(field.type) ? typeStr : `option<` + typeStr + `>`;
|
|
54
|
-
let finalType = CodegenHelpers.isNullableType(field.type) ? `@s.null ` + optionalType : optionalType;
|
|
55
|
-
let asAttr = CodegenHelpers.isReservedKeyword(field.name) ? `@as("` + field.name + `") ` : "";
|
|
56
|
-
let fieldName = CodegenHelpers.isReservedKeyword(field.name) ? field.name + `_` : field.name;
|
|
57
|
-
return asAttr + fieldName + `: ` + finalType;
|
|
58
|
-
});
|
|
59
|
-
return `{\n ` + fieldStrs.join(",\n ") + `\n}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function generatePolyVariant(cases) {
|
|
63
|
-
let caseStrs = cases.map(c => {
|
|
64
|
-
let payloadStr = generateType(c.payload);
|
|
65
|
-
return `#` + c._tag + `(` + payloadStr + `)`;
|
|
66
|
-
});
|
|
67
|
-
return `[` + caseStrs.join(" | ") + `]`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function generateUnion(types) {
|
|
71
|
-
let caseStrs = types.map(t => {
|
|
72
|
-
let tag = CodegenHelpers.getTagForType(t);
|
|
73
|
-
let payload = generateType(t);
|
|
74
|
-
return `#` + tag + `(` + payload + `)`;
|
|
75
|
-
});
|
|
76
|
-
return `[` + caseStrs.join(" | ") + `]`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function generateInlineRecord(refName, schemasDict) {
|
|
80
|
-
let other = schemasDict[refName];
|
|
81
|
-
if (other !== undefined) {
|
|
82
|
-
if (typeof other !== "object" || other._tag !== "Object") {
|
|
83
|
-
return generateType(other);
|
|
84
|
-
} else {
|
|
85
|
-
return generateRecord(other._0);
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
return CodegenHelpers.lcFirst(refName);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function generateInlineVariantBody(types, schemasDict, tagsDict) {
|
|
93
|
-
return types.map(t => {
|
|
94
|
-
if (typeof t === "object" && t._tag === "Ref") {
|
|
95
|
-
let name = t._0;
|
|
96
|
-
let tagValue = tagsDict[name];
|
|
97
|
-
let tag = tagValue !== undefined ? CodegenHelpers.ucFirst(tagValue) : CodegenHelpers.ucFirst(name);
|
|
98
|
-
let inlineRecord = generateInlineRecord(name, schemasDict);
|
|
99
|
-
return tag + `(` + inlineRecord + `)`;
|
|
100
|
-
}
|
|
101
|
-
let tag$1 = CodegenHelpers.getTagForType(t);
|
|
102
|
-
let payload = generateType(t);
|
|
103
|
-
return tag$1 + `(` + payload + `)`;
|
|
104
|
-
}).join(" | ");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function generateVariantBody(types) {
|
|
108
|
-
return types.map(t => {
|
|
109
|
-
let tag = CodegenHelpers.getTagForType(t);
|
|
110
|
-
let payload = generateType(t);
|
|
111
|
-
return tag + `(` + payload + `)`;
|
|
112
|
-
}).join(" | ");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function generateTypeDefWithSkipSet(namedSchema, _skipSet, schemasDict, tagsDict) {
|
|
116
|
-
let typeName = CodegenHelpers.lcFirst(namedSchema.name);
|
|
117
|
-
let tagName = Core__Option.getOr(namedSchema.discriminatorPropertyName, "_tag");
|
|
118
|
-
let cases = namedSchema.schema;
|
|
119
|
-
if (typeof cases === "object") {
|
|
120
|
-
switch (cases._tag) {
|
|
121
|
-
case "PolyVariant" :
|
|
122
|
-
let variantBody = cases._0.map(c => {
|
|
123
|
-
let refName = c.payload;
|
|
124
|
-
if (typeof refName === "object" && refName._tag === "Ref") {
|
|
125
|
-
let inlineRecord = generateInlineRecord(refName._0, schemasDict);
|
|
126
|
-
return CodegenHelpers.ucFirst(c._tag) + `(` + inlineRecord + `)`;
|
|
127
|
-
}
|
|
128
|
-
let payloadStr = generateType(c.payload);
|
|
129
|
-
return CodegenHelpers.ucFirst(c._tag) + `(` + payloadStr + `)`;
|
|
130
|
-
}).join(" | ");
|
|
131
|
-
return `@genType
|
|
132
|
-
@tag("` + tagName + `")
|
|
133
|
-
@schema
|
|
134
|
-
type ` + typeName + ` = ` + variantBody;
|
|
135
|
-
case "Union" :
|
|
136
|
-
let types = cases._0;
|
|
137
|
-
if (CodegenHelpers.isPrimitiveOnlyUnion(types)) {
|
|
138
|
-
let variantBody$1 = generateVariantBody(types);
|
|
139
|
-
return `@genType
|
|
140
|
-
@tag("` + tagName + `")
|
|
141
|
-
@unboxed
|
|
142
|
-
@schema
|
|
143
|
-
type ` + typeName + ` = ` + variantBody$1;
|
|
144
|
-
}
|
|
145
|
-
let variantBody$2 = generateInlineVariantBody(types, schemasDict, tagsDict);
|
|
146
|
-
return `@genType
|
|
147
|
-
@tag("` + tagName + `")
|
|
148
|
-
@schema
|
|
149
|
-
type ` + typeName + ` = ` + variantBody$2;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
let typeBody = generateType(namedSchema.schema);
|
|
153
|
-
return `@genType
|
|
154
|
-
@schema
|
|
155
|
-
type ` + typeName + ` = ` + typeBody;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function generateTypeDef(namedSchema) {
|
|
159
|
-
let typeName = CodegenHelpers.lcFirst(namedSchema.name);
|
|
160
|
-
let tagName = Core__Option.getOr(namedSchema.discriminatorPropertyName, "_tag");
|
|
161
|
-
let types = namedSchema.schema;
|
|
162
|
-
if (typeof types === "object" && types._tag === "Union") {
|
|
163
|
-
let variantBody = generateVariantBody(types._0);
|
|
164
|
-
return `@genType
|
|
165
|
-
@tag("` + tagName + `")
|
|
166
|
-
@unboxed
|
|
167
|
-
@schema
|
|
168
|
-
type ` + typeName + ` = ` + variantBody;
|
|
169
|
-
}
|
|
170
|
-
let annotations = CodegenHelpers.hasUnion(namedSchema.schema) || CodegenHelpers.hasUnknown(namedSchema.schema) ? "@genType" : "@genType\n@schema";
|
|
171
|
-
let typeBody = generateType(namedSchema.schema);
|
|
172
|
-
return annotations + `
|
|
173
|
-
type ` + typeName + ` = ` + typeBody;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export {
|
|
177
|
-
generateType,
|
|
178
|
-
generateRecord,
|
|
179
|
-
generatePolyVariant,
|
|
180
|
-
generateUnion,
|
|
181
|
-
generateInlineRecord,
|
|
182
|
-
generateInlineVariantBody,
|
|
183
|
-
generateVariantBody,
|
|
184
|
-
generateTypeDefWithSkipSet,
|
|
185
|
-
generateTypeDef,
|
|
186
|
-
}
|
|
187
|
-
/* No side effect */
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function printField(field) {
|
|
5
|
-
return ` ` + field.name + `: ` + field.typeAnnotation + `,`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function printType(module_) {
|
|
9
|
-
let fields = module_.fields.map(printField).join("\n");
|
|
10
|
-
return `type t = {\n` + fields + `\n}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function printMakeField(field) {
|
|
14
|
-
let fn = field.mapping;
|
|
15
|
-
if (fn.TAG === "Mapper") {
|
|
16
|
-
return ` ` + field.name + `: ` + fn._0 + `(raw),`;
|
|
17
|
-
} else {
|
|
18
|
-
return ` ` + field.name + `: raw.` + fn._0 + `,`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function printMake(module_) {
|
|
23
|
-
let fields = module_.fields.map(printMakeField).join("\n");
|
|
24
|
-
return `let make = (raw: ` + module_.sourceType + `): t => {\n` + fields + `\n}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function printModule(module_) {
|
|
28
|
-
let header = `// ` + module_.output + ` (generated by osury — do not edit)`;
|
|
29
|
-
let typeBlock = printType(module_);
|
|
30
|
-
let makeBlock = printMake(module_);
|
|
31
|
-
return header + "\n\n" + typeBlock + "\n\n" + makeBlock + "\n";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export {
|
|
35
|
-
printField,
|
|
36
|
-
printType,
|
|
37
|
-
printMakeField,
|
|
38
|
-
printMake,
|
|
39
|
-
printModule,
|
|
40
|
-
}
|
|
41
|
-
/* No side effect */
|
package/src/DomainConfig.res.mjs
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as Errors from "./Errors.res.mjs";
|
|
4
|
-
import * as Core__Array from "@rescript/core/src/Core__Array.res.mjs";
|
|
5
|
-
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
6
|
-
|
|
7
|
-
function parseFieldConfig(name, json) {
|
|
8
|
-
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
9
|
-
let match = json["type"];
|
|
10
|
-
let exit = 0;
|
|
11
|
-
if (match !== undefined) {
|
|
12
|
-
if (typeof match === "string") {
|
|
13
|
-
let match$1 = json["mapper"];
|
|
14
|
-
let mapper = typeof match$1 === "string" ? match$1 : undefined;
|
|
15
|
-
let match$2 = json["source"];
|
|
16
|
-
let source = typeof match$2 === "string" ? match$2 : undefined;
|
|
17
|
-
return {
|
|
18
|
-
TAG: "Ok",
|
|
19
|
-
_0: [
|
|
20
|
-
name,
|
|
21
|
-
{
|
|
22
|
-
type_: match,
|
|
23
|
-
mapper: mapper,
|
|
24
|
-
source: source
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
exit = 2;
|
|
30
|
-
} else {
|
|
31
|
-
exit = 2;
|
|
32
|
-
}
|
|
33
|
-
if (exit === 2) {
|
|
34
|
-
return {
|
|
35
|
-
TAG: "Error",
|
|
36
|
-
_0: [Errors.makeError({
|
|
37
|
-
TAG: "MissingRequiredField",
|
|
38
|
-
_0: "type"
|
|
39
|
-
}, [
|
|
40
|
-
"fields",
|
|
41
|
-
name
|
|
42
|
-
], Primitive_option.some(`Field "` + name + `" must have a "type" property`), undefined)]
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
TAG: "Error",
|
|
48
|
-
_0: [Errors.makeError({
|
|
49
|
-
TAG: "InvalidJson",
|
|
50
|
-
_0: `field "` + name + `" must be an object`
|
|
51
|
-
}, [
|
|
52
|
-
"fields",
|
|
53
|
-
name
|
|
54
|
-
], undefined, undefined)]
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function parseModuleConfig(name, json) {
|
|
59
|
-
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
60
|
-
let match = json["source"];
|
|
61
|
-
let exit = 0;
|
|
62
|
-
if (typeof match === "string") {
|
|
63
|
-
let match$1 = json["output"];
|
|
64
|
-
let output = typeof match$1 === "string" ? match$1 : undefined;
|
|
65
|
-
let match$2 = json["fields"];
|
|
66
|
-
let exit$1 = 0;
|
|
67
|
-
if (match$2 !== undefined) {
|
|
68
|
-
if (typeof match$2 === "object" && match$2 !== null && !Array.isArray(match$2)) {
|
|
69
|
-
let entries = Object.entries(match$2);
|
|
70
|
-
let results = entries.map(param => parseFieldConfig(param[0], param[1]));
|
|
71
|
-
let errors = Core__Array.filterMap(results, r => {
|
|
72
|
-
if (r.TAG === "Ok") {
|
|
73
|
-
return;
|
|
74
|
-
} else {
|
|
75
|
-
return r._0;
|
|
76
|
-
}
|
|
77
|
-
}).flat();
|
|
78
|
-
if (errors.length > 0) {
|
|
79
|
-
return {
|
|
80
|
-
TAG: "Error",
|
|
81
|
-
_0: errors
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
let fields = Core__Array.filterMap(results, r => {
|
|
85
|
-
if (r.TAG === "Ok") {
|
|
86
|
-
return r._0;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return {
|
|
90
|
-
TAG: "Ok",
|
|
91
|
-
_0: [
|
|
92
|
-
name,
|
|
93
|
-
{
|
|
94
|
-
source: match,
|
|
95
|
-
output: output,
|
|
96
|
-
fields: fields
|
|
97
|
-
}
|
|
98
|
-
]
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
exit$1 = 3;
|
|
102
|
-
} else {
|
|
103
|
-
exit$1 = 3;
|
|
104
|
-
}
|
|
105
|
-
if (exit$1 === 3) {
|
|
106
|
-
return {
|
|
107
|
-
TAG: "Error",
|
|
108
|
-
_0: [Errors.makeError({
|
|
109
|
-
TAG: "MissingRequiredField",
|
|
110
|
-
_0: "fields"
|
|
111
|
-
}, [
|
|
112
|
-
"modules",
|
|
113
|
-
name
|
|
114
|
-
], Primitive_option.some(`Module "` + name + `" must have a "fields" object`), undefined)]
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
exit = 2;
|
|
119
|
-
}
|
|
120
|
-
if (exit === 2) {
|
|
121
|
-
return {
|
|
122
|
-
TAG: "Error",
|
|
123
|
-
_0: [Errors.makeError({
|
|
124
|
-
TAG: "MissingRequiredField",
|
|
125
|
-
_0: "source"
|
|
126
|
-
}, [
|
|
127
|
-
"modules",
|
|
128
|
-
name
|
|
129
|
-
], Primitive_option.some(`Module "` + name + `" must have a "source" property referencing the API type`), undefined)]
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
TAG: "Error",
|
|
135
|
-
_0: [Errors.makeError({
|
|
136
|
-
TAG: "InvalidJson",
|
|
137
|
-
_0: `module "` + name + `" must be an object`
|
|
138
|
-
}, [
|
|
139
|
-
"modules",
|
|
140
|
-
name
|
|
141
|
-
], undefined, undefined)]
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function parse(json) {
|
|
146
|
-
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
147
|
-
let match = json["modules"];
|
|
148
|
-
let exit = 0;
|
|
149
|
-
if (match !== undefined) {
|
|
150
|
-
if (typeof match === "object" && match !== null && !Array.isArray(match)) {
|
|
151
|
-
let entries = Object.entries(match);
|
|
152
|
-
let results = entries.map(param => parseModuleConfig(param[0], param[1]));
|
|
153
|
-
let errors = Core__Array.filterMap(results, r => {
|
|
154
|
-
if (r.TAG === "Ok") {
|
|
155
|
-
return;
|
|
156
|
-
} else {
|
|
157
|
-
return r._0;
|
|
158
|
-
}
|
|
159
|
-
}).flat();
|
|
160
|
-
if (errors.length > 0) {
|
|
161
|
-
return {
|
|
162
|
-
TAG: "Error",
|
|
163
|
-
_0: errors
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
let modules = Core__Array.filterMap(results, r => {
|
|
167
|
-
if (r.TAG === "Ok") {
|
|
168
|
-
return r._0;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
return {
|
|
172
|
-
TAG: "Ok",
|
|
173
|
-
_0: {
|
|
174
|
-
modules: modules
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
exit = 2;
|
|
179
|
-
} else {
|
|
180
|
-
exit = 2;
|
|
181
|
-
}
|
|
182
|
-
if (exit === 2) {
|
|
183
|
-
return {
|
|
184
|
-
TAG: "Error",
|
|
185
|
-
_0: [Errors.makeError({
|
|
186
|
-
TAG: "MissingRequiredField",
|
|
187
|
-
_0: "modules"
|
|
188
|
-
}, [], `Config must have a "modules" object`, undefined)]
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
TAG: "Error",
|
|
194
|
-
_0: [Errors.makeError({
|
|
195
|
-
TAG: "InvalidJson",
|
|
196
|
-
_0: "config must be an object"
|
|
197
|
-
}, undefined, undefined, undefined)]
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export {
|
|
202
|
-
parseFieldConfig,
|
|
203
|
-
parseModuleConfig,
|
|
204
|
-
parse,
|
|
205
|
-
}
|
|
206
|
-
/* No side effect */
|
package/src/DomainGen.res.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function generateField(param) {
|
|
5
|
-
let fieldConfig = param[1];
|
|
6
|
-
let name = param[0];
|
|
7
|
-
let mapper = fieldConfig.mapper;
|
|
8
|
-
let mapping;
|
|
9
|
-
if (mapper !== undefined) {
|
|
10
|
-
mapping = {
|
|
11
|
-
TAG: "Mapper",
|
|
12
|
-
_0: mapper
|
|
13
|
-
};
|
|
14
|
-
} else {
|
|
15
|
-
let s = fieldConfig.source;
|
|
16
|
-
let sourceName = s !== undefined ? s : name;
|
|
17
|
-
mapping = {
|
|
18
|
-
TAG: "Passthrough",
|
|
19
|
-
_0: sourceName
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
name: name,
|
|
24
|
-
typeAnnotation: fieldConfig.type_,
|
|
25
|
-
mapping: mapping
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function generateModule(param, apiModule) {
|
|
30
|
-
let moduleConfig = param[1];
|
|
31
|
-
let name = param[0];
|
|
32
|
-
let o = moduleConfig.output;
|
|
33
|
-
let output = o !== undefined ? o : name + ".gen.res";
|
|
34
|
-
let sourceType = apiModule + "." + moduleConfig.source;
|
|
35
|
-
let fields = moduleConfig.fields.map(generateField);
|
|
36
|
-
return {
|
|
37
|
-
name: name,
|
|
38
|
-
sourceType: sourceType,
|
|
39
|
-
output: output,
|
|
40
|
-
fields: fields
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function generate(config, apiModule) {
|
|
45
|
-
return config.modules.map(entry => generateModule(entry, apiModule));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
generateField,
|
|
50
|
-
generateModule,
|
|
51
|
-
generate,
|
|
52
|
-
}
|
|
53
|
-
/* No side effect */
|
package/src/DomainIR.res.mjs
DELETED
package/src/Errors.res.mjs
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
4
|
-
|
|
5
|
-
function makeLocation(pathOpt, lineOpt, columnOpt, param) {
|
|
6
|
-
let path = pathOpt !== undefined ? pathOpt : [];
|
|
7
|
-
let line = lineOpt !== undefined ? Primitive_option.valFromOption(lineOpt) : undefined;
|
|
8
|
-
let column = columnOpt !== undefined ? Primitive_option.valFromOption(columnOpt) : undefined;
|
|
9
|
-
return {
|
|
10
|
-
path: path,
|
|
11
|
-
line: line,
|
|
12
|
-
column: column
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function makeError(kind, pathOpt, hintOpt, param) {
|
|
17
|
-
let path = pathOpt !== undefined ? pathOpt : [];
|
|
18
|
-
let hint = hintOpt !== undefined ? Primitive_option.valFromOption(hintOpt) : undefined;
|
|
19
|
-
return {
|
|
20
|
-
kind: kind,
|
|
21
|
-
location: makeLocation(path, undefined, undefined, undefined),
|
|
22
|
-
hint: hint
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function unknownType(value, pathOpt, hintOpt, param) {
|
|
27
|
-
let path = pathOpt !== undefined ? pathOpt : [];
|
|
28
|
-
let hint = hintOpt !== undefined ? Primitive_option.valFromOption(hintOpt) : undefined;
|
|
29
|
-
return makeError({
|
|
30
|
-
TAG: "UnknownType",
|
|
31
|
-
_0: value
|
|
32
|
-
}, path, Primitive_option.some(hint), undefined);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function missingField(field, pathOpt, hintOpt, param) {
|
|
36
|
-
let path = pathOpt !== undefined ? pathOpt : [];
|
|
37
|
-
let hint = hintOpt !== undefined ? Primitive_option.valFromOption(hintOpt) : undefined;
|
|
38
|
-
return makeError({
|
|
39
|
-
TAG: "MissingRequiredField",
|
|
40
|
-
_0: field
|
|
41
|
-
}, path, Primitive_option.some(hint), undefined);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function invalidRef(ref, pathOpt, hintOpt, param) {
|
|
45
|
-
let path = pathOpt !== undefined ? pathOpt : [];
|
|
46
|
-
let hint = hintOpt !== undefined ? Primitive_option.valFromOption(hintOpt) : undefined;
|
|
47
|
-
return makeError({
|
|
48
|
-
TAG: "InvalidRef",
|
|
49
|
-
_0: ref
|
|
50
|
-
}, path, Primitive_option.some(hint), undefined);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function formatError(error) {
|
|
54
|
-
let parts = error.location.path;
|
|
55
|
-
let pathStr = parts.length !== 0 ? "#/" + parts.join("/") : "#";
|
|
56
|
-
let value = error.kind;
|
|
57
|
-
let kindStr;
|
|
58
|
-
if (typeof value !== "object") {
|
|
59
|
-
kindStr = "Ambiguous union (anyOf/oneOf cannot be distinguished)";
|
|
60
|
-
} else {
|
|
61
|
-
switch (value.TAG) {
|
|
62
|
-
case "UnknownType" :
|
|
63
|
-
kindStr = `Unknown type "` + value._0 + `"`;
|
|
64
|
-
break;
|
|
65
|
-
case "MissingRequiredField" :
|
|
66
|
-
kindStr = `Missing required field "` + value._0 + `"`;
|
|
67
|
-
break;
|
|
68
|
-
case "InvalidRef" :
|
|
69
|
-
kindStr = `Invalid reference "` + value._0 + `"`;
|
|
70
|
-
break;
|
|
71
|
-
case "UnsupportedFeature" :
|
|
72
|
-
kindStr = `Unsupported feature "` + value._0 + `"`;
|
|
73
|
-
break;
|
|
74
|
-
case "InvalidFormat" :
|
|
75
|
-
kindStr = `Invalid format "` + value._0 + `"`;
|
|
76
|
-
break;
|
|
77
|
-
case "CircularReference" :
|
|
78
|
-
kindStr = `Circular reference detected: "` + value._0 + `"`;
|
|
79
|
-
break;
|
|
80
|
-
case "MissingDiscriminator" :
|
|
81
|
-
kindStr = `Missing discriminator for union "` + value._0 + `"`;
|
|
82
|
-
break;
|
|
83
|
-
case "InvalidJson" :
|
|
84
|
-
kindStr = `Invalid JSON: ` + value._0;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
let hint = error.hint;
|
|
89
|
-
let hintStr = hint !== undefined ? `\n Hint: ` + hint : "";
|
|
90
|
-
return `Error at ` + pathStr + `:\n ` + kindStr + hintStr;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function formatErrors(errors) {
|
|
94
|
-
return errors.map(formatError).join("\n\n");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export {
|
|
98
|
-
makeLocation,
|
|
99
|
-
makeError,
|
|
100
|
-
unknownType,
|
|
101
|
-
missingField,
|
|
102
|
-
invalidRef,
|
|
103
|
-
formatError,
|
|
104
|
-
formatErrors,
|
|
105
|
-
}
|
|
106
|
-
/* No side effect */
|
package/src/IR.res.mjs
DELETED