Skip to content

Commit

Permalink
fix: go back to storageType to avoid breaking the api
Browse files Browse the repository at this point in the history
  • Loading branch information
wkolod committed Jul 18, 2023
1 parent 98197ef commit c5f7411
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ const { name: fileName, data: fileBuffer } = await akord.stack.getVersion(stackI
Get stack file uri by index, return the latest file uri by default

- `stackId` (`string`, required)
- `type` (`StorageClass`, optional) - storage type, default to arweave
- `type` (`StorageType`, optional) - storage type, default to arweave
- `index` (`number`, optional) - file version index, default to latest
- returns `Promise<string>` - Promise with stack file uri

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Akord } from "../index";
import faker from '@faker-js/faker';
import { initInstance, testDataPath, vaultCreate } from './common';
import { email, password } from './data/test-credentials';
import { StorageClass } from "../types/file";
import { StorageType } from "../types/file";
import { NodeJs } from "../types/file-like";
import { getTxData } from "../arweave";
import { firstFileName, secondFileName, arweaveImportFileTx } from './data/content';
Expand Down Expand Up @@ -62,7 +62,7 @@ export const stackCreate = async (vaultId: string) => {
expect(stack.versions.length).toEqual(1);
expect(stack.versions[0].name).toEqual(firstFileName);

const binary = await akord.file.get(stack.getUri(StorageClass.S3, 0), vaultId);
const binary = await akord.file.get(stack.getUri(StorageType.S3, 0), vaultId);
expect(binary).toEqual(await file.arrayBuffer());
return stackId;
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/akord-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { Transaction } from "../types/transaction";
import { Paginated } from "../types/paginated";
import { ListOptions, VaultApiGetOptions } from "../types/query-options";
import { User, UserPublicInfo } from "../types/user";
import { FileDownloadOptions, FileUploadOptions, StorageClass } from "../types/file";
import { FileDownloadOptions, FileUploadOptions, StorageType } from "../types/file";
import { EncryptionMetadata } from "../types/encryption";

export const defaultFileUploadOptions = {
storage: StorageClass.ARWEAVE,
storage: StorageType.ARWEAVE,
public: false
};

Expand Down
6 changes: 3 additions & 3 deletions src/api/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { throwError } from "../errors/error";
import { BadRequest } from "../errors/bad-request";
import { NotFound } from "../errors/not-found";
import { User, UserPublicInfo } from "../types/user";
import { StorageClass } from "../types/file";
import { StorageType } from "../types/file";

export class ApiClient {
private _storageurl: string;
Expand All @@ -32,7 +32,7 @@ export class ApiClient {
private _input: ContractInput;
private _vaultId: string;
private _cacheOnly: boolean;
private _storage: StorageClass;
private _storage: StorageType;
private _numberOfChunks: number;

constructor() { }
Expand All @@ -59,7 +59,7 @@ export class ApiClient {
return this;
}

storage(storage: StorageClass): ApiClient {
storage(storage: StorageType): ApiClient {
this._storage = storage;
return this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { base64ToArray, digestRaw, signHash } from "@akord/crypto";
import { Logger } from "../logger";
import { ApiClient } from "../api/api-client";
import { v4 as uuid } from "uuid";
import { DownloadOptions, FileDownloadOptions, FileUploadOptions, FileUploadResult, Hooks, StorageClass } from "../types/file";
import { DownloadOptions, FileDownloadOptions, FileUploadOptions, FileUploadResult, Hooks, StorageType } from "../types/file";
import { FileLike } from "../types/file-like";
import { Blob } from "buffer";
import { Tag, Tags } from "../types/contract";
Expand Down Expand Up @@ -133,7 +133,7 @@ class FileService extends Service {
.data(processedData)
.tags(tags.concat(encryptionTags))
.public(this.isPublic)
.storage(StorageClass.S3)
.storage(StorageType.S3)
.uploadFile()
resourceUri.push(`arweave:${fileTxId}`);
return { file, resourceUri };
Expand Down Expand Up @@ -260,7 +260,7 @@ class FileService extends Service {
.data(chunk.processedData)
.tags(tags.concat(chunk.encryptionTags))
.public(this.isPublic)
.storage(StorageClass.S3)
.storage(StorageType.S3)
.progressHook(options.progressHook, chunkNumber * this.chunkSize, resourceSize)
.cancelHook(options.cancelHook)
.uploadFile()
Expand Down
4 changes: 2 additions & 2 deletions src/core/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { EncryptedPayload } from "@akord/crypto/lib/types";
import { IncorrectEncryptionKey } from "../errors/incorrect-encryption-key";
import { ProfileDetails } from "../types/profile-details";
import { ListOptions } from "../types/query-options";
import { StorageClass } from "../types/file";
import { StorageType } from "../types/file";
import { EncryptionMetadata } from "../types/encryption";

export const STATE_CONTENT_TYPE = "application/json";
Expand Down Expand Up @@ -251,7 +251,7 @@ class Service {

protected async processAvatar(avatar: ArrayBuffer, cacheOnly?: boolean): Promise<string[]> {
const { processedData, encryptionTags } = await this.processWriteRaw(avatar);
const storage = cacheOnly ? StorageClass.S3 : StorageClass.ARWEAVE;
const storage = cacheOnly ? StorageType.S3 : StorageType.ARWEAVE;
return this.api.uploadFile(processedData, encryptionTags, { storage, public: false });
}

Expand Down
12 changes: 6 additions & 6 deletions src/core/stack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NodeService } from "./node";
import { actionRefs, functions, objectType } from "../constants";
import { FileService } from "./file";
import { FileUploadOptions, FileVersion, StorageClass } from "../types/file";
import { FileUploadOptions, FileVersion, StorageType } from "../types/file";
import { FileLike } from "../types/file-like";
import { nodeType, NodeCreateOptions } from "../types/node";
import { Stack, StackCreateOptions, StackCreateResult, StackUpdateResult } from "../types/stack";
Expand All @@ -22,7 +22,7 @@ class StackService extends NodeService<Stack> {
Promise<StackCreateResult> {
await this.setVaultContext(vaultId);
const optionsFromVault = {
storage: this.vault.cacheOnly ? StorageClass.S3 : StorageClass.ARWEAVE
storage: this.vault.cacheOnly ? StorageType.S3 : StorageType.ARWEAVE
}
const createOptions = {
...this.defaultCreateOptions,
Expand Down Expand Up @@ -84,7 +84,7 @@ class StackService extends NodeService<Stack> {
this.setActionRef(actionRefs.STACK_UPLOAD_REVISION);

const optionsFromVault = {
storage: this.object.__cacheOnly__ ? StorageClass.S3 : StorageClass.ARWEAVE
storage: this.object.__cacheOnly__ ? StorageType.S3 : StorageType.ARWEAVE
}

const uploadOptions = {
Expand All @@ -110,7 +110,7 @@ class StackService extends NodeService<Stack> {
const version = stack.getVersion(index);
await this.setVaultContext(stack.vaultId);
this.setVaultContextForFile();
const { fileData, metadata } = await this.api.downloadFile(version.getUri(StorageClass.S3), { public: this.isPublic });
const { fileData, metadata } = await this.api.downloadFile(version.getUri(StorageType.S3), { public: this.isPublic });
const data = await this.processReadRaw(fileData, metadata);
const name = await this.processReadString(version.name);
return { name, data };
Expand All @@ -119,11 +119,11 @@ class StackService extends NodeService<Stack> {
/**
* Get stack file uri by index, return the latest file uri by default
* @param {string} stackId
* @param {StorageClass} [type] storage type, default to arweave
* @param {StorageType} [type] storage type, default to arweave
* @param {number} [index] file version index, default to latest
* @returns Promise with stack file uri
*/
public async getUri(stackId: string, type: StorageClass = StorageClass.ARWEAVE, index?: number): Promise<string> {
public async getUri(stackId: string, type: StorageType = StorageType.ARWEAVE, index?: number): Promise<string> {
const stack = new Stack(await this.api.getNode<Stack>(stackId, objectType.STACK, this.vaultId), null);
return stack.getUri(type, index);
}
Expand Down
6 changes: 3 additions & 3 deletions src/types/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class FileVersion extends Encryptable implements Version {
this.status = fileVersionProto.status;
}

getUri(type: StorageClass): string {
getUri(type: StorageType): string {
const resourceUri = this.resourceUri
?.find(uri => uri.startsWith(type))
?.replace(type + ":", "");
Expand All @@ -52,7 +52,7 @@ export type Hooks = {

export type FileUploadOptions = Hooks & {
public?: boolean,
storage?: StorageClass,
storage?: StorageType,
arweaveTags?: Tags
}

Expand All @@ -64,7 +64,7 @@ export type FileDownloadOptions = Hooks & {
resourceSize?: number
}

export enum StorageClass {
export enum StorageType {
ARWEAVE = "arweave",
S3 = "s3"
}
4 changes: 2 additions & 2 deletions src/types/stack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { encrypted, EncryptedKeys } from "@akord/crypto";
import { Node, NodeCreateOptions } from "./node";
import { FileUploadOptions, FileVersion, StorageClass } from "./file";
import { FileUploadOptions, FileVersion, StorageType } from "./file";

export class Stack extends Node {
@encrypted() name: string;
Expand All @@ -12,7 +12,7 @@ export class Stack extends Node {
this.versions = (nodeLike.versions || []).map((version: FileVersion) => new FileVersion(version, keys));
}

getUri(type: StorageClass = StorageClass.ARWEAVE, index?: number): string {
getUri(type: StorageType = StorageType.ARWEAVE, index?: number): string {
const version = this.getVersion(index);
return version.getUri(type);
}
Expand Down

0 comments on commit c5f7411

Please sign in to comment.