Skip to content

Commit 0e6236d

Browse files
authored
Introduce Unsupported type to Bolt 6.0 (#1325)
1 parent e75e833 commit 0e6236d

File tree

16 files changed

+342
-6
lines changed

16 files changed

+342
-6
lines changed

packages/bolt-connection/src/bolt/bolt-protocol-v6x0.transformer.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
import v5x8 from './bolt-protocol-v5x8.transformer'
1919
import { TypeTransformer } from './transformer'
2020
import { structure } from '../packstream'
21-
import { Vector, isVector, newError } from 'neo4j-driver-core'
21+
import { Vector, isVector, UnsupportedType, isUnsupportedType, newError } from 'neo4j-driver-core'
2222
const VECTOR = 0x56
2323
const FLOAT_32 = 0xc6
2424
const FLOAT_64 = 0xc1
2525
const INT_8 = 0xc8
2626
const INT_16 = 0xc9
2727
const INT_32 = 0xca
2828
const INT_64 = 0xcb
29+
const UNSUPPORTED = 0x3F
2930

3031
const typeToTypeMarker = {
3132
INT8: INT_8,
@@ -132,7 +133,21 @@ function checkLittleEndian () {
132133
return typeArray[0] === 1000
133134
}
134135

136+
function createUnsupportedTypeTransformer () {
137+
return new TypeTransformer({
138+
signature: UNSUPPORTED,
139+
isTypeInstance: object => isUnsupportedType(object),
140+
toStructure: _ => {
141+
throw newError('UnsupportedType object can not be transmitted')
142+
},
143+
fromStructure: structure => {
144+
return new UnsupportedType(structure.fields[0], structure.fields[1], structure.fields[2], structure.fields[3].message)
145+
}
146+
})
147+
}
148+
135149
export default {
136150
...v5x8,
137-
createVectorTransformer
151+
createVectorTransformer,
152+
createUnsupportedTypeTransformer
138153
}

packages/bolt-connection/src/bolt/transformer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class TypeTransformer {
114114
* @param {isTypeInstanceFunction} [param.isTypeInstance] The function which checks if object is
115115
* instance of the type described by the TypeTransformer
116116
* @param {toStructureFunction} [param.toStructure] The function which gets the object and converts to structure
117-
* @param {fromStructureFunction} pparam.fromStructure] The function which get the structure and covnverts to object
117+
* @param {fromStructureFunction} [param.fromStructure] The function which get the structure and covnverts to object
118118
* @returns {TypeTransformer} A new type transform extends with new methods
119119
*/
120120
extendsWith ({ signature, fromStructure, toStructure, isTypeInstance }) {

packages/core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import resultTransformers, { ResultTransformer } from './result-transformers'
103103
import ClientCertificate, { clientCertificateProviders, ClientCertificateProvider, ClientCertificateProviders, RotatingClientCertificateProvider, resolveCertificateProvider } from './client-certificate'
104104
import * as internal from './internal' // todo: removed afterwards
105105
import Vector, { VectorType, vector, isVector } from './vector'
106+
import UnsupportedType, { isUnsupportedType } from './unsupported-type'
106107

107108
/**
108109
* Object containing string constants representing predefined {@link Neo4jError} codes.
@@ -190,6 +191,8 @@ const forExport = {
190191
notificationFilterMinimumSeverityLevel,
191192
clientCertificateProviders,
192193
resolveCertificateProvider,
194+
UnsupportedType,
195+
isUnsupportedType,
193196
isVector,
194197
vector
195198
}
@@ -272,6 +275,8 @@ export {
272275
resolveCertificateProvider,
273276
isVector,
274277
Vector,
278+
UnsupportedType,
279+
isUnsupportedType,
275280
vector
276281
}
277282

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const UNSUPPORTED_TYPE_IDENTIFIER_PROPERTY = '__isUnsupportedType__'
19+
20+
/**
21+
* Represents a type unknown to the driver, received from the server.
22+
* 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.
23+
*
24+
* Note that this type may only be received from the server, but cannot be sent to the server (e.g., as a query parameter).
25+
*
26+
* The attributes exposed by this type are meant for displaying and debugging purposes.
27+
* They may change in future versions of the server, and should not be relied upon for any logic in your application.
28+
* If your application requires handling this type, you must upgrade your driver to a version that supports it.
29+
* @access public
30+
* @exports UnsupportedType
31+
*/
32+
export default class UnsupportedType {
33+
name: string
34+
minimumProtocolVersion: string
35+
message: string | undefined
36+
constructor (name: string, minimumProtocolMajor: number, minimumProtocolMinor: number, message: string | undefined) {
37+
/**
38+
* The name of the type that could not be transmitted.
39+
*
40+
* @type {string}
41+
*/
42+
this.name = name
43+
/**
44+
* The minimum required Bolt protocol version that supports this type.
45+
* To understand which driver version this corresponds to, refer to the driver's release notes or documentation.
46+
*
47+
* @type {string}
48+
*/
49+
this.minimumProtocolVersion = `${minimumProtocolMajor}.${minimumProtocolMinor}`
50+
/**
51+
* An optional message, including additional information regarding the untransmittable value.
52+
*
53+
* @type {string | undefined}
54+
*/
55+
this.message = message
56+
}
57+
58+
toString (): string {
59+
return `UnsupportedType<${this.name}>`
60+
}
61+
}
62+
63+
Object.defineProperty(UnsupportedType.prototype, UNSUPPORTED_TYPE_IDENTIFIER_PROPERTY, {
64+
value: true,
65+
enumerable: false,
66+
configurable: false,
67+
writable: false
68+
})
69+
70+
/**
71+
* Test if given object is an instance of the {@link UnsupportedType} class.
72+
* @param {Object} obj the object to test.
73+
* @return {boolean} `true` if given object is an {@link UnsupportedType}, `false` otherwise.
74+
*/
75+
export function isUnsupportedType (obj: any): obj is UnsupportedType {
76+
return obj != null && obj[UNSUPPORTED_TYPE_IDENTIFIER_PROPERTY] === true
77+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { UnsupportedType } from '../src'
19+
20+
describe('UnsupportedType', () => {
21+
it.each([
22+
['with message', ['QuantumInteger', 76, 87, 'Quantum computing is from the future.'], '76.87', 'UnsupportedType<QuantumInteger>'],
23+
['without message', ['CuniformInteger', 1, 1], '1.1', 'UnsupportedType<CuniformInteger>']
24+
])('should create UnsupportedType (%s)', (_, parameters: [string, number, number, string], protocolString, representation) => {
25+
const unsupportedType = new UnsupportedType(...parameters)
26+
expect(unsupportedType.minimumProtocolVersion).toBe(protocolString)
27+
expect(unsupportedType.toString()).toBe(representation)
28+
expect(unsupportedType.message).toBe(parameters[3])
29+
})
30+
})

packages/neo4j-driver-deno/deno.lock

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v6x0.transformer.js

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/neo4j-driver-deno/lib/bolt-connection/bolt/transformer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)