Skip to content

Commit 08cc1dc

Browse files
committed
feat(typesync): utilize typesync pkg Mapping
1 parent bea0602 commit 08cc1dc

File tree

31 files changed

+530
-572
lines changed

31 files changed

+530
-572
lines changed

apps/connect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@tanstack/react-router-devtools": "^1.122.0",
2525
"@xstate/store": "^3.5.1",
2626
"clsx": "^2.1.1",
27-
"effect": "^3.16.12",
27+
"effect": "^3.16.16",
2828
"framer-motion": "^12.10.1",
2929
"graphql-request": "^7.2.0",
3030
"lucide-react": "^0.508.0",

apps/events/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@graphprotocol/grc-20": "^0.21.6",
1212
"@graphprotocol/hypergraph": "workspace:*",
1313
"@graphprotocol/hypergraph-react": "workspace:*",
14+
"@graphprotocol/typesync": "workspace:*",
1415
"@noble/hashes": "^1.8.0",
1516
"@radix-ui/react-avatar": "^1.1.9",
1617
"@radix-ui/react-icons": "^1.3.2",
@@ -21,7 +22,7 @@
2122
"@xstate/store": "^3.5.1",
2223
"class-variance-authority": "^0.7.1",
2324
"clsx": "^2.1.1",
24-
"effect": "^3.16.12",
25+
"effect": "^3.16.16",
2526
"framer-motion": "^12.10.1",
2627
"graphql-request": "^7.1.2",
2728
"isomorphic-ws": "^5.0.0",

apps/events/src/mapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Id } from '@graphprotocol/grc-20';
2-
import type { Mapping } from '@graphprotocol/hypergraph';
2+
import type { Mapping } from '@graphprotocol/typesync/Mapping';
33

44
export const mapping: Mapping = {
55
Event: {

apps/events/tsconfig.app.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"@graphprotocol/hypergraph": ["../../packages/hypergraph/src/index.js"],
3636
"@graphprotocol/hypergraph/*": ["../../packages/hypergraph/src/*.js"],
3737
"@graphprotocol/hypergraph-react": ["../../packages/hypergraph-react/src/index.js"],
38-
"@graphprotocol/hypergraph-react/*": ["../../packages/hypergraph-react/src/*.js"]
38+
"@graphprotocol/hypergraph-react/*": ["../../packages/hypergraph-react/src/*.js"],
39+
"@graphprotocol/typesync": ["../../packages/typesync/src/index.js"],
40+
"@graphprotocol/typesync/*": ["../../packages/typesync/src/*.js"]
3941
}
4042
}
4143
}

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.12",
22+
"effect": "^3.16.16",
2323
"express": "^5.1.0",
2424
"prisma": "^6.7.0",
2525
"siwe": "^3.0.0",

apps/typesync/client/src/Components/App/CreateAppForm/SchemaBuilder/TypeSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RelationTypeOption extends Schema.Class<RelationTypeOption>('/hypergraph/t
1919
const typeOptions: Array<TypeOption> = [
2020
TypeOption.make({ id: 'DefaultEntityText', name: 'Text' }),
2121
TypeOption.make({ id: 'DefaultEntityNumber', name: 'Number' }),
22-
TypeOption.make({ id: 'DefaultEntityBoolean', name: 'Boolean' }),
22+
TypeOption.make({ id: 'DefaultEntityCheckbox', name: 'Checkbox' }),
2323
TypeOption.make({ id: 'DefaultEntityDate', name: 'Date' }),
2424
TypeOption.make({ id: 'DefaultEntityUrl', name: 'Url' }),
2525
TypeOption.make({ id: 'DefaultEntityPoint', name: 'Point' }),

apps/typesync/client/src/routes/apps/create.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { isDataTypeRelation } from '@graphprotocol/typesync/Mapping';
34
import {
45
ArrowUturnLeftIcon,
56
CheckCircleIcon,
@@ -14,7 +15,7 @@ import { Link, createFileRoute } from '@tanstack/react-router';
1415
import { Array as EffectArray, String as EffectString, Option, Schema, pipe } from 'effect';
1516
import { useState } from 'react';
1617

17-
import { InsertAppSchema, isDataTypeRelation } from '../../../../domain/Domain.js';
18+
import { InsertAppSchema } from '../../../../domain/Domain.js';
1819

1920
import { SchemaBrowser } from '../../Components/App/CreateAppForm/SchemaBuilder/SchemaBrowser.js';
2021
import { useAppForm } from '../../Components/App/CreateAppForm/useCreateAppForm.js';
@@ -98,7 +99,8 @@ function CreateAppPage() {
9899
defaultValues,
99100
validators: {
100101
onChangeAsyncDebounceMs: 100,
101-
onChange: Schema.standardSchemaV1(InsertAppSchema),
102+
// biome-ignore lint/suspicious/noExplicitAny: fixes an issue with the prop.dataType type-string of `Relation(${name})`
103+
onChange: Schema.standardSchemaV1(InsertAppSchema) as any,
102104
},
103105
async onSubmit({ formApi, value }) {
104106
await mutateAsync(value).then(() => formApi.reset(undefined, { keepDefaultValues: true }));
@@ -794,7 +796,7 @@ function CreateAppPage() {
794796
</div>
795797
</TabsPrimitive.Content>
796798

797-
<TabsPrimitive.List className="mt-6 flex items-center justify-end gap-x-6 fixed bottom-4 right-4 bg-white dark:bg-black p-4 rounded-lg">
799+
<TabsPrimitive.List className="mt-6 flex items-center justify-end gap-x-6 fixed bottom-4 right-4 bg-white dark:bg-inherit p-4 rounded-lg">
798800
<Link to="/" className="text-sm/6 font-semibold text-gray-900 dark:text-white">
799801
Cancel
800802
</Link>

apps/typesync/client/src/utils/mapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { SchemaDataType } from '../../../domain/Domain';
1+
import type { SchemaDataType } from '@graphprotocol/typesync/Mapping';
22

3-
import type { DataType } from '../generated/graphql';
3+
import type { DataTypes } from '../generated/graphql';
44

5-
export function mapKGDataTypeToPrimitiveType(dataType: DataType, entity: string): SchemaDataType {
5+
export function mapKGDataTypeToPrimitiveType(dataType: DataTypes, entity: string): SchemaDataType {
66
switch (dataType) {
77
case 'CHECKBOX': {
8-
return 'Boolean';
8+
return 'Checkbox';
99
}
1010
case 'NUMBER': {
1111
return 'Number';

apps/typesync/domain/Domain.ts

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,5 @@
1-
import { Array as EffectArray, String as EffectString, Schema, pipe } from 'effect';
2-
3-
function namesAreUnique<T extends { readonly name: string }>(entries: ReadonlyArray<T>): boolean {
4-
const names = new Set<string>();
5-
6-
for (const entry of entries) {
7-
const name = EffectString.toLowerCase(entry.name);
8-
if (names.has(name)) {
9-
return false;
10-
}
11-
names.add(name);
12-
}
13-
14-
return true;
15-
}
16-
17-
export type DataTypeRelation = `Relation(${string})`;
18-
export function isDataTypeRelation(val: string): val is DataTypeRelation {
19-
return /^Relation\((.+)\)$/.test(val);
20-
}
21-
22-
export const SchemaDataTypeRelation = Schema.NonEmptyTrimmedString.pipe(
23-
Schema.filter((val) => isDataTypeRelation(val)),
24-
);
25-
export type SchemaDataTypeRelation = typeof SchemaDataTypeRelation.Type;
26-
27-
export const SchemaDataTypePrimitive = Schema.Literal('Text', 'Number', 'Boolean', 'Date', 'Point', 'Url');
28-
export type SchemaDataTypePrimitive = typeof SchemaDataTypePrimitive.Type;
29-
30-
export const SchemaDataType = Schema.Union(SchemaDataTypePrimitive, SchemaDataTypeRelation);
31-
export type SchemaDataType = typeof SchemaDataType.Type;
32-
33-
export const SchemaTypePropertyRelation = Schema.Struct({
34-
name: Schema.NonEmptyTrimmedString,
35-
knowledgeGraphId: Schema.NullOr(Schema.UUID),
36-
dataType: Schema.NonEmptyTrimmedString, // The correct type for this is: `SchemaDataTypeRelation`. however, the standard schema definition to use in the form schema validation fails because of the `Relation(${string})` template string type.
37-
relationType: Schema.NonEmptyTrimmedString.annotations({
38-
identifier: 'SchemaTypePropertyRelation.relationType',
39-
description: 'name of the type within the schema that this property is related to',
40-
examples: ['Account'],
41-
}),
42-
});
43-
export type SchemaTypePropertyRelation = typeof SchemaTypePropertyRelation.Type;
44-
45-
export const SchemaTypePropertyPrimitive = Schema.Struct({
46-
name: Schema.NonEmptyTrimmedString,
47-
knowledgeGraphId: Schema.NullOr(Schema.UUID),
48-
dataType: SchemaDataTypePrimitive,
49-
});
50-
export type SchemaTypePropertyPrimitive = typeof SchemaTypePropertyPrimitive.Type;
51-
52-
export function propertyIsRelation(
53-
property: SchemaTypePropertyPrimitive | SchemaTypePropertyRelation,
54-
): property is SchemaTypePropertyRelation {
55-
return isDataTypeRelation(property.dataType);
56-
}
57-
58-
export const SchemaType = Schema.Struct({
59-
name: Schema.NonEmptyTrimmedString,
60-
knowledgeGraphId: Schema.NullOr(Schema.UUID),
61-
properties: Schema.Array(Schema.Union(SchemaTypePropertyPrimitive, SchemaTypePropertyRelation)).pipe(
62-
Schema.minItems(1),
63-
Schema.filter(namesAreUnique, {
64-
identifier: 'DuplicatePropertyNames',
65-
jsonSchema: {},
66-
description: 'The property.name must be unique across all properties in the type',
67-
}),
68-
),
69-
});
70-
export type SchemaType = typeof SchemaType.Type;
71-
72-
export function allRelationPropertyTypesExist(types: ReadonlyArray<SchemaType>): boolean {
73-
const unqTypeNames = EffectArray.reduce(types, new Set<string>(), (names, curr) => names.add(curr.name));
74-
return pipe(
75-
types,
76-
EffectArray.flatMap((curr) => curr.properties),
77-
EffectArray.filter((prop) => propertyIsRelation(prop)),
78-
EffectArray.every((prop) => unqTypeNames.has(prop.relationType)),
79-
);
80-
}
1+
import { Mapping, Utils } from '@graphprotocol/typesync';
2+
import { Schema } from 'effect';
813

824
/**
835
* Defines the type to be received by the app schema builder.
@@ -88,9 +10,9 @@ export const InsertAppSchema = Schema.Struct({
8810
description: Schema.NullOr(Schema.String),
8911
directory: Schema.NullOr(Schema.String.pipe(Schema.pattern(/^(\.\/|~\/|\/|[a-zA-Z]:\/)[\w\-\.\s\/]*[\w\-\.]$/))),
9012
template: Schema.Literal('vite_react'),
91-
types: Schema.Array(SchemaType).pipe(
13+
types: Schema.Array(Mapping.SchemaType).pipe(
9214
Schema.minItems(1),
93-
Schema.filter(namesAreUnique, {
15+
Schema.filter(Utils.namesAreUnique, {
9416
identifier: 'DuplicateTypeNames',
9517
jsonSchema: {},
9618
description: 'The type.name must be unique across all types in the schema',

apps/typesync/package.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,21 @@
3838
"hypergraph": "pnpx tsx ./src/bin.ts typesync"
3939
},
4040
"devDependencies": {
41-
"@effect/cli": "^0.67.0",
42-
"@effect/experimental": "^0.52.0",
43-
"@effect/language-service": "^0.26.0",
44-
"@effect/platform": "^0.88.0",
45-
"@effect/platform-node": "^0.90.0",
46-
"@effect/sql": "^0.41.0",
47-
"@effect/sql-sqlite-node": "^0.42.0",
48-
"@effect/vitest": "^0.24.0",
41+
"@effect/cli": "^0.67.1",
42+
"@effect/experimental": "^0.52.2",
43+
"@effect/language-service": "^0.27.1",
44+
"@effect/platform": "^0.88.1",
45+
"@effect/platform-node": "^0.91.0",
46+
"@effect/printer": "^0.44.14",
47+
"@effect/sql": "^0.42.0",
48+
"@effect/sql-sqlite-node": "^0.43.0",
49+
"@effect/vitest": "^0.24.1",
4950
"@graphql-codegen/cli": "^5.0.7",
5051
"@graphql-codegen/client-preset": "^4.8.3",
5152
"@graphql-codegen/typescript": "^4.1.6",
5253
"@graphql-codegen/typescript-operations": "^4.6.1",
53-
"@tanstack/router-plugin": "^1.127.5",
54-
"@types/node": "^24.0.13",
54+
"@tanstack/router-plugin": "^1.128.0",
55+
"@types/node": "^24.0.14",
5556
"@types/react": "^19.1.8",
5657
"@types/react-dom": "^19.1.6",
5758
"@vitejs/plugin-react": "^4.6.0",
@@ -64,6 +65,7 @@
6465
"dependencies": {
6566
"@graphql-typed-document-node/core": "^3.2.0",
6667
"@graphprotocol/grc-20": "^0.21.6",
68+
"@graphprotocol/typesync": "workspace:*",
6769
"@headlessui/react": "^2.2.4",
6870
"@heroicons/react": "^2.2.0",
6971
"@phosphor-icons/react": "^2.1.10",
@@ -72,11 +74,11 @@
7274
"@tanstack/react-form": "^1.14.1",
7375
"@tanstack/react-query": "^5.83.0",
7476
"@tanstack/react-query-devtools": "^5.83.0",
75-
"@tanstack/react-router": "^1.127.3",
76-
"@tanstack/react-router-devtools": "^1.127.3",
77+
"@tanstack/react-router": "^1.128.0",
78+
"@tanstack/react-router-devtools": "^1.128.0",
7779
"better-sqlite3": "^12.2.0",
7880
"date-fns": "^4.1.0",
79-
"effect": "^3.16.13",
81+
"effect": "^3.16.16",
8082
"graphql": "^16.11.0",
8183
"graphql-request": "^7.2.0",
8284
"jotai": "^2.12.5",

0 commit comments

Comments
 (0)