Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
import v5x8 from './bolt-protocol-v5x8.transformer'
import { TypeTransformer } from './transformer'
import { structure } from '../packstream'
import { Vector, newError } from 'neo4j-driver-core'
import { Vector, UnsupportedType, isUnsupportedType, newError } from 'neo4j-driver-core'
const VECTOR = 0x56
const FLOAT_32 = 0xc6
const FLOAT_64 = 0xc1
const INT_8 = 0xc8
const INT_16 = 0xc9
const INT_32 = 0xca
const INT_64 = 0xcb
const UNSUPPORTED = 0x3F

const typeToTypeMarker = {
INT8: INT_8,
Expand Down Expand Up @@ -132,7 +133,21 @@ function checkLittleEndian () {
return typeArray[0] === 1000
}

function createUnsupportedTypeTransformer () {
return new TypeTransformer({
signature: UNSUPPORTED,
isTypeInstance: object => isUnsupportedType(object),
toStructure: _ => {
throw newError('Unsupported Type object can not be transmitted')
},
fromStructure: structure => {
return new UnsupportedType(structure.fields[0], structure.fields[1], structure.fields[2], structure.fields[3].message)
}
})
}

export default {
...v5x8,
createVectorTransformer
createVectorTransformer,
createUnsupportedTypeTransformer
}
2 changes: 1 addition & 1 deletion packages/bolt-connection/src/bolt/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class TypeTransformer {
* @param {isTypeInstanceFunction} [param.isTypeInstance] The function which checks if object is
* instance of the type described by the TypeTransformer
* @param {toStructureFunction} [param.toStructure] The function which gets the object and converts to structure
* @param {fromStructureFunction} pparam.fromStructure] The function which get the structure and covnverts to object
* @param {fromStructureFunction} [param.fromStructure] The function which get the structure and covnverts to object
* @returns {TypeTransformer} A new type transform extends with new methods
*/
extendsWith ({ signature, fromStructure, toStructure, isTypeInstance }) {
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import resultTransformers, { ResultTransformer } from './result-transformers'
import ClientCertificate, { clientCertificateProviders, ClientCertificateProvider, ClientCertificateProviders, RotatingClientCertificateProvider, resolveCertificateProvider } from './client-certificate'
import * as internal from './internal' // todo: removed afterwards
import Vector, { VectorType, vector } from './vector'
import UnsupportedType, { isUnsupportedType } from './unsupported-type'

/**
* Object containing string constants representing predefined {@link Neo4jError} codes.
Expand Down Expand Up @@ -189,7 +190,9 @@ const forExport = {
notificationFilterDisabledClassification,
notificationFilterMinimumSeverityLevel,
clientCertificateProviders,
resolveCertificateProvider
resolveCertificateProvider,
UnsupportedType,
isUnsupportedType
}

export {
Expand Down Expand Up @@ -269,6 +272,8 @@ export {
clientCertificateProviders,
resolveCertificateProvider,
Vector,
UnsupportedType,
isUnsupportedType,
vector
}

Expand Down
92 changes: 92 additions & 0 deletions packages/core/src/unsupported-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const UNSUPPORTED_TYPE_IDENTIFIER_PROPERTY = '__isType__'

/**
* Represents a type unknown to the driver, received from the server.
* This type is used for instance when a newer DBMS produces a result containing a type that the current version of the driver does not yet understand.
*
* Note that this type may only be received from the server, but cannot be sent to the server (e.g., as a query parameter).
*
* The attributes exposed by this type are meant for displaying and debugging purposes.
* They may change in future versions of the server, and should not be relied upon for any logic in your application.
* If your application requires handling this type, you must upgrade your driver to a version that supports it.
* @access public
* @exports UnsupportedType
*/
export default class UnsupportedType {
name: string
_minimumProtocolMajor: number
_minimumProtocolMinor: number
message: string | undefined
constructor (name: string, minimumProtocolMajor: number, minimumProtocolMinor: number, message: string | undefined) {
/**
* The name of the type that could not be transmitted.
*
* @type {string}
*/
this.name = name
/**
* The major version of the protocol needed to transmit the value.
*
* @type {number}
* @access private
*/
this._minimumProtocolMajor = minimumProtocolMajor
/**
* The minor version of the protocol needed to transmit the value.
*
* @type {number}
* @access private
*/
this._minimumProtocolMinor = minimumProtocolMinor
/**
* An optional message, including additional information regarding the untransmittable value.
*
* @type {string | undefined}
*/
this.message = message
}

/**
* @returns {string} The minimum version of the protocol needed to transmit this value.
*/
minimumProtocolVersion (): string {
return `${this._minimumProtocolMajor}.${this._minimumProtocolMinor}`
}

toString (): string {
return `UnsupportedType<${this.name}>`
}
}

Object.defineProperty(UnsupportedType.prototype, UNSUPPORTED_TYPE_IDENTIFIER_PROPERTY, {
value: true,
enumerable: false,
configurable: false,
writable: false
})

/**
* Test if given object is an instance of the {@link UnsupportedType} class.
* @param {Object} obj the object to test.
* @return {boolean} `true` if given object is a {@link UnsupportedType}, `false` otherwise.
*/
export function isUnsupportedType (obj: any): obj is UnsupportedType {
return obj != null && obj[UNSUPPORTED_TYPE_IDENTIFIER_PROPERTY] === true
}
30 changes: 30 additions & 0 deletions packages/core/test/unsupported-type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { UnsupportedType } from '../src'

describe('UnsupportedType', () => {
it.each([
['with message', ['QuantumInteger', 76, 87, 'Quantum computing is from the future.'], '76.87', 'UnsupportedType<QuantumInteger>'],
['without message', ['CuniformInteger', 1, 1], '1.1', 'UnsupportedType<CuniformInteger>']
])('should create UnsupportedType (%s)', (_, parameters: [string, number, number, string], protocolString, representation) => {
const unsupportedType = new UnsupportedType(...parameters)
expect(unsupportedType.minimumProtocolVersion()).toBe(protocolString)
expect(unsupportedType.toString()).toBe(representation)
expect(unsupportedType.message).toBe(parameters[3])
})
})
92 changes: 92 additions & 0 deletions packages/neo4j-driver-deno/deno.lock

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

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

Loading