Skip to content

Commit ce07c78

Browse files
authored
Merge pull request #430 from MatrixAI/feature-swc_fix
Fixing `swc` specific bug with decorators and constructors
2 parents 07b5fe6 + dd4a38e commit ce07c78

23 files changed

+47
-75
lines changed

src/PolykeyAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class PolykeyAgent {
383383
await status?.stop({});
384384
throw e;
385385
}
386-
const pkAgent = new PolykeyAgent({
386+
const pkAgent = new this({
387387
nodePath,
388388
status,
389389
schema,

src/PolykeyClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class PolykeyClient {
6969
timer,
7070
logger: logger.getChild(GRPCClientClient.name),
7171
}));
72-
const pkClient = new PolykeyClient({
72+
const pkClient = new this({
7373
nodePath,
7474
grpcClient,
7575
session,

src/acl/ACL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ACL {
3636
fresh?: boolean;
3737
}): Promise<ACL> {
3838
logger.info(`Creating ${this.name}`);
39-
const acl = new ACL({ db, logger });
39+
const acl = new this({ db, logger });
4040
await acl.start({ fresh });
4141
logger.info(`Created ${this.name}`);
4242
return acl;

src/agent/GRPCClientAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class GRPCClientAgent extends GRPCClient<AgentServiceClient> {
5757
timer,
5858
logger,
5959
});
60-
const grpcClientAgent = new GRPCClientAgent({
60+
const grpcClientAgent = new this({
6161
client,
6262
nodeId,
6363
host,

src/client/GRPCClientClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class GRPCClientClient extends GRPCClient<ClientServiceClient> {
6969
interceptors,
7070
logger,
7171
});
72-
return new GRPCClientClient({
72+
return new this({
7373
client,
7474
nodeId,
7575
host,

src/discovery/Discovery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Discovery {
6161
fresh?: boolean;
6262
}): Promise<Discovery> {
6363
logger.info(`Creating ${this.name}`);
64-
const discovery = new Discovery({
64+
const discovery = new this({
6565
db,
6666
keyManager,
6767
gestaltGraph,

src/gestalts/GestaltGraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class GestaltGraph {
4242
fresh?: boolean;
4343
}): Promise<GestaltGraph> {
4444
logger.info(`Creating ${this.name}`);
45-
const gestaltGraph = new GestaltGraph({ acl, db, logger });
45+
const gestaltGraph = new this({ acl, db, logger });
4646
await gestaltGraph.start({ fresh });
4747
logger.info(`Created ${this.name}`);
4848
return gestaltGraph;

src/grpc/utils/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ function getClientSession(
125125
if (channel.getConnectivityState(false) !== grpc.connectivityState.READY) {
126126
throw grpcErrors.ErrorGRPCClientChannelNotReady;
127127
}
128-
// @ts-ignore
128+
// @ts-ignore: accessing private property
129129
const channelTarget = channel.target;
130130
const subchannelTarget = { host, port };
131-
// @ts-ignore
131+
// @ts-ignore: accessing private property
132132
const subchannelPool = channel.subchannelPool;
133133
// This must acquire the first channel in the subchannel pool
134134
// Only the first channel is in ready state and therefore has the session property
@@ -155,7 +155,7 @@ function getClientSession(
155155
* It will contain `stream` property, which will contain the `session` property
156156
*/
157157
function getServerSession(call: ServerSurfaceCall): Http2Session {
158-
// @ts-ignore
158+
// @ts-ignore: accessing private property
159159
return call.stream.session;
160160
}
161161

src/identities/IdentitiesManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class IdentitiesManager {
3030
fresh?: boolean;
3131
}): Promise<IdentitiesManager> {
3232
logger.info(`Creating ${this.name}`);
33-
const identitiesManager = new IdentitiesManager({ db, logger });
33+
const identitiesManager = new this({ db, logger });
3434
await identitiesManager.start({ fresh });
3535
logger.info(`Created ${this.name}`);
3636
return identitiesManager;

src/keys/KeyManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class KeyManager {
5555
}): Promise<KeyManager> {
5656
logger.info(`Creating ${this.name}`);
5757
logger.info(`Setting keys path to ${keysPath}`);
58-
const keyManager = new KeyManager({
58+
const keyManager = new this({
5959
keysPath,
6060
rootCertDuration,
6161
rootKeyPairBits,

src/keys/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function certVerified(cert1: Certificate, cert2: Certificate): boolean {
384384

385385
function certVerifiedNode(cert: Certificate): boolean {
386386
const certNodeSignatureExt = cert.getExtension({
387-
// @ts-ignore
387+
// @ts-ignore: ignoring type mismatch
388388
id: config.oids.extensions.nodeSignature,
389389
}) as any;
390390
if (certNodeSignatureExt == null) {
@@ -403,7 +403,7 @@ function certVerifiedNode(cert: Certificate): boolean {
403403
let verified;
404404
try {
405405
cert.setExtensions(extensionsFiltered);
406-
// @ts-ignore
406+
// @ts-ignore: accessing private property
407407
const certTBS = pki.getTBSCertificate(cert);
408408
const certTBSDer = asn1.toDer(certTBS);
409409
certDigest.update(certTBSDer.getBytes());

src/nodes/NodeConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class NodeConnection<T extends GRPCClient> {
8383
// 3. Relay the proxy port to the broker/s (such that they can inform the other node)
8484
// 4. Start sending hole-punching packets to other node (done in openConnection())
8585
// Done in parallel
86-
const nodeConnection = new NodeConnection<T>({
86+
const nodeConnection = new this<T>({
8787
host: targetHost,
8888
port: targetPort,
8989
hostname: targetHostname,

src/nodes/NodeGraph.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class NodeGraph {
4343
fresh?: boolean;
4444
}): Promise<NodeGraph> {
4545
logger.info(`Creating ${this.name}`);
46-
const nodeGraph = new NodeGraph({
46+
const nodeGraph = new this({
4747
db,
4848
keyManager,
4949
nodeIdBits,
@@ -368,15 +368,13 @@ class NodeGraph {
368368
)) {
369369
const nodeId = IdInternal.fromBuffer<NodeId>(nodeIdBuffer);
370370
bucketDbIterator.seek(nodeIdBuffer);
371-
// @ts-ignore
372371
// eslint-disable-next-line
373372
const iteratorResult = await bucketDbIterator.next();
374373
if (iteratorResult == null) never();
375374
const [, nodeData] = iteratorResult;
376375
bucket.push([nodeId, nodeData]);
377376
}
378377
} finally {
379-
// @ts-ignore
380378
await bucketDbIterator.end();
381379
}
382380
}
@@ -467,7 +465,6 @@ class NodeGraph {
467465
const { bucketIndex: bucketIndex_, nodeId } =
468466
nodesUtils.parseLastUpdatedBucketsDbKey(key);
469467
bucketsDbIterator.seek([key[0], key[2]]);
470-
// @ts-ignore
471468
// eslint-disable-next-line
472469
const iteratorResult = await bucketsDbIterator.next();
473470
if (iteratorResult == null) never();
@@ -491,7 +488,6 @@ class NodeGraph {
491488
yield [bucketIndex, bucket];
492489
}
493490
} finally {
494-
// @ts-ignore
495491
await bucketsDbIterator.end();
496492
}
497493
}

src/notifications/NotificationsManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class NotificationsManager {
5656
fresh?: boolean;
5757
}): Promise<NotificationsManager> {
5858
logger.info(`Creating ${this.name}`);
59-
const notificationsManager = new NotificationsManager({
59+
const notificationsManager = new this({
6060
acl,
6161
db,
6262
keyManager,

src/schema/Schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Schema {
2828
fresh?: boolean;
2929
}): Promise<Schema> {
3030
logger.info(`Creating ${this.name}`);
31-
const schema = new Schema({
31+
const schema = new this({
3232
statePath,
3333
stateVersion,
3434
fs,

src/sessions/Session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Session {
2828
}): Promise<Session> {
2929
logger.info(`Creating ${this.name}`);
3030
logger.info(`Setting session token path to ${sessionTokenPath}`);
31-
const session = new Session({
31+
const session = new this({
3232
sessionTokenPath,
3333
fs,
3434
logger,

src/sessions/SessionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SessionManager {
3434
fresh?: boolean;
3535
}): Promise<SessionManager> {
3636
logger.info(`Creating ${this.name}`);
37-
const sessionManager = new SessionManager({
37+
const sessionManager = new this({
3838
db,
3939
keyManager,
4040
expiry,

src/sigchain/Sigchain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Sigchain {
5959
fresh?: boolean;
6060
}): Promise<Sigchain> {
6161
logger.info(`Creating ${this.name}`);
62-
const sigchain = new Sigchain({ db, keyManager, logger });
62+
const sigchain = new this({ db, keyManager, logger });
6363
await sigchain.start({ fresh });
6464
logger.info(`Created ${this.name}`);
6565
return sigchain;

src/vaults/VaultInternal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class VaultInternal {
8585

8686
const vaultIdEncoded = vaultsUtils.encodeVaultId(vaultId);
8787
logger.info(`Creating ${this.name} - ${vaultIdEncoded}`);
88-
const vault = new VaultInternal({
88+
const vault = new this({
8989
vaultId,
9090
db,
9191
vaultsDbPath,

src/vaults/VaultManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class VaultManager {
8585
}) {
8686
logger.info(`Creating ${this.name}`);
8787
logger.info(`Setting vaults path to ${vaultsPath}`);
88-
const vaultManager = new VaultManager({
88+
const vaultManager = new this({
8989
vaultsPath,
9090
db,
9191
acl,

tests/bin/utils.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,7 @@ async function pkExec(
203203
return new Promise((resolve, reject) => {
204204
child_process.execFile(
205205
'ts-node',
206-
[
207-
'--project',
208-
tsConfigPath,
209-
polykeyPath,
210-
...args,
211-
],
206+
['--project', tsConfigPath, polykeyPath, ...args],
212207
{
213208
env,
214209
cwd,
@@ -266,13 +261,7 @@ async function pkSpawn(
266261
? path.resolve(path.join(global.projectDir, global.testCmd))
267262
: 'ts-node';
268263
const tsNodeArgs =
269-
global.testCmd != null
270-
? []
271-
: [
272-
'--project',
273-
tsConfigPath,
274-
polykeyPath,
275-
];
264+
global.testCmd != null ? [] : ['--project', tsConfigPath, polykeyPath];
276265
const subprocess = child_process.spawn(command, [...tsNodeArgs, ...args], {
277266
env,
278267
cwd,
@@ -326,12 +315,7 @@ async function pkExpect({
326315
// Expect chain runs against stdout and stderr
327316
let expectChain = nexpect.spawn(
328317
'ts-node',
329-
[
330-
'--project',
331-
tsConfigPath,
332-
polykeyPath,
333-
...args,
334-
],
318+
['--project', tsConfigPath, polykeyPath, ...args],
335319
{
336320
env,
337321
cwd,

tests/grpc/utils.test.ts

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,11 @@ describe('GRPC utils', () => {
449449
expect(deserialisedError).toBeInstanceOf(grpcErrors.ErrorPolykeyRemote);
450450
expect(deserialisedError.message).toBe('test error');
451451
// @ts-ignore - already checked above that error is ErrorPolykeyRemote
452-
expect(deserialisedError.metadata.nodeId).toBe(nodeId);
453-
// @ts-ignore
454-
expect(deserialisedError.metadata.host).toBe(host);
455-
// @ts-ignore
456-
expect(deserialisedError.metadata.port).toBe(port);
457-
// @ts-ignore
458-
expect(deserialisedError.metadata.command).toBe('testCall');
452+
const metadata = deserialisedError.metadata;
453+
expect(metadata.nodeId).toBe(nodeId);
454+
expect(metadata.host).toBe(host);
455+
expect(metadata.port).toBe(port);
456+
expect(metadata.command).toBe('testCall');
459457
expect(deserialisedError.cause).toBeInstanceOf(errors.ErrorPolykey);
460458
expect(deserialisedError.cause.message).toBe('test error');
461459
expect(deserialisedError.cause.exitCode).toBe(255);
@@ -490,13 +488,11 @@ describe('GRPC utils', () => {
490488
expect(deserialisedError).toBeInstanceOf(grpcErrors.ErrorPolykeyRemote);
491489
expect(deserialisedError.message).toBe('test error');
492490
// @ts-ignore - already checked above that error is ErrorPolykeyRemote
493-
expect(deserialisedError.metadata.nodeId).toBe(nodeId);
494-
// @ts-ignore
495-
expect(deserialisedError.metadata.host).toBe(host);
496-
// @ts-ignore
497-
expect(deserialisedError.metadata.port).toBe(port);
498-
// @ts-ignore
499-
expect(deserialisedError.metadata.command).toBe('testCall');
491+
const metadata = deserialisedError.metadata;
492+
expect(metadata.nodeId).toBe(nodeId);
493+
expect(metadata.host).toBe(host);
494+
expect(metadata.port).toBe(port);
495+
expect(metadata.command).toBe('testCall');
500496
expect(deserialisedError.cause).toBeInstanceOf(TypeError);
501497
expect(deserialisedError.cause.message).toBe('test error');
502498
expect(deserialisedError.cause.stack).toBe(error.stack);
@@ -524,13 +520,11 @@ describe('GRPC utils', () => {
524520
);
525521
expect(deserialisedError).toBeInstanceOf(grpcErrors.ErrorPolykeyRemote);
526522
// @ts-ignore - already checked above that error is ErrorPolykeyRemote
527-
expect(deserialisedError.metadata.nodeId).toBe(nodeId);
528-
// @ts-ignore
529-
expect(deserialisedError.metadata.host).toBe(host);
530-
// @ts-ignore
531-
expect(deserialisedError.metadata.port).toBe(port);
532-
// @ts-ignore
533-
expect(deserialisedError.metadata.command).toBe('testCall');
523+
const metadata = deserialisedError.metadata;
524+
expect(metadata.nodeId).toBe(nodeId);
525+
expect(metadata.host).toBe(host);
526+
expect(metadata.port).toBe(port);
527+
expect(metadata.command).toBe('testCall');
534528
expect(deserialisedError.cause).toBeInstanceOf(errors.ErrorPolykeyUnknown);
535529
// This is slightly brittle because it's based on what we choose to do
536530
// with unknown data in our grpc reviver
@@ -578,13 +572,11 @@ describe('GRPC utils', () => {
578572
expect(deserialisedError).toBeInstanceOf(grpcErrors.ErrorPolykeyRemote);
579573
expect(deserialisedError.message).toBe('test error');
580574
// @ts-ignore - already checked above that error is ErrorPolykeyRemote
581-
expect(deserialisedError.metadata.nodeId).toBe(nodeId);
582-
// @ts-ignore
583-
expect(deserialisedError.metadata.host).toBe(host);
584-
// @ts-ignore
585-
expect(deserialisedError.metadata.port).toBe(port);
586-
// @ts-ignore
587-
expect(deserialisedError.metadata.command).toBe('testCall');
575+
const metadata = deserialisedError.metadata;
576+
expect(metadata.nodeId).toBe(nodeId);
577+
expect(metadata.host).toBe(host);
578+
expect(metadata.port).toBe(port);
579+
expect(metadata.command).toBe('testCall');
588580
expect(deserialisedError.cause).toBeInstanceOf(errors.ErrorPolykey);
589581
expect(deserialisedError.cause.message).toBe('test error');
590582
expect(deserialisedError.cause.exitCode).toBe(255);

tests/vaults/VaultInternal.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ describe('VaultInternal', () => {
720720
for (const logElement of log) {
721721
refs.push(await quickCommit(logElement.commitId, `secret-${num++}`));
722722
}
723-
// @ts-ignore
723+
// @ts-ignore: private method
724724
await vault.garbageCollectGitObjects();
725725

726726
for (const ref of refs) {

0 commit comments

Comments
 (0)