Skip to main content

@idpass/data-collect-core / EventStorageAdapter

Interface: EventStorageAdapter

Defined in: interfaces/types.ts:391

Storage adapter interface for event persistence.

Provides the low-level storage operations for events and audit logs. Implementations include IndexedDbEventStorageAdapter and PostgresEventStorageAdapter.

Methods​

initialize()​

initialize(): Promise<void>

Defined in: interfaces/types.ts:393

Initialize the storage adapter (create tables, indexes, etc.)

Returns​

Promise<void>


saveEvents()​

saveEvents(forms): Promise<string[]>

Defined in: interfaces/types.ts:395

Save multiple events and return their IDs

Parameters​

forms​

FormSubmission[]

Returns​

Promise<string[]>


getEvents()​

getEvents(): Promise<FormSubmission[]>

Defined in: interfaces/types.ts:397

Get all events from storage

Returns​

Promise<FormSubmission[]>


saveAuditLog()​

saveAuditLog(entries): Promise<void>

Defined in: interfaces/types.ts:399

Save multiple audit log entries

Parameters​

entries​

AuditLogEntry[]

Returns​

Promise<void>


getAuditLog()​

getAuditLog(): Promise<AuditLogEntry[]>

Defined in: interfaces/types.ts:401

Get all audit log entries

Returns​

Promise<AuditLogEntry[]>


updateEventSyncLevel()​

updateEventSyncLevel(id, syncLevel): Promise<void>

Defined in: interfaces/types.ts:403

Update the sync level of an event

Parameters​

id​

string

syncLevel​

SyncLevel

Returns​

Promise<void>


updateAuditLogSyncLevel()​

updateAuditLogSyncLevel(id, syncLevel): Promise<void>

Defined in: interfaces/types.ts:405

Update the sync level of an audit log entry

Parameters​

id​

string

syncLevel​

SyncLevel

Returns​

Promise<void>


getEventsSince()​

getEventsSince(timestamp): Promise<FormSubmission[]>

Defined in: interfaces/types.ts:407

Get events created since a specific timestamp

Parameters​

timestamp​

string | Date

Returns​

Promise<FormSubmission[]>


getAuditLogsSince()​

getAuditLogsSince(timestamp): Promise<AuditLogEntry[]>

Defined in: interfaces/types.ts:409

Get audit logs created since a specific timestamp

Parameters​

timestamp​

string

Returns​

Promise<AuditLogEntry[]>


getEventsSincePagination()​

getEventsSincePagination(timestamp, limit): Promise<{ events: FormSubmission[]; nextCursor: string | Date | null; }>

Defined in: interfaces/types.ts:411

Get events since timestamp with pagination support (10 events/page default)

Parameters​

timestamp​

string | Date

limit​

number

Returns​

Promise<{ events: FormSubmission[]; nextCursor: string | Date | null; }>


updateSyncLevelFromEvents()​

updateSyncLevelFromEvents(events): Promise<void>

Defined in: interfaces/types.ts:419

Update sync levels for multiple events

Parameters​

events​

FormSubmission[]

Returns​

Promise<void>


getLastRemoteSyncTimestamp()​

getLastRemoteSyncTimestamp(): Promise<string>

Defined in: interfaces/types.ts:421

Get the timestamp of the last remote sync

Returns​

Promise<string>


setLastRemoteSyncTimestamp()​

setLastRemoteSyncTimestamp(timestamp): Promise<void>

Defined in: interfaces/types.ts:423

Set the timestamp of the last remote sync

Parameters​

timestamp​

string

Returns​

Promise<void>


getLastLocalSyncTimestamp()​

getLastLocalSyncTimestamp(): Promise<string>

Defined in: interfaces/types.ts:425

Get the timestamp of the last local sync

Returns​

Promise<string>


setLastLocalSyncTimestamp()​

setLastLocalSyncTimestamp(timestamp): Promise<void>

Defined in: interfaces/types.ts:427

Set the timestamp of the last local sync

Parameters​

timestamp​

string

Returns​

Promise<void>


getLastPullExternalSyncTimestamp()​

getLastPullExternalSyncTimestamp(): Promise<string>

Defined in: interfaces/types.ts:429

Get the timestamp of the last external sync pull

Returns​

Promise<string>


setLastPullExternalSyncTimestamp()​

setLastPullExternalSyncTimestamp(timestamp): Promise<void>

Defined in: interfaces/types.ts:431

Set the timestamp of the last external sync pull

Parameters​

timestamp​

string

Returns​

Promise<void>


getLastPushExternalSyncTimestamp()​

getLastPushExternalSyncTimestamp(): Promise<string>

Defined in: interfaces/types.ts:433

Get the timestamp of the last external sync push

Returns​

Promise<string>


setLastPushExternalSyncTimestamp()​

setLastPushExternalSyncTimestamp(timestamp): Promise<void>

Defined in: interfaces/types.ts:435

Set the timestamp of the last external sync push

Parameters​

timestamp​

string

Returns​

Promise<void>


getLastScopeHash()​

getLastScopeHash(): Promise<string | null>

Defined in: interfaces/types.ts:437

Get the last advertised scope hash from the server, or null if never seen.

Returns​

Promise<string | null>


setLastScopeHash()​

setLastScopeHash(hash): Promise<void>

Defined in: interfaces/types.ts:439

Persist the latest scope hash (called after a successful pull).

Parameters​

hash​

string

Returns​

Promise<void>


getLastScope()​

getLastScope(): Promise<EffectiveScopeBody | null>

Defined in: interfaces/types.ts:447

Get the last persisted effective scope body (areaIds/entityTypes/timeWindow + hash), or null when none has been observed yet.

Server-side adapters (Postgres) MUST NOT implement this — scope body persistence is client-only. The Postgres adapter throws.

Returns​

Promise<EffectiveScopeBody | null>


setLastScope()​

setLastScope(scope): Promise<void>

Defined in: interfaces/types.ts:455

Persist the effective scope body advertised by the server (called after a successful pull alongside setLastScopeHash).

Server-side adapters (Postgres) MUST NOT implement this — scope body persistence is client-only. The Postgres adapter throws.

Parameters​

scope​

EffectiveScopeBody

Returns​

Promise<void>


deleteEventsForEntity()​

deleteEventsForEntity(entityGuid): Promise<number>

Defined in: interfaces/types.ts:464

Delete all events whose entityGuid matches the given guid. Used during client-side scope-purge — the events would otherwise be orphans when their entity is removed. Returns the number of events deleted.

Server-side adapters (Postgres) MUST NOT implement this — purge is a client-only data-minimization operation. The Postgres adapter throws.

Parameters​

entityGuid​

string

Returns​

Promise<number>


isEventExisted()​

isEventExisted(guid): Promise<boolean>

Defined in: interfaces/types.ts:466

Check if an event with the given GUID exists

Parameters​

guid​

string

Returns​

Promise<boolean>


getAuditTrailByEntityGuid()​

getAuditTrailByEntityGuid(entityGuid): Promise<AuditLogEntry[]>

Defined in: interfaces/types.ts:468

Get complete audit trail for a specific entity

Parameters​

entityGuid​

string

Returns​

Promise<AuditLogEntry[]>


clearStore()​

clearStore(): Promise<void>

Defined in: interfaces/types.ts:470

Clear all data from the store (for testing)

Returns​

Promise<void>


closeConnection()​

closeConnection(): Promise<void>

Defined in: interfaces/types.ts:472

Close database connections and cleanup resources

Returns​

Promise<void>


persistHashAnchor()​

persistHashAnchor(hash): Promise<void>

Defined in: interfaces/types.ts:474

Persist the latest hash anchor for tamper detection on restart

Parameters​

hash​

string

Returns​

Promise<void>


getPersistedHashAnchor()​

getPersistedHashAnchor(): Promise<string | null>

Defined in: interfaces/types.ts:476

Retrieve the previously persisted hash anchor, or null if none exists

Returns​

Promise<string | null>


getMetadataValue()​

getMetadataValue(key): Promise<string | null>

Defined in: interfaces/types.ts:482

Generic key-value metadata accessor scoped to this adapter's tenant. Stored alongside scope-hash / push-watermark metadata in the same backing store. Returns null when the key is absent.

Parameters​

key​

string

Returns​

Promise<string | null>


setMetadataValue()​

setMetadataValue(key, value): Promise<void>

Defined in: interfaces/types.ts:484

Persist a metadata value under key. Upsert semantics.

Parameters​

key​

string

value​

string

Returns​

Promise<void>


deleteMetadataValue()​

deleteMetadataValue(key): Promise<void>

Defined in: interfaces/types.ts:486

Delete the metadata row for key. No-op if absent.

Parameters​

key​

string

Returns​

Promise<void>


listMetadataKeys()​

listMetadataKeys(prefix): Promise<string[]>

Defined in: interfaces/types.ts:491

List metadata keys whose name starts with prefix (tenant-scoped). Used for namespaced scans (e.g. cr: change-request records).

Parameters​

prefix​

string

Returns​

Promise<string[]>