LogoRobo.js
Packages@robojs/mock

MemoryAttachmentStorage

Class: MemoryAttachmentStorage

In-memory attachment storage implementation.

This is the default storage backend. It stores all attachments in a Map with O(1) access by ID. Suitable for development, testing, and small-scale deployments.

Limitations:

  • Data is lost when the process restarts
  • Memory usage scales linearly with stored data
  • Not suitable for horizontal scaling (no shared state)

Implements

Constructors

new MemoryAttachmentStorage()

new MemoryAttachmentStorage(): MemoryAttachmentStorage

Returns

MemoryAttachmentStorage

Methods

clear()

clear(): Promise<number>

Clear all stored attachments. Use with caution - this deletes all data.

Returns

Promise<number>

Number of attachments deleted

Implementation of

AttachmentStorage.clear


delete()

delete(id): Promise<boolean>

Delete an attachment by ID.

Parameters

ParameterTypeDescription
idstringThe attachment's snowflake ID

Returns

Promise<boolean>

true if deleted, false if not found

Implementation of

AttachmentStorage.delete


deleteForMessage()

deleteForMessage(messageId): Promise<number>

Delete all attachments for a specific message.

Parameters

ParameterTypeDescription
messageIdstringThe message's snowflake ID

Returns

Promise<number>

Number of attachments deleted

Implementation of

AttachmentStorage.deleteForMessage


deleteSync()

deleteSync(id): boolean

Parameters

ParameterType
idstring

Returns

boolean


get()

get(id): Promise<undefined | StoredAttachment>

Retrieve an attachment by ID.

Parameters

ParameterTypeDescription
idstringThe attachment's snowflake ID

Returns

Promise<undefined | StoredAttachment>

The stored attachment or undefined if not found

Implementation of

AttachmentStorage.get


getAllSync()

getAllSync(): StoredAttachment[]

Returns

StoredAttachment[]


getForMessage()

getForMessage(messageId): Promise<StoredAttachment[]>

Get all attachments for a specific message.

Parameters

ParameterTypeDescription
messageIdstringThe message's snowflake ID

Returns

Promise<StoredAttachment[]>

Array of stored attachments belonging to the message

Implementation of

AttachmentStorage.getForMessage


getForMessageSync()

getForMessageSync(messageId): StoredAttachment[]

Parameters

ParameterType
messageIdstring

Returns

StoredAttachment[]


getStats()

getStats(): Promise<StorageStats>

Get storage statistics.

Returns

Promise<StorageStats>

Current storage metrics

Implementation of

AttachmentStorage.getStats


getSync()

getSync(id): undefined | StoredAttachment

Parameters

ParameterType
idstring

Returns

undefined | StoredAttachment


store()

store(attachment): Promise<void>

Store an attachment.

Parameters

ParameterTypeDescription
attachmentStoredAttachmentThe attachment data to store

Returns

Promise<void>

Promise that resolves when storage is complete

Implementation of

AttachmentStorage.store


storeSync()

storeSync(attachment): void

Parameters

ParameterType
attachmentStoredAttachment

Returns

void

On this page