@czlab/zod-to-proto 0.1.0-beta.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.
Files changed (89) hide show
  1. package/.dist/index.cjs +2563 -0
  2. package/.dist/index.d.ts +83 -0
  3. package/.dist/index.mjs +2530 -0
  4. package/.dist/src/core/asserts/not_empty_array.d.ts +3 -0
  5. package/.dist/src/core/asserts/one_element_array.d.ts +3 -0
  6. package/.dist/src/core/types/check_tuple.d.ts +23 -0
  7. package/.dist/src/core/types/deep_read_only.d.ts +3 -0
  8. package/.dist/src/core/types/prettify.d.ts +3 -0
  9. package/.dist/src/core/types/tuplify_union.d.ts +6 -0
  10. package/.dist/src/core/types/type_debugging_error.d.ts +3 -0
  11. package/.dist/src/file/classes/content_matter.d.ts +43 -0
  12. package/.dist/src/file/classes/file_builder.d.ts +6 -0
  13. package/.dist/src/file/types/content_matter.d.ts +22 -0
  14. package/.dist/src/plugin/classes/zod_deprecated_enum_conversion_transformer.d.ts +7 -0
  15. package/.dist/src/plugin/classes/zod_deprecated_field_conversion_transformer.d.ts +7 -0
  16. package/.dist/src/plugin/classes/zod_deprecated_message_conversion_transformer.d.ts +7 -0
  17. package/.dist/src/plugin/classes/zod_deprecated_one_of_field_conversion_transformer.d.ts +7 -0
  18. package/.dist/src/plugin/classes/zod_required_field_conversion_transformer.d.ts +7 -0
  19. package/.dist/src/plugin/classes/zod_required_one_of_field_conversion_transformer.d.ts +7 -0
  20. package/.dist/src/plugin/helpers/get_full_transformers.d.ts +2 -0
  21. package/.dist/src/plugin/types/buf_validate.d.ts +57 -0
  22. package/.dist/src/plugin/types/global.d.ts +22 -0
  23. package/.dist/src/plugin/types/google_api_annotations.d.ts +105 -0
  24. package/.dist/src/plugin/types/google_protobuf.d.ts +11 -0
  25. package/.dist/src/proto3_definition/types/dynamic_size.d.ts +34 -0
  26. package/.dist/src/proto3_definition/types/extension.d.ts +21 -0
  27. package/.dist/src/proto3_definition/types/fields.d.ts +57 -0
  28. package/.dist/src/proto3_definition/types/file.d.ts +22 -0
  29. package/.dist/src/proto3_definition/types/functions.d.ts +24 -0
  30. package/.dist/src/proto3_definition/types/get_new_params.d.ts +2 -0
  31. package/.dist/src/proto3_definition/types/messages.d.ts +33 -0
  32. package/.dist/src/proto3_definition/types/scalar_standalones.d.ts +46 -0
  33. package/.dist/src/proto3_definition/types/scalars.d.ts +28 -0
  34. package/.dist/src/proto3_definition/types/service.d.ts +22 -0
  35. package/.dist/src/proto3_definition/types/types.d.ts +41 -0
  36. package/.dist/src/proto3_definition/types/with_internal_name.d.ts +5 -0
  37. package/.dist/src/proto3_processor/classes/proto3_comment_processor.d.ts +6 -0
  38. package/.dist/src/proto3_processor/classes/proto3_extension_value_processor.d.ts +7 -0
  39. package/.dist/src/proto3_processor/classes/proto3_field_extension_processor.d.ts +7 -0
  40. package/.dist/src/proto3_processor/classes/proto3_field_processor.d.ts +12 -0
  41. package/.dist/src/proto3_processor/classes/proto3_file_processor.d.ts +10 -0
  42. package/.dist/src/proto3_processor/classes/proto3_function_processor.d.ts +9 -0
  43. package/.dist/src/proto3_processor/classes/proto3_import_processor.d.ts +7 -0
  44. package/.dist/src/proto3_processor/classes/proto3_message_processor.d.ts +9 -0
  45. package/.dist/src/proto3_processor/classes/proto3_record_extension_processor.d.ts +7 -0
  46. package/.dist/src/proto3_processor/classes/proto3_service_processor.d.ts +9 -0
  47. package/.dist/src/usage/helpers/zodToProto.d.ts +3 -0
  48. package/.dist/src/usage/types/file.d.ts +14 -0
  49. package/.dist/src/usage/types/functions.d.ts +13 -0
  50. package/.dist/src/usage/types/message.d.ts +8 -0
  51. package/.dist/src/usage/types/services.d.ts +11 -0
  52. package/.dist/src/usage/types/settings.d.ts +7 -0
  53. package/.dist/src/zod/helpers/zod_one_of_union.d.ts +19 -0
  54. package/.dist/src/zod/types/zod_one_of_union.d.ts +13 -0
  55. package/.dist/src/zod_converter/asserts/any_zod_message_field_type.d.ts +5 -0
  56. package/.dist/src/zod_converter/asserts/zod_compatible_type.d.ts +5 -0
  57. package/.dist/src/zod_converter/asserts/zod_format.d.ts +8 -0
  58. package/.dist/src/zod_converter/asserts/zod_map_value.d.ts +6 -0
  59. package/.dist/src/zod_converter/asserts/zod_message_field_type.d.ts +6 -0
  60. package/.dist/src/zod_converter/asserts/zod_object.d.ts +5 -0
  61. package/.dist/src/zod_converter/asserts/zod_repeated_inner_type.d.ts +6 -0
  62. package/.dist/src/zod_converter/asserts/zod_scalar_type.d.ts +6 -0
  63. package/.dist/src/zod_converter/classes/zod_dynamic_size_converter.d.ts +9 -0
  64. package/.dist/src/zod_converter/classes/zod_message_converter.d.ts +9 -0
  65. package/.dist/src/zod_converter/classes/zod_message_field_converter.d.ts +12 -0
  66. package/.dist/src/zod_converter/classes/zod_message_field_type_converter.d.ts +19 -0
  67. package/.dist/src/zod_converter/classes/zod_message_one_of_field_converter.d.ts +12 -0
  68. package/.dist/src/zod_converter/classes/zod_scalar_converter.d.ts +6 -0
  69. package/.dist/src/zod_converter/helpers/get_empty_transformers.d.ts +2 -0
  70. package/.dist/src/zod_converter/helpers/get_zod_schema_comments.d.ts +2 -0
  71. package/.dist/src/zod_converter/helpers/is_format_compatible.d.ts +5 -0
  72. package/.dist/src/zod_converter/helpers/is_zod_literal.d.ts +3 -0
  73. package/.dist/src/zod_converter/helpers/is_zod_literal_not_nullish_values.d.ts +10 -0
  74. package/.dist/src/zod_converter/helpers/is_zod_object.d.ts +3 -0
  75. package/.dist/src/zod_converter/helpers/is_zod_schema_deprecated.d.ts +2 -0
  76. package/.dist/src/zod_converter/helpers/is_zod_schema_optional.d.ts +2 -0
  77. package/.dist/src/zod_converter/types/check.d.ts +80 -0
  78. package/.dist/src/zod_converter/types/dynamic_size.d.ts +39 -0
  79. package/.dist/src/zod_converter/types/error.d.ts +7 -0
  80. package/.dist/src/zod_converter/types/literal.d.ts +1 -0
  81. package/.dist/src/zod_converter/types/messages.d.ts +48 -0
  82. package/.dist/src/zod_converter/types/passthroughs.d.ts +32 -0
  83. package/.dist/src/zod_converter/types/scalars.d.ts +16 -0
  84. package/.dist/src/zod_converter/types/some_type.d.ts +76 -0
  85. package/.dist/src/zod_converter/types/transformers.d.ts +18 -0
  86. package/.dist/src/zod_converter/types/zod_type_value.d.ts +6 -0
  87. package/LICENSE +21 -0
  88. package/README.md +525 -0
  89. package/package.json +85 -0
@@ -0,0 +1,2563 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ $FileContentMatter: () => $FileContentMatter,
34
+ AnyProto3Type: () => AnyProto3Type,
35
+ AnyZodMessage: () => AnyZodMessage,
36
+ AnyZodMessageFieldType: () => AnyZodMessageFieldType,
37
+ AnyZodMessageFieldTypeTuple: () => AnyZodMessageFieldTypeTuple,
38
+ AnyZodMessageTypeTuple: () => AnyZodMessageTypeTuple,
39
+ CompatibleZodTypeTuple: () => CompatibleZodTypeTuple,
40
+ FileBuilder: () => FileBuilder,
41
+ Proto3BoolType: () => Proto3BoolType,
42
+ Proto3BytesType: () => Proto3BytesType,
43
+ Proto3CommentProcessor: () => Proto3CommentProcessor,
44
+ Proto3Deprecated: () => Proto3Deprecated,
45
+ Proto3DoubleType: () => Proto3DoubleType,
46
+ Proto3Empty: () => Proto3Empty,
47
+ Proto3Enum: () => Proto3Enum,
48
+ Proto3EnumField: () => Proto3EnumField,
49
+ Proto3Extension: () => Proto3Extension,
50
+ Proto3ExtensionValueProcessor: () => Proto3ExtensionValueProcessor,
51
+ Proto3FieldExtensionProcessor: () => Proto3FieldExtensionProcessor,
52
+ Proto3FieldProcessor: () => Proto3FieldProcessor,
53
+ Proto3File: () => Proto3File,
54
+ Proto3FileProcessor: () => Proto3FileProcessor,
55
+ Proto3Fixed32Type: () => Proto3Fixed32Type,
56
+ Proto3Fixed64Type: () => Proto3Fixed64Type,
57
+ Proto3FloatType: () => Proto3FloatType,
58
+ Proto3FunctionProcessor: () => Proto3FunctionProcessor,
59
+ Proto3GlobalType: () => Proto3GlobalType,
60
+ Proto3HttpAnnotation: () => Proto3HttpAnnotation,
61
+ Proto3ImportProcessor: () => Proto3ImportProcessor,
62
+ Proto3ImportedType: () => Proto3ImportedType,
63
+ Proto3Int32Type: () => Proto3Int32Type,
64
+ Proto3Int64Type: () => Proto3Int64Type,
65
+ Proto3MapType: () => Proto3MapType,
66
+ Proto3Message: () => Proto3Message,
67
+ Proto3MessageField: () => Proto3MessageField,
68
+ Proto3MessageOneOfField: () => Proto3MessageOneOfField,
69
+ Proto3MessageOneOfFieldSubField: () => Proto3MessageOneOfFieldSubField,
70
+ Proto3MessageProcessor: () => Proto3MessageProcessor,
71
+ Proto3OptionalState: () => Proto3OptionalState,
72
+ Proto3RawFile: () => Proto3RawFile,
73
+ Proto3RecordExtensionProcessor: () => Proto3RecordExtensionProcessor,
74
+ Proto3RepeatedType: () => Proto3RepeatedType,
75
+ Proto3RpcFunction: () => Proto3RpcFunction,
76
+ Proto3RpcRawFunction: () => Proto3RpcRawFunction,
77
+ Proto3RpcRawMessage: () => Proto3RpcRawMessage,
78
+ Proto3RpcRawService: () => Proto3RpcRawService,
79
+ Proto3RpcService: () => Proto3RpcService,
80
+ Proto3SFixed32Type: () => Proto3SFixed32Type,
81
+ Proto3SFixed64Type: () => Proto3SFixed64Type,
82
+ Proto3SInt32Type: () => Proto3SInt32Type,
83
+ Proto3SInt64Type: () => Proto3SInt64Type,
84
+ Proto3ServiceProcessor: () => Proto3ServiceProcessor,
85
+ Proto3StringType: () => Proto3StringType,
86
+ Proto3UInt32Type: () => Proto3UInt32Type,
87
+ Proto3UInt64Type: () => Proto3UInt64Type,
88
+ Proto3ValidateFieldAnnotation: () => Proto3ValidateFieldAnnotation,
89
+ Proto3ValidateOneOfAnnotation: () => Proto3ValidateOneOfAnnotation,
90
+ SchemaError: () => SchemaError,
91
+ ZodCompatibleType: () => ZodCompatibleType,
92
+ ZodDeprecatedEnumConversionTransformer: () => ZodDeprecatedEnumConversionTransformer,
93
+ ZodDeprecatedFieldConversionTransformer: () => ZodDeprecatedFieldConversionTransformer,
94
+ ZodDeprecatedMessageConversionTransformer: () => ZodDeprecatedMessageConversionTransformer,
95
+ ZodDeprecatedOneOfFieldConversionTransformer: () => ZodDeprecatedOneOfFieldConversionTransformer,
96
+ ZodDynamicSizeConverter: () => ZodDynamicSizeConverter,
97
+ ZodDynamicSizeType: () => ZodDynamicSizeType,
98
+ ZodDynamicSizeTypeTuple: () => ZodDynamicSizeTypeTuple,
99
+ ZodMapValueType: () => ZodMapValueType,
100
+ ZodMapValueTypeTuple: () => ZodMapValueTypeTuple,
101
+ ZodMessageConverter: () => ZodMessageConverter,
102
+ ZodMessageFieldConverter: () => ZodMessageFieldConverter,
103
+ ZodMessageFieldType: () => ZodMessageFieldType,
104
+ ZodMessageFieldTypeConverter: () => ZodMessageFieldTypeConverter,
105
+ ZodMessageFieldTypeTuple: () => ZodMessageFieldTypeTuple,
106
+ ZodMessageOneOfFieldConverter: () => ZodMessageOneOfFieldConverter,
107
+ ZodMessageOneOfFieldType: () => ZodMessageOneOfFieldType,
108
+ ZodMessageOneOfFieldTypeTuple: () => ZodMessageOneOfFieldTypeTuple,
109
+ ZodPassthroughType: () => ZodPassthroughType,
110
+ ZodPassthroughTypeTuple: () => ZodPassthroughTypeTuple,
111
+ ZodRepeatedInnerType: () => ZodRepeatedInnerType,
112
+ ZodRepeatedInnerTypeTuple: () => ZodRepeatedInnerTypeTuple,
113
+ ZodRequiredFieldConversionTransformer: () => ZodRequiredFieldConversionTransformer,
114
+ ZodRequiredOneOfFieldConversionTransformer: () => ZodRequiredOneOfFieldConversionTransformer,
115
+ ZodScalarConverter: () => ZodScalarConverter,
116
+ ZodScalarType: () => ZodScalarType,
117
+ ZodScalarTypeTuple: () => ZodScalarTypeTuple,
118
+ assertsAnyZodMessageFieldType: () => assertsAnyZodMessageFieldType,
119
+ assertsNotEmptyArray: () => assertsNotEmptyArray,
120
+ assertsOneElementArray: () => assertsOneElementArray,
121
+ assertsZodCompatibleType: () => assertsZodCompatibleType,
122
+ assertsZodFormat: () => assertsZodFormat,
123
+ assertsZodMapValueType: () => assertsZodMapValueType,
124
+ assertsZodMessageFieldType: () => assertsZodMessageFieldType,
125
+ assertsZodObject: () => assertsZodObject,
126
+ assertsZodRepeatedInnerType: () => assertsZodRepeatedInnerType,
127
+ assertsZodScalarType: () => assertsZodScalarType,
128
+ fileContentMatter: () => fileContentMatter,
129
+ getEmptyTranformers: () => getEmptyTranformers,
130
+ getFullTransformers: () => getFullTransformers,
131
+ getZodSchemaComments: () => getZodSchemaComments,
132
+ isFormatCompatible: () => isFormatCompatible,
133
+ isZodLiteral: () => isZodLiteral,
134
+ isZodLiteralNotNullishValues: () => isZodLiteralNotNullishValues,
135
+ isZodObject: () => isZodObject,
136
+ isZodSchemaDeprecated: () => isZodSchemaDeprecated,
137
+ isZodSchemaOptional: () => isZodSchemaOptional,
138
+ oneOfUnion: () => oneOfUnion,
139
+ pz: () => pz,
140
+ zodToProto: () => zodToProto
141
+ });
142
+ module.exports = __toCommonJS(index_exports);
143
+
144
+ // src/core/asserts/not_empty_array.ts
145
+ var assertsNotEmptyArray = function(array) {
146
+ if (array.length === 0) {
147
+ throw new Error("Array should have one element minimum");
148
+ }
149
+ };
150
+
151
+ // src/core/asserts/one_element_array.ts
152
+ var assertsOneElementArray = function(array) {
153
+ if (array.length !== 1) {
154
+ throw new Error("Array should have one element only");
155
+ }
156
+ };
157
+
158
+ // src/file/classes/content_matter.ts
159
+ var $FileContentMatter = class {
160
+ constructor(config) {
161
+ this.config = config;
162
+ }
163
+ #settings = {
164
+ lineTabLevel: 0,
165
+ blockLevel: 0,
166
+ listLevel: 0
167
+ };
168
+ #sources = [""];
169
+ get settings() {
170
+ return this.#settings;
171
+ }
172
+ get ["~sources"]() {
173
+ return this.#sources;
174
+ }
175
+ safeDecreaseLineTabLevel() {
176
+ if (this.#settings.lineTabLevel > 0) {
177
+ this.#settings.lineTabLevel -= 1;
178
+ }
179
+ }
180
+ safeDecreaseBlockLevel() {
181
+ if (this.#settings.blockLevel > 0) {
182
+ this.#settings.blockLevel -= 1;
183
+ }
184
+ }
185
+ safeDecreaseListLevel() {
186
+ if (this.#settings.listLevel > 0) {
187
+ this.#settings.listLevel -= 1;
188
+ }
189
+ }
190
+ indent() {
191
+ this.#settings.lineTabLevel += 1;
192
+ return this;
193
+ }
194
+ outdent() {
195
+ if (this.#settings.lineTabLevel === 0) {
196
+ throw new Error("You should indent before calling the outdent method");
197
+ }
198
+ this.safeDecreaseLineTabLevel();
199
+ return this;
200
+ }
201
+ openBlock() {
202
+ this.write(this.config.openingBlockCharacter);
203
+ this.#settings.lineTabLevel += 1;
204
+ this.#settings.blockLevel += 1;
205
+ this.endLine();
206
+ return this;
207
+ }
208
+ closeBlock() {
209
+ if (this.#settings.blockLevel === 0) {
210
+ throw new Error("You should open a block before calling the close method");
211
+ }
212
+ this.safeDecreaseLineTabLevel();
213
+ this.safeDecreaseBlockLevel();
214
+ this.endLine();
215
+ this.write(this.config.closingBlockCharacter);
216
+ return this;
217
+ }
218
+ openList() {
219
+ this.write(this.config.openingListCharacter);
220
+ this.#settings.lineTabLevel += 1;
221
+ this.#settings.listLevel += 1;
222
+ this.endLine();
223
+ return this;
224
+ }
225
+ closeList() {
226
+ if (this.#settings.listLevel === 0) {
227
+ throw new Error("You should open an array before calling the close method");
228
+ }
229
+ this.safeDecreaseLineTabLevel();
230
+ this.safeDecreaseListLevel();
231
+ this.endLine();
232
+ this.write(this.config.closingListCharacter);
233
+ return this;
234
+ }
235
+ popLastSource() {
236
+ const lastSource = this.#sources.pop();
237
+ if (lastSource === void 0) {
238
+ throw new Error("The source should never be empty");
239
+ }
240
+ return lastSource;
241
+ }
242
+ write(data) {
243
+ if (typeof data === "string") {
244
+ let lastSource = this.popLastSource();
245
+ const updatedSource = `${lastSource}${data}`;
246
+ this.#sources.push(updatedSource);
247
+ } else {
248
+ let isFirst = true;
249
+ for (const source of data["~sources"]) {
250
+ if (!isFirst) {
251
+ this.endLine();
252
+ }
253
+ this.write(source);
254
+ isFirst = false;
255
+ }
256
+ }
257
+ return this;
258
+ }
259
+ writeIf(condition, data) {
260
+ if (condition) {
261
+ return this.write(data);
262
+ }
263
+ return this;
264
+ }
265
+ endLine() {
266
+ let newLine = "";
267
+ for (let currentLevel = 0; currentLevel < this.#settings.lineTabLevel; currentLevel++) {
268
+ newLine += this.config.lineTabCharacter;
269
+ }
270
+ this.#sources.push(newLine);
271
+ return this;
272
+ }
273
+ writeBlock(content) {
274
+ if (content.isEmpty()) {
275
+ this.write(this.config.openingBlockCharacter).write(
276
+ this.config.closingBlockCharacter
277
+ );
278
+ return this;
279
+ }
280
+ this.openBlock();
281
+ let isFirst = true;
282
+ for (const source of content["~sources"]) {
283
+ if (!isFirst) {
284
+ this.endLine();
285
+ }
286
+ this.write(source);
287
+ isFirst = false;
288
+ }
289
+ this.closeBlock();
290
+ return this;
291
+ }
292
+ writeList(...contents) {
293
+ if (contents.length === 0) {
294
+ this.write(this.config.openingListCharacter).write(
295
+ this.config.closingListCharacter
296
+ );
297
+ return this;
298
+ }
299
+ this.openList();
300
+ let isFirstContent = true;
301
+ for (const content of contents) {
302
+ if (!isFirstContent) {
303
+ this.write(this.config.listSeparatorCharacter).endLine();
304
+ }
305
+ let isFirstSource = true;
306
+ for (const source of content["~sources"]) {
307
+ if (!isFirstSource) {
308
+ this.endLine();
309
+ }
310
+ this.write(source);
311
+ isFirstSource = false;
312
+ }
313
+ isFirstContent = false;
314
+ }
315
+ this.closeList();
316
+ return this;
317
+ }
318
+ writeRecord(...entries) {
319
+ if (entries.length === 0) {
320
+ this.write(this.config.openingBlockCharacter).write(
321
+ this.config.closingBlockCharacter
322
+ );
323
+ return this;
324
+ }
325
+ this.openBlock();
326
+ let isFirstContent = true;
327
+ for (const entry of entries) {
328
+ if (!isFirstContent) {
329
+ this.write(this.config.listSeparatorCharacter).endLine();
330
+ }
331
+ this.write(`${entry.key}${this.config.recordKeyValueSeparatorCharacter}`);
332
+ let isFirstSource = true;
333
+ for (const source of entry.content["~sources"]) {
334
+ if (!isFirstSource) {
335
+ this.endLine();
336
+ }
337
+ this.write(source);
338
+ isFirstSource = false;
339
+ }
340
+ isFirstContent = false;
341
+ }
342
+ this.closeBlock();
343
+ return this;
344
+ }
345
+ isEmpty() {
346
+ if (this.#sources.length === 0) {
347
+ return true;
348
+ }
349
+ if (this.#sources.length === 1) {
350
+ return this.#sources[0] === "";
351
+ }
352
+ return false;
353
+ }
354
+ };
355
+ var fileContentMatter = function() {
356
+ return new $FileContentMatter({
357
+ lineTabCharacter: " ",
358
+ openingBlockCharacter: "{",
359
+ closingBlockCharacter: "}",
360
+ openingListCharacter: "[",
361
+ closingListCharacter: "]",
362
+ listSeparatorCharacter: ",",
363
+ recordKeyValueSeparatorCharacter: ": ",
364
+ recordEntrySeparatorCharacter: ","
365
+ });
366
+ };
367
+
368
+ // src/file/classes/file_builder.ts
369
+ var FileBuilder = class {
370
+ constructor(content) {
371
+ this.content = content;
372
+ }
373
+ compute() {
374
+ const computedSources = this.content["~sources"].join("\n");
375
+ return computedSources;
376
+ }
377
+ };
378
+
379
+ // src/proto3_definition/types/types.ts
380
+ var import_ts_pattern = require("ts-pattern");
381
+ var Proto3GlobalType = {
382
+ new: (params) => {
383
+ return {
384
+ internalName: "global_type",
385
+ getDeepMessages() {
386
+ return [];
387
+ },
388
+ getDeepImportedTypes() {
389
+ return [];
390
+ },
391
+ ...params
392
+ };
393
+ }
394
+ };
395
+ var Proto3ImportedType = {
396
+ new: (params) => {
397
+ return {
398
+ internalName: "imported_type",
399
+ getDeepMessages() {
400
+ return [];
401
+ },
402
+ getDeepImportedTypes() {
403
+ return [this];
404
+ },
405
+ ...params
406
+ };
407
+ }
408
+ };
409
+ var AnyProto3Type = {
410
+ new: (params) => {
411
+ return (0, import_ts_pattern.match)(params).with(
412
+ { internalName: "global_type" },
413
+ (params2) => Proto3GlobalType.new(params2)
414
+ ).with(
415
+ { internalName: "imported_type" },
416
+ (params2) => Proto3ImportedType.new(params2)
417
+ ).exhaustive();
418
+ }
419
+ };
420
+
421
+ // src/proto3_definition/types/extension.ts
422
+ var Proto3Extension = {
423
+ new: function(params) {
424
+ return {
425
+ internalName: "extension",
426
+ getDeepImportedTypes() {
427
+ return this.key.getDeepImportedTypes();
428
+ },
429
+ ...params
430
+ };
431
+ },
432
+ simplify: function(extension) {
433
+ if (typeof extension.value !== "object" || Array.isArray(extension.value)) {
434
+ return extension;
435
+ }
436
+ const messageEntries = Object.entries(extension.value);
437
+ if (messageEntries.length < 1 || messageEntries.length > 1) {
438
+ return extension;
439
+ }
440
+ const firstKey = messageEntries[0][0];
441
+ const firstValue = messageEntries[0][1];
442
+ return this.new({
443
+ ...extension,
444
+ key: AnyProto3Type.new({
445
+ ...extension.key,
446
+ typeReference: `(${extension.key.typeReference}).${firstKey}`
447
+ }),
448
+ value: firstValue
449
+ });
450
+ }
451
+ };
452
+
453
+ // src/plugin/types/global.ts
454
+ var Proto3Deprecated = {
455
+ useType: function() {
456
+ return Proto3GlobalType.new({
457
+ typeReference: "deprecated"
458
+ });
459
+ },
460
+ useExtension: function(value) {
461
+ return Proto3Extension.new({
462
+ key: this.useType(),
463
+ value
464
+ });
465
+ }
466
+ };
467
+
468
+ // src/proto3_definition/types/messages.ts
469
+ var Proto3Message = {
470
+ new: (params) => {
471
+ return {
472
+ internalName: "message",
473
+ getDeepMessages() {
474
+ const deepMessages = this.fields.map((field) => field.getDeepMessages()).flat();
475
+ return [this, ...deepMessages];
476
+ },
477
+ getDeepImportedTypes() {
478
+ return this.fields.map((field) => field.getDeepImportedTypes()).flat();
479
+ },
480
+ getNextIndex() {
481
+ const normalFieldsCount = this.fields.filter(
482
+ (field) => field.internalName === "message_field"
483
+ ).length;
484
+ const oneOfFieldsCounts = this.fields.filter((field) => field.internalName === "message_one_of_field").map((field) => field.subFields.length);
485
+ const counts = [normalFieldsCount, oneOfFieldsCounts].flat();
486
+ const fieldsCount = counts.reduce(
487
+ (accumulator, currentValue) => accumulator + currentValue,
488
+ 0
489
+ );
490
+ return fieldsCount + 1;
491
+ },
492
+ ...params
493
+ };
494
+ }
495
+ };
496
+ var Proto3Enum = {
497
+ new: (params) => {
498
+ return {
499
+ internalName: "enum",
500
+ getDeepMessages() {
501
+ return [this];
502
+ },
503
+ getDeepImportedTypes() {
504
+ return [];
505
+ },
506
+ ...params
507
+ };
508
+ }
509
+ };
510
+
511
+ // src/zod_converter/types/check.ts
512
+ var CompatibleZodTypeTuple = {
513
+ new: function(values) {
514
+ return values;
515
+ },
516
+ get: () => {
517
+ return CompatibleZodTypeTuple.new([
518
+ "string",
519
+ "number",
520
+ "bigint",
521
+ "boolean",
522
+ "object",
523
+ "literal",
524
+ "template_literal",
525
+ "enum",
526
+ "union",
527
+ "pipe",
528
+ "default",
529
+ "prefault",
530
+ "lazy",
531
+ "intersection",
532
+ "record",
533
+ "catch",
534
+ "optional",
535
+ "nonoptional",
536
+ "readonly",
537
+ "set",
538
+ "array"
539
+ ]);
540
+ }
541
+ };
542
+ var ZodCompatibleType = {
543
+ is: (schema) => {
544
+ const zodTypes = CompatibleZodTypeTuple.get();
545
+ return zodTypes.includes(schema._zod.def.type);
546
+ }
547
+ };
548
+
549
+ // src/zod_converter/types/error.ts
550
+ var SchemaError = {
551
+ new: (message, schema, name) => {
552
+ const error = new Error(message);
553
+ if (name) {
554
+ error.name = name;
555
+ }
556
+ Object.assign(error, {
557
+ schema
558
+ });
559
+ return error;
560
+ }
561
+ };
562
+
563
+ // src/zod_converter/asserts/zod_compatible_type.ts
564
+ var assertsZodCompatibleType = function(schema) {
565
+ if (!ZodCompatibleType.is(schema)) {
566
+ const validZodTypes = CompatibleZodTypeTuple.get();
567
+ throw SchemaError.new(
568
+ `The schema type should be one of: [${validZodTypes.join(", ")}]`,
569
+ schema,
570
+ "assertsZodCompatibleType"
571
+ );
572
+ }
573
+ };
574
+
575
+ // src/zod_converter/helpers/is_zod_object.ts
576
+ var isZodObject = function(schema) {
577
+ return schema._zod.def.type === "object";
578
+ };
579
+
580
+ // src/zod_converter/asserts/zod_object.ts
581
+ var assertsZodObject = function(schema) {
582
+ if (!isZodObject(schema)) {
583
+ throw SchemaError.new("The schema should be a zod object", schema);
584
+ }
585
+ };
586
+
587
+ // src/zod_converter/types/passthroughs.ts
588
+ var import_ts_pattern2 = require("ts-pattern");
589
+ var ZodPassthroughTypeTuple = {
590
+ new: function(values) {
591
+ return values;
592
+ }
593
+ };
594
+ var ZodPassthroughType = {
595
+ is: (schema) => {
596
+ const zodTypes = ZodPassthroughTypeTuple.new([
597
+ "catch",
598
+ "optional",
599
+ "nonoptional",
600
+ "readonly",
601
+ "default",
602
+ "prefault",
603
+ "lazy",
604
+ "pipe",
605
+ "intersection"
606
+ ]);
607
+ return zodTypes.includes(schema._zod.def.type);
608
+ },
609
+ pass: (schema) => {
610
+ if (!ZodPassthroughType.is(schema)) {
611
+ return schema;
612
+ }
613
+ let passthroughSchema = schema;
614
+ while (true) {
615
+ const inner = (0, import_ts_pattern2.match)(passthroughSchema).returnType().with(
616
+ {
617
+ _zod: {
618
+ def: {
619
+ type: import_ts_pattern2.P.union(
620
+ "catch",
621
+ "readonly",
622
+ "default",
623
+ "prefault",
624
+ "optional",
625
+ "nonoptional"
626
+ )
627
+ }
628
+ }
629
+ },
630
+ (schema2) => {
631
+ assertsZodCompatibleType(schema2._zod.def.innerType);
632
+ return schema2._zod.def.innerType;
633
+ }
634
+ ).with(
635
+ {
636
+ _zod: {
637
+ def: {
638
+ type: "lazy"
639
+ }
640
+ }
641
+ },
642
+ (schema2) => {
643
+ const lazySchema = schema2._zod.def.getter();
644
+ assertsZodCompatibleType(lazySchema);
645
+ return lazySchema;
646
+ }
647
+ ).with(
648
+ {
649
+ _zod: {
650
+ def: {
651
+ type: "pipe"
652
+ }
653
+ }
654
+ },
655
+ (schema2) => {
656
+ assertsZodCompatibleType(schema2._zod.def.in);
657
+ return schema2._zod.def.in;
658
+ }
659
+ ).with(
660
+ {
661
+ _zod: {
662
+ def: {
663
+ type: "intersection"
664
+ }
665
+ }
666
+ },
667
+ (schema2) => {
668
+ assertsZodObject(schema2._zod.def.right);
669
+ assertsZodObject(schema2._zod.def.left);
670
+ const finalSchema = schema2._zod.def.left.extend(
671
+ schema2._zod.def.right["shape"]
672
+ );
673
+ assertsZodCompatibleType(finalSchema);
674
+ return finalSchema;
675
+ }
676
+ ).exhaustive();
677
+ if (ZodPassthroughType.is(inner)) {
678
+ passthroughSchema = inner;
679
+ } else {
680
+ return inner;
681
+ }
682
+ }
683
+ },
684
+ getMetaAsDeepAsPossible: (schema) => {
685
+ const allMeta = [schema.meta() ?? {}];
686
+ if (!ZodPassthroughType.is(schema)) {
687
+ return allMeta;
688
+ }
689
+ let passthroughSchema = schema;
690
+ while (true) {
691
+ const inner = (0, import_ts_pattern2.match)(passthroughSchema).returnType().with(
692
+ {
693
+ _zod: {
694
+ def: {
695
+ type: import_ts_pattern2.P.union(
696
+ "catch",
697
+ "readonly",
698
+ "default",
699
+ "prefault",
700
+ "optional",
701
+ "nonoptional"
702
+ )
703
+ }
704
+ }
705
+ },
706
+ (schema2) => {
707
+ assertsZodCompatibleType(schema2._zod.def.innerType);
708
+ return schema2._zod.def.innerType;
709
+ }
710
+ ).with(
711
+ {
712
+ _zod: {
713
+ def: {
714
+ type: "lazy"
715
+ }
716
+ }
717
+ },
718
+ (schema2) => {
719
+ const lazySchema = schema2._zod.def.getter();
720
+ assertsZodCompatibleType(lazySchema);
721
+ return lazySchema;
722
+ }
723
+ ).with(
724
+ {
725
+ _zod: {
726
+ def: {
727
+ type: "pipe"
728
+ }
729
+ }
730
+ },
731
+ (schema2) => {
732
+ assertsZodCompatibleType(schema2._zod.def.in);
733
+ return schema2._zod.def.in;
734
+ }
735
+ ).with(
736
+ {
737
+ _zod: {
738
+ def: {
739
+ type: "intersection"
740
+ }
741
+ }
742
+ },
743
+ (schema2) => {
744
+ assertsZodObject(schema2._zod.def.right);
745
+ assertsZodObject(schema2._zod.def.left);
746
+ const finalSchema = schema2._zod.def.left.extend(
747
+ schema2._zod.def.right["shape"]
748
+ );
749
+ assertsZodCompatibleType(finalSchema);
750
+ return finalSchema;
751
+ }
752
+ ).exhaustive();
753
+ allMeta.push(inner.meta() ?? {});
754
+ if (ZodPassthroughType.is(inner)) {
755
+ passthroughSchema = inner;
756
+ } else {
757
+ return allMeta;
758
+ }
759
+ }
760
+ }
761
+ };
762
+
763
+ // src/zod_converter/helpers/is_zod_schema_deprecated.ts
764
+ var isZodSchemaDeprecated = function(schema) {
765
+ const allMeta = ZodPassthroughType.getMetaAsDeepAsPossible(schema);
766
+ const isDeprecated = allMeta.some((meta) => meta.deprecated);
767
+ return isDeprecated;
768
+ };
769
+
770
+ // src/plugin/classes/zod_deprecated_enum_conversion_transformer.ts
771
+ var ZodDeprecatedEnumConversionTransformer = class {
772
+ transform(schema, protoDefinition) {
773
+ const isDeprecated = isZodSchemaDeprecated(schema);
774
+ if (!isDeprecated) {
775
+ return protoDefinition;
776
+ }
777
+ return Proto3Enum.new({
778
+ ...protoDefinition,
779
+ extensions: [
780
+ ...protoDefinition.extensions,
781
+ Proto3Deprecated.useExtension(true)
782
+ ]
783
+ });
784
+ }
785
+ };
786
+
787
+ // src/proto3_definition/types/fields.ts
788
+ var Proto3OptionalState = {
789
+ PRESENT: "PRESENT",
790
+ NONE: "NONE",
791
+ NOT_NEEDED: "NOT_NEEDED"
792
+ };
793
+ var Proto3MessageField = {
794
+ new: (params) => {
795
+ return {
796
+ internalName: "message_field",
797
+ getDeepMessages() {
798
+ return this.type.getDeepMessages();
799
+ },
800
+ getDeepImportedTypes() {
801
+ return [
802
+ ...this.type.getDeepImportedTypes(),
803
+ ...this.extensions.map(
804
+ (extension) => extension.getDeepImportedTypes()
805
+ )
806
+ ].flat();
807
+ },
808
+ ...params
809
+ };
810
+ }
811
+ };
812
+ var Proto3MessageOneOfFieldSubField = {
813
+ new: (params) => {
814
+ return {
815
+ ...Proto3MessageField.new(params),
816
+ optionalState: "NOT_NEEDED"
817
+ };
818
+ }
819
+ };
820
+ var Proto3MessageOneOfField = {
821
+ new: (params) => {
822
+ return {
823
+ internalName: "message_one_of_field",
824
+ getDeepMessages() {
825
+ return this.subFields.map((field) => field.getDeepMessages()).flat();
826
+ },
827
+ getDeepImportedTypes() {
828
+ return this.subFields.map((field) => field.getDeepImportedTypes()).flat();
829
+ },
830
+ ...params
831
+ };
832
+ }
833
+ };
834
+ var Proto3EnumField = {
835
+ new: (params) => {
836
+ return {
837
+ internalName: "enum_field",
838
+ ...params
839
+ };
840
+ }
841
+ };
842
+
843
+ // src/plugin/classes/zod_deprecated_field_conversion_transformer.ts
844
+ var ZodDeprecatedFieldConversionTransformer = class {
845
+ transform(schema, protoDefinition) {
846
+ const isDeprecated = isZodSchemaDeprecated(schema);
847
+ if (!isDeprecated) {
848
+ return protoDefinition;
849
+ }
850
+ return Proto3MessageField.new({
851
+ ...protoDefinition,
852
+ extensions: [
853
+ ...protoDefinition.extensions,
854
+ Proto3Deprecated.useExtension(true)
855
+ ]
856
+ });
857
+ }
858
+ };
859
+
860
+ // src/plugin/classes/zod_deprecated_message_conversion_transformer.ts
861
+ var ZodDeprecatedMessageConversionTransformer = class {
862
+ transform(schema, protoDefinition) {
863
+ const isDeprecated = isZodSchemaDeprecated(schema);
864
+ if (!isDeprecated) {
865
+ return protoDefinition;
866
+ }
867
+ return Proto3Message.new({
868
+ ...protoDefinition,
869
+ extensions: [
870
+ ...protoDefinition.extensions,
871
+ Proto3Deprecated.useExtension(true)
872
+ ]
873
+ });
874
+ }
875
+ };
876
+
877
+ // src/plugin/classes/zod_deprecated_one_of_field_conversion_transformer.ts
878
+ var ZodDeprecatedOneOfFieldConversionTransformer = class {
879
+ transform(schema, protoDefinition) {
880
+ const isDeprecated = isZodSchemaDeprecated(schema);
881
+ if (!isDeprecated) {
882
+ return protoDefinition;
883
+ }
884
+ return Proto3MessageOneOfField.new({
885
+ ...protoDefinition,
886
+ extensions: [
887
+ ...protoDefinition.extensions,
888
+ Proto3Deprecated.useExtension(true)
889
+ ]
890
+ });
891
+ }
892
+ };
893
+
894
+ // src/plugin/types/buf_validate.ts
895
+ var Proto3ValidateFieldAnnotation = {
896
+ useType: function() {
897
+ return Proto3ImportedType.new({
898
+ importPath: "buf/validate/validate.proto",
899
+ typeReference: "buf.validate.field"
900
+ });
901
+ },
902
+ useExtension: function(value) {
903
+ return Proto3Extension.new({
904
+ key: this.useType(),
905
+ value
906
+ });
907
+ }
908
+ };
909
+ var Proto3ValidateOneOfAnnotation = {
910
+ useType: function() {
911
+ return Proto3ImportedType.new({
912
+ importPath: "buf/validate/validate.proto",
913
+ typeReference: "buf.validate.oneof"
914
+ });
915
+ },
916
+ useExtension: function(value) {
917
+ return Proto3Extension.new({
918
+ key: this.useType(),
919
+ value
920
+ });
921
+ }
922
+ };
923
+
924
+ // src/zod_converter/helpers/is_zod_schema_optional.ts
925
+ var isZodSchemaOptional = function(schema) {
926
+ return schema.safeParse(void 0).success;
927
+ };
928
+
929
+ // src/plugin/classes/zod_required_field_conversion_transformer.ts
930
+ var ZodRequiredFieldConversionTransformer = class {
931
+ transform(schema, protoDefinition) {
932
+ const isOptional = isZodSchemaOptional(schema);
933
+ if (isOptional) {
934
+ return protoDefinition;
935
+ }
936
+ return Proto3MessageField.new({
937
+ ...protoDefinition,
938
+ extensions: [
939
+ ...protoDefinition.extensions,
940
+ Proto3ValidateFieldAnnotation.useExtension({ required: true })
941
+ ]
942
+ });
943
+ }
944
+ };
945
+
946
+ // src/plugin/classes/zod_required_one_of_field_conversion_transformer.ts
947
+ var ZodRequiredOneOfFieldConversionTransformer = class {
948
+ transform(schema, protoDefinition) {
949
+ const isOptional = isZodSchemaOptional(schema);
950
+ if (isOptional) {
951
+ return protoDefinition;
952
+ }
953
+ return Proto3MessageOneOfField.new({
954
+ ...protoDefinition,
955
+ extensions: [
956
+ ...protoDefinition.extensions,
957
+ Proto3ValidateOneOfAnnotation.useExtension({ required: true })
958
+ ]
959
+ });
960
+ }
961
+ };
962
+
963
+ // src/plugin/helpers/get_full_transformers.ts
964
+ var getFullTransformers = function() {
965
+ return {
966
+ message: [new ZodDeprecatedMessageConversionTransformer()],
967
+ messageField: [
968
+ new ZodDeprecatedFieldConversionTransformer(),
969
+ new ZodRequiredFieldConversionTransformer()
970
+ ],
971
+ messageOneOfField: [
972
+ new ZodDeprecatedOneOfFieldConversionTransformer(),
973
+ new ZodRequiredOneOfFieldConversionTransformer()
974
+ ],
975
+ enum: [new ZodDeprecatedEnumConversionTransformer()]
976
+ };
977
+ };
978
+
979
+ // src/plugin/types/google_api_annotations.ts
980
+ var Proto3HttpAnnotation = {
981
+ useType: function() {
982
+ return Proto3ImportedType.new({
983
+ importPath: "google/api/annotations.proto",
984
+ typeReference: "google.api.http"
985
+ });
986
+ },
987
+ useExtension: function(value) {
988
+ return Proto3Extension.new({
989
+ key: this.useType(),
990
+ value
991
+ });
992
+ }
993
+ };
994
+
995
+ // src/plugin/types/google_protobuf.ts
996
+ var Proto3Empty = {
997
+ useType: () => {
998
+ return Proto3ImportedType.new({
999
+ importPath: "google/protobuf/empty.proto",
1000
+ typeReference: "google.protobuf.Empty"
1001
+ });
1002
+ }
1003
+ };
1004
+
1005
+ // src/proto3_definition/types/dynamic_size.ts
1006
+ var Proto3MapType = {
1007
+ new: (params) => {
1008
+ return {
1009
+ internalName: "map",
1010
+ getDeepMessages() {
1011
+ return this.value.getDeepMessages();
1012
+ },
1013
+ getDeepImportedTypes() {
1014
+ return this.value.getDeepImportedTypes();
1015
+ },
1016
+ ...params
1017
+ };
1018
+ }
1019
+ };
1020
+ var Proto3RepeatedType = {
1021
+ new: (params) => {
1022
+ return {
1023
+ internalName: "repeated",
1024
+ getDeepMessages() {
1025
+ let currentItem = this;
1026
+ while (currentItem.internalName === "repeated") {
1027
+ currentItem = currentItem.inner;
1028
+ }
1029
+ return currentItem.getDeepMessages();
1030
+ },
1031
+ getDeepImportedTypes() {
1032
+ let currentItem = this;
1033
+ while (currentItem.internalName === "repeated") {
1034
+ currentItem = currentItem.inner;
1035
+ }
1036
+ return currentItem.getDeepImportedTypes();
1037
+ },
1038
+ ...params
1039
+ };
1040
+ }
1041
+ };
1042
+
1043
+ // src/proto3_definition/types/file.ts
1044
+ var Proto3File = {
1045
+ new: (params) => {
1046
+ return {
1047
+ internalName: "file",
1048
+ getDeepMessages() {
1049
+ return [
1050
+ ...this.service?.getDeepMessages() ?? [],
1051
+ ...this.unscopedMessages.map((message) => message.getDeepMessages())
1052
+ ].flat();
1053
+ },
1054
+ getDeepImportedTypes() {
1055
+ return [
1056
+ ...this.service?.getDeepImportedTypes() ?? [],
1057
+ ...this.unscopedMessages.map(
1058
+ (message) => message.getDeepImportedTypes()
1059
+ )
1060
+ ].flat();
1061
+ },
1062
+ applyTypePrefix() {
1063
+ this.service?.applyTypePrefix();
1064
+ },
1065
+ ...params
1066
+ };
1067
+ }
1068
+ };
1069
+
1070
+ // src/proto3_definition/types/functions.ts
1071
+ var Proto3RpcFunction = {
1072
+ new: (params) => {
1073
+ return {
1074
+ internalName: "rpc_function",
1075
+ getDeepMessages() {
1076
+ return [...this.in.getDeepMessages(), ...this.out.getDeepMessages()];
1077
+ },
1078
+ getDeepImportedTypes() {
1079
+ return [
1080
+ ...this.in.getDeepImportedTypes(),
1081
+ ...this.out.getDeepImportedTypes(),
1082
+ ...this.extensions.map(
1083
+ (extension) => extension.getDeepImportedTypes()
1084
+ )
1085
+ ].flat();
1086
+ },
1087
+ applyTypePrefix() {
1088
+ if (this.typePrefix === void 0) {
1089
+ return;
1090
+ }
1091
+ const messages = this.getDeepMessages();
1092
+ for (const message of messages) {
1093
+ message.name = `${this.typePrefix}${message.name}`;
1094
+ }
1095
+ },
1096
+ ...params
1097
+ };
1098
+ }
1099
+ };
1100
+
1101
+ // src/proto3_definition/types/scalar_standalones.ts
1102
+ var Proto3StringType = {
1103
+ new: () => {
1104
+ return {
1105
+ internalName: "string",
1106
+ name: "string",
1107
+ getDeepMessages() {
1108
+ return [];
1109
+ },
1110
+ getDeepImportedTypes() {
1111
+ return [];
1112
+ }
1113
+ };
1114
+ }
1115
+ };
1116
+ var Proto3BoolType = {
1117
+ new: () => {
1118
+ return {
1119
+ internalName: "bool",
1120
+ name: "bool",
1121
+ getDeepMessages() {
1122
+ return [];
1123
+ },
1124
+ getDeepImportedTypes() {
1125
+ return [];
1126
+ }
1127
+ };
1128
+ }
1129
+ };
1130
+ var Proto3Int32Type = {
1131
+ new: () => {
1132
+ return {
1133
+ internalName: "int32",
1134
+ name: "int32",
1135
+ getDeepMessages() {
1136
+ return [];
1137
+ },
1138
+ getDeepImportedTypes() {
1139
+ return [];
1140
+ }
1141
+ };
1142
+ }
1143
+ };
1144
+ var Proto3Int64Type = {
1145
+ new: () => {
1146
+ return {
1147
+ internalName: "int64",
1148
+ name: "int64",
1149
+ getDeepMessages() {
1150
+ return [];
1151
+ },
1152
+ getDeepImportedTypes() {
1153
+ return [];
1154
+ }
1155
+ };
1156
+ }
1157
+ };
1158
+ var Proto3UInt32Type = {
1159
+ new: () => {
1160
+ return {
1161
+ internalName: "uint32",
1162
+ name: "uint32",
1163
+ getDeepMessages() {
1164
+ return [];
1165
+ },
1166
+ getDeepImportedTypes() {
1167
+ return [];
1168
+ }
1169
+ };
1170
+ }
1171
+ };
1172
+ var Proto3UInt64Type = {
1173
+ new: () => {
1174
+ return {
1175
+ internalName: "uint64",
1176
+ name: "uint64",
1177
+ getDeepMessages() {
1178
+ return [];
1179
+ },
1180
+ getDeepImportedTypes() {
1181
+ return [];
1182
+ }
1183
+ };
1184
+ }
1185
+ };
1186
+ var Proto3SInt32Type = {
1187
+ new: () => {
1188
+ return {
1189
+ internalName: "sint32",
1190
+ name: "sint32",
1191
+ getDeepMessages() {
1192
+ return [];
1193
+ },
1194
+ getDeepImportedTypes() {
1195
+ return [];
1196
+ }
1197
+ };
1198
+ }
1199
+ };
1200
+ var Proto3SInt64Type = {
1201
+ new: () => {
1202
+ return {
1203
+ internalName: "sint64",
1204
+ name: "sint64",
1205
+ getDeepMessages() {
1206
+ return [];
1207
+ },
1208
+ getDeepImportedTypes() {
1209
+ return [];
1210
+ }
1211
+ };
1212
+ }
1213
+ };
1214
+ var Proto3Fixed32Type = {
1215
+ new: () => {
1216
+ return {
1217
+ internalName: "fixed32",
1218
+ name: "fixed32",
1219
+ getDeepMessages() {
1220
+ return [];
1221
+ },
1222
+ getDeepImportedTypes() {
1223
+ return [];
1224
+ }
1225
+ };
1226
+ }
1227
+ };
1228
+ var Proto3Fixed64Type = {
1229
+ new: () => {
1230
+ return {
1231
+ internalName: "fixed64",
1232
+ name: "fixed64",
1233
+ getDeepMessages() {
1234
+ return [];
1235
+ },
1236
+ getDeepImportedTypes() {
1237
+ return [];
1238
+ }
1239
+ };
1240
+ }
1241
+ };
1242
+ var Proto3SFixed32Type = {
1243
+ new: () => {
1244
+ return {
1245
+ internalName: "sfixed32",
1246
+ name: "sfixed32",
1247
+ getDeepMessages() {
1248
+ return [];
1249
+ },
1250
+ getDeepImportedTypes() {
1251
+ return [];
1252
+ }
1253
+ };
1254
+ }
1255
+ };
1256
+ var Proto3SFixed64Type = {
1257
+ new: () => {
1258
+ return {
1259
+ internalName: "sfixed64",
1260
+ name: "sfixed64",
1261
+ getDeepMessages() {
1262
+ return [];
1263
+ },
1264
+ getDeepImportedTypes() {
1265
+ return [];
1266
+ }
1267
+ };
1268
+ }
1269
+ };
1270
+ var Proto3DoubleType = {
1271
+ new: () => {
1272
+ return {
1273
+ internalName: "double",
1274
+ name: "double",
1275
+ getDeepMessages() {
1276
+ return [];
1277
+ },
1278
+ getDeepImportedTypes() {
1279
+ return [];
1280
+ }
1281
+ };
1282
+ }
1283
+ };
1284
+ var Proto3FloatType = {
1285
+ new: () => {
1286
+ return {
1287
+ internalName: "float",
1288
+ name: "float",
1289
+ getDeepMessages() {
1290
+ return [];
1291
+ },
1292
+ getDeepImportedTypes() {
1293
+ return [];
1294
+ }
1295
+ };
1296
+ }
1297
+ };
1298
+ var Proto3BytesType = {
1299
+ new: () => {
1300
+ return {
1301
+ internalName: "bytes",
1302
+ name: "bytes",
1303
+ getDeepMessages() {
1304
+ return [];
1305
+ },
1306
+ getDeepImportedTypes() {
1307
+ return [];
1308
+ }
1309
+ };
1310
+ }
1311
+ };
1312
+
1313
+ // src/proto3_definition/types/service.ts
1314
+ var Proto3RpcService = {
1315
+ new: (params) => {
1316
+ return {
1317
+ internalName: "rpc_service",
1318
+ getDeepMessages() {
1319
+ return this.functions.map((rpcFunction) => rpcFunction.getDeepMessages()).flat();
1320
+ },
1321
+ getDeepImportedTypes() {
1322
+ return this.functions.map((rpcFunction) => rpcFunction.getDeepImportedTypes()).flat();
1323
+ },
1324
+ applyTypePrefix() {
1325
+ for (const rpcFunction of this.functions) {
1326
+ rpcFunction.applyTypePrefix();
1327
+ }
1328
+ if (this.typePrefix === void 0) {
1329
+ return;
1330
+ }
1331
+ const messages = this.getDeepMessages();
1332
+ for (const message of messages) {
1333
+ message.name = `${this.typePrefix}${message.name}`;
1334
+ }
1335
+ },
1336
+ ...params
1337
+ };
1338
+ }
1339
+ };
1340
+
1341
+ // src/proto3_processor/classes/proto3_comment_processor.ts
1342
+ var Proto3CommentProcessor = class {
1343
+ constructor(content) {
1344
+ this.content = content;
1345
+ }
1346
+ process(comments) {
1347
+ let isFirst = true;
1348
+ for (const comment of comments) {
1349
+ if (!isFirst) {
1350
+ this.content.endLine();
1351
+ }
1352
+ this.content.write(`// ${comment}`);
1353
+ isFirst = false;
1354
+ }
1355
+ if (!this.content.isEmpty()) {
1356
+ this.content.endLine();
1357
+ }
1358
+ }
1359
+ };
1360
+
1361
+ // src/proto3_processor/classes/proto3_extension_value_processor.ts
1362
+ var Proto3ExtensionValueProcessor = class _Proto3ExtensionValueProcessor {
1363
+ constructor(content) {
1364
+ this.content = content;
1365
+ }
1366
+ process(extensionValue) {
1367
+ if (extensionValue === void 0) {
1368
+ return;
1369
+ } else if (Array.isArray(extensionValue)) {
1370
+ const arrayContents = [];
1371
+ for (const arrayValue of extensionValue) {
1372
+ const arrayValueContent = fileContentMatter();
1373
+ const processor = new _Proto3ExtensionValueProcessor(arrayValueContent);
1374
+ processor.process(arrayValue);
1375
+ if (arrayValueContent.isEmpty()) {
1376
+ continue;
1377
+ }
1378
+ arrayContents.push(arrayValueContent);
1379
+ }
1380
+ this.content.writeList(...arrayContents);
1381
+ } else if (typeof extensionValue === "object") {
1382
+ const recordContentEntries = [];
1383
+ const messageEntries = Object.entries(extensionValue);
1384
+ if (messageEntries.length === 0) {
1385
+ return;
1386
+ }
1387
+ for (const [key, value] of messageEntries) {
1388
+ const valueContent = fileContentMatter();
1389
+ const processor = new _Proto3ExtensionValueProcessor(valueContent);
1390
+ processor.process(value);
1391
+ if (valueContent.isEmpty()) {
1392
+ continue;
1393
+ }
1394
+ recordContentEntries.push({
1395
+ key,
1396
+ content: valueContent
1397
+ });
1398
+ }
1399
+ this.content.writeRecord(...recordContentEntries);
1400
+ } else if (typeof extensionValue === "string") {
1401
+ this.content.write(`"${extensionValue}"`);
1402
+ } else {
1403
+ this.content.write("" + extensionValue);
1404
+ }
1405
+ }
1406
+ };
1407
+
1408
+ // src/proto3_processor/classes/proto3_field_extension_processor.ts
1409
+ var Proto3FieldExtensionProcessor = class {
1410
+ constructor(content) {
1411
+ this.content = content;
1412
+ }
1413
+ process(extension) {
1414
+ const extensionValueContent = fileContentMatter();
1415
+ const processor = new Proto3ExtensionValueProcessor(extensionValueContent);
1416
+ processor.process(extension.value);
1417
+ if (extensionValueContent.isEmpty()) {
1418
+ return;
1419
+ }
1420
+ this.content.write(`${extension.key.typeReference} = `).write(extensionValueContent);
1421
+ }
1422
+ };
1423
+
1424
+ // src/proto3_processor/classes/proto3_record_extension_processor.ts
1425
+ var Proto3RecordExtensionProcessor = class {
1426
+ constructor(content) {
1427
+ this.content = content;
1428
+ }
1429
+ process(extension) {
1430
+ const extensionValueContent = fileContentMatter();
1431
+ const processor = new Proto3ExtensionValueProcessor(extensionValueContent);
1432
+ processor.process(extension.value);
1433
+ if (extensionValueContent.isEmpty()) {
1434
+ return;
1435
+ }
1436
+ this.content.write(`option ${extension.key.typeReference} = `).write(extensionValueContent).write(";");
1437
+ }
1438
+ };
1439
+
1440
+ // src/proto3_processor/classes/proto3_field_processor.ts
1441
+ var import_ts_pattern3 = require("ts-pattern");
1442
+ var Proto3FieldProcessor = class _Proto3FieldProcessor {
1443
+ constructor(fileContent) {
1444
+ this.fileContent = fileContent;
1445
+ }
1446
+ getCommentContent(comments) {
1447
+ const content = fileContentMatter();
1448
+ const processor = new Proto3CommentProcessor(content);
1449
+ processor.process(comments);
1450
+ return content;
1451
+ }
1452
+ getScalarTypeReferenceString(scalarType) {
1453
+ return scalarType.name;
1454
+ }
1455
+ getTypeReferenceString(item) {
1456
+ let finalType = "";
1457
+ let currentItem = item;
1458
+ while (currentItem) {
1459
+ let currentType = (0, import_ts_pattern3.match)(currentItem).returnType().with(
1460
+ { internalName: "string" },
1461
+ { internalName: "bool" },
1462
+ { internalName: "int32" },
1463
+ { internalName: "int64" },
1464
+ { internalName: "uint32" },
1465
+ { internalName: "uint64" },
1466
+ { internalName: "sint32" },
1467
+ { internalName: "sint64" },
1468
+ { internalName: "fixed32" },
1469
+ { internalName: "fixed64" },
1470
+ { internalName: "sfixed32" },
1471
+ { internalName: "sfixed64" },
1472
+ { internalName: "float" },
1473
+ { internalName: "double" },
1474
+ { internalName: "bytes" },
1475
+ this.getScalarTypeReferenceString
1476
+ ).with(
1477
+ { internalName: "message" },
1478
+ { internalName: "enum" },
1479
+ (message) => message.name
1480
+ ).with({ internalName: "repeated" }, () => "repeated").with({ internalName: "map" }, (map) => {
1481
+ const keyType = this.getScalarTypeReferenceString(map.key);
1482
+ const valueType = this.getTypeReferenceString(map.value);
1483
+ return `map<${keyType}, ${valueType}>`;
1484
+ }).with({ internalName: "imported_type" }, (imported) => {
1485
+ return imported.typeReference;
1486
+ }).exhaustive();
1487
+ if (finalType === "") {
1488
+ finalType = currentType;
1489
+ } else {
1490
+ finalType += ` ${currentType}`;
1491
+ }
1492
+ currentItem = (0, import_ts_pattern3.match)(currentItem).with({ internalName: "repeated" }, (current) => current.inner).otherwise(() => void 0);
1493
+ }
1494
+ return finalType;
1495
+ }
1496
+ getFieldExtensionContent(extension) {
1497
+ const extensionContent = fileContentMatter();
1498
+ const extensionProcessor = new Proto3FieldExtensionProcessor(extensionContent);
1499
+ extensionProcessor.process(extension);
1500
+ return extensionContent;
1501
+ }
1502
+ getRecordExtensionContent(extension) {
1503
+ const extensionContent = fileContentMatter();
1504
+ const extensionProcessor = new Proto3RecordExtensionProcessor(extensionContent);
1505
+ extensionProcessor.process(extension);
1506
+ return extensionContent;
1507
+ }
1508
+ process(anyField) {
1509
+ const commentContent = this.getCommentContent(anyField.comments);
1510
+ this.fileContent.write(commentContent);
1511
+ (0, import_ts_pattern3.match)(anyField).with({ internalName: "message_field" }, (field) => {
1512
+ const extensionContents = [];
1513
+ for (const extension of field.extensions) {
1514
+ const updatedExtension = Proto3Extension.simplify(extension);
1515
+ const extensionContent = this.getFieldExtensionContent(updatedExtension);
1516
+ if (extensionContent.isEmpty()) {
1517
+ continue;
1518
+ }
1519
+ extensionContents.push(extensionContent);
1520
+ }
1521
+ const typeString = this.getTypeReferenceString(field.type);
1522
+ if (field.optionalState === "PRESENT") {
1523
+ this.fileContent.write("optional ");
1524
+ }
1525
+ this.fileContent.write(`${typeString} ${field.key} = ${field.index}`);
1526
+ if (extensionContents.length > 0) {
1527
+ this.fileContent.write(" ").writeList(...extensionContents);
1528
+ }
1529
+ this.fileContent.write(";");
1530
+ }).with({ internalName: "message_one_of_field" }, (field) => {
1531
+ const oneOfFieldContent = fileContentMatter();
1532
+ let isFirst = true;
1533
+ for (const extension of field.extensions) {
1534
+ const updatedExtension = Proto3Extension.simplify(extension);
1535
+ const extensionContent = this.getRecordExtensionContent(updatedExtension);
1536
+ if (extensionContent.isEmpty()) {
1537
+ continue;
1538
+ }
1539
+ if (!isFirst) {
1540
+ oneOfFieldContent.endLine();
1541
+ }
1542
+ oneOfFieldContent.write(extensionContent);
1543
+ isFirst = false;
1544
+ }
1545
+ for (const subField of field.subFields) {
1546
+ if (!isFirst) {
1547
+ oneOfFieldContent.endLine();
1548
+ }
1549
+ const fieldProcessor = new _Proto3FieldProcessor(oneOfFieldContent);
1550
+ fieldProcessor.process(subField);
1551
+ isFirst = false;
1552
+ }
1553
+ this.fileContent.write(`oneof ${field.key} `).writeBlock(oneOfFieldContent);
1554
+ }).with({ internalName: "enum_field" }, (field) => {
1555
+ const extensionContents = [];
1556
+ for (const extension of field.extensions) {
1557
+ const updatedExtension = Proto3Extension.simplify(extension);
1558
+ const extensionContent = this.getFieldExtensionContent(updatedExtension);
1559
+ if (extensionContent.isEmpty()) {
1560
+ continue;
1561
+ }
1562
+ extensionContents.push(extensionContent);
1563
+ }
1564
+ this.fileContent.write(`${field.key} = ${field.index}`);
1565
+ if (extensionContents.length > 0) {
1566
+ this.fileContent.write(" ").writeList(...extensionContents);
1567
+ }
1568
+ this.fileContent.write(";");
1569
+ }).exhaustive();
1570
+ }
1571
+ };
1572
+
1573
+ // src/proto3_processor/classes/proto3_import_processor.ts
1574
+ var Proto3ImportProcessor = class {
1575
+ constructor(content) {
1576
+ this.content = content;
1577
+ }
1578
+ process(importedTypes) {
1579
+ let isFirst = true;
1580
+ const importPaths = importedTypes.map((importedType) => importedType.importPath);
1581
+ const uniqueImportPaths = new Set(importPaths);
1582
+ for (const importPath of uniqueImportPaths) {
1583
+ if (!isFirst) {
1584
+ this.content.endLine();
1585
+ }
1586
+ this.content.write(`import "${importPath}";`);
1587
+ isFirst = false;
1588
+ }
1589
+ }
1590
+ };
1591
+
1592
+ // src/proto3_processor/classes/proto3_message_processor.ts
1593
+ var import_ts_pattern4 = require("ts-pattern");
1594
+ var Proto3MessageProcessor = class {
1595
+ constructor(content) {
1596
+ this.content = content;
1597
+ }
1598
+ getCommentContent(comments) {
1599
+ const content = fileContentMatter();
1600
+ const processor = new Proto3CommentProcessor(content);
1601
+ processor.process(comments);
1602
+ return content;
1603
+ }
1604
+ getRecordExtensionContent(extension) {
1605
+ const extensionContent = fileContentMatter();
1606
+ const extensionProcessor = new Proto3RecordExtensionProcessor(extensionContent);
1607
+ extensionProcessor.process(extension);
1608
+ return extensionContent;
1609
+ }
1610
+ process(anyMessage) {
1611
+ const commentContent = this.getCommentContent(anyMessage.comments);
1612
+ this.content.write(commentContent);
1613
+ (0, import_ts_pattern4.match)(anyMessage).with({ internalName: "message" }, (message) => {
1614
+ const messageContent = fileContentMatter();
1615
+ let isFirst = true;
1616
+ for (const extension of message.extensions) {
1617
+ const updatedExtension = Proto3Extension.simplify(extension);
1618
+ const extensionContent = this.getRecordExtensionContent(updatedExtension);
1619
+ if (extensionContent.isEmpty()) {
1620
+ continue;
1621
+ }
1622
+ if (!isFirst) {
1623
+ messageContent.endLine();
1624
+ }
1625
+ messageContent.write(extensionContent);
1626
+ isFirst = false;
1627
+ }
1628
+ for (const field of message.fields) {
1629
+ if (!isFirst) {
1630
+ messageContent.endLine();
1631
+ }
1632
+ const fieldProcessor = new Proto3FieldProcessor(messageContent);
1633
+ fieldProcessor.process(field);
1634
+ isFirst = false;
1635
+ }
1636
+ this.content.write(`message ${message.name} `).writeBlock(messageContent);
1637
+ }).with({ internalName: "enum" }, (messageEnum) => {
1638
+ const enumContent = fileContentMatter();
1639
+ let isFirst = true;
1640
+ for (const extension of messageEnum.extensions) {
1641
+ const updatedExtension = Proto3Extension.simplify(extension);
1642
+ const extensionContent = this.getRecordExtensionContent(updatedExtension);
1643
+ if (extensionContent.isEmpty()) {
1644
+ continue;
1645
+ }
1646
+ if (!isFirst) {
1647
+ enumContent.endLine();
1648
+ }
1649
+ enumContent.write(extensionContent);
1650
+ isFirst = false;
1651
+ }
1652
+ for (const field of messageEnum.fields) {
1653
+ if (!isFirst) {
1654
+ enumContent.endLine();
1655
+ }
1656
+ const fieldProcessor = new Proto3FieldProcessor(enumContent);
1657
+ fieldProcessor.process(field);
1658
+ isFirst = false;
1659
+ }
1660
+ this.content.write(`enum ${messageEnum.name} `).writeBlock(enumContent);
1661
+ }).exhaustive();
1662
+ }
1663
+ };
1664
+
1665
+ // src/proto3_processor/classes/proto3_function_processor.ts
1666
+ var import_ts_pattern5 = require("ts-pattern");
1667
+ var Proto3FunctionProcessor = class {
1668
+ constructor(content) {
1669
+ this.content = content;
1670
+ }
1671
+ getCommentContent(comments) {
1672
+ const content = fileContentMatter();
1673
+ const processor = new Proto3CommentProcessor(content);
1674
+ processor.process(comments);
1675
+ return content;
1676
+ }
1677
+ getTypeReferenceString(item) {
1678
+ return (0, import_ts_pattern5.match)(item).returnType().with(
1679
+ { internalName: "enum" },
1680
+ { internalName: "message" },
1681
+ (message) => message.name
1682
+ ).with({ internalName: "imported_type" }, (imported) => imported.typeReference).exhaustive();
1683
+ }
1684
+ process(rpcFunction) {
1685
+ const commentContent = this.getCommentContent(rpcFunction.comments);
1686
+ const inTypeReference = this.getTypeReferenceString(rpcFunction.in);
1687
+ const outTypeReference = this.getTypeReferenceString(rpcFunction.out);
1688
+ const extensionBlockContent = fileContentMatter();
1689
+ let isFirstExtension = true;
1690
+ for (const extension of rpcFunction.extensions) {
1691
+ const extensionContent = fileContentMatter();
1692
+ const extensionProcessor = new Proto3RecordExtensionProcessor(
1693
+ extensionContent
1694
+ );
1695
+ const updatedExtension = Proto3Extension.simplify(extension);
1696
+ extensionProcessor.process(updatedExtension);
1697
+ if (extensionContent.isEmpty()) {
1698
+ continue;
1699
+ }
1700
+ if (!isFirstExtension) {
1701
+ extensionBlockContent.endLine();
1702
+ }
1703
+ extensionBlockContent.write(extensionContent);
1704
+ isFirstExtension = false;
1705
+ }
1706
+ this.content.write(commentContent).write(`rpc ${rpcFunction.name}(`).writeIf(rpcFunction.inStream, "stream ").write(`${inTypeReference}) returns (`).writeIf(rpcFunction.outStream, "stream ").write(`${outTypeReference}) `).writeBlock(extensionBlockContent);
1707
+ }
1708
+ };
1709
+
1710
+ // src/proto3_processor/classes/proto3_service_processor.ts
1711
+ var Proto3ServiceProcessor = class {
1712
+ constructor(content) {
1713
+ this.content = content;
1714
+ }
1715
+ getCommentContent(comments) {
1716
+ const content = fileContentMatter();
1717
+ const processor = new Proto3CommentProcessor(content);
1718
+ processor.process(comments);
1719
+ return content;
1720
+ }
1721
+ getRecordExtensionContent(extension) {
1722
+ const extensionContent = fileContentMatter();
1723
+ const extensionProcessor = new Proto3RecordExtensionProcessor(extensionContent);
1724
+ extensionProcessor.process(extension);
1725
+ return extensionContent;
1726
+ }
1727
+ process(service) {
1728
+ const commentContent = this.getCommentContent(service.comments);
1729
+ const serviceContent = fileContentMatter();
1730
+ let isFirst = true;
1731
+ for (const extension of service.extensions) {
1732
+ const updatedExtension = Proto3Extension.simplify(extension);
1733
+ const extensionContent = this.getRecordExtensionContent(updatedExtension);
1734
+ if (extensionContent.isEmpty()) {
1735
+ continue;
1736
+ }
1737
+ if (!isFirst) {
1738
+ serviceContent.endLine();
1739
+ }
1740
+ serviceContent.write(extensionContent);
1741
+ isFirst = false;
1742
+ }
1743
+ for (const rpcFunction of service.functions) {
1744
+ if (!isFirst) {
1745
+ serviceContent.endLine();
1746
+ }
1747
+ const functionProcessor = new Proto3FunctionProcessor(serviceContent);
1748
+ functionProcessor.process(rpcFunction);
1749
+ isFirst = false;
1750
+ }
1751
+ this.content.write(commentContent).write(`service ${service.name} `).writeBlock(serviceContent);
1752
+ }
1753
+ };
1754
+
1755
+ // src/proto3_processor/classes/proto3_file_processor.ts
1756
+ var Proto3FileProcessor = class {
1757
+ getImportContent(importedTypes) {
1758
+ const content = fileContentMatter();
1759
+ const processor = new Proto3ImportProcessor(content);
1760
+ processor.process(importedTypes);
1761
+ return content;
1762
+ }
1763
+ getRecordExtensionContent(extension) {
1764
+ const extensionContent = fileContentMatter();
1765
+ const extensionProcessor = new Proto3RecordExtensionProcessor(extensionContent);
1766
+ extensionProcessor.process(extension);
1767
+ return extensionContent;
1768
+ }
1769
+ getExtensionContents(extensions) {
1770
+ const contents = [];
1771
+ for (const extension of extensions) {
1772
+ const updatedExtension = Proto3Extension.simplify(extension);
1773
+ const content = this.getRecordExtensionContent(updatedExtension);
1774
+ if (content.isEmpty()) {
1775
+ continue;
1776
+ }
1777
+ contents.push(content);
1778
+ }
1779
+ return contents;
1780
+ }
1781
+ getServiceContent(service) {
1782
+ const content = fileContentMatter();
1783
+ const processor = new Proto3ServiceProcessor(content);
1784
+ processor.process(service);
1785
+ return content;
1786
+ }
1787
+ getMessageContent(messages) {
1788
+ const content = fileContentMatter();
1789
+ const processor = new Proto3MessageProcessor(content);
1790
+ let isFirst = true;
1791
+ for (const message of messages) {
1792
+ if (!isFirst) {
1793
+ content.endLine().endLine();
1794
+ }
1795
+ processor.process(message);
1796
+ isFirst = false;
1797
+ }
1798
+ return content;
1799
+ }
1800
+ process(file) {
1801
+ file.applyTypePrefix();
1802
+ const content = fileContentMatter();
1803
+ const importedTypes = file.getDeepImportedTypes();
1804
+ const importContent = this.getImportContent(importedTypes);
1805
+ const extensionContents = this.getExtensionContents(file.extensions);
1806
+ const serviceContent = file.service ? this.getServiceContent(file.service) : fileContentMatter();
1807
+ const messages = file.getDeepMessages();
1808
+ const messageContent = this.getMessageContent(messages);
1809
+ content.write(`syntax = "${file.syntax}";`);
1810
+ if (!importContent.isEmpty()) {
1811
+ content.endLine().endLine().write(importContent);
1812
+ }
1813
+ content.endLine().endLine().write(`package ${file.packageName};`);
1814
+ if (extensionContents.length > 0) {
1815
+ content.endLine().endLine();
1816
+ let isFirst = true;
1817
+ for (const extensionContent of extensionContents) {
1818
+ if (!isFirst) {
1819
+ extensionContent.endLine();
1820
+ }
1821
+ content.write(extensionContent);
1822
+ isFirst = false;
1823
+ }
1824
+ }
1825
+ if (!serviceContent.isEmpty()) {
1826
+ content.endLine().endLine().write(serviceContent);
1827
+ }
1828
+ if (!messageContent.isEmpty()) {
1829
+ content.endLine().endLine().write(messageContent);
1830
+ }
1831
+ return content;
1832
+ }
1833
+ };
1834
+
1835
+ // src/zod_converter/types/messages.ts
1836
+ var AnyZodMessageTypeTuple = {
1837
+ new: function(values) {
1838
+ return values;
1839
+ }
1840
+ };
1841
+ var AnyZodMessage = {
1842
+ is: function(schema) {
1843
+ const deepSchema = ZodPassthroughType.pass(schema);
1844
+ const zodTypes = AnyZodMessageTypeTuple.new(["object", "enum"]);
1845
+ return zodTypes.includes(deepSchema._zod.def.type);
1846
+ }
1847
+ };
1848
+ var ZodMessageFieldTypeTuple = {
1849
+ new: function(values) {
1850
+ return values;
1851
+ },
1852
+ get: () => {
1853
+ return ZodMessageFieldTypeTuple.new([
1854
+ "string",
1855
+ "number",
1856
+ "bigint",
1857
+ "boolean",
1858
+ "literal",
1859
+ "template_literal",
1860
+ "array",
1861
+ "set",
1862
+ "record",
1863
+ "object",
1864
+ "enum"
1865
+ ]);
1866
+ }
1867
+ };
1868
+ var ZodMessageFieldType = {
1869
+ is: function(schema) {
1870
+ const deepSchema = ZodPassthroughType.pass(schema);
1871
+ const zodTypes = ZodMessageFieldTypeTuple.get();
1872
+ return zodTypes.includes(deepSchema._zod.def.type);
1873
+ }
1874
+ };
1875
+ var ZodMessageOneOfFieldTypeTuple = {
1876
+ new: function(values) {
1877
+ return values;
1878
+ },
1879
+ get: () => {
1880
+ return ZodMessageOneOfFieldTypeTuple.new(["union"]);
1881
+ }
1882
+ };
1883
+ var ZodMessageOneOfFieldType = {
1884
+ is: function(schema) {
1885
+ const deepSchema = ZodPassthroughType.pass(schema);
1886
+ const zodTypes = ZodMessageOneOfFieldTypeTuple.get();
1887
+ return zodTypes.includes(deepSchema._zod.def.type);
1888
+ }
1889
+ };
1890
+ var AnyZodMessageFieldTypeTuple = {
1891
+ new: function(values) {
1892
+ return values;
1893
+ },
1894
+ get: () => {
1895
+ return AnyZodMessageFieldTypeTuple.new([
1896
+ "string",
1897
+ "number",
1898
+ "bigint",
1899
+ "boolean",
1900
+ "literal",
1901
+ "template_literal",
1902
+ "array",
1903
+ "set",
1904
+ "record",
1905
+ "object",
1906
+ "enum",
1907
+ "union"
1908
+ ]);
1909
+ }
1910
+ };
1911
+ var AnyZodMessageFieldType = {
1912
+ is: function(schema) {
1913
+ const deepSchema = ZodPassthroughType.pass(schema);
1914
+ const zodTypes = AnyZodMessageFieldTypeTuple.get();
1915
+ return zodTypes.includes(deepSchema._zod.def.type);
1916
+ }
1917
+ };
1918
+
1919
+ // src/zod_converter/asserts/any_zod_message_field_type.ts
1920
+ var assertsAnyZodMessageFieldType = function(schema) {
1921
+ if (!AnyZodMessageFieldType.is(schema)) {
1922
+ const validZodTypes = AnyZodMessageFieldTypeTuple.get();
1923
+ throw SchemaError.new(
1924
+ `The schema type should be one of: [${validZodTypes.join(", ")}]`,
1925
+ schema,
1926
+ "assertsAnyZodMessageFieldType"
1927
+ );
1928
+ }
1929
+ };
1930
+
1931
+ // src/zod_converter/types/dynamic_size.ts
1932
+ var ZodDynamicSizeTypeTuple = {
1933
+ new: function(values) {
1934
+ return values;
1935
+ }
1936
+ };
1937
+ var ZodDynamicSizeType = {
1938
+ is: function(schema) {
1939
+ const deepSchema = ZodPassthroughType.pass(schema);
1940
+ const zodTypes = ZodDynamicSizeTypeTuple.new(["array", "set", "record"]);
1941
+ return zodTypes.includes(deepSchema._zod.def.type);
1942
+ }
1943
+ };
1944
+ var ZodRepeatedInnerTypeTuple = {
1945
+ new: function(values) {
1946
+ return values;
1947
+ },
1948
+ get: () => {
1949
+ return ZodRepeatedInnerTypeTuple.new([
1950
+ "string",
1951
+ "number",
1952
+ "bigint",
1953
+ "boolean",
1954
+ "literal",
1955
+ "template_literal",
1956
+ "object",
1957
+ "enum",
1958
+ "set",
1959
+ "array"
1960
+ ]);
1961
+ }
1962
+ };
1963
+ var ZodRepeatedInnerType = {
1964
+ is: function(schema) {
1965
+ const deepSchema = ZodPassthroughType.pass(schema);
1966
+ const zodTypes = ZodRepeatedInnerTypeTuple.get();
1967
+ return zodTypes.includes(deepSchema._zod.def.type);
1968
+ }
1969
+ };
1970
+ var ZodMapValueTypeTuple = {
1971
+ new: function(values) {
1972
+ return values;
1973
+ },
1974
+ get: () => {
1975
+ return ZodMapValueTypeTuple.new([
1976
+ "string",
1977
+ "number",
1978
+ "bigint",
1979
+ "boolean",
1980
+ "literal",
1981
+ "template_literal",
1982
+ "object",
1983
+ "enum"
1984
+ ]);
1985
+ }
1986
+ };
1987
+ var ZodMapValueType = {
1988
+ is: function(schema) {
1989
+ const deepSchema = ZodPassthroughType.pass(schema);
1990
+ const zodTypes = ZodMapValueTypeTuple.get();
1991
+ return zodTypes.includes(deepSchema._zod.def.type);
1992
+ }
1993
+ };
1994
+
1995
+ // src/zod_converter/asserts/zod_map_value.ts
1996
+ var assertsZodMapValueType = function(schema) {
1997
+ if (!ZodMapValueType.is(schema)) {
1998
+ const validZodTypes = ZodMapValueTypeTuple.get();
1999
+ throw SchemaError.new(
2000
+ `The schema type should be one of: [${validZodTypes.join(", ")}]`,
2001
+ schema,
2002
+ "assertsZodMapValueType"
2003
+ );
2004
+ }
2005
+ };
2006
+
2007
+ // src/zod_converter/asserts/zod_repeated_inner_type.ts
2008
+ var assertsZodRepeatedInnerType = function(schema) {
2009
+ if (!ZodRepeatedInnerType.is(schema)) {
2010
+ const validZodTypes = ZodRepeatedInnerTypeTuple.get();
2011
+ throw SchemaError.new(
2012
+ `The schema type should be one of: [${validZodTypes.join(", ")}]`,
2013
+ schema,
2014
+ "assertsZodRepeatedInnerType"
2015
+ );
2016
+ }
2017
+ };
2018
+
2019
+ // src/zod_converter/types/scalars.ts
2020
+ var ZodScalarTypeTuple = {
2021
+ new: function(values) {
2022
+ return values;
2023
+ },
2024
+ get: () => {
2025
+ return ZodScalarTypeTuple.new([
2026
+ "string",
2027
+ "number",
2028
+ "bigint",
2029
+ "boolean",
2030
+ "literal",
2031
+ "template_literal"
2032
+ ]);
2033
+ }
2034
+ };
2035
+ var ZodScalarType = {
2036
+ is: function(schema) {
2037
+ const deepSchema = ZodPassthroughType.pass(schema);
2038
+ const zodTypes = ZodScalarTypeTuple.get();
2039
+ return zodTypes.includes(deepSchema._zod.def.type);
2040
+ }
2041
+ };
2042
+
2043
+ // src/zod_converter/asserts/zod_scalar_type.ts
2044
+ var assertsZodScalarType = function(schema) {
2045
+ if (!ZodScalarType.is(schema)) {
2046
+ const validZodTypes = ZodScalarTypeTuple.get();
2047
+ throw SchemaError.new(
2048
+ `The schema type should be one of: [${validZodTypes.join(", ")}]`,
2049
+ schema,
2050
+ "assertsZodScalarType"
2051
+ );
2052
+ }
2053
+ };
2054
+
2055
+ // src/zod_converter/classes/zod_dynamic_size_converter.ts
2056
+ var import_pluralize = __toESM(require("pluralize"));
2057
+ var import_ts_pattern6 = require("ts-pattern");
2058
+ var ZodDynamicSizeConverter = class {
2059
+ constructor(transformers) {
2060
+ this.transformers = transformers;
2061
+ }
2062
+ convert(key, rootSchema) {
2063
+ const deepSchema = ZodPassthroughType.pass(rootSchema);
2064
+ return (0, import_ts_pattern6.match)(deepSchema).returnType().with(
2065
+ {
2066
+ _zod: {
2067
+ def: {
2068
+ type: "array"
2069
+ }
2070
+ }
2071
+ },
2072
+ (schema) => {
2073
+ const converter = new ZodMessageFieldTypeConverter(this.transformers);
2074
+ assertsZodRepeatedInnerType(schema._zod.def.element);
2075
+ const inner = converter.convert(
2076
+ (0, import_pluralize.default)(key, 1),
2077
+ schema._zod.def.element
2078
+ );
2079
+ return Proto3RepeatedType.new({
2080
+ inner
2081
+ });
2082
+ }
2083
+ ).with(
2084
+ {
2085
+ _zod: {
2086
+ def: {
2087
+ type: "set"
2088
+ }
2089
+ }
2090
+ },
2091
+ (schema) => {
2092
+ const converter = new ZodMessageFieldTypeConverter(this.transformers);
2093
+ assertsZodRepeatedInnerType(schema._zod.def.valueType);
2094
+ const inner = converter.convert(key, schema._zod.def.valueType);
2095
+ return Proto3RepeatedType.new({
2096
+ inner
2097
+ });
2098
+ }
2099
+ ).with(
2100
+ {
2101
+ _zod: {
2102
+ def: {
2103
+ type: "record"
2104
+ }
2105
+ }
2106
+ },
2107
+ (schema) => {
2108
+ const converter = new ZodMessageFieldTypeConverter(this.transformers);
2109
+ assertsZodScalarType(schema._zod.def.keyType);
2110
+ const keyType = converter.convert(key, schema._zod.def.keyType);
2111
+ assertsZodMapValueType(schema._zod.def.valueType);
2112
+ const valueType = converter.convert(key, schema._zod.def.valueType);
2113
+ return Proto3MapType.new({
2114
+ key: keyType,
2115
+ value: valueType
2116
+ });
2117
+ }
2118
+ ).exhaustive();
2119
+ }
2120
+ };
2121
+
2122
+ // src/zod_converter/helpers/is_format_compatible.ts
2123
+ var isFormatCompatible = (formatValues, object) => {
2124
+ if (object.format === null) {
2125
+ return false;
2126
+ }
2127
+ return formatValues.includes(object.format);
2128
+ };
2129
+
2130
+ // src/zod_converter/asserts/zod_format.ts
2131
+ var assertsZodFormat = function(formatValues, object) {
2132
+ if (!isFormatCompatible(formatValues, object)) {
2133
+ throw SchemaError.new(
2134
+ `The schema should be uses these formats: [${formatValues.join(", ")}]`,
2135
+ object
2136
+ );
2137
+ }
2138
+ };
2139
+
2140
+ // src/zod_converter/classes/zod_scalar_converter.ts
2141
+ var import_ts_pattern7 = require("ts-pattern");
2142
+ var ZodScalarConverter = class {
2143
+ convert(rootSchema) {
2144
+ const deepSchema = ZodPassthroughType.pass(rootSchema);
2145
+ return (0, import_ts_pattern7.match)(deepSchema).returnType().with(
2146
+ {
2147
+ _zod: {
2148
+ def: {
2149
+ type: "string"
2150
+ }
2151
+ }
2152
+ },
2153
+ () => Proto3StringType.new()
2154
+ ).with(
2155
+ {
2156
+ _zod: {
2157
+ def: {
2158
+ type: "number"
2159
+ }
2160
+ }
2161
+ },
2162
+ (schema) => {
2163
+ if (schema.format === null) {
2164
+ return Proto3DoubleType.new();
2165
+ }
2166
+ assertsZodFormat(
2167
+ ["safeint", "float32", "float64", "int32", "uint32"],
2168
+ schema
2169
+ );
2170
+ return (0, import_ts_pattern7.match)(schema).with({ format: "safeint" }, () => {
2171
+ return Proto3Int64Type.new();
2172
+ }).with({ format: "int32" }, () => Proto3Int32Type.new()).with({ format: "float32" }, () => Proto3FloatType.new()).with({ format: "float64" }, () => Proto3DoubleType.new()).with({ format: "uint32" }, () => Proto3UInt32Type.new()).exhaustive();
2173
+ }
2174
+ ).with(
2175
+ {
2176
+ _zod: {
2177
+ def: {
2178
+ type: "bigint"
2179
+ }
2180
+ }
2181
+ },
2182
+ (schema) => {
2183
+ assertsZodFormat(["int64", "uint64"], schema);
2184
+ return (0, import_ts_pattern7.match)(schema).with({ format: "int64" }, () => Proto3Int64Type.new()).with({ format: "uint64" }, () => Proto3UInt64Type.new()).exhaustive();
2185
+ }
2186
+ ).with(
2187
+ {
2188
+ _zod: {
2189
+ def: {
2190
+ type: "boolean"
2191
+ }
2192
+ }
2193
+ },
2194
+ () => Proto3BoolType.new()
2195
+ ).with(
2196
+ {
2197
+ _zod: {
2198
+ def: {
2199
+ type: "literal"
2200
+ }
2201
+ }
2202
+ },
2203
+ () => Proto3StringType.new()
2204
+ ).with(
2205
+ {
2206
+ _zod: {
2207
+ def: {
2208
+ type: "template_literal"
2209
+ }
2210
+ }
2211
+ },
2212
+ () => Proto3StringType.new()
2213
+ ).exhaustive();
2214
+ }
2215
+ };
2216
+
2217
+ // src/zod_converter/classes/zod_message_field_type_converter.ts
2218
+ var ZodMessageFieldTypeConverter = class {
2219
+ constructor(transformers) {
2220
+ this.transformers = transformers;
2221
+ }
2222
+ convert(key, schema) {
2223
+ if (ZodScalarType.is(schema)) {
2224
+ const converter = new ZodScalarConverter();
2225
+ return converter.convert(schema);
2226
+ }
2227
+ if (ZodDynamicSizeType.is(schema)) {
2228
+ const converter = new ZodDynamicSizeConverter(this.transformers);
2229
+ return converter.convert(key, schema);
2230
+ }
2231
+ if (AnyZodMessage.is(schema)) {
2232
+ const converter = new ZodMessageConverter(this.transformers);
2233
+ return converter.convert(key, schema);
2234
+ }
2235
+ throw SchemaError.new("Not possible", schema);
2236
+ }
2237
+ };
2238
+
2239
+ // src/zod_converter/helpers/get_zod_schema_comments.ts
2240
+ var getZodSchemaComments = function(schema) {
2241
+ const allMeta = ZodPassthroughType.getMetaAsDeepAsPossible(schema);
2242
+ const descriptions = allMeta.map((meta) => meta.description).filter(Boolean);
2243
+ const comments = descriptions.map((description) => description.split("\n")).flat();
2244
+ let startIndex = -1;
2245
+ let endIndex = -1;
2246
+ for (let index = 0; index < comments.length; index++) {
2247
+ const comment = comments[index];
2248
+ if (comment === "") {
2249
+ continue;
2250
+ } else {
2251
+ startIndex = index;
2252
+ break;
2253
+ }
2254
+ }
2255
+ for (let index = comments.length - 1; index >= 0; index--) {
2256
+ const comment = comments[index];
2257
+ if (comment === "") {
2258
+ continue;
2259
+ } else {
2260
+ endIndex = index;
2261
+ break;
2262
+ }
2263
+ }
2264
+ if (startIndex === -1 || endIndex === -1) {
2265
+ return [];
2266
+ }
2267
+ return comments.slice(startIndex, endIndex + 1);
2268
+ };
2269
+
2270
+ // src/zod_converter/classes/zod_message_field_converter.ts
2271
+ var import_change_case = require("change-case");
2272
+ var ZodMessageFieldConverter = class {
2273
+ constructor(message, transformers) {
2274
+ this.message = message;
2275
+ this.transformers = transformers;
2276
+ }
2277
+ convert(key, rootSchema, optionalState) {
2278
+ const deepSchema = ZodPassthroughType.pass(rootSchema);
2279
+ const converter = new ZodMessageFieldTypeConverter(this.transformers);
2280
+ optionalState ??= isZodSchemaOptional(rootSchema) ? "PRESENT" : "NONE";
2281
+ const index = this.message.getNextIndex();
2282
+ const type = converter.convert(key, deepSchema);
2283
+ const field = Proto3MessageField.new({
2284
+ index,
2285
+ key: (0, import_change_case.snakeCase)(key),
2286
+ optionalState,
2287
+ type,
2288
+ extensions: [],
2289
+ comments: getZodSchemaComments(rootSchema)
2290
+ });
2291
+ const updatedField = this.transformers.messageField.reduce(
2292
+ (field2, transformer) => {
2293
+ return transformer.transform(rootSchema, field2);
2294
+ },
2295
+ field
2296
+ );
2297
+ return updatedField;
2298
+ }
2299
+ };
2300
+
2301
+ // src/zod_converter/asserts/zod_message_field_type.ts
2302
+ var assertsZodMessageFieldType = function(schema) {
2303
+ if (!ZodMessageFieldType.is(schema)) {
2304
+ const validZodTypes = ZodMessageFieldTypeTuple.get();
2305
+ throw SchemaError.new(
2306
+ `The schema type should be one of: [${validZodTypes.join(", ")}]`,
2307
+ schema,
2308
+ "assertsZodMessageFieldType"
2309
+ );
2310
+ }
2311
+ };
2312
+
2313
+ // src/zod_converter/classes/zod_message_one_of_field_converter.ts
2314
+ var import_change_case2 = require("change-case");
2315
+ var ZodMessageOneOfFieldConverter = class {
2316
+ constructor(message, transformers) {
2317
+ this.message = message;
2318
+ this.transformers = transformers;
2319
+ }
2320
+ getSubField(schema, key) {
2321
+ const converter = new ZodMessageFieldConverter(this.message, this.transformers);
2322
+ assertsZodMessageFieldType(schema);
2323
+ const subField = converter.convert(key, schema, "NOT_NEEDED");
2324
+ return subField;
2325
+ }
2326
+ convert(key, rootSchema) {
2327
+ const deepSchema = ZodPassthroughType.pass(rootSchema);
2328
+ let subFields = [];
2329
+ for (let subFieldIndex = 0; subFieldIndex < deepSchema._zod.def.options.length; subFieldIndex++) {
2330
+ const unionOptionSchema = deepSchema._zod.def.options[subFieldIndex];
2331
+ const caseName = unionOptionSchema.shape.$case._zod.def.values;
2332
+ const valueSchema = unionOptionSchema.shape.value;
2333
+ assertsOneElementArray(caseName);
2334
+ const subField = this.getSubField(valueSchema, caseName[0]);
2335
+ subFields.push(subField);
2336
+ }
2337
+ for (let subFieldIndex = 0; subFieldIndex < subFields.length; subFieldIndex++) {
2338
+ const subField = subFields[subFieldIndex];
2339
+ subField.index = this.message.getNextIndex() + subFieldIndex;
2340
+ }
2341
+ const field = Proto3MessageOneOfField.new({
2342
+ key: (0, import_change_case2.snakeCase)(key),
2343
+ subFields,
2344
+ extensions: [],
2345
+ comments: getZodSchemaComments(rootSchema)
2346
+ });
2347
+ const updatedField = this.transformers.messageOneOfField.reduce(
2348
+ (field2, transformer) => {
2349
+ return transformer.transform(rootSchema, field2);
2350
+ },
2351
+ field
2352
+ );
2353
+ return updatedField;
2354
+ }
2355
+ };
2356
+
2357
+ // src/zod_converter/classes/zod_message_converter.ts
2358
+ var import_change_case3 = require("change-case");
2359
+ var import_ts_pattern8 = require("ts-pattern");
2360
+ var ZodMessageConverter = class {
2361
+ constructor(transformers) {
2362
+ this.transformers = transformers;
2363
+ }
2364
+ convert(name, rootSchema) {
2365
+ const deepSchema = ZodPassthroughType.pass(rootSchema);
2366
+ return (0, import_ts_pattern8.match)(deepSchema).returnType().with(
2367
+ {
2368
+ _zod: {
2369
+ def: {
2370
+ type: "object"
2371
+ }
2372
+ }
2373
+ },
2374
+ (schema) => {
2375
+ const message = Proto3Message.new({
2376
+ name: (0, import_change_case3.pascalCase)(name),
2377
+ fields: [],
2378
+ extensions: [],
2379
+ comments: getZodSchemaComments(rootSchema)
2380
+ });
2381
+ for (const [key, entrySchema] of Object.entries(schema.shape)) {
2382
+ assertsAnyZodMessageFieldType(entrySchema);
2383
+ let field;
2384
+ if (ZodMessageFieldType.is(entrySchema)) {
2385
+ const converter = new ZodMessageFieldConverter(
2386
+ message,
2387
+ this.transformers
2388
+ );
2389
+ field = converter.convert(key, entrySchema);
2390
+ } else {
2391
+ const converter = new ZodMessageOneOfFieldConverter(
2392
+ message,
2393
+ this.transformers
2394
+ );
2395
+ field = converter.convert(key, entrySchema);
2396
+ }
2397
+ message.fields.push(field);
2398
+ }
2399
+ const updatedMessage = this.transformers.message.reduce(
2400
+ (message2, transformer) => {
2401
+ return transformer.transform(rootSchema, message2);
2402
+ },
2403
+ message
2404
+ );
2405
+ return updatedMessage;
2406
+ }
2407
+ ).with(
2408
+ {
2409
+ _zod: {
2410
+ def: {
2411
+ type: "enum"
2412
+ }
2413
+ }
2414
+ },
2415
+ (schema) => {
2416
+ const fields = Array.from(schema._zod.values).map((value, index) => {
2417
+ if (typeof value !== "string") {
2418
+ throw new Error(
2419
+ "This `ZodEnum` contains a value that is not a string, this is impossible depending one the `z.enum()` method type"
2420
+ );
2421
+ }
2422
+ return Proto3EnumField.new({
2423
+ index,
2424
+ key: value,
2425
+ extensions: [],
2426
+ comments: []
2427
+ });
2428
+ });
2429
+ const messageEnum = Proto3Enum.new({
2430
+ name: (0, import_change_case3.pascalCase)(name),
2431
+ fields,
2432
+ extensions: [],
2433
+ comments: getZodSchemaComments(rootSchema)
2434
+ });
2435
+ const updatedMessageEnum = this.transformers.enum.reduce(
2436
+ (messageEnum2, transformer) => {
2437
+ return transformer.transform(rootSchema, messageEnum2);
2438
+ },
2439
+ messageEnum
2440
+ );
2441
+ return updatedMessageEnum;
2442
+ }
2443
+ ).exhaustive();
2444
+ }
2445
+ };
2446
+
2447
+ // src/usage/types/functions.ts
2448
+ var Proto3RpcRawFunction = {
2449
+ into: function(raw, settings) {
2450
+ const converter = new ZodMessageConverter(settings.transformers);
2451
+ const inMessageName = raw.typePrefix ? `Input` : `${raw.name}Input`;
2452
+ const outMessageName = raw.typePrefix ? `Output` : `${raw.name}Output`;
2453
+ const convertedIn = raw.in && converter.convert(inMessageName, raw.in);
2454
+ const convertedOut = raw.out && converter.convert(outMessageName, raw.out);
2455
+ return Proto3RpcFunction.new({
2456
+ ...raw,
2457
+ typePrefix: raw.typePrefix,
2458
+ in: convertedIn ?? settings.protoVoidType,
2459
+ inStream: raw.inStream ?? false,
2460
+ out: convertedOut ?? settings.protoVoidType,
2461
+ outStream: raw.outStream ?? false,
2462
+ extensions: raw.extensions ?? [],
2463
+ comments: raw.comments ?? []
2464
+ });
2465
+ }
2466
+ };
2467
+
2468
+ // src/usage/types/services.ts
2469
+ var Proto3RpcRawService = {
2470
+ into: function(raw, settings) {
2471
+ const convertedFunctions = raw.functions.map((rawFunction) => {
2472
+ return Proto3RpcRawFunction.into(rawFunction, settings);
2473
+ });
2474
+ return Proto3RpcService.new({
2475
+ ...raw,
2476
+ typePrefix: raw.typePrefix,
2477
+ functions: convertedFunctions,
2478
+ extensions: raw.extensions ?? [],
2479
+ comments: raw.comments ?? []
2480
+ });
2481
+ }
2482
+ };
2483
+
2484
+ // src/usage/types/file.ts
2485
+ var import_change_case4 = require("change-case");
2486
+ var Proto3RawFile = {
2487
+ into: function(raw, settings) {
2488
+ const convertedService = raw.service && Proto3RpcRawService.into(raw.service, settings);
2489
+ raw.unscopedMessages ??= {};
2490
+ const converter = new ZodMessageConverter(settings.transformers);
2491
+ const convertedMessages = [];
2492
+ for (const [name, schema] of Object.entries(raw.unscopedMessages)) {
2493
+ const message = converter.convert((0, import_change_case4.pascalCase)(name), schema);
2494
+ convertedMessages.push(message);
2495
+ }
2496
+ return Proto3File.new({
2497
+ ...raw,
2498
+ syntax: raw.syntax ?? "proto3",
2499
+ service: convertedService,
2500
+ unscopedMessages: convertedMessages,
2501
+ extensions: raw.extensions ?? []
2502
+ });
2503
+ }
2504
+ };
2505
+
2506
+ // src/usage/helpers/zodToProto.ts
2507
+ var zodToProto = function(raw, settings) {
2508
+ const fullSettings = {
2509
+ transformers: settings?.transformers ?? getFullTransformers(),
2510
+ protoVoidType: settings?.protoVoidType ?? Proto3Empty.useType()
2511
+ };
2512
+ const file = Proto3RawFile.into(raw, fullSettings);
2513
+ const processor = new Proto3FileProcessor();
2514
+ const fileContent = processor.process(file);
2515
+ const fileBuilder = new FileBuilder(fileContent);
2516
+ return fileBuilder.compute();
2517
+ };
2518
+
2519
+ // src/usage/types/message.ts
2520
+ var Proto3RpcRawMessage = {
2521
+ safe: function(schema) {
2522
+ return schema;
2523
+ }
2524
+ };
2525
+
2526
+ // src/zod_converter/helpers/get_empty_transformers.ts
2527
+ var getEmptyTranformers = function() {
2528
+ return {
2529
+ message: [],
2530
+ messageField: [],
2531
+ messageOneOfField: [],
2532
+ enum: []
2533
+ };
2534
+ };
2535
+
2536
+ // src/zod_converter/helpers/is_zod_literal.ts
2537
+ var isZodLiteral = function(schema) {
2538
+ return schema._zod.def.type === "literal";
2539
+ };
2540
+
2541
+ // src/zod_converter/helpers/is_zod_literal_not_nullish_values.ts
2542
+ var import_ts_pattern9 = require("ts-pattern");
2543
+ var isZodLiteralNotNullishValues = function(schema) {
2544
+ if (!isZodLiteral(schema)) {
2545
+ return false;
2546
+ }
2547
+ return Array.from(schema.values).every((value) => {
2548
+ return (0, import_ts_pattern9.match)(typeof value).with("string", () => true).with("number", () => true).with("bigint", () => true).with("boolean", () => true).otherwise(() => false);
2549
+ });
2550
+ };
2551
+
2552
+ // src/zod/helpers/zod_one_of_union.ts
2553
+ var import_zod = __toESM(require("zod"));
2554
+ var oneOfUnion = function(cases) {
2555
+ const unionOptions = cases.map(([caseName, object]) => {
2556
+ return import_zod.default.object({ $case: import_zod.default.literal(caseName), value: object });
2557
+ });
2558
+ assertsNotEmptyArray(unionOptions);
2559
+ return import_zod.default.discriminatedUnion("$case", unionOptions);
2560
+ };
2561
+ var pz = {
2562
+ oneOfUnion
2563
+ };