cton 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +117 -345
- data/lib/cton/binary.rb +74 -0
- data/lib/cton/decoder.rb +18 -6
- data/lib/cton/encoder.rb +19 -3
- data/lib/cton/schema.rb +369 -0
- data/lib/cton/stream.rb +44 -0
- data/lib/cton/version.rb +1 -1
- data/lib/cton.rb +63 -0
- data/sig/cton/binary.rbs +12 -0
- data/sig/cton/schema.rbs +84 -0
- data/sig/cton/stream.rbs +13 -0
- data/sig/cton.rbs +15 -0
- metadata +8 -2
data/sig/cton/schema.rbs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
module Cton
|
|
2
|
+
module Schema
|
|
3
|
+
class Error
|
|
4
|
+
attr_reader path: String
|
|
5
|
+
attr_reader message: String
|
|
6
|
+
attr_reader expected: String?
|
|
7
|
+
attr_reader actual: String?
|
|
8
|
+
|
|
9
|
+
def initialize: (path: String, message: String, ?expected: String?, ?actual: String?) -> void
|
|
10
|
+
def to_s: -> String
|
|
11
|
+
def to_h: -> Hash[Symbol, untyped]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Result
|
|
15
|
+
attr_reader errors: Array[Error]
|
|
16
|
+
|
|
17
|
+
def initialize: (?Array[Error] errors) -> void
|
|
18
|
+
def valid?: -> bool
|
|
19
|
+
def to_s: -> String
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Node
|
|
23
|
+
def validate: (untyped value, String path, Array[Error] errors) -> void
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class AnySchema < Node
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class NullableSchema < Node
|
|
30
|
+
def initialize: (Node inner) -> void
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class OptionalSchema < Node
|
|
34
|
+
def initialize: (Node inner) -> void
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class ScalarSchema < Node
|
|
38
|
+
def initialize: (?types: Array[Class], ?enum: Array[untyped]) -> void
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class ObjectSchema < Node
|
|
42
|
+
def initialize: (required: Hash[String, Node], optional: Hash[String, Node], ?allow_extra: bool) -> void
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class ArraySchema < Node
|
|
46
|
+
def initialize: (item_schema: Node?, ?length: Integer?, ?min: Integer?, ?max: Integer?) -> void
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
module DSL
|
|
50
|
+
def object: (?allow_extra: bool) { () -> untyped } -> ObjectSchema
|
|
51
|
+
def array: (?length: Integer?, ?min: Integer?, ?max: Integer?, ?of: Node?) { () -> untyped } -> ArraySchema
|
|
52
|
+
def nullable: (Node schema) -> NullableSchema
|
|
53
|
+
def optional: (Node schema) -> OptionalSchema
|
|
54
|
+
def any: -> AnySchema
|
|
55
|
+
def scalar: (*untyped types, ?enum: Array[untyped]) -> ScalarSchema
|
|
56
|
+
def enum: (*untyped values) -> ScalarSchema
|
|
57
|
+
def string: -> ScalarSchema
|
|
58
|
+
def integer: -> ScalarSchema
|
|
59
|
+
def float: -> ScalarSchema
|
|
60
|
+
def number: -> ScalarSchema
|
|
61
|
+
def boolean: -> ScalarSchema
|
|
62
|
+
def null: -> ScalarSchema
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class Builder
|
|
66
|
+
include DSL
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class ObjectBuilder < Builder
|
|
70
|
+
def key: (String name, ?Node schema) { () -> untyped } -> void
|
|
71
|
+
def optional: (String name, ?Node schema) { () -> untyped } -> void
|
|
72
|
+
def allow_extra_keys!: -> void
|
|
73
|
+
def to_schema: -> ObjectSchema
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class ArrayBuilder < Builder
|
|
77
|
+
def items: (?Node schema) { () -> untyped } -> void
|
|
78
|
+
def of: (?Node schema) { () -> untyped } -> void
|
|
79
|
+
def to_schema: -> ArraySchema
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def self.define: { () -> Node } -> Node
|
|
83
|
+
end
|
|
84
|
+
end
|
data/sig/cton/stream.rbs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Cton
|
|
2
|
+
class StreamReader
|
|
3
|
+
include Enumerable[untyped]
|
|
4
|
+
|
|
5
|
+
def initialize: (IO io, ?separator: String, ?symbolize_names: bool) -> void
|
|
6
|
+
def each: { (untyped) -> void } -> void
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class StreamWriter
|
|
10
|
+
def initialize: (IO io, ?separator: String, **untyped) -> void
|
|
11
|
+
def write: (untyped value) -> void
|
|
12
|
+
end
|
|
13
|
+
end
|
data/sig/cton.rbs
CHANGED
|
@@ -26,6 +26,12 @@ module Cton
|
|
|
26
26
|
def self.unregister_type: (Class klass) -> void
|
|
27
27
|
def self.clear_type_registry!: -> void
|
|
28
28
|
def self.type_registry: -> TypeRegistry
|
|
29
|
+
def self.schema: { () -> Schema::Node } -> Schema::Node
|
|
30
|
+
def self.validate_schema: (untyped data, Schema::Node schema) -> Schema::Result
|
|
31
|
+
def self.load_stream: (IO io, ?separator: String, ?symbolize_names: bool) -> Enumerable[untyped]
|
|
32
|
+
def self.dump_stream: (Enumerable[untyped] enumerable, IO io, ?separator: String, **untyped) -> IO
|
|
33
|
+
def self.dump_binary: (untyped data, ?compress: bool, **untyped) -> String
|
|
34
|
+
def self.load_binary: (String binary) -> untyped
|
|
29
35
|
|
|
30
36
|
class ValidationResult
|
|
31
37
|
attr_reader errors: Array[ValidationError]
|
|
@@ -110,6 +116,7 @@ module Cton
|
|
|
110
116
|
attr_reader indent_level: Integer
|
|
111
117
|
attr_reader decimal_mode: Symbol
|
|
112
118
|
attr_reader comments: Hash[String, String]
|
|
119
|
+
attr_reader buffer: String
|
|
113
120
|
|
|
114
121
|
def encode_root: (untyped value) -> void
|
|
115
122
|
def encode_top_level_pair: (String | Symbol key, untyped value) -> void
|
|
@@ -139,6 +146,9 @@ module Cton
|
|
|
139
146
|
def homogeneous_scalar_tokens?: (Array[untyped] list) -> bool
|
|
140
147
|
def token_does_not_require_quotes?: (untyped value) -> bool
|
|
141
148
|
def fast_scalar_stream: (Array[untyped] list) -> String
|
|
149
|
+
def buffer_for: -> String
|
|
150
|
+
def reset_buffer: -> void
|
|
151
|
+
def buffer_available?: -> bool
|
|
142
152
|
def indent: -> void
|
|
143
153
|
def outdent: -> void
|
|
144
154
|
def newline: -> void
|
|
@@ -149,9 +159,14 @@ module Cton
|
|
|
149
159
|
TERMINATORS: Array[String]
|
|
150
160
|
KEY_VALUE_BOUNDARY_TOKENS: Array[String]
|
|
151
161
|
SAFE_KEY_PATTERN: Regexp
|
|
162
|
+
SAFE_KEY_CHAR_PATTERN: Regexp
|
|
163
|
+
TERMINATOR_REGEX: Regexp
|
|
152
164
|
INTEGER_PATTERN: Regexp
|
|
153
165
|
FLOAT_PATTERN: Regexp
|
|
154
166
|
|
|
167
|
+
def self.decode: (String cton, ?symbolize_names: bool) -> untyped
|
|
168
|
+
def self.scan_stream: (IO io, ?separator: String, ?symbolize_names: bool) -> Enumerable[untyped]
|
|
169
|
+
|
|
155
170
|
def initialize: (?symbolize_names: bool) -> void
|
|
156
171
|
def decode: (String cton) -> untyped
|
|
157
172
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cton
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Davide Santangelo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: CTON provides a JSON-compatible, token-efficient text representation
|
|
14
14
|
optimized for LLM prompts.
|
|
@@ -27,13 +27,19 @@ files:
|
|
|
27
27
|
- Rakefile
|
|
28
28
|
- bench/encode_decode_bench.rb
|
|
29
29
|
- lib/cton.rb
|
|
30
|
+
- lib/cton/binary.rb
|
|
30
31
|
- lib/cton/decoder.rb
|
|
31
32
|
- lib/cton/encoder.rb
|
|
33
|
+
- lib/cton/schema.rb
|
|
32
34
|
- lib/cton/stats.rb
|
|
35
|
+
- lib/cton/stream.rb
|
|
33
36
|
- lib/cton/type_registry.rb
|
|
34
37
|
- lib/cton/validator.rb
|
|
35
38
|
- lib/cton/version.rb
|
|
36
39
|
- sig/cton.rbs
|
|
40
|
+
- sig/cton/binary.rbs
|
|
41
|
+
- sig/cton/schema.rbs
|
|
42
|
+
- sig/cton/stream.rbs
|
|
37
43
|
homepage: https://github.com/davidesantangelo/cton
|
|
38
44
|
licenses:
|
|
39
45
|
- MIT
|