1- import { TriggersContext } from '@sofie-automation/meteor-lib/dist/triggers/triggersContext'
1+ import {
2+ TriggersAsyncCollection ,
3+ TriggersContext ,
4+ TriggerTrackerComputation ,
5+ } from '@sofie-automation/meteor-lib/dist/triggers/triggersContext'
26import { SINGLE_USE_TOKEN_SALT } from '@sofie-automation/meteor-lib/dist/api/userActions'
3- import { assertNever , getHash , Time } from '../../lib/tempLib'
7+ import { assertNever , getHash , ProtectedString , Time } from '../../lib/tempLib'
48import { getCurrentTime } from '../../lib/lib'
59import { MeteorCall } from '../methods'
610import { ClientAPI } from '@sofie-automation/meteor-lib/dist/api/client'
@@ -28,26 +32,57 @@ import {
2832} from '../../collections'
2933import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
3034import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
35+ import { AsyncOnlyReadOnlyMongoCollection } from '../../collections/collection'
3136
3237export function hashSingleUseToken ( token : string ) : string {
3338 return getHash ( SINGLE_USE_TOKEN_SALT + token )
3439}
3540
41+ class TriggersCollection2 < DBInterface extends { _id : ProtectedString < any > } >
42+ implements TriggersAsyncCollection < DBInterface >
43+ {
44+ readonly #collection: AsyncOnlyReadOnlyMongoCollection < DBInterface >
45+
46+ constructor ( collection : AsyncOnlyReadOnlyMongoCollection < DBInterface > ) {
47+ this . #collection = collection
48+ }
49+
50+ async findFetchAsync (
51+ computation : TriggerTrackerComputation | null ,
52+ selector : any ,
53+ options ?: any
54+ ) : Promise < Array < DBInterface > > {
55+ return Tracker . withComputation ( computation as Tracker . Computation | null , async ( ) => {
56+ return this . #collection. findFetchAsync ( selector , options )
57+ } )
58+ }
59+
60+ async findOneAsync (
61+ computation : TriggerTrackerComputation | null ,
62+ selector : any ,
63+ options ?: any
64+ ) : Promise < DBInterface | undefined > {
65+ return Tracker . withComputation ( computation as Tracker . Computation | null , async ( ) => {
66+ return this . #collection. findOneAsync ( selector , options )
67+ } )
68+ }
69+ }
70+
3671export const MeteorTriggersContext : TriggersContext = {
3772 MeteorCall,
3873
3974 logger,
4075
4176 isClient : false ,
4277
43- AdLibActions,
44- AdLibPieces,
45- Parts,
46- RundownBaselineAdLibActions,
47- RundownBaselineAdLibPieces,
48- RundownPlaylists,
49- Rundowns,
50- Segments,
78+ AdLibActions : new TriggersCollection2 ( AdLibActions ) ,
79+ AdLibPieces : new TriggersCollection2 ( AdLibPieces ) ,
80+ Parts : new TriggersCollection2 ( Parts ) ,
81+ RundownBaselineAdLibActions : new TriggersCollection2 ( RundownBaselineAdLibActions ) ,
82+ RundownBaselineAdLibPieces : new TriggersCollection2 ( RundownBaselineAdLibPieces ) ,
83+ RundownPlaylists : new TriggersCollection2 ( RundownPlaylists ) ,
84+ Rundowns : new TriggersCollection2 ( Rundowns ) ,
85+ Segments : new TriggersCollection2 ( Segments ) ,
5186
5287 hashSingleUseToken,
5388
@@ -67,14 +102,17 @@ export const MeteorTriggersContext: TriggersContext = {
67102 )
68103 } ,
69104
70- nonreactiveTracker : Tracker . nonreactive ,
105+ withComputation : async ( computation , func ) => {
106+ return Tracker . withComputation ( computation as Tracker . Computation | null , func )
107+ } ,
71108
72109 memoizedIsolatedAutorun : async < TArgs extends any [ ] , TRes > (
73- fnc : ( ...args : TArgs ) => Promise < TRes > ,
110+ computation : TriggerTrackerComputation | null ,
111+ fnc : ( computation : TriggerTrackerComputation | null , ...args : TArgs ) => Promise < TRes > ,
74112 _functionName : string ,
75113 ...params : TArgs
76114 ) : Promise < TRes > => {
77- return fnc ( ...params )
115+ return fnc ( computation , ...params )
78116 } ,
79117
80118 createContextForRundownPlaylistChain,
0 commit comments