Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions packages/core/src/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,8 @@ export default class Vector<K extends Float32Array | Float64Array | Int8Array |
this._type = vectorTypes.FLOAT32
} else if (typedArray instanceof Float64Array) {
this._type = vectorTypes.FLOAT64
} else if (
typedArray instanceof Uint8Array ||
typedArray instanceof Uint16Array ||
typedArray instanceof Uint32Array ||
typedArray instanceof BigUint64Array
) {
throw newError('The neo4j Vector class does not support Unsigned Integer Arrays, please use a signed IntArray')
} else {
// @ts-expect-error
throw newError(`The neo4j Vector class is a wrapper for TypedArrays. got ${(typedArray.toString() as string)}`)
throw newError(`Invalid argument type passed to Vector constructor: should be signed integer or float TypedArray, got: ${(typedArray as any)?.constructor?.name as string ?? 'undefined or type without constructor name'}`)
}
this._typedArray = typedArray
}
Expand Down Expand Up @@ -132,15 +124,7 @@ export function vector<K extends Float32Array | Float64Array | Int8Array | Int16
try {
return new Vector(typedArray)
} catch {
if (
typedArray instanceof Uint8Array ||
typedArray instanceof Uint16Array ||
typedArray instanceof Uint32Array ||
typedArray instanceof BigUint64Array
) {
throw newError('Invalid argument type passed to vector constructor function: should be signed integer or float TypedArray, got unsigned integer TypedArray')
}
throw newError(`Invalid argument type passed to vector constructor function: should be TypedArray, got ${typedArray.toString()}`)
throw newError(`Invalid argument type passed to vector constructor function: should be signed integer or float TypedArray, got: ${typedArray?.constructor?.name ?? 'undefined or type without constructor name'}`)
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/core/test/vector-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ describe('Vector', () => {
})

it.each([
['array', [], 'should be TypedArray, got'],
['Unsigned TypedArray', Uint16Array.from([]), 'should be signed integer or float TypedArray, got unsigned integer TypedArray']
['array', [], 'Invalid argument type passed to vector constructor function: should be signed integer or float TypedArray, got: Array'],
['Unsigned TypedArray', Uint16Array.from([]), 'Invalid argument type passed to vector constructor function: should be signed integer or float TypedArray, got: Uint16Array'],
['undefined', undefined, 'Invalid argument type passed to vector constructor function: should be signed integer or float TypedArray, got: undefined or type without constructor name']
])('should fail to create create vector from (%s)', (_, typedArray, expectedMessage) => {
// @ts-expect-error
expect(() => vector(typedArray)).toThrow(expectedMessage)
Expand Down
20 changes: 2 additions & 18 deletions packages/neo4j-driver-deno/lib/core/vector.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.