@aptre/protobuf-es-lite 0.2.6 → 0.2.8

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 (121) hide show
  1. package/.ignore +1 -0
  2. package/README.md +25 -24
  3. package/bin/protoc-gen-es-lite +3 -3
  4. package/dist/binary-encoding.d.ts +420 -0
  5. package/dist/binary-encoding.js +437 -0
  6. package/dist/binary.d.ts +35 -2
  7. package/dist/binary.js +69 -66
  8. package/dist/codegen-info.d.ts +43 -0
  9. package/dist/codegen-info.js +72 -0
  10. package/dist/create-descriptor-set.d.ts +36 -0
  11. package/dist/create-descriptor-set.js +936 -0
  12. package/dist/descriptor-set.d.ts +672 -0
  13. package/dist/{editions.js → descriptor-set.js} +0 -11
  14. package/dist/enum.d.ts +35 -1
  15. package/dist/feature-set.d.ts +19 -0
  16. package/dist/feature-set.js +103 -0
  17. package/dist/field-wrapper.d.ts +7 -3
  18. package/dist/field-wrapper.js +30 -1
  19. package/dist/field.d.ts +8 -19
  20. package/dist/field.js +15 -117
  21. package/dist/google/index.d.ts +9 -0
  22. package/dist/google/index.js +41 -0
  23. package/dist/google/protobuf/any.pb.d.ts +139 -0
  24. package/dist/google/protobuf/any.pb.js +42 -0
  25. package/dist/google/protobuf/api.pb.d.ts +252 -0
  26. package/dist/google/protobuf/api.pb.js +70 -0
  27. package/dist/google/protobuf/compiler/plugin.pb.d.ts +240 -0
  28. package/dist/google/protobuf/compiler/plugin.pb.js +203 -0
  29. package/dist/google/protobuf/descriptor.pb.d.ts +2132 -0
  30. package/dist/google/protobuf/descriptor.pb.js +1080 -0
  31. package/dist/google/protobuf/duration.pb.d.ts +92 -0
  32. package/dist/google/protobuf/duration.pb.js +42 -0
  33. package/dist/google/protobuf/empty.pb.d.ts +18 -0
  34. package/dist/google/protobuf/empty.pb.js +39 -0
  35. package/dist/google/protobuf/source_context.pb.d.ts +21 -0
  36. package/dist/google/protobuf/source_context.pb.js +41 -0
  37. package/dist/google/protobuf/struct.pb.d.ts +121 -0
  38. package/dist/google/protobuf/struct.pb.js +83 -0
  39. package/dist/google/protobuf/timestamp.pb.d.ts +121 -0
  40. package/dist/google/protobuf/timestamp.pb.js +42 -0
  41. package/dist/google/protobuf/type.pb.d.ts +464 -0
  42. package/dist/google/protobuf/type.pb.js +338 -0
  43. package/dist/google/protobuf/wrappers.pb.d.ts +183 -0
  44. package/dist/google/protobuf/wrappers.pb.js +107 -0
  45. package/dist/index.d.ts +8 -3
  46. package/dist/index.js +38 -8
  47. package/dist/is-message.d.ts +10 -2
  48. package/dist/is-message.js +76 -3
  49. package/dist/json.d.ts +68 -1
  50. package/dist/json.js +60 -81
  51. package/dist/message.d.ts +30 -61
  52. package/dist/message.js +63 -18
  53. package/dist/names.d.ts +43 -0
  54. package/dist/names.js +276 -0
  55. package/dist/partial.js +19 -16
  56. package/dist/proto-base64.d.ts +18 -0
  57. package/dist/proto-base64.js +128 -0
  58. package/dist/proto-double.d.ts +5 -0
  59. package/dist/proto-double.js +29 -0
  60. package/dist/proto-int64.d.ts +95 -0
  61. package/dist/proto-int64.js +116 -0
  62. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.d.ts +1 -0
  63. package/dist/{protoc-gen-es-lite-plugin.js → protoc-gen-es-lite/protoc-gen-es-lite-plugin.js} +2 -2
  64. package/dist/{typescript.d.ts → protoc-gen-es-lite/typescript.d.ts} +3 -2
  65. package/dist/{typescript.js → protoc-gen-es-lite/typescript.js} +48 -36
  66. package/dist/protoplugin/create-es-plugin.d.ts +83 -0
  67. package/dist/protoplugin/create-es-plugin.js +119 -0
  68. package/dist/protoplugin/ecmascript/file-preamble.d.ts +2 -0
  69. package/dist/protoplugin/ecmascript/file-preamble.js +74 -0
  70. package/dist/protoplugin/ecmascript/generated-file.d.ts +116 -0
  71. package/dist/protoplugin/ecmascript/generated-file.js +407 -0
  72. package/dist/protoplugin/ecmascript/import-path.d.ts +65 -0
  73. package/dist/protoplugin/ecmascript/import-path.js +156 -0
  74. package/dist/protoplugin/ecmascript/import-symbol.d.ts +39 -0
  75. package/dist/protoplugin/ecmascript/import-symbol.js +37 -0
  76. package/dist/protoplugin/ecmascript/index.d.ts +7 -0
  77. package/dist/protoplugin/ecmascript/index.js +20 -0
  78. package/dist/protoplugin/ecmascript/jsdoc.d.ts +14 -0
  79. package/dist/protoplugin/ecmascript/jsdoc.js +93 -0
  80. package/dist/protoplugin/ecmascript/opaque-printables.d.ts +27 -0
  81. package/dist/protoplugin/ecmascript/opaque-printables.js +15 -0
  82. package/dist/protoplugin/ecmascript/parameter.d.ts +13 -0
  83. package/dist/protoplugin/ecmascript/parameter.js +161 -0
  84. package/dist/protoplugin/ecmascript/reify-wkt.d.ts +100 -0
  85. package/dist/protoplugin/ecmascript/reify-wkt.js +170 -0
  86. package/dist/protoplugin/ecmascript/runtime-imports.d.ts +6 -0
  87. package/dist/protoplugin/ecmascript/runtime-imports.js +28 -0
  88. package/dist/protoplugin/ecmascript/schema.d.ts +43 -0
  89. package/dist/protoplugin/ecmascript/schema.js +73 -0
  90. package/dist/protoplugin/ecmascript/target.d.ts +4 -0
  91. package/dist/protoplugin/ecmascript/target.js +15 -0
  92. package/dist/protoplugin/ecmascript/transpile.d.ts +2 -0
  93. package/dist/protoplugin/ecmascript/transpile.js +149 -0
  94. package/dist/protoplugin/error.d.ts +6 -0
  95. package/dist/protoplugin/error.js +43 -0
  96. package/dist/protoplugin/index.d.ts +8 -0
  97. package/dist/protoplugin/index.js +20 -0
  98. package/dist/protoplugin/plugin.d.ts +18 -0
  99. package/dist/protoplugin/plugin.js +15 -0
  100. package/dist/protoplugin/run-node.d.ts +12 -0
  101. package/dist/protoplugin/run-node.js +83 -0
  102. package/dist/scalar.d.ts +53 -1
  103. package/dist/scalar.js +87 -22
  104. package/dist/service-type.d.ts +95 -0
  105. package/dist/service-type.js +53 -0
  106. package/dist/text-format.d.ts +4 -0
  107. package/dist/text-format.js +189 -0
  108. package/dist/type-registry.d.ts +43 -0
  109. package/dist/type-registry.js +15 -0
  110. package/dist/unknown.d.ts +1 -1
  111. package/dist/util.d.ts +2 -2
  112. package/dist/util.js +46 -44
  113. package/dist/varint.d.ts +70 -0
  114. package/dist/varint.js +324 -0
  115. package/example/example.pb.ts +87 -0
  116. package/example/example.proto +1 -0
  117. package/example/tsconfig.json +8 -2
  118. package/package.json +19 -12
  119. package/tsconfig.json +4 -4
  120. package/dist/editions.d.ts +0 -6
  121. package/dist/protoc-gen-es-lite-plugin.d.ts +0 -1
package/dist/enum.d.ts CHANGED
@@ -1,4 +1,38 @@
1
- import { EnumType, EnumValueInfo } from "@bufbuild/protobuf";
1
+ /**
2
+ * Reflection information for a protobuf enumeration.
3
+ */
4
+ export interface EnumType {
5
+ /**
6
+ * The fully qualified name of the enumeration.
7
+ */
8
+ readonly typeName: string;
9
+ readonly values: readonly EnumValueInfo[];
10
+ /**
11
+ * Find an enum value by its (protobuf) name.
12
+ */
13
+ findName(name: string): EnumValueInfo | undefined;
14
+ /**
15
+ * Find an enum value by its number.
16
+ */
17
+ findNumber(no: number): EnumValueInfo | undefined;
18
+ }
19
+ /**
20
+ * Reflection information for a protobuf enumeration value.
21
+ */
22
+ export interface EnumValueInfo {
23
+ /**
24
+ * The numeric enumeration value, as specified in the protobuf source.
25
+ */
26
+ readonly no: number;
27
+ /**
28
+ * The name of the enumeration value, as specified in the protobuf source.
29
+ */
30
+ readonly name: string;
31
+ /**
32
+ * The name of the enumeration value in generated code.
33
+ */
34
+ readonly localName: string;
35
+ }
2
36
  export declare function normalizeEnumValue(value: EnumValueInfo | Omit<EnumValueInfo, "localName">): EnumValueInfo;
3
37
  /**
4
38
  * Create a new EnumType with the given values.
@@ -0,0 +1,19 @@
1
+ import { Edition, FeatureSet, FeatureSetDefaults } from "./google/protobuf/descriptor.pb.js";
2
+ import type { BinaryReadOptions, BinaryWriteOptions } from "./binary.js";
3
+ /**
4
+ * A merged google.protobuf.FeaturesSet, with all fields guaranteed to be set.
5
+ */
6
+ export type MergedFeatureSet = FeatureSet & Required<FeatureSet>;
7
+ /**
8
+ * A function that resolves features.
9
+ *
10
+ * If no feature set is provided, the default feature set for the edition is
11
+ * returned. If features are provided, they are merged into the edition default
12
+ * features.
13
+ */
14
+ export type FeatureResolverFn = (a?: FeatureSet, b?: FeatureSet) => MergedFeatureSet;
15
+ /**
16
+ * Create an edition feature resolver with the given feature set defaults, or
17
+ * the feature set defaults supported by @bufbuild/protobuf.
18
+ */
19
+ export declare function createFeatureResolver(edition: Edition, compiledFeatureSetDefaults?: FeatureSetDefaults, serializationOptions?: Partial<BinaryReadOptions & BinaryWriteOptions>): FeatureResolverFn;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.createFeatureResolver = void 0;
17
+ const descriptor_pb_js_1 = require("./google/protobuf/descriptor.pb.js");
18
+ const proto_base64_js_1 = require("./proto-base64.js");
19
+ const partial_js_1 = require("./partial.js");
20
+ /**
21
+ * Return the edition feature defaults supported by @bufbuild/protobuf.
22
+ */
23
+ function getFeatureSetDefaults(options) {
24
+ return descriptor_pb_js_1.FeatureSetDefaults.fromBinary(proto_base64_js_1.protoBase64.dec("ChESDAgBEAIYAiADKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH"), options);
25
+ }
26
+ /**
27
+ * Create an edition feature resolver with the given feature set defaults, or
28
+ * the feature set defaults supported by @bufbuild/protobuf.
29
+ */
30
+ function createFeatureResolver(edition, compiledFeatureSetDefaults, serializationOptions) {
31
+ const fds = descriptor_pb_js_1.FeatureSetDefaults.create(compiledFeatureSetDefaults ?? getFeatureSetDefaults(serializationOptions));
32
+ const min = fds.minimumEdition ?? 0;
33
+ const max = fds.maximumEdition ?? 0;
34
+ if (edition === 0) {
35
+ throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is unknown and not supported.`);
36
+ }
37
+ if (edition < min) {
38
+ throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is earlier than the minimum supported edition ${descriptor_pb_js_1.Edition[min]}`);
39
+ }
40
+ if (max < edition) {
41
+ throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is later than the maximum supported edition ${descriptor_pb_js_1.Edition[max]}`);
42
+ }
43
+ let highestMatch = undefined;
44
+ for (const c of fds.defaults ?? []) {
45
+ const e = c?.edition;
46
+ if (e === undefined || e > edition) {
47
+ continue;
48
+ }
49
+ if (highestMatch !== undefined && highestMatch.e > e) {
50
+ continue;
51
+ }
52
+ highestMatch = {
53
+ e,
54
+ f: c.features ?? descriptor_pb_js_1.FeatureSet.create(),
55
+ };
56
+ }
57
+ if (highestMatch === undefined) {
58
+ throw new Error(`No valid default found for edition ${descriptor_pb_js_1.Edition[edition]}`);
59
+ }
60
+ const featureSetBin = descriptor_pb_js_1.FeatureSet.toBinary(highestMatch.f, serializationOptions);
61
+ return (...rest) => {
62
+ const f = descriptor_pb_js_1.FeatureSet.fromBinary(featureSetBin, serializationOptions);
63
+ for (const c of rest) {
64
+ if (c !== undefined) {
65
+ (0, partial_js_1.applyPartialMessage)(c, f, descriptor_pb_js_1.FeatureSet.fields);
66
+ }
67
+ }
68
+ if (!validateMergedFeatures(f)) {
69
+ throw new Error(`Invalid FeatureSet for edition ${descriptor_pb_js_1.Edition[edition]}`);
70
+ }
71
+ return f;
72
+ };
73
+ }
74
+ exports.createFeatureResolver = createFeatureResolver;
75
+ // When protoc generates google.protobuf.FeatureSetDefaults, it ensures that
76
+ // fields are not repeated or required, do not use oneof, and have a default
77
+ // value.
78
+ //
79
+ // When features for an element are resolved, features of the element and its
80
+ // parents are merged into the default FeatureSet for the edition. Because unset
81
+ // fields in the FeatureSet of an element do not unset the default FeatureSet
82
+ // values, a resolved FeatureSet is guaranteed to have all fields set. This is
83
+ // also the case for extensions to FeatureSet that a user might provide, and for
84
+ // features from the future.
85
+ //
86
+ // We cannot exhaustively validate correctness of FeatureSetDefaults at runtime
87
+ // without knowing the schema: If no value for a feature is provided, we do not
88
+ // know that it exists at all.
89
+ //
90
+ // As a sanity check, we validate that all fields known to our version of
91
+ // FeatureSet are set.
92
+ function validateMergedFeatures(featureSet) {
93
+ for (const fi of descriptor_pb_js_1.FeatureSet.fields.list()) {
94
+ const v = featureSet[fi.localName];
95
+ if (v === undefined) {
96
+ return false;
97
+ }
98
+ if (fi.kind == "enum" && v === 0) {
99
+ return false;
100
+ }
101
+ }
102
+ return true;
103
+ }
@@ -1,9 +1,8 @@
1
+ import { DescExtension, DescField } from "./descriptor-set.js";
2
+ import { ScalarType } from "./scalar.js";
1
3
  /**
2
4
  * A field wrapper unwraps a message to a primitive value that is more
3
5
  * ergonomic for use as a message field.
4
- *
5
- * Note that this feature exists for google/protobuf/wrappers.proto
6
- * and cannot be used to arbitrarily modify types in generated code.
7
6
  */
8
7
  export interface FieldWrapper<T = any, U = any> {
9
8
  wrapField(value: U): T;
@@ -14,3 +13,8 @@ export interface FieldWrapper<T = any, U = any> {
14
13
  * message. This function is idempotent.
15
14
  */
16
15
  export declare function wrapField<T>(fieldWrapper: FieldWrapper<T> | undefined, value: any): T;
16
+ /**
17
+ * If the given field uses one of the well-known wrapper types, return
18
+ * the primitive type it wraps.
19
+ */
20
+ export declare function getUnwrappedFieldType(field: DescField | DescExtension): ScalarType | undefined;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapField = void 0;
3
+ exports.getUnwrappedFieldType = exports.wrapField = void 0;
4
+ const scalar_js_1 = require("./scalar.js");
4
5
  /**
5
6
  * Wrap a primitive message field value in its corresponding wrapper
6
7
  * message. This function is idempotent.
@@ -12,3 +13,31 @@ function wrapField(fieldWrapper, value) {
12
13
  return fieldWrapper.wrapField(value);
13
14
  }
14
15
  exports.wrapField = wrapField;
16
+ /**
17
+ * If the given field uses one of the well-known wrapper types, return
18
+ * the primitive type it wraps.
19
+ */
20
+ function getUnwrappedFieldType(field) {
21
+ if (field.fieldKind !== "message") {
22
+ return undefined;
23
+ }
24
+ if (field.repeated) {
25
+ return undefined;
26
+ }
27
+ if (field.oneof != undefined) {
28
+ return undefined;
29
+ }
30
+ return wktWrapperToScalarType[field.message.typeName];
31
+ }
32
+ exports.getUnwrappedFieldType = getUnwrappedFieldType;
33
+ const wktWrapperToScalarType = {
34
+ "google.protobuf.DoubleValue": scalar_js_1.ScalarType.DOUBLE,
35
+ "google.protobuf.FloatValue": scalar_js_1.ScalarType.FLOAT,
36
+ "google.protobuf.Int64Value": scalar_js_1.ScalarType.INT64,
37
+ "google.protobuf.UInt64Value": scalar_js_1.ScalarType.UINT64,
38
+ "google.protobuf.Int32Value": scalar_js_1.ScalarType.INT32,
39
+ "google.protobuf.UInt32Value": scalar_js_1.ScalarType.UINT32,
40
+ "google.protobuf.BoolValue": scalar_js_1.ScalarType.BOOL,
41
+ "google.protobuf.StringValue": scalar_js_1.ScalarType.STRING,
42
+ "google.protobuf.BytesValue": scalar_js_1.ScalarType.BYTES,
43
+ };
package/dist/field.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { EnumType, LongType, ScalarType } from "@bufbuild/protobuf";
2
- import { MessageType } from "./message.js";
1
+ import { EnumType } from "./enum.js";
2
+ import { Message, MessageType } from "./message.js";
3
+ import { LongType, ScalarType } from "./scalar.js";
4
+ import { protoCamelCase } from "./names.js";
3
5
  /**
4
6
  * FieldInfo describes a field of a protobuf message for runtime reflection. We
5
7
  * distinguish between the following kinds of fields:
@@ -73,7 +75,6 @@ export declare class FieldList {
73
75
  export type PartialFieldInfo = fiPartialRules<fiScalar> | fiPartialRules<fiEnum> | fiPartialRules<fiMessage> | fiPartialRules<fiMap>;
74
76
  export type FieldListSource = readonly PartialFieldInfo[] | readonly FieldInfo[] | (() => readonly PartialFieldInfo[]) | (() => readonly FieldInfo[]);
75
77
  export declare function newFieldList(fields: FieldListSource, packedByDefault: boolean): FieldList;
76
- export declare function protoCamelCase(snakeCase: string): string;
77
78
  /**
78
79
  * Returns true if the field is set.
79
80
  */
@@ -82,19 +83,7 @@ export declare function isFieldSet(field: FieldInfo, target: Record<string, any>
82
83
  * Returns the JSON name for a protobuf field, exactly like protoc does.
83
84
  */
84
85
  export declare const fieldJsonName: typeof protoCamelCase;
85
- /**
86
- * Returns the name of a field in generated code.
87
- */
88
- export declare function localFieldName(protoName: string, inOneof: boolean): string;
89
- /**
90
- * Names that cannot be used for object properties because they are reserved
91
- * by built-in JavaScript properties.
92
- */
93
- export declare const safeObjectProperty: (name: string) => string;
94
- /**
95
- * Returns the name of a oneof group in generated code.
96
- */
97
- export declare function localOneofName(protoName: string): string;
86
+ export declare function resolveMessageType<T extends Message<T>>(t: fiMessage<T>["T"]): MessageType<T>;
98
87
  export declare class InternalOneofInfo implements OneofInfo {
99
88
  readonly kind = "oneof";
100
89
  readonly name: string;
@@ -215,12 +204,12 @@ interface fiScalar extends fiShared {
215
204
  */
216
205
  readonly delimited?: undefined;
217
206
  }
218
- interface fiMessage extends fiShared {
207
+ interface fiMessage<T extends Message<T> = any> extends fiShared {
219
208
  readonly kind: "message";
220
209
  /**
221
210
  * Message handler for the field.
222
211
  */
223
- readonly T: MessageType;
212
+ readonly T: MessageType<T> | (() => MessageType<T>);
224
213
  /**
225
214
  * Is the field repeated?
226
215
  */
@@ -302,7 +291,7 @@ interface fiMap extends fiShared {
302
291
  readonly T: EnumType;
303
292
  } | {
304
293
  readonly kind: "message";
305
- readonly T: MessageType;
294
+ readonly T: MessageType<any> | (() => MessageType<any>);
306
295
  };
307
296
  /**
308
297
  * Is the field repeated? Never true for maps.
package/dist/field.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeFieldInfos = exports.InternalOneofInfo = exports.localOneofName = exports.safeObjectProperty = exports.localFieldName = exports.fieldJsonName = exports.isFieldSet = exports.protoCamelCase = exports.newFieldList = exports.FieldList = void 0;
4
- const protobuf_1 = require("@bufbuild/protobuf");
3
+ exports.normalizeFieldInfos = exports.InternalOneofInfo = exports.resolveMessageType = exports.fieldJsonName = exports.isFieldSet = exports.newFieldList = exports.FieldList = void 0;
5
4
  const assert_js_1 = require("./assert.js");
6
5
  const scalar_js_1 = require("./scalar.js");
6
+ const names_js_1 = require("./names.js");
7
7
  /**
8
8
  * Provides convenient access to field information of a message type.
9
9
  */
@@ -88,44 +88,6 @@ function newFieldList(fields, packedByDefault) {
88
88
  return new FieldList(fields, (source) => normalizeFieldInfos(source, packedByDefault));
89
89
  }
90
90
  exports.newFieldList = newFieldList;
91
- /*
92
- * Converts snake_case to protoCamelCase according to the convention
93
- * used by protoc to convert a field name to a JSON name.
94
- */
95
- function protoCamelCase(snakeCase) {
96
- let capNext = false;
97
- const b = [];
98
- for (let i = 0; i < snakeCase.length; i++) {
99
- let c = snakeCase.charAt(i);
100
- switch (c) {
101
- case "_":
102
- capNext = true;
103
- break;
104
- case "0":
105
- case "1":
106
- case "2":
107
- case "3":
108
- case "4":
109
- case "5":
110
- case "6":
111
- case "7":
112
- case "8":
113
- case "9":
114
- b.push(c);
115
- capNext = false;
116
- break;
117
- default:
118
- if (capNext) {
119
- capNext = false;
120
- c = c.toUpperCase();
121
- }
122
- b.push(c);
123
- break;
124
- }
125
- }
126
- return b.join("");
127
- }
128
- exports.protoCamelCase = protoCamelCase;
129
91
  /**
130
92
  * Returns true if the field is set.
131
93
  */
@@ -159,77 +121,15 @@ exports.isFieldSet = isFieldSet;
159
121
  /**
160
122
  * Returns the JSON name for a protobuf field, exactly like protoc does.
161
123
  */
162
- exports.fieldJsonName = protoCamelCase;
163
- /**
164
- * Returns the name of a field in generated code.
165
- */
166
- function localFieldName(protoName, inOneof) {
167
- const name = protoCamelCase(protoName);
168
- if (inOneof) {
169
- // oneof member names are not properties, but values of the `case` property.
170
- return name;
124
+ exports.fieldJsonName = names_js_1.protoCamelCase;
125
+ // resolveMessageType returns the message type calling the function if necessary.
126
+ function resolveMessageType(t) {
127
+ if (t instanceof Function) {
128
+ return t();
171
129
  }
172
- return (0, exports.safeObjectProperty)(safeMessageProperty(name));
173
- }
174
- exports.localFieldName = localFieldName;
175
- /**
176
- * Names that cannot be used for object properties because they are reserved
177
- * by built-in JavaScript properties.
178
- */
179
- const reservedObjectProperties = new Set([
180
- // names reserved by JavaScript
181
- "constructor",
182
- "toString",
183
- "toJSON",
184
- "valueOf",
185
- ]);
186
- /*
187
- * Names that cannot be used for object properties because they are reserved
188
- * by the runtime.
189
- */
190
- const reservedMessageProperties = new Set([
191
- // names reserved by the runtime
192
- "getType",
193
- "clone",
194
- "equals",
195
- "fromBinary",
196
- "fromJson",
197
- "fromJsonString",
198
- "toBinary",
199
- "toJson",
200
- "toJsonString",
201
- // names reserved by the runtime for the future
202
- "toObject",
203
- ]);
204
- const fallback = (name) => `${name}$`;
205
- /**
206
- * Will wrap names that are Object prototype properties or names reserved
207
- * for `Message`s.
208
- */
209
- const safeMessageProperty = (name) => {
210
- if (reservedMessageProperties.has(name)) {
211
- return fallback(name);
212
- }
213
- return name;
214
- };
215
- /**
216
- * Names that cannot be used for object properties because they are reserved
217
- * by built-in JavaScript properties.
218
- */
219
- const safeObjectProperty = (name) => {
220
- if (reservedObjectProperties.has(name)) {
221
- return fallback(name);
222
- }
223
- return name;
224
- };
225
- exports.safeObjectProperty = safeObjectProperty;
226
- /**
227
- * Returns the name of a oneof group in generated code.
228
- */
229
- function localOneofName(protoName) {
230
- return localFieldName(protoName, false);
130
+ return t;
231
131
  }
232
- exports.localOneofName = localOneofName;
132
+ exports.resolveMessageType = resolveMessageType;
233
133
  // InternarlOneofInfo implements OneofInfo.
234
134
  class InternalOneofInfo {
235
135
  constructor(name) {
@@ -241,7 +141,7 @@ class InternalOneofInfo {
241
141
  this.default = undefined;
242
142
  this.fields = [];
243
143
  this.name = name;
244
- this.localName = localOneofName(name);
144
+ this.localName = (0, names_js_1.localOneofName)(name);
245
145
  }
246
146
  addField(field) {
247
147
  (0, assert_js_1.assert)(field.oneof === this, `field ${field.name} not one of ${this.name}`);
@@ -267,15 +167,13 @@ exports.InternalOneofInfo = InternalOneofInfo;
267
167
  function normalizeFieldInfos(fieldInfos, packedByDefault) {
268
168
  const r = [];
269
169
  let o;
270
- for (const field of typeof fieldInfos == "function"
271
- ? fieldInfos()
272
- : fieldInfos) {
170
+ for (const field of typeof fieldInfos == "function" ? fieldInfos() : (fieldInfos)) {
273
171
  const f = field;
274
- f.localName = localFieldName(field.name, field.oneof !== undefined);
172
+ f.localName = (0, names_js_1.localFieldName)(field.name, field.oneof !== undefined);
275
173
  f.jsonName = field.jsonName ?? (0, exports.fieldJsonName)(field.name);
276
174
  f.repeated = field.repeated ?? false;
277
175
  if (field.kind == "scalar") {
278
- f.L = field.L ?? protobuf_1.LongType.BIGINT;
176
+ f.L = field.L ?? scalar_js_1.LongType.BIGINT;
279
177
  }
280
178
  f.delimited = field.delimited ?? false;
281
179
  f.req = field.req ?? false;
@@ -285,8 +183,8 @@ function normalizeFieldInfos(fieldInfos, packedByDefault) {
285
183
  f.packed =
286
184
  field.kind == "enum" ||
287
185
  (field.kind == "scalar" &&
288
- field.T != protobuf_1.ScalarType.BYTES &&
289
- field.T != protobuf_1.ScalarType.STRING);
186
+ field.T != scalar_js_1.ScalarType.BYTES &&
187
+ field.T != scalar_js_1.ScalarType.STRING);
290
188
  }
291
189
  else {
292
190
  f.packed = false;
@@ -0,0 +1,9 @@
1
+ export { Type, Field, Field_Kind, Field_Cardinality, Enum, EnumValue, Option, Syntax, } from "./protobuf/type.pb.js";
2
+ export { Timestamp } from "./protobuf/timestamp.pb.js";
3
+ export { Duration } from "./protobuf/duration.pb.js";
4
+ export { Any } from "./protobuf/any.pb.js";
5
+ export { Empty } from "./protobuf/empty.pb.js";
6
+ export { DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue, } from "./protobuf/wrappers.pb.js";
7
+ export { Value, NullValue, ListValue, Struct } from "./protobuf/struct.pb.js";
8
+ export { Api, Method, Mixin } from "./protobuf/api.pb.js";
9
+ export { SourceContext } from "./protobuf/source_context.pb.js";
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SourceContext = exports.Mixin = exports.Method = exports.Api = exports.Struct = exports.ListValue = exports.NullValue = exports.Value = exports.BytesValue = exports.StringValue = exports.BoolValue = exports.UInt32Value = exports.Int32Value = exports.UInt64Value = exports.Int64Value = exports.FloatValue = exports.DoubleValue = exports.Empty = exports.Any = exports.Duration = exports.Timestamp = exports.Syntax = exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = void 0;
4
+ var type_pb_js_1 = require("./protobuf/type.pb.js");
5
+ Object.defineProperty(exports, "Type", { enumerable: true, get: function () { return type_pb_js_1.Type; } });
6
+ Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return type_pb_js_1.Field; } });
7
+ Object.defineProperty(exports, "Field_Kind", { enumerable: true, get: function () { return type_pb_js_1.Field_Kind; } });
8
+ Object.defineProperty(exports, "Field_Cardinality", { enumerable: true, get: function () { return type_pb_js_1.Field_Cardinality; } });
9
+ Object.defineProperty(exports, "Enum", { enumerable: true, get: function () { return type_pb_js_1.Enum; } });
10
+ Object.defineProperty(exports, "EnumValue", { enumerable: true, get: function () { return type_pb_js_1.EnumValue; } });
11
+ Object.defineProperty(exports, "Option", { enumerable: true, get: function () { return type_pb_js_1.Option; } });
12
+ Object.defineProperty(exports, "Syntax", { enumerable: true, get: function () { return type_pb_js_1.Syntax; } });
13
+ var timestamp_pb_js_1 = require("./protobuf/timestamp.pb.js");
14
+ Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return timestamp_pb_js_1.Timestamp; } });
15
+ var duration_pb_js_1 = require("./protobuf/duration.pb.js");
16
+ Object.defineProperty(exports, "Duration", { enumerable: true, get: function () { return duration_pb_js_1.Duration; } });
17
+ var any_pb_js_1 = require("./protobuf/any.pb.js");
18
+ Object.defineProperty(exports, "Any", { enumerable: true, get: function () { return any_pb_js_1.Any; } });
19
+ var empty_pb_js_1 = require("./protobuf/empty.pb.js");
20
+ Object.defineProperty(exports, "Empty", { enumerable: true, get: function () { return empty_pb_js_1.Empty; } });
21
+ var wrappers_pb_js_1 = require("./protobuf/wrappers.pb.js");
22
+ Object.defineProperty(exports, "DoubleValue", { enumerable: true, get: function () { return wrappers_pb_js_1.DoubleValue; } });
23
+ Object.defineProperty(exports, "FloatValue", { enumerable: true, get: function () { return wrappers_pb_js_1.FloatValue; } });
24
+ Object.defineProperty(exports, "Int64Value", { enumerable: true, get: function () { return wrappers_pb_js_1.Int64Value; } });
25
+ Object.defineProperty(exports, "UInt64Value", { enumerable: true, get: function () { return wrappers_pb_js_1.UInt64Value; } });
26
+ Object.defineProperty(exports, "Int32Value", { enumerable: true, get: function () { return wrappers_pb_js_1.Int32Value; } });
27
+ Object.defineProperty(exports, "UInt32Value", { enumerable: true, get: function () { return wrappers_pb_js_1.UInt32Value; } });
28
+ Object.defineProperty(exports, "BoolValue", { enumerable: true, get: function () { return wrappers_pb_js_1.BoolValue; } });
29
+ Object.defineProperty(exports, "StringValue", { enumerable: true, get: function () { return wrappers_pb_js_1.StringValue; } });
30
+ Object.defineProperty(exports, "BytesValue", { enumerable: true, get: function () { return wrappers_pb_js_1.BytesValue; } });
31
+ var struct_pb_js_1 = require("./protobuf/struct.pb.js");
32
+ Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return struct_pb_js_1.Value; } });
33
+ Object.defineProperty(exports, "NullValue", { enumerable: true, get: function () { return struct_pb_js_1.NullValue; } });
34
+ Object.defineProperty(exports, "ListValue", { enumerable: true, get: function () { return struct_pb_js_1.ListValue; } });
35
+ Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return struct_pb_js_1.Struct; } });
36
+ var api_pb_js_1 = require("./protobuf/api.pb.js");
37
+ Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_pb_js_1.Api; } });
38
+ Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return api_pb_js_1.Method; } });
39
+ Object.defineProperty(exports, "Mixin", { enumerable: true, get: function () { return api_pb_js_1.Mixin; } });
40
+ var source_context_pb_js_1 = require("./protobuf/source_context.pb.js");
41
+ Object.defineProperty(exports, "SourceContext", { enumerable: true, get: function () { return source_context_pb_js_1.SourceContext; } });
@@ -0,0 +1,139 @@
1
+ import type { MessageType } from "../../";
2
+ import { Message } from "../../";
3
+ export declare const protobufPackage = "google.protobuf";
4
+ /**
5
+ * `Any` contains an arbitrary serialized protocol buffer message along with a
6
+ * URL that describes the type of the serialized message.
7
+ *
8
+ * Protobuf library provides support to pack/unpack Any values in the form
9
+ * of utility functions or additional generated methods of the Any type.
10
+ *
11
+ * Example 1: Pack and unpack a message in C++.
12
+ *
13
+ * Foo foo = ...;
14
+ * Any any;
15
+ * any.PackFrom(foo);
16
+ * ...
17
+ * if (any.UnpackTo(&foo)) {
18
+ * ...
19
+ * }
20
+ *
21
+ * Example 2: Pack and unpack a message in Java.
22
+ *
23
+ * Foo foo = ...;
24
+ * Any any = Any.pack(foo);
25
+ * ...
26
+ * if (any.is(Foo.class)) {
27
+ * foo = any.unpack(Foo.class);
28
+ * }
29
+ * // or ...
30
+ * if (any.isSameTypeAs(Foo.getDefaultInstance())) {
31
+ * foo = any.unpack(Foo.getDefaultInstance());
32
+ * }
33
+ *
34
+ * Example 3: Pack and unpack a message in Python.
35
+ *
36
+ * foo = Foo(...)
37
+ * any = Any()
38
+ * any.Pack(foo)
39
+ * ...
40
+ * if any.Is(Foo.DESCRIPTOR):
41
+ * any.Unpack(foo)
42
+ * ...
43
+ *
44
+ * Example 4: Pack and unpack a message in Go
45
+ *
46
+ * foo := &pb.Foo{...}
47
+ * any, err := anypb.New(foo)
48
+ * if err != nil {
49
+ * ...
50
+ * }
51
+ * ...
52
+ * foo := &pb.Foo{}
53
+ * if err := any.UnmarshalTo(foo); err != nil {
54
+ * ...
55
+ * }
56
+ *
57
+ * The pack methods provided by protobuf library will by default use
58
+ * 'type.googleapis.com/full.type.name' as the type URL and the unpack
59
+ * methods only use the fully qualified type name after the last '/'
60
+ * in the type URL, for example "foo.bar.com/x/y.z" will yield type
61
+ * name "y.z".
62
+ *
63
+ * JSON
64
+ * ====
65
+ * The JSON representation of an `Any` value uses the regular
66
+ * representation of the deserialized, embedded message, with an
67
+ * additional field `@type` which contains the type URL. Example:
68
+ *
69
+ * package google.profile;
70
+ * message Person {
71
+ * string first_name = 1;
72
+ * string last_name = 2;
73
+ * }
74
+ *
75
+ * {
76
+ * "@type": "type.googleapis.com/google.profile.Person",
77
+ * "firstName": <string>,
78
+ * "lastName": <string>
79
+ * }
80
+ *
81
+ * If the embedded message type is well-known and has a custom JSON
82
+ * representation, that representation will be embedded adding a field
83
+ * `value` which holds the custom JSON in addition to the `@type`
84
+ * field. Example (for message [google.protobuf.Duration][]):
85
+ *
86
+ * {
87
+ * "@type": "type.googleapis.com/google.protobuf.Duration",
88
+ * "value": "1.212s"
89
+ * }
90
+ *
91
+ *
92
+ *
93
+ * @generated from message google.protobuf.Any
94
+ */
95
+ export type Any = Message<{
96
+ /**
97
+ * A URL/resource name that uniquely identifies the type of the serialized
98
+ * protocol buffer message. This string must contain at least
99
+ * one "/" character. The last segment of the URL's path must represent
100
+ * the fully qualified name of the type (as in
101
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
102
+ * (e.g., leading "." is not accepted).
103
+ *
104
+ * In practice, teams usually precompile into the binary all types that they
105
+ * expect it to use in the context of Any. However, for URLs which use the
106
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
107
+ * server that maps type URLs to message definitions as follows:
108
+ *
109
+ * * If no scheme is provided, `https` is assumed.
110
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
111
+ * value in binary format, or produce an error.
112
+ * * Applications are allowed to cache lookup results based on the
113
+ * URL, or have them precompiled into a binary to avoid any
114
+ * lookup. Therefore, binary compatibility needs to be preserved
115
+ * on changes to types. (Use versioned type names to manage
116
+ * breaking changes.)
117
+ *
118
+ * Note: this functionality is not currently available in the official
119
+ * protobuf release, and it is not used for type URLs beginning with
120
+ * type.googleapis.com. As of May 2023, there are no widely used type server
121
+ * implementations and no plans to implement one.
122
+ *
123
+ * Schemes other than `http`, `https` (or the empty scheme) might be
124
+ * used with implementation specific semantics.
125
+ *
126
+ *
127
+ *
128
+ * @generated from field: string type_url = 1 [packed = false, default = "", jstype = JS_NORMAL];
129
+ */
130
+ typeUrl?: string;
131
+ /**
132
+ * Must be a valid serialized protocol buffer of the above specified type.
133
+ *
134
+ *
135
+ * @generated from field: bytes value = 2 [packed = false, default = "", jstype = JS_NORMAL];
136
+ */
137
+ value?: Uint8Array;
138
+ }>;
139
+ export declare const Any: MessageType<Any>;