chronicle-core 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +1 -1
  3. data/.gitignore +3 -1
  4. data/.rubocop-plugin.yml +4 -0
  5. data/.rubocop.yml +16 -2
  6. data/Gemfile +2 -2
  7. data/Guardfile +3 -3
  8. data/LICENSE.txt +1 -1
  9. data/README.md +87 -2
  10. data/Rakefile +63 -1
  11. data/bin/console +6 -6
  12. data/chronicle-core.gemspec +32 -26
  13. data/lib/chronicle/core/version.rb +1 -3
  14. data/lib/chronicle/core.rb +1 -3
  15. data/lib/chronicle/models/base.rb +96 -0
  16. data/lib/chronicle/models/builder.rb +35 -0
  17. data/lib/chronicle/models/generation.rb +89 -0
  18. data/lib/chronicle/models/model_factory.rb +63 -0
  19. data/lib/chronicle/models.rb +17 -0
  20. data/lib/chronicle/schema/rdf_parsing/graph_transformer.rb +122 -0
  21. data/lib/chronicle/schema/rdf_parsing/rdf_serializer.rb +138 -0
  22. data/lib/chronicle/schema/rdf_parsing/schemaorg.rb +50 -0
  23. data/lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb +142 -0
  24. data/lib/chronicle/schema/rdf_parsing.rb +11 -0
  25. data/lib/chronicle/schema/schema_graph.rb +145 -0
  26. data/lib/chronicle/schema/schema_property.rb +81 -0
  27. data/lib/chronicle/schema/schema_type.rb +110 -0
  28. data/lib/chronicle/schema/types.rb +9 -0
  29. data/lib/chronicle/schema/validation/base_contract.rb +22 -0
  30. data/lib/chronicle/schema/validation/contract_factory.rb +133 -0
  31. data/lib/chronicle/schema/validation/edge_validator.rb +53 -0
  32. data/lib/chronicle/schema/validation/generation.rb +29 -0
  33. data/lib/chronicle/schema/validation/validator.rb +23 -0
  34. data/lib/chronicle/schema/validation.rb +41 -0
  35. data/lib/chronicle/schema.rb +9 -2
  36. data/lib/chronicle/serialization/hash_serializer.rb +5 -11
  37. data/lib/chronicle/serialization/jsonapi_serializer.rb +41 -26
  38. data/lib/chronicle/serialization/jsonld_serializer.rb +38 -0
  39. data/lib/chronicle/serialization/record.rb +90 -0
  40. data/lib/chronicle/serialization/serializer.rb +31 -18
  41. data/lib/chronicle/serialization.rb +6 -4
  42. data/lib/chronicle/utils/hash_utils.rb +26 -0
  43. data/schema/chronicle_schema_v1.json +1008 -0
  44. data/schema/chronicle_schema_v1.rb +147 -0
  45. data/schema/chronicle_schema_v1.ttl +562 -0
  46. metadata +108 -16
  47. data/lib/chronicle/schema/activity.rb +0 -5
  48. data/lib/chronicle/schema/base.rb +0 -64
  49. data/lib/chronicle/schema/entity.rb +0 -5
  50. data/lib/chronicle/schema/raw.rb +0 -9
  51. data/lib/chronicle/schema/validator.rb +0 -55
  52. data/lib/chronicle/utils/hash.rb +0 -15
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Louis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-11 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: dry-schema
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.13'
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.13'
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: rubocop
70
+ name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 1.25.1
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: 1.25.1
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/activity.rb
121
- - lib/chronicle/schema/base.rb
122
- - lib/chronicle/schema/entity.rb
123
- - lib/chronicle/schema/raw.rb
124
- - lib/chronicle/schema/validator.rb
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
- - lib/chronicle/utils/hash.rb
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: '2.7'
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.3.3
246
+ rubygems_version: 3.4.10
155
247
  signing_key:
156
248
  specification_version: 4
157
249
  summary: Core libraries for Chronicle
@@ -1,5 +0,0 @@
1
- module Chronicle::Schema
2
- class Activity < Chronicle::Schema::Base
3
- TYPE = 'activities'.freeze
4
- end
5
- end
@@ -1,64 +0,0 @@
1
- require 'chronicle/utils/hash'
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
54
- end
55
-
56
- def to_h_flattened
57
- Chronicle::Utils::Hash.flatten_keys(to_h)
58
- end
59
- end
60
- end
61
-
62
- require_relative "activity"
63
- require_relative "entity"
64
- require_relative "raw"
@@ -1,5 +0,0 @@
1
- module Chronicle::Schema
2
- class Entity < Chronicle::Schema::Base
3
- TYPE = 'entities'.freeze
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- module Chronicle::Schema
2
- class Raw < Chronicle::Schema::Base
3
- TYPE = 'raw'.freeze
4
-
5
- def to_h
6
- @properties
7
- end
8
- end
9
- end
@@ -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
@@ -1,15 +0,0 @@
1
- module Chronicle::Utils
2
- module Hash
3
- def self.flatten_keys(hash)
4
- hash.each_with_object({}) do |(k, v), h|
5
- if v.is_a? Hash
6
- flatten_hash(v).map do |h_k, h_v|
7
- h["#{k}.#{h_k}".to_sym] = h_v
8
- end
9
- else
10
- h[k] = v
11
- end
12
- end
13
- end
14
- end
15
- end