isomorfeus-data 2.5.4 → 22.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus/data/config.rb +8 -25
- data/lib/isomorfeus/data/enhancer.rb +291 -0
- data/lib/isomorfeus/data/file_accelerator.rb +95 -0
- data/lib/isomorfeus/data/object_accelerator.rb +81 -73
- data/lib/isomorfeus/data/rack_middleware.rb +73 -0
- data/lib/isomorfeus/data/reducer.rb +47 -17
- data/lib/isomorfeus/data/sid.rb +34 -0
- data/lib/isomorfeus/data/version.rb +1 -1
- data/lib/isomorfeus-data.rb +27 -32
- data/lib/lucid_data_generic.rb +163 -0
- data/lib/lucid_file.rb +137 -0
- data/lib/lucid_object.rb +431 -0
- metadata +51 -47
- data/lib/data_uri/open_uri.rb +0 -22
- data/lib/data_uri/uri.rb +0 -61
- data/lib/data_uri.rb +0 -4
- data/lib/isomorfeus/data/field_support.rb +0 -247
- data/lib/isomorfeus/data/generic_class_api.rb +0 -127
- data/lib/isomorfeus/data/generic_instance_api.rb +0 -171
- data/lib/isomorfeus/data/handler/generic.rb +0 -133
- data/lib/isomorfeus_data/lucid_file/base.rb +0 -10
- data/lib/isomorfeus_data/lucid_file/mixin.rb +0 -281
- data/lib/isomorfeus_data/lucid_object/base.rb +0 -10
- data/lib/isomorfeus_data/lucid_object/mixin.rb +0 -236
- data/lib/isomorfeus_data/lucid_query/base.rb +0 -10
- data/lib/isomorfeus_data/lucid_query/mixin.rb +0 -112
- data/lib/isomorfeus_data/lucid_query_result.rb +0 -113
- data/opal/iso_uri.rb +0 -29
- data/opal/uri/common.rb +0 -18
- data/opal/uri/generic.rb +0 -47
@@ -1,112 +0,0 @@
|
|
1
|
-
module LucidQuery
|
2
|
-
module Mixin
|
3
|
-
def self.included(base)
|
4
|
-
base.extend(LucidPropDeclaration::Mixin)
|
5
|
-
base.include(LucidI18n::Mixin)
|
6
|
-
|
7
|
-
if RUBY_ENGINE == 'opal'
|
8
|
-
base.instance_exec do
|
9
|
-
def _generate_auto_key(props_s)
|
10
|
-
component = nil
|
11
|
-
component_name = '_'
|
12
|
-
%x{
|
13
|
-
let c = Opal.Preact.active_component();
|
14
|
-
if (typeof c?.__ruby_instance !== 'undefined') { component = c.__ruby_instance; }
|
15
|
-
}
|
16
|
-
component_name = component.class.name if component
|
17
|
-
"#{component_name}:_:#{self.name}:#{props_s}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def _should_return?(lqri, gak)
|
21
|
-
if on_ssr?
|
22
|
-
lqri.loaded?
|
23
|
-
else on_browser?
|
24
|
-
if Isomorfeus::TopLevel.hydrated
|
25
|
-
if Isomorfeus::TopLevel.first_pass
|
26
|
-
lqri.loaded?
|
27
|
-
else
|
28
|
-
lqri.loaded? && !gak
|
29
|
-
end
|
30
|
-
else
|
31
|
-
lqri.loaded? && !gak
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def execute(key: nil, **props)
|
37
|
-
gak = key ? false : true
|
38
|
-
key = _generate_auto_key(`JSON.stringify(props)`) unless key
|
39
|
-
|
40
|
-
lqri = LucidQueryResult.new(key: key)
|
41
|
-
return lqri if _should_return?(lqri, gak)
|
42
|
-
props[:query_result_instance] = lqri
|
43
|
-
promise_execute(key: gak ? nil : key, **props)
|
44
|
-
lqri
|
45
|
-
end
|
46
|
-
|
47
|
-
def promise_execute(key: nil, **props)
|
48
|
-
gak = key ? false : true
|
49
|
-
key = _generate_auto_key(`JSON.stringify(props)`) unless key
|
50
|
-
|
51
|
-
lqri = props.delete(:query_result_instance)
|
52
|
-
lqri = LucidQueryResult.new(key: key) unless lqri
|
53
|
-
return Promise.new.resolve(lqri) if _should_return?(lqri, gak)
|
54
|
-
|
55
|
-
props.each_key do |prop_name|
|
56
|
-
Isomorfeus.raise_error(message: "#{self.to_s} No such query prop declared: '#{prop_name}'!") unless declared_props.key?(prop_name)
|
57
|
-
end
|
58
|
-
props = validated_props(props)
|
59
|
-
props[:key] = lqri.key
|
60
|
-
Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :execute, props).then do |agent|
|
61
|
-
agent.process do
|
62
|
-
lqri._load_from_store!
|
63
|
-
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
|
64
|
-
lqri
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def execute_query(_); end
|
70
|
-
end
|
71
|
-
else
|
72
|
-
unless base == LucidQuery::Base
|
73
|
-
Isomorfeus.add_valid_data_class(base)
|
74
|
-
end
|
75
|
-
|
76
|
-
base.instance_exec do
|
77
|
-
def promise_execute(**props)
|
78
|
-
instance = self.execute(**props)
|
79
|
-
result_promise = Promise.new
|
80
|
-
result_promise.resolve(instance)
|
81
|
-
result_promise
|
82
|
-
end
|
83
|
-
|
84
|
-
def execute(**props)
|
85
|
-
key = props.delete(:key)
|
86
|
-
result_set = self.new(**props).instance_exec(&@_query_block)
|
87
|
-
LucidQueryResult.new(key: key, result_set: result_set)
|
88
|
-
end
|
89
|
-
|
90
|
-
def execute_query(&block)
|
91
|
-
@_query_block = block
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
attr_reader :props
|
96
|
-
|
97
|
-
def initialize(**props_hash)
|
98
|
-
props_hash = self.class.validated_props(props_hash)
|
99
|
-
@props = LucidProps.new(props_hash)
|
100
|
-
end
|
101
|
-
|
102
|
-
def current_user
|
103
|
-
Isomorfeus.current_user
|
104
|
-
end
|
105
|
-
|
106
|
-
def pub_sub_client
|
107
|
-
Isomorfeus.pub_sub_client
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
class LucidQueryResult
|
2
|
-
attr_reader :key
|
3
|
-
|
4
|
-
def [](accessor_name)
|
5
|
-
self.send(accessor_name.to_sym)
|
6
|
-
end
|
7
|
-
|
8
|
-
def sid
|
9
|
-
[@class_name, @key]
|
10
|
-
end
|
11
|
-
|
12
|
-
def sid_s
|
13
|
-
"[#{@class_name}|#{@key}]"
|
14
|
-
end
|
15
|
-
|
16
|
-
if RUBY_ENGINE == 'opal'
|
17
|
-
def initialize(key: nil, result_set: nil, _loading: false)
|
18
|
-
@class_name = 'LucidQueryResult'
|
19
|
-
@key = key ? key.to_s : self.object_id.to_s
|
20
|
-
@result_set = result_set
|
21
|
-
end
|
22
|
-
|
23
|
-
def _load_from_store!
|
24
|
-
@result_set = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def loaded?
|
28
|
-
Redux.fetch_by_path(:data_state, @class_name, @key) ? true : false
|
29
|
-
end
|
30
|
-
|
31
|
-
def key?(k)
|
32
|
-
if @result_set
|
33
|
-
@result_set.key?(k)
|
34
|
-
else
|
35
|
-
stored_results = Redux.fetch_by_path(:data_state, @class_name, @key)
|
36
|
-
return false unless stored_results
|
37
|
-
`Object.hasOwnProperty(stored_results, k)`
|
38
|
-
end
|
39
|
-
end
|
40
|
-
alias has_key? key?
|
41
|
-
|
42
|
-
def method_missing(accessor_name, *args, &block)
|
43
|
-
sid_or_array = if @result_set
|
44
|
-
@result_set[accessor_name]
|
45
|
-
else
|
46
|
-
stored_results = Redux.fetch_by_path(:data_state, @class_name, @key)
|
47
|
-
stored_results.JS[accessor_name] if stored_results
|
48
|
-
end
|
49
|
-
return nil unless sid_or_array
|
50
|
-
if stored_results.JS['_is_array_']
|
51
|
-
sid_or_array.map { |sid| Isomorfeus.instance_from_sid(sid) }
|
52
|
-
else
|
53
|
-
Isomorfeus.instance_from_sid(sid_or_array)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
else
|
57
|
-
def initialize(key: nil, result_set: nil)
|
58
|
-
@class_name = 'LucidQueryResult'
|
59
|
-
@key = key ? key.to_s : self.object_id.to_s
|
60
|
-
@result_set = result_set.nil? ? {} : result_set
|
61
|
-
@result_set.transform_keys!(&:to_sym)
|
62
|
-
end
|
63
|
-
|
64
|
-
def loaded?
|
65
|
-
@result_set.any?
|
66
|
-
end
|
67
|
-
|
68
|
-
def key?(k)
|
69
|
-
@result_set.key?(k)
|
70
|
-
end
|
71
|
-
alias has_key? key?
|
72
|
-
|
73
|
-
def method_missing(accessor_name, *args, &block)
|
74
|
-
Isomorfeus.raise_error(message: "#{@class_name}: no such thing '#{accessor_name}' in the results!") unless @result_set.key?(accessor_name)
|
75
|
-
@result_set[accessor_name]
|
76
|
-
end
|
77
|
-
|
78
|
-
def to_transport
|
79
|
-
sids_hash = {}
|
80
|
-
@result_set.each do |key, value_or_array|
|
81
|
-
if value_or_array.class == Array
|
82
|
-
sids_hash[key.to_s] = value_or_array.map(&:sid)
|
83
|
-
sids_hash[:_is_array_] = true
|
84
|
-
else
|
85
|
-
sids_hash[key.to_s] = value_or_array.nil? ? nil : value_or_array.sid
|
86
|
-
end
|
87
|
-
end
|
88
|
-
{ @class_name => { @key => sids_hash }}
|
89
|
-
end
|
90
|
-
|
91
|
-
def included_items_to_transport
|
92
|
-
data_hash = {}
|
93
|
-
@result_set.each_value do |value|
|
94
|
-
if value.class == Array
|
95
|
-
value.each do |v|
|
96
|
-
data_hash.deep_merge!(v.to_transport)
|
97
|
-
if v.respond_to?(:included_items_to_transport)
|
98
|
-
data_hash.deep_merge!(v.included_items_to_transport)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
else
|
102
|
-
unless value.nil?
|
103
|
-
data_hash.deep_merge!(value.to_transport)
|
104
|
-
if value.respond_to?(:included_items_to_transport)
|
105
|
-
data_hash.deep_merge!(value.included_items_to_transport)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
data_hash
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
data/opal/iso_uri.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require "uri/common"
|
2
|
-
require "uri/generic"
|
3
|
-
|
4
|
-
module URI
|
5
|
-
@@schemes = {}
|
6
|
-
|
7
|
-
class InvalidURIError < Exception
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.parse(url)
|
11
|
-
# scheme://conn_data/path?query#hash
|
12
|
-
match = url.match(%r[(\w+)://([^/]+)([^\?]+)(\?[^\#]+)?(\#.*)?])
|
13
|
-
|
14
|
-
_, scheme, connection_data, path, query, fragment = match.to_a
|
15
|
-
|
16
|
-
connection_data = connection_data.split(/@/)
|
17
|
-
userinfo = connection_data.size > 1 ? connection_data.first : nil
|
18
|
-
host, port = connection_data.last.split(/:/)
|
19
|
-
|
20
|
-
port = port.to_i
|
21
|
-
query = query[1..-1] if query
|
22
|
-
|
23
|
-
registry = opaque = nil
|
24
|
-
|
25
|
-
Generic.new(scheme, userinfo, host, port,
|
26
|
-
registry, path, opaque, query,
|
27
|
-
fragment)
|
28
|
-
end
|
29
|
-
end
|
data/opal/uri/common.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
|
3
|
-
#
|
4
|
-
# Returns +uri+ converted to a URI object.
|
5
|
-
#
|
6
|
-
def URI(uri)
|
7
|
-
if uri.is_a?(URI::Generic)
|
8
|
-
uri
|
9
|
-
elsif uri = String.try_convert(uri)
|
10
|
-
URI.parse(uri)
|
11
|
-
else
|
12
|
-
raise ArgumentError,
|
13
|
-
"bad argument (expected URI object or URI string)"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
module_function :URI
|
17
|
-
end
|
18
|
-
|
data/opal/uri/generic.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
module URI
|
2
|
-
class Generic
|
3
|
-
attr_reader :scheme, :userinfo, :user, :password, :host, :port, :path,
|
4
|
-
:query, :fragment, :opaque, :registry
|
5
|
-
|
6
|
-
#
|
7
|
-
# An Array of the available components for URI::Generic
|
8
|
-
#
|
9
|
-
COMPONENT = [
|
10
|
-
:scheme,
|
11
|
-
:userinfo, :host, :port, :registry,
|
12
|
-
:path, :opaque,
|
13
|
-
:query,
|
14
|
-
:fragment
|
15
|
-
]
|
16
|
-
|
17
|
-
def initialize(scheme,
|
18
|
-
userinfo, host, port, registry,
|
19
|
-
path, opaque,
|
20
|
-
query,
|
21
|
-
fragment,
|
22
|
-
parser = nil,
|
23
|
-
arg_check = false)
|
24
|
-
@scheme = scheme
|
25
|
-
@userinfo = userinfo
|
26
|
-
@host = host
|
27
|
-
@port = port
|
28
|
-
@path = path
|
29
|
-
@query = query
|
30
|
-
@fragment = fragment
|
31
|
-
@user, @password = userinfo.split(/:/) if userinfo
|
32
|
-
end
|
33
|
-
|
34
|
-
def ==(other)
|
35
|
-
self.class == other.class &&
|
36
|
-
component_ary == other.component_ary
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def component_ary
|
42
|
-
self.class::COMPONENT.collect do |x|
|
43
|
-
self.send(x)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|