Socket
Socket
Sign inDemoInstall

@arktype/attest

Package Overview
Dependencies
Maintainers
0
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arktype/attest - npm Package Compare versions

Comparing version 0.18.1 to 0.18.2

4

out/assert/assertions.d.ts

@@ -7,5 +7,5 @@ import type { TypeRelationshipAssertionData } from "../cache/writeAssertionCache.ts";

actual?: unknown;
ctx: AssertionContext;
stack: string;
};
export declare const throwAssertionError: ({ ctx, ...errorArgs }: ThrowAssertionErrorContext) => never;
export declare const throwAssertionError: ({ stack, ...errorArgs }: ThrowAssertionErrorContext) => never;
export type AssertFn = (expected: unknown, actual: unknown, ctx: AssertionContext) => void;

@@ -12,0 +12,0 @@ export type MappedTypeAssertionResult = {

import { printable, throwInternalError } from "@ark/util";
import { AssertionError } from "node:assert";
import * as assert from "node:assert/strict";
export const throwAssertionError = ({ ctx, ...errorArgs }) => {
export const throwAssertionError = ({ stack, ...errorArgs }) => {
const e = new assert.AssertionError(errorArgs);
e.stack = ctx.assertionStack;
e.stack = stack;
throw e;

@@ -31,4 +30,8 @@ };

}
if (errorMessage)
throw new AssertionError({ message: errorMessage });
if (errorMessage) {
throwAssertionError({
stack: ctx.assertionStack,
message: errorMessage
});
}
}

@@ -89,3 +92,3 @@ }

export const assertEqualOrMatching = versionableAssertion((expected, actual, ctx) => {
const assertionArgs = { actual, expected, ctx };
const assertionArgs = { actual, expected, stack: ctx.assertionStack };
if (typeof actual !== "string") {

@@ -118,4 +121,8 @@ throwAssertionError({

export const getThrownMessage = (result, ctx) => {
if (!("threw" in result))
throwAssertionError({ message: "Function didn't throw.", ctx });
if (!("threw" in result)) {
throwAssertionError({
message: "Function didn't throw",
stack: ctx.assertionStack
});
}
return result.threw;

@@ -122,0 +129,0 @@ };

@@ -38,4 +38,4 @@ import { caller, getCallStack } from "@ark/fs";

ctx.lastSnapCallPosition = calledFrom;
instantiationDataHandler({ ...ctx, kind: "instantiations" }, args, false);
instantiationDataHandler({ ...ctx, lastSnapFunctionName: "instantiations" }, args, false);
}
});

@@ -52,3 +52,3 @@ import { caller } from "@ark/fs";

throwAssertionError({
ctx: this.ctx,
stack: this.ctx.assertionStack,
message: `Expected an instance of ${expected.name} (was ${typeof this.ctx.actual === "object" && this.ctx.actual !== null ?

@@ -145,3 +145,8 @@ this.ctx.actual.constructor.name

this.ctx.actual = new TypeAssertionMapping(data => {
checkCompletionsForErrors(data.completions);
if (typeof data.completions === "string") {
// if the completions were ambiguously defined, e.g. two string
// literals with the same value, they are writen as an error
// message to the JSON. Throw it immediately.
throw new Error(data.completions);
}
return { actual: data.completions };

@@ -178,6 +183,2 @@ });

}
const checkCompletionsForErrors = (completions) => {
if (typeof completions === "string")
throw new Error(completions);
};
const declarationPrefix = "type T = ";

@@ -184,0 +185,0 @@ const formatTypeString = (typeString) => prettier

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

import { snapshot } from "@ark/util";
import { AssertionError } from "node:assert";
import { snapshot, throwInternalError } from "@ark/util";
import process from "node:process";
import { throwAssertionError } from "../assert/assertions.js";
import { queueSnapshotUpdate, writeSnapshotUpdatesOnExit } from "../cache/snapshots.js";

@@ -12,11 +12,14 @@ import { stringifyMeasure } from "./measure.js";

if (!ctx.lastSnapCallPosition) {
throw new Error(`Unable to update baseline for ${ctx.qualifiedName} ('lastSnapCallPosition' was unset).`);
throwInternalError(`Unable to update baseline for ${ctx.qualifiedName} ('lastSnapCallPosition' was unset)`);
}
if (!ctx.lastSnapFunctionName) {
throwInternalError(`Unable to update baseline for ${ctx.qualifiedName} ('lastSnapFunctionName' was unset)`);
}
queueSnapshotUpdate({
position: ctx.lastSnapCallPosition,
serializedValue,
snapFunctionName: ctx.kind,
snapFunctionName: ctx.lastSnapFunctionName,
baselinePath: ctx.qualifiedPath
});
if (ctx.kind === "types")
if (ctx.lastSnapFunctionName === "types")
writeSnapshotUpdatesOnExit();

@@ -46,4 +49,4 @@ };

const errorSummary = `❌ ${message}`;
if (ctx.kind === "instantiations")
throw new AssertionError({ message: errorSummary });
if (ctx.lastSnapFunctionName === "instantiations")
throwAssertionError({ stack: ctx.assertionStack, message: errorSummary });
else {

@@ -50,0 +53,0 @@ process.exitCode = 1;

@@ -55,6 +55,7 @@ import { type SourcePosition } from "@ark/fs";

cfg: ParsedAttestConfig;
assertionStack: string;
benchCallPosition: SourcePosition;
lastSnapCallPosition: SourcePosition | undefined;
lastSnapFunctionName: string | undefined;
isAsync: boolean;
kind: TimeAssertionName | "types" | "instantiations";
};

@@ -61,0 +62,0 @@ export type BenchableFunction = () => unknown | Promise<unknown>;

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

import { caller, rmRf } from "@ark/fs";
import { caller, getCallStack, rmRf } from "@ark/fs";
import { performance } from "node:perf_hooks";

@@ -141,3 +141,3 @@ import { ensureCacheDirs, getConfig } from "../config.js";

...this.ctx,
kind: name
lastSnapFunctionName: name
});

@@ -163,3 +163,3 @@ return this.getNextAssertions();

...this.ctx,
kind: "mark"
lastSnapFunctionName: "mark"
});

@@ -225,3 +225,5 @@ return this.getNextAssertions();

lastSnapCallPosition: undefined,
isAsync
lastSnapFunctionName: undefined,
isAsync,
assertionStack: getCallStack({ offset: 1 }).join("\n")
});
import { caller } from "@ark/fs";
import { throwInternalError } from "@ark/util";
import ts from "typescript";

@@ -12,3 +13,3 @@ import { getBenchAssertionsAtPosition } from "../cache/getCachedAssertions.js";

ctx.lastSnapCallPosition = caller();
instantiationDataHandler({ ...ctx, kind: "types" }, args[0]);
instantiationDataHandler({ ...ctx, lastSnapFunctionName: "types" }, args[0]);
}

@@ -27,3 +28,3 @@ });

if (!body)
throw new Error("Unable to retrieve contents of the call expression");
throwInternalError("Unable to retrieve contents of the call expression");
return getInstantiationsContributedByNode(file, body);

@@ -30,0 +31,0 @@ };

import { filePath, positionToString, readFile, readJson, shell, writeFile, writeJson } from "@ark/fs";
import { throwInternalError } from "@ark/util";
import { existsSync } from "node:fs";

@@ -42,3 +43,3 @@ import { basename, dirname, isAbsolute, join } from "node:path";

return startNode;
throw new Error(`Unable to locate expected inline ${functionName} call from assertion at ${positionToString(position)}.`);
throwInternalError(`Unable to locate expected inline ${functionName} call from assertion at ${positionToString(position)}.`);
};

@@ -45,0 +46,0 @@ export const updateExternalSnapshot = ({ serializedValue: value, position, name, customPath }) => {

import { fromCwd } from "@ark/fs";
import { throwInternalError } from "@ark/util";
import { printable, throwInternalError } from "@ark/util";
import * as tsvfs from "@typescript/vfs";

@@ -34,3 +34,3 @@ import { readFileSync } from "node:fs";

if (!file)
throw new Error(`Could not find ${path}.`);
throwInternalError(`Could not find TS path ${path}`);
return file;

@@ -42,3 +42,3 @@ }

if (!result) {
throw new Error(`Unable to find bounding call expression at position ${position} in ${node.getSourceFile().fileName}`);
throwInternalError(`Unable to find bounding call expression at position ${position} in ${node.getSourceFile().fileName}`);
}

@@ -57,3 +57,3 @@ return result;

if (!pos) {
throw new Error(`Absolute position was not able to be found in ${file.fileName}`);
throwInternalError(`Absolute position ${printable(position)} does not exist in ${file.fileName}`);
}

@@ -67,3 +67,3 @@ return pos;

if (!configFilePath) {
throw new Error(`File ${tsconfig ?? join(fromCwd(), "tsconfig.json")} must exist.`);
throw new Error(`File ${tsconfig ?? join(fromCwd(), "tsconfig.json")} must exist`);
}

@@ -70,0 +70,0 @@ const configFileText = readFileSync(configFilePath).toString();

import { filePath } from "@ark/fs";
import { throwInternalError } from "@ark/util";
import * as tsvfs from "@typescript/vfs";

@@ -36,4 +37,6 @@ import ts from "typescript";

const body = getDescendants(enclosingFunction.ancestor).find(node => ts.isArrowFunction(node) || ts.isFunctionExpression(node));
if (!body)
throw new Error("Unable to find file contents");
if (!body) {
throwInternalError(`Unable to resolve source associated with TS Node:
${enclosingFunction.ancestor.getText()}`);
}
return {

@@ -40,0 +43,0 @@ location: enclosingFunction.position,

{
"name": "@arktype/attest",
"version": "0.18.1",
"version": "0.18.2",
"author": {

@@ -38,5 +38,5 @@ "name": "David Blass",

"@prettier/sync": "0.5.2",
"@ark/util": "0.10.0",
"@ark/fs": "0.10.0",
"arktype": "2.0.0-rc.8"
"arktype": "2.0.0-rc.9",
"@ark/util": "0.11.0",
"@ark/fs": "0.11.0"
},

@@ -43,0 +43,0 @@ "devDependencies": {

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