Skip to content

Commit 8a24c4b

Browse files
authored
feat(mapping generation): create a typesync pkg to take a user-built schema and generate the mappings definition (#210)
1 parent 6ff3135 commit 8a24c4b

28 files changed

Lines changed: 2685 additions & 1042 deletions

apps/connect/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@tanstack/react-router-devtools": "^1.122.0",
2525
"@xstate/store": "^3.5.1",
2626
"clsx": "^2.1.1",
27-
"effect": "^3.16.10",
27+
"effect": "^3.16.12",
28+
"framer-motion": "^12.10.1",
2829
"graphql-request": "^7.2.0",
2930
"lucide-react": "^0.508.0",
3031
"react": "^19.1.0",

apps/events/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@xstate/store": "^3.5.1",
2222
"class-variance-authority": "^0.7.1",
2323
"clsx": "^2.1.1",
24-
"effect": "^3.16.10",
24+
"effect": "^3.16.12",
2525
"framer-motion": "^12.10.1",
2626
"graphql-request": "^7.1.2",
2727
"isomorphic-ws": "^5.0.0",

apps/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@privy-io/server-auth": "^1.26.0",
2020
"body-parser": "^2.2.0",
2121
"cors": "^2.8.5",
22-
"effect": "^3.16.10",
22+
"effect": "^3.16.12",
2323
"express": "^5.1.0",
2424
"prisma": "^6.7.0",
2525
"siwe": "^3.0.0",

apps/typesync/package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,20 @@
3838
"hypergraph": "pnpx tsx ./src/bin.ts typesync"
3939
},
4040
"devDependencies": {
41-
"@effect/cli": "^0.66.1",
42-
"@effect/experimental": "^0.51.1",
43-
"@effect/language-service": "^0.23.3",
44-
"@effect/platform": "^0.87.1",
45-
"@effect/platform-node": "^0.88.3",
46-
"@effect/sql": "^0.40.1",
47-
"@effect/sql-sqlite-node": "^0.41.1",
48-
"@effect/vitest": "^0.23.10",
49-
"@graphprotocol/grc-20": "^0.21.6",
41+
"@effect/cli": "^0.66.12",
42+
"@effect/experimental": "^0.51.13",
43+
"@effect/language-service": "^0.24.2",
44+
"@effect/platform": "^0.87.12",
45+
"@effect/platform-node": "^0.89.5",
46+
"@effect/sql": "^0.40.13",
47+
"@effect/sql-sqlite-node": "^0.41.13",
48+
"@effect/vitest": "^0.23.12",
5049
"@graphql-codegen/cli": "^5.0.7",
5150
"@graphql-codegen/client-preset": "^4.8.3",
5251
"@graphql-codegen/typescript": "^4.1.6",
5352
"@graphql-codegen/typescript-operations": "^4.6.1",
54-
"@tanstack/router-plugin": "^1.123.2",
55-
"@types/node": "^24.0.8",
53+
"@tanstack/router-plugin": "^1.127.1",
54+
"@types/node": "^24.0.13",
5655
"@types/react": "^19.1.8",
5756
"@types/react-dom": "^19.1.6",
5857
"@vitejs/plugin-react": "^4.6.0",
@@ -64,19 +63,20 @@
6463
},
6564
"dependencies": {
6665
"@graphql-typed-document-node/core": "^3.2.0",
66+
"@graphprotocol/grc-20": "^0.21.6",
6767
"@headlessui/react": "^2.2.4",
6868
"@heroicons/react": "^2.2.0",
6969
"@phosphor-icons/react": "^2.1.10",
7070
"@radix-ui/react-tabs": "^1.1.12",
7171
"@tailwindcss/vite": "^4.1.11",
72-
"@tanstack/react-form": "^1.12.4",
73-
"@tanstack/react-query": "^5.81.5",
74-
"@tanstack/react-query-devtools": "^5.81.5",
75-
"@tanstack/react-router": "^1.123.2",
76-
"@tanstack/react-router-devtools": "^1.123.2",
72+
"@tanstack/react-form": "^1.14.1",
73+
"@tanstack/react-query": "^5.83.0",
74+
"@tanstack/react-query-devtools": "^5.83.0",
75+
"@tanstack/react-router": "^1.127.1",
76+
"@tanstack/react-router-devtools": "^1.127.1",
7777
"better-sqlite3": "^12.2.0",
7878
"date-fns": "^4.1.0",
79-
"effect": "^3.16.10",
79+
"effect": "^3.16.12",
8080
"graphql": "^16.11.0",
8181
"graphql-request": "^7.2.0",
8282
"jotai": "^2.12.5",

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"type": "module",
4-
"packageManager": "pnpm@10.6.2",
4+
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac",
55
"scripts": {
66
"clean": "rm -rf .turbo && rm -rf node_modules && pnpm --recursive --filter \"./packages/*\" exec rm -rf dist && pnpm --recursive --filter \"./packages/*\" exec rm -rf .turbo && pnpm --recursive --filter \"./packages/*\" exec rm -rf tsconfig.tsbuildinfo && pnpm --recursive --filter \"./apps/*\" exec rm -rf dist && pnpm --recursive --filter \"./apps/*\" exec rm -rf .turbo && pnpm --recursive --filter \"./apps/*\" exec rm -rf tsconfig.tsbuildinfo",
77
"dev": "pnpm --recursive --parallel --filter \"./apps/*\" run dev",
@@ -15,15 +15,15 @@
1515
"graph": "pnpm --filter server-logic-ts graph"
1616
},
1717
"devDependencies": {
18-
"@babel/cli": "^7.27.2",
19-
"@babel/core": "^7.27.1",
18+
"@babel/cli": "^7.28.0",
19+
"@babel/core": "^7.28.0",
2020
"@biomejs/biome": "1.9.4",
21-
"@changesets/cli": "^2.29.3",
21+
"@changesets/cli": "^2.29.5",
2222
"@graphprotocol/grc-20": "^0.21.6",
2323
"babel-plugin-annotate-pure-calls": "^0.5.0",
24-
"glob": "^11.0.2",
25-
"pkg-pr-new": "^0.0.43",
24+
"glob": "^11.0.3",
25+
"pkg-pr-new": "^0.0.54",
2626
"typescript": "^5.8.3",
27-
"vitest": "^3.1.3"
27+
"vitest": "^3.2.4"
2828
}
2929
}

packages/hypergraph-react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"repository": {
1212
"type": "git",
1313
"url": "https://github.com/graphprotocol/hypergraph.git",
14-
"directory": "packages/react"
14+
"directory": "packages/hypergraph-react"
1515
},
1616
"license": "MIT",
1717
"type": "module",
@@ -44,7 +44,7 @@
4444
"@graphprotocol/grc-20": "^0.21.6",
4545
"@noble/hashes": "^1.8.0",
4646
"@tanstack/react-query": "^5.75.5",
47-
"effect": "^3.16.10",
47+
"effect": "^3.16.12",
4848
"graphql-request": "^7.1.2",
4949
"siwe": "^3.0.0",
5050
"uuid": "^11.1.0",

packages/hypergraph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@serenity-kit/noble-sodium": "^0.2.1",
5555
"@xstate/store": "^3.5.1",
5656
"bs58check": "^4.0.0",
57-
"effect": "^3.16.10",
57+
"effect": "^3.16.12",
5858
"permissionless": "^0.2.47",
5959
"siwe": "^3.0.0",
6060
"uuid": "^11.1.0",

packages/typesync/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-present The Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/typesync/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# @graphprotocol/typesync
2+
3+
Package for generating the mappings used within the `hypergraph` ecosystem that is used to query for entities on the Knowledge Graph by the `grc-20` id's.
4+
5+
The `Mapping` is passed to the `<HypergraphSpaceProvider>` from the [@graphprotocol/hypergraph-react](../hypergraph-react/README.md) context to inform the query layer what entities to query from the Knowledge Graph.
6+
7+
This package exposes a function: `generateMapping` that takes the schema with an array of types, each with properties. Both `types` and `properties` have a nullable `knowledgeGraphId` UUID value. If a value is provided, the `type/property` exists on the Knowledge Graph; this value will be plugged into to the `Mapping` values. If the `knowledgeGraphId` value is null, the `type/property` will be created using the `@graphprotocol/grc-20` ops and then returned in the mapping.
8+
9+
## Mapping definition
10+
11+
```ts
12+
export type MappingEntry = {
13+
typeIds: Array<Grc20Id.Id>;
14+
properties?: {
15+
[key: string]: Grc20Id.Id;
16+
};
17+
};
18+
19+
export type Mapping = {
20+
[key: string]: MappingEntry;
21+
};
22+
```
23+
24+
## Example
25+
26+
- generated schema
27+
28+
```ts
29+
import { Entity, Type } from '@graphprotocol/hypergraph'
30+
31+
export class Account extends Entity.Class<Account>('Account')({
32+
username: Type.Text,
33+
createdAt: Type.Date
34+
}) {}
35+
36+
export class Event extends Entity.Class<Event>('Event')({
37+
name: Type.Text,
38+
description: Type.Text,
39+
account: Type.Relation(Account)
40+
}) {}
41+
```
42+
43+
- resuling mapping
44+
45+
```ts
46+
import { Id } from '@graphprotocol/grc-20'
47+
import type { Mapping } from '@graphprotocol/typesync/Mapping'
48+
49+
export const mapping: Mapping = {
50+
Account: {
51+
typeIds: [Id.Id('a5fd07b1-120f-46c6-b46f-387ef98396a6')],
52+
properties: {
53+
username: Id.Id('994edcff-6996-4a77-9797-a13e5e3efad8'),
54+
createdAt: Id.Id('64bfba51-a69b-4746-be4b-213214a879fe')
55+
}
56+
},
57+
Event: {
58+
typeIds: [Id.Id('0349187b-526f-435f-b2bb-9e9caf23127a')],
59+
properties: {
60+
name: Id.Id('3808e060-fb4a-4d08-8069-35b8c8a1902b'),
61+
description: Id.Id('1f0d9007-8da2-4b28-ab9f-3bc0709f4837'),
62+
account: Id.Id('a5fd07b1-120f-46c6-b46f-387ef98396a6')
63+
},
64+
}
65+
}
66+
```
67+
68+
## References
69+
70+
- [@graphprotocol/grc-20](https://github.com/graphprotocol/grc-20-ts)

packages/typesync/package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "@graphprotocol/typesync",
3+
"version": "0.0.1",
4+
"description": "Package for generating the mappings used within the hypergraph ecosystem that is used to query for entities on the Knowledge Graph by the grc-20 id's.",
5+
"publishConfig": {
6+
"access": "public",
7+
"directory": "publish",
8+
"provenance": true
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/graphprotocol/hypergraph.git",
13+
"directory": "packages/typesync"
14+
},
15+
"keywords": ["The Graph", "GRC-20", "hypergraph"],
16+
"license": "MIT",
17+
"type": "module",
18+
"main": "./dist/index.js",
19+
"module": "./dist/index.js",
20+
"types": "./dist/index.d.ts",
21+
"exports": {
22+
".": {
23+
"types": "./dist/index.d.ts",
24+
"default": "./dist/index.js"
25+
},
26+
"./Mapping": {
27+
"types": "./dist/Mapping.d.ts",
28+
"default": "./dist/Mapping.js"
29+
},
30+
"./Utils": {
31+
"types": "./dist/Utils.d.ts",
32+
"default": "./dist/Utils.js"
33+
}
34+
},
35+
"sideEffects": [],
36+
"scripts": {
37+
"build": "tsc -b --force tsconfig.build.json && babel dist --plugins annotate-pure-calls --out-dir dist --source-maps && node ../../scripts/package.mjs",
38+
"test": "vitest"
39+
},
40+
"dependencies": {
41+
"@graphprotocol/grc-20": "^0.21.6",
42+
"effect": "^3.16.12"
43+
}
44+
}

0 commit comments

Comments
 (0)