@nodescript/core
Advanced tools
Comparing version 1.2.2 to 1.3.0
import { DeepPartial } from '@flexent/schema'; | ||
import * as t from '../types/index.js'; | ||
import { GraphSpec, ModuleDefinition, ModuleSpec } from '../types/index.js'; | ||
@@ -13,8 +12,8 @@ import { Graph } from './Graph.js'; | ||
export declare class StandardGraphLoader implements GraphLoader { | ||
modules: Map<string, t.ModuleSpec>; | ||
modules: Map<string, ModuleSpec>; | ||
constructor(); | ||
loadGraph(spec?: DeepPartial<GraphSpec>, options?: GraphLoaderOptions): Promise<Graph>; | ||
loadModule(url: string): Promise<ModuleSpec>; | ||
resolveModule(url: string): t.ModuleSpec; | ||
getModule(url: string): t.ModuleSpec | null; | ||
resolveModule(url: string): ModuleSpec; | ||
getModule(url: string): ModuleSpec | null; | ||
defineModule(url: string, def: ModuleDefinition | ModuleSpec): ModuleSpec; | ||
@@ -21,0 +20,0 @@ protected fetchModule(url: string): Promise<ModuleSpec>; |
@@ -11,2 +11,5 @@ import { ModuleSpecSchema } from '../schema/ModuleSpec.js'; | ||
this.defineModule('core:Param', systemNodes.Param); | ||
this.defineModule('core:EvalSync', systemNodes.EvalSync); | ||
this.defineModule('core:EvalAsync', systemNodes.EvalAsync); | ||
this.defineModule('core:EvalJson', systemNodes.EvalJson); | ||
} | ||
@@ -13,0 +16,0 @@ async loadGraph(spec = {}, options = {}) { |
@@ -68,3 +68,3 @@ import { DeepPartial } from '@flexent/schema'; | ||
* | ||
* Unless specified explicitly in NodeMetadata, the first property is used. | ||
* Unless specified explicitly in ModuleSpec, the first property is used. | ||
*/ | ||
@@ -71,0 +71,0 @@ getDefaultProp(): Prop | null; |
@@ -165,7 +165,7 @@ import { NodeSpecSchema } from '../schema/index.js'; | ||
* | ||
* Unless specified explicitly in NodeMetadata, the first property is used. | ||
* Unless specified explicitly in ModuleSpec, the first property is used. | ||
*/ | ||
getDefaultProp() { | ||
const firstProp = this.props[0]; | ||
// TODO add support to customize via NodeMetadata | ||
// TODO add support to customize via ModuleSpec | ||
return firstProp ?? null; | ||
@@ -172,0 +172,0 @@ } |
@@ -139,3 +139,3 @@ import { isSchemaCompatible } from '../util/index.js'; | ||
} | ||
emitNodePreamble(node) { | ||
emitNodePreamble(_node) { | ||
this.code.line(`const {` + | ||
@@ -185,2 +185,5 @@ `convertType:${this.sym.convertType},` + | ||
case 'core:Local': return this.emitLocalNode(node, resSym); | ||
case 'core:EvalSync': return this.emitEvalSync(node, resSym); | ||
case 'core:EvalAsync': return this.emitEvalAsync(node, resSym); | ||
case 'core:EvalJson': return this.emitEvalJson(node, resSym); | ||
default: | ||
@@ -213,2 +216,43 @@ if (!node.$module.computeUrl) { | ||
} | ||
emitEvalSync(node, resSym) { | ||
const code = node.props.find(_ => _.key === 'code')?.value ?? ''; | ||
this.code.block(`const $p = {`, `}`, () => { | ||
const prop = node.getBasePropByKey('args'); | ||
if (prop) { | ||
this.emitNodeProp(node, prop); | ||
} | ||
}); | ||
const args = node.props.find(_ => _.key === 'args')?.entries ?? []; | ||
const argList = args.map(_ => _.key).join(','); | ||
const argVals = args.map(_ => `$p.args[${JSON.stringify(_.key)}]`).join(','); | ||
this.code.block(`${resSym} = ((${argList}) => {`, `})(${argVals})`, () => { | ||
this.code.line(code); | ||
}); | ||
} | ||
emitEvalAsync(node, resSym) { | ||
const code = node.props.find(_ => _.key === 'code')?.value ?? ''; | ||
this.code.block(`const $p = {`, `}`, () => { | ||
const prop = node.getBasePropByKey('args'); | ||
if (prop) { | ||
this.emitNodeProp(node, prop); | ||
} | ||
}); | ||
const args = node.props.find(_ => _.key === 'args')?.entries ?? []; | ||
const argList = args.map(_ => _.key).join(','); | ||
const argVals = args.map(_ => `$p.args[${JSON.stringify(_.key)}]`).join(','); | ||
this.code.block(`${resSym} = await (async (${argList}) => {`, `})(${argVals})`, () => { | ||
this.code.line(code); | ||
}); | ||
} | ||
emitEvalJson(node, resSym) { | ||
const code = node.props.find(_ => _.key === 'code')?.value ?? ''; | ||
try { | ||
// Make sure it's actually a JSON | ||
JSON.parse(code); | ||
this.code.line(`${resSym} = ${code};`); | ||
} | ||
catch (error) { | ||
this.code.line(`throw new Error(${JSON.stringify(error.message)})`); | ||
} | ||
} | ||
emitRegularNode(node, resSym) { | ||
@@ -215,0 +259,0 @@ this.emitNodeCompute(node, resSym); |
@@ -1,4 +0,7 @@ | ||
export * from './comment.js'; | ||
export * from './frame.js'; | ||
export * from './local.js'; | ||
export * from './param.js'; | ||
export * from './Comment.js'; | ||
export * from './EvalAsync.js'; | ||
export * from './EvalJson.js'; | ||
export * from './EvalSync.js'; | ||
export * from './Frame.js'; | ||
export * from './Local.js'; | ||
export * from './Param.js'; |
// This file is auto-generated | ||
export * from './comment.js'; | ||
export * from './frame.js'; | ||
export * from './local.js'; | ||
export * from './param.js'; | ||
export * from './Comment.js'; | ||
export * from './EvalAsync.js'; | ||
export * from './EvalJson.js'; | ||
export * from './EvalSync.js'; | ||
export * from './Frame.js'; | ||
export * from './Local.js'; | ||
export * from './Param.js'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@nodescript/core", | ||
"version": "1.2.2", | ||
"version": "1.3.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
137524
134
2427