chronicle-core 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +1 -1
- data/.gitignore +3 -1
- data/.rubocop-plugin.yml +4 -0
- data/.rubocop.yml +16 -2
- data/Gemfile +2 -2
- data/Guardfile +3 -3
- data/LICENSE.txt +1 -1
- data/README.md +87 -2
- data/Rakefile +63 -1
- data/bin/console +6 -6
- data/chronicle-core.gemspec +32 -26
- data/lib/chronicle/core/version.rb +1 -3
- data/lib/chronicle/core.rb +1 -3
- data/lib/chronicle/models/base.rb +96 -0
- data/lib/chronicle/models/builder.rb +35 -0
- data/lib/chronicle/models/generation.rb +89 -0
- data/lib/chronicle/models/model_factory.rb +65 -0
- data/lib/chronicle/models.rb +17 -0
- data/lib/chronicle/schema/rdf_parsing/graph_transformer.rb +122 -0
- data/lib/chronicle/schema/rdf_parsing/rdf_serializer.rb +138 -0
- data/lib/chronicle/schema/rdf_parsing/schemaorg.rb +47 -0
- data/lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb +142 -0
- data/lib/chronicle/schema/rdf_parsing.rb +11 -0
- data/lib/chronicle/schema/schema_graph.rb +145 -0
- data/lib/chronicle/schema/schema_property.rb +81 -0
- data/lib/chronicle/schema/schema_type.rb +110 -0
- data/lib/chronicle/schema/types.rb +9 -0
- data/lib/chronicle/schema/validation/base_contract.rb +22 -0
- data/lib/chronicle/schema/validation/contract_factory.rb +133 -0
- data/lib/chronicle/schema/validation/edge_validator.rb +53 -0
- data/lib/chronicle/schema/validation/generation.rb +29 -0
- data/lib/chronicle/schema/validation/validator.rb +23 -0
- data/lib/chronicle/schema/validation.rb +41 -0
- data/lib/chronicle/schema.rb +9 -2
- data/lib/chronicle/serialization/hash_serializer.rb +5 -11
- data/lib/chronicle/serialization/jsonapi_serializer.rb +41 -26
- data/lib/chronicle/serialization/jsonld_serializer.rb +38 -0
- data/lib/chronicle/serialization/record.rb +90 -0
- data/lib/chronicle/serialization/serializer.rb +31 -18
- data/lib/chronicle/serialization.rb +6 -4
- data/lib/chronicle/utils/hash_utils.rb +19 -16
- data/schema/chronicle_schema_v1.json +1283 -0
- data/schema/chronicle_schema_v1.rb +183 -0
- data/schema/chronicle_schema_v1.ttl +720 -0
- metadata +107 -15
- data/lib/chronicle/schema/activity.rb +0 -5
- data/lib/chronicle/schema/base.rb +0 -79
- data/lib/chronicle/schema/entity.rb +0 -5
- data/lib/chronicle/schema/raw.rb +0 -9
- data/lib/chronicle/schema/validator.rb +0 -55
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronicle-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Louis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: dry-
|
14
|
+
name: dry-struct
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-validation
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: guard-rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +67,47 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.9'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: '13'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: '13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rdf-reasoner
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rdf-turtle
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.3'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: rspec
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +122,20 @@ dependencies:
|
|
80
122
|
- - "~>"
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '3.9'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.57'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.57'
|
83
139
|
- !ruby/object:Gem::Dependency
|
84
140
|
name: simplecov
|
85
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +150,20 @@ dependencies:
|
|
94
150
|
- - "~>"
|
95
151
|
- !ruby/object:Gem::Version
|
96
152
|
version: '0.21'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sparql
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.3'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.3'
|
97
167
|
description: Core libraries for Chronicle including models and schema definitions.
|
98
168
|
email:
|
99
169
|
- andrew@hyfen.net
|
@@ -104,6 +174,7 @@ files:
|
|
104
174
|
- ".github/workflows/rspec.yml"
|
105
175
|
- ".gitignore"
|
106
176
|
- ".rspec"
|
177
|
+
- ".rubocop-plugin.yml"
|
107
178
|
- ".rubocop.yml"
|
108
179
|
- CODE_OF_CONDUCT.md
|
109
180
|
- Gemfile
|
@@ -116,17 +187,37 @@ files:
|
|
116
187
|
- chronicle-core.gemspec
|
117
188
|
- lib/chronicle/core.rb
|
118
189
|
- lib/chronicle/core/version.rb
|
190
|
+
- lib/chronicle/models.rb
|
191
|
+
- lib/chronicle/models/base.rb
|
192
|
+
- lib/chronicle/models/builder.rb
|
193
|
+
- lib/chronicle/models/generation.rb
|
194
|
+
- lib/chronicle/models/model_factory.rb
|
119
195
|
- lib/chronicle/schema.rb
|
120
|
-
- lib/chronicle/schema/
|
121
|
-
- lib/chronicle/schema/
|
122
|
-
- lib/chronicle/schema/
|
123
|
-
- lib/chronicle/schema/
|
124
|
-
- lib/chronicle/schema/
|
196
|
+
- lib/chronicle/schema/rdf_parsing.rb
|
197
|
+
- lib/chronicle/schema/rdf_parsing/graph_transformer.rb
|
198
|
+
- lib/chronicle/schema/rdf_parsing/rdf_serializer.rb
|
199
|
+
- lib/chronicle/schema/rdf_parsing/schemaorg.rb
|
200
|
+
- lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb
|
201
|
+
- lib/chronicle/schema/schema_graph.rb
|
202
|
+
- lib/chronicle/schema/schema_property.rb
|
203
|
+
- lib/chronicle/schema/schema_type.rb
|
204
|
+
- lib/chronicle/schema/types.rb
|
205
|
+
- lib/chronicle/schema/validation.rb
|
206
|
+
- lib/chronicle/schema/validation/base_contract.rb
|
207
|
+
- lib/chronicle/schema/validation/contract_factory.rb
|
208
|
+
- lib/chronicle/schema/validation/edge_validator.rb
|
209
|
+
- lib/chronicle/schema/validation/generation.rb
|
210
|
+
- lib/chronicle/schema/validation/validator.rb
|
125
211
|
- lib/chronicle/serialization.rb
|
126
212
|
- lib/chronicle/serialization/hash_serializer.rb
|
127
213
|
- lib/chronicle/serialization/jsonapi_serializer.rb
|
214
|
+
- lib/chronicle/serialization/jsonld_serializer.rb
|
215
|
+
- lib/chronicle/serialization/record.rb
|
128
216
|
- lib/chronicle/serialization/serializer.rb
|
129
217
|
- lib/chronicle/utils/hash_utils.rb
|
218
|
+
- schema/chronicle_schema_v1.json
|
219
|
+
- schema/chronicle_schema_v1.rb
|
220
|
+
- schema/chronicle_schema_v1.ttl
|
130
221
|
- sig/chronicle/core.rbs
|
131
222
|
homepage: https://github.com/chronicle-app
|
132
223
|
licenses:
|
@@ -136,6 +227,7 @@ metadata:
|
|
136
227
|
homepage_uri: https://github.com/chronicle-app
|
137
228
|
source_code_uri: https://github.com/chronicle-app/chronicle-core
|
138
229
|
changelog_uri: https://github.com/chronicle-app/chronicle-core/releases
|
230
|
+
rubygems_mfa_required: 'true'
|
139
231
|
post_install_message:
|
140
232
|
rdoc_options: []
|
141
233
|
require_paths:
|
@@ -144,14 +236,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
236
|
requirements:
|
145
237
|
- - ">="
|
146
238
|
- !ruby/object:Gem::Version
|
147
|
-
version: '
|
239
|
+
version: '3.1'
|
148
240
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
241
|
requirements:
|
150
242
|
- - ">="
|
151
243
|
- !ruby/object:Gem::Version
|
152
244
|
version: '0'
|
153
245
|
requirements: []
|
154
|
-
rubygems_version: 3.
|
246
|
+
rubygems_version: 3.4.10
|
155
247
|
signing_key:
|
156
248
|
specification_version: 4
|
157
249
|
summary: Core libraries for Chronicle
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'chronicle/utils/hash_utils'
|
2
|
-
|
3
|
-
module Chronicle::Schema
|
4
|
-
class Base
|
5
|
-
attr_accessor(:id, :dedupe_on, :properties)
|
6
|
-
|
7
|
-
def initialize(attributes = {})
|
8
|
-
@properties = {}
|
9
|
-
@dedupe_on = []
|
10
|
-
assign_attributes(attributes) if attributes
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing(method, *args)
|
14
|
-
if method.to_s.end_with?("=")
|
15
|
-
@properties[method.to_s.gsub("=", "").to_sym] = args.first
|
16
|
-
else
|
17
|
-
@properties[method]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def assign_attributes(attributes)
|
22
|
-
@properties.merge!(attributes)
|
23
|
-
end
|
24
|
-
|
25
|
-
def identifier_hash
|
26
|
-
{
|
27
|
-
id: @id,
|
28
|
-
type: self.class::TYPE
|
29
|
-
}.compact
|
30
|
-
end
|
31
|
-
|
32
|
-
def attributes
|
33
|
-
@properties.reject { |k, v| associations.keys.include?(k) }.compact
|
34
|
-
end
|
35
|
-
|
36
|
-
def associations
|
37
|
-
@properties.select do |k, v|
|
38
|
-
if v.is_a?(Array)
|
39
|
-
v.any? { |e| e.is_a?(Chronicle::Schema::Base) }
|
40
|
-
else
|
41
|
-
v.is_a?(Chronicle::Schema::Base)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def meta
|
47
|
-
{
|
48
|
-
dedupe_on: @dedupe_on.map{|d| d.map(&:to_s).join(",")}
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_h
|
53
|
-
@properties.transform_values do |v|
|
54
|
-
# convert nested records to hashes
|
55
|
-
if v.is_a?(Array)
|
56
|
-
v.map do |e|
|
57
|
-
if e.is_a?(Chronicle::Schema::Base)
|
58
|
-
e.to_h
|
59
|
-
else
|
60
|
-
e
|
61
|
-
end
|
62
|
-
end
|
63
|
-
elsif v.is_a?(Chronicle::Schema::Base)
|
64
|
-
v.to_h
|
65
|
-
else
|
66
|
-
v
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def to_h_flattened
|
72
|
-
Chronicle::Utils::HashUtils.flatten_hash(to_h)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
require_relative "activity"
|
78
|
-
require_relative "entity"
|
79
|
-
require_relative "raw"
|
data/lib/chronicle/schema/raw.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'dry/schema' # TODO: Lazy load this
|
2
|
-
Dry::Schema.load_extensions(:hints)
|
3
|
-
Dry::Schema.load_extensions(:info)
|
4
|
-
|
5
|
-
require 'chronicle/serialization'
|
6
|
-
|
7
|
-
module Chronicle::Schema
|
8
|
-
class Validator
|
9
|
-
EntitySchema = Dry::Schema.Params do
|
10
|
-
required(:type).filled(:string, eql?: 'entities')
|
11
|
-
required(:attributes).type(:hash)
|
12
|
-
end
|
13
|
-
|
14
|
-
EntityIdentifiableSchema = Dry::Schema.Params do
|
15
|
-
required(:provider).filled(:string)
|
16
|
-
end
|
17
|
-
|
18
|
-
ActorEntitySchema = Dry::Schema.Params do
|
19
|
-
required(:represents).filled(:string, eql?: 'identity')
|
20
|
-
end
|
21
|
-
|
22
|
-
ActivitySchema = Dry::Schema.Params do
|
23
|
-
required(:type).filled(:string, eql?: 'activities')
|
24
|
-
required(:attributes).schema do
|
25
|
-
required(:verb).filled(:string)
|
26
|
-
optional(:start_at).maybe(:string) # Adjust type as needed
|
27
|
-
optional(:end_at).maybe(:string) # Adjust type as needed
|
28
|
-
end
|
29
|
-
required(:relationships).schema do
|
30
|
-
required(:actor).hash do
|
31
|
-
required(:data).hash(EntitySchema) do
|
32
|
-
required(:attributes).schema(EntityIdentifiableSchema & ActorEntitySchema)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.validate(record)
|
39
|
-
case record
|
40
|
-
when Entity
|
41
|
-
result = EntitySchema.call(Chronicle::Serialization::JSONAPISerializer.serialize(record))
|
42
|
-
when Activity
|
43
|
-
result = ActivitySchema.call(Chronicle::Serialization::JSONAPISerializer.serialize(record))
|
44
|
-
else
|
45
|
-
raise ArgumentError, "Unsupported type: #{record.class}"
|
46
|
-
end
|
47
|
-
|
48
|
-
if result.success?
|
49
|
-
{ success: true, data: result.to_h }
|
50
|
-
else
|
51
|
-
{ success: false, errors: result.errors.to_h, hints: result.hints.to_h }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|