Skip to content

Commit

Permalink
completed Collection,proposal,space doc (#2777)
Browse files Browse the repository at this point in the history
* completed Collection,proposal,space doc

* finished other SDKs

---------

Co-authored-by: Adam <[email protected]>
  • Loading branch information
adamunchained and Adam authored Jan 26, 2024
1 parent 47ebb5d commit 4502b6b
Show file tree
Hide file tree
Showing 30 changed files with 745 additions and 63 deletions.
56 changes: 51 additions & 5 deletions packages/interfaces/src/models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,73 @@ export interface ValidatedAddress {
* NFT Minted Metadata.
*/
export interface NftMintingData {
/**
* Address of the asset.
*/
readonly address?: string;
/**
* Network its minted on.
*/
readonly network?: Network;

/**
* Date minted on.
*/
readonly mintedOn?: Timestamp;
/**
* User it's minted by.
*/
readonly mintedBy?: string;

/**
* Block id on the chain
*/
readonly blockId?: string;
/**
* NFT ID on the chain.
*/
readonly nftId?: string;
/**
* Storage deposit requirement.
*/
readonly storageDeposit?: number;

/**
* Alias Block Id on chain.
*/
readonly aliasBlockId?: string;
/**
* Alias Id on chain.
*/
readonly aliasId?: string;
/**
* Alias storage deposit requirement.
*/
readonly aliasStorageDeposit?: number;

/**
* Minting order id to initiate this mint.
*/
readonly mintingOrderId?: string;

/**
* Total number of NFTs to be minted.
*/
readonly nftsToMint?: number;
/**
* Total number of NFTs to be uploaded to file storage.
*/
readonly nftMediaToUpload?: number;
/**
* Total number of NFTs to be prepared for the file upload.
*/
readonly nftMediaToPrepare?: number;
/**
* Unsold options. What happens to unsold NFTs after mint.
*/
readonly unsoldMintingOptions?: UnsoldMintingOptions;
/**
* New price for NFT after it's minted.
*/
readonly newPrice?: number;
/**
* NFT Storage deposit requirement.
*/
readonly nftsStorageDeposit?: number;
}

Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/https/datasets/AuctionDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ import { DatasetClass } from './Dataset';
*/
export class AuctionDataset<D extends Dataset> extends DatasetClass<D, Auction> {
/**
* Create generic auction.
* Create generic Auction.
*
* @param req Use {@link Build5Request} with data based on {@link AuctionCreateRequest}
* @returns
*/
create = (req: Build5Request<AuctionCreateRequest>) =>
this.sendRequest(WEN_FUNC.createauction)<AuctionCreateRequest, Auction>(req);

/**
* Bid on an auction.
* Bid on auction.
*
* @param req Use {@link Build5Request} with data based on {@link AuctionBidRequest}
* @returns
*/
bid = (req: Build5Request<AuctionBidRequest>) =>
this.sendRequest(WEN_FUNC.bidAuction)<AuctionBidRequest, Transaction>(req);
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/https/datasets/BadgesDataset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Badge, Dataset } from '@build-5/interfaces';
import { DatasetClass } from './Dataset';

/**
* Badges dataset.
*/
export class BadgesDataset<D extends Dataset> extends DatasetClass<D, Badge> {}
59 changes: 57 additions & 2 deletions packages/sdk/src/https/datasets/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,41 @@ abstract class BaseDataSetClass<T> extends BaseSet<T> {
};
}

/**
* Dataset base class.
*/
export abstract class DatasetClass<D extends Dataset, T> extends BaseDataSetClass<T> {
/**
* Get many records by id.
*
* @param setIds
* @returns
*/
getManyById = (setIds: string[]) =>
wrappedFetch<T[]>(this.apiKey, this.origin + ApiRoutes.GET_MANY_BY_ID, {
dataset: this.dataset,
setIds,
});

/**
* Get many records by id. Real time stream.
*
* @param setIds
* @returns
*/
getManyByIdLive = (setIds: string[]): Observable<T[]> => {
const params = { dataset: this.dataset, setIds };
const url = this.origin + ApiRoutes.GET_MANY_BY_ID + toQueryParams({ ...params });
return fetchLive<T[]>(this.apiKey, url);
};

/**
* Get records by field.
*
* @param fieldName
* @param fieldValue
* @param startAfter
* @returns
*/
getByField = async (
fieldName: string | string[],
fieldValue: string | number | boolean | (string | number | boolean)[],
Expand All @@ -79,6 +101,13 @@ export abstract class DatasetClass<D extends Dataset, T> extends BaseDataSetClas
return await wrappedFetch<T[]>(this.apiKey, this.origin + ApiRoutes.GET_MANY, params);
};

/**
* Get records by field. Real time stream.
* @param fieldName
* @param fieldValue
* @param startAfter
* @returns
*/
getByFieldLive = (
fieldName: string | string[],
fieldValue: string | number | boolean | (string | number | boolean)[],
Expand All @@ -89,6 +118,13 @@ export abstract class DatasetClass<D extends Dataset, T> extends BaseDataSetClas
return fetchLive<T[]>(this.apiKey, url);
};

/**
* Get records by space.
*
* @param space
* @param startAfter
* @returns
*/
getBySpace = async (space: string, startAfter?: string) => {
const params: GetManyRequest = {
dataset: this.dataset,
Expand All @@ -100,6 +136,12 @@ export abstract class DatasetClass<D extends Dataset, T> extends BaseDataSetClas
return await wrappedFetch<T[]>(this.apiKey, url, { ...params });
};

/**
* Get records by space. Real time stream.
* @param space
* @param startAfter
* @returns
*/
getBySpaceLive = (space: string, startAfter?: string) => {
const params: GetManyAdvancedRequest = {
dataset: this.dataset,
Expand All @@ -113,12 +155,25 @@ export abstract class DatasetClass<D extends Dataset, T> extends BaseDataSetClas
return this.getManyAdvancedLive(params);
};

/**
* Get all records updated after unix timestamp.
*
* @param updatedAfter
* @param startAfter
* @returns
*/
getAllUpdatedAfter = async (updatedAfter: number, startAfter?: string) => {
const params: GetUpdatedAfterRequest = { dataset: this.dataset, updatedAfter, startAfter };
const url = this.origin + ApiRoutes.GET_UPDATED_AFTER;
return await wrappedFetch<T[]>(this.apiKey, url, { ...params });
};

/**
* Get all records updated after unix timestamp. Real time stream.
*
* @param updatedAfter
* @param startAfter
* @returns
*/
getAllUpdatedAfterLive = (updatedAfter: number, startAfter?: string): Observable<T[]> => {
const params: GetUpdatedAfterRequest = { dataset: this.dataset, updatedAfter, startAfter };
const url = this.origin + ApiRoutes.GET_UPDATED_AFTER + toQueryParams({ ...params });
Expand Down
23 changes: 21 additions & 2 deletions packages/sdk/src/https/datasets/MemberDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@ import {
} from '@build-5/interfaces';
import { DatasetClass } from './Dataset';

/**
* Member dataset
*/
export class MemberDataset<D extends Dataset> extends DatasetClass<D, Member> {
/**
* Update member details.
*
* @param req Use {@link Build5Request} with data based on {@link MemberUpdateRequest}
* @returns
*/
update = (req: Build5Request<MemberUpdateRequest>) =>
this.sendRequest(WEN_FUNC.updateMember)<MemberUpdateRequest, Member>(req);

/**
* Generate AUTH token.
*
* @param req Use {@link Build5Request} with data based on {@link CustomTokenRequest}
* @returns
*/
generateCustomToken = (req: Build5Request<CustomTokenRequest>) =>
this.sendRequest(WEN_FUNC.generateCustomToken)<CustomTokenRequest, string>(req);

/**
* Validate member address.
*
* @param req Use {@link Build5Request} with data based on {@link AddressValidationRequest}
* @returns
*/
validateAddress = (req: Build5Request<AddressValidationRequest>) =>
this.sendRequest(WEN_FUNC.validateAddress)<AddressValidationRequest, Transaction>(req);
}
87 changes: 78 additions & 9 deletions packages/sdk/src/https/datasets/NftDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,99 @@ import {
} from '@build-5/interfaces';
import { DatasetClass } from './Dataset';

/**
* NFT Dataset.
*/
export class NftDataset<D extends Dataset> extends DatasetClass<D, Nft> {
/**
* Create NFT
*
* @param req Use {@link Build5Request} with data based on {@link NftCreateRequest}
* @returns
*/
create = (req: Build5Request<NftCreateRequest>) =>
this.sendRequest(WEN_FUNC.createNft)<NftCreateRequest, Nft>(req);

/**
* Create batch NFT
*
* @param req Use {@link Build5Request} with data based on {@link NftCreateRequest}
* @returns
*/
createBatch = (req: Build5Request<NftCreateRequest[]>) =>
this.sendRequest(WEN_FUNC.createBatchNft)<NftCreateRequest[], Nft[]>(req);

/**
* Set NFT for sale
*
* @param req Use {@link Build5Request} with data based on {@link NftSetForSaleRequest}
* @returns
*/
setForSale = (req: Build5Request<NftSetForSaleRequest>) =>
this.sendRequest(WEN_FUNC.setForSaleNft)<NftSetForSaleRequest, Nft>(req);

/**
* Withdraw NFT
*
* @param req Use {@link Build5Request} with data based on {@link NftWithdrawRequest}
* @returns
*/
withdraw = (req: Build5Request<NftWithdrawRequest>) =>
this.sendRequest(WEN_FUNC.withdrawNft)<NftWithdrawRequest, void>(req);

/**
* Deposit NFT
*
* @param req Use {@link Build5Request} with data based on {@link ProjectDeactivateRequest}
* @returns
*/
deposit = (req: Build5Request<NftDepositRequest>) =>
this.sendRequest(WEN_FUNC.depositNft)<NftDepositRequest, Transaction>(req);

/**
* Update unsold NFT.
*
* @param req Use {@link Build5Request} with data based on {@link NftUpdateUnsoldRequest}
* @returns
*/
updateUnsold = (req: Build5Request<NftUpdateUnsoldRequest>) =>
this.sendRequest(WEN_FUNC.updateUnsoldNft)<NftUpdateUnsoldRequest, Nft>(req);

/**
* Buy NFT.
*
* @param req Use {@link Build5Request} with data based on {@link NftPurchaseRequest}
* @returns
*/
order = (req: Build5Request<NftPurchaseRequest>) =>
this.sendRequest(WEN_FUNC.orderNft)<NftPurchaseRequest, Transaction>(req);

/**
* Bin on NFT.
*
* @param req Use {@link Build5Request} with data based on {@link NftBidRequest}
* @returns
*/
openBid = (req: Build5Request<NftBidRequest>) =>
this.sendRequest(WEN_FUNC.openBid)<NftBidRequest, Transaction>(req);

/**
* Bulk purchase of NFTs
*
* @param req Use {@link Build5Request} with data based on {@link NftPurchaseBulkRequest}
* @returns
*/
bulkPurchase = (req: Build5Request<NftPurchaseBulkRequest>) =>
this.sendRequest(WEN_FUNC.orderNftBulk)<NftPurchaseBulkRequest, Transaction>(req);

/**
* Transfer NFT
*
* @param req Use {@link Build5Request} with data based on {@link NftTransferRequest}
* @returns
*/
transfer = this.sendRequest(WEN_FUNC.nftTransfer)<NftTransferRequest, { [key: string]: number }>;

/**
* Get all NFTs by collection. Real time stream.
*
* @param collection
* @param orderBy
* @param orderByDir
* @param startAfter
* @returns
*/
getByCollectionLive = (
collection: string,
orderBy: string[],
Expand All @@ -66,6 +129,12 @@ export class NftDataset<D extends Dataset> extends DatasetClass<D, Nft> {
return this.getManyAdvancedLive(params);
};

/**
* Get all NFTs by owner. Real time stream.
* @param owner
* @param startAfter
* @returns
*/
getByOwnerLive = (owner: string, startAfter?: string) => {
const params: GetManyAdvancedRequest = {
dataset: this.dataset,
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/src/https/datasets/NftStakeDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import {
} from '@build-5/interfaces';
import { DatasetClass } from './Dataset';

/**
* NFT Stake Dataset.
*/
export class NftStakeDataset<D extends Dataset> extends DatasetClass<D, NftStake> {
/**
* Stake NFT
*
* @param req Use {@link Build5Request} with data based on {@link NftStakeRequest}
* @returns
*/
stake = (req: Build5Request<NftStakeRequest>) =>
this.sendRequest(WEN_FUNC.stakeNft)<NftStakeRequest, Transaction>(req);
}
Loading

0 comments on commit 4502b6b

Please sign in to comment.