diff --git a/apps/typesync/src/Generator.ts b/apps/typesync/src/Generator.ts index 52336ad2..26adb19a 100644 --- a/apps/typesync/src/Generator.ts +++ b/apps/typesync/src/Generator.ts @@ -367,11 +367,21 @@ export function buildMappingFile(schema: Domain.InsertAppSchema) { const typeMappings: string[] = []; for (const type of schema.types) { + // Skip types without a valid knowledgeGraphId + if (!type.knowledgeGraphId) { + continue; + } + const properties: string[] = []; const relations: string[] = []; // Process properties and relations for (const property of type.properties) { + // Skip properties without a valid knowledgeGraphId + if (!property.knowledgeGraphId) { + continue; + } + if (Domain.isDataTypeRelation(property.dataType)) { // This is a relation relations.push(` ${Utils.toCamelCase(property.name)}: Id.Id('${property.knowledgeGraphId}')`); diff --git a/apps/typesync/test/Generator.test.ts b/apps/typesync/test/Generator.test.ts index d2bd1295..d8a0f5d2 100644 --- a/apps/typesync/test/Generator.test.ts +++ b/apps/typesync/test/Generator.test.ts @@ -76,4 +76,128 @@ export const mapping: Mapping = { }); expect(mapping).toBe(expectedMapping); }); + + it('should skip a type entry without a knowledgeGraphId', () => { + const expectedMapping = `import { Id } from '@graphprotocol/grc-20'; +import type { Mapping } from '@graphprotocol/hypergraph'; + +export const mapping: Mapping = { + Space: { + typeIds: [Id.Id('362c1dbd-dc64-44bb-a3c4-652f38a642d7')], + properties: { + name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'), + description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'), + }, + }, +};`; + + const mapping = buildMappingFile({ + name: 'test', + description: 'test', + directory: 'test', + template: 'vite_react', + types: [ + { + name: 'Space', + knowledgeGraphId: '362c1dbd-dc64-44bb-a3c4-652f38a642d7', + properties: [ + { + name: 'Name', + knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935', + dataType: 'Text', + }, + { + name: 'Description', + knowledgeGraphId: '9b1f76ff-9711-404c-861e-59dc3fa7d037', + dataType: 'Text', + }, + ], + }, + { + name: 'new type', + knowledgeGraphId: null, + properties: [ + { + name: 'new prop', + knowledgeGraphId: null, + dataType: 'Text', + }, + ], + }, + ], + }); + expect(mapping).toBe(expectedMapping); + }); + + it('should skip a property entry without a knowledgeGraphId', () => { + const expectedMapping = `import { Id } from '@graphprotocol/grc-20'; +import type { Mapping } from '@graphprotocol/hypergraph'; + +export const mapping: Mapping = { + Space: { + typeIds: [Id.Id('362c1dbd-dc64-44bb-a3c4-652f38a642d7')], + properties: { + name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'), + description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'), + }, + }, + Activity: { + typeIds: [Id.Id('8275c359-4662-40fb-9aec-27177b520cd2')], + properties: { + name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'), + }, + relations: { + relatedSpaces: Id.Id('5b722cd3-61d6-494e-8887-1310566437ba'), + }, + }, +};`; + + const mapping = buildMappingFile({ + name: 'test', + description: 'test', + directory: 'test', + template: 'vite_react', + types: [ + { + name: 'Space', + knowledgeGraphId: '362c1dbd-dc64-44bb-a3c4-652f38a642d7', + properties: [ + { + name: 'Name', + knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935', + dataType: 'Text', + }, + { + name: 'Description', + knowledgeGraphId: '9b1f76ff-9711-404c-861e-59dc3fa7d037', + dataType: 'Text', + }, + ], + }, + { + name: 'Activity', + knowledgeGraphId: '8275c359-4662-40fb-9aec-27177b520cd2', + properties: [ + { + name: 'Name', + knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935', + dataType: 'Text', + }, + { + name: 'Description', + knowledgeGraphId: null, + dataType: 'Text', + }, + { + name: 'Related spaces', + knowledgeGraphId: '5b722cd3-61d6-494e-8887-1310566437ba', + dataType: 'Relation(Related spaces)', + relationType: 'Related spaces', + }, + ], + }, + ], + }); + expect(mapping).toBe(expectedMapping); + }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b08f6869..381c4be7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -513,19 +513,19 @@ importers: specifier: ^1.12.4 version: 1.12.4(react-dom@19.1.0(react@19.1.0))(react@19.1.0) '@tanstack/react-query': - specifier: ^5.81.4 + specifier: ^5.81.5 version: 5.81.5(react@19.1.0) '@tanstack/react-query-devtools': - specifier: ^5.81.4 + specifier: ^5.81.5 version: 5.81.5(@tanstack/react-query@5.81.5(react@19.1.0))(react@19.1.0) '@tanstack/react-router': - specifier: ^1.121.41 + specifier: ^1.123.2 version: 1.123.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0) '@tanstack/react-router-devtools': - specifier: 1.121.41 - version: 1.121.41(@tanstack/react-router@1.123.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(@tanstack/router-core@1.123.2)(csstype@3.1.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)(solid-js@1.9.5)(tiny-invariant@1.3.3) + specifier: ^1.123.2 + version: 1.123.2(@tanstack/react-router@1.123.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(@tanstack/router-core@1.123.2)(csstype@3.1.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)(solid-js@1.9.5)(tiny-invariant@1.3.3) better-sqlite3: - specifier: ^12.1.1 + specifier: ^12.2.0 version: 12.2.0 date-fns: specifier: ^4.1.0 @@ -4797,14 +4797,6 @@ packages: peerDependencies: react: ^18 || ^19 - '@tanstack/react-router-devtools@1.121.41': - resolution: {integrity: sha512-ezbBWXBK7U/yV7bZGMwshxYe1+tOJb/Ur3HA6Xu6iUEcBOpv/5agz2jeYcQmfign69ziR3rWecGApPJZYbrPQQ==} - engines: {node: '>=12'} - peerDependencies: - '@tanstack/react-router': ^1.121.41 - react: '>=18.0.0 || >=19.0.0' - react-dom: '>=18.0.0 || >=19.0.0' - '@tanstack/react-router-devtools@1.122.0': resolution: {integrity: sha512-UClUnO+PFvX5Ddlhhfkgo/7qSRTM/a/jsT7V5dz9LrSaPCsh7oLQgm6lj1Yu8U9GfpCQBLzWzbsvmYAdpOa/TQ==} engines: {node: '>=12'} @@ -17938,18 +17930,6 @@ snapshots: '@tanstack/query-core': 5.81.5 react: 19.1.0 - '@tanstack/react-router-devtools@1.121.41(@tanstack/react-router@1.123.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(@tanstack/router-core@1.123.2)(csstype@3.1.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)(solid-js@1.9.5)(tiny-invariant@1.3.3)': - dependencies: - '@tanstack/react-router': 1.123.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0) - '@tanstack/router-devtools-core': 1.122.0(@tanstack/router-core@1.123.2)(csstype@3.1.3)(solid-js@1.9.5)(tiny-invariant@1.3.3) - react: 19.1.0 - react-dom: 19.1.0(react@19.1.0) - transitivePeerDependencies: - - '@tanstack/router-core' - - csstype - - solid-js - - tiny-invariant - '@tanstack/react-router-devtools@1.122.0(@tanstack/react-router@1.120.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(@tanstack/router-core@1.123.2)(csstype@3.1.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)(solid-js@1.9.5)(tiny-invariant@1.3.3)': dependencies: '@tanstack/react-router': 1.120.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0)