|
| 1 | +import { objectToCypher, objectMemberBitIntToNumber } from './cypher-native-binders.js' |
| 2 | + |
| 3 | +function mapPlan(plan) { |
| 4 | + return { |
| 5 | + operatorType: plan.operatorType, |
| 6 | + args: plan.arguments, |
| 7 | + identifiers: plan.identifiers, |
| 8 | + children: plan.children ? plan.children.map(mapPlan) : undefined |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +function mapCounters(stats) { |
| 13 | + return { |
| 14 | + ...stats._stats, |
| 15 | + systemUpdates: stats.systemUpdates(), |
| 16 | + containsUpdates: stats.containsUpdates(), |
| 17 | + containsSystemUpdates: stats.containsSystemUpdates() |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +function mapProfile(profile, child=false) { |
| 22 | + const mapChild = (child) => mapProfile(child, true) |
| 23 | + const obj = { |
| 24 | + args: objectMemberBitIntToNumber(profile.arguments), |
| 25 | + dbHits: Number(profile.dbHits), |
| 26 | + identifiers: profile.identifiers, |
| 27 | + operatorType: profile.operatorType, |
| 28 | + rows: Number(profile.rows), |
| 29 | + children: profile.children ? profile.children.map(mapChild) : undefined |
| 30 | + } |
| 31 | + |
| 32 | + if (child) { |
| 33 | + return { |
| 34 | + ...obj, |
| 35 | + pageCacheHitRatio: profile.pageCacheHitRatio !== undefined ? Number(profile.pageCacheHitRatio) : undefined, |
| 36 | + pageCacheHits: profile.pageCacheHits !== undefined ? Number(profile.pageCacheHits) : undefined, |
| 37 | + pageCacheMisses: profile.pageCacheMisses !== undefined ? Number(profile.pageCacheMisses) : undefined, |
| 38 | + time: profile.time !== undefined ? Number(profile.time) : undefined, |
| 39 | + } |
| 40 | + } |
| 41 | + return obj |
| 42 | +} |
| 43 | + |
| 44 | +function mapNotification(notification) { |
| 45 | + return { |
| 46 | + ...notification, |
| 47 | + position: Object.keys(notification.position).length !== 0 ? notification.position : undefined, |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +export function nativeToTestkitSummary (summary) { |
| 52 | + return { |
| 53 | + ...objectMemberBitIntToNumber(summary), |
| 54 | + database: summary.database.name, |
| 55 | + query: { |
| 56 | + text: summary.query.text, |
| 57 | + parameters: objectToCypher(summary.query.parameters) |
| 58 | + }, |
| 59 | + serverInfo: { |
| 60 | + agent: summary.server.agent, |
| 61 | + protocolVersion: summary.server.protocolVersion.toFixed(1) |
| 62 | + }, |
| 63 | + counters: mapCounters(summary.counters), |
| 64 | + plan: mapPlan(summary.plan), |
| 65 | + profile: mapProfile(summary.profile), |
| 66 | + notifications: summary.notifications.map(mapNotification) |
| 67 | + } |
| 68 | +} |
0 commit comments