From acf045965e017d127544046ace82974984da5009 Mon Sep 17 00:00:00 2001 From: Mihajlo Medjedovic Date: Tue, 5 Jan 2021 16:21:18 +0100 Subject: [PATCH] fix: move command improved --- src/ContextManager.ts | 1 - src/SASViyaApiClient.ts | 14 +++++++++----- src/SASjs.ts | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ContextManager.ts b/src/ContextManager.ts index bb4c0a1..576645e 100644 --- a/src/ContextManager.ts +++ b/src/ContextManager.ts @@ -5,7 +5,6 @@ import { ContextAllAttributes } from './types' import { makeRequest, isUrl } from './utils' -import { SASViyaApiClient } from './SASViyaApiClient' import { prefixMessage } from '@sasjs/utils/error' export class ContextManager { diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index 07faf47..d2b6708 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -24,6 +24,7 @@ import { SessionManager } from './SessionManager' import { ContextManager } from './ContextManager' import { timestampToYYYYMMDDHHMMSS } from '@sasjs/utils/time' import { Logger, LogLevel } from '@sasjs/utils/logger' +import { prefixMessage } from '@sasjs/utils/error' /** * A client for interfacing with the SAS Viya REST API. @@ -1308,7 +1309,7 @@ export class SASViyaApiClient { * @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder listed. Providing URI instead of path will save one extra request. * @param accessToken - an access token for authorizing the request. */ - public async listFolder(sourceFolder: string, accessToken?: string) { + public async listFolder(sourceFolder: string, accessToken?: string, limit: number = 20) { // checks if 'sourceFolder' is already a URI const sourceFolderUri = isUri(sourceFolder) ? sourceFolder @@ -1322,10 +1323,8 @@ export class SASViyaApiClient { } } - const url = sourceFolderUri - const { result: members } = await this.request<{ items: any[] }>( - `${this.serverUrl}${url}/members`, + `${this.serverUrl}${sourceFolderUri}/members?limit=${limit}`, requestInfo ).catch((err) => { if (err.code && err.code === 'ENOTFOUND') { @@ -1338,7 +1337,7 @@ export class SASViyaApiClient { throw notFoundError } - throw err + throw prefixMessage(err, 'There was an error while fetching folder children') }) return members.items.map((item: any) => item.name) @@ -1357,6 +1356,11 @@ export class SASViyaApiClient { targetFolderName: string, accessToken: string ) { + // If target path is existing folder, than keep source folder name, othervise rename it with given target folder name + const sourceFolderName = sourceFolder.split('/').pop() as string + let targetFolderDetails = await this.getFolderDetails(targetParentFolder, accessToken) + targetFolderName = targetFolderDetails ? sourceFolderName : targetFolderName + // checks if 'sourceFolder' is already a URI const sourceFolderUri = isUri(sourceFolder) ? sourceFolder diff --git a/src/SASjs.ts b/src/SASjs.ts index 4ccc7b1..65c10d2 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -335,10 +335,10 @@ export default class SASjs { * @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder listed. Providing URI instead of path will save one extra request. * @param accessToken - an access token for authorizing the request. */ - public async listFolder(sourceFolder: string, accessToken?: string) { + public async listFolder(sourceFolder: string, accessToken?: string, limit?: number) { this.isMethodSupported('listFolder', ServerType.SASViya) - return await this.sasViyaApiClient?.listFolder(sourceFolder, accessToken) + return await this.sasViyaApiClient?.listFolder(sourceFolder, accessToken, limit) } /**