diff --git a/src/workflows/workflowDoc.ts b/src/workflows/workflowDoc.ts new file mode 100644 index 00000000..05b9689f --- /dev/null +++ b/src/workflows/workflowDoc.ts @@ -0,0 +1,44 @@ +import { YDocument } from '@jupyter/ydoc'; +import * as Y from 'yjs'; +import { Workflow, Task } from './_interface/workflow.schema'; + +export class WorkflowDoc extends YDocument implements Workflow { + private _tasks: Y.Array>; + private _name: Y.Text; + private _parameters: Y.Map; + private _schedule: Y.Text; + private _timezone: Y.Text; + + constructor() { + super(); + + this._tasks = this.ydoc.getArray>('tasks'); + this._name = this.ydoc.getMap('name'); + this._parameters = this.ydoc.getMap('parameters'); + this._schedule = this.ydoc.getMap('schedule'); + this._timezone = this.ydoc.getMap('timezone'); + + this._tasks.observeDeep(this._tasksObserver); + //TODO: add other observers + } + + // Getter and setter methods + get tasks(): Task[] { + return this._tasks.map(task => task.toJSON() as Task); + } + + set tasks(value: Task[]) { + this.transact(() => { + this._tasks.delete(0, this._tasks.length); + value.forEach(task => { + this._tasks.push([Y.Map.from(Object.entries(task))]); + }); + }); + } + + //TODO: add other getters/setters + + private _tasksObserver = (events: Y.YEvent[]) => { + // TODO: Handle task changes + }; +}