diff --git a/packages/core/src/graph-types.ts b/packages/core/src/graph-types.ts index 03c0ff859..85736bb49 100644 --- a/packages/core/src/graph-types.ts +++ b/packages/core/src/graph-types.ts @@ -47,9 +47,9 @@ function hasIdentifierProperty (obj: any, property: string): boolean { /** * Class for Node Type. */ -class Node { +class Node { identity: T - labels: string[] + labels: Label[] properties: P elementId: string /** @@ -60,7 +60,7 @@ class Node { +class Relationship { identity: T start: T end: T - type: string + type: Type properties: P elementId: string startNodeElementId: string @@ -147,7 +147,7 @@ class Relationship { +class UnboundRelationship { identity: T - type: string + type: Type properties: P elementId: string @@ -250,7 +250,7 @@ class UnboundRelationship { expect(isNode(nonNode)).toBe(false) }) + test('should type mapping labels', () => { + type PersonLabels = 'Person' | 'Actor' + const labels: PersonLabels[] = ['Actor', 'Person'] + type Person = Node + + const p: Person = new Node(1, labels, {}) + + const receivedLabels: PersonLabels[] = p.labels + + expect(receivedLabels).toEqual(labels) + + // @ts-expect-error + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const _: 'Movie'|Array<'TvShow'> = p.labels + }) + function validNodes (): any[] { return [ [new Node(1, ['label'], {}, 'elementId')], @@ -191,6 +207,18 @@ describe('Relationship', () => { expect(isRelationship(nonRelationship)).toBe(false) }) + test('should type mapping relationship type', () => { + type ActedIn = Relationship + const a: ActedIn = new Relationship(1, 1, 2, 'ACTED_IN', {}) + + const receivedType: 'ACTED_IN' = a.type + expect(receivedType).toEqual('ACTED_IN') + + // @ts-expect-error + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const _: 'DIRECTED' = a.type + }) + function validRelationships (): any[] { return [ [new Relationship(1, 2, 3, 'Rel', {}, 'elementId', 'startNodeElementId', 'endNodeElementId')], @@ -306,6 +334,18 @@ describe('UnboundRelationship', () => { ) }) + test('should type mapping relationship type', () => { + type ActedIn = UnboundRelationship + const a: ActedIn = new UnboundRelationship(1, 'ACTED_IN', {}) + + const receivedType: 'ACTED_IN' = a.type + expect(receivedType).toEqual('ACTED_IN') + + // @ts-expect-error + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const _: 'DIRECTED' = a.type + }) + function validUnboundRelationships (): any[] { return [ [new UnboundRelationship(1, 'Rel', {}, 'elementId')], diff --git a/packages/neo4j-driver-deno/lib/core/graph-types.ts b/packages/neo4j-driver-deno/lib/core/graph-types.ts index 8ec873917..618732f70 100644 --- a/packages/neo4j-driver-deno/lib/core/graph-types.ts +++ b/packages/neo4j-driver-deno/lib/core/graph-types.ts @@ -47,9 +47,9 @@ function hasIdentifierProperty (obj: any, property: string): boolean { /** * Class for Node Type. */ -class Node { +class Node { identity: T - labels: string[] + labels: Label[] properties: P elementId: string /** @@ -60,7 +60,7 @@ class Node { +class Relationship { identity: T start: T end: T - type: string + type: Type properties: P elementId: string startNodeElementId: string @@ -147,7 +147,7 @@ class Relationship { +class UnboundRelationship { identity: T - type: string + type: Type properties: P elementId: string @@ -250,7 +250,7 @@ class UnboundRelationship