@autoplay/utils
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -8,6 +8,4 @@ export * from "./internal/invariant"; | ||
export * from "./internal/pipe"; | ||
export * from "./internal/E"; | ||
export * from "./internal/t"; | ||
export * from "./internal/z"; | ||
export * from "./internal/errorToString"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,6 +13,2 @@ "use strict"; | ||
tslib_1.__exportStar(require("./internal/pipe"), exports); | ||
// fp-ts/Either | ||
tslib_1.__exportStar(require("./internal/E"), exports); | ||
// io-ts for runtime parsing from input (I: unknown) to accepted (A) to output types (O) | ||
tslib_1.__exportStar(require("./internal/t"), exports); | ||
// zod for runtime parsing for type validators (accepted and output cannot be different types) | ||
@@ -19,0 +15,0 @@ // This also includes ZodChoice type |
import { DevString } from "./DevString"; | ||
import { t } from "./t"; | ||
import { z } from "./z"; | ||
@@ -28,8 +27,2 @@ declare type AllowedMessageTypes = DevString | string | number | object; | ||
message?: (() => AllowedMessageTypes) | AllowedMessageTypes, found?: any): void; | ||
/** Asserts that the `value` conforms to the `codec` type */ | ||
export declare function invariantT<T>(value: unknown, | ||
/** Pass a validation */ | ||
codec: t.Type<T>, | ||
/** Pass a message or function producing a message */ | ||
message?: AllowedMessageTypes): asserts value is T; | ||
/** | ||
@@ -36,0 +29,0 @@ * Enable exhaustive checking |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.invariantUnreachable = exports.invariantT = exports.invariantEq = exports.invariantChoiceIs = exports.invariantThrow = exports.invariant = void 0; | ||
exports.invariantUnreachable = exports.invariantEq = exports.invariantChoiceIs = exports.invariantThrow = exports.invariant = void 0; | ||
const devStringify_1 = require("./devStringify"); | ||
@@ -61,15 +61,2 @@ /** | ||
exports.invariantEq = invariantEq; | ||
function invariantT(value, | ||
/** Pass a validation */ | ||
codec, | ||
/** Pass a message or function producing a message */ | ||
message) { | ||
let decode = codec.decode(value); | ||
if (decode._tag === "Left") { | ||
console.error("Invariant failed to type check", message, "in", value, "with errors", ...decode.left); | ||
throw new InvariantError(`Invariant expected ${(0, devStringify_1.devStringify)(value)} is ${(0, devStringify_1.devStringify)(codec)}` + | ||
optionalMessageSuffix(message), value); | ||
} | ||
} | ||
exports.invariantT = invariantT; | ||
/** | ||
@@ -76,0 +63,0 @@ * Enable exhaustive checking |
{ | ||
"name": "@autoplay/utils", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "", | ||
@@ -24,4 +24,2 @@ "keywords": [], | ||
"peerDependencies": { | ||
"fp-ts": "^2.12.1", | ||
"io-ts": "^2.2.16", | ||
"tslib": "^2.4", | ||
@@ -31,7 +29,6 @@ "zod": "^3.17.3" | ||
"devDependencies": { | ||
"@jest/globals": "^28.1.3", | ||
"@swc/core": "^1.2.220", | ||
"@swc/jest": "^0.2.22", | ||
"@types/node": "^18.6.1", | ||
"fp-ts": "=2.12.1", | ||
"io-ts": "=2.2.16", | ||
"jest": "^28.1.3", | ||
@@ -42,2 +39,2 @@ "tslib": "^2.4", | ||
} | ||
} | ||
} |
@@ -10,6 +10,2 @@ // Invariant errors with stack trace fixing | ||
export * from "./internal/pipe"; | ||
// fp-ts/Either | ||
export * from "./internal/E"; | ||
// io-ts for runtime parsing from input (I: unknown) to accepted (A) to output types (O) | ||
export * from "./internal/t"; | ||
// zod for runtime parsing for type validators (accepted and output cannot be different types) | ||
@@ -16,0 +12,0 @@ // This also includes ZodChoice type |
import { DevString } from "./DevString"; | ||
import { devStringify } from "./devStringify"; | ||
import { t } from "./t"; | ||
import { z } from "./z"; | ||
@@ -83,4 +82,4 @@ | ||
)}` + | ||
optionalMessageSuffix(message) + | ||
(arguments.length > 3 ? `\nInstead found: ${devStringify(found)}` : ""), | ||
optionalMessageSuffix(message) + | ||
(arguments.length > 3 ? `\nInstead found: ${devStringify(found)}` : ""), | ||
found | ||
@@ -90,35 +89,2 @@ ); | ||
/** Asserts that the `value` conforms to the `codec` type */ | ||
export function invariantT<T>( | ||
value: unknown, | ||
/** Pass a validation */ | ||
codec: t.Type<T>, | ||
/** Pass a message or function producing a message */ | ||
message?: AllowedMessageTypes | ||
): asserts value is T; | ||
export function invariantT( | ||
value: any, | ||
/** Pass a validation */ | ||
codec: t.Type<any>, | ||
/** Pass a message or function producing a message */ | ||
message?: AllowedMessageTypes | ||
) { | ||
let decode = codec.decode(value); | ||
if (decode._tag === "Left") { | ||
console.error( | ||
"Invariant failed to type check", | ||
message, | ||
"in", | ||
value, | ||
"with errors", | ||
...decode.left | ||
); | ||
throw new InvariantError( | ||
`Invariant expected ${devStringify(value)} is ${devStringify(codec)}` + | ||
optionalMessageSuffix(message), | ||
value | ||
); | ||
} | ||
} | ||
/** | ||
@@ -146,3 +112,3 @@ * Enable exhaustive checking | ||
"invariantUnreachable encountered value which was supposed to be never" + | ||
optionalMessageSuffix(message), | ||
optionalMessageSuffix(message), | ||
x | ||
@@ -149,0 +115,0 @@ ); |
@@ -1,5 +0,6 @@ | ||
import {tightJsonStringify} from './tightJsonStringify' | ||
describe('tightJsonStringify', () => { | ||
it('matches a series of expectations', () => { | ||
expect(tightJsonStringify({a: 1, b: 2, c: {y: 4, z: 745}})) | ||
import { describe, expect, it } from "@jest/globals"; | ||
import { tightJsonStringify } from "./tightJsonStringify"; | ||
describe("tightJsonStringify", () => { | ||
it("matches a series of expectations", () => { | ||
expect(tightJsonStringify({ a: 1, b: 2, c: { y: 4, z: 745 } })) | ||
.toMatchInlineSnapshot(` | ||
@@ -11,8 +12,8 @@ "{ \\"a\\": 1, | ||
\\"z\\": 745 } }" | ||
`) | ||
expect(tightJsonStringify(true)).toMatchInlineSnapshot(`"true"`) | ||
expect(tightJsonStringify('Already a string')).toMatchInlineSnapshot( | ||
`"\\"Already a string\\""`, | ||
) | ||
expect(tightJsonStringify({a: 1, b: {c: [1, 2, {d: 4}], e: 8}})) | ||
`); | ||
expect(tightJsonStringify(true)).toMatchInlineSnapshot(`"true"`); | ||
expect(tightJsonStringify("Already a string")).toMatchInlineSnapshot( | ||
`"\\"Already a string\\""` | ||
); | ||
expect(tightJsonStringify({ a: 1, b: { c: [1, 2, { d: 4 }], e: 8 } })) | ||
.toMatchInlineSnapshot(` | ||
@@ -26,4 +27,4 @@ "{ \\"a\\": 1, | ||
\\"e\\": 8 } }" | ||
`) | ||
}) | ||
}) | ||
`); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2
8
76916
1593