@ovok/core 0.4.49-dev.524 → 0.4.49-dev.525

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.
@@ -26,7 +26,7 @@ exports.OVOK_CORE_REQUIREMENTS = {
26
26
  description: "The FHIR surface a server must provide for the @ovok/core client library's own methods to function.",
27
27
  software: {
28
28
  name: "@ovok/core",
29
- version: "0.4.49-dev.524+a989d15",
29
+ version: "0.4.49-dev.525+7eb412c",
30
30
  },
31
31
  fhirVersion: "4.0.1",
32
32
  format: ["json"],
@@ -77,20 +77,21 @@ class RealtimeSocket {
77
77
  this.waitingForPong = false;
78
78
  return;
79
79
  }
80
- if (!isSubscriptionStatus(message)) {
80
+ if (!isStatusBundle(message)) {
81
81
  socket.close();
82
82
  return;
83
83
  }
84
- if (message.type === "handshake") {
84
+ const [{ resource: status }, ...changes] = message.entry;
85
+ if (status.type === "handshake") {
85
86
  this.clearHandshakeTimer();
86
87
  this.onHandshake();
87
88
  return;
88
89
  }
89
- if (message.type === "heartbeat") {
90
+ if (status.type === "heartbeat") {
90
91
  return;
91
92
  }
92
- if (message.type === "event-notification") {
93
- this.handler({ ...message, type: "event-notification" });
93
+ if (status.type === "event-notification") {
94
+ this.handler({ ...status, type: "event-notification", resources: changedResources(changes) });
94
95
  }
95
96
  }
96
97
  socketClosed(socket) {
@@ -150,3 +151,9 @@ const isSubscriptionStatus = (value) => {
150
151
  typeof value.type === "string" &&
151
152
  typeof value.subscription.reference === "string");
152
153
  };
154
+ const isStatusBundle = (value) => value.resourceType === "Bundle" &&
155
+ Array.isArray(value.entry) &&
156
+ isRecord(value.entry[0]) &&
157
+ isSubscriptionStatus(value.entry[0].resource);
158
+ const isResource = (value) => isRecord(value) && typeof value.resourceType === "string";
159
+ const changedResources = (entries) => entries.flatMap((entry) => (isRecord(entry) && isResource(entry.resource) ? [entry.resource] : []));
@@ -1,4 +1,4 @@
1
- import type { SubscriptionStatus } from "@medplum/fhirtypes";
1
+ import type { Resource, SubscriptionStatus } from "@medplum/fhirtypes";
2
2
  /**
3
3
  * A notification that a resource matching a subscription changed.
4
4
  *
@@ -7,6 +7,8 @@ import type { SubscriptionStatus } from "@medplum/fhirtypes";
7
7
  export type RealtimeNotification = SubscriptionStatus & {
8
8
  /** Always `"event-notification"`. */
9
9
  type: "event-notification";
10
+ /** The changed resources sent with the notification, in the order the server sent them. */
11
+ resources: Resource[];
10
12
  };
11
13
  /**
12
14
  * Callback invoked for each realtime notification.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.49-dev.524+a989d15",
3
+ "version": "0.4.49-dev.525+7eb412c",
4
4
  "private": false,
5
5
  "main": "dist/next/index.js",
6
6
  "types": "dist/next/index.d.ts",