From 0340d7a5818f764faaba8ecd66f702f23ccc1514 Mon Sep 17 00:00:00 2001 From: Anita Ruangrotsakun <138700973+anitarua@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:40:47 -0700 Subject: [PATCH] chore: add missing KeyExists and KeysExist docs snippets and correct docstrings (#1218) --- .../doc-example-files/doc-examples-js-apis.ts | 27 +++++++++++++++++++ .../clients/cache/AbstractCacheClient.ts | 4 +-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts b/examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts index a70ae7ae1..30b2c7517 100644 --- a/examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts +++ b/examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts @@ -96,6 +96,8 @@ import { SetBatch, ReadConcern, CacheSetSample, + CacheKeyExists, + CacheKeysExist, } from '@gomomento/sdk'; import * as crypto from 'crypto'; @@ -940,6 +942,28 @@ async function example_API_SortedSetRemoveElements(cacheClient: CacheClient, cac } } +async function example_API_KeyExists(cacheClient: CacheClient, cacheName: string) { + const result = await cacheClient.keyExists(cacheName, 'test-key'); + if (result instanceof CacheKeyExists.Success) { + console.log("Does 'test-key' exists in the cache?", result.exists()); + } else if (result instanceof CacheKeyExists.Error) { + throw new Error( + `An error occurred while attempting to call keyExists on key 'test-key' in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}` + ); + } +} + +async function example_API_KeysExist(cacheClient: CacheClient, cacheName: string) { + const result = await cacheClient.keysExist(cacheName, ['test-key1', 'test-key2']); + if (result instanceof CacheKeysExist.Success) { + console.log("Do 'test-key1' and 'test-key2' exist in the cache?", result.exists()); + } else if (result instanceof CacheKeysExist.Error) { + throw new Error( + `An error occurred while attempting to call keysExist on keys 'test-key1' and 'test-key2' in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}` + ); + } +} + function example_API_InstantiateAuthClient() { new AuthClient({ credentialProvider: CredentialProvider.fromEnvironmentVariable({ @@ -1585,6 +1609,9 @@ async function main() { await example_API_SortedSetRemoveElement(cacheClient, cacheName); await example_API_SortedSetRemoveElements(cacheClient, cacheName); + await example_API_KeyExists(cacheClient, cacheName); + await example_API_KeysExist(cacheClient, cacheName); + example_API_InstantiateAuthClient(); const authClient = new AuthClient({ credentialProvider: CredentialProvider.fromEnvironmentVariable({ diff --git a/packages/core/src/internal/clients/cache/AbstractCacheClient.ts b/packages/core/src/internal/clients/cache/AbstractCacheClient.ts index 34799077e..546eb530a 100644 --- a/packages/core/src/internal/clients/cache/AbstractCacheClient.ts +++ b/packages/core/src/internal/clients/cache/AbstractCacheClient.ts @@ -1531,7 +1531,7 @@ export abstract class AbstractCacheClient implements ICacheClient { * @param {string} cacheName - The cache to look in. * @param {string | Uint8Array} key - The key to look up. * @returns {Promise} - * {@link CacheKeyExists.Success} if key is found? or if key is checked? + * {@link CacheKeyExists.Success} returns boolean indicating whether the key was found. * {@link CacheKeyExists.Error} on failure. */ public async keyExists( @@ -1547,7 +1547,7 @@ export abstract class AbstractCacheClient implements ICacheClient { * @param {string} cacheName - The cache to look in. * @param {string[] | Uint8Array[]} keys - The keys to look up. * @returns {Promise} - * {@link CacheKeysExist.Success} if at least one key is found? if all keys checked? + * {@link CacheKeysExist.Success} returns list of booleans indicating whether each key was found. * {@link CacheKeysExist.Error} on failure. */ public async keysExist(