Skip to content

Commit

Permalink
feat: web sdk topics (#509)
Browse files Browse the repository at this point in the history
* feat: add topics

* feat: adding pubsub client

* chore: refactoring integration test for common use

* chore: update types

* fix: handle 'only once' heders separately for unary vs streaming
  • Loading branch information
pgautier404 authored May 16, 2023
1 parent 9eac48f commit c62ac80
Show file tree
Hide file tree
Showing 26 changed files with 1,040 additions and 339 deletions.
16 changes: 7 additions & 9 deletions packages/client-sdk-nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/client-sdk-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"uuid": "8.3.2"
},
"dependencies": {
"@gomomento/generated-types": "^0.61.0",
"@gomomento/generated-types": "0.61.2",
"@gomomento/sdk-core": "file:../core",
"@grpc/grpc-js": "1.8.14",
"google-protobuf": "3.21.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/client-sdk-nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {CacheClient, SimpleCacheClient} from './cache-client';
import {TopicClient} from './topic-client';
import * as Configurations from './config/configurations';
import {TopicClientProps} from './topic-client-props';

// Cache Client Response Types
import * as CacheGet from '@gomomento/sdk-core/dist/src/messages/responses/cache-get';
Expand Down Expand Up @@ -197,6 +198,7 @@ export {
ItemGetType,
// TopicClient Response types
TopicClient,
TopicClientProps,
TopicItem,
TopicPublish,
TopicSubscribe,
Expand Down
3 changes: 2 additions & 1 deletion packages/client-sdk-nodejs/src/internal/data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ import grpcCache = cache.cache_client;
import _Unbounded = cache_client._Unbounded;
import ECacheResult = cache_client.ECacheResult;
import _ItemGetTypeResponse = cache_client._ItemGetTypeResponse;
import {IDataClient} from '@gomomento/sdk-core/dist/src/internal/clients';

export class DataClient {
export class DataClient implements IDataClient {
private readonly clientWrapper: GrpcClientWrapper<grpcCache.ScsClient>;
private readonly textEncoder: TextEncoder;
private readonly configuration: Configuration;
Expand Down
3 changes: 2 additions & 1 deletion packages/client-sdk-nodejs/src/internal/pubsub-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from '@gomomento/sdk-core/dist/src/internal/utils';
import {normalizeSdkError} from '@gomomento/sdk-core/dist/src/errors';
import {SubscribeCallOptions} from '@gomomento/sdk-core/dist/src/utils';
import {IPubsubClient} from '@gomomento/sdk-core/dist/src/internal/clients';

/**
* Encapsulates parameters for the `sendSubscribe` method.
Expand Down Expand Up @@ -68,7 +69,7 @@ interface PrepareSubscribeCallbackOptions extends SendSubscribeOptions {
firstMessage: boolean;
}

export class PubsubClient {
export class PubsubClient implements IPubsubClient {
private readonly clientWrapper: GrpcClientWrapper<grpcPubsub.PubsubClient>;
private readonly configuration: Configuration;
private readonly credentialProvider: CredentialProvider;
Expand Down
6 changes: 4 additions & 2 deletions packages/client-sdk-nodejs/src/topic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import {
} from '.';
import {PubsubClient} from './internal/pubsub-client';
import {TopicClientProps} from './topic-client-props';
import {ITopicClient} from '@gomomento/sdk-core/dist/src/internal/clients/pubsub/ITopicClient';
import {IPubsubClient} from '@gomomento/sdk-core/dist/src/internal/clients';

/**
* Momento Topic Client.
*
* Publish and subscribe to topics.
*/
export class TopicClient {
export class TopicClient implements ITopicClient {
private readonly logger: MomentoLogger;
private readonly client: PubsubClient;
private readonly client: IPubsubClient;

/**
* Creates an instance of TopicClient.
Expand Down
21 changes: 19 additions & 2 deletions packages/client-sdk-nodejs/test/integration/integration-setup.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {CacheClientProps} from '../../src/cache-client-props';
import {testCacheName} from '@gomomento/common-integration-tests';
import {
AuthClient,
CreateCache,
Configurations,
DeleteCache,
MomentoErrorCode,
CacheClient,
CredentialProvider,
CollectionTtl,
TopicClient,
} from '../../src';
import {AuthClient} from '../../src/auth-client';

const deleteCacheIfExists = async (momento: CacheClient, cacheName: string) => {
const deleteResponse = await momento.deleteCache(cacheName);
if (deleteResponse instanceof DeleteCache.Error) {
Expand Down Expand Up @@ -52,6 +52,13 @@ function momentoAuthClientForTesting(): AuthClient {
return new AuthClient();
}

function momentoTopicClientForTesting(): TopicClient {
return new TopicClient({
configuration: IntegrationTestCacheClientProps.configuration,
credentialProvider: IntegrationTestCacheClientProps.credentialProvider,
});
}

export function SetupIntegrationTest(): {
Momento: CacheClient;
IntegrationTestCacheName: string;
Expand Down Expand Up @@ -81,6 +88,16 @@ export function SetupIntegrationTest(): {
return {Momento: client, IntegrationTestCacheName: cacheName};
}

export function SetupTopicIntegrationTest(): {
topicClient: TopicClient;
Momento: CacheClient;
IntegrationTestCacheName: string;
} {
const {Momento, IntegrationTestCacheName} = SetupIntegrationTest();
const topicClient = momentoTopicClientForTesting();
return {topicClient, Momento, IntegrationTestCacheName};
}

export function SetupAuthIntegrationTest(): {
authClient: AuthClient;
sessionToken: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {runTopicClientTests} from '@gomomento/common-integration-tests';
import {SetupTopicIntegrationTest} from '../integration-setup';

const {topicClient, Momento, IntegrationTestCacheName} =
SetupTopicIntegrationTest();
runTopicClientTests(topicClient, Momento, IntegrationTestCacheName);
Loading

0 comments on commit c62ac80

Please sign in to comment.