diff --git a/packages/protons-benchmark/src/decode.ts b/packages/protons-benchmark/src/decode.ts index 3d31254..271068f 100644 --- a/packages/protons-benchmark/src/decode.ts +++ b/packages/protons-benchmark/src/decode.ts @@ -44,7 +44,7 @@ new Benchmark.Suite() }) .on('complete', function () { // @ts-expect-error types are wrong - console.info(`Fastest is ${this.filter('fastest').map('name')}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions + console.info(`Fastest is ${this.filter('fastest').map('name')}`) }) // run async .run({ async: true }) diff --git a/packages/protons-benchmark/src/encode.ts b/packages/protons-benchmark/src/encode.ts index e911ccf..68fb964 100644 --- a/packages/protons-benchmark/src/encode.ts +++ b/packages/protons-benchmark/src/encode.ts @@ -42,7 +42,7 @@ new Benchmark.Suite() }) .on('complete', function () { // @ts-expect-error types are wrong - console.info(`Fastest is ${this.filter('fastest').map('name')}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions + console.info(`Fastest is ${this.filter('fastest').map('name')}`) }) // run async .run({ async: true }) diff --git a/packages/protons-benchmark/src/index.ts b/packages/protons-benchmark/src/index.ts index abfad85..ef2fb16 100644 --- a/packages/protons-benchmark/src/index.ts +++ b/packages/protons-benchmark/src/index.ts @@ -67,7 +67,7 @@ new Benchmark.Suite() }) .on('complete', function () { // @ts-expect-error types are wrong - console.info(`Fastest is ${this.filter('fastest').map('name')}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions + console.info(`Fastest is ${this.filter('fastest').map('name')}`) }) // run async .run({ async: true }) diff --git a/packages/protons-benchmark/src/rpc.ts b/packages/protons-benchmark/src/rpc.ts index da897b2..1cd33cf 100644 --- a/packages/protons-benchmark/src/rpc.ts +++ b/packages/protons-benchmark/src/rpc.ts @@ -43,7 +43,7 @@ new Benchmark.Suite() }) .on('complete', function () { // @ts-expect-error types are wrong - console.info(`Fastest is ${this.filter('fastest').map('name')}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions + console.info(`Fastest is ${this.filter('fastest').map('name')}`) }) // run async .run({ async: true }) diff --git a/packages/protons/package.json b/packages/protons/package.json index 93018da..a290755 100644 --- a/packages/protons/package.json +++ b/packages/protons/package.json @@ -162,7 +162,6 @@ "pbjs": "^0.0.14", "protobufjs": "^7.0.0", "protons-runtime": "^4.0.0", - "uint8arraylist": "^2.3.2", - "uint8arrays": "^4.0.2" + "uint8arraylist": "^2.3.2" } } diff --git a/packages/protons/src/index.ts b/packages/protons/src/index.ts index 693ed4d..cc1f554 100644 --- a/packages/protons/src/index.ts +++ b/packages/protons/src/index.ts @@ -595,6 +595,10 @@ function defineModule (def: ClassDef): ModuleDef { fieldDef.repeated = fieldDef.rule === 'repeated' fieldDef.optional = !fieldDef.repeated && fieldDef.options?.proto3_optional === true fieldDef.map = fieldDef.keyType != null + + if (fieldDef.rule === 'required') { + throw new Error('"required" fields are not allowed in proto3 - please convert your proto2 definitions to proto3') + } } } diff --git a/packages/protons/test/fixtures/proto2.proto b/packages/protons/test/fixtures/proto2.proto new file mode 100644 index 0000000..4284d80 --- /dev/null +++ b/packages/protons/test/fixtures/proto2.proto @@ -0,0 +1,5 @@ +syntax = "proto2"; + +message Message { + required string requiredField = 1; +} diff --git a/packages/protons/test/index.spec.ts b/packages/protons/test/index.spec.ts index 435814f..7ad8c56 100644 --- a/packages/protons/test/index.spec.ts +++ b/packages/protons/test/index.spec.ts @@ -1,5 +1,4 @@ /* eslint-env mocha */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ import { expect } from 'aegir/chai' import pbjs from 'pbjs' diff --git a/packages/protons/test/maps.spec.ts b/packages/protons/test/maps.spec.ts index dc1c58b..fdf004b 100644 --- a/packages/protons/test/maps.spec.ts +++ b/packages/protons/test/maps.spec.ts @@ -1,5 +1,4 @@ /* eslint-env mocha */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ import { expect } from 'aegir/chai' import { MapTypes, SubMessage } from './fixtures/maps.js' diff --git a/packages/protons/test/unsupported.spec.ts b/packages/protons/test/unsupported.spec.ts new file mode 100644 index 0000000..04759a9 --- /dev/null +++ b/packages/protons/test/unsupported.spec.ts @@ -0,0 +1,11 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/chai' +import { generate } from '../src/index.js' + +describe('unsupported', () => { + it('should refuse to generate source from proto2 definition', async () => { + await expect(generate('test/fixtures/proto2.proto', {})).to.eventually.be.rejected + .with.property('message').that.contain('"required" fields are not allowed in proto3') + }) +})