@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
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { JsonReadOptions, JsonValue, JsonWriteOptions, MessageType } from "../../index.js";
|
|
2
|
-
export declare const protobufPackage = "google.protobuf";
|
|
3
|
-
/**
|
|
4
|
-
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
5
|
-
* `Value` type union.
|
|
6
|
-
*
|
|
7
|
-
* The JSON representation for `NullValue` is JSON `null`.
|
|
8
|
-
*
|
|
9
|
-
* @generated from enum google.protobuf.NullValue
|
|
10
|
-
*/
|
|
11
|
-
export declare enum NullValue {
|
|
12
|
-
/**
|
|
13
|
-
* Null value.
|
|
14
|
-
*
|
|
15
|
-
* @generated from enum value: NULL_VALUE = 0;
|
|
16
|
-
*/
|
|
17
|
-
NULL_VALUE = 0
|
|
18
|
-
}
|
|
19
|
-
export declare const NullValue_Enum: import("../../enum.js").EnumType;
|
|
20
|
-
/**
|
|
21
|
-
* `ListValue` is a wrapper around a repeated field of values.
|
|
22
|
-
*
|
|
23
|
-
* The JSON representation for `ListValue` is JSON array.
|
|
24
|
-
*
|
|
25
|
-
* @generated from message google.protobuf.ListValue
|
|
26
|
-
*/
|
|
27
|
-
export interface ListValue {
|
|
28
|
-
/**
|
|
29
|
-
* Repeated field of dynamically typed values.
|
|
30
|
-
*
|
|
31
|
-
* @generated from field: repeated google.protobuf.Value values = 1;
|
|
32
|
-
*/
|
|
33
|
-
values?: Value[];
|
|
34
|
-
}
|
|
35
|
-
declare const ListValue_Wkt: {
|
|
36
|
-
toJson(msg: ListValue, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
37
|
-
fromJson(json: JsonValue | null | undefined, options?: Partial<JsonReadOptions>): ListValue;
|
|
38
|
-
};
|
|
39
|
-
export declare const ListValue: MessageType<ListValue> & typeof ListValue_Wkt;
|
|
40
|
-
/**
|
|
41
|
-
* `Value` represents a dynamically typed value which can be either
|
|
42
|
-
* null, a number, a string, a boolean, a recursive struct value, or a
|
|
43
|
-
* list of values. A producer of value is expected to set one of these
|
|
44
|
-
* variants. Absence of any variant indicates an error.
|
|
45
|
-
*
|
|
46
|
-
* The JSON representation for `Value` is JSON value.
|
|
47
|
-
*
|
|
48
|
-
* @generated from message google.protobuf.Value
|
|
49
|
-
*/
|
|
50
|
-
export interface Value {
|
|
51
|
-
/**
|
|
52
|
-
* The kind of value.
|
|
53
|
-
*
|
|
54
|
-
* @generated from oneof google.protobuf.Value.kind
|
|
55
|
-
*/
|
|
56
|
-
kind?: {
|
|
57
|
-
value?: undefined;
|
|
58
|
-
case: undefined;
|
|
59
|
-
} | {
|
|
60
|
-
/**
|
|
61
|
-
* Represents a null value.
|
|
62
|
-
*
|
|
63
|
-
* @generated from field: google.protobuf.NullValue null_value = 1;
|
|
64
|
-
*/
|
|
65
|
-
value: NullValue;
|
|
66
|
-
case: "nullValue";
|
|
67
|
-
} | {
|
|
68
|
-
/**
|
|
69
|
-
* Represents a double value.
|
|
70
|
-
*
|
|
71
|
-
* @generated from field: double number_value = 2;
|
|
72
|
-
*/
|
|
73
|
-
value: number;
|
|
74
|
-
case: "numberValue";
|
|
75
|
-
} | {
|
|
76
|
-
/**
|
|
77
|
-
* Represents a string value.
|
|
78
|
-
*
|
|
79
|
-
* @generated from field: string string_value = 3;
|
|
80
|
-
*/
|
|
81
|
-
value: string;
|
|
82
|
-
case: "stringValue";
|
|
83
|
-
} | {
|
|
84
|
-
/**
|
|
85
|
-
* Represents a boolean value.
|
|
86
|
-
*
|
|
87
|
-
* @generated from field: bool bool_value = 4;
|
|
88
|
-
*/
|
|
89
|
-
value: boolean;
|
|
90
|
-
case: "boolValue";
|
|
91
|
-
} | {
|
|
92
|
-
/**
|
|
93
|
-
* Represents a structured value.
|
|
94
|
-
*
|
|
95
|
-
* @generated from field: google.protobuf.Struct struct_value = 5;
|
|
96
|
-
*/
|
|
97
|
-
value: Struct;
|
|
98
|
-
case: "structValue";
|
|
99
|
-
} | {
|
|
100
|
-
/**
|
|
101
|
-
* Represents a repeated `Value`.
|
|
102
|
-
*
|
|
103
|
-
* @generated from field: google.protobuf.ListValue list_value = 6;
|
|
104
|
-
*/
|
|
105
|
-
value: ListValue;
|
|
106
|
-
case: "listValue";
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
declare const Value_Wkt: {
|
|
110
|
-
toJson(msg: Value, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
111
|
-
fromJson(json: JsonValue | null | undefined, _options?: Partial<JsonReadOptions>): Value;
|
|
112
|
-
};
|
|
113
|
-
export declare const Value: MessageType<Value> & typeof Value_Wkt;
|
|
114
|
-
/**
|
|
115
|
-
* `Struct` represents a structured data value, consisting of fields
|
|
116
|
-
* which map to dynamically typed values. In some languages, `Struct`
|
|
117
|
-
* might be supported by a native representation. For example, in
|
|
118
|
-
* scripting languages like JS a struct is represented as an
|
|
119
|
-
* object. The details of that representation are described together
|
|
120
|
-
* with the proto support for the language.
|
|
121
|
-
*
|
|
122
|
-
* The JSON representation for `Struct` is JSON object.
|
|
123
|
-
*
|
|
124
|
-
* @generated from message google.protobuf.Struct
|
|
125
|
-
*/
|
|
126
|
-
export interface Struct {
|
|
127
|
-
/**
|
|
128
|
-
* Unordered map of dynamically typed values.
|
|
129
|
-
*
|
|
130
|
-
* @generated from field: map<string, google.protobuf.Value> fields = 1;
|
|
131
|
-
*/
|
|
132
|
-
fields?: {
|
|
133
|
-
[key: string]: Value;
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
declare const Struct_Wkt: {
|
|
137
|
-
toJson(msg: Struct, options?: Partial<JsonWriteOptions>): JsonValue;
|
|
138
|
-
fromJson(json: JsonValue | null | undefined, _options?: Partial<JsonReadOptions>): Struct;
|
|
139
|
-
};
|
|
140
|
-
export declare const Struct: MessageType<Struct> & typeof Struct_Wkt;
|
|
141
|
-
export {};
|
|
@@ -1,228 +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 { createEnumType, createMessageType, jsonDebugValue, ScalarType, } from "../../index.js";
|
|
31
|
-
export const protobufPackage = "google.protobuf";
|
|
32
|
-
/**
|
|
33
|
-
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
34
|
-
* `Value` type union.
|
|
35
|
-
*
|
|
36
|
-
* The JSON representation for `NullValue` is JSON `null`.
|
|
37
|
-
*
|
|
38
|
-
* @generated from enum google.protobuf.NullValue
|
|
39
|
-
*/
|
|
40
|
-
export var NullValue;
|
|
41
|
-
(function (NullValue) {
|
|
42
|
-
/**
|
|
43
|
-
* Null value.
|
|
44
|
-
*
|
|
45
|
-
* @generated from enum value: NULL_VALUE = 0;
|
|
46
|
-
*/
|
|
47
|
-
NullValue[NullValue["NULL_VALUE"] = 0] = "NULL_VALUE";
|
|
48
|
-
})(NullValue || (NullValue = {}));
|
|
49
|
-
// NullValue_Enum is the enum type for NullValue.
|
|
50
|
-
export const NullValue_Enum = createEnumType("google.protobuf.NullValue", [
|
|
51
|
-
{ no: 0, name: "NULL_VALUE" },
|
|
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.
|
|
70
|
-
export const ListValue = createMessageType({
|
|
71
|
-
typeName: "google.protobuf.ListValue",
|
|
72
|
-
fields: [
|
|
73
|
-
{
|
|
74
|
-
no: 1,
|
|
75
|
-
name: "values",
|
|
76
|
-
kind: "message",
|
|
77
|
-
T: () => Value,
|
|
78
|
-
repeated: true,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
packedByDefault: true,
|
|
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.
|
|
144
|
-
export const Value = createMessageType({
|
|
145
|
-
typeName: "google.protobuf.Value",
|
|
146
|
-
fields: [
|
|
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
|
-
},
|
|
189
|
-
],
|
|
190
|
-
packedByDefault: true,
|
|
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.
|
|
216
|
-
export const Struct = createMessageType({
|
|
217
|
-
typeName: "google.protobuf.Struct",
|
|
218
|
-
fields: [
|
|
219
|
-
{
|
|
220
|
-
no: 1,
|
|
221
|
-
name: "fields",
|
|
222
|
-
kind: "map",
|
|
223
|
-
K: ScalarType.STRING,
|
|
224
|
-
V: { kind: "message", T: () => Value },
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
packedByDefault: true,
|
|
228
|
-
}, Struct_Wkt);
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { JsonValue, MessageType } from "../../index.js";
|
|
2
|
-
export declare const protobufPackage = "google.protobuf";
|
|
3
|
-
/**
|
|
4
|
-
* A Timestamp represents a point in time independent of any time zone or local
|
|
5
|
-
* calendar, encoded as a count of seconds and fractions of seconds at
|
|
6
|
-
* nanosecond resolution. The count is relative to an epoch at UTC midnight on
|
|
7
|
-
* January 1, 1970, in the proleptic Gregorian calendar which extends the
|
|
8
|
-
* Gregorian calendar backwards to year one.
|
|
9
|
-
*
|
|
10
|
-
* All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
|
|
11
|
-
* second table is needed for interpretation, using a [24-hour linear
|
|
12
|
-
* smear](https://developers.google.com/time/smear).
|
|
13
|
-
*
|
|
14
|
-
* The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
|
|
15
|
-
* restricting to that range, we ensure that we can convert to and from [RFC
|
|
16
|
-
* 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
|
|
17
|
-
*
|
|
18
|
-
* # Examples
|
|
19
|
-
*
|
|
20
|
-
* Example 1: Compute Timestamp from POSIX `time()`.
|
|
21
|
-
*
|
|
22
|
-
* Timestamp timestamp;
|
|
23
|
-
* timestamp.set_seconds(time(NULL));
|
|
24
|
-
* timestamp.set_nanos(0);
|
|
25
|
-
*
|
|
26
|
-
* Example 2: Compute Timestamp from POSIX `gettimeofday()`.
|
|
27
|
-
*
|
|
28
|
-
* struct timeval tv;
|
|
29
|
-
* gettimeofday(&tv, NULL);
|
|
30
|
-
*
|
|
31
|
-
* Timestamp timestamp;
|
|
32
|
-
* timestamp.set_seconds(tv.tv_sec);
|
|
33
|
-
* timestamp.set_nanos(tv.tv_usec * 1000);
|
|
34
|
-
*
|
|
35
|
-
* Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
|
|
36
|
-
*
|
|
37
|
-
* FILETIME ft;
|
|
38
|
-
* GetSystemTimeAsFileTime(&ft);
|
|
39
|
-
* UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
|
|
40
|
-
*
|
|
41
|
-
* // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
|
|
42
|
-
* // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
|
|
43
|
-
* Timestamp timestamp;
|
|
44
|
-
* timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
|
|
45
|
-
* timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
|
|
46
|
-
*
|
|
47
|
-
* Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
|
|
48
|
-
*
|
|
49
|
-
* long millis = System.currentTimeMillis();
|
|
50
|
-
*
|
|
51
|
-
* Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
|
|
52
|
-
* .setNanos((int) ((millis % 1000) * 1000000)).build();
|
|
53
|
-
*
|
|
54
|
-
* Example 5: Compute Timestamp from Java `Instant.now()`.
|
|
55
|
-
*
|
|
56
|
-
* Instant now = Instant.now();
|
|
57
|
-
*
|
|
58
|
-
* Timestamp timestamp =
|
|
59
|
-
* Timestamp.newBuilder().setSeconds(now.getEpochSecond())
|
|
60
|
-
* .setNanos(now.getNano()).build();
|
|
61
|
-
*
|
|
62
|
-
* Example 6: Compute Timestamp from current time in Python.
|
|
63
|
-
*
|
|
64
|
-
* timestamp = Timestamp()
|
|
65
|
-
* timestamp.GetCurrentTime()
|
|
66
|
-
*
|
|
67
|
-
* # JSON Mapping
|
|
68
|
-
*
|
|
69
|
-
* In JSON format, the Timestamp type is encoded as a string in the
|
|
70
|
-
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
|
|
71
|
-
* format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
|
|
72
|
-
* where {year} is always expressed using four digits while {month}, {day},
|
|
73
|
-
* {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
|
|
74
|
-
* seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
|
|
75
|
-
* are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
|
|
76
|
-
* is required. A proto3 JSON serializer should always use UTC (as indicated by
|
|
77
|
-
* "Z") when printing the Timestamp type and a proto3 JSON parser should be
|
|
78
|
-
* able to accept both UTC and other timezones (as indicated by an offset).
|
|
79
|
-
*
|
|
80
|
-
* For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
|
|
81
|
-
* 01:30 UTC on January 15, 2017.
|
|
82
|
-
*
|
|
83
|
-
* In JavaScript, one can convert a Date object to this format using the
|
|
84
|
-
* standard
|
|
85
|
-
* [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
|
|
86
|
-
* method. In Python, a standard `datetime.datetime` object can be converted
|
|
87
|
-
* to this format using
|
|
88
|
-
* [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
|
|
89
|
-
* the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
|
|
90
|
-
* the Joda Time's [`ISODateTimeFormat.dateTime()`](
|
|
91
|
-
* http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
|
|
92
|
-
* ) to obtain a formatter capable of generating timestamps in this format.
|
|
93
|
-
*
|
|
94
|
-
* protobuf-go-lite:disable-text
|
|
95
|
-
*
|
|
96
|
-
* @generated from message google.protobuf.Timestamp
|
|
97
|
-
*/
|
|
98
|
-
export interface Timestamp {
|
|
99
|
-
/**
|
|
100
|
-
* Represents seconds of UTC time since Unix epoch
|
|
101
|
-
* 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
|
102
|
-
* 9999-12-31T23:59:59Z inclusive.
|
|
103
|
-
*
|
|
104
|
-
* @generated from field: int64 seconds = 1;
|
|
105
|
-
*/
|
|
106
|
-
seconds?: bigint;
|
|
107
|
-
/**
|
|
108
|
-
* Non-negative fractions of a second at nanosecond resolution. Negative
|
|
109
|
-
* second values with fractions must still have non-negative nanos values
|
|
110
|
-
* that count forward in time. Must be from 0 to 999,999,999
|
|
111
|
-
* inclusive.
|
|
112
|
-
*
|
|
113
|
-
* @generated from field: int32 nanos = 2;
|
|
114
|
-
*/
|
|
115
|
-
nanos?: number;
|
|
116
|
-
}
|
|
117
|
-
declare const Timestamp_Wkt: {
|
|
118
|
-
fromJson(json: JsonValue): Timestamp;
|
|
119
|
-
toJson(msg: Timestamp): JsonValue;
|
|
120
|
-
toDate(msg: Timestamp | null | undefined): Date | null;
|
|
121
|
-
fromDate(value: Date | null | undefined): Timestamp;
|
|
122
|
-
equals(a: Timestamp | Date | undefined | null, b: Timestamp | Date | undefined | null): boolean;
|
|
123
|
-
};
|
|
124
|
-
export declare const Timestamp: MessageType<Timestamp> & typeof Timestamp_Wkt;
|
|
125
|
-
export {};
|
|
@@ -1,137 +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 { createMessageType, protoInt64, ScalarType } from "../../index.js";
|
|
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
|
-
if (!msg?.seconds && !msg?.nanos) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
return new Date(Number(msg.seconds ?? 0) * 1000 + Math.ceil((msg.nanos ?? 0) / 1000000));
|
|
96
|
-
},
|
|
97
|
-
fromDate(value) {
|
|
98
|
-
if (value == null) {
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
const ms = value.getTime();
|
|
102
|
-
const seconds = Math.floor(ms / 1000);
|
|
103
|
-
const nanos = (ms % 1000) * 1000000;
|
|
104
|
-
return { seconds: protoInt64.parse(seconds), nanos: nanos };
|
|
105
|
-
},
|
|
106
|
-
equals(a, b) {
|
|
107
|
-
const aDate = a instanceof Date ? a : Timestamp_Wkt.toDate(a);
|
|
108
|
-
const bDate = b instanceof Date ? b : Timestamp_Wkt.toDate(b);
|
|
109
|
-
if (aDate === bDate) {
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
if (aDate == null || bDate == null) {
|
|
113
|
-
return aDate === bDate;
|
|
114
|
-
}
|
|
115
|
-
return +aDate === +bDate;
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
// Timestamp contains the message type declaration for Timestamp.
|
|
119
|
-
export const Timestamp = createMessageType({
|
|
120
|
-
typeName: "google.protobuf.Timestamp",
|
|
121
|
-
fields: [
|
|
122
|
-
{ no: 1, name: "seconds", kind: "scalar", T: ScalarType.INT64 },
|
|
123
|
-
{ no: 2, name: "nanos", kind: "scalar", T: ScalarType.INT32 },
|
|
124
|
-
],
|
|
125
|
-
packedByDefault: true,
|
|
126
|
-
fieldWrapper: {
|
|
127
|
-
wrapField(value) {
|
|
128
|
-
if (value == null || value instanceof Date) {
|
|
129
|
-
return Timestamp_Wkt.fromDate(value);
|
|
130
|
-
}
|
|
131
|
-
return Timestamp.createComplete(value);
|
|
132
|
-
},
|
|
133
|
-
unwrapField(msg) {
|
|
134
|
-
return Timestamp_Wkt.toDate(msg);
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
}, Timestamp_Wkt);
|