Skip to main content

PersistenceService

The PersistenceService is responsible for storing data on the server, either in memory or as a file. It is primarily used to enhance mocking capabilities, allowing for the addition and removal of mock entries.

import { Inject, PersistenceService } from '@archibald/server';

In order to use the Persistence service, you need to inject it by using the Inject decorator function.

@Inject()
private readonly persistenceService: PersistenceService<T>;

get

Retrieves a persisted entry based on the provided key.

const data = await this.persistenceService.get('key');

Parameters

NameTypeDescriptionDefault
keystringThe key identifying the entry.

getAll

Retrieves all persisted entries.

const data = await this.persistenceService.getAll();

set

Persists a new entry or updates an existing one.

this.persistenceService.set('key', value, options);

Parameters

NameTypeDescriptionDefault
keystringThe key identifying the entry.
valueTThe data to be persisted.
optionsSetOptionsOptional parameters (see below).

delete

This method deletes a persisted entry

this.persistenceService.delete('key', options);

Parameters

NameTypeDescriptionDefault
keystringThe key identifying the entry.
optionsSetOptionsOptional parameters (see below).

SetOptions

NameTypeDescriptionDefault
trybooleanOnly sets a value if the key does not already exist.
forcebooleanPersists the value immediately without applying debouncing.