mirror of
https://github.com/sasjs/adapter.git
synced 2026-04-21 21:21:31 +00:00
feat: listFolder and improvements
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
@@ -76,7 +76,7 @@
|
||||
<section class="tsd-index-section ">
|
||||
<h3>Modules</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-module tsd-is-not-exported"><a href="modules/reflection-804.html" class="tsd-kind-icon"><em>Module</em></a></li>
|
||||
<li class="tsd-kind-module tsd-is-not-exported"><a href="modules/reflection-817.html" class="tsd-kind-icon"><em>Module</em></a></li>
|
||||
<li class="tsd-kind-module"><a href="modules/types.html" class="tsd-kind-icon">types</a></li>
|
||||
<li class="tsd-kind-module"><a href="modules/utils.html" class="tsd-kind-icon">utils</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.folder.html#id" class="tsd-kind-icon">id</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.folder.html#links" class="tsd-kind-icon">links</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.folder.html#membercount" class="tsd-kind-icon">memberCount</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.folder.html#uri" class="tsd-kind-icon">uri</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
@@ -128,6 +129,20 @@
|
||||
</ul>
|
||||
</aside>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
|
||||
<a name="membercount" class="tsd-anchor"></a>
|
||||
<h3>member<wbr>Count</h3>
|
||||
<div class="tsd-signature tsd-kind-icon">member<wbr>Count<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in
|
||||
<a href="https://github.com/sasjs/adapter/blob/master/src/types/Folder.ts#L7">
|
||||
types/Folder.ts:7
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
|
||||
<a name="uri" class="tsd-anchor"></a>
|
||||
<h3>uri</h3>
|
||||
@@ -180,6 +195,9 @@
|
||||
<li class=" tsd-kind-property tsd-parent-kind-interface">
|
||||
<a href="types.folder.html#links" class="tsd-kind-icon">links</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-interface">
|
||||
<a href="types.folder.html#membercount" class="tsd-kind-icon">member<wbr>Count</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-interface">
|
||||
<a href="types.folder.html#uri" class="tsd-kind-icon">uri</a>
|
||||
</li>
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+57
-3
@@ -1359,8 +1359,13 @@ export class SASViyaApiClient {
|
||||
return uploadedFiles
|
||||
}
|
||||
|
||||
private async getFolderUri(folderPath: string, accessToken?: string) {
|
||||
const url = '/folders/folders/@item?path=' + folderPath
|
||||
private async getFolderDetails(
|
||||
folderPath: string,
|
||||
accessToken?: string
|
||||
): Promise<Folder | undefined> {
|
||||
const url = isUri(folderPath)
|
||||
? folderPath
|
||||
: `/folders/folders/@item?path=${folderPath}`
|
||||
const requestInfo: any = {
|
||||
method: 'GET'
|
||||
}
|
||||
@@ -1375,7 +1380,15 @@ export class SASViyaApiClient {
|
||||
})
|
||||
|
||||
if (!folder) return undefined
|
||||
return `/folders/folders/${folder.id}`
|
||||
return folder
|
||||
}
|
||||
|
||||
private async getFolderUri(folderPath: string, accessToken?: string) {
|
||||
const folderDetails = await this.getFolderDetails(folderPath, accessToken)
|
||||
|
||||
if (!folderDetails) return undefined
|
||||
|
||||
return `/folders/folders/${folderDetails.id}`
|
||||
}
|
||||
|
||||
private async getRecycleBinUri(accessToken: string) {
|
||||
@@ -1459,6 +1472,47 @@ export class SASViyaApiClient {
|
||||
return context
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists a children folders for given Viya folder.
|
||||
* @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) {
|
||||
// checks if 'sourceFolder' is already a URI
|
||||
const sourceFolderUri = isUri(sourceFolder)
|
||||
? sourceFolder
|
||||
: await this.getFolderUri(sourceFolder, accessToken)
|
||||
|
||||
const requestInfo = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + accessToken
|
||||
}
|
||||
}
|
||||
|
||||
const url = sourceFolderUri
|
||||
|
||||
const { result: members } = await this.request<{ items: any[] }>(
|
||||
`${this.serverUrl}${url}/members`,
|
||||
requestInfo
|
||||
).catch((err) => {
|
||||
if (err.code && err.code === 'ENOTFOUND') {
|
||||
const notFoundError = {
|
||||
body: JSON.stringify({
|
||||
message: `Folder '${sourceFolder.split('/').pop()}' was not found.`
|
||||
})
|
||||
}
|
||||
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
throw err
|
||||
})
|
||||
|
||||
return members.items.map((item: any) => item.name)
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a Viya folder to a new location. The folder may be renamed at the same time.
|
||||
* @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
|
||||
|
||||
@@ -277,6 +277,17 @@ export default class SASjs {
|
||||
return await this.sasViyaApiClient?.deleteFolder(folderPath, accessToken)
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists a children folders for given Viya folder.
|
||||
* @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) {
|
||||
this.isMethodSupported('listFolder', ServerType.SASViya)
|
||||
|
||||
return await this.sasViyaApiClient?.listFolder(sourceFolder, accessToken)
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves folder to a new location. The folder may be renamed at the same time.
|
||||
* @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
|
||||
|
||||
Reference in New Issue
Block a user