Skip to main content

Class: ImportDataCommand

Defined in: electron/services/commands/DatabaseCommands.ts:523

Command for importing app data from JSON.

Remarks​

Encapsulates the logic for importing data, updating the cache, and emitting success events. The persistence transaction is the commit boundary: pre-commit failures may restore the previous cache, while post-commit cache and event synchronization failures are logged without reporting the durable import as failed. Validation checks for non-empty JSON plus schema compliance via the shared import/export Zod schemas.

Hierarchy​

View Summary

Extends​

Constructors​

Constructor​

new ImportDataCommand(
serviceFactory: DatabaseCommandServiceFactory,
eventEmitter: TypedEventBus<UptimeEvents>,
cache: StandardizedCache<Site>,
data: string): ImportDataCommand;

Defined in: electron/services/commands/DatabaseCommands.ts:811

Parameters​

serviceFactory​

DatabaseCommandServiceFactory

eventEmitter​

TypedEventBus<UptimeEvents>

cache​

StandardizedCache<Site>

data​

string

Returns​

ImportDataCommand

Overrides​

DatabaseCommand.constructor

Constructor​

new ImportDataCommand(context: DatabaseCommandContext & {
data: string;
}): ImportDataCommand;

Defined in: electron/services/commands/DatabaseCommands.ts:818

Parameters​

context​

DatabaseCommandContext & { data: string; }

Returns​

ImportDataCommand

Overrides​

DatabaseCommand.constructor

Properties​

cache​

protected readonly cache: StandardizedCache<Site>;

Defined in: electron/services/commands/DatabaseCommands.ts:140

Site cache for data synchronization during operations

Inherited from​

DatabaseCommand.cache


eventEmitter​

protected readonly eventEmitter: TypedEventBus<UptimeEvents>;

Defined in: electron/services/commands/DatabaseCommands.ts:143

Event bus for emitting command execution events

Inherited from​

DatabaseCommand.eventEmitter


serviceFactory​

protected readonly serviceFactory: DatabaseCommandServiceFactory;

Defined in: electron/services/commands/DatabaseCommands.ts:146

Factory for accessing database services and repositories

Inherited from​

DatabaseCommand.serviceFactory


configurationManager​

protected readonly configurationManager:
| ConfigurationManager
| undefined;

Defined in: electron/services/commands/DatabaseCommands.ts:149

Optional configuration manager used for validation flows

Inherited from​

DatabaseCommand.configurationManager


updateHistoryLimit​

protected readonly updateHistoryLimit:
| ((limit: number) => Promise<void>)
| undefined;

Defined in: electron/services/commands/DatabaseCommands.ts:152

Optional history limit updater for settings propagation

Inherited from​

DatabaseCommand.updateHistoryLimit


backupSites​

private backupSites: Site[] = [];

Defined in: electron/services/commands/DatabaseCommands.ts:525

Backup of current sites for rollback functionality


data​

private readonly data: string;

Defined in: electron/services/commands/DatabaseCommands.ts:528

JSON data string to be imported


persistenceCommitted​

private persistenceCommitted: boolean = false;

Defined in: electron/services/commands/DatabaseCommands.ts:531

Whether the destructive import transaction has committed.

Methods​

emitSuccessEvent()​

protected emitSuccessEvent<K>(eventType: K, data: Partial<EventPayload<UptimeEvents, K>>): Promise<void>;

Defined in: electron/services/commands/DatabaseCommands.ts:167

Internal

Emits a success event for the command operation.

Type Parameters​

K​

K extends EventKey<UptimeEvents>

Parameters​

eventType​

K

The event type to emit.

data​

Partial<EventPayload<UptimeEvents, K>>

Additional event data to include in the event payload.

Returns​

Promise<void>

Remarks​

Used internally to emit a typed event indicating command success, including additional event data.

Inherited from​

DatabaseCommand.emitSuccessEvent


execute()​

execute(): Promise<boolean>;

Defined in: electron/services/commands/DatabaseCommands.ts:533

Executes the command operation.

Returns​

Promise<boolean>

Promise resolving to the operation result.

Remarks​

Performs the main database operation encapsulated by the command.

Throws​

When command execution fails.

Overrides​

DatabaseCommand.execute


rollback()​

rollback(): Promise<void>;

Defined in: electron/services/commands/DatabaseCommands.ts:619

Rolls back the command operation if possible.

Returns​

Promise<void>

Promise resolving when rollback is complete.

Remarks​

Attempts to revert the effects of the command. Not all commands require rollback.

Overrides​

DatabaseCommand.rollback


validate()​

validate(): Promise<{
errors: string[];
isValid: boolean;
}>;

Defined in: electron/services/commands/DatabaseCommands.ts:634

Validates the command before execution.

Returns​

Promise<{ errors: string[]; isValid: boolean; }>

Promise resolving to validation result.

Remarks​

Ensures the command is in a valid state before execution. Returns a validation result with errors if any.

Overrides​

DatabaseCommand.validate


applyImportedHistoryLimit()​

private applyImportedHistoryLimit(importedHistoryLimit: number | undefined): Promise<void>;

Defined in: electron/services/commands/DatabaseCommands.ts:680

Parameters​

importedHistoryLimit​

number | undefined

Returns​

Promise<void>


parseImportedHistoryLimit()​

private parseImportedHistoryLimit(settings: Record<string, string>): number | undefined;

Defined in: electron/services/commands/DatabaseCommands.ts:700

Parameters​

settings​

Record<string, string>

Returns​

number | undefined


refreshCacheAfterCommit()​

private refreshCacheAfterCommit(): Promise<Site[]>;

Defined in: electron/services/commands/DatabaseCommands.ts:719

Returns​

Promise<Site[]>


validateImportedSites()​

private validateImportedSites(sites: ImportSite[]): Promise<Site[]>;

Defined in: electron/services/commands/DatabaseCommands.ts:752

Parameters​

sites​

ImportSite[]

Returns​

Promise<Site[]>


getDescription()​

getDescription(): string;

Defined in: electron/services/commands/DatabaseCommands.ts:850

Gets a description of the command for logging and debugging.

Returns​

string

Human-readable command description.

Overrides​

DatabaseCommand.getDescription


toCanonicalSite()​

private toCanonicalSite(site: ImportSite): Site;

Defined in: electron/services/commands/DatabaseCommands.ts:854

Parameters​

site​

ImportSite

Returns​

Site