@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MessageType } from "../../index.js";
|
|
1
|
+
import type { JsonReadOptions, JsonValue, MessageType } from "../../index.js";
|
|
2
2
|
import { Message } from "../../index.js";
|
|
3
3
|
export declare const protobufPackage = "google.protobuf";
|
|
4
4
|
/**
|
|
@@ -86,4 +86,9 @@ export type Duration = Message<{
|
|
|
86
86
|
*/
|
|
87
87
|
nanos?: number;
|
|
88
88
|
}>;
|
|
89
|
-
|
|
89
|
+
declare const Duration_Wkt: {
|
|
90
|
+
fromJson(json: JsonValue | null | undefined, _options?: Partial<JsonReadOptions>): Duration;
|
|
91
|
+
toJson(msg: Duration): JsonValue;
|
|
92
|
+
};
|
|
93
|
+
export declare const Duration: MessageType<Duration> & typeof Duration_Wkt;
|
|
94
|
+
export {};
|
|
@@ -27,13 +27,63 @@
|
|
|
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, jsonDebugValue, protoInt64, ScalarType, } from "../../index.js";
|
|
31
31
|
export const protobufPackage = "google.protobuf";
|
|
32
|
+
// Duration_Wkt contains the well-known-type overrides for Duration.
|
|
33
|
+
const Duration_Wkt = {
|
|
34
|
+
fromJson(json, _options) {
|
|
35
|
+
if (typeof json !== "string") {
|
|
36
|
+
throw new Error(`cannot decode google.protobuf.Duration from JSON: ${jsonDebugValue(json)}`);
|
|
37
|
+
}
|
|
38
|
+
const match = json.match(/^(-?[0-9]+)(?:\.([0-9]+))?s/);
|
|
39
|
+
if (match === null) {
|
|
40
|
+
throw new Error(`cannot decode google.protobuf.Duration from JSON: ${jsonDebugValue(json)}`);
|
|
41
|
+
}
|
|
42
|
+
const longSeconds = Number(match[1]);
|
|
43
|
+
if (longSeconds > 315576000000 || longSeconds < -315576000000) {
|
|
44
|
+
throw new Error(`cannot decode google.protobuf.Duration from JSON: ${jsonDebugValue(json)}`);
|
|
45
|
+
}
|
|
46
|
+
const msg = {};
|
|
47
|
+
msg.seconds = protoInt64.parse(longSeconds);
|
|
48
|
+
if (typeof match[2] == "string") {
|
|
49
|
+
const nanosStr = match[2] + "0".repeat(9 - match[2].length);
|
|
50
|
+
msg.nanos = parseInt(nanosStr);
|
|
51
|
+
if (longSeconds < 0 || Object.is(longSeconds, -0)) {
|
|
52
|
+
msg.nanos = -msg.nanos;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return msg;
|
|
56
|
+
},
|
|
57
|
+
toJson(msg) {
|
|
58
|
+
const secs = Number(msg.seconds ?? 0);
|
|
59
|
+
const nanos = Number(msg.nanos ?? 0);
|
|
60
|
+
if (secs > 315576000000 || secs < -315576000000) {
|
|
61
|
+
throw new Error(`cannot encode google.protobuf.Duration to JSON: value out of range`);
|
|
62
|
+
}
|
|
63
|
+
let text = secs.toString();
|
|
64
|
+
if (nanos !== 0) {
|
|
65
|
+
let nanosStr = Math.abs(nanos).toString();
|
|
66
|
+
nanosStr = "0".repeat(9 - nanosStr.length) + nanosStr;
|
|
67
|
+
if (nanosStr.substring(3) === "000000") {
|
|
68
|
+
nanosStr = nanosStr.substring(0, 3);
|
|
69
|
+
}
|
|
70
|
+
else if (nanosStr.substring(6) === "000") {
|
|
71
|
+
nanosStr = nanosStr.substring(0, 6);
|
|
72
|
+
}
|
|
73
|
+
text += "." + nanosStr;
|
|
74
|
+
if (nanos < 0 && secs === 0) {
|
|
75
|
+
text = "-" + text;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return text + "s";
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
// Duration contains the message type declaration for Duration.
|
|
32
82
|
export const Duration = createMessageType({
|
|
33
83
|
typeName: "google.protobuf.Duration",
|
|
34
84
|
fields: [
|
|
35
|
-
{ no: 1, name: "seconds", kind: "scalar", T:
|
|
36
|
-
{ no: 2, name: "nanos", kind: "scalar", T:
|
|
85
|
+
{ no: 1, name: "seconds", kind: "scalar", T: ScalarType.INT64 },
|
|
86
|
+
{ no: 2, name: "nanos", kind: "scalar", T: ScalarType.INT32 },
|
|
37
87
|
],
|
|
38
88
|
packedByDefault: true,
|
|
39
|
-
});
|
|
89
|
+
}, Duration_Wkt);
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
30
|
import { createMessageType } from "../../index.js";
|
|
31
31
|
export const protobufPackage = "google.protobuf";
|
|
32
|
+
// Empty contains the message type declaration for Empty.
|
|
32
33
|
export const Empty = createMessageType({
|
|
33
34
|
typeName: "google.protobuf.Empty",
|
|
34
35
|
fields: [],
|
|
@@ -27,12 +27,13 @@
|
|
|
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
|
export const protobufPackage = "google.protobuf";
|
|
32
|
+
// SourceContext contains the message type declaration for SourceContext.
|
|
32
33
|
export const SourceContext = createMessageType({
|
|
33
34
|
typeName: "google.protobuf.SourceContext",
|
|
34
35
|
fields: [
|
|
35
|
-
{ no: 1, name: "file_name", kind: "scalar", T:
|
|
36
|
+
{ no: 1, name: "file_name", kind: "scalar", T: ScalarType.STRING },
|
|
36
37
|
],
|
|
37
38
|
packedByDefault: true,
|
|
38
39
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MessageType } from "../../index.js";
|
|
1
|
+
import type { JsonReadOptions, JsonValue, JsonWriteOptions, MessageType } from "../../index.js";
|
|
2
2
|
import { Message } from "../../index.js";
|
|
3
3
|
export declare const protobufPackage = "google.protobuf";
|
|
4
4
|
/**
|
|
@@ -33,7 +33,11 @@ export type ListValue = Message<{
|
|
|
33
33
|
*/
|
|
34
34
|
values?: Value[];
|
|
35
35
|
}>;
|
|
36
|
-
|
|
36
|
+
declare const ListValue_Wkt: {
|
|
37
|
+
toJson(msg: ListValue, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
38
|
+
fromJson(json: JsonValue | null | undefined, options?: Partial<JsonReadOptions>): ListValue;
|
|
39
|
+
};
|
|
40
|
+
export declare const ListValue: MessageType<ListValue> & typeof ListValue_Wkt;
|
|
37
41
|
/**
|
|
38
42
|
* `Value` represents a dynamically typed value which can be either
|
|
39
43
|
* null, a number, a string, a boolean, a recursive struct value, or a
|
|
@@ -103,7 +107,11 @@ export type Value = Message<{
|
|
|
103
107
|
case: "listValue";
|
|
104
108
|
};
|
|
105
109
|
}>;
|
|
106
|
-
|
|
110
|
+
declare const Value_Wkt: {
|
|
111
|
+
toJson(msg: Value, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
112
|
+
fromJson(json: JsonValue | null | undefined, _options?: Partial<JsonReadOptions>): Value;
|
|
113
|
+
};
|
|
114
|
+
export declare const Value: MessageType<Value> & typeof Value_Wkt;
|
|
107
115
|
/**
|
|
108
116
|
* `Struct` represents a structured data value, consisting of fields
|
|
109
117
|
* which map to dynamically typed values. In some languages, `Struct`
|
|
@@ -126,4 +134,9 @@ export type Struct = Message<{
|
|
|
126
134
|
[key: string]: Value;
|
|
127
135
|
};
|
|
128
136
|
}>;
|
|
129
|
-
|
|
137
|
+
declare const Struct_Wkt: {
|
|
138
|
+
toJson(msg: Struct, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
139
|
+
fromJson(json: JsonValue | null | undefined, _options?: Partial<JsonReadOptions>): Struct;
|
|
140
|
+
};
|
|
141
|
+
export declare const Struct: MessageType<Struct> & typeof Struct_Wkt;
|
|
142
|
+
export {};
|
|
@@ -27,7 +27,7 @@
|
|
|
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 { createEnumType, createMessageType } from "../../index.js";
|
|
30
|
+
import { createEnumType, createMessageType, jsonDebugValue, ScalarType, } from "../../index.js";
|
|
31
31
|
export const protobufPackage = "google.protobuf";
|
|
32
32
|
/**
|
|
33
33
|
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
@@ -50,29 +50,179 @@ export var NullValue;
|
|
|
50
50
|
export const NullValue_Enum = createEnumType("google.protobuf.NullValue", [
|
|
51
51
|
{ no: 0, name: "NULL_VALUE" },
|
|
52
52
|
]);
|
|
53
|
+
// ListValue_Wkt contains the well-known-type overrides for ListValue.
|
|
54
|
+
const ListValue_Wkt = {
|
|
55
|
+
toJson(msg, options) {
|
|
56
|
+
return msg.values?.map((v) => Value.toJson(v, options)) ?? [];
|
|
57
|
+
},
|
|
58
|
+
fromJson(json, options) {
|
|
59
|
+
if (json == null) {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
if (!Array.isArray(json)) {
|
|
63
|
+
throw new Error(`cannot decode google.protobuf.ListValue from JSON ${jsonDebugValue(json)}`);
|
|
64
|
+
}
|
|
65
|
+
const values = json.map((v) => Value.fromJson(v, options));
|
|
66
|
+
return { values: values };
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
// ListValue contains the message type declaration for ListValue.
|
|
53
70
|
export const ListValue = createMessageType({
|
|
54
71
|
typeName: "google.protobuf.ListValue",
|
|
55
72
|
fields: [
|
|
56
|
-
{
|
|
73
|
+
{
|
|
74
|
+
no: 1,
|
|
75
|
+
name: "values",
|
|
76
|
+
kind: "message",
|
|
77
|
+
T: () => Value,
|
|
78
|
+
repeated: true,
|
|
79
|
+
},
|
|
57
80
|
],
|
|
58
81
|
packedByDefault: true,
|
|
59
|
-
});
|
|
82
|
+
}, ListValue_Wkt);
|
|
83
|
+
// Value_Wkt contains the well-known-type overrides for Value.
|
|
84
|
+
const Value_Wkt = {
|
|
85
|
+
toJson(msg, options) {
|
|
86
|
+
switch (msg.kind?.case) {
|
|
87
|
+
case "nullValue":
|
|
88
|
+
return null;
|
|
89
|
+
case "numberValue":
|
|
90
|
+
if (!Number.isFinite(msg.kind.value)) {
|
|
91
|
+
throw new Error("google.protobuf.Value cannot be NaN or Infinity");
|
|
92
|
+
}
|
|
93
|
+
return msg.kind.value;
|
|
94
|
+
case "boolValue":
|
|
95
|
+
return msg.kind.value;
|
|
96
|
+
case "stringValue":
|
|
97
|
+
return msg.kind.value;
|
|
98
|
+
case "structValue":
|
|
99
|
+
return Struct.toJson(msg.kind.value, {
|
|
100
|
+
...options,
|
|
101
|
+
emitDefaultValues: true,
|
|
102
|
+
});
|
|
103
|
+
case "listValue":
|
|
104
|
+
return ListValue.toJson(msg.kind.value, {
|
|
105
|
+
...options,
|
|
106
|
+
emitDefaultValues: true,
|
|
107
|
+
});
|
|
108
|
+
case null:
|
|
109
|
+
case undefined:
|
|
110
|
+
default:
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
fromJson(json, _options) {
|
|
115
|
+
const msg = {};
|
|
116
|
+
switch (typeof json) {
|
|
117
|
+
case "number":
|
|
118
|
+
msg.kind = { case: "numberValue", value: json };
|
|
119
|
+
break;
|
|
120
|
+
case "string":
|
|
121
|
+
msg.kind = { case: "stringValue", value: json };
|
|
122
|
+
break;
|
|
123
|
+
case "boolean":
|
|
124
|
+
msg.kind = { case: "boolValue", value: json };
|
|
125
|
+
break;
|
|
126
|
+
case "object":
|
|
127
|
+
if (json == null) {
|
|
128
|
+
msg.kind = { case: "nullValue", value: NullValue.NULL_VALUE };
|
|
129
|
+
}
|
|
130
|
+
else if (Array.isArray(json)) {
|
|
131
|
+
msg.kind = { case: "listValue", value: ListValue.fromJson(json) };
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
msg.kind = { case: "structValue", value: Struct.fromJson(json) };
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
throw new Error(`cannot decode google.protobuf.Value from JSON ${jsonDebugValue(json)}`);
|
|
139
|
+
}
|
|
140
|
+
return msg;
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
// Value contains the message type declaration for Value.
|
|
60
144
|
export const Value = createMessageType({
|
|
61
145
|
typeName: "google.protobuf.Value",
|
|
62
146
|
fields: [
|
|
63
|
-
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
147
|
+
{
|
|
148
|
+
no: 1,
|
|
149
|
+
name: "null_value",
|
|
150
|
+
kind: "enum",
|
|
151
|
+
T: NullValue_Enum,
|
|
152
|
+
oneof: "kind",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
no: 2,
|
|
156
|
+
name: "number_value",
|
|
157
|
+
kind: "scalar",
|
|
158
|
+
T: ScalarType.DOUBLE,
|
|
159
|
+
oneof: "kind",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
no: 3,
|
|
163
|
+
name: "string_value",
|
|
164
|
+
kind: "scalar",
|
|
165
|
+
T: ScalarType.STRING,
|
|
166
|
+
oneof: "kind",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
no: 4,
|
|
170
|
+
name: "bool_value",
|
|
171
|
+
kind: "scalar",
|
|
172
|
+
T: ScalarType.BOOL,
|
|
173
|
+
oneof: "kind",
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
no: 5,
|
|
177
|
+
name: "struct_value",
|
|
178
|
+
kind: "message",
|
|
179
|
+
T: () => Struct,
|
|
180
|
+
oneof: "kind",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
no: 6,
|
|
184
|
+
name: "list_value",
|
|
185
|
+
kind: "message",
|
|
186
|
+
T: () => ListValue,
|
|
187
|
+
oneof: "kind",
|
|
188
|
+
},
|
|
69
189
|
],
|
|
70
190
|
packedByDefault: true,
|
|
71
|
-
});
|
|
191
|
+
}, Value_Wkt);
|
|
192
|
+
// Struct_Wkt contains the well-known-type overrides for Struct.
|
|
193
|
+
const Struct_Wkt = {
|
|
194
|
+
toJson(msg, options) {
|
|
195
|
+
const json = {};
|
|
196
|
+
if (!msg.fields) {
|
|
197
|
+
return json;
|
|
198
|
+
}
|
|
199
|
+
for (const [k, v] of Object.entries(msg.fields)) {
|
|
200
|
+
json[k] = v != null ? Value.toJson(v, options) : null;
|
|
201
|
+
}
|
|
202
|
+
return json;
|
|
203
|
+
},
|
|
204
|
+
fromJson(json, _options) {
|
|
205
|
+
if (typeof json != "object" || json == null || Array.isArray(json)) {
|
|
206
|
+
throw new Error(`cannot decode google.protobuf.Struct from JSON ${jsonDebugValue(json)}`);
|
|
207
|
+
}
|
|
208
|
+
const fields = {};
|
|
209
|
+
for (const [k, v] of Object.entries(json)) {
|
|
210
|
+
fields[k] = Value.fromJson(v);
|
|
211
|
+
}
|
|
212
|
+
return { fields: fields };
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
// Struct contains the message type declaration for Struct.
|
|
72
216
|
export const Struct = createMessageType({
|
|
73
217
|
typeName: "google.protobuf.Struct",
|
|
74
218
|
fields: [
|
|
75
|
-
{
|
|
219
|
+
{
|
|
220
|
+
no: 1,
|
|
221
|
+
name: "fields",
|
|
222
|
+
kind: "map",
|
|
223
|
+
K: ScalarType.STRING,
|
|
224
|
+
V: { kind: "message", T: () => Value },
|
|
225
|
+
},
|
|
76
226
|
],
|
|
77
227
|
packedByDefault: true,
|
|
78
|
-
});
|
|
228
|
+
}, Struct_Wkt);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MessageType } from "../../index.js";
|
|
1
|
+
import type { JsonValue, MessageType } from "../../index.js";
|
|
2
2
|
import { Message } from "../../index.js";
|
|
3
3
|
export declare const protobufPackage = "google.protobuf";
|
|
4
4
|
/**
|
|
@@ -115,4 +115,10 @@ export type Timestamp = Message<{
|
|
|
115
115
|
*/
|
|
116
116
|
nanos?: number;
|
|
117
117
|
}>;
|
|
118
|
-
|
|
118
|
+
declare const Timestamp_Wkt: {
|
|
119
|
+
fromJson(json: JsonValue): Timestamp;
|
|
120
|
+
toJson(msg: Timestamp): JsonValue;
|
|
121
|
+
toDate(msg: Timestamp): Date;
|
|
122
|
+
};
|
|
123
|
+
export declare const Timestamp: MessageType<Timestamp> & typeof Timestamp_Wkt;
|
|
124
|
+
export {};
|
|
@@ -27,13 +27,77 @@
|
|
|
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, protoInt64, ScalarType, } from "../../index.js";
|
|
31
31
|
export const protobufPackage = "google.protobuf";
|
|
32
|
+
// Timestamp_Wkt contains the well-known-type overrides for Timestamp.
|
|
33
|
+
const Timestamp_Wkt = {
|
|
34
|
+
fromJson(json) {
|
|
35
|
+
if (typeof json !== "string") {
|
|
36
|
+
throw new Error(`cannot decode google.protobuf.Timestamp(json)}`);
|
|
37
|
+
}
|
|
38
|
+
const matches = json.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/);
|
|
39
|
+
if (!matches) {
|
|
40
|
+
throw new Error(`cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`);
|
|
41
|
+
}
|
|
42
|
+
const ms = Date.parse(matches[1] +
|
|
43
|
+
"-" +
|
|
44
|
+
matches[2] +
|
|
45
|
+
"-" +
|
|
46
|
+
matches[3] +
|
|
47
|
+
"T" +
|
|
48
|
+
matches[4] +
|
|
49
|
+
":" +
|
|
50
|
+
matches[5] +
|
|
51
|
+
":" +
|
|
52
|
+
matches[6] +
|
|
53
|
+
(matches[8] ? matches[8] : "Z"));
|
|
54
|
+
if (Number.isNaN(ms)) {
|
|
55
|
+
throw new Error(`cannot decode google.protobuf.Timestamp from JSON: invalid RFC 3339 string`);
|
|
56
|
+
}
|
|
57
|
+
if (ms < Date.parse("0001-01-01T00:00:00Z") ||
|
|
58
|
+
ms > Date.parse("9999-12-31T23:59:59Z")) {
|
|
59
|
+
throw new Error(`cannot decode message google.protobuf.Timestamp from JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
seconds: protoInt64.parse(ms / 1000),
|
|
63
|
+
nanos: !matches[7] ? 0 : (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) -
|
|
64
|
+
1000000000),
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
toJson(msg) {
|
|
68
|
+
const ms = Number(msg.seconds) * 1000;
|
|
69
|
+
if (ms < Date.parse("0001-01-01T00:00:00Z") ||
|
|
70
|
+
ms > Date.parse("9999-12-31T23:59:59Z")) {
|
|
71
|
+
throw new Error(`cannot encode google.protobuf.Timestamp to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);
|
|
72
|
+
}
|
|
73
|
+
if (msg.nanos != null && msg.nanos < 0) {
|
|
74
|
+
throw new Error(`cannot encode google.protobuf.Timestamp to JSON: nanos must not be negative`);
|
|
75
|
+
}
|
|
76
|
+
let z = "Z";
|
|
77
|
+
if (msg.nanos != null && msg.nanos > 0) {
|
|
78
|
+
const nanosStr = (msg.nanos + 1000000000).toString().substring(1);
|
|
79
|
+
if (nanosStr.substring(3) === "000000") {
|
|
80
|
+
z = "." + nanosStr.substring(0, 3) + "Z";
|
|
81
|
+
}
|
|
82
|
+
else if (nanosStr.substring(6) === "000") {
|
|
83
|
+
z = "." + nanosStr.substring(0, 6) + "Z";
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
z = "." + nanosStr + "Z";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return new Date(ms).toISOString().replace(".000Z", z);
|
|
90
|
+
},
|
|
91
|
+
toDate(msg) {
|
|
92
|
+
return new Date(Number(msg.seconds ?? 0) * 1000 + Math.ceil((msg.nanos ?? 0) / 1000000));
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
// Timestamp contains the message type declaration for Timestamp.
|
|
32
96
|
export const Timestamp = createMessageType({
|
|
33
97
|
typeName: "google.protobuf.Timestamp",
|
|
34
98
|
fields: [
|
|
35
|
-
{ no: 1, name: "seconds", kind: "scalar", T:
|
|
36
|
-
{ no: 2, name: "nanos", kind: "scalar", T:
|
|
99
|
+
{ no: 1, name: "seconds", kind: "scalar", T: ScalarType.INT64 },
|
|
100
|
+
{ no: 2, name: "nanos", kind: "scalar", T: ScalarType.INT32 },
|
|
37
101
|
],
|
|
38
102
|
packedByDefault: true,
|
|
39
|
-
});
|
|
103
|
+
}, Timestamp_Wkt);
|
|
@@ -27,7 +27,7 @@
|
|
|
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 { createEnumType, createMessageType } from "../../index.js";
|
|
30
|
+
import { createEnumType, createMessageType, ScalarType, } from "../../index.js";
|
|
31
31
|
import { Any } from "./any.pb.js";
|
|
32
32
|
import { SourceContext } from "./source_context.pb.js";
|
|
33
33
|
export const protobufPackage = "google.protobuf";
|
|
@@ -246,61 +246,102 @@ export const Field_Cardinality_Enum = createEnumType("google.protobuf.Field.Card
|
|
|
246
246
|
{ no: 2, name: "CARDINALITY_REQUIRED" },
|
|
247
247
|
{ no: 3, name: "CARDINALITY_REPEATED" },
|
|
248
248
|
]);
|
|
249
|
+
// Option contains the message type declaration for Option.
|
|
249
250
|
export const Option = createMessageType({
|
|
250
251
|
typeName: "google.protobuf.Option",
|
|
251
252
|
fields: [
|
|
252
|
-
{ no: 1, name: "name", kind: "scalar", T:
|
|
253
|
+
{ no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
253
254
|
{ no: 2, name: "value", kind: "message", T: () => Any },
|
|
254
255
|
],
|
|
255
256
|
packedByDefault: true,
|
|
256
257
|
});
|
|
258
|
+
// Field contains the message type declaration for Field.
|
|
257
259
|
export const Field = createMessageType({
|
|
258
260
|
typeName: "google.protobuf.Field",
|
|
259
261
|
fields: [
|
|
260
262
|
{ no: 1, name: "kind", kind: "enum", T: Field_Kind_Enum },
|
|
261
263
|
{ no: 2, name: "cardinality", kind: "enum", T: Field_Cardinality_Enum },
|
|
262
|
-
{ no: 3, name: "number", kind: "scalar", T:
|
|
263
|
-
{ no: 4, name: "name", kind: "scalar", T:
|
|
264
|
-
{ no: 6, name: "type_url", kind: "scalar", T:
|
|
265
|
-
{ no: 7, name: "oneof_index", kind: "scalar", T:
|
|
266
|
-
{ no: 8, name: "packed", kind: "scalar", T:
|
|
267
|
-
{
|
|
268
|
-
|
|
269
|
-
|
|
264
|
+
{ no: 3, name: "number", kind: "scalar", T: ScalarType.INT32 },
|
|
265
|
+
{ no: 4, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
266
|
+
{ no: 6, name: "type_url", kind: "scalar", T: ScalarType.STRING },
|
|
267
|
+
{ no: 7, name: "oneof_index", kind: "scalar", T: ScalarType.INT32 },
|
|
268
|
+
{ no: 8, name: "packed", kind: "scalar", T: ScalarType.BOOL },
|
|
269
|
+
{
|
|
270
|
+
no: 9,
|
|
271
|
+
name: "options",
|
|
272
|
+
kind: "message",
|
|
273
|
+
T: () => Option,
|
|
274
|
+
repeated: true,
|
|
275
|
+
},
|
|
276
|
+
{ no: 10, name: "json_name", kind: "scalar", T: ScalarType.STRING },
|
|
277
|
+
{ no: 11, name: "default_value", kind: "scalar", T: ScalarType.STRING },
|
|
270
278
|
],
|
|
271
279
|
packedByDefault: true,
|
|
272
280
|
});
|
|
281
|
+
// Type contains the message type declaration for Type.
|
|
273
282
|
export const Type = createMessageType({
|
|
274
283
|
typeName: "google.protobuf.Type",
|
|
275
284
|
fields: [
|
|
276
|
-
{ no: 1, name: "name", kind: "scalar", T:
|
|
285
|
+
{ no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
277
286
|
{ no: 2, name: "fields", kind: "message", T: () => Field, repeated: true },
|
|
278
|
-
{
|
|
279
|
-
|
|
287
|
+
{
|
|
288
|
+
no: 3,
|
|
289
|
+
name: "oneofs",
|
|
290
|
+
kind: "scalar",
|
|
291
|
+
T: ScalarType.STRING,
|
|
292
|
+
repeated: true,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
no: 4,
|
|
296
|
+
name: "options",
|
|
297
|
+
kind: "message",
|
|
298
|
+
T: () => Option,
|
|
299
|
+
repeated: true,
|
|
300
|
+
},
|
|
280
301
|
{ no: 5, name: "source_context", kind: "message", T: () => SourceContext },
|
|
281
302
|
{ no: 6, name: "syntax", kind: "enum", T: Syntax_Enum },
|
|
282
|
-
{ no: 7, name: "edition", kind: "scalar", T:
|
|
303
|
+
{ no: 7, name: "edition", kind: "scalar", T: ScalarType.STRING },
|
|
283
304
|
],
|
|
284
305
|
packedByDefault: true,
|
|
285
306
|
});
|
|
307
|
+
// EnumValue contains the message type declaration for EnumValue.
|
|
286
308
|
export const EnumValue = createMessageType({
|
|
287
309
|
typeName: "google.protobuf.EnumValue",
|
|
288
310
|
fields: [
|
|
289
|
-
{ no: 1, name: "name", kind: "scalar", T:
|
|
290
|
-
{ no: 2, name: "number", kind: "scalar", T:
|
|
291
|
-
{
|
|
311
|
+
{ no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
312
|
+
{ no: 2, name: "number", kind: "scalar", T: ScalarType.INT32 },
|
|
313
|
+
{
|
|
314
|
+
no: 3,
|
|
315
|
+
name: "options",
|
|
316
|
+
kind: "message",
|
|
317
|
+
T: () => Option,
|
|
318
|
+
repeated: true,
|
|
319
|
+
},
|
|
292
320
|
],
|
|
293
321
|
packedByDefault: true,
|
|
294
322
|
});
|
|
323
|
+
// Enum contains the message type declaration for Enum.
|
|
295
324
|
export const Enum = createMessageType({
|
|
296
325
|
typeName: "google.protobuf.Enum",
|
|
297
326
|
fields: [
|
|
298
|
-
{ no: 1, name: "name", kind: "scalar", T:
|
|
299
|
-
{
|
|
300
|
-
|
|
327
|
+
{ no: 1, name: "name", kind: "scalar", T: ScalarType.STRING },
|
|
328
|
+
{
|
|
329
|
+
no: 2,
|
|
330
|
+
name: "enumvalue",
|
|
331
|
+
kind: "message",
|
|
332
|
+
T: () => EnumValue,
|
|
333
|
+
repeated: true,
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
no: 3,
|
|
337
|
+
name: "options",
|
|
338
|
+
kind: "message",
|
|
339
|
+
T: () => Option,
|
|
340
|
+
repeated: true,
|
|
341
|
+
},
|
|
301
342
|
{ no: 4, name: "source_context", kind: "message", T: () => SourceContext },
|
|
302
343
|
{ no: 5, name: "syntax", kind: "enum", T: Syntax_Enum },
|
|
303
|
-
{ no: 6, name: "edition", kind: "scalar", T:
|
|
344
|
+
{ no: 6, name: "edition", kind: "scalar", T: ScalarType.STRING },
|
|
304
345
|
],
|
|
305
346
|
packedByDefault: true,
|
|
306
347
|
});
|