Created
August 5, 2019 14:49
-
-
Save pmuellr/7607e1a1a64edeecfda30c0b97f2d5ca to your computer and use it in GitHub Desktop.
initial pass on an AuditLog interface
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
/* | |
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | |
* or more contributor license agreements. Licensed under the Elastic License; | |
* you may not use this file except in compliance with the Elastic License. | |
*/ | |
type IAuditRecord = Record<string, any>; | |
interface IAuditLog { | |
initialize(): Promise<void>; | |
log(record: IAuditRecord): Promise<void>; | |
} | |
interface ICreateAuditLogOptions { | |
index: string; | |
} | |
export function create(options: ICreateAuditLogOptions): IAuditLog { | |
return new AuditLog(options); | |
} | |
class AuditLog implements IAuditLog { | |
private _index: string; | |
private _initialized = false; | |
constructor(options: ICreateAuditLogOptions) { | |
this._index = options.index; | |
} | |
async log(record: IAuditRecord) { | |
if (!this._initialized) throw new Error(`audit log ${this._index} not initialized`); | |
console.log('woulda written to index', this._index, { record }); | |
} | |
async initialize(): Promise<void> { | |
this._initialized = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment