@aptre/protobuf-es-lite 0.2.5 → 0.2.6

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.
@@ -1,5 +1,7 @@
1
- import type { DescExtension, DescField } from "@bufbuild/protobuf";
2
- import type { GeneratedFile, Printable, Schema } from "@bufbuild/protoplugin/ecmascript";
1
+ import type { DescEnum, DescExtension, DescField, DescFile, DescMessage } from "@bufbuild/protobuf";
2
+ import type { GeneratedFile, ImportSymbol, Printable, Schema } from "@bufbuild/protoplugin/ecmascript";
3
3
  export declare function generateTs(schema: Schema): void;
4
+ export declare function makeImportPath(file: DescFile): string;
4
5
  export declare function generateFieldInfo(f: GeneratedFile, field: DescField | DescExtension): void;
6
+ export declare const createTypeImport: (desc: DescMessage | DescEnum | DescExtension) => ImportSymbol;
5
7
  export declare function getFieldInfoLiteral(field: DescField | DescExtension): Printable;
@@ -14,7 +14,7 @@
14
14
  // See the License for the specific language governing permissions and
15
15
  // limitations under the License.
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getFieldInfoLiteral = exports.generateFieldInfo = exports.generateTs = void 0;
17
+ exports.getFieldInfoLiteral = exports.createTypeImport = exports.generateFieldInfo = exports.makeImportPath = exports.generateTs = void 0;
18
18
  const protobuf_1 = require("@bufbuild/protobuf");
19
19
  const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript");
20
20
  const editions_js_1 = require("./editions.js");
@@ -40,6 +40,9 @@ function generateTs(schema) {
40
40
  if (message.file !== file) {
41
41
  return;
42
42
  }
43
+ for (const nestedEnum of message.nestedEnums) {
44
+ generateEnum(f, nestedEnum);
45
+ }
43
46
  messageTypes.push(message);
44
47
  const deps = new Set();
45
48
  for (const field of message.fields) {
@@ -133,12 +136,6 @@ function generateMessage(schema, f, message) {
133
136
  f.print(" },");
134
137
  f.print(");");
135
138
  f.print();
136
- for (const nestedEnum of message.nestedEnums) {
137
- generateEnum(f, nestedEnum);
138
- }
139
- for (const nestedMessage of message.nestedMessages) {
140
- generateMessage(schema, f, nestedMessage);
141
- }
142
139
  }
143
140
  function generateField(f, field) {
144
141
  if (field.oneof) {
@@ -168,10 +165,23 @@ function generateOneof(f, oneof) {
168
165
  .flat();
169
166
  f.print(" ", oneof.name, "?: {\n value?: undefined,\n case: undefined\n }", oneOfCases, ";");
170
167
  }
168
+ function makeImportPath(file) {
169
+ return "./" + file.name + "_pb.js";
170
+ }
171
+ exports.makeImportPath = makeImportPath;
171
172
  function generateFieldInfo(f, field) {
172
173
  f.print(" ", getFieldInfoLiteral(field), ",");
173
174
  }
174
175
  exports.generateFieldInfo = generateFieldInfo;
176
+ const createTypeImport = (desc) => {
177
+ var name = (0, ecmascript_1.localName)(desc);
178
+ if (desc.kind === "enum") {
179
+ name += "_Enum";
180
+ }
181
+ const from = makeImportPath(desc.file);
182
+ return (0, ecmascript_1.createImportSymbol)(name, from);
183
+ };
184
+ exports.createTypeImport = createTypeImport;
175
185
  function getFieldInfoLiteral(field) {
176
186
  const e = [];
177
187
  e.push("{ no: ", field.number, `, `);
@@ -209,7 +219,7 @@ function getFieldInfoLiteral(field) {
209
219
  }
210
220
  break;
211
221
  case "enum":
212
- e.push(`kind: "enum", T: `, field.enum, `_Enum, `);
222
+ e.push(`kind: "enum", T: `, (0, exports.createTypeImport)(field.enum), `, `);
213
223
  break;
214
224
  }
215
225
  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.5",
4
+ "version": "0.2.6",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"