Class: InMemoryStorageAdapter<S, O>
Defined in: packages/polizy/src/polizy.in-memory.storage.ts:230
An in-memory implementation of StorageAdapter.
Results returned by methods like findTuples are live references to the stored objects themselves, rather than deep copies, to maximize performance. Modifying these objects directly will corrupt the store and its internal indexes silently. You should treat all returned tuples as immutable, or use withSnapshot to obtain an isolated, consistent point-in-time copy.
Type Parameters
S
S extends SubjectType = SubjectType
O
O extends ObjectType = ObjectType
Implements
StorageAdapter<S,O>
Constructors
Constructor
new InMemoryStorageAdapter<
S,O>():InMemoryStorageAdapter<S,O>
Returns
InMemoryStorageAdapter<S, O>
Methods
delete()
delete(
filter):Promise<number>
Defined in: packages/polizy/src/polizy.in-memory.storage.ts:265
Deletes tuples matching the specified filter criteria. The filter allows matching by subject ('who'), relation ('was'), and/or object ('onWhat'). If multiple criteria are provided, only tuples matching all of them are deleted. If a criterion is omitted, it acts as a wildcard for that part of the tuple. Implementations should handle the case where the filter might be empty (though AuthSystem prevents this).
Parameters
filter
An object containing optional filter criteria:
who: The subject (or object acting as subject) of the tuple.was: The relation of the tuple.onWhat: The object of the tuple.
onWhat?
AnyObject<O>
was?
string
who?
Returns
Promise<number>
A promise resolving to the number of tuples deleted.
Implementation of
findObjects()
findObjects(
subject,relation,options?):Promise<AnyObject<O>[]>
Defined in: packages/polizy/src/polizy.in-memory.storage.ts:308
Finds objects a subject has a specific relation TO (e.g., groups user is in, parent of doc).
Parameters
subject
Subject<S>
relation
string
options?
objectType?
O
Returns
Promise<AnyObject<O>[]>
Implementation of
findSubjects()
findSubjects(
object,relation,options?):Promise<Subject<S>[]>
Defined in: packages/polizy/src/polizy.in-memory.storage.ts:300
Finds subjects with a specific relation TO an object (e.g., members of a group).
Parameters
object
AnyObject<O>
relation
string
options?
subjectType?
S
Returns
Promise<Subject<S>[]>
Implementation of
findTuples()
findTuples(
filter,options?):Promise<StoredTuple<S,O>[]>
Defined in: packages/polizy/src/polizy.in-memory.storage.ts:293
Finds stored tuples matching the filter. The delete/find subject-position
semantics: a who constraint always pins the subject; onWhat matches the
subject position only when who is absent.
Parameters
filter
Partial<InputTuple<S, O>>
options?
Optional pagination (limit, offset) applied in stable order.
limit?
number
offset?
number
Returns
Promise<StoredTuple<S, O>[]>
Implementation of
withSnapshot()
withSnapshot<
T>(fn):Promise<T>
Defined in: packages/polizy/src/polizy.in-memory.storage.ts:322
Run fn against a point-in-time copy of the store. A write that lands while
fn is in flight mutates the live store (and can edit a live tuple's
condition in place); cloning copies each tuple, so the operation sees one
coherent view without blocking writers.
Type Parameters
T
T
Parameters
fn
(reader) => Promise<T>
Returns
Promise<T>
Implementation of
write()
write(
tuples):Promise<StoredTuple<S,O>[]>
Defined in: packages/polizy/src/polizy.in-memory.storage.ts:241
Writes tuples to storage, idempotently. A tuple is identified by its (subject, relation, object) triple: writing one that already exists updates its condition rather than creating a duplicate. Returns the stored tuples (with ids) in the same order as the input.
Parameters
tuples
InputTuple<S, O>[]
An array of tuples to write (without IDs).
Returns
Promise<StoredTuple<S, O>[]>