From 282ba709f505f81d2199c78396f390672619d127 Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Mon, 1 Nov 2021 10:28:46 -0500 Subject: [PATCH 1/4] fix(owner filter): Pass owner down through list methods PE-645 --- src/ardrive.ts | 6 ++++-- src/arfsdao.ts | 35 +++++++++++++++++++++++++++-------- src/arfsdao_anonymous.ts | 19 ++++++++++++++----- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/ardrive.ts b/src/ardrive.ts index 876dea3e..a18cfe72 100644 --- a/src/ardrive.ts +++ b/src/ardrive.ts @@ -371,7 +371,8 @@ export class ArDrive extends ArDriveAnonymous { const childrenFolderIds = await this.arFsDao.getPublicChildrenFolderIds({ folderId, - driveId: destFolderDriveId + driveId: destFolderDriveId, + owner }); if (childrenFolderIds.includes(newParentFolderId)) { @@ -438,7 +439,8 @@ export class ArDrive extends ArDriveAnonymous { const childrenFolderIds = await this.arFsDao.getPrivateChildrenFolderIds({ folderId, driveId: destFolderDriveId, - driveKey + driveKey, + owner }); if (childrenFolderIds.includes(newParentFolderId)) { diff --git a/src/arfsdao.ts b/src/arfsdao.ts index ba5eaad4..e05bfe21 100644 --- a/src/arfsdao.ts +++ b/src/arfsdao.ts @@ -147,6 +147,7 @@ export interface CreatePrivateFolderSettings extends CreateFolderSettings { interface getPublicChildrenFolderIdsParams { folderId: FolderID; driveId: DriveID; + owner: ArweaveAddress; } interface getPrivateChildrenFolderIdsParams extends getPublicChildrenFolderIdsParams { driveKey: DriveKey; @@ -691,6 +692,7 @@ export class ArFSDAO extends ArFSDAOAnonymous { async getAllFoldersOfPrivateDrive( driveId: DriveID, driveKey: DriveKey, + owner: ArweaveAddress, latestRevisionsOnly = false ): Promise { let cursor = ''; @@ -703,7 +705,8 @@ export class ArFSDAO extends ArFSDAOAnonymous { { name: 'Drive-Id', value: driveId }, { name: 'Entity-Type', value: 'folder' } ], - cursor + cursor, + owner }); const response = await this.arweave.api.post(graphQLURL, gqlQuery); @@ -726,6 +729,7 @@ export class ArFSDAO extends ArFSDAOAnonymous { async getPrivateFilesWithParentFolderIds( folderIDs: FolderID[], driveKey: DriveKey, + owner: ArweaveAddress, latestRevisionsOnly = false ): Promise { let cursor = ''; @@ -738,7 +742,8 @@ export class ArFSDAO extends ArFSDAOAnonymous { { name: 'Parent-Folder-Id', value: folderIDs }, { name: 'Entity-Type', value: 'file' } ], - cursor + cursor, + owner }); const response = await this.arweave.api.post(graphQLURL, gqlQuery); @@ -874,12 +879,21 @@ export class ArFSDAO extends ArFSDAOAnonymous { async getPrivateChildrenFolderIds({ folderId, driveId, - driveKey + driveKey, + owner }: getPrivateChildrenFolderIdsParams): Promise { - return this.getChildrenFolderIds(folderId, await this.getAllFoldersOfPrivateDrive(driveId, driveKey, true)); + return this.getChildrenFolderIds( + folderId, + await this.getAllFoldersOfPrivateDrive(driveId, driveKey, owner, true) + ); } - async getPublicChildrenFolderIds({ folderId, driveId }: getPublicChildrenFolderIdsParams): Promise { - return this.getChildrenFolderIds(folderId, await this.getAllFoldersOfPublicDrive(driveId, true)); + + async getPublicChildrenFolderIds({ + folderId, + owner, + driveId + }: getPublicChildrenFolderIdsParams): Promise { + return this.getChildrenFolderIds(folderId, await this.getAllFoldersOfPublicDrive(driveId, owner, true)); } /** @@ -905,7 +919,7 @@ export class ArFSDAO extends ArFSDAOAnonymous { // Fetch all of the folder entities within the drive const driveIdOfFolder = folder.driveId; - const allFolderEntitiesOfDrive = await this.getAllFoldersOfPrivateDrive(driveIdOfFolder, driveKey, true); + const allFolderEntitiesOfDrive = await this.getAllFoldersOfPrivateDrive(driveIdOfFolder, driveKey, owner, true); const hierarchy = FolderHierarchy.newFromEntities(allFolderEntitiesOfDrive); const searchFolderIDs = hierarchy.folderIdSubtreeFromFolderId(folderId, maxDepth - 1); @@ -920,7 +934,12 @@ export class ArFSDAO extends ArFSDAOAnonymous { } // Fetch all file entities within all Folders of the drive - const childrenFileEntities = await this.getPrivateFilesWithParentFolderIds(searchFolderIDs, driveKey, true); + const childrenFileEntities = await this.getPrivateFilesWithParentFolderIds( + searchFolderIDs, + driveKey, + owner, + true + ); const children = [...childrenFolderEntities, ...childrenFileEntities]; diff --git a/src/arfsdao_anonymous.ts b/src/arfsdao_anonymous.ts index 169a14a6..bd769363 100644 --- a/src/arfsdao_anonymous.ts +++ b/src/arfsdao_anonymous.ts @@ -140,6 +140,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType { async getPublicFilesWithParentFolderIds( folderIDs: FolderID[], + owner: ArweaveAddress, latestRevisionsOnly = false ): Promise { let cursor = ''; @@ -152,7 +153,8 @@ export class ArFSDAOAnonymous extends ArFSDAOType { { name: 'Parent-Folder-Id', value: folderIDs }, { name: 'Entity-Type', value: 'file' } ], - cursor + cursor, + owner }); const response = await this.arweave.api.post(graphQLURL, gqlQuery); @@ -171,24 +173,31 @@ export class ArFSDAOAnonymous extends ArFSDAOType { return latestRevisionsOnly ? allFiles.filter(latestRevisionFilter) : allFiles; } - async getAllFoldersOfPublicDrive(driveId: DriveID, latestRevisionsOnly = false): Promise { + async getAllFoldersOfPublicDrive( + driveId: DriveID, + owner: ArweaveAddress, + latestRevisionsOnly = false + ): Promise { let cursor = ''; let hasNextPage = true; const allFolders: ArFSPublicFolder[] = []; while (hasNextPage) { + console.log('owner in getAll', owner); const gqlQuery = buildQuery({ tags: [ { name: 'Drive-Id', value: driveId }, { name: 'Entity-Type', value: 'folder' } ], - cursor + cursor, + owner }); const response = await this.arweave.api.post(graphQLURL, gqlQuery); const { data } = response.data; const { transactions } = data; const { edges } = transactions; + hasNextPage = transactions.pageInfo.hasNextPage; const folders: Promise[] = edges.map(async (edge: GQLEdgeInterface) => { const { node } = edge; @@ -222,7 +231,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType { // Fetch all of the folder entities within the drive const driveIdOfFolder = folder.driveId; - const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive(driveIdOfFolder, true); + const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive(driveIdOfFolder, owner, true); // Feed entities to FolderHierarchy const hierarchy = FolderHierarchy.newFromEntities(allFolderEntitiesOfDrive); @@ -238,7 +247,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType { } // Fetch all file entities within all Folders of the drive - const childrenFileEntities = await this.getPublicFilesWithParentFolderIds(searchFolderIDs, true); + const childrenFileEntities = await this.getPublicFilesWithParentFolderIds(searchFolderIDs, owner, true); const children = [...childrenFolderEntities, ...childrenFileEntities]; From f516798aadc1474e99a60eefcc464c3f0bc24cfc Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Mon, 1 Nov 2021 12:00:09 -0500 Subject: [PATCH 2/4] fix(owner filter): Excise debugging console log PE-645 --- src/arfsdao_anonymous.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/arfsdao_anonymous.ts b/src/arfsdao_anonymous.ts index bd769363..8ab45e32 100644 --- a/src/arfsdao_anonymous.ts +++ b/src/arfsdao_anonymous.ts @@ -183,7 +183,6 @@ export class ArFSDAOAnonymous extends ArFSDAOType { const allFolders: ArFSPublicFolder[] = []; while (hasNextPage) { - console.log('owner in getAll', owner); const gqlQuery = buildQuery({ tags: [ { name: 'Drive-Id', value: driveId }, From 8198d1cd3b87835d41c5f9b217150a4fb33e1d49 Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Mon, 1 Nov 2021 12:08:05 -0500 Subject: [PATCH 3/4] refactor(owner filter): Use destructured params PE-645 --- src/arfsdao.ts | 32 ++++++++++++++++++++++---------- src/arfsdao_anonymous.ts | 20 +++++++++++++++----- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/arfsdao.ts b/src/arfsdao.ts index e05bfe21..c02f8935 100644 --- a/src/arfsdao.ts +++ b/src/arfsdao.ts @@ -70,7 +70,8 @@ import { ArFSUploadPrivateFileResult, ArFSCreateDriveResultFactory, ArFSMoveEntityResultFactory, - ArFSUploadFileResultFactory + ArFSUploadFileResultFactory, + WithDriveKey } from './arfs_entity_result_factory'; import { ArFSFileOrFolderEntity, @@ -82,7 +83,7 @@ import { ArFSPublicFile, ArFSPublicFolder } from './arfs_entities'; -import { ArFSDAOAnonymous } from './arfsdao_anonymous'; +import { ArFSAllPublicFoldersOfDriveParams, ArFSDAOAnonymous } from './arfsdao_anonymous'; import { ArFSFileOrFolderBuilder } from './utils/arfs_builders/arfs_builders'; import { PrivateKeyData } from './private_key_data'; import { ArweaveAddress } from './arweave_address'; @@ -127,6 +128,9 @@ export interface UploadPublicFileParams { export interface UploadPrivateFileParams extends UploadPublicFileParams { driveKey: DriveKey; } + +export type ArFSAllPrivateFoldersOfDriveParams = ArFSAllPublicFoldersOfDriveParams & WithDriveKey; + export interface CreateFolderSettings { driveId: DriveID; rewardSettings: RewardSettings; @@ -689,12 +693,12 @@ export class ArFSDAO extends ArFSDAOAnonymous { return new ArFSPrivateFileBuilder(fileId, this.arweave, driveKey, owner).build(); } - async getAllFoldersOfPrivateDrive( - driveId: DriveID, - driveKey: DriveKey, - owner: ArweaveAddress, + async getAllFoldersOfPrivateDrive({ + driveId, + driveKey, + owner, latestRevisionsOnly = false - ): Promise { + }: ArFSAllPrivateFoldersOfDriveParams): Promise { let cursor = ''; let hasNextPage = true; const allFolders: ArFSPrivateFolder[] = []; @@ -884,7 +888,7 @@ export class ArFSDAO extends ArFSDAOAnonymous { }: getPrivateChildrenFolderIdsParams): Promise { return this.getChildrenFolderIds( folderId, - await this.getAllFoldersOfPrivateDrive(driveId, driveKey, owner, true) + await this.getAllFoldersOfPrivateDrive({ driveId, driveKey, owner, latestRevisionsOnly: true }) ); } @@ -893,7 +897,10 @@ export class ArFSDAO extends ArFSDAOAnonymous { owner, driveId }: getPublicChildrenFolderIdsParams): Promise { - return this.getChildrenFolderIds(folderId, await this.getAllFoldersOfPublicDrive(driveId, owner, true)); + return this.getChildrenFolderIds( + folderId, + await this.getAllFoldersOfPublicDrive({ driveId, owner, latestRevisionsOnly: true }) + ); } /** @@ -919,7 +926,12 @@ export class ArFSDAO extends ArFSDAOAnonymous { // Fetch all of the folder entities within the drive const driveIdOfFolder = folder.driveId; - const allFolderEntitiesOfDrive = await this.getAllFoldersOfPrivateDrive(driveIdOfFolder, driveKey, owner, true); + const allFolderEntitiesOfDrive = await this.getAllFoldersOfPrivateDrive({ + driveId: driveIdOfFolder, + driveKey, + owner, + latestRevisionsOnly: true + }); const hierarchy = FolderHierarchy.newFromEntities(allFolderEntitiesOfDrive); const searchFolderIDs = hierarchy.folderIdSubtreeFromFolderId(folderId, maxDepth - 1); diff --git a/src/arfsdao_anonymous.ts b/src/arfsdao_anonymous.ts index 8ab45e32..c4f52e18 100644 --- a/src/arfsdao_anonymous.ts +++ b/src/arfsdao_anonymous.ts @@ -14,6 +14,12 @@ import { ArweaveAddress } from './arweave_address'; export const graphQLURL = 'https://arweave.net/graphql'; +export interface ArFSAllPublicFoldersOfDriveParams { + driveId: DriveID; + owner: ArweaveAddress; + latestRevisionsOnly: boolean; +} + export interface ArFSListPublicFolderParams { folderId: FolderID; maxDepth: number; @@ -173,11 +179,11 @@ export class ArFSDAOAnonymous extends ArFSDAOType { return latestRevisionsOnly ? allFiles.filter(latestRevisionFilter) : allFiles; } - async getAllFoldersOfPublicDrive( - driveId: DriveID, - owner: ArweaveAddress, + async getAllFoldersOfPublicDrive({ + driveId, + owner, latestRevisionsOnly = false - ): Promise { + }: ArFSAllPublicFoldersOfDriveParams): Promise { let cursor = ''; let hasNextPage = true; const allFolders: ArFSPublicFolder[] = []; @@ -230,7 +236,11 @@ export class ArFSDAOAnonymous extends ArFSDAOType { // Fetch all of the folder entities within the drive const driveIdOfFolder = folder.driveId; - const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive(driveIdOfFolder, owner, true); + const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive({ + driveId: driveIdOfFolder, + owner, + latestRevisionsOnly: true + }); // Feed entities to FolderHierarchy const hierarchy = FolderHierarchy.newFromEntities(allFolderEntitiesOfDrive); From d7b3c04f347540212d1ddac9f8a51b4fd0f862cf Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Mon, 1 Nov 2021 16:12:18 -0500 Subject: [PATCH 4/4] chore(version): Bump to v1.0.1 PE-649 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9aea449..1fe1f91c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ardrive-cli", - "version": "1.0.0", + "version": "1.0.1", "description": "The ArDrive Command Line Interface (CLI is a Node.js application for terminal-based ArDrive workflows. It also offers utility operations for securely interacting with Arweave wallets and inspecting various Arweave blockchain conditions.", "main": "./lib/index.js", "bin": {