@bufbuild/protobuf 2.0.0-beta.2 → 2.0.0-beta.3
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/README.md +15 -13
- package/dist/cjs/clone.js +1 -2
- package/dist/cjs/codegenv1/boot.js +2 -3
- package/dist/cjs/codegenv1/embed.js +3 -4
- package/dist/cjs/codegenv1/enum.d.ts +2 -2
- package/dist/cjs/codegenv1/enum.js +2 -3
- package/dist/cjs/codegenv1/extension.d.ts +2 -2
- package/dist/cjs/codegenv1/extension.js +1 -2
- package/dist/cjs/codegenv1/file.js +1 -2
- package/dist/cjs/codegenv1/message.d.ts +2 -2
- package/dist/cjs/codegenv1/message.js +1 -2
- package/dist/cjs/codegenv1/restore-json-names.js +1 -2
- package/dist/cjs/codegenv1/scalar.js +2 -3
- package/dist/cjs/codegenv1/service.d.ts +2 -2
- package/dist/cjs/codegenv1/service.js +1 -2
- package/dist/cjs/codegenv1/symbols.d.ts +5 -5
- package/dist/cjs/codegenv1/symbols.js +5 -5
- package/dist/cjs/codegenv1/types.d.ts +9 -7
- package/dist/cjs/create.js +5 -4
- package/dist/cjs/descriptors.d.ts +4 -0
- package/dist/cjs/equals.js +1 -2
- package/dist/cjs/extensions.js +7 -8
- package/dist/cjs/fields.js +2 -3
- package/dist/cjs/from-binary.js +3 -4
- package/dist/cjs/from-json.js +6 -7
- package/dist/cjs/is-message.js +1 -2
- package/dist/cjs/reflect/error.js +2 -2
- package/dist/cjs/reflect/guard.js +5 -6
- package/dist/cjs/reflect/names.js +2 -3
- package/dist/cjs/reflect/nested-types.js +2 -3
- package/dist/cjs/reflect/reflect-check.js +4 -5
- package/dist/cjs/reflect/reflect.js +3 -4
- package/dist/cjs/reflect/scalar.js +3 -4
- package/dist/cjs/reflect/unsafe.js +7 -7
- package/dist/cjs/registry.js +15 -9
- package/dist/cjs/to-binary.js +2 -3
- package/dist/cjs/to-json.js +5 -6
- package/dist/cjs/types.d.ts +8 -8
- package/dist/cjs/wire/base64-encoding.js +2 -3
- package/dist/cjs/wire/size-delimited.js +3 -4
- package/dist/cjs/wire/text-encoding.js +2 -3
- package/dist/cjs/wire/text-format.js +2 -3
- package/dist/cjs/wire/varint.js +7 -8
- package/dist/cjs/wkt/any.js +4 -5
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.d.ts +5 -5
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +7 -7
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +52 -52
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.d.ts +6 -6
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.d.ts +3 -3
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.d.ts +10 -10
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.d.ts +11 -11
- package/dist/cjs/wkt/timestamp.js +5 -6
- package/dist/cjs/wkt/wrappers.js +2 -3
- package/dist/esm/codegenv1/enum.d.ts +2 -2
- package/dist/esm/codegenv1/extension.d.ts +2 -2
- package/dist/esm/codegenv1/message.d.ts +2 -2
- package/dist/esm/codegenv1/service.d.ts +2 -2
- package/dist/esm/codegenv1/symbols.d.ts +5 -5
- package/dist/esm/codegenv1/symbols.js +5 -5
- package/dist/esm/codegenv1/types.d.ts +9 -7
- package/dist/esm/create.js +4 -2
- package/dist/esm/descriptors.d.ts +4 -0
- package/dist/esm/registry.js +11 -5
- package/dist/esm/to-json.js +2 -2
- package/dist/esm/types.d.ts +8 -8
- package/dist/esm/wkt/gen/google/protobuf/any_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/api_pb.d.ts +5 -5
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +7 -7
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +52 -52
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.d.ts +6 -6
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.d.ts +3 -3
- package/dist/esm/wkt/gen/google/protobuf/type_pb.d.ts +10 -10
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.d.ts +11 -11
- package/package.json +8 -4
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenEnum, GenFile, GenMessage } from "../../../../codegenv1/types.js";
|
|
2
2
|
import type { Any, AnyJson } from "./any_pb.js";
|
|
3
3
|
import type { SourceContext, SourceContextJson } from "./source_context_pb.js";
|
|
4
4
|
import type { Message } from "../../../../types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Describes the file google/protobuf/type.proto.
|
|
7
7
|
*/
|
|
8
|
-
export declare const file_google_protobuf_type:
|
|
8
|
+
export declare const file_google_protobuf_type: GenFile;
|
|
9
9
|
/**
|
|
10
10
|
* A protocol buffer message type.
|
|
11
11
|
*
|
|
@@ -92,7 +92,7 @@ export type TypeJson = {
|
|
|
92
92
|
* Describes the message google.protobuf.Type.
|
|
93
93
|
* Use `create(TypeSchema)` to create a new message.
|
|
94
94
|
*/
|
|
95
|
-
export declare const TypeSchema:
|
|
95
|
+
export declare const TypeSchema: GenMessage<Type, TypeJson>;
|
|
96
96
|
/**
|
|
97
97
|
* A single field of a message type.
|
|
98
98
|
*
|
|
@@ -211,7 +211,7 @@ export type FieldJson = {
|
|
|
211
211
|
* Describes the message google.protobuf.Field.
|
|
212
212
|
* Use `create(FieldSchema)` to create a new message.
|
|
213
213
|
*/
|
|
214
|
-
export declare const FieldSchema:
|
|
214
|
+
export declare const FieldSchema: GenMessage<Field, FieldJson>;
|
|
215
215
|
/**
|
|
216
216
|
* Basic field types.
|
|
217
217
|
*
|
|
@@ -340,7 +340,7 @@ export type Field_KindJson = "TYPE_UNKNOWN" | "TYPE_DOUBLE" | "TYPE_FLOAT" | "TY
|
|
|
340
340
|
/**
|
|
341
341
|
* Describes the enum google.protobuf.Field.Kind.
|
|
342
342
|
*/
|
|
343
|
-
export declare const Field_KindSchema:
|
|
343
|
+
export declare const Field_KindSchema: GenEnum<Field_Kind, Field_KindJson>;
|
|
344
344
|
/**
|
|
345
345
|
* Whether a field is optional, required, or repeated.
|
|
346
346
|
*
|
|
@@ -379,7 +379,7 @@ export type Field_CardinalityJson = "CARDINALITY_UNKNOWN" | "CARDINALITY_OPTIONA
|
|
|
379
379
|
/**
|
|
380
380
|
* Describes the enum google.protobuf.Field.Cardinality.
|
|
381
381
|
*/
|
|
382
|
-
export declare const Field_CardinalitySchema:
|
|
382
|
+
export declare const Field_CardinalitySchema: GenEnum<Field_Cardinality, Field_CardinalityJson>;
|
|
383
383
|
/**
|
|
384
384
|
* Enum type definition.
|
|
385
385
|
*
|
|
@@ -456,7 +456,7 @@ export type EnumJson = {
|
|
|
456
456
|
* Describes the message google.protobuf.Enum.
|
|
457
457
|
* Use `create(EnumSchema)` to create a new message.
|
|
458
458
|
*/
|
|
459
|
-
export declare const EnumSchema:
|
|
459
|
+
export declare const EnumSchema: GenMessage<Enum, EnumJson>;
|
|
460
460
|
/**
|
|
461
461
|
* Enum value definition.
|
|
462
462
|
*
|
|
@@ -503,7 +503,7 @@ export type EnumValueJson = {
|
|
|
503
503
|
* Describes the message google.protobuf.EnumValue.
|
|
504
504
|
* Use `create(EnumValueSchema)` to create a new message.
|
|
505
505
|
*/
|
|
506
|
-
export declare const EnumValueSchema:
|
|
506
|
+
export declare const EnumValueSchema: GenMessage<EnumValue, EnumValueJson>;
|
|
507
507
|
/**
|
|
508
508
|
* A protocol buffer option, which can be attached to a message, field,
|
|
509
509
|
* enumeration, etc.
|
|
@@ -547,7 +547,7 @@ export type OptionJson = {
|
|
|
547
547
|
* Describes the message google.protobuf.Option.
|
|
548
548
|
* Use `create(OptionSchema)` to create a new message.
|
|
549
549
|
*/
|
|
550
|
-
export declare const OptionSchema:
|
|
550
|
+
export declare const OptionSchema: GenMessage<Option, OptionJson>;
|
|
551
551
|
/**
|
|
552
552
|
* The syntax in which a protocol buffer element is defined.
|
|
553
553
|
*
|
|
@@ -580,4 +580,4 @@ export type SyntaxJson = "SYNTAX_PROTO2" | "SYNTAX_PROTO3" | "SYNTAX_EDITIONS";
|
|
|
580
580
|
/**
|
|
581
581
|
* Describes the enum google.protobuf.Syntax.
|
|
582
582
|
*/
|
|
583
|
-
export declare const SyntaxSchema:
|
|
583
|
+
export declare const SyntaxSchema: GenEnum<Syntax, SyntaxJson>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenFile, GenMessage } from "../../../../codegenv1/types.js";
|
|
2
2
|
import type { Message } from "../../../../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Describes the file google/protobuf/wrappers.proto.
|
|
5
5
|
*/
|
|
6
|
-
export declare const file_google_protobuf_wrappers:
|
|
6
|
+
export declare const file_google_protobuf_wrappers: GenFile;
|
|
7
7
|
/**
|
|
8
8
|
* Wrapper message for `double`.
|
|
9
9
|
*
|
|
@@ -27,7 +27,7 @@ export type DoubleValueJson = number | "NaN" | "Infinity" | "-Infinity";
|
|
|
27
27
|
* Describes the message google.protobuf.DoubleValue.
|
|
28
28
|
* Use `create(DoubleValueSchema)` to create a new message.
|
|
29
29
|
*/
|
|
30
|
-
export declare const DoubleValueSchema:
|
|
30
|
+
export declare const DoubleValueSchema: GenMessage<DoubleValue, DoubleValueJson>;
|
|
31
31
|
/**
|
|
32
32
|
* Wrapper message for `float`.
|
|
33
33
|
*
|
|
@@ -51,7 +51,7 @@ export type FloatValueJson = number | "NaN" | "Infinity" | "-Infinity";
|
|
|
51
51
|
* Describes the message google.protobuf.FloatValue.
|
|
52
52
|
* Use `create(FloatValueSchema)` to create a new message.
|
|
53
53
|
*/
|
|
54
|
-
export declare const FloatValueSchema:
|
|
54
|
+
export declare const FloatValueSchema: GenMessage<FloatValue, FloatValueJson>;
|
|
55
55
|
/**
|
|
56
56
|
* Wrapper message for `int64`.
|
|
57
57
|
*
|
|
@@ -75,7 +75,7 @@ export type Int64ValueJson = string;
|
|
|
75
75
|
* Describes the message google.protobuf.Int64Value.
|
|
76
76
|
* Use `create(Int64ValueSchema)` to create a new message.
|
|
77
77
|
*/
|
|
78
|
-
export declare const Int64ValueSchema:
|
|
78
|
+
export declare const Int64ValueSchema: GenMessage<Int64Value, Int64ValueJson>;
|
|
79
79
|
/**
|
|
80
80
|
* Wrapper message for `uint64`.
|
|
81
81
|
*
|
|
@@ -99,7 +99,7 @@ export type UInt64ValueJson = string;
|
|
|
99
99
|
* Describes the message google.protobuf.UInt64Value.
|
|
100
100
|
* Use `create(UInt64ValueSchema)` to create a new message.
|
|
101
101
|
*/
|
|
102
|
-
export declare const UInt64ValueSchema:
|
|
102
|
+
export declare const UInt64ValueSchema: GenMessage<UInt64Value, UInt64ValueJson>;
|
|
103
103
|
/**
|
|
104
104
|
* Wrapper message for `int32`.
|
|
105
105
|
*
|
|
@@ -123,7 +123,7 @@ export type Int32ValueJson = number;
|
|
|
123
123
|
* Describes the message google.protobuf.Int32Value.
|
|
124
124
|
* Use `create(Int32ValueSchema)` to create a new message.
|
|
125
125
|
*/
|
|
126
|
-
export declare const Int32ValueSchema:
|
|
126
|
+
export declare const Int32ValueSchema: GenMessage<Int32Value, Int32ValueJson>;
|
|
127
127
|
/**
|
|
128
128
|
* Wrapper message for `uint32`.
|
|
129
129
|
*
|
|
@@ -147,7 +147,7 @@ export type UInt32ValueJson = number;
|
|
|
147
147
|
* Describes the message google.protobuf.UInt32Value.
|
|
148
148
|
* Use `create(UInt32ValueSchema)` to create a new message.
|
|
149
149
|
*/
|
|
150
|
-
export declare const UInt32ValueSchema:
|
|
150
|
+
export declare const UInt32ValueSchema: GenMessage<UInt32Value, UInt32ValueJson>;
|
|
151
151
|
/**
|
|
152
152
|
* Wrapper message for `bool`.
|
|
153
153
|
*
|
|
@@ -171,7 +171,7 @@ export type BoolValueJson = boolean;
|
|
|
171
171
|
* Describes the message google.protobuf.BoolValue.
|
|
172
172
|
* Use `create(BoolValueSchema)` to create a new message.
|
|
173
173
|
*/
|
|
174
|
-
export declare const BoolValueSchema:
|
|
174
|
+
export declare const BoolValueSchema: GenMessage<BoolValue, BoolValueJson>;
|
|
175
175
|
/**
|
|
176
176
|
* Wrapper message for `string`.
|
|
177
177
|
*
|
|
@@ -195,7 +195,7 @@ export type StringValueJson = string;
|
|
|
195
195
|
* Describes the message google.protobuf.StringValue.
|
|
196
196
|
* Use `create(StringValueSchema)` to create a new message.
|
|
197
197
|
*/
|
|
198
|
-
export declare const StringValueSchema:
|
|
198
|
+
export declare const StringValueSchema: GenMessage<StringValue, StringValueJson>;
|
|
199
199
|
/**
|
|
200
200
|
* Wrapper message for `bytes`.
|
|
201
201
|
*
|
|
@@ -219,4 +219,4 @@ export type BytesValueJson = string;
|
|
|
219
219
|
* Describes the message google.protobuf.BytesValue.
|
|
220
220
|
* Use `create(BytesValueSchema)` to create a new message.
|
|
221
221
|
*/
|
|
222
|
-
export declare const BytesValueSchema:
|
|
222
|
+
export declare const BytesValueSchema: GenMessage<BytesValue, BytesValueJson>;
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.timestampNow = timestampNow;
|
|
17
|
+
exports.timestampFromDate = timestampFromDate;
|
|
18
|
+
exports.timestampDate = timestampDate;
|
|
19
|
+
exports.timestampFromMs = timestampFromMs;
|
|
20
|
+
exports.timestampMs = timestampMs;
|
|
17
21
|
const timestamp_pb_js_1 = require("./gen/google/protobuf/timestamp_pb.js");
|
|
18
22
|
const create_js_1 = require("../create.js");
|
|
19
23
|
const proto_int64_js_1 = require("../proto-int64.js");
|
|
@@ -23,21 +27,18 @@ const proto_int64_js_1 = require("../proto-int64.js");
|
|
|
23
27
|
function timestampNow() {
|
|
24
28
|
return timestampFromDate(new Date());
|
|
25
29
|
}
|
|
26
|
-
exports.timestampNow = timestampNow;
|
|
27
30
|
/**
|
|
28
31
|
* Create a google.protobuf.Timestamp message from an ECMAScript Date.
|
|
29
32
|
*/
|
|
30
33
|
function timestampFromDate(date) {
|
|
31
34
|
return timestampFromMs(date.getTime());
|
|
32
35
|
}
|
|
33
|
-
exports.timestampFromDate = timestampFromDate;
|
|
34
36
|
/**
|
|
35
37
|
* Convert a google.protobuf.Timestamp message to an ECMAScript Date.
|
|
36
38
|
*/
|
|
37
39
|
function timestampDate(timestamp) {
|
|
38
40
|
return new Date(timestampMs(timestamp));
|
|
39
41
|
}
|
|
40
|
-
exports.timestampDate = timestampDate;
|
|
41
42
|
/**
|
|
42
43
|
* Create a google.protobuf.Timestamp message from a Unix timestamp in milliseconds.
|
|
43
44
|
*/
|
|
@@ -47,11 +48,9 @@ function timestampFromMs(timestampMs) {
|
|
|
47
48
|
nanos: (timestampMs % 1000) * 1000000,
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
|
-
exports.timestampFromMs = timestampFromMs;
|
|
51
51
|
/**
|
|
52
52
|
* Convert a google.protobuf.Timestamp to a Unix timestamp in milliseconds.
|
|
53
53
|
*/
|
|
54
54
|
function timestampMs(timestamp) {
|
|
55
55
|
return (Number(timestamp.seconds) * 1000 + Math.ceil(timestamp.nanos / 1000000));
|
|
56
56
|
}
|
|
57
|
-
exports.timestampMs = timestampMs;
|
package/dist/cjs/wkt/wrappers.js
CHANGED
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.isWrapper = isWrapper;
|
|
17
|
+
exports.isWrapperDesc = isWrapperDesc;
|
|
17
18
|
function isWrapper(arg) {
|
|
18
19
|
return isWrapperTypeName(arg.$typeName);
|
|
19
20
|
}
|
|
20
|
-
exports.isWrapper = isWrapper;
|
|
21
21
|
function isWrapperDesc(messageDesc) {
|
|
22
22
|
const f = messageDesc.fields[0];
|
|
23
23
|
return (isWrapperTypeName(messageDesc.typeName) &&
|
|
@@ -26,7 +26,6 @@ function isWrapperDesc(messageDesc) {
|
|
|
26
26
|
f.name == "value" &&
|
|
27
27
|
f.number == 1);
|
|
28
28
|
}
|
|
29
|
-
exports.isWrapperDesc = isWrapperDesc;
|
|
30
29
|
function isWrapperTypeName(name) {
|
|
31
30
|
return (name.startsWith("google.protobuf.") &&
|
|
32
31
|
[
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { DescEnum, DescFile } from "../descriptors.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { GenEnum } from "./types.js";
|
|
3
3
|
import type { JsonValue } from "../json-value.js";
|
|
4
4
|
/**
|
|
5
5
|
* Hydrate an enum descriptor.
|
|
6
6
|
*
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
|
-
export declare function enumDesc<Shape, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]):
|
|
9
|
+
export declare function enumDesc<Shape extends number, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenEnum<Shape, JsonType>;
|
|
10
10
|
/**
|
|
11
11
|
* Construct a TypeScript enum object at runtime from a descriptor.
|
|
12
12
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
2
|
import type { DescFile } from "../descriptors.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { GenExtension } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Hydrate an extension descriptor.
|
|
6
6
|
*
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
|
-
export declare function extDesc<Extendee extends Message, Value>(file: DescFile, path: number, ...paths: number[]):
|
|
9
|
+
export declare function extDesc<Extendee extends Message, Value>(file: DescFile, path: number, ...paths: number[]): GenExtension<Extendee, Value>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
2
|
import type { DescFile } from "../descriptors.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { GenMessage } from "./types.js";
|
|
4
4
|
import type { JsonValue } from "../json-value.js";
|
|
5
5
|
/**
|
|
6
6
|
* Hydrate a message descriptor.
|
|
7
7
|
*
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
|
-
export declare function messageDesc<Shape extends Message, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]):
|
|
10
|
+
export declare function messageDesc<Shape extends Message, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenMessage<Shape, JsonType>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenService, GenServiceMethods } from "./types.js";
|
|
2
2
|
import type { DescFile } from "../descriptors.js";
|
|
3
3
|
/**
|
|
4
4
|
* Hydrate a service descriptor.
|
|
5
5
|
*
|
|
6
6
|
* @private
|
|
7
7
|
*/
|
|
8
|
-
export declare function serviceDesc<T extends
|
|
8
|
+
export declare function serviceDesc<T extends GenServiceMethods>(file: DescFile, path: number, ...paths: number[]): GenService<T>;
|
|
@@ -106,27 +106,27 @@ export declare const symbols: {
|
|
|
106
106
|
readonly bootstrapWktFrom: "../../codegenv1/enum.js";
|
|
107
107
|
readonly from: string;
|
|
108
108
|
};
|
|
109
|
-
readonly
|
|
109
|
+
readonly GenFile: {
|
|
110
110
|
readonly typeOnly: true;
|
|
111
111
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
112
112
|
readonly from: string;
|
|
113
113
|
};
|
|
114
|
-
readonly
|
|
114
|
+
readonly GenEnum: {
|
|
115
115
|
readonly typeOnly: true;
|
|
116
116
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
117
117
|
readonly from: string;
|
|
118
118
|
};
|
|
119
|
-
readonly
|
|
119
|
+
readonly GenExtension: {
|
|
120
120
|
readonly typeOnly: true;
|
|
121
121
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
122
122
|
readonly from: string;
|
|
123
123
|
};
|
|
124
|
-
readonly
|
|
124
|
+
readonly GenMessage: {
|
|
125
125
|
readonly typeOnly: true;
|
|
126
126
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
127
127
|
readonly from: string;
|
|
128
128
|
};
|
|
129
|
-
readonly
|
|
129
|
+
readonly GenService: {
|
|
130
130
|
readonly typeOnly: true;
|
|
131
131
|
readonly bootstrapWktFrom: "../../codegenv1/types.js";
|
|
132
132
|
readonly from: string;
|
|
@@ -57,10 +57,10 @@ export const symbols = {
|
|
|
57
57
|
messageDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/message.js", from: packageName + "/codegenv1" },
|
|
58
58
|
serviceDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/service.js", from: packageName + "/codegenv1" },
|
|
59
59
|
tsEnum: { typeOnly: false, bootstrapWktFrom: "../../codegenv1/enum.js", from: packageName + "/codegenv1" },
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
GenFile: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: packageName + "/codegenv1" },
|
|
61
|
+
GenEnum: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: packageName + "/codegenv1" },
|
|
62
|
+
GenExtension: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: packageName + "/codegenv1" },
|
|
63
|
+
GenMessage: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: packageName + "/codegenv1" },
|
|
64
|
+
GenService: { typeOnly: true, bootstrapWktFrom: "../../codegenv1/types.js", from: packageName + "/codegenv1" },
|
|
65
65
|
},
|
|
66
66
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Message } from "../types.js";
|
|
2
|
-
import type { DescEnum, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescService } from "../descriptors.js";
|
|
2
|
+
import type { DescEnum, DescEnumValue, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescService } from "../descriptors.js";
|
|
3
3
|
import type { JsonValue } from "../json-value.js";
|
|
4
4
|
/**
|
|
5
5
|
* Describes a protobuf source file.
|
|
6
6
|
*
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type GenFile = DescFile;
|
|
10
10
|
/**
|
|
11
11
|
* Describes a message declaration in a protobuf source file.
|
|
12
12
|
*
|
|
@@ -15,7 +15,7 @@ export type GenDescFile = DescFile;
|
|
|
15
15
|
*
|
|
16
16
|
* @private
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type GenMessage<RuntimeShape extends Message, JsonType = JsonValue> = Omit<DescMessage, "field"> & {
|
|
19
19
|
field: Record<MessageFieldNames<RuntimeShape>, DescField>;
|
|
20
20
|
} & brandv1<RuntimeShape, JsonType>;
|
|
21
21
|
/**
|
|
@@ -26,7 +26,9 @@ export type GenDescMessage<RuntimeShape extends Message, JsonType = JsonValue> =
|
|
|
26
26
|
*
|
|
27
27
|
* @private
|
|
28
28
|
*/
|
|
29
|
-
export type
|
|
29
|
+
export type GenEnum<RuntimeShape extends number, JsonType extends JsonValue = JsonValue> = Omit<DescEnum, "value"> & {
|
|
30
|
+
value: Record<RuntimeShape, DescEnumValue>;
|
|
31
|
+
} & brandv1<RuntimeShape, JsonType>;
|
|
30
32
|
/**
|
|
31
33
|
* Describes an extension in a protobuf source file.
|
|
32
34
|
*
|
|
@@ -35,7 +37,7 @@ export type GenDescEnum<RuntimeShape, JsonType extends JsonValue = JsonValue> =
|
|
|
35
37
|
*
|
|
36
38
|
* @private
|
|
37
39
|
*/
|
|
38
|
-
export type
|
|
40
|
+
export type GenExtension<Extendee extends Message = Message, RuntimeShape = unknown> = DescExtension & brandv1<Extendee, RuntimeShape>;
|
|
39
41
|
/**
|
|
40
42
|
* Describes a service declaration in a protobuf source file.
|
|
41
43
|
*
|
|
@@ -44,7 +46,7 @@ export type GenDescExtension<Extendee extends Message = Message, RuntimeShape =
|
|
|
44
46
|
*
|
|
45
47
|
* @private
|
|
46
48
|
*/
|
|
47
|
-
export type
|
|
49
|
+
export type GenService<RuntimeShape extends GenServiceMethods> = Omit<DescService, "method"> & {
|
|
48
50
|
method: {
|
|
49
51
|
[K in keyof RuntimeShape]: RuntimeShape[K] & DescMethod;
|
|
50
52
|
};
|
|
@@ -52,7 +54,7 @@ export type GenDescService<RuntimeShape extends GenDescServiceMethods> = Omit<De
|
|
|
52
54
|
/**
|
|
53
55
|
* @private
|
|
54
56
|
*/
|
|
55
|
-
export type
|
|
57
|
+
export type GenServiceMethods = Record<string, Pick<DescMethod, "input" | "output" | "methodKind">>;
|
|
56
58
|
declare class brandv1<A, B = unknown> {
|
|
57
59
|
protected v: "codegenv1";
|
|
58
60
|
protected a: A | boolean;
|
package/dist/esm/create.js
CHANGED
|
@@ -149,7 +149,9 @@ const messagePrototypes = new WeakMap();
|
|
|
149
149
|
function createZeroMessage(desc) {
|
|
150
150
|
let msg;
|
|
151
151
|
if (!needsPrototypeChain(desc)) {
|
|
152
|
-
msg = {
|
|
152
|
+
msg = {
|
|
153
|
+
$typeName: desc.typeName,
|
|
154
|
+
};
|
|
153
155
|
for (const member of desc.members) {
|
|
154
156
|
if (member.kind == "oneof" || member.presence == IMPLICIT) {
|
|
155
157
|
msg[member.localName] = createZeroField(member);
|
|
@@ -189,6 +191,7 @@ function createZeroMessage(desc) {
|
|
|
189
191
|
messagePrototypes.set(desc, { prototype, members });
|
|
190
192
|
}
|
|
191
193
|
msg = Object.create(prototype);
|
|
194
|
+
msg.$typeName = desc.typeName;
|
|
192
195
|
for (const member of desc.members) {
|
|
193
196
|
if (members.has(member)) {
|
|
194
197
|
continue;
|
|
@@ -206,7 +209,6 @@ function createZeroMessage(desc) {
|
|
|
206
209
|
msg[member.localName] = createZeroField(member);
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
|
-
msg.$typeName = desc.typeName;
|
|
210
212
|
return msg;
|
|
211
213
|
}
|
|
212
214
|
/**
|
|
@@ -106,6 +106,10 @@ export interface DescEnum {
|
|
|
106
106
|
* Values declared for this enumeration.
|
|
107
107
|
*/
|
|
108
108
|
readonly values: DescEnumValue[];
|
|
109
|
+
/**
|
|
110
|
+
* All values of this enum by their number.
|
|
111
|
+
*/
|
|
112
|
+
readonly value: Record<number, DescEnumValue>;
|
|
109
113
|
/**
|
|
110
114
|
* A prefix shared by all enum values.
|
|
111
115
|
* For example, `my_enum_` for `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`
|
package/dist/esm/registry.js
CHANGED
|
@@ -45,6 +45,9 @@ export function createMutableRegistry(...input) {
|
|
|
45
45
|
}
|
|
46
46
|
export function createFileRegistry(...args) {
|
|
47
47
|
const registry = createBaseRegistry();
|
|
48
|
+
if (!args.length) {
|
|
49
|
+
return registry;
|
|
50
|
+
}
|
|
48
51
|
if ("$typeName" in args[0] &&
|
|
49
52
|
args[0].$typeName == "google.protobuf.FileDescriptorSet") {
|
|
50
53
|
for (const file of args[0].file) {
|
|
@@ -376,6 +379,7 @@ function addEnum(proto, file, parent, reg) {
|
|
|
376
379
|
open: true,
|
|
377
380
|
name: proto.name,
|
|
378
381
|
typeName: makeTypeName(proto, parent, file),
|
|
382
|
+
value: {},
|
|
379
383
|
values: [],
|
|
380
384
|
sharedPrefix,
|
|
381
385
|
toString() {
|
|
@@ -387,18 +391,20 @@ function addEnum(proto, file, parent, reg) {
|
|
|
387
391
|
proto.value.forEach((proto) => {
|
|
388
392
|
var _a, _b;
|
|
389
393
|
const name = proto.name;
|
|
390
|
-
desc.values.push({
|
|
394
|
+
desc.values.push((desc.value[proto.number] = {
|
|
391
395
|
kind: "enum_value",
|
|
392
396
|
proto,
|
|
393
397
|
deprecated: (_b = (_a = proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) !== null && _b !== void 0 ? _b : false,
|
|
394
398
|
parent: desc,
|
|
395
|
-
name
|
|
396
|
-
localName: safeObjectProperty(sharedPrefix == undefined
|
|
399
|
+
name,
|
|
400
|
+
localName: safeObjectProperty(sharedPrefix == undefined
|
|
401
|
+
? name
|
|
402
|
+
: name.substring(sharedPrefix.length)),
|
|
397
403
|
number: proto.number,
|
|
398
404
|
toString() {
|
|
399
|
-
return `enum value ${desc.typeName}.${
|
|
405
|
+
return `enum value ${desc.typeName}.${name}`;
|
|
400
406
|
},
|
|
401
|
-
});
|
|
407
|
+
}));
|
|
402
408
|
});
|
|
403
409
|
((_c = parent === null || parent === void 0 ? void 0 : parent.nestedEnums) !== null && _c !== void 0 ? _c : file.enums).push(desc);
|
|
404
410
|
}
|
package/dist/esm/to-json.js
CHANGED
|
@@ -56,7 +56,7 @@ export function enumToJson(descEnum, value) {
|
|
|
56
56
|
if (descEnum.typeName == "google.protobuf.NullValue") {
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
|
-
const name = (_a = descEnum.
|
|
59
|
+
const name = (_a = descEnum.value[value]) === null || _a === void 0 ? void 0 : _a.name;
|
|
60
60
|
if (name === undefined) {
|
|
61
61
|
throw new Error(`${String(value)} is not a value in ${descEnum.toString()}`);
|
|
62
62
|
}
|
|
@@ -174,7 +174,7 @@ function enumToJsonInternal(desc, value, enumAsInteger) {
|
|
|
174
174
|
if (enumAsInteger) {
|
|
175
175
|
return value;
|
|
176
176
|
}
|
|
177
|
-
const val = desc.
|
|
177
|
+
const val = desc.value[value];
|
|
178
178
|
return (_a = val === null || val === void 0 ? void 0 : val.name) !== null && _a !== void 0 ? _a : value; // if we don't know the enum value, just return the number
|
|
179
179
|
}
|
|
180
180
|
function scalarToJson(field, value) {
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenEnum, GenExtension, GenMessage } from "./codegenv1/types.js";
|
|
2
2
|
import type { DescEnum, DescExtension, DescMessage } from "./descriptors.js";
|
|
3
3
|
import type { OneofADT } from "./reflect/guard.js";
|
|
4
4
|
import type { WireType } from "./wire/index.js";
|
|
@@ -19,32 +19,32 @@ export type Message<TypeName extends string = string> = {
|
|
|
19
19
|
/**
|
|
20
20
|
* Extract the message type from a message descriptor.
|
|
21
21
|
*/
|
|
22
|
-
export type MessageShape<Desc extends DescMessage> = Desc extends
|
|
22
|
+
export type MessageShape<Desc extends DescMessage> = Desc extends GenMessage<infer RuntimeShape> ? RuntimeShape : Message;
|
|
23
23
|
/**
|
|
24
24
|
* Extract the message JSON type from a message descriptor.
|
|
25
25
|
*/
|
|
26
|
-
export type MessageJsonType<Desc extends DescMessage> = Desc extends
|
|
26
|
+
export type MessageJsonType<Desc extends DescMessage> = Desc extends GenMessage<Message, infer JsonType> ? JsonType : JsonValue;
|
|
27
27
|
/**
|
|
28
28
|
* Extract the init type from a message descriptor.
|
|
29
29
|
* The init type is accepted by the function create().
|
|
30
30
|
*/
|
|
31
|
-
export type MessageInitShape<Desc extends DescMessage> = Desc extends
|
|
31
|
+
export type MessageInitShape<Desc extends DescMessage> = Desc extends GenMessage<infer RuntimeShape> ? RuntimeShape | MessageInit<RuntimeShape> : Record<string, unknown>;
|
|
32
32
|
/**
|
|
33
33
|
* Extract the enum type of from an enum descriptor.
|
|
34
34
|
*/
|
|
35
|
-
export type EnumShape<Desc extends DescEnum> = Desc extends
|
|
35
|
+
export type EnumShape<Desc extends DescEnum> = Desc extends GenEnum<infer RuntimeShape> ? RuntimeShape : number;
|
|
36
36
|
/**
|
|
37
37
|
* Extract the enum JSON type from a enum descriptor.
|
|
38
38
|
*/
|
|
39
|
-
export type EnumJsonType<Desc extends DescEnum> = Desc extends
|
|
39
|
+
export type EnumJsonType<Desc extends DescEnum> = Desc extends GenEnum<number, infer JsonType> ? JsonType : string | null;
|
|
40
40
|
/**
|
|
41
41
|
* Extract the value type from an extension descriptor.
|
|
42
42
|
*/
|
|
43
|
-
export type ExtensionValueShape<Desc extends DescExtension> = Desc extends
|
|
43
|
+
export type ExtensionValueShape<Desc extends DescExtension> = Desc extends GenExtension<Message, infer RuntimeShape> ? RuntimeShape : unknown;
|
|
44
44
|
/**
|
|
45
45
|
* Extract the type of the extended message from an extension descriptor.
|
|
46
46
|
*/
|
|
47
|
-
export type Extendee<Desc extends DescExtension> = Desc extends
|
|
47
|
+
export type Extendee<Desc extends DescExtension> = Desc extends GenExtension<infer Extendee> ? Extendee : Message;
|
|
48
48
|
/**
|
|
49
49
|
* Unknown fields are fields that were not recognized during parsing, or
|
|
50
50
|
* extension.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenFile, GenMessage } from "../../../../codegenv1/types.js";
|
|
2
2
|
import type { Message } from "../../../../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Describes the file google/protobuf/any.proto.
|
|
5
5
|
*/
|
|
6
|
-
export declare const file_google_protobuf_any:
|
|
6
|
+
export declare const file_google_protobuf_any: GenFile;
|
|
7
7
|
/**
|
|
8
8
|
* `Any` contains an arbitrary serialized protocol buffer message along with a
|
|
9
9
|
* URL that describes the type of the serialized message.
|
|
@@ -146,4 +146,4 @@ export type AnyJson = {
|
|
|
146
146
|
* Describes the message google.protobuf.Any.
|
|
147
147
|
* Use `create(AnySchema)` to create a new message.
|
|
148
148
|
*/
|
|
149
|
-
export declare const AnySchema:
|
|
149
|
+
export declare const AnySchema: GenMessage<Any, AnyJson>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GenFile, GenMessage } from "../../../../codegenv1/types.js";
|
|
2
2
|
import type { SourceContext, SourceContextJson } from "./source_context_pb.js";
|
|
3
3
|
import type { Option, OptionJson, Syntax, SyntaxJson } from "./type_pb.js";
|
|
4
4
|
import type { Message } from "../../../../types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Describes the file google/protobuf/api.proto.
|
|
7
7
|
*/
|
|
8
|
-
export declare const file_google_protobuf_api:
|
|
8
|
+
export declare const file_google_protobuf_api: GenFile;
|
|
9
9
|
/**
|
|
10
10
|
* Api is a light-weight descriptor for an API Interface.
|
|
11
11
|
*
|
|
@@ -121,7 +121,7 @@ export type ApiJson = {
|
|
|
121
121
|
* Describes the message google.protobuf.Api.
|
|
122
122
|
* Use `create(ApiSchema)` to create a new message.
|
|
123
123
|
*/
|
|
124
|
-
export declare const ApiSchema:
|
|
124
|
+
export declare const ApiSchema: GenMessage<Api, ApiJson>;
|
|
125
125
|
/**
|
|
126
126
|
* Method represents a method of an API interface.
|
|
127
127
|
*
|
|
@@ -208,7 +208,7 @@ export type MethodJson = {
|
|
|
208
208
|
* Describes the message google.protobuf.Method.
|
|
209
209
|
* Use `create(MethodSchema)` to create a new message.
|
|
210
210
|
*/
|
|
211
|
-
export declare const MethodSchema:
|
|
211
|
+
export declare const MethodSchema: GenMessage<Method, MethodJson>;
|
|
212
212
|
/**
|
|
213
213
|
* Declares an API Interface to be included in this interface. The including
|
|
214
214
|
* interface must redeclare all the methods from the included interface, but
|
|
@@ -323,4 +323,4 @@ export type MixinJson = {
|
|
|
323
323
|
* Describes the message google.protobuf.Mixin.
|
|
324
324
|
* Use `create(MixinSchema)` to create a new message.
|
|
325
325
|
*/
|
|
326
|
-
export declare const MixinSchema:
|
|
326
|
+
export declare const MixinSchema: GenMessage<Mixin, MixinJson>;
|