@bufbuild/protobuf 2.0.0-alpha.3 → 2.0.0-beta.1
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/dist/cjs/clone.d.ts +1 -1
- package/dist/cjs/clone.js +9 -17
- package/dist/cjs/codegenv1/embed.js +25 -25
- package/dist/cjs/codegenv1/enum.d.ts +2 -1
- package/dist/cjs/codegenv1/file.js +1 -1
- package/dist/cjs/codegenv1/message.d.ts +2 -1
- package/dist/cjs/codegenv1/scalar.d.ts +4 -0
- package/dist/cjs/codegenv1/scalar.js +30 -1
- package/dist/cjs/codegenv1/symbols.d.ts +10 -0
- package/dist/cjs/codegenv1/symbols.js +2 -0
- package/dist/cjs/codegenv1/types.d.ts +7 -5
- package/dist/cjs/codegenv1/types.js +2 -1
- package/dist/cjs/create.d.ts +1 -1
- package/dist/cjs/create.js +47 -20
- package/dist/cjs/equals.d.ts +1 -1
- package/dist/cjs/equals.js +8 -15
- package/dist/cjs/from-binary.d.ts +2 -2
- package/dist/cjs/from-binary.js +17 -14
- package/dist/cjs/from-json.d.ts +14 -6
- package/dist/cjs/from-json.js +51 -55
- package/dist/cjs/is-message.d.ts +1 -1
- package/dist/cjs/is-message.js +3 -3
- package/dist/cjs/reflect/guard.js +4 -4
- package/dist/cjs/reflect/reflect-types.d.ts +13 -80
- package/dist/cjs/reflect/reflect.d.ts +29 -18
- package/dist/cjs/reflect/reflect.js +183 -78
- package/dist/cjs/reflect/scalar.d.ts +1 -1
- package/dist/cjs/reflect/unsafe.d.ts +0 -16
- package/dist/cjs/reflect/unsafe.js +1 -19
- package/dist/cjs/registry.d.ts +18 -2
- package/dist/cjs/registry.js +62 -60
- package/dist/cjs/to-binary.d.ts +1 -1
- package/dist/cjs/to-binary.js +2 -2
- package/dist/cjs/to-json.d.ts +14 -4
- package/dist/cjs/to-json.js +26 -13
- package/dist/cjs/types.d.ts +9 -0
- package/dist/cjs/wire/binary-encoding.js +30 -9
- package/dist/cjs/wkt/any.d.ts +7 -7
- package/dist/cjs/wkt/any.js +5 -5
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.d.ts +9 -3
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.d.ts +88 -9
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.js +8 -8
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +107 -11
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.js +11 -11
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +1005 -92
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +86 -86
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.d.ts +12 -3
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.d.ts +25 -8
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.js +9 -9
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.d.ts +165 -16
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.js +15 -15
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.d.ts +55 -19
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.js +20 -20
- package/dist/cjs/wkt/timestamp.js +1 -2
- package/dist/esm/clone.d.ts +1 -1
- package/dist/esm/clone.js +9 -17
- package/dist/esm/codegenv1/embed.js +26 -26
- package/dist/esm/codegenv1/enum.d.ts +2 -1
- package/dist/esm/codegenv1/file.js +2 -2
- package/dist/esm/codegenv1/message.d.ts +2 -1
- package/dist/esm/codegenv1/scalar.d.ts +4 -0
- package/dist/esm/codegenv1/scalar.js +28 -0
- package/dist/esm/codegenv1/symbols.d.ts +10 -0
- package/dist/esm/codegenv1/symbols.js +2 -0
- package/dist/esm/codegenv1/types.d.ts +7 -5
- package/dist/esm/codegenv1/types.js +2 -1
- package/dist/esm/create.d.ts +1 -1
- package/dist/esm/create.js +47 -20
- package/dist/esm/equals.d.ts +1 -1
- package/dist/esm/equals.js +8 -15
- package/dist/esm/from-binary.d.ts +2 -2
- package/dist/esm/from-binary.js +17 -14
- package/dist/esm/from-json.d.ts +14 -6
- package/dist/esm/from-json.js +49 -55
- package/dist/esm/is-message.d.ts +1 -1
- package/dist/esm/is-message.js +3 -3
- package/dist/esm/reflect/guard.js +4 -4
- package/dist/esm/reflect/reflect-types.d.ts +13 -80
- package/dist/esm/reflect/reflect-types.js +0 -1
- package/dist/esm/reflect/reflect.d.ts +29 -18
- package/dist/esm/reflect/reflect.js +185 -80
- package/dist/esm/reflect/scalar.d.ts +1 -1
- package/dist/esm/reflect/unsafe.d.ts +0 -16
- package/dist/esm/reflect/unsafe.js +0 -16
- package/dist/esm/registry.d.ts +18 -2
- package/dist/esm/registry.js +60 -59
- package/dist/esm/to-binary.d.ts +1 -1
- package/dist/esm/to-binary.js +2 -2
- package/dist/esm/to-json.d.ts +14 -4
- package/dist/esm/to-json.js +24 -12
- package/dist/esm/types.d.ts +9 -0
- package/dist/esm/wire/binary-encoding.js +30 -9
- package/dist/esm/wkt/any.d.ts +7 -7
- package/dist/esm/wkt/any.js +6 -6
- package/dist/esm/wkt/gen/google/protobuf/any_pb.d.ts +9 -3
- package/dist/esm/wkt/gen/google/protobuf/any_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/api_pb.d.ts +88 -9
- package/dist/esm/wkt/gen/google/protobuf/api_pb.js +9 -9
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +107 -11
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.js +11 -11
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +1005 -92
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +84 -84
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.d.ts +12 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.d.ts +25 -8
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.js +8 -8
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/type_pb.d.ts +165 -16
- package/dist/esm/wkt/gen/google/protobuf/type_pb.js +16 -16
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.d.ts +55 -19
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.js +19 -19
- package/dist/esm/wkt/timestamp.js +2 -3
- package/package.json +2 -2
package/dist/cjs/to-binary.js
CHANGED
|
@@ -26,8 +26,8 @@ const writeDefaults = {
|
|
|
26
26
|
function makeWriteOptions(options) {
|
|
27
27
|
return options ? Object.assign(Object.assign({}, writeDefaults), options) : writeDefaults;
|
|
28
28
|
}
|
|
29
|
-
function toBinary(
|
|
30
|
-
return writeFields(new binary_encoding_js_1.BinaryWriter(), makeWriteOptions(options), (0, reflect_js_1.reflect)(
|
|
29
|
+
function toBinary(schema, message, options) {
|
|
30
|
+
return writeFields(new binary_encoding_js_1.BinaryWriter(), makeWriteOptions(options), (0, reflect_js_1.reflect)(schema, message)).finish();
|
|
31
31
|
}
|
|
32
32
|
exports.toBinary = toBinary;
|
|
33
33
|
function writeFields(writer, opts, msg) {
|
package/dist/cjs/to-json.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type DescMessage } from "./descriptors.js";
|
|
1
|
+
import { type DescEnum, type DescMessage } from "./descriptors.js";
|
|
2
2
|
import type { JsonValue } from "./json-value.js";
|
|
3
3
|
import type { Registry } from "./registry.js";
|
|
4
|
-
import type { MessageShape } from "./types.js";
|
|
4
|
+
import type { EnumJsonType, EnumShape, MessageJsonType, MessageShape } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Options for serializing to JSON.
|
|
7
7
|
*/
|
|
@@ -44,8 +44,18 @@ export interface JsonWriteStringOptions extends JsonWriteOptions {
|
|
|
44
44
|
* Serialize the message to a JSON value, a JavaScript value that can be
|
|
45
45
|
* passed to JSON.stringify().
|
|
46
46
|
*/
|
|
47
|
-
export declare function toJson<Desc extends DescMessage>(
|
|
47
|
+
export declare function toJson<Desc extends DescMessage, Opts extends Partial<JsonWriteOptions> | undefined = undefined>(schema: Desc, message: MessageShape<Desc>, options?: Opts): ToJson<Desc, Opts>;
|
|
48
|
+
type ToJson<Desc extends DescMessage, Opts extends undefined | Partial<JsonWriteOptions>> = Opts extends undefined | {
|
|
49
|
+
alwaysEmitImplicit?: false;
|
|
50
|
+
enumAsInteger?: false;
|
|
51
|
+
useProtoFieldName?: false;
|
|
52
|
+
} ? MessageJsonType<Desc> : JsonValue;
|
|
48
53
|
/**
|
|
49
54
|
* Serialize the message to a JSON string.
|
|
50
55
|
*/
|
|
51
|
-
export declare function toJsonString<Desc extends DescMessage>(
|
|
56
|
+
export declare function toJsonString<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<JsonWriteStringOptions>): string;
|
|
57
|
+
/**
|
|
58
|
+
* Serialize a single enum value to JSON.
|
|
59
|
+
*/
|
|
60
|
+
export declare function enumToJson<Desc extends DescEnum>(descEnum: Desc, value: EnumShape<Desc>): EnumJsonType<Desc>;
|
|
61
|
+
export {};
|
package/dist/cjs/to-json.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
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.toJsonString = exports.toJson = void 0;
|
|
16
|
+
exports.enumToJson = exports.toJsonString = exports.toJson = void 0;
|
|
17
17
|
const descriptors_js_1 = require("./descriptors.js");
|
|
18
18
|
const names_js_1 = require("./reflect/names.js");
|
|
19
19
|
const reflect_js_1 = require("./reflect/reflect.js");
|
|
@@ -40,19 +40,34 @@ function makeWriteOptions(options) {
|
|
|
40
40
|
* Serialize the message to a JSON value, a JavaScript value that can be
|
|
41
41
|
* passed to JSON.stringify().
|
|
42
42
|
*/
|
|
43
|
-
function toJson(
|
|
44
|
-
return reflectToJson((0, reflect_js_1.reflect)(
|
|
43
|
+
function toJson(schema, message, options) {
|
|
44
|
+
return reflectToJson((0, reflect_js_1.reflect)(schema, message), makeWriteOptions(options));
|
|
45
45
|
}
|
|
46
46
|
exports.toJson = toJson;
|
|
47
47
|
/**
|
|
48
48
|
* Serialize the message to a JSON string.
|
|
49
49
|
*/
|
|
50
|
-
function toJsonString(
|
|
50
|
+
function toJsonString(schema, message, options) {
|
|
51
51
|
var _a;
|
|
52
|
-
const jsonValue = toJson(
|
|
52
|
+
const jsonValue = toJson(schema, message, options);
|
|
53
53
|
return JSON.stringify(jsonValue, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
|
|
54
54
|
}
|
|
55
55
|
exports.toJsonString = toJsonString;
|
|
56
|
+
/**
|
|
57
|
+
* Serialize a single enum value to JSON.
|
|
58
|
+
*/
|
|
59
|
+
function enumToJson(descEnum, value) {
|
|
60
|
+
var _a;
|
|
61
|
+
if (descEnum.typeName == "google.protobuf.NullValue") {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const name = (_a = descEnum.values.find((v) => v.number === value)) === null || _a === void 0 ? void 0 : _a.name;
|
|
65
|
+
if (name === undefined) {
|
|
66
|
+
throw new Error(`${String(value)} is not a value in ${descEnum.toString()}`);
|
|
67
|
+
}
|
|
68
|
+
return name;
|
|
69
|
+
}
|
|
70
|
+
exports.enumToJson = enumToJson;
|
|
56
71
|
function reflectToJson(msg, opts) {
|
|
57
72
|
var _a;
|
|
58
73
|
const wktJson = tryWktToJson(msg, opts);
|
|
@@ -103,7 +118,7 @@ function fieldToJson(f, val, opts) {
|
|
|
103
118
|
case "message":
|
|
104
119
|
return reflectToJson(val, opts);
|
|
105
120
|
case "enum":
|
|
106
|
-
return
|
|
121
|
+
return enumToJsonInternal(f.enum, val, opts.enumAsInteger);
|
|
107
122
|
case "list":
|
|
108
123
|
return listToJson(val, opts);
|
|
109
124
|
case "map":
|
|
@@ -116,19 +131,17 @@ function mapToJson(map, opts) {
|
|
|
116
131
|
switch (f.mapKind) {
|
|
117
132
|
case "scalar":
|
|
118
133
|
for (const [entryKey, entryValue] of map) {
|
|
119
|
-
jsonObj[entryKey
|
|
134
|
+
jsonObj[entryKey] = scalarToJson(f, entryValue);
|
|
120
135
|
}
|
|
121
136
|
break;
|
|
122
137
|
case "message":
|
|
123
138
|
for (const [entryKey, entryValue] of map) {
|
|
124
|
-
|
|
125
|
-
jsonObj[entryKey.toString()] = reflectToJson(entryValue, opts);
|
|
139
|
+
jsonObj[entryKey] = reflectToJson(entryValue, opts);
|
|
126
140
|
}
|
|
127
141
|
break;
|
|
128
142
|
case "enum":
|
|
129
143
|
for (const [entryKey, entryValue] of map) {
|
|
130
|
-
|
|
131
|
-
jsonObj[entryKey.toString()] = enumToJson(f.enum, entryValue, opts.enumAsInteger);
|
|
144
|
+
jsonObj[entryKey] = enumToJsonInternal(f.enum, entryValue, opts.enumAsInteger);
|
|
132
145
|
}
|
|
133
146
|
break;
|
|
134
147
|
}
|
|
@@ -145,7 +158,7 @@ function listToJson(list, opts) {
|
|
|
145
158
|
break;
|
|
146
159
|
case "enum":
|
|
147
160
|
for (const item of list) {
|
|
148
|
-
jsonArr.push(
|
|
161
|
+
jsonArr.push(enumToJsonInternal(f.enum, item, opts.enumAsInteger));
|
|
149
162
|
}
|
|
150
163
|
break;
|
|
151
164
|
case "message":
|
|
@@ -156,7 +169,7 @@ function listToJson(list, opts) {
|
|
|
156
169
|
}
|
|
157
170
|
return opts.alwaysEmitImplicit || jsonArr.length > 0 ? jsonArr : undefined;
|
|
158
171
|
}
|
|
159
|
-
function
|
|
172
|
+
function enumToJsonInternal(desc, value, enumAsInteger) {
|
|
160
173
|
var _a;
|
|
161
174
|
if (typeof value != "number") {
|
|
162
175
|
throw new Error(`cannot encode ${desc} to JSON: expected number, got ${(0, reflect_check_js_1.formatVal)(value)}`);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { GenDescEnum, GenDescExtension, GenDescMessage } from "./codegenv1/
|
|
|
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";
|
|
5
|
+
import type { JsonValue } from "./json-value.js";
|
|
5
6
|
/**
|
|
6
7
|
* The type `Message` contains the properties shared by all messages.
|
|
7
8
|
*/
|
|
@@ -19,6 +20,10 @@ export type Message<TypeName extends string = string> = {
|
|
|
19
20
|
* Extract the message type from a message descriptor.
|
|
20
21
|
*/
|
|
21
22
|
export type MessageShape<Desc extends DescMessage> = Desc extends GenDescMessage<infer RuntimeShape> ? RuntimeShape : Message;
|
|
23
|
+
/**
|
|
24
|
+
* Extract the message JSON type from a message descriptor.
|
|
25
|
+
*/
|
|
26
|
+
export type MessageJsonType<Desc extends DescMessage> = Desc extends GenDescMessage<Message, infer JsonType> ? JsonType : JsonValue;
|
|
22
27
|
/**
|
|
23
28
|
* Extract the init type from a message descriptor.
|
|
24
29
|
* The init type is accepted by the function create().
|
|
@@ -28,6 +33,10 @@ export type MessageInitShape<Desc extends DescMessage> = Desc extends GenDescMes
|
|
|
28
33
|
* Extract the enum type of from an enum descriptor.
|
|
29
34
|
*/
|
|
30
35
|
export type EnumShape<Desc extends DescEnum> = Desc extends GenDescEnum<infer RuntimeShape> ? RuntimeShape : number;
|
|
36
|
+
/**
|
|
37
|
+
* Extract the enum JSON type from a enum descriptor.
|
|
38
|
+
*/
|
|
39
|
+
export type EnumJsonType<Desc extends DescEnum> = Desc extends GenDescEnum<unknown, infer JsonType> ? JsonType : string | null;
|
|
31
40
|
/**
|
|
32
41
|
* Extract the value type from an extension descriptor.
|
|
33
42
|
*/
|
|
@@ -462,29 +462,50 @@ class BinaryReader {
|
|
|
462
462
|
}
|
|
463
463
|
exports.BinaryReader = BinaryReader;
|
|
464
464
|
/**
|
|
465
|
-
* Assert a valid signed protobuf 32-bit integer.
|
|
465
|
+
* Assert a valid signed protobuf 32-bit integer as a number or string.
|
|
466
466
|
*/
|
|
467
467
|
function assertInt32(arg) {
|
|
468
|
-
if (typeof arg
|
|
468
|
+
if (typeof arg == "string") {
|
|
469
|
+
arg = Number(arg);
|
|
470
|
+
}
|
|
471
|
+
else if (typeof arg != "number") {
|
|
469
472
|
throw new Error("invalid int32: " + typeof arg);
|
|
470
|
-
|
|
473
|
+
}
|
|
474
|
+
if (!Number.isInteger(arg) ||
|
|
475
|
+
arg > exports.INT32_MAX ||
|
|
476
|
+
arg < exports.INT32_MIN)
|
|
471
477
|
throw new Error("invalid int32: " + arg);
|
|
472
478
|
}
|
|
473
479
|
/**
|
|
474
|
-
* Assert a valid unsigned protobuf 32-bit integer.
|
|
480
|
+
* Assert a valid unsigned protobuf 32-bit integer as a number or string.
|
|
475
481
|
*/
|
|
476
482
|
function assertUInt32(arg) {
|
|
477
|
-
if (typeof arg
|
|
483
|
+
if (typeof arg == "string") {
|
|
484
|
+
arg = Number(arg);
|
|
485
|
+
}
|
|
486
|
+
else if (typeof arg != "number") {
|
|
478
487
|
throw new Error("invalid uint32: " + typeof arg);
|
|
479
|
-
|
|
488
|
+
}
|
|
489
|
+
if (!Number.isInteger(arg) ||
|
|
490
|
+
arg > exports.UINT32_MAX ||
|
|
491
|
+
arg < 0)
|
|
480
492
|
throw new Error("invalid uint32: " + arg);
|
|
481
493
|
}
|
|
482
494
|
/**
|
|
483
|
-
* Assert a valid protobuf float value.
|
|
495
|
+
* Assert a valid protobuf float value as a number or string.
|
|
484
496
|
*/
|
|
485
497
|
function assertFloat32(arg) {
|
|
486
|
-
if (typeof arg
|
|
498
|
+
if (typeof arg == "string") {
|
|
499
|
+
const o = arg;
|
|
500
|
+
arg = Number(arg);
|
|
501
|
+
if (isNaN(arg) && o !== "NaN") {
|
|
502
|
+
throw new Error("invalid float32: " + o);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
else if (typeof arg != "number") {
|
|
487
506
|
throw new Error("invalid float32: " + typeof arg);
|
|
488
|
-
|
|
507
|
+
}
|
|
508
|
+
if (Number.isFinite(arg) &&
|
|
509
|
+
(arg > exports.FLOAT32_MAX || arg < exports.FLOAT32_MIN))
|
|
489
510
|
throw new Error("invalid float32: " + arg);
|
|
490
511
|
}
|
package/dist/cjs/wkt/any.d.ts
CHANGED
|
@@ -5,15 +5,15 @@ import type { Registry } from "../registry.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates a `google.protobuf.Any` from a message.
|
|
7
7
|
*/
|
|
8
|
-
export declare function anyPack<Desc extends DescMessage>(
|
|
8
|
+
export declare function anyPack<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>): Any;
|
|
9
9
|
/**
|
|
10
10
|
* Packs the message into the given any.
|
|
11
11
|
*/
|
|
12
|
-
export declare function anyPack<Desc extends DescMessage>(
|
|
12
|
+
export declare function anyPack<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, into: Any): void;
|
|
13
13
|
/**
|
|
14
|
-
* Returns true if the Any contains the type given by
|
|
14
|
+
* Returns true if the Any contains the type given by schema.
|
|
15
15
|
*/
|
|
16
|
-
export declare function anyIs(any: Any,
|
|
16
|
+
export declare function anyIs(any: Any, schema: DescMessage): boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Returns true if the Any contains a message with the given typeName.
|
|
19
19
|
*/
|
|
@@ -29,10 +29,10 @@ export declare function anyUnpack(any: Any, registry: Registry): Message | undef
|
|
|
29
29
|
* Unpacks the message the Any represents.
|
|
30
30
|
*
|
|
31
31
|
* Returns undefined if the Any is empty, or if it does not contain the type
|
|
32
|
-
* given by
|
|
32
|
+
* given by schema.
|
|
33
33
|
*/
|
|
34
|
-
export declare function anyUnpack<Desc extends DescMessage>(any: Any,
|
|
34
|
+
export declare function anyUnpack<Desc extends DescMessage>(any: Any, schema: Desc): MessageShape<Desc> | undefined;
|
|
35
35
|
/**
|
|
36
36
|
* Same as anyUnpack but unpacks into the target message.
|
|
37
37
|
*/
|
|
38
|
-
export declare function anyUnpackTo<Desc extends DescMessage>(any: Any,
|
|
38
|
+
export declare function anyUnpackTo<Desc extends DescMessage>(any: Any, schema: Desc, message: MessageShape<Desc>): MessageShape<Desc> | undefined;
|
package/dist/cjs/wkt/any.js
CHANGED
|
@@ -18,13 +18,13 @@ const any_pb_js_1 = require("./gen/google/protobuf/any_pb.js");
|
|
|
18
18
|
const create_js_1 = require("../create.js");
|
|
19
19
|
const to_binary_js_1 = require("../to-binary.js");
|
|
20
20
|
const from_binary_js_1 = require("../from-binary.js");
|
|
21
|
-
function anyPack(
|
|
21
|
+
function anyPack(schema, message, into) {
|
|
22
22
|
let ret = false;
|
|
23
23
|
if (!into) {
|
|
24
|
-
into = (0, create_js_1.create)(any_pb_js_1.
|
|
24
|
+
into = (0, create_js_1.create)(any_pb_js_1.AnySchema);
|
|
25
25
|
ret = true;
|
|
26
26
|
}
|
|
27
|
-
into.value = (0, to_binary_js_1.toBinary)(
|
|
27
|
+
into.value = (0, to_binary_js_1.toBinary)(schema, message);
|
|
28
28
|
into.typeUrl = typeNameToUrl(message.$typeName);
|
|
29
29
|
return ret ? into : undefined;
|
|
30
30
|
}
|
|
@@ -56,11 +56,11 @@ exports.anyUnpack = anyUnpack;
|
|
|
56
56
|
/**
|
|
57
57
|
* Same as anyUnpack but unpacks into the target message.
|
|
58
58
|
*/
|
|
59
|
-
function anyUnpackTo(any,
|
|
59
|
+
function anyUnpackTo(any, schema, message) {
|
|
60
60
|
if (any.typeUrl === "") {
|
|
61
61
|
return undefined;
|
|
62
62
|
}
|
|
63
|
-
return (0, from_binary_js_1.mergeFromBinary)(
|
|
63
|
+
return (0, from_binary_js_1.mergeFromBinary)(schema, message, any.value);
|
|
64
64
|
}
|
|
65
65
|
exports.anyUnpackTo = anyUnpackTo;
|
|
66
66
|
function typeNameToUrl(name) {
|
|
@@ -3,7 +3,7 @@ import type { Message } from "../../../../types.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Describes the file google/protobuf/any.proto.
|
|
5
5
|
*/
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const file_google_protobuf_any: GenDescFile;
|
|
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.
|
|
@@ -136,8 +136,14 @@ export type Any = Message<"google.protobuf.Any"> & {
|
|
|
136
136
|
*/
|
|
137
137
|
value: Uint8Array;
|
|
138
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* JSON type for the message google.protobuf.Any.
|
|
141
|
+
*/
|
|
142
|
+
export type AnyJson = {
|
|
143
|
+
"@type"?: string;
|
|
144
|
+
};
|
|
139
145
|
/**
|
|
140
146
|
* Describes the message google.protobuf.Any.
|
|
141
|
-
* Use `create(
|
|
147
|
+
* Use `create(AnySchema)` to create a new message.
|
|
142
148
|
*/
|
|
143
|
-
export declare const
|
|
149
|
+
export declare const AnySchema: GenDescMessage<Any, AnyJson>;
|
|
@@ -13,15 +13,15 @@
|
|
|
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.AnySchema = exports.file_google_protobuf_any = void 0;
|
|
17
17
|
const file_js_1 = require("../../../../codegenv1/file.js");
|
|
18
18
|
const message_js_1 = require("../../../../codegenv1/message.js");
|
|
19
19
|
/**
|
|
20
20
|
* Describes the file google/protobuf/any.proto.
|
|
21
21
|
*/
|
|
22
|
-
exports.
|
|
22
|
+
exports.file_google_protobuf_any = (0, file_js_1.fileDesc)("Chlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvEg9nb29nbGUucHJvdG9idWYiJgoDQW55EhAKCHR5cGVfdXJsGAEgASgJEg0KBXZhbHVlGAIgASgMQnYKE2NvbS5nb29nbGUucHJvdG9idWZCCEFueVByb3RvUAFaLGdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL2FueXBiogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90bzM");
|
|
23
23
|
/**
|
|
24
24
|
* Describes the message google.protobuf.Any.
|
|
25
|
-
* Use `create(
|
|
25
|
+
* Use `create(AnySchema)` to create a new message.
|
|
26
26
|
*/
|
|
27
|
-
exports.
|
|
27
|
+
exports.AnySchema = (0, message_js_1.messageDesc)(exports.file_google_protobuf_any, 0);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { GenDescFile, GenDescMessage } from "../../../../codegenv1/types.js";
|
|
2
|
-
import type { SourceContext } from "./source_context_pb.js";
|
|
3
|
-
import type { Option, Syntax } from "./type_pb.js";
|
|
2
|
+
import type { SourceContext, SourceContextJson } from "./source_context_pb.js";
|
|
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
|
|
8
|
+
export declare const file_google_protobuf_api: GenDescFile;
|
|
9
9
|
/**
|
|
10
10
|
* Api is a light-weight descriptor for an API Interface.
|
|
11
11
|
*
|
|
@@ -84,11 +84,44 @@ export type Api = Message<"google.protobuf.Api"> & {
|
|
|
84
84
|
*/
|
|
85
85
|
syntax: Syntax;
|
|
86
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* JSON type for the message google.protobuf.Api.
|
|
89
|
+
*/
|
|
90
|
+
export type ApiJson = {
|
|
91
|
+
/**
|
|
92
|
+
* @generated from field: string name = 1;
|
|
93
|
+
*/
|
|
94
|
+
name?: string;
|
|
95
|
+
/**
|
|
96
|
+
* @generated from field: repeated google.protobuf.Method methods = 2;
|
|
97
|
+
*/
|
|
98
|
+
methods?: MethodJson[];
|
|
99
|
+
/**
|
|
100
|
+
* @generated from field: repeated google.protobuf.Option options = 3;
|
|
101
|
+
*/
|
|
102
|
+
options?: OptionJson[];
|
|
103
|
+
/**
|
|
104
|
+
* @generated from field: string version = 4;
|
|
105
|
+
*/
|
|
106
|
+
version?: string;
|
|
107
|
+
/**
|
|
108
|
+
* @generated from field: google.protobuf.SourceContext source_context = 5;
|
|
109
|
+
*/
|
|
110
|
+
sourceContext?: SourceContextJson;
|
|
111
|
+
/**
|
|
112
|
+
* @generated from field: repeated google.protobuf.Mixin mixins = 6;
|
|
113
|
+
*/
|
|
114
|
+
mixins?: MixinJson[];
|
|
115
|
+
/**
|
|
116
|
+
* @generated from field: google.protobuf.Syntax syntax = 7;
|
|
117
|
+
*/
|
|
118
|
+
syntax?: SyntaxJson;
|
|
119
|
+
};
|
|
87
120
|
/**
|
|
88
121
|
* Describes the message google.protobuf.Api.
|
|
89
|
-
* Use `create(
|
|
122
|
+
* Use `create(ApiSchema)` to create a new message.
|
|
90
123
|
*/
|
|
91
|
-
export declare const
|
|
124
|
+
export declare const ApiSchema: GenDescMessage<Api, ApiJson>;
|
|
92
125
|
/**
|
|
93
126
|
* Method represents a method of an API interface.
|
|
94
127
|
*
|
|
@@ -138,11 +171,44 @@ export type Method = Message<"google.protobuf.Method"> & {
|
|
|
138
171
|
*/
|
|
139
172
|
syntax: Syntax;
|
|
140
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* JSON type for the message google.protobuf.Method.
|
|
176
|
+
*/
|
|
177
|
+
export type MethodJson = {
|
|
178
|
+
/**
|
|
179
|
+
* @generated from field: string name = 1;
|
|
180
|
+
*/
|
|
181
|
+
name?: string;
|
|
182
|
+
/**
|
|
183
|
+
* @generated from field: string request_type_url = 2;
|
|
184
|
+
*/
|
|
185
|
+
requestTypeUrl?: string;
|
|
186
|
+
/**
|
|
187
|
+
* @generated from field: bool request_streaming = 3;
|
|
188
|
+
*/
|
|
189
|
+
requestStreaming?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* @generated from field: string response_type_url = 4;
|
|
192
|
+
*/
|
|
193
|
+
responseTypeUrl?: string;
|
|
194
|
+
/**
|
|
195
|
+
* @generated from field: bool response_streaming = 5;
|
|
196
|
+
*/
|
|
197
|
+
responseStreaming?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* @generated from field: repeated google.protobuf.Option options = 6;
|
|
200
|
+
*/
|
|
201
|
+
options?: OptionJson[];
|
|
202
|
+
/**
|
|
203
|
+
* @generated from field: google.protobuf.Syntax syntax = 7;
|
|
204
|
+
*/
|
|
205
|
+
syntax?: SyntaxJson;
|
|
206
|
+
};
|
|
141
207
|
/**
|
|
142
208
|
* Describes the message google.protobuf.Method.
|
|
143
|
-
* Use `create(
|
|
209
|
+
* Use `create(MethodSchema)` to create a new message.
|
|
144
210
|
*/
|
|
145
|
-
export declare const
|
|
211
|
+
export declare const MethodSchema: GenDescMessage<Method, MethodJson>;
|
|
146
212
|
/**
|
|
147
213
|
* Declares an API Interface to be included in this interface. The including
|
|
148
214
|
* interface must redeclare all the methods from the included interface, but
|
|
@@ -240,8 +306,21 @@ export type Mixin = Message<"google.protobuf.Mixin"> & {
|
|
|
240
306
|
*/
|
|
241
307
|
root: string;
|
|
242
308
|
};
|
|
309
|
+
/**
|
|
310
|
+
* JSON type for the message google.protobuf.Mixin.
|
|
311
|
+
*/
|
|
312
|
+
export type MixinJson = {
|
|
313
|
+
/**
|
|
314
|
+
* @generated from field: string name = 1;
|
|
315
|
+
*/
|
|
316
|
+
name?: string;
|
|
317
|
+
/**
|
|
318
|
+
* @generated from field: string root = 2;
|
|
319
|
+
*/
|
|
320
|
+
root?: string;
|
|
321
|
+
};
|
|
243
322
|
/**
|
|
244
323
|
* Describes the message google.protobuf.Mixin.
|
|
245
|
-
* Use `create(
|
|
324
|
+
* Use `create(MixinSchema)` to create a new message.
|
|
246
325
|
*/
|
|
247
|
-
export declare const
|
|
326
|
+
export declare const MixinSchema: GenDescMessage<Mixin, MixinJson>;
|
|
@@ -13,7 +13,7 @@
|
|
|
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.MixinSchema = exports.MethodSchema = exports.ApiSchema = exports.file_google_protobuf_api = void 0;
|
|
17
17
|
const file_js_1 = require("../../../../codegenv1/file.js");
|
|
18
18
|
const source_context_pb_js_1 = require("./source_context_pb.js");
|
|
19
19
|
const type_pb_js_1 = require("./type_pb.js");
|
|
@@ -21,19 +21,19 @@ const message_js_1 = require("../../../../codegenv1/message.js");
|
|
|
21
21
|
/**
|
|
22
22
|
* Describes the file google/protobuf/api.proto.
|
|
23
23
|
*/
|
|
24
|
-
exports.
|
|
24
|
+
exports.file_google_protobuf_api = (0, file_js_1.fileDesc)("Chlnb29nbGUvcHJvdG9idWYvYXBpLnByb3RvEg9nb29nbGUucHJvdG9idWYigQIKA0FwaRIMCgRuYW1lGAEgASgJEigKB21ldGhvZHMYAiADKAsyFy5nb29nbGUucHJvdG9idWYuTWV0aG9kEigKB29wdGlvbnMYAyADKAsyFy5nb29nbGUucHJvdG9idWYuT3B0aW9uEg8KB3ZlcnNpb24YBCABKAkSNgoOc291cmNlX2NvbnRleHQYBSABKAsyHi5nb29nbGUucHJvdG9idWYuU291cmNlQ29udGV4dBImCgZtaXhpbnMYBiADKAsyFi5nb29nbGUucHJvdG9idWYuTWl4aW4SJwoGc3ludGF4GAcgASgOMhcuZ29vZ2xlLnByb3RvYnVmLlN5bnRheCLVAQoGTWV0aG9kEgwKBG5hbWUYASABKAkSGAoQcmVxdWVzdF90eXBlX3VybBgCIAEoCRIZChFyZXF1ZXN0X3N0cmVhbWluZxgDIAEoCBIZChFyZXNwb25zZV90eXBlX3VybBgEIAEoCRIaChJyZXNwb25zZV9zdHJlYW1pbmcYBSABKAgSKAoHb3B0aW9ucxgGIAMoCzIXLmdvb2dsZS5wcm90b2J1Zi5PcHRpb24SJwoGc3ludGF4GAcgASgOMhcuZ29vZ2xlLnByb3RvYnVmLlN5bnRheCIjCgVNaXhpbhIMCgRuYW1lGAEgASgJEgwKBHJvb3QYAiABKAlCdgoTY29tLmdvb2dsZS5wcm90b2J1ZkIIQXBpUHJvdG9QAVosZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMva25vd24vYXBpcGKiAgNHUEKqAh5Hb29nbGUuUHJvdG9idWYuV2VsbEtub3duVHlwZXNiBnByb3RvMw", [source_context_pb_js_1.file_google_protobuf_source_context, type_pb_js_1.file_google_protobuf_type]);
|
|
25
25
|
/**
|
|
26
26
|
* Describes the message google.protobuf.Api.
|
|
27
|
-
* Use `create(
|
|
27
|
+
* Use `create(ApiSchema)` to create a new message.
|
|
28
28
|
*/
|
|
29
|
-
exports.
|
|
29
|
+
exports.ApiSchema = (0, message_js_1.messageDesc)(exports.file_google_protobuf_api, 0);
|
|
30
30
|
/**
|
|
31
31
|
* Describes the message google.protobuf.Method.
|
|
32
|
-
* Use `create(
|
|
32
|
+
* Use `create(MethodSchema)` to create a new message.
|
|
33
33
|
*/
|
|
34
|
-
exports.
|
|
34
|
+
exports.MethodSchema = (0, message_js_1.messageDesc)(exports.file_google_protobuf_api, 1);
|
|
35
35
|
/**
|
|
36
36
|
* Describes the message google.protobuf.Mixin.
|
|
37
|
-
* Use `create(
|
|
37
|
+
* Use `create(MixinSchema)` to create a new message.
|
|
38
38
|
*/
|
|
39
|
-
exports.
|
|
39
|
+
exports.MixinSchema = (0, message_js_1.messageDesc)(exports.file_google_protobuf_api, 2);
|