sorbet-typescript 0.1.0 → 0.1.1

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: 20b6b038eabc0014a293fcd994c56e1413d217613fa86c0df40157dc3e4399a2
4
- data.tar.gz: 331239897ffb2f29a4b52dd09987d1fecdbbb298f9cfd8a42dc7898e0034889c
3
+ metadata.gz: a1cf81a39a35ccac245e89223b1058cdac4fd86ffce3b41170ee4bea5a322d54
4
+ data.tar.gz: 026eccb4bfe1701578c88ed1ecbcc54d79a11e32071bba40f64746fa834443cf
5
5
  SHA512:
6
- metadata.gz: 28d320cb930debcab937be85c99d676743469c3a223a6d9b3e1ae50d89b14e123a7d81f698126cde66f978d0147fddaadf43422da9d5e941fe1c31e52d6b46be
7
- data.tar.gz: b7656d8962f845ed7ff48afa5a507416dfd0accdac1f8a6ff641a2561b58056fb85db80471cf78244e62a3bbc2df7511246bd1adb5189ebc0137df512b990cbf
6
+ metadata.gz: afcc21912da9832d4c91cd0662418ad08dfb983eea44c617b4b34dc0051e00b73968e052da4be3d0576761953d095d4aa68b678ea0ab590c53b61a19e4be94d7
7
+ data.tar.gz: 5a874c2be4a84432ab1718b2eef3405f2dc26af1a4517c30aca61acbb7b8d96e9532a5b6294dd47f794b5bf9c8a111dbef0c8c8bef79ebe0ad4afa2b646ee796
data/CHANGELOG.md CHANGED
@@ -2,4 +2,10 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.1.1] - 2025-09-28
6
+
7
+ - Export default enum metadata for struct fields.
8
+
9
+ ## [0.1.0] - 2025-09-27
10
+
5
11
  - Initial development release.
data/README.md CHANGED
@@ -52,6 +52,16 @@ outputs:
52
52
 
53
53
  Run it with `bundle exec sorbet-typescript export --config sorbet_typescript.yml`. Any CLI options override the config file.
54
54
 
55
+ #### What gets generated?
56
+
57
+ Each output captures the same Sorbet definitions in a format that is convenient for different consumers:
58
+
59
+ - **Enums JSON (`enums_json`)** – map of fully qualified enum names to metadata with the original name, the simple (namespace-free) name, and an ordered list of values (`name`, `serialized`).
60
+ - **Structs JSON (`structs_json`)** – map of fully qualified struct names to field metadata. Every field entry describes its Sorbet type (`type`, `enum_name`, `struct_name`, etc.), optionality, and—when the Sorbet definition provides defaults—the serialized enum default (`default_enum_*` keys) or literal default (`default`).
61
+ - **TypeScript file (`typescript_file`)** – ambient definitions that mirror the Sorbet types: literal unions for enums and interfaces for structs. Enum-backed fields become unions of the serialized values so the TS compiler enforces the same constraints as Sorbet.
62
+
63
+ These files share the same structure whether you call the CLI or the Ruby API, making it easy to feed the JSON into documentation generators, schemas, or client SDKs.
64
+
55
65
  ### Ruby API
56
66
 
57
67
  If you want to script the export yourself, use the `Exporter` directly:
@@ -263,6 +263,7 @@ module Sorbet::Typescript
263
263
  type_object = prop_info[:type_object] || prop_info[:type]
264
264
  info = analyse_type_object(type_object)
265
265
  info = augment_enum_metadata(info)
266
+ info = augment_default_metadata(info, prop_info)
266
267
  info[:optional] = prop_info[:_tnilable] || prop_info[:fully_optional] || false
267
268
  info
268
269
  end
@@ -483,6 +484,40 @@ module Sorbet::Typescript
483
484
  info
484
485
  end
485
486
 
487
+ sig do
488
+ params(info: T::Hash[Symbol, T.untyped], prop_info: T::Hash[Symbol, T.untyped])
489
+ .returns(T::Hash[Symbol, T.untyped])
490
+ end
491
+ def augment_default_metadata(info, prop_info)
492
+ default = default_from_prop(prop_info)
493
+ return info unless default
494
+
495
+ if default.is_a?(T::Enum)
496
+ info[:default_enum_name] = default.class.name
497
+ info[:default_enum_value] = enum_constant_name(default)
498
+ info[:default_enum_serialized] = default.serialize
499
+ elsif default.is_a?(String) || default.is_a?(Symbol) || default.is_a?(Numeric) || default == true || default == false
500
+ info[:default] = default
501
+ end
502
+
503
+ info
504
+ end
505
+
506
+ sig { params(prop_info: T::Hash[Symbol, T.untyped]).returns(T.untyped) }
507
+ def default_from_prop(prop_info)
508
+ return nil if prop_info[:factory]
509
+
510
+ default = prop_info[:default]
511
+ default = nil if default.is_a?(Proc)
512
+
513
+ if default.nil?
514
+ applier = prop_info[:_t_props_private_apply_default]
515
+ default = applier.default if applier&.respond_to?(:default)
516
+ end
517
+
518
+ default
519
+ end
520
+
486
521
  sig { params(info: T::Hash[Symbol, T.untyped]).returns(T::Array[T::Hash[Symbol, T.untyped]]) }
487
522
  def enum_value_details_for(info)
488
523
  details = info[:enum_value_details]
@@ -4,5 +4,5 @@
4
4
  class Sorbet; end unless defined?(Sorbet)
5
5
 
6
6
  module Sorbet::Typescript
7
- VERSION = "0.1.0"
7
+ VERSION = "0.1.1"
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-typescript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DocSpring