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

indicative-compiler

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indicative-compiler - npm Package Compare versions

Comparing version 7.0.0 to 7.0.1

build/src/contracts.d.ts

8

build/index.d.ts

@@ -1,3 +0,5 @@

export { Schema, Messages } from 'indicative-parser';
export { validationCompiler } from './src/ValidationCompiler';
export { DataNode, ValidationExecutor, FormatterContract, DataRoot, Validation, Validations, TopLevelRunner, } from './src/Contracts/ValidationCompiler';
export { Compiler as ValidatorCompiler } from './src/Validator/Compiler';
export { Executor as ValidatorExecutor } from './src/Validator/Executor';
export { Compiler as SanitizerCompiler } from './src/Sanitizer/Compiler';
export { Executor as SanitizerExecutor } from './src/Sanitizer/Executor';
export { ValidationDefination, ValidateFunction, SanitizeFunction, SanitizationDefination, ErrorFormatterContract, } from './src/contracts';

@@ -1,1 +0,10 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["indicative.parser"]=t():e["indicative.parser"]=t()}(this,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t,r){"use strict";function n(e,t){return`${t} validation failed on ${e}`}Object.defineProperty(t,"__esModule",{value:!0}),t.dotProp=function(e,t,r){for(let n=0;n<r&&null!==(e=e[t[n]]||null);n++);return e},t.defaultMessage=n,t.reportError=function(e,t,r,n,o,a){let s="",i="";s=a.arrayPaths&&a.arrayIndexes?a.arrayPaths.map((e,t)=>e.concat([a.arrayIndexes[t]]).join(".")).concat(o).concat(t).join("."):o.concat(t).join("."),i="function"==typeof n?n(s,r.name,r.args):n,e.addError(i,s,r.name,r.args)},t.isObject=function(e){return e&&e.constructor===Object},t.isArray=function(e){return e&&Array.isArray(e)},t.getItemsForIndex=function(e,t){return"*"===t?e:e[t]?[e[t]]:[]},t.getMessageFromPath=function({fields:e,rules:t},r,o,a){const s="*"===r?a.join("."):a.concat([r]).join(".");let i=n;return e[s]&&e[s][o.name]?i=e[s][o.name]:t[o.name]&&(i=t[o.name]),i}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2);t.validationCompiler=n.validationCompiler},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(3),o=r(4),a=r(0),s=r(5),i=r(6),c=r(7),u=(e,t,r,[n,o],s,i)=>{const u=n[e.name];if(!u)throw new Error(`${e.name} is not registered as a validation`);"function"==typeof u.compile&&(e.args=u.compile(e.args));const l=a.getMessageFromPath(o,t,e,i.concat(s)),d=new c.ValidationRunner(u,t,e,l,r,s);return u.async?{async:!0,fn:d.execAsync.bind(d)}:{async:!1,fn:d.exec.bind(d)}},l=(e,t,r)=>{const n=new i.ArrayRunner(e,t,r);return e.find(e=>e.async)?{async:!0,fn:n.execAsync.bind(n)}:{async:!1,fn:n.exec.bind(n)}};t.validationCompiler=function(e,t,r){const a=n.rulesParser(e),i=n.messagesParser(r),c=o.astWalker(a,[t,i],u,l),d=new s.FinalRunner(c);return d.exec.bind(d)}},function(e,t,r){e.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(1);t.rulesParser=n.rulesParser,t.messagesParser=n.messagesParser},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(3);t.rulesParser=function(e){return Object.keys(e).reduce((t,r)=>{const a=e[r];let s=[];if(!a)throw new Error(`make sure to define rules for ${r}`);return s="string"==typeof a?new n(a,new o):a,function e(t,r,n,o=0){const a=t[o++],s=t.length===o,i=/^\d+$/.test(t[o]),c="*"===t[o]||i;return"*"===a||/^\d+$/.test(a)?s?void(n.each[a].rules=r):e(t,r,n.each[a].children,o):s?void function(e,t,r){const n=e[t]||{type:"literal"};n.rules=r,e[t]=n}(n,a,r):e(t,r,c?function(e,t,r){if(e[t]&&"object"===e[t].type)throw new Error(`cannot reshape ${t} object to an array`);const n=e[t]||{rules:[]};return n.each=n.each||{},n.each[r]=n.each[r]||{children:{},rules:[]},n.type="array",e[t]=n,n}(n,a,i?t[o]:"*"):function(e,t){if(e[t]&&"array"===e[t].type)throw new Error(`cannot reshape ${t} array to an object`);const r=e[t]||{rules:[]};return r.type="object",r.children=r.children||{},e[t]=r,r}(n,a).children,o)}(r.split("."),s,t),t},{})},t.messagesParser=function(e){return Object.keys(e).reduce((t,r)=>{const n=e[r],o=r.split("."),a=o.pop();if(!o.length)return t.rules={[a]:n},t;const s=o.join(".");return t.fields[s]=t.fields[s]||{},t.fields[s][a]=n,t},{fields:{},rules:{}})}},function(e,t,r){"use strict";e.exports=function(e,t){t.add();for(var r=e.length,n=0,o="name";n<r;){var a=e[n++],s=a.charCodeAt(0);58===s||44===s?(o="arg",t.shiftValue()):124===s?(o="name",t.add()):"arg"===o?t.appendValue(a):t.appendKey(a,s)}return t.toJSON()}},function(e,t,r){"use strict";e.exports=function(){return{nodes:[],currentNode:null,add:function(){this.currentNode={name:"",args:[]},this.nodes.push(this.currentNode)},appendKey:function(e,t){32!==t&&(this.currentNode.name+=e)},appendValue:function(e){this.currentNode.args[this.currentNode.args.length-1]+=e},shiftValue:function(){this.currentNode.args.push("")},toJSON:function(){return this.nodes}}}}])},function(e,t,r){"use strict";function n(e,t,r,o,a=[],s=[]){return Object.keys(e).reduce((i,c)=>{const u=e[c];return"literal"===u.type&&(i=i.concat(function(e,t,r,n,o,a){return e.rules.map(e=>n(e,t,"literal",r,o,a))}(u,c,t,r,a,s))),"object"===u.type&&(i=i.concat(function(e,t,r,o,a,s,i){let c=[];e.rules.length&&(c=e.rules.map(e=>o(e,t,"object",r,s,i))),s=s.concat(t);const u=n(e.children,r,o,a,s,i);return c=c.concat(u)}(u,c,t,r,o,a,s))),"array"===u.type&&(i=i.concat(function(e,t,r,o,a,s,i){let c=[];e.rules.length&&(c=e.rules.map(e=>o(e,t,"array",r,s,i))),s=s.concat(t);const u=Object.keys(e.each).reduce((t,c)=>{let u=[];e.each[c].rules.length&&(u=n({"arr:literal":{type:"literal",rules:e.each[c].rules}},r,o,a,[],i.concat(s).concat(c)));const l=n(e.each[c].children,r,o,a,[],i.concat(s).concat(c));return t.push(a(u.concat(l),s,c)),t},[]);return c=c.concat(u)}(u,c,t,r,o,a,s))),i},[])}Object.defineProperty(t,"__esModule",{value:!0}),t.astWalker=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.FinalRunner=class{constructor(e){this._stack=e}async exec(e,t,r,n=!0){const o={original:e};for(let a of this._stack){let s=!1;if(s=a.async?await a.fn(e,t,o,r,n):a.fn(e,t,o,r,n),n&&!s)break}const a=t.toJSON();if(a)throw a;return e}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(0);t.ArrayRunner=class{constructor(e,t,r){this._executors=e,this._dotPath=t,this._index=r,this._dotPathLength=this._dotPath.length}_getRoot(e,t){return{arrayPaths:(e.arrayPaths||[]).concat([this._dotPath]),arrayIndexes:e.arrayIndexes||[],original:e.original,parentArray:t}}_updateIndexes(e,t){return{original:e.original,arrayIndexes:e.arrayIndexes.concat([t]),parentArray:e.parentArray,arrayPaths:e.arrayPaths,currentIndex:t}}_runExecutors(e,t,r,n,o,a){let s=!0;for(let i of this._executors)if(i.fn(e,t,this._updateIndexes(r,n),o,a)||(s=!1),!s&&a)break;return s}async _runAsyncExecutors(e,t,r,n,o,a){let s=!0;for(let i of this._executors){let c=!1;if((c=i.async?await i.fn(e,t,this._updateIndexes(r,n),o,a):i.fn(e,t,this._updateIndexes(r,n),o,a))||(s=!1),!s&&a)break}return s}exec(e,t,r,o,a){const s=n.dotProp(e,this._dotPath,this._dotPathLength);if(!n.isArray(s))return!0;const i=n.getItemsForIndex(s,this._index);if(!i.length)return!0;const c=this._getRoot(r,s);let u=!1,l=0;for(let e of i){if(!(u=this._runExecutors(e,t,c,l,o,a))&&a)break;l++}return u}async execAsync(e,t,r,o,a){const s=n.dotProp(e,this._dotPath,this._dotPathLength);if(!n.isArray(s))return!0;const i=n.getItemsForIndex(s,this._index);if(!i.length)return!0;const c=this._getRoot(r,s);let u=!1,l=0;for(let e of i){if(!(u=await this._runAsyncExecutors(e,t,c,l,o,a))&&a)break;l++}return u}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(0);t.ValidationRunner=class{constructor(e,t,r,n,o,a){this._validation=e,this._field=t,this._rule=r,this._message=n,this._type=o,this._dotPath=a,this._dotPathLength=this._dotPath.length}_reportError(e,t,r){n.reportError(e,this._field,this._rule,r||this._message,this._dotPath,t)}_runValidation(e,t,r){let o=n.dotProp(e,this._dotPath,this._dotPathLength);return"arr:literal"===this._field&&(o={[this._field]:o}),!n.isObject(o)||this._validation.validate(o,this._field,this._rule.args,this._type,t,r)}exec(e,t,r,n){try{const o=this._runValidation(e,r,n);return o||this._reportError(t,r),!!o}catch(e){return this._reportError(t,r,e),!1}}async execAsync(e,t,r,n){try{const o=await this._runValidation(e,r,n);return o||this._reportError(t,r),!!o}catch(e){return this._reportError(t,r,e),!1}}}}])});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Compiler_1 = require("./src/Validator/Compiler");
exports.ValidatorCompiler = Compiler_1.Compiler;
var Executor_1 = require("./src/Validator/Executor");
exports.ValidatorExecutor = Executor_1.Executor;
var Compiler_2 = require("./src/Sanitizer/Compiler");
exports.SanitizerCompiler = Compiler_2.Compiler;
var Executor_2 = require("./src/Sanitizer/Executor");
exports.SanitizerExecutor = Executor_2.Executor;
# The MIT License
Copyright 2018 thetutlage, contributors
Copyright 2019 Harminder virk, contributors

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "indicative-compiler",
"version": "7.0.0",
"description": "Compiles parser tree into array of top level functions",
"version": "7.0.1",
"description": "Indicative compiler to compile parsed schema into highly optimized functions",
"main": "build/index.js",
"files": [
"build/src",
"build/index.js",
"build/index.d.ts"
"build/index.d.ts",
"build/index.js"
],
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "nyc node japaFile.js",
"test": "node japaFile.js",
"lint": "tslint --project tsconfig.json",
"clean": "del build",
"compile": "npm run lint && npm run clean && webpack",
"build": "npm run compile",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile && typedoc --theme markdown --mdHideSources --excludePrivate && git add docs",
"commit": "git-cz",
"release": "np",
"version": "npm run build"
},
"keywords": [
"parser",
"indicative"
],
"author": "virk",
"homepage": "https://indicative.adonisjs.com",
"repository": {
"type": "git",
"url": "git+https://github.com/poppinss/indicative/tree/master/packages/compiler.git"
"url": "git+ssh://git@github.com/poppinss/indicative-compiler.git"
},
"keywords": [
"indicative",
"compiler",
"ast"
],
"author": "virk,poppinss",
"license": "MIT",
"bugs": {
"url": "https://github.com/poppinss/indicative-compiler/issues"
},
"homepage": "https://github.com/poppinss/indicative-compiler#readme",
"devDependencies": {
"@adonisjs/mrm-preset": "^2.0.3",
"@types/node": "^12.0.12",
"clone-deep": "^4.0.1",
"commitizen": "^3.1.1",
"cz-conventional-changelog": "^2.1.0",
"del-cli": "^2.0.0",
"doctoc": "^1.4.0",
"husky": "^3.0.0",
"indicative-utils": "^7.0.1",
"japa": "^2.0.10",
"mrm": "^1.2.2",
"np": "^5.0.3",
"require-all": "^3.0.0",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"tslint-eslint-rules": "^5.4.0",
"typedoc": "^0.14.2",
"typedoc-plugin-external-module-name": "^2.1.0",
"typedoc-plugin-markdown": "^2.0.8",
"typescript": "^3.5.2"
},
"nyc": {

@@ -39,17 +68,28 @@ "exclude": [

},
"publishConfig": {
"access": "public",
"tag": "latest"
"husky": {
"hooks": {
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md",
"commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js"
}
},
"bugs": {
"url": "https://github.com/poppinss/indicative/issues"
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"devDependencies": {
"benchmark": "^2.1.4",
"pope": "^2.0.2"
"np": {
"contents": ".",
"anyBranch": false
},
"dependencies": {
"indicative-parser": "^7.0.0"
"indicative-parser": "^7.0.1",
"isobject": "^4.0.0",
"lodash.get": "^4.4.2",
"lodash.memoize": "^4.1.2",
"lodash.set": "^4.3.2"
},
"gitHead": "ec4b9e65401b74657beab116d08dfb8f8b109551"
"publishConfig": {
"access": "public",
"tag": "latest"
}
}

@@ -1,81 +0,78 @@

<p align="center">
<a href="#">
<img src="https://res.cloudinary.com/adonisjs/image/upload/v1553759989/indicative-banner_lh27zs.png" width="600px;" />
</a>
</p>
<div align="center">
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1557762307/poppinss_iftxlt.jpg" width="600px">
</div>
<p align="center">
<a href="https://indicative.adonisjs.com/quick-start">Usage</a> •
<a href="https://indicative.adonisjs.com/why">Why?</a> •
<a href="https://indicative.adonisjs.com/features">Features</a> •
<a href="https://indicative.adonisjs.com/examples">Examples</a> •
<a href="https://indicative.adonisjs.com/docs">Documentation</a>
</p>
# Indicative Compiler
[![circleci-image]][circleci-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
> Indicative compiler to compile validations schema into a highly optimized executable function.
<br/>
Indicative is a highly performant validation library for Node.js. It achieves this by compiling the schema into a tree and then an a top level executable function.
<p align="center">
<a href="https://travis-ci.org/poppinss/indicative">
<img src="https://img.shields.io/travis/poppinss/indicative.svg?style=flat-square" alt="">
</a>
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents
<a href="https://www.typescriptlang.org/">
<img src="https://img.shields.io/badge/uses-typescript-blue.svg?style=flat-square" alt="">
</a>
</p>
- [Usage](#usage)
- [API Docs](#api-docs)
- [Maintainers](#maintainers)
## Compiler
The compiler package takes the `parser` input and creates a highly performant function that can be cached to run validations with runtime data. Below are some [benchmarks](benchmarks/index.js) ran on the output function of compiler with dummy rules.
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
- **Macbook Pro (2.2 GHz Intel Core i7)**: `2,281,616 ops/sec`
## Usage
Install the package from npm
Install the package from npm registry as follows:
> You must use [indicative](https://github.com/poppinss/indicative) directly. This is a low level module meant to be used by indicative itself.
```sh
npm i indicative-compiler
# yarn user
# yarn
yarn add indicative-compiler
```
and then use it as follows
and then use it as follows:
```js
const { validationCompiler } = require('indicative-compiler')
```ts
import { ValidatorCompiler, ValidatorExecutor } from 'indicative-compiler'
import { VanillaFormatter } from 'indicative-formatters'
import * as validations from 'indicative-rules'
const rulesSchema = {
username: 'required'
const schema = {
username: 'required',
email: 'required|email'
}
const validations = {
required: {
async: false,
validate () {
return true
}
}
}
const messages = {}
const messagesSchema = {
'username.required': 'Username is required'
}
// Do it once for each schema
const compiledFunctions = new ValidatorCompiler(schema, messages).compile()
const validate = validationCompiler(rulesSchema, validations, messagesSchema)
await new ValidatorExecutor(compiledFunctions).exec(data, VanillaFormatter, {}, false, false)
```
The above code will output a **pre-compiled function**, that can be used to run validations using `runtime` data.
The `ValidatorExecutor.exec` function takes 5 parameters.
```js
const { vanilla } = require('indicative-formatters')
const config = {}
1. `data`: The runtime data to validate against the compiled schema.
2. `formatter`: Formatter constructor to collect and format error messages.
3. `config`: The config to be passed to all the validation functions.
4. `bail`: When `true`, it will stop after first error.
5. `removeAdditional`: When `true`, the `exec` will return only validated properties.
/**
* Bail true means stop on first validation error
*/
const bail = true
## API Docs
Following are the autogenerated files via Typedoc
validate(data, vanilla, config, bail)
.then(console.log)
.catch(console.error)
```
* [API](docs/README.md)
## Maintainers
[Harminder virk](https://github.com/thetutlage)
[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/indicative-compiler/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/indicative-compiler "circleci"
[npm-image]: https://img.shields.io/npm/v/indicative-compiler.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/indicative-compiler "npm"
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[license-url]: LICENSE.md
[license-image]: https://img.shields.io/aur/license/pac.svg?style=for-the-badge
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