diff --git a/DEVELOPER.md b/DEVELOPER.md index c12785b412..094db080f0 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -139,11 +139,6 @@ Then submit this as a PR. The ConfigManifests for Blueprints and Gateways was replaced with JSONSchema in R50. However, one usage by AdlibActions for their userDataManifest remains as this is not something we are actively using. -## Blueprint Migrations - -In R49, a replacement flow was added consisting of `validateConfig` and `applyConfig`. -It is no longer recommended to use the old migrations flow for showstyle and studio blueprints. - ### ExpectedMediaItems These are used for Media-manager which is no longer being developed. diff --git a/meteor/__mocks__/helpers/database.ts b/meteor/__mocks__/helpers/database.ts index f15db2942b..ea62db5c5b 100644 --- a/meteor/__mocks__/helpers/database.ts +++ b/meteor/__mocks__/helpers/database.ts @@ -386,7 +386,6 @@ export async function setupMockStudioBlueprint( }, studioConfigSchema: '{}' as any, - studioMigrations: [], getBaseline: () => { return { timelineObjects: [], @@ -443,7 +442,6 @@ export async function setupMockShowStyleBlueprint( }, showStyleConfigSchema: '{}' as any, - showStyleMigrations: [], getShowStyleVariantId: (): string | null => { return SHOW_STYLE_VARIANT_ID }, diff --git a/meteor/server/api/blueprints/__tests__/api.test.ts b/meteor/server/api/blueprints/__tests__/api.test.ts index b2c60d3d4a..af2cf6b8b1 100644 --- a/meteor/server/api/blueprints/__tests__/api.test.ts +++ b/meteor/server/api/blueprints/__tests__/api.test.ts @@ -55,8 +55,6 @@ describe('Test blueprint management api', () => { showStyleConfigSchema: JSONBlobStringify({}), databaseVersion: { - showStyle: {}, - studio: {}, system: undefined, }, @@ -238,7 +236,6 @@ describe('Test blueprint management api', () => { TSRVersion: '0.0.0', // studioConfigManifest: [], - // studioMigrations: [], // getBaseline: (context: IStudioContext): TSRTimelineObjBase[] => { // return [] // }, diff --git a/meteor/server/api/blueprints/__tests__/lib.ts b/meteor/server/api/blueprints/__tests__/lib.ts index 1b443d9715..e50bf8b59e 100644 --- a/meteor/server/api/blueprints/__tests__/lib.ts +++ b/meteor/server/api/blueprints/__tests__/lib.ts @@ -17,7 +17,6 @@ export function generateFakeBlueprint( integrationVersion: '0.0.0', TSRVersion: '0.0.0', studioConfigManifest: [], - studioMigrations: [], getBaseline: () => { return { timelineObjects: [], @@ -43,8 +42,6 @@ export function generateFakeBlueprint( showStyleConfigSchema: JSONBlobStringify({}), databaseVersion: { - showStyle: {}, - studio: {}, system: undefined, }, diff --git a/meteor/server/api/blueprints/__tests__/migrationContext.test.ts b/meteor/server/api/blueprints/__tests__/migrationContext.test.ts index 419a13b9a7..2c44af3b17 100644 --- a/meteor/server/api/blueprints/__tests__/migrationContext.test.ts +++ b/meteor/server/api/blueprints/__tests__/migrationContext.test.ts @@ -16,1464 +16,6 @@ describe('Test blueprint migrationContext', () => { await setupDefaultStudioEnvironment() }) - // eslint-disable-next-line jest/no-commented-out-tests - /* - describe('MigrationContextStudio', () => { - async function getContext() { - const studio = (await Studios.findOneAsync({})) as DBStudio - expect(studio).toBeTruthy() - return new MigrationContextStudio(studio) - } - function getStudio(context: MigrationContextStudio): DBStudio { - const studio = (context as any).studio - expect(studio).toBeTruthy() - return studio - } - describe('mappings', () => { - async function getMappingFromDb(studio: DBStudio, mappingId: string): Promise { - const studio2 = (await Studios.findOneAsync(studio._id)) as DBStudio - expect(studio2).toBeTruthy() - return studio2.mappingsWithOverrides.defaults[mappingId] - } - - test('getMapping: no id', async () => { - const ctx = await getContext() - const mapping = ctx.getMapping('') - expect(mapping).toBeFalsy() - }) - test('getMapping: missing', async () => { - const ctx = await getContext() - const mapping = ctx.getMapping('fake_mapping') - expect(mapping).toBeFalsy() - }) - test('getMapping: good', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const rawMapping: MappingExt = { - device: TSR.DeviceType.ABSTRACT, - deviceId: protectString('dev1'), - lookahead: LookaheadMode.NONE, - options: {}, - } - studio.mappingsWithOverrides.defaults['mapping1'] = rawMapping - - const mapping = ctx.getMapping('mapping1') as BlueprintMapping - expect(mapping).toEqual(rawMapping) - - // Ensure it is a copy - mapping.deviceId = 'changed' - expect(mapping).not.toEqual(studio.mappingsWithOverrides.defaults['mapping1']) - }) - - test('insertMapping: good', async () => { - const ctx = await getContext() - - const rawMapping: BlueprintMapping = { - device: TSR.DeviceType.ABSTRACT, - deviceId: 'dev1', - lookahead: LookaheadMode.NONE, - options: {}, - } - - const mappingId = ctx.insertMapping('mapping2', rawMapping) - expect(mappingId).toEqual('mapping2') - - // get should return the same - const mapping = ctx.getMapping('mapping2') - expect(mapping).toEqual(rawMapping) - - // check db is the same - const dbMapping = await getMappingFromDb(getStudio(ctx), 'mapping2') - expect(dbMapping).toEqual(rawMapping) - }) - test('insertMapping: no id', async () => { - const ctx = await getContext() - - const rawMapping: BlueprintMapping = { - device: TSR.DeviceType.ABSTRACT, - deviceId: 'dev1', - lookahead: LookaheadMode.NONE, - options: {}, - } - - expect(() => ctx.insertMapping('', rawMapping)).toThrow(`[500] Mapping id "" is invalid`) - - // get should return the same - const mapping = ctx.getMapping('') - expect(mapping).toBeFalsy() - - // check db is the same - const dbMapping = await getMappingFromDb(getStudio(ctx), '') - expect(dbMapping).toBeFalsy() - }) - test('insertMapping: existing', async () => { - const ctx = await getContext() - const existingMapping = ctx.getMapping('mapping2') - expect(existingMapping).toBeTruthy() - - const rawMapping: BlueprintMapping = { - device: TSR.DeviceType.ATEM, - deviceId: 'dev2', - lookahead: LookaheadMode.PRELOAD, - options: {}, - } - expect(rawMapping).not.toEqual(existingMapping) - - expect(() => ctx.insertMapping('mapping2', rawMapping)).toThrow( - `[404] Mapping "mapping2" cannot be inserted as it already exists` - ) - - // get should return the same - const mapping = ctx.getMapping('mapping2') - expect(mapping).toEqual(existingMapping) - - // check db is the same - const dbMapping = await getMappingFromDb(getStudio(ctx), 'mapping2') - expect(dbMapping).toEqual(existingMapping) - }) - - test('updateMapping: good', async () => { - const ctx = await getContext() - const existingMapping = ctx.getMapping('mapping2') as BlueprintMapping - expect(existingMapping).toBeTruthy() - - const rawMapping = { - device: TSR.DeviceType.HYPERDECK, - deviceId: 'hyper0', - } - ctx.updateMapping('mapping2', rawMapping) - - const expectedMapping = { - ...existingMapping, - ...rawMapping, - } - - // get should return the same - const mapping = ctx.getMapping('mapping2') - expect(mapping).toEqual(expectedMapping) - - // check db is the same - const dbMapping = await getMappingFromDb(getStudio(ctx), 'mapping2') - expect(dbMapping).toEqual(expectedMapping) - }) - test('updateMapping: no props', async () => { - const ctx = await getContext() - const existingMapping = ctx.getMapping('mapping2') as BlueprintMapping - expect(existingMapping).toBeTruthy() - - // Should not error - ctx.updateMapping('mapping2', {}) - }) - test('updateMapping: no id', async () => { - const ctx = await getContext() - const existingMapping = ctx.getMapping('') as BlueprintMapping - expect(existingMapping).toBeFalsy() - - expect(() => ctx.updateMapping('', { device: TSR.DeviceType.HYPERDECK })).toThrow( - `[404] Mapping "" cannot be updated as it does not exist` - ) - }) - test('updateMapping: missing', async () => { - const ctx = await getContext() - expect(ctx.getMapping('mapping1')).toBeFalsy() - - const rawMapping = { - device: TSR.DeviceType.HYPERDECK, - deviceId: 'hyper0', - } - - expect(() => ctx.updateMapping('mapping1', rawMapping)).toThrow( - `[404] Mapping "mapping1" cannot be updated as it does not exist` - ) - - // get should return the same - const mapping = ctx.getMapping('mapping1') - expect(mapping).toBeFalsy() - - // check db is the same - const dbMapping = await getMappingFromDb(getStudio(ctx), 'mapping1') - expect(dbMapping).toBeFalsy() - }) - - test('removeMapping: missing', async () => { - const ctx = await getContext() - expect(ctx.getMapping('mapping1')).toBeFalsy() - - // Should not error - ctx.removeMapping('mapping1') - }) - test('removeMapping: no id', async () => { - const ctx = await getContext() - expect(ctx.getMapping('')).toBeFalsy() - expect(ctx.getMapping('mapping2')).toBeTruthy() - - // Should not error - ctx.removeMapping('') - - // ensure other mappings still exist - expect(await getMappingFromDb(getStudio(ctx), 'mapping2')).toBeTruthy() - }) - test('removeMapping: good', async () => { - const ctx = await getContext() - expect(ctx.getMapping('mapping2')).toBeTruthy() - - ctx.removeMapping('mapping2') - - // check was removed - expect(ctx.getMapping('mapping2')).toBeFalsy() - expect(await getMappingFromDb(getStudio(ctx), 'mapping2')).toBeFalsy() - }) - }) - - describe('config', () => { - async function getAllConfigFromDb(studio: DBStudio): Promise { - const studio2 = (await Studios.findOneAsync(studio._id)) as DBStudio - expect(studio2).toBeTruthy() - return studio2.blueprintConfigWithOverrides.defaults - } - - test('getConfig: no id', async () => { - const ctx = await getContext() - - expect(ctx.getConfig('')).toBeFalsy() - }) - test('getConfig: missing', async () => { - const ctx = await getContext() - - expect(ctx.getConfig('conf1')).toBeFalsy() - }) - test('getConfig: good', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - - studio.blueprintConfigWithOverrides.defaults['conf1'] = 5 - expect(ctx.getConfig('conf1')).toEqual(5) - - studio.blueprintConfigWithOverrides.defaults['conf2'] = ' af ' - expect(ctx.getConfig('conf2')).toEqual('af') - }) - - test('setConfig: no id', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - - expect(() => ctx.setConfig('', 34)).toThrow(`[500] Config id "" is invalid`) - - // Config should not have changed - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - test('setConfig: insert', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - expect(ctx.getConfig('conf1')).toBeFalsy() - - ctx.setConfig('conf1', 34) - - const expectedItem = { - _id: 'conf1', - value: 34, - } - expect(ctx.getConfig('conf1')).toEqual(expectedItem.value) - - // Config should have changed - initialConfig[expectedItem._id] = expectedItem.value - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - test('setConfig: insert undefined', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - expect(ctx.getConfig('confUndef')).toBeFalsy() - - ctx.setConfig('confUndef', undefined as any) - - const expectedItem = { - _id: 'confUndef', - value: undefined as any, - } - expect(ctx.getConfig('confUndef')).toEqual(expectedItem.value) - - // Config should have changed - initialConfig[expectedItem._id] = expectedItem.value - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - - test('setConfig: update', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - expect(ctx.getConfig('conf1')).toBeTruthy() - - ctx.setConfig('conf1', 'hello') - - const expectedItem = { - _id: 'conf1', - value: 'hello', - } - expect(ctx.getConfig('conf1')).toEqual(expectedItem.value) - - // Config should have changed - initialConfig[expectedItem._id] = expectedItem.value - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - test('setConfig: update undefined', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - expect(ctx.getConfig('conf1')).toBeTruthy() - - ctx.setConfig('conf1', undefined as any) - - const expectedItem = { - _id: 'conf1', - value: undefined as any, - } - expect(ctx.getConfig('conf1')).toEqual(expectedItem.value) - - // Config should have changed - initialConfig[expectedItem._id] = expectedItem.value - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - - test('removeConfig: no id', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - ctx.setConfig('conf1', true) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - expect(ctx.getConfig('conf1')).toBeTruthy() - - // Should not error - ctx.removeConfig('') - - // Config should not have changed - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - test('removeConfig: missing', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - expect(ctx.getConfig('conf1')).toBeTruthy() - expect(ctx.getConfig('fake_conf')).toBeFalsy() - - // Should not error - ctx.removeConfig('fake_conf') - - // Config should not have changed - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - test('removeConfig: good', async () => { - const ctx = await getContext() - const studio = getStudio(ctx) - const initialConfig = _.clone(studio.blueprintConfigWithOverrides.defaults) - expect(ctx.getConfig('conf1')).toBeTruthy() - - // Should not error - ctx.removeConfig('conf1') - - // Config should have changed - delete initialConfig['conf1'] - expect(studio.blueprintConfigWithOverrides.defaults).toEqual(initialConfig) - expect(await getAllConfigFromDb(studio)).toEqual(initialConfig) - }) - }) - - describe('devices', () => { - async function getStudio(context: MigrationContextStudio): Promise { - const studioId = (context as any).studio._id - const studio = (await Studios.findOneAsync(studioId)) as DBStudio - expect(studio).toBeTruthy() - return studio - } - async function createPlayoutDevice(studio: DBStudio) { - const peripheralDeviceId = getRandomId() - studio.peripheralDeviceSettings.playoutDevices.defaults = { - device01: { - peripheralDeviceId: peripheralDeviceId, - options: { - type: TSR.DeviceType.ABSTRACT, - options: {}, - }, - }, - } - - await Studios.updateAsync(studio._id, studio) - return PeripheralDevices.insertAsync({ - _id: peripheralDeviceId, - name: 'Fake parent device', - organizationId: null, - type: PeripheralDeviceType.PLAYOUT, - category: PeripheralDeviceCategory.PLAYOUT, - subType: PERIPHERAL_SUBTYPE_PROCESS, - deviceName: 'Playout Gateway', - studioId: studio._id, - created: 0, - lastConnected: 0, - lastSeen: 0, - status: { - statusCode: 0, - }, - connected: false, - connectionId: null, - token: '', - settings: {}, - configManifest: { - deviceConfigSchema: JSONBlobStringify({}), // can be empty as it's only useful for UI. - subdeviceManifest: {}, - }, - }) - } - async function getPlayoutDevice(studio: DBStudio): Promise { - const device = await PeripheralDevices.findOneAsync({ - studioId: studio._id, - type: PeripheralDeviceType.PLAYOUT, - category: PeripheralDeviceCategory.PLAYOUT, - subType: PERIPHERAL_SUBTYPE_PROCESS, - }) - expect(device).toBeTruthy() - return device as PeripheralDevice - } - - test('getDevice: no id', async () => { - const ctx = await getContext() - const device = ctx.getDevice('') - expect(device).toBeFalsy() - }) - test('getDevice: missing', async () => { - const ctx = await getContext() - const device = ctx.getDevice('fake_device') - expect(device).toBeFalsy() - }) - test('getDevice: missing with parent', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const playoutId = await createPlayoutDevice(studio) - expect(playoutId).toBeTruthy() - - const device = ctx.getDevice('fake_device') - expect(device).toBeFalsy() - }) - test('getDevice: good', async () => { - const ctx = await getContext() - const peripheral = getPlayoutDevice(await getStudio(ctx)) - expect(peripheral).toBeTruthy() - - const device = ctx.getDevice('device01') - expect(device).toBeTruthy() - - // Ensure bad id doesnt match it - const device2 = ctx.getDevice('fake_device') - expect(device2).toBeFalsy() - }) - - test('insertDevice: no id', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('')).toBeFalsy() - - expect(() => ctx.insertDevice('', { type: TSR.DeviceType.ABSTRACT } as any)).toThrow( - `[500] Device id "" is invalid` - ) - - expect(ctx.getDevice('')).toBeFalsy() - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - test('insertDevice: already exists', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('device01')).toBeTruthy() - - expect(() => ctx.insertDevice('device01', { type: TSR.DeviceType.CASPARCG } as any)).toThrow( - `[404] Device "device01" cannot be inserted as it already exists` - ) - - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - test('insertDevice: ok', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('device11')).toBeFalsy() - - const rawDevice: any = { type: TSR.DeviceType.CASPARCG } - - const deviceId = ctx.insertDevice('device11', rawDevice) - expect(deviceId).toEqual('device11') - initialSettings.defaults[deviceId] = { - peripheralDeviceId: (await getPlayoutDevice(studio))._id, - options: rawDevice, - } - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - - const device = ctx.getDevice(deviceId) - expect(device).toEqual(rawDevice) - }) - - test('updateDevice: no id', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('')).toBeFalsy() - - expect(() => ctx.updateDevice('', { type: TSR.DeviceType.ABSTRACT })).toThrow( - `[500] Device id "" is invalid` - ) - - expect(ctx.getDevice('')).toBeFalsy() - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - test('updateDevice: missing', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('device22')).toBeFalsy() - - expect(() => ctx.updateDevice('device22', { type: TSR.DeviceType.ATEM })).toThrow( - `[404] Device "device22" cannot be updated as it does not exist` - ) - - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - test('Device: good', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('device01')).toBeTruthy() - - const rawDevice: any = { - type: TSR.DeviceType.HYPERDECK, - } - const expectedDevice = { - ...initialSettings.defaults['device01'].options, - ...rawDevice, - } - - ctx.updateDevice('device01', rawDevice) - - expect(ctx.getDevice('device01')).toEqual(expectedDevice) - - initialSettings.defaults['device01'].options = expectedDevice - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - - test('removeDevice: no id', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('')).toBeFalsy() - - expect(() => ctx.removeDevice('')).toThrow(`[500] Device id "" is invalid`) - - expect(ctx.getDevice('')).toBeFalsy() - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - test('removeDevice: missing', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('device22')).toBeFalsy() - - // Should not error - ctx.removeDevice('device22') - - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - test('removeDevice: good', async () => { - const ctx = await getContext() - const studio = await getStudio(ctx) - const initialSettings = studio.peripheralDeviceSettings.playoutDevices - expect(ctx.getDevice('device01')).toBeTruthy() - - // Should not error - ctx.removeDevice('device01') - - expect(ctx.getDevice('device01')).toBeFalsy() - delete initialSettings.defaults['device01'] - expect((await getStudio(ctx)).peripheralDeviceSettings.playoutDevices).toEqual(initialSettings) - }) - }) - }) - - describe('MigrationContextShowStyle', () => { - async function getContext() { - const showStyle = (await ShowStyleBases.findOneAsync({})) as DBShowStyleBase - expect(showStyle).toBeTruthy() - return new MigrationContextShowStyle(showStyle) - } - function getShowStyle(context: MigrationContextShowStyle): DBShowStyleBase { - const showStyleBase = (context as any).showStyleBase - expect(showStyleBase).toBeTruthy() - return showStyleBase - } - async function createVariant(ctx: MigrationContextShowStyle, id: string, config?: IBlueprintConfig) { - const showStyle = getShowStyle(ctx) - - const rawVariant = literal({ - _id: protectString(ctx.getVariantId(id)), - name: 'test', - showStyleBaseId: showStyle._id, - blueprintConfigWithOverrides: wrapDefaultObject(config || {}), - _rundownVersionHash: '', - _rank: 0, - }) - await ShowStyleVariants.insertAsync(rawVariant) - - return rawVariant - } - - describe('variants', () => { - test('getAllVariants: good', async () => { - const ctx = await getContext() - const variants = ctx.getAllVariants() - expect(variants).toHaveLength(1) - }) - test('getAllVariants: missing base', () => { - const ctx = new MigrationContextShowStyle({ _id: 'fakeStyle' } as any) - const variants = ctx.getAllVariants() - expect(variants).toHaveLength(0) - }) - - test('getVariantId: consistent', async () => { - const ctx = await getContext() - - const id1 = ctx.getVariantId('variant1') - const id2 = ctx.getVariantId('variant1') - expect(id2).toEqual(id1) - - const id3 = ctx.getVariantId('variant2') - expect(id3).not.toEqual(id1) - }) - test('getVariantId: different base', async () => { - const ctx = await getContext() - const ctx2 = new MigrationContextShowStyle({ _id: 'fakeStyle' } as any) - - const id1 = ctx.getVariantId('variant1') - const id2 = ctx2.getVariantId('variant1') - expect(id2).not.toEqual(id1) - }) - - test('getVariant: good', async () => { - const ctx = await getContext() - const rawVariant = await createVariant(ctx, 'variant1') - - const variant = ctx.getVariant('variant1') - expect(variant).toBeTruthy() - expect(variant).toEqual(rawVariant) - }) - test('getVariant: no id', async () => { - const ctx = await getContext() - - expect(() => ctx.getVariant('')).toThrow(`[500] Variant id "" is invalid`) - }) - test('getVariant: missing', async () => { - const ctx = await getContext() - - const variant = ctx.getVariant('fake_variant') - expect(variant).toBeFalsy() - }) - - test('insertVariant: no id', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - - expect(() => - ctx.insertVariant('', { - name: 'test2', - }) - ).toThrow(`[500] Variant id "" is invalid`) - - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - test('insertVariant: already exists', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - expect(ctx.getVariant('variant1')).toBeTruthy() - - expect(() => - ctx.insertVariant('variant1', { - name: 'test2', - }) - ).toThrow(/*`[500] Variant id "variant1" already exists`* /) - - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - test('insertVariant: good', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - expect(ctx.getVariant('variant2')).toBeFalsy() - - const variantId = ctx.insertVariant('variant2', { - name: 'test2', - }) - expect(variantId).toBeTruthy() - expect(variantId).toEqual(ctx.getVariantId('variant2')) - - initialVariants.push( - literal({ - _id: protectString(variantId), - showStyleBaseId: getShowStyle(ctx)._id, - name: 'test2', - blueprintConfigWithOverrides: wrapDefaultObject({}), - _rundownVersionHash: '', - _rank: 0, - }) as any as IBlueprintShowStyleVariant - ) - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - - test('updateVariant: no id', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - - expect(() => - ctx.updateVariant('', { - name: 'test12', - }) - ).toThrow(`[500] Variant id "" is invalid`) - - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - test('updateVariant: missing', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - expect(ctx.getVariant('variant11')).toBeFalsy() - - expect(() => - ctx.updateVariant('variant11', { - name: 'test2', - }) - ).toThrow(/*`[404] Variant id "variant1" does not exist`* /) - // TODO - tidy up the error type - - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - test('updateVariant: good', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - expect(ctx.getVariant('variant1')).toBeTruthy() - - ctx.updateVariant('variant1', { - name: 'newname', - }) - - _.each(initialVariants, (variant) => { - if (variant._id === ctx.getVariantId('variant1')) { - variant.name = 'newname' - } - }) - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - - test('removeVariant: no id', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - - expect(() => ctx.removeVariant('')).toThrow(`[500] Variant id "" is invalid`) - - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - test('removeVariant: missing', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - expect(ctx.getVariant('variant11')).toBeFalsy() - - // Should not error - ctx.removeVariant('variant11') - - expect(ctx.getAllVariants()).toEqual(initialVariants) - }) - test('removeVariant: good', async () => { - const ctx = await getContext() - const initialVariants = _.clone(ctx.getAllVariants()) - expect(ctx.getVariant('variant1')).toBeTruthy() - - // Should not error - ctx.removeVariant('variant1') - - const expectedVariants = _.filter( - initialVariants, - (variant) => variant._id !== ctx.getVariantId('variant1') - ) - expect(ctx.getAllVariants()).toEqual(expectedVariants) - }) - }) - - describe('sourcelayer', () => { - async function getAllSourceLayersFromDb(showStyle: DBShowStyleBase): Promise { - const showStyle2 = (await ShowStyleBases.findOneAsync(showStyle._id)) as DBShowStyleBase - expect(showStyle2).toBeTruthy() - return showStyle2.sourceLayersWithOverrides.defaults - } - - test('getSourceLayer: no id', async () => { - const ctx = await getContext() - - expect(() => ctx.getSourceLayer('')).toThrow(`[500] SourceLayer id "" is invalid`) - }) - test('getSourceLayer: missing', async () => { - const ctx = await getContext() - - const layer = ctx.getSourceLayer('fake_source_layer') - expect(layer).toBeFalsy() - }) - test('getSourceLayer: good', async () => { - const ctx = await getContext() - - const layer = ctx.getSourceLayer('cam0') as ISourceLayer - expect(layer).toBeTruthy() - expect(layer._id).toEqual('cam0') - - const layer2 = ctx.getSourceLayer('vt0') as ISourceLayer - expect(layer2).toBeTruthy() - expect(layer2._id).toEqual('vt0') - }) - - test('insertSourceLayer: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - - expect(() => - ctx.insertSourceLayer('', { - name: 'test', - _rank: 10, - type: SourceLayerType.UNKNOWN, - }) - ).toThrow(`[500] SourceLayer id "" is invalid`) - - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - test('insertSourceLayer: existing', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - - expect(() => - ctx.insertSourceLayer('vt0', { - name: 'test', - _rank: 10, - type: SourceLayerType.UNKNOWN, - }) - ).toThrow(`[500] SourceLayer "vt0" already exists`) - - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - test('insertSourceLayer: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - - const rawLayer = { - name: 'test', - _rank: 10, - type: SourceLayerType.UNKNOWN, - } - - ctx.insertSourceLayer('lay1', rawLayer) - - initialSourceLayers['lay1'] = { - ...rawLayer, - _id: 'lay1', - } - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - - test('updateSourceLayer: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - - expect(() => - ctx.updateSourceLayer('', { - name: 'test', - _rank: 10, - type: SourceLayerType.UNKNOWN, - }) - ).toThrow(`[500] SourceLayer id "" is invalid`) - - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - test('updateSourceLayer: missing', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - - expect(() => - ctx.updateSourceLayer('fake99', { - name: 'test', - _rank: 10, - type: SourceLayerType.UNKNOWN, - }) - ).toThrow(`[404] SourceLayer "fake99" cannot be updated as it does not exist`) - - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - test('updateSourceLayer: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - expect(ctx.getSourceLayer('lay1')).toBeTruthy() - - const rawLayer = { - name: 'test98', - type: SourceLayerType.VT, - } - - ctx.updateSourceLayer('lay1', rawLayer) - - initialSourceLayers['lay1'] = { - ...initialSourceLayers['lay1']!, - ...rawLayer, - } - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - - test('removeSourceLayer: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - - expect(() => ctx.removeSourceLayer('')).toThrow(`[500] SourceLayer id "" is invalid`) - - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - test('removeSourceLayer: missing', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - expect(ctx.getSourceLayer('fake99')).toBeFalsy() - - // Should not error - ctx.removeSourceLayer('fake99') - - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - test('removeSourceLayer: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialSourceLayers = _.clone(showStyle.sourceLayersWithOverrides.defaults) - expect(ctx.getSourceLayer('lay1')).toBeTruthy() - - // Should not error - ctx.removeSourceLayer('lay1') - - delete initialSourceLayers['lay1'] - expect(getShowStyle(ctx).sourceLayersWithOverrides.defaults).toEqual(initialSourceLayers) - expect(await getAllSourceLayersFromDb(showStyle)).toEqual(initialSourceLayers) - }) - }) - - describe('outputlayer', () => { - async function getAllOutputLayersFromDb( - showStyle: DBShowStyleBase - ): Promise> { - const showStyle2 = (await ShowStyleBases.findOneAsync(showStyle._id)) as DBShowStyleBase - expect(showStyle2).toBeTruthy() - return showStyle2.outputLayersWithOverrides.defaults - } - - test('getOutputLayer: no id', async () => { - const ctx = await getContext() - - expect(() => ctx.getOutputLayer('')).toThrow(`[500] OutputLayer id "" is invalid`) - }) - test('getOutputLayer: missing', async () => { - const ctx = await getContext() - - const layer = ctx.getOutputLayer('fake_source_layer') - expect(layer).toBeFalsy() - }) - test('getOutputLayer: good', async () => { - const ctx = await getContext() - - const layer = ctx.getOutputLayer('pgm') as IOutputLayer - expect(layer).toBeTruthy() - expect(layer._id).toEqual('pgm') - }) - - test('insertOutputLayer: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - - expect(() => - ctx.insertOutputLayer('', { - name: 'test', - _rank: 10, - isPGM: true, - }) - ).toThrow(`[500] OutputLayer id "" is invalid`) - - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - test('insertOutputLayer: existing', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - - expect(() => - ctx.insertOutputLayer('pgm', { - name: 'test', - _rank: 10, - isPGM: true, - }) - ).toThrow(`[500] OutputLayer "pgm" already exists`) - - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - test('insertOutputLayer: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - - const rawLayer = { - name: 'test', - _rank: 10, - isPGM: true, - } - - ctx.insertOutputLayer('lay1', rawLayer) - - initialOutputLayers['lay1'] = { - ...rawLayer, - _id: 'lay1', - } - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - - test('updateOutputLayer: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - - expect(() => - ctx.updateOutputLayer('', { - name: 'test', - _rank: 10, - isPGM: true, - }) - ).toThrow(`[500] OutputLayer id "" is invalid`) - - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - test('updateOutputLayer: missing', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - - expect(() => - ctx.updateOutputLayer('fake99', { - name: 'test', - _rank: 10, - isPGM: true, - }) - ).toThrow(`[404] OutputLayer "fake99" cannot be updated as it does not exist`) - - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - test('updateOutputLayer: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - expect(ctx.getOutputLayer('lay1')).toBeTruthy() - - const rawLayer = { - name: 'test98', - } - - ctx.updateOutputLayer('lay1', rawLayer) - - initialOutputLayers['lay1'] = { - ...initialOutputLayers['lay1']!, - ...rawLayer, - } - - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - - test('removeOutputLayer: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - - expect(() => ctx.removeOutputLayer('')).toThrow(`[500] OutputLayer id "" is invalid`) - - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - test('removeOutputLayer: missing', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - expect(ctx.getOutputLayer('fake99')).toBeFalsy() - - // Should not error - ctx.removeOutputLayer('fake99') - - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - test('removeOutputLayer: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialOutputLayers = _.clone(showStyle.outputLayersWithOverrides.defaults) - expect(ctx.getOutputLayer('lay1')).toBeTruthy() - - // Should not error - ctx.removeOutputLayer('lay1') - - delete initialOutputLayers['lay1'] - expect(getShowStyle(ctx).outputLayersWithOverrides.defaults).toEqual(initialOutputLayers) - expect(await getAllOutputLayersFromDb(showStyle)).toEqual(initialOutputLayers) - }) - }) - - describe('base-config', () => { - async function getAllBaseConfigFromDb(showStyle: DBShowStyleBase): Promise { - const showStyle2 = (await ShowStyleBases.findOneAsync(showStyle._id)) as DBShowStyleBase - expect(showStyle2).toBeTruthy() - return showStyle2.blueprintConfigWithOverrides.defaults - } - - test('getBaseConfig: no id', async () => { - const ctx = await getContext() - - expect(ctx.getBaseConfig('')).toBeFalsy() - }) - test('getBaseConfig: missing', async () => { - const ctx = await getContext() - - expect(ctx.getBaseConfig('conf1')).toBeFalsy() - }) - test('getBaseConfig: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - - showStyle.blueprintConfigWithOverrides.defaults['conf1'] = 5 - expect(ctx.getBaseConfig('conf1')).toEqual(5) - - showStyle.blueprintConfigWithOverrides.defaults['conf2'] = ' af ' - expect(ctx.getBaseConfig('conf2')).toEqual('af') - }) - - test('setBaseConfig: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - - expect(() => ctx.setBaseConfig('', 34)).toThrow(`[500] Config id "" is invalid`) - - // BaseConfig should not have changed - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - test('setBaseConfig: insert', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - expect(ctx.getBaseConfig('conf1')).toBeFalsy() - - ctx.setBaseConfig('conf1', 34) - - const expectedItem = { - _id: 'conf1', - value: 34, - } - expect(ctx.getBaseConfig('conf1')).toEqual(expectedItem.value) - - // BaseConfig should have changed - initialBaseConfig[expectedItem._id] = expectedItem.value - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - test('setBaseConfig: insert undefined', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - expect(ctx.getBaseConfig('confUndef')).toBeFalsy() - - expect(() => ctx.setBaseConfig('confUndef', undefined as any)).toThrow( - `[400] setBaseConfig "confUndef": value is undefined` - ) - - // BaseConfig should not have changed - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - - test('setBaseConfig: update', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - expect(ctx.getBaseConfig('conf1')).toBeTruthy() - - ctx.setBaseConfig('conf1', 'hello') - - const expectedItem = { - _id: 'conf1', - value: 'hello', - } - expect(ctx.getBaseConfig('conf1')).toEqual(expectedItem.value) - - // BaseConfig should have changed - initialBaseConfig[expectedItem._id] = expectedItem.value - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - test('setBaseConfig: update undefined', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - expect(ctx.getBaseConfig('conf1')).toBeTruthy() - - expect(() => ctx.setBaseConfig('conf1', undefined as any)).toThrow( - `[400] setBaseConfig "conf1": value is undefined` - ) - - // BaseConfig should not have changed - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - - test('removeBaseConfig: no id', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - ctx.setBaseConfig('conf1', true) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - expect(ctx.getBaseConfig('conf1')).toBeTruthy() - - // Should not error - ctx.removeBaseConfig('') - - // BaseConfig should not have changed - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - test('removeBaseConfig: missing', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - expect(ctx.getBaseConfig('conf1')).toBeTruthy() - expect(ctx.getBaseConfig('fake_conf')).toBeFalsy() - - // Should not error - ctx.removeBaseConfig('fake_conf') - - // BaseConfig should not have changed - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - test('removeBaseConfig: good', async () => { - const ctx = await getContext() - const showStyle = getShowStyle(ctx) - const initialBaseConfig = _.clone(showStyle.blueprintConfigWithOverrides.defaults) - expect(ctx.getBaseConfig('conf1')).toBeTruthy() - - // Should not error - ctx.removeBaseConfig('conf1') - - // BaseConfig should have changed - delete initialBaseConfig['conf1'] - expect(showStyle.blueprintConfigWithOverrides.defaults).toEqual(initialBaseConfig) - expect(await getAllBaseConfigFromDb(showStyle)).toEqual(initialBaseConfig) - }) - }) - describe('variant-config', () => { - async function getAllVariantConfigFromDb( - ctx: MigrationContextShowStyle, - variantId: string - ): Promise { - const variant = (await ShowStyleVariants.findOneAsync( - protectString(ctx.getVariantId(variantId)) - )) as DBShowStyleVariant - expect(variant).toBeTruthy() - return variant.blueprintConfigWithOverrides.defaults - } - - test('getVariantConfig: no variant id', async () => { - const ctx = await getContext() - - expect(() => ctx.getVariantConfig('', 'conf1')).toThrow(`[404] ShowStyleVariant "" not found`) - }) - test('getVariantConfig: missing variant', async () => { - const ctx = await getContext() - - expect(() => ctx.getVariantConfig('fake_variant', 'conf1')).toThrow( - `[404] ShowStyleVariant "fake_variant" not found` - ) - }) - test('getVariantConfig: missing', async () => { - const ctx = await getContext() - await createVariant(ctx, 'configVariant', { conf1: 5, conf2: ' af ' }) - - expect(ctx.getVariantConfig('configVariant', 'conf11')).toBeFalsy() - }) - test('getVariantConfig: good', async () => { - const ctx = await getContext() - expect(ctx.getVariant('configVariant')).toBeTruthy() - - expect(ctx.getVariantConfig('configVariant', 'conf1')).toEqual(5) - expect(ctx.getVariantConfig('configVariant', 'conf2')).toEqual('af') - }) - - test('setVariantConfig: no variant id', async () => { - const ctx = await getContext() - - expect(() => ctx.setVariantConfig('', 'conf1', 5)).toThrow(`[404] ShowStyleVariant "" not found`) - }) - test('setVariantConfig: missing variant', async () => { - const ctx = await getContext() - - expect(() => ctx.setVariantConfig('fake_variant', 'conf1', 5)).toThrow( - `[404] ShowStyleVariant "fake_variant" not found` - ) - }) - test('setVariantConfig: no id', async () => { - const ctx = await getContext() - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariant('configVariant')).toBeTruthy() - - expect(() => ctx.setVariantConfig('configVariant', '', 34)).toThrow(`[500] Config id "" is invalid`) - - // VariantConfig should not have changed - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - test('setVariantConfig: insert', async () => { - const ctx = await getContext() - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariantConfig('configVariant', 'conf19')).toBeFalsy() - - ctx.setVariantConfig('configVariant', 'conf19', 34) - - const expectedItem = { - _id: 'conf19', - value: 34, - } - expect(ctx.getVariantConfig('configVariant', 'conf19')).toEqual(expectedItem.value) - - // VariantConfig should have changed - initialVariantConfig[expectedItem._id] = expectedItem.value - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - test('setVariantConfig: insert undefined', async () => { - const ctx = await getContext() - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariantConfig('configVariant', 'confUndef')).toBeFalsy() - - expect(() => ctx.setVariantConfig('configVariant', 'confUndef', undefined as any)).toThrow( - `[400] setVariantConfig "configVariant", "confUndef": value is undefined` - ) - - // VariantConfig should not have changed - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - - test('setVariantConfig: update', async () => { - const ctx = await getContext() - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariantConfig('configVariant', 'conf1')).toBeTruthy() - - ctx.setVariantConfig('configVariant', 'conf1', 'hello') - - const expectedItem = { - _id: 'conf1', - value: 'hello', - } - expect(ctx.getVariantConfig('configVariant', 'conf1')).toEqual(expectedItem.value) - - // VariantConfig should have changed - initialVariantConfig[expectedItem._id] = expectedItem.value - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - test('setVariantConfig: update undefined', async () => { - const ctx = await getContext() - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariantConfig('configVariant', 'conf1')).toBeTruthy() - - expect(() => ctx.setVariantConfig('configVariant', 'conf1', undefined as any)).toThrow( - `[400] setVariantConfig "configVariant", "conf1": value is undefined` - ) - - // VariantConfig should not have changed - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - - test('removeVariantConfig: no variant id', async () => { - const ctx = await getContext() - - expect(() => ctx.removeVariantConfig('', 'conf1')).toThrow(`[404] ShowStyleVariant "" not found`) - }) - test('removeVariantConfig: missing variant', async () => { - const ctx = await getContext() - - expect(() => ctx.removeVariantConfig('fake_variant', 'conf1')).toThrow( - `[404] ShowStyleVariant "fake_variant" not found` - ) - }) - test('removeVariantConfig: no id', async () => { - const ctx = await getContext() - ctx.setVariantConfig('configVariant', 'conf1', true) - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariantConfig('configVariant', 'conf1')).toBeTruthy() - - // Should not error - ctx.removeVariantConfig('configVariant', '') - - // VariantConfig should not have changed - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - test('removeVariantConfig: missing', async () => { - const ctx = await getContext() - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariantConfig('configVariant', 'conf1')).toBeTruthy() - expect(ctx.getVariantConfig('configVariant', 'fake_conf')).toBeFalsy() - - // Should not error - ctx.removeVariantConfig('configVariant', 'fake_conf') - - // VariantConfig should not have changed - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - test('removeVariantConfig: good', async () => { - const ctx = await getContext() - const initialVariantConfig = _.clone(await getAllVariantConfigFromDb(ctx, 'configVariant')) - expect(ctx.getVariantConfig('configVariant', 'conf1')).toBeTruthy() - - // Should not error - ctx.removeVariantConfig('configVariant', 'conf1') - - // VariantConfig should have changed - delete initialVariantConfig['conf1'] - expect(await getAllVariantConfigFromDb(ctx, 'configVariant')).toEqual(initialVariantConfig) - }) - }) - }) - */ - describe('MigrationContextSystem', () => { async function getContext() { const coreSystem = await CoreSystem.findOneAsync({}) diff --git a/meteor/server/api/blueprints/api.ts b/meteor/server/api/blueprints/api.ts index 8a294bdfec..af378dd152 100644 --- a/meteor/server/api/blueprints/api.ts +++ b/meteor/server/api/blueprints/api.ts @@ -53,8 +53,6 @@ export async function insertBlueprint( blueprintType: type, databaseVersion: { - studio: {}, - showStyle: {}, system: undefined, }, @@ -154,8 +152,6 @@ async function innerUploadBlueprint( databaseVersion: blueprint ? blueprint.databaseVersion : { - studio: {}, - showStyle: {}, system: undefined, }, blueprintId: '', @@ -205,8 +201,6 @@ async function innerUploadBlueprint( // Force reset migrations newBlueprint.databaseVersion = { - showStyle: {}, - studio: {}, system: undefined, } } else { diff --git a/meteor/server/api/blueprints/migrationContext.ts b/meteor/server/api/blueprints/migrationContext.ts index a273f24bd1..c5ab3c15c1 100644 --- a/meteor/server/api/blueprints/migrationContext.ts +++ b/meteor/server/api/blueprints/migrationContext.ts @@ -11,11 +11,6 @@ import { wrapDefaultObject } from '@sofie-automation/corelib/dist/settings/objec import { ShowStyleBaseId, TriggeredActionId } from '@sofie-automation/corelib/dist/dataModel/Ids' import { TriggeredActions } from '../../collections' -// function trimIfString(value: T): T | string { -// if (_.isString(value)) return value.trim() -// return value -// } - function convertTriggeredActionToBlueprints(triggeredAction: TriggeredActionsObj): IBlueprintTriggeredActions { const obj: Complete = { _id: unprotectString(triggeredAction._id), @@ -125,612 +120,3 @@ class AbstractMigrationContextWithTriggeredActions { export class MigrationContextSystem extends AbstractMigrationContextWithTriggeredActions implements IMigrationContextSystem {} - -/* -export class MigrationContextStudio implements IMigrationContextStudio { - private studio: DBStudio - - constructor(studio: DBStudio) { - this.studio = studio - } - - getMapping(mappingId: string): BlueprintMapping | undefined { - check(mappingId, String) - const mapping = this.studio.mappingsWithOverrides.defaults[mappingId] - if (mapping) { - return clone({ - ...mapping, - deviceId: unprotectString(mapping.deviceId), - }) - } - } - insertMapping(mappingId: string, mapping: OmitId): string { - check(mappingId, String) - if (this.studio.mappingsWithOverrides.defaults[mappingId]) { - throw new Meteor.Error(404, `Mapping "${mappingId}" cannot be inserted as it already exists`) - } - if (!mappingId) { - throw new Meteor.Error(500, `Mapping id "${mappingId}" is invalid`) - } - - const m: any = {} - m['mappingsWithOverrides.defaults.' + mappingId] = mapping - waitForPromise(Studios.updateAsync(this.studio._id, { $set: m })) - this.studio.mappingsWithOverrides.defaults[mappingId] = m['mappingsWithOverrides.defaults.' + mappingId] // Update local - return mappingId - } - updateMapping(mappingId: string, mapping: Partial): void { - check(mappingId, String) - if (!this.studio.mappingsWithOverrides.defaults[mappingId]) { - throw new Meteor.Error(404, `Mapping "${mappingId}" cannot be updated as it does not exist`) - } - - if (mappingId) { - const m: any = {} - m['mappingsWithOverrides.defaults.' + mappingId] = _.extend( - this.studio.mappingsWithOverrides.defaults[mappingId], - mapping - ) - waitForPromise(Studios.updateAsync(this.studio._id, { $set: m })) - this.studio.mappingsWithOverrides.defaults[mappingId] = m['mappingsWithOverrides.defaults.' + mappingId] // Update local - } - } - removeMapping(mappingId: string): void { - check(mappingId, String) - if (mappingId) { - const m: any = {} - m['mappingsWithOverrides.defaults.' + mappingId] = 1 - waitForPromise(Studios.updateAsync(this.studio._id, { $unset: m })) - delete this.studio.mappingsWithOverrides.defaults[mappingId] // Update local - } - } - - getConfig(configId: string): ConfigItemValue | undefined { - check(configId, String) - if (configId === '') return undefined - const configItem = objectPathGet(this.studio.blueprintConfigWithOverrides.defaults, configId) - return trimIfString(configItem) - } - setConfig(configId: string, value: ConfigItemValue): void { - check(configId, String) - if (!configId) { - throw new Meteor.Error(500, `Config id "${configId}" is invalid`) - } - - value = trimIfString(value) - - let modifier: MongoModifier = {} - if (value === undefined) { - modifier = { - $unset: { - [`blueprintConfigWithOverrides.defaults.${configId}`]: 1, - }, - } - objectPathDelete(this.studio.blueprintConfigWithOverrides.defaults, configId) // Update local - } else { - modifier = { - $set: { - [`blueprintConfigWithOverrides.defaults.${configId}`]: value, - }, - } - objectPathSet(this.studio.blueprintConfigWithOverrides.defaults, configId, value) // Update local - } - waitForPromise( - Studios.updateAsync( - { - _id: this.studio._id, - }, - modifier - ) - ) - } - removeConfig(configId: string): void { - check(configId, String) - - if (configId) { - waitForPromise( - Studios.updateAsync( - { - _id: this.studio._id, - }, - { - $unset: { - [`blueprintConfigWithOverrides.defaults.${configId}`]: 1, - }, - } - ) - ) - // Update local: - objectPathDelete(this.studio.blueprintConfigWithOverrides.defaults, configId) - } - } - - getDevice(deviceId: string): TSR.DeviceOptionsAny | undefined { - check(deviceId, String) - - const studio = waitForPromise(Studios.findOneAsync(this.studio._id)) - if (!studio || !studio.peripheralDeviceSettings.playoutDevices) return undefined - - const playoutDevices = studio.peripheralDeviceSettings.playoutDevices.defaults - - return playoutDevices[deviceId]?.options - } - insertDevice(deviceId: string, device: TSR.DeviceOptionsAny): string { - check(deviceId, String) - - if (!deviceId) { - throw new Meteor.Error(500, `Device id "${deviceId}" is invalid`) - } - - const studio = waitForPromise(Studios.findOneAsync(this.studio._id)) - if (!studio || !studio.peripheralDeviceSettings.playoutDevices) - throw new Meteor.Error(500, `Studio was not found`) - - const playoutDevices = studio.peripheralDeviceSettings.playoutDevices.defaults - - if (playoutDevices && playoutDevices[deviceId]) { - throw new Meteor.Error(404, `Device "${deviceId}" cannot be inserted as it already exists`) - } - - const parentDevice = waitForPromise( - PeripheralDevices.findOneAsync( - { - type: PeripheralDeviceType.PLAYOUT, - subType: PERIPHERAL_SUBTYPE_PROCESS, - studioId: this.studio._id, - }, - { - sort: { - created: 1, - }, - } - ) - ) - if (!parentDevice) { - throw new Meteor.Error(404, `Device "${deviceId}" cannot be updated as it does not exist`) - } - - waitForPromise( - Studios.updateAsync(this.studio._id, { - $set: { - [`peripheralDeviceSettings.playoutDevices.defaults.${deviceId}`]: literal({ - peripheralDeviceId: parentDevice._id, - options: device, - }), - }, - }) - ) - - return deviceId - } - updateDevice(deviceId: string, device: Partial): void { - check(deviceId, String) - - if (!deviceId) { - throw new Meteor.Error(500, `Device id "${deviceId}" is invalid`) - } - - const studio = waitForPromise(Studios.findOneAsync(this.studio._id)) - if (!studio || !studio.peripheralDeviceSettings.playoutDevices) - throw new Meteor.Error(500, `Studio was not found`) - - const playoutDevices = studio.peripheralDeviceSettings.playoutDevices.defaults - - if (!playoutDevices || !playoutDevices[deviceId]) { - throw new Meteor.Error(404, `Device "${deviceId}" cannot be updated as it does not exist`) - } - - const newOptions = _.extend(playoutDevices[deviceId].options, device) - - waitForPromise( - Studios.updateAsync(this.studio._id, { - $set: { - [`peripheralDeviceSettings.playoutDevices.defaults.${deviceId}.options`]: newOptions, - }, - }) - ) - } - removeDevice(deviceId: string): void { - check(deviceId, String) - - if (!deviceId) { - throw new Meteor.Error(500, `Device id "${deviceId}" is invalid`) - } - - waitForPromise( - Studios.updateAsync(this.studio._id, { - $unset: { - [`peripheralDeviceSettings.playoutDevices.defaults.${deviceId}`]: 1, - }, - }) - ) - } -} - -export class MigrationContextShowStyle - extends AbstractMigrationContextWithTriggeredActions - implements IMigrationContextShowStyle -{ - private showStyleBase: DBShowStyleBase - constructor(showStyleBase: DBShowStyleBase) { - super() - this.showStyleBaseId = showStyleBase._id - this.showStyleBase = showStyleBase - } - - getAllVariants(): IBlueprintShowStyleVariant[] { - return waitForPromise( - ShowStyleVariants.findFetchAsync({ - showStyleBaseId: this.showStyleBase._id, - }) - ).map((variant) => unprotectObject(variant)) as any - } - getVariantId(variantId: string): string { - return getHash(this.showStyleBase._id + '_' + variantId) - } - private getProtectedVariantId(variantId: string): ShowStyleVariantId { - return protectString(this.getVariantId(variantId)) - } - private getVariantFromDb(variantId: string): DBShowStyleVariant | undefined { - const variant = waitForPromise( - ShowStyleVariants.findOneAsync({ - showStyleBaseId: this.showStyleBase._id, - _id: this.getProtectedVariantId(variantId), - }) - ) - if (variant) return variant - - // Assume we were given the full id - return waitForPromise( - ShowStyleVariants.findOneAsync({ - showStyleBaseId: this.showStyleBase._id, - _id: protectString(variantId), - }) - ) - } - getVariant(variantId: string): IBlueprintShowStyleVariant | undefined { - check(variantId, String) - if (!variantId) { - throw new Meteor.Error(500, `Variant id "${variantId}" is invalid`) - } - - return unprotectObject(this.getVariantFromDb(variantId)) as any - } - insertVariant(variantId: string, variant: OmitId): string { - check(variantId, String) - if (!variantId) { - throw new Meteor.Error(500, `Variant id "${variantId}" is invalid`) - } - - return unprotectString( - waitForPromise( - ShowStyleVariants.insertAsync({ - ...variant, - _id: this.getProtectedVariantId(variantId), - showStyleBaseId: this.showStyleBase._id, - blueprintConfigWithOverrides: wrapDefaultObject({}), - _rundownVersionHash: '', - _rank: 0, - }) - ) - ) - } - updateVariant(variantId: string, newVariant: Partial): void { - check(variantId, String) - if (!variantId) { - throw new Meteor.Error(500, `Variant id "${variantId}" is invalid`) - } - const variant = this.getVariantFromDb(variantId) - if (!variant) throw new Meteor.Error(404, `Variant "${variantId}" not found`) - - waitForPromise(ShowStyleVariants.updateAsync(variant._id, { $set: newVariant })) - } - removeVariant(variantId: string): void { - check(variantId, String) - if (!variantId) { - throw new Meteor.Error(500, `Variant id "${variantId}" is invalid`) - } - - waitForPromise( - ShowStyleVariants.removeAsync({ - _id: this.getProtectedVariantId(variantId), - showStyleBaseId: this.showStyleBase._id, - }) - ) - } - getSourceLayer(sourceLayerId: string): ISourceLayer | undefined { - check(sourceLayerId, String) - if (!sourceLayerId) { - throw new Meteor.Error(500, `SourceLayer id "${sourceLayerId}" is invalid`) - } - - return this.showStyleBase.sourceLayersWithOverrides.defaults[sourceLayerId] - } - insertSourceLayer(sourceLayerId: string, layer: OmitId): string { - check(sourceLayerId, String) - if (!sourceLayerId) { - throw new Meteor.Error(500, `SourceLayer id "${sourceLayerId}" is invalid`) - } - - const oldLayer = this.showStyleBase.sourceLayersWithOverrides.defaults[sourceLayerId] - if (oldLayer) { - throw new Meteor.Error(500, `SourceLayer "${sourceLayerId}" already exists`) - } - - const fullLayer: ISourceLayer = { - ...layer, - _id: sourceLayerId, - } - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - }, - { - $set: { - [`sourceLayersWithOverrides.defaults.${sourceLayerId}`]: fullLayer, - }, - } - ) - ) - this.showStyleBase.sourceLayersWithOverrides.defaults[sourceLayerId] = fullLayer // Update local - return fullLayer._id - } - updateSourceLayer(sourceLayerId: string, layer: Partial): void { - check(sourceLayerId, String) - if (!sourceLayerId) { - throw new Meteor.Error(500, `SourceLayer id "${sourceLayerId}" is invalid`) - } - - const oldLayer = this.showStyleBase.sourceLayersWithOverrides.defaults[sourceLayerId] - if (!oldLayer) { - throw new Meteor.Error(404, `SourceLayer "${sourceLayerId}" cannot be updated as it does not exist`) - } - - const fullLayer = { - ...oldLayer, - ...layer, - } - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - 'sourceLayers._id': sourceLayerId, - }, - { - $set: { - [`sourceLayersWithOverrides.defaults.${sourceLayerId}`]: fullLayer, - }, - }, - { multi: false } - ) - ) - this.showStyleBase.sourceLayersWithOverrides.defaults[sourceLayerId] = fullLayer // Update local - } - removeSourceLayer(sourceLayerId: string): void { - check(sourceLayerId, String) - if (!sourceLayerId) { - throw new Meteor.Error(500, `SourceLayer id "${sourceLayerId}" is invalid`) - } - - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - }, - { - $unset: { - [`sourceLayersWithOverrides.defaults.${sourceLayerId}`]: 1, - }, - } - ) - ) - // Update local: - delete this.showStyleBase.sourceLayersWithOverrides.defaults[sourceLayerId] - } - getOutputLayer(outputLayerId: string): IOutputLayer | undefined { - check(outputLayerId, String) - if (!outputLayerId) { - throw new Meteor.Error(500, `OutputLayer id "${outputLayerId}" is invalid`) - } - - return this.showStyleBase.outputLayersWithOverrides.defaults[outputLayerId] - } - insertOutputLayer(outputLayerId: string, layer: OmitId): string { - check(outputLayerId, String) - if (!outputLayerId) { - throw new Meteor.Error(500, `OutputLayer id "${outputLayerId}" is invalid`) - } - - const oldLayer = this.showStyleBase.outputLayersWithOverrides.defaults[outputLayerId] - if (oldLayer) { - throw new Meteor.Error(500, `OutputLayer "${outputLayerId}" already exists`) - } - - const fullLayer: IOutputLayer = { - ...layer, - _id: outputLayerId, - } - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - }, - { - $set: { - [`outputLayersWithOverrides.defaults.${outputLayerId}`]: fullLayer, - }, - } - ) - ) - - this.showStyleBase.outputLayersWithOverrides.defaults[outputLayerId] = fullLayer // Update local - return fullLayer._id - } - updateOutputLayer(outputLayerId: string, layer: Partial): void { - check(outputLayerId, String) - if (!outputLayerId) { - throw new Meteor.Error(500, `OutputLayer id "${outputLayerId}" is invalid`) - } - - const oldLayer = this.showStyleBase.outputLayersWithOverrides.defaults[outputLayerId] - if (!oldLayer) { - throw new Meteor.Error(404, `OutputLayer "${outputLayerId}" cannot be updated as it does not exist`) - } - - const fullLayer = { - ...oldLayer, - ...layer, - } - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - }, - { - $set: { - [`outputLayersWithOverrides.defaults.${outputLayerId}`]: fullLayer, - }, - } - ) - ) - this.showStyleBase.outputLayersWithOverrides.defaults[outputLayerId] = fullLayer // Update local - } - removeOutputLayer(outputLayerId: string): void { - check(outputLayerId, String) - if (!outputLayerId) { - throw new Meteor.Error(500, `OutputLayer id "${outputLayerId}" is invalid`) - } - - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - }, - { - $unset: { - [`outputLayersWithOverrides.defaults.${outputLayerId}`]: 1, - }, - } - ) - ) - // Update local: - delete this.showStyleBase.outputLayersWithOverrides.defaults[outputLayerId] - } - getBaseConfig(configId: string): ConfigItemValue | undefined { - check(configId, String) - if (configId === '') return undefined - const configItem = objectPathGet(this.showStyleBase.blueprintConfigWithOverrides.defaults, configId) - return trimIfString(configItem) - } - setBaseConfig(configId: string, value: ConfigItemValue): void { - check(configId, String) - if (!configId) { - throw new Meteor.Error(500, `Config id "${configId}" is invalid`) - } - - if (_.isUndefined(value)) throw new Meteor.Error(400, `setBaseConfig "${configId}": value is undefined`) - - value = trimIfString(value) - - const modifier: MongoModifier = { - $set: { - [`blueprintConfigWithOverrides.defaults.${configId}`]: value, - }, - } - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - }, - modifier - ) - ) - objectPathSet(this.showStyleBase.blueprintConfigWithOverrides.defaults, configId, value) // Update local - } - removeBaseConfig(configId: string): void { - check(configId, String) - if (configId) { - waitForPromise( - ShowStyleBases.updateAsync( - { - _id: this.showStyleBase._id, - }, - { - $unset: { - [`blueprintConfigWithOverrides.defaults.${configId}`]: 1, - }, - } - ) - ) - // Update local: - objectPathDelete(this.showStyleBase.blueprintConfigWithOverrides.defaults, configId) - } - } - getVariantConfig(variantId: string, configId: string): ConfigItemValue | undefined { - check(variantId, String) - check(configId, String) - if (configId === '') return undefined - - const variant = this.getVariantFromDb(variantId) - if (!variant) throw new Meteor.Error(404, `ShowStyleVariant "${variantId}" not found`) - - const configItem = objectPathGet(variant.blueprintConfigWithOverrides.defaults, configId) - return trimIfString(configItem) - } - setVariantConfig(variantId: string, configId: string, value: ConfigItemValue): void { - check(variantId, String) - check(configId, String) - if (!configId) { - throw new Meteor.Error(500, `Config id "${configId}" is invalid`) - } - - value = trimIfString(value) - - if (_.isUndefined(value)) - throw new Meteor.Error(400, `setVariantConfig "${variantId}", "${configId}": value is undefined`) - - const variant = this.getVariantFromDb(variantId) - if (!variant) throw new Meteor.Error(404, `ShowStyleVariant "${variantId}" not found`) - - const modifier: MongoModifier = { - $set: { - [`blueprintConfigWithOverrides.defaults.${configId}`]: value, - }, - } - waitForPromise( - ShowStyleVariants.updateAsync( - { - _id: variant._id, - }, - modifier - ) - ) - objectPathSet(variant.blueprintConfigWithOverrides.defaults, configId, value) // Update local - } - removeVariantConfig(variantId: string, configId: string): void { - check(variantId, String) - check(configId, String) - - if (configId) { - const variant = this.getVariantFromDb(variantId) - if (!variant) throw new Meteor.Error(404, `ShowStyleVariant "${variantId}" not found`) - - waitForPromise( - ShowStyleVariants.updateAsync( - { - _id: variant._id, - }, - { - $unset: { - [`blueprintConfigWithOverrides.defaults.${configId}`]: 1, - }, - } - ) - ) - // Update local: - objectPathDelete(variant.blueprintConfigWithOverrides.defaults, configId) - } - } -} -*/ diff --git a/meteor/server/coreSystem/checkDatabaseVersions.ts b/meteor/server/coreSystem/checkDatabaseVersions.ts index 8fdd141b56..469b3e6914 100644 --- a/meteor/server/coreSystem/checkDatabaseVersions.ts +++ b/meteor/server/coreSystem/checkDatabaseVersions.ts @@ -1,8 +1,7 @@ import { StatusCode } from '@sofie-automation/blueprints-integration' -import { BlueprintId, StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids' -import { unprotectString } from '@sofie-automation/corelib/dist/protectedString' +import { BlueprintId } from '@sofie-automation/corelib/dist/dataModel/Ids' import { Blueprint } from '@sofie-automation/corelib/dist/dataModel/Blueprint' -import { Blueprints, ShowStyleBases, Studios } from '../collections' +import { Blueprints } from '../collections' import { parseVersion, compareSemverVersions, @@ -10,8 +9,6 @@ import { isPrerelease, parseCoreIntegrationCompatabilityRange, } from '../systemStatus/semverUtils' -import { DBShowStyleBase } from '@sofie-automation/corelib/dist/dataModel/ShowStyleBase' -import { DBStudio } from '@sofie-automation/corelib/dist/dataModel/Studio' import { lazyIgnore } from '../lib/lib' import { logger } from '../logging' import { CURRENT_SYSTEM_VERSION } from '../migration/currentSystemVersion' @@ -89,62 +86,7 @@ export function checkDatabaseVersions(): void { blueprintIds.add(blueprint._id) if (!blueprint.databaseVersion || typeof blueprint.databaseVersion === 'string') - blueprint.databaseVersion = { showStyle: {}, studio: {}, system: undefined } - if (!blueprint.databaseVersion.showStyle) blueprint.databaseVersion.showStyle = {} - if (!blueprint.databaseVersion.studio) blueprint.databaseVersion.studio = {} - - let o: { - statusCode: StatusCode - messages: string[] - } = { - statusCode: StatusCode.BAD, - messages: [], - } - - const checkedStudioIds = new Set() - - const showStylesForBlueprint = (await ShowStyleBases.findFetchAsync( - { blueprintId: blueprint._id }, - { - fields: { _id: 1 }, - } - )) as Array> - for (const showStyleBase of showStylesForBlueprint) { - if (o.statusCode === StatusCode.GOOD) { - o = compareSemverVersions( - parseVersion(blueprint.blueprintVersion), - parseRange(blueprint.databaseVersion.showStyle[unprotectString(showStyleBase._id)]), - false, - 'to fix, run migration', - 'blueprint version', - `showStyle "${showStyleBase._id}" migrations` - ) - } - - const studiosForShowStyleBase = (await Studios.findFetchAsync( - { supportedShowStyleBase: showStyleBase._id }, - { - fields: { _id: 1 }, - } - )) as Array> - for (const studio of studiosForShowStyleBase) { - if (!checkedStudioIds.has(studio._id)) { - // only run once per blueprint and studio - checkedStudioIds.add(studio._id) - - if (o.statusCode === StatusCode.GOOD) { - o = compareSemverVersions( - parseVersion(blueprint.blueprintVersion), - parseRange(blueprint.databaseVersion.studio[unprotectString(studio._id)]), - false, - 'to fix, run migration', - 'blueprint version', - `studio "${studio._id}]" migrations` - ) - } - } - } - } + blueprint.databaseVersion = { system: undefined } checkBlueprintCompability(blueprint) } diff --git a/meteor/server/migration/__tests__/migrations.test.ts b/meteor/server/migration/__tests__/migrations.test.ts index 8c6e02c4fa..973610f322 100644 --- a/meteor/server/migration/__tests__/migrations.test.ts +++ b/meteor/server/migration/__tests__/migrations.test.ts @@ -5,21 +5,11 @@ import { clearMigrationSteps, addMigrationSteps, prepareMigration, PreparedMigra import { CURRENT_SYSTEM_VERSION } from '../currentSystemVersion' import { RunMigrationResult, GetMigrationStatusResult } from '@sofie-automation/meteor-lib/dist/api/migration' import { literal, protectString } from '../../lib/tempLib' -import { - MigrationStepInputResult, - BlueprintManifestType, - MigrationContextStudio, - MigrationContextShowStyle, - PlaylistTimingType, - PlaylistTimingNone, - ShowStyleBlueprintManifest, - StudioBlueprintManifest, -} from '@sofie-automation/blueprints-integration' +import { MigrationStepInputResult } from '@sofie-automation/blueprints-integration' import { DBStudio } from '@sofie-automation/corelib/dist/dataModel/Studio' -import { generateFakeBlueprint } from '../../api/blueprints/__tests__/lib' import { MeteorCall } from '../../api/methods' import { wrapDefaultObject } from '@sofie-automation/corelib/dist/settings/objectWithOverrides' -import { Blueprints, ShowStyleBases, ShowStyleVariants, Studios } from '../../collections' +import { ShowStyleBases, ShowStyleVariants, Studios } from '../../collections' import { getCoreSystemAsync } from '../../coreSystem/collection' import { DEFAULT_MINIMUM_TAKE_SPAN } from '@sofie-automation/shared-lib/dist/core/constants' import fs from 'fs' @@ -250,160 +240,6 @@ describe('Migrations', () => { const studio = (await Studios.findOneAsync({})) as DBStudio expect(studio).toBeTruthy() - const studioManifest = (): StudioBlueprintManifest => ({ - blueprintType: 'studio' as BlueprintManifestType.STUDIO, - blueprintVersion: '1.0.0', - integrationVersion: '0.0.0', - TSRVersion: '0.0.0', - - configPresets: { - main: { - name: 'Main', - config: {}, - }, - }, - - studioConfigSchema: '{}' as any, - studioMigrations: [ - { - version: '0.2.0', - id: 'myStudioMockStep2', - validate: (context: MigrationContextStudio) => { - if (!context.getConfig('mocktest2')) return `mocktest2 config not set` - return false - }, - canBeRunAutomatically: true, - migrate: (context: MigrationContextStudio) => { - if (!context.getConfig('mocktest2')) { - context.setConfig('mocktest2', true) - } - }, - }, - { - version: '0.3.0', - id: 'myStudioMockStep3', - validate: (context: MigrationContextStudio) => { - if (!context.getConfig('mocktest3')) return `mocktest3 config not set` - return false - }, - canBeRunAutomatically: true, - migrate: (context: MigrationContextStudio) => { - if (!context.getConfig('mocktest3')) { - context.setConfig('mocktest3', true) - } - }, - }, - { - version: '0.1.0', - id: 'myStudioMockStep1', - validate: (context: MigrationContextStudio) => { - if (!context.getConfig('mocktest1')) return `mocktest1 config not set` - return false - }, - canBeRunAutomatically: true, - migrate: (context: MigrationContextStudio) => { - if (!context.getConfig('mocktest1')) { - context.setConfig('mocktest1', true) - } - }, - }, - ], - getBaseline: () => { - return { - timelineObjects: [], - } - }, - getShowStyleId: () => null, - }) - - const showStyleManifest = (): ShowStyleBlueprintManifest => ({ - blueprintType: 'showstyle' as BlueprintManifestType.SHOWSTYLE, - blueprintVersion: '1.0.0', - integrationVersion: '0.0.0', - TSRVersion: '0.0.0', - - configPresets: { - main: { - name: 'Main', - config: {}, - - variants: { - main: { - name: 'Default', - config: {}, - }, - }, - }, - }, - - showStyleConfigSchema: '{}' as any, - showStyleMigrations: [ - { - version: '0.2.0', - id: 'myShowStyleMockStep2', - validate: (context: MigrationContextShowStyle) => { - if (!context.getBaseConfig('mocktest2')) return `mocktest2 config not set` - return false - }, - canBeRunAutomatically: true, - migrate: (context: MigrationContextShowStyle) => { - if (!context.getBaseConfig('mocktest2')) { - context.setBaseConfig('mocktest2', true) - } - }, - }, - { - version: '0.3.0', - id: 'myShowStyleMockStep3', - validate: (context: MigrationContextShowStyle) => { - if (!context.getBaseConfig('mocktest3')) return `mocktest3 config not set` - return false - }, - canBeRunAutomatically: true, - migrate: (context: MigrationContextShowStyle) => { - if (!context.getBaseConfig('mocktest3')) { - context.setBaseConfig('mocktest3', true) - } - }, - }, - { - version: '0.1.0', - id: 'myShowStyleMockStep1', - validate: (context: MigrationContextShowStyle) => { - if (!context.getBaseConfig('mocktest1')) return `mocktest1 config not set` - return false - }, - canBeRunAutomatically: true, - migrate: (context: MigrationContextShowStyle) => { - if (!context.getBaseConfig('mocktest1')) { - context.setBaseConfig('mocktest1', true) - } - }, - }, - ], - getShowStyleVariantId: () => null, - getRundown: () => ({ - rundown: { - externalId: '', - name: '', - timing: literal({ - type: PlaylistTimingType.None, - }), - }, - globalAdLibPieces: [], - globalActions: [], - baseline: { timelineObjects: [] }, - }), - getSegment: () => ({ - segment: { name: '' }, - parts: [], - }), - }) - - await Blueprints.insertAsync( - generateFakeBlueprint('showStyle0', BlueprintManifestType.SHOWSTYLE, showStyleManifest) - ) - await ShowStyleBases.insertAsync({ _id: protectString('showStyle0'), name: '', @@ -427,7 +263,6 @@ describe('Migrations', () => { _rank: 0, }) - await Blueprints.insertAsync(generateFakeBlueprint('studio0', BlueprintManifestType.STUDIO, studioManifest)) await Studios.updateAsync(studio._id, { $set: { blueprintId: protectString('studio0'), diff --git a/meteor/server/migration/databaseMigration.ts b/meteor/server/migration/databaseMigration.ts index b342be20fd..4075e8ae2b 100644 --- a/meteor/server/migration/databaseMigration.ts +++ b/meteor/server/migration/databaseMigration.ts @@ -4,25 +4,15 @@ import { BlueprintManifestType, InputFunctionCore, InputFunctionSystem, - InputFunctionShowStyle, - InputFunctionStudio, MigrateFunctionCore, - MigrateFunctionShowStyle, - MigrateFunctionStudio, MigrationContextSystem as IMigrationContextSystem, - MigrationContextShowStyle as IMigrationContextShowStyle, - MigrationContextStudio as IMigrationContextStudio, MigrationStep, MigrationStepInput, MigrationStepInputFilteredResult, MigrationStepInputResult, - ShowStyleBlueprintManifest, - StudioBlueprintManifest, SystemBlueprintManifest, ValidateFunctionCore, ValidateFunctionSystem, - ValidateFunctionShowStyle, - ValidateFunctionStudio, MigrateFunctionSystem, ValidateFunction, MigrateFunction, @@ -40,13 +30,13 @@ import { logger } from '../logging' import { internalStoreSystemSnapshot } from '../api/snapshot' import { parseVersion, Version } from '../systemStatus/semverUtils' import { GENESIS_SYSTEM_VERSION } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem' -import { clone, getHash, omit, protectString, unprotectString } from '../lib/tempLib' +import { clone, getHash, omit, protectString } from '../lib/tempLib' import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError' import { evalBlueprint } from '../api/blueprints/cache' import { MigrationContextSystem } from '../api/blueprints/migrationContext' import { CURRENT_SYSTEM_VERSION } from './currentSystemVersion' -import { SnapshotId, ShowStyleBaseId, StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids' -import { Blueprints, CoreSystem, ShowStyleBases, Studios } from '../collections' +import { SnapshotId } from '@sofie-automation/corelib/dist/dataModel/Ids' +import { Blueprints, CoreSystem } from '../collections' import { getSystemStorePath } from '../coreSystem' import { getCoreSystemAsync, setCoreSystemVersion } from '../coreSystem/collection' @@ -158,101 +148,19 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise { - const chunk: MigrationChunk = { - sourceType: MigrationStepType.SHOWSTYLE, - sourceName: 'Blueprint ' + blueprint.name + ' for showStyle ' + showStyleBase.name, - blueprintId: blueprint._id, - sourceId: showStyleBase._id, - _dbVersion: parseVersion( - blueprint.databaseVersion.showStyle[unprotectString(showStyleBase._id)] || '0.0.0' - ), - _targetVersion: parseVersion(bp.blueprintVersion), - _steps: [], - } - migrationChunks.push(chunk) - // Add show-style migration steps from blueprint: - for (const step of bp.showStyleMigrations) { - allMigrationSteps.push( - prefixIdsOnStep('blueprint_' + blueprint._id + '_showStyle_' + showStyleBase._id + '_', { - id: step.id, - overrideSteps: step.overrideSteps, - validate: step.validate, - canBeRunAutomatically: step.canBeRunAutomatically, - migrate: step.migrate, - input: step.input, - dependOnResultFrom: step.dependOnResultFrom, - version: step.version, - _version: parseVersion(step.version), - _validateResult: false, // to be set later - _rank: rank++, - chunk: chunk, - }) - ) - } - }) - } else if (blueprint.blueprintType === BlueprintManifestType.STUDIO) { - const bp = blueprintManifest as StudioBlueprintManifest - - // If blueprint uses the new flow, don't attempt migrations - if (typeof bp.applyConfig === 'function') continue - - // Find all studios that use this blueprint - const studios = await Studios.findFetchAsync({ blueprintId: blueprint._id }) - studios.forEach((studio) => { - const chunk: MigrationChunk = { - sourceType: MigrationStepType.STUDIO, - sourceName: 'Blueprint ' + blueprint.name + ' for studio ' + studio.name, - blueprintId: blueprint._id, - sourceId: studio._id, - _dbVersion: parseVersion( - blueprint.databaseVersion.studio[unprotectString(studio._id)] || '0.0.0' - ), - _targetVersion: parseVersion(bp.blueprintVersion), - _steps: [], - } - migrationChunks.push(chunk) - // Add studio migration steps from blueprint: - for (const step of bp.studioMigrations) { - allMigrationSteps.push( - prefixIdsOnStep('blueprint_' + blueprint._id + '_studio_' + studio._id + '_', { - id: step.id, - overrideSteps: step.overrideSteps, - validate: step.validate, - canBeRunAutomatically: step.canBeRunAutomatically, - migrate: step.migrate, - input: step.input, - dependOnResultFrom: step.dependOnResultFrom, - version: step.version, - _version: parseVersion(step.version), - _validateResult: false, // to be set later - _rank: rank++, - chunk: chunk, - }) - ) - } - }) - } else if (blueprint.blueprintType === BlueprintManifestType.SYSTEM) { + if (blueprint.blueprintType === BlueprintManifestType.SYSTEM) { const bp = blueprintManifest as SystemBlueprintManifest // If blueprint uses the new flow, don't attempt migrations @@ -311,15 +219,6 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise) { for (const chunk of chunks) { if (chunk.sourceType === MigrationStepType.CORE) { await setCoreSystemVersion(chunk._targetVersion) - } else if ( - chunk.sourceType === MigrationStepType.STUDIO || - chunk.sourceType === MigrationStepType.SHOWSTYLE || - chunk.sourceType === MigrationStepType.SYSTEM - ) { + } else if (chunk.sourceType === MigrationStepType.SYSTEM) { if (!chunk.blueprintId) throw new Meteor.Error(500, `chunk.blueprintId missing!`) if (!chunk.sourceId) throw new Meteor.Error(500, `chunk.sourceId missing!`) @@ -712,20 +583,6 @@ async function completeMigration(chunks: Array) { `Updating Blueprint "${chunk.sourceName}" version, from "${blueprint.databaseVersion.system}" to "${chunk._targetVersion}".` ) m[`databaseVersion.system`] = chunk._targetVersion - } else if (chunk.sourceType === MigrationStepType.STUDIO && chunk.sourceId !== 'system') { - logger.info( - `Updating Blueprint "${chunk.sourceName}" version, from "${ - blueprint.databaseVersion.studio[unprotectString(chunk.sourceId)] - }" to "${chunk._targetVersion}".` - ) - m[`databaseVersion.studio.${chunk.sourceId}`] = chunk._targetVersion - } else if (chunk.sourceType === MigrationStepType.SHOWSTYLE && chunk.sourceId !== 'system') { - logger.info( - `Updating Blueprint "${chunk.sourceName}" version, from "${ - blueprint.databaseVersion.showStyle[unprotectString(chunk.sourceId)] - }" to "${chunk._targetVersion}".` - ) - m[`databaseVersion.showStyle.${chunk.sourceId}`] = chunk._targetVersion } else throw new Meteor.Error(500, `Bad chunk.sourcetype: "${chunk.sourceType}"`) await Blueprints.updateAsync(chunk.blueprintId, { $set: m }) @@ -781,8 +638,6 @@ export async function resetDatabaseVersions(): Promise { { $set: { databaseVersion: { - studio: {}, - showStyle: {}, system: '', }, }, @@ -798,29 +653,3 @@ function getMigrationSystemContext(chunk: MigrationChunk): IMigrationContextSyst return new MigrationContextSystem() } -async function getMigrationStudioContext(chunk: MigrationChunk): Promise { - if (chunk.sourceType !== MigrationStepType.STUDIO) - throw new Meteor.Error(500, `wrong chunk.sourceType "${chunk.sourceType}", expected STUDIO`) - if (!chunk.sourceId) throw new Meteor.Error(500, `chunk.sourceId missing`) - if (chunk.sourceId === 'system') - throw new Meteor.Error(500, `cunk.sourceId invalid in this context: ${chunk.sourceId}`) - - const studio = await Studios.findOneAsync(chunk.sourceId as StudioId) - if (!studio) throw new Meteor.Error(404, `Studio "${chunk.sourceId}" not found`) - - // return new MigrationContextStudio(studio) - throw new Meteor.Error(500, 'Studio migrations not supported!') -} -async function getMigrationShowStyleContext(chunk: MigrationChunk): Promise { - if (chunk.sourceType !== MigrationStepType.SHOWSTYLE) - throw new Meteor.Error(500, `wrong chunk.sourceType "${chunk.sourceType}", expected SHOWSTYLE`) - if (!chunk.sourceId) throw new Meteor.Error(500, `chunk.sourceId missing`) - if (chunk.sourceId === 'system') - throw new Meteor.Error(500, `cunk.sourceId invalid in this context: ${chunk.sourceId}`) - - const showStyleBase = await ShowStyleBases.findOneAsync(chunk.sourceId as ShowStyleBaseId) - if (!showStyleBase) throw new Meteor.Error(404, `ShowStyleBase "${chunk.sourceId}" not found`) - - // return new MigrationContextShowStyle(showStyleBase) - throw new Meteor.Error(500, 'ShowStyle migrations not supported!') -} diff --git a/meteor/server/migration/upgrades/__tests__/showStyleBase.test.ts b/meteor/server/migration/upgrades/__tests__/showStyleBase.test.ts index 645f78e989..9ac3aff7ca 100644 --- a/meteor/server/migration/upgrades/__tests__/showStyleBase.test.ts +++ b/meteor/server/migration/upgrades/__tests__/showStyleBase.test.ts @@ -49,7 +49,6 @@ describe('ShowStyleBase upgrades', () => { }, showStyleConfigSchema: JSONBlobStringify({}), - showStyleMigrations: [], getShowStyleVariantId: (): string | null => { return null }, diff --git a/packages/blueprints-integration/src/api/showStyle.ts b/packages/blueprints-integration/src/api/showStyle.ts index 9a4958ea28..c318ab1cf1 100644 --- a/packages/blueprints-integration/src/api/showStyle.ts +++ b/packages/blueprints-integration/src/api/showStyle.ts @@ -21,7 +21,7 @@ import type { } from '../context' import type { IngestAdlib, ExtendedIngestRundown, IngestRundown } from '../ingest' import type { IBlueprintExternalMessageQueueObj } from '../message' -import type { MigrationStepShowStyle } from '../migrations' +import type {} from '../migrations' import type { IBlueprintAdLibPiece, IBlueprintResolvedPieceInstance, @@ -56,10 +56,6 @@ export interface ShowStyleBlueprintManifest - /** A list of Migration steps related to a ShowStyle - * @deprecated This has been replaced with `validateConfig` and `applyConfig` - */ - showStyleMigrations: MigrationStepShowStyle[] /** The config presets exposed by this blueprint */ configPresets: Record> diff --git a/packages/blueprints-integration/src/api/studio.ts b/packages/blueprints-integration/src/api/studio.ts index 5392c4e221..3818645f2b 100644 --- a/packages/blueprints-integration/src/api/studio.ts +++ b/packages/blueprints-integration/src/api/studio.ts @@ -3,7 +3,6 @@ import type { ReadonlyDeep } from 'type-fest' import type { BlueprintConfigCoreConfig, BlueprintManifestBase, BlueprintManifestType, IConfigMessage } from './base' import type { JSONSchema } from '@sofie-automation/shared-lib/dist/lib/JSONSchemaTypes' import type { JSONBlob } from '@sofie-automation/shared-lib/dist/lib/JSONBlob' -import type { MigrationStepStudio } from '../migrations' import type { ICommonContext, IFixUpConfigContext, @@ -36,10 +35,6 @@ export interface StudioBlueprintManifest - /** A list of Migration steps related to a Studio - * @deprecated This has been replaced with `validateConfig` and `applyConfig` - */ - studioMigrations: MigrationStepStudio[] /** The config presets exposed by this blueprint */ configPresets: Record> diff --git a/packages/blueprints-integration/src/migrations.ts b/packages/blueprints-integration/src/migrations.ts index 6309e8cc90..62d3d4913f 100644 --- a/packages/blueprints-integration/src/migrations.ts +++ b/packages/blueprints-integration/src/migrations.ts @@ -1,9 +1,4 @@ -import { ConfigItemValue } from './common' -import { OmitId } from './lib' -import { IBlueprintShowStyleVariant, IOutputLayer, ISourceLayer } from './showStyle' import { IBlueprintTriggeredActions } from './triggers' -import { BlueprintMapping } from './studio' -import { TSR } from './timeline' export interface MigrationStepInput { stepId?: string // automatically filled in later @@ -28,59 +23,18 @@ export type ValidateFunctionSystem = ( context: MigrationContextSystem, afterMigration: boolean ) => Promise -export type ValidateFunctionStudio = (context: MigrationContextStudio, afterMigration: boolean) => boolean | string -export type ValidateFunctionShowStyle = ( - context: MigrationContextShowStyle, - afterMigration: boolean -) => boolean | string -export type ValidateFunction = - | ValidateFunctionStudio - | ValidateFunctionShowStyle - | ValidateFunctionSystem - | ValidateFunctionCore +export type ValidateFunction = ValidateFunctionSystem | ValidateFunctionCore export type MigrateFunctionCore = (input: MigrationStepInputFilteredResult) => Promise export type MigrateFunctionSystem = ( context: MigrationContextSystem, input: MigrationStepInputFilteredResult ) => Promise -export type MigrateFunctionStudio = (context: MigrationContextStudio, input: MigrationStepInputFilteredResult) => void -export type MigrateFunctionShowStyle = ( - context: MigrationContextShowStyle, - input: MigrationStepInputFilteredResult -) => void -export type MigrateFunction = - | MigrateFunctionStudio - | MigrateFunctionShowStyle - | MigrateFunctionSystem - | MigrateFunctionCore +export type MigrateFunction = MigrateFunctionSystem | MigrateFunctionCore export type InputFunctionCore = () => MigrationStepInput[] export type InputFunctionSystem = (context: MigrationContextSystem) => MigrationStepInput[] -export type InputFunctionStudio = (context: MigrationContextStudio) => MigrationStepInput[] -export type InputFunctionShowStyle = (context: MigrationContextShowStyle) => MigrationStepInput[] -export type InputFunction = InputFunctionStudio | InputFunctionShowStyle | InputFunctionSystem | InputFunctionCore - -export interface MigrationContextStudio { - getMapping: (mappingId: string) => BlueprintMapping | undefined - insertMapping: (mappingId: string, mapping: OmitId) => string - updateMapping: (mappingId: string, mapping: Partial) => void - removeMapping: (mappingId: string) => void - - getConfig: (configId: string) => ConfigItemValue | undefined - setConfig: (configId: string, value: ConfigItemValue) => void - removeConfig: (configId: string) => void - - getDevice: (deviceId: string) => TSR.DeviceOptionsAny | undefined - insertDevice: (deviceId: string, device: TSR.DeviceOptionsAny) => string | null - updateDevice: (deviceId: string, device: Partial) => void - removeDevice: (deviceId: string) => void -} - -export interface ShowStyleVariantPart { - // Note: if more props are added it may make sense to use Omit<> to build this type - name: string -} +export type InputFunction = InputFunctionSystem | InputFunctionCore interface MigrationContextWithTriggeredActions { getAllTriggeredActions: () => Promise @@ -90,33 +44,6 @@ interface MigrationContextWithTriggeredActions { removeTriggeredAction: (triggeredActionId: string) => Promise } -export interface MigrationContextShowStyle extends MigrationContextWithTriggeredActions { - getAllVariants: () => IBlueprintShowStyleVariant[] - getVariantId: (variantId: string) => string - getVariant: (variantId: string) => IBlueprintShowStyleVariant | undefined - insertVariant: (variantId: string, variant: OmitId) => string - updateVariant: (variantId: string, variant: Partial) => void - removeVariant: (variantId: string) => void - - getSourceLayer: (sourceLayerId: string) => ISourceLayer | undefined - insertSourceLayer: (sourceLayerId: string, layer: OmitId) => string - updateSourceLayer: (sourceLayerId: string, layer: Partial) => void - removeSourceLayer: (sourceLayerId: string) => void - - getOutputLayer: (outputLayerId: string) => IOutputLayer | undefined - insertOutputLayer: (outputLayerId: string, layer: OmitId) => string - updateOutputLayer: (outputLayerId: string, layer: Partial) => void - removeOutputLayer: (outputLayerId: string) => void - - getBaseConfig: (configId: string) => ConfigItemValue | undefined - setBaseConfig: (configId: string, value: ConfigItemValue) => void - removeBaseConfig: (configId: string) => void - - getVariantConfig: (variantId: string, configId: string) => ConfigItemValue | undefined - setVariantConfig: (variantId: string, configId: string, value: ConfigItemValue) => void - removeVariantConfig: (variantId: string, configId: string) => void -} - export type MigrationContextSystem = MigrationContextWithTriggeredActions export interface MigrationStepBase< @@ -163,9 +90,3 @@ export interface MigrationStep< export type MigrationStepCore = MigrationStep export type MigrationStepSystem = MigrationStep -export type MigrationStepStudio = MigrationStep -export type MigrationStepShowStyle = MigrationStep< - ValidateFunctionShowStyle, - MigrateFunctionShowStyle, - InputFunctionShowStyle -> diff --git a/packages/corelib/src/dataModel/Blueprint.ts b/packages/corelib/src/dataModel/Blueprint.ts index 32ba8af5e5..2ca55d4e2e 100644 --- a/packages/corelib/src/dataModel/Blueprint.ts +++ b/packages/corelib/src/dataModel/Blueprint.ts @@ -38,12 +38,6 @@ export interface Blueprint { showStyleConfigPresets?: Record databaseVersion: { - showStyle: { - [showStyleBaseId: string]: string - } - studio: { - [studioId: string]: string - } system: string | undefined } diff --git a/packages/job-worker/src/__mocks__/context.ts b/packages/job-worker/src/__mocks__/context.ts index d06fac5154..52df23225e 100644 --- a/packages/job-worker/src/__mocks__/context.ts +++ b/packages/job-worker/src/__mocks__/context.ts @@ -296,7 +296,6 @@ const MockStudioBlueprint: () => StudioBlueprintManifest = () => ({ }, studioConfigSchema: JSONBlobStringify({}), - studioMigrations: [], getBaseline: () => { return { timelineObjects: [], @@ -328,7 +327,6 @@ const MockShowStyleBlueprint: () => ShowStyleBlueprintManifest = () => ({ }, showStyleConfigSchema: JSONBlobStringify({}), - showStyleMigrations: [], getShowStyleVariantId: (_context, variants): string | null => { return variants[0]._id }, diff --git a/packages/job-worker/src/blueprints/__tests__/lib.ts b/packages/job-worker/src/blueprints/__tests__/lib.ts index cd34200204..29b54f4aac 100644 --- a/packages/job-worker/src/blueprints/__tests__/lib.ts +++ b/packages/job-worker/src/blueprints/__tests__/lib.ts @@ -18,7 +18,6 @@ export function generateFakeBlueprint( integrationVersion: '0.0.0', TSRVersion: '0.0.0', studioConfigManifest: [], - studioMigrations: [], getBaseline: () => { return { timelineObjects: [], @@ -45,8 +44,6 @@ export function generateFakeBlueprint( databaseVersion: { system: undefined, - showStyle: {}, - studio: {}, }, blueprintVersion: '', diff --git a/packages/job-worker/src/blueprints/defaults/studio.ts b/packages/job-worker/src/blueprints/defaults/studio.ts index ff8a899cf8..43949c6384 100644 --- a/packages/job-worker/src/blueprints/defaults/studio.ts +++ b/packages/job-worker/src/blueprints/defaults/studio.ts @@ -26,7 +26,6 @@ export const DefaultStudioBlueprint: ReadonlyDeep = dee blueprintType: BlueprintManifestType.STUDIO, studioConfigSchema: JSONBlobStringify({}), - studioMigrations: [], configPresets: { 0: {