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
| Name | Type | Description | Default |
|---|---|---|---|
| key | string | The 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
| Name | Type | Description | Default |
|---|---|---|---|
| key | string | The key identifying the entry. | |
| value | T | The data to be persisted. | |
| options | SetOptions | Optional parameters (see below). |
delete
This method deletes a persisted entry
this.persistenceService.delete('key', options);
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| key | string | The key identifying the entry. | |
| options | SetOptions | Optional parameters (see below). |
SetOptions
| Name | Type | Description | Default |
|---|---|---|---|
| try | boolean | Only sets a value if the key does not already exist. | |
| force | boolean | Persists the value immediately without applying debouncing. |