Skip to content

Commit ef5a644

Browse files
committed
Wire initial typescript
1 parent d85ddaa commit ef5a644

76 files changed

Lines changed: 12971 additions & 1051 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint.config.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export default tseslint.config(
5151
},
5252
},
5353
{
54-
ignores: ['dist'],
54+
files: ['lib/**/*.js'],
55+
// ignores: ['dist'],
5556
languageOptions: {
5657
ecmaVersion: 2025,
5758
sourceType: 'module',
@@ -213,15 +214,28 @@ export default tseslint.config(
213214
'no-restricted-modules': 0,
214215
'no-sync': 0,
215216
'no-async-promise-executor': 0,
217+
218+
"no-restricted-imports": ["error", {
219+
"patterns": [{
220+
"regex": ".*\\.ts",
221+
"message": "Do not import typescript files. Import them with *.js"
222+
}]
223+
}]
216224
},
217225
},
218226
{
219-
languageOptions: {
227+
languageOptions: {
220228
parser: tseslint.parser,
221229
parserOptions: {
222230
projectService: true,
223231
tsconfigRootDir: import.meta.dirname,
224232
},
225233
},
226234
},
235+
tseslint.configs.eslintRecommended,
236+
{
237+
rules: {
238+
"prefer-const": "off"
239+
}
240+
}
227241
)

google/protobuf/any.ts

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
// @generated by protobuf-ts 2.11.1
2+
// @generated from protobuf file "google/protobuf/any.proto" (package "google.protobuf", syntax proto3)
3+
// tslint:disable
4+
//
5+
// Protocol Buffers - Google's data interchange format
6+
// Copyright 2008 Google Inc. All rights reserved.
7+
// https://developers.google.com/protocol-buffers/
8+
//
9+
// Redistribution and use in source and binary forms, with or without
10+
// modification, are permitted provided that the following conditions are
11+
// met:
12+
//
13+
// * Redistributions of source code must retain the above copyright
14+
// notice, this list of conditions and the following disclaimer.
15+
// * Redistributions in binary form must reproduce the above
16+
// copyright notice, this list of conditions and the following disclaimer
17+
// in the documentation and/or other materials provided with the
18+
// distribution.
19+
// * Neither the name of Google Inc. nor the names of its
20+
// contributors may be used to endorse or promote products derived from
21+
// this software without specific prior written permission.
22+
//
23+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
//
35+
import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
36+
import type { IBinaryWriter } from "@protobuf-ts/runtime";
37+
import { WireType } from "@protobuf-ts/runtime";
38+
import type { IBinaryReader } from "@protobuf-ts/runtime";
39+
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
40+
import type { PartialMessage } from "@protobuf-ts/runtime";
41+
import { reflectionMergePartial } from "@protobuf-ts/runtime";
42+
import { isJsonObject } from "@protobuf-ts/runtime";
43+
import { typeofJsonValue } from "@protobuf-ts/runtime";
44+
import type { JsonValue } from "@protobuf-ts/runtime";
45+
import { jsonWriteOptions } from "@protobuf-ts/runtime";
46+
import type { JsonReadOptions } from "@protobuf-ts/runtime";
47+
import type { JsonWriteOptions } from "@protobuf-ts/runtime";
48+
import type { BinaryReadOptions } from "@protobuf-ts/runtime";
49+
import type { IMessageType } from "@protobuf-ts/runtime";
50+
import { MessageType } from "@protobuf-ts/runtime";
51+
/**
52+
* `Any` contains an arbitrary serialized protocol buffer message along with a
53+
* URL that describes the type of the serialized message.
54+
*
55+
* Protobuf library provides support to pack/unpack Any values in the form
56+
* of utility functions or additional generated methods of the Any type.
57+
*
58+
* Example 1: Pack and unpack a message in C++.
59+
*
60+
* Foo foo = ...;
61+
* Any any;
62+
* any.PackFrom(foo);
63+
* ...
64+
* if (any.UnpackTo(&foo)) {
65+
* ...
66+
* }
67+
*
68+
* Example 2: Pack and unpack a message in Java.
69+
*
70+
* Foo foo = ...;
71+
* Any any = Any.pack(foo);
72+
* ...
73+
* if (any.is(Foo.class)) {
74+
* foo = any.unpack(Foo.class);
75+
* }
76+
* // or ...
77+
* if (any.isSameTypeAs(Foo.getDefaultInstance())) {
78+
* foo = any.unpack(Foo.getDefaultInstance());
79+
* }
80+
*
81+
* Example 3: Pack and unpack a message in Python.
82+
*
83+
* foo = Foo(...)
84+
* any = Any()
85+
* any.Pack(foo)
86+
* ...
87+
* if any.Is(Foo.DESCRIPTOR):
88+
* any.Unpack(foo)
89+
* ...
90+
*
91+
* Example 4: Pack and unpack a message in Go
92+
*
93+
* foo := &pb.Foo{...}
94+
* any, err := anypb.New(foo)
95+
* if err != nil {
96+
* ...
97+
* }
98+
* ...
99+
* foo := &pb.Foo{}
100+
* if err := any.UnmarshalTo(foo); err != nil {
101+
* ...
102+
* }
103+
*
104+
* The pack methods provided by protobuf library will by default use
105+
* 'type.googleapis.com/full.type.name' as the type URL and the unpack
106+
* methods only use the fully qualified type name after the last '/'
107+
* in the type URL, for example "foo.bar.com/x/y.z" will yield type
108+
* name "y.z".
109+
*
110+
* JSON
111+
* ====
112+
* The JSON representation of an `Any` value uses the regular
113+
* representation of the deserialized, embedded message, with an
114+
* additional field `@type` which contains the type URL. Example:
115+
*
116+
* package google.profile;
117+
* message Person {
118+
* string first_name = 1;
119+
* string last_name = 2;
120+
* }
121+
*
122+
* {
123+
* "@type": "type.googleapis.com/google.profile.Person",
124+
* "firstName": <string>,
125+
* "lastName": <string>
126+
* }
127+
*
128+
* If the embedded message type is well-known and has a custom JSON
129+
* representation, that representation will be embedded adding a field
130+
* `value` which holds the custom JSON in addition to the `@type`
131+
* field. Example (for message [google.protobuf.Duration][]):
132+
*
133+
* {
134+
* "@type": "type.googleapis.com/google.protobuf.Duration",
135+
* "value": "1.212s"
136+
* }
137+
*
138+
*
139+
* @generated from protobuf message google.protobuf.Any
140+
*/
141+
export interface Any {
142+
/**
143+
* A URL/resource name that uniquely identifies the type of the serialized
144+
* protocol buffer message. This string must contain at least
145+
* one "/" character. The last segment of the URL's path must represent
146+
* the fully qualified name of the type (as in
147+
* `path/google.protobuf.Duration`). The name should be in a canonical form
148+
* (e.g., leading "." is not accepted).
149+
*
150+
* In practice, teams usually precompile into the binary all types that they
151+
* expect it to use in the context of Any. However, for URLs which use the
152+
* scheme `http`, `https`, or no scheme, one can optionally set up a type
153+
* server that maps type URLs to message definitions as follows:
154+
*
155+
* * If no scheme is provided, `https` is assumed.
156+
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
157+
* value in binary format, or produce an error.
158+
* * Applications are allowed to cache lookup results based on the
159+
* URL, or have them precompiled into a binary to avoid any
160+
* lookup. Therefore, binary compatibility needs to be preserved
161+
* on changes to types. (Use versioned type names to manage
162+
* breaking changes.)
163+
*
164+
* Note: this functionality is not currently available in the official
165+
* protobuf release, and it is not used for type URLs beginning with
166+
* type.googleapis.com. As of May 2023, there are no widely used type server
167+
* implementations and no plans to implement one.
168+
*
169+
* Schemes other than `http`, `https` (or the empty scheme) might be
170+
* used with implementation specific semantics.
171+
*
172+
*
173+
* @generated from protobuf field: string type_url = 1
174+
*/
175+
typeUrl: string;
176+
/**
177+
* Must be a valid serialized protocol buffer of the above specified type.
178+
*
179+
* @generated from protobuf field: bytes value = 2
180+
*/
181+
value: Uint8Array;
182+
}
183+
// @generated message type with reflection information, may provide speed optimized methods
184+
class Any$Type extends MessageType<Any> {
185+
constructor() {
186+
super("google.protobuf.Any", [
187+
{ no: 1, name: "type_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
188+
{ no: 2, name: "value", kind: "scalar", T: 12 /*ScalarType.BYTES*/ }
189+
]);
190+
}
191+
/**
192+
* Pack the message into a new `Any`.
193+
*
194+
* Uses 'type.googleapis.com/full.type.name' as the type URL.
195+
*/
196+
pack<T extends object>(message: T, type: IMessageType<T>): Any {
197+
return {
198+
typeUrl: this.typeNameToUrl(type.typeName), value: type.toBinary(message),
199+
};
200+
}
201+
/**
202+
* Unpack the message from the `Any`.
203+
*/
204+
unpack<T extends object>(any: Any, type: IMessageType<T>, options?: Partial<BinaryReadOptions>): T {
205+
if (!this.contains(any, type))
206+
throw new Error("Cannot unpack google.protobuf.Any with typeUrl '" + any.typeUrl + "' as " + type.typeName + ".");
207+
return type.fromBinary(any.value, options);
208+
}
209+
/**
210+
* Does the given `Any` contain a packed message of the given type?
211+
*/
212+
contains(any: Any, type: IMessageType<any> | string): boolean {
213+
if (!any.typeUrl.length)
214+
return false;
215+
let wants = typeof type == "string" ? type : type.typeName;
216+
let has = this.typeUrlToName(any.typeUrl);
217+
return wants === has;
218+
}
219+
/**
220+
* Convert the message to canonical JSON value.
221+
*
222+
* You have to provide the `typeRegistry` option so that the
223+
* packed message can be converted to JSON.
224+
*
225+
* The `typeRegistry` option is also required to read
226+
* `google.protobuf.Any` from JSON format.
227+
*/
228+
internalJsonWrite(any: Any, options: JsonWriteOptions): JsonValue {
229+
if (any.typeUrl === "")
230+
return {};
231+
let typeName = this.typeUrlToName(any.typeUrl);
232+
let opt = jsonWriteOptions(options);
233+
let type = opt.typeRegistry?.find(t => t.typeName === typeName);
234+
if (!type)
235+
throw new globalThis.Error("Unable to convert google.protobuf.Any with typeUrl '" + any.typeUrl + "' to JSON. The specified type " + typeName + " is not available in the type registry.");
236+
let value = type.fromBinary(any.value, { readUnknownField: false });
237+
let json = type.internalJsonWrite(value, opt);
238+
if (typeName.startsWith("google.protobuf.") || !isJsonObject(json))
239+
json = { value: json };
240+
json["@type"] = any.typeUrl;
241+
return json;
242+
}
243+
internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Any): Any {
244+
if (!isJsonObject(json))
245+
throw new globalThis.Error("Unable to parse google.protobuf.Any from JSON " + typeofJsonValue(json) + ".");
246+
if (typeof json["@type"] != "string" || json["@type"] == "")
247+
return this.create();
248+
let typeName = this.typeUrlToName(json["@type"]);
249+
let type = options?.typeRegistry?.find(t => t.typeName == typeName);
250+
if (!type)
251+
throw new globalThis.Error("Unable to parse google.protobuf.Any from JSON. The specified type " + typeName + " is not available in the type registry.");
252+
let value;
253+
if (typeName.startsWith("google.protobuf.") && json.hasOwnProperty("value"))
254+
value = type.fromJson(json["value"], options);
255+
else {
256+
let copy = Object.assign({}, json);
257+
delete copy["@type"];
258+
value = type.fromJson(copy, options);
259+
}
260+
if (target === undefined)
261+
target = this.create();
262+
target.typeUrl = json["@type"];
263+
target.value = type.toBinary(value);
264+
return target;
265+
}
266+
typeNameToUrl(name: string): string {
267+
if (!name.length)
268+
throw new Error("invalid type name: " + name);
269+
return "type.googleapis.com/" + name;
270+
}
271+
typeUrlToName(url: string): string {
272+
if (!url.length)
273+
throw new Error("invalid type url: " + url);
274+
let slash = url.lastIndexOf("/");
275+
let name = slash > 0 ? url.substring(slash + 1) : url;
276+
if (!name.length)
277+
throw new Error("invalid type url: " + url);
278+
return name;
279+
}
280+
create(value?: PartialMessage<Any>): Any {
281+
const message = globalThis.Object.create((this.messagePrototype!));
282+
message.typeUrl = "";
283+
message.value = new Uint8Array(0);
284+
if (value !== undefined)
285+
reflectionMergePartial<Any>(this, message, value);
286+
return message;
287+
}
288+
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Any): Any {
289+
let message = target ?? this.create(), end = reader.pos + length;
290+
while (reader.pos < end) {
291+
let [fieldNo, wireType] = reader.tag();
292+
switch (fieldNo) {
293+
case /* string type_url */ 1:
294+
message.typeUrl = reader.string();
295+
break;
296+
case /* bytes value */ 2:
297+
message.value = reader.bytes();
298+
break;
299+
default:
300+
let u = options.readUnknownField;
301+
if (u === "throw")
302+
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
303+
let d = reader.skip(wireType);
304+
if (u !== false)
305+
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
306+
}
307+
}
308+
return message;
309+
}
310+
internalBinaryWrite(message: Any, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
311+
/* string type_url = 1; */
312+
if (message.typeUrl !== "")
313+
writer.tag(1, WireType.LengthDelimited).string(message.typeUrl);
314+
/* bytes value = 2; */
315+
if (message.value.length)
316+
writer.tag(2, WireType.LengthDelimited).bytes(message.value);
317+
let u = options.writeUnknownFields;
318+
if (u !== false)
319+
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
320+
return writer;
321+
}
322+
}
323+
/**
324+
* @generated MessageType for protobuf message google.protobuf.Any
325+
*/
326+
export const Any = new Any$Type();

lib/cli/please.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import './index.ts'
1+
import './index.js'

0 commit comments

Comments
 (0)