triangulum 0.0.0 → 0.5.2
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.
- checksums.yaml +4 -4
- data/README.md +58 -16
- data/lib/triangulum/js/single-validation.js +173681 -0
- data/lib/triangulum/validation.rb +102 -0
- data/lib/triangulum/version.rb +1 -1
- data/lib/triangulum.rb +6 -2
- metadata +86 -11
- data/.rspec +0 -3
- data/.rubocop.yml +0 -16
- data/Rakefile +0 -12
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Triangulum
|
|
4
|
+
# == Triangulum::Validation
|
|
5
|
+
# This class implements the validation using the typescript package
|
|
6
|
+
class Validation
|
|
7
|
+
class TriangulumFailed < Triangulum::Error
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class BunNotFound < Triangulum::Error
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Result = Struct.new(:valid?, :return_type, :diagnostics, keyword_init: true)
|
|
14
|
+
Diagnostic = Struct.new(:message, :code, :severity, :node_id, :parameter_index, keyword_init: true)
|
|
15
|
+
|
|
16
|
+
ENTRYPOINT = File.expand_path('js/single-validation.js', __dir__)
|
|
17
|
+
BUN_EXE = Dir.glob(File.expand_path('../../exe/*/bun', __dir__)).find do |path|
|
|
18
|
+
platform = Gem::Platform.new(File.basename(File.dirname(path)))
|
|
19
|
+
Gem::Platform.match_gem?(platform, Gem::Platform.local.to_s)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
IS_RUBY_PLATFORM_GEM = Dir.glob(File.expand_path('../../exe/*/bun', __dir__)).empty?
|
|
23
|
+
|
|
24
|
+
attr_reader :flow, :runtime_function_definitions, :data_types
|
|
25
|
+
|
|
26
|
+
def initialize(flow, runtime_function_definitions, data_types)
|
|
27
|
+
@flow = flow
|
|
28
|
+
@runtime_function_definitions = runtime_function_definitions
|
|
29
|
+
@data_types = data_types
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def validate
|
|
33
|
+
input = serialize_input
|
|
34
|
+
|
|
35
|
+
output = run_ts_triangulum(input)
|
|
36
|
+
|
|
37
|
+
parse_output(output)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def run_ts_triangulum(input)
|
|
43
|
+
stdout_s, stderr_s, status = Open3.capture3(
|
|
44
|
+
bun, 'run', ENTRYPOINT,
|
|
45
|
+
stdin_data: input
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
raise TriangulumFailed, "OUT:\n#{stdout_s}\n\nERR:\n#{stderr_s}" unless status.success?
|
|
49
|
+
|
|
50
|
+
stdout_s
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def serialize_input
|
|
54
|
+
input = []
|
|
55
|
+
|
|
56
|
+
input << Base64.strict_encode64(flow.to_proto)
|
|
57
|
+
input << ''
|
|
58
|
+
|
|
59
|
+
runtime_function_definitions.each do |rfd|
|
|
60
|
+
input << Base64.strict_encode64(rfd.to_proto)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
input << ''
|
|
64
|
+
|
|
65
|
+
data_types.each do |dt|
|
|
66
|
+
input << Base64.strict_encode64(dt.to_proto)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
input << ''
|
|
70
|
+
|
|
71
|
+
input.join("\n")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def parse_output(output)
|
|
75
|
+
json = JSON.parse(output, symbolize_names: true)
|
|
76
|
+
|
|
77
|
+
Result.new(
|
|
78
|
+
valid?: json[:isValid],
|
|
79
|
+
return_type: json[:returnType],
|
|
80
|
+
diagnostics: json[:diagnostics].map do |diagnostic|
|
|
81
|
+
Diagnostic.new(
|
|
82
|
+
message: diagnostic[:message],
|
|
83
|
+
code: diagnostic[:code],
|
|
84
|
+
severity: diagnostic[:severity],
|
|
85
|
+
node_id: diagnostic[:nodeId],
|
|
86
|
+
parameter_index: diagnostic[:parameterIndex]
|
|
87
|
+
)
|
|
88
|
+
end
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def bun
|
|
93
|
+
if IS_RUBY_PLATFORM_GEM
|
|
94
|
+
'bun'
|
|
95
|
+
else
|
|
96
|
+
raise BunNotFound, "No bundled bun binary found for #{Gem::Platform.local}" if BUN_EXE.nil?
|
|
97
|
+
|
|
98
|
+
BUN_EXE
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
data/lib/triangulum/version.rb
CHANGED
data/lib/triangulum.rb
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'open3'
|
|
4
6
|
|
|
5
7
|
module Triangulum
|
|
6
8
|
class Error < StandardError; end
|
|
7
|
-
# Your code goes here...
|
|
8
9
|
end
|
|
10
|
+
|
|
11
|
+
require_relative 'triangulum/version'
|
|
12
|
+
require_relative 'triangulum/validation'
|
metadata
CHANGED
|
@@ -1,28 +1,90 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: triangulum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Niklas van Schrick
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: base64
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.3'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.3'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: json
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.19'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.19'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: open3
|
|
14
42
|
requirement: !ruby/object:Gem::Requirement
|
|
15
43
|
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0.2'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0.2'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: tucana
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0.0'
|
|
16
61
|
- - ">="
|
|
17
62
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
19
|
-
type: :
|
|
63
|
+
version: 0.0.62
|
|
64
|
+
type: :runtime
|
|
20
65
|
prerelease: false
|
|
21
66
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
67
|
requirements:
|
|
68
|
+
- - "~>"
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0.0'
|
|
23
71
|
- - ">="
|
|
24
72
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
73
|
+
version: 0.0.62
|
|
74
|
+
- !ruby/object:Gem::Dependency
|
|
75
|
+
name: irb
|
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - "~>"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '1.17'
|
|
81
|
+
type: :development
|
|
82
|
+
prerelease: false
|
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - "~>"
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '1.17'
|
|
26
88
|
- !ruby/object:Gem::Dependency
|
|
27
89
|
name: rake
|
|
28
90
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -37,6 +99,20 @@ dependencies:
|
|
|
37
99
|
- - "~>"
|
|
38
100
|
- !ruby/object:Gem::Version
|
|
39
101
|
version: '13.0'
|
|
102
|
+
- !ruby/object:Gem::Dependency
|
|
103
|
+
name: rubyzip
|
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - "~>"
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '2.3'
|
|
109
|
+
type: :development
|
|
110
|
+
prerelease: false
|
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - "~>"
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '2.3'
|
|
40
116
|
- !ruby/object:Gem::Dependency
|
|
41
117
|
name: rspec
|
|
42
118
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -99,17 +175,16 @@ executables: []
|
|
|
99
175
|
extensions: []
|
|
100
176
|
extra_rdoc_files: []
|
|
101
177
|
files:
|
|
102
|
-
- ".rspec"
|
|
103
|
-
- ".rubocop.yml"
|
|
104
178
|
- README.md
|
|
105
|
-
- Rakefile
|
|
106
179
|
- lib/triangulum.rb
|
|
180
|
+
- lib/triangulum/js/single-validation.js
|
|
181
|
+
- lib/triangulum/validation.rb
|
|
107
182
|
- lib/triangulum/version.rb
|
|
108
183
|
homepage: https://github.com/code0-tech/triangulum
|
|
109
|
-
licenses:
|
|
184
|
+
licenses:
|
|
185
|
+
- MIT
|
|
110
186
|
metadata:
|
|
111
187
|
homepage_uri: https://github.com/code0-tech/triangulum
|
|
112
|
-
source_code_uri: https://github.com/code0-tech/triangulum
|
|
113
188
|
changelog_uri: https://github.com/code0-tech/triangulum/releases
|
|
114
189
|
rubygems_mfa_required: 'true'
|
|
115
190
|
rdoc_options: []
|
data/.rspec
DELETED
data/.rubocop.yml
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
plugins:
|
|
2
|
-
- rubocop-rake
|
|
3
|
-
- rubocop-rspec
|
|
4
|
-
|
|
5
|
-
AllCops:
|
|
6
|
-
TargetRubyVersion: 3.1
|
|
7
|
-
NewCops: enable
|
|
8
|
-
|
|
9
|
-
Gemspec/DevelopmentDependencies:
|
|
10
|
-
EnforcedStyle: gemspec
|
|
11
|
-
|
|
12
|
-
Metrics:
|
|
13
|
-
Enabled: false
|
|
14
|
-
|
|
15
|
-
Style/StringLiteralsInInterpolation:
|
|
16
|
-
EnforcedStyle: double_quotes
|