@aptre/protobuf-es-lite 0.4.9 → 0.5.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 +2 -1
- package/dist/create-descriptor-set.js +3 -2
- package/dist/enum.d.ts +1 -1
- package/dist/enum.js +1 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/json.js +2 -1
- package/dist/protoc-gen-es-lite/typescript.js +2 -2
- package/dist/protoplugin/ecmascript/generated-file.d.ts +0 -4
- package/dist/protoplugin/ecmascript/generated-file.js +0 -3
- package/dist/protoplugin/ecmascript/import-path.js +1 -1
- package/dist/util.js +4 -8
- package/example/example.pb.ts +2 -6
- package/example/tsconfig.json +3 -0
- package/package.json +64 -9
- package/tsconfig.base.json +1 -1
- package/tsconfig.json +8 -1
- package/dist/google/index.d.ts +0 -9
- package/dist/google/index.js +0 -9
- package/dist/google/protobuf/any.pb.d.ts +0 -148
- package/dist/google/protobuf/any.pb.js +0 -120
- package/dist/google/protobuf/api.pb.d.ts +0 -232
- package/dist/google/protobuf/api.pb.js +0 -88
- package/dist/google/protobuf/duration.pb.d.ts +0 -93
- package/dist/google/protobuf/duration.pb.js +0 -89
- package/dist/google/protobuf/empty.pb.d.ts +0 -17
- package/dist/google/protobuf/empty.pb.js +0 -37
- package/dist/google/protobuf/source_context.pb.d.ts +0 -18
- package/dist/google/protobuf/source_context.pb.js +0 -39
- package/dist/google/protobuf/struct.pb.d.ts +0 -141
- package/dist/google/protobuf/struct.pb.js +0 -228
- package/dist/google/protobuf/timestamp.pb.d.ts +0 -125
- package/dist/google/protobuf/timestamp.pb.js +0 -137
- package/dist/google/protobuf/type.pb.d.ts +0 -401
- package/dist/google/protobuf/type.pb.js +0 -347
- package/dist/google/protobuf/wrappers.pb.d.ts +0 -201
- package/dist/google/protobuf/wrappers.pb.js +0 -365
package/LICENSE
CHANGED
|
@@ -187,7 +187,8 @@
|
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
|
188
188
|
identification within third-party archives.
|
|
189
189
|
|
|
190
|
-
Copyright 2024 Aperture Robotics, LLC.
|
|
190
|
+
Copyright 2024-2025 Aperture Robotics, LLC.
|
|
191
|
+
Copyright 2024-2025 Christian Stewart <christian@aperture.us>
|
|
191
192
|
Copyright 2021-2024 Buf Technologies, Inc.
|
|
192
193
|
|
|
193
194
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -36,9 +36,10 @@ export function createDescriptorSet(input, options) {
|
|
|
36
36
|
extensions: new Map(),
|
|
37
37
|
mapEntries: new Map(),
|
|
38
38
|
};
|
|
39
|
-
const fileDescriptors = input instanceof Uint8Array ?
|
|
39
|
+
const fileDescriptors = input instanceof Uint8Array ?
|
|
40
|
+
(FileDescriptorSet.fromBinary(input).file ?? [])
|
|
40
41
|
: Array.isArray(input) ? input
|
|
41
|
-
: input.file ?? [];
|
|
42
|
+
: (input.file ?? []);
|
|
42
43
|
const resolverByEdition = new Map();
|
|
43
44
|
for (const proto of fileDescriptors) {
|
|
44
45
|
const edition = proto.edition || parseFileSyntax(proto.syntax, proto.edition).edition;
|
package/dist/enum.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface EnumValueInfo {
|
|
|
37
37
|
/**
|
|
38
38
|
* Create a new EnumType with the given values.
|
|
39
39
|
*/
|
|
40
|
-
export declare function createEnumType(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[]
|
|
40
|
+
export declare function createEnumType(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[]): EnumType;
|
|
41
41
|
export declare function enumInfoZeroValue(values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[]): number;
|
|
42
42
|
export declare function enumDescZeroValue(info: DescEnum): number;
|
|
43
43
|
export declare function enumZeroValue<T extends EnumType>(info: T): number;
|
package/dist/enum.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Create a new EnumType with the given values.
|
|
3
3
|
*/
|
|
4
|
-
export function createEnumType(typeName, values
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
_opt) {
|
|
4
|
+
export function createEnumType(typeName, values) {
|
|
7
5
|
const names = Object.create(null);
|
|
8
6
|
const numbers = Object.create(null);
|
|
9
7
|
const normalValues = [];
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export { int64FromString, int64ToString, uInt64ToString } from "./varint.js";
|
|
|
10
10
|
export { protoInt64 } from "./proto-int64.js";
|
|
11
11
|
export { protoBase64 } from "./proto-base64.js";
|
|
12
12
|
export { protoDouble } from "./proto-double.js";
|
|
13
|
-
export { Timestamp, Duration, Any, Empty, DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue, Value, NullValue, ListValue, Struct, } from "./google/index.js";
|
|
14
13
|
export { DescComments, AnyDesc, DescEnum, DescEnumValue, DescExtension, DescField, DescFile, DescMessage, DescMethod, DescOneof, DescService, DescriptorSet, } from "./descriptor-set.js";
|
|
15
14
|
export { jsonReadEnum, jsonReadField, jsonReadMapKey, jsonReadScalar, jsonReadMessage, jsonWriteEnum, jsonWriteField, jsonWriteScalar, jsonWriteMessage, jsonDebugValue, JsonValue, JsonObject, JsonReadOptions, jsonMakeReadOptions, JsonWriteOptions, JsonWriteStringOptions, jsonMakeWriteOptions, } from "./json.js";
|
|
16
15
|
export { binaryReadField, binaryReadMapEntry, binaryReadScalar, binaryReadScalarLTString, binaryReadMessage, binaryWriteField, binaryWriteScalar, binaryWritePacked, binaryWriteMapEntry, binaryWriteMessage, binaryMakeReadOptions, binaryMakeWriteOptions, BinaryReadOptions, BinaryWriteOptions, } from "./binary.js";
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export { int64FromString, int64ToString, uInt64ToString } from "./varint.js";
|
|
|
10
10
|
export { protoInt64 } from "./proto-int64.js";
|
|
11
11
|
export { protoBase64 } from "./proto-base64.js";
|
|
12
12
|
export { protoDouble } from "./proto-double.js";
|
|
13
|
-
export { Timestamp, Duration, Any, Empty, DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue, Value, NullValue, ListValue, Struct, } from "./google/index.js";
|
|
14
13
|
export { jsonReadEnum, jsonReadField, jsonReadMapKey, jsonReadScalar, jsonReadMessage, jsonWriteEnum, jsonWriteField, jsonWriteScalar, jsonWriteMessage, jsonDebugValue, jsonMakeReadOptions, jsonMakeWriteOptions, } from "./json.js";
|
|
15
14
|
export { binaryReadField, binaryReadMapEntry, binaryReadScalar, binaryReadScalarLTString, binaryReadMessage, binaryWriteField, binaryWriteScalar, binaryWritePacked, binaryWriteMapEntry, binaryWriteMessage, binaryMakeReadOptions, binaryMakeWriteOptions, } from "./binary.js";
|
|
16
15
|
export { compareFieldZeroValue, isMessageZeroValue, getFieldZeroValue, } from "./zero-value.js";
|
package/dist/json.js
CHANGED
|
@@ -383,8 +383,9 @@ function readScalar(type, json, longType = LongType.BIGINT, nullAsZeroValue = tr
|
|
|
383
383
|
// We validate with encodeURIComponent, which appears to be the fastest widely available option.
|
|
384
384
|
try {
|
|
385
385
|
encodeURIComponent(json);
|
|
386
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
386
387
|
}
|
|
387
|
-
catch (
|
|
388
|
+
catch (_e) {
|
|
388
389
|
throw new Error("invalid UTF8");
|
|
389
390
|
}
|
|
390
391
|
return json;
|
|
@@ -328,13 +328,13 @@ function generateWktMethods(schema, f, message, ref) {
|
|
|
328
328
|
f.print(" },");
|
|
329
329
|
f.print();
|
|
330
330
|
f.print(" unpack<T extends Message<T>>(msg: ", message, ", registry: ", IMessageTypeRegistry, "): {message: ", Message, "<T>, messageType: ", MessageType, "<T>} | undefined {");
|
|
331
|
-
f.print(" const typeUrl = msg.", localName(ref.typeUrl)
|
|
331
|
+
f.print(" const typeUrl = msg.", localName(ref.typeUrl), ";");
|
|
332
332
|
f.print(" const messageType = !!typeUrl && registry.findMessage<T>(typeUrl);");
|
|
333
333
|
f.print(" return messageType ? {message: messageType.fromBinary(msg.", localName(ref.value), "), messageType} : undefined;");
|
|
334
334
|
f.print(" },");
|
|
335
335
|
f.print();
|
|
336
336
|
f.print(" is(msg: ", message, ", msgType: ", MessageType, " | string): boolean {");
|
|
337
|
-
f.print(" const name = msg.", localName(ref.typeUrl)
|
|
337
|
+
f.print(" const name = msg.", localName(ref.typeUrl), ";");
|
|
338
338
|
f.print(" return !!name && (typeof msgType === 'string' ? name === msgType : name === msgType.typeName);");
|
|
339
339
|
f.print(" },");
|
|
340
340
|
break;
|
|
@@ -49,10 +49,6 @@ export interface GeneratedFile {
|
|
|
49
49
|
* See print(Printable[]) for behavior when printing Printable items.
|
|
50
50
|
*/
|
|
51
51
|
print(fragments: TemplateStringsArray, ...printables: Printable[]): void;
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated Please use createImportSymbol() from @bufbuild/protoplugin/ecmascript instead
|
|
54
|
-
*/
|
|
55
|
-
export(name: string): ImportSymbol;
|
|
56
52
|
/**
|
|
57
53
|
* Create a string literal.
|
|
58
54
|
*/
|
|
@@ -40,9 +40,6 @@ export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImpo
|
|
|
40
40
|
printableToEl(printables, el, createTypeImport, runtimeImports);
|
|
41
41
|
el.push("\n");
|
|
42
42
|
},
|
|
43
|
-
export(name) {
|
|
44
|
-
return createImportSymbol(name, importPath);
|
|
45
|
-
},
|
|
46
43
|
exportDecl(declaration, name) {
|
|
47
44
|
return {
|
|
48
45
|
kind: "es_export_decl",
|
|
@@ -96,7 +96,7 @@ export function makeImportPath(file, bootstrapWkt, filesToGenerate) {
|
|
|
96
96
|
if (!bootstrapWkt &&
|
|
97
97
|
!filesToGenerate.includes(file) &&
|
|
98
98
|
codegenInfo.wktSourceFiles.includes(file.name + ".proto")) {
|
|
99
|
-
return codegenInfo.packageName;
|
|
99
|
+
return codegenInfo.packageName + "/" + file.name;
|
|
100
100
|
}
|
|
101
101
|
return "./" + file.name + ".pb.js";
|
|
102
102
|
}
|
package/dist/util.js
CHANGED
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
|
-
import { FieldDescriptorProto_Label } from "./google/protobuf/descriptor.pb.js";
|
|
16
15
|
import { codegenInfo } from "./codegen-info.js";
|
|
17
16
|
import { LongType, ScalarType } from "./scalar.js";
|
|
18
17
|
import { localName } from "./names.js";
|
|
19
18
|
// unixMilliToDate converts the unix milliseconds bigint into a Date.
|
|
20
19
|
// Throws an error if the bigint is outside the safe range of Number values.
|
|
21
20
|
export function unixMilliToDate(unixMilliseconds) {
|
|
22
|
-
if (unixMilliseconds < -8640000000000000n ||
|
|
21
|
+
if (unixMilliseconds < -8640000000000000n ||
|
|
22
|
+
unixMilliseconds > 8640000000000000n) {
|
|
23
23
|
throw new Error("Timestamp is outside the range that can be safely represented by a JavaScript Date");
|
|
24
24
|
}
|
|
25
25
|
return new Date(Number(unixMilliseconds));
|
|
@@ -31,9 +31,7 @@ export function getFieldTypeInfo(field) {
|
|
|
31
31
|
switch (field.fieldKind) {
|
|
32
32
|
case "scalar":
|
|
33
33
|
typing.push(scalarTypeScriptType(field.scalar, field.longType));
|
|
34
|
-
optional =
|
|
35
|
-
field.optional ||
|
|
36
|
-
field.proto.label === FieldDescriptorProto_Label.REQUIRED;
|
|
34
|
+
optional = field.optional || field.proto.label === 2; // FieldDescriptorProto_Label.REQUIRED; avoid descriptor.pb.js import
|
|
37
35
|
typingInferrableFromZeroValue = true;
|
|
38
36
|
break;
|
|
39
37
|
case "message": {
|
|
@@ -48,9 +46,7 @@ export function getFieldTypeInfo(field) {
|
|
|
48
46
|
type: field.enum,
|
|
49
47
|
typeOnly: true,
|
|
50
48
|
});
|
|
51
|
-
optional =
|
|
52
|
-
field.optional ||
|
|
53
|
-
field.proto.label === FieldDescriptorProto_Label.REQUIRED;
|
|
49
|
+
optional = field.optional || field.proto.label === 2; // FieldDescriptorProto_Label.REQUIRED; avoid descriptor.pb.js import
|
|
54
50
|
typingInferrableFromZeroValue = true;
|
|
55
51
|
break;
|
|
56
52
|
case "map": {
|
package/example/example.pb.ts
CHANGED
|
@@ -3,12 +3,8 @@
|
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
|
|
5
5
|
import type { MessageType, PartialFieldInfo } from "../src/index.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
createMessageType,
|
|
9
|
-
ScalarType,
|
|
10
|
-
Timestamp,
|
|
11
|
-
} from "../src/index.js";
|
|
6
|
+
import { createEnumType, createMessageType, ScalarType } from "../src/index.js";
|
|
7
|
+
import { Timestamp } from "../src/google/protobuf/timestamp.pb.js";
|
|
12
8
|
|
|
13
9
|
export const protobufPackage = "example";
|
|
14
10
|
|
package/example/tsconfig.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptre/protobuf-es-lite",
|
|
3
3
|
"description": "Lightweight Protobuf codegen for TypeScript and JavaScript.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"
|
|
@@ -23,24 +23,79 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
26
27
|
"import": "./dist/index.js",
|
|
27
|
-
"require": "./dist/index.js"
|
|
28
|
-
|
|
28
|
+
"require": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./descriptor-set": {
|
|
31
|
+
"types": "./dist/descriptor-set.d.ts",
|
|
32
|
+
"import": "./dist/descriptor-set.js",
|
|
33
|
+
"require": "./dist/descriptor-set.js"
|
|
34
|
+
},
|
|
35
|
+
"./create-descriptor-set": {
|
|
36
|
+
"types": "./dist/create-descriptor-set.d.ts",
|
|
37
|
+
"import": "./dist/create-descriptor-set.js",
|
|
38
|
+
"require": "./dist/create-descriptor-set.js"
|
|
29
39
|
},
|
|
30
40
|
"./protoplugin": {
|
|
41
|
+
"types": "./dist/protoplugin/index.d.ts",
|
|
31
42
|
"import": "./dist/protoplugin/index.js",
|
|
32
|
-
"require": "./dist/protoplugin/index.js"
|
|
33
|
-
"types": "./dist/protoplugin/index.d.ts"
|
|
43
|
+
"require": "./dist/protoplugin/index.js"
|
|
34
44
|
},
|
|
35
45
|
"./protoplugin/ecmascript": {
|
|
46
|
+
"types": "./dist/protoplugin/ecmascript/index.d.ts",
|
|
36
47
|
"import": "./dist/protoplugin/ecmascript/index.js",
|
|
37
|
-
"require": "./dist/protoplugin/ecmascript/index.js"
|
|
38
|
-
"types": "./dist/protoplugin/ecmascript/index.d.ts"
|
|
48
|
+
"require": "./dist/protoplugin/ecmascript/index.js"
|
|
39
49
|
},
|
|
40
50
|
"./google": {
|
|
51
|
+
"types": "./dist/google/index.d.ts",
|
|
41
52
|
"import": "./dist/google/index.js",
|
|
42
|
-
"require": "./dist/google/index.js"
|
|
43
|
-
|
|
53
|
+
"require": "./dist/google/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./google/protobuf/type": {
|
|
56
|
+
"types": "./dist/google/protobuf/type.pb.d.ts",
|
|
57
|
+
"import": "./dist/google/protobuf/type.pb.js",
|
|
58
|
+
"require": "./dist/google/protobuf/type.pb.js"
|
|
59
|
+
},
|
|
60
|
+
"./google/protobuf/timestamp": {
|
|
61
|
+
"types": "./dist/google/protobuf/timestamp.pb.d.ts",
|
|
62
|
+
"import": "./dist/google/protobuf/timestamp.pb.js",
|
|
63
|
+
"require": "./dist/google/protobuf/timestamp.pb.js"
|
|
64
|
+
},
|
|
65
|
+
"./google/protobuf/duration": {
|
|
66
|
+
"types": "./dist/google/protobuf/duration.pb.d.ts",
|
|
67
|
+
"import": "./dist/google/protobuf/duration.pb.js",
|
|
68
|
+
"require": "./dist/google/protobuf/duration.pb.js"
|
|
69
|
+
},
|
|
70
|
+
"./google/protobuf/any": {
|
|
71
|
+
"types": "./dist/google/protobuf/any.pb.d.ts",
|
|
72
|
+
"import": "./dist/google/protobuf/any.pb.js",
|
|
73
|
+
"require": "./dist/google/protobuf/any.pb.js"
|
|
74
|
+
},
|
|
75
|
+
"./google/protobuf/empty": {
|
|
76
|
+
"types": "./dist/google/protobuf/empty.pb.d.ts",
|
|
77
|
+
"import": "./dist/google/protobuf/empty.pb.js",
|
|
78
|
+
"require": "./dist/google/protobuf/empty.pb.js"
|
|
79
|
+
},
|
|
80
|
+
"./google/protobuf/wrappers": {
|
|
81
|
+
"types": "./dist/google/protobuf/wrappers.pb.d.ts",
|
|
82
|
+
"import": "./dist/google/protobuf/wrappers.pb.js",
|
|
83
|
+
"require": "./dist/google/protobuf/wrappers.pb.js"
|
|
84
|
+
},
|
|
85
|
+
"./google/protobuf/struct": {
|
|
86
|
+
"types": "./dist/google/protobuf/struct.pb.d.ts",
|
|
87
|
+
"import": "./dist/google/protobuf/struct.pb.js",
|
|
88
|
+
"require": "./dist/google/protobuf/struct.pb.js"
|
|
89
|
+
},
|
|
90
|
+
"./google/protobuf/api": {
|
|
91
|
+
"types": "./dist/google/protobuf/api.pb.d.ts",
|
|
92
|
+
"import": "./dist/google/protobuf/api.pb.js",
|
|
93
|
+
"require": "./dist/google/protobuf/api.pb.js"
|
|
94
|
+
},
|
|
95
|
+
"./google/protobuf/source_context": {
|
|
96
|
+
"types": "./dist/google/protobuf/source_context.pb.d.ts",
|
|
97
|
+
"import": "./dist/google/protobuf/source_context.pb.js",
|
|
98
|
+
"require": "./dist/google/protobuf/source_context.pb.js"
|
|
44
99
|
}
|
|
45
100
|
},
|
|
46
101
|
"engines": {
|
package/tsconfig.base.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"files": [
|
|
2
|
+
"files": [
|
|
3
|
+
"src/protoc-gen-es-lite/protoc-gen-es-lite-plugin.ts",
|
|
4
|
+
"src/index.ts",
|
|
5
|
+
"src/descriptor-set.ts",
|
|
6
|
+
"src/create-descriptor-set.ts",
|
|
7
|
+
"src/protoplugin/index.ts",
|
|
8
|
+
"src/protoplugin/ecmascript/index.ts"
|
|
9
|
+
],
|
|
3
10
|
"extends": "./tsconfig.base.json",
|
|
4
11
|
"compilerOptions": {
|
|
5
12
|
"rootDir": "./src"
|
package/dist/google/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { Type, Field, Field_Kind, Field_Cardinality, Enum, EnumValue, Option, Syntax, } from "./protobuf/type.pb.js";
|
|
2
|
-
export { Timestamp } from "./protobuf/timestamp.pb.js";
|
|
3
|
-
export { Duration } from "./protobuf/duration.pb.js";
|
|
4
|
-
export { Any } from "./protobuf/any.pb.js";
|
|
5
|
-
export { Empty } from "./protobuf/empty.pb.js";
|
|
6
|
-
export { DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue, } from "./protobuf/wrappers.pb.js";
|
|
7
|
-
export { Value, NullValue, ListValue, Struct } from "./protobuf/struct.pb.js";
|
|
8
|
-
export { Api, Method, Mixin } from "./protobuf/api.pb.js";
|
|
9
|
-
export { SourceContext } from "./protobuf/source_context.pb.js";
|
package/dist/google/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { Type, Field, Field_Kind, Field_Cardinality, Enum, EnumValue, Option, Syntax, } from "./protobuf/type.pb.js";
|
|
2
|
-
export { Timestamp } from "./protobuf/timestamp.pb.js";
|
|
3
|
-
export { Duration } from "./protobuf/duration.pb.js";
|
|
4
|
-
export { Any } from "./protobuf/any.pb.js";
|
|
5
|
-
export { Empty } from "./protobuf/empty.pb.js";
|
|
6
|
-
export { DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue, } from "./protobuf/wrappers.pb.js";
|
|
7
|
-
export { Value, NullValue, ListValue, Struct } from "./protobuf/struct.pb.js";
|
|
8
|
-
export { Api, Method, Mixin } from "./protobuf/api.pb.js";
|
|
9
|
-
export { SourceContext } from "./protobuf/source_context.pb.js";
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type { IMessageTypeRegistry, JsonReadOptions, JsonValue, JsonWriteOptions, MessageType } from "../../index.js";
|
|
2
|
-
import { Message } from "../../index.js";
|
|
3
|
-
export declare const protobufPackage = "google.protobuf";
|
|
4
|
-
/**
|
|
5
|
-
* `Any` contains an arbitrary serialized protocol buffer message along with a
|
|
6
|
-
* URL that describes the type of the serialized message.
|
|
7
|
-
*
|
|
8
|
-
* Protobuf library provides support to pack/unpack Any values in the form
|
|
9
|
-
* of utility functions or additional generated methods of the Any type.
|
|
10
|
-
*
|
|
11
|
-
* Example 1: Pack and unpack a message in C++.
|
|
12
|
-
*
|
|
13
|
-
* Foo foo = ...;
|
|
14
|
-
* Any any;
|
|
15
|
-
* any.PackFrom(foo);
|
|
16
|
-
* ...
|
|
17
|
-
* if (any.UnpackTo(&foo)) {
|
|
18
|
-
* ...
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* Example 2: Pack and unpack a message in Java.
|
|
22
|
-
*
|
|
23
|
-
* Foo foo = ...;
|
|
24
|
-
* Any any = Any.pack(foo);
|
|
25
|
-
* ...
|
|
26
|
-
* if (any.is(Foo.class)) {
|
|
27
|
-
* foo = any.unpack(Foo.class);
|
|
28
|
-
* }
|
|
29
|
-
* // or ...
|
|
30
|
-
* if (any.isSameTypeAs(Foo.getDefaultInstance())) {
|
|
31
|
-
* foo = any.unpack(Foo.getDefaultInstance());
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* Example 3: Pack and unpack a message in Python.
|
|
35
|
-
*
|
|
36
|
-
* foo = Foo(...)
|
|
37
|
-
* any = Any()
|
|
38
|
-
* any.Pack(foo)
|
|
39
|
-
* ...
|
|
40
|
-
* if any.Is(Foo.DESCRIPTOR):
|
|
41
|
-
* any.Unpack(foo)
|
|
42
|
-
* ...
|
|
43
|
-
*
|
|
44
|
-
* Example 4: Pack and unpack a message in Go
|
|
45
|
-
*
|
|
46
|
-
* foo := &pb.Foo{...}
|
|
47
|
-
* any, err := anypb.New(foo)
|
|
48
|
-
* if err != nil {
|
|
49
|
-
* ...
|
|
50
|
-
* }
|
|
51
|
-
* ...
|
|
52
|
-
* foo := &pb.Foo{}
|
|
53
|
-
* if err := any.UnmarshalTo(foo); err != nil {
|
|
54
|
-
* ...
|
|
55
|
-
* }
|
|
56
|
-
*
|
|
57
|
-
* The pack methods provided by protobuf library will by default use
|
|
58
|
-
* 'type.googleapis.com/full.type.name' as the type URL and the unpack
|
|
59
|
-
* methods only use the fully qualified type name after the last '/'
|
|
60
|
-
* in the type URL, for example "foo.bar.com/x/y.z" will yield type
|
|
61
|
-
* name "y.z".
|
|
62
|
-
*
|
|
63
|
-
* JSON
|
|
64
|
-
* ====
|
|
65
|
-
* The JSON representation of an `Any` value uses the regular
|
|
66
|
-
* representation of the deserialized, embedded message, with an
|
|
67
|
-
* additional field `@type` which contains the type URL. Example:
|
|
68
|
-
*
|
|
69
|
-
* package google.profile;
|
|
70
|
-
* message Person {
|
|
71
|
-
* string first_name = 1;
|
|
72
|
-
* string last_name = 2;
|
|
73
|
-
* }
|
|
74
|
-
*
|
|
75
|
-
* {
|
|
76
|
-
* "@type": "type.googleapis.com/google.profile.Person",
|
|
77
|
-
* "firstName": <string>,
|
|
78
|
-
* "lastName": <string>
|
|
79
|
-
* }
|
|
80
|
-
*
|
|
81
|
-
* If the embedded message type is well-known and has a custom JSON
|
|
82
|
-
* representation, that representation will be embedded adding a field
|
|
83
|
-
* `value` which holds the custom JSON in addition to the `@type`
|
|
84
|
-
* field. Example (for message [google.protobuf.Duration][]):
|
|
85
|
-
*
|
|
86
|
-
* {
|
|
87
|
-
* "@type": "type.googleapis.com/google.protobuf.Duration",
|
|
88
|
-
* "value": "1.212s"
|
|
89
|
-
* }
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @generated from message google.protobuf.Any
|
|
93
|
-
*/
|
|
94
|
-
export interface Any {
|
|
95
|
-
/**
|
|
96
|
-
* A URL/resource name that uniquely identifies the type of the serialized
|
|
97
|
-
* protocol buffer message. This string must contain at least
|
|
98
|
-
* one "/" character. The last segment of the URL's path must represent
|
|
99
|
-
* the fully qualified name of the type (as in
|
|
100
|
-
* `path/google.protobuf.Duration`). The name should be in a canonical form
|
|
101
|
-
* (e.g., leading "." is not accepted).
|
|
102
|
-
*
|
|
103
|
-
* In practice, teams usually precompile into the binary all types that they
|
|
104
|
-
* expect it to use in the context of Any. However, for URLs which use the
|
|
105
|
-
* scheme `http`, `https`, or no scheme, one can optionally set up a type
|
|
106
|
-
* server that maps type URLs to message definitions as follows:
|
|
107
|
-
*
|
|
108
|
-
* * If no scheme is provided, `https` is assumed.
|
|
109
|
-
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
|
|
110
|
-
* value in binary format, or produce an error.
|
|
111
|
-
* * Applications are allowed to cache lookup results based on the
|
|
112
|
-
* URL, or have them precompiled into a binary to avoid any
|
|
113
|
-
* lookup. Therefore, binary compatibility needs to be preserved
|
|
114
|
-
* on changes to types. (Use versioned type names to manage
|
|
115
|
-
* breaking changes.)
|
|
116
|
-
*
|
|
117
|
-
* Note: this functionality is not currently available in the official
|
|
118
|
-
* protobuf release, and it is not used for type URLs beginning with
|
|
119
|
-
* type.googleapis.com. As of May 2023, there are no widely used type server
|
|
120
|
-
* implementations and no plans to implement one.
|
|
121
|
-
*
|
|
122
|
-
* Schemes other than `http`, `https` (or the empty scheme) might be
|
|
123
|
-
* used with implementation specific semantics.
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @generated from field: string type_url = 1;
|
|
127
|
-
*/
|
|
128
|
-
typeUrl?: string;
|
|
129
|
-
/**
|
|
130
|
-
* Must be a valid serialized protocol buffer of the above specified type.
|
|
131
|
-
*
|
|
132
|
-
* @generated from field: bytes value = 2;
|
|
133
|
-
*/
|
|
134
|
-
value?: Uint8Array;
|
|
135
|
-
}
|
|
136
|
-
declare const Any_Wkt: {
|
|
137
|
-
toJson(msg: Any, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
138
|
-
fromJson(json: JsonValue, options?: Partial<JsonReadOptions>): Any;
|
|
139
|
-
packFrom<T extends Message<T>>(out: Any, message: Message<T>, messageType: MessageType<T>): void;
|
|
140
|
-
unpackTo<T extends Message<T>>(msg: Any, target: Message<T>, targetMessageType: MessageType<T>): boolean;
|
|
141
|
-
unpack<T extends Message<T>>(msg: Any, registry: IMessageTypeRegistry): {
|
|
142
|
-
message: Message<T>;
|
|
143
|
-
messageType: MessageType<T>;
|
|
144
|
-
} | undefined;
|
|
145
|
-
is(msg: Any, msgType: MessageType | string): boolean;
|
|
146
|
-
};
|
|
147
|
-
export declare const Any: MessageType<Any> & typeof Any_Wkt;
|
|
148
|
-
export {};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// Protocol Buffers - Google's data interchange format
|
|
2
|
-
// Copyright 2008 Google Inc. All rights reserved.
|
|
3
|
-
// https://developers.google.com/protocol-buffers/
|
|
4
|
-
//
|
|
5
|
-
// Redistribution and use in source and binary forms, with or without
|
|
6
|
-
// modification, are permitted provided that the following conditions are
|
|
7
|
-
// met:
|
|
8
|
-
//
|
|
9
|
-
// * Redistributions of source code must retain the above copyright
|
|
10
|
-
// notice, this list of conditions and the following disclaimer.
|
|
11
|
-
// * Redistributions in binary form must reproduce the above
|
|
12
|
-
// copyright notice, this list of conditions and the following disclaimer
|
|
13
|
-
// in the documentation and/or other materials provided with the
|
|
14
|
-
// distribution.
|
|
15
|
-
// * Neither the name of Google Inc. nor the names of its
|
|
16
|
-
// contributors may be used to endorse or promote products derived from
|
|
17
|
-
// this software without specific prior written permission.
|
|
18
|
-
//
|
|
19
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
20
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
21
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
22
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
23
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
24
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
25
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
26
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
27
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
-
import { applyPartialMessage, createMessageType, ScalarType, } from "../../index.js";
|
|
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.
|
|
113
|
-
export const Any = createMessageType({
|
|
114
|
-
typeName: "google.protobuf.Any",
|
|
115
|
-
fields: [
|
|
116
|
-
{ no: 1, name: "type_url", kind: "scalar", T: ScalarType.STRING },
|
|
117
|
-
{ no: 2, name: "value", kind: "scalar", T: ScalarType.BYTES },
|
|
118
|
-
],
|
|
119
|
-
packedByDefault: true,
|
|
120
|
-
}, Any_Wkt);
|