@freeword/meta
Version:
Meta package for Freeword: exports all core types, constants, and utilities from the src/ directory.
123 lines • 7.94 kB
JavaScript
import _ /**/ from 'lodash';
import { decorate, throwable } from "../utils/UF.js";
import { Z, ensureDescribed } from "./ZodInternal.js";
import * as CheckerTypers from "./ZodTypeguards.js";
import * as Checks from "../checks/internal.js";
import { ZMakers, isDuration, isLuxontime,
//
addrpart, alnum, alnumbar, anybag, anything, asciish, azalnum, azalnumbar, bareint, became, before, bigint, bigstr, blobbish, bool, boolish, boolstr, brandcode, brandname, byte, camel, ccmasked, city, colname, company, country, countryCode, crDT, crISO, crTC, crTS, currency, days, dashlabel, deliveryHints, distance, dotfield, duration, duration2obj, duration2str, email, emoji, expiresDT, expiresISO, expiresTC, expiresTS, extkey, extkeyish, exturi, family, familyName, ffmt, fieldname, firstName, float, fmt, fullname, fullstr, func, func0args, func1arg, funcAnyargs, funcOrKey, funcPassthru, futurism, givenName, guidv4, guidv4TT, handle, handleish, hexcolor, hexrange, hostPortPair, hostPortStr, hostname, hostorip, hours, hrutc, httpMETHOD, httpMethod, id26, idk, idkbag, idkstr, imageOrUrl, imageStub, image_path, int32, int64, intstr, ipv4host, ipv6host, iso, isodate, isodur, isodur_str, isonearfut, isonowish, isotime, isoymd, isoymdhms, iterfunc, jsdate, keyish, label, lastName, lat, liveurl, lng, loalnumbar, loazalnumbar, locamel, lodotfield, longtitle, loosetime, lower, luxontime, mashword, masked_num, maskedccnum, medstr, middleName, millis, minutc, minutes, modern, moneyish, monthday, monthnum, months, namepart, namespace, namestr, nearfuttc, nearfutts, nearpastts, neartc, nearts, nearyear, nickname, notOK, noteish, notestr, notnil, notund, num, numstr, ok, orig, parsedUrlpath, pctcode, phone, phrasetag, place_stub, plain, plainwords, plan, poBox, portnum, postcode, price, pricestr, pts_stub, pxdim, qtdotfield, qtystr, quantity, quarters, refreshedDT, refreshedISO, refreshedTC, refreshedTS, reg, regexp, regexstr, roundingstrat, rqDT, rqISO, rqTC, rqTS, safeint, safenum, seconds, secutc, shortstr, sintstr, snake, snumstr, sortdir, sstrint, sstrnum, str, strToHostPort, stradd1, stradd2, strcase, stringish, strint, strnum, strset, tagsegs, tax_rate, tblname, textish, timecode, timestamp, timevals, titleish, tkvDT, tkvISO, tkvTC, tkvTS, trimmed, trimpolice, tstype, typenamestr, ubux, uint32, uint64, uintstr, ulid, unk, unkbag, unumstr, upDT, upISO, upTC, upTS, upalnumbar, upazalnum, upazalnumbar, upper, urlOrPathToLiveurl, urlobj, urlpath, urlstr, ustrint, ustrnum, varname, weeks, whim, yayOK, years, znever,
// paste newly added checks here and in the right group below
absglob, abspath, anyfext, anyglob, anypath, awsregion, bareglob, barename, baseglob, basename, comprfext, dirent, extglob, extname, fext, globseg, ino, knownfext, logger, loglevel, pathseg, pathseglist, pathsegs, relglob, relpath, s3Bucket, stream, } from "../checks/internal.js";
export const StrChecks = {
addrpart, alnum, alnumbar, asciish, azalnum, azalnumbar,
bigstr, blobbish, brandcode, brandname, camel, ccmasked,
city, colname, company, crISO, crTC, dashlabel, deliveryHints,
dotfield, email, emoji, expiresISO, expiresTC, extkey,
extkeyish, exturi, family, familyName, fieldname, firstName,
fmt, fullname, fullstr, givenName, guidv4, guidv4TT,
handle, handleish, hexcolor, hexrange, hostPortStr, hostname,
hostorip, id26, idkstr, image_path, intstr, ipv4host,
ipv6host, iso, isodate, isodur_str, isonearfut, isonowish,
isotime, isoymd, isoymdhms, keyish, label, lastName,
loalnumbar, loazalnumbar, locamel, lodotfield, longtitle, lower,
mashword, masked_num, maskedccnum, medstr, middleName, moneyish,
namepart, namespace, namestr, nearfuttc, neartc, nickname,
noteish, notestr, numstr, orig, pctcode, phone,
phrasetag, plain, plan, poBox, postcode, pricestr,
qtdotfield, qtystr, refreshedISO, refreshedTC, reg, regexstr,
rqISO, rqTC, shortstr, sintstr, snake, snumstr,
str, stradd1, stradd2, stringish, tagsegs, tax_rate,
tblname, textish, timecode, titleish, tkvISO, tkvTC,
trimmed, trimpolice, tstype, typenamestr, uintstr, ulid,
unumstr, upISO, upTC, upalnumbar, upazalnum, upazalnumbar,
upper, urlstr, varname, whim,
//
absglob, abspath, anyglob, anypath, bareglob, barename, baseglob, basename,
extglob, extname, globseg, pathseg, pathsegs, relglob, relpath, s3Bucket,
anyfext,
};
export const OneofChecks = {
became, before, country, countryCode, currency, ffmt,
futurism, httpMETHOD, httpMethod, roundingstrat, sortdir, strcase,
awsregion, loglevel,
comprfext, fext, knownfext,
};
// const ZodtypedOneofChecks = {
// agtname, boxname, reponame, agtnick, appnick, appname, boxkind, reponick,
// }
// _.merge(OneofChecks, ZodtypedOneofChecks)
export const ObjChecks = {
imageStub, place_stub, price, pts_stub, timevals,
};
export const ZodTypedObjChecks = {};
_.merge(ObjChecks, ZodTypedObjChecks);
export const NumChecks = {
bareint, byte, crTS, days, distance, expiresTS,
float, hours, hrutc, int32, int64, lat,
lng, millis, minutc, minutes, monthday, monthnum,
months, nearfutts, nearpastts, nearts, nearyear, num,
portnum, pxdim, quantity, quarters, refreshedTS, rqTS,
safeint, safenum, seconds, secutc, sstrint, sstrnum,
strint, strnum, timestamp, tkvTS, ubux, uint32,
uint64, upTS, ustrint, ustrnum, weeks, years,
ino,
};
// export const ZodTypedNumChecks = {
// appnum,
// } as const
// _.merge(NumChecks, ZodTypedNumChecks)
export const BoolChecks = {
bool, boolish, boolstr, ok,
};
export const OtherChecks = {
anybag, anything, bigint, crDT, duration, duration2obj,
duration2str, expiresDT, func, func0args, func1arg, funcAnyargs,
funcOrKey, funcPassthru, hostPortPair, idk, idkbag, imageOrUrl,
isodur, iterfunc, jsdate, liveurl, loosetime, luxontime,
modern, notOK, notnil, notund, parsedUrlpath, plainwords,
refreshedDT, regexp, rqDT, strToHostPort, strset, tkvDT,
unk, unkbag, upDT, urlobj, urlpath, urlOrPathToLiveurl,
yayOK, znever,
dirent, logger, pathseglist,
stream,
// appnick, boxname, agtname, reponame, appnum,
};
// export const StringishChecks = { ...StrChecks, ...OneofChecks } as const satisfies PartialBag<keyof typeof Checks, ZodStringish | ZodEnum<StrArrNZ>>
export const Zcheckers = {
...StrChecks, ...OneofChecks, ...NumChecks, ...BoolChecks, ...ObjChecks, ...OtherChecks,
...ZodTypedObjChecks, // ...ZodtypedOneofChecks, ...ZodTypedNumChecks,
}; // satisfies Record<keyof typeof Zcheckers, ZodTypeAny>
// Combine the Makers (obj, arr, etc), the utils (zShape, ...) and the Shapers (quantity, safeint, ...)
export const ZodFood = {
...Zcheckers, ...ZMakers,
isDuration, isLuxontime,
}; // satisfies ZcheckersT & ZMakersT
// Call this with a
export function Validator(shaper) {
// const shapes: ZOT = shaper(ZodFood)
// return _.mapValues(shapes, (shape) => Z.object(shape)) as Zodified<KT, ZOT>
const lintbag = {};
const raws = shaper(ZodFood);
const validator = _.mapValues(raws, (zcheck, checkname) => {
if (!CheckerTypers.isChecker(zcheck)) {
lintbag[checkname] = `Validator got ${checkname}, but it is not a checker -- maybe it's missing or needs an obj() wrapper?`;
}
return ensureDescribed(zcheck, checkname);
});
// if (! _.isEmpty(lintbag)) { throw BadValue({ ...lintbag }, validator) }
if (!_.isEmpty(lintbag)) {
throw throwable(`Validation issue`, 'invalid', { ...lintbag });
}
return validator;
}
Validator.Checks = Zcheckers;
Validator.Zods = ZodFood;
Validator.Z = Z;
Validator.CheckerTypers = CheckerTypers;
decorate(Validator, {
StrChecks, OneofChecks, NumChecks, BoolChecks, ObjChecks, OtherChecks,
ZodTypedObjChecks, // ZodtypedOneofChecks
});
//
export default Validator;
//# sourceMappingURL=Validator.js.map