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

Class: ServiceStorage

Storage driver implementing simple storage via StorageService API

StorageService API temporarily supports extra methods (find, list, clear), which are not part of the StorageDriver interface and are considered unsafe for production use (to be removed).

Note

FOR PROTOTYPING ONLY. This storage, though secure itself, violates Spatium security policy regarding storing both secrets at the same party. By using this storage, you effectively store both user secrets at Spatium, thus resulting in a CUSTODIAL wallet.

Implements

  • StorageDriver

Constructors

constructor

new ServiceStorage(url, auth)

Note

requests are attributed to accountId of an authorization session, thus storing data independently for each authorized user

Example

const auth = new AuthorizationSession('https://cloud.spatium.net/authorization/v1', uuid(randomBytes), ['read', 'secret']);
const storage = new ServiceStorage('https://cloud.spatium.net/storage/v1', auth);

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);

Parameters

Name Type Description
url string storage service endpoint (HTTP(S))
auth AuthorizationSession authorization AuthorizationSession session to use

Methods

clear

clear(filter): Promise<number>

Deprecated

used for tracing

Parameters

Name Type
filter Partial<{}>

Returns

Promise<number>


find

find(filter): Promise<null | StoragePayload>

Deprecated

used for tracing

Parameters

Name Type
filter Partial<{}>

Returns

Promise<null | StoragePayload>


list

list(filter): Promise<StoragePayload[]>

Deprecated

used for tracing

Parameters

Name Type
filter Partial<{}>

Returns

Promise<StoragePayload[]>


read

read(meta): Promise<unknown>

Parameters

Name Type
meta StorageMeta

Returns

Promise<unknown>

Implementation of

StorageDriver.read


take

take(meta): Promise<unknown>

Parameters

Name Type
meta StorageMeta

Returns

Promise<unknown>

Implementation of

StorageDriver.take


write

write(meta, data): Promise<void>

Parameters

Name Type
meta StorageMeta
data unknown

Returns

Promise<void>

Implementation of

StorageDriver.write