interfacets 0.9.99 → 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 -64
- data/lib/interfacets/client/bus.rb +28 -9
- data/lib/interfacets/client/channels/api.rb +138 -39
- 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 +3 -2
- 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 +7 -3
- data/lib/interfacets/client/utils/open_struct.rb +2 -4
- data/lib/interfacets/component_registry.rb +34 -29
- data/lib/interfacets/component_schema_parser.rb +8 -4
- data/lib/interfacets/mruby/build_config.rb +8 -4
- data/lib/interfacets/mruby/entrypoint.rb +2 -2
- data/lib/interfacets/server/api.rb +44 -7
- data/lib/interfacets/server/assets.rb +58 -23
- data/lib/interfacets/server/basic_router.rb +29 -19
- data/lib/interfacets/server/bus.rb +5 -6
- data/lib/interfacets/server/registry.rb +17 -10
- data/lib/interfacets/shared/basic_routable.rb +7 -4
- data/lib/interfacets/shared/entities/bus.rb +619 -185
- 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 +58 -37
- data/lib/interfacets/shared/entities/specs.rb +184 -18
- data/lib/interfacets/shared/entity.rb +113 -23
- data/lib/interfacets/shared/entity_dsl.rb +138 -20
- data/lib/interfacets/shared/facet.rb +128 -68
- data/lib/interfacets/shared/generated_store.rb +69 -34
- data/lib/interfacets/shared/refreshable.rb +85 -0
- data/lib/interfacets/shared/utils.rb +36 -32
- data/lib/interfacets/shared/validations.rb +746 -26
- data/lib/interfacets/shared/view.rb +74 -28
- data/lib/interfacets/test/component_registry.rb +31 -12
- data/lib/interfacets/test/js/inline_bus.rb +51 -25
- data/lib/interfacets/test/js/nodo_bus.rb +21 -10
- data/lib/interfacets/test/js/receivers/api.rb +14 -12
- 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 +33 -5
- data/lib/interfacets/test/js/receivers/react/node.rb +69 -15
- data/lib/interfacets/test/js/receivers/react.rb +13 -4
- data/lib/interfacets/test/js/receivers/timer.rb +12 -8
- data/lib/interfacets/test/js/receivers/url.rb +47 -11
- data/lib/interfacets/test/ui_simulator.rb +88 -18
- data/lib/interfacets/test/validation_engine.rb +82 -49
- data/lib/interfacets/test.rb +1 -3
- data/lib/interfacets/version.rb +1 -1
- data/lib/interfacets.rb +11 -3
- metadata +31 -28
- data/.rubocop.yml +0 -180
- data/.tmp +0 -5
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -14
- 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/server/assets/facet.rb +0 -63
- data/lib/interfacets/server/config.rb +0 -87
- 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
|
@@ -4,44 +4,90 @@ module Interfacets
|
|
|
4
4
|
module Shared
|
|
5
5
|
class View
|
|
6
6
|
class Evaluator
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
# rubocop:disable Style/ArgumentsForwarding
|
|
8
|
+
def self.call(**opts)
|
|
9
|
+
new(**opts).call
|
|
9
10
|
end
|
|
11
|
+
# rubocop:enable Style/ArgumentsForwarding
|
|
10
12
|
|
|
11
|
-
attr_reader
|
|
12
|
-
|
|
13
|
+
attr_reader(
|
|
14
|
+
:entity,
|
|
15
|
+
:channels,
|
|
16
|
+
:block,
|
|
17
|
+
:props,
|
|
18
|
+
:template_block,
|
|
19
|
+
:data
|
|
20
|
+
)
|
|
21
|
+
def initialize(entity:, channels:, block:, props: {}, template_block: nil)
|
|
13
22
|
@entity = entity
|
|
14
23
|
@channels = channels
|
|
15
24
|
@block = block
|
|
25
|
+
@props = props
|
|
26
|
+
@template_block = template_block
|
|
16
27
|
@data = Hash.new { |h, k| h[k] = { streams: {} } }
|
|
17
28
|
end
|
|
18
29
|
|
|
19
30
|
def call
|
|
20
|
-
|
|
31
|
+
entity.validate if entity.respond_to?(:validate)
|
|
32
|
+
instance_exec(entity, &block)
|
|
21
33
|
end
|
|
22
34
|
|
|
23
|
-
def render(
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
def render(target, **props, &block)
|
|
36
|
+
if target.is_a?(Class) && target.respond_to?(:render) && target < Interfacets::Client::Template
|
|
37
|
+
target.render(
|
|
38
|
+
self,
|
|
39
|
+
@current_builder,
|
|
40
|
+
**props,
|
|
41
|
+
&block
|
|
30
42
|
)
|
|
43
|
+
else
|
|
44
|
+
target
|
|
45
|
+
.class
|
|
46
|
+
.view
|
|
47
|
+
.render(
|
|
48
|
+
entity: target,
|
|
49
|
+
channels: channels,
|
|
50
|
+
props: props,
|
|
51
|
+
block: block
|
|
52
|
+
)
|
|
53
|
+
end
|
|
31
54
|
end
|
|
32
55
|
|
|
33
|
-
|
|
56
|
+
# rubocop:disable Style/ArgumentsForwarding
|
|
57
|
+
def render_to(channel_id, stream: "default", slots: [], **_opts, &block)
|
|
34
58
|
channel_id = channel_id.to_s
|
|
35
59
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
60
|
+
builder = (
|
|
61
|
+
channels
|
|
62
|
+
.fetch(channel_id)
|
|
63
|
+
.builder(stream.to_s)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
@current_builder = builder
|
|
67
|
+
|
|
68
|
+
if props.any? || template_block
|
|
69
|
+
slots_obj = Interfacets::Client::Template.create(
|
|
70
|
+
self,
|
|
71
|
+
builder,
|
|
72
|
+
slots: slots,
|
|
73
|
+
&template_block
|
|
74
|
+
)
|
|
75
|
+
instance_exec(
|
|
76
|
+
builder,
|
|
77
|
+
args: props, slots: slots_obj,
|
|
78
|
+
&block
|
|
79
|
+
)
|
|
80
|
+
else
|
|
81
|
+
instance_exec(builder, &block)
|
|
82
|
+
end
|
|
41
83
|
end
|
|
84
|
+
# rubocop:enable Style/ArgumentsForwarding
|
|
42
85
|
|
|
43
|
-
def channel(name)
|
|
44
|
-
|
|
86
|
+
def channel(name, stream: "default", &block)
|
|
87
|
+
ch = channels.fetch(name.to_s)
|
|
88
|
+
target = ch.respond_to?(:builder) ? ch.builder(stream.to_s) : ch
|
|
89
|
+
instance_exec(target, &block) if block
|
|
90
|
+
target
|
|
45
91
|
end
|
|
46
92
|
end
|
|
47
93
|
|
|
@@ -51,22 +97,22 @@ module Interfacets
|
|
|
51
97
|
@view
|
|
52
98
|
end
|
|
53
99
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def render(**p)
|
|
59
|
-
new.render(**p)
|
|
100
|
+
# rubocop:disable Style/ArgumentsForwarding
|
|
101
|
+
def render(**opts)
|
|
102
|
+
new.render(**opts)
|
|
60
103
|
end
|
|
104
|
+
# rubocop:enable Style/ArgumentsForwarding
|
|
61
105
|
end
|
|
62
106
|
|
|
63
|
-
def render(entity:, channels:)
|
|
107
|
+
def render(entity:, channels:, props: {}, block: nil)
|
|
64
108
|
return unless self.class.view
|
|
65
109
|
|
|
66
110
|
Evaluator.call(
|
|
67
111
|
entity: entity,
|
|
68
112
|
channels: channels,
|
|
69
|
-
block: self.class.view
|
|
113
|
+
block: self.class.view,
|
|
114
|
+
props: props,
|
|
115
|
+
template_block: block
|
|
70
116
|
)
|
|
71
117
|
end
|
|
72
118
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require("yaml")
|
|
4
4
|
|
|
5
5
|
module Interfacets
|
|
6
6
|
module Test
|
|
@@ -11,8 +11,11 @@ module Interfacets
|
|
|
11
11
|
new(path)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
attr_reader
|
|
15
|
-
|
|
14
|
+
attr_reader(
|
|
15
|
+
:contracts,
|
|
16
|
+
:path,
|
|
17
|
+
:schema_cache
|
|
18
|
+
)
|
|
16
19
|
def initialize(path)
|
|
17
20
|
@path = path
|
|
18
21
|
@schema_cache = {}
|
|
@@ -20,19 +23,19 @@ module Interfacets
|
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
def find_component(name)
|
|
23
|
-
|
|
26
|
+
contracts[name.to_s]
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
def definitions
|
|
27
|
-
|
|
30
|
+
contracts["definitions"] || {}
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
private
|
|
31
34
|
|
|
32
35
|
def load_contracts
|
|
33
|
-
return {} unless File.exist?(
|
|
36
|
+
return {} unless File.exist?(path)
|
|
34
37
|
|
|
35
|
-
contracts = YAML.load_file(
|
|
38
|
+
contracts = YAML.load_file(path, aliases: true) || {}
|
|
36
39
|
contracts.each do |name, config|
|
|
37
40
|
next unless config.is_a?(Hash)
|
|
38
41
|
|
|
@@ -43,19 +46,35 @@ module Interfacets
|
|
|
43
46
|
end
|
|
44
47
|
contracts
|
|
45
48
|
rescue Psych::SyntaxError => e
|
|
46
|
-
raise
|
|
49
|
+
raise(
|
|
50
|
+
Error.new(
|
|
51
|
+
"Failed to parse component registry at #{path}: #{e.message}"
|
|
52
|
+
)
|
|
53
|
+
)
|
|
47
54
|
end
|
|
48
55
|
|
|
49
56
|
def load_schema_file(component_name, schema_path)
|
|
50
|
-
full_path = File.expand_path(
|
|
51
|
-
|
|
57
|
+
full_path = File.expand_path(
|
|
58
|
+
schema_path,
|
|
59
|
+
File.dirname(path)
|
|
60
|
+
)
|
|
61
|
+
return schema_cache[full_path] if schema_cache.key?(full_path)
|
|
52
62
|
|
|
53
|
-
raise
|
|
63
|
+
raise(
|
|
64
|
+
Errno::ENOENT.new(
|
|
65
|
+
"Schema file not found for component '#{component_name}' at #{full_path}"
|
|
66
|
+
)
|
|
67
|
+
) unless File.exist?(full_path)
|
|
54
68
|
|
|
55
69
|
begin
|
|
56
70
|
@schema_cache[full_path] = YAML.load_file(full_path, aliases: true) || {}
|
|
57
71
|
rescue Psych::SyntaxError => e
|
|
58
|
-
raise
|
|
72
|
+
raise(
|
|
73
|
+
Error.new(
|
|
74
|
+
"Failed to parse schema file for component '#{component_name}' " \
|
|
75
|
+
"at #{full_path}: #{e.message}"
|
|
76
|
+
)
|
|
77
|
+
)
|
|
59
78
|
end
|
|
60
79
|
end
|
|
61
80
|
end
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require("nodo")
|
|
2
4
|
|
|
3
5
|
module Interfacets
|
|
4
6
|
module Test
|
|
5
7
|
module Js
|
|
6
8
|
class InlineBus
|
|
7
|
-
attr_reader
|
|
9
|
+
attr_reader(
|
|
10
|
+
:receiver_index,
|
|
11
|
+
:client_system_json
|
|
12
|
+
)
|
|
8
13
|
def initialize(receiver_index:, client_system_json:)
|
|
9
14
|
@receiver_index = receiver_index
|
|
10
15
|
@client_system_json = client_system_json
|
|
@@ -15,23 +20,32 @@ module Interfacets
|
|
|
15
20
|
end
|
|
16
21
|
|
|
17
22
|
def init(hydrated_facet:)
|
|
18
|
-
client.handle(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
client.handle(
|
|
24
|
+
H.j(
|
|
25
|
+
{
|
|
26
|
+
type: "interfacets:system:create_bus",
|
|
27
|
+
payload: {
|
|
28
|
+
id: "default",
|
|
29
|
+
channel_ids: ["interfacets:api", "dom", "url", "timer", "pubsub",
|
|
30
|
+
"audio"],
|
|
31
|
+
hydration: {
|
|
32
|
+
destination: { bus: "default", channel: "interfacets:api" },
|
|
33
|
+
type: "interfacets:api:hydrate",
|
|
34
|
+
payload: hydrated_facet
|
|
35
|
+
},
|
|
36
|
+
config: client_system_json,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
)
|
|
31
41
|
end
|
|
32
42
|
|
|
33
43
|
def dispatch(channel_id, event)
|
|
34
|
-
dispatch_to_bus(
|
|
44
|
+
dispatch_to_bus(
|
|
45
|
+
bus_id: "default",
|
|
46
|
+
channel_id: channel_id,
|
|
47
|
+
event: event
|
|
48
|
+
)
|
|
35
49
|
end
|
|
36
50
|
|
|
37
51
|
private
|
|
@@ -50,12 +64,18 @@ module Interfacets
|
|
|
50
64
|
.receive(
|
|
51
65
|
payload: channel_event.fetch("payload"),
|
|
52
66
|
dispatch: ->(ev) {
|
|
53
|
-
dispatch_to_bus(
|
|
67
|
+
dispatch_to_bus(
|
|
68
|
+
bus_id:,
|
|
69
|
+
channel_id:,
|
|
70
|
+
event: ev
|
|
71
|
+
)
|
|
54
72
|
},
|
|
55
73
|
)
|
|
56
74
|
end
|
|
57
75
|
else
|
|
58
|
-
raise(
|
|
76
|
+
raise(
|
|
77
|
+
"unhandled event type: #{event}"
|
|
78
|
+
)
|
|
59
79
|
end
|
|
60
80
|
|
|
61
81
|
# Flush any responses that may have come from the server
|
|
@@ -64,7 +84,11 @@ module Interfacets
|
|
|
64
84
|
receiver_index.each do |channel_id, receiver|
|
|
65
85
|
if receiver.respond_to?(:response_queue)
|
|
66
86
|
receiver.flush_responses.each do |response|
|
|
67
|
-
dispatch_to_bus(
|
|
87
|
+
dispatch_to_bus(
|
|
88
|
+
bus_id:,
|
|
89
|
+
channel_id:,
|
|
90
|
+
event: response
|
|
91
|
+
)
|
|
68
92
|
end
|
|
69
93
|
end
|
|
70
94
|
end
|
|
@@ -85,13 +109,15 @@ module Interfacets
|
|
|
85
109
|
def client
|
|
86
110
|
@client ||= (
|
|
87
111
|
$asset_logger = Logger.new("/dev/null")
|
|
88
|
-
Client::System
|
|
112
|
+
Client::System
|
|
113
|
+
.logger = $asset_logger
|
|
89
114
|
|
|
90
|
-
Client
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
Client
|
|
116
|
+
.start(
|
|
117
|
+
transmit: ->(event) {
|
|
118
|
+
handle(H.j(event))
|
|
119
|
+
},
|
|
120
|
+
)
|
|
95
121
|
)
|
|
96
122
|
end
|
|
97
123
|
end
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require("nodo")
|
|
2
4
|
|
|
3
5
|
module Interfacets
|
|
4
6
|
module Test
|
|
5
7
|
module Js
|
|
6
8
|
class NodoBus < Nodo::Core
|
|
7
|
-
attr_reader
|
|
9
|
+
attr_reader(
|
|
10
|
+
:receiver_index,
|
|
11
|
+
:client_system_json
|
|
12
|
+
)
|
|
8
13
|
def initialize(receiver_index:, client_system_json:)
|
|
9
14
|
super()
|
|
10
15
|
@receiver_index = receiver_index
|
|
@@ -12,6 +17,7 @@ module Interfacets
|
|
|
12
17
|
end
|
|
13
18
|
|
|
14
19
|
def dispatch(channel_id, event)
|
|
20
|
+
receiver_index.fetch(channel_id) # unknown channels raise KeyError, as on the inline bus
|
|
15
21
|
js_dispatch(channel_id, event)
|
|
16
22
|
render
|
|
17
23
|
end
|
|
@@ -49,15 +55,20 @@ module Interfacets
|
|
|
49
55
|
|
|
50
56
|
if js_get_logs.any? { _1.fetch("type") == "error" }
|
|
51
57
|
js_get_logs
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
.map { _1.fetch("value") }
|
|
59
|
+
.then { raise(_1.join("\n")) }
|
|
54
60
|
end
|
|
55
61
|
end
|
|
56
62
|
|
|
57
|
-
import
|
|
58
|
-
|
|
63
|
+
import(
|
|
64
|
+
app: File.join(
|
|
65
|
+
__dir__,
|
|
66
|
+
"../../../../test/wasm/app.mjs"
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
import(:fs)
|
|
59
70
|
|
|
60
|
-
function
|
|
71
|
+
function(:js_init, <<~JS)
|
|
61
72
|
async (config) => {
|
|
62
73
|
global.logs = []
|
|
63
74
|
global.console = {
|
|
@@ -79,17 +90,17 @@ module Interfacets
|
|
|
79
90
|
}
|
|
80
91
|
JS
|
|
81
92
|
|
|
82
|
-
function
|
|
93
|
+
function(:js_dispatch, <<~JS)
|
|
83
94
|
(channelName, event) => {
|
|
84
95
|
app.dispatch(channelName, event)
|
|
85
96
|
}
|
|
86
97
|
JS
|
|
87
98
|
|
|
88
|
-
function
|
|
99
|
+
function(:js_get_logs, <<~JS)
|
|
89
100
|
() => global.logs
|
|
90
101
|
JS
|
|
91
102
|
|
|
92
|
-
function
|
|
103
|
+
function(:js_get_state, <<~JS)
|
|
93
104
|
(channelName) => app.getState(channelName)
|
|
94
105
|
JS
|
|
95
106
|
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# require_relative "./channels/react"
|
|
4
|
-
|
|
5
3
|
module Interfacets
|
|
6
4
|
module Test
|
|
7
5
|
module Js
|
|
8
6
|
module Receivers
|
|
9
7
|
class Api
|
|
10
|
-
attr_reader
|
|
8
|
+
attr_reader(
|
|
9
|
+
:router,
|
|
10
|
+
:name,
|
|
11
|
+
:response_queue
|
|
12
|
+
)
|
|
11
13
|
def initialize(name:, router:)
|
|
12
14
|
@name = name
|
|
13
15
|
@router = router
|
|
@@ -25,17 +27,17 @@ module Interfacets
|
|
|
25
27
|
return if payload.dig("streams", "default").nil?
|
|
26
28
|
return if payload.dig("streams", "default").empty?
|
|
27
29
|
|
|
28
|
-
method = payload.dig("streams", "default", "method")
|
|
29
30
|
url = payload.dig("streams", "default", "url")
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
payload
|
|
33
|
+
.dig(
|
|
34
|
+
"streams",
|
|
35
|
+
"default",
|
|
36
|
+
"body",
|
|
37
|
+
"event",
|
|
38
|
+
"payload"
|
|
39
|
+
)
|
|
40
|
+
.then { response_queue << router.call(url).handle(_1) }
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def flush_responses
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Interfacets
|
|
4
|
+
module Test
|
|
5
|
+
module Js
|
|
6
|
+
module Receivers
|
|
7
|
+
# Simulates the browser audio channel: records the events a facet asks for (play, load,
|
|
8
|
+
# request-mic, start-record, stop-record) and lets a test answer them the way the browser
|
|
9
|
+
# would.
|
|
10
|
+
class Audio
|
|
11
|
+
include(Enumerable)
|
|
12
|
+
|
|
13
|
+
attr_reader(:name, :events)
|
|
14
|
+
def initialize(name:)
|
|
15
|
+
@name = name
|
|
16
|
+
@events = []
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def receive(payload:, dispatch:)
|
|
20
|
+
@dispatch = dispatch
|
|
21
|
+
|
|
22
|
+
event = payload&.dig("streams", "default")
|
|
23
|
+
return if event.nil? || event.empty?
|
|
24
|
+
|
|
25
|
+
events << event
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def handler
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def each(&)
|
|
33
|
+
events.each(&)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def first
|
|
37
|
+
events.first
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def last
|
|
41
|
+
events.last
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def clear
|
|
45
|
+
@events = []
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Answers a request like the browser does, e.g. `audio.respond_to(audio.last, "loaded")`:
|
|
49
|
+
# sends an event of `type` carrying the request's id (and any extra payload) back to the
|
|
50
|
+
# facet.
|
|
51
|
+
def respond_to(request, type, payload = {})
|
|
52
|
+
@dispatch.call(
|
|
53
|
+
{ "type" => type,
|
|
54
|
+
"payload" => { "id" => request.fetch("id") }.merge(payload) }
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Interfacets
|
|
4
|
+
module Test
|
|
5
|
+
module Js
|
|
6
|
+
module Receivers
|
|
7
|
+
class Pubsub
|
|
8
|
+
attr_reader(:name, :topics)
|
|
9
|
+
def initialize(name:)
|
|
10
|
+
@name = name
|
|
11
|
+
@topics = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
alias_method(:streams, :topics)
|
|
15
|
+
alias_method(:listening, :topics)
|
|
16
|
+
|
|
17
|
+
def receive(payload:, dispatch:)
|
|
18
|
+
@dispatch = dispatch
|
|
19
|
+
|
|
20
|
+
if payload.nil? || payload.empty? || payload.dig("streams", "default").nil?
|
|
21
|
+
@topics = []
|
|
22
|
+
return
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
listen = payload.dig("streams", "default", "listen")
|
|
26
|
+
@topics = Array(listen).map(&:to_s)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def handler
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def listening?(topic)
|
|
34
|
+
topics.include?(topic.to_s)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def notify(topic, data = {}) # rubocop:disable Naming/PredicateMethod
|
|
38
|
+
return false unless listening?(topic)
|
|
39
|
+
return false unless @dispatch
|
|
40
|
+
|
|
41
|
+
@dispatch.call(
|
|
42
|
+
{ "topic" => topic.to_s, "data" => data }
|
|
43
|
+
)
|
|
44
|
+
true
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require("nokogiri")
|
|
4
4
|
|
|
5
5
|
module Interfacets
|
|
6
6
|
module Test
|
|
@@ -9,12 +9,24 @@ module Interfacets
|
|
|
9
9
|
class React
|
|
10
10
|
class Node
|
|
11
11
|
class XmlParser
|
|
12
|
-
attr_reader
|
|
12
|
+
attr_reader(:json, :validation_engine)
|
|
13
13
|
def initialize(json, validation_engine:)
|
|
14
14
|
@json = json
|
|
15
15
|
@validation_engine = validation_engine
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def self.element_node?(value)
|
|
19
|
+
value.is_a?(Hash) && ["interfacets:react-dom:element",
|
|
20
|
+
"interfacets:string-node"].include?(value["type"])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Builds the XML node for one raw element/string node (a captured prop value).
|
|
24
|
+
def self.parse_node(raw)
|
|
25
|
+
parser = new(nil, validation_engine: nil)
|
|
26
|
+
result = parser.send(:parse_element, raw)
|
|
27
|
+
result.is_a?(String) ? Nokogiri::XML::Document.new.create_text_node(result) : result
|
|
28
|
+
end
|
|
29
|
+
|
|
18
30
|
def call
|
|
19
31
|
xml = Nokogiri::XML.fragment("<Facet/>")
|
|
20
32
|
json
|
|
@@ -29,6 +41,9 @@ module Interfacets
|
|
|
29
41
|
def parse_attribute(value, top: true)
|
|
30
42
|
case value
|
|
31
43
|
when Array
|
|
44
|
+
value
|
|
45
|
+
.map { parse_attribute(_1, top: false) }
|
|
46
|
+
.then { top ? _1.to_json : _1 }
|
|
32
47
|
when Hash
|
|
33
48
|
value
|
|
34
49
|
.transform_values { parse_attribute(_1, top: false) }
|
|
@@ -37,7 +52,9 @@ module Interfacets
|
|
|
37
52
|
when Numeric, String, TrueClass, FalseClass, NilClass
|
|
38
53
|
value
|
|
39
54
|
else
|
|
40
|
-
raise
|
|
55
|
+
raise(
|
|
56
|
+
"unknown attribute type: #{value}"
|
|
57
|
+
)
|
|
41
58
|
end
|
|
42
59
|
end
|
|
43
60
|
|
|
@@ -50,22 +67,33 @@ module Interfacets
|
|
|
50
67
|
el
|
|
51
68
|
.fetch("element")
|
|
52
69
|
.tap { validation_engine&.validate_props(_1, el.fetch("attributes")) }
|
|
53
|
-
.then {
|
|
70
|
+
.then {
|
|
71
|
+
Nokogiri::XML
|
|
72
|
+
.fragment("<#{_1} />")
|
|
73
|
+
.children
|
|
74
|
+
.first
|
|
75
|
+
}
|
|
54
76
|
)
|
|
55
77
|
|
|
56
78
|
el.fetch("children").each do |child|
|
|
57
79
|
xml.add_child(parse_element(child)) if child
|
|
58
80
|
end
|
|
59
81
|
|
|
82
|
+
# Captured elements stay in their attribute as raw node JSON; Node#attribute
|
|
83
|
+
# turns them back into Nodes. The simulator cannot know where a component
|
|
84
|
+
# would render them.
|
|
60
85
|
el.fetch("attributes").each do |name, value|
|
|
61
86
|
xml.set_attribute(name, parse_attribute(value))
|
|
62
87
|
end
|
|
63
88
|
|
|
64
89
|
xml
|
|
65
90
|
else
|
|
66
|
-
raise
|
|
91
|
+
raise(
|
|
92
|
+
"unknown type: #{el.fetch("type")}"
|
|
93
|
+
)
|
|
67
94
|
end
|
|
68
95
|
end
|
|
96
|
+
|
|
69
97
|
end
|
|
70
98
|
end
|
|
71
99
|
end
|