@f3liz/rescript-autogen-openapi 0.1.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/LICENSE +339 -0
- package/README.md +98 -0
- package/lib/es6/src/Codegen.mjs +423 -0
- package/lib/es6/src/Types.mjs +20 -0
- package/lib/es6/src/core/CodegenUtils.mjs +186 -0
- package/lib/es6/src/core/DocOverride.mjs +399 -0
- package/lib/es6/src/core/FileSystem.mjs +78 -0
- package/lib/es6/src/core/IRBuilder.mjs +201 -0
- package/lib/es6/src/core/OpenAPIParser.mjs +168 -0
- package/lib/es6/src/core/Pipeline.mjs +150 -0
- package/lib/es6/src/core/ReferenceResolver.mjs +41 -0
- package/lib/es6/src/core/Result.mjs +378 -0
- package/lib/es6/src/core/SchemaIR.mjs +355 -0
- package/lib/es6/src/core/SchemaIRParser.mjs +490 -0
- package/lib/es6/src/core/SchemaRefResolver.mjs +146 -0
- package/lib/es6/src/core/SchemaRegistry.mjs +92 -0
- package/lib/es6/src/core/SpecDiffer.mjs +251 -0
- package/lib/es6/src/core/SpecMerger.mjs +237 -0
- package/lib/es6/src/generators/ComponentSchemaGenerator.mjs +125 -0
- package/lib/es6/src/generators/DiffReportGenerator.mjs +155 -0
- package/lib/es6/src/generators/EndpointGenerator.mjs +172 -0
- package/lib/es6/src/generators/IRToSuryGenerator.mjs +233 -0
- package/lib/es6/src/generators/IRToTypeGenerator.mjs +241 -0
- package/lib/es6/src/generators/IRToTypeScriptGenerator.mjs +143 -0
- package/lib/es6/src/generators/ModuleGenerator.mjs +285 -0
- package/lib/es6/src/generators/SchemaCodeGenerator.mjs +77 -0
- package/lib/es6/src/generators/ThinWrapperGenerator.mjs +97 -0
- package/lib/es6/src/generators/TypeScriptDtsGenerator.mjs +172 -0
- package/lib/es6/src/generators/TypeScriptWrapperGenerator.mjs +145 -0
- package/lib/es6/src/types/CodegenError.mjs +79 -0
- package/lib/es6/src/types/Config.mjs +42 -0
- package/lib/es6/src/types/GenerationContext.mjs +24 -0
- package/package.json +44 -0
- package/rescript.json +20 -0
- package/src/Codegen.res +222 -0
- package/src/Types.res +195 -0
- package/src/core/CodegenUtils.res +130 -0
- package/src/core/DocOverride.res +504 -0
- package/src/core/FileSystem.res +62 -0
- package/src/core/IRBuilder.res +66 -0
- package/src/core/OpenAPIParser.res +144 -0
- package/src/core/Pipeline.res +51 -0
- package/src/core/ReferenceResolver.res +41 -0
- package/src/core/Result.res +187 -0
- package/src/core/SchemaIR.res +258 -0
- package/src/core/SchemaIRParser.res +360 -0
- package/src/core/SchemaRefResolver.res +143 -0
- package/src/core/SchemaRegistry.res +107 -0
- package/src/core/SpecDiffer.res +270 -0
- package/src/core/SpecMerger.res +245 -0
- package/src/generators/ComponentSchemaGenerator.res +127 -0
- package/src/generators/DiffReportGenerator.res +152 -0
- package/src/generators/EndpointGenerator.res +172 -0
- package/src/generators/IRToSuryGenerator.res +199 -0
- package/src/generators/IRToTypeGenerator.res +199 -0
- package/src/generators/IRToTypeScriptGenerator.res +72 -0
- package/src/generators/ModuleGenerator.res +362 -0
- package/src/generators/SchemaCodeGenerator.res +83 -0
- package/src/generators/ThinWrapperGenerator.res +124 -0
- package/src/generators/TypeScriptDtsGenerator.res +193 -0
- package/src/generators/TypeScriptWrapperGenerator.res +166 -0
- package/src/types/CodegenError.res +82 -0
- package/src/types/Config.res +89 -0
- package/src/types/GenerationContext.res +23 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
4
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
|
+
|
|
6
|
+
function parseMethod(methodStr) {
|
|
7
|
+
let match = methodStr.toLowerCase();
|
|
8
|
+
switch (match) {
|
|
9
|
+
case "delete" :
|
|
10
|
+
return "DELETE";
|
|
11
|
+
case "get" :
|
|
12
|
+
return "GET";
|
|
13
|
+
case "head" :
|
|
14
|
+
return "HEAD";
|
|
15
|
+
case "options" :
|
|
16
|
+
return "OPTIONS";
|
|
17
|
+
case "patch" :
|
|
18
|
+
return "PATCH";
|
|
19
|
+
case "post" :
|
|
20
|
+
return "POST";
|
|
21
|
+
case "put" :
|
|
22
|
+
return "PUT";
|
|
23
|
+
default:
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function httpMethodToString(method) {
|
|
29
|
+
if (method === "GET") {
|
|
30
|
+
return "get";
|
|
31
|
+
} else if (method === "PUT") {
|
|
32
|
+
return "put";
|
|
33
|
+
} else if (method === "DELETE") {
|
|
34
|
+
return "delete";
|
|
35
|
+
} else if (method === "HEAD") {
|
|
36
|
+
return "head";
|
|
37
|
+
} else if (method === "POST") {
|
|
38
|
+
return "post";
|
|
39
|
+
} else if (method === "PATCH") {
|
|
40
|
+
return "patch";
|
|
41
|
+
} else {
|
|
42
|
+
return "options";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function tupleToEndpoint(param) {
|
|
47
|
+
let operation = param[2];
|
|
48
|
+
return {
|
|
49
|
+
path: param[0],
|
|
50
|
+
method: httpMethodToString(param[1]),
|
|
51
|
+
operationId: operation.operationId,
|
|
52
|
+
summary: operation.summary,
|
|
53
|
+
description: operation.description,
|
|
54
|
+
tags: operation.tags,
|
|
55
|
+
requestBody: operation.requestBody,
|
|
56
|
+
responses: operation.responses,
|
|
57
|
+
parameters: operation.parameters
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getOperations(path, param) {
|
|
62
|
+
return Stdlib_Array.filterMap([
|
|
63
|
+
[
|
|
64
|
+
"GET",
|
|
65
|
+
param.get
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
"POST",
|
|
69
|
+
param.post
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
"PUT",
|
|
73
|
+
param.put
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
"PATCH",
|
|
77
|
+
param.patch
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
"DELETE",
|
|
81
|
+
param.delete
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
"HEAD",
|
|
85
|
+
param.head
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"OPTIONS",
|
|
89
|
+
param.options
|
|
90
|
+
]
|
|
91
|
+
], param => {
|
|
92
|
+
let method = param[0];
|
|
93
|
+
return Stdlib_Option.map(param[1], op => [
|
|
94
|
+
path,
|
|
95
|
+
method,
|
|
96
|
+
op
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getAllEndpoints(spec) {
|
|
102
|
+
let pathsArray = Object.entries(spec.paths);
|
|
103
|
+
return pathsArray.flatMap(param => getOperations(param[0], param[1])).map(tupleToEndpoint);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function groupByTag(endpoints) {
|
|
107
|
+
let grouped = {};
|
|
108
|
+
endpoints.forEach(endpoint => {
|
|
109
|
+
let tags = Stdlib_Option.getOr(endpoint.tags, ["default"]);
|
|
110
|
+
tags.forEach(tag => {
|
|
111
|
+
let existing = Stdlib_Option.getOr(grouped[tag], []);
|
|
112
|
+
existing.push(endpoint);
|
|
113
|
+
grouped[tag] = existing;
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return grouped;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getAllSchemas(spec) {
|
|
120
|
+
return Stdlib_Option.getOr(Stdlib_Option.flatMap(spec.components, c => c.schemas), {});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getOperationId(path, method, operation) {
|
|
124
|
+
let methodStr = method === "GET" ? "get" : (
|
|
125
|
+
method === "PUT" ? "put" : (
|
|
126
|
+
method === "DELETE" ? "delete" : (
|
|
127
|
+
method === "HEAD" ? "head" : (
|
|
128
|
+
method === "POST" ? "post" : (
|
|
129
|
+
method === "PATCH" ? "patch" : "options"
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
);
|
|
135
|
+
let pathParts = path.replaceAll("/", "_").replaceAll("{", "").replaceAll("}", "").replaceAll("-", "_");
|
|
136
|
+
return Stdlib_Option.getOr(operation.operationId, methodStr + pathParts);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function filterByTags(endpoints, includeTags, excludeTags) {
|
|
140
|
+
return endpoints.filter(endpoint => {
|
|
141
|
+
let operationTags = Stdlib_Option.getOr(endpoint.tags, []);
|
|
142
|
+
let included = operationTags.some(tag => includeTags.includes(tag));
|
|
143
|
+
let excluded = operationTags.some(tag => excludeTags.includes(tag));
|
|
144
|
+
if (included) {
|
|
145
|
+
return !excluded;
|
|
146
|
+
} else {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getAllTags(endpoints) {
|
|
153
|
+
return Array.from(new Set(endpoints.flatMap(endpoint => Stdlib_Option.getOr(endpoint.tags, []))));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
parseMethod,
|
|
158
|
+
httpMethodToString,
|
|
159
|
+
tupleToEndpoint,
|
|
160
|
+
getOperations,
|
|
161
|
+
getAllEndpoints,
|
|
162
|
+
groupByTag,
|
|
163
|
+
getAllSchemas,
|
|
164
|
+
getOperationId,
|
|
165
|
+
filterByTags,
|
|
166
|
+
getAllTags,
|
|
167
|
+
}
|
|
168
|
+
/* No side effect */
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
let empty_files = [];
|
|
5
|
+
|
|
6
|
+
let empty_warnings = [];
|
|
7
|
+
|
|
8
|
+
let empty = {
|
|
9
|
+
files: empty_files,
|
|
10
|
+
warnings: empty_warnings
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function merge(a, b) {
|
|
14
|
+
return {
|
|
15
|
+
files: a.files.concat(b.files),
|
|
16
|
+
warnings: a.warnings.concat(b.warnings)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function combine(outputs) {
|
|
21
|
+
return {
|
|
22
|
+
files: outputs.flatMap(p => p.files),
|
|
23
|
+
warnings: outputs.flatMap(p => p.warnings)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function addFile(file, p) {
|
|
28
|
+
return {
|
|
29
|
+
files: p.files.concat([file]),
|
|
30
|
+
warnings: p.warnings
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function addFiles(files, p) {
|
|
35
|
+
return {
|
|
36
|
+
files: p.files.concat(files),
|
|
37
|
+
warnings: p.warnings
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function addWarning(warning, p) {
|
|
42
|
+
return {
|
|
43
|
+
files: p.files,
|
|
44
|
+
warnings: p.warnings.concat([warning])
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function addWarnings(warnings, p) {
|
|
49
|
+
return {
|
|
50
|
+
files: p.files,
|
|
51
|
+
warnings: p.warnings.concat(warnings)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function mapFiles(fn, p) {
|
|
56
|
+
return {
|
|
57
|
+
files: p.files.map(fn),
|
|
58
|
+
warnings: p.warnings
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function filterWarnings(pred, p) {
|
|
63
|
+
return {
|
|
64
|
+
files: p.files,
|
|
65
|
+
warnings: p.warnings.filter(pred)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function make(filesOpt, warningsOpt, param) {
|
|
70
|
+
let files = filesOpt !== undefined ? filesOpt : [];
|
|
71
|
+
let warnings = warningsOpt !== undefined ? warningsOpt : [];
|
|
72
|
+
return {
|
|
73
|
+
files: files,
|
|
74
|
+
warnings: warnings
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fromFile(file) {
|
|
79
|
+
return make([file], undefined, undefined);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fromFiles(files) {
|
|
83
|
+
return make(files, undefined, undefined);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function fromWarning(warning) {
|
|
87
|
+
return make(undefined, [warning], undefined);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function fromWarnings(warnings) {
|
|
91
|
+
return make(undefined, warnings, undefined);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function files(p) {
|
|
95
|
+
return p.files;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function warnings(p) {
|
|
99
|
+
return p.warnings;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function fileCount(p) {
|
|
103
|
+
return p.files.length;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function warningCount(p) {
|
|
107
|
+
return p.warnings.length;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function filePaths(p) {
|
|
111
|
+
return p.files.map(f => f.path);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function withWarnings(p, w) {
|
|
115
|
+
return addWarnings(w, p);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function withFiles(p, f) {
|
|
119
|
+
return addFiles(f, p);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function fromFilesAndWarnings(files, warnings) {
|
|
123
|
+
return make(files, warnings, undefined);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
empty,
|
|
128
|
+
merge,
|
|
129
|
+
combine,
|
|
130
|
+
addFile,
|
|
131
|
+
addFiles,
|
|
132
|
+
addWarning,
|
|
133
|
+
addWarnings,
|
|
134
|
+
mapFiles,
|
|
135
|
+
filterWarnings,
|
|
136
|
+
make,
|
|
137
|
+
fromFile,
|
|
138
|
+
fromFiles,
|
|
139
|
+
fromWarning,
|
|
140
|
+
fromWarnings,
|
|
141
|
+
files,
|
|
142
|
+
warnings,
|
|
143
|
+
fileCount,
|
|
144
|
+
warningCount,
|
|
145
|
+
filePaths,
|
|
146
|
+
withWarnings,
|
|
147
|
+
withFiles,
|
|
148
|
+
fromFilesAndWarnings,
|
|
149
|
+
}
|
|
150
|
+
/* No side effect */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Text from "@std/text";
|
|
4
|
+
|
|
5
|
+
function refToTypePath(insideComponentSchemasOpt, modulePrefixOpt, ref) {
|
|
6
|
+
let insideComponentSchemas = insideComponentSchemasOpt !== undefined ? insideComponentSchemasOpt : false;
|
|
7
|
+
let modulePrefix = modulePrefixOpt !== undefined ? modulePrefixOpt : "";
|
|
8
|
+
let parts = ref.split("/");
|
|
9
|
+
let schemaName = parts[parts.length - 1 | 0];
|
|
10
|
+
if (schemaName === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let moduleName = Text.toPascalCase(schemaName);
|
|
14
|
+
if (insideComponentSchemas) {
|
|
15
|
+
return moduleName + `.t`;
|
|
16
|
+
} else {
|
|
17
|
+
return modulePrefix + `ComponentSchemas.` + moduleName + `.t`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function refToSchemaPath(insideComponentSchemasOpt, modulePrefixOpt, ref) {
|
|
22
|
+
let insideComponentSchemas = insideComponentSchemasOpt !== undefined ? insideComponentSchemasOpt : false;
|
|
23
|
+
let modulePrefix = modulePrefixOpt !== undefined ? modulePrefixOpt : "";
|
|
24
|
+
let parts = ref.split("/");
|
|
25
|
+
let schemaName = parts[parts.length - 1 | 0];
|
|
26
|
+
if (schemaName === undefined) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let moduleName = Text.toPascalCase(schemaName);
|
|
30
|
+
if (insideComponentSchemas) {
|
|
31
|
+
return moduleName + `.schema`;
|
|
32
|
+
} else {
|
|
33
|
+
return modulePrefix + `ComponentSchemas.` + moduleName + `.schema`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
refToTypePath,
|
|
39
|
+
refToSchemaPath,
|
|
40
|
+
}
|
|
41
|
+
/* @std/text Not a pure module */
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib from "@rescript/runtime/lib/es6/Stdlib.js";
|
|
4
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
6
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
7
|
+
|
|
8
|
+
function map2(ra, rb, f) {
|
|
9
|
+
if (ra.TAG === "Ok") {
|
|
10
|
+
if (rb.TAG === "Ok") {
|
|
11
|
+
return {
|
|
12
|
+
TAG: "Ok",
|
|
13
|
+
_0: f(ra._0, rb._0)
|
|
14
|
+
};
|
|
15
|
+
} else {
|
|
16
|
+
return {
|
|
17
|
+
TAG: "Error",
|
|
18
|
+
_0: rb._0
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
return {
|
|
23
|
+
TAG: "Error",
|
|
24
|
+
_0: ra._0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function map3(ra, rb, rc, f) {
|
|
30
|
+
if (ra.TAG === "Ok") {
|
|
31
|
+
if (rb.TAG === "Ok") {
|
|
32
|
+
if (rc.TAG === "Ok") {
|
|
33
|
+
return {
|
|
34
|
+
TAG: "Ok",
|
|
35
|
+
_0: f(ra._0, rb._0, rc._0)
|
|
36
|
+
};
|
|
37
|
+
} else {
|
|
38
|
+
return {
|
|
39
|
+
TAG: "Error",
|
|
40
|
+
_0: rc._0
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
return {
|
|
45
|
+
TAG: "Error",
|
|
46
|
+
_0: rb._0
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
return {
|
|
51
|
+
TAG: "Error",
|
|
52
|
+
_0: ra._0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function map4(ra, rb, rc, rd, f) {
|
|
58
|
+
if (ra.TAG === "Ok") {
|
|
59
|
+
if (rb.TAG === "Ok") {
|
|
60
|
+
if (rc.TAG === "Ok") {
|
|
61
|
+
if (rd.TAG === "Ok") {
|
|
62
|
+
return {
|
|
63
|
+
TAG: "Ok",
|
|
64
|
+
_0: f(ra._0, rb._0, rc._0, rd._0)
|
|
65
|
+
};
|
|
66
|
+
} else {
|
|
67
|
+
return {
|
|
68
|
+
TAG: "Error",
|
|
69
|
+
_0: rd._0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
return {
|
|
74
|
+
TAG: "Error",
|
|
75
|
+
_0: rc._0
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
return {
|
|
80
|
+
TAG: "Error",
|
|
81
|
+
_0: rb._0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
return {
|
|
86
|
+
TAG: "Error",
|
|
87
|
+
_0: ra._0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function all(results) {
|
|
93
|
+
let acc = [];
|
|
94
|
+
let error = {
|
|
95
|
+
contents: undefined
|
|
96
|
+
};
|
|
97
|
+
let len = results.length;
|
|
98
|
+
let loop = _idx => {
|
|
99
|
+
while (true) {
|
|
100
|
+
let idx = _idx;
|
|
101
|
+
if (!(idx < len && Stdlib_Option.isNone(error.contents))) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
let v = results[idx];
|
|
105
|
+
if (v.TAG !== "Ok") {
|
|
106
|
+
error.contents = Primitive_option.some(v._0);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
acc.push(v._0);
|
|
110
|
+
_idx = idx + 1 | 0;
|
|
111
|
+
continue;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
loop(0);
|
|
115
|
+
let e = error.contents;
|
|
116
|
+
if (e !== undefined) {
|
|
117
|
+
return {
|
|
118
|
+
TAG: "Error",
|
|
119
|
+
_0: Primitive_option.valFromOption(e)
|
|
120
|
+
};
|
|
121
|
+
} else {
|
|
122
|
+
return {
|
|
123
|
+
TAG: "Ok",
|
|
124
|
+
_0: acc
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function allUnit(results) {
|
|
130
|
+
let error = {
|
|
131
|
+
contents: undefined
|
|
132
|
+
};
|
|
133
|
+
let len = results.length;
|
|
134
|
+
let loop = _idx => {
|
|
135
|
+
while (true) {
|
|
136
|
+
let idx = _idx;
|
|
137
|
+
if (!(idx < len && Stdlib_Option.isNone(error.contents))) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let e = results[idx];
|
|
141
|
+
if (e.TAG !== "Ok") {
|
|
142
|
+
error.contents = Primitive_option.some(e._0);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
_idx = idx + 1 | 0;
|
|
146
|
+
continue;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
loop(0);
|
|
150
|
+
let e = error.contents;
|
|
151
|
+
if (e !== undefined) {
|
|
152
|
+
return {
|
|
153
|
+
TAG: "Error",
|
|
154
|
+
_0: Primitive_option.valFromOption(e)
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
return {
|
|
158
|
+
TAG: "Ok",
|
|
159
|
+
_0: undefined
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function partition(results) {
|
|
165
|
+
let successes = [];
|
|
166
|
+
let errors = [];
|
|
167
|
+
results.forEach(r => {
|
|
168
|
+
if (r.TAG === "Ok") {
|
|
169
|
+
successes.push(r._0);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
errors.push(r._0);
|
|
173
|
+
});
|
|
174
|
+
return [
|
|
175
|
+
successes,
|
|
176
|
+
errors
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function firstSuccess(results) {
|
|
181
|
+
let errors = [];
|
|
182
|
+
let success = {
|
|
183
|
+
contents: undefined
|
|
184
|
+
};
|
|
185
|
+
let len = results.length;
|
|
186
|
+
let loop = _idx => {
|
|
187
|
+
while (true) {
|
|
188
|
+
let idx = _idx;
|
|
189
|
+
if (!(idx < len && Stdlib_Option.isNone(success.contents))) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
let v = results[idx];
|
|
193
|
+
if (v.TAG === "Ok") {
|
|
194
|
+
success.contents = Primitive_option.some(v._0);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
errors.push(v._0);
|
|
198
|
+
_idx = idx + 1 | 0;
|
|
199
|
+
continue;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
loop(0);
|
|
203
|
+
let v = success.contents;
|
|
204
|
+
if (v !== undefined) {
|
|
205
|
+
return {
|
|
206
|
+
TAG: "Ok",
|
|
207
|
+
_0: Primitive_option.valFromOption(v)
|
|
208
|
+
};
|
|
209
|
+
} else {
|
|
210
|
+
return {
|
|
211
|
+
TAG: "Error",
|
|
212
|
+
_0: errors
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function foldM(arr, init, f) {
|
|
218
|
+
let loop = (acc, idx) => {
|
|
219
|
+
if (idx >= arr.length) {
|
|
220
|
+
return {
|
|
221
|
+
TAG: "Ok",
|
|
222
|
+
_0: acc
|
|
223
|
+
};
|
|
224
|
+
} else {
|
|
225
|
+
return Stdlib_Result.flatMap(f(acc, arr[idx]), newAcc => loop(newAcc, idx + 1 | 0));
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return loop(init, 0);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function tap(result, f) {
|
|
232
|
+
if (result.TAG === "Ok") {
|
|
233
|
+
f(result._0);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function tapError(result, f) {
|
|
239
|
+
if (result.TAG !== "Ok") {
|
|
240
|
+
f(result._0);
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function fromOption(opt, error) {
|
|
246
|
+
if (opt !== undefined) {
|
|
247
|
+
return {
|
|
248
|
+
TAG: "Ok",
|
|
249
|
+
_0: Primitive_option.valFromOption(opt)
|
|
250
|
+
};
|
|
251
|
+
} else {
|
|
252
|
+
return {
|
|
253
|
+
TAG: "Error",
|
|
254
|
+
_0: error
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function toOption(result) {
|
|
260
|
+
if (result.TAG === "Ok") {
|
|
261
|
+
return Primitive_option.some(result._0);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function recover(result, f) {
|
|
266
|
+
if (result.TAG === "Ok") {
|
|
267
|
+
return result;
|
|
268
|
+
} else {
|
|
269
|
+
return f(result._0);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function getOr(result, $$default) {
|
|
274
|
+
if (result.TAG === "Ok") {
|
|
275
|
+
return result._0;
|
|
276
|
+
} else {
|
|
277
|
+
return $$default;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function getExn(result) {
|
|
282
|
+
if (result.TAG === "Ok") {
|
|
283
|
+
return result._0;
|
|
284
|
+
} else {
|
|
285
|
+
return Stdlib.panic("Result.getExn called on Error");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function getError(result) {
|
|
290
|
+
if (result.TAG === "Ok") {
|
|
291
|
+
return;
|
|
292
|
+
} else {
|
|
293
|
+
return Primitive_option.some(result._0);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let getOrThrow = Stdlib_Result.getOrThrow;
|
|
298
|
+
|
|
299
|
+
let mapOr = Stdlib_Result.mapOr;
|
|
300
|
+
|
|
301
|
+
let mapWithDefault = Stdlib_Result.mapWithDefault;
|
|
302
|
+
|
|
303
|
+
let map = Stdlib_Result.map;
|
|
304
|
+
|
|
305
|
+
let flatMap = Stdlib_Result.flatMap;
|
|
306
|
+
|
|
307
|
+
let getWithDefault = Stdlib_Result.getWithDefault;
|
|
308
|
+
|
|
309
|
+
let isOk = Stdlib_Result.isOk;
|
|
310
|
+
|
|
311
|
+
let isError = Stdlib_Result.isError;
|
|
312
|
+
|
|
313
|
+
let equal = Stdlib_Result.equal;
|
|
314
|
+
|
|
315
|
+
let compare = Stdlib_Result.compare;
|
|
316
|
+
|
|
317
|
+
let forEach = Stdlib_Result.forEach;
|
|
318
|
+
|
|
319
|
+
let mapError = Stdlib_Result.mapError;
|
|
320
|
+
|
|
321
|
+
let all2 = Stdlib_Result.all2;
|
|
322
|
+
|
|
323
|
+
let all3 = Stdlib_Result.all3;
|
|
324
|
+
|
|
325
|
+
let all4 = Stdlib_Result.all4;
|
|
326
|
+
|
|
327
|
+
let all5 = Stdlib_Result.all5;
|
|
328
|
+
|
|
329
|
+
let all6 = Stdlib_Result.all6;
|
|
330
|
+
|
|
331
|
+
let mapOkAsync = Stdlib_Result.mapOkAsync;
|
|
332
|
+
|
|
333
|
+
let mapErrorAsync = Stdlib_Result.mapErrorAsync;
|
|
334
|
+
|
|
335
|
+
let flatMapOkAsync = Stdlib_Result.flatMapOkAsync;
|
|
336
|
+
|
|
337
|
+
let flatMapErrorAsync = Stdlib_Result.flatMapErrorAsync;
|
|
338
|
+
|
|
339
|
+
export {
|
|
340
|
+
getOrThrow,
|
|
341
|
+
mapOr,
|
|
342
|
+
mapWithDefault,
|
|
343
|
+
map,
|
|
344
|
+
flatMap,
|
|
345
|
+
getWithDefault,
|
|
346
|
+
isOk,
|
|
347
|
+
isError,
|
|
348
|
+
equal,
|
|
349
|
+
compare,
|
|
350
|
+
forEach,
|
|
351
|
+
mapError,
|
|
352
|
+
all2,
|
|
353
|
+
all3,
|
|
354
|
+
all4,
|
|
355
|
+
all5,
|
|
356
|
+
all6,
|
|
357
|
+
mapOkAsync,
|
|
358
|
+
mapErrorAsync,
|
|
359
|
+
flatMapOkAsync,
|
|
360
|
+
flatMapErrorAsync,
|
|
361
|
+
map2,
|
|
362
|
+
map3,
|
|
363
|
+
map4,
|
|
364
|
+
all,
|
|
365
|
+
allUnit,
|
|
366
|
+
partition,
|
|
367
|
+
firstSuccess,
|
|
368
|
+
foldM,
|
|
369
|
+
tap,
|
|
370
|
+
tapError,
|
|
371
|
+
fromOption,
|
|
372
|
+
toOption,
|
|
373
|
+
recover,
|
|
374
|
+
getOr,
|
|
375
|
+
getExn,
|
|
376
|
+
getError,
|
|
377
|
+
}
|
|
378
|
+
/* No side effect */
|