Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/shared/modules/commands/helpers/lambdas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {

import bolt from '../../../services/bolt/bolt'
import { recursivelyTypeGraphItems } from '../../../services/bolt/boltMappings'
import { userDirectTxMetadata } from '../../../services/bolt/txMetadata'
import arrayHasItems from '../../../utils/array-has-items'

const FAT_ARROW = '=>'
Expand Down Expand Up @@ -83,7 +84,8 @@ export async function collectLambdaValues(
{},
{
requestId,
cancelable: false
cancelable: false,
...userDirectTxMetadata
}
)

Expand Down
21 changes: 16 additions & 5 deletions src/shared/modules/cypher/cypherDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import {
import { getCausalClusterAddresses } from './queriesProcedureHelper'
import bolt from 'services/bolt/bolt'
import { buildTxFunctionByMode } from 'services/bolt/boltHelpers'
import { getUserTxMetadata } from 'services/bolt/txMetadata'
import {
getUserTxMetadata,
userActionTxMetadata
} from 'services/bolt/txMetadata'
import { flatten } from 'services/utils'
import {
Connection,
Expand All @@ -53,6 +56,7 @@ const queryAndResolve = async (
driver: any,
action: any,
host: any,
metadata: { type: string; app: string },
useDb = {}
) => {
return new Promise(resolve => {
Expand All @@ -62,7 +66,7 @@ const queryAndResolve = async (
})
const txFn = buildTxFunctionByMode(session)
txFn &&
txFn((tx: any) => tx.run(action.query, action.parameters))
txFn((tx: any) => tx.run(action.query, action.parameters), { metadata })
.then((r: any) => {
session.close()
resolve({
Expand Down Expand Up @@ -90,7 +94,12 @@ const callClusterMember = async (connection: any, action: any) => {
bolt
.directConnect(connection, undefined, undefined, false) // Ignore validation errors
.then(async driver => {
const res = await queryAndResolve(driver, action, connection.host)
const res = await queryAndResolve(
driver,
action,
connection.host,
userActionTxMetadata.txMetadata
)
driver.close()
resolve(res)
})
Expand Down Expand Up @@ -168,7 +177,7 @@ export const clusterCypherRequestEpic = (some$: any, store: any) =>
.mergeMap((action: any) => {
if (!action.$$responseChannel) return Rx.Observable.of(null)
return bolt
.directTransaction(getCausalClusterAddresses, {})
.directTransaction(getCausalClusterAddresses, {}, userActionTxMetadata)
.then((res: any) => {
const addresses = flatten(
res.records.map((record: any) => record.get('addresses'))
Expand Down Expand Up @@ -258,7 +267,8 @@ export const handleForcePasswordChangeEpic = (some$: any, store: any) =>
const versionRes: any = await queryAndResolve(
driver,
{ ...action, query: serverInfoQuery, parameters: {} },
undefined
undefined,
userActionTxMetadata.txMetadata
)
// What does the driver say, does the server support multidb?
const supportsMultiDb = await driver.supportsMultiDb()
Expand Down Expand Up @@ -289,6 +299,7 @@ export const handleForcePasswordChangeEpic = (some$: any, store: any) =>
driver,
{ ...action, ...queryObj },
undefined,
userActionTxMetadata.txMetadata,
driverDatabaseSelection(store.getState(), 'system') // target system db if it has multi-db support
)
driver.close()
Expand Down
7 changes: 4 additions & 3 deletions src/shared/services/bolt/boltConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from './globalDrivers'
import { buildTxFunctionByMode } from 'services/bolt/boltHelpers'
import { Connection } from 'shared/modules/connections/connectionsDuck'
import { backgroundTxMetadata } from './txMetadata'

export const DIRECT_CONNECTION = 'DIRECT_CONNECTION'
export const ROUTED_WRITE_CONNECTION = 'ROUTED_WRITE_CONNECTION'
Expand Down Expand Up @@ -68,9 +69,9 @@ export const validateConnection = (
})
const txFn = buildTxFunctionByMode(session)
txFn &&
txFn((tx: { run: (query: string) => void }) =>
tx.run('CALL db.indexes()')
)
txFn(tx => tx.run('CALL db.indexes()'), {
metadata: backgroundTxMetadata.txMetadata
})
.then(() => {
session.close()
res(driver)
Expand Down
6 changes: 3 additions & 3 deletions src/shared/services/bolt/boltHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('buildTxFunctionByMode', () => {

// When
const txFn = buildTxFunctionByMode(fakeSession)
txFn()
txFn!(() => {})

// Then
expect(fakeSession.readTransaction).toHaveBeenCalledTimes(0)
Expand All @@ -49,7 +49,7 @@ describe('buildTxFunctionByMode', () => {

// When
const txFn = buildTxFunctionByMode(fakeSession)
txFn()
txFn!(() => {})

// Then
expect(fakeSession.readTransaction).toHaveBeenCalledTimes(1)
Expand All @@ -64,7 +64,7 @@ describe('buildTxFunctionByMode', () => {

// When
const txFn = buildTxFunctionByMode(fakeSession)
txFn()
txFn!(() => {})

// Then
expect(fakeSession.readTransaction).toHaveBeenCalledTimes(0)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/services/bolt/boltHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const isConfigValTruthy = (val: boolean | string | number): boolean =>
export const isConfigValFalsy = (val: boolean | string | number): boolean =>
[false, 'false', 'no', 0, '0'].indexOf(val) > -1

export const buildTxFunctionByMode = (session?: Session): any => {
export const buildTxFunctionByMode = (session?: Session) => {
if (!session) {
return null
}
Expand Down
9 changes: 5 additions & 4 deletions src/shared/services/bolt/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { v4 } from 'uuid'
import { BoltConnectionError } from '../exceptions'
import { buildTxFunctionByMode } from './boltHelpers'
import { getGlobalDrivers } from './globalDrivers'
import { defaultTxMetadata } from './txMetadata'

const runningQueryRegister: Record<string, (cb?: () => void) => void> = {}

Expand All @@ -31,7 +32,7 @@ function _trackedTransaction(
parameters = {},
session?: Session,
requestId = null,
txMetadata = undefined,
txMetadata = defaultTxMetadata.txMetadata,
autoCommit = false
): [string, Promise<unknown>] {
const id = requestId || v4()
Expand Down Expand Up @@ -63,7 +64,7 @@ function _trackedTransaction(
txFn!(
(tx: { run: (input: string, parameters: unknown) => unknown }) =>
tx.run(input, parameters),
metadata
metadata as any
)
} else {
// Auto-Commit transaction, only used for PERIODIC COMMIT etc.
Expand All @@ -86,14 +87,14 @@ function _transaction(
input: string,
parameters: unknown,
session: any,
txMetadata = undefined
txMetadata = defaultTxMetadata.txMetadata
): Promise<unknown> {
if (!session) return Promise.reject(BoltConnectionError())

const metadata = txMetadata ? { metadata: txMetadata } : undefined
const txFn = buildTxFunctionByMode(session)

return txFn((tx: any) => tx.run(input, parameters), metadata)
return txFn!((tx: any) => tx.run(input, parameters), metadata)
.then((r: any) => {
session.close()
return r
Expand Down
13 changes: 11 additions & 2 deletions src/shared/services/bolt/txMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { version } from 'project-root/package.json'
export const NEO4J_BROWSER_BACKGROUND_QUERY = 'system'
export const NEO4J_BROWSER_USER_QUERY = 'user-direct'
export const NEO4J_BROWSER_USER_ACTION_QUERY = 'user-action'
const UNKOWN_SOURCE = 'no-info'
export const DEFAULT_QUERY_METADATA_TYPE = NEO4J_BROWSER_USER_ACTION_QUERY
export const NEO4J_BROWSER_APP_ID = `neo4j-browser_v${version}`

export const backgroundTxMetadata = {
Expand All @@ -39,8 +39,17 @@ export const userDirectTxMetadata = {
app: NEO4J_BROWSER_APP_ID
}
}
export const userActionTxMetadata = {
txMetadata: {
type: NEO4J_BROWSER_USER_QUERY,
app: NEO4J_BROWSER_APP_ID
}
}
export const defaultTxMetadata = userActionTxMetadata

export const getUserTxMetadata = (type: string = UNKOWN_SOURCE) => ({
export const getUserTxMetadata = (
type: string = DEFAULT_QUERY_METADATA_TYPE
) => ({
txMetadata: {
type,
app: NEO4J_BROWSER_APP_ID
Expand Down