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

arktype

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arktype - npm Package Compare versions

Comparing version 1.0.10-alpha to 1.0.11-alpha

50

dist/cjs/main.js

@@ -12,26 +12,28 @@ "use strict";

_export(exports, {
scope: ()=>_scopeTs.scope,
type: ()=>_arkTs.type,
ark: ()=>_arkTs.ark,
arkScope: ()=>_arkTs.arkScope,
intersection: ()=>_expressionsTs.intersection,
union: ()=>_expressionsTs.union,
arrayOf: ()=>_expressionsTs.arrayOf,
instanceOf: ()=>_expressionsTs.instanceOf,
valueOf: ()=>_expressionsTs.valueOf,
morph: ()=>_expressionsTs.morph,
narrow: ()=>_expressionsTs.narrow,
keyOf: ()=>_expressionsTs.keyOf,
jsObjectsScope: ()=>_jsObjectsTs.jsObjectsScope,
tsKeywordsScope: ()=>_tsKeywordsTs.tsKeywordsScope,
validationScope: ()=>_validationTs.validationScope,
Problems: ()=>_problemsTs.Problems,
Problem: ()=>_problemsTs.Problem
scope: ()=>_scopeJs.scope,
type: ()=>_arkJs.type,
ark: ()=>_arkJs.ark,
arkScope: ()=>_arkJs.arkScope,
arrayOf: ()=>_expressionsJs.arrayOf,
instanceOf: ()=>_expressionsJs.instanceOf,
intersection: ()=>_expressionsJs.intersection,
keyOf: ()=>_expressionsJs.keyOf,
morph: ()=>_expressionsJs.morph,
narrow: ()=>_expressionsJs.narrow,
union: ()=>_expressionsJs.union,
valueOf: ()=>_expressionsJs.valueOf,
jsObjectsScope: ()=>_jsObjectsJs.jsObjectsScope,
tsKeywordsScope: ()=>_tsKeywordsJs.tsKeywordsScope,
validationScope: ()=>_validationJs.validationScope,
Problems: ()=>_problemsJs.Problems,
Problem: ()=>_problemsJs.Problem,
parseConfigTuple: ()=>_configJs.parseConfigTuple
});
const _scopeTs = require("./scopes/scope.js");
const _arkTs = require("./scopes/ark.js");
const _expressionsTs = require("./scopes/expressions.js");
const _jsObjectsTs = require("./scopes/jsObjects.js");
const _tsKeywordsTs = require("./scopes/tsKeywords.js");
const _validationTs = require("./scopes/validation/validation.js");
const _problemsTs = require("./traverse/problems.js");
const _scopeJs = require("./scopes/scope.js");
const _arkJs = require("./scopes/ark.js");
const _expressionsJs = require("./scopes/expressions.js");
const _jsObjectsJs = require("./scopes/jsObjects.js");
const _tsKeywordsJs = require("./scopes/tsKeywords.js");
const _validationJs = require("./scopes/validation/validation.js");
const _problemsJs = require("./traverse/problems.js");
const _configJs = require("./parse/ast/config.js");

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

});
const _intersectionTs = require("../parse/ast/intersection.js");
const _domainsTs = require("../utils/domains.js");
const _errorsTs = require("../utils/errors.js");
const _composeTs = require("./compose.js");
const _rulesTs = require("./rules/rules.js");
const _intersectionJs = require("../parse/ast/intersection.js");
const _domainsJs = require("../utils/domains.js");
const _errorsJs = require("../utils/errors.js");
const _composeJs = require("./compose.js");
const _rulesJs = require("./rules/rules.js");
const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;

@@ -46,3 +46,3 @@ const compareBranches = (lConditions, rConditions, state)=>{

const subresult = branchIntersection(l, r, state);
if ((0, _composeTs.isDisjoint)(subresult)) {
if ((0, _composeJs.isDisjoint)(subresult)) {
// doesn't tell us about any redundancies or add a distinct pair

@@ -64,3 +64,3 @@ return null;

return null;
} else if ((0, _composeTs.isEquality)(subresult)) {
} else if ((0, _composeJs.isEquality)(subresult)) {
// Combination of l and r subtype cases.

@@ -74,3 +74,3 @@ result.equalities.push([

return null;
} else if ((0, _domainsTs.hasDomain)(subresult, "object")) {
} else if ((0, _domainsJs.hasDomain)(subresult, "object")) {
// Neither branch is a subtype of the other, return

@@ -81,3 +81,3 @@ // the result of the intersection as a candidate

}
return (0, _errorsTs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsTs.domainOf)(subresult)}'`);
return (0, _errorsJs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsJs.domainOf)(subresult)}'`);
});

@@ -98,3 +98,3 @@ if (!lImpliesR) {

if (isTransformationBranch(branch)) {
const result = (0, _rulesTs.flattenRules)(branch.rules, ctx);
const result = (0, _rulesJs.flattenRules)(branch.rules, ctx);
if (branch.morph) {

@@ -117,3 +117,3 @@ if (typeof branch.morph === "function") {

}
return (0, _rulesTs.flattenRules)(branch, ctx);
return (0, _rulesJs.flattenRules)(branch, ctx);
};

@@ -124,7 +124,7 @@ const rulesOf = (branch)=>branch.rules ?? branch;

const rRules = rulesOf(r);
const rulesResult = (0, _rulesTs.rulesIntersection)(lRules, rRules, state);
const rulesResult = (0, _rulesJs.rulesIntersection)(lRules, rRules, state);
if ("morph" in l) {
if ("morph" in r) {
if (l.morph === r.morph) {
return (0, _composeTs.isEquality)(rulesResult) || (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
return (0, _composeJs.isEquality)(rulesResult) || (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
rules: rulesResult,

@@ -134,6 +134,6 @@ morph: l.morph

}
return state.lastOperator === "&" ? (0, _errorsTs.throwParseError)((0, _intersectionTs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
return state.lastOperator === "&" ? (0, _errorsJs.throwParseError)((0, _intersectionJs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
}
return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
rules: (0, _composeTs.isEquality)(rulesResult) ? l.rules : rulesResult,
return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
rules: (0, _composeJs.isEquality)(rulesResult) ? l.rules : rulesResult,
morph: l.morph

@@ -143,4 +143,4 @@ };

if ("morph" in r) {
return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
rules: (0, _composeTs.isEquality)(rulesResult) ? r.rules : rulesResult,
return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
rules: (0, _composeJs.isEquality)(rulesResult) ? r.rules : rulesResult,
morph: r.morph

@@ -147,0 +147,0 @@ };

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

});
const _errorsTs = require("../utils/errors.js");
const _genericsTs = require("../utils/generics.js");
const _pathsTs = require("../utils/paths.js");
const _serializeTs = require("../utils/serialize.js");
const _errorsJs = require("../utils/errors.js");
const _genericsJs = require("../utils/generics.js");
const _pathsJs = require("../utils/paths.js");
const _serializeJs = require("../utils/serialize.js");
function _checkPrivateRedeclaration(obj, privateCollection) {

@@ -68,3 +68,16 @@ if (privateCollection.has(obj)) {

}
const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r === undefined ? (0, _errorsTs.throwInternalError)(undefinedOperandsMessage) : r : r === undefined ? l : reducer(l, r, state);
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r === undefined ? (0, _errorsJs.throwInternalError)(undefinedOperandsMessage) : r : r === undefined ? l : reducer(l, r, state);
const undefinedOperandsMessage = `Unexpected operation two undefined operands`;

@@ -76,6 +89,6 @@ const disjointDescriptionWriters = {

tupleLength: ({ l , r })=>`tuples of length ${l} and ${r}`,
value: ({ l , r })=>`literal values ${(0, _serializeTs.stringify)(l)} and ${(0, _serializeTs.stringify)(r)}`,
leftAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.stringify)(l.value)} and ${(0, _serializeTs.stringify)(r)}`,
rightAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.stringify)(r.value)} and ${(0, _serializeTs.stringify)(l)}`,
union: ({ l , r })=>`branches ${(0, _serializeTs.stringify)(l)} and branches ${(0, _serializeTs.stringify)(r)}`
value: ({ l , r })=>`literal values ${(0, _serializeJs.stringify)(l)} and ${(0, _serializeJs.stringify)(r)}`,
leftAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(l.value)} and ${(0, _serializeJs.stringify)(r)}`,
rightAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(r.value)} and ${(0, _serializeJs.stringify)(l)}`,
union: ({ l , r })=>`branches ${(0, _serializeJs.stringify)(l)} and branches ${(0, _serializeJs.stringify)(r)}`
};

@@ -97,2 +110,6 @@ const stringifyRange = (range)=>"limit" in range ? `the range of exactly ${range.limit}` : range.min ? range.max ? `the range bounded by ${range.min.comparator}${range.min.limit} and ${range.max.comparator}${range.max.limit}` : `${range.min.comparator}${range.min.limit}` : range.max ? `${range.max.comparator}${range.max.limit}` : "the unbounded range";

constructor(type, lastOperator){
_defineProperty(this, "type", void 0);
_defineProperty(this, "lastOperator", void 0);
_defineProperty(this, "path", void 0);
_defineProperty(this, "domain", void 0);
_classPrivateFieldInit(this, _disjoints, {

@@ -104,3 +121,3 @@ writable: true,

this.lastOperator = lastOperator;
this.path = new _pathsTs.Path();
this.path = new _pathsJs.Path();
_classPrivateFieldSet(this, _disjoints, {});

@@ -117,3 +134,3 @@ }

const result = {};
const keys = (0, _genericsTs.objectKeysOf)({
const keys = (0, _genericsJs.objectKeysOf)({
...l,

@@ -120,0 +137,0 @@ ...r

@@ -16,12 +16,12 @@ "use strict";

});
const _unionTs = require("../parse/ast/union.js");
const _domainsTs = require("../utils/domains.js");
const _errorsTs = require("../utils/errors.js");
const _genericsTs = require("../utils/generics.js");
const _objectKindsTs = require("../utils/objectKinds.js");
const _pathsTs = require("../utils/paths.js");
const _serializeTs = require("../utils/serialize.js");
const _branchTs = require("./branch.js");
const _composeTs = require("./compose.js");
const _propsTs = require("./rules/props.js");
const _unionJs = require("../parse/ast/union.js");
const _domainsJs = require("../utils/domains.js");
const _errorsJs = require("../utils/errors.js");
const _genericsJs = require("../utils/generics.js");
const _objectKindsJs = require("../utils/objectKinds.js");
const _pathsJs = require("../utils/paths.js");
const _serializeJs = require("../utils/serialize.js");
const _branchJs = require("./branch.js");
const _composeJs = require("./compose.js");
const _propsJs = require("./rules/props.js");
const flattenBranches = (branches, ctx)=>{

@@ -34,3 +34,3 @@ const discriminants = calculateDiscriminants(branches, ctx);

if (remainingIndices.length === 1) {
return (0, _branchTs.flattenBranch)(originalBranches[remainingIndices[0]], ctx);
return (0, _branchJs.flattenBranch)(originalBranches[remainingIndices[0]], ctx);
}

@@ -42,3 +42,3 @@ const bestDiscriminant = findBestDiscriminant(remainingIndices, discriminants);

"branches",
remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.scope) ? (0, _errorsTs.throwParseError)((0, _unionTs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchTs.flattenBranch)(originalBranches[i], ctx))
remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.scope) ? (0, _errorsJs.throwParseError)((0, _unionJs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchJs.flattenBranch)(originalBranches[i], ctx))
]

@@ -100,3 +100,3 @@ ];

if (k === "domains") {
/* c8 ignore next */ if ((0, _genericsTs.keyCount)(v) !== 1 || !v.object) {
/* c8 ignore next */ if ((0, _genericsJs.keyCount)(v) !== 1 || !v.object) {
return throwInternalPruneFailure(discriminant);

@@ -120,3 +120,3 @@ }

};
const throwInternalPruneFailure = (discriminant)=>(0, _errorsTs.throwInternalError)(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`);
const throwInternalPruneFailure = (discriminant)=>(0, _errorsJs.throwInternalError)(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`);
const discriminantKinds = {

@@ -137,10 +137,10 @@ domain: true,

discriminants.disjointsByPair[pairKey] = pairDisjoints;
const intersectionState = new _composeTs.IntersectionState(ctx.type, "|");
(0, _branchTs.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
const intersectionState = new _composeJs.IntersectionState(ctx.type, "|");
(0, _branchJs.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
for(const path in intersectionState.disjoints){
if (path.includes(_propsTs.mappedKeys.index)) {
if (path.includes(_propsJs.mappedKeys.index)) {
continue;
}
const { l , r , kind } = intersectionState.disjoints[path];
if (!(0, _genericsTs.isKeyOf)(kind, discriminantKinds)) {
if (!(0, _genericsJs.isKeyOf)(kind, discriminantKinds)) {
continue;

@@ -189,3 +189,3 @@ }

const parseQualifiedDisjoint = (qualifiedDisjoint)=>{
const path = _pathsTs.Path.fromString(qualifiedDisjoint);
const path = _pathsJs.Path.fromString(qualifiedDisjoint);
return [

@@ -224,3 +224,3 @@ path,

}
const defaultCaseKeys = (0, _genericsTs.objectKeysOf)(defaultCases);
const defaultCaseKeys = (0, _genericsJs.objectKeysOf)(defaultCases);
if (defaultCaseKeys.length) {

@@ -254,3 +254,3 @@ filteredCases["default"] = defaultCaseKeys.map((k)=>parseInt(k));

case "class":
return (0, _objectKindsTs.getExactConstructorObjectKind)(definition);
return (0, _objectKindsJs.getExactConstructorObjectKind)(definition);
default:

@@ -261,12 +261,12 @@ return;

const serializeIfPrimitive = (data)=>{
const domain = (0, _domainsTs.domainOf)(data);
return domain === "object" || domain === "symbol" ? undefined : (0, _serializeTs.serializePrimitive)(data);
const domain = (0, _domainsJs.domainOf)(data);
return domain === "object" || domain === "symbol" ? undefined : (0, _serializeJs.serializePrimitive)(data);
};
const serializeData = {
value: (data)=>serializeIfPrimitive(data) ?? "default",
class: (data)=>(0, _objectKindsTs.objectKindOf)(data) ?? "default",
domain: _domainsTs.domainOf
class: (data)=>(0, _objectKindsJs.objectKindOf)(data) ?? "default",
domain: _domainsJs.domainOf
};
const serializeCase = (kind, data)=>serializeData[kind](data);
const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsTs.propToNode)(prop), $)) : false;
const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).includesMorph : Object.values($.resolveTypeNode(node)).some((predicate)=>predicate === true ? false : (0, _objectKindsTs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsJs.propToNode)(prop), $)) : false;
const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).includesMorph : Object.values($.resolveTypeNode(node)).some((predicate)=>predicate === true ? false : (0, _objectKindsJs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));

@@ -23,9 +23,9 @@ "use strict";

});
const _intersectionTs = require("../parse/ast/intersection.js");
const _errorsTs = require("../utils/errors.js");
const _genericsTs = require("../utils/generics.js");
const _pathsTs = require("../utils/paths.js");
const _composeTs = require("./compose.js");
const _predicateTs = require("./predicate.js");
const _propsTs = require("./rules/props.js");
const _intersectionJs = require("../parse/ast/intersection.js");
const _errorsJs = require("../utils/errors.js");
const _genericsJs = require("../utils/generics.js");
const _pathsJs = require("../utils/paths.js");
const _composeJs = require("./compose.js");
const _predicateJs = require("./predicate.js");
const _propsJs = require("./rules/props.js");
const isConfigNode = (node)=>"config" in node;

@@ -37,10 +37,10 @@ const nodeIntersection = (l, r, state)=>{

const result = typeNodeIntersection(lDomains, rDomains, state);
if (typeof result === "object" && !(0, _genericsTs.hasKeys)(result)) {
return (0, _genericsTs.hasKeys)(state.disjoints) ? (0, _composeTs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsTs.objectKeysOf)(lDomains), (0, _genericsTs.objectKeysOf)(rDomains));
if (typeof result === "object" && !(0, _genericsJs.hasKeys)(result)) {
return (0, _genericsJs.hasKeys)(state.disjoints) ? (0, _composeJs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsJs.objectKeysOf)(lDomains), (0, _genericsJs.objectKeysOf)(rDomains));
}
return result === lDomains ? l : result === rDomains ? r : result;
};
const typeNodeIntersection = (0, _composeTs.composeKeyedIntersection)((domain, l, r, context)=>{
const typeNodeIntersection = (0, _composeJs.composeKeyedIntersection)((domain, l, r, context)=>{
if (l === undefined) {
return r === undefined ? (0, _errorsTs.throwInternalError)(_composeTs.undefinedOperandsMessage) : undefined;
return r === undefined ? (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage) : undefined;
}

@@ -50,3 +50,3 @@ if (r === undefined) {

}
return (0, _predicateTs.predicateIntersection)(domain, l, r, context);
return (0, _predicateJs.predicateIntersection)(domain, l, r, context);
}, {

@@ -56,5 +56,5 @@ onEmpty: "omit"

const rootIntersection = (l, r, type)=>{
const state = new _composeTs.IntersectionState(type, "&");
const state = new _composeJs.IntersectionState(type, "&");
const result = nodeIntersection(l, r, state);
return (0, _composeTs.isDisjoint)(result) ? (0, _errorsTs.throwParseError)((0, _intersectionTs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeTs.isEquality)(result) ? l : result;
return (0, _composeJs.isDisjoint)(result) ? (0, _errorsJs.throwParseError)((0, _intersectionJs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeJs.isEquality)(result) ? l : result;
};

@@ -65,3 +65,3 @@ const rootUnion = (l, r, type)=>{

const result = {};
const domains = (0, _genericsTs.objectKeysOf)({
const domains = (0, _genericsJs.objectKeysOf)({
...lDomains,

@@ -71,3 +71,3 @@ ...rDomains

for (const domain of domains){
result[domain] = (0, _genericsTs.hasKey)(lDomains, domain) ? (0, _genericsTs.hasKey)(rDomains, domain) ? (0, _predicateTs.predicateUnion)(domain, lDomains[domain], rDomains[domain], type) : lDomains[domain] : (0, _genericsTs.hasKey)(rDomains, domain) ? rDomains[domain] : (0, _errorsTs.throwInternalError)(_composeTs.undefinedOperandsMessage);
result[domain] = (0, _genericsJs.hasKey)(lDomains, domain) ? (0, _genericsJs.hasKey)(rDomains, domain) ? (0, _predicateJs.predicateUnion)(domain, lDomains[domain], rDomains[domain], type) : lDomains[domain] : (0, _genericsJs.hasKey)(rDomains, domain) ? rDomains[domain] : (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage);
}

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

type,
path: new _pathsTs.Path(),
path: new _pathsJs.Path(),
lastDomain: "undefined"

@@ -96,3 +96,3 @@ };

{
config: (0, _genericsTs.entriesOf)(node.config),
config: (0, _genericsJs.entriesOf)(node.config),
node: flattenedTypeNode

@@ -104,3 +104,3 @@ }

const flattenTypeNode = (node, ctx)=>{
const domains = (0, _genericsTs.objectKeysOf)(node);
const domains = (0, _genericsJs.objectKeysOf)(node);
if (domains.length === 1) {

@@ -113,3 +113,3 @@ const domain = domains[0];

ctx.lastDomain = domain;
const flatPredicate = (0, _predicateTs.flattenPredicate)(predicate, ctx);
const flatPredicate = (0, _predicateJs.flattenPredicate)(predicate, ctx);
return hasImpliedDomain(flatPredicate) ? flatPredicate : [

@@ -126,3 +126,3 @@ [

ctx.lastDomain = domain;
result[domain] = (0, _predicateTs.flattenPredicate)(node[domain], ctx);
result[domain] = (0, _predicateJs.flattenPredicate)(node[domain], ctx);
}

@@ -137,6 +137,6 @@ return [

const isLiteralNode = (node, domain)=>{
return resolutionExtendsDomain(node, domain) && (0, _predicateTs.isLiteralCondition)(node[domain]);
return resolutionExtendsDomain(node, domain) && (0, _predicateJs.isLiteralCondition)(node[domain]);
};
const resolutionExtendsDomain = (resolution, domain)=>{
const domains = (0, _genericsTs.objectKeysOf)(resolution);
const domains = (0, _genericsJs.objectKeysOf)(resolution);
return domains.length === 1 && domains[0] === domain;

@@ -148,5 +148,5 @@ };

props: {
[_propsTs.mappedKeys.index]: node
[_propsJs.mappedKeys.index]: node
}
}
});

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

});
const _genericsTs = require("../utils/generics.js");
const _objectKindsTs = require("../utils/objectKinds.js");
const _branchTs = require("./branch.js");
const _composeTs = require("./compose.js");
const _discriminateTs = require("./discriminate.js");
const _genericsJs = require("../utils/generics.js");
const _objectKindsJs = require("../utils/objectKinds.js");
const _branchJs = require("./branch.js");
const _composeJs = require("./compose.js");
const _discriminateJs = require("./discriminate.js");
const emptyRulesIfTrue = (predicate)=>predicate === true ? {} : predicate;
const comparePredicates = (l, r, context)=>{
if (l === true && r === true) {
return (0, _composeTs.equality)();
return (0, _composeJs.equality)();
}
if (!(0, _objectKindsTs.isArray)(l) && !(0, _objectKindsTs.isArray)(r)) {
const result = (0, _branchTs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
if (!(0, _objectKindsJs.isArray)(l) && !(0, _objectKindsJs.isArray)(r)) {
const result = (0, _branchJs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
return result === l ? l : result === r ? r : result;
}
const lBranches = (0, _genericsTs.listFrom)(emptyRulesIfTrue(l));
const rBranches = (0, _genericsTs.listFrom)(emptyRulesIfTrue(r));
const comparison = (0, _branchTs.compareBranches)(lBranches, rBranches, context);
const lBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(l));
const rBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(r));
const comparison = (0, _branchJs.compareBranches)(lBranches, rBranches, context);
if (comparison.equalities.length === lBranches.length && comparison.equalities.length === rBranches.length) {
return (0, _composeTs.equality)();
return (0, _composeJs.equality)();
}

@@ -50,3 +50,3 @@ if (comparison.lExtendsR.length + comparison.equalities.length === lBranches.length) {

const comparison = comparePredicates(l, r, state);
if (!(0, _branchTs.isBranchComparison)(comparison)) {
if (!(0, _branchJs.isBranchComparison)(comparison)) {
return comparison;

@@ -66,6 +66,6 @@ }

const predicateUnion = (domain, l, r, type)=>{
const state = new _composeTs.IntersectionState(type, "|");
const state = new _composeJs.IntersectionState(type, "|");
const comparison = comparePredicates(l, r, state);
if (!(0, _branchTs.isBranchComparison)(comparison)) {
return (0, _composeTs.isEquality)(comparison) || comparison === l ? r : comparison === r ? l : // subtype of the other, it consists of two opposite literals
if (!(0, _branchJs.isBranchComparison)(comparison)) {
return (0, _composeJs.isEquality)(comparison) || comparison === l ? r : comparison === r ? l : // subtype of the other, it consists of two opposite literals
// and can be simplified to a non-literal boolean.

@@ -87,4 +87,4 @@ domain === "boolean" ? true : [

}
return (0, _objectKindsTs.isArray)(predicate) ? (0, _discriminateTs.flattenBranches)(predicate, context) : (0, _branchTs.flattenBranch)(predicate, context);
return (0, _objectKindsJs.isArray)(predicate) ? (0, _discriminateJs.flattenBranches)(predicate, context) : (0, _branchJs.flattenBranch)(predicate, context);
};
const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;

@@ -15,12 +15,12 @@ "use strict";

});
const _objectKindsTs = require("../../utils/objectKinds.js");
const _composeTs = require("../compose.js");
const classIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
return l === r ? (0, _composeTs.equality)() : l instanceof r ? l : r instanceof l ? r : state.addDisjoint("class", l, r);
const _objectKindsJs = require("../../utils/objectKinds.js");
const _composeJs = require("../compose.js");
const classIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
return l === r ? (0, _composeJs.equality)() : l instanceof r ? l : r instanceof l ? r : state.addDisjoint("class", l, r);
});
const checkClass = (expectedClass, state)=>{
if (typeof expectedClass === "string") {
return (0, _objectKindsTs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
return (0, _objectKindsJs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
}
return state.data instanceof expectedClass || !state.problems.add("class", expectedClass);
};

@@ -15,3 +15,3 @@ "use strict";

});
const _composeTs = require("../compose.js");
const _composeJs = require("../compose.js");
const collapsibleListUnion = (l, r)=>{

@@ -21,3 +21,3 @@ if (Array.isArray(l)) {

const result = listUnion(l, r);
return result.length === l.length ? result.length === r.length ? (0, _composeTs.equality)() : l : result.length === r.length ? r : result;
return result.length === l.length ? result.length === r.length ? (0, _composeJs.equality)() : l : result.length === r.length ? r : result;
}

@@ -35,3 +35,3 @@ return l.includes(r) ? l : [

}
return l === r ? (0, _composeTs.equality)() : [
return l === r ? (0, _composeJs.equality)() : [
l,

@@ -38,0 +38,0 @@ r

@@ -15,4 +15,4 @@ "use strict";

});
const _composeTs = require("../compose.js");
const divisorIntersection = (0, _composeTs.composeIntersection)((l, r)=>l === r ? (0, _composeTs.equality)() : Math.abs(l * r / greatestCommonDivisor(l, r)));
const _composeJs = require("../compose.js");
const divisorIntersection = (0, _composeJs.composeIntersection)((l, r)=>l === r ? (0, _composeJs.equality)() : Math.abs(l * r / greatestCommonDivisor(l, r)));
// https://en.wikipedia.org/wiki/Euclidean_algorithm

@@ -19,0 +19,0 @@ const greatestCommonDivisor = (l, r)=>{

@@ -19,4 +19,4 @@ "use strict";

});
const _composeTs = require("../compose.js");
const _nodeTs = require("../node.js");
const _composeJs = require("../compose.js");
const _nodeJs = require("../node.js");
const isOptional = (prop)=>prop[0] === "?";

@@ -29,7 +29,7 @@ const isPrerequisite = (prop)=>prop[0] === "!";

const getTupleLengthIfPresent = (result)=>{
if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0, _nodeTs.isLiteralNode)(result.length[1], "number")) {
if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0, _nodeJs.isLiteralNode)(result.length[1], "number")) {
return result.length[1].number.value;
}
};
const propsIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
const propsIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
const result = propKeysIntersection(l, r, state);

@@ -56,7 +56,7 @@ if (typeof result === "symbol") {

state.path.push(`${i}`);
const updatedResultAtIndex = (0, _nodeTs.nodeIntersection)(existingNodeAtIndex, indexNode, state);
const updatedResultAtIndex = (0, _nodeJs.nodeIntersection)(existingNodeAtIndex, indexNode, state);
state.path.pop();
if ((0, _composeTs.isDisjoint)(updatedResultAtIndex)) {
if ((0, _composeJs.isDisjoint)(updatedResultAtIndex)) {
return updatedResultAtIndex;
} else if (!(0, _composeTs.isEquality)(updatedResultAtIndex) && updatedResultAtIndex !== existingNodeAtIndex) {
} else if (!(0, _composeJs.isEquality)(updatedResultAtIndex) && updatedResultAtIndex !== existingNodeAtIndex) {
updatedResult[i] = updatedResultAtIndex;

@@ -67,5 +67,5 @@ }

});
const propKeysIntersection = (0, _composeTs.composeKeyedIntersection)((propKey, l, r, context)=>{
const propKeysIntersection = (0, _composeJs.composeKeyedIntersection)((propKey, l, r, context)=>{
if (l === undefined) {
return r === undefined ? (0, _composeTs.equality)() : r;
return r === undefined ? (0, _composeJs.equality)() : r;
}

@@ -76,6 +76,6 @@ if (r === undefined) {

context.path.push(propKey);
const result = (0, _nodeTs.nodeIntersection)(propToNode(l), propToNode(r), context);
const result = (0, _nodeJs.nodeIntersection)(propToNode(l), propToNode(r), context);
context.path.pop();
const resultIsOptional = isOptional(l) && isOptional(r);
if ((0, _composeTs.isDisjoint)(result) && resultIsOptional) {
if ((0, _composeJs.isDisjoint)(result) && resultIsOptional) {
// If an optional key has an empty intersection, the type can

@@ -102,3 +102,3 @@ // still be satisfied as long as the key is not included. Set

"indexProp",
(0, _nodeTs.flattenNode)(propToNode(prop), ctx)
(0, _nodeJs.flattenNode)(propToNode(prop), ctx)
]);

@@ -110,3 +110,3 @@ } else if (isOptional(prop)) {

k,
(0, _nodeTs.flattenNode)(prop[1], ctx)
(0, _nodeJs.flattenNode)(prop[1], ctx)
]

@@ -119,3 +119,3 @@ ]);

k,
(0, _nodeTs.flattenNode)(prop[1], ctx)
(0, _nodeJs.flattenNode)(prop[1], ctx)
]

@@ -128,3 +128,3 @@ ]);

k,
(0, _nodeTs.flattenNode)(prop, ctx)
(0, _nodeJs.flattenNode)(prop, ctx)
]

@@ -148,5 +148,5 @@ ]);

if (k === mappedKeys.index) {
result.index = (0, _nodeTs.flattenNode)(propToNode(prop), ctx);
result.index = (0, _nodeJs.flattenNode)(propToNode(prop), ctx);
} else if (isOptional(prop)) {
result.optional[k] = (0, _nodeTs.flattenNode)(prop[1], ctx);
result.optional[k] = (0, _nodeJs.flattenNode)(prop[1], ctx);
} else if (isPrerequisite(prop)) {

@@ -158,7 +158,7 @@ // we still have to push prerequisite props as normal entries so they can be checked first

k,
(0, _nodeTs.flattenNode)(prop[1], ctx)
(0, _nodeJs.flattenNode)(prop[1], ctx)
]
]);
} else {
result.required[k] = (0, _nodeTs.flattenNode)(prop, ctx);
result.required[k] = (0, _nodeJs.flattenNode)(prop, ctx);
}

@@ -165,0 +165,0 @@ ctx.path.pop();

@@ -20,4 +20,4 @@ "use strict";

});
const _dataTs = require("../../utils/data.js");
const _composeTs = require("../compose.js");
const _dataJs = require("../../utils/data.js");
const _composeJs = require("../compose.js");
const minComparators = {

@@ -32,6 +32,6 @@ ">": true,

const isEqualityRange = (range)=>"comparator" in range;
const rangeIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
const rangeIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
if (isEqualityRange(l)) {
if (isEqualityRange(r)) {
return l.limit === r.limit ? (0, _composeTs.equality)() : state.addDisjoint("range", l, r);
return l.limit === r.limit ? (0, _composeJs.equality)() : state.addDisjoint("range", l, r);
}

@@ -63,3 +63,3 @@ return rangeAllows(r, l.limit) ? l : state.addDisjoint("range", l, r);

}
return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, _composeTs.equality)();
return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, _composeJs.equality)();
});

@@ -99,3 +99,3 @@ const rangeAllows = (range, n)=>isEqualityRange(range) ? n === range.limit : minAllows(range.min, n) && maxAllows(range.max, n);

};
const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0, _dataTs.sizeOf)(state.data), bound.limit) || !state.problems.add("bound", bound);
const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0, _dataJs.sizeOf)(state.data), bound.limit) || !state.problems.add("bound", bound);
const comparatorCheckers = {

@@ -102,0 +102,0 @@ "<": (size, limit)=>size < limit,

@@ -16,4 +16,4 @@ "use strict";

});
const _composeTs = require("../compose.js");
const _collapsibleSetTs = require("./collapsibleSet.js");
const _composeJs = require("../compose.js");
const _collapsibleSetJs = require("./collapsibleSet.js");
const regexCache = {};

@@ -27,2 +27,2 @@ const getRegex = (source)=>{

const checkRegex = (source, state)=>getRegex(source).test(state.data) || !state.problems.add("regex", `/${source}/`);
const regexIntersection = (0, _composeTs.composeIntersection)(_collapsibleSetTs.collapsibleListUnion);
const regexIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);

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

});
const _genericsTs = require("../../utils/generics.js");
const _composeTs = require("../compose.js");
const _classTs = require("./class.js");
const _collapsibleSetTs = require("./collapsibleSet.js");
const _divisorTs = require("./divisor.js");
const _propsTs = require("./props.js");
const _rangeTs = require("./range.js");
const _regexTs = require("./regex.js");
const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeTs.equality)() : state.addDisjoint("value", l.value, r.value) : literalSatisfiesRules(l.value, r, state) ? l : state.addDisjoint("leftAssignability", l, r) : "value" in r ? literalSatisfiesRules(r.value, l, state) ? r : state.addDisjoint("rightAssignability", l, r) : narrowableRulesIntersection(l, r, state);
const narrowIntersection = (0, _composeTs.composeIntersection)(_collapsibleSetTs.collapsibleListUnion);
const narrowableRulesIntersection = (0, _composeTs.composeKeyedIntersection)({
divisor: _divisorTs.divisorIntersection,
regex: _regexTs.regexIntersection,
props: _propsTs.propsIntersection,
class: _classTs.classIntersection,
range: _rangeTs.rangeIntersection,
const _genericsJs = require("../../utils/generics.js");
const _composeJs = require("../compose.js");
const _classJs = require("./class.js");
const _collapsibleSetJs = require("./collapsibleSet.js");
const _divisorJs = require("./divisor.js");
const _propsJs = require("./props.js");
const _rangeJs = require("./range.js");
const _regexJs = require("./regex.js");
const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeJs.equality)() : state.addDisjoint("value", l.value, r.value) : literalSatisfiesRules(l.value, r, state) ? l : state.addDisjoint("leftAssignability", l, r) : "value" in r ? literalSatisfiesRules(r.value, l, state) ? r : state.addDisjoint("rightAssignability", l, r) : narrowableRulesIntersection(l, r, state);
const narrowIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
const narrowableRulesIntersection = (0, _composeJs.composeKeyedIntersection)({
divisor: _divisorJs.divisorIntersection,
regex: _regexJs.regexIntersection,
props: _propsJs.propsIntersection,
class: _classJs.classIntersection,
range: _rangeJs.rangeIntersection,
narrow: narrowIntersection

@@ -53,3 +53,3 @@ }, {

regex: (entries, rule)=>{
for (const source of (0, _genericsTs.listFrom)(rule)){
for (const source of (0, _genericsJs.listFrom)(rule)){
entries.push([

@@ -67,3 +67,3 @@ "regex",

},
range: _rangeTs.flattenRange,
range: _rangeJs.flattenRange,
class: (entries, rule)=>{

@@ -75,5 +75,5 @@ entries.push([

},
props: _propsTs.flattenProps,
props: _propsJs.flattenProps,
narrow: (entries, rule)=>{
for (const narrow of (0, _genericsTs.listFrom)(rule)){
for (const narrow of (0, _genericsJs.listFrom)(rule)){
entries.push([

@@ -80,0 +80,0 @@ "narrow",

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

});
const _definitionTs = require("../definition.js");
const _definitionJs = require("../definition.js");
const parseConfigTuple = (def, ctx)=>({
node: ctx.type.scope.resolveTypeNode((0, _definitionTs.parseDefinition)(def[0], ctx)),
node: ctx.type.scope.resolveTypeNode((0, _definitionJs.parseDefinition)(def[0], ctx)),
config: def[2]
});

@@ -15,11 +15,11 @@ "use strict";

});
const _domainsTs = require("../../utils/domains.js");
const _errorsTs = require("../../utils/errors.js");
const _genericsTs = require("../../utils/generics.js");
const _serializeTs = require("../../utils/serialize.js");
const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeTs.stringify)(def)} was invalid)`;
const _domainsJs = require("../../utils/domains.js");
const _errorsJs = require("../../utils/errors.js");
const _genericsJs = require("../../utils/generics.js");
const _serializeJs = require("../../utils/serialize.js");
const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeJs.stringify)(def)} was invalid)`;
const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
const domains = (0, _genericsTs.objectKeysOf)(node);
if (!(0, _domainsTs.hasDomain)(distributableFunction, "object")) {
return (0, _errorsTs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
const domains = (0, _genericsJs.objectKeysOf)(node);
if (!(0, _domainsJs.hasDomain)(distributableFunction, "object")) {
return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
}

@@ -43,3 +43,3 @@ const distributed = {};

if (typeof functionInDomain[ruleKey] !== "function") {
return (0, _errorsTs.throwParseError)(writeMalformedDistributableFunctionMessage(functionInDomain));
return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(functionInDomain));
}

@@ -46,0 +46,0 @@ distributed[domain] = functionInDomain;

@@ -15,9 +15,9 @@ "use strict";

});
const _composeTs = require("../../nodes/compose.js");
const _genericsTs = require("../../utils/generics.js");
const _composeJs = require("../../nodes/compose.js");
const _genericsJs = require("../../utils/generics.js");
const compileDisjointReasonsMessage = (disjoints)=>{
const paths = (0, _genericsTs.objectKeysOf)(disjoints);
const paths = (0, _genericsJs.objectKeysOf)(disjoints);
if (paths.length === 1) {
const path = paths[0];
return `${path === "/" ? "" : `At ${path}: `}Intersection of ${_composeTs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
return `${path === "/" ? "" : `At ${path}: `}Intersection of ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
}

@@ -27,3 +27,3 @@ let message = `

for(const path in disjoints){
message += ` ${path}: ${_composeTs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
message += ` ${path}: ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
}

@@ -30,0 +30,0 @@ return message;

@@ -9,16 +9,15 @@ "use strict";

});
const _propsTs = require("../../nodes/rules/props.js");
const _errorsTs = require("../../utils/errors.js");
const _freezeTs = require("../../utils/freeze.js");
const _genericsTs = require("../../utils/generics.js");
const _numericLiteralsTs = require("../../utils/numericLiterals.js");
const _objectKindsTs = require("../../utils/objectKinds.js");
const _serializeTs = require("../../utils/serialize.js");
const _definitionTs = require("../definition.js");
const _intersectionTs = require("./intersection.js");
var _keyNode, _keyType, _keyNode1, _keyNode2;
const arrayIndexStringBranch = (0, _freezeTs.deepFreeze)({
regex: _numericLiteralsTs.wellFormedNonNegativeIntegerMatcher.source
const _propsJs = require("../../nodes/rules/props.js");
const _errorsJs = require("../../utils/errors.js");
const _freezeJs = require("../../utils/freeze.js");
const _genericsJs = require("../../utils/generics.js");
const _numericLiteralsJs = require("../../utils/numericLiterals.js");
const _objectKindsJs = require("../../utils/objectKinds.js");
const _serializeJs = require("../../utils/serialize.js");
const _definitionJs = require("../definition.js");
const _intersectionJs = require("./intersection.js");
const arrayIndexStringBranch = (0, _freezeJs.deepFreeze)({
regex: _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.source
});
const arrayIndexNumberBranch = (0, _freezeTs.deepFreeze)({
const arrayIndexNumberBranch = (0, _freezeJs.deepFreeze)({
range: {

@@ -33,7 +32,7 @@ min: {

const parseKeyOfTuple = (def, ctx)=>{
const resolution = ctx.type.scope.resolveNode((0, _definitionTs.parseDefinition)(def[1], ctx));
const predicateKeys = (0, _genericsTs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
const resolution = ctx.type.scope.resolveNode((0, _definitionJs.parseDefinition)(def[1], ctx));
const predicateKeys = (0, _genericsJs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
const sharedKeys = sharedKeysOf(predicateKeys);
if (!sharedKeys.length) {
return (0, _intersectionTs.writeImplicitNeverMessage)(ctx.path, "keyof");
return (0, _intersectionJs.writeImplicitNeverMessage)(ctx.path, "keyof");
}

@@ -44,2 +43,3 @@ const keyNode = {};

if (keyType === "string" || keyType === "number" || keyType === "symbol") {
var _keyNode, _keyType;
(_keyNode = keyNode)[_keyType = keyType] ?? (_keyNode[_keyType] = []);

@@ -49,3 +49,4 @@ keyNode[keyType].push({

});
} else if (key === _numericLiteralsTs.wellFormedNonNegativeIntegerMatcher) {
} else if (key === _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher) {
var _keyNode1, _keyNode2;
(_keyNode1 = keyNode).string ?? (_keyNode1.string = []);

@@ -56,3 +57,3 @@ keyNode.string.push(arrayIndexStringBranch);

} else {
return (0, _errorsTs.throwInternalError)(`Unexpected keyof key '${(0, _serializeTs.stringify)(key)}'`);
return (0, _errorsJs.throwInternalError)(`Unexpected keyof key '${(0, _serializeJs.stringify)(key)}'`);
}

@@ -66,13 +67,13 @@ }

const baseKeysByDomain = {
bigint: (0, _genericsTs.prototypeKeysOf)(0n),
boolean: (0, _genericsTs.prototypeKeysOf)(false),
bigint: (0, _genericsJs.prototypeKeysOf)(0n),
boolean: (0, _genericsJs.prototypeKeysOf)(false),
null: [],
number: (0, _genericsTs.prototypeKeysOf)(0),
number: (0, _genericsJs.prototypeKeysOf)(0),
// TS doesn't include the Object prototype in keyof, so keyof object is never
object: [],
string: (0, _genericsTs.prototypeKeysOf)(""),
symbol: (0, _genericsTs.prototypeKeysOf)(Symbol()),
string: (0, _genericsJs.prototypeKeysOf)(""),
symbol: (0, _genericsJs.prototypeKeysOf)(Symbol()),
undefined: []
};
const keysOfPredicate = (domain, predicate)=>domain !== "object" || predicate === true ? baseKeysByDomain[domain] : sharedKeysOf((0, _genericsTs.listFrom)(predicate).map((branch)=>keysOfObjectBranch(branch)));
const keysOfPredicate = (domain, predicate)=>domain !== "object" || predicate === true ? baseKeysByDomain[domain] : sharedKeysOf((0, _genericsJs.listFrom)(predicate).map((branch)=>keysOfObjectBranch(branch)));
const sharedKeysOf = (keyBranches)=>{

@@ -95,10 +96,10 @@ if (!keyBranches.length) {

for (const key of Object.keys(branch.props)){
if (key === _propsTs.mappedKeys.index) {
if (key === _propsJs.mappedKeys.index) {
// if any number is a valid key push this RegExp
result.push(_numericLiteralsTs.wellFormedNonNegativeIntegerMatcher);
result.push(_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher);
} else if (!result.includes(key)) {
result.push(key);
if (_numericLiteralsTs.wellFormedNonNegativeIntegerMatcher.test(key)) {
if (_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.test(key)) {
// allow numeric access to keys
result.push((0, _numericLiteralsTs.tryParseWellFormedInteger)(key, `Unexpectedly failed to parse an integer from key '${key}'`));
result.push((0, _numericLiteralsJs.tryParseWellFormedInteger)(key, `Unexpectedly failed to parse an integer from key '${key}'`));
}

@@ -109,4 +110,4 @@ }

if ("class" in branch) {
const constructor = typeof branch.class === "string" ? _objectKindsTs.defaultObjectKinds[branch.class] : branch.class;
for (const key of (0, _genericsTs.prototypeKeysOf)(constructor.prototype)){
const constructor = typeof branch.class === "string" ? _objectKindsJs.defaultObjectKinds[branch.class] : branch.class;
for (const key of (0, _genericsJs.prototypeKeysOf)(constructor.prototype)){
if (!result.includes(key)) {

@@ -113,0 +114,0 @@ result.push(key);

@@ -15,12 +15,12 @@ "use strict";

});
const _branchTs = require("../../nodes/branch.js");
const _errorsTs = require("../../utils/errors.js");
const _objectKindsTs = require("../../utils/objectKinds.js");
const _serializeTs = require("../../utils/serialize.js");
const _definitionTs = require("../definition.js");
const _branchJs = require("../../nodes/branch.js");
const _errorsJs = require("../../utils/errors.js");
const _objectKindsJs = require("../../utils/objectKinds.js");
const _serializeJs = require("../../utils/serialize.js");
const _definitionJs = require("../definition.js");
const parseMorphTuple = (def, ctx)=>{
if (typeof def[2] !== "function") {
return (0, _errorsTs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
return (0, _errorsJs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
}
const node = (0, _definitionTs.parseDefinition)(def[0], ctx);
const node = (0, _definitionJs.parseDefinition)(def[0], ctx);
const resolution = ctx.type.scope.resolveTypeNode(node);

@@ -39,5 +39,5 @@ const morph = def[2];

} else if (typeof predicate === "object") {
result[domain] = (0, _objectKindsTs.isArray)(predicate) ? predicate.map((branch)=>applyMorph(branch, morph)) : applyMorph(predicate, morph);
result[domain] = (0, _objectKindsJs.isArray)(predicate) ? predicate.map((branch)=>applyMorph(branch, morph)) : applyMorph(predicate, morph);
} else {
(0, _errorsTs.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, _serializeTs.stringify)(predicate)}`);
(0, _errorsJs.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, _serializeJs.stringify)(predicate)}`);
}

@@ -47,3 +47,3 @@ }

};
const applyMorph = (branch, morph)=>(0, _branchTs.isTransformationBranch)(branch) ? {
const applyMorph = (branch, morph)=>(0, _branchJs.isTransformationBranch)(branch) ? {
...branch,

@@ -50,0 +50,0 @@ morph: branch.morph ? Array.isArray(branch.morph) ? [

@@ -9,11 +9,11 @@ "use strict";

});
const _nodeTs = require("../../nodes/node.js");
const _definitionTs = require("../definition.js");
const _distributableFunctionTs = require("./distributableFunction.js");
const _nodeJs = require("../../nodes/node.js");
const _definitionJs = require("../definition.js");
const _distributableFunctionJs = require("./distributableFunction.js");
const parseNarrowTuple = (def, ctx)=>{
const inputNode = (0, _definitionTs.parseDefinition)(def[0], ctx);
const inputNode = (0, _definitionJs.parseDefinition)(def[0], ctx);
const resolution = ctx.type.scope.resolveNode(inputNode);
const hasConfig = (0, _nodeTs.isConfigNode)(resolution);
const hasConfig = (0, _nodeJs.isConfigNode)(resolution);
const typeNode = hasConfig ? resolution.node : resolution;
const result = (0, _nodeTs.rootIntersection)(inputNode, (0, _distributableFunctionTs.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
const result = (0, _nodeJs.rootIntersection)(inputNode, (0, _distributableFunctionJs.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
return hasConfig ? {

@@ -20,0 +20,0 @@ config: resolution.config,

@@ -15,11 +15,11 @@ "use strict";

});
const _nodeTs = require("../../nodes/node.js");
const _domainsTs = require("../../utils/domains.js");
const _errorsTs = require("../../utils/errors.js");
const _definitionTs = require("../definition.js");
const _unenclosedTs = require("../string/shift/operand/unenclosed.js");
const _configTs = require("./config.js");
const _keyofTs = require("./keyof.js");
const _morphTs = require("./morph.js");
const _narrowTs = require("./narrow.js");
const _nodeJs = require("../../nodes/node.js");
const _domainsJs = require("../../utils/domains.js");
const _errorsJs = require("../../utils/errors.js");
const _definitionJs = require("../definition.js");
const _unenclosedJs = require("../string/shift/operand/unenclosed.js");
const _configJs = require("./config.js");
const _keyofJs = require("./keyof.js");
const _morphJs = require("./morph.js");
const _narrowJs = require("./narrow.js");
const parseTuple = (def, ctx)=>{

@@ -47,3 +47,3 @@ if (isIndexOneExpression(def)) {

ctx.path.push(`${i}`);
props[i] = (0, _definitionTs.parseDefinition)(def[i], ctx);
props[i] = (0, _definitionJs.parseDefinition)(def[i], ctx);
ctx.path.pop();

@@ -60,9 +60,9 @@ }

if (def[2] === undefined) {
return (0, _errorsTs.throwParseError)((0, _unenclosedTs.writeMissingRightOperandMessage)(def[1], ""));
return (0, _errorsJs.throwParseError)((0, _unenclosedJs.writeMissingRightOperandMessage)(def[1], ""));
}
const l = (0, _definitionTs.parseDefinition)(def[0], ctx);
const r = (0, _definitionTs.parseDefinition)(def[2], ctx);
return def[1] === "&" ? (0, _nodeTs.rootIntersection)(l, r, ctx.type) : (0, _nodeTs.rootUnion)(l, r, ctx.type);
const l = (0, _definitionJs.parseDefinition)(def[0], ctx);
const r = (0, _definitionJs.parseDefinition)(def[2], ctx);
return def[1] === "&" ? (0, _nodeJs.rootIntersection)(l, r, ctx.type) : (0, _nodeJs.rootUnion)(l, r, ctx.type);
};
const parseArrayTuple = (def, scope)=>(0, _nodeTs.toArrayNode)((0, _definitionTs.parseDefinition)(def[0], scope));
const parseArrayTuple = (def, scope)=>(0, _nodeJs.toArrayNode)((0, _definitionJs.parseDefinition)(def[0], scope));
const writeMalformedFunctionalExpressionMessage = (operator, rightDef)=>`Expression requires a function following '${operator}' (was ${typeof rightDef})`;

@@ -74,11 +74,11 @@ const isIndexOneExpression = (def)=>indexOneParsers[def[1]] !== undefined;

"[]": parseArrayTuple,
"=>": _narrowTs.parseNarrowTuple,
"|>": _morphTs.parseMorphTuple,
":": _configTs.parseConfigTuple
"=>": _narrowJs.parseNarrowTuple,
"|>": _morphJs.parseMorphTuple,
":": _configJs.parseConfigTuple
};
const prefixParsers = {
keyof: _keyofTs.parseKeyOfTuple,
keyof: _keyofJs.parseKeyOfTuple,
instanceof: (def)=>{
if (typeof def[1] !== "function") {
return (0, _errorsTs.throwParseError)(`Expected a constructor following 'instanceof' operator (was ${typeof def[1]}).`);
return (0, _errorsJs.throwParseError)(`Expected a constructor following 'instanceof' operator (was ${typeof def[1]}).`);
}

@@ -92,3 +92,3 @@ return {

"===": (def)=>({
[(0, _domainsTs.domainOf)(def[1])]: {
[(0, _domainsJs.domainOf)(def[1])]: {
value: def[1]

@@ -95,0 +95,0 @@ }

@@ -14,27 +14,26 @@ "use strict";

as: ()=>as,
unknownDefinitionMessage: ()=>unknownDefinitionMessage,
writeBadDefinitionTypeMessage: ()=>writeBadDefinitionTypeMessage
});
const _typeTs = require("../scopes/type.js");
const _domainsTs = require("../utils/domains.js");
const _errorsTs = require("../utils/errors.js");
const _objectKindsTs = require("../utils/objectKinds.js");
const _serializeTs = require("../utils/serialize.js");
const _tupleTs = require("./ast/tuple.js");
const _recordTs = require("./record.js");
const _stringTs = require("./string/string.js");
const _typeJs = require("../scopes/type.js");
const _domainsJs = require("../utils/domains.js");
const _errorsJs = require("../utils/errors.js");
const _objectKindsJs = require("../utils/objectKinds.js");
const _serializeJs = require("../utils/serialize.js");
const _tupleJs = require("./ast/tuple.js");
const _recordJs = require("./record.js");
const _stringJs = require("./string/string.js");
const parseDefinition = (def, ctx)=>{
const domain = (0, _domainsTs.domainOf)(def);
const domain = (0, _domainsJs.domainOf)(def);
if (domain === "string") {
return (0, _stringTs.parseString)(def, ctx);
return (0, _stringJs.parseString)(def, ctx);
}
if (domain !== "object") {
return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage(domain));
return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage(domain));
}
const objectKind = (0, _objectKindsTs.objectKindOf)(def);
const objectKind = (0, _objectKindsJs.objectKindOf)(def);
switch(objectKind){
case "Object":
return (0, _recordTs.parseRecord)(def, ctx);
return (0, _recordJs.parseRecord)(def, ctx);
case "Array":
return (0, _tupleTs.parseTuple)(def, ctx);
return (0, _tupleJs.parseTuple)(def, ctx);
case "RegExp":

@@ -47,3 +46,3 @@ return {

case "Function":
if ((0, _typeTs.isType)(def)) {
if ((0, _typeJs.isType)(def)) {
return ctx.type.scope.addAnonymousTypeReference(def, ctx);

@@ -53,14 +52,13 @@ }

const returned = def();
if ((0, _typeTs.isType)(returned)) {
if ((0, _typeJs.isType)(returned)) {
return ctx.type.scope.addAnonymousTypeReference(returned, ctx);
}
}
return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
default:
return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage(objectKind ?? (0, _serializeTs.stringify)(def)));
return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage(objectKind ?? (0, _serializeJs.stringify)(def)));
}
};
const as = Symbol("as");
const unknownDefinitionMessage = "Cannot statically parse a definition inferred as unknown. Consider using 'as Infer<...>' to cast it.";
const isThunk = (def)=>typeof def === "function" && def.length === 0;
const writeBadDefinitionTypeMessage = (actual)=>`Type definitions must be strings or objects (was ${actual})`;

@@ -9,4 +9,4 @@ "use strict";

});
const _definitionTs = require("./definition.js");
const _scannerTs = require("./string/shift/scanner.js");
const _definitionJs = require("./definition.js");
const _scannerJs = require("./string/shift/scanner.js");
const parseRecord = (def, ctx)=>{

@@ -18,3 +18,3 @@ const props = {};

if (definitionKey[definitionKey.length - 1] === "?") {
if (definitionKey[definitionKey.length - 2] === _scannerTs.Scanner.escapeToken) {
if (definitionKey[definitionKey.length - 2] === _scannerJs.Scanner.escapeToken) {
keyName = `${definitionKey.slice(0, -2)}?`;

@@ -27,3 +27,3 @@ } else {

ctx.path.push(keyName);
const propNode = (0, _definitionTs.parseDefinition)(def[definitionKey], ctx);
const propNode = (0, _definitionJs.parseDefinition)(def[definitionKey], ctx);
ctx.path.pop();

@@ -30,0 +30,0 @@ props[keyName] = isOptional ? [

@@ -9,12 +9,25 @@ "use strict";

});
const _nodeTs = require("../../../nodes/node.js");
const _rangeTs = require("../../../nodes/rules/range.js");
const _errorsTs = require("../../../utils/errors.js");
const _genericsTs = require("../../../utils/generics.js");
const _serializeTs = require("../../../utils/serialize.js");
const _scannerTs = require("../shift/scanner.js");
const _sharedTs = require("./shared.js");
const _nodeJs = require("../../../nodes/node.js");
const _rangeJs = require("../../../nodes/rules/range.js");
const _errorsJs = require("../../../utils/errors.js");
const _genericsJs = require("../../../utils/generics.js");
const _serializeJs = require("../../../utils/serialize.js");
const _scannerJs = require("../shift/scanner.js");
const _sharedJs = require("./shared.js");
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
class DynamicState {
error(message) {
return (0, _errorsTs.throwParseError)(message);
return (0, _errorsJs.throwParseError)(message);
}

@@ -30,3 +43,3 @@ hasRoot() {

this.assertHasRoot();
return (0, _serializeTs.stringify)(this.root);
return (0, _serializeJs.stringify)(this.root);
}

@@ -36,3 +49,3 @@ ejectRootIfLimit() {

const resolution = typeof this.root === "string" ? this.ctx.type.scope.resolveNode(this.root) : this.root;
if ((0, _nodeTs.isLiteralNode)(resolution, "number")) {
if ((0, _nodeJs.isLiteralNode)(resolution, "number")) {
const limit = resolution.number.value;

@@ -52,3 +65,3 @@ this.root = undefined;

if (this.root === undefined) {
return (0, _errorsTs.throwInternalError)("Unexpected interaction with unset root");
return (0, _errorsJs.throwInternalError)("Unexpected interaction with unset root");
}

@@ -58,3 +71,3 @@ }

if (this.root !== undefined) {
return (0, _errorsTs.throwInternalError)("Unexpected attempt to overwrite root");
return (0, _errorsJs.throwInternalError)("Unexpected attempt to overwrite root");
}

@@ -67,6 +80,6 @@ }

rootToArray() {
this.root = (0, _nodeTs.toArrayNode)(this.ejectRoot());
this.root = (0, _nodeJs.toArrayNode)(this.ejectRoot());
}
intersect(node) {
this.root = (0, _nodeTs.rootIntersection)(this.ejectRoot(), node, this.ctx.type);
this.root = (0, _nodeJs.rootIntersection)(this.ejectRoot(), node, this.ctx.type);
}

@@ -87,3 +100,3 @@ ejectRoot() {

if (this.groups.length) {
return this.error(_sharedTs.unclosedGroupMessage);
return this.error(_sharedJs.unclosedGroupMessage);
}

@@ -94,8 +107,8 @@ this.finalizeBranches();

reduceLeftBound(limit, comparator) {
const invertedComparator = _scannerTs.Scanner.invertedComparators[comparator];
if (!(0, _genericsTs.isKeyOf)(invertedComparator, _rangeTs.minComparators)) {
return this.error((0, _sharedTs.writeUnpairableComparatorMessage)(comparator));
const invertedComparator = _scannerJs.Scanner.invertedComparators[comparator];
if (!(0, _genericsJs.isKeyOf)(invertedComparator, _rangeJs.minComparators)) {
return this.error((0, _sharedJs.writeUnpairableComparatorMessage)(comparator));
}
if (this.branches.range) {
return this.error((0, _sharedTs.writeMultipleLeftBoundsMessage)(`${this.branches.range.limit}`, this.branches.range.comparator, `${limit}`, invertedComparator));
return this.error((0, _sharedJs.writeMultipleLeftBoundsMessage)(`${this.branches.range.limit}`, this.branches.range.comparator, `${limit}`, invertedComparator));
}

@@ -113,3 +126,3 @@ this.branches.range = {

} else if (this.branches.intersection) {
this.setRoot((0, _nodeTs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type));
this.setRoot((0, _nodeJs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type));
}

@@ -121,3 +134,3 @@ }

if (!topBranchState) {
return this.error((0, _sharedTs.writeUnmatchedGroupCloseMessage)(this.scanner.unscanned));
return this.error((0, _sharedJs.writeUnmatchedGroupCloseMessage)(this.scanner.unscanned));
}

@@ -128,5 +141,5 @@ this.branches = topBranchState;

this.assertRangeUnset();
this.branches.intersection = this.branches.intersection ? (0, _nodeTs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type) : this.ejectRoot();
this.branches.intersection = this.branches.intersection ? (0, _nodeJs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type) : this.ejectRoot();
if (token === "|") {
this.branches.union = this.branches.union ? (0, _nodeTs.rootUnion)(this.branches.union, this.branches.intersection, this.ctx.type) : this.branches.intersection;
this.branches.union = this.branches.union ? (0, _nodeJs.rootUnion)(this.branches.union, this.branches.intersection, this.ctx.type) : this.branches.intersection;
delete this.branches.intersection;

@@ -137,3 +150,3 @@ }

if (this.branches.range) {
return this.error((0, _sharedTs.writeOpenRangeMessage)(`${this.branches.range.limit}`, this.branches.range.comparator));
return this.error((0, _sharedJs.writeOpenRangeMessage)(`${this.branches.range.limit}`, this.branches.range.comparator));
}

@@ -153,10 +166,15 @@ }

constructor(def, ctx){
_defineProperty(this, "ctx", void 0);
_defineProperty(this, "scanner", void 0);
_defineProperty(this, "root", void 0);
_defineProperty(this, "branches", void 0);
_defineProperty(this, "groups", void 0);
this.ctx = ctx;
this.branches = {};
this.groups = [];
this.scanner = new _scannerTs.Scanner(def);
this.scanner = new _scannerJs.Scanner(def);
}
}
const ejectedProxy = new Proxy({}, {
get: ()=>(0, _errorsTs.throwInternalError)(`Unexpected attempt to access ejected attributes`)
get: ()=>(0, _errorsJs.throwInternalError)(`Unexpected attempt to access ejected attributes`)
});

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

});
const _scannerTs = require("../shift/scanner.js");
const _scannerJs = require("../shift/scanner.js");
const writeUnmatchedGroupCloseMessage = (unscanned)=>`Unmatched )${unscanned === "" ? "" : ` before ${unscanned}`}`;

@@ -24,2 +24,2 @@ const unclosedGroupMessage = "Missing )";

const writeUnpairableComparatorMessage = (comparator)=>`Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator)=>`An expression may have at most one left bound (parsed ${openLimit}${_scannerTs.Scanner.invertedComparators[openComparator]}, ${limit}${_scannerTs.Scanner.invertedComparators[comparator]})`;
const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator)=>`An expression may have at most one left bound (parsed ${openLimit}${_scannerJs.Scanner.invertedComparators[openComparator]}, ${limit}${_scannerJs.Scanner.invertedComparators[comparator]})`;

@@ -16,3 +16,3 @@ "use strict";

});
const _regexTs = require("../../../../nodes/rules/regex.js");
const _regexJs = require("../../../../nodes/rules/regex.js");
const parseEnclosed = (s, enclosing)=>{

@@ -26,3 +26,3 @@ const token = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosing]);

// Cache the regex instance to throw right way if its invalid
(0, _regexTs.getRegex)(token);
(0, _regexJs.getRegex)(token);
s.setRoot({

@@ -29,0 +29,0 @@ string: {

@@ -9,4 +9,4 @@ "use strict";

});
const _enclosedTs = require("./enclosed.js");
const _unenclosedTs = require("./unenclosed.js");
const parseOperand = (s)=>s.scanner.lookahead === "" ? s.error((0, _unenclosedTs.writeMissingOperandMessage)(s)) : s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen() : s.scanner.lookaheadIsIn(_enclosedTs.enclosingChar) ? (0, _enclosedTs.parseEnclosed)(s, s.scanner.shift()) : s.scanner.lookahead === " " ? parseOperand(s.shiftedByOne()) : (0, _unenclosedTs.parseUnenclosed)(s);
const _enclosedJs = require("./enclosed.js");
const _unenclosedJs = require("./unenclosed.js");
const parseOperand = (s)=>s.scanner.lookahead === "" ? s.error((0, _unenclosedJs.writeMissingOperandMessage)(s)) : s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen() : s.scanner.lookaheadIsIn(_enclosedJs.enclosingChar) ? (0, _enclosedJs.parseEnclosed)(s, s.scanner.shift()) : s.scanner.lookahead === " " ? parseOperand(s.shiftedByOne()) : (0, _unenclosedJs.parseUnenclosed)(s);

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

});
const _numericLiteralsTs = require("../../../../utils/numericLiterals.js");
const _numericLiteralsJs = require("../../../../utils/numericLiterals.js");
const parseUnenclosed = (s)=>{

@@ -31,3 +31,3 @@ const token = s.scanner.shiftUntilNextTerminator();

const maybeParseUnenclosedLiteral = (token)=>{
const maybeNumber = (0, _numericLiteralsTs.tryParseWellFormedNumber)(token);
const maybeNumber = (0, _numericLiteralsJs.tryParseWellFormedNumber)(token);
if (maybeNumber !== undefined) {

@@ -40,3 +40,3 @@ return {

}
const maybeBigint = (0, _numericLiteralsTs.tryParseWellFormedBigint)(token);
const maybeBigint = (0, _numericLiteralsJs.tryParseWellFormedBigint)(token);
if (maybeBigint !== undefined) {

@@ -43,0 +43,0 @@ return {

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

});
const _composeTs = require("../../../../nodes/compose.js");
const _rangeTs = require("../../../../nodes/rules/range.js");
const _errorsTs = require("../../../../utils/errors.js");
const _genericsTs = require("../../../../utils/generics.js");
const _numericLiteralsTs = require("../../../../utils/numericLiterals.js");
const _boundTs = require("../../../ast/bound.js");
const _sharedTs = require("../../reduce/shared.js");
const _scannerTs = require("../scanner.js");
const _composeJs = require("../../../../nodes/compose.js");
const _rangeJs = require("../../../../nodes/rules/range.js");
const _errorsJs = require("../../../../utils/errors.js");
const _genericsJs = require("../../../../utils/generics.js");
const _numericLiteralsJs = require("../../../../utils/numericLiterals.js");
const _boundJs = require("../../../ast/bound.js");
const _sharedJs = require("../../reduce/shared.js");
const _scannerJs = require("../scanner.js");
const parseBound = (s, start)=>{

@@ -32,7 +32,7 @@ const comparator = shiftComparator(s, start);

};
const shiftComparator = (s, start)=>s.scanner.lookaheadIs("=") ? `${start}${s.scanner.shift()}` : (0, _genericsTs.isKeyOf)(start, _scannerTs.Scanner.oneCharComparators) ? start : s.error(singleEqualsMessage);
const shiftComparator = (s, start)=>s.scanner.lookaheadIs("=") ? `${start}${s.scanner.shift()}` : (0, _genericsJs.isKeyOf)(start, _scannerJs.Scanner.oneCharComparators) ? start : s.error(singleEqualsMessage);
const singleEqualsMessage = `= is not a valid comparator. Use == to check for equality`;
const parseRightBound = (s, comparator)=>{
const limitToken = s.scanner.shiftUntilNextTerminator();
const limit = (0, _numericLiteralsTs.tryParseWellFormedNumber)(limitToken, writeInvalidLimitMessage(comparator, limitToken + s.scanner.unscanned));
const limit = (0, _numericLiteralsJs.tryParseWellFormedNumber)(limitToken, writeInvalidLimitMessage(comparator, limitToken + s.scanner.unscanned));
const openRange = s.ejectRangeIfOpen();

@@ -43,3 +43,3 @@ const rightBound = {

};
const range = openRange ? !hasComparatorIn(rightBound, _rangeTs.maxComparators) ? s.error((0, _sharedTs.writeUnpairableComparatorMessage)(comparator)) : (0, _rangeTs.compareStrictness)("min", openRange, rightBound) === "l" ? s.error(writeEmptyRangeMessage({
const range = openRange ? !hasComparatorIn(rightBound, _rangeJs.maxComparators) ? s.error((0, _sharedJs.writeUnpairableComparatorMessage)(comparator)) : (0, _rangeJs.compareStrictness)("min", openRange, rightBound) === "l" ? s.error(writeEmptyRangeMessage({
min: openRange,

@@ -50,7 +50,7 @@ max: rightBound

max: rightBound
} : hasComparator(rightBound, "==") ? rightBound : hasComparatorIn(rightBound, _rangeTs.minComparators) ? {
} : hasComparator(rightBound, "==") ? rightBound : hasComparatorIn(rightBound, _rangeJs.minComparators) ? {
min: rightBound
} : hasComparatorIn(rightBound, _rangeTs.maxComparators) ? {
} : hasComparatorIn(rightBound, _rangeJs.maxComparators) ? {
max: rightBound
} : (0, _errorsTs.throwInternalError)(`Unexpected comparator '${rightBound.comparator}'`);
} : (0, _errorsJs.throwInternalError)(`Unexpected comparator '${rightBound.comparator}'`);
s.intersect(distributeRange(range, s));

@@ -60,3 +60,3 @@ };

const resolution = s.resolveRoot();
const domains = (0, _genericsTs.objectKeysOf)(resolution);
const domains = (0, _genericsJs.objectKeysOf)(resolution);
const distributedRange = {};

@@ -79,3 +79,3 @@ const rangePredicate = {

}
return (0, _genericsTs.listFrom)(resolution.object).every((branch)=>"class" in branch && branch.class === Array);
return (0, _genericsJs.listFrom)(resolution.object).every((branch)=>"class" in branch && branch.class === Array);
default:

@@ -86,3 +86,3 @@ return false;

if (!isBoundable) {
s.error((0, _boundTs.writeUnboundableMessage)(s.rootToString()));
s.error((0, _boundJs.writeUnboundableMessage)(s.rootToString()));
}

@@ -94,2 +94,2 @@ return distributedRange;

const writeInvalidLimitMessage = (comparator, limit)=>`Comparator ${comparator} must be followed by a number literal (was '${limit}')`;
const writeEmptyRangeMessage = (range)=>`${(0, _composeTs.stringifyRange)(range)} is empty`;
const writeEmptyRangeMessage = (range)=>`${(0, _composeJs.stringifyRange)(range)} is empty`;

@@ -15,12 +15,12 @@ "use strict";

});
const _genericsTs = require("../../../../utils/generics.js");
const _numericLiteralsTs = require("../../../../utils/numericLiterals.js");
const _divisorTs = require("../../../ast/divisor.js");
const _genericsJs = require("../../../../utils/generics.js");
const _numericLiteralsJs = require("../../../../utils/numericLiterals.js");
const _divisorJs = require("../../../ast/divisor.js");
const parseDivisor = (s)=>{
const divisorToken = s.scanner.shiftUntilNextTerminator();
const divisor = (0, _numericLiteralsTs.tryParseWellFormedInteger)(divisorToken, writeInvalidDivisorMessage(divisorToken));
const divisor = (0, _numericLiteralsJs.tryParseWellFormedInteger)(divisorToken, writeInvalidDivisorMessage(divisorToken));
if (divisor === 0) {
s.error(writeInvalidDivisorMessage(0));
}
const rootDomains = (0, _genericsTs.objectKeysOf)(s.resolveRoot());
const rootDomains = (0, _genericsJs.objectKeysOf)(s.resolveRoot());
if (rootDomains.length === 1 && rootDomains[0] === "number") {

@@ -33,5 +33,5 @@ s.intersect({

} else {
s.error((0, _divisorTs.writeIndivisibleMessage)(s.rootToString()));
s.error((0, _divisorJs.writeIndivisibleMessage)(s.rootToString()));
}
};
const writeInvalidDivisorMessage = (divisor)=>`% operator must be followed by a non-zero integer literal (was ${divisor})`;

@@ -16,12 +16,12 @@ "use strict";

});
const _errorsTs = require("../../../../utils/errors.js");
const _genericsTs = require("../../../../utils/generics.js");
const _scannerTs = require("../scanner.js");
const _boundsTs = require("./bounds.js");
const _divisorTs = require("./divisor.js");
const _errorsJs = require("../../../../utils/errors.js");
const _genericsJs = require("../../../../utils/generics.js");
const _scannerJs = require("../scanner.js");
const _boundsJs = require("./bounds.js");
const _divisorJs = require("./divisor.js");
const parseOperator = (s)=>{
const lookahead = s.scanner.shift();
return lookahead === "" ? s.finalize() : lookahead === "[" ? s.scanner.shift() === "]" ? s.rootToArray() : s.error(incompleteArrayTokenMessage) : (0, _genericsTs.isKeyOf)(lookahead, _scannerTs.Scanner.branchTokens) ? s.pushRootToBranch(lookahead) : lookahead === ")" ? s.finalizeGroup() : (0, _genericsTs.isKeyOf)(lookahead, _scannerTs.Scanner.comparatorStartChars) ? (0, _boundsTs.parseBound)(s, lookahead) : lookahead === "%" ? (0, _divisorTs.parseDivisor)(s) : lookahead === " " ? parseOperator(s) : (0, _errorsTs.throwInternalError)(writeUnexpectedCharacterMessage(lookahead));
return lookahead === "" ? s.finalize() : lookahead === "[" ? s.scanner.shift() === "]" ? s.rootToArray() : s.error(incompleteArrayTokenMessage) : (0, _genericsJs.isKeyOf)(lookahead, _scannerJs.Scanner.branchTokens) ? s.pushRootToBranch(lookahead) : lookahead === ")" ? s.finalizeGroup() : (0, _genericsJs.isKeyOf)(lookahead, _scannerJs.Scanner.comparatorStartChars) ? (0, _boundsJs.parseBound)(s, lookahead) : lookahead === "%" ? (0, _divisorJs.parseDivisor)(s) : lookahead === " " ? parseOperator(s) : (0, _errorsJs.throwInternalError)(writeUnexpectedCharacterMessage(lookahead));
};
const writeUnexpectedCharacterMessage = (char)=>`Unexpected character '${char}'`;
const incompleteArrayTokenMessage = `Missing expected ']'`;

@@ -9,2 +9,15 @@ "use strict";

});
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
class Scanner {

@@ -45,3 +58,5 @@ /** Get lookahead and advance scanner by one */ shift() {

constructor(def){
this.finalized = false;
_defineProperty(this, "chars", void 0);
_defineProperty(this, "i", void 0);
_defineProperty(this, "finalized", false);
this.chars = [

@@ -48,0 +63,0 @@ ...def

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

});
const _nodeTs = require("../../nodes/node.js");
const _dynamicTs = require("./reduce/dynamic.js");
const _operandTs = require("./shift/operand/operand.js");
const _operatorTs = require("./shift/operator/operator.js");
const _nodeJs = require("../../nodes/node.js");
const _dynamicJs = require("./reduce/dynamic.js");
const _operandJs = require("./shift/operand/operand.js");
const _operatorJs = require("./shift/operator/operator.js");
const parseString = (def, ctx)=>ctx.type.scope.parseCache.get(def) ?? ctx.type.scope.parseCache.set(def, maybeNaiveParse(def, ctx) ?? fullStringParse(def, ctx));

@@ -29,3 +29,3 @@ const maybeNaiveParse = (def, ctx)=>{

if (ctx.type.scope.addParsedReferenceIfResolvable(def, ctx)) {
return (0, _nodeTs.toArrayNode)(elementDef);
return (0, _nodeJs.toArrayNode)(elementDef);
}

@@ -35,4 +35,4 @@ }

const fullStringParse = (def, ctx)=>{
const s = new _dynamicTs.DynamicState(def, ctx);
(0, _operandTs.parseOperand)(s);
const s = new _dynamicJs.DynamicState(def, ctx);
(0, _operandJs.parseOperand)(s);
return loop(s);

@@ -46,2 +46,2 @@ };

};
const next = (s)=>s.hasRoot() ? (0, _operatorTs.parseOperator)(s) : (0, _operandTs.parseOperand)(s);
const next = (s)=>s.hasRoot() ? (0, _operatorJs.parseOperator)(s) : (0, _operandJs.parseOperand)(s);

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

});
const _jsObjectsTs = require("./jsObjects.js");
const _scopeTs = require("./scope.js");
const _tsKeywordsTs = require("./tsKeywords.js");
const _validationTs = require("./validation/validation.js");
const arkScope = (0, _scopeTs.scope)({}, {
const _jsObjectsJs = require("./jsObjects.js");
const _scopeJs = require("./scope.js");
const _tsKeywordsJs = require("./tsKeywords.js");
const _validationJs = require("./validation/validation.js");
const arkScope = (0, _scopeJs.scope)({}, {
name: "standard",
includes: [
_tsKeywordsTs.tsKeywords,
_jsObjectsTs.jsObjects,
_validationTs.validation
_tsKeywordsJs.tsKeywords,
_jsObjectsJs.jsObjects,
_validationJs.validation
],

@@ -34,14 +34,14 @@ standard: false

const scopes = {
root: _scopeTs.rootScope,
tsKeywords: _tsKeywordsTs.tsKeywordsScope,
jsObjects: _jsObjectsTs.jsObjectsScope,
validation: _validationTs.validationScope,
root: _scopeJs.rootScope,
tsKeywords: _tsKeywordsJs.tsKeywordsScope,
jsObjects: _jsObjectsJs.jsObjectsScope,
validation: _validationJs.validationScope,
ark: arkScope
};
const spaces = {
tsKeywords: _tsKeywordsTs.tsKeywords,
jsObjects: _jsObjectsTs.jsObjects,
validation: _validationTs.validation,
tsKeywords: _tsKeywordsJs.tsKeywords,
jsObjects: _jsObjectsJs.jsObjects,
validation: _validationJs.validation,
ark
};
const type = arkScope.type;

@@ -15,3 +15,16 @@ "use strict";

});
const _freezeTs = require("../utils/freeze.js");
const _freezeJs = require("../utils/freeze.js");
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
class Cache {

@@ -32,3 +45,3 @@ get root() {

constructor(){
this.cache = {};
_defineProperty(this, "cache", {});
}

@@ -38,5 +51,5 @@ }

set(name, item) {
this.cache[name] = (0, _freezeTs.deepFreeze)(item);
this.cache[name] = (0, _freezeJs.deepFreeze)(item);
return item;
}
}

@@ -21,10 +21,10 @@ "use strict";

});
const _arkTs = require("./ark.js");
const intersection = _arkTs.scopes.ark.intersection;
const union = _arkTs.scopes.ark.union;
const arrayOf = _arkTs.scopes.ark.arrayOf;
const keyOf = _arkTs.scopes.ark.keyOf;
const instanceOf = _arkTs.scopes.ark.instanceOf;
const valueOf = _arkTs.scopes.ark.valueOf;
const narrow = _arkTs.scopes.ark.narrow;
const morph = _arkTs.scopes.ark.morph;
const _arkJs = require("./ark.js");
const intersection = _arkJs.scopes.ark.intersection;
const union = _arkJs.scopes.ark.union;
const arrayOf = _arkJs.scopes.ark.arrayOf;
const keyOf = _arkJs.scopes.ark.keyOf;
const instanceOf = _arkJs.scopes.ark.instanceOf;
const valueOf = _arkJs.scopes.ark.valueOf;
const narrow = _arkJs.scopes.ark.narrow;
const morph = _arkJs.scopes.ark.morph;

@@ -15,4 +15,4 @@ "use strict";

});
const _scopeTs = require("./scope.js");
const jsObjectsScope = (0, _scopeTs.scope)({
const _scopeJs = require("./scope.js");
const jsObjectsScope = (0, _scopeJs.scope)({
Function: [

@@ -26,10 +26,2 @@ "node",

],
Array: [
"node",
{
object: {
class: Array
}
}
],
Date: [

@@ -75,34 +67,2 @@ "node",

],
Object: [
"node",
{
object: {
class: Object
}
}
],
String: [
"node",
{
object: {
class: String
}
}
],
Number: [
"node",
{
object: {
class: Number
}
}
],
Boolean: [
"node",
{
object: {
class: Boolean
}
}
],
WeakMap: [

@@ -109,0 +69,0 @@ "node",

@@ -21,12 +21,12 @@ "use strict";

});
const _nodeTs = require("../nodes/node.js");
const _definitionTs = require("../parse/definition.js");
const _problemsTs = require("../traverse/problems.js");
const _chainableNoOpProxyTs = require("../utils/chainableNoOpProxy.js");
const _errorsTs = require("../utils/errors.js");
const _freezeTs = require("../utils/freeze.js");
const _genericsTs = require("../utils/generics.js");
const _pathsTs = require("../utils/paths.js");
const _cacheTs = require("./cache.js");
const _typeTs = require("./type.js");
const _nodeJs = require("../nodes/node.js");
const _definitionJs = require("../parse/definition.js");
const _problemsJs = require("../traverse/problems.js");
const _chainableNoOpProxyJs = require("../utils/chainableNoOpProxy.js");
const _errorsJs = require("../utils/errors.js");
const _freezeJs = require("../utils/freeze.js");
const _genericsJs = require("../utils/generics.js");
const _pathsJs = require("../utils/paths.js");
const _cacheJs = require("./cache.js");
const _typeJs = require("./type.js");
function _checkPrivateRedeclaration(obj, privateCollection) {

@@ -82,5 +82,17 @@ if (privateCollection.has(obj)) {

}
var _ctx_type, _ctx_type1;
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
const compileScopeOptions = (opts)=>({
codes: (0, _problemsTs.compileProblemWriters)(opts.codes),
codes: (0, _problemsJs.compileProblemWriters)(opts.codes),
keys: opts.keys ?? "loose"

@@ -103,2 +115,3 @@ });

addAnonymousTypeReference(referencedType, ctx) {
var _ctx_type;
(_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = referencedType.includesMorph);

@@ -108,3 +121,3 @@ return referencedType.node;

get infer() {
return _chainableNoOpProxyTs.chainableNoOpProxy;
return _chainableNoOpProxyJs.chainableNoOpProxy;
}

@@ -121,2 +134,3 @@ compile() {

addParsedReferenceIfResolvable(name, ctx) {
var _ctx_type;
const resolution = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, name, "undefined", [

@@ -128,3 +142,3 @@ name

}
(_ctx_type1 = ctx.type).includesMorph || (_ctx_type1.includesMorph = resolution.includesMorph);
(_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = resolution.includesMorph);
return true;

@@ -142,3 +156,3 @@ }

const resolution = this.resolveNode(node);
return (0, _nodeTs.isConfigNode)(resolution) ? resolution.node : resolution;
return (0, _nodeJs.isConfigNode)(resolution) ? resolution.node : resolution;
}

@@ -153,2 +167,6 @@ isResolvable(name) {

_classPrivateMethodInit(this, _resolveRecurse);
_defineProperty(this, "aliases", void 0);
_defineProperty(this, "name", void 0);
_defineProperty(this, "config", void 0);
_defineProperty(this, "parseCache", void 0);
_classPrivateFieldInit(this, _resolutions, {

@@ -162,6 +180,16 @@ writable: true,

});
_defineProperty(this, "expressions", void 0);
_defineProperty(this, "intersection", void 0);
_defineProperty(this, "union", void 0);
_defineProperty(this, "arrayOf", void 0);
_defineProperty(this, "keyOf", void 0);
_defineProperty(this, "valueOf", void 0);
_defineProperty(this, "instanceOf", void 0);
_defineProperty(this, "narrow", void 0);
_defineProperty(this, "morph", void 0);
_defineProperty(this, "type", void 0);
this.aliases = aliases;
this.parseCache = new _cacheTs.FreezingCache();
_classPrivateFieldSet(this, _resolutions, new _cacheTs.Cache());
_classPrivateFieldSet(this, _exports, new _cacheTs.Cache());
this.parseCache = new _cacheJs.FreezingCache();
_classPrivateFieldSet(this, _resolutions, new _cacheJs.Cache());
_classPrivateFieldSet(this, _exports, new _cacheJs.Cache());
this.expressions = {

@@ -218,10 +246,10 @@ intersection: (l, r, opts)=>this.type([

this.type = Object.assign((def, config = {})=>{
const t = (0, _typeTs.initializeType)("Ξ»type", def, config, this);
const t = (0, _typeJs.initializeType)("Ξ»type", def, config, this);
const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
const root = (0, _definitionTs.parseDefinition)(def, ctx);
t.node = (0, _freezeTs.deepFreeze)((0, _genericsTs.hasKeys)(config) ? {
const root = (0, _definitionJs.parseDefinition)(def, ctx);
t.node = (0, _freezeJs.deepFreeze)((0, _genericsJs.hasKeys)(config) ? {
config,
node: this.resolveTypeNode(root)
} : root);
t.flat = (0, _freezeTs.deepFreeze)((0, _nodeTs.flattenType)(t));
t.flat = (0, _freezeJs.deepFreeze)((0, _nodeJs.flattenType)(t));
return t;

@@ -247,3 +275,3 @@ }, {

function register(opts) {
const name = opts.name ? scopeRegistry[opts.name] ? (0, _errorsTs.throwParseError)(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
const name = opts.name ? scopeRegistry[opts.name] ? (0, _errorsJs.throwParseError)(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
scopeRegistry[name] = this;

@@ -256,3 +284,3 @@ return name;

if (_classPrivateFieldGet(this, _resolutions).has(name) || name in this.aliases) {
(0, _errorsTs.throwParseError)(writeDuplicateAliasesMessage(name));
(0, _errorsJs.throwParseError)(writeDuplicateAliasesMessage(name));
}

@@ -269,3 +297,3 @@ _classPrivateFieldGet(this, _resolutions).set(name, space[name]);

type,
path: new _pathsTs.Path()
path: new _pathsJs.Path()
};

@@ -280,12 +308,12 @@ }

if (!aliasDef) {
return onUnresolvable === "throw" ? (0, _errorsTs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
return onUnresolvable === "throw" ? (0, _errorsJs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
}
const t = (0, _typeTs.initializeType)(name, aliasDef, {}, this);
const t = (0, _typeJs.initializeType)(name, aliasDef, {}, this);
const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, t);
_classPrivateFieldGet(this, _resolutions).set(name, t);
_classPrivateFieldGet(this, _exports).set(name, t);
let node = (0, _definitionTs.parseDefinition)(aliasDef, ctx);
let node = (0, _definitionJs.parseDefinition)(aliasDef, ctx);
if (typeof node === "string") {
if (seen.includes(node)) {
return (0, _errorsTs.throwParseError)(writeShallowCycleErrorMessage(name, seen));
return (0, _errorsJs.throwParseError)(writeShallowCycleErrorMessage(name, seen));
}

@@ -295,4 +323,4 @@ seen.push(node);

}
t.node = (0, _freezeTs.deepFreeze)(node);
t.flat = (0, _freezeTs.deepFreeze)((0, _nodeTs.flattenType)(t));
t.node = (0, _freezeJs.deepFreeze)(node);
t.flat = (0, _freezeJs.deepFreeze)((0, _nodeJs.flattenType)(t));
return t;

@@ -299,0 +327,0 @@ }

@@ -15,3 +15,3 @@ "use strict";

});
const _scopeTs = require("./scope.js");
const _scopeJs = require("./scope.js");
const always = {

@@ -27,3 +27,3 @@ bigint: true,

};
const tsKeywordsScope = (0, _scopeTs.scope)({
const tsKeywordsScope = (0, _scopeJs.scope)({
any: [

@@ -30,0 +30,0 @@ "node",

@@ -16,4 +16,4 @@ "use strict";

});
const _traverseTs = require("../traverse/traverse.js");
const _chainableNoOpProxyTs = require("../utils/chainableNoOpProxy.js");
const _traverseJs = require("../traverse/traverse.js");
const _chainableNoOpProxyJs = require("../utils/chainableNoOpProxy.js");
const initializeType = (name, definition, config, scope)=>{

@@ -35,4 +35,4 @@ const root = {

},
infer: _chainableNoOpProxyTs.chainableNoOpProxy,
inferIn: _chainableNoOpProxyTs.chainableNoOpProxy,
infer: _chainableNoOpProxyJs.chainableNoOpProxy,
inferIn: _chainableNoOpProxyJs.chainableNoOpProxy,
qualifiedName: isAnonymousName(name) ? scope.getAnonymousQualifiedName(name) : `${scope.name}.${name}`,

@@ -46,3 +46,3 @@ definition,

const namedTraverse = {
[name]: (data)=>(0, _traverseTs.traverseRoot)(namedTraverse, data)
[name]: (data)=>(0, _traverseJs.traverseRoot)(namedTraverse, data)
}[name];

@@ -52,3 +52,3 @@ const t = Object.assign(namedTraverse, root);

};
const isType = (value)=>value?.infer === _chainableNoOpProxyTs.chainableNoOpProxy;
const isType = (value)=>value?.infer === _chainableNoOpProxyJs.chainableNoOpProxy;
const isAnonymousName = (name)=>name[0] === "Ξ»";

@@ -15,3 +15,3 @@ "use strict";

});
const _scopeTs = require("../scope.js");
const _scopeJs = require("../scope.js");
const isLuhnValid = (creditCardInput)=>{

@@ -42,3 +42,3 @@ const sanitized = creditCardInput.replace(/[- ]+/g, "");

const creditCardMatcher = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
const creditCard = (0, _scopeTs.rootType)([
const creditCard = (0, _scopeJs.rootType)([
creditCardMatcher,

@@ -45,0 +45,0 @@ "=>",

@@ -15,4 +15,4 @@ "use strict";

});
const _scopeTs = require("../scope.js");
const _tsKeywordsTs = require("../tsKeywords.js");
const _scopeJs = require("../scope.js");
const _tsKeywordsJs = require("../tsKeywords.js");
const dayDelimiterMatcher = /^[./-]$/;

@@ -56,4 +56,4 @@ // ISO 8601 date/time modernized from https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO8601.js

};
const parsedDate = (0, _scopeTs.rootType)([
_tsKeywordsTs.tsKeywords.string,
const parsedDate = (0, _scopeJs.rootType)([
_tsKeywordsJs.tsKeywords.string,
"|>",

@@ -60,0 +60,0 @@ (s, problems)=>{

@@ -15,10 +15,10 @@ "use strict";

});
const _numericLiteralsTs = require("../../utils/numericLiterals.js");
const _scopeTs = require("../scope.js");
const _tsKeywordsTs = require("../tsKeywords.js");
const _creditCardTs = require("./creditCard.js");
const _dateTs = require("./date.js");
const _numericLiteralsJs = require("../../utils/numericLiterals.js");
const _scopeJs = require("../scope.js");
const _tsKeywordsJs = require("../tsKeywords.js");
const _creditCardJs = require("./creditCard.js");
const _dateJs = require("./date.js");
// Non-trivial expressions should have an explanation or attribution
const parsedNumber = (0, _scopeTs.rootType)([
_numericLiteralsTs.wellFormedNumberMatcher,
const parsedNumber = (0, _scopeJs.rootType)([
_numericLiteralsJs.wellFormedNumberMatcher,
"|>",

@@ -29,4 +29,4 @@ (s)=>parseFloat(s)

});
const parsedInteger = (0, _scopeTs.rootType)([
_numericLiteralsTs.wellFormedIntegerMatcher,
const parsedInteger = (0, _scopeJs.rootType)([
_numericLiteralsJs.wellFormedIntegerMatcher,
"|>",

@@ -38,15 +38,15 @@ (s)=>parseInt(s)

// https://www.regular-expressions.info/email.html
const email = (0, _scopeTs.rootType)(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
const email = (0, _scopeJs.rootType)(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, {
mustBe: "a valid email"
});
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
const uuid = (0, _scopeTs.rootType)(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/, {
const uuid = (0, _scopeJs.rootType)(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/, {
mustBe: "a valid UUID"
});
// https://semver.org/
const semver = (0, _scopeTs.rootType)(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, {
const semver = (0, _scopeJs.rootType)(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/, {
mustBe: "a valid semantic version (see https://semver.org/)"
});
const json = (0, _scopeTs.rootType)([
_tsKeywordsTs.tsKeywords.string,
const json = (0, _scopeJs.rootType)([
_tsKeywordsJs.tsKeywords.string,
"|>",

@@ -57,3 +57,3 @@ (s)=>JSON.parse(s)

});
const validationScope = (0, _scopeTs.scope)({
const validationScope = (0, _scopeJs.scope)({
// Character sets

@@ -88,3 +88,3 @@ alpha: [

],
creditCard: _creditCardTs.creditCard,
creditCard: _creditCardJs.creditCard,
email,

@@ -94,3 +94,3 @@ uuid,

parsedInteger,
parsedDate: _dateTs.parsedDate,
parsedDate: _dateJs.parsedDate,
semver,

@@ -97,0 +97,0 @@ json,

@@ -22,10 +22,10 @@ "use strict";

});
const _scannerTs = require("../parse/string/shift/scanner.js");
const _dataTs = require("../utils/data.js");
const _domainsTs = require("../utils/domains.js");
const _genericsTs = require("../utils/generics.js");
const _numericLiteralsTs = require("../utils/numericLiterals.js");
const _objectKindsTs = require("../utils/objectKinds.js");
const _pathsTs = require("../utils/paths.js");
const _serializeTs = require("../utils/serialize.js");
const _scannerJs = require("../parse/string/shift/scanner.js");
const _dataJs = require("../utils/data.js");
const _domainsJs = require("../utils/domains.js");
const _genericsJs = require("../utils/generics.js");
const _numericLiteralsJs = require("../utils/numericLiterals.js");
const _objectKindsJs = require("../utils/objectKinds.js");
const _pathsJs = require("../utils/paths.js");
const _serializeJs = require("../utils/serialize.js");
function _checkPrivateRedeclaration(obj, privateCollection) {

@@ -71,5 +71,19 @@ if (privateCollection.has(obj)) {

}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
class ArkTypeError extends TypeError {
constructor(problems){
super(`${problems}`);
_defineProperty(this, "cause", void 0);
this.cause = problems;

@@ -86,3 +100,3 @@ }

get reason() {
return this.writers.writeReason(this.mustBe, new _dataTs.DataWrapper(this.data));
return this.writers.writeReason(this.mustBe, new _dataJs.DataWrapper(this.data));
}

@@ -93,2 +107,8 @@ get mustBe() {

constructor(code, path, data, source, writers){
_defineProperty(this, "code", void 0);
_defineProperty(this, "path", void 0);
_defineProperty(this, "data", void 0);
_defineProperty(this, "source", void 0);
_defineProperty(this, "writers", void 0);
_defineProperty(this, "parts", void 0);
this.code = code;

@@ -111,3 +131,3 @@ this.path = path;

// copy the path to avoid future mutations affecting it
const path = opts?.path ?? _pathsTs.Path.from(_classPrivateFieldGet(this, _state).path);
const path = opts?.path ?? _pathsJs.Path.from(_classPrivateFieldGet(this, _state).path);
const data = // we have to check for the presence of the key explicitly since the

@@ -157,4 +177,4 @@ // data could be undefined or null

super();
this.byPath = {};
this.count = 0;
_defineProperty(this, "byPath", {});
_defineProperty(this, "count", 0);
_classPrivateFieldInit(this, _state, {

@@ -169,4 +189,4 @@ writable: true,

const capitalize = (s)=>s[0].toUpperCase() + s.slice(1);
const domainsToDescriptions = (domains)=>domains.map((objectKind)=>_domainsTs.domainDescriptions[objectKind]);
const objectKindsToDescriptions = (kinds)=>kinds.map((objectKind)=>_objectKindsTs.objectKindDescriptions[objectKind]);
const domainsToDescriptions = (domains)=>domains.map((objectKind)=>_domainsJs.domainDescriptions[objectKind]);
const objectKindsToDescriptions = (kinds)=>kinds.map((objectKind)=>_objectKindsJs.objectKindDescriptions[objectKind]);
const describeBranches = (descriptions)=>{

@@ -190,3 +210,3 @@ if (descriptions.length === 0) {

const writeDefaultReason = (mustBe, was)=>`must be ${mustBe}${was && ` (was ${was})`}`;
const addDefaultContext = (reason, path)=>path.length === 0 ? capitalize(reason) : path.length === 1 && (0, _numericLiteralsTs.isWellFormedInteger)(path[0]) ? `Item at index ${path[0]} ${reason}` : `${path} ${reason}`;
const addDefaultContext = (reason, path)=>path.length === 0 ? capitalize(reason) : path.length === 1 && (0, _numericLiteralsJs.isWellFormedInteger)(path[0]) ? `Item at index ${path[0]} ${reason}` : `${path} ${reason}`;
const defaultProblemConfig = {

@@ -198,4 +218,4 @@ divisor: {

mustBe: (expected)=>{
const possibleObjectKind = (0, _objectKindsTs.getExactConstructorObjectKind)(expected);
return possibleObjectKind ? _objectKindsTs.objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`;
const possibleObjectKind = (0, _objectKindsJs.getExactConstructorObjectKind)(expected);
return possibleObjectKind ? _objectKindsJs.objectKindDescriptions[possibleObjectKind] : `an instance of ${expected.name}`;
},

@@ -205,3 +225,3 @@ writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.className)

domain: {
mustBe: (domain)=>_domainsTs.domainDescriptions[domain],
mustBe: (domain)=>_domainsJs.domainDescriptions[domain],
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, data.domain)

@@ -218,3 +238,3 @@ },

bound: {
mustBe: (bound)=>`${_scannerTs.Scanner.comparatorDescriptions[bound.comparator]} ${bound.limit}${bound.units ? ` ${bound.units}` : ""}`,
mustBe: (bound)=>`${_scannerJs.Scanner.comparatorDescriptions[bound.comparator]} ${bound.limit}${bound.units ? ` ${bound.units}` : ""}`,
writeReason: (mustBe, data)=>writeDefaultReason(mustBe, `${data.size}`)

@@ -226,3 +246,3 @@ },

value: {
mustBe: _serializeTs.stringify
mustBe: _serializeJs.stringify
},

@@ -246,3 +266,3 @@ branches: {

};
const problemCodes = (0, _genericsTs.objectKeysOf)(defaultProblemConfig);
const problemCodes = (0, _genericsJs.objectKeysOf)(defaultProblemConfig);
const compileDefaultProblemWriters = ()=>{

@@ -249,0 +269,0 @@ const result = {};

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

});
const _discriminateTs = require("../nodes/discriminate.js");
const _classTs = require("../nodes/rules/class.js");
const _divisorTs = require("../nodes/rules/divisor.js");
const _rangeTs = require("../nodes/rules/range.js");
const _regexTs = require("../nodes/rules/regex.js");
const _rulesTs = require("../nodes/rules/rules.js");
const _domainsTs = require("../utils/domains.js");
const _errorsTs = require("../utils/errors.js");
const _genericsTs = require("../utils/generics.js");
const _pathsTs = require("../utils/paths.js");
const _problemsTs = require("./problems.js");
const _discriminateJs = require("../nodes/discriminate.js");
const _classJs = require("../nodes/rules/class.js");
const _divisorJs = require("../nodes/rules/divisor.js");
const _rangeJs = require("../nodes/rules/range.js");
const _regexJs = require("../nodes/rules/regex.js");
const _rulesJs = require("../nodes/rules/rules.js");
const _domainsJs = require("../utils/domains.js");
const _errorsJs = require("../utils/errors.js");
const _genericsJs = require("../utils/generics.js");
const _pathsJs = require("../utils/paths.js");
const _problemsJs = require("./problems.js");
function _checkPrivateRedeclaration(obj, privateCollection) {

@@ -70,2 +70,15 @@ if (privateCollection.has(obj)) {

}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
const initializeTraversalConfig = ()=>({

@@ -97,2 +110,6 @@ mustBe: [],

const CheckResult = class {
constructor(){
_defineProperty(this, "data", void 0);
_defineProperty(this, "problems", void 0);
}
};

@@ -135,3 +152,3 @@ var _seen = /*#__PURE__*/ new WeakMap();

const data = this.data;
const isObject = (0, _domainsTs.hasDomain)(data, "object");
const isObject = (0, _domainsJs.hasDomain)(data, "object");
if (isObject) {

@@ -166,3 +183,3 @@ const seenByCurrentType = _classPrivateFieldGet(this, _seen)[id];

const lastProblems = this.problems;
const branchProblems = new _problemsTs.Problems(this);
const branchProblems = new _problemsJs.Problems(this);
this.problems = branchProblems;

@@ -173,3 +190,3 @@ const lastPath = this.path;

for (const branch of branches){
this.path = new _pathsTs.Path();
this.path = new _pathsJs.Path();
this.entriesToPrune = [];

@@ -189,2 +206,10 @@ if (checkEntries(branch, this)) {

constructor(data, type){
_defineProperty(this, "data", void 0);
_defineProperty(this, "type", void 0);
_defineProperty(this, "path", void 0);
_defineProperty(this, "problems", void 0);
_defineProperty(this, "entriesToPrune", void 0);
_defineProperty(this, "failFast", void 0);
_defineProperty(this, "traversalConfig", void 0);
_defineProperty(this, "rootScope", void 0);
_classPrivateFieldInit(this, _seen, {

@@ -196,4 +221,4 @@ writable: true,

this.type = type;
this.path = new _pathsTs.Path();
this.problems = new _problemsTs.Problems(this);
this.path = new _pathsJs.Path();
this.problems = new _problemsJs.Problems(this);
this.entriesToPrune = [];

@@ -206,3 +231,3 @@ this.failFast = false;

}
const traverse = (node, state)=>typeof node === "string" ? (0, _domainsTs.domainOf)(state.data) === node || !state.problems.add("domain", node) : checkEntries(node, state);
const traverse = (node, state)=>typeof node === "string" ? (0, _domainsJs.domainOf)(state.data) === node || !state.problems.add("domain", node) : checkEntries(node, state);
const checkEntries = (entries, state)=>{

@@ -218,3 +243,3 @@ let isValid = true;

}
if (i < entries.length - 1 && _rulesTs.precedenceMap[k] < _rulesTs.precedenceMap[entries[i + 1][0]]) {
if (i < entries.length - 1 && _rulesJs.precedenceMap[k] < _rulesJs.precedenceMap[entries[i + 1][0]]) {
// if we've encountered a problem, there is at least one entry

@@ -287,10 +312,10 @@ // remaining, and the next entry is of a higher precedence level

const entryCheckers = {
regex: _regexTs.checkRegex,
divisor: _divisorTs.checkDivisor,
regex: _regexJs.checkRegex,
divisor: _divisorJs.checkDivisor,
domains: (domains, state)=>{
const entries = domains[(0, _domainsTs.domainOf)(state.data)];
return entries ? checkEntries(entries, state) : !state.problems.add("cases", (0, _problemsTs.domainsToDescriptions)((0, _genericsTs.objectKeysOf)(domains)));
const entries = domains[(0, _domainsJs.domainOf)(state.data)];
return entries ? checkEntries(entries, state) : !state.problems.add("cases", (0, _problemsJs.domainsToDescriptions)((0, _genericsJs.objectKeysOf)(domains)));
},
domain: (domain, state)=>(0, _domainsTs.domainOf)(state.data) === domain || !state.problems.add("domain", domain),
bound: _rangeTs.checkBound,
domain: (domain, state)=>(0, _domainsJs.domainOf)(state.data) === domain || !state.problems.add("domain", domain),
bound: _rangeJs.checkBound,
optionalProp: (prop, state)=>{

@@ -322,10 +347,10 @@ if (prop[0] in state.data) {

switch: (rule, state)=>{
const dataAtPath = (0, _pathsTs.getPath)(state.data, rule.path);
const caseKey = (0, _discriminateTs.serializeCase)(rule.kind, dataAtPath);
if ((0, _genericsTs.hasKey)(rule.cases, caseKey)) {
const dataAtPath = (0, _pathsJs.getPath)(state.data, rule.path);
const caseKey = (0, _discriminateJs.serializeCase)(rule.kind, dataAtPath);
if ((0, _genericsJs.hasKey)(rule.cases, caseKey)) {
return checkEntries(rule.cases[caseKey], state);
}
const caseKeys = (0, _genericsTs.objectKeysOf)(rule.cases);
const caseKeys = (0, _genericsJs.objectKeysOf)(rule.cases);
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) : (0, _errorsTs.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`);
const caseDescriptions = rule.kind === "value" ? caseKeys : rule.kind === "domain" ? (0, _problemsJs.domainsToDescriptions)(caseKeys) : rule.kind === "class" ? (0, _problemsJs.objectKindsToDescriptions)(caseKeys) : (0, _errorsJs.throwInternalError)(`Unexpectedly encountered rule kind '${rule.kind}' during traversal`);
state.problems.add("cases", caseDescriptions, {

@@ -338,3 +363,3 @@ path: missingCasePath,

alias: (name, state)=>state.traverseResolution(name),
class: _classTs.checkClass,
class: _classJs.checkClass,
narrow: (narrow, state)=>{

@@ -355,3 +380,3 @@ const lastProblemsCount = state.problems.count;

}
if (out instanceof _problemsTs.Problem) {
if (out instanceof _problemsJs.Problem) {
// if a problem was returned from the morph but not added, add it

@@ -358,0 +383,0 @@ state.problems.addProblem(out);

@@ -16,4 +16,17 @@ "use strict";

});
const _domainsTs = require("./domains.js");
const _serializeTs = require("./serialize.js");
const _domainsJs = require("./domains.js");
const _serializeJs = require("./serialize.js");
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
const sizeOf = (data)=>typeof data === "string" || Array.isArray(data) ? data.length : typeof data === "number" ? data : 0;

@@ -23,6 +36,6 @@ const unitsOf = (data)=>typeof data === "string" ? "characters" : Array.isArray(data) ? "items long" : "";

toString() {
return (0, _serializeTs.stringify)(this.value);
return (0, _serializeJs.stringify)(this.value);
}
get domain() {
return (0, _domainsTs.domainOf)(this.value);
return (0, _domainsJs.domainOf)(this.value);
}

@@ -39,4 +52,5 @@ get size() {

constructor(value){
_defineProperty(this, "value", void 0);
this.value = value;
}
}

@@ -26,3 +26,3 @@ "use strict";

});
const _domainsTs = require("./domains.js");
const _domainsJs = require("./domains.js");
const asConst = (t)=>t;

@@ -55,3 +55,3 @@ const isKeyOf = (k, obj)=>k in obj;

const keyCount = (o)=>Object.keys(o).length;
const hasKeys = (value)=>(0, _domainsTs.hasDomain)(value, "object") ? Object.keys(value).length !== 0 : false;
const hasKeys = (value)=>(0, _domainsJs.hasDomain)(value, "object") ? Object.keys(value).length !== 0 : false;
const id = Symbol("id");

@@ -61,3 +61,3 @@ const nominal = (o, name)=>Object.assign(o, {

});
const getNominalId = (data)=>(0, _domainsTs.hasDomain)(data, "object") && id in data ? data[id] : undefined;
const getNominalId = (data)=>(0, _domainsJs.hasDomain)(data, "object") && id in data ? data[id] : undefined;
const hasNominalId = (data, name)=>getNominalId(data) === name;

@@ -64,0 +64,0 @@ const listFrom = (data)=>Array.isArray(data) ? data : [

@@ -21,3 +21,3 @@ "use strict";

});
const _errorsTs = require("./errors.js");
const _errorsJs = require("./errors.js");
const wellFormedNumberMatcher = /^(?!^-0$)-?(?:0|[1-9]\d*)(?:\.\d*[1-9])?$/;

@@ -52,6 +52,6 @@ const isWellFormedNumber = (s)=>wellFormedNumberMatcher.test(s);

// not well-formed, always throw.
return (0, _errorsTs.throwParseError)(writeMalformedNumericLiteralMessage(token, kind));
return (0, _errorsJs.throwParseError)(writeMalformedNumericLiteralMessage(token, kind));
}
}
return errorOnFail ? (0, _errorsTs.throwParseError)(errorOnFail === true ? `Failed to parse ${numericLiteralDescriptions[kind]} from '${token}'` : errorOnFail) : undefined;
return errorOnFail ? (0, _errorsJs.throwParseError)(errorOnFail === true ? `Failed to parse ${numericLiteralDescriptions[kind]} from '${token}'` : errorOnFail) : undefined;
};

@@ -75,4 +75,4 @@ const tryParseWellFormedBigint = (def)=>{

// not well-formed, throw.
return (0, _errorsTs.throwParseError)(writeMalformedNumericLiteralMessage(def, "bigint"));
return (0, _errorsJs.throwParseError)(writeMalformedNumericLiteralMessage(def, "bigint"));
}
};

@@ -19,4 +19,4 @@ "use strict";

});
const _domainsTs = require("./domains.js");
const _genericsTs = require("./generics.js");
const _domainsJs = require("./domains.js");
const _genericsJs = require("./generics.js");
const defaultObjectKinds = {

@@ -39,3 +39,3 @@ Array,

const objectKindOf = (data, kinds)=>{
if ((0, _domainsTs.domainOf)(data) !== "object") {
if ((0, _domainsJs.domainOf)(data) !== "object") {
return undefined;

@@ -70,3 +70,3 @@ }

const constructorName = Object(constructor).name;
return constructorName && (0, _genericsTs.isKeyOf)(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === constructor ? constructorName : undefined;
return constructorName && (0, _genericsJs.isKeyOf)(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === constructor ? constructorName : undefined;
};

@@ -17,8 +17,8 @@ "use strict";

});
const _domainsTs = require("./domains.js");
const _genericsTs = require("./generics.js");
const _numericLiteralsTs = require("./numericLiterals.js");
const _domainsJs = require("./domains.js");
const _genericsJs = require("./generics.js");
const _numericLiteralsJs = require("./numericLiterals.js");
const snapshot = (data, opts = {})=>serializeRecurse(data, opts, []);
const stringify = (data, indent)=>{
switch((0, _domainsTs.domainOf)(data)){
switch((0, _domainsJs.domainOf)(data)){
case "object":

@@ -38,3 +38,3 @@ return JSON.stringify(serializeRecurse(data, stringifyOpts, []), null, indent);

const serializeRecurse = (data, context, seen)=>{
switch((0, _domainsTs.domainOf)(data)){
switch((0, _domainsJs.domainOf)(data)){
case "object":

@@ -70,3 +70,3 @@ if (typeof data === "function") {

const serializePrimitive = (value)=>typeof value === "string" ? `'${value}'` : typeof value === "bigint" ? `${value}n` : `${value}`;
const deserializePrimitive = (serialized)=>(0, _genericsTs.isKeyOf)(serialized, serializedKeywords) ? serializedKeywords[serialized] : serialized[0] === "'" ? serialized.slice(1, -1) : (0, _numericLiteralsTs.tryParseWellFormedBigint)(serialized) ?? (0, _numericLiteralsTs.tryParseWellFormedNumber)(serialized, true);
const deserializePrimitive = (serialized)=>(0, _genericsJs.isKeyOf)(serialized, serializedKeywords) ? serializedKeywords[serialized] : serialized[0] === "'" ? serialized.slice(1, -1) : (0, _numericLiteralsJs.tryParseWellFormedBigint)(serialized) ?? (0, _numericLiteralsJs.tryParseWellFormedNumber)(serialized, true);
const serializedKeywords = {

@@ -73,0 +73,0 @@ true: true,

export { scope } from "./scopes/scope.js";
export { type, ark, arkScope } from "./scopes/ark.js";
export { intersection, union, arrayOf, instanceOf, valueOf, morph, narrow, keyOf } from "./scopes/expressions.js";
export { arrayOf, instanceOf, intersection, keyOf, morph, narrow, union, valueOf } from "./scopes/expressions.js";
export { jsObjectsScope } from "./scopes/jsObjects.js";

@@ -8,1 +8,2 @@ export { tsKeywordsScope } from "./scopes/tsKeywords.js";

export { Problems, Problem } from "./traverse/problems.js";
export { parseConfigTuple } from "./parse/ast/config.js";

@@ -41,2 +41,15 @@ function _checkPrivateRedeclaration(obj, privateCollection) {

}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
import { throwInternalError } from "../utils/errors.js";

@@ -73,2 +86,6 @@ import { objectKeysOf } from "../utils/generics.js";

constructor(type, lastOperator){
_defineProperty(this, "type", void 0);
_defineProperty(this, "lastOperator", void 0);
_defineProperty(this, "path", void 0);
_defineProperty(this, "domain", void 0);
_classPrivateFieldInit(this, _disjoints, {

@@ -75,0 +92,0 @@ writable: true,

import { parseDefinition } from "../definition.js";
export const parseConfigTuple = (def, ctx)=>({
/**
* @operator {@link parseConfigTuple | :}
* @docgenTable
* @tuple ["type", ":", config]
*/ export const parseConfigTuple = (def, ctx)=>({
node: ctx.type.scope.resolveTypeNode(parseDefinition(def[0], ctx)),
config: def[2]
});

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

var _keyNode, _keyType, _keyNode1, _keyNode2;
import { mappedKeys } from "../../nodes/rules/props.js";

@@ -34,2 +33,3 @@ import { throwInternalError } from "../../utils/errors.js";

if (keyType === "string" || keyType === "number" || keyType === "symbol") {
var _keyNode, _keyType;
(_keyNode = keyNode)[_keyType = keyType] ?? (_keyNode[_keyType] = []);

@@ -40,2 +40,3 @@ keyNode[keyType].push({

} else if (key === wellFormedNonNegativeIntegerMatcher) {
var _keyNode1, _keyNode2;
(_keyNode1 = keyNode).string ?? (_keyNode1.string = []);

@@ -42,0 +43,0 @@ keyNode.string.push(arrayIndexStringBranch);

@@ -45,4 +45,3 @@ import { isType } from "../scopes/type.js";

export const as = Symbol("as");
export const unknownDefinitionMessage = "Cannot statically parse a definition inferred as unknown. Consider using 'as Infer<...>' to cast it.";
const isThunk = (def)=>typeof def === "function" && def.length === 0;
export const writeBadDefinitionTypeMessage = (actual)=>`Type definitions must be strings or objects (was ${actual})`;

@@ -0,1 +1,14 @@

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
import { isLiteralNode, rootIntersection, rootUnion, toArrayNode } from "../../../nodes/node.js";

@@ -133,2 +146,7 @@ import { minComparators } from "../../../nodes/rules/range.js";

constructor(def, ctx){
_defineProperty(this, "ctx", void 0);
_defineProperty(this, "scanner", void 0);
_defineProperty(this, "root", void 0);
_defineProperty(this, "branches", void 0);
_defineProperty(this, "groups", void 0);
this.ctx = ctx;

@@ -135,0 +153,0 @@ this.branches = {};

@@ -0,1 +1,14 @@

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
export class Scanner {

@@ -36,3 +49,5 @@ /** Get lookahead and advance scanner by one */ shift() {

constructor(def){
this.finalized = false;
_defineProperty(this, "chars", void 0);
_defineProperty(this, "i", void 0);
_defineProperty(this, "finalized", false);
this.chars = [

@@ -39,0 +54,0 @@ ...def

@@ -0,1 +1,14 @@

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
import { deepFreeze } from "../utils/freeze.js";

@@ -17,3 +30,3 @@ export class Cache {

constructor(){
this.cache = {};
_defineProperty(this, "cache", {});
}

@@ -20,0 +33,0 @@ }

import { scopes } from "./ark.js";
export const intersection = scopes.ark.intersection;
export const union = scopes.ark.union;
export const arrayOf = scopes.ark.arrayOf;
export const keyOf = scopes.ark.keyOf;
export const instanceOf = scopes.ark.instanceOf;
export const valueOf = scopes.ark.valueOf;
export const narrow = scopes.ark.narrow;
export const morph = scopes.ark.morph;
/**
* @operator {@link intersection | &}
* @docgenTable
* @string "L&R"
* @tuple [L, "&", R]
* @helper intersection(L,R)
* @example string
* const intersection = type("/@arktype\.io$/ & email")
* @example tuple
* const tupleIntersection = type(["/@arktype\.io$/", "&", "email"])
* @example helper
* const helperIntersection = intersection("/@arktype\.io$/","email")
*/ export const intersection = scopes.ark.intersection;
/**
* @operator {@link union | |}
* @docgenTable
* @string "L|R"
* @tuple [L, "|" , R]
* @helper union(L,R)
* @example string
* const union = type("string|number")
* @example tuple
* const tupleUnion = type(["string", "|", "number"])
* @example helper
* const helperUnion = union("string", "number")
*/ export const union = scopes.ark.union;
/**
* @operator {@link arrayOf}
* @docgenTable
* @string "T[]"
* @tuple [T, "[]"]
* @helper arrayOf(T)
* @example string
* const numberArray = type("number[]")
* @example tuple
* const tupleArray = type(["number", "[]"])
* @example helper
* const helperArray = arrayOf("number")
*/ export const arrayOf = scopes.ark.arrayOf;
/**
* @operator {@link keyOf}
* @docgenTable
* @tuple "["keyOf", T]"
* @helper keyOf(T)
* @example tuple
* const tupleKeyOf = type(["keyOf", {a:"string"}])
* @example helper
* const helperKeyOf = keyOf({a:"string"})
*/ export const keyOf = scopes.ark.keyOf;
/**
* @operator {@link instanceOf}
* @docgenTable
* @tuple ["instanceOf", T]
* @helper instanceOf(T)
* @example tuple
* const tupleInstanceOf = type(["instanceOf", Date])
* @example helper
* const helperInstanceOf = instanceOf(Date)
*/ export const instanceOf = scopes.ark.instanceOf;
/**
* @operator {@link valueOf | ===}
* @docgenTable
* @tuple ["===", T]
* @helper valueOf(T)
* @example tuple
* const tupleValueOf = type(["valueOf", {a:"string"}])
* @example helper
* const helperValueOf = valueOf({a:"string"})
*/ export const valueOf = scopes.ark.valueOf;
/**
* @operator {@link narrow | =>}
* @docgenTable
* @tuple ["type", "=>" , condition]
* @example tuple
* const narrow = type( ["number", "=>" , (n) => n % 2 === 0])
* @example
* const isEven = (x: unknown): x is number => x % 2 === 0
*/ export const narrow = scopes.ark.narrow;
/**
* @operator {@link morph | |>}
* @docgenTable
* @tuple [inputType, "|>", (data) => output]
* @helper morph(inputType, (data) => output)
* @example tuple
* const tupleMorph = type( ["string", "|>" , (data) => `morphed ${data}`])
* @example helper
* const helperMorph = morph("string", (data) => `morphed ${data}`)
*/ export const morph = scopes.ark.morph;
import { scope } from "./scope.js";
/**
* @scope
* @docgenScope
* @docgenTable
*/ export const jsObjectsScope = scope({

@@ -13,10 +14,2 @@ Function: [

],
Array: [
"node",
{
object: {
class: Array
}
}
],
Date: [

@@ -62,34 +55,2 @@ "node",

],
Object: [
"node",
{
object: {
class: Object
}
}
],
String: [
"node",
{
object: {
class: String
}
}
],
Number: [
"node",
{
object: {
class: Number
}
}
],
Boolean: [
"node",
{
object: {
class: Boolean
}
}
],
WeakMap: [

@@ -96,0 +57,0 @@ "node",

@@ -51,3 +51,15 @@ function _checkPrivateRedeclaration(obj, privateCollection) {

}
var _ctx_type, _ctx_type1;
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
import { flattenType, isConfigNode } from "../nodes/node.js";

@@ -82,2 +94,3 @@ import { parseDefinition } from "../parse/definition.js";

addAnonymousTypeReference(referencedType, ctx) {
var _ctx_type;
(_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = referencedType.includesMorph);

@@ -99,2 +112,3 @@ return referencedType.node;

addParsedReferenceIfResolvable(name, ctx) {
var _ctx_type;
const resolution = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, name, "undefined", [

@@ -106,3 +120,3 @@ name

}
(_ctx_type1 = ctx.type).includesMorph || (_ctx_type1.includesMorph = resolution.includesMorph);
(_ctx_type = ctx.type).includesMorph || (_ctx_type.includesMorph = resolution.includesMorph);
return true;

@@ -130,2 +144,6 @@ }

_classPrivateMethodInit(this, _resolveRecurse);
_defineProperty(this, "aliases", void 0);
_defineProperty(this, "name", void 0);
_defineProperty(this, "config", void 0);
_defineProperty(this, "parseCache", void 0);
_classPrivateFieldInit(this, _resolutions, {

@@ -139,2 +157,12 @@ writable: true,

});
_defineProperty(this, "expressions", void 0);
_defineProperty(this, "intersection", void 0);
_defineProperty(this, "union", void 0);
_defineProperty(this, "arrayOf", void 0);
_defineProperty(this, "keyOf", void 0);
_defineProperty(this, "valueOf", void 0);
_defineProperty(this, "instanceOf", void 0);
_defineProperty(this, "narrow", void 0);
_defineProperty(this, "morph", void 0);
_defineProperty(this, "type", void 0);
this.aliases = aliases;

@@ -141,0 +169,0 @@ this.parseCache = new FreezingCache();

@@ -27,3 +27,4 @@ import { scope } from "./scope.js";

"undefined": "undefined"}
* @scope
* @docgenScope
* @docgenTable
*/ export const tsKeywordsScope = scope({

@@ -30,0 +31,0 @@ any: [

@@ -56,3 +56,4 @@ import { wellFormedIntegerMatcher, wellFormedNumberMatcher } from "../../utils/numericLiterals.js";

}
* @scope
* @docgenScope
* @docgenTable
*/ export const validationScope = scope({

@@ -59,0 +60,0 @@ // Character sets

@@ -41,2 +41,15 @@ function _checkPrivateRedeclaration(obj, privateCollection) {

}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
import { Scanner } from "../parse/string/shift/scanner.js";

@@ -53,2 +66,3 @@ import { DataWrapper } from "../utils/data.js";

super(`${problems}`);
_defineProperty(this, "cause", void 0);
this.cause = problems;

@@ -71,2 +85,8 @@ }

constructor(code, path, data, source, writers){
_defineProperty(this, "code", void 0);
_defineProperty(this, "path", void 0);
_defineProperty(this, "data", void 0);
_defineProperty(this, "source", void 0);
_defineProperty(this, "writers", void 0);
_defineProperty(this, "parts", void 0);
this.code = code;

@@ -134,4 +154,4 @@ this.path = path;

super();
this.byPath = {};
this.count = 0;
_defineProperty(this, "byPath", {});
_defineProperty(this, "count", 0);
_classPrivateFieldInit(this, _state, {

@@ -138,0 +158,0 @@ writable: true,

@@ -41,2 +41,15 @@ function _checkPrivateRedeclaration(obj, privateCollection) {

}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
import { serializeCase } from "../nodes/discriminate.js";

@@ -79,2 +92,6 @@ import { checkClass } from "../nodes/rules/class.js";

const CheckResult = class {
constructor(){
_defineProperty(this, "data", void 0);
_defineProperty(this, "problems", void 0);
}
};

@@ -168,2 +185,10 @@ var _seen = /*#__PURE__*/ new WeakMap();

constructor(data, type){
_defineProperty(this, "data", void 0);
_defineProperty(this, "type", void 0);
_defineProperty(this, "path", void 0);
_defineProperty(this, "problems", void 0);
_defineProperty(this, "entriesToPrune", void 0);
_defineProperty(this, "failFast", void 0);
_defineProperty(this, "traversalConfig", void 0);
_defineProperty(this, "rootScope", void 0);
_classPrivateFieldInit(this, _seen, {

@@ -170,0 +195,0 @@ writable: true,

@@ -0,1 +1,14 @@

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
import { domainOf } from "./domains.js";

@@ -22,4 +35,5 @@ import { stringify } from "./serialize.js";

constructor(value){
_defineProperty(this, "value", void 0);
this.value = value;
}
}
export { scope } from "./scopes/scope.js";
export { type, ark, arkScope } from "./scopes/ark.js";
export type { Infer } from "./parse/definition.js";
export { intersection, union, arrayOf, instanceOf, valueOf, morph, narrow, keyOf } from "./scopes/expressions.js";
export type { Scope, Space } from "./scopes/scope.js";
export { arrayOf, instanceOf, intersection, keyOf, morph, narrow, union, valueOf } from "./scopes/expressions.js";
export { jsObjectsScope } from "./scopes/jsObjects.js";

@@ -11,1 +11,5 @@ export { tsKeywordsScope } from "./scopes/tsKeywords.js";

export { Problems, Problem } from "./traverse/problems.js";
export { parseConfigTuple } from "./parse/ast/config.js";
export type { validateBound } from "./parse/ast/bound.js";
export type { validateDivisor } from "./parse/ast/divisor.js";
export type { ResolvedNode } from "./nodes/node.js";

@@ -12,2 +12,8 @@ import type { ParseContext } from "../parse/definition.js";

export type Identifier<$ = Dict> = stringKeyOf<$>;
/**
* @operator {@link ResolvedNode | node}
* @docgenTable
* @tuple ["node", nodeDefinition]
* @helper type.from(nodeDefinition)
*/
export type ResolvedNode<$ = Dict> = TypeNode<$> | ConfigNode<$>;

@@ -14,0 +20,0 @@ export type ConfigNode<$ = Dict> = {

@@ -6,2 +6,16 @@ import type { SizedData } from "../../utils/data.js";

import type { astToString } from "./utils.js";
/**
* @operator {@link validateBound | bound}
* @docgenTable
* * @tableRow N number literal
* @tableRow S sized data (a number, string or array)
* @tableRow < Comparator (one of <, <=, ==, >=, >)
* @description
* Bound operators allow data to be bounded in the format "S<N", or as a Range: "N<S<N", with comparators restricted to < or <=
* @string "N<S<N", with comparators restricted to < or <=
* @example string
* const range = type("2<=number<5")
* @example string
* const bound = type("string[]==5")
*/
export type validateBound<l, r, $> = l extends NumberLiteral ? validateAst<r, $> : isBoundable<inferAst<l, $>> extends true ? validateAst<l, $> : error<writeUnboundableMessage<astToString<l>>>;

@@ -8,0 +22,0 @@ type isBoundable<data> = isAny<data> extends true ? false : [data] extends [SizedData] ? true : false;

@@ -5,2 +5,7 @@ import type { TypeOptions } from "../../scopes/type.js";

export type ConfigTuple<def = unknown, config extends TypeOptions = TypeOptions> = readonly [def, ":", config];
/**
* @operator {@link parseConfigTuple | :}
* @docgenTable
* @tuple ["type", ":", config]
*/
export declare const parseConfigTuple: PostfixParser<":">;

@@ -7,0 +12,0 @@ export type validateConfigTuple<def extends TupleExpression, $> = readonly [

import type { error, isAny } from "../../utils/generics.js";
import type { inferAst, validateAst } from "./ast.js";
import type { astToString } from "./utils.js";
/**
* @operator {@link validateDivisor | %}
* @docgenTable
* @string "N%D", where "N" is a number and "D" is a non-zero integer
*/
export type validateDivisor<l, $> = isDivisible<inferAst<l, $>> extends true ? validateAst<l, $> : error<writeIndivisibleMessage<astToString<l>>>;

@@ -5,0 +10,0 @@ type isDivisible<data> = isAny<data> extends true ? false : [data] extends [number] ? true : false;

@@ -5,3 +5,3 @@ import type { Node } from "../nodes/node.js";

import { domainOf } from "../utils/domains.js";
import type { Dict, evaluate, isAny, isUnknown, List } from "../utils/generics.js";
import type { Dict, evaluate, isAny, isUnknown, List, stringKeyOf } from "../utils/generics.js";
import { objectKindOf } from "../utils/objectKinds.js";

@@ -19,6 +19,4 @@ import type { Path } from "../utils/paths.js";

export type inferDefinition<def, $> = isAny<def> extends true ? never : def extends Infer<infer t> | InferredThunk<infer t> ? t : def extends string ? inferString<def, $> : def extends List ? inferTuple<def, $> : def extends RegExp ? string : def extends Dict ? inferRecord<def, $> : never;
export type validateDefinition<def, $> = [def] extends [(...args: any[]) => any] ? def : [def] extends [Terminal] ? def : [def] extends [string] ? validateString<def, $> : [def] extends [TupleExpression] ? validateTupleExpression<def, $> : [def] extends [BadDefinitionType] ? writeBadDefinitionTypeMessage<objectKindOf<def> extends string ? objectKindOf<def> : domainOf<def>> : isUnknown<def> extends true ? unknownDefinitionMessage : [def] extends [readonly unknown[]] ? {
export type validateDefinition<def, $> = [def] extends [(...args: any[]) => any] ? def : def extends Terminal ? def : def extends string ? validateString<def, $> : def extends TupleExpression ? validateTupleExpression<def, $> : def extends BadDefinitionType ? writeBadDefinitionTypeMessage<objectKindOf<def> extends string ? objectKindOf<def> : domainOf<def>> : isUnknown<def> extends true ? stringKeyOf<$> : evaluate<{
[k in keyof def]: validateDefinition<def[k], $>;
} : evaluate<{
[k in keyof def]: validateDefinition<def[k], $>;
}>;

@@ -29,4 +27,2 @@ export declare const as: unique symbol;

};
export declare const unknownDefinitionMessage = "Cannot statically parse a definition inferred as unknown. Consider using 'as Infer<...>' to cast it.";
export type unknownDefinitionMessage = typeof unknownDefinitionMessage;
type InferredThunk<t = unknown> = () => Infer<t>;

@@ -33,0 +29,0 @@ type Terminal = RegExp | Infer<unknown> | InferredThunk;

import type { MaxComparator, MinComparator } from "../../../nodes/rules/range.js";
import type { defined, error } from "../../../utils/generics.js";
import type { NumberLiteral } from "../../../utils/numericLiterals.js";
import type { astToString } from "../../ast/utils.js";
import type { Scanner } from "../shift/scanner.js";

@@ -11,2 +10,3 @@ import type { unclosedGroupMessage, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";

groups: BranchState[];
scanned: string;
unscanned: string;

@@ -28,2 +28,3 @@ };

groups: [];
scanned: "";
unscanned: def;

@@ -36,2 +37,3 @@ }>;

}>;
type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
export type setRoot<s extends StaticState, root, unscanned extends string> = from<{

@@ -41,2 +43,3 @@ root: root;

groups: s["groups"];
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;

@@ -52,2 +55,3 @@ }>;

groups: s["groups"];
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;

@@ -66,2 +70,3 @@ }>;

groups: s["groups"];
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;

@@ -77,2 +82,3 @@ }> : error<writeUnpairableComparatorMessage<comparator>>;

groups: s["groups"];
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;

@@ -88,2 +94,3 @@ }>;

groups: s["groups"];
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;

@@ -101,2 +108,3 @@ }>;

root: mergeToUnion<s>;
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;

@@ -108,2 +116,3 @@ }> : error<writeUnmatchedGroupCloseMessage<unscanned>>;

root: undefined;
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;

@@ -115,2 +124,3 @@ }>;

branches: initialBranches;
scanned: s["scanned"];
unscanned: Scanner.finalized;

@@ -124,5 +134,5 @@ }> : error<unclosedGroupMessage>;

groups: s["groups"];
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
unscanned: unscanned;
}>;
export type toString<s extends StaticState> = astToString<mergeToUnion<s>>;
export type from<s extends StaticState> = s;

@@ -129,0 +139,0 @@ export type branchesFrom<b extends BranchState> = b;

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

import type { error } from "../../../../utils/generics.js";
import type { error, stringKeyOf } from "../../../../utils/generics.js";
import type { DynamicState } from "../../reduce/dynamic.js";

@@ -7,4 +7,4 @@ import type { state, StaticState } from "../../reduce/static.js";

import { parseEnclosed } from "./enclosed.js";
import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
import { parseUnenclosed } from "./unenclosed.js";
export declare const parseOperand: (s: DynamicState) => void;
export type parseOperand<s extends StaticState, $> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingChar ? parseEnclosed<s, lookahead, unscanned> : lookahead extends " " ? parseOperand<state.scanTo<s, unscanned>, $> : parseUnenclosed<s, $> : error<writeMissingOperandMessage<s>>;
export type parseOperand<s extends StaticState, $> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingChar ? parseEnclosed<s, lookahead, unscanned> : lookahead extends " " ? parseOperand<state.scanTo<s, unscanned>, $> : parseUnenclosed<s, $> : error<`${s["scanned"]}${stringKeyOf<$>}`>;

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

import type { error, stringKeyOf } from "../../../../utils/generics.js";
import type { error } from "../../../../utils/generics.js";
import type { BigintLiteral, NumberLiteral } from "../../../../utils/numericLiterals.js";

@@ -8,12 +8,12 @@ import type { DynamicState } from "../../reduce/dynamic.js";

export type parseUnenclosed<s extends StaticState, $> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? tryResolve<s, scanned, $> extends infer result ? result extends error<infer message> ? error<message> : state.setRoot<s, result, nextUnscanned> : never : never;
export type isResolvableIdentifier<token, $> = token extends stringKeyOf<$> ? true : false;
type tryResolve<s extends StaticState, token extends string, $> = isResolvableIdentifier<token, $> extends true ? token : token extends NumberLiteral ? token : token extends BigintLiteral ? token : error<token extends "" ? writeMissingOperandMessage<s> : writeUnresolvableMessage<token>>;
type tryResolve<s extends StaticState, token extends string, $> = token extends keyof $ ? token : token extends NumberLiteral ? token : token extends BigintLiteral ? token : possibleCompletions<s, token, $>;
export type possibleCompletions<s extends StaticState, token extends string, $> = Extract<keyof $, `${token}${string}`> extends never ? error<writeUnresolvableMessage<token>> : error<`${s["scanned"]}${Extract<keyof $, `${token}${string}`>}`>;
export declare const writeUnresolvableMessage: <token extends string>(token: token) => `'${token}' is unresolvable`;
type writeUnresolvableMessage<token extends string> = `'${token}' is unresolvable`;
export declare const writeMissingOperandMessage: <s extends DynamicState>(s: s) => `Token '|' requires a right operand before '${string}'` | `Token '&' requires a right operand before '${string}'` | `Expected an expression before '${string}'`;
export declare const writeMissingOperandMessage: <s extends DynamicState>(s: s) => string;
export type writeMissingOperandMessage<s extends StaticState, operator extends Scanner.InfixToken | undefined = state.previousOperator<s>> = operator extends {} ? writeMissingRightOperandMessage<operator, s["unscanned"]> : writeExpressionExpectedMessage<s["unscanned"]>;
export type writeMissingRightOperandMessage<token extends Scanner.InfixToken, unscanned extends string> = `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
export declare const writeMissingRightOperandMessage: <token extends Scanner.InfixToken, unscanned extends string>(token: token, unscanned: unscanned) => `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => string;
export type writeExpressionExpectedMessage<unscanned extends string> = `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
export {};

@@ -7,3 +7,2 @@ import type { error } from "../../utils/generics.js";

import { parseOperand } from "./shift/operand/operand.js";
import type { isResolvableIdentifier } from "./shift/operand/unenclosed.js";
import { parseOperator } from "./shift/operator/operator.js";

@@ -18,3 +17,3 @@ import type { Scanner } from "./shift/scanner.js";

*/
type maybeNaiveParse<def extends string, $> = def extends `${infer child}[]` ? isResolvableIdentifier<child, $> extends true ? [child, "[]"] : fullStringParse<def, $> : isResolvableIdentifier<def, $> extends true ? def : fullStringParse<def, $>;
type maybeNaiveParse<def extends string, $> = def extends `${infer child}[]` ? child extends keyof $ ? [child, "[]"] : fullStringParse<def, $> : def extends keyof $ ? def : fullStringParse<def, $>;
export declare const maybeNaiveParse: (def: string, ctx: ParseContext) => string | import("../../nodes/node.js").ResolvedNode<import("../../utils/generics.js").Dict> | undefined;

@@ -21,0 +20,0 @@ export declare const fullStringParse: (def: string, ctx: ParseContext) => import("../../nodes/node.js").Node;

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

import type { InferredObjectKinds } from "../utils/objectKinds.js";
import type { Space } from "./scope.js";

@@ -20,3 +19,2 @@ import type { TypeParser } from "./type.js";

Function: (...args: any[]) => unknown;
Array: unknown[];
Date: Date;

@@ -27,6 +25,2 @@ Error: Error;

Set: Set<unknown>;
Object: Record<string, unknown>;
String: String;
Number: Number;
Boolean: Boolean;
WeakMap: WeakMap<object, unknown>;

@@ -70,3 +64,2 @@ WeakSet: WeakSet<object>;

Function: (...args: any[]) => unknown;
Array: unknown[];
Date: Date;

@@ -77,6 +70,2 @@ Error: Error;

Set: Set<unknown>;
Object: Record<string, unknown>;
String: String;
Number: Number;
Boolean: Boolean;
WeakMap: WeakMap<object, unknown>;

@@ -117,3 +106,2 @@ WeakSet: WeakSet<object>;

Function: (...args: any[]) => unknown;
Array: unknown[];
Date: Date;

@@ -124,6 +112,2 @@ Error: Error;

Set: Set<unknown>;
Object: Record<string, unknown>;
String: String;
Number: Number;
Boolean: Boolean;
WeakMap: WeakMap<object, unknown>;

@@ -166,3 +150,2 @@ WeakSet: WeakSet<object>;

Function: (...args: any[]) => unknown;
Array: unknown[];
Date: Date;

@@ -173,6 +156,2 @@ Error: Error;

Set: Set<unknown>;
Object: Record<string, unknown>;
String: String;
Number: Number;
Boolean: Boolean;
WeakMap: WeakMap<object, unknown>;

@@ -227,3 +206,12 @@ WeakSet: WeakSet<object>;

parsedDate: (In: string) => Date;
} & InferredObjectKinds;
Function: (...args: any[]) => unknown;
Date: Date;
Error: Error;
Map: Map<unknown, unknown>;
RegExp: RegExp;
Set: Set<unknown>;
WeakMap: WeakMap<object, unknown>;
WeakSet: WeakSet<object>;
Promise: Promise<unknown>;
};
export declare const type: TypeParser<PrecompiledDefaults>;

@@ -21,9 +21,97 @@ import type { distributable } from "../parse/ast/distributableFunction.js";

type Ark = Expressions<PrecompiledDefaults>;
/**
* @operator {@link intersection | &}
* @docgenTable
* @string "L&R"
* @tuple [L, "&", R]
* @helper intersection(L,R)
* @example string
* const intersection = type("/@arktype\.io$/ & email")
* @example tuple
* const tupleIntersection = type(["/@arktype\.io$/", "&", "email"])
* @example helper
* const helperIntersection = intersection("/@arktype\.io$/","email")
*/
export declare const intersection: Ark["intersection"];
/**
* @operator {@link union | |}
* @docgenTable
* @string "L|R"
* @tuple [L, "|" , R]
* @helper union(L,R)
* @example string
* const union = type("string|number")
* @example tuple
* const tupleUnion = type(["string", "|", "number"])
* @example helper
* const helperUnion = union("string", "number")
*/
export declare const union: Ark["union"];
/**
* @operator {@link arrayOf}
* @docgenTable
* @string "T[]"
* @tuple [T, "[]"]
* @helper arrayOf(T)
* @example string
* const numberArray = type("number[]")
* @example tuple
* const tupleArray = type(["number", "[]"])
* @example helper
* const helperArray = arrayOf("number")
*/
export declare const arrayOf: Ark["arrayOf"];
/**
* @operator {@link keyOf}
* @docgenTable
* @tuple "["keyOf", T]"
* @helper keyOf(T)
* @example tuple
* const tupleKeyOf = type(["keyOf", {a:"string"}])
* @example helper
* const helperKeyOf = keyOf({a:"string"})
*/
export declare const keyOf: Ark["keyOf"];
/**
* @operator {@link instanceOf}
* @docgenTable
* @tuple ["instanceOf", T]
* @helper instanceOf(T)
* @example tuple
* const tupleInstanceOf = type(["instanceOf", Date])
* @example helper
* const helperInstanceOf = instanceOf(Date)
*/
export declare const instanceOf: Ark["instanceOf"];
/**
* @operator {@link valueOf | ===}
* @docgenTable
* @tuple ["===", T]
* @helper valueOf(T)
* @example tuple
* const tupleValueOf = type(["valueOf", {a:"string"}])
* @example helper
* const helperValueOf = valueOf({a:"string"})
*/
export declare const valueOf: Ark["valueOf"];
/**
* @operator {@link narrow | =>}
* @docgenTable
* @tuple ["type", "=>" , condition]
* @example tuple
* const narrow = type( ["number", "=>" , (n) => n % 2 === 0])
* @example
* const isEven = (x: unknown): x is number => x % 2 === 0
*/
export declare const narrow: Ark["narrow"];
/**
* @operator {@link morph | |>}
* @docgenTable
* @tuple [inputType, "|>", (data) => output]
* @helper morph(inputType, (data) => output)
* @example tuple
* const tupleMorph = type( ["string", "|>" , (data) => `morphed ${data}`])
* @example helper
* const helperMorph = morph("string", (data) => `morphed ${data}`)
*/
export declare const morph: Ark["morph"];

@@ -30,0 +118,0 @@ export type BinaryExpressionParser<$, operator extends "&" | "|"> = {

/**
* @scope
* @docgenScope
* @docgenTable
*/
export declare const jsObjectsScope: import("./scope.js").Scope<[{
Function: (...args: any[]) => unknown;
Array: unknown[];
Date: Date;

@@ -12,6 +12,2 @@ Error: Error;

Set: Set<unknown>;
Object: Record<string, unknown>;
String: String;
Number: Number;
Boolean: Boolean;
WeakMap: WeakMap<object, unknown>;

@@ -23,3 +19,2 @@ WeakSet: WeakSet<object>;

Function: (...args: any[]) => unknown;
Array: unknown[];
Date: Date;

@@ -30,6 +25,2 @@ Error: Error;

Set: Set<unknown>;
Object: Record<string, unknown>;
String: String;
Number: Number;
Boolean: Boolean;
WeakMap: WeakMap<object, unknown>;

@@ -36,0 +27,0 @@ WeakSet: WeakSet<object>;

@@ -16,3 +16,4 @@ /**

"undefined": "undefined"}
* @scope
* @docgenScope
* @docgenTable
*/

@@ -19,0 +20,0 @@ export declare const tsKeywordsScope: import("./scope.js").Scope<[{

@@ -17,3 +17,4 @@ /**

}
* @scope
* @docgenScope
* @docgenTable
*/

@@ -20,0 +21,0 @@ export declare const validationScope: import("../scope.js").Scope<[{

@@ -91,3 +91,3 @@ export declare const asConst: <t>(t: { [k in keyof t]: t[k] extends [] | Literalable ? t[k] : t[k] extends infer T ? { [k_1 in keyof T]: t[k][k_1] extends [] | Literalable ? t[k][k_1] : t[k][k_1] extends infer T_1 ? { [k_2 in keyof T_1]: t[k][k_1][k_2] extends [] | Literalable ? t[k][k_1][k_2] : t[k][k_1][k_2] extends infer T_2 ? { [k_3 in keyof T_2]: t[k][k_1][k_2][k_3] extends [] | Literalable ? t[k][k_1][k_2][k_3] : t[k][k_1][k_2][k_3] extends infer T_3 ? { [k_4 in keyof T_3]: t[k][k_1][k_2][k_3][k_4] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4] : t[k][k_1][k_2][k_3][k_4] extends infer T_4 ? { [k_5 in keyof T_4]: t[k][k_1][k_2][k_3][k_4][k_5] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5] : t[k][k_1][k_2][k_3][k_4][k_5] extends infer T_5 ? { [k_6 in keyof T_5]: t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6] : t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends infer T_6 ? { [k_7 in keyof T_6]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends infer T_7 ? { [k_8 in keyof T_7]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends infer T_8 ? { [k_9 in keyof T_8]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends infer T_9 ? { [k_10 in keyof T_9]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] : any; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; }) => { [k in keyof t]: t[k] extends [] | Literalable ? t[k] : t[k] extends infer T ? { [k_1 in keyof T]: t[k][k_1] extends [] | Literalable ? t[k][k_1] : t[k][k_1] extends infer T_1 ? { [k_2 in keyof T_1]: t[k][k_1][k_2] extends [] | Literalable ? t[k][k_1][k_2] : t[k][k_1][k_2] extends infer T_2 ? { [k_3 in keyof T_2]: t[k][k_1][k_2][k_3] extends [] | Literalable ? t[k][k_1][k_2][k_3] : t[k][k_1][k_2][k_3] extends infer T_3 ? { [k_4 in keyof T_3]: t[k][k_1][k_2][k_3][k_4] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4] : t[k][k_1][k_2][k_3][k_4] extends infer T_4 ? { [k_5 in keyof T_4]: t[k][k_1][k_2][k_3][k_4][k_5] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5] : t[k][k_1][k_2][k_3][k_4][k_5] extends infer T_5 ? { [k_6 in keyof T_5]: t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6] : t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends infer T_6 ? { [k_7 in keyof T_6]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends infer T_7 ? { [k_8 in keyof T_7]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends infer T_8 ? { [k_9 in keyof T_8]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends infer T_9 ? { [k_10 in keyof T_9]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] : any; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; };

export type coalesce<t, fallback> = t extends {} ? t : fallback;
export type error<message extends string = string> = nominal<`!${message}`, "error">;
export type error<message extends string = string> = `!${message}`;
export type castOnError<t, to> = isTopType<t> extends true ? t : t extends never ? t : t extends error ? to : t;

@@ -94,0 +94,0 @@ export type tryCatch<t, onValid> = isAny<t> extends true ? onValid : t extends never ? onValid : t extends error ? t : onValid;

{
"name": "arktype",
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
"version": "1.0.10-alpha",
"version": "1.0.11-alpha",
"author": {

@@ -34,14 +34,14 @@ "name": "David Blass",

"devDependencies": {
"@changesets/cli": "2.26.0",
"@changesets/changelog-github": "0.4.8",
"@changesets/cli": "2.26.1",
"@swc/cli": "0.1.62",
"@swc/core": "1.3.35",
"@swc/core": "1.3.42",
"@types/mocha": "10.0.1",
"@types/node": "18.14.0",
"@typescript-eslint/eslint-plugin": "5.53.0",
"@typescript-eslint/parser": "5.53.0",
"@types/node": "18.15.5",
"@typescript-eslint/eslint-plugin": "5.56.0",
"@typescript-eslint/parser": "5.56.0",
"c8": "7.13.0",
"eslint": "8.34.0",
"eslint-config-prettier": "8.6.0",
"eslint-define-config": "1.15.0",
"eslint": "8.36.0",
"eslint-config-prettier": "8.8.0",
"eslint-define-config": "1.17.0",
"eslint-import-resolver-typescript": "3.5.3",

@@ -51,13 +51,13 @@ "eslint-plugin-import": "2.27.5",

"eslint-plugin-prefer-arrow": "1.2.3",
"eslint-plugin-unicorn": "45.0.2",
"fast-check": "3.6.3",
"eslint-plugin-unicorn": "46.0.0",
"fast-check": "3.7.1",
"get-current-line": "6.6.0",
"husky": "8.0.3",
"mocha": "10.2.0",
"prettier": "2.8.4",
"prettier": "2.8.6",
"prettier-plugin-jsdoc": "0.4.2",
"pretty-quick": "3.1.3",
"ts-morph": "17.0.1",
"ts-morph": "18.0.0",
"ts-node": "10.9.1",
"typescript": "5.0.1-rc",
"typescript": "5.0.3",
"zod": "3.21.4"

@@ -104,7 +104,6 @@ },

"tnt": "ts-node ./dev/attest/cli.ts --coverage --skipTypes --cmd mocha",
"testRepo": " pnpm testBuild && pnpm testTsVersions && pnpm testAttest && pnpm testDeno",
"testRepo": " pnpm testBuild && pnpm testTsVersions && pnpm testAttest",
"testBuild": "ts-node ./dev/scripts/testBuild.ts",
"testAttest": "ts-node ./dev/scripts/testAttest.ts",
"testTsVersions": "ts-node ./dev/scripts/testTsVersions.ts",
"testDeno": "deno test -c ./dev/configs/deno.jsonc --no-check --allow-all --no-npm -- --skipTypes",
"bench": "ts-node ./dev/attest/cli.ts bench --benchmarksPath ./test/benchmarks.json",

@@ -111,0 +110,0 @@ "lint": "eslint --max-warnings=0 .",

@@ -22,3 +22,3 @@ <h1 align="center">ArkType <sub><sup>TypeScript's 1:1 validator</sup></sub></h1>

```ts @blockFrom:dev/examples/type.ts
import { type } from "arktype"
import { type } from "../../src/main.js"

@@ -56,6 +56,6 @@ // Definitions are statically parsed and inferred as TS.

<img src="./dev/arktype.io/static/img/deno.svg" alt="Deno Icon" height="16px" /> <code>import { type } from "https://deno.land/x/arktype/main.ts"</code>
Our types are tested in [strict-mode](https://www.typescriptlang.org/tsconfig#strict) with TypeScript versions `4.8`, `4.9`, and `5.0`.
If you're using VSCode, setting `"editor.quickSuggestions"` to `{"strings": true}` will improve its autocomplete suggestions.
_Our APIs have mostly stabilized, but details may still change during the alpha/beta stages of our 1.0 release. If you have suggestions that may require a breaking change, now is the time to let us know!_ β›΅

@@ -70,3 +70,3 @@

```ts @blockFrom:dev/examples/scope.ts
import { scope } from "arktype"
import { scope } from "../../src/main.js"

@@ -111,2 +111,20 @@ // Scopes are collections of types that can reference each other.

## Integrations
### tRPC
ArkType can easily be used with tRPC via the `assert` prop:
```ts
...
t.procedure
.input(
type({
name: "string",
"age?": "number"
}).assert
)
...
```
## How?

@@ -113,0 +131,0 @@

Sorry, the diff of this file is not supported yet

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