Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

behave-graph

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

behave-graph - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

src/lib/Graphs/Validation/validateGraphRegistry.ts

20

dist/lib/index.d.ts

@@ -102,2 +102,10 @@ declare type DebugLogFunc = (test: string) => void;

declare class ValueType {
name: string;
creator: () => any;
parse: (text: string) => any;
toString: (value: any) => string;
constructor(name: string, creator: () => any, parse: (text: string) => any, toString: (value: any) => string);
}
declare type SocketFactory = () => Socket;

@@ -128,10 +136,2 @@

declare class ValueType {
name: string;
creator: () => any;
parse: (text: string) => any;
toString: (value: any) => string;
constructor(name: string, creator: () => any, parse: (text: string) => any, toString: (value: any) => string);
}
declare class ValueTypeRegistry {

@@ -200,2 +200,4 @@ valueTypeNameToValueType: Map<string, ValueType>;

export { BooleanSocket, Debug, FlowSocket, Graph, GraphEvaluator, GraphJSON, GraphRegistry, InputJSON, InputSocketSpecJSON, LinkJSON, Node, NodeEvalContext, NodeFactory, NodeJSON, NodeSocketRef, NodeSpecJSON, NodeTypeRegistry, NumberSocket, OutputSocketSpecJSON, Socket, SocketFactory, StringSocket, ValueTypeRegistry, readGraphFromJSON, registerGenericNodes, validateDirectedAcyclicGraph, validateLinks, writeGraphToJSON, writeNodeSpecsToJSON };
declare function validateGraphRegistry(graphRegistry: GraphRegistry): string[];
export { BooleanSocket, Debug, FlowSocket, Graph, GraphEvaluator, GraphJSON, GraphRegistry, InputJSON, InputSocketSpecJSON, LinkJSON, Node, NodeEvalContext, NodeFactory, NodeJSON, NodeSocketRef, NodeSpecJSON, NodeTypeRegistry, NumberSocket, OutputSocketSpecJSON, Socket, SocketFactory, StringSocket, ValueType, ValueTypeRegistry, readGraphFromJSON, registerGenericNodes, validateDirectedAcyclicGraph, validateGraphRegistry, validateLinks, writeGraphToJSON, writeNodeSpecsToJSON };

@@ -98,2 +98,11 @@ class Debug {

class ValueType {
constructor(name, creator, parse, toString) {
this.name = name;
this.creator = creator;
this.parse = parse;
this.toString = toString;
}
}
class Socket {

@@ -312,2 +321,4 @@ constructor(name, valueTypeName, value) {

if (upstreamNode.isEvalNode) {
// eslint-disable-next-line no-param-reassign
inputSocket.value = upstreamOutputSocket.value;
return upstreamOutputSocket.value;

@@ -398,12 +409,17 @@ }

return __awaiter(this, void 0, void 0, function* () {
const startDateTime = Date.now();
let stepsExecuted = 0;
let timeUsed = 0;
let elapsedTime = 0;
let iterations = 0;
do {
// eslint-disable-next-line no-await-in-loop
yield sleep(0.5);
if (iterations > 0) {
// eslint-disable-next-line no-await-in-loop
yield sleep(0);
}
stepsExecuted += this.executeAll(stepLimit);
timeUsed += 0.01;
Debug.logVerbose(`this.asyncNodes.length: ${this.asyncNodes.length}`);
Debug.logVerbose(`this.flowWorkQueue.length: ${this.flowWorkQueue.length}`);
} while ((this.asyncNodes.length > 0 || this.flowWorkQueue.length > 0) && timeUsed < timeLimit && stepsExecuted < stepLimit);
elapsedTime = (Date.now() - startDateTime) * 0.001;
iterations += 1;
} while ((this.asyncNodes.length > 0 || this.flowWorkQueue.length > 0) && (elapsedTime < timeLimit) && stepsExecuted < stepLimit);
return stepsExecuted;

@@ -609,11 +625,2 @@ });

class ValueType {
constructor(name, creator, parse, toString) {
this.name = name;
this.creator = creator;
this.parse = parse;
this.toString = toString;
}
}
class ValueTypeRegistry {

@@ -623,2 +630,3 @@ constructor() {

// register core types
this.register(new ValueType('flow', () => '', () => '', () => ''));
this.register(new ValueType('string', () => '', (text) => text, (value) => value));

@@ -870,3 +878,3 @@ this.register(new ValueType('boolean', () => false, (text) => (text === 'true'), (value) => (value ? 'true' : 'false')));

// logic: exponential
registry.register('logic/numberE', () => new NullaryOp('logic/numberSign', 'number', () => (Math.E)));
registry.register('logic/numberE', () => new NullaryOp('logic/numberE', 'number', () => (Math.E)));
registry.register('logic/numberExp', () => new UnaryOp('logic/numberExp', 'number', 'number', (a) => (Math.exp(a))));

@@ -877,3 +885,3 @@ registry.register('logic/numberLog', () => new UnaryOp('logic/numberLog', 'number', 'number', (a) => (Math.log(a))));

// logic: trigonometry
registry.register('logic/numberPi', () => new NullaryOp('logic/numberNegate', 'number', () => (Math.PI)));
registry.register('logic/numberPi', () => new NullaryOp('logic/numberPi', 'number', () => (Math.PI)));
registry.register('logic/numberSin', () => new UnaryOp('logic/numberSin', 'number', 'number', (a) => (Math.sin(a))));

@@ -892,3 +900,3 @@ registry.register('logic/numberAsin', () => new UnaryOp('logic/numberAsin', 'number', 'number', (a) => (Math.asin(a))));

registry.register('logic/numberCeil', () => new UnaryOp('logic/numberCeil', 'number', 'number', (a) => (Math.ceil(a))));
registry.register('logic/numberRound', () => new UnaryOp('logic/numberCeil', 'number', 'number', (a) => (Math.round(a))));
registry.register('logic/numberRound', () => new UnaryOp('logic/numberRound', 'number', 'number', (a) => (Math.round(a))));
registry.register('logic/numberTrunc', () => new UnaryOp('logic/numberTrunc', 'number', 'number', (a) => (Math.trunc(a))));

@@ -1007,2 +1015,28 @@ // logic: sampling

export { BooleanSocket, Debug, FlowSocket, Graph, GraphEvaluator, GraphRegistry, Node, NodeEvalContext, NodeSocketRef, NodeTypeRegistry, NumberSocket, Socket, StringSocket, ValueTypeRegistry, readGraphFromJSON, registerGenericNodes, validateDirectedAcyclicGraph, validateLinks, writeGraphToJSON, writeNodeSpecsToJSON };
function validateGraphRegistry(graphRegistry) {
const errorList = [];
graphRegistry.nodes.nodeTypeNameToNodeFactory.forEach((nodeFactory, nodeTypeName) => {
const node = nodeFactory();
// ensure node is registered correctly.
if (node.typeName !== nodeTypeName) {
errorList.push(`node with typeName '${node.typeName}' is registered under a different name '${nodeTypeName}'`);
}
node.inputSockets.forEach((socket) => {
const valueType = graphRegistry.values.valueTypeNameToValueType.get(socket.valueTypeName);
// check to ensure all value types are supported.
if (valueType === undefined) {
errorList.push(`node '${node.typeName}' has on input socket '${socket.name}' an unregistered value type ${socket.valueTypeName}'`);
}
});
node.outputSockets.forEach((socket) => {
const valueType = graphRegistry.values.valueTypeNameToValueType.get(socket.valueTypeName);
// check to ensure all value types are supported.
if (valueType === undefined) {
errorList.push(`node '${node.typeName}' has on output socket '${socket.name}' an unregistered value type ${socket.valueTypeName}'`);
}
});
});
return errorList;
}
export { BooleanSocket, Debug, FlowSocket, Graph, GraphEvaluator, GraphRegistry, Node, NodeEvalContext, NodeSocketRef, NodeTypeRegistry, NumberSocket, Socket, StringSocket, ValueType, ValueTypeRegistry, readGraphFromJSON, registerGenericNodes, validateDirectedAcyclicGraph, validateGraphRegistry, validateLinks, writeGraphToJSON, writeNodeSpecsToJSON };
{
"name": "behave-graph",
"version": "0.0.6",
"version": "0.0.7",
"description": "Simple, extensible behavior graph engine",

@@ -5,0 +5,0 @@ "type": "module",

@@ -0,1 +1,2 @@

/* eslint-disable space-in-parens */
import Debug from '../Debug';

@@ -78,2 +79,4 @@ import Node from '../Nodes/Node';

if (upstreamNode.isEvalNode) {
// eslint-disable-next-line no-param-reassign
inputSocket.value = upstreamOutputSocket.value;
return upstreamOutputSocket.value;

@@ -182,12 +185,17 @@ }

async executeAllAsync(timeLimit = 100, stepLimit: number = 100000000): Promise<number> {
const startDateTime = Date.now();
let stepsExecuted = 0;
let timeUsed = 0;
let elapsedTime = 0;
let iterations = 0;
do {
// eslint-disable-next-line no-await-in-loop
await sleep(0.5);
if ( iterations > 0 ) {
// eslint-disable-next-line no-await-in-loop
await sleep(0);
}
stepsExecuted += this.executeAll(stepLimit);
timeUsed += 0.01;
Debug.logVerbose(`this.asyncNodes.length: ${this.asyncNodes.length}`);
Debug.logVerbose(`this.flowWorkQueue.length: ${this.flowWorkQueue.length}`);
} while ((this.asyncNodes.length > 0 || this.flowWorkQueue.length > 0) && timeUsed < timeLimit && stepsExecuted < stepLimit);
elapsedTime = ( Date.now() - startDateTime ) * 0.001;
iterations += 1;
} while ((this.asyncNodes.length > 0 || this.flowWorkQueue.length > 0) && ( elapsedTime < timeLimit ) && stepsExecuted < stepLimit);

@@ -194,0 +202,0 @@ return stepsExecuted;

@@ -7,2 +7,3 @@ import NodeTypeRegistry from '../Nodes/NodeTypeRegistry';

public nodes = new NodeTypeRegistry();
}
};

@@ -8,2 +8,3 @@ export { default as Debug } from './Debug';

export { default as NodeSocketRef } from './Nodes/NodeSocketRef';
export { default as ValueType } from './Values/ValueType';
export { default as Socket } from './Sockets/Socket';

@@ -32,2 +33,3 @@ export { SocketFactory } from './Sockets/SocketFactory';

export { default as validateLinks } from './Graphs/Validation/validateLinks';
export { default as validateGraphRegistry } from './Graphs/Validation/validateGraphRegistry';

@@ -34,0 +36,0 @@ // types

@@ -65,3 +65,3 @@ import BooleanSocket from '../../Sockets/Typed/BooleanSocket';

registry.register('logic/numberE', () => new NullaryOp<number>('logic/numberSign', 'number', () => (Math.E)));
registry.register('logic/numberE', () => new NullaryOp<number>('logic/numberE', 'number', () => (Math.E)));
registry.register('logic/numberExp', () => new UnaryOp<number, number>('logic/numberExp', 'number', 'number', (a) => (Math.exp(a))));

@@ -74,3 +74,3 @@ registry.register('logic/numberLog', () => new UnaryOp<number, number>('logic/numberLog', 'number', 'number', (a) => (Math.log(a))));

registry.register('logic/numberPi', () => new NullaryOp<number>('logic/numberNegate', 'number', () => (Math.PI)));
registry.register('logic/numberPi', () => new NullaryOp<number>('logic/numberPi', 'number', () => (Math.PI)));
registry.register('logic/numberSin', () => new UnaryOp<number, number>('logic/numberSin', 'number', 'number', (a) => (Math.sin(a))));

@@ -91,3 +91,3 @@ registry.register('logic/numberAsin', () => new UnaryOp<number, number>('logic/numberAsin', 'number', 'number', (a) => (Math.asin(a))));

registry.register('logic/numberCeil', () => new UnaryOp<number, number>('logic/numberCeil', 'number', 'number', (a) => (Math.ceil(a))));
registry.register('logic/numberRound', () => new UnaryOp<number, number>('logic/numberCeil', 'number', 'number', (a) => (Math.round(a))));
registry.register('logic/numberRound', () => new UnaryOp<number, number>('logic/numberRound', 'number', 'number', (a) => (Math.round(a))));
registry.register('logic/numberTrunc', () => new UnaryOp<number, number>('logic/numberTrunc', 'number', 'number', (a) => (Math.trunc(a))));

@@ -94,0 +94,0 @@

@@ -8,2 +8,3 @@ import ValueType from './ValueType';

// register core types
this.register(new ValueType('flow', () => '', () => '', () => ''));
this.register(new ValueType('string', () => '', (text) => text, (value) => (value as string)));

@@ -10,0 +11,0 @@ this.register(new ValueType('boolean', () => false, (text) => (text === 'true'), (value) => ((value as boolean) ? 'true' : 'false')));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc