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

3xpr

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3xpr - npm Package Compare versions

Comparing version 1.5.4 to 1.5.9

expression/operand/normalizer.d.ts

8

expression/contract/managers.d.ts

@@ -22,2 +22,4 @@ import { Type } from './type';

export interface IModelManager {
get operatorAlias(): [string, any][];
get functionAlias(): [string, any][];
get enums(): [string, [string, any][]][];

@@ -51,2 +53,8 @@ get formats(): [string, Format][];

}
export interface IOperandNormalizer {
normalize(operand: Operand): Operand;
}
export interface IOperandReducer {
reduce(operand: Operand): Operand;
}
export interface IEvaluatorFactory {

@@ -53,0 +61,0 @@ create(operand: Operand): IEvaluator | undefined;

2

expression/contract/operand.d.ts

@@ -55,3 +55,3 @@ import { Type, Context, Parameter, Position } from '.';

readonly pos: Position;
readonly name: any;
name: any;
readonly type: OperandType;

@@ -58,0 +58,0 @@ children: Operand[];

@@ -14,4 +14,6 @@ "use strict";

const typeManager = new operand_1.TypeManager(model);
const basic = new _1.OperandBuilder(model, new operand_1.EvaluatorFactory(model));
const process = new _1.OperandBuilder(model, new process_1.ProcessOperandFactory(model));
const normalizer = new operand_1.OperandNormalizer(model);
const reducer = new operand_1.OperandReducer(model);
const basic = new _1.OperandBuilder(model, normalizer, reducer, new operand_1.EvaluatorFactory(model));
const process = new _1.OperandBuilder(model, normalizer, reducer, new process_1.ProcessOperandFactory(model));
new operand_1.CoreLibrary(model).load();

@@ -18,0 +20,0 @@ return new Expressions(model, basic, process, typeManager);

@@ -1,11 +0,11 @@

import { Operand, IOperandBuilder, IModelManager, IEvaluatorFactory } from '../contract';
import { Operand, IOperandBuilder, IModelManager, IEvaluatorFactory, IOperandNormalizer, IOperandReducer } from '../contract';
export declare class OperandBuilder implements IOperandBuilder {
private readonly model;
private readonly factory;
constructor(model: IModelManager, factory: IEvaluatorFactory);
protected readonly model: IModelManager;
protected readonly normalizer: IOperandNormalizer;
protected readonly reducer: IOperandReducer;
protected readonly factory: IEvaluatorFactory;
constructor(model: IModelManager, normalizer: IOperandNormalizer, reducer: IOperandReducer, factory: IEvaluatorFactory);
build(expression: string): Operand;
clone(source: Operand): Operand;
private reduce;
private reduceOperand;
private complete;
protected complete(operand: Operand, index?: number, parentId?: string): void;
}

@@ -7,7 +7,8 @@ "use strict";

const parser_1 = require("./parser");
const factory_1 = require("./factory");
class OperandBuilder {
// eslint-disable-next-line no-useless-constructor
constructor(model, factory) {
constructor(model, normalizer, reducer, factory) {
this.model = model;
this.normalizer = normalizer;
this.reducer = reducer;
this.factory = factory;

@@ -17,4 +18,5 @@ }

const operand = new parser_1.Parser(this.model, expression).parse();
this.complete(operand);
return this.reduce(operand);
const normalized = this.normalizer.normalize(operand);
this.complete(normalized);
return this.reducer.reduce(normalized);
}

@@ -31,39 +33,2 @@ clone(source) {

}
reduce(operand) {
if (operand.type === contract_1.OperandType.Operator) {
return this.reduceOperand(operand);
}
else if (operand.type === contract_1.OperandType.CallFunc) {
// Example: .[0].states.filter() where function name is states.filter
const names = operand.name.split('.');
const funcName = names[names.length - 1];
const funcMetadata = this.model.getFunction(funcName);
if (funcMetadata && funcMetadata.deterministic) {
return this.reduceOperand(operand);
}
}
return operand;
}
reduceOperand(operand) {
let allConstants = true;
for (const child of operand.children) {
if (!(child.type === contract_1.OperandType.Const)) {
allConstants = false;
break;
}
}
if (allConstants) {
const value = operand.eval(new contract_1.Context());
const constant = new factory_1.ConstBuilder().build(operand.pos, value);
constant.id = operand.id;
return constant;
}
else {
for (let i = 0; i < operand.children.length; i++) {
const child = operand.children[i];
operand.children[i] = this.reduce(child);
}
}
return operand;
}
complete(operand, index = 0, parentId) {

@@ -70,0 +35,0 @@ const id = parentId ? parentId + '.' + index : index.toString();

@@ -638,2 +638,6 @@ "use strict";

}
else if (this.operand.children[2].type === contract_1.OperandType.Var && !Array.isArray(list)) {
// Example orders.0.number
return list;
}
// simple case without aggregate functions

@@ -640,0 +644,0 @@ const childContext = context.newContext();

@@ -10,1 +10,3 @@ export * from './evaluators';

export * from './parser';
export * from './reducer';
export * from './normalizer';

@@ -26,2 +26,4 @@ "use strict";

__exportStar(require("./parser"), exports);
__exportStar(require("./reducer"), exports);
__exportStar(require("./normalizer"), exports);
//# sourceMappingURL=index.js.map

@@ -8,3 +8,7 @@ import { OperatorMetadata, IModelManager, Format, OperatorAdditionalInfo, FunctionAdditionalInfo } from '../contract';

private _functions;
_operatorAlias: any;
_functionAlias: any;
constructor();
get operatorAlias(): [string, any][];
get functionAlias(): [string, any][];
get constants(): [string, any][];

@@ -11,0 +15,0 @@ get formats(): [string, Format][];

@@ -14,3 +14,11 @@ "use strict";

this._functions = {};
this._operatorAlias = {};
this._functionAlias = {};
}
get operatorAlias() {
return Object.entries(this._operatorAlias);
}
get functionAlias() {
return Object.entries(this._functionAlias);
}
get constants() {

@@ -32,6 +40,18 @@ return Object.entries(this._constants);

}
for (const entry of Object.entries(this._operatorAlias)) {
const key = entry[1];
for (const q of Object.values(this._operators[key])) {
operators.push([entry[0], q]);
}
}
return operators;
}
get functions() {
return Object.entries(this._functions);
let list = [];
list = Object.entries(this._functions);
for (const entry of Object.entries(this._functionAlias)) {
const key = entry[1];
list.push([entry[0], this._functions[key]]);
}
return list;
}

@@ -62,6 +82,6 @@ addEnum(name, values) {

addOperatorAlias(alias, reference) {
this._operators[alias] = this._operators[reference];
this._operatorAlias[alias] = reference;
}
addFunctionAlias(alias, reference) {
this._functions[alias] = this._functions[reference];
this._functionAlias[alias] = reference;
}

@@ -137,5 +157,11 @@ addOperator(sing, source, additionalInfo) {

getOperator(name, operands) {
const operators = this._operators[name];
let operators = this._operators[name];
if (operators === undefined) {
throw new Error(`operator: ${name} not found `);
const key = this._operatorAlias[name];
if (key) {
operators = this._operators[key];
}
else {
throw new Error(`operator: ${name} not found `);
}
}

@@ -158,5 +184,11 @@ if (operands !== undefined) {

getFunction(name) {
const metadata = this._functions[name];
let metadata = this._functions[name];
if (metadata === undefined) {
throw new Error(`function: ${name} not found `);
const key = this._functionAlias[name];
if (key) {
metadata = this._functions[key];
}
else {
throw new Error(`function: ${name} not found `);
}
}

@@ -173,10 +205,19 @@ return metadata;

isOperator(name, operands) {
const operators = this._operators[name];
let operators = this._operators[name];
if (operators === undefined) {
const key = this._operatorAlias[name];
if (key) {
operators = this._operators[key];
}
else {
return false;
}
}
if (operands !== undefined) {
return operators && operators[operands] !== undefined;
}
return operators !== undefined;
return true;
}
isFunction(name) {
return this._functions[name] !== undefined;
return this._functions[name] !== undefined || this._functionAlias[name] !== undefined;
}

@@ -183,0 +224,0 @@ priority(name, cardinality) {

{
"name": "3xpr",
"version": "1.5.4",
"version": "1.5.9",
"description": "expressions",

@@ -5,0 +5,0 @@ "author": "Flavio Lionel Rita <flaviolrita@hotmail.com>",

@@ -21,7 +21,7 @@ # 3xpr

, [array](https://github.com/FlavioLionelRita/3xpr/wiki/Array)
and [nullable](https://github.com/FlavioLionelRita/3xpr/wiki/Nullable) functions
- [Conversion](https://github.com/FlavioLionelRita/3xpr/wiki/Conversion) functions
- [Arrow](https://github.com/FlavioLionelRita/3xpr/wiki/Arrow) functions
- [Group](https://github.com/FlavioLionelRita/3xpr/wiki/Group) functions (distinct, first, last, min, max, sum and avg)
- [Sets](https://github.com/FlavioLionelRita/3xpr/wiki/Sets) functions (union, intersection, difference and symmetric difference)
and [nullable functions](https://github.com/FlavioLionelRita/3xpr/wiki/Nullable)
- [Conversion functions](https://github.com/FlavioLionelRita/3xpr/wiki/Conversion)
- [Arrow functions](https://github.com/FlavioLionelRita/3xpr/wiki/Arrow)
- [Group functions](https://github.com/FlavioLionelRita/3xpr/wiki/Group) (distinct, first, last, min, max, sum and avg)
- [Sets functions](https://github.com/FlavioLionelRita/3xpr/wiki/Sets) (union, intersection, difference and symmetric difference)
- [Control flows](https://github.com/FlavioLionelRita/3xpr/wiki/Flows) flows

@@ -28,0 +28,0 @@ - Environment variables

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

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