Dev Guide
Dev GuideUser GuidesLegal TermsGitHubDevCommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

BaseKVStore

OCP App SDK / BaseKVStore

BaseKVStore<T, R>

The base interface all key-value stores implement

Type parameters

Hierarchy

Index

Methods

Methods

delete()

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

Async

Signature

delete<V>(key: string, fields?: string[]): Promise<R extends T ? V : R>;

Type parameters

  • V

Parameters

NameTypeDescription
keystringof 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.

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

exists()

Check if an object exists at a given key.

Async

Signature

exists(key: string): Promise<boolean>;

Parameters

NameTypeDescription
keystringof the stored object

Returns

Promise<boolean>

true if the object exists

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

get()

Retrieve an object from the store given a key.

Async

Signature

get<V>(key: string, fields?: string[]): Promise<V>;

Type parameters

  • V

Parameters

NameTypeDescription
keystringof 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.

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

patch()

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

Async

Signature

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

Type parameters

  • V

Parameters

NameTypeDescription
keystringof the stored object
valueVhash 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.

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

Update a stored object using a callback to make changes.

Async

Signature

patch<V>(key: string, updater: PatchUpdater<V>): Promise<V>;

Type parameters

  • V

Parameters

NameTypeDescription
keystringof the stored object
updaterPatchUpdater<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.

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

put()

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

Async

Signature

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

Type parameters

  • V

Parameters

NameTypeDescription
keystringof the stored object
valueVcomplete hash to write

Returns

Promise<R extends T ? V : R>

true if successful. Otherwise throws an error.

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