trailblazer-pro 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +8 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +13 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/trailblazer/pro/client.rb +95 -0
- data/lib/trailblazer/pro/generate.rb +99 -0
- data/lib/trailblazer/pro/version.rb +5 -0
- data/lib/trailblazer/pro.rb +10 -0
- data/trailblazer-pro.gemspec +34 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f87a1d9c0c7d557676ed48a4c3bab753f618b2593e018bcf9aeca16560257a26
|
4
|
+
data.tar.gz: 6a97c8a6ff18033972a4113e5d794ff399cb2f64dc81dc8df8a3f76361cffcfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a2dc896a3d018eb93620f22e8ea5e528e2f6c737ede31612bf6ecd0f55824c863a99b30de790579b9d768988c693af0bf5b90eb5647e8e76c9cabd354c58fad
|
7
|
+
data.tar.gz: 30eb6636827c3070582f1b26a145c1b98a1d6fda95f19eba9565c6e95fe68492ab483eca897af37337b965fe8bf5899cd89d3fa4761ae80aa1c0919dc85ba7ff
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.0
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.11
|
17
|
+
bundle install
|
18
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Trailblazer::Pro
|
2
|
+
|
3
|
+
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/trailblazer/pro`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'trailblazer-pro'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install trailblazer-pro
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/trailblazer-pro.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "trailblazer/pro"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "base64"
|
3
|
+
require "json"
|
4
|
+
require "representable/json"
|
5
|
+
|
6
|
+
module Trailblazer::Developer
|
7
|
+
module Client
|
8
|
+
Diagram = Struct.new(:id, :body)
|
9
|
+
|
10
|
+
class Diagram::Representer < Representable::Decorator
|
11
|
+
include Representable::JSON
|
12
|
+
property :id
|
13
|
+
property :body, as: :diagram
|
14
|
+
end
|
15
|
+
|
16
|
+
module_function
|
17
|
+
|
18
|
+
def Diagram(id, body)
|
19
|
+
Diagram.new(id, body).freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
def import(id:, query:"", **options)
|
23
|
+
token = retrieve_token(**options)
|
24
|
+
export_diagram(id: id, token: token, query: query, **options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def retrieve_token(email:, api_key:, url: "/signin", **options)
|
28
|
+
body = JSON.generate({email: email, api_key: api_key})
|
29
|
+
|
30
|
+
response = request(token: nil, method: :get, url: url, body: body, **options)
|
31
|
+
return false unless response.status == 200
|
32
|
+
|
33
|
+
# token = CGI::Cookie.parse(response.headers["set-cookie"])["token"][0]
|
34
|
+
JSON.parse(response.body)["token"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def export_diagram(id:, query:, **options)
|
38
|
+
response = request(body: nil, url: "/api/v1/diagrams/#{id}/export#{query}", method: :get, **options)
|
39
|
+
|
40
|
+
# parse_response(response)
|
41
|
+
response.body
|
42
|
+
end
|
43
|
+
|
44
|
+
def duplicate(id:, **options)
|
45
|
+
token = retrieve_token(**options)
|
46
|
+
|
47
|
+
response = request(body: nil, token: token, url: "/api/v1/diagrams/#{id}/duplicate", method: :get, **options)
|
48
|
+
parse_response(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
# DISCUSS: do we need that?
|
52
|
+
def new_diagram(token:, **options)
|
53
|
+
response = request(body: nil, url: "/api/v1/diagrams/new", method: :get, token: token, **options)
|
54
|
+
|
55
|
+
# TODO: use Dry::Struct
|
56
|
+
# TODO: handle unauthorized/errors
|
57
|
+
parse_response(response)
|
58
|
+
end
|
59
|
+
|
60
|
+
def request(host:, url:, method:, token:, body:, **)
|
61
|
+
conn = Faraday.new(url: host)
|
62
|
+
|
63
|
+
conn.send(method) do |req|
|
64
|
+
req.url url
|
65
|
+
req.headers["Content-Type"] = "application/json"
|
66
|
+
req.body = body
|
67
|
+
req.headers["Authorization"] = token
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_response(response)
|
72
|
+
diagram = Diagram.new
|
73
|
+
Diagram::Representer.new(diagram).from_json(response.body) # a parsed hash would be cooler?
|
74
|
+
|
75
|
+
diagram
|
76
|
+
end
|
77
|
+
|
78
|
+
# TODO: remove me!
|
79
|
+
def self.push(operation:, name:)
|
80
|
+
xml = Trailblazer::Diagram::BPMN.to_xml(operation["__activity__"], operation["__sequence__"].map(&:id))
|
81
|
+
token = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJpZCI6MywidXNlcm5hbWUiOiJhcG90b25pY2siLCJlbWFpbCI6Im5pY2tAdHJhaWxibGF6ZXIudG8ifQ." # rubocop:disable Metrics/LineLength
|
82
|
+
conn = Faraday.new(url: "https://api.trb.to")
|
83
|
+
response = conn.post do |req|
|
84
|
+
req.url "/dev/v1/import"
|
85
|
+
req.headers["Content-Type"] = "application/json"
|
86
|
+
req.headers["Authorization"] = token
|
87
|
+
require "base64"
|
88
|
+
|
89
|
+
req.body = %({ "name": "#{name}", "xml":"#{Base64.strict_encode64(xml)}" })
|
90
|
+
end
|
91
|
+
|
92
|
+
puts response.status.inspect
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
gem "representable"
|
2
|
+
require "representable/hash"
|
3
|
+
require "trailblazer/activity/dsl/linear" # Railway.
|
4
|
+
|
5
|
+
module Trailblazer
|
6
|
+
module Developer
|
7
|
+
# Computes an {Intermediate} data structure from a TRB-editor.js file.
|
8
|
+
module Generate
|
9
|
+
module_function
|
10
|
+
|
11
|
+
Element = Struct.new(:id, :type, :linksTo, :data, :label, :parent)
|
12
|
+
Arrow = Struct.new(:target, :label, :message, :target_lane)
|
13
|
+
|
14
|
+
module Representer
|
15
|
+
class Activity < Representable::Decorator
|
16
|
+
include Representable::Hash
|
17
|
+
|
18
|
+
collection :elements, class: Element do
|
19
|
+
property :id
|
20
|
+
property :type
|
21
|
+
collection :linksTo, class: Arrow, default: ::Declarative::Variables::Append([]) do
|
22
|
+
property :target
|
23
|
+
property :label
|
24
|
+
property :message
|
25
|
+
property :target_lane
|
26
|
+
end
|
27
|
+
property :data, default: {}
|
28
|
+
|
29
|
+
property :label
|
30
|
+
property :parent # TODO: remove?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(hash)
|
36
|
+
_, (ctx, _) = Activity::TaskWrap.invoke(Pipeline, [{hash: hash}, {}])
|
37
|
+
ctx[:intermediate]
|
38
|
+
end
|
39
|
+
|
40
|
+
def transform_from_hash(ctx, hash:, parser: Representer::Activity, **)
|
41
|
+
ctx[:elements] = parser.new(OpenStruct.new).from_hash(hash).elements
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_start_events(ctx, elements:, **)
|
45
|
+
ctx[:start_events] = elements.find_all { |el| el.type == "Event" }
|
46
|
+
end
|
47
|
+
|
48
|
+
def compute_intermediate(ctx, elements:, start_events:, **)
|
49
|
+
end_events = elements.find_all { |el| el.type == "EndEventTerminate" } # DISCUSS: is it really called TERMINATE?
|
50
|
+
|
51
|
+
inter = Activity::Schema::Intermediate
|
52
|
+
|
53
|
+
wiring = elements.collect { |el|
|
54
|
+
data = data_for(el)
|
55
|
+
|
56
|
+
[inter.TaskRef(el.id, data), el.linksTo.collect { |arrow| inter.Out(semantic_for(**arrow.to_h), arrow.target) } ] }
|
57
|
+
wiring = Hash[wiring]
|
58
|
+
|
59
|
+
# end events need this stupid special handling
|
60
|
+
# DISCUSS: currently, the END-SEMANTIC is read from the event's label.
|
61
|
+
wiring = wiring.merge(Hash[
|
62
|
+
end_events.collect do |_end|
|
63
|
+
ref, = wiring.find { |ref, _| ref.id == _end.id }
|
64
|
+
|
65
|
+
[ref, [inter.Out(semantic_for(**_end.to_h)|| raise, nil)]] # TODO: test the raise, happens when the semantic of an End can't be distinguished. # TODO: don't extract semantic from :label but from :data.
|
66
|
+
end
|
67
|
+
])
|
68
|
+
# pp wiring
|
69
|
+
|
70
|
+
ctx[:intermediate] = inter.new(wiring, end_events.collect(&:id), start_events.collect(&:id))
|
71
|
+
end
|
72
|
+
|
73
|
+
# private
|
74
|
+
|
75
|
+
def data_for(element)
|
76
|
+
{type: element.type}.merge(element.data)
|
77
|
+
end
|
78
|
+
|
79
|
+
# We currently use the {:label} field of an arrow to encode an output semantic.
|
80
|
+
# The {:symbol_style} part will be filtered out as semantic. Defaults to {:success}.
|
81
|
+
def semantic_for(label:nil, **)
|
82
|
+
return :success unless label
|
83
|
+
|
84
|
+
extract_semantic(label)
|
85
|
+
end
|
86
|
+
|
87
|
+
def extract_semantic(label)
|
88
|
+
label.to_sym
|
89
|
+
end
|
90
|
+
|
91
|
+
class Pipeline < Trailblazer::Activity::Railway
|
92
|
+
step Generate.method(:transform_from_hash), id: :transform_from_hash
|
93
|
+
step Generate.method(:find_start_events), id: :find_start_events
|
94
|
+
step Generate.method(:compute_intermediate), id: :compute_intermediate
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
# [Inter::Out(:success, nil)]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/trailblazer/pro/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "trailblazer-pro"
|
7
|
+
spec.version = Trailblazer::Pro::VERSION
|
8
|
+
spec.authors = ["Nick Sutterer"]
|
9
|
+
spec.email = ["apotonick@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Integrations for our BPMN editor."
|
12
|
+
# spec.description = "TODO: Write a longer description or delete this line."
|
13
|
+
spec.homepage = "https://trailblazer.to/2.1/docs/pro.html"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/trailblazer/trailblazer-pro"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/trailblazer/trailblazer-pro/blob/master/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
# Uncomment to register a new dependency of your gem
|
30
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
31
|
+
|
32
|
+
# For more information and examples about making a new gem, checkout our
|
33
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trailblazer-pro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Sutterer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- apotonick@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".github/workflows/main.yml"
|
21
|
+
- ".gitignore"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- lib/trailblazer/pro.rb
|
29
|
+
- lib/trailblazer/pro/client.rb
|
30
|
+
- lib/trailblazer/pro/generate.rb
|
31
|
+
- lib/trailblazer/pro/version.rb
|
32
|
+
- trailblazer-pro.gemspec
|
33
|
+
homepage: https://trailblazer.to/2.1/docs/pro.html
|
34
|
+
licenses: []
|
35
|
+
metadata:
|
36
|
+
homepage_uri: https://trailblazer.to/2.1/docs/pro.html
|
37
|
+
source_code_uri: https://github.com/trailblazer/trailblazer-pro
|
38
|
+
changelog_uri: https://github.com/trailblazer/trailblazer-pro/blob/master/CHANGELOG.md
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.4.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.2.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Integrations for our BPMN editor.
|
58
|
+
test_files: []
|