jsi 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e18f4241f5f0013f657912295cb85db30095223a25030da3bbb690e68a5954d9
4
- data.tar.gz: '083cbd8436424eeab11c36aeabb42f27ad9072d44450a0b8bfca391503131f9e'
3
+ metadata.gz: daf35895a6186a3d3123b037f917912ff65ea03c876da9dd5cb40e2a9b079641
4
+ data.tar.gz: b14524e9eb8796385fdd2ec96bcbb5129c2e80ad9eabb39d60637b9c6078d1c8
5
5
  SHA512:
6
- metadata.gz: 1030a1013ae2209a7c6b1df083efe2466a670e1f644d64fd349475ba07331c182629c41a77d4d7220aaffcfb669f0c13bc5c49e6cb23a4f231747fbdc4b5ec7a
7
- data.tar.gz: d9f24dec46a507e9d2f40046e891acec2bbef92150e72dd29bb1245618bb6be0ea9beb140cc4f0a465f187bd65e6e52c68bf82d906f8df0edaff67f062dd4c15
6
+ metadata.gz: 005c27210c96f9b613f7f6959e86e17b41380c5366fe14f69cd047498fb5bfc8256b8404aa6c5f2ced04882b94edd1c9b62ff79c48001b7388b4b4faadf6c5b1
7
+ data.tar.gz: 9eccdec2038200c340df2365a3b179da83fd900deb8b4f8f21aa5e4430f785d80afa929e8d718e80850d463fd5d2cd0e0982f7b99352b9e4109cf7c781e07c74
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.8.1
2
+
3
+ - JSIs are immutable by default
4
+
1
5
  # v0.8.0
2
6
 
3
7
  - Immutable JSIs with new_jsi param `mutable`
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
- # this would usually load YAML or JSON; the schema instance is inlined for copypastability.
67
- bill = Contact.new_jsi({"name" => "bill", "phone" => [{"location" => "home", "number" => "555"}], "nickname" => "big b"})
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
@@ -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
- @subschema_map[subptr: Ptr.ary_ptr(subptr)]
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
- @resource_root_subschema_map[ptr: Ptr.ary_ptr(ptr)]
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
@@ -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: true
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSI
4
- VERSION = "0.8.0".freeze
4
+ VERSION = "0.8.1".freeze
5
5
  end
data/readme.rb CHANGED
@@ -59,7 +59,7 @@ bill = Contact.new_jsi({
59
59
  }
60
60
  ],
61
61
  "nickname" => "big b",
62
- })
62
+ }, mutable: true)
63
63
 
64
64
  print 'bill: '
65
65
  pp bill
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.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2024-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable