routier-collection / core/src / EphemeralDataPlugin
Abstract Class: EphemeralDataPlugin
Defined in: core/src/plugins/EphemeralDataPlugin.ts:44
Interface for a database plugin, which provides query, destroy, and bulk operations.
Implements
Constructors
Constructor
new EphemeralDataPlugin(
databaseName):EphemeralDataPlugin
Defined in: core/src/plugins/EphemeralDataPlugin.ts:48
Parameters
databaseName
string
Returns
EphemeralDataPlugin
Accessors
databaseName
Get Signature
get databaseName():
string
Defined in: core/src/plugins/EphemeralDataPlugin.ts:57
See IDbPlugin.databaseName. A getter rather than the field itself so a subclass whose database is identified by more than a name can widen it — FileSystemPlugin returns the resolved file path, because one name in two directories is two databases.
Returns
string
Uniquely identifies the database this plugin talks to, INCLUDING host or path where a bare name would collide — orders.db in two directories is two databases, and mydb on two hosts is two databases. Two instances over the same database must return the same string, in this process and in any other; two over different databases must not.
Used to scope schema subscription channels, so instances of one database (another tab, a worker) see each other's change notifications and unrelated databases holding the same schema do not.
Required rather than optional on purpose. An absent value used to fall back to scoping by schema alone, which shares one channel across every database holding that schema — the exact cross-talk this prevents, arrived at by omission. Requiring it also makes a wrapper that forgets to forward it a compile error rather than a silent regression.
Derive it, never generate it: a random value is unique per PROCESS, not per database, so another tab would never match one and cross-context notifications would stop.
Must not contain credentials — it becomes part of a channel key, so build it from host/port/database rather than returning a connection string.
Implementation of
Methods
bulkPersist()
bulkPersist(
event,done):void
Defined in: core/src/plugins/EphemeralDataPlugin.ts:77
All-or-nothing across every collection in the save.
The naive shape — validate/apply/save one schema at a time — leaks partial saves: a conflict in the SECOND collection left the first collection's changes applied (measured in the finance stress app as one orphan ledger row per conflict). So the work is phased: every collection loads and validates BEFORE anything is applied, mutations apply with an undo log, and a failure anywhere reverts the memory state (and re-saves any files already written) so the caller sees a save that did nothing.
The remaining honesty gap is crash-safety across FILES: a process dying between two file writes can leave disk partially updated. Guarding that needs a journal, which a memory-first plugin does not pretend to have.
Parameters
event
done
PluginEventCallbackPartialResult<BulkPersistResult>
Returns
void
Implementation of
query()
query<
TEntity,TShape>(event,done):void
Defined in: core/src/plugins/EphemeralDataPlugin.ts:362
Executes a query operation on the database.
Type Parameters
TEntity
TEntity extends object
TShape
TShape extends unknown = TEntity
Parameters
event
DbPluginQueryEvent<TEntity, TShape>
The query event containing schema, parent, and query operation.
done
PluginEventCallbackResult<ITranslatedValue<TShape>>
Callback with the result or error.
Returns
void
Implementation of
destroy()
abstractdestroy(event,done):void
Defined in: core/src/plugins/EphemeralDataPlugin.ts:487
Destroys or cleans up the plugin, closing connections or freeing resources.
Parameters
event
done
PluginEventCallbackResult<never>
Callback with an optional error.
Returns
void