@teamkeel/wasm 0.26.0 → 0.29.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/index.js +610 -0
- package/package.json +6 -3
- package/build.mjs +0 -13
- package/index.ts +0 -29
- package/keel.wasm +0 -0
- package/lib/wasm_exec.js +0 -554
- package/lib/wasm_exec_node.js +0 -26
- package/main.go +0 -122
- package/tsconfig.json +0 -16
- package/types.d.ts +0 -4
package/main.go
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
//go:build wasm
|
|
2
|
-
|
|
3
|
-
package main
|
|
4
|
-
|
|
5
|
-
import (
|
|
6
|
-
"encoding/json"
|
|
7
|
-
"syscall/js"
|
|
8
|
-
|
|
9
|
-
"github.com/fatih/color"
|
|
10
|
-
"github.com/teamkeel/keel/schema"
|
|
11
|
-
"github.com/teamkeel/keel/schema/format"
|
|
12
|
-
"github.com/teamkeel/keel/schema/parser"
|
|
13
|
-
"github.com/teamkeel/keel/schema/reader"
|
|
14
|
-
"github.com/teamkeel/keel/schema/validation/errorhandling"
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
func init() {
|
|
18
|
-
// we have to declare our functions in an init func otherwise they aren't
|
|
19
|
-
// available in JS land at the call time.
|
|
20
|
-
js.Global().Set("keel", js.ValueOf(map[string]interface{}{
|
|
21
|
-
"validate": js.FuncOf(validate),
|
|
22
|
-
"format": js.FuncOf(formatSchema),
|
|
23
|
-
}))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
func main() {
|
|
27
|
-
done := make(chan bool)
|
|
28
|
-
<-done
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
func formatSchema(this js.Value, args []js.Value) interface{} {
|
|
32
|
-
ast, err := parser.Parse(&reader.SchemaFile{
|
|
33
|
-
FileName: "schema.keel",
|
|
34
|
-
Contents: args[0].String(),
|
|
35
|
-
})
|
|
36
|
-
if err != nil {
|
|
37
|
-
// if the schema can't be parsed then just return it as-is
|
|
38
|
-
return js.ValueOf(args[0].String())
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return js.ValueOf(format.Format(ast))
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Type definition for this function:
|
|
45
|
-
// validate(schema: string, options?: {color: boolean})
|
|
46
|
-
func validate(this js.Value, args []js.Value) interface{} {
|
|
47
|
-
|
|
48
|
-
if len(args) > 1 {
|
|
49
|
-
withColor := args[1].Get("color").Truthy()
|
|
50
|
-
if withColor {
|
|
51
|
-
color.NoColor = false
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
schemaFile := reader.SchemaFile{
|
|
56
|
-
FileName: "schema.keel",
|
|
57
|
-
Contents: args[0].String(),
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
builder := schema.Builder{}
|
|
61
|
-
var validationErrors map[string]interface{}
|
|
62
|
-
var validationOutput string
|
|
63
|
-
|
|
64
|
-
_, err := builder.MakeFromInputs(&reader.Inputs{
|
|
65
|
-
SchemaFiles: []reader.SchemaFile{schemaFile},
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
if err != nil {
|
|
69
|
-
errs, ok := err.(errorhandling.ValidationErrors)
|
|
70
|
-
if ok {
|
|
71
|
-
validationErrors, err = toMap(errs)
|
|
72
|
-
if err != nil {
|
|
73
|
-
return js.ValueOf(map[string]interface{}{
|
|
74
|
-
"error": err.Error(),
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
validationOutput, err = errs.ToAnnotatedSchema([]reader.SchemaFile{
|
|
79
|
-
schemaFile,
|
|
80
|
-
})
|
|
81
|
-
if err != nil {
|
|
82
|
-
return js.ValueOf(map[string]interface{}{
|
|
83
|
-
"error": err.Error(),
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
return js.ValueOf(map[string]interface{}{
|
|
88
|
-
"error": err.Error(),
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
var astMap map[string]interface{}
|
|
94
|
-
asts := builder.ASTs()
|
|
95
|
-
if len(asts) > 0 {
|
|
96
|
-
astMap, err = toMap(asts[0])
|
|
97
|
-
if err != nil {
|
|
98
|
-
return js.ValueOf(map[string]interface{}{
|
|
99
|
-
"error": err.Error(),
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return js.ValueOf(map[string]interface{}{
|
|
105
|
-
"ast": astMap,
|
|
106
|
-
"validationErrors": validationErrors,
|
|
107
|
-
"validationOutput": validationOutput,
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// js.ValueOf can only marshall map[string]interface{} to a JS object
|
|
112
|
-
// so for structs we need to do the struct->json->map[string]interface{} dance
|
|
113
|
-
func toMap(v interface{}) (map[string]interface{}, error) {
|
|
114
|
-
b, err := json.Marshal(v)
|
|
115
|
-
if err != nil {
|
|
116
|
-
return nil, err
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
var res map[string]interface{}
|
|
120
|
-
err = json.Unmarshal(b, &res)
|
|
121
|
-
return res, err
|
|
122
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES6",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"lib": [
|
|
7
|
-
"DOM"
|
|
8
|
-
],
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"skipLibCheck": true
|
|
15
|
-
}
|
|
16
|
-
}
|
package/types.d.ts
DELETED