@vinejs/compiler
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -1,62 +0,2 @@ | ||
import { RootNode, CompilerOptions, CompilerNodes, CompilerParent, CompilerField, Refs, MessagesProviderContact, ErrorReporterContract, RefsStore } from './src/types.js'; | ||
/** | ||
* Compiler buffer to collect JS fragments in memory | ||
*/ | ||
declare class CompilerBuffer { | ||
#private; | ||
/** | ||
* The character used to create a new line | ||
*/ | ||
newLine: string; | ||
/** | ||
* Write statement ot the output | ||
*/ | ||
writeStatement(statement: string): void; | ||
/** | ||
* Creates a child buffer | ||
*/ | ||
child(): CompilerBuffer; | ||
/** | ||
* Returns the buffer contents as string | ||
*/ | ||
toString(): string; | ||
/** | ||
* Flush in-memory string | ||
*/ | ||
flush(): void; | ||
} | ||
/** | ||
* Compiler is used to compile an array of schema nodes into a re-usable | ||
* JavaScript. | ||
*/ | ||
declare class Compiler { | ||
#private; | ||
/** | ||
* Variables counter is used to generate unique variable | ||
* names with a counter suffix. | ||
*/ | ||
variablesCounter: number; | ||
constructor(rootNode: RootNode, options?: CompilerOptions); | ||
/** | ||
* Converts a node to a field. Optionally accepts a parent node to create | ||
* a field for a specific parent type. | ||
*/ | ||
createFieldFor(node: CompilerNodes, parent: CompilerParent): CompilerField; | ||
/** | ||
* Compiles a given compiler node | ||
*/ | ||
compileNode(node: CompilerNodes, buffer: CompilerBuffer, parent: CompilerParent, parentField?: CompilerField): void; | ||
/** | ||
* Compile schema nodes to an async function | ||
*/ | ||
compile(): (data: any, meta: Record<string, any>, refs: Refs, messagesProvider: MessagesProviderContact, errorReporter: ErrorReporterContract) => Promise<Record<string, any>>; | ||
} | ||
/** | ||
* Creates a refs store for parsing the schema | ||
*/ | ||
declare function refsBuilder(): RefsStore; | ||
export { Compiler, refsBuilder }; | ||
export { Compiler } from './src/compiler/main.js'; | ||
export { refsBuilder } from './src/refs_builder.js'; |
@@ -1052,1 +1052,2 @@ // src/compiler/buffer.ts | ||
}; | ||
//# sourceMappingURL=index.js.map |
/** | ||
* Represenation of a ref id | ||
*/ | ||
type RefIdentifier = `ref://${number}`; | ||
export type RefIdentifier = `ref://${number}`; | ||
/** | ||
* Allowed values for refs | ||
*/ | ||
type Refs = Record<RefIdentifier, ValidationRule | TransformFn<any, any> | ParseFn | ConditionalFn<any>>; | ||
export type Refs = Record<RefIdentifier, ValidationRule | TransformFn<any, any> | ParseFn | ConditionalFn<any>>; | ||
/** | ||
@@ -13,3 +13,3 @@ * Refs store to track runtime values as refs with | ||
*/ | ||
type RefsStore = { | ||
export type RefsStore = { | ||
toJSON(): Refs; | ||
@@ -41,3 +41,3 @@ /** | ||
*/ | ||
type FieldContext = { | ||
export type FieldContext = { | ||
/** | ||
@@ -98,3 +98,3 @@ * Field value | ||
*/ | ||
type ValidationRule = { | ||
export type ValidationRule = { | ||
/** | ||
@@ -112,15 +112,15 @@ * Performs validation | ||
*/ | ||
type ParseFn = (value: unknown, ctx: Pick<FieldContext, 'data' | 'parent' | 'meta'>) => any; | ||
export type ParseFn = (value: unknown, ctx: Pick<FieldContext, 'data' | 'parent' | 'meta'>) => any; | ||
/** | ||
* The shape of transform function picked from the refs | ||
*/ | ||
type TransformFn<Input, Output> = (value: Input, field: FieldContext) => Output; | ||
export type TransformFn<Input, Output> = (value: Input, field: FieldContext) => Output; | ||
/** | ||
* The shape of conditional function used for narrowing down unions. | ||
*/ | ||
type ConditionalFn<Input> = (value: Input, field: FieldContext) => boolean; | ||
export type ConditionalFn<Input> = (value: Input, field: FieldContext) => boolean; | ||
/** | ||
* Shape of a validation rule accepted by the compiler | ||
*/ | ||
type ValidationNode = { | ||
export type ValidationNode = { | ||
/** | ||
@@ -143,3 +143,3 @@ * Rule implementation function id. | ||
*/ | ||
type FieldNode = { | ||
export type FieldNode = { | ||
/** | ||
@@ -184,3 +184,3 @@ * Should the validation cycle stop after the first error. | ||
*/ | ||
type LiteralNode = FieldNode & { | ||
export type LiteralNode = FieldNode & { | ||
type: 'literal'; | ||
@@ -197,3 +197,3 @@ /** | ||
*/ | ||
type ObjectNode = FieldNode & { | ||
export type ObjectNode = FieldNode & { | ||
type: 'object'; | ||
@@ -222,3 +222,3 @@ /** | ||
*/ | ||
type ObjectGroupNode = { | ||
export type ObjectGroupNode = { | ||
type: 'group'; | ||
@@ -259,3 +259,3 @@ /** | ||
*/ | ||
type TupleNode = FieldNode & { | ||
export type TupleNode = FieldNode & { | ||
type: 'tuple'; | ||
@@ -277,3 +277,3 @@ /** | ||
*/ | ||
type RecordNode = FieldNode & { | ||
export type RecordNode = FieldNode & { | ||
type: 'record'; | ||
@@ -288,3 +288,3 @@ /** | ||
*/ | ||
type ArrayNode = FieldNode & { | ||
export type ArrayNode = FieldNode & { | ||
type: 'array'; | ||
@@ -300,3 +300,3 @@ /** | ||
*/ | ||
type UnionNode = { | ||
export type UnionNode = { | ||
type: 'union'; | ||
@@ -335,3 +335,3 @@ /** | ||
*/ | ||
type RootNode = { | ||
export type RootNode = { | ||
type: 'root'; | ||
@@ -346,3 +346,3 @@ /** | ||
*/ | ||
type CompilerNodes = LiteralNode | ObjectNode | ArrayNode | UnionNode | RecordNode | TupleNode; | ||
export type CompilerNodes = LiteralNode | ObjectNode | ArrayNode | UnionNode | RecordNode | TupleNode; | ||
/** | ||
@@ -352,3 +352,3 @@ * Properties of a parent node as the compiler loops through the | ||
*/ | ||
type CompilerParent = { | ||
export type CompilerParent = { | ||
type: 'array' | 'object' | 'tuple' | 'record' | 'root'; | ||
@@ -378,3 +378,3 @@ /** | ||
*/ | ||
type CompilerField = { | ||
export type CompilerField = { | ||
parentValueExpression: string; | ||
@@ -393,3 +393,3 @@ fieldNameExpression: string; | ||
*/ | ||
interface ErrorReporterContract { | ||
export interface ErrorReporterContract { | ||
/** | ||
@@ -413,3 +413,3 @@ * A boolean to known if there are one or more | ||
*/ | ||
interface MessagesProviderContact { | ||
export interface MessagesProviderContact { | ||
/** | ||
@@ -424,3 +424,3 @@ * Returns a validation message for a given field + rule. The args | ||
*/ | ||
type CompilerOptions = { | ||
export type CompilerOptions = { | ||
/** | ||
@@ -441,3 +441,1 @@ * Convert empty string values to null for sake of | ||
}; | ||
export { ArrayNode, CompilerField, CompilerNodes, CompilerOptions, CompilerParent, ConditionalFn, ErrorReporterContract, FieldContext, FieldNode, LiteralNode, MessagesProviderContact, ObjectGroupNode, ObjectNode, ParseFn, RecordNode, RefIdentifier, Refs, RefsStore, RootNode, TransformFn, TupleNode, UnionNode, ValidationNode, ValidationRule }; |
{ | ||
"name": "@vinejs/compiler", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Low level compiler for VineJS validator", | ||
@@ -8,3 +8,8 @@ "type": "module", | ||
"files": [ | ||
"build" | ||
"build", | ||
"!build/benchmarks", | ||
"!build/bin", | ||
"!build/examples", | ||
"!build/factories", | ||
"!build/tests" | ||
], | ||
@@ -16,14 +21,16 @@ "exports": { | ||
"scripts": { | ||
"pretest": "npm run lint", | ||
"test": "c8 npm run quick:test", | ||
"quick:test": "node --loader=ts-node/esm bin/test.ts", | ||
"clean": "del-cli build", | ||
"typecheck": "tsc --noEmit", | ||
"precompile": "npm run lint && npm run clean", | ||
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration", | ||
"build": "npm run compile", | ||
"release": "np", | ||
"version": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"lint": "eslint . --ext=.ts", | ||
"format": "prettier --write .", | ||
"quick:test": "node --loader=ts-node/esm bin/test.ts", | ||
"pretest": "npm run lint", | ||
"test": "c8 npm run quick:test", | ||
"prebuild": "npm run lint && npm run clean", | ||
"build": "tsup-node", | ||
"release": "np", | ||
"version": "npm run build", | ||
"prepublishOnly": "npm run build" | ||
"sync-labels": "github-label-sync --labels .github/labels.json vinejs/compiler" | ||
}, | ||
@@ -35,3 +42,3 @@ "keywords": [ | ||
], | ||
"author": "virk", | ||
"author": "virk,vinejs", | ||
"license": "MIT", | ||
@@ -42,20 +49,21 @@ "devDependencies": { | ||
"@adonisjs/tsconfig": "^1.1.8", | ||
"@japa/assert": "^2.0.0-1", | ||
"@japa/runner": "^3.0.0-6", | ||
"@swc/core": "^1.3.71", | ||
"@types/node": "^20.4.5", | ||
"acorn": "^8.10.0", | ||
"@japa/assert": "^2.0.1", | ||
"@japa/runner": "^3.0.5", | ||
"@swc/core": "^1.3.96", | ||
"@types/node": "^20.9.2", | ||
"acorn": "^8.11.2", | ||
"ajv": "^8.12.0", | ||
"benchmark": "^2.1.4", | ||
"c8": "^8.0.1", | ||
"del-cli": "^5.0.0", | ||
"eslint": "^8.45.0", | ||
"js-beautify": "^1.14.9", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.54.0", | ||
"github-label-sync": "^2.3.1", | ||
"js-beautify": "^1.14.11", | ||
"np": "^8.0.3", | ||
"prettier": "^3.0.0", | ||
"tinybench": "^2.5.0", | ||
"prettier": "^3.1.0", | ||
"tinybench": "^2.5.1", | ||
"ts-node": "^10.9.1", | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6", | ||
"zod": "^3.21.4" | ||
"tsup": "^8.0.0", | ||
"typescript": "^5.2.2", | ||
"zod": "^3.22.4" | ||
}, | ||
@@ -106,5 +114,6 @@ "repository": { | ||
"format": "esm", | ||
"dts": true, | ||
"dts": false, | ||
"sourcemap": true, | ||
"target": "esnext" | ||
} | ||
} |
# @vinejs/compiler | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url] | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] | ||
@@ -11,3 +11,3 @@ The compiler is used to convert an array of schema nodes to a function with imperative JavaScript code that can be executed to validate a data object. The compiler operates at the low-level and does not offer any JavaScript API for creating the schema (see vinejs for user-land APIs). | ||
![](./vine_benchmarks.png) | ||
![](./vinejs_benchmarks.png) | ||
@@ -128,3 +128,1 @@ ## Schema | ||
[license-image]: https://img.shields.io/github/license/vinejs/compiler?style=for-the-badge | ||
[snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/vinejs/compiler?label=Snyk%20Vulnerabilities&style=for-the-badge | ||
[snyk-url]: https://snyk.io/test/github/vinejs/compiler?targetFile=package.json 'snyk' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
141176
43
1806
0
22
127