ts-proto 1.181.1 → 2.0.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.
- package/build/protos/google/protobuf/compiler/plugin.d.ts +185 -0
- package/build/protos/google/protobuf/compiler/plugin.js +501 -0
- package/build/protos/google/protobuf/descriptor.d.ts +1155 -0
- package/build/protos/google/protobuf/descriptor.js +4237 -0
- package/build/protos/index.d.ts +2 -0
- package/build/protos/index.js +18 -0
- package/build/{case.js → src/case.js} +6 -7
- package/build/{context.js → src/context.js} +1 -2
- package/build/{encode.js → src/encode.js} +2 -3
- package/build/{enums.d.ts → src/enums.d.ts} +1 -0
- package/build/{enums.js → src/enums.js} +7 -8
- package/build/{generate-async-iterable.js → src/generate-async-iterable.js} +2 -3
- package/build/{generate-generic-service-definition.js → src/generate-generic-service-definition.js} +1 -2
- package/build/{generate-grpc-js.js → src/generate-grpc-js.js} +1 -2
- package/build/{generate-grpc-web.js → src/generate-grpc-web.js} +4 -5
- package/build/{generate-nestjs.js → src/generate-nestjs.js} +3 -4
- package/build/{generate-nice-grpc.js → src/generate-nice-grpc.js} +1 -2
- package/build/{generate-services.js → src/generate-services.js} +11 -12
- package/build/{generate-struct-wrappers.js → src/generate-struct-wrappers.js} +5 -6
- package/build/{generate-type-registry.js → src/generate-type-registry.js} +5 -7
- package/build/{main.d.ts → src/main.d.ts} +1 -3
- package/build/{main.js → src/main.js} +69 -84
- package/build/{options.js → src/options.js} +5 -5
- package/build/{schema.js → src/schema.js} +5 -7
- package/build/{types.js → src/types.js} +51 -53
- package/build/{utils.d.ts → src/utils.d.ts} +0 -2
- package/build/{utils.js → src/utils.js} +28 -28
- package/build/{visit.js → src/visit.js} +2 -3
- package/package.json +12 -10
- /package/build/{case.d.ts → src/case.d.ts} +0 -0
- /package/build/{context.d.ts → src/context.d.ts} +0 -0
- /package/build/{encode.d.ts → src/encode.d.ts} +0 -0
- /package/build/{generate-async-iterable.d.ts → src/generate-async-iterable.d.ts} +0 -0
- /package/build/{generate-generic-service-definition.d.ts → src/generate-generic-service-definition.d.ts} +0 -0
- /package/build/{generate-grpc-js.d.ts → src/generate-grpc-js.d.ts} +0 -0
- /package/build/{generate-grpc-web.d.ts → src/generate-grpc-web.d.ts} +0 -0
- /package/build/{generate-nestjs.d.ts → src/generate-nestjs.d.ts} +0 -0
- /package/build/{generate-nice-grpc.d.ts → src/generate-nice-grpc.d.ts} +0 -0
- /package/build/{generate-services.d.ts → src/generate-services.d.ts} +0 -0
- /package/build/{generate-struct-wrappers.d.ts → src/generate-struct-wrappers.d.ts} +0 -0
- /package/build/{generate-type-registry.d.ts → src/generate-type-registry.d.ts} +0 -0
- /package/build/{index.d.ts → src/index.d.ts} +0 -0
- /package/build/{index.js → src/index.js} +0 -0
- /package/build/{options.d.ts → src/options.d.ts} +0 -0
- /package/build/{plugin.d.ts → src/plugin.d.ts} +0 -0
- /package/build/{plugin.js → src/plugin.js} +0 -0
- /package/build/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/build/{sourceInfo.d.ts → src/sourceInfo.d.ts} +0 -0
- /package/build/{sourceInfo.js → src/sourceInfo.js} +0 -0
- /package/build/{types.d.ts → src/types.d.ts} +0 -0
- /package/build/{visit.d.ts → src/visit.d.ts} +0 -0
|
@@ -1,7 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.basicWireType = basicWireType;
|
|
4
|
+
exports.basicLongWireType = basicLongWireType;
|
|
5
|
+
exports.basicTypeName = basicTypeName;
|
|
6
|
+
exports.toReaderCall = toReaderCall;
|
|
7
|
+
exports.packedType = packedType;
|
|
8
|
+
exports.getFieldOptionsJsType = getFieldOptionsJsType;
|
|
9
|
+
exports.defaultValue = defaultValue;
|
|
10
|
+
exports.notDefaultCheck = notDefaultCheck;
|
|
11
|
+
exports.createTypeMap = createTypeMap;
|
|
12
|
+
exports.isScalar = isScalar;
|
|
13
|
+
exports.isOptionalProperty = isOptionalProperty;
|
|
14
|
+
exports.isPrimitive = isPrimitive;
|
|
15
|
+
exports.isBytes = isBytes;
|
|
16
|
+
exports.isMessage = isMessage;
|
|
17
|
+
exports.isEnum = isEnum;
|
|
18
|
+
exports.isWithinOneOf = isWithinOneOf;
|
|
19
|
+
exports.isWithinOneOfThatShouldBeUnion = isWithinOneOfThatShouldBeUnion;
|
|
20
|
+
exports.isRepeated = isRepeated;
|
|
21
|
+
exports.isLong = isLong;
|
|
22
|
+
exports.isWholeNumber = isWholeNumber;
|
|
23
|
+
exports.isMapType = isMapType;
|
|
24
|
+
exports.isObjectId = isObjectId;
|
|
25
|
+
exports.isTimestamp = isTimestamp;
|
|
26
|
+
exports.isValueType = isValueType;
|
|
27
|
+
exports.isAnyValueType = isAnyValueType;
|
|
28
|
+
exports.isAnyValueTypeName = isAnyValueTypeName;
|
|
29
|
+
exports.isBytesValueType = isBytesValueType;
|
|
30
|
+
exports.isFieldMaskType = isFieldMaskType;
|
|
31
|
+
exports.isFieldMaskTypeName = isFieldMaskTypeName;
|
|
32
|
+
exports.isListValueType = isListValueType;
|
|
33
|
+
exports.isListValueTypeName = isListValueTypeName;
|
|
34
|
+
exports.isStructType = isStructType;
|
|
35
|
+
exports.isStructTypeName = isStructTypeName;
|
|
36
|
+
exports.isLongValueType = isLongValueType;
|
|
37
|
+
exports.isEmptyType = isEmptyType;
|
|
38
|
+
exports.valueTypeName = valueTypeName;
|
|
39
|
+
exports.wrapperTypeName = wrapperTypeName;
|
|
40
|
+
exports.messageToTypeName = messageToTypeName;
|
|
41
|
+
exports.getEnumMethod = getEnumMethod;
|
|
42
|
+
exports.toTypeName = toTypeName;
|
|
43
|
+
exports.shouldGenerateJSMapType = shouldGenerateJSMapType;
|
|
44
|
+
exports.detectMapType = detectMapType;
|
|
45
|
+
exports.rawRequestType = rawRequestType;
|
|
46
|
+
exports.observableType = observableType;
|
|
47
|
+
exports.requestType = requestType;
|
|
48
|
+
exports.responseType = responseType;
|
|
49
|
+
exports.responsePromise = responsePromise;
|
|
50
|
+
exports.responseObservable = responseObservable;
|
|
51
|
+
exports.responsePromiseOrObservable = responsePromiseOrObservable;
|
|
52
|
+
exports.detectBatchMethod = detectBatchMethod;
|
|
53
|
+
exports.isJsTypeFieldOption = isJsTypeFieldOption;
|
|
5
54
|
const ts_poet_1 = require("ts-poet");
|
|
6
55
|
const ts_proto_descriptors_1 = require("ts-proto-descriptors");
|
|
7
56
|
const case_1 = require("./case");
|
|
@@ -44,7 +93,6 @@ function basicWireType(type) {
|
|
|
44
93
|
throw new Error("Invalid type " + type);
|
|
45
94
|
}
|
|
46
95
|
}
|
|
47
|
-
exports.basicWireType = basicWireType;
|
|
48
96
|
function basicLongWireType(type) {
|
|
49
97
|
switch (type) {
|
|
50
98
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_INT64:
|
|
@@ -58,7 +106,6 @@ function basicLongWireType(type) {
|
|
|
58
106
|
return undefined;
|
|
59
107
|
}
|
|
60
108
|
}
|
|
61
|
-
exports.basicLongWireType = basicLongWireType;
|
|
62
109
|
/** Returns the type name without any repeated/required/etc. labels. */
|
|
63
110
|
function basicTypeName(ctx, field, typeOptions = {}) {
|
|
64
111
|
const { options } = ctx;
|
|
@@ -100,7 +147,6 @@ function basicTypeName(ctx, field, typeOptions = {}) {
|
|
|
100
147
|
return (0, ts_poet_1.code) `${field.typeName}`;
|
|
101
148
|
}
|
|
102
149
|
}
|
|
103
|
-
exports.basicTypeName = basicTypeName;
|
|
104
150
|
/** Returns the Reader method for the primitive's read/write call. */
|
|
105
151
|
function toReaderCall(field) {
|
|
106
152
|
switch (field.type) {
|
|
@@ -139,7 +185,6 @@ function toReaderCall(field) {
|
|
|
139
185
|
throw new Error(`Not a primitive field ${field}`);
|
|
140
186
|
}
|
|
141
187
|
}
|
|
142
|
-
exports.toReaderCall = toReaderCall;
|
|
143
188
|
function packedType(type) {
|
|
144
189
|
switch (type) {
|
|
145
190
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_DOUBLE:
|
|
@@ -167,7 +212,6 @@ function packedType(type) {
|
|
|
167
212
|
return undefined;
|
|
168
213
|
}
|
|
169
214
|
}
|
|
170
|
-
exports.packedType = packedType;
|
|
171
215
|
function getFieldOptionsJsType(field, options) {
|
|
172
216
|
if (!options.useJsTypeOverride || field.options?.jstype === undefined) {
|
|
173
217
|
return;
|
|
@@ -184,7 +228,6 @@ function getFieldOptionsJsType(field, options) {
|
|
|
184
228
|
return;
|
|
185
229
|
}
|
|
186
230
|
}
|
|
187
|
-
exports.getFieldOptionsJsType = getFieldOptionsJsType;
|
|
188
231
|
function defaultValue(ctx, field) {
|
|
189
232
|
const { typeMap, options, utils, currentFile } = ctx;
|
|
190
233
|
if (options.noDefaultsForOptionals) {
|
|
@@ -261,7 +304,6 @@ function defaultValue(ctx, field) {
|
|
|
261
304
|
return (0, utils_1.nullOrUndefined)(options);
|
|
262
305
|
}
|
|
263
306
|
}
|
|
264
|
-
exports.defaultValue = defaultValue;
|
|
265
307
|
/** Creates code that checks that the field is not the default value. Supports scalars and enums. */
|
|
266
308
|
function notDefaultCheck(ctx, field, messageOptions, place) {
|
|
267
309
|
const { typeMap, options, currentFile } = ctx;
|
|
@@ -319,7 +361,6 @@ function notDefaultCheck(ctx, field, messageOptions, place) {
|
|
|
319
361
|
throw new Error("Not implemented for the given type.");
|
|
320
362
|
}
|
|
321
363
|
}
|
|
322
|
-
exports.notDefaultCheck = notDefaultCheck;
|
|
323
364
|
/** Scans all of the proto files in `request` and builds a map of proto typeName -> TS module/name. */
|
|
324
365
|
function createTypeMap(request, options) {
|
|
325
366
|
const typeMap = new Map();
|
|
@@ -336,7 +377,6 @@ function createTypeMap(request, options) {
|
|
|
336
377
|
}
|
|
337
378
|
return typeMap;
|
|
338
379
|
}
|
|
339
|
-
exports.createTypeMap = createTypeMap;
|
|
340
380
|
/** A "Scalar Value Type" as defined in https://developers.google.com/protocol-buffers/docs/proto3#scalar */
|
|
341
381
|
function isScalar(field) {
|
|
342
382
|
const scalarTypes = [
|
|
@@ -358,7 +398,6 @@ function isScalar(field) {
|
|
|
358
398
|
];
|
|
359
399
|
return scalarTypes.includes(field.type);
|
|
360
400
|
}
|
|
361
|
-
exports.isScalar = isScalar;
|
|
362
401
|
// When useOptionals='messages', non-scalar fields are translated into optional
|
|
363
402
|
// properties.
|
|
364
403
|
// When useOptionals='all', all fields are translated into
|
|
@@ -384,42 +423,33 @@ function isOptionalProperty(field, messageOptions, options, isProto3Syntax) {
|
|
|
384
423
|
isWithinOneOf(field) ||
|
|
385
424
|
field.proto3Optional);
|
|
386
425
|
}
|
|
387
|
-
exports.isOptionalProperty = isOptionalProperty;
|
|
388
426
|
/** This includes all scalars, enums and the [groups type](https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/DescriptorProtos.FieldDescriptorProto.Type.html#TYPE_GROUP) */
|
|
389
427
|
function isPrimitive(field) {
|
|
390
428
|
return !isMessage(field);
|
|
391
429
|
}
|
|
392
|
-
exports.isPrimitive = isPrimitive;
|
|
393
430
|
function isBytes(field) {
|
|
394
431
|
return field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_BYTES;
|
|
395
432
|
}
|
|
396
|
-
exports.isBytes = isBytes;
|
|
397
433
|
function isMessage(field) {
|
|
398
434
|
return field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_MESSAGE || field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_GROUP;
|
|
399
435
|
}
|
|
400
|
-
exports.isMessage = isMessage;
|
|
401
436
|
function isEnum(field) {
|
|
402
437
|
return field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_ENUM;
|
|
403
438
|
}
|
|
404
|
-
exports.isEnum = isEnum;
|
|
405
439
|
function isWithinOneOf(field) {
|
|
406
440
|
return field.hasOwnProperty("oneofIndex");
|
|
407
441
|
}
|
|
408
|
-
exports.isWithinOneOf = isWithinOneOf;
|
|
409
442
|
function isWithinOneOfThatShouldBeUnion(options, field) {
|
|
410
443
|
return (isWithinOneOf(field) &&
|
|
411
444
|
(options.oneof === options_1.OneofOption.UNIONS || options.oneof === options_1.OneofOption.UNIONS_VALUE) &&
|
|
412
445
|
!field.proto3Optional);
|
|
413
446
|
}
|
|
414
|
-
exports.isWithinOneOfThatShouldBeUnion = isWithinOneOfThatShouldBeUnion;
|
|
415
447
|
function isRepeated(field) {
|
|
416
448
|
return field.label === ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_REPEATED;
|
|
417
449
|
}
|
|
418
|
-
exports.isRepeated = isRepeated;
|
|
419
450
|
function isLong(field) {
|
|
420
451
|
return basicLongWireType(field.type) !== undefined;
|
|
421
452
|
}
|
|
422
|
-
exports.isLong = isLong;
|
|
423
453
|
function isWholeNumber(field) {
|
|
424
454
|
return (field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_INT32 ||
|
|
425
455
|
field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_INT64 ||
|
|
@@ -432,68 +462,52 @@ function isWholeNumber(field) {
|
|
|
432
462
|
field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_SFIXED32 ||
|
|
433
463
|
field.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_SFIXED64);
|
|
434
464
|
}
|
|
435
|
-
exports.isWholeNumber = isWholeNumber;
|
|
436
465
|
function isMapType(ctx, messageDesc, field) {
|
|
437
466
|
return detectMapType(ctx, messageDesc, field) !== undefined;
|
|
438
467
|
}
|
|
439
|
-
exports.isMapType = isMapType;
|
|
440
468
|
function isObjectId(field) {
|
|
441
469
|
// need to use endsWith instead of === because objectid could be imported from an external proto file
|
|
442
470
|
return field.typeName.endsWith(".ObjectId");
|
|
443
471
|
}
|
|
444
|
-
exports.isObjectId = isObjectId;
|
|
445
472
|
function isTimestamp(field) {
|
|
446
473
|
return field.typeName === ".google.protobuf.Timestamp";
|
|
447
474
|
}
|
|
448
|
-
exports.isTimestamp = isTimestamp;
|
|
449
475
|
function isValueType(ctx, field) {
|
|
450
476
|
return valueTypeName(ctx, field.typeName) !== undefined;
|
|
451
477
|
}
|
|
452
|
-
exports.isValueType = isValueType;
|
|
453
478
|
function isAnyValueType(field) {
|
|
454
479
|
return isAnyValueTypeName(field.typeName);
|
|
455
480
|
}
|
|
456
|
-
exports.isAnyValueType = isAnyValueType;
|
|
457
481
|
function isAnyValueTypeName(typeName) {
|
|
458
482
|
return typeName === "google.protobuf.Value" || typeName === ".google.protobuf.Value";
|
|
459
483
|
}
|
|
460
|
-
exports.isAnyValueTypeName = isAnyValueTypeName;
|
|
461
484
|
function isBytesValueType(field) {
|
|
462
485
|
return field.typeName === ".google.protobuf.BytesValue";
|
|
463
486
|
}
|
|
464
|
-
exports.isBytesValueType = isBytesValueType;
|
|
465
487
|
function isFieldMaskType(field) {
|
|
466
488
|
return isFieldMaskTypeName(field.typeName);
|
|
467
489
|
}
|
|
468
|
-
exports.isFieldMaskType = isFieldMaskType;
|
|
469
490
|
function isFieldMaskTypeName(typeName) {
|
|
470
491
|
return typeName === "google.protobuf.FieldMask" || typeName === ".google.protobuf.FieldMask";
|
|
471
492
|
}
|
|
472
|
-
exports.isFieldMaskTypeName = isFieldMaskTypeName;
|
|
473
493
|
function isListValueType(field) {
|
|
474
494
|
return isListValueTypeName(field.typeName);
|
|
475
495
|
}
|
|
476
|
-
exports.isListValueType = isListValueType;
|
|
477
496
|
function isListValueTypeName(typeName) {
|
|
478
497
|
return typeName === "google.protobuf.ListValue" || typeName === ".google.protobuf.ListValue";
|
|
479
498
|
}
|
|
480
|
-
exports.isListValueTypeName = isListValueTypeName;
|
|
481
499
|
function isStructType(field) {
|
|
482
500
|
return isStructTypeName(field.typeName);
|
|
483
501
|
}
|
|
484
|
-
exports.isStructType = isStructType;
|
|
485
502
|
function isStructTypeName(typeName) {
|
|
486
503
|
return typeName === "google.protobuf.Struct" || typeName === ".google.protobuf.Struct";
|
|
487
504
|
}
|
|
488
|
-
exports.isStructTypeName = isStructTypeName;
|
|
489
505
|
function isLongValueType(field) {
|
|
490
506
|
return field.typeName === ".google.protobuf.Int64Value" || field.typeName === ".google.protobuf.UInt64Value";
|
|
491
507
|
}
|
|
492
|
-
exports.isLongValueType = isLongValueType;
|
|
493
508
|
function isEmptyType(typeName) {
|
|
494
509
|
return typeName === ".google.protobuf.Empty";
|
|
495
510
|
}
|
|
496
|
-
exports.isEmptyType = isEmptyType;
|
|
497
511
|
function valueTypeName(ctx, typeName) {
|
|
498
512
|
switch (typeName) {
|
|
499
513
|
case ".google.protobuf.StringValue":
|
|
@@ -535,7 +549,6 @@ function valueTypeName(ctx, typeName) {
|
|
|
535
549
|
return undefined;
|
|
536
550
|
}
|
|
537
551
|
}
|
|
538
|
-
exports.valueTypeName = valueTypeName;
|
|
539
552
|
function wrapperTypeName(typeName) {
|
|
540
553
|
switch (typeName) {
|
|
541
554
|
case ".google.protobuf.StringValue":
|
|
@@ -556,7 +569,6 @@ function wrapperTypeName(typeName) {
|
|
|
556
569
|
return undefined;
|
|
557
570
|
}
|
|
558
571
|
}
|
|
559
|
-
exports.wrapperTypeName = wrapperTypeName;
|
|
560
572
|
function longTypeName(ctx) {
|
|
561
573
|
const { options, utils } = ctx;
|
|
562
574
|
if (options.forceLong === options_1.LongOption.LONG) {
|
|
@@ -610,7 +622,6 @@ function messageToTypeName(ctx, protoType, typeOptions = {}) {
|
|
|
610
622
|
const [module, type] = toModuleAndType(typeMap, protoType);
|
|
611
623
|
return (0, ts_poet_1.code) `${(0, utils_1.impProto)(options, module, type)}`;
|
|
612
624
|
}
|
|
613
|
-
exports.messageToTypeName = messageToTypeName;
|
|
614
625
|
/** Breaks `.some_proto_namespace.Some.Message` into `['some_proto_namespace', 'Some_Message', Descriptor]. */
|
|
615
626
|
function toModuleAndType(typeMap, protoType) {
|
|
616
627
|
return typeMap.get(protoType) || (0, utils_1.fail)(`No type found for ${protoType}`);
|
|
@@ -619,7 +630,6 @@ function getEnumMethod(ctx, enumProtoType, methodSuffix) {
|
|
|
619
630
|
const [module, type] = toModuleAndType(ctx.typeMap, enumProtoType);
|
|
620
631
|
return (0, utils_1.impProto)(ctx.options, module, `${(0, case_1.uncapitalize)(type)}${methodSuffix}`);
|
|
621
632
|
}
|
|
622
|
-
exports.getEnumMethod = getEnumMethod;
|
|
623
633
|
/** Return the TypeName for any field (primitive/message/etc.) as exposed in the interface. */
|
|
624
634
|
function toTypeName(ctx, messageDesc, field, ensureOptional = false) {
|
|
625
635
|
function finalize(type, isOptional) {
|
|
@@ -668,7 +678,6 @@ function toTypeName(ctx, messageDesc, field, ensureOptional = false) {
|
|
|
668
678
|
(isWithinOneOf(field) && field.proto3Optional) ||
|
|
669
679
|
ensureOptional);
|
|
670
680
|
}
|
|
671
|
-
exports.toTypeName = toTypeName;
|
|
672
681
|
/**
|
|
673
682
|
* For a protobuf map field, if the generated code should use the javascript Map type.
|
|
674
683
|
*
|
|
@@ -692,7 +701,6 @@ function shouldGenerateJSMapType(ctx, message, field) {
|
|
|
692
701
|
return (mapType.keyField.type === ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_BOOL ||
|
|
693
702
|
(isLong(mapType.keyField) && ctx.options.forceLong === options_1.LongOption.LONG));
|
|
694
703
|
}
|
|
695
|
-
exports.shouldGenerateJSMapType = shouldGenerateJSMapType;
|
|
696
704
|
function detectMapType(ctx, messageDesc, fieldDesc) {
|
|
697
705
|
const { typeMap } = ctx;
|
|
698
706
|
if (fieldDesc.label === ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_REPEATED &&
|
|
@@ -708,11 +716,9 @@ function detectMapType(ctx, messageDesc, fieldDesc) {
|
|
|
708
716
|
}
|
|
709
717
|
return undefined;
|
|
710
718
|
}
|
|
711
|
-
exports.detectMapType = detectMapType;
|
|
712
719
|
function rawRequestType(ctx, methodDesc, typeOptions = {}) {
|
|
713
720
|
return messageToTypeName(ctx, methodDesc.inputType, typeOptions);
|
|
714
721
|
}
|
|
715
|
-
exports.rawRequestType = rawRequestType;
|
|
716
722
|
function observableType(ctx, asType = false) {
|
|
717
723
|
if (ctx.options.useAsyncIterable) {
|
|
718
724
|
return (0, ts_poet_1.code) `AsyncIterable`;
|
|
@@ -724,7 +730,6 @@ function observableType(ctx, asType = false) {
|
|
|
724
730
|
return (0, ts_poet_1.code) `${(0, ts_poet_1.imp)("Observable@rxjs")}`;
|
|
725
731
|
}
|
|
726
732
|
}
|
|
727
|
-
exports.observableType = observableType;
|
|
728
733
|
function requestType(ctx, methodDesc, partial = false) {
|
|
729
734
|
let typeName = rawRequestType(ctx, methodDesc, { keepValueType: true });
|
|
730
735
|
if (partial) {
|
|
@@ -735,19 +740,15 @@ function requestType(ctx, methodDesc, partial = false) {
|
|
|
735
740
|
}
|
|
736
741
|
return typeName;
|
|
737
742
|
}
|
|
738
|
-
exports.requestType = requestType;
|
|
739
743
|
function responseType(ctx, methodDesc, typeOptions = {}) {
|
|
740
744
|
return messageToTypeName(ctx, methodDesc.outputType, { keepValueType: true });
|
|
741
745
|
}
|
|
742
|
-
exports.responseType = responseType;
|
|
743
746
|
function responsePromise(ctx, methodDesc) {
|
|
744
747
|
return (0, ts_poet_1.code) `Promise<${responseType(ctx, methodDesc, { keepValueType: true })}>`;
|
|
745
748
|
}
|
|
746
|
-
exports.responsePromise = responsePromise;
|
|
747
749
|
function responseObservable(ctx, methodDesc) {
|
|
748
750
|
return (0, ts_poet_1.code) `${observableType(ctx)}<${responseType(ctx, methodDesc, { keepValueType: true })}>`;
|
|
749
751
|
}
|
|
750
|
-
exports.responseObservable = responseObservable;
|
|
751
752
|
function responsePromiseOrObservable(ctx, methodDesc) {
|
|
752
753
|
const { options } = ctx;
|
|
753
754
|
if (options.returnObservable || methodDesc.serverStreaming) {
|
|
@@ -755,7 +756,6 @@ function responsePromiseOrObservable(ctx, methodDesc) {
|
|
|
755
756
|
}
|
|
756
757
|
return responsePromise(ctx, methodDesc);
|
|
757
758
|
}
|
|
758
|
-
exports.responsePromiseOrObservable = responsePromiseOrObservable;
|
|
759
759
|
function detectBatchMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
760
760
|
const { typeMap } = ctx;
|
|
761
761
|
const nameMatches = methodDesc.name.startsWith("Batch");
|
|
@@ -790,7 +790,6 @@ function detectBatchMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
790
790
|
}
|
|
791
791
|
return undefined;
|
|
792
792
|
}
|
|
793
|
-
exports.detectBatchMethod = detectBatchMethod;
|
|
794
793
|
function hasSingleRepeatedField(messageDesc) {
|
|
795
794
|
return messageDesc.field.length == 1 && messageDesc.field[0].label === ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_REPEATED;
|
|
796
795
|
}
|
|
@@ -798,4 +797,3 @@ function isJsTypeFieldOption(options, field) {
|
|
|
798
797
|
return (options.useJsTypeOverride &&
|
|
799
798
|
(field.options?.jstype === ts_proto_descriptors_1.FieldOptions_JSType.JS_NUMBER || field.options?.jstype === ts_proto_descriptors_1.FieldOptions_JSType.JS_STRING));
|
|
800
799
|
}
|
|
801
|
-
exports.isJsTypeFieldOption = isJsTypeFieldOption;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { Code, Import } from "ts-poet";
|
|
4
2
|
import { CodeGeneratorRequest, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, MethodOptions } from "ts-proto-descriptors";
|
|
5
3
|
import ReadStream = NodeJS.ReadStream;
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FormattedMethodDescriptor = void 0;
|
|
4
|
+
exports.protoFilesToGenerate = protoFilesToGenerate;
|
|
5
|
+
exports.generateIndexFiles = generateIndexFiles;
|
|
6
|
+
exports.readToBuffer = readToBuffer;
|
|
7
|
+
exports.fail = fail;
|
|
8
|
+
exports.singular = singular;
|
|
9
|
+
exports.lowerFirst = lowerFirst;
|
|
10
|
+
exports.upperFirst = upperFirst;
|
|
11
|
+
exports.maybeAddComment = maybeAddComment;
|
|
12
|
+
exports.maybePrefixPackage = maybePrefixPackage;
|
|
13
|
+
exports.assertInstanceOf = assertInstanceOf;
|
|
14
|
+
exports.getFieldJsonName = getFieldJsonName;
|
|
15
|
+
exports.getFieldName = getFieldName;
|
|
16
|
+
exports.safeAccessor = safeAccessor;
|
|
17
|
+
exports.getPropertyAccessor = getPropertyAccessor;
|
|
18
|
+
exports.impFile = impFile;
|
|
19
|
+
exports.impProto = impProto;
|
|
20
|
+
exports.tryCatchBlock = tryCatchBlock;
|
|
21
|
+
exports.arrowFunction = arrowFunction;
|
|
22
|
+
exports.nullOrUndefined = nullOrUndefined;
|
|
23
|
+
exports.maybeCheckIsNotNull = maybeCheckIsNotNull;
|
|
24
|
+
exports.maybeCheckIsNull = maybeCheckIsNull;
|
|
25
|
+
exports.oneofValueName = oneofValueName;
|
|
26
|
+
exports.withOrMaybeCheckIsNotNull = withOrMaybeCheckIsNotNull;
|
|
27
|
+
exports.withOrMaybeCheckIsNull = withOrMaybeCheckIsNull;
|
|
28
|
+
exports.withAndMaybeCheckIsNotNull = withAndMaybeCheckIsNotNull;
|
|
29
|
+
exports.withAndMaybeCheckIsNull = withAndMaybeCheckIsNull;
|
|
30
|
+
exports.getVersions = getVersions;
|
|
4
31
|
const path = require("path");
|
|
5
32
|
const ts_poet_1 = require("ts-poet");
|
|
6
33
|
const options_1 = require("./options");
|
|
@@ -8,7 +35,6 @@ const case_1 = require("./case");
|
|
|
8
35
|
function protoFilesToGenerate(request) {
|
|
9
36
|
return request.protoFile.filter((f) => request.fileToGenerate.includes(f.name));
|
|
10
37
|
}
|
|
11
|
-
exports.protoFilesToGenerate = protoFilesToGenerate;
|
|
12
38
|
function generateIndexFiles(files, options) {
|
|
13
39
|
const packageTree = {
|
|
14
40
|
index: "index.ts",
|
|
@@ -42,7 +68,6 @@ function generateIndexFiles(files, options) {
|
|
|
42
68
|
}
|
|
43
69
|
return indexFiles;
|
|
44
70
|
}
|
|
45
|
-
exports.generateIndexFiles = generateIndexFiles;
|
|
46
71
|
function readToBuffer(stream) {
|
|
47
72
|
return new Promise((resolve) => {
|
|
48
73
|
const ret = [];
|
|
@@ -59,23 +84,18 @@ function readToBuffer(stream) {
|
|
|
59
84
|
});
|
|
60
85
|
});
|
|
61
86
|
}
|
|
62
|
-
exports.readToBuffer = readToBuffer;
|
|
63
87
|
function fail(message) {
|
|
64
88
|
throw new Error(message);
|
|
65
89
|
}
|
|
66
|
-
exports.fail = fail;
|
|
67
90
|
function singular(name) {
|
|
68
91
|
return name.substring(0, name.length - 1); // drop the 's', which is extremely naive
|
|
69
92
|
}
|
|
70
|
-
exports.singular = singular;
|
|
71
93
|
function lowerFirst(name) {
|
|
72
94
|
return name.substring(0, 1).toLowerCase() + name.substring(1);
|
|
73
95
|
}
|
|
74
|
-
exports.lowerFirst = lowerFirst;
|
|
75
96
|
function upperFirst(name) {
|
|
76
97
|
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
|
77
98
|
}
|
|
78
|
-
exports.upperFirst = upperFirst;
|
|
79
99
|
// Since we don't know what form the comment originally took, it may contain closing block comments.
|
|
80
100
|
const CloseComment = /\*\//g;
|
|
81
101
|
/** Removes potentially harmful characters from comments and pushes it into chunks. */
|
|
@@ -115,12 +135,10 @@ function maybeAddComment(options, desc, chunks, deprecated, prefix = "") {
|
|
|
115
135
|
chunks.push((0, ts_poet_1.code) `\n\n${comment}\n\n`);
|
|
116
136
|
}
|
|
117
137
|
}
|
|
118
|
-
exports.maybeAddComment = maybeAddComment;
|
|
119
138
|
function maybePrefixPackage(fileDesc, rest) {
|
|
120
139
|
const prefix = fileDesc.package === "" ? "" : `${fileDesc.package}.`;
|
|
121
140
|
return `${prefix}${rest}`;
|
|
122
141
|
}
|
|
123
|
-
exports.maybePrefixPackage = maybePrefixPackage;
|
|
124
142
|
/**
|
|
125
143
|
* Asserts that an object is an instance of a certain class
|
|
126
144
|
* @param obj The object to check
|
|
@@ -131,7 +149,6 @@ function assertInstanceOf(obj, constructor) {
|
|
|
131
149
|
throw new Error(`Expected instance of ${constructor.name}`);
|
|
132
150
|
}
|
|
133
151
|
}
|
|
134
|
-
exports.assertInstanceOf = assertInstanceOf;
|
|
135
152
|
/**
|
|
136
153
|
* A MethodDescriptorProto subclass that adds formatted properties
|
|
137
154
|
*/
|
|
@@ -194,14 +211,12 @@ function getFieldJsonName(field, options) {
|
|
|
194
211
|
return isJsonNameSet ? field.jsonName : field.name;
|
|
195
212
|
}
|
|
196
213
|
}
|
|
197
|
-
exports.getFieldJsonName = getFieldJsonName;
|
|
198
214
|
function getFieldName(field, options) {
|
|
199
215
|
if (options.useJsonName) {
|
|
200
216
|
return field.jsonName;
|
|
201
217
|
}
|
|
202
218
|
return (0, case_1.maybeSnakeToCamel)(field.name, options);
|
|
203
219
|
}
|
|
204
|
-
exports.getFieldName = getFieldName;
|
|
205
220
|
/**
|
|
206
221
|
* https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/the-dangers-of-square-bracket-notation.md
|
|
207
222
|
*/
|
|
@@ -212,7 +227,6 @@ function isValidIdentifier(propertyName) {
|
|
|
212
227
|
function safeAccessor(propertyName) {
|
|
213
228
|
return isValidIdentifier(propertyName) ? propertyName : JSON.stringify(propertyName);
|
|
214
229
|
}
|
|
215
|
-
exports.safeAccessor = safeAccessor;
|
|
216
230
|
/**
|
|
217
231
|
* Returns a snippet for reading an object's property, such as `foo.bar`, or `foo['bar']` if the property name contains unusual characters.
|
|
218
232
|
* For simplicity, we don't match the ECMA 5/6 rules for valid identifiers exactly, and return array syntax liberally.
|
|
@@ -225,11 +239,9 @@ function getPropertyAccessor(objectName, propertyName, optional = false) {
|
|
|
225
239
|
? `${objectName}${optional ? "?" : ""}.${propertyName}`
|
|
226
240
|
: `${objectName}${optional ? "?." : ""}[${safeAccessor(propertyName)}]`;
|
|
227
241
|
}
|
|
228
|
-
exports.getPropertyAccessor = getPropertyAccessor;
|
|
229
242
|
function impFile(options, spec) {
|
|
230
243
|
return (0, ts_poet_1.imp)(`${spec}${options.importSuffix}`);
|
|
231
244
|
}
|
|
232
|
-
exports.impFile = impFile;
|
|
233
245
|
function impProto(options, module, type) {
|
|
234
246
|
const prefix = options.onlyTypes ? "t:" : "";
|
|
235
247
|
const protoFile = `${module}.proto`;
|
|
@@ -238,7 +250,6 @@ function impProto(options, module, type) {
|
|
|
238
250
|
}
|
|
239
251
|
return (0, ts_poet_1.imp)(`${prefix}${type}@./${module}${options.fileSuffix}${options.importSuffix}`);
|
|
240
252
|
}
|
|
241
|
-
exports.impProto = impProto;
|
|
242
253
|
function tryCatchBlock(tryBlock, handleErrorBlock) {
|
|
243
254
|
return (0, ts_poet_1.code) `try {
|
|
244
255
|
${tryBlock}
|
|
@@ -246,46 +257,36 @@ function tryCatchBlock(tryBlock, handleErrorBlock) {
|
|
|
246
257
|
${handleErrorBlock}
|
|
247
258
|
}`;
|
|
248
259
|
}
|
|
249
|
-
exports.tryCatchBlock = tryCatchBlock;
|
|
250
260
|
function arrowFunction(params, body, isOneLine = true) {
|
|
251
261
|
if (isOneLine) {
|
|
252
262
|
return (0, ts_poet_1.code) `(${params}) => ${body}`;
|
|
253
263
|
}
|
|
254
264
|
return (0, ts_poet_1.code) `(${params}) => { ${body} }`;
|
|
255
265
|
}
|
|
256
|
-
exports.arrowFunction = arrowFunction;
|
|
257
266
|
function nullOrUndefined(options, hasProto3Optional = false) {
|
|
258
267
|
return options.useNullAsOptional ? `null ${hasProto3Optional ? "| undefined" : ""}` : "undefined";
|
|
259
268
|
}
|
|
260
|
-
exports.nullOrUndefined = nullOrUndefined;
|
|
261
269
|
function maybeCheckIsNotNull(options, typeName, prefix) {
|
|
262
270
|
return options.useNullAsOptional ? ` ${prefix} ${typeName} !== null` : "";
|
|
263
271
|
}
|
|
264
|
-
exports.maybeCheckIsNotNull = maybeCheckIsNotNull;
|
|
265
272
|
function maybeCheckIsNull(options, typeName, prefix) {
|
|
266
273
|
return options.useNullAsOptional ? ` ${prefix} ${typeName} === null` : "";
|
|
267
274
|
}
|
|
268
|
-
exports.maybeCheckIsNull = maybeCheckIsNull;
|
|
269
275
|
function oneofValueName(fieldName, options) {
|
|
270
276
|
return options.oneof === options_1.OneofOption.UNIONS ? fieldName : "value";
|
|
271
277
|
}
|
|
272
|
-
exports.oneofValueName = oneofValueName;
|
|
273
278
|
function withOrMaybeCheckIsNotNull(options, typeName) {
|
|
274
279
|
return maybeCheckIsNotNull(options, typeName, "||");
|
|
275
280
|
}
|
|
276
|
-
exports.withOrMaybeCheckIsNotNull = withOrMaybeCheckIsNotNull;
|
|
277
281
|
function withOrMaybeCheckIsNull(options, typeName) {
|
|
278
282
|
return maybeCheckIsNull(options, typeName, "||");
|
|
279
283
|
}
|
|
280
|
-
exports.withOrMaybeCheckIsNull = withOrMaybeCheckIsNull;
|
|
281
284
|
function withAndMaybeCheckIsNotNull(options, typeName) {
|
|
282
285
|
return maybeCheckIsNotNull(options, typeName, "&&");
|
|
283
286
|
}
|
|
284
|
-
exports.withAndMaybeCheckIsNotNull = withAndMaybeCheckIsNotNull;
|
|
285
287
|
function withAndMaybeCheckIsNull(options, typeName) {
|
|
286
288
|
return maybeCheckIsNotNull(options, typeName, "&&");
|
|
287
289
|
}
|
|
288
|
-
exports.withAndMaybeCheckIsNull = withAndMaybeCheckIsNull;
|
|
289
290
|
async function getVersions(request) {
|
|
290
291
|
let protocVersion = "unknown";
|
|
291
292
|
if (request.compilerVersion) {
|
|
@@ -300,4 +301,3 @@ async function getVersions(request) {
|
|
|
300
301
|
tsProtoVersion,
|
|
301
302
|
};
|
|
302
303
|
}
|
|
303
|
-
exports.getVersions = getVersions;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.visit = visit;
|
|
4
|
+
exports.visitServices = visitServices;
|
|
4
5
|
const sourceInfo_1 = require("./sourceInfo");
|
|
5
6
|
const case_1 = require("./case");
|
|
6
7
|
function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPrefix = "", protoPrefix = "") {
|
|
@@ -29,7 +30,6 @@ function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPref
|
|
|
29
30
|
visit(message, nestedSourceInfo, messageFn, options, enumFn, tsFullName + delim, protoFullName + ".");
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
|
-
exports.visit = visit;
|
|
33
33
|
const builtInNames = ["Date"];
|
|
34
34
|
/** Potentially suffixes `Message` to names to avoid conflicts, i.e. with `Date`. */
|
|
35
35
|
function messageName(message) {
|
|
@@ -42,4 +42,3 @@ function visitServices(proto, sourceInfo, serviceFn) {
|
|
|
42
42
|
serviceFn(serviceDesc, nestedSourceInfo);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
exports.visitServices = visitServices;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -36,17 +36,18 @@
|
|
|
36
36
|
"@nestjs/core": "^9.4.3",
|
|
37
37
|
"@nestjs/microservices": "^9.4.3",
|
|
38
38
|
"@semantic-release/changelog": "^6.0.3",
|
|
39
|
-
"@semantic-release/commit-analyzer": "^
|
|
39
|
+
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
40
40
|
"@semantic-release/exec": "^6.0.3",
|
|
41
41
|
"@semantic-release/git": "^10.0.1",
|
|
42
|
-
"@semantic-release/github": "^
|
|
43
|
-
"@semantic-release/npm": "^
|
|
44
|
-
"@semantic-release/release-notes-generator": "^
|
|
42
|
+
"@semantic-release/github": "^10.1.6",
|
|
43
|
+
"@semantic-release/npm": "^12.0.1",
|
|
44
|
+
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
45
45
|
"@tsconfig/strictest": "^2.0.1",
|
|
46
46
|
"@types/jest": "^29.5.3",
|
|
47
47
|
"@types/node": "^16.18.38",
|
|
48
48
|
"@types/object-hash": "^3.0.2",
|
|
49
49
|
"chokidar": "^3.5.3",
|
|
50
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
50
51
|
"dataloader": "^2.2.2",
|
|
51
52
|
"jest": "^29.6.1",
|
|
52
53
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
@@ -55,20 +56,21 @@
|
|
|
55
56
|
"nice-grpc": "^2.1.4",
|
|
56
57
|
"object-hash": "^3.0.0",
|
|
57
58
|
"prettier": "^2.8.8",
|
|
59
|
+
"protobufjs": "^7.2.4",
|
|
58
60
|
"protobufjs-cli": "^1.1.1",
|
|
59
61
|
"reflect-metadata": "^0.1.13",
|
|
60
62
|
"rxjs": "^7.8.1",
|
|
61
|
-
"semantic-release": "^
|
|
63
|
+
"semantic-release": "^24.0.0",
|
|
62
64
|
"ts-jest": "^29.1.1",
|
|
63
|
-
"tsx": "^4.
|
|
64
|
-
"typescript": "^5.
|
|
65
|
+
"tsx": "^4.17.0",
|
|
66
|
+
"typescript": "^5.5.4",
|
|
65
67
|
"uglify-js": "^3.17.4"
|
|
66
68
|
},
|
|
67
69
|
"dependencies": {
|
|
70
|
+
"@bufbuild/protobuf": "^2.0.0",
|
|
68
71
|
"case-anything": "^2.1.13",
|
|
69
|
-
"protobufjs": "^7.2.4",
|
|
70
72
|
"ts-poet": "^6.7.0",
|
|
71
73
|
"ts-proto-descriptors": "1.16.0"
|
|
72
74
|
},
|
|
73
|
-
"packageManager": "yarn@
|
|
75
|
+
"packageManager": "yarn@4.4.0"
|
|
74
76
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|