@aptre/protobuf-es-lite 0.2.3 → 0.2.5
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/enum.d.ts +6 -0
- package/dist/enum.js +41 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/typescript.js +23 -16
- package/package.json +1 -1
package/dist/enum.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EnumType, EnumValueInfo } from "@bufbuild/protobuf";
|
|
2
|
+
export declare function normalizeEnumValue(value: EnumValueInfo | Omit<EnumValueInfo, "localName">): EnumValueInfo;
|
|
3
|
+
/**
|
|
4
|
+
* Create a new EnumType with the given values.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createEnumType(typeName: string, values: (EnumValueInfo | Omit<EnumValueInfo, "localName">)[], _opt?: {}): EnumType;
|
package/dist/enum.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEnumType = exports.normalizeEnumValue = void 0;
|
|
4
|
+
function normalizeEnumValue(value) {
|
|
5
|
+
if ("localName" in value) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
return { ...value, localName: value.name };
|
|
9
|
+
}
|
|
10
|
+
exports.normalizeEnumValue = normalizeEnumValue;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new EnumType with the given values.
|
|
13
|
+
*/
|
|
14
|
+
function createEnumType(typeName, values,
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
_opt) {
|
|
17
|
+
const names = Object.create(null);
|
|
18
|
+
const numbers = Object.create(null);
|
|
19
|
+
const normalValues = [];
|
|
20
|
+
for (const value of values) {
|
|
21
|
+
// We do not surface options at this time
|
|
22
|
+
// const value: EnumValueInfo = {...v, options: v.options ?? emptyReadonlyObject};
|
|
23
|
+
const n = normalizeEnumValue(value);
|
|
24
|
+
normalValues.push(n);
|
|
25
|
+
names[value.name] = n;
|
|
26
|
+
numbers[value.no] = n;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
typeName,
|
|
30
|
+
values: normalValues,
|
|
31
|
+
// We do not surface options at this time
|
|
32
|
+
// options: opt?.options ?? Object.create(null),
|
|
33
|
+
findName(name) {
|
|
34
|
+
return names[name];
|
|
35
|
+
},
|
|
36
|
+
findNumber(no) {
|
|
37
|
+
return numbers[no];
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.createEnumType = createEnumType;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { EnumType, EnumValue, EnumValueInfo, ScalarType, WireType, LongType, } from "@bufbuild/protobuf";
|
|
1
2
|
export { Message, CompleteMessage, AnyMessage, MessageType, Field, CompleteField, compareMessages, createMessageType, } from "./message.js";
|
|
2
3
|
export { isCompleteMessage, isCompleteField } from "./is-message.js";
|
|
3
4
|
export { newFieldList, FieldList, PartialFieldInfo, FieldInfo, OneofInfo, fieldJsonName, localFieldName, localOneofName, } from "./field.js";
|
|
4
5
|
export { scalarEquals, scalarZeroValue, isScalarZeroValue } from "./scalar.js";
|
|
6
|
+
export { createEnumType, normalizeEnumValue } from "./enum.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isScalarZeroValue = exports.scalarZeroValue = exports.scalarEquals = exports.localOneofName = exports.localFieldName = exports.fieldJsonName = exports.FieldList = exports.newFieldList = exports.isCompleteField = exports.isCompleteMessage = exports.createMessageType = exports.compareMessages = void 0;
|
|
3
|
+
exports.normalizeEnumValue = exports.createEnumType = exports.isScalarZeroValue = exports.scalarZeroValue = exports.scalarEquals = exports.localOneofName = exports.localFieldName = exports.fieldJsonName = exports.FieldList = exports.newFieldList = exports.isCompleteField = exports.isCompleteMessage = exports.createMessageType = exports.compareMessages = exports.LongType = exports.WireType = exports.ScalarType = exports.EnumValue = void 0;
|
|
4
|
+
var protobuf_1 = require("@bufbuild/protobuf");
|
|
5
|
+
Object.defineProperty(exports, "EnumValue", { enumerable: true, get: function () { return protobuf_1.EnumValue; } });
|
|
6
|
+
Object.defineProperty(exports, "ScalarType", { enumerable: true, get: function () { return protobuf_1.ScalarType; } });
|
|
7
|
+
Object.defineProperty(exports, "WireType", { enumerable: true, get: function () { return protobuf_1.WireType; } });
|
|
8
|
+
Object.defineProperty(exports, "LongType", { enumerable: true, get: function () { return protobuf_1.LongType; } });
|
|
4
9
|
var message_js_1 = require("./message.js");
|
|
5
10
|
Object.defineProperty(exports, "compareMessages", { enumerable: true, get: function () { return message_js_1.compareMessages; } });
|
|
6
11
|
Object.defineProperty(exports, "createMessageType", { enumerable: true, get: function () { return message_js_1.createMessageType; } });
|
|
@@ -17,3 +22,6 @@ var scalar_js_1 = require("./scalar.js");
|
|
|
17
22
|
Object.defineProperty(exports, "scalarEquals", { enumerable: true, get: function () { return scalar_js_1.scalarEquals; } });
|
|
18
23
|
Object.defineProperty(exports, "scalarZeroValue", { enumerable: true, get: function () { return scalar_js_1.scalarZeroValue; } });
|
|
19
24
|
Object.defineProperty(exports, "isScalarZeroValue", { enumerable: true, get: function () { return scalar_js_1.isScalarZeroValue; } });
|
|
25
|
+
var enum_js_1 = require("./enum.js");
|
|
26
|
+
Object.defineProperty(exports, "createEnumType", { enumerable: true, get: function () { return enum_js_1.createEnumType; } });
|
|
27
|
+
Object.defineProperty(exports, "normalizeEnumValue", { enumerable: true, get: function () { return enum_js_1.normalizeEnumValue; } });
|
package/dist/typescript.js
CHANGED
|
@@ -24,6 +24,7 @@ const MessageImport = (0, ecmascript_1.createImportSymbol)("Message", libPkg);
|
|
|
24
24
|
const MessageTypeImport = (0, ecmascript_1.createImportSymbol)("MessageType", libPkg);
|
|
25
25
|
const CreateMessageTypeImport = (0, ecmascript_1.createImportSymbol)("createMessageType", libPkg);
|
|
26
26
|
const PartialFieldInfo = (0, ecmascript_1.createImportSymbol)("PartialFieldInfo", libPkg);
|
|
27
|
+
const CreateEnumTypeImport = (0, ecmascript_1.createImportSymbol)("createEnumType", libPkg);
|
|
27
28
|
function generateTs(schema) {
|
|
28
29
|
for (const file of schema.files) {
|
|
29
30
|
const f = schema.generateFile(file.name + "_pb.ts");
|
|
@@ -36,24 +37,30 @@ function generateTs(schema) {
|
|
|
36
37
|
const messageTypes = [];
|
|
37
38
|
const dependencies = new Map();
|
|
38
39
|
function collectMessages(message) {
|
|
39
|
-
if (message.file
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
if (message.file !== file) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
messageTypes.push(message);
|
|
44
|
+
const deps = new Set();
|
|
45
|
+
for (const field of message.fields) {
|
|
46
|
+
if (field.fieldKind === "message" && field.message.file === file) {
|
|
47
|
+
deps.add(field.message);
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
else if (field.fieldKind === "map" &&
|
|
50
|
+
field.mapValue.kind === "message" &&
|
|
51
|
+
field.mapValue.message.file === file) {
|
|
52
|
+
deps.add(field.mapValue.message);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
55
|
+
dependencies.set(message, deps);
|
|
56
|
+
for (const nestedMessage of message.nestedMessages) {
|
|
57
|
+
collectMessages(nestedMessage);
|
|
58
|
+
}
|
|
52
59
|
}
|
|
53
60
|
for (const message of file.messages) {
|
|
54
61
|
collectMessages(message);
|
|
55
62
|
}
|
|
56
|
-
// Topological sort
|
|
63
|
+
// Topological sort to ensure consts are declared in the right order.
|
|
57
64
|
const sortedMessageTypes = topologicalSort(messageTypes, dependencies);
|
|
58
65
|
for (const message of sortedMessageTypes) {
|
|
59
66
|
generateMessage(schema, f, message);
|
|
@@ -92,12 +99,12 @@ function generateEnum(f, enumeration) {
|
|
|
92
99
|
}
|
|
93
100
|
f.print("}");
|
|
94
101
|
f.print();
|
|
95
|
-
f.print("// ", enumeration, "
|
|
96
|
-
f.print(f.exportDecl("const", enumeration.name + "
|
|
102
|
+
f.print("// ", enumeration, "_Enum is the enum type for ", enumeration, ".");
|
|
103
|
+
f.print(f.exportDecl("const", enumeration.name + "_Enum"), " = ", CreateEnumTypeImport, "(", f.string(enumeration.typeName), ", [");
|
|
97
104
|
for (const value of enumeration.values) {
|
|
98
|
-
f.print(" ",
|
|
105
|
+
f.print(" { no: ", value.number, ', name: "', value.name, '" },');
|
|
99
106
|
}
|
|
100
|
-
f.print("
|
|
107
|
+
f.print("]);");
|
|
101
108
|
f.print();
|
|
102
109
|
}
|
|
103
110
|
function generateMessage(schema, f, message) {
|
|
@@ -202,7 +209,7 @@ function getFieldInfoLiteral(field) {
|
|
|
202
209
|
}
|
|
203
210
|
break;
|
|
204
211
|
case "enum":
|
|
205
|
-
e.push(`kind: "enum", T: `, field.enum,
|
|
212
|
+
e.push(`kind: "enum", T: `, field.enum, `_Enum, `);
|
|
206
213
|
break;
|
|
207
214
|
}
|
|
208
215
|
if (field.repeated) {
|
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.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"
|