@aptre/protobuf-es-lite 0.4.9 → 0.5.0
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/json.js +2 -1
- package/dist/protoc-gen-es-lite/typescript.js +2 -2
- package/dist/util.js +4 -8
- package/package.json +11 -1
- package/tsconfig.base.json +1 -1
- package/tsconfig.json +8 -1
package/LICENSE
CHANGED
|
@@ -187,7 +187,8 @@
|
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
|
188
188
|
identification within third-party archives.
|
|
189
189
|
|
|
190
|
-
Copyright 2024 Aperture Robotics, LLC.
|
|
190
|
+
Copyright 2024-2025 Aperture Robotics, LLC.
|
|
191
|
+
Copyright 2024-2025 Christian Stewart <christian@aperture.us>
|
|
191
192
|
Copyright 2021-2024 Buf Technologies, Inc.
|
|
192
193
|
|
|
193
194
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -36,9 +36,10 @@ export function createDescriptorSet(input, options) {
|
|
|
36
36
|
extensions: new Map(),
|
|
37
37
|
mapEntries: new Map(),
|
|
38
38
|
};
|
|
39
|
-
const fileDescriptors = input instanceof Uint8Array ?
|
|
39
|
+
const fileDescriptors = input instanceof Uint8Array ?
|
|
40
|
+
(FileDescriptorSet.fromBinary(input).file ?? [])
|
|
40
41
|
: Array.isArray(input) ? input
|
|
41
|
-
: input.file ?? [];
|
|
42
|
+
: (input.file ?? []);
|
|
42
43
|
const resolverByEdition = new Map();
|
|
43
44
|
for (const proto of fileDescriptors) {
|
|
44
45
|
const edition = proto.edition || parseFileSyntax(proto.syntax, proto.edition).edition;
|
package/dist/enum.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface EnumValueInfo {
|
|
|
37
37
|
/**
|
|
38
38
|
* Create a new EnumType with the given values.
|
|
39
39
|
*/
|
|
40
|
-
export declare function createEnumType(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[]
|
|
40
|
+
export declare function createEnumType(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[]): EnumType;
|
|
41
41
|
export declare function enumInfoZeroValue(values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[]): number;
|
|
42
42
|
export declare function enumDescZeroValue(info: DescEnum): number;
|
|
43
43
|
export declare function enumZeroValue<T extends EnumType>(info: T): number;
|
package/dist/enum.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Create a new EnumType with the given values.
|
|
3
3
|
*/
|
|
4
|
-
export function createEnumType(typeName, values
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
_opt) {
|
|
4
|
+
export function createEnumType(typeName, values) {
|
|
7
5
|
const names = Object.create(null);
|
|
8
6
|
const numbers = Object.create(null);
|
|
9
7
|
const normalValues = [];
|
package/dist/json.js
CHANGED
|
@@ -383,8 +383,9 @@ function readScalar(type, json, longType = LongType.BIGINT, nullAsZeroValue = tr
|
|
|
383
383
|
// We validate with encodeURIComponent, which appears to be the fastest widely available option.
|
|
384
384
|
try {
|
|
385
385
|
encodeURIComponent(json);
|
|
386
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
386
387
|
}
|
|
387
|
-
catch (
|
|
388
|
+
catch (_e) {
|
|
388
389
|
throw new Error("invalid UTF8");
|
|
389
390
|
}
|
|
390
391
|
return json;
|
|
@@ -328,13 +328,13 @@ function generateWktMethods(schema, f, message, ref) {
|
|
|
328
328
|
f.print(" },");
|
|
329
329
|
f.print();
|
|
330
330
|
f.print(" unpack<T extends Message<T>>(msg: ", message, ", registry: ", IMessageTypeRegistry, "): {message: ", Message, "<T>, messageType: ", MessageType, "<T>} | undefined {");
|
|
331
|
-
f.print(" const typeUrl = msg.", localName(ref.typeUrl)
|
|
331
|
+
f.print(" const typeUrl = msg.", localName(ref.typeUrl), ";");
|
|
332
332
|
f.print(" const messageType = !!typeUrl && registry.findMessage<T>(typeUrl);");
|
|
333
333
|
f.print(" return messageType ? {message: messageType.fromBinary(msg.", localName(ref.value), "), messageType} : undefined;");
|
|
334
334
|
f.print(" },");
|
|
335
335
|
f.print();
|
|
336
336
|
f.print(" is(msg: ", message, ", msgType: ", MessageType, " | string): boolean {");
|
|
337
|
-
f.print(" const name = msg.", localName(ref.typeUrl)
|
|
337
|
+
f.print(" const name = msg.", localName(ref.typeUrl), ";");
|
|
338
338
|
f.print(" return !!name && (typeof msgType === 'string' ? name === msgType : name === msgType.typeName);");
|
|
339
339
|
f.print(" },");
|
|
340
340
|
break;
|
package/dist/util.js
CHANGED
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
|
-
import { FieldDescriptorProto_Label } from "./google/protobuf/descriptor.pb.js";
|
|
16
15
|
import { codegenInfo } from "./codegen-info.js";
|
|
17
16
|
import { LongType, ScalarType } from "./scalar.js";
|
|
18
17
|
import { localName } from "./names.js";
|
|
19
18
|
// unixMilliToDate converts the unix milliseconds bigint into a Date.
|
|
20
19
|
// Throws an error if the bigint is outside the safe range of Number values.
|
|
21
20
|
export function unixMilliToDate(unixMilliseconds) {
|
|
22
|
-
if (unixMilliseconds < -8640000000000000n ||
|
|
21
|
+
if (unixMilliseconds < -8640000000000000n ||
|
|
22
|
+
unixMilliseconds > 8640000000000000n) {
|
|
23
23
|
throw new Error("Timestamp is outside the range that can be safely represented by a JavaScript Date");
|
|
24
24
|
}
|
|
25
25
|
return new Date(Number(unixMilliseconds));
|
|
@@ -31,9 +31,7 @@ export function getFieldTypeInfo(field) {
|
|
|
31
31
|
switch (field.fieldKind) {
|
|
32
32
|
case "scalar":
|
|
33
33
|
typing.push(scalarTypeScriptType(field.scalar, field.longType));
|
|
34
|
-
optional =
|
|
35
|
-
field.optional ||
|
|
36
|
-
field.proto.label === FieldDescriptorProto_Label.REQUIRED;
|
|
34
|
+
optional = field.optional || field.proto.label === 2; // FieldDescriptorProto_Label.REQUIRED; avoid descriptor.pb.js import
|
|
37
35
|
typingInferrableFromZeroValue = true;
|
|
38
36
|
break;
|
|
39
37
|
case "message": {
|
|
@@ -48,9 +46,7 @@ export function getFieldTypeInfo(field) {
|
|
|
48
46
|
type: field.enum,
|
|
49
47
|
typeOnly: true,
|
|
50
48
|
});
|
|
51
|
-
optional =
|
|
52
|
-
field.optional ||
|
|
53
|
-
field.proto.label === FieldDescriptorProto_Label.REQUIRED;
|
|
49
|
+
optional = field.optional || field.proto.label === 2; // FieldDescriptorProto_Label.REQUIRED; avoid descriptor.pb.js import
|
|
54
50
|
typingInferrableFromZeroValue = true;
|
|
55
51
|
break;
|
|
56
52
|
case "map": {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptre/protobuf-es-lite",
|
|
3
3
|
"description": "Lightweight Protobuf codegen for TypeScript and JavaScript.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"
|
|
@@ -27,6 +27,16 @@
|
|
|
27
27
|
"require": "./dist/index.js",
|
|
28
28
|
"types": "./dist/index.d.ts"
|
|
29
29
|
},
|
|
30
|
+
"./descriptor-set": {
|
|
31
|
+
"import": "./dist/descriptor-set.js",
|
|
32
|
+
"require": "./dist/descriptor-set.js",
|
|
33
|
+
"types": "./dist/descriptor-set.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./create-descriptor-set": {
|
|
36
|
+
"import": "./dist/create-descriptor-set.js",
|
|
37
|
+
"require": "./dist/create-descriptor-set.js",
|
|
38
|
+
"types": "./dist/create-descriptor-set.d.ts"
|
|
39
|
+
},
|
|
30
40
|
"./protoplugin": {
|
|
31
41
|
"import": "./dist/protoplugin/index.js",
|
|
32
42
|
"require": "./dist/protoplugin/index.js",
|
package/tsconfig.base.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"files": [
|
|
2
|
+
"files": [
|
|
3
|
+
"src/protoc-gen-es-lite/protoc-gen-es-lite-plugin.ts",
|
|
4
|
+
"src/index.ts",
|
|
5
|
+
"src/descriptor-set.ts",
|
|
6
|
+
"src/create-descriptor-set.ts",
|
|
7
|
+
"src/protoplugin/index.ts",
|
|
8
|
+
"src/protoplugin/ecmascript/index.ts"
|
|
9
|
+
],
|
|
3
10
|
"extends": "./tsconfig.base.json",
|
|
4
11
|
"compilerOptions": {
|
|
5
12
|
"rootDir": "./src"
|