Skip to content

Commit

Permalink
feat: Upgrade to long 5.0.0. (#882)
Browse files Browse the repository at this point in the history
* feat: Upgrade to long 5.0.0.

* Use import require for Long w/o esModuleInterop.

* Update tests.

* Er, undo importSuffix addition.
  • Loading branch information
stephenh authored Jul 15, 2023
1 parent da1eadf commit 4c1e7a6
Show file tree
Hide file tree
Showing 78 changed files with 204 additions and 704 deletions.
2 changes: 1 addition & 1 deletion integration/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@angular/platform-browser": "~9.1.9",
"@angular/platform-browser-dynamic": "~9.1.9",
"@angular/router": "~9.1.9",
"long": "^4.0.0",
"long": "^5.0.0",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
Expand Down
4 changes: 1 addition & 3 deletions integration/bytes-node/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -678,8 +678,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
148 changes: 74 additions & 74 deletions integration/extensions/extensions-test.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
import { Extendable, Nested, packed, repeated, bytes, string, long, fixed, enumField, group, Enum } from './test';
import * as Long from 'long';
import { Extendable, Nested, packed, repeated, bytes, string, long, fixed, enumField, group, Enum } from "./test";
import Long = require("long");

describe('extensions-test', () => {
it('works with namespaced extensions', () => {
const test: Extendable = {
field: 'hello'
};
describe("extensions-test", () => {
it("works with namespaced extensions", () => {
const test: Extendable = {
field: "hello",
};

const extensionData = [
{
field: 'a'
},
{
field: 'b'
}
];
const extensionData = [
{
field: "a",
},
{
field: "b",
},
];

Extendable.setExtension(test, Nested.message, extensionData);
Extendable.setExtension(test, Nested.message, extensionData);

const encoded = Extendable.encode(test).finish();
const result = Extendable.decode(encoded);
const encoded = Extendable.encode(test).finish();
const result = Extendable.decode(encoded);

expect(result).toEqual(test);
expect(result).toEqual(test);

const extension = Extendable.getExtension(result, Nested.message);
const extension = Extendable.getExtension(result, Nested.message);

expect(extension).toEqual(extensionData);
expect(extension).toEqual(extensionData);

const unsetExtension = Extendable.getExtension(result, packed);
const unsetExtension = Extendable.getExtension(result, packed);

expect(unsetExtension).toEqual(undefined);
});
expect(unsetExtension).toEqual(undefined);
});

it('works with repeated fields', () => {
const test: Extendable = {
field: 'repeated',
it("works with repeated fields", () => {
const test: Extendable = {
field: "repeated",

_unknownFields: {
[(6 << 3) | 2]: [Buffer.from([1, 1]), Buffer.from([1, 1])],
[(6 << 3) | 0]: [Buffer.from([2]), Buffer.from([3]), Buffer.from([5])]
}
};
_unknownFields: {
[(6 << 3) | 2]: [Buffer.from([1, 1]), Buffer.from([1, 1])],
[(6 << 3) | 0]: [Buffer.from([2]), Buffer.from([3]), Buffer.from([5])],
},
};

const extensionData = [1, 2, 3, 4, 5];
const extensionData = [1, 2, 3, 4, 5];

Extendable.setExtension(test, packed, extensionData);
Extendable.setExtension(test, packed, extensionData);

const encoded = Extendable.encode(test).finish();
const result = Extendable.decode(encoded);
const encoded = Extendable.encode(test).finish();
const result = Extendable.decode(encoded);

expect(result).toEqual(test);
expect(result).toEqual(test);

const extension = Extendable.getExtension(result, packed);
const extension = Extendable.getExtension(result, packed);

expect(extension).toEqual(extensionData);
expect(extension).toEqual(extensionData);

expect(Extendable.getExtension(result, repeated)).toEqual([1, 1, 2, 3, 5]);
expect(Extendable.getExtension(result, repeated)).toEqual([1, 1, 2, 3, 5]);

const unsetExtension = Extendable.getExtension(result, Nested.message);
const unsetExtension = Extendable.getExtension(result, Nested.message);

expect(unsetExtension).toEqual(undefined);
});
expect(unsetExtension).toEqual(undefined);
});

it('works with various field types', () => {
const test: Extendable = {
field: 'various'
};
it("works with various field types", () => {
const test: Extendable = {
field: "various",
};

const bytesExtensionData = Buffer.from([2, 3, 5, 7, 11]);
const stringExtensionData = "this is a string";
const longExtensionData = new Long(0x89ABCDEF, 0x01234567, false);
const fixedExtensionData = new Long(0x01234567, 0x89ABCDEF, true);
const enumExtensionData = Enum.ENUM_ONE;
const groupExtensionData = {
name: 'this is',
value: 'a group'
};
const bytesExtensionData = Buffer.from([2, 3, 5, 7, 11]);
const stringExtensionData = "this is a string";
const longExtensionData = new Long(0x89abcdef, 0x01234567, false);
const fixedExtensionData = new Long(0x01234567, 0x89abcdef, true);
const enumExtensionData = Enum.ENUM_ONE;
const groupExtensionData = {
name: "this is",
value: "a group",
};

Extendable.setExtension(test, bytes, bytesExtensionData);
Extendable.setExtension(test, string, stringExtensionData);
Extendable.setExtension(test, long, longExtensionData);
Extendable.setExtension(test, fixed, fixedExtensionData);
Extendable.setExtension(test, enumField, enumExtensionData);
Extendable.setExtension(test, group, groupExtensionData);
Extendable.setExtension(test, bytes, bytesExtensionData);
Extendable.setExtension(test, string, stringExtensionData);
Extendable.setExtension(test, long, longExtensionData);
Extendable.setExtension(test, fixed, fixedExtensionData);
Extendable.setExtension(test, enumField, enumExtensionData);
Extendable.setExtension(test, group, groupExtensionData);

const encoded = Extendable.encode(test).finish();
const result = Extendable.decode(encoded);
const encoded = Extendable.encode(test).finish();
const result = Extendable.decode(encoded);

expect(result).toEqual(test);
expect(result).toEqual(test);

expect( Extendable.getExtension(result, bytes) ).toEqual(bytesExtensionData);
expect( Extendable.getExtension(result, string) ).toEqual(stringExtensionData);
expect( Extendable.getExtension(result, long) ).toEqual(longExtensionData);
expect( Extendable.getExtension(result, fixed) ).toEqual(fixedExtensionData);
expect( Extendable.getExtension(result, enumField) ).toEqual(enumExtensionData);
expect( Extendable.getExtension(result, group) ).toEqual(groupExtensionData);
expect(Extendable.getExtension(result, bytes)).toEqual(bytesExtensionData);
expect(Extendable.getExtension(result, string)).toEqual(stringExtensionData);
expect(Extendable.getExtension(result, long)).toEqual(longExtensionData);
expect(Extendable.getExtension(result, fixed)).toEqual(fixedExtensionData);
expect(Extendable.getExtension(result, enumField)).toEqual(enumExtensionData);
expect(Extendable.getExtension(result, group)).toEqual(groupExtensionData);

const unsetExtension = Extendable.getExtension(result, Nested.message);
const unsetExtension = Extendable.getExtension(result, Nested.message);

expect(unsetExtension).toEqual(undefined);
});
expect(unsetExtension).toEqual(undefined);
});
});
4 changes: 1 addition & 3 deletions integration/extensions/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import * as Long from "long";
import Long = require("long");
import * as _m0 from "protobufjs/minimal";

export const protobufPackage = "";
Expand Down Expand Up @@ -608,8 +608,6 @@ type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
4 changes: 1 addition & 3 deletions integration/file-suffix/google/protobuf/timestamp.pb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -223,8 +223,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -223,8 +223,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -223,8 +223,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -223,8 +223,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
4 changes: 1 addition & 3 deletions integration/grpc-js/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -223,8 +223,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
4 changes: 1 addition & 3 deletions integration/grpc-js/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -678,8 +678,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
4 changes: 1 addition & 3 deletions integration/import-mapping/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -223,8 +223,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
4 changes: 1 addition & 3 deletions integration/import-suffix/google/protobuf/timestamp.pb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal.js";
import Long = require("long");

export const protobufPackage = "google.protobuf";

Expand Down Expand Up @@ -223,8 +223,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
4 changes: 1 addition & 3 deletions integration/map-bigint-optional/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import * as Long from "long";
import * as _m0 from "protobufjs/minimal";
import Long = require("long");

export const protobufPackage = "";

Expand Down Expand Up @@ -241,8 +241,6 @@ function longToBigint(long: Long) {
return BigInt(long.toString());
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
4 changes: 1 addition & 3 deletions integration/map-long-optional/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import * as Long from "long";
import Long = require("long");
import * as _m0 from "protobufjs/minimal";

export const protobufPackage = "";
Expand Down Expand Up @@ -264,8 +264,6 @@ function longToNumber(long: Long): number {
return long.toNumber();
}

// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down
Loading

0 comments on commit 4c1e7a6

Please sign in to comment.