Skip to content

Commit 2cc06ee

Browse files
committed
feat(typesync pkg): create typesync pkg. export Mapping definition
1 parent 4e4727e commit 2cc06ee

20 files changed

+1025
-792
lines changed

apps/connect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@tanstack/react-router": "^1.120.2",
1818
"class-variance-authority": "^0.7.1",
1919
"clsx": "^2.1.1",
20-
"effect": "^3.16.3",
20+
"effect": "^3.16.5",
2121
"framer-motion": "^12.10.1",
2222
"lucide-react": "^0.508.0",
2323
"react": "^19.1.0",

package.json

Lines changed: 5 additions & 5 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": "node scripts/clean.mjs",
77
"build": "tsc -b tsconfig.build.json && pnpm --recursive --parallel --filter \"./packages/*\" run build",
@@ -12,13 +12,13 @@
1212
},
1313
"devDependencies": {
1414
"@babel/cli": "^7.27.2",
15-
"@babel/core": "^7.27.1",
15+
"@babel/core": "^7.27.4",
1616
"@biomejs/biome": "1.9.4",
17-
"@changesets/cli": "^2.29.3",
17+
"@changesets/cli": "^2.29.4",
1818
"babel-plugin-annotate-pure-calls": "^0.5.0",
1919
"glob": "^11.0.2",
20-
"pkg-pr-new": "^0.0.43",
20+
"pkg-pr-new": "^0.0.51",
2121
"typescript": "^5.8.3",
22-
"vitest": "^3.1.3"
22+
"vitest": "^3.2.3"
2323
}
2424
}

packages/hypergraph-react/package.json

Lines changed: 1 addition & 1 deletion
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",

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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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: `generateMappings` 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+
relations?: {
18+
[key: string]: Grc20Id.Id;
19+
};
20+
};
21+
22+
export type Mapping = {
23+
[key: string]: MappingEntry;
24+
};
25+
```
26+
27+
## Example
28+
29+
- generated schema
30+
31+
```ts
32+
import { Entity, Type } from '@graphprotocol/hypergraph'
33+
34+
export class Account extends Entity.Class<Account>('Account')({
35+
username: Type.Text,
36+
createdAt: Type.Date
37+
}) {}
38+
39+
export class Event extends Entity.Class<Event>('Event')({
40+
name: Type.Text,
41+
description: Type.Text,
42+
account: Type.Relation(Account)
43+
}) {}
44+
```
45+
46+
- resuling mapping
47+
48+
```ts
49+
import { Id } from '@graphprotocol/grc-20'
50+
import type { Mapping } from '@graphprotocol/typesync/Mapping'
51+
52+
export const mapping: Mapping = {
53+
Account: {
54+
typeIds: [Id.Id('a5fd07b1-120f-46c6-b46f-387ef98396a6')],
55+
properties: {
56+
username: Id.Id('994edcff-6996-4a77-9797-a13e5e3efad8'),
57+
createdAt: Id.Id('64bfba51-a69b-4746-be4b-213214a879fe')
58+
}
59+
},
60+
Event: {
61+
typeIds: [Id.Id('0349187b-526f-435f-b2bb-9e9caf23127a')],
62+
properties: {
63+
name: Id.Id('3808e060-fb4a-4d08-8069-35b8c8a1902b'),
64+
description: Id.Id('1f0d9007-8da2-4b28-ab9f-3bc0709f4837'),
65+
},
66+
relations: {
67+
account: Id.Id('a5fd07b1-120f-46c6-b46f-387ef98396a6')
68+
}
69+
}
70+
}
71+
```
72+
73+
## References
74+
75+
- [@graphprotocol/grc-20](https://github.com/graphprotocol/grc-20-ts)

packages/typesync/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
},
31+
"sideEffects": [],
32+
"scripts": {
33+
"build": "tsc -b --force tsconfig.build.json && babel dist --plugins annotate-pure-calls --out-dir dist --source-maps && node ../../scripts/package.mjs",
34+
"test": "vitest"
35+
},
36+
"peerDependencies": {
37+
"@graphprotocol/hypergraph": "workspace:*"
38+
},
39+
"devDependencies": {
40+
"@graphprotocol/hypergraph": "workspace:*"
41+
},
42+
"dependencies": {
43+
"@graphprotocol/grc-20": "^0.17.1",
44+
"effect": "^3.16.5"
45+
}
46+
}

packages/typesync/src/Mapping.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import type { Id as Grc20Id } from '@graphprotocol/grc-20';
2+
3+
/**
4+
* Mappings for a schema type and its properties/relations
5+
*
6+
* @since 0.0.1
7+
*/
8+
export type MappingEntry = {
9+
/**
10+
* Array of the `Id.Id` of the type in the Knowledge Graph.
11+
* Is an array because a type can belong to multiple spaces/extend multiple types.
12+
*
13+
* @since 0.0.1
14+
*/
15+
typeIds: Array<Grc20Id.Id>;
16+
/**
17+
* Record of property names to the `Id.Id` of the type in the Knowledge Graph
18+
*
19+
* @since 0.0.1
20+
*/
21+
properties?: {
22+
[key: string]: Grc20Id.Id;
23+
};
24+
/**
25+
* Record of schema type relation names to the `Id.Id` of the relation in the Knowledge Graph
26+
*
27+
* @since 0.0.1
28+
*/
29+
relations?: {
30+
[key: string]: Grc20Id.Id;
31+
};
32+
};
33+
34+
/**
35+
* @example
36+
* ```ts
37+
* import { Id } from '@graphprotocol/grc-20'
38+
* import type { Mapping } from '@graphprotocol/typesync'
39+
*
40+
* const mapping: Mapping = {
41+
* Account: {
42+
* typeIds: [Id.Id('a5fd07b1-120f-46c6-b46f-387ef98396a6')],
43+
* properties: {
44+
* username: Id.Id('994edcff-6996-4a77-9797-a13e5e3efad8'),
45+
* createdAt: Id.Id('64bfba51-a69b-4746-be4b-213214a879fe')
46+
* }
47+
* },
48+
* Event: {
49+
* typeIds: [Id.Id('0349187b-526f-435f-b2bb-9e9caf23127a')],
50+
* properties: {
51+
* name: Id.Id('3808e060-fb4a-4d08-8069-35b8c8a1902b'),
52+
* description: Id.Id('1f0d9007-8da2-4b28-ab9f-3bc0709f4837'),
53+
* },
54+
* relations: {
55+
* account: Id.Id('a5fd07b1-120f-46c6-b46f-387ef98396a6')
56+
* }
57+
* }
58+
* }
59+
* ```
60+
*
61+
* @since 0.0.1
62+
*/
63+
export type Mapping = {
64+
[key: string]: MappingEntry;
65+
};

packages/typesync/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as Mapping from './Mapping.js';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.src.json",
3+
"compilerOptions": {
4+
"tsBuildInfoFile": ".tsbuildinfo/build.tsbuildinfo",
5+
"outDir": "dist",
6+
"stripInternal": true
7+
}
8+
}

packages/typesync/tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": [],
4+
"references": [{ "path": "tsconfig.src.json" }, { "path": "tsconfig.test.json" }]
5+
}

0 commit comments

Comments
 (0)