Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Dev Guide
Dev GuideUser GuidesGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

BaseKVStore

OCP App SDK


OCP App SDK / BaseKVStore

Interface: BaseKVStore<T, R>

Defined in: src/store/BaseKVStore.ts:27

The base interface all key-value stores implement

Extended by

Type Parameters

T

T = ValueHash

R

R = true

Methods

delete()

delete<V>(key, fields?): Promise<R extends T ? V : R>

Defined in: src/store/BaseKVStore.ts:76

Delete an object or a single field from the store at a given key.
If fields is undefined, the entire object will be deleted.

Type Parameters

V

V

Parameters

key

string

of the stored object

fields?

string[]

to delete or undefined to delete all fields

Returns

Promise<R extends T ? V : R>

true if successful. Otherwise throws an error.

Async


exists()

exists(key): Promise<boolean>

Defined in: src/store/BaseKVStore.ts:84

Check if an object exists at a given key.

Parameters

key

string

of the stored object

Returns

Promise<boolean>

true if the object exists

Async


get()

get<V>(key, fields?): Promise<V>

Defined in: src/store/BaseKVStore.ts:36

Retrieve an object from the store given a key.

Type Parameters

V

V

Parameters

key

string

of the stored object

fields?

string[]

to retrieve from the stored object, or undefined to retrieve the full object

Returns

Promise<V>

hash of the complete object or only the specified fields, if supplied.
An empty object is returned if the object, or all specified fields, does not exist.

Async


patch()

Call Signature

patch<V>(key, value): Promise<V>

Defined in: src/store/BaseKVStore.ts:55

Write a set of fields to an object in the store at a given key. Does not overwrite the entire object.

Type Parameters
V

V

Parameters
key

string

of the stored object

value

V

hash of fields and values to update the object with. Leaves all other fields untouched.

Returns

Promise<V>

the complete object from before the update
An empty object is returned if the object previously did not exist.

Async

Call Signature

patch<V>(key, updater): Promise<V>

Defined in: src/store/BaseKVStore.ts:66

Update a stored object using a callback to make changes.

Type Parameters
V

V

Parameters
key

string

of the stored object

updater

PatchUpdater<V>

function to manipulate the existing object (may be called multiple times to ensure an atomic change)

Returns

Promise<V>

the complete object from before the update
An empty object is returned if the object previously did not exist.

Async

put()

put<V>(key, value): Promise<R extends T ? V : R>

Defined in: src/store/BaseKVStore.ts:45

Write an object to the store at a given key. Overwrites the entire object.

Type Parameters

V

V

Parameters

key

string

of the stored object

value

V

complete hash to write

Returns

Promise<R extends T ? V : R>

true if successful. Otherwise throws an error.

Async