From cfa9e2a200576d4284a7770b9d7ca6ba7b507add Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 2 Apr 2026 12:49:18 -0700 Subject: [PATCH] fix: make LevelDocument._id and _documentType required These properties are always present after document creation. Update PluginDevice constructor to require id parameter. --- server/src/db-types.ts | 6 +++--- server/src/level.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/db-types.ts b/server/src/db-types.ts index d79d83480..aa29fba00 100644 --- a/server/src/db-types.ts +++ b/server/src/db-types.ts @@ -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; } diff --git a/server/src/level.ts b/server/src/level.ts index f19a06784..1862d276c 100644 --- a/server/src/level.ts +++ b/server/src/level.ts @@ -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 { @@ -20,7 +20,7 @@ export class WrappedLevel extends Level { override async open(): Promise; override async open(options?: OpenOptions): Promise { - 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 { 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 { 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; };