Skip to content

Commit

Permalink
feat: bump @matrixai/rpc to 0.2.6 and moved timeoutMiddleware f…
Browse files Browse the repository at this point in the history
…rom `src/client` to `@matrixai/rpc`

chore: lintfix

[ci-skip]
  • Loading branch information
amydevs committed Nov 1, 2023
1 parent daeafaa commit 4f1469f
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 393 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@matrixai/mdns": "^1.2.3",
"@matrixai/quic": "^1.0.0",
"@matrixai/resources": "^1.1.5",
"@matrixai/rpc": "^0.2.4",
"@matrixai/rpc": "^0.2.6",
"@matrixai/timer": "^1.1.2",
"@matrixai/workers": "^1.3.7",
"@matrixai/ws": "^1.1.7",
Expand Down
2 changes: 1 addition & 1 deletion src/PolykeyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class PolykeyClient {
optionsDefaulted.rpcParserBufferSize,
),
toError: networkUtils.toError,
streamKeepAliveTimeoutTime: optionsDefaulted.rpcCallTimeoutTime,
timeoutTime: optionsDefaulted.rpcCallTimeoutTime,
logger: this.logger.getChild(RPCClient.name),
});
this._nodeId = nodeId_;
Expand Down
2 changes: 1 addition & 1 deletion src/client/ClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ClientService {
this.logger = logger ?? new Logger(this.constructor.name);
this.rpcServer = new RPCServer({
idGen,
handlerTimeoutTime: rpcCallTimeoutTime,
timeoutTime: rpcCallTimeoutTime,
middlewareFactory: rpcMiddleware.defaultServerMiddlewareWrapper(
middlewareFactory,
rpcParserBufferSize,
Expand Down
1 change: 0 additions & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ export * as handlers from './handlers';
export * as utils from './utils';
export * as middleware from './middleware';
export * as authenticationMiddleware from './authenticationMiddleware';
export * as timeoutMiddleWare from './timeoutMiddleware';
export * as errors from './errors';
export * as types from './types';
31 changes: 6 additions & 25 deletions src/client/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
import type SessionManager from '../sessions/SessionManager';
import type KeyRing from '../keys/KeyRing';
import * as authenticationMiddlewareUtils from './authenticationMiddleware';
import * as timeoutMiddlewareUtils from './timeoutMiddleware';

function middlewareServer(
sessionManager: SessionManager,
Expand All @@ -26,24 +25,15 @@ function middlewareServer(
);
return (ctx, cancel, meta) => {
const authMiddleware = authMiddlewareFactory(ctx, cancel, meta);
const timeoutMiddleware = timeoutMiddlewareUtils.timeoutMiddlewareServer(
ctx,
cancel,
meta,
);
// Order is auth -> timeout
return {
forward: {
writable: authMiddleware.forward.writable,
readable: authMiddleware.forward.readable.pipeThrough(
timeoutMiddleware.forward,
),
readable: authMiddleware.forward.readable,
},
reverse: {
writable: timeoutMiddleware.reverse.writable,
readable: timeoutMiddleware.reverse.readable.pipeThrough(
authMiddleware.reverse,
),
writable: authMiddleware.reverse.writable,
readable: authMiddleware.reverse.readable,
},
};
};
Expand All @@ -61,24 +51,15 @@ function middlewareClient(
authenticationMiddlewareUtils.authenticationMiddlewareClient(session);
return (ctx, cancel, meta) => {
const authMiddleware = authMiddlewareFactory(ctx, cancel, meta);
const timeoutMiddleware = timeoutMiddlewareUtils.timeoutMiddlewareClient(
ctx,
cancel,
meta,
);
// Order is timeout -> auth
return {
forward: {
writable: timeoutMiddleware.forward.writable,
readable: timeoutMiddleware.forward.readable.pipeThrough(
authMiddleware.forward,
),
writable: authMiddleware.forward.writable,
readable: authMiddleware.forward.readable,
},
reverse: {
writable: authMiddleware.reverse.writable,
readable: authMiddleware.reverse.readable.pipeThrough(
timeoutMiddleware.reverse,
),
readable: authMiddleware.reverse.readable,
},
};
};
Expand Down
104 changes: 0 additions & 104 deletions src/client/timeoutMiddleware.ts

This file was deleted.

30 changes: 15 additions & 15 deletions src/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { JSONValue, ObjectEmpty } from '../types';
import type {
JSONObject,
JSONValue,
JSONRPCParams,
JSONRPCResult,
} from '@matrixai/rpc';
import type {
GestaltIdEncoded,
IdentityId,
Expand All @@ -18,27 +23,22 @@ import type { Notification } from '../notifications/types';
import type { ProviderToken } from '../identities/types';

// Prevent overwriting the metadata type with `Omit<>`
type ClientRPCRequestParams<T extends Record<string, JSONValue> = ObjectEmpty> =
{
metadata?: {
[Key: string]: JSONValue;
} & Partial<{
authorization: string;
timeout: number;
}>;
} & Omit<T, 'metadata'>;
type ClientRPCRequestParams<T extends JSONObject = JSONObject> = {
metadata?: {
[Key: string]: JSONValue;
} & Partial<{
authorization: string;
}>;
} & JSONRPCParams<T>;

// Prevent overwriting the metadata type with `Omit<>`
type ClientRPCResponseResult<
T extends Record<string, JSONValue> = ObjectEmpty,
> = {
type ClientRPCResponseResult<T extends JSONObject = JSONObject> = {
metadata?: {
[Key: string]: JSONValue;
} & Partial<{
authorization: string;
timeout: number;
}>;
} & Omit<T, 'metadata'>;
} & JSONRPCResult<T>;

type StatusResultMessage = {
pid: number;
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class NodeConnectionManager {
this.rpcParserBufferSize,
),
fromError: networkUtils.fromError,
handlerTimeoutTime: this.rpcCallTimeoutTime,
timeoutTime: this.rpcCallTimeoutTime,
logger: this.logger.getChild(RPCServer.name),
});

Expand Down
4 changes: 2 additions & 2 deletions src/nodes/agent/handlers/VaultsGitInfoGet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { DB } from '@matrixai/db';
import type Logger from '@matrixai/logger';
import type { JSONObject, JSONRPCRequest } from '@matrixai/rpc';
import type { ContextTimed } from '@matrixai/contexts';
import type ACL from '../../../acl/ACL';
import type VaultManager from '../../../vaults/VaultManager';
import type { JSONValue } from '../../../types';
import type { JSONRPCRequest } from '@matrixai/rpc';
import { ReadableStream } from 'stream/web';
import { RawHandler } from '@matrixai/rpc';
import * as agentErrors from '../errors';
Expand All @@ -28,7 +28,7 @@ class VaultsGitInfoGet extends RawHandler<{
_cancel,
meta: Record<string, JSONValue> | undefined,
_ctx: ContextTimed, // TODO: use
): Promise<[JSONValue, ReadableStream<Uint8Array>]> => {
): Promise<[JSONObject, ReadableStream<Uint8Array>]> => {
const { db, vaultManager, acl } = this.container;
const [headerMessage, inputStream] = input;
await inputStream.cancel();
Expand Down
7 changes: 3 additions & 4 deletions src/nodes/agent/handlers/VaultsGitPackGet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { DB } from '@matrixai/db';
import type { JSONObject, JSONRPCRequest } from '@matrixai/rpc';
import type { PassThrough } from 'readable-stream';
import type { VaultName } from '../../../vaults/types';
import type ACL from '../../../acl/ACL';
import type VaultManager from '../../../vaults/VaultManager';
import type { JSONValue } from '../../../types';
import type { JSONRPCRequest } from '@matrixai/rpc';
import { ReadableStream } from 'stream/web';
import { RawHandler } from '@matrixai/rpc';
import * as agentErrors from '../errors';
Expand All @@ -26,7 +25,7 @@ class VaultsGitPackGet extends RawHandler<{
input: [JSONRPCRequest, ReadableStream<Uint8Array>],
_cancel,
meta,
): Promise<[JSONValue, ReadableStream<Uint8Array>]> => {
): Promise<[JSONObject, ReadableStream<Uint8Array>]> => {
const { vaultManager, acl, db } = this.container;
const [headerMessage, inputStream] = input;
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
Expand Down Expand Up @@ -103,7 +102,7 @@ class VaultsGitPackGet extends RawHandler<{
sideBand.destroy(e);
},
});
return [null, outputStream];
return [{}, outputStream];
};
}

Expand Down
37 changes: 16 additions & 21 deletions src/nodes/agent/types.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import type { JSONObject, JSONRPCParams, JSONRPCResult } from '@matrixai/rpc';
import type { SignedTokenEncoded } from '../../tokens/types';
import type { ClaimIdEncoded, NodeIdEncoded, VaultIdEncoded } from '../../ids';
import type { VaultAction, VaultName } from '../../vaults/types';
import type { SignedNotification } from '../../notifications/types';
import type { JSONValue, ObjectEmpty } from '../../types';
import type { JSONValue } from '../../types';

// Prevent overwriting the metadata type with `Omit<>`
type AgentRPCRequestParams<T extends Record<string, JSONValue> = ObjectEmpty> =
{
metadata?: {
[Key: string]: JSONValue;
} & Partial<{
authorization: string;
timeout: number;
}>;
} & Omit<T, 'metadata'>;
type AgentRPCRequestParams<T extends JSONObject = JSONObject> = {
metadata?: {
[Key: string]: JSONValue;
} & Partial<{
authorization: string;
}>;
} & JSONRPCParams<T>;

// Prevent overwriting the metadata type with `Omit<>`
type AgentRPCResponseResult<T extends Record<string, JSONValue> = ObjectEmpty> =
{
metadata?: {
[Key: string]: JSONValue;
} & Partial<{
authorization: string;
timeout: number;
}>;
} & Omit<T, 'metadata'>;
type AgentRPCResponseResult<T extends JSONObject = JSONObject> = {
metadata?: {
[Key: string]: JSONValue;
} & Partial<{
authorization: string;
}>;
} & JSONRPCResult<T>;

type ClaimIdMessage = {
claimIdEncoded: ClaimIdEncoded;
Expand Down
Loading

0 comments on commit 4f1469f

Please sign in to comment.