New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

actml

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

actml - npm Package Compare versions

Comparing version 0.9.0 to 0.10.0

lib/elements/A.js

54

lib/deburger.js

@@ -6,50 +6,16 @@ 'use strict';

});
var log = function log() {
var _console;
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var getIndent = function getIndent(level) {
return [].concat(_toConsumableArray(Array(level))).join(' ');
return (_console = console).log.apply(_console, arguments);
};
var DEFAULT_OPTIONS = {
log: function log() {
var _console;
return (_console = console).log.apply(_console, arguments);
},
severity: {
IN: true,
OUT: true,
EXECUTE_IN: false,
EXECUTE_OUT: false,
EXPORTS_IN: false,
EXPORTS_OUT: false,
RESULTS_IN: false,
RESULTS_OUT: false,
CHILDREN_IN: false,
CHILDREN_OUT: false
exports.default = function (element, type) {
if (type === 'IN') {
log('<' + element.name + '>');
} else if (type === 'OUT') {
log('</' + element.name + '>');
} else {
log('<' + element.name + '>(' + type + ')');
}
};
exports.default = function (customOptions) {
var options = Object.assign({}, DEFAULT_OPTIONS, customOptions);
var log = options.log;
return function (element, level) {
return function (type) {
var indent = getIndent(level);
if (options.severity[type]) {
if (type === 'IN') {
log(indent + '<' + element.name + '>');
element.props && log(indent + 'props:', element.props);
} else if (type === 'OUT') {
log(indent + '</' + element.name + '>');
element.result && log(indent + 'result:', element.result);
} else {
log(indent + '<' + element.name + '>(' + type + ')');
}
}
};
};
};

@@ -17,3 +17,7 @@ 'use strict';

function Element(func, props, children) {
var scopedVars = props && props.scope ? props.scope.split(/, ?/) : [];
var processor = void 0;
return {
__actml: true,
id: (0, _utils.getId)(),

@@ -23,10 +27,8 @@ func: func,

children: children,
scopedVars: (0, _utils.getScopedVars)(props),
name: (0, _utils.getFuncName)(func),
scope: {},
processor: undefined,
result: undefined,
context: undefined,
parent: undefined,
debug: undefined,
debug: false,

@@ -36,4 +38,7 @@ mergeToProps: function mergeToProps(additionalProps) {

},
mergeToScope: function mergeToScope(additionalProps) {
this.scope = Object.assign({}, this.scope, additionalProps);
},
dispatch: function dispatch(type, value) {
if (this.scopedVars.indexOf(type) >= 0 || this.scopedVars[0] === '*') {
if (scopedVars.indexOf(type) >= 0 || scopedVars[0] === '*') {
this.scope[type] = value;

@@ -59,37 +64,24 @@ } else {

this.context = parent.context;
this.debug = parent.debug;
if (!this.processor) {
this.processor = (0, _Processor2.default)(this, this.func.processor);
// setting the debug flag
if (this.props && typeof this.props.debug !== 'undefined') {
this.debug = true;
}
if (typeof func === 'string') {
if (this.context[func]) {
this.func = this.context[func];
} else {
throw new Error('"' + func + '" is missing in the context.');
if (!processor) {
processor = (0, _Processor2.default)(this, this.func.processor);
if (typeof func === 'string') {
if (this.context[func]) {
this.func = this.context[func];
} else {
throw new Error('"' + func + '" is missing in the context.');
}
}
}
return await this.processor();
return await processor();
}
};
}
// Static
Element.createRootElement = function (context) {
return {
context: context,
scope: {},
dispatch: function dispatch() {},
readFromScope: function readFromScope(key, requester) {
var value = this.scope[key];
if (typeof value !== 'undefined') return value;
value = this.context[key];
if (typeof value !== 'undefined') return value;
requester = requester === '' ? 'unknown' : requester;
throw new Error('Undefined variable "' + key + '" requested by <' + requester + '>.');
}
};
};
}

@@ -17,10 +17,18 @@ 'use strict';

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
async function Subscribe(_ref) {
var children = _ref.children,
type = _ref.type;
var exports = this.props.exports;
if (type) {
_Integration2.default.addListener(function (action) {
if (action.type === type) {
children(action);
if (exports && typeof exports === 'string') {
children(_defineProperty({}, exports, action));
} else {
children({ action: action });
}
}

@@ -27,0 +35,0 @@ });

@@ -17,10 +17,18 @@ 'use strict';

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function SubscribeOnce(_ref) {
var children = _ref.children,
type = _ref.type;
var exports = this.props.exports;
if (type) {
var removeListener = _Integration2.default.addListener(function (action) {
if (action.type === type) {
children(action);
if (exports && typeof exports === 'string') {
children(_defineProperty({}, exports, action));
} else {
children({ action: action });
}
removeListener();

@@ -27,0 +35,0 @@ }

@@ -18,6 +18,2 @@ 'use strict';

var _result = require('./middlewares/result');
var _result2 = _interopRequireDefault(_result);
var _children = require('./middlewares/children');

@@ -33,2 +29,10 @@

var _A = require('./elements/A');
var _A2 = _interopRequireDefault(_A);
var _createRootElement = require('./elements/createRootElement');
var _createRootElement2 = _interopRequireDefault(_createRootElement);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -43,12 +47,3 @@

// using A as a dymmy component
if (func === create) {
return (0, _Element2.default)(function A() {
return {
scope: this.scope,
context: this.context
};
}, _extends({}, props, { scope: '*' }), children);
}
return (0, _Element2.default)(func, props, children);
return func === create ? (0, _Element2.default)(_A2.default, _extends({}, props, { scope: '*' }), children) : (0, _Element2.default)(func, props, children);
}

@@ -59,16 +54,10 @@

var rootElement = _Element2.default.createRootElement(context);
if ((0, _utils.isItAnElement)(element)) {
if ((0, _utils.isItAnElement)(element.func)) {
element.func.mergeToProps(element.props);
return await element.func.run(rootElement);
}
return await element.run(rootElement);
return await element.run((0, _createRootElement2.default)(context));
}
return await create(element, null).run(rootElement);
throw new Error('`run` should be called with an ActML element. You are passing:', element);
}
var Redux = _extends({}, ReduxMethods);
var Processor = { execute: _execute2.default, result: _result2.default, children: _children2.default };
var Processor = { execute: _execute2.default, children: _children2.default };
var A = create;

@@ -75,0 +64,0 @@

@@ -7,32 +7,18 @@ 'use strict';

var _constants = require('../constants');
var _utils = require('../utils');
async function childrenMiddleware(element) {
var func = element.func,
children = element.children,
result = element.result;
exports.default = async function childrenMiddleware(element) {
var children = element.children;
// FACC pattern
if (children && children.length === 1 && !(0, _utils.isItAnElement)(children[0])) {
var resultOfFACC = await children[0].call(element, result);
if ((0, _utils.isItAnElement)(resultOfFACC)) {
await resultOfFACC.run(element);
}
// nested tags
} else if (children && children.length > 0) {
if (children && Array.isArray(children) && children.length > 0) {
var pointer = 0;
while (pointer < children.length) {
await children[pointer].run(element);
if ((0, _utils.isItAnElement)(children[pointer])) {
await children[pointer].run(element);
}
pointer++;
}
}
}
childrenMiddleware._name = 'CHILDREN';
exports.default = childrenMiddleware;
};

@@ -9,56 +9,114 @@ 'use strict';

var _constants = require('../constants');
var _utils = require('../utils');
var _children = require('./children');
var _ = require('../');
var _children2 = _interopRequireDefault(_children);
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var _exports = require('./exports');
function normalizeProps(element) {
var props = element.props,
name = element.name;
var _exports2 = _interopRequireDefault(_exports);
var normalizedProps = _extends({}, props);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (!props) return normalizedProps;
async function executeMiddleware(element) {
var func = element.func,
props = element.props,
name = element.name;
Object.keys(props).forEach(function (propName) {
if (propName.charAt(0) === '$') {
var prop = propName.substr(1, propName.length);
var value = element.readFromScope(prop, name);
var normalizedProps = _extends({}, props);
if (typeof value !== 'undefined') {
if (typeof props[propName] === 'string') {
normalizedProps[props[propName]] = value;
} else if (typeof props[propName] === 'function') {
normalizedProps = _extends({}, normalizedProps, props[propName](value));
} else {
normalizedProps[prop] = value;
}
delete normalizedProps[propName];
}
}
});
// normalizing props
if (props) {
normalizedProps = _extends({}, props);
Object.keys(props).forEach(function (propName) {
if (propName.charAt(0) === '$') {
var prop = propName.substr(1, propName.length);
var value = element.readFromScope(prop, name);
return normalizedProps;
}
function defineChildrenProp(element) {
var children = element.children;
if (typeof value !== 'undefined') {
if (typeof props[propName] === 'string') {
normalizedProps[props[propName]] = value;
} else if (typeof props[propName] === 'function') {
normalizedProps = _extends({}, normalizedProps, props[propName](value));
} else {
normalizedProps[prop] = value;
}
delete normalizedProps[propName];
// passing a `children` prop
if (children.length === 1 && !(0, _utils.isItAnElement)(children[0]) && typeof children[0] === 'function') {
// FACC
return function () {
var _children$;
for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) {
params[_key] = arguments[_key];
}
if (params.length === 0) params = [undefined];
return (0, _.A)((_children$ = children[0]).bind.apply(_children$, [null].concat(_toConsumableArray(params))), null).run(element);
};
} else if (children.find(_utils.isItAnElement)) {
// if an array of Elements pass a function
return async function (newProps) {
element.mergeToScope(newProps);
for (var i = 0; i < children.length; i++) {
await children[i].run(element);
}
};
}
return children.length === 1 ? children[0] : children;
}
async function processResult(element) {
var result = element.result;
if (result) {
// another ActML element
if ((0, _utils.isItAnElement)(result)) {
await result.run(element);
} else if (typeof result.next === 'function') {
// generator
var gen = result;
var genRes = { value: undefined, done: false };
while (!genRes.done) {
genRes = gen.next(genRes.value);
if ((0, _utils.isItAnElement)(genRes.value)) {
genRes.value = await genRes.value.run(element);
}
}
});
element.result = genRes.value;
}
}
}
function resolveExports(element) {
var props = element.props,
scope = element.scope;
// creating the `children` prop
normalizedProps.children = function (result) {
element.result = result;
(0, _exports2.default)(element);
(0, _children2.default)(element);
};
// actual running of the function
element.result = await func.call(element, normalizedProps);
if (props && props.exports) {
if (typeof props.exports === 'function') {
var exportedProps = props.exports(element.result);
Object.keys(exportedProps).forEach(function (key) {
scope[key] = exportedProps[key];
element.dispatch(key, exportedProps[key]);
});
} else {
scope[props.exports] = element.result;
element.dispatch(props.exports, element.result);
}
}
}
executeMiddleware._name = 'EXECUTE';
exports.default = executeMiddleware;
exports.default = async function executeMiddleware(element) {
element.result = await element.func.call(element, _extends({}, normalizeProps(element), {
children: defineChildrenProp(element)
}));
await processResult(element);
resolveExports(element);
};

@@ -6,9 +6,12 @@ 'use strict';

});
exports.default = Processor;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _execute = require('./middlewares/execute');
exports.default = Processor;
var _execute2 = _interopRequireDefault(_execute);
var _middlewares = require('./middlewares');
var _children = require('./middlewares/children');
var _children2 = _interopRequireDefault(_children);
var _deburger = require('./deburger');

@@ -18,19 +21,6 @@

var _utils = require('./utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var DEFAULT_MIDDLEWARES = [_middlewares.execute, _middlewares.exports, _middlewares.result, _middlewares.children];
var DEFAULT_MIDDLEWARES = [_execute2.default, _children2.default];
var setDebugger = function setDebugger(element, d, level) {
if ((0, _utils.isItAnElement)(element) && !element.debug) {
element.debug = d(element, level);
if (element.children && element.children.length > 0) {
element.children.forEach(function (e) {
return setDebugger(e, d, level + 1);
});
}
}
};
function Processor(element) {

@@ -43,44 +33,30 @@ var middlewares = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_MIDDLEWARES;

var props = element.props;
var debug = element.debug,
props = element.props;
// debugging
// running the middlewares
var debugMode = element.debug;
if (props && props.debug) {
var debug = props.debug;
return async function () {
debug && (0, _deburger2.default)(element, 'IN');
for (var index = 0; index < middlewares.length; index++) {
var entry = middlewares[index];
if (!entry) {
throw new Error('Falsy middleware at index ' + index + '!');
}
if (debug === true) {
debugMode = true;
setDebugger(element, (0, _deburger2.default)(), 1);
} else if (debug && (typeof debug === 'undefined' ? 'undefined' : _typeof(debug)) === 'object') {
debugMode = true;
setDebugger(element, (0, _deburger2.default)(debug), 1);
}
}
// running the middlewares
return async function () {
var entry = void 0;
var index = 0;
try {
debugMode && element.debug('IN');
while (entry = middlewares[index]) {
debugMode && element.debug(entry._name + '_IN');
try {
await entry(element);
index++;
debugMode && element.debug(entry._name + '_OUT');
} catch (error) {
if (props && props.onError) {
props.onError.mergeToProps({ error: error });
if (!(await props.onError.run(element))) {
index = middlewares.length + 1;
};
} else {
throw error;
}
}
debugMode && element.debug('OUT');
} catch (error) {
if (props && props.onError) {
props.onError.mergeToProps({ error: error });
if (!(await props.onError.run(element))) {
index = middlewares.length + 1;
};
} else {
throw error;
}
}
debug && (0, _deburger2.default)(element, 'OUT');

@@ -87,0 +63,0 @@ return element.result;

@@ -6,22 +6,9 @@ 'use strict';

});
var getFuncName = exports.getFuncName = function getFuncName(fun) {
if (typeof fun === 'string') return fun;
var ret = fun.toString();
ret = ret.substr('function '.length);
ret = ret.substr(0, ret.indexOf('('));
if (ret === '') return 'unknown';
return ret;
var getFuncName = exports.getFuncName = function getFuncName(func) {
var result = /function\*?\s+([\w\$]+)\s*\(/.exec(func.toString());
return result ? result[1] : '';
};
var getScopedVars = exports.getScopedVars = function getScopedVars(props) {
var scoped = [];
if (props && props.scope) {
scoped = props.scope.split(/, ?/);
}
return scoped;
};
var isItAnElement = exports.isItAnElement = function isItAnElement(element) {
return element && !!element.run;
return element && element.__actml;
};

@@ -28,0 +15,0 @@

{
"name": "actml",
"version": "0.9.0",
"version": "0.10.0",
"description": "Like jsx but for your business logic",

@@ -5,0 +5,0 @@ "main": "lib",

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