From 409a2fa7c7a2331ea4e4335bee589fcd14629b41 Mon Sep 17 00:00:00 2001 From: Cas Haagen Date: Fri, 29 May 2026 20:35:54 +0200 Subject: [PATCH 1/2] Fix types being exported for poe as enum and object when the poe2 override is a type but the poe1 version is an enum --- src/reader.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/reader.ts b/src/reader.ts index c8b600c..a22debb 100644 --- a/src/reader.ts +++ b/src/reader.ts @@ -215,7 +215,7 @@ class VersionedTypedefNode implements Iterable<[ValidFor, T]> { constructor( public vBase: T | undefined, public vOverride: T | undefined, - readonly allowSharing: boolean + public allowSharing: boolean ) {} *[Symbol.iterator](): Iterator<[ValidFor, T]> { @@ -237,15 +237,13 @@ class VersionedTypedefNode implements Iterable<[ValidFor, T]> { class VersionedTypedefMap { readonly data = new Map>(); - constructor(readonly allowSharing: boolean) {} - - add(typeNode: T, override: boolean): boolean { + add(typeNode: T, override: boolean, allowSharing: boolean): boolean { const existingNode = this.data.get(typeNode.name.value); if (!existingNode) { this.data.set(typeNode.name.value, new VersionedTypedefNode( !override ? typeNode : undefined, override ? typeNode : undefined, - this.allowSharing + allowSharing )); } else if (override) { if (existingNode.vOverride != null) return false; @@ -300,8 +298,8 @@ export function readSchemaSources( definitionOrderDelta: number; } ): Pick { - const typeDefsMap = new VersionedTypedefMap(opts.allowSharingSchemas); - const enumDefsMap = new VersionedTypedefMap(opts.allowSharingSchemas); + const typeDefsMap = new VersionedTypedefMap(); + const enumDefsMap = new VersionedTypedefMap(); for (const source of sources) { const doc = parse(source, { noLocation: false }); @@ -313,14 +311,24 @@ export function readSchemaSources( const override = source.name.startsWith('poe2'); if (typeNode.kind === 'EnumTypeDefinition') { - if (!enumDefsMap.add(typeNode, override)) { + const objectDefinition = typeDefsMap.data.get(typeNode.name.value); + if(objectDefinition != undefined){ + objectDefinition.allowSharing = false; + } + let allowSharing = opts.allowSharingSchemas && objectDefinition == undefined; + if (!enumDefsMap.add(typeNode, override, allowSharing)) { throw new GraphQLError( 'Enum with this name has already been defined.', { nodes: typeNode.name } ); } } else if (typeNode.kind === 'ObjectTypeDefinition') { - if (!typeDefsMap.add(typeNode, override)) { + const enumDefinition = enumDefsMap.data.get(typeNode.name.value); + if(enumDefinition != undefined){ + enumDefinition.allowSharing = false; + } + let allowSharing = opts.allowSharingSchemas && enumDefinition == undefined; + if (!typeDefsMap.add(typeNode, override, allowSharing)) { throw new GraphQLError( 'Table with this name has already been defined.', { nodes: typeNode.name } From ddbb23aa0680717a4d3ae7d0012324baf2affa43 Mon Sep 17 00:00:00 2001 From: Alexander Drozdov Date: Sat, 30 May 2026 00:48:56 +0300 Subject: [PATCH 2/2] cleanup --- src/reader.ts | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/reader.ts b/src/reader.ts index a22debb..c580d8e 100644 --- a/src/reader.ts +++ b/src/reader.ts @@ -237,13 +237,16 @@ class VersionedTypedefNode implements Iterable<[ValidFor, T]> { class VersionedTypedefMap { readonly data = new Map>(); - add(typeNode: T, override: boolean, allowSharing: boolean): boolean { + constructor(readonly allowSharing: boolean) {} + + add(typeNode: T, override: boolean, otherMap: VersionedTypedefMap): boolean { const existingNode = this.data.get(typeNode.name.value); + const nodeInOtherMap = otherMap.data.get(typeNode.name.value); if (!existingNode) { this.data.set(typeNode.name.value, new VersionedTypedefNode( !override ? typeNode : undefined, override ? typeNode : undefined, - allowSharing + nodeInOtherMap != null ? false : this.allowSharing )); } else if (override) { if (existingNode.vOverride != null) return false; @@ -252,6 +255,10 @@ class VersionedTypedefMap { if (existingNode.vBase != null) return false; existingNode.vBase = typeNode; } + + if (nodeInOtherMap) { + nodeInOtherMap.allowSharing = false; + } return true; } } @@ -298,8 +305,8 @@ export function readSchemaSources( definitionOrderDelta: number; } ): Pick { - const typeDefsMap = new VersionedTypedefMap(); - const enumDefsMap = new VersionedTypedefMap(); + const typeDefsMap = new VersionedTypedefMap(opts.allowSharingSchemas); + const enumDefsMap = new VersionedTypedefMap(opts.allowSharingSchemas); for (const source of sources) { const doc = parse(source, { noLocation: false }); @@ -311,24 +318,14 @@ export function readSchemaSources( const override = source.name.startsWith('poe2'); if (typeNode.kind === 'EnumTypeDefinition') { - const objectDefinition = typeDefsMap.data.get(typeNode.name.value); - if(objectDefinition != undefined){ - objectDefinition.allowSharing = false; - } - let allowSharing = opts.allowSharingSchemas && objectDefinition == undefined; - if (!enumDefsMap.add(typeNode, override, allowSharing)) { + if (!enumDefsMap.add(typeNode, override, typeDefsMap)) { throw new GraphQLError( 'Enum with this name has already been defined.', { nodes: typeNode.name } ); } } else if (typeNode.kind === 'ObjectTypeDefinition') { - const enumDefinition = enumDefsMap.data.get(typeNode.name.value); - if(enumDefinition != undefined){ - enumDefinition.allowSharing = false; - } - let allowSharing = opts.allowSharingSchemas && enumDefinition == undefined; - if (!typeDefsMap.add(typeNode, override, allowSharing)) { + if (!typeDefsMap.add(typeNode, override, enumDefsMap)) { throw new GraphQLError( 'Table with this name has already been defined.', { nodes: typeNode.name }