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,17 +4,47 @@ module Interfacets
|
|
|
4
4
|
module Shared
|
|
5
5
|
class GeneratedStore
|
|
6
6
|
class Constructor
|
|
7
|
-
def self.call(entity_class)
|
|
7
|
+
def self.call(entity_class, klasses: nil)
|
|
8
8
|
klass = Class.new(GeneratedStore) do
|
|
9
9
|
define_singleton_method(:name) { "#{entity_class.name}.GeneratedStore" }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
entity_class.accessors.
|
|
13
|
-
|
|
12
|
+
all_accessors = entity_class.accessors.dup
|
|
13
|
+
all_associations = entity_class.associations.dup
|
|
14
|
+
all_actions = entity_class.actions.dup
|
|
15
|
+
|
|
16
|
+
if klasses
|
|
17
|
+
klasses.values.each do |sub|
|
|
18
|
+
all_accessors.merge!(sub.accessors)
|
|
19
|
+
all_associations.merge!(sub.associations)
|
|
20
|
+
all_actions.merge!(sub.actions)
|
|
21
|
+
end
|
|
14
22
|
end
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
all_accessors.each_key { klass.accessor(_1) }
|
|
25
|
+
|
|
26
|
+
all_associations.each do |name, spec|
|
|
27
|
+
sub_klasses = spec.respond_to?(:klasses) ? spec.klasses : nil
|
|
28
|
+
sub_class = call(
|
|
29
|
+
spec.klass,
|
|
30
|
+
klasses: sub_klasses
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
if spec.respond_to?(:polymorphic_key) && spec.polymorphic_key &&
|
|
34
|
+
spec.polymorphic_key != Entities::Specs::NOT_PASSED.to_s
|
|
35
|
+
sub_klasses&.each do |type, sub_facet|
|
|
36
|
+
next if sub_facet.accessors.key?(spec.polymorphic_key.to_s)
|
|
37
|
+
|
|
38
|
+
raise(
|
|
39
|
+
ArgumentError.new(
|
|
40
|
+
"Polymorphic type #{type.inspect} of association '#{name}' must declare " \
|
|
41
|
+
"accessor(:#{spec.polymorphic_key}) (the polymorphic_key), " \
|
|
42
|
+
"or the client cannot pick its facet"
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
sub_class.accessor(spec.polymorphic_key)
|
|
47
|
+
end
|
|
18
48
|
|
|
19
49
|
if spec.type == :reference
|
|
20
50
|
klass.association(name, klass: sub_class)
|
|
@@ -23,13 +53,16 @@ module Interfacets
|
|
|
23
53
|
end
|
|
24
54
|
end
|
|
25
55
|
|
|
26
|
-
|
|
56
|
+
all_actions.each_key do |name|
|
|
27
57
|
klass.define_method(name) do |entity:|
|
|
28
58
|
Client::System
|
|
29
59
|
.current_bus
|
|
30
60
|
.channel("interfacets:api")
|
|
31
61
|
.builder
|
|
32
|
-
.submit(
|
|
62
|
+
.submit(
|
|
63
|
+
name,
|
|
64
|
+
nesting: entity.entity_nesting
|
|
65
|
+
)
|
|
33
66
|
end
|
|
34
67
|
end
|
|
35
68
|
|
|
@@ -37,8 +70,8 @@ module Interfacets
|
|
|
37
70
|
end
|
|
38
71
|
end
|
|
39
72
|
|
|
40
|
-
class
|
|
41
|
-
attr_reader
|
|
73
|
+
class Association
|
|
74
|
+
attr_reader(:store, :spec)
|
|
42
75
|
def initialize(store:, spec:)
|
|
43
76
|
@store = store
|
|
44
77
|
@spec = spec
|
|
@@ -63,34 +96,31 @@ module Interfacets
|
|
|
63
96
|
end
|
|
64
97
|
end
|
|
65
98
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def
|
|
69
|
-
|
|
99
|
+
class Spec
|
|
100
|
+
attr_reader(:name, :klass, :type)
|
|
101
|
+
def initialize(name:, klass:, type:)
|
|
102
|
+
@name = name
|
|
103
|
+
@klass = klass
|
|
104
|
+
@type = type
|
|
70
105
|
end
|
|
106
|
+
end
|
|
71
107
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
@klass = klass
|
|
77
|
-
@type = type
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def build
|
|
81
|
-
spec.klass.new
|
|
82
|
-
end
|
|
108
|
+
class << self
|
|
109
|
+
# rubocop:disable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
110
|
+
def construct(*args, **opts, &block)
|
|
111
|
+
Constructor.call(*args, **opts, &block)
|
|
83
112
|
end
|
|
113
|
+
# rubocop:enable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
84
114
|
|
|
85
115
|
def accessor(name)
|
|
86
116
|
name = name.to_s
|
|
87
117
|
|
|
88
118
|
define_method(name) do
|
|
89
|
-
|
|
119
|
+
attributes[name]
|
|
90
120
|
end
|
|
91
121
|
|
|
92
122
|
define_method("#{name}=") do |val|
|
|
93
|
-
|
|
123
|
+
attributes[name] = val
|
|
94
124
|
end
|
|
95
125
|
end
|
|
96
126
|
|
|
@@ -104,24 +134,30 @@ module Interfacets
|
|
|
104
134
|
)
|
|
105
135
|
|
|
106
136
|
define_method(name) do
|
|
107
|
-
|
|
137
|
+
attributes[name]
|
|
108
138
|
end
|
|
109
139
|
|
|
110
140
|
define_method("#{name}=") do |val|
|
|
111
|
-
|
|
141
|
+
attributes[name] = val
|
|
112
142
|
end
|
|
113
143
|
end
|
|
114
144
|
|
|
115
|
-
|
|
116
|
-
|
|
145
|
+
# rubocop:disable Style/ArgumentsForwarding
|
|
146
|
+
def collection(*args, **opts)
|
|
147
|
+
association(
|
|
148
|
+
*args,
|
|
149
|
+
**opts,
|
|
150
|
+
type: :collection
|
|
151
|
+
)
|
|
117
152
|
end
|
|
153
|
+
# rubocop:enable Style/ArgumentsForwarding
|
|
118
154
|
|
|
119
155
|
def associations
|
|
120
156
|
@associations ||= {}
|
|
121
157
|
end
|
|
122
158
|
end
|
|
123
159
|
|
|
124
|
-
attr_accessor
|
|
160
|
+
attr_accessor(:attributes)
|
|
125
161
|
def initialize
|
|
126
162
|
@attributes = {
|
|
127
163
|
"internal_entity_id" => SecureRandom.uuid
|
|
@@ -137,13 +173,12 @@ module Interfacets
|
|
|
137
173
|
self
|
|
138
174
|
.class
|
|
139
175
|
.associations
|
|
140
|
-
.map { |name, spec| [name,
|
|
176
|
+
.map { |name, spec| [name, Association.new(store: self, spec:)] }
|
|
141
177
|
.to_h
|
|
142
178
|
)
|
|
143
179
|
|
|
144
|
-
@association_handlers.fetch(name)
|
|
180
|
+
@association_handlers.fetch(name.to_s)
|
|
145
181
|
end
|
|
146
|
-
|
|
147
182
|
end
|
|
148
183
|
end
|
|
149
184
|
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Interfacets
|
|
4
|
+
module Shared
|
|
5
|
+
# Opt-in: lets a facet pull fresh state from the server without losing the
|
|
6
|
+
# user's in-flight work, and wires that up to pubsub messages.
|
|
7
|
+
#
|
|
8
|
+
# class ApplicationFacet
|
|
9
|
+
# include Interfacets::Shared::Facet
|
|
10
|
+
# def self.inherited(mod)
|
|
11
|
+
# mod.include(Interfacets::Shared::Refreshable)
|
|
12
|
+
# end
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# Adds:
|
|
16
|
+
# - a `refresh` server action. The request carries no attributes (so it
|
|
17
|
+
# cannot clobber server state with stale client state); the server
|
|
18
|
+
# replies with a `refresh` event carrying `in_reply_to`, which the client merges as a patch
|
|
19
|
+
# (nothing is checkpointed, so dirty fields stay dirty and
|
|
20
|
+
# `protect_during_patch` / `merge(attr, :patch)` rules apply).
|
|
21
|
+
# - a client `on_pubsub(topic:, data:)` handler: a message carrying
|
|
22
|
+
# `"attributes"` (or a full patch envelope as built by
|
|
23
|
+
# `Server::Api#patch`) is merged as a patch; any other message is a
|
|
24
|
+
# signal and triggers `refresh`. Override `on_pubsub` to do something
|
|
25
|
+
# else.
|
|
26
|
+
module Refreshable
|
|
27
|
+
extend(ActiveSupport::Concern)
|
|
28
|
+
|
|
29
|
+
module ClientMethods
|
|
30
|
+
def on_pubsub(topic:, data:)
|
|
31
|
+
event = refreshable_patch_event(data)
|
|
32
|
+
|
|
33
|
+
if event
|
|
34
|
+
Shared::Entities::Bus.new(entity: self).handle(event:)
|
|
35
|
+
else
|
|
36
|
+
refresh
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def refreshable_patch_event(data)
|
|
43
|
+
return nil unless data.is_a?(Hash)
|
|
44
|
+
|
|
45
|
+
envelope = data["payload"]
|
|
46
|
+
if envelope.is_a?(Hash) && envelope.key?("action") && envelope["payload"].is_a?(Hash)
|
|
47
|
+
envelope
|
|
48
|
+
elsif data["attributes"].is_a?(Hash)
|
|
49
|
+
{
|
|
50
|
+
"id" => SecureRandom.uuid,
|
|
51
|
+
"from" => "server",
|
|
52
|
+
"to" => entity_role.to_s,
|
|
53
|
+
"nesting" => data["nesting"] || ["root"],
|
|
54
|
+
"action" => "patch",
|
|
55
|
+
"payload" => { "attributes" => data["attributes"] },
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
included do
|
|
62
|
+
entity_base do
|
|
63
|
+
server_action(
|
|
64
|
+
:refresh,
|
|
65
|
+
only_if_valid: false,
|
|
66
|
+
stateless: true,
|
|
67
|
+
reply: { patch: true }
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# The reply is the server entity as loaded for the request.
|
|
72
|
+
server_entity do
|
|
73
|
+
def refresh
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
client_entity do
|
|
78
|
+
include(
|
|
79
|
+
Interfacets::Shared::Refreshable::ClientMethods
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -3,52 +3,56 @@
|
|
|
3
3
|
module Interfacets
|
|
4
4
|
module Shared
|
|
5
5
|
module Utils
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def permissive_exec(receiver, *, &lambda)
|
|
6
|
+
# rubocop:disable Style/ArgumentsForwarding
|
|
7
|
+
def self.permissive_exec(receiver, *args, &lambda)
|
|
9
8
|
if lambda.arity.zero?
|
|
10
9
|
receiver.instance_exec(&lambda)
|
|
11
10
|
else
|
|
12
|
-
receiver.instance_exec(
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def permissive_call(lambda, ...)
|
|
17
|
-
if lambda.arity.zero?
|
|
18
|
-
lambda.call
|
|
19
|
-
else
|
|
20
|
-
lambda.call(...)
|
|
11
|
+
receiver.instance_exec(*args, &lambda)
|
|
21
12
|
end
|
|
22
13
|
end
|
|
14
|
+
# rubocop:enable Style/ArgumentsForwarding
|
|
23
15
|
|
|
24
|
-
def
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
id = parts.pop
|
|
31
|
-
facet = parts.join("/")
|
|
16
|
+
def self.blank?(obj)
|
|
17
|
+
return true if obj.nil? || obj == false
|
|
18
|
+
return false if obj == true || obj.is_a?(Numeric)
|
|
19
|
+
return obj.empty? if obj.is_a?(Array) || obj.is_a?(Hash)
|
|
20
|
+
return !obj.match(/\S/) if obj.is_a?(String)
|
|
21
|
+
return obj.empty? if obj.respond_to?(:empty?)
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
false
|
|
34
24
|
end
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
def blank?(str)
|
|
38
|
-
return true if str.nil?
|
|
39
|
-
return str.empty? if str.is_a?(Array)
|
|
40
|
-
return str.match(/\A\s*\z/) if str.is_a?(String)
|
|
41
|
-
|
|
42
|
-
raise("unsupported blank check")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def present?(str)
|
|
26
|
+
def self.present?(str)
|
|
46
27
|
!blank?(str)
|
|
47
28
|
end
|
|
48
29
|
|
|
49
|
-
def presence(obj)
|
|
30
|
+
def self.presence(obj)
|
|
50
31
|
present?(obj) ? obj : nil
|
|
51
32
|
end
|
|
33
|
+
|
|
34
|
+
def self.deep_dup(obj)
|
|
35
|
+
case obj
|
|
36
|
+
when Hash
|
|
37
|
+
result = {}
|
|
38
|
+
obj.each do |k, v|
|
|
39
|
+
result[deep_dup(k)] = deep_dup(v)
|
|
40
|
+
end
|
|
41
|
+
result
|
|
42
|
+
when Array
|
|
43
|
+
obj.map { deep_dup(_1) }
|
|
44
|
+
when String
|
|
45
|
+
obj.dup
|
|
46
|
+
when Numeric, Symbol, TrueClass, FalseClass, NilClass
|
|
47
|
+
obj
|
|
48
|
+
else
|
|
49
|
+
begin
|
|
50
|
+
obj.dup
|
|
51
|
+
rescue TypeError
|
|
52
|
+
obj
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
52
56
|
end
|
|
53
57
|
end
|
|
54
58
|
end
|