Skip to content

Commit 161d03f

Browse files
committed
Docs and cleaning up
1 parent a0a51c8 commit 161d03f

20 files changed

+366
-224
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 3
4545
const PATH = 0x50
4646
const PATH_STRUCT_SIZE = 3
4747

48+
/**
49+
* Creates the Node Transformer
50+
* @returns {TypeTransformer}
51+
*/
4852
function createNodeTransformer () {
4953
return new TypeTransformer({
5054
signature: NODE,
@@ -65,6 +69,10 @@ function createNodeTransformer () {
6569
})
6670
}
6771

72+
/**
73+
* Creates the Relationship Transformer
74+
* @returns {TypeTransformer}
75+
*/
6876
function createRelationshipTransformer () {
6977
return new TypeTransformer({
7078
signature: RELATIONSHIP,
@@ -85,6 +93,10 @@ function createRelationshipTransformer () {
8593
})
8694
}
8795

96+
/**
97+
* Creates the Unbound Relationship Transformer
98+
* @returns {TypeTransformer}
99+
*/
88100
function createUnboundRelationshipTransformer () {
89101
return new TypeTransformer({
90102
signature: UNBOUND_RELATIONSHIP,
@@ -109,6 +121,10 @@ function createUnboundRelationshipTransformer () {
109121
})
110122
}
111123

124+
/**
125+
* Creates the Path Transformer
126+
* @returns {TypeTransformer}
127+
*/
112128
function createPathTransformer () {
113129
return new TypeTransformer({
114130
signature: PATH,

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ const DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE = 3
8080
const DATE_TIME_WITH_ZONE_ID = 0x66
8181
const DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE = 3
8282

83+
/**
84+
* Creates the Point2D Transformer
85+
* @returns {TypeTransformer}
86+
*/
8387
function createPoint2DTransformer () {
8488
return new TypeTransformer({
8589
signature: POINT_2D,
@@ -103,6 +107,10 @@ function createPoint2DTransformer () {
103107
})
104108
}
105109

110+
/**
111+
* Creates the Point3D Transformer
112+
* @returns {TypeTransformer}
113+
*/
106114
function createPoint3DTransformer () {
107115
return new TypeTransformer({
108116
signature: POINT_3D,
@@ -127,6 +135,10 @@ function createPoint3DTransformer () {
127135
})
128136
}
129137

138+
/**
139+
* Creates the Duration Transformer
140+
* @returns {TypeTransformer}
141+
*/
130142
function createDurationTransformer () {
131143
return new TypeTransformer({
132144
signature: DURATION,
@@ -149,6 +161,13 @@ function createDurationTransformer () {
149161
})
150162
}
151163

164+
/**
165+
* Creates the LocalTime Transformer
166+
* @param {Object} param
167+
* @param {boolean} param.disableLosslessIntegers Disables lossless integers
168+
* @param {boolean} param.useBigInt Uses BigInt instead of number or Integer
169+
* @returns {TypeTransformer}
170+
*/
152171
function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) {
153172
return new TypeTransformer({
154173
signature: LOCAL_TIME,
@@ -173,6 +192,13 @@ function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) {
173192
})
174193
}
175194

195+
/**
196+
* Creates the Time Transformer
197+
* @param {Object} param
198+
* @param {boolean} param.disableLosslessIntegers Disables lossless integers
199+
* @param {boolean} param.useBigInt Uses BigInt instead of number or Integer
200+
* @returns {TypeTransformer}
201+
*/
176202
function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) {
177203
return new TypeTransformer({
178204
signature: TIME,
@@ -205,6 +231,13 @@ function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) {
205231
})
206232
}
207233

234+
/**
235+
* Creates the Date Transformer
236+
* @param {Object} param
237+
* @param {boolean} param.disableLosslessIntegers Disables lossless integers
238+
* @param {boolean} param.useBigInt Uses BigInt instead of number or Integer
239+
* @returns {TypeTransformer}
240+
*/
208241
function createDateTransformer ({ disableLosslessIntegers, useBigInt }) {
209242
return new TypeTransformer({
210243
signature: DATE,
@@ -224,6 +257,13 @@ function createDateTransformer ({ disableLosslessIntegers, useBigInt }) {
224257
})
225258
}
226259

260+
/**
261+
* Creates the LocalDateTime Transformer
262+
* @param {Object} param
263+
* @param {boolean} param.disableLosslessIntegers Disables lossless integers
264+
* @param {boolean} param.useBigInt Uses BigInt instead of number or Integer
265+
* @returns {TypeTransformer}
266+
*/
227267
function createLocalDateTimeTransformer ({ disableLosslessIntegers, useBigInt }) {
228268
return new TypeTransformer({
229269
signature: LOCAL_DATE_TIME,
@@ -256,6 +296,13 @@ function createLocalDateTimeTransformer ({ disableLosslessIntegers, useBigInt })
256296
})
257297
}
258298

299+
/**
300+
* Creates the DateTime with ZoneId Transformer
301+
* @param {Object} param
302+
* @param {boolean} param.disableLosslessIntegers Disables lossless integers
303+
* @param {boolean} param.useBigInt Uses BigInt instead of number or Integer
304+
* @returns {TypeTransformer}
305+
*/
259306
function createDateTimeWithZoneIdTransformer ({ disableLosslessIntegers, useBigInt }) {
260307
return new TypeTransformer({
261308
signature: DATE_TIME_WITH_ZONE_ID,
@@ -301,6 +348,13 @@ function createDateTimeWithZoneIdTransformer ({ disableLosslessIntegers, useBigI
301348
})
302349
}
303350

351+
/**
352+
* Creates the DateTime with Offset Transformer
353+
* @param {Object} param
354+
* @param {boolean} param.disableLosslessIntegers Disables lossless integers
355+
* @param {boolean} param.useBigInt Uses BigInt instead of number or Integer
356+
* @returns {TypeTransformer}
357+
*/
304358
function createDateTimeWithOffsetTransformer ({ disableLosslessIntegers, useBigInt }) {
305359
return new TypeTransformer({
306360
signature: DATE_TIME_WITH_ZONE_OFFSET,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const NODE_STRUCT_SIZE = 4
2525
const RELATIONSHIP_STRUCT_SIZE = 8
2626
const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 4
2727

28+
/**
29+
* Create an extend Node transformer with support to elementId
30+
* @param {any} config
31+
* @returns {TypeTransformer}
32+
*/
2833
function createNodeTransformer (config) {
2934
const node4x4Transformer = v4x4.createNodeTransformer(config)
3035
return node4x4Transformer.extendsWith({
@@ -43,6 +48,11 @@ function createNodeTransformer (config) {
4348
})
4449
}
4550

51+
/**
52+
* Create an extend Relationship transformer with support to elementId
53+
* @param {any} config
54+
* @returns {TypeTransformer}
55+
*/
4656
function createRelationshipTransformer (config) {
4757
const relationship4x4Transformer = v4x4.createRelationshipTransformer(config)
4858
return relationship4x4Transformer.extendsWith({
@@ -74,6 +84,11 @@ function createRelationshipTransformer (config) {
7484
})
7585
}
7686

87+
/**
88+
* Create an extend Unbound Relationship transformer with support to elementId
89+
* @param {any} config
90+
* @returns {TypeTransformer}
91+
*/
7792
function createUnboundRelationshipTransformer (config) {
7893
const unboundRelationshipTransformer = v4x4.createUnboundRelationshipTransformer(config)
7994
return unboundRelationshipTransformer.extendsWith({

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919

2020
import { structure } from '../packstream'
2121

22+
/**
23+
* Class responsible for applying the expected {@link TypeTransformer} to
24+
* transform the driver types from and to {@link struct.Structure}
25+
*/
2226
export default class Transformer {
27+
/**
28+
* Constructor
29+
* @param {TypeTransformer[]} transformers The type transformers
30+
*/
2331
constructor (transformers) {
2432
this._transformers = transformers
2533
this._transformersPerSignature = new Map(transformers.map(typeTransformer => [typeTransformer.signature, typeTransformer]))
@@ -28,6 +36,12 @@ export default class Transformer {
2836
Object.freeze(this)
2937
}
3038

39+
/**
40+
* Transform from structure to specific object
41+
*
42+
* @param {struct.Structure} struct The structure
43+
* @returns {<T>|structure.Structure} The driver object or the structure if the transformer was not found.
44+
*/
3145
fromStructure (struct) {
3246
if (struct instanceof structure.Structure && this._transformersPerSignature.has(struct.signature)) {
3347
const { fromStructure } = this._transformersPerSignature.get(struct.signature)
@@ -36,6 +50,11 @@ export default class Transformer {
3650
return struct
3751
}
3852

53+
/**
54+
* Transform from object to structure
55+
* @param {<T>} type The object to be transoformed in structure
56+
* @returns {<T>|structure.Structure} The structure or the object, if any transformer was found
57+
*/
3958
toStructure (type) {
4059
const transformer = this._transformers.find(({ isTypeInstance }) => isTypeInstance(type))
4160
if (transformer !== undefined) {
@@ -45,7 +64,36 @@ export default class Transformer {
4564
}
4665
}
4766

67+
/**
68+
* @callback isTypeInstanceFunction
69+
* @param {any} object The object
70+
* @return {boolean} is instance of
71+
*/
72+
73+
/**
74+
* @callback toStructureFunction
75+
* @param {any} object The object
76+
* @return {structure.Structure} The structure
77+
*/
78+
79+
/**
80+
* @callback fromStructureFunction
81+
* @param {structure.Structure} struct The structure
82+
* @return {any} The object
83+
*/
84+
85+
/**
86+
* Class responsible for grouping the properties of a TypeTransformer
87+
*/
4888
export class TypeTransformer {
89+
/**
90+
* @param {Object} param
91+
* @param {number} param.signature The signature of the structure
92+
* @param {isTypeInstanceFunction} param.isTypeInstance The function which checks if object is
93+
* instance of the type described by the TypeTransformer
94+
* @param {toStructureFunction} param.toStructure The function which gets the object and converts to structure
95+
* @param {fromStructureFunction} param.fromStructure The function which get the structure and covnverts to object
96+
*/
4997
constructor ({ signature, fromStructure, toStructure, isTypeInstance }) {
5098
this.signature = signature
5199
this.isTypeInstance = isTypeInstance
@@ -55,6 +103,15 @@ export class TypeTransformer {
55103
Object.freeze(this)
56104
}
57105

106+
/**
107+
* @param {Object} param
108+
* @param {number} [param.signature] The signature of the structure
109+
* @param {isTypeInstanceFunction} [param.isTypeInstance] The function which checks if object is
110+
* instance of the type described by the TypeTransformer
111+
* @param {toStructureFunction} [param.toStructure] The function which gets the object and converts to structure
112+
* @param {fromStructureFunction} pparam.fromStructure] The function which get the structure and covnverts to object
113+
* @returns {TypeTransformer} A new type transform extends with new methods
114+
*/
58115
extendsWith ({ signature, fromStructure, toStructure, isTypeInstance }) {
59116
return new TypeTransformer({
60117
signature: signature || this.signature,

packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Rela
88

99
exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`;
1010

11-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`;
11+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`;
1212

13-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`;
13+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`;
1414

15-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`;
15+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`;
1616

17-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`;
17+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`;
1818

19-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`;
19+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`;
2020

21-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`;
21+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`;
2222

23-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`;
23+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`;
2424

25-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`;
25+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`;
2626

27-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`;
27+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`;
2828

29-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`;
29+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`;
3030

31-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`;
31+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`;
3232

33-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`;
33+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`;
3434

35-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`;
35+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`;
3636

37-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`;
37+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`;
3838

39-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`;
39+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`;
4040

41-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`;
41+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`;
4242

43-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`;
43+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`;
4444

45-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`;
45+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`;
4646

47-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`;
47+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`;
4848

49-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`;
49+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`;
5050

51-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`;
51+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`;
5252

53-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`;
53+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`;
5454

55-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`;
55+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`;
5656

57-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`;
57+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`;
5858

59-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`;
59+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`;
6060

61-
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`;
61+
exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`;

0 commit comments

Comments
 (0)