init
This commit is contained in:
24
lib/.eslintrc.js
Normal file
24
lib/.eslintrc.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||
* This file is part of Snippeteer which is released under BSD-3-Clause.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@scode/eslint-config-ts'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
10
lib/ControlModel.ts
Normal file
10
lib/ControlModel.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export abstract class ControlModel {
|
||||
public abstract get object(): Record<string, unknown>;
|
||||
public abstract set object(obj: Record<string, unknown>);
|
||||
|
||||
public update (): void {
|
||||
this.verify ();
|
||||
}
|
||||
|
||||
public abstract verify(): void;
|
||||
}
|
25
lib/DatabaseModel.ts
Normal file
25
lib/DatabaseModel.ts
Normal file
@ -0,0 +1,25 @@
|
||||
export abstract class DatabaseModel {
|
||||
protected id?: number;
|
||||
|
||||
public static async get<T extends DatabaseModel> (
|
||||
id: number,
|
||||
constructor: new () => T
|
||||
): Promise<T> {
|
||||
const dbm = (new constructor);
|
||||
dbm.id = id;
|
||||
await dbm.read ();
|
||||
return dbm;
|
||||
}
|
||||
|
||||
public get object (): Record<string, number | string | undefined> {
|
||||
const obj = { id: this.id };
|
||||
return obj;
|
||||
}
|
||||
|
||||
public set object (obj: Record<string, number | string | undefined>) {
|
||||
this.id = obj.id as number | undefined;
|
||||
}
|
||||
|
||||
public abstract read(): Promise<void>;
|
||||
public abstract write(): Promise<void>;
|
||||
}
|
2
lib/index.ts
Normal file
2
lib/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { ControlModel } from './ControlModel';
|
||||
export { DatabaseModel } from './DatabaseModel';
|
Reference in New Issue
Block a user