e-invoice-api 0.1.0.pre.alpha.5
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 +7 -0
- data/.ignore +2 -0
- data/CHANGELOG.md +57 -0
- data/README.md +285 -0
- data/SECURITY.md +27 -0
- data/lib/e_invoice_api/client.rb +94 -0
- data/lib/e_invoice_api/errors.rb +192 -0
- data/lib/e_invoice_api/file_part.rb +55 -0
- data/lib/e_invoice_api/internal/documents_number_page.rb +96 -0
- data/lib/e_invoice_api/internal/transport/base_client.rb +555 -0
- data/lib/e_invoice_api/internal/transport/pooled_net_requester.rb +209 -0
- data/lib/e_invoice_api/internal/type/array_of.rb +162 -0
- data/lib/e_invoice_api/internal/type/base_model.rb +482 -0
- data/lib/e_invoice_api/internal/type/base_page.rb +55 -0
- data/lib/e_invoice_api/internal/type/boolean.rb +71 -0
- data/lib/e_invoice_api/internal/type/converter.rb +292 -0
- data/lib/e_invoice_api/internal/type/enum.rb +148 -0
- data/lib/e_invoice_api/internal/type/file_input.rb +103 -0
- data/lib/e_invoice_api/internal/type/hash_of.rb +182 -0
- data/lib/e_invoice_api/internal/type/request_parameters.rb +42 -0
- data/lib/e_invoice_api/internal/type/union.rb +236 -0
- data/lib/e_invoice_api/internal/type/unknown.rb +75 -0
- data/lib/e_invoice_api/internal/util.rb +914 -0
- data/lib/e_invoice_api/internal.rb +20 -0
- data/lib/e_invoice_api/models/certificate.rb +34 -0
- data/lib/e_invoice_api/models/currency_code.rb +28 -0
- data/lib/e_invoice_api/models/document_attachment_create.rb +33 -0
- data/lib/e_invoice_api/models/document_create.rb +521 -0
- data/lib/e_invoice_api/models/document_create_params.rb +14 -0
- data/lib/e_invoice_api/models/document_delete_params.rb +14 -0
- data/lib/e_invoice_api/models/document_delete_response.rb +16 -0
- data/lib/e_invoice_api/models/document_direction.rb +15 -0
- data/lib/e_invoice_api/models/document_response.rb +418 -0
- data/lib/e_invoice_api/models/document_retrieve_params.rb +14 -0
- data/lib/e_invoice_api/models/document_send_params.rb +44 -0
- data/lib/e_invoice_api/models/document_state.rb +18 -0
- data/lib/e_invoice_api/models/document_type.rb +15 -0
- data/lib/e_invoice_api/models/documents/attachment_add_params.rb +22 -0
- data/lib/e_invoice_api/models/documents/attachment_delete_params.rb +22 -0
- data/lib/e_invoice_api/models/documents/attachment_delete_response.rb +18 -0
- data/lib/e_invoice_api/models/documents/attachment_list_params.rb +16 -0
- data/lib/e_invoice_api/models/documents/attachment_list_response.rb +11 -0
- data/lib/e_invoice_api/models/documents/attachment_retrieve_params.rb +22 -0
- data/lib/e_invoice_api/models/documents/document_attachment.rb +44 -0
- data/lib/e_invoice_api/models/documents/ubl_get_params.rb +16 -0
- data/lib/e_invoice_api/models/documents/ubl_get_response.rb +72 -0
- data/lib/e_invoice_api/models/inbox_list_credit_notes_params.rb +30 -0
- data/lib/e_invoice_api/models/inbox_list_invoices_params.rb +30 -0
- data/lib/e_invoice_api/models/inbox_list_params.rb +78 -0
- data/lib/e_invoice_api/models/lookup_retrieve_params.rb +26 -0
- data/lib/e_invoice_api/models/lookup_retrieve_response.rb +491 -0
- data/lib/e_invoice_api/models/outbox_list_draft_documents_params.rb +30 -0
- data/lib/e_invoice_api/models/outbox_list_received_documents_params.rb +78 -0
- data/lib/e_invoice_api/models/paginated_document_response.rb +39 -0
- data/lib/e_invoice_api/models/payment_detail_create.rb +33 -0
- data/lib/e_invoice_api/models/ubl_document_validation.rb +97 -0
- data/lib/e_invoice_api/models/unit_of_measure_code.rb +104 -0
- data/lib/e_invoice_api/models/validate_validate_json_params.rb +14 -0
- data/lib/e_invoice_api/models/validate_validate_peppol_id_params.rb +26 -0
- data/lib/e_invoice_api/models/validate_validate_peppol_id_response.rb +80 -0
- data/lib/e_invoice_api/models/validate_validate_ubl_params.rb +20 -0
- data/lib/e_invoice_api/models/webhook_create_params.rb +32 -0
- data/lib/e_invoice_api/models/webhook_delete_params.rb +14 -0
- data/lib/e_invoice_api/models/webhook_delete_response.rb +18 -0
- data/lib/e_invoice_api/models/webhook_list_params.rb +14 -0
- data/lib/e_invoice_api/models/webhook_list_response.rb +8 -0
- data/lib/e_invoice_api/models/webhook_response.rb +42 -0
- data/lib/e_invoice_api/models/webhook_retrieve_params.rb +14 -0
- data/lib/e_invoice_api/models/webhook_update_params.rb +32 -0
- data/lib/e_invoice_api/models.rb +105 -0
- data/lib/e_invoice_api/request_options.rb +77 -0
- data/lib/e_invoice_api/resources/documents/attachments.rb +109 -0
- data/lib/e_invoice_api/resources/documents/ubl.rb +35 -0
- data/lib/e_invoice_api/resources/documents.rb +188 -0
- data/lib/e_invoice_api/resources/inbox.rb +101 -0
- data/lib/e_invoice_api/resources/lookup.rb +43 -0
- data/lib/e_invoice_api/resources/outbox.rb +76 -0
- data/lib/e_invoice_api/resources/validate.rb +168 -0
- data/lib/e_invoice_api/resources/webhooks.rb +117 -0
- data/lib/e_invoice_api/version.rb +5 -0
- data/lib/e_invoice_api.rb +107 -0
- data/manifest.yaml +15 -0
- data/rbi/e_invoice_api/client.rbi +64 -0
- data/rbi/e_invoice_api/errors.rbi +162 -0
- data/rbi/e_invoice_api/file_part.rbi +37 -0
- data/rbi/e_invoice_api/internal/documents_number_page.rbi +28 -0
- data/rbi/e_invoice_api/internal/transport/base_client.rbi +298 -0
- data/rbi/e_invoice_api/internal/transport/pooled_net_requester.rbi +80 -0
- data/rbi/e_invoice_api/internal/type/array_of.rbi +104 -0
- data/rbi/e_invoice_api/internal/type/base_model.rbi +304 -0
- data/rbi/e_invoice_api/internal/type/base_page.rbi +43 -0
- data/rbi/e_invoice_api/internal/type/boolean.rbi +56 -0
- data/rbi/e_invoice_api/internal/type/converter.rbi +162 -0
- data/rbi/e_invoice_api/internal/type/enum.rbi +82 -0
- data/rbi/e_invoice_api/internal/type/file_input.rbi +59 -0
- data/rbi/e_invoice_api/internal/type/hash_of.rbi +104 -0
- data/rbi/e_invoice_api/internal/type/request_parameters.rbi +31 -0
- data/rbi/e_invoice_api/internal/type/union.rbi +116 -0
- data/rbi/e_invoice_api/internal/type/unknown.rbi +56 -0
- data/rbi/e_invoice_api/internal/util.rbi +487 -0
- data/rbi/e_invoice_api/internal.rbi +18 -0
- data/rbi/e_invoice_api/models/certificate.rbi +54 -0
- data/rbi/e_invoice_api/models/currency_code.rbi +34 -0
- data/rbi/e_invoice_api/models/document_attachment_create.rbi +57 -0
- data/rbi/e_invoice_api/models/document_create.rbi +638 -0
- data/rbi/e_invoice_api/models/document_create_params.rbi +30 -0
- data/rbi/e_invoice_api/models/document_delete_params.rbi +30 -0
- data/rbi/e_invoice_api/models/document_delete_response.rbi +26 -0
- data/rbi/e_invoice_api/models/document_direction.rbi +22 -0
- data/rbi/e_invoice_api/models/document_response.rbi +504 -0
- data/rbi/e_invoice_api/models/document_retrieve_params.rbi +30 -0
- data/rbi/e_invoice_api/models/document_send_params.rbi +65 -0
- data/rbi/e_invoice_api/models/document_state.rbi +24 -0
- data/rbi/e_invoice_api/models/document_type.rbi +21 -0
- data/rbi/e_invoice_api/models/documents/attachment_add_params.rbi +43 -0
- data/rbi/e_invoice_api/models/documents/attachment_delete_params.rbi +43 -0
- data/rbi/e_invoice_api/models/documents/attachment_delete_response.rbi +28 -0
- data/rbi/e_invoice_api/models/documents/attachment_list_params.rbi +34 -0
- data/rbi/e_invoice_api/models/documents/attachment_list_response.rbi +15 -0
- data/rbi/e_invoice_api/models/documents/attachment_retrieve_params.rbi +43 -0
- data/rbi/e_invoice_api/models/documents/document_attachment.rbi +72 -0
- data/rbi/e_invoice_api/models/documents/ubl_get_params.rbi +34 -0
- data/rbi/e_invoice_api/models/documents/ubl_get_response.rbi +97 -0
- data/rbi/e_invoice_api/models/inbox_list_credit_notes_params.rbi +60 -0
- data/rbi/e_invoice_api/models/inbox_list_invoices_params.rbi +60 -0
- data/rbi/e_invoice_api/models/inbox_list_params.rbi +105 -0
- data/rbi/e_invoice_api/models/lookup_retrieve_params.rbi +45 -0
- data/rbi/e_invoice_api/models/lookup_retrieve_response.rbi +852 -0
- data/rbi/e_invoice_api/models/outbox_list_draft_documents_params.rbi +60 -0
- data/rbi/e_invoice_api/models/outbox_list_received_documents_params.rbi +108 -0
- data/rbi/e_invoice_api/models/paginated_document_response.rbi +56 -0
- data/rbi/e_invoice_api/models/payment_detail_create.rbi +56 -0
- data/rbi/e_invoice_api/models/ubl_document_validation.rbi +159 -0
- data/rbi/e_invoice_api/models/unit_of_measure_code.rbi +149 -0
- data/rbi/e_invoice_api/models/validate_validate_json_params.rbi +30 -0
- data/rbi/e_invoice_api/models/validate_validate_peppol_id_params.rbi +45 -0
- data/rbi/e_invoice_api/models/validate_validate_peppol_id_response.rbi +141 -0
- data/rbi/e_invoice_api/models/validate_validate_ubl_params.rbi +41 -0
- data/rbi/e_invoice_api/models/webhook_create_params.rbi +54 -0
- data/rbi/e_invoice_api/models/webhook_delete_params.rbi +30 -0
- data/rbi/e_invoice_api/models/webhook_delete_response.rbi +27 -0
- data/rbi/e_invoice_api/models/webhook_list_params.rbi +27 -0
- data/rbi/e_invoice_api/models/webhook_list_response.rbi +11 -0
- data/rbi/e_invoice_api/models/webhook_response.rbi +57 -0
- data/rbi/e_invoice_api/models/webhook_retrieve_params.rbi +30 -0
- data/rbi/e_invoice_api/models/webhook_update_params.rbi +51 -0
- data/rbi/e_invoice_api/models.rbi +70 -0
- data/rbi/e_invoice_api/request_options.rbi +59 -0
- data/rbi/e_invoice_api/resources/documents/attachments.rbi +58 -0
- data/rbi/e_invoice_api/resources/documents/ubl.rbi +24 -0
- data/rbi/e_invoice_api/resources/documents.rbi +164 -0
- data/rbi/e_invoice_api/resources/inbox.rbi +93 -0
- data/rbi/e_invoice_api/resources/lookup.rbi +31 -0
- data/rbi/e_invoice_api/resources/outbox.rbi +72 -0
- data/rbi/e_invoice_api/resources/validate.rbi +145 -0
- data/rbi/e_invoice_api/resources/webhooks.rbi +72 -0
- data/rbi/e_invoice_api/version.rbi +5 -0
- data/sig/e_invoice_api/client.rbs +36 -0
- data/sig/e_invoice_api/errors.rbs +101 -0
- data/sig/e_invoice_api/file_part.rbs +21 -0
- data/sig/e_invoice_api/internal/documents_number_page.rbs +17 -0
- data/sig/e_invoice_api/internal/transport/base_client.rbs +131 -0
- data/sig/e_invoice_api/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/e_invoice_api/internal/type/array_of.rbs +48 -0
- data/sig/e_invoice_api/internal/type/base_model.rbs +102 -0
- data/sig/e_invoice_api/internal/type/base_page.rbs +24 -0
- data/sig/e_invoice_api/internal/type/boolean.rbs +26 -0
- data/sig/e_invoice_api/internal/type/converter.rbs +56 -0
- data/sig/e_invoice_api/internal/type/enum.rbs +32 -0
- data/sig/e_invoice_api/internal/type/file_input.rbs +25 -0
- data/sig/e_invoice_api/internal/type/hash_of.rbs +48 -0
- data/sig/e_invoice_api/internal/type/request_parameters.rbs +19 -0
- data/sig/e_invoice_api/internal/type/union.rbs +52 -0
- data/sig/e_invoice_api/internal/type/unknown.rbs +26 -0
- data/sig/e_invoice_api/internal/util.rbs +185 -0
- data/sig/e_invoice_api/internal.rbs +9 -0
- data/sig/e_invoice_api/models/certificate.rbs +26 -0
- data/sig/e_invoice_api/models/currency_code.rbs +42 -0
- data/sig/e_invoice_api/models/document_attachment_create.rbs +39 -0
- data/sig/e_invoice_api/models/document_create.rbs +403 -0
- data/sig/e_invoice_api/models/document_create_params.rbs +15 -0
- data/sig/e_invoice_api/models/document_delete_params.rbs +15 -0
- data/sig/e_invoice_api/models/document_delete_response.rbs +13 -0
- data/sig/e_invoice_api/models/document_direction.rbs +14 -0
- data/sig/e_invoice_api/models/document_response.rbs +358 -0
- data/sig/e_invoice_api/models/document_retrieve_params.rbs +15 -0
- data/sig/e_invoice_api/models/document_send_params.rbs +46 -0
- data/sig/e_invoice_api/models/document_state.rbs +17 -0
- data/sig/e_invoice_api/models/document_type.rbs +14 -0
- data/sig/e_invoice_api/models/documents/attachment_add_params.rbs +26 -0
- data/sig/e_invoice_api/models/documents/attachment_delete_params.rbs +26 -0
- data/sig/e_invoice_api/models/documents/attachment_delete_response.rbs +15 -0
- data/sig/e_invoice_api/models/documents/attachment_list_params.rbs +17 -0
- data/sig/e_invoice_api/models/documents/attachment_list_response.rbs +10 -0
- data/sig/e_invoice_api/models/documents/attachment_retrieve_params.rbs +26 -0
- data/sig/e_invoice_api/models/documents/document_attachment.rbs +48 -0
- data/sig/e_invoice_api/models/documents/ubl_get_params.rbs +17 -0
- data/sig/e_invoice_api/models/documents/ubl_get_response.rbs +69 -0
- data/sig/e_invoice_api/models/inbox_list_credit_notes_params.rbs +32 -0
- data/sig/e_invoice_api/models/inbox_list_invoices_params.rbs +32 -0
- data/sig/e_invoice_api/models/inbox_list_params.rbs +65 -0
- data/sig/e_invoice_api/models/lookup_retrieve_params.rbs +23 -0
- data/sig/e_invoice_api/models/lookup_retrieve_response.rbs +365 -0
- data/sig/e_invoice_api/models/outbox_list_draft_documents_params.rbs +32 -0
- data/sig/e_invoice_api/models/outbox_list_received_documents_params.rbs +65 -0
- data/sig/e_invoice_api/models/paginated_document_response.rbs +40 -0
- data/sig/e_invoice_api/models/payment_detail_create.rbs +35 -0
- data/sig/e_invoice_api/models/ubl_document_validation.rbs +98 -0
- data/sig/e_invoice_api/models/unit_of_measure_code.rbs +192 -0
- data/sig/e_invoice_api/models/validate_validate_json_params.rbs +15 -0
- data/sig/e_invoice_api/models/validate_validate_peppol_id_params.rbs +23 -0
- data/sig/e_invoice_api/models/validate_validate_peppol_id_response.rbs +65 -0
- data/sig/e_invoice_api/models/validate_validate_ubl_params.rbs +24 -0
- data/sig/e_invoice_api/models/webhook_create_params.rbs +34 -0
- data/sig/e_invoice_api/models/webhook_delete_params.rbs +15 -0
- data/sig/e_invoice_api/models/webhook_delete_response.rbs +13 -0
- data/sig/e_invoice_api/models/webhook_list_params.rbs +15 -0
- data/sig/e_invoice_api/models/webhook_list_response.rbs +7 -0
- data/sig/e_invoice_api/models/webhook_response.rbs +42 -0
- data/sig/e_invoice_api/models/webhook_retrieve_params.rbs +15 -0
- data/sig/e_invoice_api/models/webhook_update_params.rbs +32 -0
- data/sig/e_invoice_api/models.rbs +65 -0
- data/sig/e_invoice_api/request_options.rbs +36 -0
- data/sig/e_invoice_api/resources/documents/attachments.rbs +32 -0
- data/sig/e_invoice_api/resources/documents/ubl.rbs +14 -0
- data/sig/e_invoice_api/resources/documents.rbs +76 -0
- data/sig/e_invoice_api/resources/inbox.rbs +31 -0
- data/sig/e_invoice_api/resources/lookup.rbs +12 -0
- data/sig/e_invoice_api/resources/outbox.rbs +25 -0
- data/sig/e_invoice_api/resources/validate.rbs +62 -0
- data/sig/e_invoice_api/resources/webhooks.rbs +36 -0
- data/sig/e_invoice_api/version.rbs +3 -0
- metadata +290 -0
@@ -0,0 +1,182 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EInvoiceAPI
|
4
|
+
module Internal
|
5
|
+
module Type
|
6
|
+
# @api private
|
7
|
+
#
|
8
|
+
# @abstract
|
9
|
+
#
|
10
|
+
# @generic Elem
|
11
|
+
#
|
12
|
+
# Hash of items of a given type.
|
13
|
+
class HashOf
|
14
|
+
include EInvoiceAPI::Internal::Type::Converter
|
15
|
+
include EInvoiceAPI::Internal::Util::SorbetRuntimeSupport
|
16
|
+
|
17
|
+
private_class_method :new
|
18
|
+
|
19
|
+
# @overload [](type_info, spec = {})
|
20
|
+
#
|
21
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, EInvoiceAPI::Internal::Type::Converter, Class]
|
22
|
+
#
|
23
|
+
# @param spec [Hash{Symbol=>Object}] .
|
24
|
+
#
|
25
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
26
|
+
#
|
27
|
+
# @option spec [Proc] :enum
|
28
|
+
#
|
29
|
+
# @option spec [Proc] :union
|
30
|
+
#
|
31
|
+
# @option spec [Boolean] :"nil?"
|
32
|
+
#
|
33
|
+
# @return [self]
|
34
|
+
def self.[](...) = new(...)
|
35
|
+
|
36
|
+
# @api public
|
37
|
+
#
|
38
|
+
# @param other [Object]
|
39
|
+
#
|
40
|
+
# @return [Boolean]
|
41
|
+
def ===(other)
|
42
|
+
type = item_type
|
43
|
+
case other
|
44
|
+
in Hash
|
45
|
+
other.all? do |key, val|
|
46
|
+
case [key, val]
|
47
|
+
in [Symbol | String, ^type]
|
48
|
+
true
|
49
|
+
else
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @api public
|
59
|
+
#
|
60
|
+
# @param other [Object]
|
61
|
+
#
|
62
|
+
# @return [Boolean]
|
63
|
+
def ==(other)
|
64
|
+
# rubocop:disable Layout/LineLength
|
65
|
+
other.is_a?(EInvoiceAPI::Internal::Type::HashOf) && other.nilable? == nilable? && other.item_type == item_type
|
66
|
+
# rubocop:enable Layout/LineLength
|
67
|
+
end
|
68
|
+
|
69
|
+
# @api public
|
70
|
+
#
|
71
|
+
# @return [Integer]
|
72
|
+
def hash = [self.class, item_type].hash
|
73
|
+
|
74
|
+
# @api private
|
75
|
+
#
|
76
|
+
# @param value [Hash{Object=>Object}, Object]
|
77
|
+
#
|
78
|
+
# @param state [Hash{Symbol=>Object}] .
|
79
|
+
#
|
80
|
+
# @option state [Boolean, :strong] :strictness
|
81
|
+
#
|
82
|
+
# @option state [Hash{Symbol=>Object}] :exactness
|
83
|
+
#
|
84
|
+
# @option state [Integer] :branched
|
85
|
+
#
|
86
|
+
# @return [Hash{Symbol=>Object}, Object]
|
87
|
+
def coerce(value, state:)
|
88
|
+
exactness = state.fetch(:exactness)
|
89
|
+
|
90
|
+
unless value.is_a?(Hash)
|
91
|
+
exactness[:no] += 1
|
92
|
+
return value
|
93
|
+
end
|
94
|
+
|
95
|
+
target = item_type
|
96
|
+
exactness[:yes] += 1
|
97
|
+
value
|
98
|
+
.to_h do |key, val|
|
99
|
+
k = key.is_a?(String) ? key.to_sym : key
|
100
|
+
v =
|
101
|
+
case [nilable?, val]
|
102
|
+
in [true, nil]
|
103
|
+
exactness[:yes] += 1
|
104
|
+
nil
|
105
|
+
else
|
106
|
+
EInvoiceAPI::Internal::Type::Converter.coerce(target, val, state: state)
|
107
|
+
end
|
108
|
+
|
109
|
+
exactness[:no] += 1 unless k.is_a?(Symbol)
|
110
|
+
[k, v]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# @api private
|
115
|
+
#
|
116
|
+
# @param value [Hash{Object=>Object}, Object]
|
117
|
+
#
|
118
|
+
# @param state [Hash{Symbol=>Object}] .
|
119
|
+
#
|
120
|
+
# @option state [Boolean] :can_retry
|
121
|
+
#
|
122
|
+
# @return [Hash{Symbol=>Object}, Object]
|
123
|
+
def dump(value, state:)
|
124
|
+
target = item_type
|
125
|
+
if value.is_a?(Hash)
|
126
|
+
value.transform_values do
|
127
|
+
EInvoiceAPI::Internal::Type::Converter.dump(target, _1, state: state)
|
128
|
+
end
|
129
|
+
else
|
130
|
+
super
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# @api private
|
135
|
+
#
|
136
|
+
# @return [Object]
|
137
|
+
def to_sorbet_type
|
138
|
+
T::Hash[EInvoiceAPI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(item_type)]
|
139
|
+
end
|
140
|
+
|
141
|
+
# @api private
|
142
|
+
#
|
143
|
+
# @return [generic<Elem>]
|
144
|
+
protected def item_type = @item_type_fn.call
|
145
|
+
|
146
|
+
# @api private
|
147
|
+
#
|
148
|
+
# @return [Boolean]
|
149
|
+
protected def nilable? = @nilable
|
150
|
+
|
151
|
+
# @api private
|
152
|
+
#
|
153
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, EInvoiceAPI::Internal::Type::Converter, Class]
|
154
|
+
#
|
155
|
+
# @param spec [Hash{Symbol=>Object}] .
|
156
|
+
#
|
157
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
158
|
+
#
|
159
|
+
# @option spec [Proc] :enum
|
160
|
+
#
|
161
|
+
# @option spec [Proc] :union
|
162
|
+
#
|
163
|
+
# @option spec [Boolean] :"nil?"
|
164
|
+
def initialize(type_info, spec = {})
|
165
|
+
@item_type_fn = EInvoiceAPI::Internal::Type::Converter.type_info(type_info || spec)
|
166
|
+
@nilable = spec.fetch(:nil?, false)
|
167
|
+
end
|
168
|
+
|
169
|
+
# @api private
|
170
|
+
#
|
171
|
+
# @param depth [Integer]
|
172
|
+
#
|
173
|
+
# @return [String]
|
174
|
+
def inspect(depth: 0)
|
175
|
+
items = EInvoiceAPI::Internal::Type::Converter.inspect(item_type, depth: depth.succ)
|
176
|
+
|
177
|
+
"#{self.class}[#{[items, nilable? ? 'nil' : nil].compact.join(' | ')}]"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EInvoiceAPI
|
4
|
+
module Internal
|
5
|
+
module Type
|
6
|
+
# @api private
|
7
|
+
module RequestParameters
|
8
|
+
# @!attribute request_options
|
9
|
+
# Options to specify HTTP behaviour for this request.
|
10
|
+
#
|
11
|
+
# @return [EInvoiceAPI::RequestOptions, Hash{Symbol=>Object}]
|
12
|
+
|
13
|
+
# @param mod [Module]
|
14
|
+
def self.included(mod)
|
15
|
+
raise ArgumentError.new(mod) unless mod <= EInvoiceAPI::Internal::Type::BaseModel
|
16
|
+
|
17
|
+
mod.optional(:request_options, EInvoiceAPI::RequestOptions)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @api private
|
21
|
+
module Converter
|
22
|
+
# @api private
|
23
|
+
#
|
24
|
+
# @param params [Object]
|
25
|
+
#
|
26
|
+
# @return [Array(Object, Hash{Symbol=>Object})]
|
27
|
+
def dump_request(params)
|
28
|
+
state = {can_retry: true}
|
29
|
+
case (dumped = dump(params, state: state))
|
30
|
+
in Hash
|
31
|
+
options = EInvoiceAPI::Internal::Util.coerce_hash!(dumped[:request_options]).to_h
|
32
|
+
request_options = state.fetch(:can_retry) ? options : {**options, max_retries: 0}
|
33
|
+
[dumped.except(:request_options), request_options]
|
34
|
+
else
|
35
|
+
[dumped, nil]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EInvoiceAPI
|
4
|
+
module Internal
|
5
|
+
module Type
|
6
|
+
# @api private
|
7
|
+
module Union
|
8
|
+
include EInvoiceAPI::Internal::Type::Converter
|
9
|
+
include EInvoiceAPI::Internal::Util::SorbetRuntimeSupport
|
10
|
+
|
11
|
+
# @api private
|
12
|
+
#
|
13
|
+
# All of the specified variant info for this union.
|
14
|
+
#
|
15
|
+
# @return [Array<Array(Symbol, Proc)>]
|
16
|
+
private def known_variants = (@known_variants ||= [])
|
17
|
+
|
18
|
+
# @api private
|
19
|
+
#
|
20
|
+
# @return [Array<Array(Symbol, Object)>]
|
21
|
+
protected def derefed_variants
|
22
|
+
known_variants.map { |key, variant_fn| [key, variant_fn.call] }
|
23
|
+
end
|
24
|
+
|
25
|
+
# All of the specified variants for this union.
|
26
|
+
#
|
27
|
+
# @return [Array<Object>]
|
28
|
+
def variants = derefed_variants.map(&:last)
|
29
|
+
|
30
|
+
# @api private
|
31
|
+
#
|
32
|
+
# @param property [Symbol]
|
33
|
+
private def discriminator(property)
|
34
|
+
case property
|
35
|
+
in Symbol
|
36
|
+
@discriminator = property
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
# @param key [Symbol, Hash{Symbol=>Object}, Proc, EInvoiceAPI::Internal::Type::Converter, Class]
|
43
|
+
#
|
44
|
+
# @param spec [Hash{Symbol=>Object}, Proc, EInvoiceAPI::Internal::Type::Converter, Class] .
|
45
|
+
#
|
46
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
47
|
+
#
|
48
|
+
# @option spec [Proc] :enum
|
49
|
+
#
|
50
|
+
# @option spec [Proc] :union
|
51
|
+
#
|
52
|
+
# @option spec [Boolean] :"nil?"
|
53
|
+
private def variant(key, spec = nil)
|
54
|
+
variant_info =
|
55
|
+
case key
|
56
|
+
in Symbol
|
57
|
+
[key, EInvoiceAPI::Internal::Type::Converter.type_info(spec)]
|
58
|
+
in Proc | EInvoiceAPI::Internal::Type::Converter | Class | Hash
|
59
|
+
[nil, EInvoiceAPI::Internal::Type::Converter.type_info(key)]
|
60
|
+
end
|
61
|
+
|
62
|
+
known_variants << variant_info
|
63
|
+
end
|
64
|
+
|
65
|
+
# @api private
|
66
|
+
#
|
67
|
+
# @param value [Object]
|
68
|
+
#
|
69
|
+
# @return [EInvoiceAPI::Internal::Type::Converter, Class, nil]
|
70
|
+
private def resolve_variant(value)
|
71
|
+
case [@discriminator, value]
|
72
|
+
in [_, EInvoiceAPI::Internal::Type::BaseModel]
|
73
|
+
value.class
|
74
|
+
in [Symbol, Hash]
|
75
|
+
key = value.fetch(@discriminator) do
|
76
|
+
value.fetch(@discriminator.to_s, EInvoiceAPI::Internal::OMIT)
|
77
|
+
end
|
78
|
+
|
79
|
+
return nil if key == EInvoiceAPI::Internal::OMIT
|
80
|
+
|
81
|
+
key = key.to_sym if key.is_a?(String)
|
82
|
+
known_variants.find { |k,| k == key }&.last&.call
|
83
|
+
else
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# rubocop:disable Style/HashEachMethods
|
89
|
+
# rubocop:disable Style/CaseEquality
|
90
|
+
|
91
|
+
# @api public
|
92
|
+
#
|
93
|
+
# @param other [Object]
|
94
|
+
#
|
95
|
+
# @return [Boolean]
|
96
|
+
def ===(other)
|
97
|
+
known_variants.any? do |_, variant_fn|
|
98
|
+
variant_fn.call === other
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# @api public
|
103
|
+
#
|
104
|
+
# @param other [Object]
|
105
|
+
#
|
106
|
+
# @return [Boolean]
|
107
|
+
def ==(other)
|
108
|
+
EInvoiceAPI::Internal::Type::Union === other && other.derefed_variants == derefed_variants
|
109
|
+
end
|
110
|
+
|
111
|
+
# @api public
|
112
|
+
#
|
113
|
+
# @return [Integer]
|
114
|
+
def hash = variants.hash
|
115
|
+
|
116
|
+
# @api private
|
117
|
+
#
|
118
|
+
# @param value [Object]
|
119
|
+
#
|
120
|
+
# @param state [Hash{Symbol=>Object}] .
|
121
|
+
#
|
122
|
+
# @option state [Boolean, :strong] :strictness
|
123
|
+
#
|
124
|
+
# @option state [Hash{Symbol=>Object}] :exactness
|
125
|
+
#
|
126
|
+
# @option state [Integer] :branched
|
127
|
+
#
|
128
|
+
# @return [Object]
|
129
|
+
def coerce(value, state:)
|
130
|
+
if (target = resolve_variant(value))
|
131
|
+
return EInvoiceAPI::Internal::Type::Converter.coerce(target, value, state: state)
|
132
|
+
end
|
133
|
+
|
134
|
+
strictness = state.fetch(:strictness)
|
135
|
+
exactness = state.fetch(:exactness)
|
136
|
+
state[:strictness] = strictness == :strong ? true : strictness
|
137
|
+
|
138
|
+
alternatives = []
|
139
|
+
known_variants.each do |_, variant_fn|
|
140
|
+
target = variant_fn.call
|
141
|
+
exact = state[:exactness] = {yes: 0, no: 0, maybe: 0}
|
142
|
+
state[:branched] += 1
|
143
|
+
|
144
|
+
coerced = EInvoiceAPI::Internal::Type::Converter.coerce(target, value, state: state)
|
145
|
+
yes, no, maybe = exact.values
|
146
|
+
if (no + maybe).zero? || (!strictness && yes.positive?)
|
147
|
+
exact.each { exactness[_1] += _2 }
|
148
|
+
state[:exactness] = exactness
|
149
|
+
return coerced
|
150
|
+
elsif maybe.positive?
|
151
|
+
alternatives << [[-yes, -maybe, no], exact, coerced]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
case alternatives.sort_by(&:first)
|
156
|
+
in []
|
157
|
+
exactness[:no] += 1
|
158
|
+
if strictness == :strong
|
159
|
+
message = "no possible conversion of #{value.class} into a variant of #{target.inspect}"
|
160
|
+
raise ArgumentError.new(message)
|
161
|
+
end
|
162
|
+
value
|
163
|
+
in [[_, exact, coerced], *]
|
164
|
+
exact.each { exactness[_1] += _2 }
|
165
|
+
coerced
|
166
|
+
end
|
167
|
+
.tap { state[:exactness] = exactness }
|
168
|
+
ensure
|
169
|
+
state[:strictness] = strictness
|
170
|
+
end
|
171
|
+
|
172
|
+
# @api private
|
173
|
+
#
|
174
|
+
# @param value [Object]
|
175
|
+
#
|
176
|
+
# @param state [Hash{Symbol=>Object}] .
|
177
|
+
#
|
178
|
+
# @option state [Boolean] :can_retry
|
179
|
+
#
|
180
|
+
# @return [Object]
|
181
|
+
def dump(value, state:)
|
182
|
+
if (target = resolve_variant(value))
|
183
|
+
return EInvoiceAPI::Internal::Type::Converter.dump(target, value, state: state)
|
184
|
+
end
|
185
|
+
|
186
|
+
known_variants.each do
|
187
|
+
target = _2.call
|
188
|
+
if target === value
|
189
|
+
return EInvoiceAPI::Internal::Type::Converter.dump(
|
190
|
+
target,
|
191
|
+
value,
|
192
|
+
state: state
|
193
|
+
)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
super
|
198
|
+
end
|
199
|
+
|
200
|
+
# @api private
|
201
|
+
#
|
202
|
+
# @return [Object]
|
203
|
+
def to_sorbet_type
|
204
|
+
types = variants.map { EInvoiceAPI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
|
205
|
+
case types
|
206
|
+
in []
|
207
|
+
T.noreturn
|
208
|
+
in [type]
|
209
|
+
type
|
210
|
+
else
|
211
|
+
T.any(*types)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# rubocop:enable Style/CaseEquality
|
216
|
+
# rubocop:enable Style/HashEachMethods
|
217
|
+
|
218
|
+
# @api private
|
219
|
+
#
|
220
|
+
# @param depth [Integer]
|
221
|
+
#
|
222
|
+
# @return [String]
|
223
|
+
def inspect(depth: 0)
|
224
|
+
if depth.positive?
|
225
|
+
return is_a?(Module) ? super() : self.class.name
|
226
|
+
end
|
227
|
+
|
228
|
+
members = variants.map { EInvoiceAPI::Internal::Type::Converter.inspect(_1, depth: depth.succ) }
|
229
|
+
prefix = is_a?(Module) ? name : self.class.name
|
230
|
+
|
231
|
+
"#{prefix}[#{members.join(' | ')}]"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EInvoiceAPI
|
4
|
+
module Internal
|
5
|
+
module Type
|
6
|
+
# @api private
|
7
|
+
#
|
8
|
+
# @abstract
|
9
|
+
#
|
10
|
+
# When we don't know what to expect for the value.
|
11
|
+
class Unknown
|
12
|
+
extend EInvoiceAPI::Internal::Type::Converter
|
13
|
+
extend EInvoiceAPI::Internal::Util::SorbetRuntimeSupport
|
14
|
+
|
15
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
16
|
+
|
17
|
+
private_class_method :new
|
18
|
+
|
19
|
+
# @api public
|
20
|
+
#
|
21
|
+
# @param other [Object]
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
24
|
+
def self.===(other) = true
|
25
|
+
|
26
|
+
# @api public
|
27
|
+
#
|
28
|
+
# @param other [Object]
|
29
|
+
#
|
30
|
+
# @return [Boolean]
|
31
|
+
def self.==(other) = other.is_a?(Class) && other <= EInvoiceAPI::Internal::Type::Unknown
|
32
|
+
|
33
|
+
class << self
|
34
|
+
# @api private
|
35
|
+
#
|
36
|
+
# @param value [Object]
|
37
|
+
#
|
38
|
+
# @param state [Hash{Symbol=>Object}] .
|
39
|
+
#
|
40
|
+
# @option state [Boolean, :strong] :strictness
|
41
|
+
#
|
42
|
+
# @option state [Hash{Symbol=>Object}] :exactness
|
43
|
+
#
|
44
|
+
# @option state [Integer] :branched
|
45
|
+
#
|
46
|
+
# @return [Object]
|
47
|
+
def coerce(value, state:)
|
48
|
+
state.fetch(:exactness)[:yes] += 1
|
49
|
+
value
|
50
|
+
end
|
51
|
+
|
52
|
+
# @!method dump(value, state:)
|
53
|
+
# @api private
|
54
|
+
#
|
55
|
+
# @param value [Object]
|
56
|
+
#
|
57
|
+
# @param state [Hash{Symbol=>Object}] .
|
58
|
+
#
|
59
|
+
# @option state [Boolean] :can_retry
|
60
|
+
#
|
61
|
+
# @return [Object]
|
62
|
+
|
63
|
+
# @api private
|
64
|
+
#
|
65
|
+
# @return [Object]
|
66
|
+
def to_sorbet_type
|
67
|
+
T.anything
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|