wirejs-deploy-amplify-basic 0.0.92-realtime → 0.0.94-realtime

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.
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.1",
5
5
  "wirejs-dom": "^1.0.41",
6
- "wirejs-resources": "^0.1.60-realtime"
6
+ "wirejs-resources": "^0.1.62-realtime"
7
7
  }
8
8
  }
@@ -82,14 +82,23 @@ export function subscribe(url, channel, token, subscriber) {
82
82
  }
83
83
  if (!channelSubs.has(channel)) {
84
84
  const subscriptionId = crypto.randomUUID();
85
- connections.get(url).send(JSON.stringify({
86
- id: subscriptionId,
87
- type: 'subscribe',
88
- channel,
89
- authorization
90
- }));
91
- channelSubs.set(fullChannelName, subscriptionId);
92
- subscribers.set(subscriptionId, []);
85
+ const ws = connections.get(url);
86
+ const subscribe = () => {
87
+ ws.send(JSON.stringify({
88
+ id: subscriptionId,
89
+ type: 'subscribe',
90
+ channel,
91
+ authorization
92
+ }));
93
+ channelSubs.set(fullChannelName, subscriptionId);
94
+ subscribers.set(subscriptionId, []);
95
+ };
96
+ if (ws.readyState === WebSocket.OPEN) {
97
+ subscribe();
98
+ }
99
+ else {
100
+ ws.addEventListener('open', subscribe);
101
+ }
93
102
  }
94
103
  subscribers.get(fullChannelName).push(subscriber);
95
104
  }
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from 'wirejs-resources';
2
2
  export { FileService } from './services/file.js';
3
3
  export { AuthenticationService } from './services/authentication.js';
4
4
  export { DistributedTable } from './resources/distributed-table.js';
5
+ export { RealtimeService } from './services/realtime.js';
package/dist/index.js CHANGED
@@ -8,7 +8,10 @@ import { AuthenticationService } from './services/authentication.js';
8
8
  export { AuthenticationService } from './services/authentication.js';
9
9
  import { DistributedTable } from './resources/distributed-table.js';
10
10
  export { DistributedTable } from './resources/distributed-table.js';
11
+ import { RealtimeService } from './services/realtime.js';
12
+ export { RealtimeService } from './services/realtime.js';
11
13
  // expose resources to other resources that might depend on it.
12
14
  overrides.AuthenticationService = AuthenticationService;
13
15
  overrides.DistributedTable = DistributedTable;
14
16
  overrides.FileService = FileService;
17
+ overrides.RealtimeService = RealtimeService;
@@ -7,6 +7,6 @@ export declare class RealtimeService<T = any> extends Resource {
7
7
  * The address the client will need to connect to.
8
8
  */
9
9
  get address(): string;
10
- publish(channel: string, events: T[]): Promise<void>;
10
+ publish(channel: string, data: T | T[]): Promise<void>;
11
11
  getStream(channel: string): Promise<any>;
12
12
  }
@@ -1,10 +1,10 @@
1
1
  import * as jose from 'jose';
2
2
  import { Resource, Secret } from 'wirejs-resources';
3
- import { addResource } from '../resource-collector.js';
4
3
  import { SignatureV4 } from '@aws-sdk/signature-v4';
5
4
  import { HttpRequest } from '@aws-sdk/protocol-http';
6
5
  import { defaultProvider } from '@aws-sdk/credential-provider-node';
7
6
  import { Sha256 } from '@aws-crypto/sha256-js';
7
+ import { addResource } from '../resource-collector.js';
8
8
  export const SECRET_ID = 'realtime-secret';
9
9
  export class RealtimeService extends Resource {
10
10
  #secret;
@@ -37,9 +37,10 @@ export class RealtimeService extends Resource {
37
37
  get address() {
38
38
  return `ws://${process.env.REALTIME_WS_DOMAIN}/event`;
39
39
  }
40
- async publish(channel, events) {
40
+ async publish(channel, data) {
41
41
  this.#validateChannelName(channel);
42
42
  console.log('Publishing to channels:', channel);
43
+ const events = Array.isArray(data) ? data : [data];
43
44
  // AppSync allows batches of no more than 5. Hence, if we have more than 5,
44
45
  // we need to perform batching on our end.
45
46
  if (events.length > 5) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.0.92-realtime",
3
+ "version": "0.0.94-realtime",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "recursive-copy": "^2.0.14",
42
42
  "rimraf": "^6.0.1",
43
43
  "wirejs-dom": "^1.0.41",
44
- "wirejs-resources": "^0.1.60-realtime"
44
+ "wirejs-resources": "^0.1.62-realtime"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@aws-amplify/backend": "^1.14.0",