Skip to content

Commit

Permalink
feat: Use strings for DeviceType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Lee committed Jun 13, 2023
1 parent 36ff5e4 commit f1b95bc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Usage of library', () => {

// Note that the command 'yarn types-build' must have been run for these tests to pass
test('types', () => {
expect(Types_DeviceType.ATEM).toEqual(2)
expect(Types_DeviceType.ATEM).toEqual('ATEM')

// Expect these types to work:
const obj: TSRTimelineObj<TimelineContentEmpty> = {
Expand All @@ -23,6 +23,6 @@ describe('Usage of library', () => {
classes: [],
}
const tl: TSRTimeline = [obj]
expect(tl[0].content.deviceType).toEqual(0)
expect(tl[0].content.deviceType).toEqual('ABSTRACT')
})
})
44 changes: 22 additions & 22 deletions packages/timeline-state-resolver-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ export * from './translations'
export * from './generated'

export enum DeviceType {
ABSTRACT = 0,
CASPARCG = 1,
ATEM = 2,
LAWO = 3,
HTTPSEND = 4,
PANASONIC_PTZ = 5,
TCPSEND = 6,
HYPERDECK = 7,
PHAROS = 8,
OSC = 9,
HTTPWATCHER = 10,
SISYFOS = 11,
QUANTEL = 12,
VIZMSE = 13,
SINGULAR_LIVE = 14,
SHOTOKU = 15,
VMIX = 20,
OBS = 21,
SOFIE_CHEF = 22,
TELEMETRICS = 23,
TRICASTER = 24,
MULTI_OSC = 25,
ABSTRACT = 'ABSTRACT',
CASPARCG = 'CASPARCG',
ATEM = 'ATEM',
LAWO = 'LAWO',
HTTPSEND = 'HTTPSEND',
PANASONIC_PTZ = 'PANASONIC_PTZ',
TCPSEND = 'TCPSEND',
HYPERDECK = 'HYPERDECK',
PHAROS = 'PHAROS',
OSC = 'OSC',
HTTPWATCHER = 'HTTPWATCHER',
SISYFOS = 'SISYFOS',
QUANTEL = 'QUANTEL',
VIZMSE = 'VIZMSE',
SINGULAR_LIVE = 'SINGULAR_LIVE',
SHOTOKU = 'SHOTOKU',
VMIX = 'VMIX',
OBS = 'OBS',
SOFIE_CHEF = 'SOFIE_CHEF',
TELEMETRICS = 'TELEMETRICS',
TRICASTER = 'TRICASTER',
MULTI_OSC = 'MULTI_OSC',
}

export type TSRTimelineKeyframe<TContent> = Timeline.TimelineKeyframe<TContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Conductor', () => {
expect(getMockCall(commandReceiver0, 0, 1)).toMatchObject({
commandName: 'addedAbstract',
content: {
deviceType: 0, // abstract
deviceType: 'ABSTRACT',
myAttr1: 'one',
myAttr2: 'two',
},
Expand All @@ -138,7 +138,7 @@ describe('Conductor', () => {
expect(getMockCall(commandReceiver0, 0, 1)).toMatchObject({
commandName: 'removedAbstract',
content: {
deviceType: 0, // abstract
deviceType: 'ABSTRACT',
myAttr1: 'one',
myAttr2: 'two',
},
Expand All @@ -149,7 +149,7 @@ describe('Conductor', () => {
expect(getMockCall(commandReceiver1, 0, 1)).toMatchObject({
commandName: 'addedAbstract',
content: {
deviceType: 0, // abstract
deviceType: 'ABSTRACT',
myAttr1: 'three',
myAttr2: 'four',
},
Expand All @@ -165,7 +165,7 @@ describe('Conductor', () => {
expect(getMockCall(commandReceiver1, 0, 1)).toMatchObject({
commandName: 'removedAbstract',
content: {
deviceType: 0, // abstract
deviceType: 'ABSTRACT',
myAttr1: 'three',
myAttr2: 'four',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe('Usage of library', () => {
type: DeviceType.ABSTRACT,
options: {},
}
expect(options.type).toEqual(0)
expect(options.type).toEqual('ABSTRACT')
})
test('types', () => {
expect(Types_DeviceType.ATEM).toEqual(2)
expect(Types_DeviceType.ATEM).toEqual('ATEM')

expect(Types_DeviceType).toEqual(DeviceType)

Expand All @@ -44,6 +44,6 @@ describe('Usage of library', () => {
classes: [],
}
const tl: TSRTimeline = [obj]
expect(tl[0].content.deviceType).toEqual(0)
expect(tl[0].content.deviceType).toEqual('ABSTRACT')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Abstract device', () => {
expect(getMockCall(commandReceiver0, 0, 1)).toMatchObject({
commandName: 'addedAbstract',
content: {
deviceType: 0, // abstract
deviceType: 'ABSTRACT',
tmp0: 'abc',
},
context: 'added: obj0',
Expand All @@ -99,7 +99,7 @@ describe('Abstract device', () => {
expect(getMockCall(commandReceiver0, 1, 1)).toMatchObject({
commandName: 'changedAbstract',
content: {
deviceType: 0, // abstract
deviceType: 'ABSTRACT',
tmp0: 'abcde',
},
context: 'changed: obj1',
Expand All @@ -110,7 +110,7 @@ describe('Abstract device', () => {
expect(getMockCall(commandReceiver0, 2, 1)).toMatchObject({
commandName: 'removedAbstract',
content: {
deviceType: 0, // abstract
deviceType: 'ABSTRACT',
tmp0: 'abcde',
},
context: 'removed: obj1',
Expand Down
14 changes: 8 additions & 6 deletions packages/timeline-state-resolver/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ const stringifyActionSchema = (action: Omit<TSRActionSchema, 'payload'> & { payl
const stringifyMappingSchema = (schema: any): Record<string, string> =>
Object.fromEntries(Object.entries<any>(schema.mappings).map(([id, sch]) => [id, JSON.stringify(sch)]))

export type TSRDevicesManifestEntry = {
displayName: string
configSchema: string
actions?: TSRActionSchema[]
mappingsSchemas: Record<string, string>
}

export type TSRDevicesManifest = {
[deviceType in DeviceType]: {
displayName: string
configSchema: string
actions?: TSRActionSchema[]
mappingsSchemas: Record<string, string>
}
[deviceType in DeviceType]: TSRDevicesManifestEntry
}

export interface TSRManifest {
Expand Down

0 comments on commit f1b95bc

Please sign in to comment.