Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents fcf6031 + 1f52c3f commit 3a4d470
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 115 deletions.
70 changes: 35 additions & 35 deletions examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ import {
PutWebhook,
RotateWebhookSecret,
GetWebhookSecret,
GetBatch,
SetBatch,
// GetBatch,
// SetBatch,
ReadConcern,
CacheSetSample,
CacheKeyExists,
Expand Down Expand Up @@ -385,37 +385,37 @@ async function example_API_SetIfAbsentOrEqual(cacheClient: CacheClient, cacheNam
}
}

async function example_API_SetBatch(cacheClient: CacheClient, cacheName: string) {
const values = new Map<string, string>([
['abc', '123'],
['xyz', '321'],
['123', 'xyz'],
['321', 'abc'],
]);
const result = await cacheClient.setBatch(cacheName, values);
if (result instanceof SetBatch.Success) {
console.log('Keys and values stored successfully');
} else if (result instanceof SetBatch.Error) {
throw new Error(
`An error occurred while attempting to batch set in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_GetBatch(cacheClient: CacheClient, cacheName: string) {
const keys = ['abc', 'xyz', '123', '321'];
const result = await cacheClient.getBatch(cacheName, keys);
if (result instanceof GetBatch.Success) {
const values = result.values();
for (const key of keys) {
console.log(`Retrieved value for key '${key}': ${values[key]}`);
}
} else if (result instanceof GetBatch.Error) {
throw new Error(
`An error occurred while attempting to batch get in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
}
// async function example_API_SetBatch(cacheClient: CacheClient, cacheName: string) {
// const values = new Map<string, string>([
// ['abc', '123'],
// ['xyz', '321'],
// ['123', 'xyz'],
// ['321', 'abc'],
// ]);
// const result = await cacheClient.setBatch(cacheName, values);
// if (result instanceof SetBatch.Success) {
// console.log('Keys and values stored successfully');
// } else if (result instanceof SetBatch.Error) {
// throw new Error(
// `An error occurred while attempting to batch set in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
// );
// }
// }

// async function example_API_GetBatch(cacheClient: CacheClient, cacheName: string) {
// const keys = ['abc', 'xyz', '123', '321'];
// const result = await cacheClient.getBatch(cacheName, keys);
// if (result instanceof GetBatch.Success) {
// const values = result.values();
// for (const key of keys) {
// console.log(`Retrieved value for key '${key}': ${values[key]}`);
// }
// } else if (result instanceof GetBatch.Error) {
// throw new Error(
// `An error occurred while attempting to batch get in cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
// );
// }
// }

async function example_API_ListFetch(cacheClient: CacheClient, cacheName: string) {
await cacheClient.listConcatenateBack(cacheName, 'test-list', ['a', 'b', 'c']);
Expand Down Expand Up @@ -1568,8 +1568,8 @@ async function main() {
await example_API_SetIfNotEqual(cacheClient, cacheName);
await example_API_SetIfPresentAndNotEqual(cacheClient, cacheName);
await example_API_SetIfAbsentOrEqual(cacheClient, cacheName);
await example_API_SetBatch(cacheClient, cacheName);
await example_API_GetBatch(cacheClient, cacheName);
// await example_API_SetBatch(cacheClient, cacheName);
// await example_API_GetBatch(cacheClient, cacheName);

await example_API_ListFetch(cacheClient, cacheName);
await example_API_ListConcatenateBack(cacheClient, cacheName);
Expand Down
8 changes: 4 additions & 4 deletions packages/client-sdk-nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ import * as CacheKeysExist from '@gomomento/sdk-core/dist/src/messages/responses
import * as CacheUpdateTtl from '@gomomento/sdk-core/dist/src/messages/responses/cache-ttl-update';
import * as CacheIncreaseTtl from '@gomomento/sdk-core/dist/src/messages/responses/cache-ttl-increase';
import * as CacheDecreaseTtl from '@gomomento/sdk-core/dist/src/messages/responses/cache-ttl-decrease';
import * as GetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-get';
import * as SetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-set';
import * as CacheGetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-get';
import * as CacheSetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-set';

// TopicClient Response Types
import * as TopicPublish from '@gomomento/sdk-core/dist/src/messages/responses/topic-publish';
Expand Down Expand Up @@ -353,8 +353,8 @@ export {
CacheUpdateTtl,
CacheIncreaseTtl,
CacheDecreaseTtl,
GetBatch,
SetBatch,
CacheGetBatch,
CacheSetBatch,
// TopicClient
TopicConfigurations,
TopicConfiguration,
Expand Down
24 changes: 12 additions & 12 deletions packages/client-sdk-nodejs/src/internal/cache-data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ import {
CollectionTtl,
CompressionLevel,
CredentialProvider,
GetBatch,
CacheGetBatch,
ICompression,
InvalidArgumentError,
ItemType,
MomentoLogger,
MomentoLoggerFactory,
SetBatch,
CacheSetBatch,
SortedSetOrder,
UnknownError,
} from '..';
Expand Down Expand Up @@ -1515,13 +1515,13 @@ export class CacheDataClient implements IDataClient {
public async getBatch(
cacheName: string,
keys: Array<string | Uint8Array>
): Promise<GetBatch.Response> {
): Promise<CacheGetBatch.Response> {
try {
validateCacheName(cacheName);
} catch (err) {
return this.cacheServiceErrorMapper.returnOrThrowError(
err as Error,
err => new GetBatch.Error(err)
err => new CacheGetBatch.Error(err)
);
}

Expand All @@ -1542,7 +1542,7 @@ export class CacheDataClient implements IDataClient {
private async sendGetBatch(
cacheName: string,
keys: Uint8Array[]
): Promise<GetBatch.Response> {
): Promise<CacheGetBatch.Response> {
const getRequests = [];
for (const k of keys) {
const getRequest = new grpcCache._GetRequest({
Expand Down Expand Up @@ -1578,13 +1578,13 @@ export class CacheDataClient implements IDataClient {
});

call.on('end', () => {
resolve(new GetBatch.Success(results, keys));
resolve(new CacheGetBatch.Success(results, keys));
});

call.on('error', (err: ServiceError | null) => {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new GetBatch.Error(e),
errorResponseFactoryFn: e => new CacheGetBatch.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
Expand All @@ -1598,7 +1598,7 @@ export class CacheDataClient implements IDataClient {
| Record<string, string | Uint8Array>
| Map<string | Uint8Array, string | Uint8Array>,
ttl?: number
): Promise<SetBatch.Response> {
): Promise<CacheSetBatch.Response> {
try {
validateCacheName(cacheName);
if (ttl !== undefined) {
Expand All @@ -1607,7 +1607,7 @@ export class CacheDataClient implements IDataClient {
} catch (err) {
return this.cacheServiceErrorMapper.returnOrThrowError(
err as Error,
err => new SetBatch.Error(err)
err => new CacheSetBatch.Error(err)
);
}

Expand All @@ -1630,7 +1630,7 @@ export class CacheDataClient implements IDataClient {
cacheName: string,
items: Record<string, Uint8Array>[],
ttlSeconds: number
): Promise<SetBatch.Response> {
): Promise<CacheSetBatch.Response> {
const setRequests = [];
for (const item of items) {
const setRequest = new grpcCache._SetRequest({
Expand Down Expand Up @@ -1666,13 +1666,13 @@ export class CacheDataClient implements IDataClient {
});

call.on('end', () => {
resolve(new SetBatch.Success(results));
resolve(new CacheSetBatch.Success(results));
});

call.on('error', (err: ServiceError | null) => {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new SetBatch.Error(e),
errorResponseFactoryFn: e => new CacheSetBatch.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
Expand Down
8 changes: 4 additions & 4 deletions packages/client-sdk-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ import * as CacheKeysExist from '@gomomento/sdk-core/dist/src/messages/responses
import * as CacheUpdateTtl from '@gomomento/sdk-core/dist/src/messages/responses/cache-ttl-update';
import * as CacheIncreaseTtl from '@gomomento/sdk-core/dist/src/messages/responses/cache-ttl-increase';
import * as CacheDecreaseTtl from '@gomomento/sdk-core/dist/src/messages/responses/cache-ttl-decrease';
import * as GetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-get';
import * as SetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-set';
import * as CacheGetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-get';
import * as CacheSetBatch from '@gomomento/sdk-core/dist/src/messages/responses/cache-batch-set';

// TopicClient Response Types
import * as TopicPublish from '@gomomento/sdk-core/dist/src/messages/responses/topic-publish';
Expand Down Expand Up @@ -252,8 +252,8 @@ export {
CacheSetIfNotEqual,
CacheSetIfPresentAndNotEqual,
CacheSetIfAbsentOrEqual,
SetBatch,
GetBatch,
CacheSetBatch,
CacheGetBatch,
CacheDelete,
CacheFlush,
CreateCache,
Expand Down
24 changes: 12 additions & 12 deletions packages/client-sdk-web/src/internal/cache-data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import {
SortedSetOrder,
UnknownError,
CacheDictionaryLength,
GetBatch,
SetBatch,
CacheGetBatch,
CacheSetBatch,
} from '..';
import {Configuration} from '../config/configuration';
import {Request, RpcError, UnaryResponse} from 'grpc-web';
Expand Down Expand Up @@ -977,13 +977,13 @@ export class CacheDataClient<
public async getBatch(
cacheName: string,
keys: Array<string | Uint8Array>
): Promise<GetBatch.Response> {
): Promise<CacheGetBatch.Response> {
try {
validateCacheName(cacheName);
} catch (err) {
return this.cacheServiceErrorMapper.returnOrThrowError(
err as Error,
err => new GetBatch.Error(err)
err => new CacheGetBatch.Error(err)
);
}
this.logger.trace(`Issuing 'getBatch' request; keys: ${keys.toString()}`);
Expand All @@ -998,7 +998,7 @@ export class CacheDataClient<
private async sendGetBatch(
cacheName: string,
keys: string[]
): Promise<GetBatch.Response> {
): Promise<CacheGetBatch.Response> {
const getRequests = [];
for (const k of keys) {
const getRequest = new _GetRequest();
Expand Down Expand Up @@ -1033,7 +1033,7 @@ export class CacheDataClient<

call.on('end', () => {
resolve(
new GetBatch.Success(
new CacheGetBatch.Success(
results,
keys.map(key => this.convertToUint8Array(key))
)
Expand All @@ -1043,7 +1043,7 @@ export class CacheDataClient<
call.on('error', (err: RpcError) => {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new GetBatch.Error(e),
errorResponseFactoryFn: e => new CacheGetBatch.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
Expand All @@ -1057,7 +1057,7 @@ export class CacheDataClient<
| Record<string, string | Uint8Array>
| Map<string | Uint8Array, string | Uint8Array>,
ttl?: number
): Promise<SetBatch.Response> {
): Promise<CacheSetBatch.Response> {
try {
validateCacheName(cacheName);
if (ttl !== undefined) {
Expand All @@ -1066,7 +1066,7 @@ export class CacheDataClient<
} catch (err) {
return this.cacheServiceErrorMapper.returnOrThrowError(
err as Error,
err => new SetBatch.Error(err)
err => new CacheSetBatch.Error(err)
);
}

Expand All @@ -1086,7 +1086,7 @@ export class CacheDataClient<
cacheName: string,
items: Record<string, string>[],
ttlSeconds: number
): Promise<SetBatch.Response> {
): Promise<CacheSetBatch.Response> {
const setRequests = [];
for (const item of items) {
const setRequest = new _SetRequest();
Expand Down Expand Up @@ -1121,13 +1121,13 @@ export class CacheDataClient<
});

call.on('end', () => {
resolve(new SetBatch.Success(results));
resolve(new CacheSetBatch.Success(results));
});

call.on('error', (err: RpcError) => {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new SetBatch.Error(e),
errorResponseFactoryFn: e => new CacheSetBatch.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
Expand Down
Loading

0 comments on commit 3a4d470

Please sign in to comment.