Skip to main content

Class: InMemoryStorageAdapter<S, O>

Defined in: packages/polizy/src/polizy.in-memory.storage.ts:221

Type Parameters

S

S extends SubjectType = SubjectType

O

O extends ObjectType = ObjectType

Implements

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:252

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?

Subject<S> | AnyObject<O>

Returns

Promise<number>

A promise resolving to the number of tuples deleted.

Implementation of

StorageAdapter.delete


findObjects()

findObjects(subject, relation, options?): Promise<AnyObject<O>[]>

Defined in: packages/polizy/src/polizy.in-memory.storage.ts:297

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

StorageAdapter.findObjects


findSubjects()

findSubjects(object, relation, options?): Promise<Subject<S>[]>

Defined in: packages/polizy/src/polizy.in-memory.storage.ts:289

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

StorageAdapter.findSubjects


findTuples()

findTuples(filter, options?): Promise<StoredTuple<S, O>[]>

Defined in: packages/polizy/src/polizy.in-memory.storage.ts:282

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

StorageAdapter.findTuples


withSnapshot()

withSnapshot<T>(fn): Promise<T>

Defined in: packages/polizy/src/polizy.in-memory.storage.ts:311

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

StorageAdapter.withSnapshot


write()

write(tuples): Promise<StoredTuple<S, O>[]>

Defined in: packages/polizy/src/polizy.in-memory.storage.ts:228

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>[]>

Implementation of

StorageAdapter.write