triangulum 0.0.0 → 0.5.1
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/validation.rb +102 -0
- data/lib/triangulum/version.rb +1 -1
- data/lib/triangulum.rb +6 -2
- metadata +85 -11
- data/.rspec +0 -3
- data/.rubocop.yml +0 -16
- data/Rakefile +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f137764486446b6e51d9128b0b70ec8dd1b2196fe9305362a24dc301c679aa37
|
|
4
|
+
data.tar.gz: b933bf128294b70979a14d4cfed7cca1a198a6000717c6278c23ada61788ca6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a622fa85400a9899c3f628ec72533c9b7c05f6832c9712d3a374be948188cead8275b6b27e9c93baea4f45f3319efc0016a3dca84d824e047eb81cbc3cc5b54c
|
|
7
|
+
data.tar.gz: ebc28c4fbaa4dde0727ace7c7e90631a15990ac64faf91bc3fbf4729a0e47eb97d614de075bb1a0f86c06f6cd2c830230212ad5e7b8ea6b77a0e9e7adbfafc9e
|
data/README.md
CHANGED
|
@@ -1,35 +1,77 @@
|
|
|
1
|
-
# Triangulum
|
|
1
|
+
# Triangulum Ruby Gem
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/triangulum`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
3
|
+
Ruby bindings for the [Triangulum](https://github.com/code0-tech/triangulum) validation layer. This gem wraps the TypeScript library and a bundled [Bun](https://bun.sh) runtime to validate flows using the TypeScript compiler.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
|
7
|
+
Add to your Gemfile:
|
|
12
8
|
|
|
13
|
-
```
|
|
14
|
-
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'triangulum'
|
|
15
11
|
```
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
Platform-specific gems are published for:
|
|
14
|
+
|
|
15
|
+
- `arm64-darwin` (macOS Apple Silicon)
|
|
16
|
+
- `x86_64-darwin` (macOS Intel)
|
|
17
|
+
- `x86_64-linux-gnu` (Linux x64)
|
|
18
|
+
- `x86_64-linux-musl` (Linux x64 musl)
|
|
19
|
+
- `aarch64-linux-gnu` (Linux ARM64)
|
|
20
|
+
- `aarch64-linux-musl` (Linux ARM64 musl)
|
|
21
|
+
|
|
22
|
+
If Bundler doesn't automatically select the correct platform gem, add your platform:
|
|
18
23
|
|
|
19
24
|
```bash
|
|
20
|
-
|
|
25
|
+
bundle lock --add-platform x86_64-linux-gnu
|
|
21
26
|
```
|
|
22
27
|
|
|
23
28
|
## Usage
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
```ruby
|
|
31
|
+
result = Triangulum::Validation.new(flow, runtime_function_definitions, data_types).validate
|
|
32
|
+
|
|
33
|
+
result.valid? # => true / false
|
|
34
|
+
result.return_type # => "void"
|
|
35
|
+
result.diagnostics # => [Triangulum::Validation::Diagnostic, ...]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The arguments are [Tucana](https://github.com/code0-tech/tucana) protobuf objects:
|
|
39
|
+
|
|
40
|
+
- `flow` — `Tucana::Shared::ValidationFlow`
|
|
41
|
+
- `runtime_function_definitions` — `Array<Tucana::Shared::RuntimeFunctionDefinition>`
|
|
42
|
+
- `data_types` — `Array<Tucana::Shared::DefinitionDataType>`
|
|
43
|
+
|
|
44
|
+
### Diagnostics
|
|
45
|
+
|
|
46
|
+
Each diagnostic contains:
|
|
47
|
+
|
|
48
|
+
| Field | Description |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `message` | Human-readable error description |
|
|
51
|
+
| `code` | TypeScript diagnostic code |
|
|
52
|
+
| `severity` | `"error"` or `"warning"` |
|
|
53
|
+
| `node_id` | ID of the node that caused the error |
|
|
54
|
+
| `parameter_index` | Index of the parameter that caused the error |
|
|
26
55
|
|
|
27
56
|
## Development
|
|
28
57
|
|
|
29
|
-
|
|
58
|
+
Prerequisites: [Bun](https://bun.sh) installed locally for building the entrypoint.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
cd gem
|
|
62
|
+
bundle install
|
|
63
|
+
bundle exec rake prepare_build # downloads bun binaries + builds JS entrypoint
|
|
64
|
+
bundle exec rake # run tests and rubocop
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Building platform gems
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
bundle exec rake package
|
|
71
|
+
```
|
|
30
72
|
|
|
31
|
-
|
|
73
|
+
This will download bun binaries (with SHA256 checksum verification) for all supported platforms and build a `.gem` file for each.
|
|
32
74
|
|
|
33
|
-
##
|
|
75
|
+
## License
|
|
34
76
|
|
|
35
|
-
|
|
77
|
+
See [LICENSE](../LICENSE).
|
|
@@ -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.1
|
|
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,15 @@ 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/validation.rb
|
|
107
181
|
- lib/triangulum/version.rb
|
|
108
182
|
homepage: https://github.com/code0-tech/triangulum
|
|
109
|
-
licenses:
|
|
183
|
+
licenses:
|
|
184
|
+
- MIT
|
|
110
185
|
metadata:
|
|
111
186
|
homepage_uri: https://github.com/code0-tech/triangulum
|
|
112
|
-
source_code_uri: https://github.com/code0-tech/triangulum
|
|
113
187
|
changelog_uri: https://github.com/code0-tech/triangulum/releases
|
|
114
188
|
rubygems_mfa_required: 'true'
|
|
115
189
|
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
|