Skip to content

Commit 2972ad3

Browse files
tegefaulkesaryanjassal
authored andcommitted
feat: applying cancellability to handlers
chore: added ctx to most of the vault domain feat: added cancellation for most `polykey vaults` commands chore: added ctx to most of `secrets` commands chore: cleaned up `VaultInternal.ts` chore: added ctx to `VaultInternal` and `VaultManager` feat: added context cancellation to the entire `vault` domain chore: cleaned up vaults handlers chore: updated `meta` type to match signature chore: made `SuccessOrErrorMessage` consistently tagged chore: added test for cancellation to `VaultsSecretsRemove` chore: working on dynamic handler cancellation chore: added cancellation tests for all secrets commands chore: removed cancellation from synchronous loops chore: added tests for vaults handlers feat: added cancellation and tests for some git operations chore: updated arbitraries
1 parent 47716b7 commit 2972ad3

File tree

78 files changed

+2741
-1392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2741
-1392
lines changed

src/acl/ACL.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ class ACL {
144144
if (permId in permIds) {
145145
nodePerm = permIds[permId];
146146
// Get the first existing perm object
147-
let perm: Permission;
148-
for (const nodeId_ in nodePerm) {
149-
perm = nodePerm[nodeId_];
150-
break;
151-
}
147+
const perm = Object.values(nodePerm)[0];
152148
// All perm objects are shared
153149
nodePerm[nodeId] = perm!;
154150
} else {
@@ -614,8 +610,8 @@ class ACL {
614610
[...this.aclNodesDbPath, nodeId.toBuffer()],
615611
true,
616612
);
617-
// Skip if the nodeId doesn't exist
618-
// this means that it previously been removed
613+
// Skip if the nodeId doesn't exist. This means that it has previously
614+
// been removed.
619615
if (permId == null) {
620616
continue;
621617
}

src/client/callers/vaultsSecretsGet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { HandlerTypes } from '@matrixai/rpc';
22
import type VaultsSecretsGet from '../handlers/VaultsSecretsGet';
3-
import { ServerCaller } from '@matrixai/rpc';
3+
import { UnaryCaller } from '@matrixai/rpc';
44

55
type CallerTypes = HandlerTypes<VaultsSecretsGet>;
66

7-
const vaultsSecretsGet = new ServerCaller<
7+
const vaultsSecretsGet = new UnaryCaller<
88
CallerTypes['input'],
99
CallerTypes['output']
1010
>();

src/client/handlers/AgentStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type {
55
} from '../types';
66
import type PolykeyAgent from '../../PolykeyAgent';
77
import { UnaryHandler } from '@matrixai/rpc';
8-
import * as nodesUtils from '../../nodes/utils';
98
import config from '../../config';
9+
import * as nodesUtils from '../../nodes/utils';
1010

1111
class AgentStatus extends UnaryHandler<
1212
{

src/client/handlers/AuditEventsGet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { JSONValue } from '@matrixai/rpc';
23
import type { ClientRPCRequestParams, ClientRPCResponseResult } from '../types';
34
import type {
45
AuditEvent,
@@ -42,8 +43,8 @@ class AuditEventsGet extends ServerHandler<
4243
}> & {
4344
paths: Array<TopicSubPath>;
4445
},
45-
_cancel,
46-
_meta,
46+
_cancel: (reason?: any) => void,
47+
_meta: Record<string, JSONValue>,
4748
ctx: ContextTimed,
4849
): AsyncGenerator<ClientRPCResponseResult<AuditEventSerialized>> {
4950
const { audit }: { audit: Audit } = this.container;

src/client/handlers/GestaltsActionsGetByIdentity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type GestaltGraph from '../../gestalts/GestaltGraph';
88
import type { GestaltAction } from '../../gestalts/types';
99
import type { IdentityId, ProviderId } from '../../ids';
1010
import { UnaryHandler } from '@matrixai/rpc';
11-
import * as ids from '../../ids';
1211
import { validateSync } from '../../validation';
1312
import { matchSync } from '../../utils';
13+
import * as ids from '../../ids';
1414

1515
class GestaltsActionsGetByIdentity extends UnaryHandler<
1616
{

src/client/handlers/IdentitiesAuthenticate.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { JSONValue } from '@matrixai/rpc';
13
import type {
24
AuthProcessMessage,
35
ClientRPCRequestParams,
@@ -21,11 +23,10 @@ class IdentitiesAuthenticate extends ServerHandler<
2123
public timeout = 120000; // 2 Minutes
2224
public handle = async function* (
2325
input: ClientRPCRequestParams<{ providerId: string }>,
24-
_cancel,
25-
_meta,
26-
ctx,
26+
_cancel: (reason?: any) => void,
27+
_meta: Record<string, JSONValue>,
28+
ctx: ContextTimed,
2729
): AsyncGenerator<ClientRPCResponseResult<AuthProcessMessage>> {
28-
if (ctx.signal.aborted) throw ctx.signal.reason;
2930
const { identitiesManager }: { identitiesManager: IdentitiesManager } =
3031
this.container;
3132
const {
@@ -52,7 +53,7 @@ class IdentitiesAuthenticate extends ServerHandler<
5253
if (authFlowResult.done) {
5354
never('authFlow signalled done too soon');
5455
}
55-
if (ctx.signal.aborted) throw ctx.signal.reason;
56+
ctx.signal.throwIfAborted();
5657
yield {
5758
request: {
5859
url: authFlowResult.value.url,
@@ -63,7 +64,7 @@ class IdentitiesAuthenticate extends ServerHandler<
6364
if (!authFlowResult.done) {
6465
never('authFlow did not signal done when expected');
6566
}
66-
if (ctx.signal.aborted) throw ctx.signal.reason;
67+
ctx.signal.throwIfAborted();
6768
yield {
6869
response: {
6970
identityId: authFlowResult.value,

src/client/handlers/IdentitiesAuthenticatedGet.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { JSONValue } from '@matrixai/rpc';
13
import type {
24
ClientRPCRequestParams,
35
ClientRPCResponseResult,
@@ -19,11 +21,10 @@ class IdentitiesAuthenticatedGet extends ServerHandler<
1921
> {
2022
public handle = async function* (
2123
input: ClientRPCRequestParams<{ providerId?: string }>,
22-
_cancel,
23-
_meta,
24-
ctx,
24+
_cancel: (reason?: any) => void,
25+
_meta: Record<string, JSONValue>,
26+
ctx: ContextTimed,
2527
): AsyncGenerator<ClientRPCResponseResult<IdentityMessage>> {
26-
if (ctx.signal.aborted) throw ctx.signal.reason;
2728
const { identitiesManager }: { identitiesManager: IdentitiesManager } =
2829
this.container;
2930
let providerId: ProviderId | undefined;
@@ -46,12 +47,10 @@ class IdentitiesAuthenticatedGet extends ServerHandler<
4647
: [providerId];
4748
for (const providerId of providerIds) {
4849
const provider = identitiesManager.getProvider(providerId);
49-
if (provider == null) {
50-
continue;
51-
}
50+
if (provider == null) continue;
5251
const identities = await provider.getAuthIdentityIds();
5352
for (const identityId of identities) {
54-
if (ctx.signal.aborted) throw ctx.signal.reason;
53+
ctx.signal.throwIfAborted();
5554
yield {
5655
providerId: provider.id,
5756
identityId: identityId,

src/client/handlers/IdentitiesInfoConnectedGet.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { JSONValue } from '@matrixai/rpc';
13
import type {
24
ClientRPCRequestParams,
35
ClientRPCResponseResult,
@@ -22,11 +24,10 @@ class IdentitiesInfoConnectedGet extends ServerHandler<
2224
> {
2325
public handle = async function* (
2426
input: ClientRPCRequestParams<ProviderSearchMessage>,
25-
_cancel,
26-
_meta,
27-
ctx,
27+
_cancel: (reason?: any) => void,
28+
_meta: Record<string, JSONValue>,
29+
ctx: ContextTimed,
2830
): AsyncGenerator<ClientRPCResponseResult<IdentityInfoMessage>> {
29-
if (ctx.signal.aborted) throw ctx.signal.reason;
3031
const { identitiesManager }: { identitiesManager: IdentitiesManager } =
3132
this.container;
3233
const {
@@ -71,6 +72,7 @@ class IdentitiesInfoConnectedGet extends ServerHandler<
7172
}
7273
const identities: Array<AsyncGenerator<IdentityData>> = [];
7374
for (const providerId of providerIds) {
75+
ctx.signal.throwIfAborted();
7476
// Get provider from id
7577
const provider = identitiesManager.getProvider(providerId);
7678
if (provider === undefined) {
@@ -94,7 +96,7 @@ class IdentitiesInfoConnectedGet extends ServerHandler<
9496
let count = 0;
9597
for (const gen of identities) {
9698
for await (const identity of gen) {
97-
if (ctx.signal.aborted) throw ctx.signal.reason;
99+
ctx.signal.throwIfAborted();
98100
if (input.limit !== undefined && count >= input.limit) break;
99101
yield {
100102
providerId: identity.providerId,

src/client/handlers/IdentitiesInfoGet.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { JSONValue } from '@matrixai/rpc';
13
import type {
24
ClientRPCRequestParams,
35
ClientRPCResponseResult,
@@ -8,11 +10,11 @@ import type { IdentityId, ProviderId } from '../../ids';
810
import type IdentitiesManager from '../../identities/IdentitiesManager';
911
import type { IdentityData } from '../../identities/types';
1012
import { ServerHandler } from '@matrixai/rpc';
13+
import { validateSync } from '../../validation';
14+
import { matchSync } from '../../utils';
1115
import * as ids from '../../ids';
1216
import * as identitiesErrors from '../../identities/errors';
1317
import * as identitiesUtils from '../../identities/utils';
14-
import { validateSync } from '../../validation';
15-
import { matchSync } from '../../utils';
1618

1719
class IdentitiesInfoGet extends ServerHandler<
1820
{
@@ -23,9 +25,9 @@ class IdentitiesInfoGet extends ServerHandler<
2325
> {
2426
public handle = async function* (
2527
input: ClientRPCRequestParams<ProviderSearchMessage>,
26-
_cancel,
27-
_meta,
28-
ctx,
28+
_cancel: (reason?: any) => void,
29+
_meta: Record<string, JSONValue>,
30+
ctx: ContextTimed,
2931
): AsyncGenerator<ClientRPCResponseResult<IdentityInfoMessage>> {
3032
if (ctx.signal.aborted) throw ctx.signal.reason;
3133
const { identitiesManager }: { identitiesManager: IdentitiesManager } =
@@ -86,7 +88,7 @@ class IdentitiesInfoGet extends ServerHandler<
8688
input.limit = identities.length;
8789
}
8890
for (let i = 0; i < input.limit; i++) {
89-
if (ctx.signal.aborted) throw ctx.signal.reason;
91+
ctx.signal.throwIfAborted();
9092
const identity = identities[i];
9193
if (identity !== undefined) {
9294
if (identitiesUtils.matchIdentityData(identity, searchTerms)) {

src/client/handlers/KeysCertsChainGet.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ContextTimed } from '@matrixai/contexts';
2+
import type { JSONValue } from '@matrixai/rpc';
13
import type {
24
CertMessage,
35
ClientRPCRequestParams,
@@ -14,17 +16,15 @@ class KeysCertsChainGet extends ServerHandler<
1416
ClientRPCResponseResult<CertMessage>
1517
> {
1618
public handle = async function* (
17-
_input,
18-
_cancel,
19-
_meta,
20-
ctx,
19+
_input: ClientRPCRequestParams,
20+
_cancel: (reason?: any) => void,
21+
_meta: Record<string, JSONValue>,
22+
ctx: ContextTimed,
2123
): AsyncGenerator<ClientRPCResponseResult<CertMessage>> {
2224
const { certManager }: { certManager: CertManager } = this.container;
2325
for (const certPEM of await certManager.getCertPEMsChain()) {
24-
if (ctx.signal.aborted) throw ctx.signal.reason;
25-
yield {
26-
cert: certPEM,
27-
};
26+
ctx.signal.throwIfAborted();
27+
yield { cert: certPEM };
2828
}
2929
};
3030
}

0 commit comments

Comments
 (0)