Skip to content

Commit ac0362e

Browse files
committed
Enabling Optimization:ImplicitDefaultArguments
Omiting un-needed query ids optimization was not possible to be implemented in a simple and reliable way, the query id was being wrongly omitted in situation where it was need when the omitting logic was in place.
1 parent 44064f0 commit ac0362e

File tree

4 files changed

+64
-19
lines changed

4 files changed

+64
-19
lines changed

packages/core/src/auth.ts

+20-17
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,28 @@
5858
credentials: string,
5959
realm: string,
6060
scheme: string,
61-
parameters?: string
61+
parameters?: object
6262
) => {
63-
if (parameters) {
64-
return {
65-
scheme: scheme,
66-
principal: principal,
67-
credentials: credentials,
68-
realm: realm,
69-
parameters: parameters
70-
}
71-
} else {
72-
return {
73-
scheme: scheme,
74-
principal: principal,
75-
credentials: credentials,
76-
realm: realm
77-
}
63+
return {
64+
scheme: scheme,
65+
principal: principal,
66+
credentials: emptyAsUndefined(credentials),
67+
realm: emptyAsUndefined(realm),
68+
parameters: emptyAsUndefined(parameters)
7869
}
7970
}
8071
}
8172

82-
export default auth
73+
function emptyAsUndefined<T extends object | string>(value: T | null | undefined): T | undefined {
74+
if (
75+
value === null ||
76+
value === undefined ||
77+
value === '' ||
78+
Object.getPrototypeOf(value) === Object.prototype && Object.keys(value).length === 0
79+
) {
80+
return undefined
81+
}
82+
return value
83+
}
84+
85+
export default auth

packages/core/test/auth.test.ts

+37-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,42 @@ import auth from '../src/auth'
2121
describe('auth', () => {
2222

2323
test('.bearer()', () => {
24-
expect(auth.bearer('==Qyahiadakkda')).toEqual({ scheme: 'bearer', credentials: '==Qyahiadakkda' } )
24+
expect(auth.bearer('==Qyahiadakkda')).toEqual({ scheme: 'bearer', credentials: '==Qyahiadakkda' })
25+
})
26+
27+
test.each([
28+
[
29+
['user', 'pass', 'realm', 'scheme', { param: 'param' }],
30+
{
31+
scheme: 'scheme',
32+
principal: 'user',
33+
credentials: 'pass',
34+
realm: 'realm',
35+
parameters: { param: 'param' }
36+
}
37+
],
38+
[
39+
['user', '', '', 'scheme', {}],
40+
{
41+
scheme: 'scheme',
42+
principal: 'user'
43+
}
44+
],
45+
[
46+
['user', undefined, undefined, 'scheme', undefined],
47+
{
48+
scheme: 'scheme',
49+
principal: 'user'
50+
}
51+
],
52+
[
53+
['user', null, null, 'scheme', null],
54+
{
55+
scheme: 'scheme',
56+
principal: 'user'
57+
}
58+
]
59+
])('.custom()', (args, output) => {
60+
expect(auth.custom.apply(auth, args)).toEqual(output)
2561
})
26-
2762
})

packages/testkit-backend/src/request-handlers.js

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ export function GetFeatures (_context, _params, wire) {
372372
'Feature:Bolt:4.4',
373373
'Feature:API:Result.List',
374374
'Feature:API:Result.Peek',
375+
'Optimization:ImplicitDefaultArguments',
375376
'Temporary:ConnectionAcquisitionTimeout',
376377
'Temporary:CypherPathAndRelationship',
377378
'Temporary:DriverFetchSize',

packages/testkit-backend/src/skipped-tests/common.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import skip, { ifEquals, ifEndsWith, ifStartsWith } from './skip'
22

33
const skippedTests = [
4+
skip(
5+
'Handle qid omission optmization can cause issues in nested queries',
6+
ifEquals('stub.optimizations.test_optimizations.TestOptimizations.test_uses_implicit_default_arguments'),
7+
ifEquals('stub.optimizations.test_optimizations.TestOptimizations.test_uses_implicit_default_arguments_multi_query'),
8+
ifEquals('stub.optimizations.test_optimizations.TestOptimizations.test_uses_implicit_default_arguments_multi_query_nested')
9+
),
410
skip(
511
'Fail while enable Temporary::ResultKeys',
612
ifEquals('neo4j.test_bookmarks.TestBookmarks.test_can_pass_bookmark_into_next_session'),

0 commit comments

Comments
 (0)