Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify JS release #10853

Merged
merged 6 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"lint": "lerna run lint",
"link-all": "yarn unlink-all && lerna exec --no-bail --parallel yarn link",
"unlink-all": "lerna exec --no-bail --parallel -- yarn unlink; exit 0",
"publish:main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=unstable --preid=unstable-v5 --exact --no-verify-access",
"publish:main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=unstable --preid=unstableV5 --exact --no-verify-access",
"publish:next-major-version/5": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=next --preid=next --exact --no-verify-access",
"publish:beta": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=beta --preid=beta --exact --no-verify-access",
"publish:release": "lerna publish --conventional-commits --yes --message 'chore(release): Publish [ci skip]' --no-verify-access",
Expand Down
65 changes: 2 additions & 63 deletions packages/pubsub/__tests__/PubSub-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@ jest.mock('@aws-amplify/core', () => ({
import { PubSubClass as PubSub } from '../src/PubSub';
import {
MqttOverWSProvider,
AWSAppSyncProvider,
AWSIoTProvider,
mqttTopicMatch,
} from '../src/Providers';

import {
Credentials,
Hub,
INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER,
Logger,
Reachability,
} from '@aws-amplify/core';
import { Credentials, Reachability } from '@aws-amplify/core';
import * as Paho from 'paho-mqtt';
import { ConnectionState, CONNECTION_STATE_CHANGE } from '../src';
import { ConnectionState } from '../src';
import { HubConnectionListener } from './helpers';
import Observable from 'zen-observable-ts';
import * as constants from '../src/Providers/constants';
Expand Down Expand Up @@ -87,45 +80,6 @@ const testPubSubAsync = (pubsub, topic, message, options?) =>
pubsub.publish(topic, message, options);
});

const testAppSyncAsync = (pubsub, topic, message) =>
new Promise((resolve, reject) => {
const testUrl = 'wss://appsync';
const testClientId = 'test-client';
const testTopicAlias = 'test-topic-alias';

const subscriptionOptions = {
mqttConnections: [
{
topics: [topic],
client: testClientId,
url: testUrl,
},
],
newSubscriptions: {
[testTopicAlias]: { topic },
},
};

const opt = {
...subscriptionOptions,
provider: INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER,
};

const obs = pubsub.subscribe(topic, opt).subscribe({
next: data => {
expect(data.value.data[testTopicAlias]).toEqual(message);
obs.unsubscribe();
resolve();
},
close: () => console.log('close'),
error: reject,
});

// simulate an AppSync update
const testClient = new Paho.Client(testUrl, testClientId);
testClient.send(topic, JSON.stringify({ data: { testKey: message } }));
});

beforeEach(() => {
const spyon = jest.spyOn(Credentials, 'get').mockImplementation(() => {
return new Promise((res, rej) => {
Expand Down Expand Up @@ -174,12 +128,6 @@ describe('PubSub', () => {
const config = pubsub.configure(options);
expect(config).toEqual(options.PubSub);
});

test('should allow AppSync subscriptions without extra configuration', async () => {
const pubsub = new PubSub();

await testAppSyncAsync(pubsub, 'topicA', 'my message AWSAppSyncProvider');
});
});

describe('AWSIoTProvider', () => {
Expand Down Expand Up @@ -512,16 +460,12 @@ describe('PubSub', () => {
});
pubsub.addPluggable(awsIotProvider);

const awsAppSyncProvider = new AWSAppSyncProvider();
pubsub.addPluggable(awsAppSyncProvider);

const mqttOverWSProvider = new MqttOverWSProvider({
aws_pubsub_endpoint: 'wss://iot.eclipse.org:443/mqtt',
});
pubsub.addPluggable(mqttOverWSProvider);

expect(awsIotProvider.getCategory()).toBe('PubSub');
expect(awsAppSyncProvider.getCategory()).toBe('PubSub');
expect(mqttOverWSProvider.getCategory()).toBe('PubSub');

await testPubSubAsync(pubsub, 'topicA', 'my message AWSIoTProvider', {
Expand All @@ -543,8 +487,6 @@ describe('PubSub', () => {

expect(mqttOverWSProvider.getCategory()).toBe('PubSub');

await testAppSyncAsync(pubsub, 'topicA', 'my message AWSAppSyncProvider');

await testPubSubAsync(pubsub, 'topicA', 'my message MqttOverWSProvider');
});

Expand Down Expand Up @@ -576,9 +518,6 @@ describe('PubSub', () => {
});
pubsub.addPluggable(awsIotProvider);

const awsAppSyncProvider = new AWSAppSyncProvider();
pubsub.addPluggable(awsAppSyncProvider);

const mqttOverWSProvider = new MqttOverWSProvider({
aws_pubsub_endpoint: 'wss://iot.eclipse.org:443/mqtt',
});
Expand Down
21 changes: 1 addition & 20 deletions packages/pubsub/src/PubSub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
Amplify,
browserOrNode,
ConsoleLogger as Logger,
INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER,
INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
} from '@aws-amplify/core';
import { PubSubProvider, PubSubOptions, ProviderOptions } from './types';
import { AWSAppSyncProvider, AWSAppSyncRealTimeProvider } from './Providers';
import { AWSAppSyncRealTimeProvider } from './Providers';

const { isNode } = browserOrNode();
const logger = new Logger('PubSub');
Expand All @@ -21,26 +20,11 @@ export class PubSubClass {

private _pluggables: PubSubProvider[];

/**
* Internal instance of AWSAppSyncProvider used by the API category to subscribe to AppSync
*/
private _awsAppSyncProvider?: AWSAppSyncProvider;

/**
* Internal instance of AWSAppSyncRealTimeProvider used by the API category to subscribe to AppSync
*/
private _awsAppSyncRealTimeProvider?: AWSAppSyncRealTimeProvider;

/**
* Lazy instantiate AWSAppSyncProvider when it is required by the API category
*/
private get awsAppSyncProvider() {
if (!this._awsAppSyncProvider) {
this._awsAppSyncProvider = new AWSAppSyncProvider(this._options);
}
return this._awsAppSyncProvider;
}

/**
* Lazy instantiate AWSAppSyncRealTimeProvider when it is required by the API category
*/
Expand Down Expand Up @@ -111,9 +95,6 @@ export class PubSubClass {
}

private getProviderByName(providerName: string | symbol) {
if (providerName === INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER) {
return this.awsAppSyncProvider;
}
if (providerName === INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER) {
return this.awsAppSyncRealTimeProvider;
}
Expand Down