@or-sdk/key-value-storage
v0.30.2
Published
OneReach SDK client for Key Value Storage
Readme
@or-sdk/key-value-storage
OneReach SDK client for Key Value Storage.
When to use
- Use this package when integrating with the Key Value Storage capability on the OneReach platform.
- Use its typed client and exported models instead of hand-writing requests to that service.
When not to use
- Do not use it for a different platform capability; choose the dedicated
@or-sdk/*package instead. - Do not use it for generic third-party HTTP calls.
Installation
$ npm i @or-sdk/key-value-storageUsage
import { KeyValueStorage } from '@or-sdk/key-value-storage'
// with direct api url
const keyValueStorage = new KeyValueStorage({
token: 'my-account-token-string',
sdkUrl: 'http://example.sdk-api/endpoint'
});
// with service discovery(slower)
const keyValueStorage = new KeyValueStorage({
token: 'my-account-token-string',
discoveryUrl: 'http://example.discovery/endpoint'
});Configuration
- Prefer
sdkUrlwhen the service URL is known; it avoids a discovery request. - Use
discoveryUrlonly when the service URL is not available. - Provide
tokenas a bearer-token string or getter where supported.
Common pitfalls
- Keep the client token current when it can expire; a token getter is preferable where the constructor accepts one.
- Treat the generated TypeScript types as the authoritative contract for optional parameters and response shapes.
Method map
| Method | Purpose |
|---|---|
| composeRoute(...) | See the exported TypeScript signature for parameters and result. |
| scrollCollections(...) | See the exported TypeScript signature for parameters and result. |
| listCollections(...) | See the exported TypeScript signature for parameters and result. |
| scrollKeysWithPrefixes(...) | See the exported TypeScript signature for parameters and result. |
| listUniqueKeysWithPrefixes(...) | See the exported TypeScript signature for parameters and result. |
| existsValueByKey(...) | See the exported TypeScript signature for parameters and result. |
| deleteKey(...) | See the exported TypeScript signature for parameters and result. |
More detail
Full signatures and exported types are available in src/ and dist/types/.
Additional API reference
Methods below were missing from the package guide. Signatures and return types are taken directly from the exported source API.
KeyValueStorage
| Method | Returns | Purpose |
|---|---|---|
| scrollKeys(options: ScrollOptions, collectionName: string) | Promise<ScrollResult< ListKeysRecord >> | List keys in a collection starting with given substring with pagination |
| scrollKeys(options: ScrollOptions, collectionName: string, prefix?: string) | Promise<ScrollResult< ListKeysRecord >> | See the exported TypeScript signature for behavior and constraints. |
| scrollKeys(options: ScrollOptions, collectionName: string, prefix?: string, withValues?: false) | Promise<ScrollResult< ListKeysRecord >> | See the exported TypeScript signature for behavior and constraints. |
| scrollKeys(options: ScrollOptions, collectionName: string, prefix?: string, withValues?: true) | Promise<ScrollResult< ListKeysRecordWithValue<T> >> | See the exported TypeScript signature for behavior and constraints. |
| scrollKeys(options: ScrollOptions, collectionName: string, prefix?: string, withValues?: boolean) | Promise<ScrollResult< ListKeysRecord \| ListKeysRecordWithValue<T> >> | See the exported TypeScript signature for behavior and constraints. |
| scrollKeys({ numberOfItems, nextId }: ScrollOptions, collectionName: string, prefix?: string, withValues?: boolean) | Promise<ScrollResult<ListKeysRecord \| ListKeysRecordWithValue<T>>> | See the exported TypeScript signature for behavior and constraints. |
| listKeys(collectionName: string) | Promise<List< ListKeysRecord >> | List keys in a collection starting with given substring |
| listKeys(collectionName: string, prefix?: string) | Promise<List< ListKeysRecord >> | See the exported TypeScript signature for behavior and constraints. |
| listKeys(collectionName: string, prefix?: string, withValues?: false) | Promise<List< ListKeysRecord >> | See the exported TypeScript signature for behavior and constraints. |
| listKeys(collectionName: string, prefix?: string, withValues?: true) | Promise<List< ListKeysRecordWithValue<T> >> | See the exported TypeScript signature for behavior and constraints. |
| listKeys(collectionName: string, prefix?: string, withValues?: boolean) | Promise<List< ListKeysRecord \| ListKeysRecordWithValue<T> >> | See the exported TypeScript signature for behavior and constraints. |
| getValueByKey(collectionName: string, key: string) | Promise<KeyValueStorageRecord<T>> | Get value from collection by key |
| setValueByKey(collectionName: string, key: string, value: T extends undefined ? never : T, expire?: number) | Promise<SetValueResponse<T>> | Set value to collection by key |
| processMultipleRecords(records: KeyValueStorageRecord[], action: Action.GET, collectionName: string) | Promise<GetValueResponse<T>[]> | Process multiple records |
| processMultipleRecords(records: KeyValueStorageRecord[], action: Action.SET, collectionName: string) | Promise<SetValueResponse<T>[]> | See the exported TypeScript signature for behavior and constraints. |
| processMultipleRecords(records: KeyValueStorageRecord[], action: Action.DELETE, collectionName: string) | Promise<DeleteValueResponse<T>[]> | See the exported TypeScript signature for behavior and constraints. |
| processMultipleRecords(records: KeyValueStorageRecord[], action: Action.EXISTS, collectionName: string) | Promise<ExistsValueResponse[]> | See the exported TypeScript signature for behavior and constraints. |
| processMultipleRecords(records: KeyValueStorageRecord[], action: Action, collectionName: string) | Promise<MultipleRecordsResult<T>> | See the exported TypeScript signature for behavior and constraints. |
| copyCollection(sourceCollectionName: string, targetCollectionName: string) | Promise<void> | Copy records from one collection to another |
| clearCollection(collectionName: string) | Promise<void> | Delete all records from collection |
Exported utility reference
| Function | Returns | Purpose |
|---|---|---|
| chunk(array: T[], size: number = 10) | T[][] | Exported utility; see its TypeScript signature for behavior. |
