Comparing version 1.0.8-alpha to 1.0.9-alpha
@@ -83,3 +83,3 @@ "use strict"; | ||
if (discriminant.kind !== "domain") { | ||
return throwPruneFailure(discriminant); | ||
return throwInternalPruneFailure(discriminant); | ||
} | ||
@@ -98,4 +98,4 @@ entries.splice(i, 1); | ||
if (k === "domains") { | ||
if ((0, _genericsTs.keyCount)(v) !== 1 || !v.object) { | ||
return throwPruneFailure(discriminant); | ||
/* c8 ignore next */ if ((0, _genericsTs.keyCount)(v) !== 1 || !v.object) { | ||
return throwInternalPruneFailure(discriminant); | ||
} | ||
@@ -116,5 +116,5 @@ pruneDiscriminant(v.object, segments, discriminant, ctx); | ||
} | ||
return throwPruneFailure(discriminant); | ||
return throwInternalPruneFailure(discriminant); | ||
}; | ||
const throwPruneFailure = (discriminant)=>(0, _errorsTs.throwInternalError)(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`); | ||
const throwInternalPruneFailure = (discriminant)=>(0, _errorsTs.throwInternalError)(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`); | ||
const discriminantKinds = { | ||
@@ -249,4 +249,3 @@ domain: true, | ||
case "class": | ||
const constructorName = Object(definition).name; | ||
return constructorName && (0, _genericsTs.isKeyOf)(constructorName, _objectKindsTs.defaultObjectKinds) && _objectKindsTs.defaultObjectKinds[constructorName] === definition ? constructorName : undefined; | ||
return (0, _objectKindsTs.getExactConstructorObjectKind)(definition); | ||
default: | ||
@@ -253,0 +252,0 @@ return; |
@@ -54,3 +54,3 @@ "use strict"; | ||
} | ||
/* c8 ignore stop*/ } | ||
} | ||
return Object.fromEntries(Object.entries(keyNode).map(([domain, branches])=>[ | ||
@@ -57,0 +57,0 @@ domain, |
@@ -189,3 +189,6 @@ "use strict"; | ||
class: { | ||
mustBe: (expected)=>typeof expected === "string" ? _objectKindsTs.objectKindDescriptions[expected] : `an instance of ${expected.name}`, | ||
mustBe: (expected)=>{ | ||
const possibleObjectKind = (0, _objectKindsTs.getExactConstructorObjectKind)(expected); | ||
return possibleObjectKind ? _objectKindsTs.objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`; | ||
}, | ||
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.className) | ||
@@ -192,0 +195,0 @@ }, |
@@ -105,5 +105,2 @@ "use strict"; | ||
} | ||
getConfigKey(k) { | ||
return this.traversalConfig[k][0]; | ||
} | ||
traverseConfig(configEntries, node) { | ||
@@ -301,3 +298,3 @@ for (const entry of configEntries){ | ||
if (!Array.isArray(state.data)) { | ||
state.problems.add("class", "Array"); | ||
state.problems.add("class", Array); | ||
return false; | ||
@@ -323,4 +320,4 @@ } | ||
const missingCasePath = state.path.concat(rule.path); | ||
const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? (0, _problemsTs.domainsToDescriptions)(caseKeys) : rule.kind === "class" ? (0, _problemsTs.objectKindsToDescriptions)(caseKeys) : /* c8 ignore start*/ (0, _errorsTs.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`); | ||
/* c8 ignore stop*/ state.problems.add("cases", caseDescriptions, { | ||
const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? (0, _problemsTs.domainsToDescriptions)(caseKeys) : rule.kind === "class" ? (0, _problemsTs.objectKindsToDescriptions)(caseKeys) : (0, _errorsTs.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`); | ||
state.problems.add("cases", caseDescriptions, { | ||
path: missingCasePath, | ||
@@ -327,0 +324,0 @@ data: dataAtPath |
@@ -16,5 +16,7 @@ "use strict"; | ||
isArray: ()=>isArray, | ||
objectKindDescriptions: ()=>objectKindDescriptions | ||
objectKindDescriptions: ()=>objectKindDescriptions, | ||
getExactConstructorObjectKind: ()=>getExactConstructorObjectKind | ||
}); | ||
const _domainsTs = require("./domains.js"); | ||
const _genericsTs = require("./generics.js"); | ||
const defaultObjectKinds = { | ||
@@ -65,1 +67,5 @@ Array, | ||
}; | ||
const getExactConstructorObjectKind = (constructor)=>{ | ||
const constructorName = Object(constructor).name; | ||
return constructorName && (0, _genericsTs.isKeyOf)(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === constructor ? constructorName : undefined; | ||
}; |
@@ -5,3 +5,3 @@ import { writeUndiscriminatableMorphUnionMessage } from "../parse/ast/union.js"; | ||
import { isKeyOf, keyCount, objectKeysOf } from "../utils/generics.js"; | ||
import { defaultObjectKinds, isArray, objectKindOf } from "../utils/objectKinds.js"; | ||
import { getExactConstructorObjectKind, isArray, objectKindOf } from "../utils/objectKinds.js"; | ||
import { Path } from "../utils/paths.js"; | ||
@@ -69,3 +69,3 @@ import { serializePrimitive } from "../utils/serialize.js"; | ||
if (discriminant.kind !== "domain") { | ||
return throwPruneFailure(discriminant); | ||
return throwInternalPruneFailure(discriminant); | ||
} | ||
@@ -84,4 +84,4 @@ entries.splice(i, 1); | ||
if (k === "domains") { | ||
if (keyCount(v) !== 1 || !v.object) { | ||
return throwPruneFailure(discriminant); | ||
/* c8 ignore next */ if (keyCount(v) !== 1 || !v.object) { | ||
return throwInternalPruneFailure(discriminant); | ||
} | ||
@@ -102,5 +102,5 @@ pruneDiscriminant(v.object, segments, discriminant, ctx); | ||
} | ||
return throwPruneFailure(discriminant); | ||
return throwInternalPruneFailure(discriminant); | ||
}; | ||
const throwPruneFailure = (discriminant)=>throwInternalError(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`); | ||
const throwInternalPruneFailure = (discriminant)=>throwInternalError(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`); | ||
const discriminantKinds = { | ||
@@ -235,4 +235,3 @@ domain: true, | ||
case "class": | ||
const constructorName = Object(definition).name; | ||
return constructorName && isKeyOf(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === definition ? constructorName : undefined; | ||
return getExactConstructorObjectKind(definition); | ||
default: | ||
@@ -239,0 +238,0 @@ return; |
@@ -46,3 +46,3 @@ var _keyNode, _keyType, _keyNode1, _keyNode2; | ||
} | ||
/* c8 ignore stop*/ } | ||
} | ||
return Object.fromEntries(Object.entries(keyNode).map(([domain, branches])=>[ | ||
@@ -49,0 +49,0 @@ domain, |
@@ -46,3 +46,3 @@ function _checkPrivateRedeclaration(obj, privateCollection) { | ||
import { isWellFormedInteger } from "../utils/numericLiterals.js"; | ||
import { objectKindDescriptions } from "../utils/objectKinds.js"; | ||
import { getExactConstructorObjectKind, objectKindDescriptions } from "../utils/objectKinds.js"; | ||
import { Path } from "../utils/paths.js"; | ||
@@ -169,3 +169,6 @@ import { stringify } from "../utils/serialize.js"; | ||
class: { | ||
mustBe: (expected)=>typeof expected === "string" ? objectKindDescriptions[expected] : `an instance of ${expected.name}`, | ||
mustBe: (expected)=>{ | ||
const possibleObjectKind = getExactConstructorObjectKind(expected); | ||
return possibleObjectKind ? objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`; | ||
}, | ||
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.className) | ||
@@ -172,0 +175,0 @@ }, |
@@ -88,5 +88,2 @@ function _checkPrivateRedeclaration(obj, privateCollection) { | ||
} | ||
getConfigKey(k) { | ||
return this.traversalConfig[k][0]; | ||
} | ||
traverseConfig(configEntries, node) { | ||
@@ -284,3 +281,3 @@ for (const entry of configEntries){ | ||
if (!Array.isArray(state.data)) { | ||
state.problems.add("class", "Array"); | ||
state.problems.add("class", Array); | ||
return false; | ||
@@ -306,4 +303,4 @@ } | ||
const missingCasePath = state.path.concat(rule.path); | ||
const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? domainsToDescriptions(caseKeys) : rule.kind === "class" ? objectKindsToDescriptions(caseKeys) : /* c8 ignore start*/ throwInternalError(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`); | ||
/* c8 ignore stop*/ state.problems.add("cases", caseDescriptions, { | ||
const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? domainsToDescriptions(caseKeys) : rule.kind === "class" ? objectKindsToDescriptions(caseKeys) : throwInternalError(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`); | ||
state.problems.add("cases", caseDescriptions, { | ||
path: missingCasePath, | ||
@@ -310,0 +307,0 @@ data: dataAtPath |
import { domainOf } from "./domains.js"; | ||
import { isKeyOf } from "./generics.js"; | ||
// Built-in object constructors based on a subset of: | ||
@@ -49,1 +50,7 @@ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects | ||
}; | ||
// this will only return an object kind if it's the root constructor | ||
// example TypeError would return undefined not 'Error' | ||
export const getExactConstructorObjectKind = (constructor)=>{ | ||
const constructorName = Object(constructor).name; | ||
return constructorName && isKeyOf(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === constructor ? constructorName : undefined; | ||
}; |
@@ -9,6 +9,18 @@ import type { DisjointsByPath } from "../../nodes/compose.js"; | ||
[k in stringKeyOf<l>]: k extends keyof r ? inferIntersectionRecurse<l[k], r[k], [...path, k]> : l[k]; | ||
} & Omit<r, keyof l>>> : [l, r] extends [List<infer lItem>, List<infer rItem>] ? inferIntersectionRecurse<lItem, rItem, [ | ||
} & Omit<r, keyof l>>> : l extends List ? r extends List ? inferArrayIntersection<l, r, path> : l & r : l & r; | ||
type inferArrayIntersection<l extends List, r extends List, path extends string[]> = isTuple<l> extends true ? { | ||
[i in keyof l]: inferIntersectionRecurse<l[i], r[i & keyof r], [ | ||
...path, | ||
`${i}` | ||
]> extends infer result ? tryCatch<result, result> : never; | ||
} : isTuple<r> extends true ? { | ||
[i in keyof r]: inferIntersectionRecurse<l[i & keyof l], r[i], [ | ||
...path, | ||
`${i}` | ||
]> extends infer result ? tryCatch<result, result> : never; | ||
} : inferIntersectionRecurse<l[number], r[number], [ | ||
...path, | ||
MappedKeys["index"] | ||
]> extends infer result ? tryCatch<result, result[]> : never : l & r; | ||
]> extends infer result ? tryCatch<result, result[]> : never; | ||
type isTuple<list extends List> = number extends list["length"] ? false : true; | ||
type bubblePropErrors<o> = extractValues<o, error> extends never ? o : extractValues<o, error>; | ||
@@ -15,0 +27,0 @@ export declare const compileDisjointReasonsMessage: (disjoints: DisjointsByPath) => string; |
@@ -48,3 +48,3 @@ import type { FlatBound } from "../nodes/rules/range.js"; | ||
divisor: number; | ||
class: DefaultObjectKind | constructor; | ||
class: constructor; | ||
domain: Domain; | ||
@@ -51,0 +51,0 @@ missing: undefined; |
@@ -28,8 +28,2 @@ import type { ConfigEntry, TraversalEntry, TraversalKey, TraversalNode, TraversalValue } from "../nodes/node.js"; | ||
getProblemConfig<code extends ProblemCode>(code: code): ProblemWriters<code>; | ||
getConfigKey<k extends keyof TypeConfig>(k: k): { | ||
keys?: import("../scopes/type.js").KeyCheckKind; | ||
mustBe?: import("./problems.js").MustBeWriter<ProblemCode>; | ||
writeReason?: import("./problems.js").ReasonWriter<ProblemCode>; | ||
addContext?: import("./problems.js").ContextWriter; | ||
}[k] | undefined; | ||
traverseConfig(configEntries: ConfigEntry[], node: TraversalNode): boolean; | ||
@@ -36,0 +30,0 @@ traverseKey(key: stringKeyOf<this["data"]>, node: TraversalNode): boolean; |
@@ -83,2 +83,3 @@ import type { constructor, instanceOf, isTopType } from "./generics.js"; | ||
}; | ||
export declare const getExactConstructorObjectKind: (constructor: unknown) => DefaultObjectKind | undefined; | ||
export {}; |
{ | ||
"name": "arktype", | ||
"description": "The first isomorphic type system for TS/JS", | ||
"version": "1.0.8-alpha", | ||
"version": "1.0.9-alpha", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "David Blass", |
@@ -168,4 +168,17 @@ <h1 align="center">ArkType <sub><sup>Isomorphic types for TS/JS</sup></sub></h1> | ||
When you're ready, check out our [guide](./dev/configs/CONTRIBUTING.md) to get started! | ||
When you're ready, check out our [guide](./.github/CONTRIBUTING.md) to get started! | ||
## License | ||
This project is licensed under the terms of the | ||
[MIT license](./LICENSE). | ||
## Collaboration | ||
I'd love to hear about what you're working on and how ArkType can help. Please reach out to david@arktype.io. | ||
## Code of Conduct | ||
We will not tolerate any form of disrespect toward members of our community. Please refer to our [Code of Conduct](./.github/CODE_OF_CONDUCT.md) and reach out to david@arktype.io immediately if you've seen or experienced an interaction that may violate these standards. | ||
## Sponsorship | ||
@@ -175,13 +188,10 @@ | ||
If the project has been useful to you and you are in a financial position to do so, please feel free to chip in [via our Patreon](https://www.patreon.com/ArkType240). | ||
If the project has been useful to you and you are in a financial position to do so, please chip in via [GitHub Sponsors](https://github.com/sponsors/arktypeio). | ||
Otherwise, consider sending me an email (david@arktype.io) or [message me on Discord](https://discord.gg/WSNF3Kc4xh) to let me know you're a fan of ArkType. Either would make my day! π | ||
Otherwise, consider sending me an email (david@arktype.io) or [message me on Discord](https://discord.gg/WSNF3Kc4xh) to let me know you're a fan of ArkType. Either would make my day! | ||
## Collaboration | ||
### Current Sponsors π₯° | ||
I'd love to hear about what you're working on and how ArkType can help. Please reach out to david@arktype.io. | ||
[<img height="64px" src="https://avatars.githubusercontent.com/u/6759464">](https://github.com/tmm) | ||
## License | ||
This project is licensed under the terms of the | ||
[MIT license](./LICENSE). | ||
[tmm](https://github.com/tmm) |
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
469493
10170
196