Skip to content
Draft
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
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, UnknownType, 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 UNKNOWN = 0x3F

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

function createUnknownTypeTransformer () {
return new TypeTransformer({
signature: UNKNOWN,
isTypeInstance: object => object instanceof UnknownType,
toStructure: _ => {
throw newError('Unknown Type object can not be transmitted')
},
fromStructure: structure => {
return new UnknownType(structure.fields[0], structure.fields[1], structure.fields[2], structure.fields[3].message)
}
})
}

export default {
...v5x8,
createVectorTransformer
createVectorTransformer,
createUnknownTypeTransformer
}
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
5 changes: 4 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 UnknownType from './unknown-type'

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

export {
Expand Down Expand Up @@ -269,6 +271,7 @@ export {
clientCertificateProviders,
resolveCertificateProvider,
Vector,
UnknownType,
vector
}

Expand Down
67 changes: 67 additions & 0 deletions packages/core/src/unknown-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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.
*/

/**
* A representation of a value that could not be transmitted over the wire due to an outdated protocol version.
* @access public
* @exports UnknownType
*/
export default class UnknownType {
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 `UnknownType<${this.name}>`
}
}

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.

5 changes: 4 additions & 1 deletion packages/neo4j-driver-deno/lib/core/index.ts

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

29 changes: 29 additions & 0 deletions packages/neo4j-driver-deno/lib/core/unknown-type.ts

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

8 changes: 8 additions & 0 deletions packages/testkit-backend/src/cypher-native-binders.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ export default function CypherNativeBinders (neo4j) {
return structResponse('CypherVector', { dtype, data })
}

if (x._minimumProtocolMajor != null) {
const name = x.name
const minimumProtocolMajor = x._minimumProtocolMajor
const minimumProtocolMinor = x._minimumProtocolMinor
const message = x.message
return structResponse('CypherUnknownType', { name, minimumProtocolMajor, minimumProtocolMinor, message })
}

// If all failed, interpret as a map
const map = {}
for (const [key, value] of Object.entries(x)) {
Expand Down
1 change: 1 addition & 0 deletions packages/testkit-backend/src/feature/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const features = [
'Feature:API:Summary:GqlStatusObjects',
'Feature:API:Liveness.Check',
'Feature:API:Type.Vector',
'Feature:API:Type.UnknownType',
'Optimization:AuthPipelining',
'Optimization:EagerTransactionBegin',
'Optimization:ExecuteQueryPipelining',
Expand Down
2 changes: 1 addition & 1 deletion testkit/testkit.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"testkit": {
"uri": "https://github.com/neo4j-drivers/testkit.git",
"ref": "6.x"
"ref": "unknown-type-stub-tests"
}
}