flack 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36dd9d587c7d003cc296db2fc3ac9f7dac0916e267a43904f5ca8be1e25b780e
4
- data.tar.gz: 1bc04ec7696966e9d197b80c25af1a76309463eabc88222d4777d769f866f9c6
3
+ metadata.gz: f3568a0f9f164613704ec78d2db777847180a5e6871dc77078aac09469506eed
4
+ data.tar.gz: f52a6ed6b32a249a98c5ac43d4d4178ea01a727995d6238efa458822502f9a81
5
5
  SHA512:
6
- metadata.gz: f8f69c70110ed67738d5c0ef95b97d4d0d0612520bbe8bab4c0353018f9bd0476bc48f29644514d3628cd2edb446abacdb38bf5392e2fbf95044a6401c7a3d37
7
- data.tar.gz: 59784ead309c9df695c416af89087d1fdf5e16d7900c758027da2f771b48337774252ee792e47fac32ba43fce0a86d2600798e155e420aecb357c1a235843bea
6
+ metadata.gz: 001a5dbaaebef7d8265b7a717da42972b1417eb1fc503e7ecc180c0320145038275a0ae7f6d51aa3fa6941757995147e96399844fbee04e648326d0008927fd3
7
+ data.tar.gz: cd6cd3d2952b87e8bd009b1bd6212889221a99a7e422a9865cab27398e567c290e7730f45a424e7c12c9c1d6ad30c08a9008a63337c0872e34f8d1d838189a4e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## flack 1.3.0 released 2023-03-29
6
+
7
+ - GET /pointers?count=true
8
+ - GET /executions?count=true
9
+ - GET /pointers?exid=net.ntt.finance-
10
+ - GET /pointers?dexid=20230310
11
+ - GET /executions?exid=net.ntt.finance-
12
+ - GET /executions?dexid=20230310
13
+ - Add Flack.on_unit_created(unit) callback
14
+
15
+
16
+ ## flack 1.2.2 released 2021-04-08
17
+
18
+ - let #rel fall back on PATH_INFO if no REQUEST_PATH
19
+
20
+
5
21
  ## flack 1.2.1 released 2021-04-08
6
22
 
7
23
  - Respond with a proper 500 error when necessary (and dump to $stderr)
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2016-2017, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2016-2023, John Mettraux, jmettraux+flor@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/Makefile CHANGED
@@ -1,10 +1,10 @@
1
1
 
2
2
  ## gem tasks ##
3
3
 
4
- NAME = \
5
- $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
6
- VERSION = \
7
- $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
4
+ NAME != \
5
+ ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name"
6
+ VERSION != \
7
+ ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version"
8
8
 
9
9
  PORT = 7007
10
10
  PID_FILE = tmp/$(NAME).pid
data/README.md CHANGED
@@ -23,6 +23,17 @@ Warning: this serves an API, not some fancy web interface.
23
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
+ ## in a rack app
27
+
28
+ ```ruby
29
+ map '/flack' do
30
+
31
+ run Flack::App.new('flor/')
32
+ # starts a flack app whose flor unit uses the tree at flor/
33
+ end
34
+ ```
35
+
36
+
26
37
  ## license
27
38
 
28
39
  MIT, see [LICENSE.txt](LICENSE.txt)
@@ -5,20 +5,31 @@
5
5
  class Flack::App
6
6
 
7
7
  # GET /executions
8
+ # GET /executions?exid=<exid_prefix>
9
+ # GET /executions?dexid=<date_exid_prefix>
8
10
  #
9
11
  def get_executions(env)
10
12
 
11
13
  # TODO implement paging
12
14
  env['flack.rel'] = 'flack:executions'
13
15
 
14
- qs = CGI.parse(env['QUERY_STRING'] || '')
15
- statuses = qs['status']
16
- statuses = nil if statuses == []
16
+ statuses = query_values(env, 'statuses', 'status')
17
+ exid = query_value(env, 'exid')
18
+ dexid = query_value(env, 'dexid')
17
19
 
18
20
  q = @unit.executions
21
+ #
19
22
  q = q.where(status: statuses) if statuses
23
+ q = q.where(Sequel.like(:exid, "#{exid}%")) if exid
24
+ q = q.where(Sequel.like(:exid, "%-#{dexid}%")) if dexid
25
+ #
26
+ q = q.order(:exid)
20
27
 
21
- respond(env, q.all)
28
+ if query_value(env, 'count')
29
+ respond(env, { count: q.count })
30
+ else
31
+ respond(env, q.all)
32
+ end
22
33
  end
23
34
 
24
35
  # GET /executions/<id>
@@ -98,9 +109,7 @@ class Flack::App
98
109
 
99
110
  def get_executions_by_domain(env, dom)
100
111
 
101
- qs = CGI.parse(env['QUERY_STRING'] || '')
102
- statuses = qs['status']
103
- statuses = nil if statuses == []
112
+ statuses = query_values(env, 'statuses', 'status')
104
113
 
105
114
  q = @unit.executions
106
115
 
@@ -126,14 +126,14 @@ class Flack::App
126
126
 
127
127
  h = {}
128
128
 
129
- h['self'] = {
130
- href: rel(env, env['REQUEST_PATH']) }
129
+ h['self'] = { href: rel(env, env['REQUEST_PATH'] || env['PATH_INFO']) }
130
+
131
131
  m = env['REQUEST_METHOD']
132
132
  h['self'][:method] = m unless %w[ GET HEAD ].include?(m)
133
133
 
134
134
  h['curies'] = CURIES
135
135
 
136
- link(env, h, 'executions{?status}')
136
+ link(env, h, 'executions{?status,exid,dexid,count}')
137
137
  link(env, h, 'executions/{domain}{?status}')
138
138
  link(env, h, 'executions/{domain}*{?status}')
139
139
  link(env, h, 'executions/{domain}.*{?status}')
@@ -146,11 +146,11 @@ class Flack::App
146
146
  link(env, h, 'messages/{exid}')
147
147
  link(env, h, 'messages/{id}')
148
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}')
149
+ link(env, h, 'pointers{?types,exid,dexid,count}')
150
+ link(env, h, 'pointers/{exid}{?types}')
151
+ link(env, h, 'pointers/{domain}{?types}')
152
+ link(env, h, 'pointers/{domain}*{?types}')
153
+ link(env, h, 'pointers/{domain}.*{?types}')
154
154
 
155
155
  h
156
156
  end
@@ -189,5 +189,29 @@ class Flack::App
189
189
 
190
190
  respond(env, {}, code: 500, error: error)
191
191
  end
192
+
193
+ def query_value(env, *keys)
194
+
195
+ query = (env['__query'] ||= CGI.parse(env['QUERY_STRING'] || ''))
196
+
197
+ r = keys.collect { |k| query[k] }.compact.first
198
+ r ? r.first : r
199
+ end
200
+
201
+ def query_values(env, *keys)
202
+
203
+ query = (env['__query'] ||= CGI.parse(env['QUERY_STRING'] || ''))
204
+
205
+ r = keys
206
+ .collect { |k| query[k] }
207
+ .select { |v| v != [] }
208
+ .first
209
+ return nil unless r
210
+
211
+ r = r.first.split(',').select { |e| e.length > 0 }
212
+ return nil if r == []
213
+
214
+ r
215
+ end
192
216
  end
193
217
 
@@ -64,7 +64,8 @@ class Flack::App
64
64
  return respond_not_found(env, 'missing execution node') \
65
65
  unless exe.nodes[nid]
66
66
 
67
- ret['xxx'] = @unit.queue({ 'point' => 'cancel', 'exid' => exid, 'nid' => nid }) # FIXME change me
67
+ ret['queued'] = @unit.queue({
68
+ 'point' => 'cancel', 'exid' => exid, 'nid' => nid })
68
69
 
69
70
  ret['_status'] = 202
70
71
  ret['_location'] = rel(env, '/executions/' + exid)
@@ -92,7 +93,8 @@ class Flack::App
92
93
  return respond_not_found(env, 'missing execution node') \
93
94
  unless exe.nodes[nid]
94
95
 
95
- ret['xxx'] = @unit.queue({ 'point' => 'return', 'exid' => exid, 'nid' => nid, 'payload' => payload}) # FIXME change me
96
+ ret['queued'] = @unit.queue({
97
+ 'point' => 'return', 'exid' => exid, 'nid' => nid, 'payload' => payload})
96
98
 
97
99
  ret['_status'] = 202
98
100
  ret['_location'] = rel(env, '/executions/' + exid)
@@ -10,6 +10,8 @@ class Flack::App
10
10
  # TODO implement paging
11
11
  env['flack.rel'] = 'flack:messages'
12
12
 
13
+ # TODO {?exid,dexid,count} like for /executions and /pointers
14
+
13
15
  respond(env, @unit.messages.all)
14
16
  end
15
17
 
@@ -5,20 +5,32 @@
5
5
  class Flack::App
6
6
 
7
7
  # GET /pointers
8
+ # GET /pointers?exid=<exid_prefix>
9
+ # GET /pointers?dexid=<date_exid_prefix>
8
10
  #
9
11
  def get_pointers(env)
10
12
 
11
13
  # TODO implement paging
12
14
  env['flack.rel'] = 'flack:pointers'
13
15
 
14
- qs = CGI.parse(env['QUERY_STRING'] || '')
15
- types = qs['types'].collect { |e| e.split(',') }.flatten
16
- types = nil if types == []
16
+ types = query_values(env, 'types', 'type')
17
+
18
+ exid = query_value(env, 'exid')
19
+ dexid = query_value(env, 'dexid')
17
20
 
18
21
  q = @unit.pointers
22
+ #
19
23
  q = q.where(type: types) if types
24
+ q = q.where(Sequel.like(:exid, "#{exid}%")) if exid
25
+ q = q.where(Sequel.like(:exid, "%-#{dexid}%")) if dexid
26
+ #
27
+ q = q.order(:exid)
20
28
 
21
- respond(env, q.all)
29
+ if query_value(env, 'count')
30
+ respond(env, { count: q.count })
31
+ else
32
+ respond(env, q.all)
33
+ end
22
34
  end
23
35
 
24
36
  # GET /pointers/<exid>
@@ -30,10 +42,7 @@ class Flack::App
30
42
 
31
43
  arg = env['flack.args'][0]
32
44
 
33
- qs = CGI.parse(env['QUERY_STRING'] || '')
34
-
35
- types = qs['types'].collect { |e| e.split(',') }.flatten
36
- types = nil if types == []
45
+ types = query_values(env, 'types', 'type')
37
46
 
38
47
  if arg.count('-') == 0
39
48
  get_pointers_by_domain(env, arg, types)
data/lib/flack/app.rb CHANGED
@@ -29,6 +29,8 @@ class Flack::App
29
29
 
30
30
  self.class.unit = @unit
31
31
 
32
+ Flack.on_unit_created(@unit) if Flack.respond_to?(:on_unit_created)
33
+
32
34
  @unit
33
35
  end
34
36
 
@@ -97,8 +99,11 @@ class Flack::App
97
99
 
98
100
  $stderr.puts '=' * 80
99
101
  $stderr.puts Time.now.to_s
102
+ $stderr.puts '-' * 80
100
103
  $stderr.puts err.inspect
101
104
  $stderr.puts err.backtrace
105
+ $stderr.puts '-' * 80
106
+ PP.pp(env, $stderr)
102
107
  $stderr.puts ('=' * 79) + '.'
103
108
 
104
109
  respond_internal_server_error(env, err)
data/lib/flack.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pp'
3
4
  require 'cgi'
4
5
  require 'rack'
5
6
 
@@ -8,7 +9,7 @@ require 'flor/unit'
8
9
 
9
10
  module Flack
10
11
 
11
- VERSION = '1.2.1'
12
+ VERSION = '1.3.0'
12
13
  end
13
14
 
14
15
  require 'flack/app'
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.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-08 00:00:00.000000000 Z
11
+ date: 2023-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flor
@@ -83,7 +83,7 @@ homepage: https://github.com/floraison/flack
83
83
  licenses:
84
84
  - MIT
85
85
  metadata: {}
86
- post_install_message:
86
+ post_install_message:
87
87
  rdoc_options: []
88
88
  require_paths:
89
89
  - lib
@@ -98,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.0.3
102
- signing_key:
101
+ rubygems_version: 3.2.33
102
+ signing_key:
103
103
  specification_version: 4
104
104
  summary: a web front-end to the flor workflow engine
105
105
  test_files: []