flack 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2db9db527f885215d426f53353b9cc428d35bb54e6b11205a31c04ef234410f6
4
- data.tar.gz: 5b2242b4137b08e65064682b7aa37f3f92267e58c7acca773580168b290b1cf5
3
+ metadata.gz: 83938d22a1da3371d405bc6f6f9ad5458d2e44ac21616b99df1d3f1058ffbc40
4
+ data.tar.gz: 5c844ae9c4eeca795a70cbcacfd616e40217b120ca75ae6d8368e343bb87746c
5
5
  SHA512:
6
- metadata.gz: 11f46755eaa4d5aac73d8478bfa2de24dc3c6c3c7f29673eeec75a2932149452726c6c77c71b6eec5a53bf3401ca61851b9dbd04ddeca26f931128e460d711b8
7
- data.tar.gz: 3fbb4eb5155ae97de8ab8cee7c4b99e4634c18fad5e5263e288e411f63f08286821021b6b05372bfeafccf845e4cdaee8b04a559b8b737e23728ee96c25641ca
6
+ metadata.gz: 43ca7e422779cc153db5c11db80a7048a9f526de6f2382e88b67a1b3fb12418f9a4a3e87e72b948bb685bd22e18ae8bb3d5d549dd24d00d840ce6b3f16ac5a17
7
+ data.tar.gz: fdca36864febf3ac369363de3fbe1b1687efbeb850f84b5ba3131d7af66d710d4e61d163a33c18c3b4923314c8eb3f7ddad3992e169de085aec80b476ac3d2c2
data/CHANGELOG.md CHANGED
@@ -2,7 +2,15 @@
2
2
  # flack CHANGELOG.md
3
3
 
4
4
 
5
- ## flack 0.17.0 not yet released
5
+ ## flack 1.2.0 released 2021-03-29
6
+
7
+ - Simplify links
8
+ - Remove dependency on HttpClient gem
9
+ - Introduce DELETE /executions/:exid
10
+ - Ensure METHS order, stabilize across Ruby versions
11
+
12
+
13
+ ## flack 1.0.0 released 2020-11-22
6
14
 
7
15
  - Leave Sequel dependency to flor
8
16
 
data/Makefile CHANGED
@@ -70,3 +70,9 @@ stop:
70
70
  restart:
71
71
  @if [ -f $(PID_FILE) ]; then make -s stop; fi; make -s start
72
72
 
73
+ # Calls / and lists the links available
74
+ #
75
+ links:
76
+ bundle exec ruby -Ilib -r 'flack' \
77
+ -e "app = Flack::App.new('envs/test/', start: false); pp JSON.parse(app.call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/', 'REQUEST_PATH' => '/', 'SCRIPT_NAME' => '')[2].first)"
78
+
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # flack
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/floraison/flack.svg)](http://travis-ci.org/floraison/flack)
4
+ [![tests](https://github.com/floraison/flack/workflows/test/badge.svg)](https://github.com/floraison/flack/actions)
5
5
  [![Gem Version](https://badge.fury.io/rb/flack.svg)](http://badge.fury.io/rb/flack)
6
6
 
7
7
  Flack is a Rack app for the [flor](https://github.com/floraison/flor) workflow engine.
@@ -20,7 +20,7 @@ Warning: this serves an API, not some fancy web interface.
20
20
 
21
21
  ## api
22
22
 
23
- Based on HAL ([spec](http://stateless.co/hal_specification.html) and [draft](https://tools.ietf.org/html/draft-kelly-json-hal-08)).
23
+ Based on HAL ([spec](http://stateless.co/hal_specification.html) and [draft](https://tools.ietf.org/html/draft-kelly-json-hal-08)), [URI Template](https://tools.ietf.org/html/rfc6570), and [CURIE](https://www.w3.org/TR/curie/).
24
24
 
25
25
 
26
26
  ## license
data/flack.gemspec CHANGED
@@ -32,7 +32,7 @@ A web front-end to the flor workflow engine
32
32
  s.add_runtime_dependency 'flor'
33
33
 
34
34
  s.add_runtime_dependency 'rack', '>= 1.6', '< 3.0'
35
- s.add_runtime_dependency 'httpclient', '~> 2.8'
35
+ #s.add_runtime_dependency 'httpclient', '~> 2.8'
36
36
 
37
37
  s.add_development_dependency 'rspec', '~> 3'
38
38
 
data/lib/flack.rb CHANGED
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
3
+ require 'cgi'
2
4
  require 'rack'
3
5
 
4
6
  require 'flor/unit'
@@ -6,7 +8,7 @@ require 'flor/unit'
6
8
 
7
9
  module Flack
8
10
 
9
- VERSION = '1.0.0'
11
+ VERSION = '1.2.0'
10
12
  end
11
13
 
12
14
  require 'flack/app'
data/lib/flack/app.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'flack/app/helpers'
3
4
  #
@@ -6,6 +7,7 @@ require 'flack/app/static'
6
7
  require 'flack/app/message'
7
8
  require 'flack/app/executions'
8
9
  require 'flack/app/messages'
10
+ require 'flack/app/pointers'
9
11
 
10
12
 
11
13
  class Flack::App
@@ -99,6 +101,7 @@ class Flack::App
99
101
  .collect(&:to_s)
100
102
  .select { |m| m.match(/\A(get|head|put|post|delete)_.+\z/) }
101
103
  .select { |m| instance_method(m).arity == 1 }
104
+ .sort
102
105
  .collect { |m|
103
106
  s = m.split('_')
104
107
  if s.length == 3 && s[2] == 'suffix'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # /executions/*
3
4
  #
@@ -10,7 +11,14 @@ class Flack::App
10
11
  # TODO implement paging
11
12
  env['flack.rel'] = 'flack:executions'
12
13
 
13
- respond(env, @unit.executions.all)
14
+ qs = CGI.parse(env['QUERY_STRING'] || '')
15
+ statuses = qs['status']
16
+ statuses = nil if statuses == []
17
+
18
+ q = @unit.executions
19
+ q = q.where(status: statuses) if statuses
20
+
21
+ respond(env, q.all)
14
22
  end
15
23
 
16
24
  # GET /executions/<id>
@@ -42,6 +50,39 @@ class Flack::App
42
50
  end
43
51
  end
44
52
 
53
+ # DELETE /executions/<exid>
54
+ #
55
+ def delete_executions_s(env)
56
+
57
+ exid = env['flack.args'][0]
58
+
59
+ return respond_not_found(env) \
60
+ unless @unit.executions.where(exid: exid).count > 0
61
+
62
+ r = { exid: exid, counts: {} }
63
+ cs = r[:counts]
64
+
65
+ @unit.storage.db.transaction do
66
+
67
+ cs[:messages] = @unit.messages.where(exid: exid).count
68
+ cs[:executions] = @unit.executions.where(exid: exid).count
69
+ cs[:pointers] = @unit.pointers.where(exid: exid).count
70
+ cs[:timers] = @unit.timers.where(exid: exid).count
71
+ cs[:traps] = @unit.traps.where(exid: exid).count
72
+ #
73
+ # not sure if the DB adapter returns the DELETE count,
74
+ # so counting first
75
+
76
+ @unit.messages.where(exid: exid).delete
77
+ @unit.executions.where(exid: exid).delete
78
+ @unit.pointers.where(exid: exid).delete
79
+ @unit.timers.where(exid: exid).delete
80
+ @unit.traps.where(exid: exid).delete
81
+ end
82
+
83
+ respond(env, r)
84
+ end
85
+
45
86
  protected
46
87
 
47
88
  def get_executions_by_exid(env, exid)
@@ -57,6 +98,10 @@ class Flack::App
57
98
 
58
99
  def get_executions_by_domain(env, dom)
59
100
 
101
+ qs = CGI.parse(env['QUERY_STRING'] || '')
102
+ statuses = qs['status']
103
+ statuses = nil if statuses == []
104
+
60
105
  q = @unit.executions
61
106
 
62
107
  if m = dom.match(/\A([^*]+)\*+\z/)
@@ -74,6 +119,8 @@ class Flack::App
74
119
  q = q.where(domain: dom)
75
120
  end
76
121
 
122
+ q = q.where(status: statuses) if statuses
123
+
77
124
  respond(env, q.all)
78
125
  end
79
126
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # helpers
3
4
  #
@@ -108,6 +109,7 @@ class Flack::App
108
109
  l[:templated] = true if type.index('{')
109
110
 
110
111
  rel_right_part = type
112
+ .gsub(/\{\?[^}]*\}/, '')
111
113
  .gsub(/[{}]/, '')
112
114
  .gsub(/\./, '-dot')
113
115
  .gsub(/\*/, '-star')
@@ -115,6 +117,11 @@ class Flack::App
115
117
  h["flack:#{rel_right_part}"] = l
116
118
  end
117
119
 
120
+ CURIES = [ {
121
+ name: 'flack',
122
+ href: 'https://github.com/floraison/flack/blob/master/doc/rels.md#{rel}',
123
+ templated: true } ].freeze
124
+
118
125
  def links(env)
119
126
 
120
127
  h = {}
@@ -124,15 +131,12 @@ class Flack::App
124
131
  m = env['REQUEST_METHOD']
125
132
  h['self'][:method] = m unless %w[ GET HEAD ].include?(m)
126
133
 
127
- h['curies'] = [{
128
- name: 'flack',
129
- href: 'https://github.com/floraison/flack/blob/master/doc/rels.md#{rel}',
130
- templated: true }]
134
+ h['curies'] = CURIES
131
135
 
132
- link(env, h, 'executions')
133
- link(env, h, 'executions/{domain}')
134
- link(env, h, 'executions/{domain}*')
135
- link(env, h, 'executions/{domain}.*')
136
+ link(env, h, 'executions{?status}')
137
+ link(env, h, 'executions/{domain}{?status}')
138
+ link(env, h, 'executions/{domain}*{?status}')
139
+ link(env, h, 'executions/{domain}.*{?status}')
136
140
  link(env, h, 'executions/{exid}')
137
141
  link(env, h, 'executions/{id}')
138
142
 
@@ -142,6 +146,12 @@ class Flack::App
142
146
  link(env, h, 'messages/{exid}')
143
147
  link(env, h, 'messages/{id}')
144
148
 
149
+ link(env, h, 'pointers{?type}')
150
+ link(env, h, 'pointers/{exid}{?type}')
151
+ link(env, h, 'pointers/{domain}{?type}')
152
+ link(env, h, 'pointers/{domain}*{?type}')
153
+ link(env, h, 'pointers/{domain}.*{?type}')
154
+
145
155
  h
146
156
  end
147
157
 
@@ -149,11 +159,19 @@ class Flack::App
149
159
 
150
160
  h = {}
151
161
 
162
+ h['curies'] = CURIES
163
+
152
164
  h['flack:forms/message'] = {
153
165
  action: rel(env, '/message'),
154
166
  method: 'POST',
155
167
  _inputs: { 'flack:forms/message-content' => { type: 'json' } } }
156
168
 
169
+ h['flack:forms/execution-deletion'] = {
170
+ action: rel(env, '/executions/{exid}'),
171
+ method: 'DELETE',
172
+ _inputs: {},
173
+ templated: true }
174
+
157
175
  h
158
176
  end
159
177
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # /
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # /message
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # /messages/*
3
4
  #
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ # /pointers/*
4
+ #
5
+ class Flack::App
6
+
7
+ # GET /pointers
8
+ #
9
+ def get_pointers(env)
10
+
11
+ # TODO implement paging
12
+ env['flack.rel'] = 'flack:pointers'
13
+
14
+ qs = CGI.parse(env['QUERY_STRING'] || '')
15
+ types = qs['types'].collect { |e| e.split(',') }.flatten
16
+ types = nil if types == []
17
+
18
+ q = @unit.pointers
19
+ q = q.where(type: types) if types
20
+
21
+ respond(env, q.all)
22
+ end
23
+
24
+ # GET /pointers/<exid>
25
+ # GET /pointers/<domain>
26
+ # GET /pointers/<domain>*
27
+ # GET /pointers/<domain>.*
28
+ #
29
+ def get_pointers_s(env)
30
+
31
+ arg = env['flack.args'][0]
32
+
33
+ qs = CGI.parse(env['QUERY_STRING'] || '')
34
+
35
+ types = qs['types'].collect { |e| e.split(',') }.flatten
36
+ types = nil if types == []
37
+
38
+ if arg.count('-') == 0
39
+ get_pointers_by_domain(env, arg, types)
40
+ else
41
+ get_pointers_by_exid(env, arg, types)
42
+ end
43
+ end
44
+
45
+ protected
46
+
47
+ def get_pointers_by_exid(env, exid, types)
48
+
49
+ env['flack.rel'] = 'flack:pointers/exid'
50
+
51
+ q = @unit.pointers.where(exid: exid)
52
+ q = q.where(type: types) if types
53
+
54
+ respond(env, q.all)
55
+ end
56
+
57
+ def get_pointers_by_domain(env, dom, types)
58
+
59
+ q = @unit.pointers
60
+ q = q.where(type: types) if types
61
+
62
+ if m = dom.match(/\A([^*]+)\*+\z/)
63
+ if m[1][-1, 1] == '.'
64
+ env['flack.rel'] = 'flack:pointers/domain-dot-star'
65
+ q = q.where(Sequel.like(:domain, "#{m[1]}%"))
66
+ else
67
+ env['flack.rel'] = 'flack:pointers/domain-star'
68
+ q = q.where(
69
+ Sequel[{ domain: m[1] }] |
70
+ Sequel.like(:domain, "#{m[1]}.%"))
71
+ end
72
+ else
73
+ env['flack.rel'] = 'flack:pointers/domain'
74
+ q = q.where(domain: dom)
75
+ end
76
+
77
+ respond(env, q.all)
78
+ end
79
+ end
80
+
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # /*.html
3
4
  # /*.css
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-22 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flor
@@ -44,20 +44,6 @@ dependencies:
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
- - !ruby/object:Gem::Dependency
48
- name: httpclient
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '2.8'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '2.8'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: rspec
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +77,7 @@ files:
91
77
  - lib/flack/app/index.rb
92
78
  - lib/flack/app/message.rb
93
79
  - lib/flack/app/messages.rb
80
+ - lib/flack/app/pointers.rb
94
81
  - lib/flack/app/static.rb
95
82
  homepage: https://github.com/floraison/flack
96
83
  licenses: