json_p3 0.4.0 → 1.0.0

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.rubocop.yml +26 -7
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +58 -0
  6. data/README.md +125 -123
  7. data/Rakefile +3 -3
  8. data/certs/jgrp.pem +21 -21
  9. data/lib/json_p3/errors.rb +51 -43
  10. data/lib/json_p3/patch/op.rb +23 -0
  11. data/lib/json_p3/patch/op_add.rb +51 -0
  12. data/lib/json_p3/patch/op_copy.rb +64 -0
  13. data/lib/json_p3/patch/op_move.rb +74 -0
  14. data/lib/json_p3/patch/op_remove.rb +56 -0
  15. data/lib/json_p3/patch/op_replace.rb +54 -0
  16. data/lib/json_p3/patch/op_test.rb +31 -0
  17. data/lib/json_p3/patch.rb +15 -330
  18. data/lib/json_p3/path/environment.rb +113 -0
  19. data/lib/json_p3/path/filter.rb +463 -0
  20. data/lib/json_p3/path/function.rb +12 -0
  21. data/lib/json_p3/path/function_extensions/count.rb +15 -0
  22. data/lib/json_p3/path/function_extensions/length.rb +17 -0
  23. data/lib/json_p3/path/function_extensions/match.rb +62 -0
  24. data/lib/json_p3/path/function_extensions/pattern.rb +42 -0
  25. data/lib/json_p3/path/function_extensions/search.rb +44 -0
  26. data/lib/json_p3/path/function_extensions/value.rb +15 -0
  27. data/lib/json_p3/path/lexer.rb +220 -0
  28. data/lib/json_p3/path/node.rb +48 -0
  29. data/lib/json_p3/path/parser.rb +676 -0
  30. data/lib/json_p3/path/query.rb +74 -0
  31. data/lib/json_p3/path/segment.rb +172 -0
  32. data/lib/json_p3/path/selector.rb +304 -0
  33. data/lib/json_p3/path/serialize.rb +16 -0
  34. data/lib/json_p3/path/unescape.rb +134 -0
  35. data/lib/json_p3/pointer.rb +15 -76
  36. data/lib/json_p3/relative_pointer.rb +69 -0
  37. data/lib/json_p3/version.rb +1 -1
  38. data/lib/json_p3.rb +50 -13
  39. data/sig/json_p3/cache.rbs +21 -0
  40. data/sig/json_p3/errors.rbs +55 -0
  41. data/sig/json_p3/patch.rbs +145 -0
  42. data/sig/json_p3/path/environment.rbs +81 -0
  43. data/sig/json_p3/path/filter.rbs +196 -0
  44. data/sig/json_p3/path/function.rbs +94 -0
  45. data/sig/json_p3/path/lexer.rbs +62 -0
  46. data/sig/json_p3/path/node.rbs +46 -0
  47. data/sig/json_p3/path/parser.rbs +92 -0
  48. data/sig/json_p3/path/query.rbs +47 -0
  49. data/sig/json_p3/path/segment.rbs +54 -0
  50. data/sig/json_p3/path/selector.rbs +100 -0
  51. data/sig/json_p3/path/serialize.rbs +9 -0
  52. data/sig/json_p3/path/unescape.rbs +12 -0
  53. data/sig/json_p3/pointer.rbs +64 -0
  54. data/sig/json_p3/relative_pointer.rbs +30 -0
  55. data/sig/json_p3.rbs +24 -1313
  56. data.tar.gz.sig +0 -0
  57. metadata +66 -46
  58. metadata.gz.sig +0 -0
  59. data/lib/json_p3/environment.rb +0 -111
  60. data/lib/json_p3/filter.rb +0 -459
  61. data/lib/json_p3/function.rb +0 -10
  62. data/lib/json_p3/function_extensions/count.rb +0 -15
  63. data/lib/json_p3/function_extensions/length.rb +0 -17
  64. data/lib/json_p3/function_extensions/match.rb +0 -62
  65. data/lib/json_p3/function_extensions/pattern.rb +0 -39
  66. data/lib/json_p3/function_extensions/search.rb +0 -44
  67. data/lib/json_p3/function_extensions/value.rb +0 -15
  68. data/lib/json_p3/lexer.rb +0 -419
  69. data/lib/json_p3/node.rb +0 -44
  70. data/lib/json_p3/parser.rb +0 -553
  71. data/lib/json_p3/path.rb +0 -72
  72. data/lib/json_p3/segment.rb +0 -158
  73. data/lib/json_p3/selector.rb +0 -306
  74. data/lib/json_p3/serialize.rb +0 -13
  75. data/lib/json_p3/token.rb +0 -36
  76. data/lib/json_p3/unescape.rb +0 -112
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,42 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_p3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Prior
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
12
11
  -----BEGIN CERTIFICATE-----
13
12
  MIIEhTCCAu2gAwIBAgIBATANBgkqhkiG9w0BAQsFADBEMRYwFAYDVQQDDA1qYW1l
14
13
  c2dyLnByaW9yMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
15
- FgNjb20wHhcNMjQxMDI0MDcxNDAzWhcNMjUxMDI0MDcxNDAzWjBEMRYwFAYDVQQD
14
+ FgNjb20wHhcNMjUxMDI1MDc0ODI4WhcNMjYxMDI1MDc0ODI4WjBEMRYwFAYDVQQD
16
15
  DA1qYW1lc2dyLnByaW9yMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
17
- k/IsZAEZFgNjb20wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDvtEeN
18
- ZNN153v2ZK+U+Tj7kfRgl52GzmZS7lIG83xvT5/K8xEG5G4Tqiq/aGuDdbnxtd/t
19
- TQf6CtkixPzwj7WGIwoV28AUHKOJ7UjqRhXIuAn3nmzRLRNK2gVYpvzLTNCyLhIb
20
- jyZqgvtjR9mmW/Uuq+9LcLN4iFfkW+4dSmcABnkZHWMWGZYMIwoYYpluEUS1KiRZ
21
- mIALPEGO5JcpVvjpDwaP6GqV0khgnLixz9KlAF+2DCyki21wxtJoxJTuL9H5Ogb+
22
- k+nDQd9ELFYfbn73UKYGPtoUxkQeNF/ajJAkb/8t0cwUeSgtpSPhWIITWBgdLq11
23
- svViBlK9UZZC+dWG9x1lueVTG9fXBl69NJ9VA7MaxmHVY133sEySqwZMCrtDYjPX
24
- wIzLI2U8iSDIsjxTq3F3pbxeD4ee85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rPscB/ODPTBK8i+u4gwrD1UAsVAHuIbOpQu4LYAujluCu5cl2A8
36
+ HhmlCT7sTkqG
38
37
  -----END CERTIFICATE-----
39
- date: 2025-02-10 00:00:00.000000000 Z
38
+ date: 1980-01-02 00:00:00.000000000 Z
40
39
  dependencies: []
41
40
  description: JSONPath following RFC 9535
42
41
  email:
@@ -56,27 +55,34 @@ files:
56
55
  - certs/jgrp.pem
57
56
  - lib/json_p3.rb
58
57
  - lib/json_p3/cache.rb
59
- - lib/json_p3/environment.rb
60
58
  - lib/json_p3/errors.rb
61
- - lib/json_p3/filter.rb
62
- - lib/json_p3/function.rb
63
- - lib/json_p3/function_extensions/count.rb
64
- - lib/json_p3/function_extensions/length.rb
65
- - lib/json_p3/function_extensions/match.rb
66
- - lib/json_p3/function_extensions/pattern.rb
67
- - lib/json_p3/function_extensions/search.rb
68
- - lib/json_p3/function_extensions/value.rb
69
- - lib/json_p3/lexer.rb
70
- - lib/json_p3/node.rb
71
- - lib/json_p3/parser.rb
72
59
  - lib/json_p3/patch.rb
73
- - lib/json_p3/path.rb
60
+ - lib/json_p3/patch/op.rb
61
+ - lib/json_p3/patch/op_add.rb
62
+ - lib/json_p3/patch/op_copy.rb
63
+ - lib/json_p3/patch/op_move.rb
64
+ - lib/json_p3/patch/op_remove.rb
65
+ - lib/json_p3/patch/op_replace.rb
66
+ - lib/json_p3/patch/op_test.rb
67
+ - lib/json_p3/path/environment.rb
68
+ - lib/json_p3/path/filter.rb
69
+ - lib/json_p3/path/function.rb
70
+ - lib/json_p3/path/function_extensions/count.rb
71
+ - lib/json_p3/path/function_extensions/length.rb
72
+ - lib/json_p3/path/function_extensions/match.rb
73
+ - lib/json_p3/path/function_extensions/pattern.rb
74
+ - lib/json_p3/path/function_extensions/search.rb
75
+ - lib/json_p3/path/function_extensions/value.rb
76
+ - lib/json_p3/path/lexer.rb
77
+ - lib/json_p3/path/node.rb
78
+ - lib/json_p3/path/parser.rb
79
+ - lib/json_p3/path/query.rb
80
+ - lib/json_p3/path/segment.rb
81
+ - lib/json_p3/path/selector.rb
82
+ - lib/json_p3/path/serialize.rb
83
+ - lib/json_p3/path/unescape.rb
74
84
  - lib/json_p3/pointer.rb
75
- - lib/json_p3/segment.rb
76
- - lib/json_p3/selector.rb
77
- - lib/json_p3/serialize.rb
78
- - lib/json_p3/token.rb
79
- - lib/json_p3/unescape.rb
85
+ - lib/json_p3/relative_pointer.rb
80
86
  - lib/json_p3/version.rb
81
87
  - performance/benchmark.rb
82
88
  - performance/benchmark_ips.rb
@@ -85,6 +91,22 @@ files:
85
91
  - performance/memory_profile_small_citylots.rb
86
92
  - performance/profile.rb
87
93
  - sig/json_p3.rbs
94
+ - sig/json_p3/cache.rbs
95
+ - sig/json_p3/errors.rbs
96
+ - sig/json_p3/patch.rbs
97
+ - sig/json_p3/path/environment.rbs
98
+ - sig/json_p3/path/filter.rbs
99
+ - sig/json_p3/path/function.rbs
100
+ - sig/json_p3/path/lexer.rbs
101
+ - sig/json_p3/path/node.rbs
102
+ - sig/json_p3/path/parser.rbs
103
+ - sig/json_p3/path/query.rbs
104
+ - sig/json_p3/path/segment.rbs
105
+ - sig/json_p3/path/selector.rbs
106
+ - sig/json_p3/path/serialize.rbs
107
+ - sig/json_p3/path/unescape.rbs
108
+ - sig/json_p3/pointer.rbs
109
+ - sig/json_p3/relative_pointer.rbs
88
110
  homepage: https://github.com/jg-rp/ruby-json-p3
89
111
  licenses:
90
112
  - MIT
@@ -93,7 +115,6 @@ metadata:
93
115
  source_code_uri: https://github.com/jg-rp/ruby-json-p3
94
116
  changelog_uri: https://github.com/jg-rp/ruby-json-p3/blob/main/CHANGELOG.md
95
117
  rubygems_mfa_required: 'true'
96
- post_install_message:
97
118
  rdoc_options: []
98
119
  require_paths:
99
120
  - lib
@@ -101,15 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
122
  requirements:
102
123
  - - ">="
103
124
  - !ruby/object:Gem::Version
104
- version: 3.0.0
125
+ version: 3.3.0
105
126
  required_rubygems_version: !ruby/object:Gem::Requirement
106
127
  requirements:
107
128
  - - ">="
108
129
  - !ruby/object:Gem::Version
109
130
  version: '0'
110
131
  requirements: []
111
- rubygems_version: 3.5.22
112
- signing_key:
132
+ rubygems_version: 4.0.6
113
133
  specification_version: 4
114
134
  summary: 'JSONPath: Query Expressions for JSON in Ruby'
115
135
  test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lexer"
4
- require_relative "parser"
5
- require_relative "path"
6
- require_relative "function_extensions/length"
7
- require_relative "function_extensions/value"
8
- require_relative "function_extensions/count"
9
- require_relative "function_extensions/match"
10
- require_relative "function_extensions/search"
11
-
12
- module JSONP3
13
- # JSONPath configuration
14
- #
15
- # Configure an environment by inheriting from `JSONPathEnvironment` and setting one
16
- # or more constants and/or overriding {setup_function_extensions}.
17
- class JSONPathEnvironment
18
- # The maximum integer allowed when selecting array items by index.
19
- MAX_INT_INDEX = (2**53) - 1
20
-
21
- # The minimum integer allowed when selecting array items by index.
22
- MIN_INT_INDEX = -(2**53) + 1
23
-
24
- # The maximum number of arrays and hashes the recursive descent segment will
25
- # traverse before raising a {JSONPathRecursionError}.
26
- MAX_RECURSION_DEPTH = 100
27
-
28
- # One of the available implementations of the _name selector_.
29
- #
30
- # - {NameSelector} (the default) will select values from hashes using string keys.
31
- # - {SymbolNameSelector} will select values from hashes using string or symbol keys.
32
- #
33
- # Implement your own name selector by inheriting from {NameSelector} and overriding
34
- # `#resolve`.
35
- NAME_SELECTOR = NameSelector
36
-
37
- # An implementation of the _index selector_. The default implementation will
38
- # select values from arrays only. Implement your own by inheriting from
39
- # {IndexSelector} and overriding `#resolve`.
40
- INDEX_SELECTOR = IndexSelector
41
-
42
- attr_accessor :function_extensions
43
-
44
- def initialize
45
- @parser = Parser.new(self)
46
- @function_extensions = {}
47
- setup_function_extensions
48
- end
49
-
50
- # Prepare JSONPath expression _query_ for repeated application.
51
- # @param query [String]
52
- # @return [JSONPath]
53
- def compile(query)
54
- tokens = JSONP3.tokenize(query)
55
- JSONPath.new(self, @parser.parse(tokens))
56
- end
57
-
58
- # Apply JSONPath expression _query_ to _value_.
59
- # @param query [String] the JSONPath expression
60
- # @param value [JSON-like data] the target JSON "document"
61
- # @return [Array<JSONPath>]
62
- def find(query, value)
63
- compile(query).find(value)
64
- end
65
-
66
- # Apply JSONPath expression _query_ to _value_.
67
- # @param query [String] the JSONPath expression
68
- # @param value [JSON-like data] the target JSON "document"
69
- # @return [Enumerable<JSONPath>]
70
- def find_enum(query, value)
71
- compile(query).find_enum(value)
72
- end
73
-
74
- # Apply JSONPath expression _query_ to _value_ an return the first
75
- # available node.
76
- # @param query [String] the JSONPath expression
77
- # @param value [JSON-like data] the target JSON "document"
78
- # @return [JSONPathNode | nil]
79
- def match(path, value)
80
- find_enum(path, value).first
81
- end
82
-
83
- # Apply JSONPath expression _query_ to _value_ an return `true` if there's at
84
- # least one node, or nil if there were no matches.
85
- # @param query [String] the JSONPath expression
86
- # @param value [JSON-like data] the target JSON "document"
87
- # @return [bool]
88
- def match?(path, value)
89
- !find_enum(path, value).first.nil?
90
- end
91
-
92
- # Apply JSONPath expression _query_ to _value_ an return the first
93
- # available node, or nil if there were no matches.
94
- # @param query [String] the JSONPath expression
95
- # @param value [JSON-like data] the target JSON "document"
96
- # @return [JSONPathNode | nil]
97
- def first(path, value)
98
- find_enum(path, value).first
99
- end
100
-
101
- # Override this function to configure JSONPath function extensions.
102
- # By default, only the standard functions described in RFC 9535 are enabled.
103
- def setup_function_extensions
104
- @function_extensions["length"] = Length.new
105
- @function_extensions["count"] = Count.new
106
- @function_extensions["value"] = Value.new
107
- @function_extensions["match"] = Match.new
108
- @function_extensions["search"] = Search.new
109
- end
110
- end
111
- end