@neo4j-cypher/query-tools 2.0.0-next.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/LICENSE.md +201 -0
  3. package/README.md +7 -0
  4. package/dist/cjs/package.json +41 -0
  5. package/dist/cjs/src/connectionErrorHandler.d.ts +12 -0
  6. package/dist/cjs/src/connectionErrorHandler.js +41 -0
  7. package/dist/cjs/src/connectionErrorHandler.js.map +1 -0
  8. package/dist/cjs/src/cypher-execution/query-result.d.ts +11 -0
  9. package/dist/cjs/src/cypher-execution/query-result.js +195 -0
  10. package/dist/cjs/src/cypher-execution/query-result.js.map +1 -0
  11. package/dist/cjs/src/data-transforms/clean-type.d.ts +6 -0
  12. package/dist/cjs/src/data-transforms/clean-type.js +16 -0
  13. package/dist/cjs/src/data-transforms/clean-type.js.map +1 -0
  14. package/dist/cjs/src/data-transforms/cypher-type-names.d.ts +6 -0
  15. package/dist/cjs/src/data-transforms/cypher-type-names.js +85 -0
  16. package/dist/cjs/src/data-transforms/cypher-type-names.js.map +1 -0
  17. package/dist/cjs/src/data-transforms/format-float.d.ts +1 -0
  18. package/dist/cjs/src/data-transforms/format-float.js +14 -0
  19. package/dist/cjs/src/data-transforms/format-float.js.map +1 -0
  20. package/dist/cjs/src/data-transforms/record-to-string.d.ts +5 -0
  21. package/dist/cjs/src/data-transforms/record-to-string.js +174 -0
  22. package/dist/cjs/src/data-transforms/record-to-string.js.map +1 -0
  23. package/dist/cjs/src/data-types/cypher-data-types.d.ts +29 -0
  24. package/dist/cjs/src/data-types/cypher-data-types.js +3 -0
  25. package/dist/cjs/src/data-types/cypher-data-types.js.map +1 -0
  26. package/dist/cjs/src/index.d.ts +14 -0
  27. package/dist/cjs/src/index.js +15 -0
  28. package/dist/cjs/src/index.js.map +1 -0
  29. package/dist/cjs/src/metadataPoller.d.ts +31 -0
  30. package/dist/cjs/src/metadataPoller.js +197 -0
  31. package/dist/cjs/src/metadataPoller.js.map +1 -0
  32. package/dist/cjs/src/neo4jConnection.d.ts +29 -0
  33. package/dist/cjs/src/neo4jConnection.js +107 -0
  34. package/dist/cjs/src/neo4jConnection.js.map +1 -0
  35. package/dist/cjs/src/queries/dataSummary.d.ts +7 -0
  36. package/dist/cjs/src/queries/dataSummary.js +33 -0
  37. package/dist/cjs/src/queries/dataSummary.js.map +1 -0
  38. package/dist/cjs/src/queries/databases.d.ts +27 -0
  39. package/dist/cjs/src/queries/databases.js +28 -0
  40. package/dist/cjs/src/queries/databases.js.map +1 -0
  41. package/dist/cjs/src/queries/functions.d.ts +16 -0
  42. package/dist/cjs/src/queries/functions.js +88 -0
  43. package/dist/cjs/src/queries/functions.js.map +1 -0
  44. package/dist/cjs/src/queries/procedures.d.ts +16 -0
  45. package/dist/cjs/src/queries/procedures.js +106 -0
  46. package/dist/cjs/src/queries/procedures.js.map +1 -0
  47. package/dist/cjs/src/queries/roles.d.ts +11 -0
  48. package/dist/cjs/src/queries/roles.js +24 -0
  49. package/dist/cjs/src/queries/roles.js.map +1 -0
  50. package/dist/cjs/src/queries/users.d.ts +15 -0
  51. package/dist/cjs/src/queries/users.js +24 -0
  52. package/dist/cjs/src/queries/users.js.map +1 -0
  53. package/dist/cjs/src/queries/version.d.ts +7 -0
  54. package/dist/cjs/src/queries/version.js +26 -0
  55. package/dist/cjs/src/queries/version.js.map +1 -0
  56. package/dist/cjs/src/schemaPoller.d.ts +44 -0
  57. package/dist/cjs/src/schemaPoller.js +167 -0
  58. package/dist/cjs/src/schemaPoller.js.map +1 -0
  59. package/dist/cjs/src/types/cypher-data-types.d.ts +41 -0
  60. package/dist/cjs/src/types/cypher-data-types.js +46 -0
  61. package/dist/cjs/src/types/cypher-data-types.js.map +1 -0
  62. package/dist/cjs/src/types/sdkTypes.d.ts +17 -0
  63. package/dist/cjs/src/types/sdkTypes.js +3 -0
  64. package/dist/cjs/src/types/sdkTypes.js.map +1 -0
  65. package/dist/cjs/tsconfig.tsbuildinfo +1 -0
  66. package/dist/esm/package.json +41 -0
  67. package/dist/esm/src/connectionErrorHandler.d.ts +12 -0
  68. package/dist/esm/src/connectionErrorHandler.js +35 -0
  69. package/dist/esm/src/connectionErrorHandler.js.map +1 -0
  70. package/dist/esm/src/cypher-execution/query-result.d.ts +11 -0
  71. package/dist/esm/src/cypher-execution/query-result.js +188 -0
  72. package/dist/esm/src/cypher-execution/query-result.js.map +1 -0
  73. package/dist/esm/src/data-transforms/clean-type.d.ts +6 -0
  74. package/dist/esm/src/data-transforms/clean-type.js +12 -0
  75. package/dist/esm/src/data-transforms/clean-type.js.map +1 -0
  76. package/dist/esm/src/data-transforms/cypher-type-names.d.ts +6 -0
  77. package/dist/esm/src/data-transforms/cypher-type-names.js +80 -0
  78. package/dist/esm/src/data-transforms/cypher-type-names.js.map +1 -0
  79. package/dist/esm/src/data-transforms/format-float.d.ts +1 -0
  80. package/dist/esm/src/data-transforms/format-float.js +10 -0
  81. package/dist/esm/src/data-transforms/format-float.js.map +1 -0
  82. package/dist/esm/src/data-transforms/record-to-string.d.ts +5 -0
  83. package/dist/esm/src/data-transforms/record-to-string.js +169 -0
  84. package/dist/esm/src/data-transforms/record-to-string.js.map +1 -0
  85. package/dist/esm/src/data-types/cypher-data-types.d.ts +29 -0
  86. package/dist/esm/src/data-types/cypher-data-types.js +2 -0
  87. package/dist/esm/src/data-types/cypher-data-types.js.map +1 -0
  88. package/dist/esm/src/index.d.ts +14 -0
  89. package/dist/esm/src/index.js +6 -0
  90. package/dist/esm/src/index.js.map +1 -0
  91. package/dist/esm/src/metadataPoller.d.ts +31 -0
  92. package/dist/esm/src/metadataPoller.js +191 -0
  93. package/dist/esm/src/metadataPoller.js.map +1 -0
  94. package/dist/esm/src/neo4jConnection.d.ts +29 -0
  95. package/dist/esm/src/neo4jConnection.js +103 -0
  96. package/dist/esm/src/neo4jConnection.js.map +1 -0
  97. package/dist/esm/src/queries/dataSummary.d.ts +7 -0
  98. package/dist/esm/src/queries/dataSummary.js +30 -0
  99. package/dist/esm/src/queries/dataSummary.js.map +1 -0
  100. package/dist/esm/src/queries/databases.d.ts +27 -0
  101. package/dist/esm/src/queries/databases.js +25 -0
  102. package/dist/esm/src/queries/databases.js.map +1 -0
  103. package/dist/esm/src/queries/functions.d.ts +16 -0
  104. package/dist/esm/src/queries/functions.js +81 -0
  105. package/dist/esm/src/queries/functions.js.map +1 -0
  106. package/dist/esm/src/queries/procedures.d.ts +16 -0
  107. package/dist/esm/src/queries/procedures.js +99 -0
  108. package/dist/esm/src/queries/procedures.js.map +1 -0
  109. package/dist/esm/src/queries/roles.d.ts +11 -0
  110. package/dist/esm/src/queries/roles.js +21 -0
  111. package/dist/esm/src/queries/roles.js.map +1 -0
  112. package/dist/esm/src/queries/users.d.ts +15 -0
  113. package/dist/esm/src/queries/users.js +21 -0
  114. package/dist/esm/src/queries/users.js.map +1 -0
  115. package/dist/esm/src/queries/version.d.ts +7 -0
  116. package/dist/esm/src/queries/version.js +23 -0
  117. package/dist/esm/src/queries/version.js.map +1 -0
  118. package/dist/esm/src/schemaPoller.d.ts +44 -0
  119. package/dist/esm/src/schemaPoller.js +160 -0
  120. package/dist/esm/src/schemaPoller.js.map +1 -0
  121. package/dist/esm/src/types/cypher-data-types.d.ts +41 -0
  122. package/dist/esm/src/types/cypher-data-types.js +39 -0
  123. package/dist/esm/src/types/cypher-data-types.js.map +1 -0
  124. package/dist/esm/src/types/sdkTypes.d.ts +17 -0
  125. package/dist/esm/src/types/sdkTypes.js +2 -0
  126. package/dist/esm/src/types/sdkTypes.js.map +1 -0
  127. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  128. package/package.json +41 -0
  129. package/src/connectionErrorHandler.ts +56 -0
  130. package/src/cypher-execution/query-result.ts +348 -0
  131. package/src/data-transforms/clean-type.ts +13 -0
  132. package/src/data-transforms/cypher-type-names.ts +146 -0
  133. package/src/data-transforms/format-float.ts +9 -0
  134. package/src/data-transforms/record-to-string.ts +248 -0
  135. package/src/data-types/cypher-data-types.ts +60 -0
  136. package/src/index.ts +21 -0
  137. package/src/metadataPoller.ts +261 -0
  138. package/src/neo4jConnection.ts +149 -0
  139. package/src/queries/dataSummary.ts +42 -0
  140. package/src/queries/databases.ts +63 -0
  141. package/src/queries/functions.ts +97 -0
  142. package/src/queries/procedures.ts +117 -0
  143. package/src/queries/roles.ts +30 -0
  144. package/src/queries/users.ts +35 -0
  145. package/src/queries/version.ts +28 -0
  146. package/src/schemaPoller.ts +301 -0
  147. package/src/types/cypher-data-types.ts +153 -0
  148. package/src/types/sdkTypes.ts +29 -0
  149. package/tsconfig.json +8 -0
@@ -0,0 +1,348 @@
1
+ import type { QueryResult, Record as Neo4jRecord } from 'neo4j-driver';
2
+ import { int, isInt, types } from 'neo4j-driver';
3
+
4
+ export const RESERVED_TYPE_PROPERTY_NAME = 'transport-class';
5
+ export const ESCAPE_CHAR = '_';
6
+
7
+ export type Neo4jType =
8
+ | typeof types.Record
9
+ | typeof types.Result
10
+ | typeof types.ResultSummary
11
+ | typeof types.Node
12
+ | typeof types.PathSegment
13
+ | typeof types.Path
14
+ | typeof types.Relationship
15
+ | typeof types.Point
16
+ | typeof types.Date
17
+ | typeof types.DateTime
18
+ | typeof types.Duration
19
+ | typeof types.LocalDateTime
20
+ | typeof types.LocalTime
21
+ | typeof types.Time
22
+ | typeof types.Integer
23
+ | Record<string, unknown>
24
+ | Neo4jType[]
25
+ | undefined
26
+ | null;
27
+
28
+ export function addAnnotationProp(
29
+ obj: Record<string, unknown>,
30
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
31
+ type: string | unknown,
32
+ prop: string = RESERVED_TYPE_PROPERTY_NAME,
33
+ ): Record<string, unknown> {
34
+ // The shallow copy is needed because the object type returned by the driver is not extensible.
35
+ let objShallowCopy = Object.entries(obj).reduce<Record<string, unknown>>(
36
+ (newObj, [key, value]) => {
37
+ newObj[key] = value;
38
+ return newObj;
39
+ },
40
+ {},
41
+ );
42
+
43
+ // Recursively escape the reserved property if it already exists.
44
+ if (Object.prototype.hasOwnProperty.call(objShallowCopy, prop)) {
45
+ objShallowCopy = addAnnotationProp(
46
+ objShallowCopy,
47
+ objShallowCopy[prop],
48
+ ESCAPE_CHAR + prop,
49
+ );
50
+ delete objShallowCopy[prop];
51
+ }
52
+
53
+ objShallowCopy[prop] = type;
54
+ return objShallowCopy;
55
+ }
56
+
57
+ export function deleteAnnotationProp(obj: Record<string, unknown>): void {
58
+ let escapedProp = RESERVED_TYPE_PROPERTY_NAME;
59
+
60
+ while (Object.prototype.hasOwnProperty.call(obj, escapedProp)) {
61
+ // On the first loop since `escapedProp` is not actually escaped, this
62
+ // line does nothing. In the next loops we only want to replace the
63
+ // first instance of the escape char.
64
+ obj[escapedProp.replace(ESCAPE_CHAR, '')] = obj[escapedProp];
65
+
66
+ delete obj[escapedProp];
67
+ escapedProp = ESCAPE_CHAR + escapedProp;
68
+ }
69
+ }
70
+
71
+ function copyAndAnnotate(
72
+ obj: Exclude<Neo4jType | QueryResult, undefined | null | Neo4jType[]>,
73
+ ): Record<string, unknown> {
74
+ return Object.keys(obj).reduce<Record<string, unknown>>((newObj, key) => {
75
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
76
+ // @ts-ignore TypeScript complains about not being able to use `key` to
77
+ // index `obj`, but we know that `key` exists in `obj` since it's coming
78
+ // from Object.keys.
79
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
80
+ const value = obj[key] as unknown as Neo4jType;
81
+
82
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
83
+ newObj[key] = serializeTypeAnnotations(value);
84
+ return newObj;
85
+ }, {});
86
+ }
87
+
88
+ export function serializeTypeAnnotations(
89
+ item: QueryResult | Neo4jRecord,
90
+ ): Record<string, unknown>;
91
+ export function serializeTypeAnnotations(
92
+ item: Neo4jType,
93
+ ): Record<string, unknown> | null | undefined | unknown[];
94
+ export function serializeTypeAnnotations(
95
+ item: Neo4jType | QueryResult | Neo4jRecord,
96
+ ): Record<string, unknown> | null | undefined | unknown[] {
97
+ if (Array.isArray(item)) {
98
+ return item.map((i) => serializeTypeAnnotations(i));
99
+ }
100
+ if (item === null || item === undefined) {
101
+ return item;
102
+ }
103
+
104
+ if (item instanceof types.Record) {
105
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
106
+ // @ts-ignore There are two versions of the type for Record coming from the
107
+ // driver.
108
+ const tmp = copyAndAnnotate(item);
109
+ return addAnnotationProp(tmp, 'Record');
110
+ }
111
+ if (item instanceof types.ResultSummary) {
112
+ const tmp = copyAndAnnotate(item);
113
+ return addAnnotationProp(tmp, 'ResultSummary');
114
+ }
115
+ if (item instanceof types.Node) {
116
+ const tmp = copyAndAnnotate(item);
117
+ return addAnnotationProp(tmp, 'Node');
118
+ }
119
+ if (item instanceof types.PathSegment) {
120
+ const tmp = copyAndAnnotate(item);
121
+ return addAnnotationProp(tmp, 'PathSegment');
122
+ }
123
+ if (item instanceof types.Path) {
124
+ const tmp = copyAndAnnotate(item);
125
+ return addAnnotationProp(tmp, 'Path');
126
+ }
127
+ if (item instanceof types.Relationship) {
128
+ const tmp = copyAndAnnotate(item);
129
+ return addAnnotationProp(tmp, 'Relationship');
130
+ }
131
+ if (item instanceof types.Point) {
132
+ const tmp = copyAndAnnotate(item);
133
+ return addAnnotationProp(tmp, 'Point');
134
+ }
135
+ if (item instanceof types.Date) {
136
+ const tmp = copyAndAnnotate(item);
137
+ return addAnnotationProp(tmp, 'Date');
138
+ }
139
+ if (item instanceof types.DateTime) {
140
+ const tmp = copyAndAnnotate(item);
141
+ return addAnnotationProp(tmp, 'DateTime');
142
+ }
143
+ if (item instanceof types.Duration) {
144
+ const tmp = copyAndAnnotate(item);
145
+ return addAnnotationProp(tmp, 'Duration');
146
+ }
147
+ if (item instanceof types.LocalDateTime) {
148
+ const tmp = copyAndAnnotate(item);
149
+ return addAnnotationProp(tmp, 'LocalDateTime');
150
+ }
151
+ if (item instanceof types.LocalTime) {
152
+ const tmp = copyAndAnnotate(item);
153
+ return addAnnotationProp(tmp, 'LocalTime');
154
+ }
155
+ if (item instanceof types.Time) {
156
+ const tmp = copyAndAnnotate(item);
157
+ return addAnnotationProp(tmp, 'Time');
158
+ }
159
+ if (isInt(item)) {
160
+ const tmp = { ...item };
161
+ return addAnnotationProp(tmp, 'Integer');
162
+ }
163
+ if (typeof item === 'object') {
164
+ const tmp = copyAndAnnotate(item);
165
+ return addAnnotationProp(tmp, 'Object');
166
+ }
167
+
168
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
169
+ // @ts-ignore this type isn't inferred correctly
170
+ return item;
171
+ }
172
+
173
+ /* eslint-disable @typescript-eslint/no-explicit-any,
174
+ @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access,
175
+ @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment,
176
+ no-underscore-dangle, @typescript-eslint/no-redundant-type-constituents
177
+ */
178
+
179
+ export function deserializeTypeAnnotations(
180
+ rawItem: Record<string, unknown>,
181
+ ): QueryResult | Neo4jRecord;
182
+ export function deserializeTypeAnnotations(rawItem: any): any;
183
+ export function deserializeTypeAnnotations(
184
+ rawItem: Record<string, unknown> | any,
185
+ ): QueryResult | any {
186
+ if (Array.isArray(rawItem)) {
187
+ const mapped = rawItem.map((i) => deserializeTypeAnnotations(i));
188
+ return mapped;
189
+ }
190
+
191
+ if (
192
+ rawItem === null ||
193
+ rawItem === undefined ||
194
+ typeof rawItem === 'boolean' ||
195
+ typeof rawItem === 'string' ||
196
+ !Object.prototype.hasOwnProperty.call(rawItem, RESERVED_TYPE_PROPERTY_NAME)
197
+ ) {
198
+ return rawItem;
199
+ }
200
+
201
+ const item = { ...rawItem };
202
+ const className = item[RESERVED_TYPE_PROPERTY_NAME];
203
+ deleteAnnotationProp(item);
204
+
205
+ switch (className) {
206
+ case 'Record':
207
+ return new types.Record(
208
+ deserializeTypeAnnotations(item.keys),
209
+ deserializeTypeAnnotations(item._fields),
210
+ deserializeTypeAnnotations(item._fieldLookup),
211
+ );
212
+ case 'ResultSummary': {
213
+ const metadata = {
214
+ ...item,
215
+ type: item.queryType,
216
+ db: item.database.name,
217
+
218
+ result_available_after: deserializeTypeAnnotations(
219
+ item.resultAvailableAfter,
220
+ ),
221
+ result_consumed_after: deserializeTypeAnnotations(
222
+ item.resultConsumedAfter,
223
+ ),
224
+
225
+ profile: item.profile === false ? null : item.profile,
226
+ plan: item.plan === false ? null : item.plan,
227
+
228
+ stream_summary: { have_records_streamed: true },
229
+
230
+ server: {
231
+ ...item.server,
232
+ version: item.server.agent,
233
+ },
234
+ };
235
+
236
+ return new types.ResultSummary(
237
+ deserializeTypeAnnotations(item.query.text),
238
+ deserializeTypeAnnotations(item.query.parameters),
239
+ deserializeTypeAnnotations(metadata),
240
+ deserializeTypeAnnotations(item.server.protocolVersion),
241
+ );
242
+ }
243
+ case 'Node':
244
+ return new types.Node(
245
+ deserializeTypeAnnotations(item.identity),
246
+ item.labels,
247
+ deserializeTypeAnnotations(item.properties),
248
+ item.elementId,
249
+ );
250
+ case 'Relationship':
251
+ return new types.Relationship(
252
+ deserializeTypeAnnotations(item.identity),
253
+ deserializeTypeAnnotations(item.start),
254
+ deserializeTypeAnnotations(item.end),
255
+ item.type,
256
+ deserializeTypeAnnotations(item.properties),
257
+ item.elementId,
258
+ item.startNodeElementId,
259
+ item.endNodeElementId,
260
+ );
261
+ case 'PathSegment':
262
+ return new types.PathSegment(
263
+ deserializeTypeAnnotations(item.start),
264
+ deserializeTypeAnnotations(item.relationship),
265
+ deserializeTypeAnnotations(item.end),
266
+ );
267
+ case 'Path': {
268
+ const { segments } = item;
269
+
270
+ return new types.Path(
271
+ deserializeTypeAnnotations(item.start),
272
+ deserializeTypeAnnotations(item.end),
273
+ (Array.isArray(segments) ? segments : []).map((x: any) =>
274
+ deserializeTypeAnnotations(x),
275
+ ),
276
+ );
277
+ }
278
+ case 'Point':
279
+ return new types.Point(
280
+ deserializeTypeAnnotations(item.srid),
281
+ deserializeTypeAnnotations(item.x),
282
+ deserializeTypeAnnotations(item.y),
283
+ deserializeTypeAnnotations(item.z),
284
+ );
285
+ case 'Date':
286
+ return new types.Date(
287
+ deserializeTypeAnnotations(item.year),
288
+ deserializeTypeAnnotations(item.month),
289
+ deserializeTypeAnnotations(item.day),
290
+ );
291
+ case 'DateTime':
292
+ return new types.DateTime(
293
+ deserializeTypeAnnotations(item.year),
294
+ deserializeTypeAnnotations(item.month),
295
+ deserializeTypeAnnotations(item.day),
296
+ deserializeTypeAnnotations(item.hour),
297
+ deserializeTypeAnnotations(item.minute),
298
+ deserializeTypeAnnotations(item.second),
299
+ deserializeTypeAnnotations(item.nanosecond),
300
+ deserializeTypeAnnotations(item.timeZoneOffsetSeconds),
301
+ deserializeTypeAnnotations(item.timeZoneId),
302
+ );
303
+ case 'Duration':
304
+ return new types.Duration(
305
+ deserializeTypeAnnotations(item.months),
306
+ deserializeTypeAnnotations(item.days),
307
+ deserializeTypeAnnotations(item.seconds),
308
+ deserializeTypeAnnotations(item.nanoseconds),
309
+ );
310
+ case 'LocalDateTime':
311
+ return new types.LocalDateTime(
312
+ deserializeTypeAnnotations(item.year),
313
+ deserializeTypeAnnotations(item.month),
314
+ deserializeTypeAnnotations(item.day),
315
+ deserializeTypeAnnotations(item.hour),
316
+ deserializeTypeAnnotations(item.minute),
317
+ deserializeTypeAnnotations(item.second),
318
+ deserializeTypeAnnotations(item.nanosecond),
319
+ );
320
+ case 'LocalTime':
321
+ return new types.LocalTime(
322
+ deserializeTypeAnnotations(item.hour),
323
+ deserializeTypeAnnotations(item.minute),
324
+ deserializeTypeAnnotations(item.second),
325
+ deserializeTypeAnnotations(item.nanosecond),
326
+ );
327
+ case 'Time':
328
+ return new types.Time(
329
+ deserializeTypeAnnotations(item.hour),
330
+ deserializeTypeAnnotations(item.minute),
331
+ deserializeTypeAnnotations(item.second),
332
+ deserializeTypeAnnotations(item.nanosecond),
333
+ deserializeTypeAnnotations(item.timeZoneOffsetSeconds),
334
+ );
335
+ case 'Integer':
336
+ return int(item);
337
+ case 'Object':
338
+ return Object.keys(item).reduce<Record<string, unknown>>(
339
+ (newObj, key) => {
340
+ newObj[key] = deserializeTypeAnnotations(item[key]);
341
+ return newObj;
342
+ },
343
+ {},
344
+ );
345
+ default:
346
+ return item;
347
+ }
348
+ }
@@ -0,0 +1,13 @@
1
+ export function cleanType(type: string): string {
2
+ let resultType = type;
3
+
4
+ if (resultType.startsWith('LIST? OF ')) {
5
+ resultType = resultType.replace('LIST? OF ', 'LIST<');
6
+ resultType += '>';
7
+ }
8
+ return resultType.replace(/\?/g, '');
9
+ }
10
+
11
+ export function cleanTypeDescription<T extends { type: string }>(arg: T) {
12
+ return { ...arg, type: cleanType(arg.type) };
13
+ }
@@ -0,0 +1,146 @@
1
+ import {
2
+ isDate,
3
+ isDateTime,
4
+ isDuration,
5
+ isInt,
6
+ isLocalDateTime,
7
+ isLocalTime,
8
+ isNode,
9
+ isPath,
10
+ isPoint,
11
+ isRelationship,
12
+ isTime,
13
+ } from 'neo4j-driver';
14
+
15
+ import type {
16
+ CypherDataType,
17
+ CypherProperty,
18
+ } from '../types/cypher-data-types';
19
+ import {
20
+ isCypherBasicPropertyType,
21
+ isInt8Array,
22
+ } from '../types/cypher-data-types';
23
+
24
+ type CypherPropertyName =
25
+ | 'Float'
26
+ | 'null'
27
+ | 'String'
28
+ | 'Bigint'
29
+ | 'Boolean'
30
+ | `List${string}`
31
+ | 'LocalTime'
32
+ | 'Time'
33
+ | 'Date'
34
+ | 'LocalDateTime'
35
+ | 'DateTime'
36
+ | 'Integer'
37
+ | 'Duration'
38
+ | 'Point'
39
+ | 'ByteArray'
40
+ | 'Unknown';
41
+
42
+ const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
43
+
44
+ export const getPropertyTypeDisplayName = (
45
+ val?: CypherProperty,
46
+ ): CypherPropertyName => {
47
+ const jsType = typeof val;
48
+ if (jsType === 'number') {
49
+ return 'Float';
50
+ }
51
+
52
+ if (val === null || val === undefined) {
53
+ /* There's no concept of undefined in cypher, null serves both purposes */
54
+ return 'null';
55
+ }
56
+
57
+ // Need to duplicate this `typeof` for typescripts type inference to understand
58
+ if (typeof val !== 'object') {
59
+ const capitalized = capitalize(jsType);
60
+
61
+ switch (capitalized) {
62
+ case 'String':
63
+ case 'Bigint':
64
+ case 'Boolean':
65
+ return capitalized;
66
+ default:
67
+ return 'Unknown';
68
+ }
69
+ }
70
+
71
+ if (val instanceof Array) {
72
+ const [firstVal] = val;
73
+ if (firstVal !== undefined) {
74
+ // Lists in properties are only allowed to contain a single type so all items are the same type
75
+ return `List<${getPropertyTypeDisplayName(firstVal)}>(${val.length})`;
76
+ }
77
+ return `List(${val.length})`;
78
+ }
79
+
80
+ if (isLocalTime(val)) {
81
+ return 'LocalTime';
82
+ }
83
+
84
+ if (isTime(val)) {
85
+ return 'Time';
86
+ }
87
+
88
+ if (isDate(val)) {
89
+ return 'Date';
90
+ }
91
+
92
+ if (isLocalDateTime(val)) {
93
+ return 'LocalDateTime';
94
+ }
95
+
96
+ if (isDateTime(val)) {
97
+ return 'DateTime';
98
+ }
99
+
100
+ if (isInt(val)) {
101
+ return 'Integer';
102
+ }
103
+
104
+ if (isDuration(val)) {
105
+ return 'Duration';
106
+ }
107
+
108
+ if (isPoint(val)) {
109
+ return 'Point';
110
+ }
111
+
112
+ if (isInt8Array(val)) {
113
+ return 'ByteArray';
114
+ }
115
+
116
+ return 'Unknown';
117
+ };
118
+
119
+ export type CypherDataTypeName =
120
+ | CypherPropertyName
121
+ | 'Node'
122
+ | 'Relationship'
123
+ | 'Path'
124
+ | 'Map';
125
+ export function getCypherTypeName(val?: CypherDataType): CypherDataTypeName {
126
+ if (Array.isArray(val)) {
127
+ return 'List';
128
+ }
129
+
130
+ if (isCypherBasicPropertyType(val)) {
131
+ return getPropertyTypeDisplayName(val);
132
+ }
133
+ if (isNode(val)) {
134
+ return 'Node';
135
+ }
136
+
137
+ if (isRelationship(val)) {
138
+ return 'Relationship';
139
+ }
140
+
141
+ if (isPath(val)) {
142
+ return 'Path';
143
+ }
144
+
145
+ return 'Map';
146
+ }
@@ -0,0 +1,9 @@
1
+ export const formatFloat = (anything: number) => {
2
+ if ([Infinity, -Infinity, NaN].includes(anything)) {
3
+ return `${anything}`;
4
+ }
5
+ if (Math.floor(anything) === anything) {
6
+ return `${anything}.0`;
7
+ }
8
+ return anything.toString();
9
+ };