Skip to content

Commit

Permalink
chore: added datamapper examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kolhapuresatyajeet committed Oct 10, 2023
1 parent 40312f4 commit b1e58a8
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 44 deletions.
22 changes: 22 additions & 0 deletions sdk/examples/attestation/attestationExamples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import VeraxSdk from "../../src/VeraxSdk";

export default class AttestationExamples {
private veraxSdk: VeraxSdk;
constructor(_veraxSdk: VeraxSdk) {
this.veraxSdk = _veraxSdk;
}
async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(
await this.veraxSdk.attestation.findOneById(
"0x00000000000000000000000000000000000000000000000000000000000007b5",
),
);
if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(
await this.veraxSdk.attestation.findBy(
`{schemaId: "0xd1664d97bd195df77e3d5fe78c1737ab3adaa38bbe52a680d1aa30fa51f186ba"}`,
),
);
}
}
5 changes: 0 additions & 5 deletions sdk/examples/attestation/findBy.ts

This file was deleted.

7 changes: 0 additions & 7 deletions sdk/examples/attestation/findOneById.ts

This file was deleted.

6 changes: 6 additions & 0 deletions sdk/examples/attestation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import VeraxSdk from "../../src/VeraxSdk";
import AttestationExamples from "./attestationExamples";

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new AttestationExamples(veraxSdk).run(process.argv[2]);
5 changes: 0 additions & 5 deletions sdk/examples/module/findBy.ts

This file was deleted.

5 changes: 0 additions & 5 deletions sdk/examples/module/findOneById.ts

This file was deleted.

6 changes: 6 additions & 0 deletions sdk/examples/module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import VeraxSdk from "../../src/VeraxSdk";
import ModuleExamples from "./moduleExamples";

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new ModuleExamples(veraxSdk).run(process.argv[2]);
17 changes: 17 additions & 0 deletions sdk/examples/module/moduleExamples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import VeraxSdk from "../../src/VeraxSdk";

export default class ModuleExamples {
private veraxSdk: VeraxSdk;
constructor(_veraxSdk: VeraxSdk) {
this.veraxSdk = _veraxSdk;
}
async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.module.findOneById("0xf75be6f9418710fd516fa82afb3aad07e11a0f1b"));

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.module.findBy(`{name: "SchemaCheckerModule"}`));

if (methodName.toLowerCase() == "register" || methodName == "") console.log(await this.veraxSdk.module.register());
}
}
5 changes: 0 additions & 5 deletions sdk/examples/portal/findBy.ts

This file was deleted.

5 changes: 0 additions & 5 deletions sdk/examples/portal/findOneById.ts

This file was deleted.

6 changes: 6 additions & 0 deletions sdk/examples/portal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import VeraxSdk from "../../src/VeraxSdk";
import PortalExamples from "./portalExamples";

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new PortalExamples(veraxSdk).run(process.argv[2]);
34 changes: 34 additions & 0 deletions sdk/examples/portal/portalExamples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import VeraxSdk from "../../src/VeraxSdk";

export default class PortalExamples {
private veraxSdk: VeraxSdk;
constructor(_veraxSdk: VeraxSdk) {
this.veraxSdk = _veraxSdk;
}
async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.findOneById("0x1495341ab1019798dd08976f4a3e5ab0e095510b"));

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.findBy(`{ownerName: "Clique"}`));

if (methodName.toLowerCase() == "attest" || methodName == "") console.log(await this.veraxSdk.portal.attest());

if (methodName.toLowerCase() == "bulkAttest".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.bulkAttest());

if (methodName.toLowerCase() == "replace" || methodName == "") console.log(await this.veraxSdk.portal.replace());

if (methodName.toLowerCase() == "revoke" || methodName == "") console.log(await this.veraxSdk.portal.revoke());

if (methodName.toLowerCase() == "bulkRevoke".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.bulkRevoke());

if (methodName.toLowerCase() == "massImport".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.massImport());

if (methodName.toLowerCase() == "register" || methodName == "") console.log(await this.veraxSdk.portal.register());

if (methodName.toLowerCase() == "clone" || methodName == "") console.log(await this.veraxSdk.portal.clone());
}
}
5 changes: 0 additions & 5 deletions sdk/examples/schema/findBy.ts

This file was deleted.

5 changes: 0 additions & 5 deletions sdk/examples/schema/findOneById.ts

This file was deleted.

6 changes: 6 additions & 0 deletions sdk/examples/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import VeraxSdk from "../../src/VeraxSdk";
import PortalExamples from "./schemaExamples";

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);

await new PortalExamples(veraxSdk).run(process.argv[2]);
19 changes: 19 additions & 0 deletions sdk/examples/schema/schemaExamples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import VeraxSdk from "../../src/VeraxSdk";

export default class SchemaExamples {
private veraxSdk: VeraxSdk;
constructor(_veraxSdk: VeraxSdk) {
this.veraxSdk = _veraxSdk;
}
async run(methodName: string = "") {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "")
console.log(
await this.veraxSdk.schema.findOneById("0x01f031da36192c34057c764239eb77bb6ec8ebfb808f72a7bb172f37a5bec31f"),
);

if (methodName.toLowerCase() == "findBy".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.schema.findBy(`{name: "Relationship"}`));

if (methodName.toLowerCase() == "create" || methodName == "") console.log(await this.veraxSdk.schema.create());
}
}
4 changes: 4 additions & 0 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"author": "Consensys",
"type": "module",
"scripts": {
"attestation": "ts-node examples/attestation/index.ts",
"module": "ts-node examples/module/index.ts",
"portal": "ts-node examples/portal/index.ts",
"schema": "ts-node examples/schema/index.ts",
"attestation:all": "ts-node examples/attestation/findBy.ts",
"attestation:one": "ts-node examples/attestation/findOneById.ts",
"module:all": "ts-node examples/module/findBy.ts",
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/dataMapper/BaseDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default abstract class BaseDataMapper {
return JSON.stringify(queryResult.data[this.typeName]);
}

async findBy() {
async findBy(whereClause: string) {
const queryResult = await this.apolloClient.query({
query: gql(`query GetBy { ${this.typeName}s ${this.gqlInterface} }`),
query: gql(`query GetBy { ${this.typeName}s(where: ${whereClause}) ${this.gqlInterface} }`),
});

return JSON.stringify(queryResult.data[`${this.typeName}s`]);
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/dataMapper/ModuleDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export default class ModuleDataMapper extends BaseDataMapper {
name
description
}`;

async register() {
throw new Error("Not implemented");
}
}
32 changes: 32 additions & 0 deletions sdk/src/dataMapper/PortalDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,36 @@ export default class PortalDataMapper extends BaseDataMapper {
description
ownerName
}`;

async attest() {
throw new Error("Not implemented");
}

async bulkAttest() {
throw new Error("Not implemented");
}

async replace() {
throw new Error("Not implemented");
}

async revoke() {
throw new Error("Not implemented");
}

async bulkRevoke() {
throw new Error("Not implemented");
}

async massImport() {
throw new Error("Not implemented");
}

async register() {
throw new Error("Not implemented");
}

async clone() {
throw new Error("Not implemented");
}
}
4 changes: 4 additions & 0 deletions sdk/src/dataMapper/SchemaDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ export default class SchemaDataMapper extends BaseDataMapper {
context
schema
}`;

async create() {
throw new Error("Not implemented");
}
}

0 comments on commit b1e58a8

Please sign in to comment.