Skip to main content

Interface: StorageAdapter<S, O>

Defined in: packages/polizy/src/polizy.storage.ts:11

Type Parameters

S

S extends SubjectType = SubjectType

O

O extends ObjectType = ObjectType

Methods

delete()

delete(filter): Promise<number>

Defined in: packages/polizy/src/polizy.storage.ts:37

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.


findObjects()

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

Defined in: packages/polizy/src/polizy.storage.ts:59

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


findSubjects()

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

Defined in: packages/polizy/src/polizy.storage.ts:53

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


findTuples()

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

Defined in: packages/polizy/src/polizy.storage.ts:48

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


withSnapshot()?

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

Defined in: packages/polizy/src/polizy.storage.ts:72

Optional: run fn against a read-only view pinned to a single point in time, so one authorization operation sees a consistent snapshot WITHOUT locking writers (e.g. a read-only REPEATABLE READ transaction for SQL, or a captured copy for in-memory). Adapters that can't provide this omit it, and the engine falls back to live reads.

Type Parameters

T

T

Parameters

fn

(reader) => Promise<T>

Returns

Promise<T>


write()

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

Defined in: packages/polizy/src/polizy.storage.ts:22

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