@nodescript/core
Advanced tools
Comparing version 6.1.2 to 7.0.0
@@ -54,3 +54,3 @@ import { clone } from '../util/index.js'; | ||
for (const node of scope.getEmittedNodes()) { | ||
this.symbols.createNodeSym(scope.scopeId, node.nodeId); | ||
this.symbols.createNodeSym(node.getNodeUid()); | ||
} | ||
@@ -84,4 +84,4 @@ } | ||
for (const node of scope.getEmittedNodes()) { | ||
const sym = this.symbols.getNodeSym(scope.scopeId, node.nodeId); | ||
this.code.line(`nodeMap.set(${JSON.stringify(node.nodeId)}, ${sym})`); | ||
const sym = this.symbols.getNodeSym(node.getNodeUid()); | ||
this.code.line(`nodeMap.set(${JSON.stringify(node.getNodeUid())}, ${sym})`); | ||
} | ||
@@ -103,3 +103,3 @@ } | ||
else { | ||
const rootNodeSym = this.symbols.getNodeSym('root', rootNode.nodeId); | ||
const rootNodeSym = this.symbols.getNodeSym(rootNode.getNodeUid()); | ||
this.code.line(`export const compute = ${rootNodeSym};`); | ||
@@ -106,0 +106,0 @@ } |
@@ -47,4 +47,2 @@ import { GraphView, NodeView } from '../runtime/index.js'; | ||
private isNodeCached; | ||
private getNodeSym; | ||
private getLineSym; | ||
private escapeValue; | ||
@@ -51,0 +49,0 @@ private asyncSym; |
@@ -55,7 +55,7 @@ import { convertAuto, isSchemaCompatible } from '../util/index.js'; | ||
emitNode(node) { | ||
this.emitComment(`${node.ref} ${node.nodeId}`); | ||
const sym = this.getNodeSym(node.nodeId); | ||
this.emitComment(`${node.ref} ${node.getNodeUid()}`); | ||
const sym = this.symbols.getNodeSym(node.getNodeUid()); | ||
this.code.block(`${this.asyncSym(node)}function ${sym}(params, ctx) {`, `}`, () => { | ||
if (this.isNodeCached(node)) { | ||
this.code.line(`let $c = ctx.cache.get("${node.nodeId}");`); | ||
this.code.line(`let $c = ctx.cache.get("${node.getNodeUid()}");`); | ||
this.code.line(`if ($c) { return $c.res; }`); | ||
@@ -65,3 +65,3 @@ this.code.block(`$c = (${this.asyncSym(node)}() => {`, `})();`, () => { | ||
}); | ||
this.code.line(`ctx.cache.set("${node.nodeId}", { res: $c });`); | ||
this.code.line(`ctx.cache.set("${node.getNodeUid()}", { res: $c });`); | ||
this.code.line(`return $c;`); | ||
@@ -78,8 +78,9 @@ } | ||
if (this.options.introspect) { | ||
const nodeUid = node.getNodeUid(); | ||
this.code.block('try {', '}', () => { | ||
if (this.options.evalMode === 'manual') { | ||
this.code.line(`ctx.checkPendingNode(${JSON.stringify(node.nodeId)});`); | ||
this.code.line(`ctx.checkPendingNode(${JSON.stringify(nodeUid)});`); | ||
} | ||
this.code.line(`ctx.nodeEvaluated.emit({` + | ||
`nodeId: ${JSON.stringify(node.nodeId)},` + | ||
`nodeUid: ${JSON.stringify(nodeUid)},` + | ||
`progress: 0` + | ||
@@ -90,3 +91,3 @@ `});`); | ||
this.code.line(`ctx.nodeEvaluated.emit({` + | ||
`nodeId: ${JSON.stringify(node.nodeId)},` + | ||
`nodeUid: ${JSON.stringify(nodeUid)},` + | ||
`result: ${resSym},` + | ||
@@ -100,3 +101,3 @@ `timestamp: Date.now(),` + | ||
this.code.line(`ctx.nodeEvaluated.emit({` + | ||
`nodeId: ${JSON.stringify(node.nodeId)},` + | ||
`nodeUid: ${JSON.stringify(nodeUid)},` + | ||
`error,` + | ||
@@ -133,4 +134,4 @@ `timestamp: Date.now(),` + | ||
this.code.line(`ctx.nodeEvaluated.emit({` + | ||
`nodeId: ${JSON.stringify(node.nodeId)},` + | ||
`progress: $i / $l` + | ||
`nodeUid: ${JSON.stringify(node.getNodeUid())},` + | ||
`progress: $i / $l,` + | ||
`});`); | ||
@@ -147,4 +148,4 @@ } | ||
for (const line of node.allLines()) { | ||
const lineId = line.getLineId(); | ||
const sym = this.symbols.createLineSym(this.scopeId, lineId); | ||
const lineUid = line.getLineUid(); | ||
const sym = this.symbols.createLineSym(lineUid); | ||
const { decl, expr } = this.createLineDecl(line, sym); | ||
@@ -155,3 +156,3 @@ if (decl) { | ||
} | ||
this.lineExprMap.set(lineId, expr); | ||
this.lineExprMap.set(lineUid, expr); | ||
} | ||
@@ -169,3 +170,3 @@ if (node.isAsync()) { | ||
if (this.options.comments) { | ||
this.code.line(`// Line: ${line.getLineId()}`); | ||
this.code.line(`// Line: ${line.getLineUid()}`); | ||
this.code.line(`// Schema: ${JSON.stringify(targetSchema)}`); | ||
@@ -182,3 +183,3 @@ } | ||
// 2. create a base expression for calling the linked function, i.e. r1(params, ctx) | ||
const linkSym = this.getNodeSym(linkNode.nodeId); | ||
const linkSym = this.symbols.getNodeSym(linkNode.getNodeUid()); | ||
let callExpr = `${linkSym}(params, ctx)`; | ||
@@ -223,4 +224,4 @@ // 3. compose in linkKey operation | ||
for (const line of node.expandedLines()) { | ||
const lineId = line.getLineId(); | ||
const sym = this.getLineSym(lineId); | ||
const lineUid = line.getLineUid(); | ||
const sym = this.symbols.getLineSym(lineUid); | ||
expSyms.push(sym); | ||
@@ -313,3 +314,2 @@ } | ||
emitGenericCompute(node, resSym) { | ||
this.code.line(`ctx.nodeId = ${JSON.stringify(node.nodeId)};`); | ||
const computeSym = this.symbols.getComputeSym(node.ref); | ||
@@ -328,3 +328,3 @@ const scopeSym = this.graph.moduleSpec.newScope ? `ctx.newScope()` : `ctx`; | ||
if (rootNode) { | ||
return this.symbols.getNodeSym(subgraph.scopeId, rootNode.nodeId); | ||
return this.symbols.getNodeSym(rootNode.getNodeUid()); | ||
} | ||
@@ -378,3 +378,3 @@ return `() => undefined`; | ||
getLineExpr(line) { | ||
const lineId = line.getLineId(); | ||
const lineId = line.getLineUid(); | ||
const expr = this.lineExprMap.get(lineId); | ||
@@ -415,8 +415,2 @@ if (!expr) { | ||
} | ||
getNodeSym(nodeId) { | ||
return this.symbols.getNodeSym(this.scopeId, nodeId); | ||
} | ||
getLineSym(lineId) { | ||
return this.symbols.getLineSym(this.scopeId, lineId); | ||
} | ||
escapeValue(value) { | ||
@@ -423,0 +417,0 @@ if (value === undefined) { |
@@ -7,6 +7,6 @@ export declare class CompilerSymbols { | ||
createModuleSym(moduleRef: string): string; | ||
getNodeSym(scopeId: string, nodeId: string, fallback?: string): string; | ||
createNodeSym(scopeId: string, nodeId: string): string; | ||
getLineSym(scopeId: string, lineId: string): string; | ||
createLineSym(scopeId: string, lineId: string): string; | ||
getNodeSym(nodeUid: string, fallback?: string): string; | ||
createNodeSym(nodeUid: string): string; | ||
getLineSym(lineUid: string): string; | ||
createLineSym(lineUid: string): string; | ||
} |
@@ -22,16 +22,16 @@ import { SymTable } from './SymTable.js'; | ||
} | ||
getNodeSym(scopeId, nodeId, fallback) { | ||
return this.symtable.get(`node:${scopeId}:${nodeId}`, fallback); | ||
getNodeSym(nodeUid, fallback) { | ||
return this.symtable.get(`node:${nodeUid}`, fallback); | ||
} | ||
createNodeSym(scopeId, nodeId) { | ||
createNodeSym(nodeUid) { | ||
const sym = this.symtable.nextSym('r'); | ||
this.symtable.set(`node:${scopeId}:${nodeId}`, sym); | ||
this.symtable.set(`node:${nodeUid}`, sym); | ||
return sym; | ||
} | ||
getLineSym(scopeId, lineId) { | ||
return this.symtable.get(`prop:${scopeId}:${lineId}`); | ||
getLineSym(lineUid) { | ||
return this.symtable.get(`prop:${lineUid}`); | ||
} | ||
createLineSym(scopeId, lineId) { | ||
createLineSym(lineUid) { | ||
const sym = this.symtable.nextSym('p'); | ||
this.symtable.set(`prop:${scopeId}:${lineId}`, sym); | ||
this.symtable.set(`prop:${lineUid}`, sym); | ||
return sym; | ||
@@ -38,0 +38,0 @@ } |
@@ -12,4 +12,3 @@ import { Event } from 'nanoevent'; | ||
readonly lib: t.RuntimeLib; | ||
nodeId: string; | ||
pendingNodeIds: Set<string>; | ||
pendingNodeUids: Set<string>; | ||
nodeEvaluated: Event<t.NodeResult>; | ||
@@ -29,3 +28,3 @@ cache: Map<string, any>; | ||
convertAuto(value: string, targetSchema?: SchemaSpec): unknown; | ||
checkPendingNode(nodeId: string): void; | ||
checkPendingNode(nodeUid: string): void; | ||
deferred(fn: () => unknown, schema?: SchemaSpec): Deferred; | ||
@@ -32,0 +31,0 @@ isDeferred(value: unknown): value is t.Deferred; |
@@ -13,3 +13,2 @@ import { Schema } from 'airtight'; | ||
this.lib = runtimeLib; | ||
this.nodeId = ''; | ||
// Each context maintains its own cache. Subscopes have separate caches | ||
@@ -21,3 +20,3 @@ // and do not delegate to parent contexts. | ||
this.nodeEvaluated = parent ? parent.nodeEvaluated : new Event(); | ||
this.pendingNodeIds = parent ? parent.pendingNodeIds : new Set(); | ||
this.pendingNodeUids = parent ? parent.pendingNodeUids : new Set(); | ||
} | ||
@@ -27,3 +26,3 @@ clear() { | ||
this.locals.clear(); | ||
this.pendingNodeIds.clear(); | ||
this.pendingNodeUids.clear(); | ||
} | ||
@@ -67,4 +66,4 @@ async finalize() { } | ||
} | ||
checkPendingNode(nodeId) { | ||
if (this.pendingNodeIds.has(nodeId)) { | ||
checkPendingNode(nodeUid) { | ||
if (this.pendingNodeUids.has(nodeUid)) { | ||
throw new NodePendingError(); | ||
@@ -71,0 +70,0 @@ } |
@@ -17,2 +17,3 @@ import { NodeSpec } from '../types/model.js'; | ||
private _moduleSpec; | ||
private _nodeUid; | ||
constructor(graph: GraphView, nodeId: string, nodeSpec: NodeSpec); | ||
@@ -25,2 +26,3 @@ toJSON(): NodeSpec; | ||
isRoot(): boolean; | ||
getNodeUid(): string; | ||
supportsSubgraph(): boolean; | ||
@@ -27,0 +29,0 @@ getSubgraph(): GraphView | null; |
@@ -12,2 +12,3 @@ import { coerce } from 'airtight'; | ||
this.nodeSpec = nodeSpec; | ||
this._nodeUid = this.graph.scopeId + ':' + nodeId; | ||
this._moduleSpec = this.loader.resolveModule(this.nodeSpec.ref); | ||
@@ -36,2 +37,5 @@ if (this.nodeSpec.ref === '@system/Result') { | ||
} | ||
getNodeUid() { | ||
return this._nodeUid; | ||
} | ||
supportsSubgraph() { | ||
@@ -38,0 +42,0 @@ const { subgraph } = this.getModuleSpec(); |
@@ -18,3 +18,3 @@ import { PropEntrySpec, PropSpec } from '../types/model.js'; | ||
toJSON(): PropLine; | ||
abstract getLineId(): string; | ||
abstract getLineUid(): string; | ||
abstract getSchema(): SchemaSpec; | ||
@@ -41,3 +41,3 @@ get graph(): import("./GraphView.js").GraphView; | ||
constructor(node: NodeView, propKey: string, propSpec: PropSpec); | ||
getLineId(): string; | ||
getLineUid(): string; | ||
getSchema(): SchemaSpec; | ||
@@ -69,5 +69,5 @@ getLabel(): string; | ||
get key(): string; | ||
getLineId(): string; | ||
getLineUid(): string; | ||
isManaged(): boolean | undefined; | ||
getSchema(): SchemaSpec; | ||
} |
@@ -79,4 +79,4 @@ import { coerce, getDefaultValue } from 'airtight'; | ||
} | ||
getLineId() { | ||
return this.node.nodeId + ':' + this.propKey; | ||
getLineUid() { | ||
return this.node.getNodeUid() + ':' + this.propKey; | ||
} | ||
@@ -164,4 +164,4 @@ getSchema() { | ||
} | ||
getLineId() { | ||
return this.parentProp.getLineId() + ':' + this.propEntrySpec.id; | ||
getLineUid() { | ||
return this.parentProp.getLineUid() + ':' + this.propEntrySpec.id; | ||
} | ||
@@ -168,0 +168,0 @@ isManaged() { |
@@ -6,3 +6,3 @@ import { Schema } from 'airtight'; | ||
properties: { | ||
nodeId: { type: 'string' }, | ||
nodeUid: { type: 'string' }, | ||
result: { type: 'any', optional: true }, | ||
@@ -9,0 +9,0 @@ error: { type: 'any', optional: true }, |
@@ -11,3 +11,2 @@ import { Event } from 'nanoevent'; | ||
readonly lib: RuntimeLib; | ||
nodeId: string; | ||
cache: Map<string, any>; | ||
@@ -26,3 +25,3 @@ locals: Map<string, any>; | ||
toArray(object: unknown): unknown[]; | ||
checkPendingNode(nodeId: string): void; | ||
checkPendingNode(nodeUid: string): void; | ||
deferred(fn: () => unknown, schema?: SchemaSpec): unknown; | ||
@@ -29,0 +28,0 @@ isDeferred(value: unknown): value is Deferred; |
export interface NodeResult { | ||
nodeId: string; | ||
nodeUid: string; | ||
result?: any; | ||
@@ -4,0 +4,0 @@ error?: any; |
{ | ||
"name": "@nodescript/core", | ||
"version": "6.1.2", | ||
"version": "7.0.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Visual programming language for Browser and Node", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
192436
3356