Skip to content

Commit e90e6e8

Browse files
committed
fix: build
1 parent acd0436 commit e90e6e8

File tree

6 files changed

+95
-70
lines changed

6 files changed

+95
-70
lines changed

src/git/http.ts

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ContextCancellable } from '@matrixai/contexts';
12
import type {
23
CapabilityList,
34
Reference,
@@ -10,7 +11,6 @@ import { Buffer } from 'buffer';
1011
import git from 'isomorphic-git';
1112
import * as gitUtils from './utils';
1213
import * as utils from '../utils';
13-
import {ContextCancellable} from "@matrixai/contexts";
1414

1515
/**
1616
* Reference discovery
@@ -111,15 +111,18 @@ import {ContextCancellable} from "@matrixai/contexts";
111111
*
112112
* `referenceList` is called for generating the `ref_list` stage.
113113
*/
114-
async function* advertiseRefGenerator({
115-
efs,
116-
dir,
117-
gitDir,
118-
}: {
119-
efs: EncryptedFS;
120-
dir: string;
121-
gitDir: string;
122-
}, ctx: ContextCancellable): AsyncGenerator<Buffer, void, void> {
114+
async function* advertiseRefGenerator(
115+
{
116+
efs,
117+
dir,
118+
gitDir,
119+
}: {
120+
efs: EncryptedFS;
121+
dir: string;
122+
gitDir: string;
123+
},
124+
ctx: ContextCancellable,
125+
): AsyncGenerator<Buffer, void, void> {
123126
// Providing side-band-64, symref for the HEAD and agent name capabilities
124127
const capabilityList = [
125128
gitUtils.SIDE_BAND_64_CAPABILITY,
@@ -131,11 +134,14 @@ async function* advertiseRefGenerator({
131134
}),
132135
gitUtils.AGENT_CAPABILITY,
133136
];
134-
const objectGenerator = gitUtils.listReferencesGenerator({
135-
efs,
136-
dir,
137-
gitDir,
138-
}, ctx );
137+
const objectGenerator = gitUtils.listReferencesGenerator(
138+
{
139+
efs,
140+
dir,
141+
gitDir,
142+
},
143+
ctx,
144+
);
139145

140146
// PKT-LINE("# service=$servicename" LF)
141147
yield packetLineBuffer(gitUtils.REFERENCE_DISCOVERY_HEADER);
@@ -344,34 +350,43 @@ async function parsePackRequest(
344350
* It will respond with the `PKT-LINE(NAK_BUFFER)` and then the `packFile` data chunked into lines for the stream.
345351
*
346352
*/
347-
async function* generatePackRequest({
348-
efs,
349-
dir,
350-
gitDir,
351-
body,
352-
}: {
353-
efs: EncryptedFS;
354-
dir: string;
355-
gitDir: string;
356-
body: Array<Buffer>;
357-
}, ctx: ContextCancellable): AsyncGenerator<Buffer, void, void> {
358-
const [wants, haves, _capabilities] = await parsePackRequest(body);
359-
const objectIds = await gitUtils.listObjects({
360-
efs: efs,
353+
async function* generatePackRequest(
354+
{
355+
efs,
361356
dir,
362-
gitDir: gitDir,
363-
wants,
364-
haves,
365-
}, ctx);
357+
gitDir,
358+
body,
359+
}: {
360+
efs: EncryptedFS;
361+
dir: string;
362+
gitDir: string;
363+
body: Array<Buffer>;
364+
},
365+
ctx: ContextCancellable,
366+
): AsyncGenerator<Buffer, void, void> {
367+
const [wants, haves, _capabilities] = await parsePackRequest(body);
368+
const objectIds = await gitUtils.listObjects(
369+
{
370+
efs: efs,
371+
dir,
372+
gitDir: gitDir,
373+
wants,
374+
haves,
375+
},
376+
// ctx,
377+
);
366378
// Reply that we have no common history and that we need to send everything
367379
yield packetLineBuffer(gitUtils.NAK_BUFFER);
368380
// Send everything over in pack format
369-
yield* generatePackData({
370-
efs: efs,
371-
dir,
372-
gitDir,
373-
objectIds,
374-
}, ctx);
381+
yield* generatePackData(
382+
{
383+
efs: efs,
384+
dir,
385+
gitDir,
386+
objectIds,
387+
},
388+
ctx,
389+
);
375390
// Send dummy progress data
376391
yield packetLineBuffer(
377392
gitUtils.DUMMY_PROGRESS_BUFFER,
@@ -387,19 +402,22 @@ async function* generatePackRequest({
387402
* The `packFile` is chunked into the `packetLineBuffer` with the size defined by `chunkSize`.
388403
*
389404
*/
390-
async function* generatePackData({
391-
efs,
392-
dir,
393-
gitDir,
394-
objectIds,
395-
chunkSize = gitUtils.PACK_CHUNK_SIZE,
396-
}: {
397-
efs: EncryptedFS;
398-
dir: string;
399-
gitDir: string;
400-
objectIds: Array<ObjectId>;
401-
chunkSize?: number;
402-
}, ctx: ContextCancellable): AsyncGenerator<Buffer, void, void> {
405+
async function* generatePackData(
406+
{
407+
efs,
408+
dir,
409+
gitDir,
410+
objectIds,
411+
chunkSize = gitUtils.PACK_CHUNK_SIZE,
412+
}: {
413+
efs: EncryptedFS;
414+
dir: string;
415+
gitDir: string;
416+
objectIds: Array<ObjectId>;
417+
chunkSize?: number;
418+
},
419+
ctx: ContextCancellable,
420+
): AsyncGenerator<Buffer, void, void> {
403421
let packFile: PackObjectsResult;
404422
// In case of errors we don't want to throw them. This will result in the error being thrown into `isometric-git`
405423
// when it consumes the response. It handles this by logging out the error which we don't want to happen.

src/git/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,16 @@ async function listObjects({
158158
gitDir: string;
159159
wants: ObjectIdList;
160160
haves: ObjectIdList;
161-
}, ctx: ContextCancellable): Promise<ObjectIdList> {
161+
}/*, ctx: ContextCancellable*/): Promise<ObjectIdList> {
162+
// TODO: add support for ctx
162163
const commits = new Set<string>();
163164
const trees = new Set<string>();
164165
const blobs = new Set<string>();
165166
const tags = new Set<string>();
166167
const havesSet: Set<string> = new Set(haves);
167168

168169
async function walk(objectId: ObjectId, type: ObjectType): Promise<void> {
169-
ctx.signal.throwIfAborted();
170+
// ctx.signal.throwIfAborted();
170171
// If object was listed as a have then we don't need to walk over it
171172
if (havesSet.has(objectId)) return;
172173
switch (type) {

src/nodes/agent/handlers/VaultsGitInfoGet.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class VaultsGitInfoGet extends RawHandler<{
2525
}> {
2626
public handle = async (
2727
input: [JSONRPCRequest, ReadableStream<Uint8Array>],
28-
_cancel,
28+
_cancel: (reason?: any) => void,
2929
meta: Record<string, JSONValue> | undefined,
30-
_ctx: ContextTimed, // TODO: use
30+
ctx: ContextTimed,
3131
): Promise<[JSONObject, ReadableStream<Uint8Array>]> => {
3232
const { db, vaultManager, acl } = this.container;
3333
const [headerMessage, inputStream] = input;
@@ -91,7 +91,10 @@ class VaultsGitInfoGet extends RawHandler<{
9191
let handleInfoRequestGen: AsyncGenerator<Buffer>;
9292
const stream = new ReadableStream({
9393
start: async () => {
94-
handleInfoRequestGen = vaultManager.handleInfoRequest(data.vaultId);
94+
handleInfoRequestGen = vaultManager.handleInfoRequest(
95+
data.vaultId,
96+
ctx,
97+
);
9598
},
9699
pull: async (controller) => {
97100
const result = await handleInfoRequestGen.next();

src/nodes/agent/handlers/VaultsGitPackGet.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DB } from '@matrixai/db';
2-
import type { JSONObject, JSONRPCRequest } from '@matrixai/rpc';
3-
import type {ContextTimed} from '@matrixai/contexts';
2+
import type { JSONObject, JSONRPCRequest, JSONValue } from '@matrixai/rpc';
3+
import type { ContextTimed } from '@matrixai/contexts';
44
import type { VaultName } from '../../../vaults/types';
55
import type ACL from '../../../acl/ACL';
66
import type VaultManager from '../../../vaults/VaultManager';
@@ -23,8 +23,8 @@ class VaultsGitPackGet extends RawHandler<{
2323
}> {
2424
public handle = async (
2525
input: [JSONRPCRequest, ReadableStream<Uint8Array>],
26-
_cancel,
27-
meta,
26+
_cancel: (reason: any) => void,
27+
meta: Record<string, JSONValue>,
2828
ctx: ContextTimed,
2929
): Promise<[JSONObject, ReadableStream<Uint8Array>]> => {
3030
const { vaultManager, acl, db } = this.container;
@@ -79,7 +79,7 @@ class VaultsGitPackGet extends RawHandler<{
7979
for await (const message of inputStream) {
8080
body.push(Buffer.from(message));
8181
}
82-
packRequestGen = vaultManager.handlePackRequest(vaultId, body);
82+
packRequestGen = vaultManager.handlePackRequest(vaultId, body, ctx);
8383
},
8484
pull: async (controller) => {
8585
const next = await packRequestGen.next();

src/nodes/agent/handlers/VaultsScan.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { DB } from '@matrixai/db';
2-
import type {ContextTimed} from '@matrixai/contexts';
2+
import type { ContextTimed } from '@matrixai/contexts';
33
import type {
44
AgentRPCRequestParams,
55
AgentRPCResponseResult,
66
VaultsScanMessage,
77
} from '../types';
88
import type VaultManager from '../../../vaults/VaultManager';
9+
import type { JSONValue } from '@matrixai/rpc';
910
import { ServerHandler } from '@matrixai/rpc';
1011
import * as agentErrors from '../errors';
1112
import * as agentUtils from '../utils';
@@ -23,12 +24,13 @@ class VaultsScan extends ServerHandler<
2324
AgentRPCResponseResult<VaultsScanMessage>
2425
> {
2526
public handle = async function* (
26-
input: AgentRPCRequestParams,
27-
_cancel,
28-
meta,
27+
_input: AgentRPCRequestParams,
28+
_cancel: (reason?: any) => void,
29+
meta: Record<string, JSONValue> | undefined,
2930
ctx: ContextTimed,
3031
): AsyncGenerator<AgentRPCResponseResult<VaultsScanMessage>> {
31-
const { vaultManager, db } = this.container;
32+
const { vaultManager, db }: { vaultManager: VaultManager; db: DB } =
33+
this.container;
3234
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
3335
if (requestingNodeId == null) {
3436
throw new agentErrors.ErrorAgentNodeIdMissing();

src/vaults/VaultManager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import * as nodesUtils from '../nodes/utils';
4040
import * as keysUtils from '../keys/utils';
4141
import config from '../config';
4242
import { mkdirExists } from '../utils/utils';
43-
import {ContextCancellable} from "@matrixai/contexts";
43+
import {ContextCancellable, ContextTimed} from "@matrixai/contexts";
4444

4545
/**
4646
* Object map pattern for each vault
@@ -804,11 +804,12 @@ class VaultManager {
804804
@ready(new vaultsErrors.ErrorVaultManagerNotRunning())
805805
public async *handleInfoRequest(
806806
vaultId: VaultId,
807+
ctx: ContextTimed,
807808
tran?: DBTransaction,
808809
): AsyncGenerator<Buffer, void, void> {
809810
if (tran == null) {
810811
const handleInfoRequest = (tran: DBTransaction) =>
811-
this.handleInfoRequest(vaultId, tran);
812+
this.handleInfoRequest(vaultId, ctx, tran);
812813
return yield* this.db.withTransactionG(async function* (tran) {
813814
return yield* handleInfoRequest(tran);
814815
});
@@ -826,7 +827,7 @@ class VaultManager {
826827
efs,
827828
dir: path.join(vaultsUtils.encodeVaultId(vaultId), 'contents'),
828829
gitDir: path.join(vaultsUtils.encodeVaultId(vaultId), '.git'),
829-
});
830+
}, ctx);
830831
},
831832
);
832833
}

0 commit comments

Comments
 (0)