@nodescript/core
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,4 +0,4 @@ | ||
(()=>{var ie=Object.defineProperty;var i=(s,e)=>ie(s,"name",{value:e,configurable:!0});var I=(s,e)=>{for(var t in e)ie(s,t,{get:e[t],enumerable:!0})};var ue={};I(ue,{Graph:()=>u,Node:()=>l,Prop:()=>m});var ce={};I(ce,{DataSchemaSchema:()=>h,GraphSchema:()=>X,NodeDefSchema:()=>F,NodeResultSchema:()=>ke,NodeSchema:()=>A,ParamMetadataSchema:()=>R,PropSchema:()=>v});function _(s){if(s==null)return"null";if(Array.isArray(s))return"array";let e=typeof s;return e==="object"||e==="number"||e==="string"||e==="boolean"?e:"any"}i(_,"getType");var ye={boolean:{number:s=>s>0,string:s=>(s=s.trim().toLowerCase(),s==="true"?!0:s==="false"||s===""?!1:void 0)},number:{string:s=>{let e=Number(s);if(!isNaN(e))return e},boolean:s=>s?1:0},integer:{number:s=>Math.floor(s),string:s=>{let e=parseInt(s,10);if(!isNaN(e))return e},boolean:s=>s?1:0},string:{null:s=>"",number:s=>s.toString(),boolean:s=>s.toString()},array:{null:s=>{},"*":s=>[s]}};function V(s,e){var t,r;let o=_(e);if(o===s)return e;let n=(t=ye[s])!==null&&t!==void 0?t:{},a=(r=n[o])!==null&&r!==void 0?r:n["*"];if(a)return a(e);if(o==="array"){let p=e;if(p.length===1)return V(s,p[0])}}i(V,"coerce");var ne={any:null,ref:null,array:[],boolean:!1,integer:0,number:0,object:{},string:""};var E=class extends Error{constructor(e,t){var r;super(),this.name=this.constructor.name,this.status=400;let o=this.formatMessage(t),n=(r=e.id)!==null&&r!==void 0?r:e.type;this.message=`${n} validation failed: | ||
(()=>{var ie=Object.defineProperty;var i=(s,e)=>ie(s,"name",{value:e,configurable:!0});var I=(s,e)=>{for(var t in e)ie(s,t,{get:e[t],enumerable:!0})};var ue={};I(ue,{Graph:()=>u,Node:()=>m,Prop:()=>l});var ce={};I(ce,{DataSchemaSchema:()=>g,GraphSchema:()=>G,NodeDefSchema:()=>H,NodeMetadataSchema:()=>R,NodeResultSchema:()=>ke,NodeSchema:()=>v,ParamMetadataSchema:()=>F,PropSchema:()=>A});function K(s){if(s==null)return"null";if(Array.isArray(s))return"array";let e=typeof s;return e==="object"||e==="number"||e==="string"||e==="boolean"?e:"any"}i(K,"getType");var ye={boolean:{number:s=>s>0,string:s=>(s=s.trim().toLowerCase(),s==="true"?!0:s==="false"||s===""?!1:void 0)},number:{string:s=>{let e=Number(s);if(!isNaN(e))return e},boolean:s=>s?1:0},integer:{number:s=>Math.floor(s),string:s=>{let e=parseInt(s,10);if(!isNaN(e))return e},boolean:s=>s?1:0},string:{null:s=>"",number:s=>s.toString(),boolean:s=>s.toString()},array:{null:s=>{},"*":s=>[s]}};function V(s,e){var t,r;let o=K(e);if(o===s)return e;let n=(t=ye[s])!==null&&t!==void 0?t:{},a=(r=n[o])!==null&&r!==void 0?r:n["*"];if(a)return a(e);if(o==="array"){let c=e;if(c.length===1)return V(s,c[0])}}i(V,"coerce");var ne={any:null,ref:null,array:[],boolean:!1,integer:0,number:0,object:{},string:""};var E=class extends Error{constructor(e,t){var r;super(),this.name=this.constructor.name,this.status=400;let o=this.formatMessage(t),n=(r=e.id)!==null&&r!==void 0?r:e.type;this.message=`${n} validation failed: | ||
${o}`,this.details={errors:t}}formatMessage(e){let t=e.map(o=>` - ${o.path} ${o.message}`);return[...new Set(t)].sort().join(` | ||
`)}};i(E,"ValidationError");var O=class{constructor(e,t){this.decoder=e,this.value=t,this.errors=[]}decode(){let e=this.decodeAny(this.decoder.schema,this.value,"");if(this.errors.length>0)throw new E(this.decoder.schema,this.errors);return e}decodeAny(e,t,r){let o=e;if(t==null){if(o.optional)return;if(o.nullable)return null;t=this.defaultValue(e)}if(e.type==="any")return t;if(e.type==="ref")return this.decodeRef(e.schemaId,t,r);if(e.type!==_(t)){let n=V(e.type,t);if(n===void 0)return this.errors.push({path:r,message:`must be ${e.type}`}),this.defaultValue(e);t=n}switch(e.type){case"boolean":return t;case"number":case"integer":return this.decodeNumber(e,t,r);case"string":return this.decodeString(e,t,r);case"object":return this.decodeObject(e,t,r);case"array":return this.decodeArray(e,t,r);default:return this.errors.push({path:r,message:"must be a valid data type"}),this.defaultValue(e)}}decodeNumber(e,t,r){let o=t,n=!0;return e.minimum!=null&&o<e.minimum&&(this.errors.push({path:r,message:`must be greater than or equal to ${e.minimum}`}),n=!1),e.maximum!=null&&o>e.maximum&&(this.errors.push({path:r,message:`must be less than or equal to ${e.maximum}`}),n=!1),n?o:this.defaultValue(e)}decodeString(e,t,r){var o;let n=t,a=!0;return e.enum!=null&&!e.enum.includes(n)&&(this.errors.push({path:r,message:"must be an allowed value"}),a=!1),e.regex!=null&&(new RegExp(e.regex,(o=e.regexFlags)!==null&&o!==void 0?o:"").test(n)||(this.errors.push({path:r,message:"must be in allowed format"}),a=!1)),a?n:this.defaultValue(e)}decodeObject(e,t,r){let o=new Set,n={},a=t;for(let[p,d]of Object.entries(e.properties)){let k=a[p],w=this.decodeAny(d,k,`${r}.${p}`);w!==void 0&&(n[p]=w),o.add(p)}if(e.additionalProperties)for(let[p,d]of Object.entries(a))o.has(p)||(n[p]=this.decodeAny(e.additionalProperties,d,`${r}.${p}`));return n}decodeArray(e,t,r){let o=[],n=t;for(let a of n){let p=this.decodeAny(e.items,a,`${r}.*`);o.push(p)}return o}decodeRef(e,t,r){let o=this.decoder.getRef(e);if(!o){this.errors.push({path:r,message:`unknown type ${e}`});return}return this.decodeAny(o,t,r)}defaultValue(e){let t=e.default;return typeof t=="function"?t():t??(e.optional?void 0:e.nullable?null:ne[e.type])}};i(O,"DecodeJob");var c=class{constructor(e){this._refs=null,this.schema=e}create(e){return this.decode(e)}decode(e){return new O(this,e).decode()}getRef(e){var t;return(t=this.getRefs().get(e))!==null&&t!==void 0?t:null}getRefs(){return this._refs||(this._refs=new Map,this._collectRefs(this._refs,this.schema)),this._refs}_collectRefs(e,t){if(t.id&&e.set(t.id,t),t.refs)for(let r of t.refs)this._collectRefs(e,r);if(t.type==="object"&&(t.additionalProperties&&this._collectRefs(e,t.additionalProperties),t.properties))for(let r of Object.values(t.properties))this._collectRefs(e,r);t.type==="array"&&t.items&&this._collectRefs(e,t.items)}};i(c,"Schema");var h=new c({id:"DataSchema",type:"object",properties:{type:{type:"string",default:"any"},kind:{type:"string",optional:!0},enum:{type:"array",items:{type:"string"},optional:!0},default:{type:"any",optional:!0},properties:{type:"object",optional:!0,properties:{},additionalProperties:{type:"ref",schemaId:"DataSchema"}},additionalProperties:{type:"ref",optional:!0,schemaId:"DataSchema"},items:{type:"ref",optional:!0,schemaId:"DataSchema"}}});var ge=i(s=>crypto.getRandomValues(new Uint8Array(s)),"random"),xe=i((s,e,t)=>{let r=(2<<Math.log(s.length-1)/Math.LN2)-1,o=-~(1.6*r*e/s.length);return(n=e)=>{let a="";for(;;){let p=t(o),d=o;for(;d--;)if(a+=s[p[d]&r]||"",a.length===n)return a}}},"customRandom"),G=i((s,e=21)=>xe(s,e,ge),"customAlphabet"),Z=i((s=21)=>crypto.getRandomValues(new Uint8Array(s)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),""),"nanoid");var ae="abcdefghijklmnopqrstuvwxyz0123456789",$e=i(()=>Z(4),"tinyId"),f=i(()=>Z(8),"shortId"),be=G(ae,12),pe=G(ae,24),j=new c({id:"Id",type:"string",regex:"^[a-zA-Z0-9_-]{1,64}$",default:()=>pe()});function Ne(s,e,t=f){let r=new Map,o=JSON.stringify(s,(n,a)=>{if(e.includes(n)){let p=a,d=t();return r.set(p,d),d}return a});return JSON.parse(o,(n,a)=>{if(typeof a=="string"){let p=r.get(a);if(p)return p}return a})}i(Ne,"cloneWithNewIds");var q=new c({id:"Point",type:"object",properties:{x:{type:"number"},y:{type:"number"}},default:{x:0,y:0}}),Se={ZERO:{x:0,y:0},add(s,e){return{x:s.x+e.x,y:s.y+e.y}},scale(s,e){return{x:s.x*e,y:s.y*e}}};var v=new c({id:"Prop",type:"object",properties:{id:{...j.schema,default:f},key:{type:"string"},value:{type:"string"},linkId:{type:"string"},linkKey:{type:"string"},expand:{type:"boolean"},entries:{type:"array",optional:!0,items:{type:"ref",schemaId:"Prop"}}}});var A=new c({id:"Node",type:"object",properties:{id:{...j.schema,default:()=>f()},ref:{type:"string"},pos:q.schema,w:{type:"integer",default:5,minimum:3,maximum:20},collapsed:{type:"boolean"},props:{type:"array",items:v.schema}}});var R=new c({id:"ParamDef",type:"object",properties:{kind:{type:"string",enum:["lambda"],optional:!0},label:{type:"string",optional:!0},schema:h.schema,scope:{type:"object",properties:{},additionalProperties:h.schema,optional:!0},default:{type:"string",optional:!0},addItemLabel:{type:"string",optional:!0},removeItemLabel:{type:"string",optional:!0},keyPlaceholder:{type:"string",optional:!0},valuePlaceholder:{type:"string",optional:!0},hideEntries:{type:"boolean",optional:!0}}});var X=new c({id:"Graph",type:"object",properties:{label:{type:"string"},category:{type:"array",items:{type:"string"}},description:{type:"string"},deprecated:{type:"string"},hidden:{type:"boolean"},params:{type:"object",properties:{},additionalProperties:R.schema},result:h.schema,compute:{type:"any"},nodes:{type:"array",items:A.schema},rootNodeId:{type:"string"},refs:{type:"object",properties:{},additionalProperties:{type:"string"}}}});var F=new c({type:"object",properties:{label:{type:"string"},category:{type:"array",items:{type:"string"}},description:{type:"string"},deprecated:{type:"string"},hidden:{type:"boolean"},params:{type:"object",properties:{},additionalProperties:R.schema},result:h.schema,compute:{type:"any"}}});var ke=new c({type:"object",properties:{nodeId:{type:"string"},result:{type:"any",optional:!0},error:{type:"any",optional:!0}}});var me={};I(me,{IdSchema:()=>j,InvalidTypeError:()=>L,MultiMap:()=>$,NotFoundError:()=>x,Point:()=>Se,PointSchema:()=>q,abbreviate:()=>Ee,capitalizeWords:()=>le,checkType:()=>Ie,clamp:()=>K,cloneWithNewIds:()=>Ne,codeToUrl:()=>de,convertType:()=>H,evalEsmModule:()=>we,getType:()=>C,humanize:()=>Q,isSchemaCompatible:()=>g,mediumId:()=>be,parseAny:()=>Pe,safeId:()=>pe,serialize:()=>y,shortId:()=>f,tinyId:()=>$e});function K(s,e,t){return Math.min(Math.max(s,e),t)}i(K,"clamp");function H(s,e){return new c(e).decode(s)}i(H,"convertType");var x=class extends Error{constructor(e="Object"){super(`${e} not found`),this.name=this.constructor.name,this.status=404}};i(x,"NotFoundError");async function we(s){return await import(de(s))}i(we,"evalEsmModule");function de(s){return`data:text/javascript;base64,${btoa(s)}`}i(de,"codeToUrl");var $=class{constructor(){this.map=new Map}add(e,t){let r=this.map.get(e)??new Set;r.add(t),this.map.set(e,r)}get(e){return this.map.get(e)??new Set}delete(e,t){let r=this.map.get(e);return r?r.delete(t):!1}deleteAll(e){this.map.delete(e)}deleteValue(e){for(let t of this.groups())t.delete(e)}clear(){this.map.clear()}keys(){return this.map.keys()}groups(){return this.map.values()}};i($,"MultiMap");function y(s,e={}){let t={};for(let[r,o]of Object.entries(s))r[0]==="$"||r[0]==="_"||r in e&&String(e[r])===String(o)||(t[r]=o);return t}i(y,"serialize");function Pe(s){switch(String(s??"").trim()){case"false":return!1;case"true":return!0;case"null":return null;case"":return"";default:{let t=Number(s);if(!isNaN(t))return t;if(s.startsWith("[")||s.startsWith("{"))try{return JSON.parse(s)}catch{}return s}}}i(Pe,"parseAny");function C(s){if(s==null)return"null";if(Array.isArray(s))return"array";let e=typeof s;return e==="object"||e==="number"||e==="string"||e==="boolean"?e:"any"}i(C,"getType");function Ie(s,e){let t=C(s),r=Array.isArray(e)?e:[e];for(let o of r)if(t===o)return;throw new L(`Expected ${r.join(" or ")}, instead got ${t}`)}i(Ie,"checkType");function g(s,e){switch(s.type){case"any":return!0;case"string":case"boolean":case"number":return e.type===s.type;case"object":if(e.type!=="object")return!1;if(s.properties)for(let[t,r]of Object.entries(s.properties)){let o=(e.properties??{})[t]??{type:"any"};if(!g(r,o))return!1}return!(s.additionalProperties&&!g(s.additionalProperties,e.additionalProperties??{type:"any"}));case"array":return e.type!=="array"?!1:s.items?g(s.items,e.items??{type:"any"}):!0;default:return!1}}i(g,"isSchemaCompatible");var L=class extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=400}};i(L,"InvalidTypeError");function le(s){return s.replace(/\b([a-zA-Z])/g,(e,t)=>t.toUpperCase())}i(le,"capitalizeWords");function Q(s){return le(s.replace(/([A-Z])/g," $1").trim())}i(Q,"humanize");function Ee(s){switch(C(s)){case"object":return"{\u2026}";case"array":return"[\u2026]";case"string":return s.substring(0,20)+(s.length>20?"\u2026":"");case"null":return"null";default:return String(s)}}i(Ee,"abbreviate");var m=class{constructor(e,t={}){this.$parent=e;let r=m.schema.decode(t);Object.assign(this,r),this.entries=(r.entries??[]).map(o=>new m(this,o))}toJSON(){return y(this,{value:"",linkId:"",linkKey:"",expand:!1,entries:[]})}get $node(){return this.$parent instanceof l?this.$parent:this.$parent.$node}get $graph(){return this.$node.$graph}get $param(){return this.$node.$def.params[this.$paramKey]??{schema:{type:"any"}}}get $paramKey(){return this.$parent instanceof m?this.$parent.key:this.key}getLabel(){return this.$param.label??Q(this.$paramKey)}get $baseProp(){return this.$parent instanceof m?this.$parent:this}isLambda(){return this.$param.kind==="lambda"}isEntry(){return this.$parent instanceof m}isSupportsEntries(){if(this.isEntry()||this.isLambda())return!1;let{schema:e,hideEntries:t}=this.$param;return!t&&(e.type==="object"||e.type==="array")}isUsesEntries(){return this.isSupportsEntries()&&!this.getLinkNode()}getLinkNode(){return this.linkId?this.$graph.getNodeById(this.linkId):null}canExpand(){return!this.isLambda()}isExpanded(){return this.canExpand()&&!!this.expand&&!!this.getLinkNode()}getTargetSchema(){let e=this.$param.schema;if(this.isEntry()){if(e.type==="array")return e.items??{type:"any"};if(e.type==="object")return e.additionalProperties??{type:"any"}}return e}};i(m,"Prop");m.schema=v;var l=class{constructor(e,t={}){this.$graph=e,this.props=[];let r=l.schema.decode(t);Object.assign(this,r),this.props=this.initProps(r.props),this.applyInvariants()}toJSON(){return y(this,{collapsed:!1,scopeId:""})}get $uri(){return this.$graph.resolveUri(this.ref)}get $def(){return this.$graph.resolveNode(this.ref)}isRoot(){return this.$graph.rootNodeId===this.id}getBasePropByKey(e){return this.props.find(t=>t.key===e)??null}getPropById(e){for(let t of this.allProps())if(t.id===e)return t;return null}*allProps(){for(let e of this.props)yield e,e.isSupportsEntries()&&(yield*e.entries)}*computedProps(){for(let e of this.props)e.isUsesEntries()?yield*e.entries:yield e}*displayedProps(){for(let e of this.props)e.isUsesEntries()?(yield e,yield*e.entries):yield e}isExpanded(){return[...this.computedProps()].some(e=>e.isExpanded())}*leftNodes(e=new Set){if(!e.has(this.id)){e.add(this.id),yield this;for(let t of this.inboundLinks())yield*t.linkNode.leftNodes(e)}}*rightNodes(e=this.$graph.computeLinkMap()){yield this;for(let t of e.get(this.id))yield*t.node.rightNodes(e)}canLinkTo(e){for(let t of this.leftNodes())if(t.id===e.id)return!1;return!0}*inboundLinks(){for(let e of this.allProps()){let t=e.getLinkNode();t&&(yield{node:this,prop:e,linkNode:t,linkKey:e.linkKey})}}setCollapsed(e){this.collapsed=e}setPos(e){this.pos=e}setWidth(e){this.w=K(e,l.MIN_W,l.MAX_W)}setPropKey(e,t){let r=this.getPropById(e);r&&r.isEntry()&&(r.key=t)}setPropValue(e,t){let r=this.getPropById(e);r&&(r.value=t)}setPropExpand(e,t){let r=this.getPropById(e);r&&(r.expand=t)}addPropEntry(e){let t=this.getBasePropByKey(e);if(t&&t.isSupportsEntries()){let r=new m(t);t.entries.push(r)}}removePropEntry(e,t){let r=this.getBasePropByKey(e);if(r&&r.isSupportsEntries()){let o=r.entries.findIndex(n=>n.id===t);o>-1&&r.entries.splice(o,1)}}initProps(e){let t=[];for(let r of Object.keys(this.$def.params)){let o=e.find(a=>a.key===r)??{key:r},n=new m(this,o);t.push(n)}return t}applyInvariants(){this.w=K(this.w,l.MIN_W,l.MAX_W);for(let e of this.props){let t=e.getLinkNode();t&&(t.canLinkTo(this)||(e.linkId=""))}}};i(l,"Node");l.schema=A;l.MIN_W=3;l.MAX_W=20;var u=class{constructor(e,t={}){this.$loader=e,this.params={},this.result={type:"any"},this.refs={},this.$nodeMap=new Map;let r=u.schema.decode(t);Object.assign(this,r),this.nodes=[];for(let o of r.nodes){let n=new l(this,o);this.addNodeRaw(n)}}toJSON(){return y(this,{label:"",description:"",deprecated:"",hidden:!1,category:[],params:{},rootNodeId:"",refs:{}})}resolveUri(e){return this.refs[e]??""}resolveNode(e){let t=this.resolveUri(e);return this.$loader.resolveNodeDef(t)}getNodeById(e){return this.$nodeMap.get(e)??null}getRootNode(){return this.rootNodeId?this.getNodeById(this.rootNodeId):null}async createNode(e){await this.$loader.loadNodeDef(e.uri);let t=this.getRefForUri(e.uri),r=new l(this,{...e.node,ref:t});return this.addNodeRaw(r),r}addNodeRaw(e){this.nodes.push(e),this.$nodeMap.set(e.id,e)}deleteNode(e){this.$nodeMap.delete(e);let t=this.nodes.findIndex(r=>r.id===e);return t>-1?(this.nodes.splice(t,1),!0):!1}rightmostNodes(){let e=new Set(this.nodes);for(let t of this.nodes)for(let r of t.inboundLinks())e.delete(r.linkNode);return[...e]}*allLinks(){for(let e of this.nodes)yield*e.inboundLinks()}computeLinkMap(){let e=new $;for(let t of this.nodes)for(let r of t.computedProps()){let o=r.getLinkNode();o&&e.add(o.id,{node:t,prop:r,linkNode:o,linkKey:r.linkKey})}return e}computeOrder(e=this.rootNodeId){let t=[],r=this.getNodeById(e??this.rootNodeId);return r&&this._computeOrder(t,r),t}_computeOrder(e,t){e.unshift(t);for(let r of t.computedProps()){let o=r.getLinkNode();if(o){let n=e.findIndex(a=>a.id===o.id);n>-1&&e.splice(n,1),this._computeOrder(e,o)}}}getRefForUri(e){for(let[r,o]of Object.entries(this.refs))if(o===e)return r;let t=f();return this.refs[t]=e,t}compute(){}};i(u,"Graph");u.schema=X;var se={};I(se,{Comment:()=>Y,Local:()=>ee,Param:()=>te,Result:()=>re});var Y={label:"Comment",category:["Graph"],params:{comment:{schema:{type:"string"}}},result:{type:"any"},compute(){}};var ee={label:"Local",category:["Graph"],params:{key:{schema:{type:"string"}}},result:{type:"any"},compute(){}};var te={label:"Parameter",category:["Graph"],params:{key:{schema:{type:"string",kind:"param"}}},result:{type:"any"},compute(){}};var re={label:"Result",category:["Graph"],params:{value:{schema:{type:"any"}}},result:{type:"any"},compute(){}};var he={};I(he,{BaseContext:()=>S,CodeBuilder:()=>b,CompilerError:()=>N,GraphCompiler:()=>J,GraphEvalContext:()=>U,GraphLoader:()=>z,ScopeEvalContext:()=>D,UnresolvedNodeError:()=>B});var b=class{constructor(e=" ",t=0){this.indentString=e,this.currentIndent=t,this.buffer=[]}toString(){return this.buffer.join("")}push(e){return this.buffer.push(e),this}pushIndent(){return this.buffer.push(this.indentString.repeat(this.currentIndent)),this}line(e){return this.pushIndent(),this.push(e),this.push(` | ||
`),this}indent(e=1){return this.currentIndent+=e,this}block(e,t,r){this.line(e),this.indent(),r(),this.indent(-1),this.line(t)}};i(b,"CodeBuilder");var J=class{compileEsm(e,t={}){let r=e.getNodeById(t.rootNodeId??e.rootNodeId);if(!r)throw new x("Node");return new W(e,r,t).compileEsm()}};i(J,"GraphCompiler");var W=class{constructor(e,t,r={}){this.graph=e,this.rootNode=t,this.symCounters=new Map,this.symtable=new Map,this.code=new b,this.order=[],this.sym={nodeEvaluated:this.nextSym("o"),toArray:this.nextSym("o"),convertType:this.nextSym("o")},this.options={rootNodeId:t.id,comments:!1,introspect:!1,...r},this.order=e.computeOrder(t.id),this.linkMap=e.computeLinkMap()}compileEsm(){return this.emitImports(),this.emitExportNode(),this.code.toString()}emitImports(){this.emitComment("Imports");let e=new Set(this.order.map(t=>t.ref));for(let t of e){let r=this.graph.refs[t];if(!r)throw new N(`Cannot resolve ref ${t}`);if(r.startsWith("core:"))continue;let o=this.nextSym("n");this.symtable.set(`def:${t}`,o),this.code.line(`import { node as ${o} } from '${r}'`)}}emitExportNode(){this.emitComment("Node Definition"),this.code.block("export const node = {","};",()=>{this.emitGraphProp("label"),this.emitGraphProp("category"),this.emitGraphProp("description"),this.emitGraphProp("deprecated"),this.emitGraphProp("hidden"),this.emitGraphProp("params"),this.emitGraphProp("result"),this.code.block("async compute(params, ctx) {","}",()=>{this.emitComputeBody()})})}emitGraphProp(e){this.code.line(`${e}: ${JSON.stringify(this.graph[e])},`)}emitComputeBody(){this.emitCtxLocals();for(let e of this.order)this.emitNode(e);this.emitResult()}emitCtxLocals(){this.symtable.set("nodeEvaluated",this.sym.nodeEvaluated),this.symtable.set("toArray",this.sym.toArray),this.symtable.set("convertType",this.sym.convertType),this.code.line(`const {$nodeEvaluated: ${this.sym.nodeEvaluated},$toArray: ${this.sym.toArray},$convertType: ${this.sym.convertType},} = ctx;`)}emitResult(){this.emitComment("Result");let e=this.nodeResultExpr(this.rootNode);this.code.line(`return ${e};`)}emitNode(e){this.emitComment(`${e.ref} ${e.id}`);let t=this.nextSym("r");if(this.symtable.set(`node:${e.id}`,t),e.$uri.startsWith("core:"))return this.emitCoreNode(e);this.code.block(`async function ${t}(ctx) {`,"}",()=>{this.isNodeCached(e.id)?(this.code.line(`const $c = ctx.$cache.get("${e.id}");`),this.code.line("if ($c) return $c;"),this.code.block("try {","}",()=>{this.emitNodeBody(e)}),this.code.block("catch (err) {","}",()=>{this.code.line(`ctx.$cache.set("${e.id}", Promise.reject(err));`),this.code.line("throw err;")})):this.emitNodeBody(e)})}emitCoreNode(e){switch(e.$uri){case"core:Param":return;case"core:Comment":return;case"core:Result":return this.emitResultNode(e);case"core:Local":return this.emitLocalNode(e)}}emitNodeBody(e){let t=i(()=>{e.isExpanded()?this.emitExpandedNode(e):this.emitRegularNode(e)},"emitBody");this.options.introspect?(this.code.block("try {","}",()=>{t()}),this.code.block("catch (error) {","}",()=>{this.code.line(`${this.sym.nodeEvaluated}.emit({nodeId: ${JSON.stringify(e.id)},error,});`),this.code.line("throw error;")})):t()}emitResultNode(e){let t=this.getNodeSym(e.id),r=e.getBasePropByKey("value"),o=this.singlePropExpr(r,this.graph.result);this.code.line(`async function ${t}(ctx) {return ${o};}`)}emitLocalNode(e){let t=this.getNodeSym(e.id),r=e.getBasePropByKey("key");this.code.line(`async function ${t}(ctx) {return ctx.getLocal(${JSON.stringify(r.value)});}`)}emitRegularNode(e){let t=this.getDefSym(e.ref),r="$r";this.code.block(`const ${r} = ${t}.compute({`,"}, ctx);",()=>{this.emitNodeProps(e)}),this.isNodeCached(e.id)&&this.code.line(`ctx.$cache.set("${e.id}", ${r});`),this.options.introspect&&this.code.line(`${this.sym.nodeEvaluated}.emit({nodeId: ${JSON.stringify(e.id)},result: await ${r}});`),this.code.line(`return await ${r};`)}emitExpandedNode(e){let t=this.getDefSym(e.ref),r="$r",n=[...e.computedProps()].filter(d=>d.isExpanded());this.code.line(`const ${r} = []`);let a=[];for(let d of n){let k=this.nextSym("p");this.symtable.set(`prop:${d.id}`,k),a.push(k);let w=d.linkKey,oe=d.getLinkNode(),T=this.nodeResultExpr(oe),fe=oe.isExpanded(),P;fe?w?P=`(${T}).map(_ => _[${JSON.stringify(d.linkKey)}])`:P=`${T}`:w?P=`${this.sym.toArray}((${T})[${JSON.stringify(d.linkKey)}])`:P=`${this.sym.toArray}(${T})`,this.code.line(`const ${k} = ${P}`)}let p=a.map(d=>`i < ${d}.length`).join(" && ");this.code.block(`for (let i = 0;${p};i++) {`,"}",()=>{let d="$t";this.code.block(`const ${d} = ${t}.compute({`,"}, ctx);",()=>{this.emitNodeProps(e)}),this.code.line(`${r}.push(await ${d});`)}),this.isNodeCached(e.id)&&this.code.line(`ctx.$cache.set("${e.id}", ${r});`),this.options.introspect&&this.code.line(`${this.sym.nodeEvaluated}.emit({nodeId: ${JSON.stringify(e.id)},result: ${r}});`),this.code.line(`return ${r};`)}emitNodeProps(e){for(let t of e.props)t.isUsesEntries()?this.emitEntries(t):this.emitSingleProp(t)}emitEntries(e){let{schema:t}=e.$param;switch(t.type){case"array":return this.emitArrayEntries(e);case"object":return this.emitObjectEntries(e)}}emitArrayEntries(e){this.code.block(`${JSON.stringify(e.key)}: [`,"],",()=>{for(let t of e.entries){let r=this.singlePropExpr(t);this.code.line(`${r},`)}})}emitObjectEntries(e){this.code.block(`${JSON.stringify(e.key)}: {`,"},",()=>{for(let t of e.entries){let r=this.singlePropExpr(t);this.code.line(`${JSON.stringify(t.key)}: ${r},`)}})}emitSingleProp(e){let t=this.singlePropExpr(e);this.code.line(`${JSON.stringify(e.key)}: ${t},`)}singlePropExpr(e,t=e.getTargetSchema()){if(e.isLambda())return this.lambdaPropExpr(e);let r=this.rawPropExpr(e),o={type:"string"},n=e.getLinkNode();return n&&(o=n.$def.result),!g(t,o)&&(r=this.convertTypeExpr(r,t)),r}convertTypeExpr(e,t){return`${this.sym.convertType}(${e}, ${JSON.stringify(t)})`}rawPropExpr(e){let t=this.symtable.get(`prop:${e.id}`);if(t)return`${t}[i]`;let r=JSON.stringify(String(e.value)),o=e.getLinkNode();return o&&(r=this.nodeResultExpr(o),e.linkKey&&(r=`(${r})[${JSON.stringify(e.linkKey)}]`)),r}nodeResultExpr(e){if(e.$uri==="core:Param"){let r=e.getBasePropByKey("key"),o=r?r.value:"";return`params[${JSON.stringify(o)}]`}return`await ${this.getNodeSym(e.id)}(ctx)`}lambdaPropExpr(e){let t=e.$param,r=e.getLinkNode();if(!r)return`() => ${this.convertTypeExpr(t.default??"",t.schema)}`;let o=r.$def.result,n=this.getNodeSym(r.id);return g(t.schema,o)?`p => ctx.$scoped(p, ${n})`:`p => Promise.resolve(ctx.$scoped(p, ${n})).then(res => ${this.convertTypeExpr("res",o)})`}getNodeSym(e){return this.getSym(`node:${e}`)}getDefSym(e){return this.getSym(`def:${e}`)}getSym(e){let t=this.symtable.get(e);if(!t)throw new N(`Symbol not found: ${e}`);return t}nextSym(e){let t=this.symCounters.get(e)??0;return this.symCounters.set(e,t+1),`${e}${t+1}`}emitComment(e){this.options.comments&&this.code.line(`// ${e}`)}isNodeCached(e){return this.linkMap.get(e).size>1}};i(W,"GraphCompilerContext");var N=class extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500}};i(N,"CompilerError");var M=class{constructor(){this.listeners=[]}on(e,t=void 0){return this.listeners.push({listener:e,once:!1,group:t}),()=>this.off(e)}once(e,t=void 0){return this.listeners.push({listener:e,once:!0,group:t}),()=>this.off(e)}off(e){let t=this.listeners.findIndex(r=>r.listener===e);t>-1&&this.listeners.splice(t,1)}removeAll(e){this.listeners=this.listeners.filter(t=>t.group!==e)}emit(e){for(let t=0;t<this.listeners.length;t++){let{listener:r,once:o}=this.listeners[t];r(e),o&&(this.listeners.splice(t,1),t-=1)}}};i(M,"Event");var S=class{constructor(){this.$cache=new Map}$scoped(e,t){let r=new D(this,e);return t(r)}$toArray(e){return Array.isArray(e)?e:[e]}$convertType(e,t){return H(e,t)}};i(S,"BaseContext");var U=class extends S{constructor(){super(...arguments),this.$nodeEvaluated=new M}getLocal(e){return null}};i(U,"GraphEvalContext");var D=class extends S{constructor(e,t={}){super(),this.parent=e,this.locals=new Map,this.locals=new Map(Object.entries(t))}get $nodeEvaluated(){return this.parent.$nodeEvaluated}getLocal(e){let t=this.locals.get(e);return t!==void 0?t:this.parent.getLocal(e)}};i(D,"ScopeEvalContext");var z=class{constructor(){this.nodeDefs=new Map,this.defineOperator("core:Comment",Y),this.defineOperator("core:Param",te),this.defineOperator("core:Result",re),this.defineOperator("core:Local",ee)}async loadGraph(e){let{refs:t={}}=e,r=[];for(let o of Object.values(t))!o||r.push(this.loadNodeDef(o));return await Promise.all(r),new u(this,e)}async loadNodeDef(e){let t=this.getNodeDef(e);if(t)return t;if(e.startsWith("core:"))return t??this.unresolved(e);let r=await import(e);if(!r.node)return this.unresolved(e);let o=F.decode(r.node);return this.defineOperator(e,o),o}resolveNodeDef(e){return this.getNodeDef(e)??this.unresolved(e)}getNodeDef(e){return this.nodeDefs.get(e)??null}defineOperator(e,t){let r={category:[],description:"",deprecated:"",hidden:!1,...t};return this.nodeDefs.set(e,r),r}unresolved(e){return{label:"Unresolved",description:"",deprecated:"",category:[],hidden:!0,params:{},result:{type:"any"},compute(){throw new B(`Node definition ${e} not found`)}}}};i(z,"GraphLoader");var B=class extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500}};i(B,"UnresolvedNodeError");var Oe={};})(); | ||
`)}};i(E,"ValidationError");var O=class{constructor(e,t){this.decoder=e,this.value=t,this.errors=[]}decode(){let e=this.decodeAny(this.decoder.schema,this.value,"");if(this.errors.length>0)throw new E(this.decoder.schema,this.errors);return e}decodeAny(e,t,r){let o=e;if(t==null){if(o.optional)return;if(o.nullable)return null;t=this.defaultValue(e)}if(e.type==="any")return t;if(e.type==="ref")return this.decodeRef(e.schemaId,t,r);if(e.type!==K(t)){let n=V(e.type,t);if(n===void 0)return this.errors.push({path:r,message:`must be ${e.type}`}),this.defaultValue(e);t=n}switch(e.type){case"boolean":return t;case"number":case"integer":return this.decodeNumber(e,t,r);case"string":return this.decodeString(e,t,r);case"object":return this.decodeObject(e,t,r);case"array":return this.decodeArray(e,t,r);default:return this.errors.push({path:r,message:"must be a valid data type"}),this.defaultValue(e)}}decodeNumber(e,t,r){let o=t,n=!0;return e.minimum!=null&&o<e.minimum&&(this.errors.push({path:r,message:`must be greater than or equal to ${e.minimum}`}),n=!1),e.maximum!=null&&o>e.maximum&&(this.errors.push({path:r,message:`must be less than or equal to ${e.maximum}`}),n=!1),n?o:this.defaultValue(e)}decodeString(e,t,r){var o;let n=t,a=!0;return e.enum!=null&&!e.enum.includes(n)&&(this.errors.push({path:r,message:"must be an allowed value"}),a=!1),e.regex!=null&&(new RegExp(e.regex,(o=e.regexFlags)!==null&&o!==void 0?o:"").test(n)||(this.errors.push({path:r,message:"must be in allowed format"}),a=!1)),a?n:this.defaultValue(e)}decodeObject(e,t,r){let o=new Set,n={},a=t;for(let[c,d]of Object.entries(e.properties)){let k=a[c],w=this.decodeAny(d,k,`${r}.${c}`);w!==void 0&&(n[c]=w),o.add(c)}if(e.additionalProperties)for(let[c,d]of Object.entries(a))o.has(c)||(n[c]=this.decodeAny(e.additionalProperties,d,`${r}.${c}`));return n}decodeArray(e,t,r){let o=[],n=t;for(let a of n){let c=this.decodeAny(e.items,a,`${r}.*`);o.push(c)}return o}decodeRef(e,t,r){let o=this.decoder.getRef(e);if(!o){this.errors.push({path:r,message:`unknown type ${e}`});return}return this.decodeAny(o,t,r)}defaultValue(e){let t=e.default;return typeof t=="function"?t():t??(e.optional?void 0:e.nullable?null:ne[e.type])}};i(O,"DecodeJob");var p=class{constructor(e){this._refs=null,this.schema=e}create(e){return this.decode(e)}decode(e){return new O(this,e).decode()}getRef(e){var t;return(t=this.getRefs().get(e))!==null&&t!==void 0?t:null}getRefs(){return this._refs||(this._refs=new Map,this._collectRefs(this._refs,this.schema)),this._refs}_collectRefs(e,t){if(t.id&&e.set(t.id,t),t.refs)for(let r of t.refs)this._collectRefs(e,r);if(t.type==="object"&&(t.additionalProperties&&this._collectRefs(e,t.additionalProperties),t.properties))for(let r of Object.values(t.properties))this._collectRefs(e,r);t.type==="array"&&t.items&&this._collectRefs(e,t.items)}};i(p,"Schema");var g=new p({id:"DataSchema",type:"object",properties:{type:{type:"string",default:"any"},kind:{type:"string",optional:!0},enum:{type:"array",items:{type:"string"},optional:!0},default:{type:"any",optional:!0},properties:{type:"object",optional:!0,properties:{},additionalProperties:{type:"ref",schemaId:"DataSchema"}},additionalProperties:{type:"ref",optional:!0,schemaId:"DataSchema"},items:{type:"ref",optional:!0,schemaId:"DataSchema"}}});var ge=i(s=>crypto.getRandomValues(new Uint8Array(s)),"random"),xe=i((s,e,t)=>{let r=(2<<Math.log(s.length-1)/Math.LN2)-1,o=-~(1.6*r*e/s.length);return(n=e)=>{let a="";for(;;){let c=t(o),d=o;for(;d--;)if(a+=s[c[d]&r]||"",a.length===n)return a}}},"customRandom"),Z=i((s,e=21)=>xe(s,e,ge),"customAlphabet"),q=i((s=21)=>crypto.getRandomValues(new Uint8Array(s)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),""),"nanoid");var ae="abcdefghijklmnopqrstuvwxyz0123456789",$e=i(()=>q(4),"tinyId"),f=i(()=>q(8),"shortId"),be=Z(ae,12),pe=Z(ae,24),j=new p({id:"Id",type:"string",regex:"^[a-zA-Z0-9_-]{1,64}$",default:()=>pe()});function Ne(s,e,t=f){let r=new Map,o=JSON.stringify(s,(n,a)=>{if(e.includes(n)){let c=a,d=t();return r.set(c,d),d}return a});return JSON.parse(o,(n,a)=>{if(typeof a=="string"){let c=r.get(a);if(c)return c}return a})}i(Ne,"cloneWithNewIds");var X=new p({id:"Point",type:"object",properties:{x:{type:"number"},y:{type:"number"}},default:{x:0,y:0}}),Se={ZERO:{x:0,y:0},add(s,e){return{x:s.x+e.x,y:s.y+e.y}},scale(s,e){return{x:s.x*e,y:s.y*e}}};var A=new p({id:"Prop",type:"object",properties:{id:{...j.schema,default:f},key:{type:"string"},value:{type:"string"},linkId:{type:"string"},linkKey:{type:"string"},expand:{type:"boolean"},entries:{type:"array",optional:!0,items:{type:"ref",schemaId:"Prop"}}}});var v=new p({id:"Node",type:"object",properties:{id:{...j.schema,default:()=>f()},ref:{type:"string"},pos:X.schema,w:{type:"integer",default:5,minimum:3,maximum:20},collapsed:{type:"boolean"},props:{type:"array",items:A.schema}}});var F=new p({id:"ParamDef",type:"object",properties:{kind:{type:"string",enum:["lambda"],optional:!0},label:{type:"string",optional:!0},schema:g.schema,scope:{type:"object",properties:{},additionalProperties:g.schema,optional:!0},default:{type:"string",optional:!0},addItemLabel:{type:"string",optional:!0},removeItemLabel:{type:"string",optional:!0},keyPlaceholder:{type:"string",optional:!0},valuePlaceholder:{type:"string",optional:!0},hideEntries:{type:"boolean",optional:!0}}});var R=new p({id:"NodeMetadata",type:"object",properties:{label:{type:"string"},category:{type:"array",items:{type:"string"}},description:{type:"string"},deprecated:{type:"string"},hidden:{type:"boolean"},params:{type:"object",properties:{},additionalProperties:F.schema},result:g.schema}});var G=new p({id:"Graph",type:"object",properties:{metadata:R.schema,nodes:{type:"array",items:v.schema},rootNodeId:{type:"string"},refs:{type:"object",properties:{},additionalProperties:{type:"string"}}}});var H=new p({id:"NodeDef",type:"object",properties:{metadata:R.schema,compute:{type:"any"}}});var ke=new p({type:"object",properties:{nodeId:{type:"string"},result:{type:"any",optional:!0},error:{type:"any",optional:!0}}});var le={};I(le,{IdSchema:()=>j,InvalidTypeError:()=>L,MultiMap:()=>$,NotFoundError:()=>x,Point:()=>Se,PointSchema:()=>X,abbreviate:()=>Ee,capitalizeWords:()=>me,checkType:()=>Ie,clamp:()=>C,cloneWithNewIds:()=>Ne,codeToUrl:()=>de,evalEsmModule:()=>we,getType:()=>T,humanize:()=>Q,isSchemaCompatible:()=>y,mediumId:()=>be,parseAny:()=>Pe,safeId:()=>pe,serialize:()=>h,shortId:()=>f,tinyId:()=>$e});function C(s,e,t){return Math.min(Math.max(s,e),t)}i(C,"clamp");var x=class extends Error{constructor(e="Object"){super(`${e} not found`),this.name=this.constructor.name,this.status=404}};i(x,"NotFoundError");async function we(s){return await import(de(s))}i(we,"evalEsmModule");function de(s){return`data:text/javascript;base64,${btoa(s)}`}i(de,"codeToUrl");var $=class{constructor(){this.map=new Map}add(e,t){let r=this.map.get(e)??new Set;r.add(t),this.map.set(e,r)}get(e){return this.map.get(e)??new Set}delete(e,t){let r=this.map.get(e);return r?r.delete(t):!1}deleteAll(e){this.map.delete(e)}deleteValue(e){for(let t of this.groups())t.delete(e)}clear(){this.map.clear()}keys(){return this.map.keys()}groups(){return this.map.values()}};i($,"MultiMap");function h(s,e={}){let t={};for(let[r,o]of Object.entries(s))r[0]==="$"||r[0]==="_"||r in e&&String(e[r])===String(o)||(t[r]=o);return t}i(h,"serialize");function Pe(s){switch(String(s??"").trim()){case"false":return!1;case"true":return!0;case"null":return null;case"":return"";default:{let t=Number(s);if(!isNaN(t))return t;if(s.startsWith("[")||s.startsWith("{"))try{return JSON.parse(s)}catch{}return s}}}i(Pe,"parseAny");function T(s){if(s==null)return"null";if(Array.isArray(s))return"array";let e=typeof s;return e==="object"||e==="number"||e==="string"||e==="boolean"?e:"any"}i(T,"getType");function Ie(s,e){let t=T(s),r=Array.isArray(e)?e:[e];for(let o of r)if(t===o)return;throw new L(`Expected ${r.join(" or ")}, instead got ${t}`)}i(Ie,"checkType");function y(s,e){switch(s.type){case"any":return!0;case"string":case"boolean":case"number":return e.type===s.type;case"object":if(e.type!=="object")return!1;if(s.properties)for(let[t,r]of Object.entries(s.properties)){let o=(e.properties??{})[t]??{type:"any"};if(!y(r,o))return!1}return!(s.additionalProperties&&!y(s.additionalProperties,e.additionalProperties??{type:"any"}));case"array":return e.type!=="array"?!1:s.items?y(s.items,e.items??{type:"any"}):!0;default:return!1}}i(y,"isSchemaCompatible");var L=class extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=400}};i(L,"InvalidTypeError");function me(s){return s.replace(/\b([a-zA-Z])/g,(e,t)=>t.toUpperCase())}i(me,"capitalizeWords");function Q(s){return me(s.replace(/([A-Z])/g," $1").trim())}i(Q,"humanize");function Ee(s){switch(T(s)){case"object":return"{\u2026}";case"array":return"[\u2026]";case"string":return s.substring(0,20)+(s.length>20?"\u2026":"");case"null":return"null";default:return String(s)}}i(Ee,"abbreviate");var l=class{constructor(e,t={}){this.$parent=e;let r=l.schema.decode(t);Object.assign(this,r),this.entries=(r.entries??[]).map(o=>new l(this,o))}toJSON(){return h(this,{value:"",linkId:"",linkKey:"",expand:!1,entries:[]})}get $node(){return this.$parent instanceof m?this.$parent:this.$parent.$node}get $graph(){return this.$node.$graph}get $param(){return this.$node.$def.metadata.params[this.$paramKey]??{schema:{type:"any"}}}get $paramKey(){return this.$parent instanceof l?this.$parent.key:this.key}getLabel(){return this.$param.label??Q(this.$paramKey)}get $baseProp(){return this.$parent instanceof l?this.$parent:this}isLambda(){return this.$param.kind==="lambda"}isEntry(){return this.$parent instanceof l}isSupportsEntries(){if(this.isEntry()||this.isLambda())return!1;let{schema:e,hideEntries:t}=this.$param;return!t&&(e.type==="object"||e.type==="array")}isUsesEntries(){return this.isSupportsEntries()&&!this.getLinkNode()}getLinkNode(){return this.linkId?this.$graph.getNodeById(this.linkId):null}canExpand(){return!this.isLambda()}isExpanded(){return this.canExpand()&&!!this.expand&&!!this.getLinkNode()}getTargetSchema(){let e=this.$param.schema;if(this.isEntry()){if(e.type==="array")return e.items??{type:"any"};if(e.type==="object")return e.additionalProperties??{type:"any"}}return e}};i(l,"Prop");l.schema=A;var m=class{constructor(e,t={}){this.$graph=e,this.props=[];let r=m.schema.decode(t);Object.assign(this,r),this.props=this.initProps(r.props),this.applyInvariants()}toJSON(){return h(this,{collapsed:!1,scopeId:""})}get $uri(){return this.$graph.resolveUri(this.ref)}get $def(){return this.$graph.resolveNode(this.ref)}isRoot(){return this.$graph.rootNodeId===this.id}getBasePropByKey(e){return this.props.find(t=>t.key===e)??null}getPropById(e){for(let t of this.allProps())if(t.id===e)return t;return null}*allProps(){for(let e of this.props)yield e,e.isSupportsEntries()&&(yield*e.entries)}*computedProps(){for(let e of this.props)e.isUsesEntries()?yield*e.entries:yield e}*displayedProps(){for(let e of this.props)e.isUsesEntries()?(yield e,yield*e.entries):yield e}isExpanded(){return[...this.computedProps()].some(e=>e.isExpanded())}*leftNodes(e=new Set){if(!e.has(this.id)){e.add(this.id),yield this;for(let t of this.inboundLinks())yield*t.linkNode.leftNodes(e)}}*rightNodes(e=this.$graph.computeLinkMap()){yield this;for(let t of e.get(this.id))yield*t.node.rightNodes(e)}canLinkTo(e){for(let t of this.leftNodes())if(t.id===e.id)return!1;return!0}*inboundLinks(){for(let e of this.allProps()){let t=e.getLinkNode();t&&(yield{node:this,prop:e,linkNode:t,linkKey:e.linkKey})}}setCollapsed(e){this.collapsed=e}setPos(e){this.pos=e}setWidth(e){this.w=C(e,m.MIN_W,m.MAX_W)}setPropKey(e,t){let r=this.getPropById(e);r&&r.isEntry()&&(r.key=t)}setPropValue(e,t){let r=this.getPropById(e);r&&(r.value=t)}setPropExpand(e,t){let r=this.getPropById(e);r&&(r.expand=t)}addPropEntry(e){let t=this.getBasePropByKey(e);if(t&&t.isSupportsEntries()){let r=new l(t);t.entries.push(r)}}removePropEntry(e,t){let r=this.getBasePropByKey(e);if(r&&r.isSupportsEntries()){let o=r.entries.findIndex(n=>n.id===t);o>-1&&r.entries.splice(o,1)}}initProps(e){let t=[];for(let r of Object.keys(this.$def.metadata.params)){let o=e.find(a=>a.key===r)??{key:r},n=new l(this,o);t.push(n)}return t}applyInvariants(){this.w=C(this.w,m.MIN_W,m.MAX_W);for(let e of this.props){let t=e.getLinkNode();t&&(t.canLinkTo(this)||(e.linkId=""))}}};i(m,"Node");m.schema=v;m.MIN_W=3;m.MAX_W=20;var u=class{constructor(e,t={}){this.$loader=e,this.refs={},this.$nodeMap=new Map;let r=u.schema.decode(t);Object.assign(this,r),this.nodes=[];for(let o of r.nodes){let n=new m(this,o);this.addNodeRaw(n)}}toJSON(){return h(this,{label:"",description:"",deprecated:"",hidden:!1,category:[],params:{},rootNodeId:"",refs:{}})}resolveUri(e){return this.refs[e]??""}resolveNode(e){let t=this.resolveUri(e);return this.$loader.resolveNodeDef(t)}getNodeById(e){return this.$nodeMap.get(e)??null}getRootNode(){return this.rootNodeId?this.getNodeById(this.rootNodeId):null}async createNode(e){await this.$loader.loadNodeDef(e.uri);let t=this.getRefForUri(e.uri),r=new m(this,{...e.node,ref:t});return this.addNodeRaw(r),r}addNodeRaw(e){this.nodes.push(e),this.$nodeMap.set(e.id,e)}deleteNode(e){this.$nodeMap.delete(e);let t=this.nodes.findIndex(r=>r.id===e);return t>-1?(this.nodes.splice(t,1),!0):!1}rightmostNodes(){let e=new Set(this.nodes);for(let t of this.nodes)for(let r of t.inboundLinks())e.delete(r.linkNode);return[...e]}*allLinks(){for(let e of this.nodes)yield*e.inboundLinks()}computeLinkMap(){let e=new $;for(let t of this.nodes)for(let r of t.computedProps()){let o=r.getLinkNode();o&&e.add(o.id,{node:t,prop:r,linkNode:o,linkKey:r.linkKey})}return e}computeOrder(e=this.rootNodeId){let t=[],r=this.getNodeById(e??this.rootNodeId);return r&&this._computeOrder(t,r),t}_computeOrder(e,t){e.unshift(t);for(let r of t.computedProps()){let o=r.getLinkNode();if(o){let n=e.findIndex(a=>a.id===o.id);n>-1&&e.splice(n,1),this._computeOrder(e,o)}}}getRefForUri(e){for(let[r,o]of Object.entries(this.refs))if(o===e)return r;let t=f();return this.refs[t]=e,t}};i(u,"Graph");u.schema=G;var se={};I(se,{Comment:()=>Y,Local:()=>ee,Param:()=>te,Result:()=>re});var Y={metadata:{label:"Comment",category:["Graph"],params:{comment:{schema:{type:"string"}}},result:{type:"any"}},compute(){}};var ee={metadata:{label:"Local",category:["Graph"],params:{key:{schema:{type:"string"}}},result:{type:"any"}},compute(){}};var te={metadata:{label:"Parameter",category:["Graph"],params:{key:{schema:{type:"string",kind:"param"}}},result:{type:"any"}},compute(){}};var re={metadata:{label:"Result",category:["Graph"],params:{value:{schema:{type:"any"}}},result:{type:"any"}},compute(){}};var fe={};I(fe,{BaseContext:()=>S,CodeBuilder:()=>b,CompilerError:()=>N,GraphCompiler:()=>J,GraphEvalContext:()=>W,GraphLoader:()=>z,ScopeEvalContext:()=>D,UnresolvedNodeError:()=>B});var b=class{constructor(e=" ",t=0){this.indentString=e,this.currentIndent=t,this.buffer=[]}toString(){return this.buffer.join("")}push(e){return this.buffer.push(e),this}pushIndent(){return this.buffer.push(this.indentString.repeat(this.currentIndent)),this}line(e){return this.pushIndent(),this.push(e),this.push(` | ||
`),this}indent(e=1){return this.currentIndent+=e,this}block(e,t,r){this.line(e),this.indent(),r(),this.indent(-1),this.line(t)}};i(b,"CodeBuilder");var J=class{compileEsm(e,t={}){let r=e.getNodeById(t.rootNodeId??e.rootNodeId);if(!r)throw new x("Node");return new U(e,r,t).compileEsm()}};i(J,"GraphCompiler");var U=class{constructor(e,t,r={}){this.graph=e,this.rootNode=t,this.symCounters=new Map,this.symtable=new Map,this.code=new b,this.order=[],this.sym={nodeEvaluated:this.nextSym("o"),toArray:this.nextSym("o"),convertType:this.nextSym("o")},this.options={rootNodeId:t.id,comments:!1,introspect:!1,...r},this.order=e.computeOrder(t.id),this.linkMap=e.computeLinkMap()}compileEsm(){return this.emitImports(),this.emitExportNode(),this.code.toString()}emitImports(){this.emitComment("Imports");let e=new Set(this.order.map(t=>t.ref));for(let t of e){let r=this.graph.refs[t];if(!r)throw new N(`Cannot resolve ref ${t}`);if(r.startsWith("core:"))continue;let o=this.nextSym("n");this.symtable.set(`def:${t}`,o),this.code.line(`import { node as ${o} } from '${r}'`)}}emitExportNode(){this.emitComment("Node Definition"),this.code.block("export const node = {","};",()=>{this.emitGraphMetadata(),this.code.block("async compute(params, ctx) {","}",()=>{this.emitComputeBody()})})}emitGraphMetadata(){this.code.line(`metadata: ${JSON.stringify(this.graph.metadata)},`)}emitComputeBody(){this.emitCtxLocals();for(let e of this.order)this.emitNode(e);this.emitResult()}emitCtxLocals(){this.symtable.set("nodeEvaluated",this.sym.nodeEvaluated),this.symtable.set("toArray",this.sym.toArray),this.symtable.set("convertType",this.sym.convertType),this.code.line(`const {$nodeEvaluated: ${this.sym.nodeEvaluated},$toArray: ${this.sym.toArray},$convertType: ${this.sym.convertType},} = ctx;`)}emitResult(){this.emitComment("Result");let e=this.nodeResultExpr(this.rootNode);this.code.line(`return ${e};`)}emitNode(e){this.emitComment(`${e.ref} ${e.id}`);let t=this.nextSym("r");if(this.symtable.set(`node:${e.id}`,t),e.$uri.startsWith("core:"))return this.emitCoreNode(e);this.code.block(`async function ${t}(ctx) {`,"}",()=>{this.isNodeCached(e.id)?(this.code.line(`const $c = ctx.$cache.get("${e.id}");`),this.code.line("if ($c) return $c;"),this.code.block("try {","}",()=>{this.emitNodeBody(e)}),this.code.block("catch (err) {","}",()=>{this.code.line(`ctx.$cache.set("${e.id}", Promise.reject(err));`),this.code.line("throw err;")})):this.emitNodeBody(e)})}emitCoreNode(e){switch(e.$uri){case"core:Param":return;case"core:Comment":return;case"core:Result":return this.emitResultNode(e);case"core:Local":return this.emitLocalNode(e)}}emitNodeBody(e){let t=i(()=>{e.isExpanded()?this.emitExpandedNode(e):this.emitRegularNode(e)},"emitBody");this.options.introspect?(this.code.block("try {","}",()=>{t()}),this.code.block("catch (error) {","}",()=>{this.code.line(`${this.sym.nodeEvaluated}.emit({nodeId: ${JSON.stringify(e.id)},error,});`),this.code.line("throw error;")})):t()}emitResultNode(e){let t=this.getNodeSym(e.id),r=e.getBasePropByKey("value"),o=this.singlePropExpr(r,this.graph.metadata.result);this.code.line(`async function ${t}(ctx) {return ${o};}`)}emitLocalNode(e){let t=this.getNodeSym(e.id),r=e.getBasePropByKey("key");this.code.line(`async function ${t}(ctx) {return ctx.getLocal(${JSON.stringify(r.value)});}`)}emitRegularNode(e){let t=this.getDefSym(e.ref),r="$r";this.code.block(`const ${r} = ${t}.compute({`,"}, ctx);",()=>{this.emitNodeProps(e)}),this.isNodeCached(e.id)&&this.code.line(`ctx.$cache.set("${e.id}", ${r});`),this.options.introspect&&this.code.line(`${this.sym.nodeEvaluated}.emit({nodeId: ${JSON.stringify(e.id)},result: await ${r}});`),this.code.line(`return await ${r};`)}emitExpandedNode(e){let t=this.getDefSym(e.ref),r="$r",n=[...e.computedProps()].filter(d=>d.isExpanded());this.code.line(`const ${r} = []`);let a=[];for(let d of n){let k=this.nextSym("p");this.symtable.set(`prop:${d.id}`,k),a.push(k);let w=d.linkKey,oe=d.getLinkNode(),_=this.nodeResultExpr(oe),he=oe.isExpanded(),P;he?w?P=`(${_}).map(_ => _[${JSON.stringify(d.linkKey)}])`:P=`${_}`:w?P=`${this.sym.toArray}((${_})[${JSON.stringify(d.linkKey)}])`:P=`${this.sym.toArray}(${_})`,this.code.line(`const ${k} = ${P}`)}let c=a.map(d=>`i < ${d}.length`).join(" && ");this.code.block(`for (let i = 0;${c};i++) {`,"}",()=>{let d="$t";this.code.block(`const ${d} = ${t}.compute({`,"}, ctx);",()=>{this.emitNodeProps(e)}),this.code.line(`${r}.push(await ${d});`)}),this.isNodeCached(e.id)&&this.code.line(`ctx.$cache.set("${e.id}", ${r});`),this.options.introspect&&this.code.line(`${this.sym.nodeEvaluated}.emit({nodeId: ${JSON.stringify(e.id)},result: ${r}});`),this.code.line(`return ${r};`)}emitNodeProps(e){for(let t of e.props)t.isUsesEntries()?this.emitEntries(t):this.emitSingleProp(t)}emitEntries(e){let{schema:t}=e.$param;switch(t.type){case"array":return this.emitArrayEntries(e);case"object":return this.emitObjectEntries(e)}}emitArrayEntries(e){this.code.block(`${JSON.stringify(e.key)}: [`,"],",()=>{for(let t of e.entries){let r=this.singlePropExpr(t);this.code.line(`${r},`)}})}emitObjectEntries(e){this.code.block(`${JSON.stringify(e.key)}: {`,"},",()=>{for(let t of e.entries){let r=this.singlePropExpr(t);this.code.line(`${JSON.stringify(t.key)}: ${r},`)}})}emitSingleProp(e){let t=this.singlePropExpr(e);this.code.line(`${JSON.stringify(e.key)}: ${t},`)}singlePropExpr(e,t=e.getTargetSchema()){if(e.isLambda())return this.lambdaPropExpr(e);let r=this.rawPropExpr(e),o={type:"string"},n=e.getLinkNode();return n&&(o=n.$def.metadata.result),!y(t,o)&&(r=this.convertTypeExpr(r,t)),r}convertTypeExpr(e,t){return`${this.sym.convertType}(${e}, ${JSON.stringify(t)})`}rawPropExpr(e){let t=this.symtable.get(`prop:${e.id}`);if(t)return`${t}[i]`;let r=JSON.stringify(String(e.value)),o=e.getLinkNode();return o&&(r=this.nodeResultExpr(o),e.linkKey&&(r=`(${r})[${JSON.stringify(e.linkKey)}]`)),r}nodeResultExpr(e){if(e.$uri==="core:Param"){let r=e.getBasePropByKey("key"),o=r?r.value:"";return`params[${JSON.stringify(o)}]`}return`await ${this.getNodeSym(e.id)}(ctx)`}lambdaPropExpr(e){let t=e.$param,r=e.getLinkNode();if(!r)return`() => ${this.convertTypeExpr(t.default??"",t.schema)}`;let o=r.$def.metadata.result,n=this.getNodeSym(r.id);return y(t.schema,o)?`p => ctx.$scoped(p, ${n})`:`p => Promise.resolve(ctx.$scoped(p, ${n})).then(res => ${this.convertTypeExpr("res",o)})`}getNodeSym(e){return this.getSym(`node:${e}`)}getDefSym(e){return this.getSym(`def:${e}`)}getSym(e){let t=this.symtable.get(e);if(!t)throw new N(`Symbol not found: ${e}`);return t}nextSym(e){let t=this.symCounters.get(e)??0;return this.symCounters.set(e,t+1),`${e}${t+1}`}emitComment(e){this.options.comments&&this.code.line(`// ${e}`)}isNodeCached(e){return this.linkMap.get(e).size>1}};i(U,"GraphCompilerContext");var N=class extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500}};i(N,"CompilerError");var M=class{constructor(){this.listeners=[]}on(e,t=void 0){return this.listeners.push({listener:e,once:!1,group:t}),()=>this.off(e)}once(e,t=void 0){return this.listeners.push({listener:e,once:!0,group:t}),()=>this.off(e)}off(e){let t=this.listeners.findIndex(r=>r.listener===e);t>-1&&this.listeners.splice(t,1)}removeAll(e){this.listeners=this.listeners.filter(t=>t.group!==e)}emit(e){for(let t=0;t<this.listeners.length;t++){let{listener:r,once:o}=this.listeners[t];r(e),o&&(this.listeners.splice(t,1),t-=1)}}};i(M,"Event");var S=class{constructor(){this.$cache=new Map}$scoped(e,t){let r=new D(this,e);return t(r)}$toArray(e){return Array.isArray(e)?e:[e]}$convertType(e,t){return new p(t).decode(e)}};i(S,"BaseContext");var W=class extends S{constructor(){super(...arguments),this.$nodeEvaluated=new M}getLocal(e){return null}};i(W,"GraphEvalContext");var D=class extends S{constructor(e,t={}){super(),this.parent=e,this.locals=new Map,this.locals=new Map(Object.entries(t))}get $nodeEvaluated(){return this.parent.$nodeEvaluated}getLocal(e){let t=this.locals.get(e);return t!==void 0?t:this.parent.getLocal(e)}};i(D,"ScopeEvalContext");var z=class{constructor(){this.nodeDefs=new Map,this.defineOperator("core:Comment",Y),this.defineOperator("core:Param",te),this.defineOperator("core:Result",re),this.defineOperator("core:Local",ee)}async loadGraph(e){let{refs:t={}}=e,r=[];for(let o of Object.values(t))!o||r.push(this.loadNodeDef(o));return await Promise.all(r),new u(this,e)}async loadNodeDef(e){let t=this.getNodeDef(e);if(t)return t;if(e.startsWith("core:"))return t??this.createUnresolvedDef(e);let r=await import(e);if(!r.node)return this.createUnresolvedDef(e);let o=H.decode(r.node);return this.defineNode(e,o),o}resolveNodeDef(e){return this.getNodeDef(e)??this.createUnresolvedDef(e)}getNodeDef(e){return this.nodeDefs.get(e)??null}defineOperator(e,t){let o={metadata:{category:[],description:"",deprecated:"",hidden:!1,...t.metadata},compute:t.compute};return this.nodeDefs.set(e,o),o}defineNode(e,t){this.nodeDefs.set(e,t)}createUnresolvedDef(e){return{metadata:{label:"Unresolved",description:"",deprecated:"",category:[],hidden:!0,params:{},result:{type:"any"}},compute(){throw new B(`Node definition ${e} not found`)}}}};i(z,"GraphLoader");var B=class extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500}};i(B,"UnresolvedNodeError");var Oe={};})(); |
@@ -7,10 +7,4 @@ import * as t from '../types/index.js'; | ||
static schema: import("airtight").Schema<t.Graph>; | ||
label: string; | ||
category: string[]; | ||
description: string; | ||
deprecated: string; | ||
hidden: boolean; | ||
metadata: t.NodeMetadata; | ||
rootNodeId: string; | ||
params: Record<string, t.ParamMetadata>; | ||
result: t.DataSchema<any>; | ||
nodes: Node[]; | ||
@@ -34,3 +28,2 @@ refs: Record<string, string>; | ||
protected getRefForUri(uri: string): string; | ||
compute(): void; | ||
} |
@@ -7,4 +7,2 @@ import { GraphSchema } from '../schema/index.js'; | ||
this.$loader = $loader; | ||
this.params = {}; | ||
this.result = { type: 'any' }; | ||
this.refs = {}; | ||
@@ -129,7 +127,4 @@ this.$nodeMap = new Map(); | ||
} | ||
compute() { | ||
// Just a dummy to satisfy the interface | ||
} | ||
} | ||
Graph.schema = GraphSchema; | ||
//# sourceMappingURL=graph.js.map |
@@ -181,3 +181,3 @@ import { NodeSchema } from '../schema/node.js'; | ||
const props = []; | ||
for (const key of Object.keys(this.$def.params)) { | ||
for (const key of Object.keys(this.$def.metadata.params)) { | ||
const spec = specs.find(_ => _.key === key) ?? { key }; | ||
@@ -184,0 +184,0 @@ const prop = new Prop(this, spec); |
@@ -34,3 +34,3 @@ import { PropSchema } from '../schema/prop.js'; | ||
get $param() { | ||
return this.$node.$def.params[this.$paramKey] ?? { | ||
return this.$node.$def.metadata.params[this.$paramKey] ?? { | ||
schema: { type: 'any' }, | ||
@@ -37,0 +37,0 @@ }; |
export const Comment = { | ||
label: 'Comment', | ||
category: ['Graph'], | ||
params: { | ||
comment: { | ||
schema: { | ||
type: 'string' | ||
}, | ||
} | ||
metadata: { | ||
label: 'Comment', | ||
category: ['Graph'], | ||
params: { | ||
comment: { | ||
schema: { | ||
type: 'string' | ||
}, | ||
} | ||
}, | ||
result: { type: 'any' }, | ||
}, | ||
result: { type: 'any' }, | ||
compute() { }, | ||
}; | ||
//# sourceMappingURL=comment.js.map |
export const Local = { | ||
label: 'Local', | ||
category: ['Graph'], | ||
params: { | ||
key: { | ||
schema: { | ||
type: 'string', | ||
}, | ||
} | ||
metadata: { | ||
label: 'Local', | ||
category: ['Graph'], | ||
params: { | ||
key: { | ||
schema: { | ||
type: 'string', | ||
}, | ||
} | ||
}, | ||
result: { type: 'any' }, | ||
}, | ||
result: { type: 'any' }, | ||
compute() { } | ||
}; | ||
//# sourceMappingURL=local.js.map |
export const Param = { | ||
label: 'Parameter', | ||
category: ['Graph'], | ||
params: { | ||
key: { | ||
schema: { | ||
type: 'string', | ||
kind: 'param', | ||
}, | ||
} | ||
metadata: { | ||
label: 'Parameter', | ||
category: ['Graph'], | ||
params: { | ||
key: { | ||
schema: { | ||
type: 'string', | ||
kind: 'param', | ||
}, | ||
} | ||
}, | ||
result: { type: 'any' }, | ||
}, | ||
result: { type: 'any' }, | ||
compute() { } | ||
}; | ||
//# sourceMappingURL=param.js.map |
export const Result = { | ||
label: 'Result', | ||
category: ['Graph'], | ||
params: { | ||
value: { | ||
schema: { | ||
type: 'any', | ||
}, | ||
} | ||
metadata: { | ||
label: 'Result', | ||
category: ['Graph'], | ||
params: { | ||
value: { | ||
schema: { | ||
type: 'any', | ||
}, | ||
} | ||
}, | ||
result: { type: 'any' }, | ||
}, | ||
result: { type: 'any' }, | ||
compute() { }, | ||
}; | ||
//# sourceMappingURL=result.js.map |
@@ -76,9 +76,3 @@ import { isSchemaCompatible, NotFoundError } from '../util/index.js'; | ||
this.code.block('export const node = {', '};', () => { | ||
this.emitGraphProp('label'); | ||
this.emitGraphProp('category'); | ||
this.emitGraphProp('description'); | ||
this.emitGraphProp('deprecated'); | ||
this.emitGraphProp('hidden'); | ||
this.emitGraphProp('params'); | ||
this.emitGraphProp('result'); | ||
this.emitGraphMetadata(); | ||
this.code.block('async compute(params, ctx) {', '}', () => { | ||
@@ -89,4 +83,4 @@ this.emitComputeBody(); | ||
} | ||
emitGraphProp(key) { | ||
this.code.line(`${key}: ${JSON.stringify(this.graph[key])},`); | ||
emitGraphMetadata() { | ||
this.code.line(`metadata: ${JSON.stringify(this.graph.metadata)},`); | ||
} | ||
@@ -182,3 +176,3 @@ emitComputeBody() { | ||
const prop = node.getBasePropByKey('value'); | ||
const expr = this.singlePropExpr(prop, this.graph.result); | ||
const expr = this.singlePropExpr(prop, this.graph.metadata.result); | ||
this.code.line(`async function ${sym}(ctx) {` + | ||
@@ -316,3 +310,3 @@ `return ${expr};` + | ||
if (linkNode) { | ||
sourceSchema = linkNode.$def.result; | ||
sourceSchema = linkNode.$def.metadata.result; | ||
} | ||
@@ -361,3 +355,3 @@ const needsTypeConversion = !isSchemaCompatible(targetSchema, sourceSchema); | ||
} | ||
const targetSchema = linkNode.$def.result; | ||
const targetSchema = linkNode.$def.metadata.result; | ||
const linkSym = this.getNodeSym(linkNode.id); | ||
@@ -364,0 +358,0 @@ const schemaCompatible = isSchemaCompatible(param.schema, targetSchema); |
@@ -0,3 +1,3 @@ | ||
import { Schema } from 'airtight'; | ||
import { Event } from 'typesafe-event'; | ||
import { convertType } from '../util/index.js'; | ||
/** | ||
@@ -22,3 +22,3 @@ * GraphEvalContext provides runtime tools for graph computation | ||
$convertType(value, schema) { | ||
return convertType(value, schema); | ||
return new Schema(schema).decode(value); | ||
} | ||
@@ -25,0 +25,0 @@ } |
@@ -11,3 +11,4 @@ import { Graph } from '../model/graph.js'; | ||
defineOperator(uri: string, op: t.Operator): t.NodeDef; | ||
unresolved(uri: string): t.NodeDef; | ||
protected defineNode(uri: string, nodeDef: t.NodeDef): void; | ||
protected createUnresolvedDef(uri: string): t.NodeDef; | ||
} | ||
@@ -14,0 +15,0 @@ export declare class UnresolvedNodeError extends Error { |
@@ -32,3 +32,3 @@ import { Graph } from '../model/graph.js'; | ||
// Do not import core: | ||
return existing ?? this.unresolved(uri); | ||
return existing ?? this.createUnresolvedDef(uri); | ||
} | ||
@@ -38,6 +38,6 @@ const res = await import(uri); | ||
if (!res.node) { | ||
return this.unresolved(uri); | ||
return this.createUnresolvedDef(uri); | ||
} | ||
const nodeDef = NodeDefSchema.decode(res.node); | ||
this.defineOperator(uri, nodeDef); | ||
this.defineNode(uri, nodeDef); | ||
return nodeDef; | ||
@@ -47,3 +47,3 @@ } | ||
const def = this.getNodeDef(uri); | ||
return def ?? this.unresolved(uri); | ||
return def ?? this.createUnresolvedDef(uri); | ||
} | ||
@@ -54,3 +54,3 @@ getNodeDef(uri) { | ||
defineOperator(uri, op) { | ||
const def = { | ||
const metadata = { | ||
category: [], | ||
@@ -60,16 +60,25 @@ description: '', | ||
hidden: false, | ||
...op, | ||
...op.metadata, | ||
}; | ||
this.nodeDefs.set(uri, def); | ||
return def; | ||
const nodeDef = { | ||
metadata, | ||
compute: op.compute, | ||
}; | ||
this.nodeDefs.set(uri, nodeDef); | ||
return nodeDef; | ||
} | ||
unresolved(uri) { | ||
defineNode(uri, nodeDef) { | ||
this.nodeDefs.set(uri, nodeDef); | ||
} | ||
createUnresolvedDef(uri) { | ||
return { | ||
label: 'Unresolved', | ||
description: '', | ||
deprecated: '', | ||
category: [], | ||
hidden: true, | ||
params: {}, | ||
result: { type: 'any' }, | ||
metadata: { | ||
label: 'Unresolved', | ||
description: '', | ||
deprecated: '', | ||
category: [], | ||
hidden: true, | ||
params: {}, | ||
result: { type: 'any' }, | ||
}, | ||
compute() { | ||
@@ -76,0 +85,0 @@ throw new UnresolvedNodeError(`Node definition ${uri} not found`); |
import { Schema } from 'airtight'; | ||
import { DataSchemaSchema } from './data-schema.js'; | ||
import { NodeSchema } from './node.js'; | ||
import { ParamMetadataSchema } from './param-metadata.js'; | ||
import { NodeMetadataSchema } from './node-metadata.js'; | ||
export const GraphSchema = new Schema({ | ||
@@ -9,27 +8,3 @@ id: 'Graph', | ||
properties: { | ||
label: { | ||
type: 'string', | ||
}, | ||
category: { | ||
type: 'array', | ||
items: { | ||
type: 'string' | ||
} | ||
}, | ||
description: { | ||
type: 'string', | ||
}, | ||
deprecated: { | ||
type: 'string', | ||
}, | ||
hidden: { | ||
type: 'boolean', | ||
}, | ||
params: { | ||
type: 'object', | ||
properties: {}, | ||
additionalProperties: ParamMetadataSchema.schema, | ||
}, | ||
result: DataSchemaSchema.schema, | ||
compute: { type: 'any' }, | ||
metadata: NodeMetadataSchema.schema, | ||
nodes: { | ||
@@ -36,0 +11,0 @@ type: 'array', |
export * from './data-schema.js'; | ||
export * from './graph.js'; | ||
export * from './node-def.js'; | ||
export * from './node-metadata.js'; | ||
export * from './node-result.js'; | ||
@@ -5,0 +6,0 @@ export * from './node.js'; |
@@ -5,2 +5,3 @@ // This file is auto-generated | ||
export * from './node-def.js'; | ||
export * from './node-metadata.js'; | ||
export * from './node-result.js'; | ||
@@ -7,0 +8,0 @@ export * from './node.js'; |
import { Schema } from 'airtight'; | ||
import { DataSchemaSchema } from './data-schema.js'; | ||
import { ParamMetadataSchema } from './param-metadata.js'; | ||
import { NodeMetadataSchema } from './node-metadata.js'; | ||
export const NodeDefSchema = new Schema({ | ||
id: 'NodeDef', | ||
type: 'object', | ||
properties: { | ||
label: { type: 'string' }, | ||
category: { | ||
type: 'array', | ||
items: { type: 'string' }, | ||
}, | ||
description: { type: 'string' }, | ||
deprecated: { type: 'string' }, | ||
hidden: { type: 'boolean' }, | ||
params: { | ||
type: 'object', | ||
properties: {}, | ||
additionalProperties: ParamMetadataSchema.schema, | ||
}, | ||
result: DataSchemaSchema.schema, | ||
metadata: NodeMetadataSchema.schema, | ||
compute: { type: 'any' }, | ||
} | ||
}, | ||
}); | ||
//# sourceMappingURL=node-def.js.map |
import { GraphEvalContext } from './ctx.js'; | ||
import { DataSchema } from './data.js'; | ||
export declare type NodeDef = { | ||
export declare type NodeMetadata = { | ||
label: string; | ||
@@ -11,13 +11,15 @@ category: string[]; | ||
result: DataSchema<any>; | ||
}; | ||
export declare type NodeDef = { | ||
metadata: NodeMetadata; | ||
compute: (...args: any[]) => any; | ||
}; | ||
export declare type Operator<Params = any, Result = any> = { | ||
metadata: OperatorMetadata<Params, Result>; | ||
compute: NodeCompute<Params, Result>; | ||
}; | ||
export declare type OperatorMetadata<Params = any, Result = any> = Partial<NodeMetadata> & { | ||
label: string; | ||
category?: string[]; | ||
description?: string; | ||
deprecated?: string; | ||
hidden?: boolean; | ||
params: ParamDefs<Params>; | ||
result: DataSchema<Result>; | ||
compute: NodeCompute<Params, Result>; | ||
}; | ||
@@ -24,0 +26,0 @@ export declare type NodeCompute<P, R> = (this: void, params: P, ctx: GraphEvalContext) => R | Promise<R>; |
import { DeepPartial } from './deep-partial.js'; | ||
import { NodeDef } from './defs.js'; | ||
export interface Graph extends NodeDef { | ||
import { NodeMetadata } from './defs.js'; | ||
export interface Graph { | ||
metadata: NodeMetadata; | ||
nodes: Node[]; | ||
@@ -5,0 +6,0 @@ rootNodeId: string; |
export * from './clamp.js'; | ||
export * from './convert.js'; | ||
export * from './errors.js'; | ||
@@ -4,0 +3,0 @@ export * from './eval.js'; |
// This file is auto-generated | ||
export * from './clamp.js'; | ||
export * from './convert.js'; | ||
export * from './errors.js'; | ||
@@ -5,0 +4,0 @@ export * from './eval.js'; |
{ | ||
"name": "@nodescript/core", | ||
"version": "0.1.0", | ||
"version": "0.2.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
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
144406
2217