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 / ^ R e l a t i o n \( ( .+ ) \) $ / . 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 - z A - 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' ,
0 commit comments