This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Type Error in Ocular Telemeter (#124)
- Loading branch information
1 parent
3131fa2
commit 3c4edce
Showing
3 changed files
with
139 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,73 @@ | ||
import Configstore from "configstore" | ||
import path from "path" | ||
import Configstore from "configstore"; | ||
import path from "path"; | ||
|
||
import InMemoryConfigStore from "./util/in-memory-config" | ||
import isTruthy from "./util/is-truthy" | ||
import OutboxStore from "./util/outbox-store" | ||
import InMemoryConfigStore from "./util/in-memory-config"; | ||
import isTruthy from "./util/is-truthy"; | ||
import OutboxStore from "./util/outbox-store"; | ||
|
||
class Store { | ||
private config_: typeof InMemoryConfigStore; | ||
private outbox_: OutboxStore; | ||
private disabled_: boolean; | ||
|
||
private config_: typeof InMemoryConfigStore | ||
private outbox_: OutboxStore | ||
private disabled_: boolean | ||
|
||
private static instance:Store | ||
private static instance: Store; | ||
|
||
constructor() { | ||
try { | ||
this.config_ = new Configstore(`ocular`, {}, { globalConfigPath: true }) | ||
this.config_ = new Configstore(`ocular`, {}, { globalConfigPath: true }); | ||
} catch (e) { | ||
console.error(e) | ||
console.error(e); | ||
} | ||
|
||
const baseDir = path.dirname(this.config_.path) | ||
this.outbox_ = new OutboxStore(baseDir) | ||
const baseDir = path.dirname(this.config_.path); | ||
this.outbox_ = new OutboxStore(baseDir); | ||
|
||
this.disabled_ = isTruthy(process.env.OCULAR_DISABLE_TELEMETRY) | ||
this.disabled_ = isTruthy(process.env.OCULAR_DISABLE_TELEMETRY); | ||
} | ||
|
||
static getInstance():Store{ | ||
if(!Store.instance){ | ||
Store.instance = new Store() | ||
static getInstance(): Store { | ||
if (!Store.instance) { | ||
Store.instance = new Store(); | ||
} | ||
return Store.instance | ||
return Store.instance; | ||
} | ||
|
||
public getQueueSize() :number{ | ||
return this.outbox_.getSize() | ||
public getQueueSize(): number { | ||
return this.outbox_.getSize(); | ||
} | ||
|
||
public getQueueCount():number { | ||
return this.outbox_.getCount() | ||
public getQueueCount(): number { | ||
return this.outbox_.getCount(); | ||
} | ||
|
||
public addEvent(event):string|null { | ||
public addEvent(event): string | null { | ||
if (this.disabled_) { | ||
return | ||
return; | ||
} | ||
const eventString = JSON.stringify(event) | ||
return this.outbox_.appendToBuffer(eventString + `\n`) | ||
const eventString = JSON.stringify(event); | ||
return this.outbox_.appendToBuffer(eventString + `\n`); | ||
} | ||
|
||
public async flushEvents(handler: (events: any[]) => Promise<boolean>): Promise<boolean> { | ||
return await this.outbox_.startFlushEvents(async (eventData:string) => { | ||
public async flushEvents( | ||
handler: (events: any[]) => Promise<boolean> | ||
): Promise<boolean> { | ||
return await this.outbox_.startFlushEvents(async (eventData: string) => { | ||
const events = eventData | ||
.split(`\n`) | ||
.filter((e) => e && e.length > 2) | ||
.map((e) => JSON.parse(e)) | ||
.map((e) => JSON.parse(e)); | ||
|
||
return await handler(events) | ||
}) | ||
return await handler(events); | ||
}); | ||
} | ||
|
||
public getConfig(path:string) :any{ | ||
return this.config_.get(path) | ||
public getConfig(path: string): any { | ||
return this.config_.get(path); | ||
} | ||
|
||
public setConfig(path:string, val:any) :void{ | ||
return this.config_.set(path, val) | ||
public setConfig(path: string, val: any): void { | ||
return this.config_.set(path, val); | ||
} | ||
} | ||
|
||
export default Store.getInstance() | ||
export default Store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.