Перейти к содержанию

Interface: StorageDriver

Abstract Storage Driver API

Describes both permanent (database, filesystem) and temporary (cache, memory) storage methods. SDK actively uses both storage strategies, distinguished by name:

  • storage - permanent storage
  • cache - temporary storage

Example

async (storage: StorageDriver) => {
  await write(storage, { room: '323', topic: 'dinner' }, { foo: 'woo' });

  expect(await read(storage, { room: '323', topic: 'dinner' })).toEqual({ foo: 'woo' });
  expect(await read(storage, { room: '323', topic: 'dinner' })).toEqual({ foo: 'woo' });

  expect(await take(storage, { room: '323', topic: 'dinner' })).toEqual({ foo: 'woo' });
  expect(await take(storage, { room: '323', topic: 'dinner' })).toEqual(null);
};

Implemented by

Methods

read

read(meta): Promise<unknown>

Read data stored under the provided meta

This method is typically used in a permanent storage strategy

Parameters

Name Type Description
meta StorageMeta composite identifier

Returns

Promise<unknown>

stored data, or null if not found


take

take(meta): Promise<unknown>

Take the data stored under the provided meta and remove original

This method is typically used in a temporary storage strategy and as a mean to delete stored entry

Parameters

Name Type Description
meta StorageMeta composite identifier

Returns

Promise<unknown>

stored data, or null if not found


write

write(meta, data): Promise<void>

Write a unit of data into storage, uniquely identified by meta

If such unit of data already exists, it is silently overwritten

Parameters

Name Type Description
meta StorageMeta composite identifier
data unknown unit of data to insert

Returns

Promise<void>