@bufbuild/protobuf 0.2.0 → 0.2.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/codegen-info.js +2 -0
- package/dist/cjs/google/protobuf/any_pb.js +3 -0
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/private/reify-wkt.js +170 -0
- package/dist/esm/codegen-info.js +2 -0
- package/dist/esm/google/protobuf/any_pb.js +3 -0
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/private/reify-wkt.js +166 -0
- package/dist/types/codegen-info.d.ts +2 -0
- package/dist/types/private/reify-wkt.d.ts +100 -0
- package/package.json +1 -1
package/dist/cjs/codegen-info.js
CHANGED
|
@@ -17,10 +17,12 @@ exports.codegenInfo = void 0;
|
|
|
17
17
|
const names_js_1 = require("./private/names.js");
|
|
18
18
|
const field_wrapper_js_1 = require("./private/field-wrapper.js");
|
|
19
19
|
const scalars_js_1 = require("./private/scalars.js");
|
|
20
|
+
const reify_wkt_js_1 = require("./private/reify-wkt.js");
|
|
20
21
|
const packageName = "@bufbuild/protobuf";
|
|
21
22
|
exports.codegenInfo = {
|
|
22
23
|
packageName,
|
|
23
24
|
localName: names_js_1.localName,
|
|
25
|
+
reifyWkt: reify_wkt_js_1.reifyWkt,
|
|
24
26
|
getUnwrappedFieldType: field_wrapper_js_1.getUnwrappedFieldType,
|
|
25
27
|
scalarDefaultValue: scalars_js_1.scalarDefaultValue,
|
|
26
28
|
// prettier-ignore
|
|
@@ -170,6 +170,9 @@ class Any extends message_js_1.Message {
|
|
|
170
170
|
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
171
171
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
|
|
172
172
|
}
|
|
173
|
+
if (Object.keys(json).length == 0) {
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
173
176
|
const typeUrl = json["@type"];
|
|
174
177
|
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
175
178
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v0.2.
|
|
17
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v0.2.
|
|
17
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.reifyWkt = void 0;
|
|
17
|
+
const field_js_1 = require("../field.js");
|
|
18
|
+
/**
|
|
19
|
+
* Reifies a given DescMessage into a more concrete object representing its
|
|
20
|
+
* respective well-known type. The returned object will contain properties
|
|
21
|
+
* representing the WKT's defined fields.
|
|
22
|
+
*
|
|
23
|
+
* Useful during code generation when immediate access to a particular field
|
|
24
|
+
* is needed without having to search the object's typename and DescField list.
|
|
25
|
+
*
|
|
26
|
+
* Returns undefined if the WKT cannot be completely constructed via the
|
|
27
|
+
* DescMessage.
|
|
28
|
+
*/
|
|
29
|
+
function reifyWkt(message) {
|
|
30
|
+
switch (message.typeName) {
|
|
31
|
+
case "google.protobuf.Any": {
|
|
32
|
+
const typeUrl = message.fields.find((f) => f.number == 1 &&
|
|
33
|
+
f.fieldKind == "scalar" &&
|
|
34
|
+
f.scalar === field_js_1.ScalarType.STRING);
|
|
35
|
+
const value = message.fields.find((f) => f.number == 2 &&
|
|
36
|
+
f.fieldKind == "scalar" &&
|
|
37
|
+
f.scalar === field_js_1.ScalarType.BYTES);
|
|
38
|
+
if (typeUrl && value) {
|
|
39
|
+
return {
|
|
40
|
+
typeName: message.typeName,
|
|
41
|
+
typeUrl,
|
|
42
|
+
value,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "google.protobuf.Timestamp": {
|
|
48
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
49
|
+
f.fieldKind == "scalar" &&
|
|
50
|
+
f.scalar === field_js_1.ScalarType.INT64);
|
|
51
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
52
|
+
f.fieldKind == "scalar" &&
|
|
53
|
+
f.scalar === field_js_1.ScalarType.INT32);
|
|
54
|
+
if (seconds && nanos) {
|
|
55
|
+
return {
|
|
56
|
+
typeName: message.typeName,
|
|
57
|
+
seconds,
|
|
58
|
+
nanos,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case "google.protobuf.Duration": {
|
|
64
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
65
|
+
f.fieldKind == "scalar" &&
|
|
66
|
+
f.scalar === field_js_1.ScalarType.INT64);
|
|
67
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
68
|
+
f.fieldKind == "scalar" &&
|
|
69
|
+
f.scalar === field_js_1.ScalarType.INT32);
|
|
70
|
+
if (seconds && nanos) {
|
|
71
|
+
return {
|
|
72
|
+
typeName: message.typeName,
|
|
73
|
+
seconds,
|
|
74
|
+
nanos,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "google.protobuf.Struct": {
|
|
80
|
+
const fields = message.fields.find((f) => f.number == 1 && !f.repeated);
|
|
81
|
+
if ((fields === null || fields === void 0 ? void 0 : fields.fieldKind) !== "map" ||
|
|
82
|
+
fields.mapValue.kind !== "message" ||
|
|
83
|
+
fields.mapValue.message.typeName !== "google.protobuf.Value") {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return { typeName: message.typeName, fields };
|
|
87
|
+
}
|
|
88
|
+
case "google.protobuf.Value": {
|
|
89
|
+
const kind = message.oneofs.find((o) => o.name === "kind");
|
|
90
|
+
const nullValue = message.fields.find((f) => f.number == 1 && f.oneof === kind);
|
|
91
|
+
if ((nullValue === null || nullValue === void 0 ? void 0 : nullValue.fieldKind) !== "enum" ||
|
|
92
|
+
nullValue.enum.typeName !== "google.protobuf.NullValue") {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const numberValue = message.fields.find((f) => f.number == 2 &&
|
|
96
|
+
f.fieldKind == "scalar" &&
|
|
97
|
+
f.scalar === field_js_1.ScalarType.DOUBLE &&
|
|
98
|
+
f.oneof === kind);
|
|
99
|
+
const stringValue = message.fields.find((f) => f.number == 3 &&
|
|
100
|
+
f.fieldKind == "scalar" &&
|
|
101
|
+
f.scalar === field_js_1.ScalarType.STRING &&
|
|
102
|
+
f.oneof === kind);
|
|
103
|
+
const boolValue = message.fields.find((f) => f.number == 4 &&
|
|
104
|
+
f.fieldKind == "scalar" &&
|
|
105
|
+
f.scalar === field_js_1.ScalarType.BOOL &&
|
|
106
|
+
f.oneof === kind);
|
|
107
|
+
const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
|
|
108
|
+
if ((structValue === null || structValue === void 0 ? void 0 : structValue.fieldKind) !== "message" ||
|
|
109
|
+
structValue.message.typeName !== "google.protobuf.Struct") {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const listValue = message.fields.find((f) => f.number == 6 && f.oneof === kind);
|
|
113
|
+
if ((listValue === null || listValue === void 0 ? void 0 : listValue.fieldKind) !== "message" ||
|
|
114
|
+
listValue.message.typeName !== "google.protobuf.ListValue") {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
if (kind && numberValue && stringValue && boolValue) {
|
|
118
|
+
return {
|
|
119
|
+
typeName: message.typeName,
|
|
120
|
+
kind,
|
|
121
|
+
nullValue,
|
|
122
|
+
numberValue,
|
|
123
|
+
stringValue,
|
|
124
|
+
boolValue,
|
|
125
|
+
structValue,
|
|
126
|
+
listValue,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "google.protobuf.ListValue": {
|
|
132
|
+
const values = message.fields.find((f) => f.number == 1 && f.repeated);
|
|
133
|
+
if ((values === null || values === void 0 ? void 0 : values.fieldKind) != "message" ||
|
|
134
|
+
values.message.typeName !== "google.protobuf.Value") {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
return { typeName: message.typeName, values };
|
|
138
|
+
}
|
|
139
|
+
case "google.protobuf.FieldMask": {
|
|
140
|
+
const paths = message.fields.find((f) => f.number == 1 &&
|
|
141
|
+
f.fieldKind == "scalar" &&
|
|
142
|
+
f.scalar === field_js_1.ScalarType.STRING &&
|
|
143
|
+
f.repeated);
|
|
144
|
+
if (paths) {
|
|
145
|
+
return { typeName: message.typeName, paths };
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "google.protobuf.DoubleValue":
|
|
150
|
+
case "google.protobuf.FloatValue":
|
|
151
|
+
case "google.protobuf.Int64Value":
|
|
152
|
+
case "google.protobuf.UInt64Value":
|
|
153
|
+
case "google.protobuf.Int32Value":
|
|
154
|
+
case "google.protobuf.UInt32Value":
|
|
155
|
+
case "google.protobuf.BoolValue":
|
|
156
|
+
case "google.protobuf.StringValue":
|
|
157
|
+
case "google.protobuf.BytesValue": {
|
|
158
|
+
const value = message.fields.find((f) => f.number == 1 && f.name == "value");
|
|
159
|
+
if (!value) {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (value.fieldKind !== "scalar") {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
return { typeName: message.typeName, value };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
exports.reifyWkt = reifyWkt;
|
package/dist/esm/codegen-info.js
CHANGED
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
import { localName } from "./private/names.js";
|
|
15
15
|
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
|
|
16
16
|
import { scalarDefaultValue } from "./private/scalars.js";
|
|
17
|
+
import { reifyWkt } from "./private/reify-wkt.js";
|
|
17
18
|
const packageName = "@bufbuild/protobuf";
|
|
18
19
|
export const codegenInfo = {
|
|
19
20
|
packageName,
|
|
20
21
|
localName,
|
|
22
|
+
reifyWkt,
|
|
21
23
|
getUnwrappedFieldType,
|
|
22
24
|
scalarDefaultValue,
|
|
23
25
|
// prettier-ignore
|
|
@@ -167,6 +167,9 @@ export class Any extends Message {
|
|
|
167
167
|
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
168
168
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
|
|
169
169
|
}
|
|
170
|
+
if (Object.keys(json).length == 0) {
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
170
173
|
const typeUrl = json["@type"];
|
|
171
174
|
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
172
175
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
// @generated by protoc-gen-es v0.2.
|
|
14
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
15
15
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
16
16
|
/* eslint-disable */
|
|
17
17
|
import { proto3 } from "../../proto3.js";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
// @generated by protoc-gen-es v0.2.
|
|
14
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
15
15
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
16
16
|
/* eslint-disable */
|
|
17
17
|
import { proto3 } from "../../proto3.js";
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { ScalarType } from "../field.js";
|
|
15
|
+
/**
|
|
16
|
+
* Reifies a given DescMessage into a more concrete object representing its
|
|
17
|
+
* respective well-known type. The returned object will contain properties
|
|
18
|
+
* representing the WKT's defined fields.
|
|
19
|
+
*
|
|
20
|
+
* Useful during code generation when immediate access to a particular field
|
|
21
|
+
* is needed without having to search the object's typename and DescField list.
|
|
22
|
+
*
|
|
23
|
+
* Returns undefined if the WKT cannot be completely constructed via the
|
|
24
|
+
* DescMessage.
|
|
25
|
+
*/
|
|
26
|
+
export function reifyWkt(message) {
|
|
27
|
+
switch (message.typeName) {
|
|
28
|
+
case "google.protobuf.Any": {
|
|
29
|
+
const typeUrl = message.fields.find((f) => f.number == 1 &&
|
|
30
|
+
f.fieldKind == "scalar" &&
|
|
31
|
+
f.scalar === ScalarType.STRING);
|
|
32
|
+
const value = message.fields.find((f) => f.number == 2 &&
|
|
33
|
+
f.fieldKind == "scalar" &&
|
|
34
|
+
f.scalar === ScalarType.BYTES);
|
|
35
|
+
if (typeUrl && value) {
|
|
36
|
+
return {
|
|
37
|
+
typeName: message.typeName,
|
|
38
|
+
typeUrl,
|
|
39
|
+
value,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "google.protobuf.Timestamp": {
|
|
45
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
46
|
+
f.fieldKind == "scalar" &&
|
|
47
|
+
f.scalar === ScalarType.INT64);
|
|
48
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
49
|
+
f.fieldKind == "scalar" &&
|
|
50
|
+
f.scalar === ScalarType.INT32);
|
|
51
|
+
if (seconds && nanos) {
|
|
52
|
+
return {
|
|
53
|
+
typeName: message.typeName,
|
|
54
|
+
seconds,
|
|
55
|
+
nanos,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case "google.protobuf.Duration": {
|
|
61
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
62
|
+
f.fieldKind == "scalar" &&
|
|
63
|
+
f.scalar === ScalarType.INT64);
|
|
64
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
65
|
+
f.fieldKind == "scalar" &&
|
|
66
|
+
f.scalar === ScalarType.INT32);
|
|
67
|
+
if (seconds && nanos) {
|
|
68
|
+
return {
|
|
69
|
+
typeName: message.typeName,
|
|
70
|
+
seconds,
|
|
71
|
+
nanos,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "google.protobuf.Struct": {
|
|
77
|
+
const fields = message.fields.find((f) => f.number == 1 && !f.repeated);
|
|
78
|
+
if ((fields === null || fields === void 0 ? void 0 : fields.fieldKind) !== "map" ||
|
|
79
|
+
fields.mapValue.kind !== "message" ||
|
|
80
|
+
fields.mapValue.message.typeName !== "google.protobuf.Value") {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
return { typeName: message.typeName, fields };
|
|
84
|
+
}
|
|
85
|
+
case "google.protobuf.Value": {
|
|
86
|
+
const kind = message.oneofs.find((o) => o.name === "kind");
|
|
87
|
+
const nullValue = message.fields.find((f) => f.number == 1 && f.oneof === kind);
|
|
88
|
+
if ((nullValue === null || nullValue === void 0 ? void 0 : nullValue.fieldKind) !== "enum" ||
|
|
89
|
+
nullValue.enum.typeName !== "google.protobuf.NullValue") {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
const numberValue = message.fields.find((f) => f.number == 2 &&
|
|
93
|
+
f.fieldKind == "scalar" &&
|
|
94
|
+
f.scalar === ScalarType.DOUBLE &&
|
|
95
|
+
f.oneof === kind);
|
|
96
|
+
const stringValue = message.fields.find((f) => f.number == 3 &&
|
|
97
|
+
f.fieldKind == "scalar" &&
|
|
98
|
+
f.scalar === ScalarType.STRING &&
|
|
99
|
+
f.oneof === kind);
|
|
100
|
+
const boolValue = message.fields.find((f) => f.number == 4 &&
|
|
101
|
+
f.fieldKind == "scalar" &&
|
|
102
|
+
f.scalar === ScalarType.BOOL &&
|
|
103
|
+
f.oneof === kind);
|
|
104
|
+
const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
|
|
105
|
+
if ((structValue === null || structValue === void 0 ? void 0 : structValue.fieldKind) !== "message" ||
|
|
106
|
+
structValue.message.typeName !== "google.protobuf.Struct") {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const listValue = message.fields.find((f) => f.number == 6 && f.oneof === kind);
|
|
110
|
+
if ((listValue === null || listValue === void 0 ? void 0 : listValue.fieldKind) !== "message" ||
|
|
111
|
+
listValue.message.typeName !== "google.protobuf.ListValue") {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (kind && numberValue && stringValue && boolValue) {
|
|
115
|
+
return {
|
|
116
|
+
typeName: message.typeName,
|
|
117
|
+
kind,
|
|
118
|
+
nullValue,
|
|
119
|
+
numberValue,
|
|
120
|
+
stringValue,
|
|
121
|
+
boolValue,
|
|
122
|
+
structValue,
|
|
123
|
+
listValue,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "google.protobuf.ListValue": {
|
|
129
|
+
const values = message.fields.find((f) => f.number == 1 && f.repeated);
|
|
130
|
+
if ((values === null || values === void 0 ? void 0 : values.fieldKind) != "message" ||
|
|
131
|
+
values.message.typeName !== "google.protobuf.Value") {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return { typeName: message.typeName, values };
|
|
135
|
+
}
|
|
136
|
+
case "google.protobuf.FieldMask": {
|
|
137
|
+
const paths = message.fields.find((f) => f.number == 1 &&
|
|
138
|
+
f.fieldKind == "scalar" &&
|
|
139
|
+
f.scalar === ScalarType.STRING &&
|
|
140
|
+
f.repeated);
|
|
141
|
+
if (paths) {
|
|
142
|
+
return { typeName: message.typeName, paths };
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "google.protobuf.DoubleValue":
|
|
147
|
+
case "google.protobuf.FloatValue":
|
|
148
|
+
case "google.protobuf.Int64Value":
|
|
149
|
+
case "google.protobuf.UInt64Value":
|
|
150
|
+
case "google.protobuf.Int32Value":
|
|
151
|
+
case "google.protobuf.UInt32Value":
|
|
152
|
+
case "google.protobuf.BoolValue":
|
|
153
|
+
case "google.protobuf.StringValue":
|
|
154
|
+
case "google.protobuf.BytesValue": {
|
|
155
|
+
const value = message.fields.find((f) => f.number == 1 && f.name == "value");
|
|
156
|
+
if (!value) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
if (value.fieldKind !== "scalar") {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
return { typeName: message.typeName, value };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { localName } from "./private/names.js";
|
|
2
2
|
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
|
|
3
3
|
import { scalarDefaultValue } from "./private/scalars.js";
|
|
4
|
+
import { reifyWkt } from "./private/reify-wkt.js";
|
|
4
5
|
interface CodegenInfo {
|
|
5
6
|
readonly packageName: string;
|
|
6
7
|
readonly localName: typeof localName;
|
|
@@ -8,6 +9,7 @@ interface CodegenInfo {
|
|
|
8
9
|
readonly getUnwrappedFieldType: typeof getUnwrappedFieldType;
|
|
9
10
|
readonly wktSourceFiles: readonly string[];
|
|
10
11
|
readonly scalarDefaultValue: typeof scalarDefaultValue;
|
|
12
|
+
readonly reifyWkt: typeof reifyWkt;
|
|
11
13
|
}
|
|
12
14
|
declare type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency";
|
|
13
15
|
declare type RuntimeSymbolInfo = {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { DescField, DescMessage, DescOneof } from "../descriptor-set.js";
|
|
2
|
+
declare type DescWkt = {
|
|
3
|
+
typeName: "google.protobuf.Any";
|
|
4
|
+
typeUrl: DescField;
|
|
5
|
+
value: DescField;
|
|
6
|
+
} | {
|
|
7
|
+
typeName: "google.protobuf.Timestamp";
|
|
8
|
+
seconds: DescField;
|
|
9
|
+
nanos: DescField;
|
|
10
|
+
} | {
|
|
11
|
+
typeName: "google.protobuf.Duration";
|
|
12
|
+
seconds: DescField;
|
|
13
|
+
nanos: DescField;
|
|
14
|
+
} | {
|
|
15
|
+
typeName: "google.protobuf.Struct";
|
|
16
|
+
fields: DescField & {
|
|
17
|
+
fieldKind: "map";
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
typeName: "google.protobuf.Value";
|
|
21
|
+
kind: DescOneof;
|
|
22
|
+
nullValue: DescField & {
|
|
23
|
+
fieldKind: "enum";
|
|
24
|
+
};
|
|
25
|
+
numberValue: DescField;
|
|
26
|
+
stringValue: DescField;
|
|
27
|
+
boolValue: DescField;
|
|
28
|
+
structValue: DescField & {
|
|
29
|
+
fieldKind: "message";
|
|
30
|
+
};
|
|
31
|
+
listValue: DescField & {
|
|
32
|
+
fieldKind: "message";
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
typeName: "google.protobuf.ListValue";
|
|
36
|
+
values: DescField & {
|
|
37
|
+
fieldKind: "message";
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
typeName: "google.protobuf.FieldMask";
|
|
41
|
+
paths: DescField;
|
|
42
|
+
} | {
|
|
43
|
+
typeName: "google.protobuf.DoubleValue";
|
|
44
|
+
value: DescField & {
|
|
45
|
+
fieldKind: "scalar";
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
48
|
+
typeName: "google.protobuf.FloatValue";
|
|
49
|
+
value: DescField & {
|
|
50
|
+
fieldKind: "scalar";
|
|
51
|
+
};
|
|
52
|
+
} | {
|
|
53
|
+
typeName: "google.protobuf.Int64Value";
|
|
54
|
+
value: DescField & {
|
|
55
|
+
fieldKind: "scalar";
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
typeName: "google.protobuf.UInt64Value";
|
|
59
|
+
value: DescField & {
|
|
60
|
+
fieldKind: "scalar";
|
|
61
|
+
};
|
|
62
|
+
} | {
|
|
63
|
+
typeName: "google.protobuf.Int32Value";
|
|
64
|
+
value: DescField & {
|
|
65
|
+
fieldKind: "scalar";
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
typeName: "google.protobuf.UInt32Value";
|
|
69
|
+
value: DescField & {
|
|
70
|
+
fieldKind: "scalar";
|
|
71
|
+
};
|
|
72
|
+
} | {
|
|
73
|
+
typeName: "google.protobuf.BoolValue";
|
|
74
|
+
value: DescField & {
|
|
75
|
+
fieldKind: "scalar";
|
|
76
|
+
};
|
|
77
|
+
} | {
|
|
78
|
+
typeName: "google.protobuf.StringValue";
|
|
79
|
+
value: DescField & {
|
|
80
|
+
fieldKind: "scalar";
|
|
81
|
+
};
|
|
82
|
+
} | {
|
|
83
|
+
typeName: "google.protobuf.BytesValue";
|
|
84
|
+
value: DescField & {
|
|
85
|
+
fieldKind: "scalar";
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Reifies a given DescMessage into a more concrete object representing its
|
|
90
|
+
* respective well-known type. The returned object will contain properties
|
|
91
|
+
* representing the WKT's defined fields.
|
|
92
|
+
*
|
|
93
|
+
* Useful during code generation when immediate access to a particular field
|
|
94
|
+
* is needed without having to search the object's typename and DescField list.
|
|
95
|
+
*
|
|
96
|
+
* Returns undefined if the WKT cannot be completely constructed via the
|
|
97
|
+
* DescMessage.
|
|
98
|
+
*/
|
|
99
|
+
export declare function reifyWkt(message: DescMessage): DescWkt | undefined;
|
|
100
|
+
export {};
|
package/package.json
CHANGED