jade-lang 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e1034e93db617cde9f33aad318dc23a4bf4987f9f0243558434f14ed64feca8
4
- data.tar.gz: f1e067ee109d4db4b7ac9a94664d2d69b92e1df10ccdbf31260958c23827e8d8
3
+ metadata.gz: 38f4067e761c85016ad9baa6c733e6567aa93eea5cc0ffb755c0ac469a6a0002
4
+ data.tar.gz: 97dd4372b13bcb7e23bdc3ac2dcbe231d067410e9a99634afbbd3bd1a485452e
5
5
  SHA512:
6
- metadata.gz: 69fb033248f3950561b72732f70b51e2b7ed0e32aeffdab821c86a112a767e3b01dacccfda561467c312958b0f068be132421798d59551c6a0d28f3ddde06f67
7
- data.tar.gz: 612d3fa844be6d1fa368679d1af12eb77f59a18175e84a906f29dd47405e7d6ef6002975dde83ffc291973eec3ca1cdad1c061755e89ba158a88eb369e3b8e93
6
+ metadata.gz: 415bcc6027fbefa912960d30c004d3d442000b37d6b3e6a27485b9ef9a12685bad3dc79855f7ccd99378987ea38fb6810fafe8f371dad5c50ce9b605c464f756
7
+ data.tar.gz: 8891cbe3dfe48e80cdb2ae73ec96a13b09a3adc8287adf812e7a30639ca4918b417cc02e45148222bacd2f7b1d412b58ce78d15f783dceed0868d0175e194daf
data/CHANGELOG.md CHANGED
@@ -6,6 +6,21 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.8.0]
10
+
11
+ ### Added
12
+
13
+ - `Assignable` also derives for structs, naming one column per field in
14
+ declaration order. A field renamed to dodge a keyword (`type_`) maps back to
15
+ the column it came from. Generic structs derive at the type they are applied
16
+ to. Inert unless jade-sql is loaded.
17
+
18
+ ### Changed
19
+
20
+ - The derived jade-sql interface is now `Sql.Assignable`, was `Sql.SqlMapper`.
21
+ It is matched by name, so jade-sql must move to the new name in the same
22
+ release.
23
+
9
24
  ## [0.7.0]
10
25
 
11
26
  ### Added
@@ -68,6 +83,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
68
83
  anonymous record. A project that CI-checks committed artifacts will see a
69
84
  diff.
70
85
 
86
+
71
87
  ## [0.6.0]
72
88
 
73
89
  ### Fixed
@@ -6,11 +6,11 @@ module Jade
6
6
  # jade-sql's interface, derived here rather than there: the
7
7
  # deriving framework is not extensible, and this stays inert
8
8
  # without jade-sql, since nothing else names the interface.
9
- module SqlMapper
9
+ module Assignable
10
10
  extend self
11
11
  include Helpers
12
12
 
13
- INTERFACE = 'Sql.SqlMapper'
13
+ INTERFACE = 'Sql.Assignable'
14
14
  ASSIGNMENT = 'Sql.Assignment'
15
15
  ASSIGNMENT_FIELDS = %w[col value_sql params].freeze
16
16
 
@@ -20,11 +20,11 @@ module Jade
20
20
  return failed(constraint, entry_name) unless assignment_matches?(registry)
21
21
 
22
22
  case constraint.type
23
- in Type::Application(constructor: Type::Constructor(name:), args: [])
23
+ in Type::Application(constructor: Type::Constructor(name:), args:)
24
24
  Symbol
25
25
  .type_ref_from_qualified_name(name)
26
26
  .then { registry.lookup(it) }
27
- .then { derive_for(constraint, it, registry, lookup, entry_name) }
27
+ .then { derive_for(constraint, it, args, registry, lookup, entry_name) }
28
28
 
29
29
  else
30
30
  failed(constraint, entry_name)
@@ -47,11 +47,14 @@ module Jade
47
47
  end
48
48
  end
49
49
 
50
- def derive_for(constraint, symbol, registry, lookup, entry_name)
50
+ def derive_for(constraint, symbol, args, registry, lookup, entry_name)
51
51
  case symbol
52
- in Symbol::Union if single_payload?(symbol, registry)
52
+ in Symbol::Union if args.empty? && single_payload?(symbol, registry)
53
53
  derive_union(constraint, symbol, registry, lookup, entry_name)
54
54
 
55
+ in Symbol::Struct
56
+ derive_struct(constraint, symbol, args, registry, lookup, entry_name)
57
+
55
58
  else
56
59
  failed(constraint, entry_name)
57
60
  end
@@ -74,6 +77,43 @@ module Jade
74
77
  .map { implementation(constraint, union_body(vs), it) }
75
78
  end
76
79
 
80
+ def derive_struct(constraint, struct_sym, args, registry, lookup, entry_name)
81
+ fields = struct_fields(struct_sym, args, registry)
82
+
83
+ fields
84
+ .map { |_, type| Type.constraint('Encode.Encodable', type, nil) }
85
+ .map { lookup.call(it) }
86
+ .then { Results.sequence(it) }
87
+ .map { implementation(constraint, struct_body(fields), it) }
88
+ end
89
+
90
+ def struct_body(fields)
91
+ fields
92
+ .each_with_index
93
+ .map { |(name, _), idx| field_assignment(name, idx) }
94
+ .then { [:list, it] }
95
+ end
96
+
97
+ def field_assignment(name, idx)
98
+ [:call,
99
+ [:struct_constructor, ASSIGNMENT, 3],
100
+ [
101
+ column_name(name),
102
+ '?',
103
+ [:list,
104
+ [[:call, [:impl_arg, idx, 'encoder'], [[:access, [:var, 'f'], name.to_s]]]],
105
+ ],
106
+ ],
107
+ ]
108
+ end
109
+
110
+ def column_name(field)
111
+ field
112
+ .to_s
113
+ .then { it.end_with?('_') ? it.delete_suffix('_') : it }
114
+ .then { Lexer::KEYWORDS.include?(it) ? it : field.to_s }
115
+ end
116
+
77
117
  def encodable_dep(variant, registry)
78
118
  variant
79
119
  .args
@@ -2,7 +2,7 @@ require_relative './deriving/helpers.rb'
2
2
  require_relative './deriving/eq.rb'
3
3
  require_relative './deriving/decodable.rb'
4
4
  require_relative './deriving/encodable.rb'
5
- require_relative './deriving/sql_mapper.rb'
5
+ require_relative './deriving/assignable.rb'
6
6
  require_relative './deriving/show.rb'
7
7
 
8
8
  module Jade
@@ -12,7 +12,7 @@ module Jade
12
12
  module Deriving
13
13
  extend self
14
14
 
15
- DERIVERS = [Eq, Show, Decodable, Encodable, SqlMapper]
15
+ DERIVERS = [Eq, Show, Decodable, Encodable, Assignable]
16
16
 
17
17
  def derivable?(interface)
18
18
  DERIVERS.any? { it.supports?(interface) }
data/lib/jade/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jade
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jade-lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agustin Cornu
@@ -218,12 +218,12 @@ files:
218
218
  - lib/jade/frontend/type_checking/canonicalize.rb
219
219
  - lib/jade/frontend/type_checking/constraints.rb
220
220
  - lib/jade/frontend/type_checking/constraints/deriving.rb
221
+ - lib/jade/frontend/type_checking/constraints/deriving/assignable.rb
221
222
  - lib/jade/frontend/type_checking/constraints/deriving/decodable.rb
222
223
  - lib/jade/frontend/type_checking/constraints/deriving/encodable.rb
223
224
  - lib/jade/frontend/type_checking/constraints/deriving/eq.rb
224
225
  - lib/jade/frontend/type_checking/constraints/deriving/helpers.rb
225
226
  - lib/jade/frontend/type_checking/constraints/deriving/show.rb
226
- - lib/jade/frontend/type_checking/constraints/deriving/sql_mapper.rb
227
227
  - lib/jade/frontend/type_checking/definition.rb
228
228
  - lib/jade/frontend/type_checking/env.rb
229
229
  - lib/jade/frontend/type_checking/error.rb