{
  "version": 3,
  "sources": ["../../../../src/evaluator/dependency-nodes/base-eval-node.ts"],
  "sourcesContent": [
    "import { type DependencyNode } from \"../../core/managers/dependency-node.mjs\";\nimport type { SpillMetaNode } from \"./spill-meta-node.mjs\";\n\nexport class BaseEvalNode<T> {\n  public key: string;\n  private _dependencies: Set<DependencyNode> = new Set();\n  private _lastDependencies: Set<DependencyNode> = new Set();\n  public _evaluationResult: T;\n  private _resolved: boolean = false;\n\n  constructor(key: string) {\n    this.key = key;\n    this._evaluationResult = {\n      type: \"awaiting-evaluation\",\n      waitingFor: this,\n      errAddress: this,\n    } as any;\n  }\n\n  public addDependency(dep: DependencyNode) {\n    if (this._dependencies.has(dep)) {\n      return;\n    }\n    this._dependencies.add(dep);\n  }\n\n  public get directDepsUpdated() {\n    return (\n      !this._lastDependencies.isSubsetOf(this._dependencies) ||\n      this._dependencies.size !== this._lastDependencies.size\n    );\n  }\n\n  public resolve() {\n    if (this.canResolve()) {\n      this._resolved = true;\n    }\n  }\n\n  public canResolve() {\n    return (\n      (this.evaluationResult as any).type !== \"awaiting-evaluation\" &&\n      !this.directDepsUpdated\n    );\n  }\n\n  public get resolved() {\n    return this._resolved;\n  }\n\n  public get evaluationResult(): T {\n    return this._evaluationResult;\n  }\n\n  public setEvaluationResult(result: T) {\n    this._evaluationResult = result;\n  }\n\n  public invalidate() {\n    this._dependencies = new Set();\n    this._lastDependencies = new Set();\n    this._resolved = false;\n    this._evaluationResult = {\n      type: \"awaiting-evaluation\",\n      waitingFor: this,\n      errAddress: this,\n    } as T;\n  }\n\n  public resetDirectDepsUpdated() {\n    if (this._resolved) {\n      return;\n    }\n    this._lastDependencies = new Set(this._dependencies);\n    this._dependencies = new Set();\n  }\n\n  /**\n   * Get the direct dependencies of the node, either RangeEvaluationNode or DependencyNode\n   */\n  public getDependencies() {\n    return this._dependencies;\n  }\n\n  public restoreResolvedSnapshot(options: {\n    dependencies: Set<DependencyNode>;\n    evaluationResult: T;\n  }) {\n    this._dependencies = new Set(options.dependencies);\n    this._lastDependencies = new Set(options.dependencies);\n    this._evaluationResult = options.evaluationResult;\n    this._resolved = true;\n  }\n\n  /**\n   * Just to mirror the method in RangeEvaluationNode\n   */\n  public getAllDependencies() {\n    return this.getDependencies();\n  }\n\n  /**\n   * Just to mirror the method in RangeEvaluationNode\n   */\n  public getFrontierDependencies(): Set<SpillMetaNode> {\n    return new Set();\n  }\n\n  toJSON(visitor: Set<string> = new Set()): any {\n    const hasVisited = visitor?.has(this.key);\n    if (hasVisited) {\n      return {\n        key: this.key,\n        resolved: this.resolved,\n        cycle: true,\n        dependencies: [],\n      };\n    }\n    visitor?.add(this.key);\n    return {\n      key: this.key,\n      resolved: this.resolved,\n      evaluationResult: this.evaluationResult,\n      dependencies: Array.from(this.getDependencies()).map((node) =>\n        node.toJSON(visitor)\n      ),\n    };\n  }\n}\n"
  ],
  "mappings": ";AAGO,MAAM,aAAgB;AAAA,EACpB;AAAA,EACC,gBAAqC,IAAI;AAAA,EACzC,oBAAyC,IAAI;AAAA,EAC9C;AAAA,EACC,YAAqB;AAAA,EAE7B,WAAW,CAAC,KAAa;AAAA,IACvB,KAAK,MAAM;AAAA,IACX,KAAK,oBAAoB;AAAA,MACvB,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,IACd;AAAA;AAAA,EAGK,aAAa,CAAC,KAAqB;AAAA,IACxC,IAAI,KAAK,cAAc,IAAI,GAAG,GAAG;AAAA,MAC/B;AAAA,IACF;AAAA,IACA,KAAK,cAAc,IAAI,GAAG;AAAA;AAAA,MAGjB,iBAAiB,GAAG;AAAA,IAC7B,OACE,CAAC,KAAK,kBAAkB,WAAW,KAAK,aAAa,KACrD,KAAK,cAAc,SAAS,KAAK,kBAAkB;AAAA;AAAA,EAIhD,OAAO,GAAG;AAAA,IACf,IAAI,KAAK,WAAW,GAAG;AAAA,MACrB,KAAK,YAAY;AAAA,IACnB;AAAA;AAAA,EAGK,UAAU,GAAG;AAAA,IAClB,OACG,KAAK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