-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Data piping for Rundown, Segment and Part
- Loading branch information
Showing
43 changed files
with
1,761 additions
and
129 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/apps/backend/src/api-server/services/PartService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import EventEmitter from 'eventemitter3' | ||
import { Application, PaginationParams, Params } from '@feathersjs/feathers' | ||
import { ServiceTypes, Services, PartServiceDefinition as Definition } from '@sofie-prompter-editor/shared-model' | ||
export { PlaylistServiceDefinition } from '@sofie-prompter-editor/shared-model' | ||
import { PublishChannels } from '../PublishChannels.js' | ||
import { CustomFeathersService } from './lib.js' | ||
import { Store } from '../../data-stores/Store.js' | ||
import { Lambda, observe } from 'mobx' | ||
import { LoggerInstance } from '../../lib/logger.js' | ||
import { NotFound, NotImplemented } from '@feathersjs/errors' | ||
|
||
export type PartFeathersService = CustomFeathersService<Definition.Service, Definition.Events> | ||
|
||
/** The methods exposed by this class are exposed in the API */ | ||
export class PartService extends EventEmitter<Definition.Events> implements Definition.Service { | ||
static setupService(log: LoggerInstance, app: Application<ServiceTypes, any>, store: Store): PartFeathersService { | ||
app.use(Services.Part, new PartService(log.category('PartService'), store), { | ||
methods: Definition.ALL_METHODS, | ||
serviceEvents: Definition.ALL_EVENTS, | ||
}) | ||
const service = app.service(Services.Part) as PartFeathersService | ||
this.setupPublications(app, service) | ||
return service | ||
} | ||
private static setupPublications(app: Application<ServiceTypes, any>, service: PartFeathersService) { | ||
service.publish('created', (data, _context) => { | ||
return app.channel(PublishChannels.RundownsInPlaylist(data.playlistId)) | ||
}) | ||
service.publish('updated', (data, _context) => { | ||
return app.channel(PublishChannels.RundownsInPlaylist(data.playlistId)) | ||
}) | ||
// service.publish('patched', (data, _context) => { | ||
// return app.channel(PublishChannels.RundownsInPlaylist(data.playlistId)) | ||
// }) | ||
service.publish('removed', (data, _context) => { | ||
return app.channel(PublishChannels.RundownsInPlaylist(data.playlistId)) | ||
}) | ||
} | ||
|
||
private observers: Lambda[] = [] | ||
constructor( | ||
private log: LoggerInstance, | ||
|
||
private store: Store | ||
) { | ||
super() | ||
|
||
this.observers.push( | ||
observe(this.store.parts.parts, (change) => { | ||
this.log.debug('observed change', change) | ||
|
||
if (change.type === 'add') { | ||
this.emit('created', change.newValue) | ||
} else if (change.type === 'update') { | ||
// const patch = diff(change.oldValue, change.newValue) | ||
// if (patch) this.emit('patched', patch) | ||
this.emit('updated', change.newValue) | ||
} else if (change.type === 'delete') { | ||
this.emit('removed', { | ||
_id: change.oldValue._id, | ||
playlistId: change.oldValue.playlistId, | ||
rundownId: change.oldValue.rundownId, | ||
segmentId: change.oldValue.segmentId, | ||
}) | ||
} | ||
}) | ||
) | ||
} | ||
destroy() { | ||
// dispose of observers: | ||
for (const obs of this.observers) { | ||
obs() | ||
} | ||
} | ||
|
||
public async find(_params?: Params & { paginate?: PaginationParams }): Promise<Data[]> { | ||
return Array.from(this.store.parts.parts.values()) | ||
} | ||
public async get(id: Id, _params?: Params): Promise<Data> { | ||
const data = this.store.parts.parts.get(id) | ||
if (!data) throw new NotFound(`Rundown "${id}" not found`) | ||
return data | ||
} | ||
/** @deprecated not supported */ | ||
public async create(_data: Data, _params?: Params): Promise<Result> { | ||
throw new NotImplemented(`Not supported`) | ||
} | ||
/** @deprecated not supported */ | ||
public async update(_id: NullId, _data: Data, _params?: Params): Promise<Result> { | ||
throw new NotImplemented(`Not supported`) | ||
} | ||
/** @deprecated not supported */ | ||
// public async patch(_id: NullId, _data: PatchData, _params?: Params): Promise<Result> { | ||
// throw new NotImplemented(`Not supported`) | ||
// } | ||
/** @deprecated not supported */ | ||
public async remove(_id: NullId, _params?: Params): Promise<Result> { | ||
throw new NotImplemented(`Not supported`) | ||
} | ||
} | ||
type Result = Definition.Result | ||
type Id = Definition.Id | ||
type NullId = Definition.NullId | ||
type Data = Definition.Data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.