@contember/typesafe
Advanced tools
Comparing version 1.3.0-alpha.5 to 1.3.0-alpha.6
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.valueAt = exports.coalesce = exports.transform = exports.nullable = exports.false_ = exports.true_ = exports.null_ = exports.enumeration = exports.intersection = exports.discriminatedTupleUnion = exports.tuple = exports.discriminatedUnion = exports.partiallyDiscriminatedUnion = exports.union = exports.record = exports.noExtraProps = exports.partial = exports.object = exports.array = exports.literal = exports.anyJsonObject = exports.anyJson = exports.scalar = exports.boolean = exports.integer = exports.number = exports.string = exports.fail = exports.ParseError = void 0; | ||
const node_util_1 = require("node:util"); | ||
class ParseError extends Error { | ||
@@ -212,2 +211,13 @@ constructor(path, reason, expected) { | ||
exports.union = union; | ||
const isSamePath = (a, b) => { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
for (let i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
const partiallyDiscriminatedUnion = (field, ...inner) => { | ||
@@ -222,3 +232,3 @@ const type = (input, path = []) => { | ||
if (e instanceof ParseError) { | ||
if ((0, node_util_1.isDeepStrictEqual)(e.path, [...path, field])) { | ||
if (isSamePath(e.path, [...path, field])) { | ||
continue; | ||
@@ -225,0 +235,0 @@ } |
{ | ||
"name": "@contember/typesafe", | ||
"version": "1.3.0-alpha.5", | ||
"version": "1.3.0-alpha.6", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -1,3 +0,1 @@ | ||
import { isDeepStrictEqual } from 'node:util' | ||
type Unpacked<T> = T extends readonly (infer U)[] ? U : never | ||
@@ -245,2 +243,14 @@ | ||
const isSamePath = (a: PropertyKey[], b: PropertyKey[]) => { | ||
if (a.length !== b.length) { | ||
return false | ||
} | ||
for (let i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
export const partiallyDiscriminatedUnion = <T extends Type<JsonObject>[]>(field: string, ...inner: T): Type<ReturnType<Unpacked<T>>> => { | ||
@@ -254,3 +264,3 @@ const type = (input: unknown, path: PropertyKey[] = []): ReturnType<Unpacked<T>> => { | ||
if (e instanceof ParseError) { | ||
if (isDeepStrictEqual(e.path, [...path, field])) { | ||
if (isSamePath(e.path, [...path, field])) { | ||
continue | ||
@@ -257,0 +267,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
76419
791