mirror of
https://github.com/koush/scrypted.git
synced 2026-05-05 22:00:27 +01:00
fix: make LevelDocument._id and _documentType required
These properties are always present after document creation. Update PluginDevice constructor to require id parameter.
This commit is contained in:
@@ -2,8 +2,8 @@ import { LevelDocument } from "./level";
|
||||
import { ScryptedNativeId, SystemDeviceState } from "@scrypted/types";
|
||||
|
||||
export class ScryptedDocument implements LevelDocument {
|
||||
_id?: string;
|
||||
_documentType?: string;
|
||||
_id: string;
|
||||
_documentType: string;
|
||||
}
|
||||
|
||||
export class Settings extends ScryptedDocument {
|
||||
@@ -31,7 +31,7 @@ export class ScryptedAlert extends ScryptedDocument {
|
||||
}
|
||||
|
||||
export class PluginDevice extends ScryptedDocument {
|
||||
constructor(id?: string) {
|
||||
constructor(id: string) {
|
||||
super();
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { GetOptions, Level, OpenOptions, PutOptions } from 'level';
|
||||
|
||||
export interface LevelDocument {
|
||||
_id?: any;
|
||||
_documentType?: string;
|
||||
_id: any;
|
||||
_documentType: string;
|
||||
}
|
||||
|
||||
export interface LevelDocumentConstructor<T extends LevelDocument> {
|
||||
@@ -20,7 +20,7 @@ export class WrappedLevel extends Level<string, string | number> {
|
||||
|
||||
override async open(): Promise<void>;
|
||||
override async open(options?: OpenOptions): Promise<void> {
|
||||
await super.open(options);
|
||||
await super.open(options!);
|
||||
try {
|
||||
this.curId = parseInt(await this.get('_id') as string);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ export class WrappedLevel extends Level<string, string | number> {
|
||||
try {
|
||||
const _documentType = documentConstructor.name;
|
||||
const key = `${_documentType}/${_id}`;
|
||||
const json = await this.get(key, options)
|
||||
const json = await this.get(key, options!)
|
||||
return createLevelDocument(documentConstructor, json);
|
||||
}
|
||||
catch (e) {
|
||||
@@ -83,7 +83,7 @@ export class WrappedLevel extends Level<string, string | number> {
|
||||
|
||||
value._documentType = _documentType;
|
||||
const key = `${_documentType}/${value._id}`;
|
||||
await this.put(key, JSON.stringify(value), options);
|
||||
await this.put(key, JSON.stringify(value), options!);
|
||||
return value;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user