-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from skyflowapi/release/23.7.1
SK-861/Release/23.7.1
- Loading branch information
Showing
11 changed files
with
711 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import Client from "../client"; | ||
import SkyflowError from "../libs/SkyflowError"; | ||
import { IDeleteOptions, IDeleteRecord } from "../utils/common"; | ||
|
||
const formatForPureJsFailure = (cause, skyflowId: string) => ({ | ||
id: skyflowId, | ||
...new SkyflowError({ | ||
code: cause?.error?.code, | ||
description: cause?.error?.description, | ||
}, [], true), | ||
}); | ||
|
||
const deleteRecordInVault = ( | ||
deleteRecord: IDeleteRecord, | ||
options: IDeleteOptions, | ||
client: Client, | ||
authToken: string, | ||
): Promise<any> => { | ||
const vaultEndPointURL: string = `${client.config.vaultURL}/v1/vaults/${client.config.vaultID}/${deleteRecord.table}/${deleteRecord.id}`; | ||
return client.request({ | ||
requestMethod: 'DELETE', | ||
url: vaultEndPointURL, | ||
headers: { | ||
Authorization: `Bearer ${authToken}`, | ||
'Content-Type': 'application/json', | ||
} | ||
}); | ||
}; | ||
|
||
/** Delete By Skyflow ID */ | ||
export const deleteRecordsBySkyflowID = ( | ||
deleteRecords: IDeleteRecord[], | ||
options: IDeleteOptions, | ||
client: Client, | ||
authToken: String | ||
) => { | ||
return new Promise((rootResolve, rootReject) => { | ||
const vaultResponseSet: Promise<any>[] = deleteRecords.map( | ||
(deleteRecord) => | ||
new Promise((resolve) => { | ||
const deleteResponse: any = []; | ||
deleteRecordInVault( | ||
deleteRecord, | ||
options, | ||
client, | ||
authToken as string | ||
) | ||
.then( | ||
(response: any) => { | ||
deleteResponse.push(response); | ||
}, | ||
(cause: any) => { | ||
deleteResponse.push(formatForPureJsFailure(cause, deleteRecord.id)); | ||
} | ||
) | ||
.finally(() => { | ||
resolve(deleteResponse); | ||
}); | ||
}) | ||
); | ||
|
||
Promise.allSettled(vaultResponseSet).then((resultSet) => { | ||
const recordsResponse: Record<string, any>[] = []; | ||
const errorResponse: Record<string, any>[] = []; | ||
resultSet.forEach((result) => { | ||
if (result.status === "fulfilled") { | ||
result.value.forEach((res: Record<string, any>) => { | ||
if (Object.prototype.hasOwnProperty.call(res, "error")) { | ||
errorResponse.push(res); | ||
} else { | ||
recordsResponse.push(res); | ||
} | ||
}); | ||
} | ||
}); | ||
if (errorResponse.length === 0) { | ||
rootResolve({ records: recordsResponse }); | ||
} else if (recordsResponse.length === 0) { | ||
rootReject({ errors: errorResponse }); | ||
}else rootReject({ records: recordsResponse, errors: errorResponse }); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.