Skip to content

Commit 4267f07

Browse files
committed
WIP Node fixes + start of storage refactor
1 parent 26414dd commit 4267f07

File tree

13 files changed

+50
-99
lines changed

13 files changed

+50
-99
lines changed

.vscode/launch.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@
4141
"runtimeArgs": [
4242
"--nolazy"
4343
],
44+
"console": "integratedTerminal",
4445
"sourceMaps": true,
45-
"cwd": "${workspaceRoot}",
46-
},
47-
{
48-
"name": "Attach",
49-
"request": "attach",
50-
"type": "node",
51-
"port": 5858,
52-
"sourceMaps": true,
46+
"cwd": "${workspaceRoot}"
5347
}
5448
]
5549
}

packages/core/src/ExceptionlessClient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export class ExceptionlessClient {
2525
configurationOrApiKey(this.config);
2626
}
2727

28-
this.config.subscribe(() => this.updateSettingsTimer(this._timeoutId > 0 ? 5000 : 0));
2928
this.config.services.queue.onEventsPosted(() => this.updateSettingsTimer());
3029
}
3130

packages/core/src/configuration/Configuration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import { IEnvironmentInfoCollector } from "../services/IEnvironmentInfoCollector
1414
import { IErrorParser } from "../services/IErrorParser.js";
1515
import { IModuleCollector } from "../services/IModuleCollector.js";
1616
import { IRequestInfoCollector } from "../services/IRequestInfoCollector.js";
17-
import { InMemoryStorageProvider } from "../storage/InMemoryStorageProvider.js";
18-
import { IStorageProvider } from "../storage/IStorageProvider.js";
1917
import { ISubmissionClient } from "../submission/ISubmissionClient.js";
2018
import { guid } from "../Utils.js";
2119
import { KnownEventDataKeys } from "../models/Event.js";
20+
import { InMemoryStorage } from "../storage/InMemoryStorage.js";
21+
import { IStorage } from "../storage/IStorage.js";
2222

2323
export class Configuration {
2424
constructor() {
2525
// TODO: Can we make this seamless via setters.
2626
this.services = new Proxy({
2727
lastReferenceIdManager: new DefaultLastReferenceIdManager(),
2828
log: new NullLog(),
29-
storage: new InMemoryStorageProvider(),
29+
storage: new InMemoryStorage(),
3030
queue: new DefaultEventQueue(this)
3131
}, this.subscriberHandler);
3232

@@ -67,7 +67,7 @@ export class Configuration {
6767
moduleCollector?: IModuleCollector,
6868
requestInfoCollector?: IRequestInfoCollector,
6969
submissionClient?: ISubmissionClient,
70-
storage: IStorageProvider,
70+
storage: IStorage,
7171
queue: IEventQueue
7272
};
7373

packages/core/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ export type { IModuleCollector } from "./services/IModuleCollector.js";
5050
export type { IRequestInfoCollector } from "./services/IRequestInfoCollector.js";
5151

5252
export { InMemoryStorage } from "./storage/InMemoryStorage.js";
53-
export { InMemoryStorageProvider } from "./storage/InMemoryStorageProvider.js";
5453
export type { IStorage } from "./storage/IStorage.js";
55-
export type { IStorageItem } from "./storage/IStorageItem.js";
56-
export type { IStorageProvider } from "./storage/IStorageProvider.js";
57-
export { KeyValueStorageBase } from "./storage/KeyValueStorageBase.js";
5854

5955
export type { ISubmissionClient } from "./submission/ISubmissionClient.js";
6056
export { Response } from "./submission/Response.js";

packages/core/src/queue/DefaultEventQueue.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Configuration } from "../configuration/Configuration.js";
22
import { ILog } from "../logging/ILog.js";
33
import { Event } from "../models/Event.js";
44
import { IEventQueue } from "../queue/IEventQueue.js";
5-
import { IStorageItem } from "../storage/IStorageItem.js";
65
import { Response } from "../submission/Response.js";
76

87
export class DefaultEventQueue implements IEventQueue {
@@ -251,7 +250,7 @@ export class DefaultEventQueue implements IEventQueue {
251250
this.suspendProcessing();
252251
}
253252

254-
private removeEvents(events: IStorageItem[]) {
253+
private removeEvents(events: string[]) {
255254
for (let index = 0; index < (events || []).length; index++) {
256255
this.config.services.storage.queue.remove(events[index].timestamp);
257256
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { IStorageItem } from "./IStorageItem.js";
2-
31
export interface IStorage {
4-
save(value: any): number;
5-
get(limit?: number): IStorageItem[];
6-
remove(timestamp: number): void;
7-
clear(): void;
2+
readonly length: Promise<number>;
3+
clear(): Promise<void>;
4+
getItem(key: string): Promise<string | null>;
5+
key(index: number): Promise<string | null>;
6+
removeItem(key: string): Promise<void>;
7+
setItem(key: string, value: string): Promise<void>;
88
}

packages/core/src/storage/IStorageItem.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/core/src/storage/IStorageProvider.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
11
import { IStorage } from "./IStorage.js";
2-
import { IStorageItem } from "./IStorageItem.js";
32

43
export class InMemoryStorage implements IStorage {
5-
private maxItems: number;
6-
private items: IStorageItem[] = [];
7-
private lastTimestamp: number = 0;
4+
private items = new Map<string, string>();
85

9-
constructor(maxItems: number) {
10-
this.maxItems = maxItems;
11-
}
12-
13-
public save(value: any): number {
14-
if (!value) {
15-
return null;
16-
}
6+
constructor(private maxItems: number = 250) { }
177

18-
const items = this.items;
19-
const timestamp = Math.max(Date.now(), this.lastTimestamp + 1);
20-
const item = { timestamp, value };
8+
public get length(): Promise<number> {
9+
return Promise.resolve(this.items.size);
10+
}
2111

22-
if (items.push(item) > this.maxItems) {
23-
items.shift();
24-
}
12+
public clear(): Promise<void> {
13+
this.items.clear();
14+
return Promise.resolve();
15+
}
2516

26-
this.lastTimestamp = timestamp;
27-
return item.timestamp;
17+
public getItem(key: string): Promise<string> {
18+
return Promise.resolve(this.items.get(key));
2819
}
2920

30-
public get(limit?: number): IStorageItem[] {
31-
return this.items.slice(0, limit);
21+
public key(index: number): Promise<string> {
22+
const keys = Array.from(this.items.keys())
23+
return Promise.resolve(keys[index]);
3224
}
3325

34-
public remove(timestamp: number): void {
35-
const items = this.items;
36-
for (let i = 0; i < items.length; i++) {
37-
if (items[i].timestamp === timestamp) {
38-
items.splice(i, 1);
39-
return;
40-
}
41-
}
26+
public removeItem(key: string): Promise<void> {
27+
this.items.delete(key);
28+
return Promise.resolve();
4229
}
4330

44-
public clear(): void {
45-
this.items = [];
31+
public async setItem(key: string, value: string): Promise<void> {
32+
this.items.set(key, value);
33+
while (this.items.size > this.maxItems) {
34+
await this.removeItem(await this.key(0));
35+
}
4636
}
4737
}

packages/core/src/storage/InMemoryStorageProvider.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)