interfacets 0.9.9 → 0.99999
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/LICENSE +9 -17
- data/lib/interfacets/client/actor.rb +2 -1
- data/lib/interfacets/client/assets.rb +77 -63
- data/lib/interfacets/client/bus.rb +31 -8
- data/lib/interfacets/client/channels/api.rb +141 -35
- data/lib/interfacets/client/channels/audio.rb +13 -10
- data/lib/interfacets/client/channels/base.rb +2 -2
- data/lib/interfacets/client/channels/pubsub.rb +69 -0
- data/lib/interfacets/client/channels/react/builder.rb +42 -72
- data/lib/interfacets/client/channels/react/channel.rb +7 -5
- data/lib/interfacets/client/channels/react/evaluator.rb +6 -4
- data/lib/interfacets/client/channels/timer.rb +8 -7
- data/lib/interfacets/client/channels/url.rb +39 -6
- data/lib/interfacets/client/registry.rb +10 -70
- data/lib/interfacets/client/slots.rb +45 -0
- data/lib/interfacets/client/system.rb +20 -15
- data/lib/interfacets/client/template.rb +90 -0
- data/lib/interfacets/client/utils/mruby_patches.rb +8 -4
- data/lib/interfacets/client/utils/open_struct.rb +88 -77
- data/lib/interfacets/component_registry.rb +120 -0
- data/lib/interfacets/component_schema_parser.rb +88 -0
- data/lib/interfacets/mruby/build_config.rb +8 -4
- data/lib/interfacets/mruby/entrypoint.rb +2 -2
- data/lib/interfacets/server/api.rb +44 -27
- data/lib/interfacets/server/assets.rb +69 -28
- data/lib/interfacets/server/basic_router.rb +38 -23
- data/lib/interfacets/server/bus.rb +8 -14
- data/lib/interfacets/server/registry.rb +31 -185
- data/lib/interfacets/shared/basic_routable.rb +48 -0
- data/lib/interfacets/shared/entities/bus.rb +623 -177
- data/lib/interfacets/shared/entities/changeset.rb +432 -0
- data/lib/interfacets/shared/entities/collection_proxy.rb +132 -72
- data/lib/interfacets/shared/entities/specs/handlers.rb +74 -37
- data/lib/interfacets/shared/entities/specs.rb +223 -20
- data/lib/interfacets/shared/entity.rb +124 -110
- data/lib/interfacets/shared/entity_dsl.rb +272 -0
- data/lib/interfacets/shared/facet.rb +260 -0
- data/lib/interfacets/shared/generated_store.rb +74 -35
- data/lib/interfacets/shared/refreshable.rb +85 -0
- data/lib/interfacets/shared/utils.rb +36 -32
- data/lib/interfacets/shared/validations.rb +749 -25
- data/lib/interfacets/shared/view.rb +120 -0
- data/lib/interfacets/test/component_registry.rb +82 -0
- data/lib/interfacets/test/js/inline_bus.rb +68 -33
- data/lib/interfacets/test/js/nodo_bus.rb +37 -9
- data/lib/interfacets/test/js/receivers/api.rb +17 -4
- data/lib/interfacets/test/js/receivers/audio.rb +61 -0
- data/lib/interfacets/test/js/receivers/pubsub.rb +50 -0
- data/lib/interfacets/test/js/receivers/react/node/xml_parser.rb +103 -0
- data/lib/interfacets/test/js/receivers/react/node.rb +91 -71
- data/lib/interfacets/test/js/receivers/react.rb +15 -5
- data/lib/interfacets/test/js/receivers/timer.rb +81 -0
- data/lib/interfacets/test/js/receivers/url.rb +51 -10
- data/lib/interfacets/test/standard_elements.yml +173 -0
- data/lib/interfacets/test/ui_simulator.rb +145 -0
- data/lib/interfacets/test/validation_engine.rb +184 -0
- data/lib/interfacets/test.rb +1 -7
- data/lib/interfacets/version.rb +1 -1
- data/lib/interfacets.rb +13 -2
- metadata +51 -37
- data/.rubocop.yml +0 -180
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -10
- data/lib/interfacets/client/channels/page_visibility.rb +0 -21
- data/lib/interfacets/client/channels/react/dom.rb +0 -91
- data/lib/interfacets/client/channels/speech_to_text.rb +0 -100
- data/lib/interfacets/client/config.rb +0 -22
- data/lib/interfacets/client/delegator.rb +0 -37
- data/lib/interfacets/client/facet.rb +0 -26
- data/lib/interfacets/client/facet2.rb +0 -15
- data/lib/interfacets/client/facets/attributes/accessor.rb +0 -28
- data/lib/interfacets/client/facets/attributes/association.rb +0 -50
- data/lib/interfacets/client/facets/attributes/bind.rb +0 -25
- data/lib/interfacets/client/facets/attributes/collection.rb +0 -47
- data/lib/interfacets/client/facets/attributes/readonly.rb +0 -19
- data/lib/interfacets/client/facets/deserializer.rb +0 -30
- data/lib/interfacets/client/facets/schema/deserializer.rb +0 -63
- data/lib/interfacets/client/facets/schema.rb +0 -63
- data/lib/interfacets/client/facets/serializer.rb +0 -18
- data/lib/interfacets/client/view.rb +0 -47
- data/lib/interfacets/server/assets/facet.rb +0 -61
- data/lib/interfacets/server/basic_routable.rb +0 -40
- data/lib/interfacets/server/config.rb +0 -87
- data/lib/interfacets/server/facet.rb +0 -51
- data/lib/interfacets/server/facets/deserializer.rb +0 -25
- data/lib/interfacets/server/facets/schema/serializer.rb +0 -54
- data/lib/interfacets/server/facets/serializer.rb +0 -50
- data/lib/interfacets/shared/entity_collection.rb +0 -88
- data/lib/interfacets/test/browser.rb +0 -63
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Interfacets
|
|
4
|
+
module Client
|
|
5
|
+
class Template
|
|
6
|
+
RESERVED_SLOTS = %i[render capture slots evaluator call]
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def slot(name)
|
|
10
|
+
name = name.to_sym
|
|
11
|
+
if RESERVED_SLOTS.include?(name)
|
|
12
|
+
raise(
|
|
13
|
+
ArgumentError.new(
|
|
14
|
+
"Slot name :#{name} is reserved"
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
(@declared_slots ||= []) << name
|
|
20
|
+
define_method(name) do |&block|
|
|
21
|
+
slots[name] = block
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def declared_slots
|
|
26
|
+
inherited = superclass == Object ? [] : superclass.declared_slots
|
|
27
|
+
inherited + (@declared_slots || [])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# rubocop:disable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
31
|
+
def render(evaluator, c, **props, &block)
|
|
32
|
+
instance = new(evaluator, c)
|
|
33
|
+
instance.call(
|
|
34
|
+
c,
|
|
35
|
+
slots: instance.capture(&block),
|
|
36
|
+
**props
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def create(evaluator, c, slots: [], &block)
|
|
41
|
+
klass = Class.new(self)
|
|
42
|
+
Array(slots).each { klass.slot(_1) }
|
|
43
|
+
klass.new(evaluator, c).capture(&block)
|
|
44
|
+
end
|
|
45
|
+
# rubocop:enable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
attr_reader(:slots, :evaluator, :c)
|
|
49
|
+
def initialize(evaluator, c)
|
|
50
|
+
@evaluator = evaluator
|
|
51
|
+
@c = c
|
|
52
|
+
@slots = {}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# rubocop:disable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
56
|
+
def render(target, **opts, &block)
|
|
57
|
+
evaluator.render(target, **opts, &block)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def channel(name, **opts, &block)
|
|
61
|
+
evaluator.channel(name, **opts, &block)
|
|
62
|
+
end
|
|
63
|
+
# rubocop:enable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
64
|
+
|
|
65
|
+
def capture(&block)
|
|
66
|
+
main_nodes = nil
|
|
67
|
+
if block
|
|
68
|
+
# `capture` absorbs any direct `c.div` calls.
|
|
69
|
+
# Slot definitions (`s.header {}`) are just procs and aren't executed yet.
|
|
70
|
+
main_nodes = c.capture { block.call(self) }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
Interfacets::Client::Slots.new(
|
|
74
|
+
c:,
|
|
75
|
+
slots_hash: slots,
|
|
76
|
+
declared: self.class.declared_slots,
|
|
77
|
+
main_nodes:
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def main(&block)
|
|
82
|
+
slots[:main] = block
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def call(c, slots:, **props)
|
|
86
|
+
raise(NotImplementedError)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -13,7 +13,9 @@ module Interfacets
|
|
|
13
13
|
elsif block_given?
|
|
14
14
|
yield
|
|
15
15
|
elsif default == NO_DEFAULT
|
|
16
|
-
raise(
|
|
16
|
+
raise(
|
|
17
|
+
KeyError.new("key not found: #{k.inspect}")
|
|
18
|
+
)
|
|
17
19
|
else
|
|
18
20
|
default
|
|
19
21
|
end
|
|
@@ -21,9 +23,11 @@ module Interfacets
|
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
module InspectPatch
|
|
24
|
-
|
|
26
|
+
# rubocop:disable Naming/BlockForwarding
|
|
27
|
+
def inspect(*args, **opts, &block)
|
|
25
28
|
"<#{self.class}:#{self.object_id}>"
|
|
26
29
|
end
|
|
30
|
+
# rubocop:enable Naming/BlockForwarding
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
module ArrayPatch
|
|
@@ -31,7 +35,7 @@ module Interfacets
|
|
|
31
35
|
raise(ArgumentError) unless block_given?
|
|
32
36
|
|
|
33
37
|
result = {}
|
|
34
|
-
each {
|
|
38
|
+
each { result[yield(_1)] = _1 }
|
|
35
39
|
result
|
|
36
40
|
end
|
|
37
41
|
end
|
|
@@ -60,7 +64,7 @@ module Interfacets
|
|
|
60
64
|
|
|
61
65
|
module StringPresence
|
|
62
66
|
def blank?
|
|
63
|
-
match
|
|
67
|
+
!!match(/\A\s*\z/)
|
|
64
68
|
end
|
|
65
69
|
end
|
|
66
70
|
|
|
@@ -2,101 +2,112 @@
|
|
|
2
2
|
|
|
3
3
|
# copied from github
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@table[k] = v
|
|
12
|
-
new_ostruct_member(k)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
5
|
+
required = (
|
|
6
|
+
begin
|
|
7
|
+
require "ostruct"
|
|
8
|
+
true
|
|
9
|
+
rescue
|
|
10
|
+
false
|
|
15
11
|
end
|
|
12
|
+
)
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
super
|
|
19
|
-
@table = @table.dup
|
|
20
|
-
@table.each_key{|key| new_ostruct_member(key)}
|
|
21
|
-
end
|
|
14
|
+
unless required
|
|
22
15
|
|
|
23
|
-
def to_h
|
|
24
|
-
@table.dup
|
|
25
|
-
end
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
class OpenStruct
|
|
18
|
+
def initialize hash=nil
|
|
19
|
+
@table = {}
|
|
20
|
+
if hash
|
|
21
|
+
hash.each do |k,v|
|
|
22
|
+
k = k.to_sym
|
|
23
|
+
@table[k] = v
|
|
24
|
+
new_ostruct_member(k)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
define_singleton_method("#{name}=".to_sym){ |x| @table[name] = x }
|
|
29
|
+
def initialize_copy orig
|
|
30
|
+
super
|
|
31
|
+
@table = @table.dup
|
|
32
|
+
@table.each_key{|key| new_ostruct_member(key)}
|
|
37
33
|
end
|
|
38
|
-
name
|
|
39
|
-
end
|
|
40
|
-
protected :new_ostruct_member
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ary = []
|
|
45
|
-
@table.each do |k,v|
|
|
46
|
-
ary << "#{k}=#{v}"
|
|
35
|
+
def to_h
|
|
36
|
+
@table.dup
|
|
47
37
|
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
|
|
39
|
+
def each_pair
|
|
40
|
+
return to_enum __method__ unless block_given?
|
|
41
|
+
@table.each{|p| yield p}
|
|
51
42
|
end
|
|
52
|
-
str << '>'
|
|
53
|
-
end
|
|
54
|
-
alias :to_s :inspect
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
def new_ostruct_member name
|
|
45
|
+
name = name.to_sym
|
|
46
|
+
unless respond_to?(name)
|
|
47
|
+
define_singleton_method(name){ @table[name] }
|
|
48
|
+
define_singleton_method("#{name}=".to_sym){ |x| @table[name] = x }
|
|
49
|
+
end
|
|
50
|
+
name
|
|
51
|
+
end
|
|
52
|
+
protected :new_ostruct_member
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
def inspect
|
|
55
|
+
str = "#<#{self.class}"
|
|
56
|
+
ary = []
|
|
57
|
+
@table.each do |k,v|
|
|
58
|
+
ary << "#{k}=#{v}"
|
|
59
|
+
end
|
|
60
|
+
if 0 < ary.length
|
|
61
|
+
str << ' '
|
|
62
|
+
str << ary.join(', ')
|
|
63
|
+
end
|
|
64
|
+
str << '>'
|
|
65
|
+
end
|
|
66
|
+
alias :to_s :inspect
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
def delete_field name
|
|
69
|
+
sym = name.to_sym
|
|
70
|
+
singleton_class.__send__ :remove_method, sym, "#{sym}=".to_sym
|
|
71
|
+
@table.delete sym
|
|
72
|
+
end
|
|
70
73
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
def == other
|
|
75
|
+
return false unless other.kind_of?(OpenStruct)
|
|
76
|
+
@table == other.to_h
|
|
77
|
+
end
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
+
def [] key
|
|
80
|
+
@table[key.to_sym]
|
|
81
|
+
end
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
def []= key, value
|
|
84
|
+
@table[new_ostruct_member(key)] = value
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def eql? other
|
|
88
|
+
return false unless other.kind_of?(OpenStruct)
|
|
89
|
+
@table.eql?(other.to_h)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def hash
|
|
93
|
+
@table.hash
|
|
94
|
+
end
|
|
83
95
|
|
|
84
|
-
attr_reader :table
|
|
85
|
-
protected :table
|
|
86
96
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
def method_missing mid, *args
|
|
98
|
+
mname = mid.to_s
|
|
99
|
+
len = args.length
|
|
100
|
+
if mname.chomp! '='
|
|
101
|
+
if len != 1
|
|
102
|
+
raise ArgumentError, "wrong number of arguments (#{len} for 1)"
|
|
103
|
+
end
|
|
104
|
+
@table[new_ostruct_member(mname)] = args[0]
|
|
105
|
+
elsif len == 0
|
|
106
|
+
@table[mid]
|
|
107
|
+
else
|
|
108
|
+
raise NoMethodError, "undefined method `#{mid}' for #{self}"
|
|
93
109
|
end
|
|
94
|
-
@table[new_ostruct_member(mname)] = args[0]
|
|
95
|
-
elsif len == 0
|
|
96
|
-
@table[mid]
|
|
97
|
-
else
|
|
98
|
-
raise NoMethodError, "undefined method `#{mid}' for #{self}"
|
|
99
110
|
end
|
|
100
111
|
end
|
|
112
|
+
# rubocop:enable all
|
|
101
113
|
end
|
|
102
|
-
# rubocop:enable all
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require('yaml')
|
|
4
|
+
require('fileutils')
|
|
5
|
+
require('json')
|
|
6
|
+
require(
|
|
7
|
+
"interfacets/component_schema_parser"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
module Interfacets
|
|
11
|
+
class ComponentRegistry
|
|
12
|
+
attr_reader(:config_path)
|
|
13
|
+
def initialize(config_path:)
|
|
14
|
+
@config_path = config_path
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def write_client_registry(path:)
|
|
18
|
+
components = load_components
|
|
19
|
+
content = generate_registry_content(components)
|
|
20
|
+
write_atomic(path, content)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def load_components
|
|
26
|
+
raise(
|
|
27
|
+
Errno::ENOENT.new(
|
|
28
|
+
"Configuration file not found at #{config_path}"
|
|
29
|
+
)
|
|
30
|
+
) unless File.exist?(config_path)
|
|
31
|
+
|
|
32
|
+
components = YAML.load_file(config_path, aliases: true) || {}
|
|
33
|
+
|
|
34
|
+
parser = Interfacets::ComponentSchemaParser.new
|
|
35
|
+
parsed_components = {}
|
|
36
|
+
components.each do |name, config|
|
|
37
|
+
next unless config.is_a?(Hash)
|
|
38
|
+
component_data = { name => config }
|
|
39
|
+
parsed_components.merge!(parser.parse(component_data))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
parsed_components
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def generate_registry_content(components)
|
|
46
|
+
registry_components = components.select { |_, config|
|
|
47
|
+
config.key?("js") || transforms?(config)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
imports = []
|
|
51
|
+
mappings = []
|
|
52
|
+
any_transforms = false
|
|
53
|
+
|
|
54
|
+
registry_components.each do |name, config|
|
|
55
|
+
js_config = config["js"]
|
|
56
|
+
path = js_config&.dig("path")
|
|
57
|
+
|
|
58
|
+
transforms = extract_transforms(config)
|
|
59
|
+
|
|
60
|
+
imports << if path
|
|
61
|
+
if js_config["default"]
|
|
62
|
+
"import #{name} from \"#{path}\";"
|
|
63
|
+
elsif (export = js_config["export"])
|
|
64
|
+
"import { #{export} as #{name} } from \"#{path}\";"
|
|
65
|
+
else
|
|
66
|
+
"import { #{name} } from \"#{path}\";"
|
|
67
|
+
end
|
|
68
|
+
else
|
|
69
|
+
# Native element
|
|
70
|
+
"const #{name} = \"#{name}\";"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if transforms.any?
|
|
74
|
+
any_transforms = true
|
|
75
|
+
mappings << " #{name}: withTransform(#{name}, #{transforms.to_json}),"
|
|
76
|
+
else
|
|
77
|
+
mappings << " #{name},"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
if any_transforms
|
|
82
|
+
imports.unshift(
|
|
83
|
+
'import { withTransform } from "interfacets/withTransform";'
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
template = []
|
|
88
|
+
template << imports.join("\n") if imports.any?
|
|
89
|
+
template << <<~JS.strip
|
|
90
|
+
export const registry = {
|
|
91
|
+
#{mappings.join("\n")}
|
|
92
|
+
};
|
|
93
|
+
JS
|
|
94
|
+
|
|
95
|
+
"#{template.join("\n\n")}\n"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def transforms?(config)
|
|
99
|
+
extract_transforms(config).any?
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def extract_transforms(config)
|
|
103
|
+
transforms = {}
|
|
104
|
+
if (props = config["props"])
|
|
105
|
+
props.each do |prop_name, prop_config|
|
|
106
|
+
if prop_config["is_event"] && prop_config.key?("transform")
|
|
107
|
+
transforms[prop_name] = prop_config["transform"]
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
transforms
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def write_atomic(path, content)
|
|
115
|
+
temp_file = "#{path}.tmp"
|
|
116
|
+
File.write(temp_file, content)
|
|
117
|
+
FileUtils.mv(temp_file, path)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require("json_schemer")
|
|
4
|
+
|
|
5
|
+
module Interfacets
|
|
6
|
+
class ComponentSchemaParser
|
|
7
|
+
SCHEMA = {
|
|
8
|
+
"$schema" => "http://json-schema.org/draft-07/schema#",
|
|
9
|
+
"type" => "object",
|
|
10
|
+
"patternProperties" => {
|
|
11
|
+
"^.*$" => {
|
|
12
|
+
"type" => "object",
|
|
13
|
+
"properties" => {
|
|
14
|
+
"schema" => {
|
|
15
|
+
"if" => { "type" => "object" },
|
|
16
|
+
"then" => {
|
|
17
|
+
"not" => { "required" => ["props"] }
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"props" => {
|
|
21
|
+
"type" => "object",
|
|
22
|
+
"patternProperties" => {
|
|
23
|
+
"^.*$" => {
|
|
24
|
+
"type" => "object",
|
|
25
|
+
"properties" => {
|
|
26
|
+
"is_event" => { "type" => "boolean" }
|
|
27
|
+
},
|
|
28
|
+
"if" => {
|
|
29
|
+
"required" => ["is_event"],
|
|
30
|
+
"properties" => { "is_event" => { "const" => true } }
|
|
31
|
+
},
|
|
32
|
+
"then" => {
|
|
33
|
+
"properties" => {
|
|
34
|
+
"transform" => { "$ref" => "#/definitions/Transform" },
|
|
35
|
+
"payload" => { "type" => "object" }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"definitions" => {
|
|
45
|
+
"Transform" => {
|
|
46
|
+
"oneOf" => [
|
|
47
|
+
{ "type" => "null" },
|
|
48
|
+
{ "type" => "string" },
|
|
49
|
+
{
|
|
50
|
+
"type" => "object",
|
|
51
|
+
"additionalProperties" => {
|
|
52
|
+
"type" => "array",
|
|
53
|
+
"items" => [
|
|
54
|
+
{ "type" => "integer" }
|
|
55
|
+
],
|
|
56
|
+
"additionalItems" => { "type" => "string" },
|
|
57
|
+
"minItems" => 1
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
SCHEMER = JSONSchemer.schema(SCHEMA)
|
|
66
|
+
|
|
67
|
+
def parse(component_config)
|
|
68
|
+
errors = SCHEMER.validate(component_config).to_a
|
|
69
|
+
if errors.any?
|
|
70
|
+
if errors.any? { |e| e["data_pointer"].include?("/schema") && e["type"] == "not" }
|
|
71
|
+
raise(
|
|
72
|
+
StandardError.new(
|
|
73
|
+
"Old schema format is not supported."
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
message = "Validation failed:\n"
|
|
79
|
+
errors.each do |error|
|
|
80
|
+
message += " - #{error["data_pointer"]}: #{error["type"]} #{error["details"]}\n"
|
|
81
|
+
end
|
|
82
|
+
raise(StandardError.new(message))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
component_config
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
MRuby::Build.new do |conf|
|
|
4
|
-
toolchain
|
|
4
|
+
toolchain(:gcc)
|
|
5
5
|
conf.gembox("full-core")
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
MRuby::CrossBuild.new("emscripten") do |conf|
|
|
9
|
-
toolchain
|
|
9
|
+
toolchain(:clang)
|
|
10
10
|
conf.gembox("full-core")
|
|
11
11
|
conf.cc.command = "emcc"
|
|
12
12
|
conf.cc.flags = ["-Os", "-fPIC"]
|
|
@@ -15,6 +15,10 @@ MRuby::CrossBuild.new("emscripten") do |conf|
|
|
|
15
15
|
|
|
16
16
|
conf.gem(github: "mattn/mruby-json")
|
|
17
17
|
conf.gem(github: "mattn/mruby-base64")
|
|
18
|
-
conf.gem(
|
|
19
|
-
|
|
18
|
+
conf.gem(
|
|
19
|
+
github: "monochromegane/mruby-secure-random"
|
|
20
|
+
)
|
|
21
|
+
conf.gem(
|
|
22
|
+
github: "iij/mruby-regexp-pcre"
|
|
23
|
+
)
|
|
20
24
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Kernel
|
|
4
4
|
def wrapped_eval(str, path)
|
|
5
|
-
eval(str, binding, path)
|
|
5
|
+
eval(str, binding, path) # rubocop:disable Security/Eval
|
|
6
6
|
rescue StandardError, SyntaxError => e
|
|
7
7
|
$stderr.puts(e.class)
|
|
8
8
|
$stderr.puts(e.message)
|
|
@@ -11,7 +11,7 @@ module Kernel
|
|
|
11
11
|
|
|
12
12
|
def wrapped_call(json_string)
|
|
13
13
|
spec = JSON.parse(json_string)
|
|
14
|
-
eval(spec.fetch("receiver")).send(
|
|
14
|
+
eval(spec.fetch("receiver")).send( # rubocop:disable Security/Eval
|
|
15
15
|
spec.fetch("method"),
|
|
16
16
|
*spec.fetch("args", []),
|
|
17
17
|
)
|
|
@@ -3,21 +3,7 @@
|
|
|
3
3
|
module Interfacets
|
|
4
4
|
module Server
|
|
5
5
|
class Api
|
|
6
|
-
|
|
7
|
-
attr_reader :klass, :store
|
|
8
|
-
|
|
9
|
-
def rendered?
|
|
10
|
-
@rendered
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def render(klass, store)
|
|
14
|
-
@rendered = true
|
|
15
|
-
@klass = klass
|
|
16
|
-
@store = store
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
attr_reader :entity, :name, :registry
|
|
6
|
+
attr_reader(:entity, :name, :registry)
|
|
21
7
|
def initialize(entity:, name:, registry:)
|
|
22
8
|
@entity = entity
|
|
23
9
|
@name = name
|
|
@@ -25,36 +11,67 @@ module Interfacets
|
|
|
25
11
|
end
|
|
26
12
|
|
|
27
13
|
def handle(event)
|
|
28
|
-
channel = Channel.new
|
|
29
|
-
|
|
30
|
-
entity.channel = channel
|
|
31
14
|
Shared::Entities::Bus
|
|
32
15
|
.new(entity:)
|
|
33
16
|
.handle(event:)
|
|
34
17
|
|
|
35
18
|
if entity.channel.rendered?
|
|
36
|
-
|
|
37
|
-
channel.klass,
|
|
38
|
-
channel.store,
|
|
39
|
-
).render
|
|
19
|
+
entity.channel.render_facet(in_reply_to: event.fetch("id"))
|
|
40
20
|
else
|
|
41
|
-
emit(
|
|
21
|
+
emit(
|
|
22
|
+
event.fetch("action"),
|
|
23
|
+
nesting: event.fetch("nesting"),
|
|
24
|
+
|
|
25
|
+
in_reply_to: event.fetch("id"),
|
|
26
|
+
root_id: event["root_id"]
|
|
27
|
+
)
|
|
42
28
|
end
|
|
43
29
|
end
|
|
44
30
|
|
|
45
|
-
def render
|
|
46
|
-
emit(
|
|
31
|
+
def render(in_reply_to: SecureRandom.uuid)
|
|
32
|
+
emit(
|
|
33
|
+
"hydrate",
|
|
34
|
+
nesting: ["root"],
|
|
35
|
+
in_reply_to:
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def patch(nesting: ["root"], attributes: nil)
|
|
40
|
+
norm_nesting = Shared::Entities::Bus.validate_nesting!(nesting)
|
|
41
|
+
if attributes
|
|
42
|
+
{
|
|
43
|
+
facet: name,
|
|
44
|
+
payload: {
|
|
45
|
+
id: SecureRandom.uuid,
|
|
46
|
+
from: :server,
|
|
47
|
+
to: "client",
|
|
48
|
+
nesting: norm_nesting,
|
|
49
|
+
action: "patch",
|
|
50
|
+
payload: {
|
|
51
|
+
attributes:
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
emit("patch", nesting: norm_nesting)
|
|
57
|
+
end
|
|
47
58
|
end
|
|
48
59
|
|
|
49
60
|
private
|
|
50
61
|
|
|
51
|
-
def emit(action)
|
|
62
|
+
def emit(action, nesting:, in_reply_to: nil, root_id: nil)
|
|
52
63
|
{
|
|
53
64
|
facet: name,
|
|
54
65
|
payload: (
|
|
55
66
|
Shared::Entities::Bus
|
|
56
67
|
.new(entity:)
|
|
57
|
-
.serialize(
|
|
68
|
+
.serialize(
|
|
69
|
+
to: "client",
|
|
70
|
+
action:,
|
|
71
|
+
nesting:,
|
|
72
|
+
in_reply_to:,
|
|
73
|
+
root_id:
|
|
74
|
+
)
|
|
58
75
|
)
|
|
59
76
|
}
|
|
60
77
|
end
|