Skip to content

Commit 676b28a

Browse files
keeganirbykaranA-aws
authored andcommitted
refactor(cwl): change LiveTailRegistry to standard map aws#5789
## Problem The nestedMap implementation of the registry was forcing a defined Default item. This doesn't fit the usecase I am aiming to provide by this registry. There is no default object to be returned. If an item doesn't exist in the registry, we should handle an undefined object, and not a placeholder. In other words, there is no concept of a placeholder/default value for a LiveTailSession. Additionally, `set` on the NestedMap would perform a deep merge. I am wanting to replace the object. Originally I defined the default object to an exception, but the NestedMap `set` operation calls `get`. And if there isn't already a value in the map, it would throw the exception defined as the default object. This means we could never add any item to the map. ## Solution Swap the underlying implementation of the registry to a basic Map. I am still defining a `LiveTailSessionRegistry` class so we can statically initialize a registry singleton, as well as leaving the possibility open to override or extend the `Map` class. Also so we can pass around the type `LiveTailSessionRegistry` instead of `Map<Foo, Bar>`.
1 parent 7a8eb52 commit 676b28a

File tree

2 files changed

+3
-61
lines changed

2 files changed

+3
-61
lines changed

packages/core/src/awsService/cloudWatchLogs/registry/liveTailSessionRegistry.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import * as vscode from 'vscode'
66
import { CLOUDWATCH_LOGS_LIVETAIL_SCHEME } from '../../../shared/constants'
77
import { LiveTailSession, LiveTailSessionConfiguration } from './liveTailSession'
8-
import { ToolkitError } from '../../../shared'
9-
import { NestedMap } from '../../../shared/utilities/map'
108

11-
export class LiveTailSessionRegistry extends NestedMap<vscode.Uri, LiveTailSession> {
9+
export class LiveTailSessionRegistry extends Map<vscode.Uri, LiveTailSession> {
1210
static #instance: LiveTailSessionRegistry
1311

1412
public static get instance() {
@@ -18,18 +16,6 @@ export class LiveTailSessionRegistry extends NestedMap<vscode.Uri, LiveTailSessi
1816
public constructor() {
1917
super()
2018
}
21-
22-
protected override hash(uri: vscode.Uri): string {
23-
return uri.toString()
24-
}
25-
26-
protected override get name(): string {
27-
return LiveTailSessionRegistry.name
28-
}
29-
30-
protected override get default(): LiveTailSession {
31-
throw new ToolkitError('No LiveTailSession found for provided uri.')
32-
}
3319
}
3420

3521
export function createLiveTailURIFromArgs(sessionData: LiveTailSessionConfiguration): vscode.Uri {

packages/core/src/test/awsService/cloudWatchLogs/registry/liveTailRegistry.test.ts

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,10 @@
44
*/
55
import * as vscode from 'vscode'
66
import assert from 'assert'
7-
import {
8-
LiveTailSession,
9-
LiveTailSessionConfiguration,
10-
} from '../../../../awsService/cloudWatchLogs/registry/liveTailSession'
11-
import {
12-
createLiveTailURIFromArgs,
13-
LiveTailSessionRegistry,
14-
} from '../../../../awsService/cloudWatchLogs/registry/liveTailSessionRegistry'
7+
import { LiveTailSessionConfiguration } from '../../../../awsService/cloudWatchLogs/registry/liveTailSession'
8+
import { createLiveTailURIFromArgs } from '../../../../awsService/cloudWatchLogs/registry/liveTailSessionRegistry'
159
import { CLOUDWATCH_LOGS_LIVETAIL_SCHEME } from '../../../../shared/constants'
1610

17-
/**
18-
* Exposes protected methods so we can test them
19-
*/
20-
class TestLiveTailSessionRegistry extends LiveTailSessionRegistry {
21-
constructor() {
22-
super()
23-
}
24-
25-
override hash(uri: vscode.Uri): string {
26-
return super.hash(uri)
27-
}
28-
29-
override get default(): LiveTailSession {
30-
return super.default
31-
}
32-
}
33-
34-
describe('LiveTailRegistry', async function () {
35-
const session = new LiveTailSession({
36-
logGroupName: 'test-log-group',
37-
region: 'test-region',
38-
})
39-
40-
let liveTailSessionRegistry: TestLiveTailSessionRegistry
41-
42-
beforeEach(function () {
43-
liveTailSessionRegistry = new TestLiveTailSessionRegistry()
44-
})
45-
46-
it('hash()', function () {
47-
assert.deepStrictEqual(liveTailSessionRegistry.hash(session.uri), session.uri.toString())
48-
})
49-
50-
it('default()', function () {
51-
assert.throws(() => liveTailSessionRegistry.default)
52-
})
53-
})
54-
5511
describe('LiveTailSession URI', async function () {
5612
const testLogGroupName = 'test-log-group'
5713
const testRegion = 'test-region'

0 commit comments

Comments
 (0)