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

pbt-properties

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pbt-properties - npm Package Compare versions

Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.72

2

lib/cjs/index.d.ts

@@ -1,4 +0,4 @@

export { PropertyFunction, PropertyCounterexample } from './runProperty';
export { PropertyFunction } from './runProperty';
export { property, Property } from './Property';
export { PropertyConfig } from './PropertyConfig';
export { PropertyResult } from './PropertyResult';

@@ -18,6 +18,6 @@ "use strict";

return PropertyResult_1.success();
case 'exhaustionFailure':
return PropertyResult_1.exhaustionFailure(config.iterations, runResult.iterationNumber - 1);
case 'predicateFailure':
return PropertyResult_1.predicateFailure(runResult.seed, runResult.size, config.iterations, runResult.iterationNumber, runResult.counterexample);
case 'exhaustion':
return PropertyResult_1.exhausted(config.iterations, runResult.iterationNumber - 1);
case 'failure':
return PropertyResult_1.failed(runResult.reason, runResult.seed, runResult.size, config.iterations, runResult.iterationNumber, runResult.counterexample);
case 'invalidShrinkPath':

@@ -24,0 +24,0 @@ return {

import { Seed, Size } from 'pbt-core';
import { PropertyCounterexample } from './runProperty';
export declare namespace PropertyResult {

@@ -7,5 +6,16 @@ type Success = {

};
type Counterexample<Values extends any[]> = {
originalValues: Values;
values: Values;
shrinkPath: number[];
};
type FailureReason = {
kind: 'predicate';
} | {
kind: 'throws';
error: unknown;
};
type Failure<Values extends any[]> = {
kind: 'failure';
reason: 'predicate';
reason: FailureReason;
seed: Seed;

@@ -15,3 +25,3 @@ size: Size;

iterationsCompleted: number;
counterexample: PropertyCounterexample<Values>;
counterexample: Counterexample<Values>;
};

@@ -32,4 +42,4 @@ type ValidationFailure = {

export declare type PropertyResult<Values extends any[]> = PropertyResult.Success | PropertyResult.ValidationFailure | PropertyResult.Failure<Values> | PropertyResult.Exhausted;
export declare const exhaustionFailure: (iterationsRequested: number, iterationsCompleted: number) => PropertyResult.Exhausted;
export declare const predicateFailure: <Values extends any[]>(seed: Seed, size: Size, iterationsRequested: number, iterationsCompleted: number, counterexample: PropertyCounterexample<Values>) => PropertyResult.Failure<Values>;
export declare const exhausted: (iterationsRequested: number, iterationsCompleted: number) => PropertyResult.Exhausted;
export declare const failed: <Values extends any[]>(reason: PropertyResult.FailureReason, seed: Seed, size: Size, iterationsRequested: number, iterationsCompleted: number, counterexample: PropertyResult.Counterexample<Values>) => PropertyResult.Failure<Values>;
export declare const success: () => PropertyResult.Success;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.success = exports.predicateFailure = exports.exhaustionFailure = void 0;
exports.exhaustionFailure = (iterationsRequested, iterationsCompleted) => ({
exports.success = exports.failed = exports.exhausted = void 0;
exports.exhausted = (iterationsRequested, iterationsCompleted) => ({
kind: 'exhaustion',

@@ -9,5 +9,5 @@ iterationsRequested,

});
exports.predicateFailure = (seed, size, iterationsRequested, iterationsCompleted, counterexample) => ({
exports.failed = (reason, seed, size, iterationsRequested, iterationsCompleted, counterexample) => ({
kind: 'failure',
reason: 'predicate',
reason,
seed,

@@ -14,0 +14,0 @@ size,

import { Gens, Seed, Size } from 'pbt-core';
import { PropertyConfig } from './PropertyConfig';
export declare type PropertyFunction<Values extends any[]> = (...args: Values) => boolean;
export declare type PropertyCounterexample<Values extends any[]> = {
originalValues: Values;
values: Values;
shrinkPath: number[];
};
declare type SuccessPropertyRunResult = {
kind: 'success';
};
declare type PredicateFailurePropertyRunResult<Values extends any[]> = {
kind: 'predicateFailure';
seed: Seed;
size: Size;
iterationNumber: number;
counterexample: PropertyCounterexample<Values>;
};
declare type ExhaustionFailurePropertyRunResult = {
kind: 'exhaustionFailure';
seed: Seed;
size: Size;
iterationNumber: number;
};
declare type InvalidShrinkPathPropertyRunResult = {
kind: 'invalidShrinkPath';
};
export declare type PropertyRunResult<Values extends any[]> = SuccessPropertyRunResult | PredicateFailurePropertyRunResult<Values> | ExhaustionFailurePropertyRunResult | InvalidShrinkPathPropertyRunResult;
import { PropertyResult } from './PropertyResult';
export declare type PropertyFunction<Values extends any[]> = (...args: Values) => boolean | void;
export declare namespace PropertyRunResult {
type Success = {
kind: 'success';
};
type Failure<Values extends any[]> = {
kind: 'failure';
reason: PropertyResult.FailureReason;
seed: Seed;
size: Size;
iterationNumber: number;
counterexample: PropertyResult.Counterexample<Values>;
};
type Exhaustion = {
kind: 'exhaustion';
seed: Seed;
size: Size;
iterationNumber: number;
};
type InvalidShrinkPath = {
kind: 'invalidShrinkPath';
};
}
export declare type PropertyRunResult<Values extends any[]> = PropertyRunResult.Success | PropertyRunResult.Failure<Values> | PropertyRunResult.Exhaustion | PropertyRunResult.InvalidShrinkPath;
declare const runProperty: <Values extends any[]>(gs: Gens<Values>, f: PropertyFunction<Values>, config: PropertyConfig) => PropertyRunResult<Values>;
export default runProperty;

@@ -38,40 +38,65 @@ "use strict";

const invokeGens = (gs, seed, size) => iterable_1.pipe(iterableOperators_1.zipSafe(...seedGens(gs, seed, size)), operators_1.map((genResults) => combineGenResults(genResults)));
const invokePropertyFunction = (f, values) => {
try {
return f(...values) === false ? { kind: 'predicate' } : null;
}
catch (error) {
return { kind: 'throws', error };
}
};
var Exploration;
(function (Exploration) {
const NOT_A_COUNTEREXAMPLE = Symbol();
const isCounterexample = (maybeCounterexample) => maybeCounterexample !== NOT_A_COUNTEREXAMPLE;
const tryFindCounterexample = (f, instanceData, originalInstanceData) => {
if (f(...instanceData.value)) {
return NOT_A_COUNTEREXAMPLE;
const isNotNull = (x) => x !== null;
const tryFindFailure = (f, instanceData, originalInstanceData) => {
const failureReason = invokePropertyFunction(f, instanceData.value);
if (!failureReason) {
return null;
}
const maybeIndexedSimplerCounterexample = iterable_1.first(iterable_1.pipe(instanceData.shrink(), iterableOperators_1.indexed(), iterableOperators_1.mapIndexed((childInstanceData) => tryFindCounterexample(f, childInstanceData, originalInstanceData)), iterableOperators_1.filterIndexed(isCounterexample)));
return maybeIndexedSimplerCounterexample
? {
shrinkPath: [...maybeIndexedSimplerCounterexample.value.shrinkPath, maybeIndexedSimplerCounterexample.index],
values: maybeIndexedSimplerCounterexample.value.values,
const smallerFailureAndIndex = iterable_1.first(iterable_1.pipe(instanceData.shrink(), iterableOperators_1.indexed(), iterableOperators_1.mapIndexed((childInstanceData) => tryFindFailure(f, childInstanceData, originalInstanceData)), iterableOperators_1.filterIndexed(isNotNull)));
if (!smallerFailureAndIndex) {
return [
{
values: instanceData.value,
originalValues: originalInstanceData.value,
shrinkPath: [],
},
failureReason,
];
}
const { index: smallerIndex, value: smallerFailure } = smallerFailureAndIndex;
const [smallerCounterexample, smallerReason] = smallerFailure;
return [
{
shrinkPath: [...smallerCounterexample.shrinkPath, smallerIndex],
values: smallerCounterexample.values,
originalValues: originalInstanceData.value,
},
smallerReason,
];
};
const mapGenResultToPropertyIterationResult = (f, genResult) => {
switch (genResult.kind) {
case 'instance': {
const failure = tryFindFailure(f, genResult, genResult);
if (!failure) {
return { kind: 'success' };
}
const [counterexample, reason] = failure;
return {
kind: 'failure',
counterexample,
reason,
};
}
: {
shrinkPath: [],
values: instanceData.value,
originalValues: originalInstanceData.value,
};
default:
return { kind: 'exhaustion' };
}
};
const runIteration = (gs, f, seed, size) => {
const statusAndCounterexample = iterable_1.first(iterable_1.pipe(invokeGens(gs, seed, size), operators_1.map((r) => {
if (r.kind === 'instance') {
const counterexample = tryFindCounterexample(f, r, r);
return counterexample === NOT_A_COUNTEREXAMPLE
? { kind: 'success' }
: { kind: 'predicateFailure', counterexample };
}
return {
kind: 'exhaustionFailure',
};
})));
const propertyIterationResult = iterable_1.first(iterable_1.pipe(invokeGens(gs, seed, size), operators_1.map((r) => mapGenResultToPropertyIterationResult(f, r))));
/* istanbul ignore next */
if (!statusAndCounterexample) {
if (!propertyIterationResult) {
throw new Error('Fatal: Failed to run iteration');
}
return statusAndCounterexample;
return propertyIterationResult;
};

@@ -87,5 +112,6 @@ const runIterations = function* (gs, f, initialSeed, initialSize) {

switch (iterationResult.kind) {
case 'predicateFailure':
case 'failure':
yield {
kind: 'predicateFailure',
kind: 'failure',
reason: iterationResult.reason,
counterexample: iterationResult.counterexample,

@@ -96,5 +122,5 @@ iterationNumber,

};
case 'exhaustionFailure':
case 'exhaustion':
yield {
kind: 'exhaustionFailure',
kind: 'exhaustion',
iterationNumber,

@@ -147,16 +173,18 @@ seed: currentSeed,

}
/* istanbul ignore next */
return f(...shrunkInstance.value)
? { kind: 'success' }
: {
kind: 'predicateFailure',
iterationNumber: 1,
seed: initialSeed,
size: initialSize,
counterexample: {
shrinkPath,
values: shrunkInstance.value,
originalValues: rootInstance.value,
},
};
const reason = invokePropertyFunction(f, shrunkInstance.value);
if (!reason) {
return { kind: 'success' };
}
return {
kind: 'failure',
reason,
iterationNumber: 1,
seed: initialSeed,
size: initialSize,
counterexample: {
shrinkPath,
values: shrunkInstance.value,
originalValues: rootInstance.value,
},
};
};

@@ -163,0 +191,0 @@ })(Reproduction || (Reproduction = {}));

@@ -1,4 +0,4 @@

export { PropertyFunction, PropertyCounterexample } from './runProperty';
export { PropertyFunction } from './runProperty';
export { property, Property } from './Property';
export { PropertyConfig } from './PropertyConfig';
export { PropertyResult } from './PropertyResult';

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

import { success, exhaustionFailure, predicateFailure } from './PropertyResult';
import { success, exhausted, failed } from './PropertyResult';
import { preValidateConfig } from './PropertyConfig';

@@ -15,6 +15,6 @@ import runProperty from './runProperty';

return success();
case 'exhaustionFailure':
return exhaustionFailure(config.iterations, runResult.iterationNumber - 1);
case 'predicateFailure':
return predicateFailure(runResult.seed, runResult.size, config.iterations, runResult.iterationNumber, runResult.counterexample);
case 'exhaustion':
return exhausted(config.iterations, runResult.iterationNumber - 1);
case 'failure':
return failed(runResult.reason, runResult.seed, runResult.size, config.iterations, runResult.iterationNumber, runResult.counterexample);
case 'invalidShrinkPath':

@@ -21,0 +21,0 @@ return {

import { Seed, Size } from 'pbt-core';
import { PropertyCounterexample } from './runProperty';
export declare namespace PropertyResult {

@@ -7,5 +6,16 @@ type Success = {

};
type Counterexample<Values extends any[]> = {
originalValues: Values;
values: Values;
shrinkPath: number[];
};
type FailureReason = {
kind: 'predicate';
} | {
kind: 'throws';
error: unknown;
};
type Failure<Values extends any[]> = {
kind: 'failure';
reason: 'predicate';
reason: FailureReason;
seed: Seed;

@@ -15,3 +25,3 @@ size: Size;

iterationsCompleted: number;
counterexample: PropertyCounterexample<Values>;
counterexample: Counterexample<Values>;
};

@@ -32,4 +42,4 @@ type ValidationFailure = {

export declare type PropertyResult<Values extends any[]> = PropertyResult.Success | PropertyResult.ValidationFailure | PropertyResult.Failure<Values> | PropertyResult.Exhausted;
export declare const exhaustionFailure: (iterationsRequested: number, iterationsCompleted: number) => PropertyResult.Exhausted;
export declare const predicateFailure: <Values extends any[]>(seed: Seed, size: Size, iterationsRequested: number, iterationsCompleted: number, counterexample: PropertyCounterexample<Values>) => PropertyResult.Failure<Values>;
export declare const exhausted: (iterationsRequested: number, iterationsCompleted: number) => PropertyResult.Exhausted;
export declare const failed: <Values extends any[]>(reason: PropertyResult.FailureReason, seed: Seed, size: Size, iterationsRequested: number, iterationsCompleted: number, counterexample: PropertyResult.Counterexample<Values>) => PropertyResult.Failure<Values>;
export declare const success: () => PropertyResult.Success;

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

export const exhaustionFailure = (iterationsRequested, iterationsCompleted) => ({
export const exhausted = (iterationsRequested, iterationsCompleted) => ({
kind: 'exhaustion',

@@ -6,5 +6,5 @@ iterationsRequested,

});
export const predicateFailure = (seed, size, iterationsRequested, iterationsCompleted, counterexample) => ({
export const failed = (reason, seed, size, iterationsRequested, iterationsCompleted, counterexample) => ({
kind: 'failure',
reason: 'predicate',
reason,
seed,

@@ -11,0 +11,0 @@ size,

import { Gens, Seed, Size } from 'pbt-core';
import { PropertyConfig } from './PropertyConfig';
export declare type PropertyFunction<Values extends any[]> = (...args: Values) => boolean;
export declare type PropertyCounterexample<Values extends any[]> = {
originalValues: Values;
values: Values;
shrinkPath: number[];
};
declare type SuccessPropertyRunResult = {
kind: 'success';
};
declare type PredicateFailurePropertyRunResult<Values extends any[]> = {
kind: 'predicateFailure';
seed: Seed;
size: Size;
iterationNumber: number;
counterexample: PropertyCounterexample<Values>;
};
declare type ExhaustionFailurePropertyRunResult = {
kind: 'exhaustionFailure';
seed: Seed;
size: Size;
iterationNumber: number;
};
declare type InvalidShrinkPathPropertyRunResult = {
kind: 'invalidShrinkPath';
};
export declare type PropertyRunResult<Values extends any[]> = SuccessPropertyRunResult | PredicateFailurePropertyRunResult<Values> | ExhaustionFailurePropertyRunResult | InvalidShrinkPathPropertyRunResult;
import { PropertyResult } from './PropertyResult';
export declare type PropertyFunction<Values extends any[]> = (...args: Values) => boolean | void;
export declare namespace PropertyRunResult {
type Success = {
kind: 'success';
};
type Failure<Values extends any[]> = {
kind: 'failure';
reason: PropertyResult.FailureReason;
seed: Seed;
size: Size;
iterationNumber: number;
counterexample: PropertyResult.Counterexample<Values>;
};
type Exhaustion = {
kind: 'exhaustion';
seed: Seed;
size: Size;
iterationNumber: number;
};
type InvalidShrinkPath = {
kind: 'invalidShrinkPath';
};
}
export declare type PropertyRunResult<Values extends any[]> = PropertyRunResult.Success | PropertyRunResult.Failure<Values> | PropertyRunResult.Exhaustion | PropertyRunResult.InvalidShrinkPath;
declare const runProperty: <Values extends any[]>(gs: Gens<Values>, f: PropertyFunction<Values>, config: PropertyConfig) => PropertyRunResult<Values>;
export default runProperty;

@@ -36,40 +36,65 @@ import { GenResult, GenInstance } from 'pbt-core';

const invokeGens = (gs, seed, size) => pipe(zipSafe(...seedGens(gs, seed, size)), map((genResults) => combineGenResults(genResults)));
const invokePropertyFunction = (f, values) => {
try {
return f(...values) === false ? { kind: 'predicate' } : null;
}
catch (error) {
return { kind: 'throws', error };
}
};
var Exploration;
(function (Exploration) {
const NOT_A_COUNTEREXAMPLE = Symbol();
const isCounterexample = (maybeCounterexample) => maybeCounterexample !== NOT_A_COUNTEREXAMPLE;
const tryFindCounterexample = (f, instanceData, originalInstanceData) => {
if (f(...instanceData.value)) {
return NOT_A_COUNTEREXAMPLE;
const isNotNull = (x) => x !== null;
const tryFindFailure = (f, instanceData, originalInstanceData) => {
const failureReason = invokePropertyFunction(f, instanceData.value);
if (!failureReason) {
return null;
}
const maybeIndexedSimplerCounterexample = first(pipe(instanceData.shrink(), indexed(), mapIndexed((childInstanceData) => tryFindCounterexample(f, childInstanceData, originalInstanceData)), filterIndexed(isCounterexample)));
return maybeIndexedSimplerCounterexample
? {
shrinkPath: [...maybeIndexedSimplerCounterexample.value.shrinkPath, maybeIndexedSimplerCounterexample.index],
values: maybeIndexedSimplerCounterexample.value.values,
const smallerFailureAndIndex = first(pipe(instanceData.shrink(), indexed(), mapIndexed((childInstanceData) => tryFindFailure(f, childInstanceData, originalInstanceData)), filterIndexed(isNotNull)));
if (!smallerFailureAndIndex) {
return [
{
values: instanceData.value,
originalValues: originalInstanceData.value,
shrinkPath: [],
},
failureReason,
];
}
const { index: smallerIndex, value: smallerFailure } = smallerFailureAndIndex;
const [smallerCounterexample, smallerReason] = smallerFailure;
return [
{
shrinkPath: [...smallerCounterexample.shrinkPath, smallerIndex],
values: smallerCounterexample.values,
originalValues: originalInstanceData.value,
},
smallerReason,
];
};
const mapGenResultToPropertyIterationResult = (f, genResult) => {
switch (genResult.kind) {
case 'instance': {
const failure = tryFindFailure(f, genResult, genResult);
if (!failure) {
return { kind: 'success' };
}
const [counterexample, reason] = failure;
return {
kind: 'failure',
counterexample,
reason,
};
}
: {
shrinkPath: [],
values: instanceData.value,
originalValues: originalInstanceData.value,
};
default:
return { kind: 'exhaustion' };
}
};
const runIteration = (gs, f, seed, size) => {
const statusAndCounterexample = first(pipe(invokeGens(gs, seed, size), map((r) => {
if (r.kind === 'instance') {
const counterexample = tryFindCounterexample(f, r, r);
return counterexample === NOT_A_COUNTEREXAMPLE
? { kind: 'success' }
: { kind: 'predicateFailure', counterexample };
}
return {
kind: 'exhaustionFailure',
};
})));
const propertyIterationResult = first(pipe(invokeGens(gs, seed, size), map((r) => mapGenResultToPropertyIterationResult(f, r))));
/* istanbul ignore next */
if (!statusAndCounterexample) {
if (!propertyIterationResult) {
throw new Error('Fatal: Failed to run iteration');
}
return statusAndCounterexample;
return propertyIterationResult;
};

@@ -85,5 +110,6 @@ const runIterations = function* (gs, f, initialSeed, initialSize) {

switch (iterationResult.kind) {
case 'predicateFailure':
case 'failure':
yield {
kind: 'predicateFailure',
kind: 'failure',
reason: iterationResult.reason,
counterexample: iterationResult.counterexample,

@@ -94,5 +120,5 @@ iterationNumber,

};
case 'exhaustionFailure':
case 'exhaustion':
yield {
kind: 'exhaustionFailure',
kind: 'exhaustion',
iterationNumber,

@@ -145,16 +171,18 @@ seed: currentSeed,

}
/* istanbul ignore next */
return f(...shrunkInstance.value)
? { kind: 'success' }
: {
kind: 'predicateFailure',
iterationNumber: 1,
seed: initialSeed,
size: initialSize,
counterexample: {
shrinkPath,
values: shrunkInstance.value,
originalValues: rootInstance.value,
},
};
const reason = invokePropertyFunction(f, shrunkInstance.value);
if (!reason) {
return { kind: 'success' };
}
return {
kind: 'failure',
reason,
iterationNumber: 1,
seed: initialSeed,
size: initialSize,
counterexample: {
shrinkPath,
values: shrunkInstance.value,
originalValues: rootInstance.value,
},
};
};

@@ -161,0 +189,0 @@ })(Reproduction || (Reproduction = {}));

{
"name": "pbt-properties",
"version": "0.0.1-alpha.0+77d4587",
"version": "0.0.1-alpha.72+9f013f8",
"license": "MIT",

@@ -18,3 +18,3 @@ "repository": {

"ix": "^4.0.0",
"pbt-core": "^0.0.1-alpha.0+77d4587"
"pbt-core": "^0.0.1-alpha.72+9f013f8"
},

@@ -26,3 +26,3 @@ "devDependencies": {

"jest": "^26.4.1",
"pbt-gen": "^0.0.1-alpha.0+77d4587",
"pbt-gen": "^0.0.1-alpha.72+9f013f8",
"rimraf": "^3.0.2",

@@ -42,3 +42,3 @@ "ts-jest": "^26.2.0",

},
"gitHead": "77d4587327a065429c0e849fac421b79833592e0"
"gitHead": "9f013f88f9883eabc3a5f64f63cc81bf98df87ca"
}
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