@aws-amplify/pubsub 5.5.6-api-v6-models.b3abc9b.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/iot/packages.json +7 -0
  2. package/lib/Providers/AWSIot.d.ts +10 -0
  3. package/lib/Providers/AWSIot.js +34 -0
  4. package/lib/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +16 -16
  5. package/lib/Providers/MqttOverWS.js +274 -0
  6. package/lib/Providers/PubSub.d.ts +11 -0
  7. package/lib/Providers/PubSub.js +19 -0
  8. package/lib/Providers/constants.d.ts +1 -1
  9. package/lib/Providers/constants.js +3 -4
  10. package/lib/Providers/index.d.ts +3 -4
  11. package/lib/Providers/index.js +8 -10
  12. package/lib/clients/iot.d.ts +1 -0
  13. package/lib/clients/iot.js +7 -0
  14. package/lib/clients/mqtt.d.ts +1 -0
  15. package/lib/clients/mqtt.js +7 -0
  16. package/lib/index.d.ts +2 -2
  17. package/lib/index.js +7 -11
  18. package/lib/tsconfig.tsbuildinfo +1 -0
  19. package/lib/types/PubSub.d.ts +21 -3
  20. package/lib/types/PubSub.js +1 -1
  21. package/lib/types/index.d.ts +0 -1
  22. package/lib/types/index.js +5 -3
  23. package/lib/utils/ConnectionStateMonitor.d.ts +5 -5
  24. package/lib/utils/ConnectionStateMonitor.js +52 -64
  25. package/lib/utils/ReachabilityMonitor/index.d.ts +1 -3
  26. package/lib/utils/ReachabilityMonitor/index.js +4 -3
  27. package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -3
  28. package/lib/utils/ReachabilityMonitor/index.native.js +7 -8
  29. package/lib/utils/ReconnectionMonitor.d.ts +1 -1
  30. package/lib/utils/ReconnectionMonitor.js +21 -25
  31. package/lib-esm/Providers/AWSIot.d.ts +10 -0
  32. package/lib-esm/Providers/AWSIot.js +30 -0
  33. package/lib-esm/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +16 -16
  34. package/lib-esm/Providers/MqttOverWS.js +268 -0
  35. package/lib-esm/Providers/PubSub.d.ts +11 -0
  36. package/lib-esm/Providers/PubSub.js +15 -0
  37. package/lib-esm/Providers/constants.d.ts +1 -1
  38. package/lib-esm/Providers/constants.js +11 -14
  39. package/lib-esm/Providers/index.d.ts +3 -4
  40. package/lib-esm/Providers/index.js +3 -5
  41. package/lib-esm/clients/iot.d.ts +1 -0
  42. package/{src/internals/index.ts → lib-esm/clients/iot.js} +1 -1
  43. package/lib-esm/clients/mqtt.d.ts +1 -0
  44. package/lib-esm/{internals/index.js → clients/mqtt.js} +1 -2
  45. package/lib-esm/index.d.ts +2 -2
  46. package/lib-esm/index.js +2 -3
  47. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  48. package/lib-esm/types/PubSub.d.ts +21 -3
  49. package/lib-esm/types/PubSub.js +0 -1
  50. package/lib-esm/types/index.d.ts +0 -1
  51. package/lib-esm/types/index.js +2 -1
  52. package/lib-esm/utils/ConnectionStateMonitor.d.ts +5 -5
  53. package/lib-esm/utils/ConnectionStateMonitor.js +50 -64
  54. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -3
  55. package/lib-esm/utils/ReachabilityMonitor/index.js +2 -3
  56. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -3
  57. package/lib-esm/utils/ReachabilityMonitor/index.native.js +2 -5
  58. package/lib-esm/utils/ReconnectionMonitor.d.ts +1 -1
  59. package/lib-esm/utils/ReconnectionMonitor.js +19 -25
  60. package/mqtt/packages.json +7 -0
  61. package/package.json +146 -126
  62. package/src/Providers/{AWSIotProvider.ts → AWSIot.ts} +17 -15
  63. package/src/Providers/{MqttOverWSProvider.ts → MqttOverWS.ts} +38 -50
  64. package/src/Providers/PubSub.ts +40 -0
  65. package/src/Providers/constants.ts +2 -6
  66. package/src/Providers/index.ts +3 -12
  67. package/src/clients/iot.ts +4 -0
  68. package/src/clients/mqtt.ts +7 -0
  69. package/src/index.ts +3 -12
  70. package/src/types/PubSub.ts +28 -5
  71. package/src/types/index.ts +0 -1
  72. package/src/utils/ConnectionStateMonitor.ts +17 -13
  73. package/src/utils/ReachabilityMonitor/index.native.ts +2 -1
  74. package/src/utils/ReachabilityMonitor/index.ts +1 -1
  75. package/src/utils/ReconnectionMonitor.ts +1 -1
  76. package/internals/package.json +0 -8
  77. package/lib/.tsbuildinfo +0 -3
  78. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -77
  79. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +0 -856
  80. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +0 -1
  81. package/lib/Providers/AWSIotProvider.d.ts +0 -11
  82. package/lib/Providers/AWSIotProvider.js +0 -53
  83. package/lib/Providers/AWSIotProvider.js.map +0 -1
  84. package/lib/Providers/MqttOverWSProvider.js +0 -396
  85. package/lib/Providers/MqttOverWSProvider.js.map +0 -1
  86. package/lib/Providers/PubSubProvider.d.ts +0 -15
  87. package/lib/Providers/PubSubProvider.js +0 -28
  88. package/lib/Providers/PubSubProvider.js.map +0 -1
  89. package/lib/Providers/constants.js.map +0 -1
  90. package/lib/Providers/index.js.map +0 -1
  91. package/lib/PubSub.d.ts +0 -13
  92. package/lib/PubSub.js +0 -22
  93. package/lib/PubSub.js.map +0 -1
  94. package/lib/index.js.map +0 -1
  95. package/lib/internals/InternalPubSub.d.ts +0 -50
  96. package/lib/internals/InternalPubSub.js +0 -136
  97. package/lib/internals/InternalPubSub.js.map +0 -1
  98. package/lib/internals/index.d.ts +0 -1
  99. package/lib/internals/index.js +0 -8
  100. package/lib/internals/index.js.map +0 -1
  101. package/lib/types/Provider.d.ts +0 -18
  102. package/lib/types/Provider.js +0 -3
  103. package/lib/types/Provider.js.map +0 -1
  104. package/lib/types/PubSub.js.map +0 -1
  105. package/lib/types/index.js.map +0 -1
  106. package/lib/utils/ConnectionStateMonitor.js.map +0 -1
  107. package/lib/utils/ReachabilityMonitor/index.js.map +0 -1
  108. package/lib/utils/ReachabilityMonitor/index.native.js.map +0 -1
  109. package/lib/utils/ReconnectionMonitor.js.map +0 -1
  110. package/lib/vendor/paho-mqtt.d.ts +0 -2
  111. package/lib/vendor/paho-mqtt.js.map +0 -1
  112. package/lib-esm/.tsbuildinfo +0 -3
  113. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -77
  114. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +0 -854
  115. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +0 -1
  116. package/lib-esm/Providers/AWSIotProvider.d.ts +0 -11
  117. package/lib-esm/Providers/AWSIotProvider.js +0 -51
  118. package/lib-esm/Providers/AWSIotProvider.js.map +0 -1
  119. package/lib-esm/Providers/MqttOverWSProvider.js +0 -393
  120. package/lib-esm/Providers/MqttOverWSProvider.js.map +0 -1
  121. package/lib-esm/Providers/PubSubProvider.d.ts +0 -15
  122. package/lib-esm/Providers/PubSubProvider.js +0 -26
  123. package/lib-esm/Providers/PubSubProvider.js.map +0 -1
  124. package/lib-esm/Providers/constants.js.map +0 -1
  125. package/lib-esm/Providers/index.js.map +0 -1
  126. package/lib-esm/PubSub.d.ts +0 -13
  127. package/lib-esm/PubSub.js +0 -20
  128. package/lib-esm/PubSub.js.map +0 -1
  129. package/lib-esm/index.js.map +0 -1
  130. package/lib-esm/internals/InternalPubSub.d.ts +0 -50
  131. package/lib-esm/internals/InternalPubSub.js +0 -134
  132. package/lib-esm/internals/InternalPubSub.js.map +0 -1
  133. package/lib-esm/internals/index.d.ts +0 -1
  134. package/lib-esm/internals/index.js.map +0 -1
  135. package/lib-esm/types/Provider.d.ts +0 -18
  136. package/lib-esm/types/Provider.js +0 -1
  137. package/lib-esm/types/Provider.js.map +0 -1
  138. package/lib-esm/types/PubSub.js.map +0 -1
  139. package/lib-esm/types/index.js.map +0 -1
  140. package/lib-esm/utils/ConnectionStateMonitor.js.map +0 -1
  141. package/lib-esm/utils/ReachabilityMonitor/index.js.map +0 -1
  142. package/lib-esm/utils/ReachabilityMonitor/index.native.js.map +0 -1
  143. package/lib-esm/utils/ReconnectionMonitor.js.map +0 -1
  144. package/lib-esm/vendor/paho-mqtt.d.ts +0 -2
  145. package/lib-esm/vendor/paho-mqtt.js.map +0 -1
  146. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +0 -1049
  147. package/src/Providers/PubSubProvider.ts +0 -53
  148. package/src/PubSub.ts +0 -33
  149. package/src/internals/InternalPubSub.ts +0 -185
  150. package/src/types/Provider.ts +0 -37
@@ -1,53 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import Observable from 'zen-observable-ts';
4
- import { PubSubProvider, ProviderOptions } from '../types/Provider';
5
- import {
6
- CustomUserAgentDetails,
7
- ConsoleLogger as Logger,
8
- } from '@aws-amplify/core';
9
- import { PubSubContent } from '../types/PubSub';
10
-
11
- const logger = new Logger('AbstractPubSubProvider');
12
-
13
- export abstract class AbstractPubSubProvider<T extends ProviderOptions>
14
- implements PubSubProvider
15
- {
16
- private _config: T;
17
-
18
- constructor(options: T) {
19
- this._config = options;
20
- }
21
-
22
- configure(config: T): T {
23
- this._config = { ...config, ...this._config };
24
-
25
- logger.debug(`configure ${this.getProviderName()}`, this._config);
26
-
27
- return this.options;
28
- }
29
-
30
- getCategory() {
31
- return 'PubSub';
32
- }
33
-
34
- abstract getProviderName(): string;
35
-
36
- protected get options(): T {
37
- return { ...this._config };
38
- }
39
-
40
- public abstract newClient(clientOptions: T): Promise<any>;
41
-
42
- public abstract publish(
43
- topics: string[] | string,
44
- msg: PubSubContent,
45
- options?: T
46
- ): void;
47
-
48
- public abstract subscribe(
49
- topics: string[] | string,
50
- options?: T,
51
- customUserAgentDetails?: CustomUserAgentDetails
52
- ): Observable<PubSubContent>;
53
- }
package/src/PubSub.ts DELETED
@@ -1,33 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- // import '../Common/Polyfills';
4
- import Observable from 'zen-observable-ts';
5
-
6
- import {
7
- Amplify,
8
- browserOrNode,
9
- ConsoleLogger as Logger,
10
- } from '@aws-amplify/core';
11
- import { PubSubProvider, ProviderOptions } from './types';
12
- import { InternalPubSubClass } from './internals';
13
-
14
- type PubSubObservable = {
15
- provider: PubSubProvider;
16
- value: string | Record<string, unknown>;
17
- };
18
-
19
- export class PubSubClass extends InternalPubSubClass {
20
- public getModuleName() {
21
- return 'PubSub';
22
- }
23
-
24
- subscribe(
25
- topics: string[] | string,
26
- options?: ProviderOptions
27
- ): Observable<PubSubObservable> {
28
- return super.subscribe(topics, options);
29
- }
30
- }
31
-
32
- export const PubSub = new PubSubClass();
33
- Amplify.register(PubSub);
@@ -1,185 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import {
4
- Amplify,
5
- browserOrNode,
6
- Category,
7
- ConsoleLogger as Logger,
8
- CustomUserAgentDetails,
9
- INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
10
- PubSubAction,
11
- } from '@aws-amplify/core';
12
- import { PubSubProvider, PubSubOptions, ProviderOptions } from '../types';
13
- import { AWSAppSyncRealTimeProvider } from '../Providers';
14
- import { PubSubContent } from '../types/PubSub';
15
- import Observable from 'zen-observable-ts';
16
-
17
- const { isNode } = browserOrNode();
18
- const logger = new Logger('PubSub');
19
-
20
- type PubSubObservable = {
21
- provider: PubSubProvider;
22
- value: string | Record<string, unknown>;
23
- };
24
-
25
- export class InternalPubSubClass {
26
- private _options: PubSubOptions;
27
-
28
- private _pluggables: PubSubProvider[];
29
-
30
- /**
31
- * Internal instance of AWSAppSyncRealTimeProvider used by the API category to subscribe to AppSync
32
- */
33
- private _awsAppSyncRealTimeProvider?: AWSAppSyncRealTimeProvider;
34
-
35
- /**
36
- * Lazy instantiate AWSAppSyncRealTimeProvider when it is required by the API category
37
- */
38
- private get awsAppSyncRealTimeProvider() {
39
- if (!this._awsAppSyncRealTimeProvider) {
40
- this._awsAppSyncRealTimeProvider = new AWSAppSyncRealTimeProvider(
41
- this._options
42
- );
43
- }
44
- return this._awsAppSyncRealTimeProvider;
45
- }
46
-
47
- /**
48
- * Initialize PubSub with AWS configurations
49
- *
50
- * @param {PubSubOptions} options - Configuration object for PubSub
51
- */
52
- constructor(options?: PubSubOptions) {
53
- this._options = options ?? {};
54
- logger.debug('PubSub Options', this._options);
55
- this._pluggables = [];
56
- this.subscribe = this.subscribe.bind(this);
57
- }
58
-
59
- public getModuleName() {
60
- return 'InternalPubSub';
61
- }
62
-
63
- /**
64
- * Configure PubSub part with configurations
65
- *
66
- * @param {PubSubOptions} config - Configuration for PubSub
67
- * @return {Object} - The current configuration
68
- */
69
- configure(options: PubSubOptions) {
70
- const opt: Record<string, unknown> = options
71
- ? options.PubSub || options
72
- : {};
73
- logger.debug('configure PubSub', { opt });
74
-
75
- this._options = Object.assign({}, this._options, opt);
76
-
77
- this._pluggables.map(pluggable => pluggable.configure(this._options));
78
-
79
- return this._options;
80
- }
81
-
82
- /**
83
- * add plugin into Analytics category
84
- * @param {Object} pluggable - an instance of the plugin
85
- */
86
- public async addPluggable(pluggable: PubSubProvider) {
87
- if (pluggable && pluggable.getCategory() === 'PubSub') {
88
- this._pluggables.push(pluggable);
89
-
90
- const config = pluggable.configure(this._options);
91
-
92
- return config;
93
- }
94
- }
95
-
96
- /**
97
- * remove plugin from PubSub category
98
- * @param providerName - the name of the plugin
99
- */
100
- removePluggable(providerName: string): void {
101
- this._pluggables = this._pluggables.filter(
102
- pluggable => pluggable.getProviderName() !== providerName
103
- );
104
- }
105
-
106
- private getProviderByName(providerName: string | symbol) {
107
- if (providerName === INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER) {
108
- return this.awsAppSyncRealTimeProvider;
109
- }
110
-
111
- return this._pluggables.find(
112
- pluggable => pluggable.getProviderName() === providerName
113
- );
114
- }
115
-
116
- private getProviders(options: ProviderOptions = {}) {
117
- const providerName = options.provider;
118
- if (!providerName) {
119
- return this._pluggables;
120
- }
121
-
122
- const provider = this.getProviderByName(providerName);
123
- if (!provider) {
124
- throw new Error(`Could not find provider named ${String(providerName)}`);
125
- }
126
-
127
- return [provider];
128
- }
129
-
130
- async publish(
131
- topics: string[] | string,
132
- msg: PubSubContent,
133
- options?: ProviderOptions
134
- ) {
135
- return Promise.all(
136
- this.getProviders(options).map(provider =>
137
- provider.publish(topics, msg, options)
138
- )
139
- );
140
- }
141
-
142
- subscribe(
143
- topics: string[] | string,
144
- options?: ProviderOptions,
145
- customUserAgentDetails?: CustomUserAgentDetails
146
- ): Observable<PubSubObservable> {
147
- if (isNode && this._options && this._options.ssr) {
148
- throw new Error(
149
- 'Subscriptions are not supported for Server-Side Rendering (SSR)'
150
- );
151
- }
152
-
153
- logger.debug('subscribe options', options);
154
-
155
- const providers = this.getProviders(options);
156
-
157
- const pubSubUserAgentDetails: CustomUserAgentDetails = {
158
- category: Category.PubSub,
159
- action: PubSubAction.Subscribe,
160
- ...customUserAgentDetails,
161
- };
162
-
163
- return new Observable<PubSubObservable>(observer => {
164
- const observables = providers.map(provider => ({
165
- provider,
166
- observable: provider.subscribe(topics, options, pubSubUserAgentDetails),
167
- }));
168
-
169
- const subscriptions = observables.map(({ provider, observable }) =>
170
- observable.subscribe({
171
- start: console.error,
172
- next: (value: PubSubContent) => observer.next({ provider, value }),
173
- error: (error: unknown) => observer.error({ provider, error }),
174
- // complete: observer.complete, // TODO: when all completed, complete the outer one
175
- })
176
- );
177
-
178
- return () =>
179
- subscriptions.forEach(subscription => subscription.unsubscribe());
180
- });
181
- }
182
- }
183
-
184
- export const InternalPubSub = new InternalPubSubClass();
185
- Amplify.register(InternalPubSub);
@@ -1,37 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import Observable from 'zen-observable-ts';
4
- import { PubSubContent } from './PubSub';
5
-
6
- export interface PubSubOptions {
7
- [key: string]: any;
8
- ssr?: boolean;
9
- PubSub?: {};
10
- }
11
-
12
- export interface ProviderOptions {
13
- [key: string]: any;
14
- provider?: string | symbol;
15
- }
16
-
17
- export interface PubSubProvider {
18
- // configure your provider
19
- configure(config: Record<string, unknown>): Record<string, unknown>;
20
-
21
- // return 'Analytics';
22
- getCategory(): string;
23
-
24
- // return the name of you provider
25
- getProviderName(): string;
26
-
27
- publish(
28
- topics: string[] | string,
29
- msg: PubSubContent,
30
- options?: ProviderOptions
31
- ): void;
32
-
33
- subscribe(
34
- topics: string[] | string,
35
- options?: ProviderOptions
36
- ): Observable<PubSubContent>;
37
- }