jsi 0.8.0 → 0.8.2
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/CHANGELOG.md +8 -0
- data/README.md +10 -2
- data/lib/jsi/schema.rb +10 -11
- data/lib/jsi/schema_set.rb +1 -1
- data/lib/jsi/version.rb +1 -1
- data/readme.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1afec35b87d23f2fba8a85b82c2064cce1c3e2121b312ecbb9a484df161647a0
|
4
|
+
data.tar.gz: 90a488102c7f238fc9f983ee2a702699d2bf09af583942698a682a7e2c577be1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66dd7b0af2007287d3d5ed34644f14ca8600671a8d09c3568345846f395426d37d250aa1b33c5e711d27591173b3ca5997186129dc248d8b0eaaab801c60a5da
|
7
|
+
data.tar.gz: 21df5cc4f501977db1d65b2a675f2e22c138b82658b069f35924ea1bdadf768a9d6a6aa7496d3f91b220c02fe25fc45626aed01decf380b5dd6db89663c9ab1d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -63,8 +63,12 @@ nickname: big b
|
|
63
63
|
So, if we construct an instance like:
|
64
64
|
|
65
65
|
```ruby
|
66
|
-
|
67
|
-
|
66
|
+
bill = Contact.new_jsi(
|
67
|
+
# this would typically load JSON or YAML; the schema instance is inlined for copypastability.
|
68
|
+
{"name" => "bill", "phone" => [{"location" => "home", "number" => "555"}], "nickname" => "big b"},
|
69
|
+
# note: bill is mutable to demonstrate setters below; the default is immutable.
|
70
|
+
mutable: true
|
71
|
+
)
|
68
72
|
# => #{<JSI (Contact)>
|
69
73
|
# "name" => "bill",
|
70
74
|
# "phone" => #[<JSI (Contact.properties["phone"])>
|
@@ -241,6 +245,10 @@ end
|
|
241
245
|
|
242
246
|
The classes used to instantiate JSIs are dynamically generated subclasses of JSI::Base which include the JSI Schema Module of each schema describing the given instance. These are mostly intended to be ignored: applications aren't expected to instantiate these directly (rather, `#new_jsi` on a Schema or Schema Module is intended), and they are not intended for subclassing or method definition (applications should instead define methods on a schema's {JSI::Schema#jsi_schema_module}).
|
243
247
|
|
248
|
+
## Mutability
|
249
|
+
|
250
|
+
JSI instances are immutable by default. Mutable JSIs may be instantiated using the `mutable` param of `new_jsi`. Immutable JSIs are much more performant, because mutation may change what schemas apply to nodes in a document, and checking for that is costly. It is not recommended to instantiate large documents as mutable; their JSI instances become unusably slow.
|
251
|
+
|
244
252
|
## Registration
|
245
253
|
|
246
254
|
In order for references across documents (generally from a `$ref` schema keyword) to resolve, JSI provides a registry (a {JSI::SchemaRegistry}) which associates URIs with schemas (or resources containing schemas). The default registry is accessible on {JSI.schema_registry}.
|
data/lib/jsi/schema.rb
CHANGED
@@ -155,6 +155,9 @@ module JSI
|
|
155
155
|
# By default, the `schema_content` will have any Symbol keys of Hashes replaced with Strings
|
156
156
|
# (recursively through the document). This is controlled by the param `stringify_symbol_keys`.
|
157
157
|
#
|
158
|
+
# Schemas instantiated with `new_schema` are immutable, their content transformed using
|
159
|
+
# the `to_immutable` param.
|
160
|
+
#
|
158
161
|
# @param schema_content an object to be instantiated as a JSI Schema - typically a Hash
|
159
162
|
# @param uri [#to_str, Addressable::URI] The retrieval URI of the schema document.
|
160
163
|
# If specified, the root schema will be identified by this URI, in addition
|
@@ -198,6 +201,7 @@ module JSI
|
|
198
201
|
schema_registry: schema_registry,
|
199
202
|
stringify_symbol_keys: stringify_symbol_keys,
|
200
203
|
to_immutable: to_immutable,
|
204
|
+
mutable: false,
|
201
205
|
)
|
202
206
|
|
203
207
|
schema_jsi.jsi_schema_module_exec(&block) if block
|
@@ -240,7 +244,7 @@ module JSI
|
|
240
244
|
#
|
241
245
|
# `nil` to unset.
|
242
246
|
def default_metaschema=(default_metaschema)
|
243
|
-
@default_metaschema = default_metaschema.nil? ? nil : ensure_metaschema(default_metaschema)
|
247
|
+
@default_metaschema = default_metaschema.nil? ? nil : Schema.ensure_metaschema(default_metaschema)
|
244
248
|
end
|
245
249
|
|
246
250
|
# Instantiates the given schema content as a JSI Schema.
|
@@ -281,6 +285,9 @@ module JSI
|
|
281
285
|
# {SchemaModule::MetaSchemaModule#new_schema schema module}, e.g.
|
282
286
|
# `JSI::JSONSchemaDraft07.new_schema(my_schema_content)`
|
283
287
|
#
|
288
|
+
# Schemas instantiated with `new_schema` are immutable, their content transformed using
|
289
|
+
# the `to_immutable` param.
|
290
|
+
#
|
284
291
|
# @param schema_content (see Schema::MetaSchema#new_schema)
|
285
292
|
# @param default_metaschema [Schema::MetaSchema, SchemaModule::MetaSchemaModule, #to_str]
|
286
293
|
# Indicates the meta-schema to use if the given `schema_content` does not have a `$schema` property.
|
@@ -626,10 +633,7 @@ module JSI
|
|
626
633
|
# @param subptr [JSI::Ptr, #to_ary] a relative pointer, or array of tokens, pointing to the subschema
|
627
634
|
# @return [JSI::Schema] the subschema at the location indicated by subptr. self if subptr is empty.
|
628
635
|
def subschema(subptr)
|
629
|
-
|
630
|
-
end
|
631
|
-
|
632
|
-
private def subschema_compute(subptr: )
|
636
|
+
subptr = Ptr.ary_ptr(subptr)
|
633
637
|
Schema.ensure_schema(jsi_descendent_node(subptr), msg: [
|
634
638
|
"subschema is not a schema at pointer: #{subptr.pointer}"
|
635
639
|
])
|
@@ -641,10 +645,7 @@ module JSI
|
|
641
645
|
# @param ptr [JSI::Ptr, #to_ary] a pointer to a schema from our schema resource root
|
642
646
|
# @return [JSI::Schema] the schema pointed to by ptr
|
643
647
|
def resource_root_subschema(ptr)
|
644
|
-
|
645
|
-
end
|
646
|
-
|
647
|
-
private def resource_root_subschema_compute(ptr: )
|
648
|
+
ptr = Ptr.ary_ptr(ptr)
|
648
649
|
Schema.ensure_schema(schema_resource_root.jsi_descendent_node(ptr),
|
649
650
|
reinstantiate_as: jsi_schemas.select(&:describes_schema?)
|
650
651
|
)
|
@@ -815,8 +816,6 @@ module JSI
|
|
815
816
|
Schema::Ref.new(value, ref_schema: self)
|
816
817
|
end
|
817
818
|
@schema_uris_map = jsi_memomap(&method(:schema_uris_compute))
|
818
|
-
@subschema_map = jsi_memomap(&method(:subschema_compute))
|
819
|
-
@resource_root_subschema_map = jsi_memomap(&method(:resource_root_subschema_compute))
|
820
819
|
@described_object_property_names_map = jsi_memomap(&method(:described_object_property_names_compute))
|
821
820
|
end
|
822
821
|
end
|
data/lib/jsi/schema_set.rb
CHANGED
@@ -101,7 +101,7 @@ module JSI
|
|
101
101
|
schema_registry: JSI.schema_registry,
|
102
102
|
stringify_symbol_keys: false,
|
103
103
|
to_immutable: DEFAULT_CONTENT_TO_IMMUTABLE,
|
104
|
-
mutable:
|
104
|
+
mutable: false
|
105
105
|
)
|
106
106
|
instance = Util.deep_stringify_symbol_keys(instance) if stringify_symbol_keys
|
107
107
|
|
data/lib/jsi/version.rb
CHANGED
data/readme.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
150
|
+
rubygems_version: 3.5.22
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: 'JSI: JSON Schema Instantiation'
|