dexkit 0.7.0 → 0.8.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 +31 -0
- data/README.md +34 -5
- data/guides/llm/EVENT.md +43 -1
- data/guides/llm/FORM.md +1 -1
- data/guides/llm/OPERATION.md +106 -2
- data/guides/llm/QUERY.md +1 -1
- data/lib/dex/event/export.rb +56 -0
- data/lib/dex/event/handler.rb +33 -0
- data/lib/dex/event.rb +27 -0
- data/lib/dex/operation/explain.rb +204 -0
- data/lib/dex/operation/export.rb +144 -0
- data/lib/dex/operation/guard_wrapper.rb +15 -4
- data/lib/dex/operation/record_backend.rb +12 -0
- data/lib/dex/operation.rb +46 -2
- data/lib/dex/props_setup.rb +25 -2
- data/lib/dex/railtie.rb +84 -0
- data/lib/dex/registry.rb +63 -0
- data/lib/dex/tool.rb +115 -0
- data/lib/dex/type_serializer.rb +132 -0
- data/lib/dex/version.rb +1 -1
- data/lib/dexkit.rb +5 -0
- metadata +8 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dex
|
|
4
|
+
module TypeSerializer
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
# --- Human-readable string ---
|
|
8
|
+
|
|
9
|
+
def to_string(type)
|
|
10
|
+
case type
|
|
11
|
+
when Dex::RefType
|
|
12
|
+
"Ref(#{type.model_class.name})"
|
|
13
|
+
when Literal::Types::NilableType
|
|
14
|
+
"Nilable(#{to_string(type.type)})"
|
|
15
|
+
when Literal::Types::ArrayType
|
|
16
|
+
"Array(#{to_string(type.type)})"
|
|
17
|
+
when Literal::Types::UnionType
|
|
18
|
+
_union_string(type)
|
|
19
|
+
when Literal::Types::ConstraintType
|
|
20
|
+
_constraint_string(type)
|
|
21
|
+
when Literal::Types::BooleanType
|
|
22
|
+
"Boolean"
|
|
23
|
+
when Class
|
|
24
|
+
type.name || type.to_s
|
|
25
|
+
else
|
|
26
|
+
type.inspect
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# --- JSON Schema ---
|
|
31
|
+
|
|
32
|
+
BIGDECIMAL_PATTERN = '^-?\d+\.?\d*$'
|
|
33
|
+
|
|
34
|
+
def to_json_schema(type, desc: nil)
|
|
35
|
+
schema = _type_to_schema(type)
|
|
36
|
+
schema[:description] = desc if desc
|
|
37
|
+
schema
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def _type_to_schema(type) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
|
|
41
|
+
case type
|
|
42
|
+
when Dex::RefType
|
|
43
|
+
{ type: "string", description: "#{type.model_class.name} ID" }
|
|
44
|
+
when Literal::Types::NilableType
|
|
45
|
+
{ oneOf: [_type_to_schema(type.type), { type: "null" }] }
|
|
46
|
+
when Literal::Types::ArrayType
|
|
47
|
+
{ type: "array", items: _type_to_schema(type.type) }
|
|
48
|
+
when Literal::Types::UnionType
|
|
49
|
+
_union_schema(type)
|
|
50
|
+
when Literal::Types::ConstraintType
|
|
51
|
+
_constraint_schema(type)
|
|
52
|
+
when Literal::Types::BooleanType
|
|
53
|
+
{ type: "boolean" }
|
|
54
|
+
when Class
|
|
55
|
+
_class_schema(type)
|
|
56
|
+
else
|
|
57
|
+
{}
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def _union_string(type)
|
|
62
|
+
items = if type.primitives&.any?
|
|
63
|
+
type.primitives.map(&:inspect)
|
|
64
|
+
else
|
|
65
|
+
type.types.map { |t| to_string(t) }
|
|
66
|
+
end
|
|
67
|
+
"Union(#{items.join(", ")})"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def _constraint_string(type)
|
|
71
|
+
constraints = type.object_constraints
|
|
72
|
+
return "{}" if constraints.empty?
|
|
73
|
+
|
|
74
|
+
base = constraints.first
|
|
75
|
+
rest = constraints[1..]
|
|
76
|
+
base_str = base.is_a?(Class) ? (base.name || base.to_s) : base.inspect
|
|
77
|
+
if rest.empty?
|
|
78
|
+
base_str
|
|
79
|
+
else
|
|
80
|
+
"#{base_str}(#{rest.map(&:inspect).join(", ")})"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def _union_schema(type)
|
|
85
|
+
if type.primitives&.any?
|
|
86
|
+
{ enum: type.primitives.to_a }
|
|
87
|
+
else
|
|
88
|
+
{ oneOf: type.types.map { |t| _type_to_schema(t) } }
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def _constraint_schema(type)
|
|
93
|
+
constraints = type.object_constraints
|
|
94
|
+
return {} if constraints.empty?
|
|
95
|
+
|
|
96
|
+
base = constraints.first
|
|
97
|
+
schema = base.is_a?(Class) ? _class_schema(base) : {}
|
|
98
|
+
_apply_range_constraints(schema, constraints[1..])
|
|
99
|
+
schema
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def _apply_range_constraints(schema, constraints)
|
|
103
|
+
constraints.each do |c|
|
|
104
|
+
next unless c.is_a?(Range)
|
|
105
|
+
|
|
106
|
+
schema[:minimum] = c.begin if c.begin
|
|
107
|
+
if c.end
|
|
108
|
+
schema[c.exclude_end? ? :exclusiveMaximum : :maximum] = c.end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def _class_schema(type) # rubocop:disable Metrics/MethodLength
|
|
114
|
+
case type.name
|
|
115
|
+
when "String" then { type: "string" }
|
|
116
|
+
when "Integer" then { type: "integer" }
|
|
117
|
+
when "Float" then { type: "number" }
|
|
118
|
+
when "TrueClass", "FalseClass" then { type: "boolean" }
|
|
119
|
+
when "Symbol" then { type: "string" }
|
|
120
|
+
when "Hash" then { type: "object" }
|
|
121
|
+
when "Date" then { type: "string", format: "date" }
|
|
122
|
+
when "Time" then { type: "string", format: "date-time" }
|
|
123
|
+
when "DateTime" then { type: "string", format: "date-time" }
|
|
124
|
+
when "BigDecimal" then { type: "string", pattern: BIGDECIMAL_PATTERN }
|
|
125
|
+
else {}
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
private_class_method :_type_to_schema, :_union_string, :_constraint_string,
|
|
130
|
+
:_union_schema, :_constraint_schema, :_apply_range_constraints, :_class_schema
|
|
131
|
+
end
|
|
132
|
+
end
|
data/lib/dex/version.rb
CHANGED
data/lib/dexkit.rb
CHANGED
|
@@ -19,8 +19,11 @@ require_relative "dex/error"
|
|
|
19
19
|
require_relative "dex/settings"
|
|
20
20
|
require_relative "dex/pipeline"
|
|
21
21
|
require_relative "dex/executable"
|
|
22
|
+
require_relative "dex/registry"
|
|
23
|
+
require_relative "dex/type_serializer"
|
|
22
24
|
require_relative "dex/operation"
|
|
23
25
|
require_relative "dex/event"
|
|
26
|
+
require_relative "dex/tool"
|
|
24
27
|
require_relative "dex/form"
|
|
25
28
|
require_relative "dex/query"
|
|
26
29
|
|
|
@@ -89,3 +92,5 @@ module Dex
|
|
|
89
92
|
end
|
|
90
93
|
end
|
|
91
94
|
end
|
|
95
|
+
|
|
96
|
+
require_relative "dex/railtie" if defined?(Rails::Railtie)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dexkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jacek Galanciak
|
|
@@ -171,6 +171,7 @@ files:
|
|
|
171
171
|
- lib/dex/event.rb
|
|
172
172
|
- lib/dex/event/bus.rb
|
|
173
173
|
- lib/dex/event/execution_state.rb
|
|
174
|
+
- lib/dex/event/export.rb
|
|
174
175
|
- lib/dex/event/handler.rb
|
|
175
176
|
- lib/dex/event/metadata.rb
|
|
176
177
|
- lib/dex/event/processor.rb
|
|
@@ -187,6 +188,8 @@ files:
|
|
|
187
188
|
- lib/dex/operation/async_proxy.rb
|
|
188
189
|
- lib/dex/operation/async_wrapper.rb
|
|
189
190
|
- lib/dex/operation/callback_wrapper.rb
|
|
191
|
+
- lib/dex/operation/explain.rb
|
|
192
|
+
- lib/dex/operation/export.rb
|
|
190
193
|
- lib/dex/operation/guard_wrapper.rb
|
|
191
194
|
- lib/dex/operation/jobs.rb
|
|
192
195
|
- lib/dex/operation/lock_wrapper.rb
|
|
@@ -205,14 +208,18 @@ files:
|
|
|
205
208
|
- lib/dex/query/backend.rb
|
|
206
209
|
- lib/dex/query/filtering.rb
|
|
207
210
|
- lib/dex/query/sorting.rb
|
|
211
|
+
- lib/dex/railtie.rb
|
|
208
212
|
- lib/dex/ref_type.rb
|
|
213
|
+
- lib/dex/registry.rb
|
|
209
214
|
- lib/dex/settings.rb
|
|
210
215
|
- lib/dex/test_helpers.rb
|
|
211
216
|
- lib/dex/test_helpers/assertions.rb
|
|
212
217
|
- lib/dex/test_helpers/execution.rb
|
|
213
218
|
- lib/dex/test_helpers/stubbing.rb
|
|
214
219
|
- lib/dex/test_log.rb
|
|
220
|
+
- lib/dex/tool.rb
|
|
215
221
|
- lib/dex/type_coercion.rb
|
|
222
|
+
- lib/dex/type_serializer.rb
|
|
216
223
|
- lib/dex/version.rb
|
|
217
224
|
- lib/dexkit.rb
|
|
218
225
|
homepage: https://dex.razorjack.net/
|