diff --git a/package.json b/package.json index 9a6f8e4..9635171 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.2.0", + "version": "1.2.1", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": { diff --git a/src/ain.ts b/src/ain.ts index 7b1ef2a..f4c8835 100644 --- a/src/ain.ts +++ b/src/ain.ts @@ -4,6 +4,7 @@ import { TransactionBody } from "@ainblockchain/ain-util"; import { txResult } from "./types/type"; import { Signer } from "@ainblockchain/ain-js/lib/signer/signer"; import { DefaultSigner } from "@ainblockchain/ain-js/lib/signer/default-signer" +import { GetOptions } from "@ainblockchain/ain-js/lib/types"; // NOTE(yoojin): Plz suggest a good name. export default class AinModule { @@ -20,7 +21,7 @@ export default class AinModule { initAin(chainId: 0 | 1) { const blockchainAPIEndpoint = getBlockChainAPIEndpoint(chainId); const blockchainEventEndpoint = getBlockChainEventEndpoint(chainId); - this.ain = new Ain(blockchainAPIEndpoint,blockchainEventEndpoint, chainId); + this.ain = new Ain(blockchainAPIEndpoint, blockchainEventEndpoint, chainId); } createAccount() { @@ -89,9 +90,9 @@ export default class AinModule { return await this.ain!.db.ref(balancePath).getValue(); } - async getValue(path: string) { + async getValue(path: string, options?: GetOptions) { this.checkAinInitiated(); - return await this.ain!.db.ref(path).getValue(); + return await this.ain!.db.ref().getValue(path, options); } private async _sendTransaction(txBody: TransactionBody) { diff --git a/src/ainize.ts b/src/ainize.ts index d99bff0..ee765bd 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -107,7 +107,7 @@ export default class Ainize { */ async getService(serviceName: string): Promise { const servicePath = Path.app(serviceName).root(); - const serviceData = await this.ain.getValue(servicePath); + const serviceData = await this.ain.getValue(servicePath, { is_shallow: true }); if(!serviceData) { throw new Error("Service not found"); } diff --git a/src/constants.ts b/src/constants.ts index 91bc1d8..f96358f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -22,10 +22,12 @@ export const Path = { service: () => `${Path.app(appName).root()}/service`, userOfService: (userAddress: string) => `${Path.app(appName).service()}/${userAddress}`, + requestKey: (userAddress: string, requestKey: string) => + `${Path.app(appName).userOfService(userAddress)}/${requestKey}`, request: (userAddress: string, requestKey: string) => - `${Path.app(appName).userOfService(userAddress)}/${requestKey}/request`, + `${Path.app(appName).requestKey(userAddress, requestKey)}/request`, response: (userAddress: string, requestKey: string) => - `${Path.app(appName).userOfService(userAddress)}/${requestKey}/response`, + `${Path.app(appName).requestKey(userAddress, requestKey)}/response`, } }, transfer: (from: string, to: string, transferKey: string) => @@ -33,7 +35,6 @@ export const Path = { } export const defaultAppRules = (appName: string): { [type: string]: { ref: string, value: object } } => { - const rootRef = Path.app(appName).root(); return { deposit: { ref: `${Path.app(appName).depositOfUser("$userAddress")}/$transferKey`, @@ -54,7 +55,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, balanceHistory: { - ref: `${rootRef}/balance/$userAddress/history/$timestamp`, + ref: `${Path.app(appName).balance()}/$userAddress/history/$timestamp`, value: { ".rule": { write: @@ -64,6 +65,17 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, }, + requestKey: { + ref: Path.app(appName).requestKey("$userAddress", "$requestKey"), + value: { + ".rule": { + state: { + gc_max_siblings: 20, + gc_num_siblings_deleted: 10, + }, + }, + } + }, request: { ref: Path.app(appName).request("$userAddress", "$requestKey"), value: { @@ -77,7 +89,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin }, }, response: { - ref: Path.app(appName).response("userAddress", "$requestKey"), + ref: Path.app(appName).response("$userAddress", "$requestKey"), value: { ".rule": { write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.status)"