Class: ReactiveModelIntrospector<T, PK, R>
A testing utility class for introspecting and testing ReactiveModel instances. This class is designed to help with testing by exposing internal state that would otherwise be inaccessible due to TypeScript's private field declarations.
Type Parameters
Type Parameter | Description |
---|---|
T extends PlainObject | The shape of the model's data as a plain object |
PK extends StringKeyOf <T > | The primary key field of the model, must be a string key of T |
R extends Record <string , RelationshipConfiguration > | Record of relationship configurations for the model |
Constructors
Constructor
new ReactiveModelIntrospector<T, PK, R>(): ReactiveModelIntrospector<T, PK, R>;
Returns
ReactiveModelIntrospector
<T
, PK
, R
>
Accessors
boundOnReactiveModelDeletedInSwarm
Get Signature
get boundOnReactiveModelDeletedInSwarm(): undefined | (modelName: string, instanceKey: string) => void;
Gets the bound handler for model deletions in Swarm
Throws
If accessed before initialization
Returns
undefined
| (modelName
: string
, instanceKey
: string
) => void
boundOnReactiveModelUpdatedInSwarm
Get Signature
get boundOnReactiveModelUpdatedInSwarm():
| undefined
| (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void;
Gets the bound handler for model updates in Swarm
Throws
If accessed before initialization
Returns
| undefined
| (modelName
: string
, instanceKey
: string
, values
: Record
<StringKeyOf
<T
>, string
>) => void
deleted
Get Signature
get deleted(): boolean;
Gets the deleted status of the model
Throws
If accessed before initialization
Returns
boolean
emitter
Get Signature
get emitter(): ReactiveModelChangeEmitter<T, PK, R>;
Gets the ReactiveModelChangeEmitter instance
Throws
If accessed before initialization
Returns
ReactiveModelChangeEmitter
<T
, PK
, R
>
encryption
Get Signature
get encryption(): Encryption;
Gets the Encryption instance used for data encryption
Throws
If accessed before initialization
Returns
Encryption
logBus
Get Signature
get logBus(): TypedEventEmitter<LogBusEventMap>;
Gets the LogBus event emitter instance
Throws
If accessed before initialization
Returns
TypedEventEmitter
<LogBusEventMap
>
modelKey
Get Signature
get modelKey(): string;
Gets the model's unique key
Throws
If accessed before initialization
Returns
string
modelName
Get Signature
get modelName(): string;
Gets the model's name
Throws
If accessed before initialization
Returns
string
pending
Get Signature
get pending(): Map<StringKeyOf<T>, T[StringKeyOf<T>]>;
Gets the map of pending changes
Throws
If accessed before initialization
Returns
Map
<StringKeyOf
<T
>, T
[StringKeyOf
<T
>]>
primaryKey
Get Signature
get primaryKey(): PK;
Gets the primary key field name
Throws
If accessed before initialization
Returns
PK
properties
Get Signature
get properties(): readonly StringKeyOf<T>[];
Gets the array of model property names
Throws
If accessed before initialization
Returns
readonly StringKeyOf
<T
>[]
relationships
Get Signature
get relationships(): Record<string, Relationship>;
Gets the model's relationships
Throws
If accessed before initialization
Returns
Record
<string
, Relationship
>
state
Get Signature
get state(): Map<StringKeyOf<T>, T[StringKeyOf<T>]>;
Gets the current state map
Throws
If accessed before initialization
Returns
Map
<StringKeyOf
<T
>, T
[StringKeyOf
<T
>]>
swarm
Get Signature
get swarm(): UnifiedEventBus;
Gets the Swarm instance used for reactive state synchronization
Throws
If accessed before initialization
Returns
UnifiedEventBus
table
Get Signature
get table(): EntityTable<T>;
Gets the Dexie EntityTable instance
Throws
If accessed before initialization
Returns
EntityTable
<T
>
throwError
Get Signature
get throwError(): (err: Error) => void;
Gets the error throwing function
Throws
If accessed before initialization
Returns
(err: Error): void;
Parameters
Parameter | Type |
---|---|
err | Error |
Returns
void
Methods
$init()
$init(
swarm: () => UnifiedEventBus,
encryption: () => Encryption,
logBus: () => TypedEventEmitter<LogBusEventMap>,
throwError: () => (err: Error) => void,
table: () => EntityTable<T>,
properties: () => readonly StringKeyOf<T>[],
primaryKey: () => PK,
modelName: () => string,
modelKey: () => string,
pending: () => Map<StringKeyOf<T>, T[StringKeyOf<T>]>,
state: () => Map<StringKeyOf<T>, T[StringKeyOf<T>]>,
emitter: () => ReactiveModelChangeEmitter<T, PK, R>,
relationships: () => Record<string, Relationship>,
deleted: () => boolean,
boundOnReactiveModelUpdatedInSwarm: () =>
| undefined
| (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void,
boundOnReactiveModelDeletedInSwarm: () => undefined | (modelName: string, instanceKey: string) => void,
onReactiveModelUpdatedInSwarm: (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void,
onReactiveModelDeletedInSwarm: (modelName: string, instanceKey: string) => void,
getProperty: <P>(prop: P) => undefined | T[P],
getRelatedProperty: <P>(prop: P) => any,
setProperty: <P>(prop: P, value: T[P]) => void,
doEmitChanges: () => void): void;
Initializes the introspector with all necessary dependencies and functions. This method can only be called once. Subsequent calls will throw an error.
Parameters
Parameter | Type |
---|---|
swarm | () => UnifiedEventBus |
encryption | () => Encryption |
logBus | () => TypedEventEmitter <LogBusEventMap > |
throwError | () => (err : Error ) => void |
table | () => EntityTable <T > |
properties | () => readonly StringKeyOf <T >[] |
primaryKey | () => PK |
modelName | () => string |
modelKey | () => string |
pending | () => Map <StringKeyOf <T >, T [StringKeyOf <T >]> |
state | () => Map <StringKeyOf <T >, T [StringKeyOf <T >]> |
emitter | () => ReactiveModelChangeEmitter <T , PK , R > |
relationships | () => Record <string , Relationship > |
deleted | () => boolean |
boundOnReactiveModelUpdatedInSwarm | () => | undefined | (modelName : string , instanceKey : string , values : Record <StringKeyOf <T >, string >) => void |
boundOnReactiveModelDeletedInSwarm | () => undefined | (modelName : string , instanceKey : string ) => void |
onReactiveModelUpdatedInSwarm | (modelName : string , instanceKey : string , values : Record <StringKeyOf <T >, string >) => void |
onReactiveModelDeletedInSwarm | (modelName : string , instanceKey : string ) => void |
getProperty | <P >(prop : P ) => undefined | T [P ] |
getRelatedProperty | <P >(prop : P ) => any |
setProperty | <P >(prop : P , value : T [P ]) => void |
doEmitChanges | () => void |
Returns
void
Throws
If attempting to reinitialize any property
doEmitChanges()
doEmitChanges(): void;
Emits any pending changes to subscribers
Returns
void
Throws
If accessed before initialization
getProperty()
getProperty<P>(prop: P): undefined | T[P];
Gets a property value from the model
Type Parameters
Type Parameter |
---|
P extends string |
Parameters
Parameter | Type | Description |
---|---|---|
prop | P | Name of the property to get |
Returns
undefined
| T
[P
]
The property value or undefined if not found
Throws
If accessed before initialization
getRelatedProperty()
getRelatedProperty<P>(prop: P): any;
Gets a related property value from the model's relationships
Type Parameters
Type Parameter |
---|
P extends string |
Parameters
Parameter | Type | Description |
---|---|---|
prop | P | Name of the related property to get |
Returns
any
The related property value or undefined if not found
Throws
If accessed before initialization
onReactiveModelDeletedInSwarm()
onReactiveModelDeletedInSwarm(modelName: string, instanceKey: string): void;
Handles model deletion events in Swarm
Parameters
Parameter | Type | Description |
---|---|---|
modelName | string | Name of the model being deleted |
instanceKey | string | Unique key of the model instance |
Returns
void
Throws
If accessed before initialization
setProperty()
setProperty<P>(prop: P, value: T[P]): void;
Sets a property value on the model
Type Parameters
Type Parameter |
---|
P extends string |
Parameters
Parameter | Type | Description |
---|---|---|
prop | P | Name of the property to set |
value | T [P ] | Value to set for the property |
Returns
void
Throws
If accessed before initialization