Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/runtime/GraphEvalContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class GraphEvalContext implements t.GraphEvalContext {
cache = new Map<string, any>();
// Locals are stored per-context. Lookups delegate up the hierarchy.
locals = new Map<string, any>();
_currentScope: any = null;

constructor(
readonly parent: GraphEvalContext | null = null,
Expand Down Expand Up @@ -115,6 +116,16 @@ export class GraphEvalContext implements t.GraphEvalContext {
*/
span() {}

get currentScope(): any {
return this._currentScope ?? this.parent?.currentScope;
}

withScope(scope: any): t.GraphEvalContext {
const ctx = new GraphEvalContext(this);
ctx._currentScope = scope;
return ctx;
}

}

export class NodePendingError extends Error {
Expand Down
1 change: 1 addition & 0 deletions src/main/runtime/ModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export abstract class GenericModuleLoader implements ModuleLoader {
this.addModule('@system/Output', systemModules.Output);
this.addModule('@system/Param', systemModules.Param);
this.addModule('@system/Result', systemModules.Output);
this.addModule('@system/Scope', systemModules.Scope);
}

abstract resolveComputeUrl(ref: string): string;
Expand Down
9 changes: 8 additions & 1 deletion src/main/runtime/NodeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ export class NodeView {

supportsSubgraph() {
const { subgraph } = this.getModuleSpec();
if (this.isScopeNode() && this.graph.isSubgraph()) {
return false;
}
return !!subgraph;
}

getSubgraph(): GraphView | null {
const { subgraph } = this.getModuleSpec();
if (!subgraph) {
if (!subgraph || (this.isScopeNode() && this.graph.isSubgraph())) {
return null;
}
const { nodes = {}, rootNodeId = '', metadata = {} } = this.nodeSpec.subgraph ?? {};
Expand Down Expand Up @@ -303,6 +306,10 @@ export class NodeView {
return this.canDock() && !!this.metadata.docked;
}

isScopeNode() {
return this.ref === '@system/Scope';
}

}

export interface NodeLink {
Expand Down
17 changes: 17 additions & 0 deletions src/main/system/Scope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ModuleSpecSchema } from '../schema/ModuleSpec.js';

export const Scope = ModuleSpecSchema.create({
moduleName: 'Scope',
version: '1.0.0',
keywords: ['system'],
description: 'Returns the current scope or an empty object',
deprecated: '',
params: {},
result: {
schema: { type: 'object' },
async: false,
},
newScope: false,
cacheMode: 'auto',
evalMode: 'auto'
});
1 change: 1 addition & 0 deletions src/main/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './Frame.js';
export * from './Input.js';
export * from './Output.js';
export * from './Param.js';
export * from './Scope.js';
1 change: 1 addition & 0 deletions src/main/types/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface GraphEvalContext {
locals: Map<string, any>;
nodeEvaluated: Event<NodeResult>;
scopeCaptured: Event<ScopeData>;
_currentScope: any;

clear(): void;
finalize(): Promise<void>;
Expand Down
Loading