@aptre/protobuf-es-lite 0.2.15 → 0.3.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/LICENSE +1 -1
- package/README.md +10 -15
- package/dist/binary.d.ts +13 -10
- package/dist/binary.js +24 -23
- package/dist/codegen-info.d.ts +8 -0
- package/dist/codegen-info.js +12 -4
- package/dist/descriptor-set.d.ts +8 -9
- package/dist/field-wrapper.d.ts +2 -2
- package/dist/google/protobuf/any.pb.d.ts +55 -2
- package/dist/google/protobuf/any.pb.js +85 -4
- package/dist/google/protobuf/api.pb.js +34 -13
- package/dist/google/protobuf/descriptor.pb.js +1045 -161
- package/dist/google/protobuf/duration.pb.d.ts +7 -2
- package/dist/google/protobuf/duration.pb.js +54 -4
- package/dist/google/protobuf/empty.pb.js +1 -0
- package/dist/google/protobuf/source_context.pb.js +3 -2
- package/dist/google/protobuf/struct.pb.d.ts +17 -4
- package/dist/google/protobuf/struct.pb.js +162 -12
- package/dist/google/protobuf/timestamp.pb.d.ts +8 -2
- package/dist/google/protobuf/timestamp.pb.js +68 -4
- package/dist/google/protobuf/type.pb.js +62 -21
- package/dist/google/protobuf/wrappers.pb.d.ts +47 -10
- package/dist/google/protobuf/wrappers.pb.js +280 -19
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -1
- package/dist/json.d.ts +30 -4
- package/dist/json.js +17 -16
- package/dist/message.d.ts +5 -12
- package/dist/message.js +75 -77
- package/dist/protoc-gen-es-lite/typescript.d.ts +2 -2
- package/dist/protoc-gen-es-lite/typescript.js +348 -26
- package/dist/protoplugin/ecmascript/reify-wkt.d.ts +1 -5
- package/dist/protoplugin/ecmascript/reify-wkt.js +0 -10
- package/dist/type-registry.d.ts +43 -0
- package/dist/type-registry.js +14 -0
- package/example/example.pb.ts +56 -32
- package/package.json +3 -1
package/LICENSE
CHANGED
|
@@ -188,7 +188,7 @@
|
|
|
188
188
|
identification within third-party archives.
|
|
189
189
|
|
|
190
190
|
Copyright 2024 Aperture Robotics, LLC.
|
|
191
|
-
Copyright 2021-
|
|
191
|
+
Copyright 2021-2024 Buf Technologies, Inc.
|
|
192
192
|
|
|
193
193
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
194
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
## protobuf-es-lite
|
|
2
2
|
|
|
3
|
-
[![
|
|
4
|
-
|
|
5
|
-
[GoDoc]: https://godoc.org/github.com/aperturerobotics/protobuf-es-lite
|
|
6
|
-
[GoDoc Widget]: https://godoc.org/github.com/aperturerobotics/protobuf-es-lite?status.svg
|
|
7
|
-
[Go Report Card Widget]: https://goreportcard.com/badge/github.com/aperturerobotics/protobuf-es-lite
|
|
8
|
-
[Go Report Card]: https://goreportcard.com/report/github.com/aperturerobotics/protobuf-es-lite
|
|
3
|
+
[](https://www.npmjs.com/package/@aptre/protobuf-es-lite)
|
|
4
|
+
[](https://www.npmjs.com/package/@aptre/protobuf-es-lite)
|
|
9
5
|
|
|
10
6
|
protobuf-es-lite is a TypeScript and JavaScript protobuf implementation.
|
|
11
7
|
|
|
@@ -33,11 +29,12 @@ Lightweight Protobuf 3 RPCs are implemented in [StaRPC] for Go and TypeScript.
|
|
|
33
29
|
|
|
34
30
|
## Purpose
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
[protobuf-es] generates a class for each message with interfaces for partial or
|
|
33
|
+
plain messages. It is significantly easier to construct and pass around plain
|
|
34
|
+
and partial messages as opposed to using classes, and plain messages work better
|
|
35
|
+
when used in React props/state. This ends up looking like:
|
|
36
|
+
|
|
37
|
+
[protobuf-es]: https://github.com/bufbuild/protobuf-es
|
|
41
38
|
|
|
42
39
|
```typescript
|
|
43
40
|
const myMessage: PlainMessage<MyMessage> = {body: "Hello world"}
|
|
@@ -46,12 +43,10 @@ const myMessageBin = new MyMessage(myMessage).toBinary()
|
|
|
46
43
|
|
|
47
44
|
[ts-proto] generates an interface for each protobuf message and a const message
|
|
48
45
|
declaration object containing the marshal and unmarshal functions. This allows
|
|
49
|
-
using interfaces and plain messages everywhere
|
|
46
|
+
using interfaces and plain messages everywhere:
|
|
50
47
|
|
|
51
48
|
[ts-proto]: https://github.com/stephenh/ts-proto
|
|
52
49
|
|
|
53
|
-
This fork generates the ts-proto style with the protoc-gen-es tools:
|
|
54
|
-
|
|
55
50
|
```typescript
|
|
56
51
|
// Create a partial MyMessage with just one field sets.
|
|
57
52
|
const myMessage: MyMessage = {body: "Hello world"}
|
|
@@ -61,7 +56,7 @@ const myCompleteMessage: MyMessage = MyMessage.create(myMessage)
|
|
|
61
56
|
const myMessageBin = MyMessage.toBinary(myCompleteMessage)
|
|
62
57
|
```
|
|
63
58
|
|
|
64
|
-
|
|
59
|
+
This fork generates the ts-proto style with the protobuf-es code generator.
|
|
65
60
|
|
|
66
61
|
## Installation
|
|
67
62
|
|
package/dist/binary.d.ts
CHANGED
|
@@ -33,7 +33,9 @@ export interface BinaryWriteOptions {
|
|
|
33
33
|
*/
|
|
34
34
|
writerFactory: () => IBinaryWriter;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
declare function makeReadOptions(options?: Partial<BinaryReadOptions>): Readonly<BinaryReadOptions>;
|
|
37
|
+
declare function makeWriteOptions(options?: Partial<BinaryWriteOptions>): Readonly<BinaryWriteOptions>;
|
|
38
|
+
declare function readField(target: Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
37
39
|
reader: IBinaryReader, field: FieldInfo, wireType: WireType, options: BinaryReadOptions): void;
|
|
38
40
|
/**
|
|
39
41
|
* AnyMessage is an interface implemented by all messages. If you need to
|
|
@@ -43,19 +45,20 @@ reader: IBinaryReader, field: FieldInfo, wireType: WireType, options: BinaryRead
|
|
|
43
45
|
type AnyMessage = {
|
|
44
46
|
[k: string]: any;
|
|
45
47
|
};
|
|
46
|
-
|
|
48
|
+
declare function readMapEntry(field: FieldInfo & {
|
|
47
49
|
kind: "map";
|
|
48
50
|
}, reader: IBinaryReader, options: BinaryReadOptions): [string | number, ScalarValue | AnyMessage | undefined];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export declare function makeWriteOptions(options?: Partial<BinaryWriteOptions>): Readonly<BinaryWriteOptions>;
|
|
53
|
-
export declare function readMessage<T>(message: T, fields: FieldList, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding?: boolean): void;
|
|
51
|
+
declare function readScalar(reader: IBinaryReader, type: ScalarType): ScalarValue;
|
|
52
|
+
declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): Exclude<ScalarValue, bigint>;
|
|
53
|
+
declare function readMessage<T>(message: T, fields: FieldList, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding?: boolean): void;
|
|
54
54
|
/**
|
|
55
55
|
* Serialize a message to binary data.
|
|
56
56
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
declare function writeMessage<T>(message: T, fields: FieldList, writer: IBinaryWriter, options: BinaryWriteOptions): void;
|
|
58
|
+
declare function writeField<T>(field: FieldInfo, value: T, writer: IBinaryWriter, options: BinaryWriteOptions): void;
|
|
59
|
+
declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: unknown): void;
|
|
60
|
+
declare function writePacked<T>(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: T[]): void;
|
|
61
|
+
declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
59
62
|
kind: "map";
|
|
60
63
|
}, key: string, value: any): void;
|
|
61
|
-
export {};
|
|
64
|
+
export { readField as binaryReadField, readMapEntry as binaryReadMapEntry, readScalar as binaryReadScalar, readScalarLTString as binaryReadScalarLTString, readMessage as binaryReadMessage, writeField as binaryWriteField, writeScalar as binaryWriteScalar, writePacked as binaryWritePacked, writeMapEntry as binaryWriteMapEntry, writeMessage as binaryWriteMessage, makeReadOptions as binaryMakeReadOptions, makeWriteOptions as binaryMakeWriteOptions, };
|
package/dist/binary.js
CHANGED
|
@@ -4,7 +4,23 @@ import { wrapField } from "./field-wrapper.js";
|
|
|
4
4
|
import { LongType, ScalarType, scalarZeroValue, } from "./scalar.js";
|
|
5
5
|
import { assert } from "./assert.js";
|
|
6
6
|
import { BinaryReader, BinaryWriter, WireType, } from "./binary-encoding.js";
|
|
7
|
-
|
|
7
|
+
// Default options for parsing binary data.
|
|
8
|
+
const readDefaults = {
|
|
9
|
+
readUnknownFields: true,
|
|
10
|
+
readerFactory: (bytes) => new BinaryReader(bytes),
|
|
11
|
+
};
|
|
12
|
+
// Default options for serializing binary data.
|
|
13
|
+
const writeDefaults = {
|
|
14
|
+
writeUnknownFields: true,
|
|
15
|
+
writerFactory: () => new BinaryWriter(),
|
|
16
|
+
};
|
|
17
|
+
function makeReadOptions(options) {
|
|
18
|
+
return options ? { ...readDefaults, ...options } : readDefaults;
|
|
19
|
+
}
|
|
20
|
+
function makeWriteOptions(options) {
|
|
21
|
+
return options ? { ...writeDefaults, ...options } : writeDefaults;
|
|
22
|
+
}
|
|
23
|
+
function readField(target, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
8
24
|
reader, field, wireType, options) {
|
|
9
25
|
let { repeated, localName } = field;
|
|
10
26
|
if (field.oneof) {
|
|
@@ -78,7 +94,7 @@ reader, field, wireType, options) {
|
|
|
78
94
|
}
|
|
79
95
|
}
|
|
80
96
|
// Read a map field, expecting key field = 1, value field = 2
|
|
81
|
-
|
|
97
|
+
function readMapEntry(field, reader, options) {
|
|
82
98
|
const length = reader.uint32(), end = reader.pos + length;
|
|
83
99
|
let key, val;
|
|
84
100
|
while (reader.pos < end) {
|
|
@@ -125,7 +141,7 @@ export function readMapEntry(field, reader, options) {
|
|
|
125
141
|
}
|
|
126
142
|
return [key, val];
|
|
127
143
|
}
|
|
128
|
-
|
|
144
|
+
function readScalar(reader, type) {
|
|
129
145
|
switch (type) {
|
|
130
146
|
case ScalarType.STRING:
|
|
131
147
|
return reader.string();
|
|
@@ -161,7 +177,7 @@ export function readScalar(reader, type) {
|
|
|
161
177
|
}
|
|
162
178
|
// Read a scalar value, but return 64 bit integral types (int64, uint64,
|
|
163
179
|
// sint64, fixed64, sfixed64) as string instead of bigint.
|
|
164
|
-
|
|
180
|
+
function readScalarLTString(reader, type) {
|
|
165
181
|
const v = readScalar(reader, type);
|
|
166
182
|
return typeof v == "bigint" ? v.toString() : v;
|
|
167
183
|
}
|
|
@@ -173,23 +189,7 @@ function readMessageField(reader, message, fields, options, field) {
|
|
|
173
189
|
options, delimited);
|
|
174
190
|
return message;
|
|
175
191
|
}
|
|
176
|
-
|
|
177
|
-
const readDefaults = {
|
|
178
|
-
readUnknownFields: true,
|
|
179
|
-
readerFactory: (bytes) => new BinaryReader(bytes),
|
|
180
|
-
};
|
|
181
|
-
// Default options for serializing binary data.
|
|
182
|
-
const writeDefaults = {
|
|
183
|
-
writeUnknownFields: true,
|
|
184
|
-
writerFactory: () => new BinaryWriter(),
|
|
185
|
-
};
|
|
186
|
-
export function makeReadOptions(options) {
|
|
187
|
-
return options ? { ...readDefaults, ...options } : readDefaults;
|
|
188
|
-
}
|
|
189
|
-
export function makeWriteOptions(options) {
|
|
190
|
-
return options ? { ...writeDefaults, ...options } : writeDefaults;
|
|
191
|
-
}
|
|
192
|
-
export function readMessage(message, fields, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) {
|
|
192
|
+
function readMessage(message, fields, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) {
|
|
193
193
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
194
194
|
const end = delimitedMessageEncoding ? reader.len : reader.pos + lengthOrEndTagFieldNo;
|
|
195
195
|
let fieldNo, wireType;
|
|
@@ -216,7 +216,7 @@ export function readMessage(message, fields, reader, lengthOrEndTagFieldNo, opti
|
|
|
216
216
|
/**
|
|
217
217
|
* Serialize a message to binary data.
|
|
218
218
|
*/
|
|
219
|
-
|
|
219
|
+
function writeMessage(message, fields, writer, options) {
|
|
220
220
|
for (const field of fields.byNumber()) {
|
|
221
221
|
if (!isFieldSet(field, message)) {
|
|
222
222
|
if (field.req) {
|
|
@@ -347,7 +347,7 @@ function scalarTypeInfo(type) {
|
|
|
347
347
|
const method = ScalarType[type].toLowerCase();
|
|
348
348
|
return [wireType, method];
|
|
349
349
|
}
|
|
350
|
-
|
|
350
|
+
function writeMapEntry(writer, options, field, key, value) {
|
|
351
351
|
writer.tag(field.no, WireType.LengthDelimited);
|
|
352
352
|
writer.fork();
|
|
353
353
|
// javascript only allows number or string for object properties
|
|
@@ -387,3 +387,4 @@ export function writeMapEntry(writer, options, field, key, value) {
|
|
|
387
387
|
}
|
|
388
388
|
writer.join();
|
|
389
389
|
}
|
|
390
|
+
export { readField as binaryReadField, readMapEntry as binaryReadMapEntry, readScalar as binaryReadScalar, readScalarLTString as binaryReadScalarLTString, readMessage as binaryReadMessage, writeField as binaryWriteField, writeScalar as binaryWriteScalar, writePacked as binaryWritePacked, writeMapEntry as binaryWriteMapEntry, writeMessage as binaryWriteMessage, makeReadOptions as binaryMakeReadOptions, makeWriteOptions as binaryMakeWriteOptions, };
|
package/dist/codegen-info.d.ts
CHANGED
|
@@ -20,16 +20,24 @@ export declare const codegenInfo: {
|
|
|
20
20
|
readonly PartialFieldInfo: RuntimeSymbolInfo;
|
|
21
21
|
readonly MessageType: RuntimeSymbolInfo;
|
|
22
22
|
readonly Extension: RuntimeSymbolInfo;
|
|
23
|
+
readonly IMessageTypeRegistry: RuntimeSymbolInfo;
|
|
23
24
|
readonly BinaryReadOptions: RuntimeSymbolInfo;
|
|
24
25
|
readonly BinaryWriteOptions: RuntimeSymbolInfo;
|
|
25
26
|
readonly JsonReadOptions: RuntimeSymbolInfo;
|
|
26
27
|
readonly JsonWriteOptions: RuntimeSymbolInfo;
|
|
27
28
|
readonly JsonValue: RuntimeSymbolInfo;
|
|
28
29
|
readonly JsonObject: RuntimeSymbolInfo;
|
|
30
|
+
readonly jsonReadEnum: RuntimeSymbolInfo;
|
|
31
|
+
readonly jsonReadScalar: RuntimeSymbolInfo;
|
|
32
|
+
readonly jsonWriteEnum: RuntimeSymbolInfo;
|
|
33
|
+
readonly jsonWriteScalar: RuntimeSymbolInfo;
|
|
34
|
+
readonly jsonDebugValue: RuntimeSymbolInfo;
|
|
29
35
|
readonly protoDouble: RuntimeSymbolInfo;
|
|
30
36
|
readonly protoInt64: RuntimeSymbolInfo;
|
|
37
|
+
readonly applyPartialMessage: RuntimeSymbolInfo;
|
|
31
38
|
readonly ScalarType: RuntimeSymbolInfo;
|
|
32
39
|
readonly LongType: RuntimeSymbolInfo;
|
|
40
|
+
readonly ScalarValue: RuntimeSymbolInfo;
|
|
33
41
|
readonly MethodKind: RuntimeSymbolInfo;
|
|
34
42
|
readonly MethodIdempotency: RuntimeSymbolInfo;
|
|
35
43
|
readonly createEnumType: RuntimeSymbolInfo;
|
package/dist/codegen-info.js
CHANGED
|
@@ -27,16 +27,24 @@ const symbols = {
|
|
|
27
27
|
PartialFieldInfo: symbolInfo(true, "./field.js"),
|
|
28
28
|
MessageType: symbolInfo(true, "./message-type.js"),
|
|
29
29
|
Extension: symbolInfo(true, "./extension.js"),
|
|
30
|
+
IMessageTypeRegistry: symbolInfo(true, "./type-registry.js"),
|
|
30
31
|
BinaryReadOptions: symbolInfo(true, "./binary-format.js"),
|
|
31
32
|
BinaryWriteOptions: symbolInfo(true, "./binary-format.js"),
|
|
32
|
-
JsonReadOptions: symbolInfo(true, "./json
|
|
33
|
-
JsonWriteOptions: symbolInfo(true, "./json
|
|
34
|
-
JsonValue: symbolInfo(true, "./json
|
|
35
|
-
JsonObject: symbolInfo(true, "./json
|
|
33
|
+
JsonReadOptions: symbolInfo(true, "./json.js"),
|
|
34
|
+
JsonWriteOptions: symbolInfo(true, "./json.js"),
|
|
35
|
+
JsonValue: symbolInfo(true, "./json.js"),
|
|
36
|
+
JsonObject: symbolInfo(true, "./json.js"),
|
|
37
|
+
jsonReadEnum: symbolInfo(false, "./json.js"),
|
|
38
|
+
jsonReadScalar: symbolInfo(false, "./json.js"),
|
|
39
|
+
jsonWriteEnum: symbolInfo(false, "./json.js"),
|
|
40
|
+
jsonWriteScalar: symbolInfo(false, "./json.js"),
|
|
41
|
+
jsonDebugValue: symbolInfo(false, "./json.js"),
|
|
36
42
|
protoDouble: symbolInfo(false, "./proto-double.js"),
|
|
37
43
|
protoInt64: symbolInfo(false, "./proto-int64.js"),
|
|
44
|
+
applyPartialMessage: symbolInfo(false, "./partial.js"),
|
|
38
45
|
ScalarType: symbolInfo(false, "./scalar.js"),
|
|
39
46
|
LongType: symbolInfo(false, "./scalar.js"),
|
|
47
|
+
ScalarValue: symbolInfo(false, "./scalar.js"),
|
|
40
48
|
MethodKind: symbolInfo(false, "./service-type.js"),
|
|
41
49
|
MethodIdempotency: symbolInfo(false, "./service-type.js"),
|
|
42
50
|
createEnumType: symbolInfo(false, "./enum.js"),
|
package/dist/descriptor-set.d.ts
CHANGED
|
@@ -294,7 +294,7 @@ export type DescExtension = DescFieldCommon & (DescFieldScalar | DescFieldMessag
|
|
|
294
294
|
*/
|
|
295
295
|
readonly extendee: DescMessage;
|
|
296
296
|
};
|
|
297
|
-
interface DescFieldCommon {
|
|
297
|
+
export interface DescFieldCommon {
|
|
298
298
|
/**
|
|
299
299
|
* The field name, as specified in the protobuf source
|
|
300
300
|
*/
|
|
@@ -354,7 +354,7 @@ interface DescFieldCommon {
|
|
|
354
354
|
getFeatures(): MergedFeatureSet;
|
|
355
355
|
toString(): string;
|
|
356
356
|
}
|
|
357
|
-
interface DescFieldScalar {
|
|
357
|
+
export interface DescFieldScalar {
|
|
358
358
|
readonly fieldKind: "scalar";
|
|
359
359
|
/**
|
|
360
360
|
* Is the field repeated?
|
|
@@ -391,7 +391,7 @@ interface DescFieldScalar {
|
|
|
391
391
|
*/
|
|
392
392
|
getDefaultValue(): number | boolean | string | bigint | Uint8Array | undefined;
|
|
393
393
|
}
|
|
394
|
-
interface DescFieldMessage {
|
|
394
|
+
export interface DescFieldMessage {
|
|
395
395
|
readonly fieldKind: "message";
|
|
396
396
|
/**
|
|
397
397
|
* Is the field repeated?
|
|
@@ -423,7 +423,7 @@ interface DescFieldMessage {
|
|
|
423
423
|
*/
|
|
424
424
|
readonly mapValue: undefined;
|
|
425
425
|
}
|
|
426
|
-
interface DescFieldEnum {
|
|
426
|
+
export interface DescFieldEnum {
|
|
427
427
|
readonly fieldKind: "enum";
|
|
428
428
|
/**
|
|
429
429
|
* Is the field repeated?
|
|
@@ -460,7 +460,7 @@ interface DescFieldEnum {
|
|
|
460
460
|
*/
|
|
461
461
|
getDefaultValue(): number | boolean | string | bigint | Uint8Array | undefined;
|
|
462
462
|
}
|
|
463
|
-
interface DescFieldMap {
|
|
463
|
+
export interface DescFieldMap {
|
|
464
464
|
readonly fieldKind: "map";
|
|
465
465
|
/**
|
|
466
466
|
* Is the field repeated?
|
|
@@ -492,7 +492,7 @@ interface DescFieldMap {
|
|
|
492
492
|
*/
|
|
493
493
|
readonly mapValue: DescFieldMapValueEnum | DescFieldMapValueMessage | DescFieldMapValueScalar;
|
|
494
494
|
}
|
|
495
|
-
interface DescFieldMapValueEnum {
|
|
495
|
+
export interface DescFieldMapValueEnum {
|
|
496
496
|
readonly kind: "enum";
|
|
497
497
|
/**
|
|
498
498
|
* The enum type, if this is a map field with enum values.
|
|
@@ -507,7 +507,7 @@ interface DescFieldMapValueEnum {
|
|
|
507
507
|
*/
|
|
508
508
|
readonly scalar: undefined;
|
|
509
509
|
}
|
|
510
|
-
interface DescFieldMapValueMessage {
|
|
510
|
+
export interface DescFieldMapValueMessage {
|
|
511
511
|
readonly kind: "message";
|
|
512
512
|
/**
|
|
513
513
|
* The enum type, if this is a map field with enum values.
|
|
@@ -522,7 +522,7 @@ interface DescFieldMapValueMessage {
|
|
|
522
522
|
*/
|
|
523
523
|
readonly scalar: undefined;
|
|
524
524
|
}
|
|
525
|
-
interface DescFieldMapValueScalar {
|
|
525
|
+
export interface DescFieldMapValueScalar {
|
|
526
526
|
readonly kind: "scalar";
|
|
527
527
|
/**
|
|
528
528
|
* The enum type, if this is a map field with enum values.
|
|
@@ -669,4 +669,3 @@ export interface DescComments {
|
|
|
669
669
|
readonly trailing?: string;
|
|
670
670
|
readonly sourcePath: readonly number[];
|
|
671
671
|
}
|
|
672
|
-
export {};
|
package/dist/field-wrapper.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { ScalarType } from "./scalar.js";
|
|
|
5
5
|
* ergonomic for use as a message field.
|
|
6
6
|
*/
|
|
7
7
|
export interface FieldWrapper<T = any, U = any> {
|
|
8
|
-
wrapField(value: U): T;
|
|
9
|
-
unwrapField(value: T): U;
|
|
8
|
+
wrapField(value: U | null | undefined): T;
|
|
9
|
+
unwrapField(value: T): U | null | undefined;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Wrap a primitive message field value in its corresponding wrapper
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MessageType } from "../../index.js";
|
|
1
|
+
import type { IMessageTypeRegistry, JsonReadOptions, JsonValue, JsonWriteOptions, MessageType } from "../../index.js";
|
|
2
2
|
import { Message } from "../../index.js";
|
|
3
3
|
export declare const protobufPackage = "google.protobuf";
|
|
4
4
|
/**
|
|
@@ -133,4 +133,57 @@ export type Any = Message<{
|
|
|
133
133
|
*/
|
|
134
134
|
value?: Uint8Array;
|
|
135
135
|
}>;
|
|
136
|
-
|
|
136
|
+
declare const Any_Wkt: {
|
|
137
|
+
toJson(msg: Any, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
138
|
+
fromJson(json: JsonValue, options?: Partial<JsonReadOptions>): Message<{
|
|
139
|
+
/**
|
|
140
|
+
* A URL/resource name that uniquely identifies the type of the serialized
|
|
141
|
+
* protocol buffer message. This string must contain at least
|
|
142
|
+
* one "/" character. The last segment of the URL's path must represent
|
|
143
|
+
* the fully qualified name of the type (as in
|
|
144
|
+
* `path/google.protobuf.Duration`). The name should be in a canonical form
|
|
145
|
+
* (e.g., leading "." is not accepted).
|
|
146
|
+
*
|
|
147
|
+
* In practice, teams usually precompile into the binary all types that they
|
|
148
|
+
* expect it to use in the context of Any. However, for URLs which use the
|
|
149
|
+
* scheme `http`, `https`, or no scheme, one can optionally set up a type
|
|
150
|
+
* server that maps type URLs to message definitions as follows:
|
|
151
|
+
*
|
|
152
|
+
* * If no scheme is provided, `https` is assumed.
|
|
153
|
+
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
|
|
154
|
+
* value in binary format, or produce an error.
|
|
155
|
+
* * Applications are allowed to cache lookup results based on the
|
|
156
|
+
* URL, or have them precompiled into a binary to avoid any
|
|
157
|
+
* lookup. Therefore, binary compatibility needs to be preserved
|
|
158
|
+
* on changes to types. (Use versioned type names to manage
|
|
159
|
+
* breaking changes.)
|
|
160
|
+
*
|
|
161
|
+
* Note: this functionality is not currently available in the official
|
|
162
|
+
* protobuf release, and it is not used for type URLs beginning with
|
|
163
|
+
* type.googleapis.com. As of May 2023, there are no widely used type server
|
|
164
|
+
* implementations and no plans to implement one.
|
|
165
|
+
*
|
|
166
|
+
* Schemes other than `http`, `https` (or the empty scheme) might be
|
|
167
|
+
* used with implementation specific semantics.
|
|
168
|
+
*
|
|
169
|
+
*
|
|
170
|
+
* @generated from field: string type_url = 1;
|
|
171
|
+
*/
|
|
172
|
+
typeUrl?: string | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Must be a valid serialized protocol buffer of the above specified type.
|
|
175
|
+
*
|
|
176
|
+
* @generated from field: bytes value = 2;
|
|
177
|
+
*/
|
|
178
|
+
value?: Uint8Array | undefined;
|
|
179
|
+
}>;
|
|
180
|
+
packFrom<T extends Message<T>>(out: Any, message: Message<T>, messageType: MessageType<T>): void;
|
|
181
|
+
unpackTo<T_1 extends Message<T_1>>(msg: Any, target: Message<T_1>, targetMessageType: MessageType<T_1>): boolean;
|
|
182
|
+
unpack<T_2 extends Message<T_2>>(msg: Any, registry: IMessageTypeRegistry): {
|
|
183
|
+
message: Message<T_2>;
|
|
184
|
+
messageType: MessageType<T_2>;
|
|
185
|
+
} | undefined;
|
|
186
|
+
is(msg: Any, msgType: MessageType | string): boolean;
|
|
187
|
+
};
|
|
188
|
+
export declare const Any: MessageType<Any> & typeof Any_Wkt;
|
|
189
|
+
export {};
|
|
@@ -27,13 +27,94 @@
|
|
|
27
27
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
28
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
29
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
-
import { createMessageType } from "../../index.js";
|
|
30
|
+
import { applyPartialMessage, createMessageType, ScalarType, } from "../../index.js";
|
|
31
31
|
export const protobufPackage = "google.protobuf";
|
|
32
|
+
// Any_Wkt contains the well-known-type overrides for Any.
|
|
33
|
+
const Any_Wkt = {
|
|
34
|
+
toJson(msg, options) {
|
|
35
|
+
const typeName = msg?.typeUrl;
|
|
36
|
+
if (!typeName) {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
const messageType = options?.typeRegistry?.findMessage(typeName);
|
|
40
|
+
if (!messageType) {
|
|
41
|
+
throw new Error(`cannot encode message google.protobuf.Any to JSON: "${typeName}" is not in the type registry`);
|
|
42
|
+
}
|
|
43
|
+
const message = messageType.fromBinary(msg.value);
|
|
44
|
+
let json = messageType.toJson(message, options);
|
|
45
|
+
if (typeName.startsWith("google.protobuf.") ||
|
|
46
|
+
json === null ||
|
|
47
|
+
Array.isArray(json) ||
|
|
48
|
+
typeof json !== "object") {
|
|
49
|
+
json = { value: json };
|
|
50
|
+
}
|
|
51
|
+
json["@type"] = typeName;
|
|
52
|
+
return json;
|
|
53
|
+
},
|
|
54
|
+
fromJson(json, options) {
|
|
55
|
+
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
56
|
+
throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null"
|
|
57
|
+
: Array.isArray(json) ? "array"
|
|
58
|
+
: typeof json}`);
|
|
59
|
+
}
|
|
60
|
+
if (Object.keys(json).length == 0) {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
const typeUrl = json["@type"];
|
|
64
|
+
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
65
|
+
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
66
|
+
}
|
|
67
|
+
const typeName = typeUrl, messageType = options?.typeRegistry?.findMessage(typeName);
|
|
68
|
+
if (!messageType) {
|
|
69
|
+
throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
|
|
70
|
+
}
|
|
71
|
+
let message;
|
|
72
|
+
if (typeName.startsWith("google.protobuf.") &&
|
|
73
|
+
Object.prototype.hasOwnProperty.call(json, "value")) {
|
|
74
|
+
message = messageType.fromJson(json["value"], options);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const copy = Object.assign({}, json);
|
|
78
|
+
delete copy["@type"];
|
|
79
|
+
message = messageType.fromJson(copy, options);
|
|
80
|
+
}
|
|
81
|
+
const out = {};
|
|
82
|
+
Any.packFrom(out, message, messageType);
|
|
83
|
+
return out;
|
|
84
|
+
},
|
|
85
|
+
packFrom(out, message, messageType) {
|
|
86
|
+
out.value = messageType.toBinary(message);
|
|
87
|
+
out.typeUrl = messageType.typeName;
|
|
88
|
+
},
|
|
89
|
+
unpackTo(msg, target, targetMessageType) {
|
|
90
|
+
if (!Any.is(msg, targetMessageType)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const partial = targetMessageType.fromBinary(msg.value);
|
|
94
|
+
applyPartialMessage(partial, target, targetMessageType.fields);
|
|
95
|
+
return true;
|
|
96
|
+
},
|
|
97
|
+
unpack(msg, registry) {
|
|
98
|
+
const typeUrl = msg.typeUrl;
|
|
99
|
+
const messageType = !!typeUrl && registry.findMessage(typeUrl);
|
|
100
|
+
return messageType ?
|
|
101
|
+
{ message: messageType.fromBinary(msg.value), messageType }
|
|
102
|
+
: undefined;
|
|
103
|
+
},
|
|
104
|
+
is(msg, msgType) {
|
|
105
|
+
const name = msg.typeUrl;
|
|
106
|
+
return (!!name &&
|
|
107
|
+
(typeof msgType === "string" ?
|
|
108
|
+
name === msgType
|
|
109
|
+
: name === msgType.typeName));
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
// Any contains the message type declaration for Any.
|
|
32
113
|
export const Any = createMessageType({
|
|
33
114
|
typeName: "google.protobuf.Any",
|
|
34
115
|
fields: [
|
|
35
|
-
{ no: 1, name: "type_url", kind: "scalar", T:
|
|
36
|
-
{ no: 2, name: "value", kind: "scalar", T:
|
|
116
|
+
{ no: 1, name: "type_url", kind: "scalar", T: ScalarType.STRING },
|
|
117
|
+
{ no: 2, name: "value", kind: "scalar", T: ScalarType.BYTES },
|
|
37
118
|
],
|
|
38
119
|
packedByDefault: true,
|
|
39
|
-
});
|
|
120
|
+
}, Any_Wkt);
|
|
@@ -27,38 +27,59 @@
|
|
|
27
27
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
28
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
29
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
-
import { createMessageType } from "../../index.js";
|
|
30
|
+
import { createMessageType, ScalarType } from "../../index.js";
|
|
31
31
|
import { Option, Syntax_Enum } from "./type.pb.js";
|
|
32
32
|
import { SourceContext } from "./source_context.pb.js";
|
|
33
33
|
export const protobufPackage = "google.protobuf";
|
|
34
|
+
// Method contains the message type declaration for Method.
|
|
34
35
|
export const Method = createMessageType({
|
|
35
36
|
typeName: "google.protobuf.Method",
|
|
36
37
|
fields: [
|
|
37
|
-
{ no: 1, name: "name", kind: "scalar", T:
|
|
38
|
-
{ no: 2, name: "request_type_url", kind: "scalar", T:
|
|
39
|
-
{ no: 3, name: "request_streaming", kind: "scalar", T:
|
|
40
|
-
{ no: 4, name: "response_type_url", kind: "scalar", T:
|
|
41
|
-
{ no: 5, name: "response_streaming", kind: "scalar", T:
|
|
42
|
-
{
|
|
38
|
+
{ no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
39
|
+
{ no: 2, name: "request_type_url", kind: "scalar", T: ScalarType.STRING },
|
|
40
|
+
{ no: 3, name: "request_streaming", kind: "scalar", T: ScalarType.BOOL },
|
|
41
|
+
{ no: 4, name: "response_type_url", kind: "scalar", T: ScalarType.STRING },
|
|
42
|
+
{ no: 5, name: "response_streaming", kind: "scalar", T: ScalarType.BOOL },
|
|
43
|
+
{
|
|
44
|
+
no: 6,
|
|
45
|
+
name: "options",
|
|
46
|
+
kind: "message",
|
|
47
|
+
T: () => Option,
|
|
48
|
+
repeated: true,
|
|
49
|
+
},
|
|
43
50
|
{ no: 7, name: "syntax", kind: "enum", T: Syntax_Enum },
|
|
44
51
|
],
|
|
45
52
|
packedByDefault: true,
|
|
46
53
|
});
|
|
54
|
+
// Mixin contains the message type declaration for Mixin.
|
|
47
55
|
export const Mixin = createMessageType({
|
|
48
56
|
typeName: "google.protobuf.Mixin",
|
|
49
57
|
fields: [
|
|
50
|
-
{ no: 1, name: "name", kind: "scalar", T:
|
|
51
|
-
{ no: 2, name: "root", kind: "scalar", T:
|
|
58
|
+
{ no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
59
|
+
{ no: 2, name: "root", kind: "scalar", T: ScalarType.STRING },
|
|
52
60
|
],
|
|
53
61
|
packedByDefault: true,
|
|
54
62
|
});
|
|
63
|
+
// Api contains the message type declaration for Api.
|
|
55
64
|
export const Api = createMessageType({
|
|
56
65
|
typeName: "google.protobuf.Api",
|
|
57
66
|
fields: [
|
|
58
|
-
{ no: 1, name: "name", kind: "scalar", T:
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
{ no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
68
|
+
{
|
|
69
|
+
no: 2,
|
|
70
|
+
name: "methods",
|
|
71
|
+
kind: "message",
|
|
72
|
+
T: () => Method,
|
|
73
|
+
repeated: true,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
no: 3,
|
|
77
|
+
name: "options",
|
|
78
|
+
kind: "message",
|
|
79
|
+
T: () => Option,
|
|
80
|
+
repeated: true,
|
|
81
|
+
},
|
|
82
|
+
{ no: 4, name: "version", kind: "scalar", T: ScalarType.STRING },
|
|
62
83
|
{ no: 5, name: "source_context", kind: "message", T: () => SourceContext },
|
|
63
84
|
{ no: 6, name: "mixins", kind: "message", T: () => Mixin, repeated: true },
|
|
64
85
|
{ no: 7, name: "syntax", kind: "enum", T: Syntax_Enum },
|