trailblazer-macro-contract 2.1.2 → 2.1.3.beta1
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/.github/workflows/ci.yml +1 -1
- data/CHANGES.md +5 -0
- data/Gemfile +2 -0
- data/lib/trailblazer/macro/contract/build.rb +22 -11
- data/lib/trailblazer/macro/contract/validate.rb +2 -2
- data/lib/trailblazer/macro/contract/version.rb +1 -1
- data/lib/trailblazer/macro/contract.rb +1 -3
- data/test/docs/contract_test.rb +31 -14
- data/trailblazer-macro-contract.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c3c0092a4bd1f8b71d4506ed24e77af326b28d2991a88bdb45d67586dad746
|
4
|
+
data.tar.gz: 6de99c14b4bc553a0e32e568a9c31a74abf839f0d82f36dac33884300d979777
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15de139140c545de9ab6d1b6d19a83053815b78b7e4ae990a9b5a57dea89e77566524d2eb84326694f5399f41d3d7f367a761572badf465fdaa58cd32c2e1a79
|
7
|
+
data.tar.gz: 4b9fc7eb3a4f30a7f57f2ec95c6b0459ad5ccff8e4adbfd3ddc324570d8647b1046277e61f7f1b402bbbb663e28fbe3b1161d649db5036e74c91da66b9e6b8c1
|
data/.github/workflows/ci.yml
CHANGED
@@ -6,7 +6,7 @@ jobs:
|
|
6
6
|
fail-fast: false
|
7
7
|
matrix:
|
8
8
|
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
9
|
-
ruby: [2.
|
9
|
+
ruby: [2.6, 2.7, '3.0', jruby]
|
10
10
|
runs-on: ubuntu-latest
|
11
11
|
steps:
|
12
12
|
- uses: actions/checkout@v2
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
@@ -9,6 +9,8 @@ gem "dry-matcher"
|
|
9
9
|
# gem "trailblazer-macro", path: "../trailblazer-macro"
|
10
10
|
# gem "trailblazer-activity", path: "../trailblazer-activity"
|
11
11
|
# gem "trailblazer-activity-dsl-linear", path: "../trailblazer-activity-dsl-linear"
|
12
|
+
# gem "trailblazer-errors", path: "../trailblazer-errors"
|
13
|
+
# gem "trailblazer-developer", path: "../trailblazer-developer"
|
12
14
|
|
13
15
|
gem "minitest-line"
|
14
16
|
|
@@ -22,14 +22,25 @@ module Trailblazer
|
|
22
22
|
def self.Build(name: "default", constant: nil, builder: nil)
|
23
23
|
contract_path = :"contract.#{name}"
|
24
24
|
|
25
|
-
|
25
|
+
injections = {
|
26
|
+
Activity::Railway.Inject() => {
|
27
|
+
"#{contract_path}.class": ->(*) { constant }, # default to {constant} if not injected.
|
28
|
+
}
|
29
|
+
}
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
# DISCUSS: can we force-default this via Inject()?
|
32
|
+
input = {
|
33
|
+
Activity::Railway.In() => ->(ctx, **) do
|
34
|
+
ctx.to_hash.merge(
|
35
|
+
constant: constant,
|
36
|
+
name: contract_path
|
37
|
+
)
|
38
|
+
end
|
39
|
+
}
|
40
|
+
|
41
|
+
output = {
|
42
|
+
Activity::Railway.Out() => [contract_path]
|
43
|
+
}
|
33
44
|
|
34
45
|
default_contract_builder = ->(ctx, model: nil, **) { ctx[:"#{contract_path}.class"].new(model) }
|
35
46
|
|
@@ -43,10 +54,10 @@ module Trailblazer
|
|
43
54
|
|
44
55
|
{
|
45
56
|
task: task, id: "contract.build",
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
}.
|
58
|
+
merge(injections).
|
59
|
+
merge(input).
|
60
|
+
merge(output)
|
50
61
|
end
|
51
62
|
|
52
63
|
module DSL
|
@@ -20,8 +20,8 @@ module Trailblazer
|
|
20
20
|
|
21
21
|
# Build a simple Railway {Activity} for the internal flow.
|
22
22
|
activity = Class.new(Activity::Railway(name: "Contract::Validate")) do
|
23
|
-
step extract, id: "#{params_path}_extract", Output(:failure) => End(:extract_failure),
|
24
|
-
step validate, id: "contract.#{name}.call",
|
23
|
+
step extract, id: "#{params_path}_extract", Output(:failure) => End(:extract_failure), Activity::Railway.Inject() => extract_injections unless skip_extract# || representer
|
24
|
+
step validate, id: "contract.#{name}.call", Activity::Railway.Inject() => validate_injections
|
25
25
|
end
|
26
26
|
|
27
27
|
options = activity.Subprocess(activity)
|
@@ -13,7 +13,5 @@ module Trailblazer
|
|
13
13
|
|
14
14
|
# All macros sit in the {Trailblazer::Macro::Contract} namespace, where we forward calls from
|
15
15
|
# operations and activities to.
|
16
|
-
|
17
|
-
Contract = Macro::Contract
|
18
|
-
end
|
16
|
+
Activity::DSL::Linear::Helper::Constants::Contract = Macro::Contract
|
19
17
|
end
|
data/test/docs/contract_test.rb
CHANGED
@@ -294,7 +294,7 @@ class DocsContractInjectedKeyTest < Minitest::Spec
|
|
294
294
|
"contract.default.extract_key": "song"
|
295
295
|
)
|
296
296
|
#:inject-key-call end
|
297
|
-
.inspect(:model).must_equal %{<Result:true [#<struct DocsContractInjectedKeyTest::Song title=\"SVG\", length=13>] >} }
|
297
|
+
res.inspect(:model).must_equal %{<Result:true [#<struct DocsContractInjectedKeyTest::Song title=\"SVG\", length=13>] >} }
|
298
298
|
end
|
299
299
|
|
300
300
|
#---
|
@@ -517,30 +517,47 @@ class DryValidationContractTest < Minitest::Spec
|
|
517
517
|
it { Create.(params: { id: 1, title: "Y" }).inspect(:model).must_equal %{<Result:false [#<struct DryValidationContractTest::Song id=nil, title=nil>] >} }
|
518
518
|
it { Create.(params: { id: 1, title: "Yo" }).inspect(:model).must_equal %{<Result:true [#<struct DryValidationContractTest::Song id=1, title="Yo">] >} }
|
519
519
|
|
520
|
-
|
520
|
+
##---
|
521
521
|
# Contract::Validate(constant: DrySchema)
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
522
|
+
|
523
|
+
#:dry-schema-contract
|
524
|
+
module Song::Operation
|
525
|
+
class Archive < Trailblazer::Operation
|
526
|
+
Schema = Dry::Validation.Contract do
|
527
|
+
params do
|
528
|
+
required(:id).filled
|
529
|
+
end
|
526
530
|
end
|
527
|
-
end
|
528
531
|
|
529
|
-
|
530
|
-
|
532
|
+
# step Model(Song, :new) # You don't need {ctx[:model]}.
|
533
|
+
step Contract::Validate(constant: Schema, key: :song) # Your validation.
|
534
|
+
#~methods
|
535
|
+
# step Contract::Persist() # this is not possible!
|
536
|
+
#~methods end
|
537
|
+
end
|
531
538
|
end
|
539
|
+
#:dry-schema-contract end
|
532
540
|
|
533
541
|
# success
|
534
|
-
it {
|
542
|
+
it { _(Song::Operation::Archive.(params: {song: {id: "SVG"}}).success?).must_equal true }
|
535
543
|
# failure
|
536
|
-
it {
|
544
|
+
it { _(Song::Operation::Archive.(params: {song: {id: nil}}).success?).must_equal false }
|
545
|
+
# shows error messages
|
537
546
|
it "shows error messages" do
|
538
|
-
|
547
|
+
#:dry-contract-call
|
548
|
+
result = Song::Operation::Archive.(params: {song: {id: nil}})
|
549
|
+
#:dry-contract-call end
|
550
|
+
|
551
|
+
_(result[:"result.contract.default"].errors.inspect).must_equal %{#<Dry::Validation::MessageSet messages=[#<Dry::Schema::Message text=\"must be filled\" path=[:id] predicate=:filled? input=nil>] options={:source=>[#<Dry::Schema::Message text=\"must be filled\" path=[:id] predicate=:filled? input=nil>], :hints=>false}>}
|
539
552
|
|
540
|
-
result[:"result.contract.default"].errors.
|
553
|
+
# raise result[:"result.contract.default"].errors.messages[0].to_s.inspect
|
554
|
+
assert_equal result[:"result.contract.default"].errors[:id].inspect, %{["must be filled"]}
|
555
|
+
#:dry-contract-result
|
556
|
+
result[:"result.contract.default"].errors[:id] #=> ["must be filled"]
|
557
|
+
#:dry-contract-result end
|
541
558
|
end
|
542
559
|
# key not found
|
543
|
-
it {
|
560
|
+
it { _(Song::Operation::Archive.(params: {}).success?).must_equal false }
|
544
561
|
end
|
545
562
|
|
546
563
|
class DocContractBuilderTest < Minitest::Spec
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "minitest"
|
31
31
|
spec.add_development_dependency "rake"
|
32
32
|
|
33
|
-
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.
|
33
|
+
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 1.0.0.beta1", "< 1.1.0"
|
34
34
|
|
35
35
|
spec.required_ruby_version = ">= 2.0.0"
|
36
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-macro-contract
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reform
|
@@ -148,20 +148,20 @@ dependencies:
|
|
148
148
|
requirements:
|
149
149
|
- - ">="
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version: 0.
|
151
|
+
version: 1.0.0.beta1
|
152
152
|
- - "<"
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
154
|
+
version: 1.1.0
|
155
155
|
type: :runtime
|
156
156
|
prerelease: false
|
157
157
|
version_requirements: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
159
|
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
|
-
version: 0.
|
161
|
+
version: 1.0.0.beta1
|
162
162
|
- - "<"
|
163
163
|
- !ruby/object:Gem::Version
|
164
|
-
version:
|
164
|
+
version: 1.1.0
|
165
165
|
description: Operation macros for form objects
|
166
166
|
email:
|
167
167
|
- apotonick@gmail.com
|
@@ -207,9 +207,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
207
207
|
version: 2.0.0
|
208
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
209
|
requirements:
|
210
|
-
- - "
|
210
|
+
- - ">"
|
211
211
|
- !ruby/object:Gem::Version
|
212
|
-
version:
|
212
|
+
version: 1.3.1
|
213
213
|
requirements: []
|
214
214
|
rubygems_version: 3.2.3
|
215
215
|
signing_key:
|