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
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Client
|
|
5
|
-
module Facets
|
|
6
|
-
class Deserializer
|
|
7
|
-
def self.call(data:, config: Client.system.config)
|
|
8
|
-
Logger.main.debug("deserializing facet: #{data.fetch("facet_class")}")
|
|
9
|
-
|
|
10
|
-
klass = Object.const_get(data.fetch("facet_class"))
|
|
11
|
-
|
|
12
|
-
Logger.main.debug("constructing: #{klass.client.name}")
|
|
13
|
-
|
|
14
|
-
facet = klass.new
|
|
15
|
-
|
|
16
|
-
entity = (
|
|
17
|
-
klass
|
|
18
|
-
.client
|
|
19
|
-
.build(data.fetch("attributes"), parent: nil, facet:)
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
Logger.main.debug("entity constructed")
|
|
23
|
-
|
|
24
|
-
facet.entity = entity
|
|
25
|
-
facet
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Client
|
|
5
|
-
module Facets
|
|
6
|
-
module Schema
|
|
7
|
-
class Deserializer
|
|
8
|
-
def self.call(...)
|
|
9
|
-
new(...).call
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
attr_reader :schema, :results
|
|
13
|
-
def initialize(schema:)
|
|
14
|
-
@schema = schema
|
|
15
|
-
@results = { views: {}, entities: {}, apis: {} }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def call
|
|
19
|
-
schema.fetch("views").each do |view_type, view_json|
|
|
20
|
-
block = view_json.fetch("body")
|
|
21
|
-
|
|
22
|
-
results[:views][view_type] = View.new(
|
|
23
|
-
block: eval(block),
|
|
24
|
-
name: view_type,
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
schema.fetch("apis").each do |api_type, entity_json|
|
|
29
|
-
block = entity_json.fetch("body")
|
|
30
|
-
|
|
31
|
-
results[:apis][api_type] =
|
|
32
|
-
Module.new do
|
|
33
|
-
extend ActiveSupport::Concern
|
|
34
|
-
define_singleton_method(:name) { api_type }
|
|
35
|
-
|
|
36
|
-
included do
|
|
37
|
-
class_exec(&eval(block))
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
schema.fetch("entities").each do |entity_type, client_json|
|
|
43
|
-
block = client_json.fetch("body")
|
|
44
|
-
api_type = client_json.fetch("api_type")
|
|
45
|
-
|
|
46
|
-
api_mod = results[:apis].fetch(api_type)
|
|
47
|
-
|
|
48
|
-
results[:entities][entity_type] =
|
|
49
|
-
Class.new(Entity) do
|
|
50
|
-
define_singleton_method(:name) { entity_type }
|
|
51
|
-
include api_mod
|
|
52
|
-
|
|
53
|
-
class_exec(&eval(block))
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
results
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Client
|
|
5
|
-
module Facets
|
|
6
|
-
module Schema
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
class_methods do
|
|
9
|
-
def view_spec(&block)
|
|
10
|
-
@view_spec = block
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def view
|
|
14
|
-
# TODO: change this to just inherit from view
|
|
15
|
-
@view ||= View.new(
|
|
16
|
-
block: @view_spec,
|
|
17
|
-
name: "#{self.name}::View",
|
|
18
|
-
)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def client_spec(&block)
|
|
22
|
-
@client_spec = block
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def client
|
|
26
|
-
# scoping
|
|
27
|
-
client_name = "#{self.name}::Client"
|
|
28
|
-
client_spec = @client_spec
|
|
29
|
-
entity = self.entity
|
|
30
|
-
|
|
31
|
-
@client ||=
|
|
32
|
-
Class.new(Entity) do
|
|
33
|
-
define_singleton_method(:name) { client_name }
|
|
34
|
-
extend_entity { include entity }
|
|
35
|
-
|
|
36
|
-
class_exec(&client_spec)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def entity_spec(&block)
|
|
41
|
-
@entity_spec = block
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def entity
|
|
45
|
-
# scoping
|
|
46
|
-
entity_name = "#{self.name}::Entity"
|
|
47
|
-
entity_spec = @entity_spec
|
|
48
|
-
|
|
49
|
-
@entity ||=
|
|
50
|
-
Module.new do
|
|
51
|
-
extend ActiveSupport::Concern
|
|
52
|
-
define_singleton_method(:name) { entity_name }
|
|
53
|
-
|
|
54
|
-
included do
|
|
55
|
-
class_exec(&entity_spec)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Client
|
|
5
|
-
module Facets
|
|
6
|
-
class Serializer
|
|
7
|
-
class << self
|
|
8
|
-
def call(facet)
|
|
9
|
-
{
|
|
10
|
-
facet_class: facet.class.name,
|
|
11
|
-
attributes: facet.entity.serialize,
|
|
12
|
-
}
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Client
|
|
5
|
-
class View
|
|
6
|
-
class Evaluator
|
|
7
|
-
def self.call(...)
|
|
8
|
-
new(...).call
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
attr_reader :entity, :channels, :block
|
|
12
|
-
def initialize(entity:, channels:, block:)
|
|
13
|
-
@entity = entity
|
|
14
|
-
@channels = channels
|
|
15
|
-
@block = block
|
|
16
|
-
@data = Hash.new { |h, k| h[k] = { streams: {} } }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def call
|
|
20
|
-
instance_exec(entity, &@block)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def render(channel_id, stream: "default", &block)
|
|
24
|
-
channels
|
|
25
|
-
.fetch(channel_id.to_s)
|
|
26
|
-
.builder(stream.to_s)
|
|
27
|
-
.then { instance_exec(_1, &block) }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def channel(name)
|
|
31
|
-
@channels.fetch(name)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
class << self
|
|
36
|
-
def view(&block)
|
|
37
|
-
@view = block if block_given?
|
|
38
|
-
@view
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def render(entity:, channels:)
|
|
43
|
-
Evaluator.call(entity: entity, channels:, block: self.class.view)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Server
|
|
5
|
-
module Assets
|
|
6
|
-
class Facet
|
|
7
|
-
def self.register(klass:, assets:)
|
|
8
|
-
assets[klass.name] = new(klass).code
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
attr_reader :klass
|
|
12
|
-
def initialize(klass)
|
|
13
|
-
@klass = klass
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def code
|
|
17
|
-
# nest it all so names resolve
|
|
18
|
-
*mods, klass_name = klass.name.split("::")
|
|
19
|
-
|
|
20
|
-
headers = []
|
|
21
|
-
footers = []
|
|
22
|
-
|
|
23
|
-
current_mod = ""
|
|
24
|
-
mods.each do |mod_name|
|
|
25
|
-
current_mod += "::#{mod_name}"
|
|
26
|
-
type = current_mod.constantize.is_a?(Module) ? :module : :class
|
|
27
|
-
headers << "#{type} #{mod_name}"
|
|
28
|
-
footers << "end"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
headers << "class #{klass_name} < Interfacets::Client::Facet"
|
|
32
|
-
footers << "end"
|
|
33
|
-
|
|
34
|
-
<<~TXT
|
|
35
|
-
#{headers.join("\n")}
|
|
36
|
-
|
|
37
|
-
include Interfacets::Client::Facets::Schema
|
|
38
|
-
|
|
39
|
-
view_spec #{write_source(klass.client_config.view.block)}
|
|
40
|
-
|
|
41
|
-
entity_spec #{write_source(klass.client_config.api.block)}
|
|
42
|
-
|
|
43
|
-
client_spec #{write_source(klass.client_config.entity.block)}
|
|
44
|
-
#{footers.join("\n")}
|
|
45
|
-
TXT
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
private
|
|
49
|
-
|
|
50
|
-
def write_source(block)
|
|
51
|
-
return unless block
|
|
52
|
-
|
|
53
|
-
RubyVM::AbstractSyntaxTree
|
|
54
|
-
.of(block, keep_script_lines: true)
|
|
55
|
-
.source
|
|
56
|
-
.strip
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Server
|
|
5
|
-
module BasicRoutable
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
included do
|
|
9
|
-
attach(self)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class_methods do
|
|
14
|
-
def attach(mod)
|
|
15
|
-
mod.shared do
|
|
16
|
-
accessor(:api_path, accepted_by: :client)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
mod.server do
|
|
20
|
-
attr_accessor :api_path
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def inherited(mod)
|
|
25
|
-
attach(mod)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
attr_accessor :bus
|
|
29
|
-
def find(&block)
|
|
30
|
-
@find = block if block_given?
|
|
31
|
-
@find
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def build(klass, store)
|
|
35
|
-
bus.registry.build(klass, store)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Server
|
|
5
|
-
class Config
|
|
6
|
-
attr_reader :registry
|
|
7
|
-
attr_accessor(
|
|
8
|
-
:mount_point,
|
|
9
|
-
:host,
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
def initialize(
|
|
13
|
-
mount_point:,
|
|
14
|
-
registry:,
|
|
15
|
-
assets:
|
|
16
|
-
)
|
|
17
|
-
@mount_point = mount_point
|
|
18
|
-
@registry = registry
|
|
19
|
-
@assets = assets
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def bundled_assets
|
|
23
|
-
dirs = @assets.map(&:to_s)
|
|
24
|
-
|
|
25
|
-
facets = (
|
|
26
|
-
@registry
|
|
27
|
-
.values
|
|
28
|
-
.map { Object.const_get(_1) }
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
Interfacets::Server::Assets.bundle(dirs:, facets:)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def schema
|
|
35
|
-
@facet_registry
|
|
36
|
-
.values
|
|
37
|
-
.map { Object.const_get(_1) }
|
|
38
|
-
.then {
|
|
39
|
-
Interfacets::Server::Facets::Schema::Serializer
|
|
40
|
-
.call(facets: _1)
|
|
41
|
-
}
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def register_facet(name, class_or_class_name)
|
|
45
|
-
# if klass.name is nil, then just use the class reference
|
|
46
|
-
@facet_registry[name] = class_or_class_name
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def all_facets
|
|
50
|
-
@facet_registry.keys.map { facet(_1) }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def default_facet
|
|
54
|
-
build_facet(facet_uid: @default_facet)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def facet(name)
|
|
58
|
-
klass_name = (
|
|
59
|
-
if @facet_registry.key?(name)
|
|
60
|
-
@facet_registry.fetch(name)
|
|
61
|
-
elsif @facet_registry.values.include?(name)
|
|
62
|
-
name
|
|
63
|
-
else
|
|
64
|
-
raise("unknown facet_class: #{name}")
|
|
65
|
-
end
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
klass_name.constantize
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def ingest_facet(data)
|
|
72
|
-
Facets::Deserializer.call(data:, config: self)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def build_facet(facet_uid: nil, name: nil, id: nil, query: {})
|
|
76
|
-
if name
|
|
77
|
-
facet(name).build(id, query:)
|
|
78
|
-
elsif @facet_registry.key?(facet_uid)
|
|
79
|
-
facet(facet_uid).build(nil, query:)
|
|
80
|
-
else
|
|
81
|
-
*name, id = facet_uid.split("/")
|
|
82
|
-
facet(name.join("/")).build(id, query:)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require "active_support/concern"
|
|
3
|
-
|
|
4
|
-
module Interfacets
|
|
5
|
-
module Server
|
|
6
|
-
module Facet
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
|
|
9
|
-
class Actor
|
|
10
|
-
def initialize(entity:, facet:)
|
|
11
|
-
@entity = entity
|
|
12
|
-
@facet = facet
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class_methods do
|
|
17
|
-
def view(&block)
|
|
18
|
-
views << block
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def views
|
|
22
|
-
@views ||= []
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def client(&block)
|
|
26
|
-
clients << block
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def clients
|
|
30
|
-
@clients ||= []
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def shared(&block)
|
|
34
|
-
shareds << block
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def shareds
|
|
38
|
-
@shareds ||= []
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def server(&block)
|
|
42
|
-
servers << block
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def servers
|
|
46
|
-
@servers ||= []
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Server
|
|
5
|
-
module Facets
|
|
6
|
-
class Deserializer
|
|
7
|
-
class << self
|
|
8
|
-
def call(data:, config:)
|
|
9
|
-
facet_class_name = data.fetch("facet_class")
|
|
10
|
-
attributes = data.fetch("attributes")
|
|
11
|
-
|
|
12
|
-
facet = (
|
|
13
|
-
config
|
|
14
|
-
.facet(facet_class_name)
|
|
15
|
-
.build(attributes.fetch("id"))
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
facet.entity.ingest(attributes)
|
|
19
|
-
facet
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Server
|
|
5
|
-
module Facets
|
|
6
|
-
module Schema
|
|
7
|
-
class Serializer
|
|
8
|
-
def self.call(...)
|
|
9
|
-
new(...).call
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private attr_reader(:facets, :schema)
|
|
13
|
-
def initialize(facets:)
|
|
14
|
-
@facets = facets
|
|
15
|
-
@schema = { views: {}, entities: {}, apis: {} }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def call
|
|
19
|
-
facets.each do |facet|
|
|
20
|
-
config = facet.client_config
|
|
21
|
-
|
|
22
|
-
schema[:views][config.view.name] = {
|
|
23
|
-
body: write_source(config.view.block),
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
schema[:entities][config.entity.name] = {
|
|
27
|
-
api_type: config.api.name,
|
|
28
|
-
body: write_source(config.entity.block),
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
schema[:apis][config.api.name] = {
|
|
32
|
-
body: write_source(config.api.block),
|
|
33
|
-
}
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
schema
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
def write_source(block)
|
|
42
|
-
return unless block
|
|
43
|
-
|
|
44
|
-
RubyVM::AbstractSyntaxTree
|
|
45
|
-
.of(block, keep_script_lines: true)
|
|
46
|
-
.source
|
|
47
|
-
.then { block.is_a?(UnboundMethod) ? _1 : "lambda #{_1}" }
|
|
48
|
-
.strip
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Server
|
|
5
|
-
module Facets
|
|
6
|
-
class Serializer
|
|
7
|
-
def self.call(...)
|
|
8
|
-
new(...).call
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
attr_reader :facet, :mount_point
|
|
12
|
-
def initialize(facet, mount_point)
|
|
13
|
-
@facet = facet
|
|
14
|
-
@mount_point = mount_point
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def call
|
|
18
|
-
{
|
|
19
|
-
id: facet.entity.id,
|
|
20
|
-
facet_class: facet.class.name,
|
|
21
|
-
attributes: facet.entity.serialize,
|
|
22
|
-
}
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def attributes(entity)
|
|
26
|
-
entity
|
|
27
|
-
.attribute_specs
|
|
28
|
-
.each_with_object({}) { |(name, _attribute), json|
|
|
29
|
-
# refactor this, shouldn't be attributes...
|
|
30
|
-
# next if attribute.is_a?(Facets::Attributes::ClientEvent)
|
|
31
|
-
# next if attribute.is_a?(Facets::Attributes::ServerEvent)
|
|
32
|
-
# next if attribute.is_a?(Facets::Attributes::Inherit)
|
|
33
|
-
|
|
34
|
-
value = entity.public_send(name)
|
|
35
|
-
|
|
36
|
-
json[name] = (
|
|
37
|
-
if value.is_a?(Array)
|
|
38
|
-
value.map { _1.is_a?(Entity) || _1.is_a?(Facet::Handler) ? attributes(_1) : _1 }
|
|
39
|
-
elsif value.is_a?(Entity) || value.is_a?(Facet::Handler)
|
|
40
|
-
attributes(value)
|
|
41
|
-
else
|
|
42
|
-
value
|
|
43
|
-
end
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Interfacets
|
|
4
|
-
module Shared
|
|
5
|
-
class EntityCollection
|
|
6
|
-
include Enumerable
|
|
7
|
-
|
|
8
|
-
attr_reader :items
|
|
9
|
-
def initialize(items, &block)
|
|
10
|
-
@items = items || []
|
|
11
|
-
@wrap = block
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def each(&)
|
|
15
|
-
@items.each do |item|
|
|
16
|
-
yield(@wrap.call(item))
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def to_a
|
|
21
|
-
@items.map { @wrap.call(_1) }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def size
|
|
25
|
-
@items.size
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def length
|
|
29
|
-
@items.length
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def empty?
|
|
33
|
-
@items.empty?
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def include?(item)
|
|
37
|
-
@items.include?(to_record(item))
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def [](index)
|
|
41
|
-
item = @items[index]
|
|
42
|
-
item ? @wrap.call(item) : nil
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def first
|
|
46
|
-
item = @items.first
|
|
47
|
-
item ? @wrap.call(item) : nil
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def last
|
|
51
|
-
item = @items.last
|
|
52
|
-
item ? @wrap.call(item) : nil
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def <<(item_to_add)
|
|
56
|
-
@items << to_record(item_to_add)
|
|
57
|
-
self
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def push(*items_to_add)
|
|
61
|
-
@items.push(*items_to_add.map { to_record(_1) })
|
|
62
|
-
self
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def delete(item)
|
|
66
|
-
@items.delete(to_record(item))
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def delete_at(index)
|
|
70
|
-
@items.delete_at(index)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def original
|
|
74
|
-
@items
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def inspect
|
|
78
|
-
"#<#{self.class.name} decorating=#{@items.inspect} with=#{@entity_class}>"
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
private
|
|
82
|
-
|
|
83
|
-
def to_record(item)
|
|
84
|
-
item.is_a?(Entity) ? item.record : item
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|