json_p3 0.4.1 → 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 -9
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +54 -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 -1318
  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 -440
  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/sig/json_p3.rbs CHANGED
@@ -1,1330 +1,36 @@
1
1
  # JSONPath, JSON Patch and JSON Pointer for Ruby
2
2
  module JSONP3
3
- DefaultEnvironment: JSONPathEnvironment
3
+ VERSION: String
4
+
5
+ module Path
6
+ DefaultEnvironment: JSONP3::Path::Environment
7
+
8
+ def self.find: (String path, untyped data) -> JSONP3::Path::NodeList
9
+
10
+ def self.find_enum: (String path, untyped data) -> Enumerable[JSONP3::Path::Node]
11
+
12
+ def self.compile: (String path) -> JSONP3::Path::Query
13
+
14
+ def self.match: (String path, untyped data) -> (JSONP3::Path::Node | nil)
15
+
16
+ def self.first: (String path, untyped data) -> (JSONP3::Path::Node | nil)
17
+
18
+ def self.match?: (String path, untyped data) -> bool
19
+ end
4
20
 
5
- def self.find: (String path, untyped data) -> JSONPathNodeList
6
-
7
- def self.find_enum: (String path, untyped data) -> Enumerable[JSONPathNode]
21
+ def self.find: (String path, untyped data) -> JSONP3::Path::NodeList
22
+
23
+ def self.find_enum: (String path, untyped data) -> Enumerable[JSONP3::Path::Node]
8
24
 
9
- def self.compile: (String path) -> JSONPath
25
+ def self.compile: (String path) -> JSONP3::Path::Query
10
26
 
11
- def self.match: (String path, untyped data) -> (JSONPathNode | nil)
27
+ def self.match: (String path, untyped data) -> (JSONP3::Path::Node | nil)
12
28
 
13
- def self.first: (String path, untyped data) -> (JSONPathNode | nil)
29
+ def self.first: (String path, untyped data) -> (JSONP3::Path::Node | nil)
14
30
 
15
31
  def self.match?: (String path, untyped data) -> bool
16
32
 
17
33
  def self.resolve: (String pointer, untyped value, ?default: untyped) -> untyped
18
34
 
19
- def self.apply: (Array[Op | Hash[String, untyped]] ops, untyped value) -> untyped
20
- end
21
-
22
- module JSONP3
23
- # A least recently used cache relying on Ruby hash insertion order.
24
- class LRUCache
25
- @data: Hash[untyped, untyped]
26
-
27
- @max_size: Integer
28
-
29
- attr_reader max_size: Integer
30
-
31
- def initialize: (Integer max_size) -> void
32
-
33
- # Return the cached value or nil if _key_ does not exist.
34
- def []: (untyped key) -> (nil | untyped)
35
-
36
- def []=: (untyped key, untyped value) -> untyped
37
-
38
- def length: () -> Integer
39
-
40
- def keys: () -> Array[untyped]
41
- end
42
- end
43
-
44
- module JSONP3
45
- # JSONPath configuration
46
- class JSONPathEnvironment
47
- MAX_INT_INDEX: Numeric
48
-
49
- MIN_INT_INDEX: Numeric
50
-
51
- MAX_RECURSION_DEPTH: Integer
52
-
53
- # XXX: I don't known how to specify a class rather than a class instance.
54
- NAME_SELECTOR: untyped
55
-
56
- INDEX_SELECTOR: untyped
57
-
58
- @parser: Parser
59
-
60
- @function_extensions: Hash[String, FunctionExtension]
61
-
62
- attr_accessor function_extensions: Hash[String, FunctionExtension]
63
-
64
- def initialize: () -> void
65
-
66
- # Prepare JSONPath expression _query_ for repeated application.
67
- # @param query [String]
68
- # @return [JSONPath]
69
- def compile: (String query) -> JSONPath
70
-
71
- # Apply JSONPath expression _query_ to _value_.
72
- # @param query [String]
73
- # @param value [JSON-like data]
74
- # @return [Array<JSONPath>]
75
- def find: (String query, untyped value) -> JSONPathNodeList
76
-
77
- def find_enum: (String query, untyped value) -> Enumerable[JSONPathNode]
78
-
79
- def match: (String query, untyped value) -> (JSONPathNode | nil)
80
-
81
- def match?: (String query, untyped value) -> bool
82
-
83
- def first: (String query, untyped value) -> (JSONPathNode | nil)
84
-
85
- def setup_function_extensions: () -> void
86
- end
87
- end
88
-
89
- module JSONP3
90
- # An exception raised when a JSONPathEnvironment is misconfigured.
91
- class JSONPathEnvironmentError < StandardError
92
- end
93
-
94
- # Base class for JSONPath exceptions that happen when parsing or evaluating a query.
95
- class JSONPathError < StandardError
96
- FULL_MESSAGE: bool
97
-
98
- @token: Token
99
-
100
- def initialize: (String msg, Token token) -> void
101
- end
102
-
103
- class JSONPathSyntaxError < JSONPathError
104
- end
105
-
106
- class JSONPathTypeError < JSONPathError
107
- end
108
-
109
- class JSONPathNameError < JSONPathError
110
- end
111
-
112
- class JSONPathRecursionError < JSONPathError
113
- end
114
-
115
- class JSONPointerError < StandardError
116
- end
117
-
118
- class JSONPointerIndexError < JSONPointerError
119
- end
120
-
121
- class JSONPointerSyntaxError < JSONPointerError
122
- end
123
-
124
- class JSONPointerTypeError < JSONPointerError
125
- end
126
-
127
- class JSONPatchError < StandardError
128
- end
129
-
130
- class JSONPatchTestFailure < JSONPatchError
131
- end
132
-
133
- end
134
-
135
- module JSONP3
136
- # Base class for all filter expression nodes.
137
- class Expression
138
- @token: Token
139
-
140
- # @dynamic token
141
- attr_reader token: Token
142
-
143
- def initialize: (Token token) -> void
144
-
145
- # Evaluate the filter expression in the given context.
146
- def evaluate: (FilterContext _context) -> untyped
147
- end
148
-
149
- # An expression that evaluates to true or false.
150
- class FilterExpression < Expression
151
- @expression: Expression
152
-
153
- attr_reader expression: Expression
154
-
155
- def initialize: (Token token, Expression expression) -> void
156
-
157
- def evaluate: (FilterContext context) -> untyped
158
-
159
- def to_s: () -> String
160
-
161
- def ==: (untyped other) -> bool
162
-
163
- alias eql? ==
164
-
165
- def hash: () -> Integer
166
-
167
- private
168
-
169
- class Precedence
170
- LOWEST: 1
171
-
172
- LOGICAL_OR: 3
173
-
174
- LOGICAL_AND: 4
175
-
176
- PREFIX: 7
177
- end
178
-
179
- def to_canonical_string: (Expression expression, Integer parent_precedence) -> String
180
- end
181
-
182
- # Base class for expression literals.
183
- class FilterExpressionLiteral < Expression
184
- @value: untyped
185
-
186
- attr_reader value: untyped
187
-
188
- def initialize: (Token token, untyped value) -> void
189
-
190
- def evaluate: (FilterContext _context) -> untyped
191
-
192
- def to_s: () -> String
193
-
194
- def ==: (untyped other) -> bool
195
-
196
- alias eql? ==
197
-
198
- def hash: () -> Integer
199
- end
200
-
201
- # Literal true or false.
202
- class BooleanLiteral < FilterExpressionLiteral
203
- end
204
-
205
- # A double or single quoted string literal.
206
- class StringLiteral < FilterExpressionLiteral
207
- def to_s: () -> String
208
- end
209
-
210
- # A literal integer.
211
- class IntegerLiteral < FilterExpressionLiteral
212
- end
213
-
214
- # A literal float
215
- class FloatLiteral < FilterExpressionLiteral
216
- end
217
-
218
- # A literal null
219
- class NullLiteral < FilterExpressionLiteral
220
- def to_s: () -> "null"
221
- end
222
-
223
- # An expression prefixed with the logical not operator.
224
- class LogicalNotExpression < Expression
225
- @expression: Expression
226
-
227
- attr_reader expression: Expression
228
-
229
- def initialize: (Token token, Expression expression) -> void
230
-
231
- def evaluate: (FilterContext context) -> untyped
232
-
233
- def to_s: () -> ::String
234
-
235
- def ==: (untyped other) -> bool
236
-
237
- alias eql? ==
238
-
239
- def hash: () -> Integer
240
- end
241
-
242
- # Base class for expression with a left expression, operator and right expression.
243
- class InfixExpression < Expression
244
- @left: Expression
245
-
246
- @right: Expression
247
-
248
- attr_reader left: Expression
249
-
250
- attr_reader right: Expression
251
-
252
- def initialize: (Token token, Expression left, Expression right) -> void
253
-
254
- def evaluate: (FilterContext _context) -> untyped
255
-
256
- def to_s: () -> String
257
-
258
- def ==: (untyped other) -> bool
259
-
260
- alias eql? ==
261
-
262
- def hash: () -> Integer
263
- end
264
-
265
- # A logical `&&` expression.
266
- class LogicalAndExpression < InfixExpression
267
- def evaluate: (FilterContext context) -> untyped
268
-
269
- def to_s: () -> ::String
270
- end
271
-
272
- # A logical `||` expression.
273
- class LogicalOrExpression < InfixExpression
274
- def evaluate: (FilterContext context) -> untyped
275
-
276
- def to_s: () -> ::String
277
- end
278
-
279
- # An `==` expression.
280
- class EqExpression < InfixExpression
281
- def evaluate: (FilterContext context) -> untyped
282
-
283
- def to_s: () -> ::String
284
- end
285
-
286
- # A `!=` expression.
287
- class NeExpression < InfixExpression
288
- def evaluate: (FilterContext context) -> untyped
289
-
290
- def to_s: () -> ::String
291
- end
292
-
293
- # A `<=` expression.
294
- class LeExpression < InfixExpression
295
- def evaluate: (FilterContext context) -> untyped
296
-
297
- def to_s: () -> ::String
298
- end
299
-
300
- # A `>=` expression.
301
- class GeExpression < InfixExpression
302
- def evaluate: (FilterContext context) -> untyped
303
-
304
- def to_s: () -> ::String
305
- end
306
-
307
- # A `<` expression.
308
- class LtExpression < InfixExpression
309
- def evaluate: (FilterContext context) -> untyped
310
-
311
- def to_s: () -> ::String
312
- end
313
-
314
- # A `>` expression.
315
- class GtExpression < InfixExpression
316
- def evaluate: (FilterContext context) -> untyped
317
-
318
- def to_s: () -> ::String
319
- end
320
-
321
- # Base class for all embedded filter queries
322
- class QueryExpression < Expression
323
- @query: JSONPath
324
-
325
- attr_reader query: JSONPath
326
-
327
- def initialize: (Token token, JSONPath query) -> void
328
-
329
- def evaluate: (FilterContext _context) -> untyped
330
-
331
- def to_s: () -> String
332
-
333
- def ==: (untyped other) -> bool
334
-
335
- alias eql? ==
336
-
337
- def hash: () -> Integer
338
- end
339
-
340
- # An embedded query starting at the current node.
341
- class RelativeQueryExpression < QueryExpression
342
- def evaluate: (FilterContext context) -> untyped
343
-
344
- def to_s: () -> ::String
345
- end
346
-
347
- # An embedded query starting at the root node.
348
- class RootQueryExpression < QueryExpression
349
- def evaluate: (FilterContext context) -> untyped
350
-
351
- def to_s: () -> String
352
- end
353
-
354
- # A filter function call.
355
- class FunctionExpression < Expression
356
- @name: String
357
-
358
- @args: Array[Expression]
359
-
360
- attr_reader name: String
361
-
362
- attr_reader args: Array[Expression]
363
-
364
- # @param name [String]
365
- # @param args [Array<Expression>]
366
- def initialize: (Token token, String name, Array[Expression] args) -> void
367
-
368
- def evaluate: (FilterContext context) -> untyped
369
-
370
- def to_s: () -> ::String
371
-
372
- def ==: (untyped other) -> bool
373
-
374
- alias eql? ==
375
-
376
- def hash: () -> Integer
377
-
378
- private
379
-
380
- def unpack_node_lists: (FunctionExtension func, Array[untyped] args) -> Array[untyped]
381
- end
382
-
383
- def self.truthy?: (untyped obj) -> bool
384
-
385
- def self.eq?: (Expression left, Expression right) -> bool
386
-
387
- def self.lt?: (Expression left, Expression right) -> bool
388
-
389
- # Contextual information and data used for evaluating a filter expression.
390
- class FilterContext
391
- @env: JSONPathEnvironment
392
-
393
- @current: untyped
394
-
395
- @root: untyped
396
-
397
- attr_reader env: JSONPathEnvironment
398
-
399
- attr_reader current: untyped
400
-
401
- attr_reader root: untyped
402
-
403
- def initialize: (JSONPathEnvironment env, untyped current, untyped root) -> void
404
- end
405
- end
406
-
407
- type expression_t = :value_expression | :logical_expression | :nodes_expression
408
-
409
- module JSONP3
410
- # Base class for all filter functions.
411
- class FunctionExtension
412
- ARG_TYPES: Array[expression_t]
413
-
414
- RETURN_TYPE: expression_t
415
-
416
- def call: (*untyped _args, **untyped _kwargs) -> untyped
417
- end
418
- end
419
-
420
- module JSONP3
421
- # Return an array of tokens for the JSONPath expression _query_.
422
- #
423
- # @param query [String] the JSONPath expression to tokenize.
424
- # @return [Array<Token>]
425
- def self.tokenize: (String query) -> Array[Token]
426
-
427
- # JSONPath query expression lexical scanner.
428
- #
429
- # @see tokenize
430
- class Lexer
431
- @filter_depth: Integer
432
-
433
- @paren_stack: Array[Integer]
434
-
435
- @bracket_stack: Array[Array[untyped]]
436
-
437
- @tokens: Array[Token]
438
-
439
- @start: Integer
440
-
441
- @query: String
442
-
443
- @scanner: untyped
444
-
445
- RE_INT: ::Regexp
446
-
447
- RE_NAME: ::Regexp
448
-
449
- RE_WHITESPACE: ::Regexp
450
-
451
- S_ESCAPES: Set[String]
452
-
453
- # @dynamic tokens
454
- attr_reader tokens: Array[Token]
455
-
456
- # @dynamic tokens
457
- attr_reader bracket_stack: Array[Array[untyped]]
458
-
459
- def initialize: (String query) -> void
460
-
461
- def run: () -> void
462
-
463
- # Generate a new token with the given type.
464
- # @param token_type [Symbol] one of the constants defined on the _Token_ class.
465
- # @param value [String | nil] a the token's value, if it is known, otherwise the
466
- # value will be sliced from @query. This is a performance optimization.
467
- def emit: (token_t token_type, ?untyped value) -> void
468
-
469
- def next: () -> String
470
-
471
- def ignore: () -> void
472
-
473
- def backup: () -> void
474
-
475
- def peek: () -> String
476
-
477
- # Advance the lexer if the next character is equal to _char_.
478
- def accept?: (String | Regexp pattern) -> bool
479
-
480
- # Accept a run of digits, possibly preceded by a negative sign.
481
- # Does not handle exponents.
482
- def accept_int?: () -> bool
483
-
484
- def ignore_whitespace?: () -> (false | true)
485
-
486
- def error: (String message) -> void
487
-
488
- def lex_root: () -> (nil | :lex_segment)
489
-
490
- def lex_segment: () -> (nil | :lex_shorthand_selector | untyped)
491
-
492
- def lex_descendant_segment: () -> untyped
493
-
494
- def lex_shorthand_selector: () -> (nil | :lex_segment)
495
-
496
- def lex_inside_bracketed_segment: () -> untyped
497
-
498
- def lex_inside_filter: () -> untyped
499
-
500
- def self.lex_string_factory: (String quote, Symbol state, token_t token) -> untyped
501
- end
502
- end
503
-
504
- type location_element = String | Integer | Array[location_element]
505
-
506
- module JSONP3
507
- # A JSON-like value and its location.
508
- class JSONPathNode
509
- @value: untyped
510
-
511
- @location: Array[location_element]
512
-
513
- @root: untyped
514
-
515
- # @dynamic value, location, root
516
- attr_reader value: untyped
517
-
518
- # @dynamic value, location, root
519
- attr_reader location: Array[location_element]
520
-
521
- # @dynamic value, location, root
522
- attr_reader root: untyped
523
-
524
- # @param value [JSON-like] the value at this node.
525
- # @param location [Array<String | Integer | Array<String | Integer>>] the sequence of
526
- # names and/or indices leading to _value_ in _root_.
527
- # @param root [JSON-like] the root value containing _value_ at _location_.
528
- def initialize: (untyped value, Array[location_element] location, untyped root) -> void
529
-
530
- # Return the normalized path to this node.
531
- # @return [String] the normalized path.
532
- def path: () -> ::String
533
-
534
- # Return a new node that is a child of this node.
535
- # @param value the JSON-like value at the new node.
536
- # @param key [Integer, String] the array index or hash key associated with _value_.
537
- def new_child: (untyped value, String | Integer key) -> JSONPathNode
538
-
539
- def to_s: () -> ::String
540
- end
541
-
542
- # An array of JSONPathNode instances.
543
- class JSONPathNodeList < Array[JSONPathNode]
544
- end
35
+ def self.apply!: (Array[Patch::Op | Hash[String, untyped]] ops, untyped value) -> untyped
545
36
  end
546
-
547
- module JSONP3
548
- # Step through tokens
549
- class Stream
550
- @tokens: Array[Token]
551
-
552
- @index: Integer
553
-
554
- @eoi: Token
555
-
556
- def initialize: (Array[Token] tokens) -> void
557
-
558
- def next: () -> Token
559
-
560
- def peek: () -> Token
561
-
562
- def expect: (token_t token_type) -> void
563
-
564
- def expect_not: (token_t token_type, String message) -> void
565
-
566
- def to_s: () -> ::String
567
- end
568
-
569
- class Precedence
570
- LOWEST: 1
571
-
572
- LOGICAL_OR: 3
573
-
574
- LOGICAL_AND: 4
575
-
576
- RELATIONAL: 5
577
-
578
- PREFIX: 7
579
- end
580
-
581
- # A JSONPath expression parser.
582
- class Parser
583
- @env: JSONPathEnvironment
584
-
585
- @name_selector: untyped
586
-
587
- @index_selector: untyped
588
-
589
- def initialize: (JSONPathEnvironment env) -> void
590
-
591
- # Parse an array of tokens into an abstract syntax tree.
592
- # @param tokens [Array<Token>] tokens from the lexer.
593
- # @return [Array<Segment>]
594
- def parse: (Array[Token] tokens) -> Array[Segment]
595
-
596
- def parse_query: (Stream stream) -> Array[Segment]
597
-
598
- def parse_selectors: (Stream stream) -> Array[Selector]
599
-
600
- def parse_bracketed_selection: (Stream stream) -> Array[Selector]
601
-
602
- def parse_index_or_slice: (Stream stream) -> Selector
603
-
604
- def parse_slice_selector: (Stream stream) -> Selector
605
-
606
- def parse_filter_selector: (Stream stream) -> Selector
607
-
608
- def parse_filter_expression: (Stream stream, ?Integer precedence) -> Expression
609
-
610
- def parse_integer_literal: (Stream stream) -> Expression
611
-
612
- def parse_float_literal: (Stream stream) -> Expression
613
-
614
- def parse_function_expression: (Stream stream) -> Expression
615
-
616
- def parse_grouped_expression: (Stream stream) -> Expression
617
-
618
- def parse_prefix_expression: (Stream stream) -> Expression
619
-
620
- def parse_root_query: (Stream stream) -> Expression
621
-
622
- def parse_relative_query: (Stream stream) -> Expression
623
-
624
- def parse_infix_expression: (Stream stream, Expression left) -> Expression
625
-
626
- def parse_i_json_int: (Token token) -> Integer
627
-
628
- def decode_string_literal: (Token token) -> String
629
-
630
- def raise_for_non_comparable_function: (Expression expression) -> void
631
-
632
- def raise_for_not_compared_literal: (Expression expression) -> void
633
-
634
- def validate_function_extension_signature: (Token token, untyped args) -> void
635
-
636
- def function_return_type: (Expression expression) -> (expression_t | nil)
637
-
638
- PRECEDENCES: ::Hash[token_t, Integer]
639
-
640
- BINARY_OPERATORS: ::Hash[token_t, "&&" | "||" | "==" | ">=" | ">" | "<=" | "<" | "!="]
641
-
642
- COMPARISON_OPERATORS: Set[String]
643
- end
644
- end
645
-
646
- module JSONP3
647
- # A compiled JSONPath expression ready to be applied to JSON-like values.
648
- class JSONPath
649
- @env: JSONPathEnvironment
650
-
651
- @segments: Array[Segment]
652
-
653
- def initialize: (JSONPathEnvironment env, Array[Segment] segments) -> void
654
-
655
- def to_s: () -> ::String
656
-
657
- # Apply this JSONPath expression to JSON-like value _root_.
658
- # @param root [Array, Hash, String, Integer] the root JSON-like value to apply this query to.
659
- # @return [Array<JSONPathNode>] the sequence of nodes found while applying this query to _root_.
660
- def find: (untyped root) -> JSONPathNodeList
661
-
662
- def find_enum: (untyped root) -> Enumerable[JSONPathNode]
663
-
664
- def match: (untyped root) -> (JSONPathNode | nil)
665
-
666
- def match?: (untyped root) -> bool
667
-
668
- def first: (untyped root) -> (JSONPathNode | nil)
669
-
670
- alias apply find
671
-
672
- # Return true if this JSONPath expression is a singular query.
673
- def singular?: () -> (false | true)
674
-
675
- # Return true if this JSONPath expression has no segments.
676
- def empty?: () -> (false | true)
677
- end
678
- end
679
-
680
- module JSONP3
681
- # Base class for all JSONPath segments.
682
- class Segment
683
- @env: JSONPathEnvironment
684
-
685
- @token: Token
686
-
687
- @selectors: Array[Selector]
688
-
689
- # @dynamic token, selectors
690
- attr_reader token: Token
691
-
692
- # @dynamic token, selectors
693
- attr_reader selectors: Array[Selector]
694
-
695
- def initialize: (JSONPathEnvironment env, Token token, Array[Selector] selectors) -> void
696
-
697
- # Select the children of each node in _nodes_.
698
- def resolve: (Array[JSONPathNode] _nodes) -> Array[JSONPathNode]
699
-
700
- # Select the children of each node in _nodes_.
701
- def resolve_enum: (Enumerable[JSONPathNode] _nodes) -> Enumerable[JSONPathNode]
702
- end
703
-
704
- # The child selection segment.
705
- class ChildSegment < Segment
706
- def resolve: (Array[JSONPathNode] nodes) -> Array[JSONPathNode]
707
-
708
- def resolve_enum: (Enumerable[JSONPathNode] nodes) -> Enumerable[JSONPathNode]
709
-
710
- def to_s: () -> ::String
711
-
712
- def ==: (untyped other) -> bool
713
-
714
- alias eql? ==
715
-
716
- def hash: () -> Integer
717
- end
718
-
719
- # The recursive descent segment
720
- class RecursiveDescentSegment < Segment
721
- def resolve: (Array[JSONPathNode] nodes) -> Array[JSONPathNode]
722
-
723
- def resolve_enum: (Enumerable[JSONPathNode] nodes) -> Enumerable[JSONPathNode]
724
-
725
- def to_s: () -> ::String
726
-
727
- def ==: (untyped other) -> bool
728
-
729
- alias eql? ==
730
-
731
- def hash: () -> Integer
732
-
733
- def visit: (JSONPathNode node, ?::Integer depth) -> Array[JSONPathNode]
734
- def visit_enum: (JSONPathNode node, ?::Integer depth) -> Enumerable[JSONPathNode]
735
- end
736
- end
737
-
738
- module JSONP3
739
- # Base class for all JSONPath selectors
740
- class Selector
741
- @env: JSONPathEnvironment
742
-
743
- @token: Token
744
-
745
- # @dynamic token
746
- attr_reader token: Token
747
-
748
- def initialize: (JSONPathEnvironment env, Token token) -> void
749
-
750
- # Apply this selector to _node_.
751
- # @return [Array<JSONPathNode>]
752
- def resolve: (JSONPathNode _node) -> Array[JSONPathNode]
753
- def resolve_enum: (JSONPathNode _node) -> Enumerable[JSONPathNode]
754
-
755
- # Return true if this selector is a singular selector.
756
- def singular?: () -> false
757
- end
758
-
759
- # The name selector select values from hashes given a key.
760
- class NameSelector < Selector
761
- @name: String
762
-
763
- # @dynamic name
764
- attr_reader name: String
765
-
766
- def initialize: (JSONPathEnvironment env, Token token, String name) -> void
767
-
768
- def resolve: (JSONPathNode node) -> ::Array[JSONPathNode]
769
- def resolve_enum: (JSONPathNode node) -> Enumerable[JSONPathNode]
770
-
771
- def singular?: () -> true
772
-
773
- def to_s: () -> String
774
-
775
- def ==: (untyped other) -> bool
776
-
777
- alias eql? ==
778
-
779
- def hash: () -> Integer
780
- end
781
-
782
- class SymbolNameSelector < NameSelector
783
- @name: String
784
-
785
- @sym: Symbol
786
-
787
- # @dynamic name
788
- attr_reader name: String
789
-
790
- def initialize: (JSONPathEnvironment env, Token token, String name) -> void
791
-
792
- def resolve: (JSONPathNode node) -> ::Array[JSONPathNode]
793
- def resolve_enum: (JSONPathNode node) -> Enumerable[JSONPathNode]
794
-
795
- def singular?: () -> true
796
-
797
- def to_s: () -> String
798
-
799
- def ==: (untyped other) -> bool
800
-
801
- alias eql? ==
802
-
803
- def hash: () -> Integer
804
- end
805
-
806
- # The index selector selects values from arrays given an index.
807
- class IndexSelector < Selector
808
- @index: Integer
809
-
810
- # @dynamic index
811
- attr_reader index: Integer
812
-
813
- def initialize: (JSONPathEnvironment env, Token token, Integer index) -> void
814
-
815
- def resolve: (JSONPathNode node) -> ::Array[JSONPathNode]
816
- def resolve_enum: (JSONPathNode node) -> Enumerable[JSONPathNode]
817
-
818
- def singular?: () -> true
819
-
820
- def to_s: () -> String
821
-
822
- def ==: (untyped other) -> bool
823
-
824
- alias eql? ==
825
-
826
- def hash: () -> Integer
827
-
828
- private
829
-
830
- def normalize: (Integer index, Integer length) -> Integer
831
- end
832
-
833
- # The wildcard selector selects all elements from an array or values from a hash.
834
- class WildcardSelector < Selector
835
- def resolve: (JSONPathNode node) -> ::Array[JSONPathNode]
836
- def resolve_enum: (JSONPathNode node) -> Enumerable[JSONPathNode]
837
-
838
- def to_s: () -> "*"
839
-
840
- def ==: (untyped other) -> bool
841
-
842
- alias eql? ==
843
-
844
- def hash: () -> Integer
845
- end
846
-
847
- # The slice selector selects a range of elements from an array.
848
- class SliceSelector < Selector
849
- @start: (Integer | nil)
850
-
851
- @stop: (Integer | nil)
852
-
853
- @step: Integer
854
-
855
- # @dynamic start, stop, step
856
- attr_reader start: (Integer | nil)
857
-
858
- # @dynamic start, stop, step
859
- attr_reader stop: (Integer | nil)
860
-
861
- # @dynamic start, stop, step
862
- attr_reader step: Integer
863
-
864
- def initialize: (JSONPathEnvironment env, Token token, (Integer | nil) start, (Integer | nil) stop, (Integer | nil) step) -> void
865
-
866
- def resolve: (JSONPathNode node) -> ::Array[JSONPathNode]
867
- def resolve_enum: (JSONPathNode node) -> Enumerable[JSONPathNode]
868
-
869
- def to_s: () -> ::String
870
-
871
- def ==: (untyped other) -> bool
872
-
873
- alias eql? ==
874
-
875
- def hash: () -> Integer
876
- end
877
-
878
- # Select array elements or hash values according to a filter expression.
879
- class FilterSelector < Selector
880
- @expression: Expression
881
-
882
- # @dynamic expression
883
- attr_reader expression: Expression
884
-
885
- def initialize: (JSONPathEnvironment env, Token token, Expression expression) -> void
886
-
887
- def resolve: (JSONPathNode node) -> ::Array[JSONPathNode]
888
- def resolve_enum: (JSONPathNode node) -> Enumerable[JSONPathNode]
889
-
890
- def to_s: () -> ::String
891
-
892
- def ==: (untyped other) -> bool
893
-
894
- alias eql? ==
895
-
896
- def hash: () -> Integer
897
- end
898
- end
899
-
900
- type token_t = (
901
- :token_eoi |
902
- :token_error |
903
- :token_colon |
904
- :token_comma |
905
- :token_double_dot |
906
- :token_filter |
907
- :token_index |
908
- :token_lbracket |
909
- :token_name |
910
- :token_rbracket |
911
- :token_root |
912
- :token_wild |
913
- :token_and |
914
- :token_current |
915
- :token_double_quote_string |
916
- :token_eq |
917
- :token_false |
918
- :token_float |
919
- :token_function |
920
- :token_ge |
921
- :token_gt |
922
- :token_int |
923
- :token_le |
924
- :token_lparen |
925
- :token_lt |
926
- :token_ne |
927
- :token_not |
928
- :token_null |
929
- :token_or |
930
- :token_rparen |
931
- :token_single_quote_string |
932
- :token_true
933
- )
934
-
935
-
936
- module JSONP3
937
- # Tokens are produced by the lexer and consumed by the parser. Each token contains sub
938
- # string from a JSONPath expression, its location within the JSONPath expression and a
939
- # symbol indicating what type of token it is.
940
- class Token
941
- @type: token_t
942
-
943
- @value: String
944
-
945
- @start: Integer
946
-
947
- @query: String
948
-
949
- @message: (String | nil)
950
-
951
- # @dynamic type, value, start, query
952
- attr_reader type: token_t
953
-
954
- # @dynamic type, value, start, query
955
- attr_reader value: String
956
-
957
- # @dynamic type, value, start, query
958
- attr_reader start: Integer
959
-
960
- # @dynamic type, value, start, query
961
- attr_reader query: String
962
-
963
- # @dynamic type, value, start, query
964
- attr_reader message: (String | nil)
965
-
966
- def initialize: (token_t type, String value, Integer start, String query, ?message: (String | nil)?) -> void
967
-
968
- def ==: (untyped other) -> bool
969
-
970
- alias eql? ==
971
-
972
- def hash: () -> Integer
973
- end
974
- end
975
-
976
- module JSONP3
977
- # Replace escape sequences with their equivalent Unicode code point.
978
- # @param value [String]
979
- # @param quote [String] one of '"' or "'".
980
- # @param token [Token]
981
- # @return [String] A new string without escape sequences.
982
- def self.unescape_string: (String value, String quote, Token token) -> String
983
-
984
- def self.decode_hex_char: (untyped value, untyped index, Token token) -> ::Array[untyped]
985
-
986
- def self.parse_hex_digits: (untyped digits, Token token) -> untyped
987
-
988
- def self.high_surrogate?: (untyped code_point) -> untyped
989
-
990
- def self.low_surrogate?: (untyped code_point) -> untyped
991
-
992
- def self.code_point_to_string: (untyped code_point, Token token) -> untyped
993
-
994
- def self.canonical_string: (untyped String) -> ::String
995
- end
996
-
997
- module JSONP3
998
- VERSION: String
999
- end
1000
-
1001
- module JSONP3
1002
- # The standard `count` function.
1003
- class Count < FunctionExtension
1004
- ARG_TYPES: Array[expression_t]
1005
-
1006
- RETURN_TYPE: expression_t
1007
-
1008
- def call: (JSONPathNodeList node_list) -> untyped
1009
- end
1010
- end
1011
-
1012
- module JSONP3
1013
- # The standard `length` function.
1014
- class Length < FunctionExtension
1015
- ARG_TYPES: Array[expression_t]
1016
-
1017
- RETURN_TYPE: expression_t
1018
-
1019
- def call: (untyped obj) -> (:nothing | untyped)
1020
- end
1021
- end
1022
-
1023
- module JSONP3
1024
- # The standard `match` function.
1025
- class Match < FunctionExtension
1026
- @cache_size: Integer
1027
-
1028
- @raise_errors: (true | false)
1029
-
1030
- @cache: LRUCache
1031
-
1032
- ARG_TYPES: Array[expression_t]
1033
-
1034
- RETURN_TYPE: expression_t
1035
-
1036
- # @param cache_size [Integer] the maximum size of the regexp cache. Set it to
1037
- # zero or negative to disable the cache.
1038
- # @param raise_errors [bool] if _false_ (the default), return _false_ when this
1039
- # function causes a RegexpError instead of raising the exception.
1040
- def initialize: (?::Integer cache_size, ?raise_errors: bool) -> void
1041
-
1042
- # @param value [String]
1043
- # @param pattern [String]
1044
- # @return bool
1045
- def call: (untyped value, untyped pattern) -> untyped
1046
-
1047
- private
1048
-
1049
- def full_match: (String pattern) -> String
1050
- end
1051
- end
1052
-
1053
- module JSONP3
1054
- # Map I-Regexp pattern to Ruby regex pattern.
1055
- # @param pattern [String]
1056
- # @return [String]
1057
- def self.map_iregexp: (String pattern) -> String
1058
- end
1059
-
1060
- module JSONP3
1061
- # The standard `search` function.
1062
- class Search < FunctionExtension
1063
- @cache_size: Integer
1064
-
1065
- @raise_errors: (true | false)
1066
-
1067
- @cache: LRUCache
1068
-
1069
- ARG_TYPES: Array[expression_t]
1070
-
1071
- RETURN_TYPE: expression_t
1072
-
1073
- # @param cache_size [Integer] the maximum size of the regexp cache. Set it to
1074
- # zero or negative to disable the cache.
1075
- # @param raise_errors [bool] if _false_ (the default), return _false_ when this
1076
- # function causes a RegexpError instead of raising the exception.
1077
- def initialize: (?::Integer cache_size, ?raise_errors: bool) -> void
1078
-
1079
- # @param value [String]
1080
- # @param pattern [String]
1081
- # @return bool
1082
- def call: (untyped value, untyped pattern) -> untyped
1083
- end
1084
- end
1085
-
1086
- module JSONP3
1087
- # The standard `value` function.
1088
- class Value < FunctionExtension
1089
- ARG_TYPES: Array[expression_t]
1090
-
1091
- RETURN_TYPE: expression_t
1092
-
1093
- def call: (JSONPathNodeList node_list) -> (untyped | :nothing)
1094
- end
1095
- end
1096
-
1097
- module JSONP3
1098
- # Identify a single value in JSON-like data, as per RFC 6901.
1099
- class JSONPointer
1100
- @tokens: Array[String | Integer]
1101
-
1102
- @pointer: String
1103
-
1104
- UNDEFINED: :__undefined
1105
-
1106
- RE_INT: ::Regexp
1107
-
1108
- attr_reader tokens: Array[String | Integer]
1109
-
1110
- # Encode an array of strings and integers into a JSON pointer.
1111
- # @param tokens [Array<String | Integer>]
1112
- # @return [String]
1113
- def self.encode: (Array[String | Integer] tokens) -> String
1114
-
1115
- # @param pointer [String]
1116
- def initialize: (String pointer) -> void
1117
-
1118
- # Resolve this pointer against JSON-like data _value_.
1119
- def resolve: (untyped value, ?default: untyped) -> untyped
1120
-
1121
- def resolve_with_parent: (untyped value) -> ::Array[untyped]
1122
-
1123
- def relative_to?: (JSONPointer pointer) -> bool
1124
-
1125
- # @param parts [String]
1126
- def join: (*String parts) -> JSONPointer
1127
-
1128
- # Return _true_ if this pointer can be resolved against _value_, even if the resolved
1129
- # value is false or nil.
1130
- def exist?: (untyped value) -> bool
1131
-
1132
- # Return this pointer's parent as a new pointer. If this pointer points to the
1133
- # document root, self is returned.
1134
- def parent: () -> JSONPointer
1135
-
1136
- # @param rel [String | RelativeJSONPointer]
1137
- # @return [JSONPointer]
1138
- def to: ((String | RelativeJSONPointer) rel) -> JSONPointer
1139
-
1140
- def to_s: () -> String
1141
-
1142
- # @param pointer [String]
1143
- # @return [Array<String | Integer>]
1144
- def parse: (String pointer) -> Array[(String | Integer)]
1145
-
1146
- # @param value [Object]
1147
- # @param token [String | Integer]
1148
- # @return [Object] the "fetched" object from _value_ or UNDEFINED.
1149
- def get_item: (untyped value, (String | Integer) token) -> untyped
1150
-
1151
- # Like `#parse`, but assumes there's no leading slash.
1152
- # @param pointer [String]
1153
- # @return [Array<String | Integer>]
1154
- def _parse: (String pointer) -> Array[(String | Integer)]
1155
-
1156
- def _join: (String other) -> JSONPointer
1157
- end
1158
-
1159
- # A relative JSON Pointer.
1160
- # See https://datatracker.ietf.org/doc/html/draft-hha-relative-json-pointer
1161
- class RelativeJSONPointer
1162
- @origin: Integer
1163
-
1164
- @index: Integer
1165
-
1166
- @pointer: (String | JSONPointer)
1167
-
1168
- RE_RELATIVE_POINTER: ::Regexp
1169
-
1170
- RE_INT: ::Regexp
1171
-
1172
- # @param rel [String]
1173
- def initialize: (String rel) -> void
1174
-
1175
- def to_s: () -> ::String
1176
-
1177
- # @param pointer [String | JSONPointer]
1178
- # @return [JSONPointer]
1179
- def to: ((String | JSONPointer) pointer) -> JSONPointer
1180
-
1181
- private
1182
-
1183
- # @param token [String]
1184
- # @return [Integer]
1185
- def parse_int: (String token) -> Integer
1186
- end
1187
- end
1188
-
1189
- module JSONP3
1190
- # Base class for all JSON Patch operations
1191
- class Op
1192
- # Return the name of the patch operation.
1193
- def name: () -> String
1194
-
1195
- # Apply the patch operation to _value_.
1196
- def apply: (untyped _value, Integer _index) -> untyped
1197
-
1198
- # Return a JSON-like representation of this patch operation.
1199
- def to_h: () -> untyped
1200
- end
1201
-
1202
- # The JSON Patch _add_ operation.
1203
- class OpAdd < Op
1204
- @pointer: JSONPointer
1205
-
1206
- @value: untyped
1207
-
1208
- # @param pointer [JSONPointer]
1209
- # @param value [JSON-like value]
1210
- def initialize: (JSONPointer pointer, untyped value) -> void
1211
-
1212
- def name: () -> "add"
1213
- end
1214
-
1215
- # The JSON Patch _remove_ operation.
1216
- class OpRemove < Op
1217
- @pointer: JSONPointer
1218
-
1219
- # @param pointer [JSONPointer]
1220
- def initialize: (JSONPointer pointer) -> void
1221
-
1222
- def name: () -> "remove"
1223
- end
1224
-
1225
- # The JSON Patch _replace_ operation.
1226
- class OpReplace < Op
1227
- @pointer: JSONPointer
1228
-
1229
- @value: untyped
1230
-
1231
- # @param pointer [JSONPointer]
1232
- # @param value [JSON-like value]
1233
- def initialize: (JSONPointer pointer, untyped value) -> void
1234
-
1235
- def name: () -> "replace"
1236
- end
1237
-
1238
- # The JSON Patch _move_ operation.
1239
- class OpMove < Op
1240
- @from: JSONPointer
1241
-
1242
- @pointer: JSONPointer
1243
-
1244
- # @param from [JSONPointer]
1245
- # @param pointer [JSONPointer]
1246
- def initialize: (JSONPointer from, JSONPointer pointer) -> void
1247
-
1248
- def name: () -> "move"
1249
- end
1250
-
1251
- # The JSON Patch _copy_ operation.
1252
- class OpCopy < Op
1253
- @from: JSONPointer
1254
-
1255
- @pointer: JSONPointer
1256
-
1257
- # @param from [JSONPointer]
1258
- # @param pointer [JSONPointer]
1259
- def initialize: (JSONPointer from, JSONPointer pointer) -> void
1260
-
1261
- def name: () -> "copy"
1262
-
1263
- def deep_copy: (untyped obj) -> untyped
1264
- end
1265
-
1266
- # The JSON Patch _test_ operation.
1267
- class OpTest < Op
1268
- @pointer: JSONPointer
1269
-
1270
- @value: untyped
1271
-
1272
- # @param pointer [JSONPointer]
1273
- # @param value [JSON-like value]
1274
- def initialize: (JSONPointer pointer, untyped value) -> void
1275
-
1276
- def name: () -> "test"
1277
- end
1278
-
1279
- # A JSON Patch containing zero or more patch operations.
1280
- class JSONPatch
1281
- @ops: Array[Op]
1282
-
1283
- # @param ops [Array<Op>?]
1284
- def initialize: (?Array[Op | Hash[String, untyped]]? ops) -> void
1285
-
1286
- # @param pointer [String | JSONPointer]
1287
- # @param value [JSON-like value]
1288
- # @return [self]
1289
- def add: (JSONPointer | String pointer, untyped value) -> self
1290
-
1291
- # @param pointer [String | JSONPointer]
1292
- # @return [self]
1293
- def remove: (JSONPointer | String pointer) -> self
1294
-
1295
- # @param pointer [String | JSONPointer]
1296
- # @param value [JSON-like value]
1297
- # @return [self]
1298
- def replace: (JSONPointer | String pointer, untyped value) -> self
1299
-
1300
- # @param from [String | JSONPointer]
1301
- # @param pointer [String | JSONPointer]
1302
- # @return [self]
1303
- def move: (JSONPointer | String from, JSONPointer | String pointer) -> self
1304
-
1305
- # @param from [String | JSONPointer]
1306
- # @param pointer [String | JSONPointer]
1307
- # @return [self]
1308
- def copy: (JSONPointer | String from, JSONPointer | String pointer) -> self
1309
-
1310
- # @param pointer [String | JSONPointer]
1311
- # @param value [JSON-like value]
1312
- # @return [self]
1313
- def test: (JSONPointer | String pointer, untyped value) -> self
1314
-
1315
- # Apply this patch to JSON-like value _value_.
1316
- def apply: (untyped value) -> untyped
1317
-
1318
- def to_a: () -> Array[untyped]
1319
-
1320
- private
1321
-
1322
- def ensure_pointer: (JSONPointer | String pointer, Symbol op, Integer index) -> JSONPointer
1323
-
1324
- def build: (Array[Op | Hash[String, untyped]]) -> void
1325
-
1326
- def op_pointer: (Hash[String, untyped] obj, String key, String op, Integer index) -> JSONPointer
1327
-
1328
- def op_value: (Hash[String, untyped] obj, String key, String op, Integer index) -> untyped
1329
- end
1330
- end