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
|
@@ -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
|
|
@@ -73,7 +73,7 @@ unless required
|
|
|
73
73
|
|
|
74
74
|
def == other
|
|
75
75
|
return false unless other.kind_of?(OpenStruct)
|
|
76
|
-
@table == other.
|
|
76
|
+
@table == other.to_h
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def [] key
|
|
@@ -86,15 +86,13 @@ unless required
|
|
|
86
86
|
|
|
87
87
|
def eql? other
|
|
88
88
|
return false unless other.kind_of?(OpenStruct)
|
|
89
|
-
@table.eql?(other.
|
|
89
|
+
@table.eql?(other.to_h)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def hash
|
|
93
93
|
@table.hash
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
attr_reader :table
|
|
97
|
-
protected :table
|
|
98
96
|
|
|
99
97
|
def method_missing mid, *args
|
|
100
98
|
mname = mid.to_s
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require('yaml')
|
|
4
|
+
require('fileutils')
|
|
5
|
+
require('json')
|
|
6
|
+
require(
|
|
7
|
+
"interfacets/component_schema_parser"
|
|
8
|
+
)
|
|
7
9
|
|
|
8
10
|
module Interfacets
|
|
9
11
|
class ComponentRegistry
|
|
12
|
+
attr_reader(:config_path)
|
|
10
13
|
def initialize(config_path:)
|
|
11
14
|
@config_path = config_path
|
|
12
|
-
@schema_cache = {}
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def write_client_registry(path:)
|
|
@@ -21,26 +23,29 @@ module Interfacets
|
|
|
21
23
|
private
|
|
22
24
|
|
|
23
25
|
def load_components
|
|
24
|
-
raise
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
|
|
30
34
|
parser = Interfacets::ComponentSchemaParser.new
|
|
31
35
|
parsed_components = {}
|
|
32
36
|
components.each do |name, config|
|
|
33
37
|
next unless config.is_a?(Hash)
|
|
34
38
|
component_data = { name => config }
|
|
35
|
-
# The result of parse is the component data, which we merge.
|
|
36
39
|
parsed_components.merge!(parser.parse(component_data))
|
|
37
40
|
end
|
|
38
|
-
|
|
41
|
+
|
|
39
42
|
parsed_components
|
|
40
43
|
end
|
|
41
44
|
|
|
42
45
|
def generate_registry_content(components)
|
|
43
|
-
registry_components = components.select { |_, config|
|
|
46
|
+
registry_components = components.select { |_, config|
|
|
47
|
+
config.key?("js") || transforms?(config)
|
|
48
|
+
}
|
|
44
49
|
|
|
45
50
|
imports = []
|
|
46
51
|
mappings = []
|
|
@@ -52,18 +57,18 @@ module Interfacets
|
|
|
52
57
|
|
|
53
58
|
transforms = extract_transforms(config)
|
|
54
59
|
|
|
55
|
-
if path
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
63
68
|
else
|
|
64
69
|
# Native element
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
"const #{name} = \"#{name}\";"
|
|
71
|
+
end
|
|
67
72
|
|
|
68
73
|
if transforms.any?
|
|
69
74
|
any_transforms = true
|
|
@@ -74,7 +79,9 @@ module Interfacets
|
|
|
74
79
|
end
|
|
75
80
|
|
|
76
81
|
if any_transforms
|
|
77
|
-
imports.unshift(
|
|
82
|
+
imports.unshift(
|
|
83
|
+
'import { withTransform } from "interfacets/withTransform";'
|
|
84
|
+
)
|
|
78
85
|
end
|
|
79
86
|
|
|
80
87
|
template = []
|
|
@@ -88,13 +95,13 @@ module Interfacets
|
|
|
88
95
|
"#{template.join("\n\n")}\n"
|
|
89
96
|
end
|
|
90
97
|
|
|
91
|
-
def
|
|
98
|
+
def transforms?(config)
|
|
92
99
|
extract_transforms(config).any?
|
|
93
100
|
end
|
|
94
101
|
|
|
95
102
|
def extract_transforms(config)
|
|
96
103
|
transforms = {}
|
|
97
|
-
if props = config["props"]
|
|
104
|
+
if (props = config["props"])
|
|
98
105
|
props.each do |prop_name, prop_config|
|
|
99
106
|
if prop_config["is_event"] && prop_config.key?("transform")
|
|
100
107
|
transforms[prop_name] = prop_config["transform"]
|
|
@@ -104,8 +111,6 @@ module Interfacets
|
|
|
104
111
|
transforms
|
|
105
112
|
end
|
|
106
113
|
|
|
107
|
-
|
|
108
|
-
|
|
109
114
|
def write_atomic(path, content)
|
|
110
115
|
temp_file = "#{path}.tmp"
|
|
111
116
|
File.write(temp_file, content)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require("json_schemer")
|
|
4
4
|
|
|
5
5
|
module Interfacets
|
|
6
6
|
class ComponentSchemaParser
|
|
@@ -60,7 +60,7 @@ module Interfacets
|
|
|
60
60
|
]
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
|
64
64
|
|
|
65
65
|
SCHEMER = JSONSchemer.schema(SCHEMA)
|
|
66
66
|
|
|
@@ -68,14 +68,18 @@ module Interfacets
|
|
|
68
68
|
errors = SCHEMER.validate(component_config).to_a
|
|
69
69
|
if errors.any?
|
|
70
70
|
if errors.any? { |e| e["data_pointer"].include?("/schema") && e["type"] == "not" }
|
|
71
|
-
raise
|
|
71
|
+
raise(
|
|
72
|
+
StandardError.new(
|
|
73
|
+
"Old schema format is not supported."
|
|
74
|
+
)
|
|
75
|
+
)
|
|
72
76
|
end
|
|
73
77
|
|
|
74
78
|
message = "Validation failed:\n"
|
|
75
79
|
errors.each do |error|
|
|
76
80
|
message += " - #{error["data_pointer"]}: #{error["type"]} #{error["details"]}\n"
|
|
77
81
|
end
|
|
78
|
-
raise
|
|
82
|
+
raise(StandardError.new(message))
|
|
79
83
|
end
|
|
80
84
|
|
|
81
85
|
component_config
|
|
@@ -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,7 +3,7 @@
|
|
|
3
3
|
module Interfacets
|
|
4
4
|
module Server
|
|
5
5
|
class Api
|
|
6
|
-
attr_reader
|
|
6
|
+
attr_reader(:entity, :name, :registry)
|
|
7
7
|
def initialize(entity:, name:, registry:)
|
|
8
8
|
@entity = entity
|
|
9
9
|
@name = name
|
|
@@ -16,25 +16,62 @@ module Interfacets
|
|
|
16
16
|
.handle(event:)
|
|
17
17
|
|
|
18
18
|
if entity.channel.rendered?
|
|
19
|
-
entity.channel.render_facet
|
|
19
|
+
entity.channel.render_facet(in_reply_to: event.fetch("id"))
|
|
20
20
|
else
|
|
21
|
-
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
|
+
)
|
|
22
28
|
end
|
|
23
29
|
end
|
|
24
30
|
|
|
25
|
-
def render
|
|
26
|
-
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
|
|
27
58
|
end
|
|
28
59
|
|
|
29
60
|
private
|
|
30
61
|
|
|
31
|
-
def emit(action, nesting: )
|
|
62
|
+
def emit(action, nesting:, in_reply_to: nil, root_id: nil)
|
|
32
63
|
{
|
|
33
64
|
facet: name,
|
|
34
65
|
payload: (
|
|
35
66
|
Shared::Entities::Bus
|
|
36
67
|
.new(entity:)
|
|
37
|
-
.serialize(
|
|
68
|
+
.serialize(
|
|
69
|
+
to: "client",
|
|
70
|
+
action:,
|
|
71
|
+
nesting:,
|
|
72
|
+
in_reply_to:,
|
|
73
|
+
root_id:
|
|
74
|
+
)
|
|
38
75
|
)
|
|
39
76
|
}
|
|
40
77
|
end
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require("prism")
|
|
4
4
|
|
|
5
5
|
module Interfacets
|
|
6
6
|
module Server
|
|
7
7
|
module Assets
|
|
8
8
|
Const =
|
|
9
|
-
Data.define(
|
|
9
|
+
Data.define(
|
|
10
|
+
:nesting,
|
|
11
|
+
:type,
|
|
12
|
+
:name,
|
|
13
|
+
:parent
|
|
14
|
+
) do
|
|
10
15
|
def full_name
|
|
11
16
|
[nesting.last&.full_name, name].compact.join("::")
|
|
12
17
|
end
|
|
@@ -15,7 +20,7 @@ module Interfacets
|
|
|
15
20
|
class Classifier
|
|
16
21
|
class Visitor < Prism::Visitor
|
|
17
22
|
# This class just gathers up all modules and classes defined
|
|
18
|
-
attr_reader :
|
|
23
|
+
attr_reader(:mods, :stack)
|
|
19
24
|
def initialize
|
|
20
25
|
@stack = []
|
|
21
26
|
@mods = []
|
|
@@ -42,27 +47,32 @@ module Interfacets
|
|
|
42
47
|
)
|
|
43
48
|
|
|
44
49
|
const = Const.new(
|
|
45
|
-
nesting:
|
|
50
|
+
nesting: stack.dup,
|
|
46
51
|
name: node.constant_path.full_name,
|
|
47
52
|
type:,
|
|
48
53
|
parent:
|
|
49
54
|
)
|
|
50
|
-
|
|
51
|
-
mods <<
|
|
55
|
+
stack << const
|
|
56
|
+
mods << stack.dup
|
|
52
57
|
visit_child_nodes(node)
|
|
53
|
-
|
|
58
|
+
stack.pop
|
|
54
59
|
end
|
|
55
60
|
end
|
|
56
61
|
|
|
57
|
-
attr_reader
|
|
62
|
+
attr_reader(:code)
|
|
58
63
|
def initialize(code)
|
|
59
64
|
@code = code
|
|
60
65
|
end
|
|
61
66
|
|
|
62
67
|
def consts
|
|
63
68
|
@consts ||= (
|
|
64
|
-
Prism
|
|
65
|
-
|
|
69
|
+
Prism
|
|
70
|
+
.parse(code)
|
|
71
|
+
.value
|
|
72
|
+
.accept(visitor)
|
|
73
|
+
visitor
|
|
74
|
+
.mods
|
|
75
|
+
.map(&:last)
|
|
66
76
|
)
|
|
67
77
|
end
|
|
68
78
|
|
|
@@ -72,7 +82,7 @@ module Interfacets
|
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
class Serializer
|
|
75
|
-
attr_reader
|
|
85
|
+
attr_reader(:paths, :file)
|
|
76
86
|
def initialize(paths:, file: File)
|
|
77
87
|
@paths = paths
|
|
78
88
|
@file = file
|
|
@@ -97,7 +107,8 @@ module Interfacets
|
|
|
97
107
|
consts_by_path.fetch(path).each { |c| full_map[c.full_name] << path }
|
|
98
108
|
}
|
|
99
109
|
|
|
100
|
-
full_map
|
|
110
|
+
full_map
|
|
111
|
+
.transform_values(&:uniq!)
|
|
101
112
|
full_map
|
|
102
113
|
)
|
|
103
114
|
end
|
|
@@ -106,9 +117,9 @@ module Interfacets
|
|
|
106
117
|
serialized = {}
|
|
107
118
|
results = []
|
|
108
119
|
|
|
109
|
-
consts.each
|
|
120
|
+
consts.each do |const|
|
|
110
121
|
push_bootstrapper(const, results, serialized)
|
|
111
|
-
|
|
122
|
+
end
|
|
112
123
|
|
|
113
124
|
results
|
|
114
125
|
end
|
|
@@ -119,12 +130,22 @@ module Interfacets
|
|
|
119
130
|
serialized[const.full_name] = true
|
|
120
131
|
|
|
121
132
|
const.nesting.each do |nesting_const|
|
|
122
|
-
push_bootstrapper(
|
|
133
|
+
push_bootstrapper(
|
|
134
|
+
nesting_const,
|
|
135
|
+
results,
|
|
136
|
+
serialized
|
|
137
|
+
)
|
|
123
138
|
end
|
|
124
139
|
|
|
125
140
|
parent = (
|
|
126
141
|
if const.parent
|
|
127
|
-
resolve_const_name(
|
|
142
|
+
resolve_const_name(
|
|
143
|
+
const
|
|
144
|
+
.nesting
|
|
145
|
+
.last
|
|
146
|
+
&.full_name,
|
|
147
|
+
const.parent
|
|
148
|
+
)
|
|
128
149
|
end
|
|
129
150
|
)
|
|
130
151
|
|
|
@@ -145,13 +166,21 @@ module Interfacets
|
|
|
145
166
|
end
|
|
146
167
|
|
|
147
168
|
def resolve_const_name(nesting, name)
|
|
148
|
-
full_name =
|
|
169
|
+
full_name = (
|
|
170
|
+
[nesting, name]
|
|
171
|
+
.compact
|
|
172
|
+
.reject(&:empty?)
|
|
173
|
+
.join("::")
|
|
174
|
+
)
|
|
149
175
|
return consts_by_name[full_name] if consts_by_name.key?(full_name)
|
|
150
176
|
|
|
151
177
|
# maybe a constant that we don't handle loading for (eg, StandardError)
|
|
152
178
|
return name if nesting.nil? || nesting.empty?
|
|
153
179
|
|
|
154
|
-
resolve_const_name(
|
|
180
|
+
resolve_const_name(
|
|
181
|
+
nesting.split("::")[0...-1].join("::"),
|
|
182
|
+
name
|
|
183
|
+
)
|
|
155
184
|
end
|
|
156
185
|
|
|
157
186
|
def consts_by_name
|
|
@@ -169,16 +198,22 @@ module Interfacets
|
|
|
169
198
|
def consts_by_path
|
|
170
199
|
@consts_by_path ||= (
|
|
171
200
|
fs_map
|
|
172
|
-
.transform_values {
|
|
201
|
+
.transform_values { Classifier.new(_1).consts }
|
|
173
202
|
)
|
|
174
203
|
end
|
|
175
204
|
end
|
|
176
205
|
|
|
177
206
|
GEM_DIRS = [
|
|
178
|
-
File.expand_path(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
207
|
+
File.expand_path(
|
|
208
|
+
File.join(__dir__, "../shared")
|
|
209
|
+
),
|
|
210
|
+
File.expand_path(
|
|
211
|
+
File.join(__dir__, "../client")
|
|
212
|
+
),
|
|
213
|
+
File.expand_path(
|
|
214
|
+
File.join(__dir__, "../client.rb")
|
|
215
|
+
),
|
|
216
|
+
]
|
|
182
217
|
|
|
183
218
|
class << self
|
|
184
219
|
def bundle(dirs:, registry:, only_facets: false)
|
|
@@ -3,20 +3,24 @@
|
|
|
3
3
|
module Interfacets
|
|
4
4
|
module Server
|
|
5
5
|
class BasicRouter
|
|
6
|
+
# Raised when no configured path (and no default) matches the url.
|
|
7
|
+
class NotFound < RuntimeError; end
|
|
8
|
+
|
|
6
9
|
class Evaluator
|
|
7
|
-
attr_reader
|
|
10
|
+
attr_reader(:bus)
|
|
8
11
|
def initialize(bus:)
|
|
9
12
|
@bus = bus
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
def call(klass:, id:, query:, resolved_path:)
|
|
13
|
-
klass
|
|
14
|
-
.
|
|
16
|
+
klass
|
|
17
|
+
.server_entity_class
|
|
18
|
+
.find_for_basic_routing(id, query:, bus:)
|
|
15
19
|
.tap { _1.entity.api_path = resolved_path }
|
|
16
20
|
end
|
|
17
21
|
end
|
|
18
22
|
|
|
19
|
-
attr_reader
|
|
23
|
+
attr_reader(:paths, :bus, :default)
|
|
20
24
|
def initialize(bus:, paths:, default: nil)
|
|
21
25
|
@bus = bus
|
|
22
26
|
@paths = paths
|
|
@@ -25,28 +29,34 @@ module Interfacets
|
|
|
25
29
|
|
|
26
30
|
def call(url, query: {})
|
|
27
31
|
path = normalize(url)
|
|
32
|
+
route_path, id, resolved_path = route_for(path)
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
klass
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
evaluator.call(
|
|
35
|
+
klass: klass_for(route_path),
|
|
36
|
+
id:,
|
|
37
|
+
query:,
|
|
38
|
+
resolved_path:
|
|
39
|
+
)
|
|
40
|
+
end
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
# Returns [configured path, record id, resolved path]
|
|
43
|
+
def route_for(path)
|
|
44
|
+
if path.nil? && default
|
|
45
|
+
[default, nil, default]
|
|
46
|
+
elsif normalized_paths.key?(path)
|
|
47
|
+
[path, nil, path]
|
|
38
48
|
else
|
|
39
49
|
*parts, id = path.split("/")
|
|
40
|
-
|
|
50
|
+
base_path = parts.join("/")
|
|
41
51
|
|
|
42
|
-
if normalized_paths.key?(
|
|
43
|
-
|
|
44
|
-
evaluator.call(klass:, id:, query:, resolved_path: path)
|
|
52
|
+
if normalized_paths.key?(base_path)
|
|
53
|
+
[base_path, id, path]
|
|
45
54
|
elsif default
|
|
46
|
-
|
|
47
|
-
evaluator.call(klass:, id: nil, query:, resolved_path: default)
|
|
55
|
+
[default, nil, default]
|
|
48
56
|
else
|
|
49
|
-
raise
|
|
57
|
+
raise(
|
|
58
|
+
NotFound.new("unhandled route: #{path}")
|
|
59
|
+
)
|
|
50
60
|
end
|
|
51
61
|
end
|
|
52
62
|
end
|
|
@@ -8,7 +8,6 @@ module Interfacets
|
|
|
8
8
|
:asset_paths,
|
|
9
9
|
:registry,
|
|
10
10
|
)
|
|
11
|
-
|
|
12
11
|
def initialize(root_url:, asset_paths:)
|
|
13
12
|
@registry = Registry.new
|
|
14
13
|
@root_url = root_url
|
|
@@ -17,7 +16,11 @@ module Interfacets
|
|
|
17
16
|
|
|
18
17
|
def client_system_json(only_facets: false)
|
|
19
18
|
{
|
|
20
|
-
assets: Assets.bundle(
|
|
19
|
+
assets: Assets.bundle(
|
|
20
|
+
dirs: asset_paths,
|
|
21
|
+
registry:,
|
|
22
|
+
only_facets:
|
|
23
|
+
),
|
|
21
24
|
root_url:
|
|
22
25
|
}
|
|
23
26
|
end
|
|
@@ -25,10 +28,6 @@ module Interfacets
|
|
|
25
28
|
def build(name:, store:)
|
|
26
29
|
registry.build(name, store)
|
|
27
30
|
end
|
|
28
|
-
|
|
29
|
-
def handle(name:, id:, event:)
|
|
30
|
-
registry.load(name, id).handle(event)
|
|
31
|
-
end
|
|
32
31
|
end
|
|
33
32
|
end
|
|
34
33
|
end
|
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require("active_support/all")
|
|
4
|
+
require("ostruct")
|
|
5
5
|
|
|
6
6
|
module Interfacets
|
|
7
7
|
module Server
|
|
8
8
|
class Registry
|
|
9
9
|
class Channel
|
|
10
|
+
attr_reader(:facet)
|
|
11
|
+
|
|
12
|
+
attr_reader(:registry)
|
|
10
13
|
def initialize(registry:)
|
|
11
14
|
@registry = registry
|
|
12
15
|
end
|
|
13
16
|
|
|
14
|
-
def
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def render_facet
|
|
19
|
-
@facet.render
|
|
17
|
+
def render_facet(in_reply_to:)
|
|
18
|
+
facet.render(in_reply_to:)
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
def rendered?
|
|
23
|
-
|
|
22
|
+
facet
|
|
24
23
|
end
|
|
25
24
|
|
|
26
25
|
def render(klass, store)
|
|
27
|
-
@facet =
|
|
26
|
+
@facet = registry.build(klass, store)
|
|
28
27
|
end
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
def build(name, store)
|
|
32
31
|
facet = name.is_a?(Module) ? name : Object.const_get(name)
|
|
32
|
+
if facet.name.nil?
|
|
33
|
+
raise(
|
|
34
|
+
ArgumentError.new(
|
|
35
|
+
"Facet #{facet.inspect} must be a named module: " \
|
|
36
|
+
"the client looks facets up by constant name"
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
end
|
|
33
40
|
|
|
34
41
|
Api.new(
|
|
35
42
|
registry: self,
|