Skip to content

Commit f6c0dbd

Browse files
justandrasJulusian
andcommitted
fix: add unknown notification target type default case
Co-authored-by: Julian Waller <[email protected]>
1 parent 2a480c8 commit f6c0dbd

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

packages/live-status-gateway-api/api/schemas/notifications.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ $defs:
7979
- $ref: '#/$defs/NotificationTargetRundownPlaylist'
8080
- $ref: '#/$defs/NotificationTargetPartInstance'
8181
- $ref: '#/$defs/NotificationTargetPieceInstance'
82+
- $ref: '#/$defs/NotificationTargetUnknown'
8283
examples:
8384
- $ref: '#/$defs/NotificationTargetRundown/examples/0'
8485
- $ref: '#/$defs/NotificationTargetRundownPlaylist/examples/0'
8586
- $ref: '#/$defs/NotificationTargetPartInstance/examples/0'
8687
- $ref: '#/$defs/NotificationTargetPieceInstance/examples/0'
88+
- $ref: '#/$defs/NotificationTargetUnknown/examples/0'
8789

8890
NotificationTargetType:
8991
type: string
@@ -94,6 +96,7 @@ $defs:
9496
- playlist
9597
- partInstance
9698
- pieceInstance
99+
- unknown
97100

98101
NotificationTargetRundown:
99102
type: object
@@ -175,3 +178,15 @@ $defs:
175178
rundownId: rd123
176179
partInstanceId: pi789
177180
pieceInstanceId: pc1011
181+
182+
NotificationTargetUnknown:
183+
type: object
184+
title: NotificationTargetUnknown
185+
required: [type]
186+
properties:
187+
type:
188+
$ref: '#/$defs/NotificationTargetType'
189+
enum: [unknown]
190+
additionalProperties: false
191+
examples:
192+
- type: unknown

packages/live-status-gateway-api/src/generated/schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ interface NotificationObj {
760760
| NotificationTargetRundownPlaylist
761761
| NotificationTargetPartInstance
762762
| NotificationTargetPieceInstance
763+
| NotificationTargetUnknown
763764
/**
764765
* Unix timestamp of creation
765766
*/
@@ -796,6 +797,7 @@ enum NotificationTargetType {
796797
PLAYLIST = 'playlist',
797798
PART_INSTANCE = 'partInstance',
798799
PIECE_INSTANCE = 'pieceInstance',
800+
UNKNOWN = 'unknown',
799801
}
800802

801803
interface NotificationTargetRundownPlaylist {
@@ -828,6 +830,13 @@ interface NotificationTargetPieceInstance {
828830
pieceInstanceId: string
829831
}
830832

833+
interface NotificationTargetUnknown {
834+
/**
835+
* Possible NotificationTarget types
836+
*/
837+
type: NotificationTargetType
838+
}
839+
831840
export {
832841
Slash,
833842
PongEvent,
@@ -877,4 +886,5 @@ export {
877886
NotificationTargetRundownPlaylist,
878887
NotificationTargetPartInstance,
879888
NotificationTargetPieceInstance,
889+
NotificationTargetUnknown,
880890
}

packages/live-status-gateway/src/topics/helpers/notification/notificationTarget/toNotificationTarget.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import {
1212
NotificationTargetRundown,
1313
NotificationTargetRundownPlaylist,
1414
NotificationTargetType,
15+
NotificationTargetUnknown,
1516
} from '@sofie-automation/live-status-gateway-api'
16-
import { literal, unprotectString } from '@sofie-automation/server-core-integration'
17+
import { assertNever, literal, unprotectString } from '@sofie-automation/server-core-integration'
1718

1819
type NotificationTarget =
1920
| NotificationTargetRundown
2021
| NotificationTargetRundownPlaylist
2122
| NotificationTargetPartInstance
2223
| NotificationTargetPieceInstance
2324

24-
export function toNotificationTarget(dbTarget: DBNotificationTarget): NotificationTarget {
25+
export function toNotificationTarget(dbTarget: DBNotificationTarget): NotificationTarget | NotificationTargetUnknown {
2526
switch (dbTarget.type) {
2627
case DBNotificationTargetType.PARTINSTANCE:
2728
return toNotificationTargetPartInstance(dbTarget)
@@ -31,6 +32,9 @@ export function toNotificationTarget(dbTarget: DBNotificationTarget): Notificati
3132
return toNotificationTargetPlaylist(dbTarget)
3233
case DBNotificationTargetType.PIECEINSTANCE:
3334
return toNotificationTargetPieceInstance(dbTarget)
35+
default:
36+
assertNever(dbTarget)
37+
return literal<NotificationTargetUnknown>({ type: NotificationTargetType.UNKNOWN })
3438
}
3539
}
3640

packages/live-status-gateway/src/topics/helpers/notification/toNotificationStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NotificationObj, NotificationSeverity } from '@sofie-automation/live-st
55
import { literal, unprotectString } from '@sofie-automation/server-core-integration'
66
import { toNotificationTarget } from './notificationTarget/toNotificationTarget.js'
77

8-
export function toNotificationStatus(dbNotification: DBNotificationObj): NotificationObj {
8+
export function toNotificationStatus(dbNotification: DBNotificationObj): NotificationObj | undefined {
99
return literal<NotificationObj>({
1010
_id: unprotectString(dbNotification._id),
1111
severity: toNotificationSeverity(dbNotification.severity),

packages/live-status-gateway/src/topics/notificationsTopic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export class NotificationsTopic extends WebSocketTopicBase implements WebSocketT
2727
sendStatus(subscribers: Iterable<WebSocket>): void {
2828
const message = literal<NotificationsEvent>({
2929
event: 'notifications',
30-
activeNotifications: this._notifications.map(toNotificationStatus),
30+
activeNotifications: this._notifications
31+
.map(toNotificationStatus)
32+
.filter((notification) => notification !== undefined),
3133
})
3234

3335
this.sendMessage(subscribers, message)

0 commit comments

Comments
 (0)