Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions apps/events/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { store } from '@graphprotocol/hypergraph';
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { PublicGraph, Utils, store } from '@graphprotocol/hypergraph';
import { useHypergraphApp, useHypergraphAuth } from '@graphprotocol/hypergraph-react';
import { Link, createFileRoute } from '@tanstack/react-router';
import { useSelector } from '@xstate/store/react';
import { useEffect } from 'react';
Expand All @@ -14,6 +14,7 @@ export const Route = createFileRoute('/')({
function Index() {
const spaces = useSelector(store, (state) => state.context.spaces);
const { createSpace, listSpaces, listInvitations, invitations, acceptInvitation, loading } = useHypergraphApp();
const { identity } = useHypergraphAuth();

console.log('Home page', { loading });

Expand Down Expand Up @@ -85,6 +86,41 @@ function Index() {
);
})}
</ul>
<h2>Public Graph</h2>
<Button
onClick={() => {
if (!identity) {
throw new Error('Identity not found');
}
PublicGraph.createSpace({
initialEditorAddress: identity.accountId,
spaceName: 'Example-Name',
});
}}
>
Create space
</Button>
<Button
onClick={() => {
if (!identity) {
throw new Error('Identity not found');
}
const id = Utils.generateId();
PublicGraph.createEntity({
id,
accountId: identity.accountId,
spaceId: 'APRxsbvk2awdZQChF4i5ey',
data: {
name: 'Test Geo',
},
mapping: {
name: PublicGraph.SYSTEM_IDS.NAME_ATTRIBUTE,
},
});
}}
>
Create entity
</Button>
</div>
);
}
16 changes: 16 additions & 0 deletions apps/node-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "node-client",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"start": "bun run ./src/index.ts"
},
"dependencies": {
"@graphprotocol/hypergraph": "workspace:*"
},
"devDependencies": {
"@types/node": "^22.10.7",
"typescript": "^5.7.3"
}
}
28 changes: 28 additions & 0 deletions apps/node-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PublicGraph, Utils } from '@graphprotocol/hypergraph';

const accountId = '0x098B742F2696AFC37724887cf999e1cFdB8f4b55';

// const result = await PublicGraph.createSpace({
// initialEditorAddress: accountId,
// spaceName: 'Example-Name',
// });

// const result = await PublicGraph.createAccount(accountId);

// console.log(result);

const entityResult = await PublicGraph.createEntity({
id: Utils.generateId(),
accountId,
data: {
name: 'Test Geo',
description: 'Test Description',
},
mapping: {
name: PublicGraph.SYSTEM_IDS.NAME_ATTRIBUTE,
description: PublicGraph.SYSTEM_IDS.DESCRIPTION_ATTRIBUTE,
},
spaceId: 'APRxsbvk2awdZQChF4i5ey',
});

console.log(entityResult);
29 changes: 29 additions & 0 deletions apps/node-client/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src", "tsup.config.ts"],
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,

"composite": false,
"incremental": false,
"declaration": false,
"declarationMap": false,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"exactOptionalPropertyTypes": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
}
}
29 changes: 29 additions & 0 deletions apps/node-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src", "tsup.config.ts"],
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,

"composite": false,
"incremental": false,
"declaration": false,
"declarationMap": false,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"exactOptionalPropertyTypes": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
}
}
29 changes: 29 additions & 0 deletions apps/node-client/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": "../../tsconfig.base.json",
"include": ["vite.config.ts"],
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,

"composite": false,
"incremental": false,
"declaration": false,
"declarationMap": false,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"exactOptionalPropertyTypes": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
}
}
1 change: 1 addition & 0 deletions packages/hypergraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@automerge/automerge": "^v2.2.9-alpha.3",
"@automerge/automerge-repo": "^2.0.0-alpha.14",
"@effect/experimental": "^0.37.1",
"@graphprotocol/grc-20": "^0.5.0",
"@noble/ciphers": "^1.2.0",
"@noble/curves": "^1.8.0",
"@noble/hashes": "^1.7.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/hypergraph/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export * as Entity from './Entity.js';
export * as Identity from './identity/index.js';
export * as Key from './key/index.js';
export * as Messages from './messages/index.js';
export * as Entity from './Entity.js';
export * as PublicGraph from './public-graph/index.js';
export * as SpaceEvents from './space-events/index.js';
export * from './store.js';
export * as Utils from './utils/index.js';
6 changes: 6 additions & 0 deletions packages/hypergraph/src/public-graph/create-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Account } from '@graphprotocol/grc-20';
export const createAccount = async (accountId: string) => {
const account = Account.make(accountId);
console.log(account);
return account;
};
62 changes: 62 additions & 0 deletions packages/hypergraph/src/public-graph/create-entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { IPFS, type SetTripleOp, Triple } from '@graphprotocol/grc-20';

type Params = {
id: string;
spaceId: string;
accountId: string;
data: {
[filedName: string]: string;
};
mapping: {
[filedName: string]: string;
};
};

export const createEntity = async ({ id, data, spaceId, accountId, mapping }: Params) => {
const ops: SetTripleOp[] = [];

for (const [fieldName, value] of Object.entries(data)) {
const attributeId = mapping[fieldName];
let attributeValueType: 'TEXT' | 'CHECKBOX' | 'NUMBER' | 'URL' | 'POINT';
switch (typeof value) {
case 'string':
attributeValueType = 'TEXT';
break;
case 'boolean':
attributeValueType = 'CHECKBOX';
break;
case 'number':
attributeValueType = 'NUMBER';
break;
default:
throw new Error('Not implemented value type');
}
const setTripleOp: SetTripleOp = Triple.make({
entityId: id,
attributeId,
value: {
type: attributeValueType,
value,
},
});

ops.push(setTripleOp);
}

const cid = await IPFS.publishEdit({
name: 'Edit name',
ops,
author: accountId,
});

const result = await fetch(`https://api-testnet.grc-20.thegraph.com/space/${spaceId}/edit/calldata`, {
method: 'POST',
body: JSON.stringify({
cid: cid,
network: 'TESTNET',
}),
});

const jsonResult = await result.json();
return jsonResult;
};
19 changes: 19 additions & 0 deletions packages/hypergraph/src/public-graph/create-space.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type Params = {
initialEditorAddress: string;
spaceName: string;
};

export const createSpace = async (params: Params) => {
const result = await fetch('https://api-testnet.grc-20.thegraph.com/deploy', {
method: 'POST',
mode: 'cors',
body: JSON.stringify(params),
headers: {
'Content-Type': 'application/json',
'x-custom-header': 'myValue',
},
});

const { spaceId } = await result.json();
return { id: spaceId };
};
Empty file.
5 changes: 5 additions & 0 deletions packages/hypergraph/src/public-graph/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { NETWORK_IDS, SYSTEM_IDS } from '@graphprotocol/grc-20';
export * from './create-account.js';
export * from './create-entity.js';
export * from './create-space.js';
export * from './delete-entity.js';
Loading
Loading