import { Parser } from "ts-matches" import { Effects, EnsureWrapperDataPath, ExtractWrapperData } from "../types" import { NoAny } from "." export class WrapperData { constructor( readonly effects: Effects, readonly path: Path & EnsureWrapperDataPath, readonly options: { /** Defaults to what ever the package currently in */ packageId?: string | undefined } = {}, ) {} const() { return this.effects.getWrapperData({ ...this.options, path: this.path as any, callback: this.effects.restart, }) } once() { return this.effects.getWrapperData({ ...this.options, path: this.path as any, callback: () => {}, }) } async *watch() { while (true) { let callback: () => void const waitForNext = new Promise((resolve) => { callback = resolve }) yield await this.effects.getWrapperData({ ...this.options, path: this.path as any, callback: () => callback(), }) await waitForNext } } } export function getWrapperData( effects: Effects, path: Path & EnsureWrapperDataPath, options: { /** Defaults to what ever the package currently in */ packageId?: string | undefined } = {}, ) { return new WrapperData(effects, path as any, options) }