osury 0.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.
@@ -0,0 +1,103 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Errors from "./Errors.res.mjs";
4
+ import * as Schema from "./Schema.res.mjs";
5
+ import * as Core__Array from "@rescript/core/src/Core__Array.res.mjs";
6
+
7
+ function parseDocument(json) {
8
+ if (typeof json === "object" && json !== null && !Array.isArray(json)) {
9
+ let match = json["components"];
10
+ if (match === undefined) {
11
+ return {
12
+ TAG: "Ok",
13
+ _0: []
14
+ };
15
+ }
16
+ let exit = 0;
17
+ if (typeof match === "object" && match !== null && !Array.isArray(match)) {
18
+ let match$1 = match["schemas"];
19
+ if (match$1 === undefined) {
20
+ return {
21
+ TAG: "Ok",
22
+ _0: []
23
+ };
24
+ }
25
+ let exit$1 = 0;
26
+ if (typeof match$1 === "object" && match$1 !== null && !Array.isArray(match$1)) {
27
+ let entries = Object.entries(match$1);
28
+ let results = entries.map(param => {
29
+ let schemaType = Schema.parse(param[1]);
30
+ if (schemaType.TAG === "Ok") {
31
+ return {
32
+ TAG: "Ok",
33
+ _0: {
34
+ name: param[0],
35
+ schema: schemaType._0
36
+ }
37
+ };
38
+ } else {
39
+ return {
40
+ TAG: "Error",
41
+ _0: schemaType._0
42
+ };
43
+ }
44
+ });
45
+ let errors = Core__Array.filterMap(results, r => {
46
+ if (r.TAG === "Ok") {
47
+ return;
48
+ } else {
49
+ return r._0;
50
+ }
51
+ }).flat();
52
+ if (errors.length > 0) {
53
+ return {
54
+ TAG: "Error",
55
+ _0: errors
56
+ };
57
+ }
58
+ let schemas = Core__Array.filterMap(results, r => {
59
+ if (r.TAG === "Ok") {
60
+ return r._0;
61
+ }
62
+ });
63
+ return {
64
+ TAG: "Ok",
65
+ _0: schemas
66
+ };
67
+ }
68
+ exit$1 = 3;
69
+ if (exit$1 === 3) {
70
+ return {
71
+ TAG: "Error",
72
+ _0: [Errors.makeError({
73
+ TAG: "InvalidJson",
74
+ _0: "schemas must be an object"
75
+ }, undefined, undefined, undefined)]
76
+ };
77
+ }
78
+ } else {
79
+ exit = 2;
80
+ }
81
+ if (exit === 2) {
82
+ return {
83
+ TAG: "Error",
84
+ _0: [Errors.makeError({
85
+ TAG: "InvalidJson",
86
+ _0: "components must be an object"
87
+ }, undefined, undefined, undefined)]
88
+ };
89
+ }
90
+ }
91
+ return {
92
+ TAG: "Error",
93
+ _0: [Errors.makeError({
94
+ TAG: "InvalidJson",
95
+ _0: "document must be an object"
96
+ }, undefined, undefined, undefined)]
97
+ };
98
+ }
99
+
100
+ export {
101
+ parseDocument,
102
+ }
103
+ /* No side effect */
@@ -0,0 +1,27 @@
1
+ /* TypeScript file generated from Schema.res by genType. */
2
+
3
+ /* eslint-disable */
4
+ /* tslint:disable */
5
+
6
+ export type field = {
7
+ readonly name: string;
8
+ readonly type: schemaType;
9
+ readonly required: boolean
10
+ };
11
+
12
+ export type variantCase = { readonly _tag: string; readonly payload: schemaType };
13
+
14
+ export type schemaType =
15
+ "String"
16
+ | "Number"
17
+ | "Integer"
18
+ | "Boolean"
19
+ | "Null"
20
+ | { _tag: "Optional"; _0: schemaType }
21
+ | { _tag: "Object"; _0: field[] }
22
+ | { _tag: "Array"; _0: schemaType }
23
+ | { _tag: "Ref"; _0: string }
24
+ | { _tag: "Enum"; _0: string[] }
25
+ | { _tag: "PolyVariant"; _0: variantCase[] }
26
+ | { _tag: "Dict"; _0: schemaType }
27
+ | { _tag: "Union"; _0: schemaType[] };