Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add baseline expectedPlayoutItems support (#520) [publish] #520

Merged
merged 7 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions meteor/__mocks__/helpers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ export function setupMockStudioBlueprint(

studioConfigManifest: [],
studioMigrations: [],
getBaseline: (): TSR.TSRTimelineObjBase[] => {
return []
getBaseline: () => {
return {
timelineObjects: [],
}
},
getShowStyleId: (): string | null => {
return SHOW_STYLE_ID
Expand Down Expand Up @@ -309,7 +311,7 @@ export function setupMockShowStyleBlueprint(
return {
rundown,
globalAdLibPieces: [],
baseline: [],
baseline: { timelineObjects: [] },
}
},
getSegment: (context: unknown, ingestSegment: IngestSegment): BlueprintResultSegment => {
Expand Down
18 changes: 17 additions & 1 deletion meteor/lib/collections/ExpectedPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ export type ExpectedPackageDB =
| ExpectedPackageDBFromBaselineAdLibAction
| ExpectedPackageDBFromBucketAdLib
| ExpectedPackageDBFromBucketAdLibAction
| ExpectedPackageDBFromRundownBaselineObjects
| ExpectedPackageDBFromStudioBaselineObjects

export enum ExpectedPackageDBType {
PIECE = 'piece',
ADLIB_ACTION = 'adlib_action',
BASELINE_ADLIB_ACTION = 'baseline_adlib_action',
BUCKET_ADLIB = 'bucket_adlib',
BUCKET_ADLIB_ACTION = 'bucket_adlib_action',
RUNDOWN_BASELINE_OBJECTS = 'rundown_baseline_objects',
STUDIO_BASELINE_OBJECTS = 'studio_baseline_objects',
}
export interface ExpectedPackageDBBase extends Omit<ExpectedPackage.Base, '_id'> {
_id: ExpectedPackageId
Expand All @@ -44,7 +48,7 @@ export interface ExpectedPackageDBBase extends Omit<ExpectedPackage.Base, '_id'>
/** Hash that changes whenever the content or version changes. See getContentVersionHash() */
contentVersionHash: string

pieceId: ProtectedString<any>
pieceId: ProtectedString<any> | null
fromPieceType: ExpectedPackageDBType
}
export interface ExpectedPackageDBFromPiece extends ExpectedPackageDBBase {
Expand All @@ -69,6 +73,18 @@ export interface ExpectedPackageDBFromBaselineAdLibAction extends ExpectedPackag
/** The rundown of the Piece this package belongs to */
rundownId: RundownId
}

export interface ExpectedPackageDBFromRundownBaselineObjects extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.RUNDOWN_BASELINE_OBJECTS
/** The rundown of the Piece this package belongs to */
rundownId: RundownId
pieceId: null
}
export interface ExpectedPackageDBFromStudioBaselineObjects extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.STUDIO_BASELINE_OBJECTS
pieceId: null
}

export interface ExpectedPackageDBFromBucketAdLib extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB
/** The Bucket adlib this package belongs to */
Expand Down
17 changes: 16 additions & 1 deletion meteor/lib/collections/ExpectedPlayoutItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,30 @@ import { registerIndex } from '../database'
*/
export type ExpectedPlayoutItemId = ProtectedString<'ExpectedPlayoutItemId'>
/** @deprecated */
export interface ExpectedPlayoutItem extends ExpectedPlayoutItemGeneric {
export interface ExpectedPlayoutItemBase extends ExpectedPlayoutItemGeneric {
/** Globally unique id of the item */
_id: ExpectedPlayoutItemId

/** The studio installation this ExpectedPlayoutItem was generated in */
studioId: StudioId
}
/** @deprecated */
export interface ExpectedPlayoutItemRundown extends ExpectedPlayoutItemBase {
/** The rundown id that is the source of this PlayoutItem */
rundownId: RundownId
/** The part id that is the source of this Playout Item */
partId?: PartId
// /** The piece id that is the source of this Playout Item */
// pieceId: PieceId
/** Is created for studio/rundown baseline */
baseline?: 'rundown'
}
/** @deprecated */
export interface ExpectedPlayoutItemStudio extends ExpectedPlayoutItemBase {
baseline: 'studio'
}
/** @deprecated */
export type ExpectedPlayoutItem = ExpectedPlayoutItemStudio | ExpectedPlayoutItemRundown

/** @deprecated */
export const ExpectedPlayoutItems: TransformedCollection<
Expand All @@ -40,3 +51,7 @@ registerIndex(ExpectedPlayoutItems, {
registerIndex(ExpectedPlayoutItems, {
rundownId: 1,
})
registerIndex(ExpectedPlayoutItems, {
studioId: 1,
baseline: 1,
})
4 changes: 2 additions & 2 deletions meteor/server/__tests__/cronjobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MeteorMock } from '../../__mocks__/meteor'
import { logger } from '../logging'
import { IngestDataCache, IngestCacheType, IngestDataCacheObjId } from '../../lib/collections/IngestDataCache'
import { Random } from 'meteor/random'
import { protectString } from '../../lib/lib'
import { getRandomId, protectString } from '../../lib/lib'
import { Rundowns, RundownId } from '../../lib/collections/Rundowns'
import { UserActionsLog, UserActionsLogItemId } from '../../lib/collections/UserActionsLog'
import { Snapshots, SnapshotId, SnapshotType } from '../../lib/collections/Snapshots'
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('cronjobs', () => {
},
modified: new Date(2000, 0, 1, 0, 0, 0).getTime(),
// this one is attached to rundown0
rundownId: protectString(Random.id()),
rundownId: getRandomId(),
type: IngestCacheType.RUNDOWN,
})
// Attached IngestDataCache object 1
Expand Down
10 changes: 5 additions & 5 deletions meteor/server/api/__tests__/peripheralDevice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Pieces } from '../../../lib/collections/Pieces'

import { PeripheralDeviceAPI, PeripheralDeviceAPIMethods } from '../../../lib/api/peripheralDevice'

import { getCurrentTime, literal, protectString, ProtectedString, waitTime } from '../../../lib/lib'
import { getCurrentTime, literal, protectString, ProtectedString, waitTime, getRandomId } from '../../../lib/lib'
import * as MOS from 'mos-connection'
import { testInFiber } from '../../../__mocks__/helpers/jest'
import { setupDefaultStudioEnvironment, DefaultEnvironment } from '../../../__mocks__/helpers/database'
Expand Down Expand Up @@ -587,9 +587,9 @@ describe('test peripheralDevice general API methods', () => {
let deviceId: ProtectedString<any>
let device: PeripheralDevice
beforeEach(() => {
workFlowId = protectString(Random.id())
workStepIds = [protectString(Random.id()), protectString(Random.id())]
deviceId = protectString(Random.id())
workFlowId = getRandomId()
workStepIds = [getRandomId(), getRandomId()]
deviceId = getRandomId()
env = setupDefaultStudioEnvironment()
PeripheralDevices.insert({
_id: deviceId,
Expand Down Expand Up @@ -758,7 +758,7 @@ describe('test peripheralDevice general API methods', () => {
const MOCK_MEDIA_ID = 'SOME_FILE'.toUpperCase()
const MOCK_OBJID = Random.id()
beforeEach(() => {
deviceId = protectString(Random.id())
deviceId = getRandomId()
env = setupDefaultStudioEnvironment()
PeripheralDevices.insert({
_id: deviceId,
Expand Down
8 changes: 4 additions & 4 deletions meteor/server/api/__tests__/userActions/buckets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { Rundowns, Rundown } from '../../../../lib/collections/Rundowns'
import { setMinimumTakeSpan } from '../../userActions'
import { RundownPlaylists, RundownPlaylist } from '../../../../lib/collections/RundownPlaylists'
import { RESTART_SALT } from '../../../../lib/api/userActions'
import { getHash, waitForPromise, protectString } from '../../../../lib/lib'
import { getHash, waitForPromise, protectString, getRandomId } from '../../../../lib/lib'
import { UserActionsLog } from '../../../../lib/collections/UserActionsLog'
import { MeteorCall } from '../../../../lib/api/methods'
import { ClientAPI } from '../../../../lib/api/client'
import { Bucket, Buckets } from '../../../../lib/collections/Buckets'
import { Bucket, BucketId, Buckets } from '../../../../lib/collections/Buckets'
import { Random } from 'meteor/random'
import { BucketAdLibs } from '../../../../lib/collections/BucketAdlibs'
import { PieceLifespan } from '@sofie-automation/blueprints-integration'
Expand All @@ -40,7 +40,7 @@ namespace UserActionAPI {
describe('User Actions - Buckets', () => {
let env: DefaultEnvironment
function setUpMockBucket() {
const bucketId = protectString(Random.id())
const bucketId: BucketId = getRandomId()
const bucket: Bucket = {
_id: bucketId,
_rank: 0,
Expand All @@ -55,7 +55,7 @@ describe('User Actions - Buckets', () => {

for (let i = 0; i < 3; i++) {
BucketAdLibs.insert({
_id: protectString(Random.id()),
_id: getRandomId(),
_rank: 0,
bucketId: bucketId,
externalId: `FAKE_EXTERNAL_ID_${i}`,
Expand Down
7 changes: 3 additions & 4 deletions meteor/server/api/__tests__/userActions/mediaManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Meteor } from 'meteor/meteor'
import { Random } from 'meteor/random'
import { testInFiber, testInFiberOnly } from '../../../../__mocks__/helpers/jest'
import { protectString, getCurrentTime } from '../../../../lib/lib'
import { getCurrentTime, getRandomId } from '../../../../lib/lib'
import { setupDefaultStudioEnvironment, DefaultEnvironment } from '../../../../__mocks__/helpers/database'
import { ClientAPI } from '../../../../lib/api/client'
import { MediaWorkFlows } from '../../../../lib/collections/MediaWorkFlows'
import { MediaWorkFlowId, MediaWorkFlows } from '../../../../lib/collections/MediaWorkFlows'
import { PeripheralDeviceCommands } from '../../../../lib/collections/PeripheralDeviceCommands'
import { PeripheralDevices } from '../../../../lib/collections/PeripheralDevices'

Expand All @@ -25,7 +24,7 @@ namespace UserActionAPI {
describe('User Actions - Media Manager', () => {
let env: DefaultEnvironment
function setupMockWorkFlow(env: DefaultEnvironment) {
const workFlowId = protectString(Random.id())
const workFlowId: MediaWorkFlowId = getRandomId()
const workFlow = {
_id: workFlowId,
_rev: '',
Expand Down
12 changes: 10 additions & 2 deletions meteor/server/api/blueprints/__tests__/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ describe('Test blueprint cache', () => {

studioConfigManifest: [],
studioMigrations: [],
getBaseline: () => [],
getBaseline: () => {
return {
timelineObjects: [],
}
},
getShowStyleId: () => null,
})

Expand Down Expand Up @@ -250,7 +254,11 @@ describe('Test blueprint cache', () => {

studioConfigManifest: [],
studioMigrations: [],
getBaseline: () => [],
getBaseline: () => {
return {
timelineObjects: [],
}
},
getShowStyleId: () => null,
})

Expand Down
6 changes: 5 additions & 1 deletion meteor/server/api/blueprints/__tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ describe('Test blueprint api context', () => {
] as ConfigManifestEntry[],

studioMigrations: [],
getBaseline: () => [],
getBaseline: () => {
return {
timelineObjects: [],
}
},
getShowStyleId: () => null,
})
const blueprint = generateFakeBlueprint('', BlueprintManifestType.STUDIO, manifest)
Expand Down
6 changes: 5 additions & 1 deletion meteor/server/api/blueprints/__tests__/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export function generateFakeBlueprint(id: string, type?: BlueprintManifestType,
TSRVersion: '0.0.0',
studioConfigManifest: [],
studioMigrations: [],
getBaseline: () => [],
getBaseline: () => {
return {
timelineObjects: [],
}
},
getShowStyleId: () => null
})`

Expand Down
9 changes: 4 additions & 5 deletions meteor/server/api/buckets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as _ from 'underscore'
import { Random } from 'meteor/random'
import { Meteor } from 'meteor/meteor'
import { Buckets, Bucket, BucketId } from '../../lib/collections/Buckets'
import { literal, protectString, waitForPromise, waitForPromiseAll } from '../../lib/lib'
import { getRandomId, literal, waitForPromise, waitForPromiseAll } from '../../lib/lib'
import { BucketSecurity } from '../security/buckets'
import { BucketAdLibs, BucketAdLib } from '../../lib/collections/BucketAdlibs'
import { ExpectedMediaItems } from '../../lib/collections/ExpectedMediaItems'
Expand Down Expand Up @@ -140,7 +139,7 @@ export namespace BucketsAPI {
}

const newBucket = literal<Bucket>({
_id: protectString(Random.id()),
_id: getRandomId(),
_rank: rank,
name: name,
studioId,
Expand Down Expand Up @@ -225,7 +224,7 @@ export namespace BucketsAPI {

adLibAction = {
...action,
_id: protectString(Random.id()),
_id: getRandomId(),
bucketId: bucketId,
}
} else {
Expand Down Expand Up @@ -262,7 +261,7 @@ export namespace BucketsAPI {

adLibAction = {
...(_.omit(action, ['partId', 'rundownId']) as Omit<AdLibAction, 'partId' | 'rundownId'>),
_id: protectString(Random.id()),
_id: getRandomId(),
externalId: '', // TODO - is this ok?
bucketId: bucketId,
studioId: studioId,
Expand Down
17 changes: 13 additions & 4 deletions meteor/server/api/ingest/cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ExpectedPackageDB } from '../../../lib/collections/ExpectedPackages'
import { SegmentId } from '../../../lib/collections/Segments'
import { CacheForIngest } from './cache'

Expand All @@ -13,11 +14,19 @@ export function removeSegmentContents(cache: CacheForIngest, segmentIds: Set<Seg
if (removedPartIds.length > 0) {
// Clean up all the db items that belong to the removed Parts
const removedPartIds2 = new Set(removedPartIds)
cache.Pieces.remove((p) => removedPartIds2.has(p.startPartId))
cache.ExpectedPlayoutItems.remove((e) => e.partId && removedPartIds2.has(e.partId))

const removedPieceIds = cache.Pieces.remove((p) => removedPartIds2.has(p.startPartId))
const removedAdlibIds = cache.AdLibPieces.remove((e) => e.partId && removedPartIds2.has(e.partId))
const removedActionIds = cache.AdLibActions.remove((e) => removedPartIds2.has(e.partId))
const allRemovedPieceIds: Set<NonNullable<ExpectedPackageDB['pieceId']>> = new Set([
...removedPieceIds,
...removedAdlibIds,
...removedActionIds,
])

cache.ExpectedPackages.remove((e) => e.pieceId && allRemovedPieceIds.has(e.pieceId))
cache.ExpectedPlayoutItems.remove((e) => 'partId' in e && e.partId && removedPartIds2.has(e.partId))
cache.ExpectedMediaItems.remove((e) => 'partId' in e && e.partId && removedPartIds2.has(e.partId))
cache.AdLibPieces.remove((e) => e.partId && removedPartIds2.has(e.partId))
cache.AdLibActions.remove((e) => removedPartIds2.has(e.partId))
}
}
}
Loading