decoders 2.2.0 → 2.3.0-test2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +14 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +13 -15
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -519,10 +519,6 @@ function prep(mapperFn, decoder) {
|
|
|
519
519
|
return r.ok ? r : err2(public_annotate(originalInput, r.error.text));
|
|
520
520
|
});
|
|
521
521
|
}
|
|
522
|
-
function never(msg) {
|
|
523
|
-
return define((_, __, err2) => err2(msg));
|
|
524
|
-
}
|
|
525
|
-
var fail = never;
|
|
526
522
|
|
|
527
523
|
// src/lib/unions.ts
|
|
528
524
|
var EITHER_PREFIX = "Either:\n";
|
|
@@ -572,14 +568,10 @@ function taggedUnion(field, mapping2) {
|
|
|
572
568
|
}
|
|
573
569
|
|
|
574
570
|
// src/lib/basics.ts
|
|
575
|
-
var null_ =
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
(blob, ok2, err2) => blob === void 0 ? ok2(blob) : err2("Must be undefined")
|
|
580
|
-
);
|
|
581
|
-
var undefined_or_null = define(
|
|
582
|
-
(blob, ok2, err2) => blob === void 0 || blob === null ? ok2(blob) : (
|
|
571
|
+
var null_ = constant(null);
|
|
572
|
+
var undefined_ = constant(void 0);
|
|
573
|
+
var nullish_ = define(
|
|
574
|
+
(blob, ok2, err2) => blob == null ? ok2(blob) : (
|
|
583
575
|
// Combine error message into a single line for readability
|
|
584
576
|
err2("Must be undefined or null")
|
|
585
577
|
)
|
|
@@ -592,13 +584,14 @@ function nullable(decoder, defaultValue) {
|
|
|
592
584
|
const rv = either(null_, decoder);
|
|
593
585
|
return arguments.length >= 2 ? rv.transform((value) => _nullishCoalesce(value, () => ( lazyval(defaultValue)))) : rv;
|
|
594
586
|
}
|
|
595
|
-
|
|
596
|
-
|
|
587
|
+
var maybe = nullish;
|
|
588
|
+
function nullish(decoder, defaultValue) {
|
|
589
|
+
const rv = either(nullish_, decoder);
|
|
597
590
|
return arguments.length >= 2 ? rv.transform((value) => _nullishCoalesce(value, () => ( lazyval(defaultValue)))) : rv;
|
|
598
591
|
}
|
|
599
592
|
function constant(value) {
|
|
600
593
|
return define(
|
|
601
|
-
(blob, ok2, err2) => blob === value ? ok2(value) : err2(`Must be
|
|
594
|
+
(blob, ok2, err2) => blob === value ? ok2(value) : err2(`Must be ${JSON.stringify(value)}`)
|
|
602
595
|
);
|
|
603
596
|
}
|
|
604
597
|
function always(value) {
|
|
@@ -606,6 +599,10 @@ function always(value) {
|
|
|
606
599
|
typeof value === "function" ? (_, ok2) => ok2(value()) : (_, ok2) => ok2(value)
|
|
607
600
|
);
|
|
608
601
|
}
|
|
602
|
+
function never(msg) {
|
|
603
|
+
return define((_, __, err2) => err2(msg));
|
|
604
|
+
}
|
|
605
|
+
var fail = never;
|
|
609
606
|
var hardcoded = always;
|
|
610
607
|
var unknown2 = define((blob, ok2, _) => ok2(blob));
|
|
611
608
|
var mixed = unknown2;
|
|
@@ -819,5 +816,6 @@ var json = either(
|
|
|
819
816
|
|
|
820
817
|
|
|
821
818
|
|
|
822
|
-
|
|
819
|
+
|
|
820
|
+
exports.always = always; exports.anyNumber = anyNumber; exports.array = array2; exports.boolean = boolean; exports.constant = constant; exports.date = date; exports.define = define; exports.dict = dict; exports.either = either; exports.email = email; exports.err = err; exports.exact = exact; exports.fail = fail; exports.formatInline = formatInline; exports.formatShort = formatShort; exports.hardcoded = hardcoded; exports.httpsUrl = httpsUrl; exports.inexact = inexact; exports.instanceOf = instanceOf; exports.integer = integer; exports.iso8601 = iso8601; exports.json = json; exports.jsonArray = jsonArray; exports.jsonObject = jsonObject; exports.lazy = lazy; exports.mapping = mapping; exports.maybe = maybe; exports.mixed = mixed; exports.never = never; exports.nonEmptyArray = nonEmptyArray; exports.nonEmptyString = nonEmptyString; exports.null_ = null_; exports.nullable = nullable; exports.nullish = nullish; exports.number = number; exports.numericBoolean = numericBoolean; exports.object = object2; exports.ok = ok; exports.oneOf = oneOf; exports.optional = optional; exports.poja = poja; exports.pojo = pojo; exports.positiveInteger = positiveInteger; exports.positiveNumber = positiveNumber; exports.prep = prep; exports.regex = regex; exports.set = set; exports.string = string; exports.taggedUnion = taggedUnion; exports.truthy = truthy; exports.tuple = tuple; exports.undefined_ = undefined_; exports.unknown = unknown2; exports.url = url; exports.uuid = uuid; exports.uuidv1 = uuidv1; exports.uuidv4 = uuidv4;
|
|
823
821
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/_utils.ts","../src/annotate.ts","../src/format.ts","../src/result.ts","../src/Decoder.ts","../src/lib/objects.ts","../src/lib/utilities.ts","../src/lib/unions.ts","../src/lib/basics.ts","../src/lib/arrays.ts","../src/lib/numbers.ts","../src/lib/booleans.ts","../src/lib/strings.ts","../src/lib/dates.ts","../src/lib/json.ts"],"names":["ann","err","value","ok","object","mapping","unknown","array","regex","date"],"mappings":";AAIO,IAAM,SAAS;AAEf,SAAS,QAAW,OAAyB;AAClD,SAAO,OAAO,UAAU,aAAc,MAAkB,IAAI;AAC9D;AAKO,SAAS,SAA2B,IAAY,IAAoB;AACzE,QAAM,SAAS,oBAAI,IAAO;AAC1B,aAAW,KAAK,IAAI;AAClB,QAAI,CAAC,GAAG,IAAI,CAAC,GAAG;AACd,aAAO,IAAI,CAAC;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,OAAO,OAA6B;AAQlD,SAAO,CAAC,CAAC,SACP,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,mBAC1C,CAAC,MAAM,KAAe,IACnB,QACD;AACN;AAEO,SAAS,OAAO,OAAkD;AACvE,SACE,UAAU,QACV,UAAU,UACV,OAAO,UAAU;AAAA;AAAA,EAG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,QAAyB;AAAA;AAAA,EAEpC;AAAA,EACA;AACF;AAKO,IAAM,MAAoB;AAAA,EAC/B,MAAM,QAAQ,aAAa,EAAE,UAAU,CAAC,UAAU,IAAI,IAAI,KAAK,CAAC;AAAA,EAChE,WAAW,GAAG;AAChB;AAMO,IAAM,WAAyB,IAAI;AAAA,EACxC,CAAC,UAAU,MAAM,aAAa;AAAA,EAC9B;AACF;AAOO,IAAM,OAAwB;AAAA,EACnC;AAAA,EACA;AACF;AAOO,IAAM;AAAA;AAAA,EAEX,KAAK,OAAO,CAAC,UAAU,MAAM,EAAE,MAAM,KAAK,gBAAgB;AAAA;AAOrD,IAAM;AAAA;AAAA,EAEX,KAAK,OAAO,CAAC,UAAU,MAAM,EAAE,MAAM,KAAK,gBAAgB;AAAA;;;AC/E5D,IAAM,aACJ;AAKK,IAAM,OAAsB,OAAO,CAAC,MAAML,KAAIF,SAAQ;AAC3D,QAAMQ,QAAO,OAAO,IAAI;AACxB,SAAOA,UAAS,OAAON,IAAGM,KAAI,IAAIR,KAAI,gBAAgB;AACxD,CAAC;AASM,IAAM;AAAA;AAAA,EAEX,MAAM,YAAY,wBAAwB,EAAE;AAAA;AAAA,IAE1C,CAAC,UAAkB;AACjB,YAAMQ,QAAO,IAAI,KAAK,KAAK;AAC3B,UAAI,MAAMA,MAAK,QAAQ,CAAC,GAAG;AACzB,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,aAAOA;AAAA,IACT;AAAA,EACF;AAAA;;;ACpBK,IAAM,aAAkC,KAAK,MAAM,KAAK,IAAI,CAAC;AAK7D,IAAM,YAAgC,KAAK,MAAMF,OAAM,IAAI,CAAC;AAkB5D,IAAM,OAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,SAAS,0BAA0B","sourcesContent":["import type { Annotation } from './annotate';\nimport type { Scalar } from './Decoder';\n\n// Two spaces of indentation\nexport const INDENT = ' ';\n\nexport function lazyval<V>(value: (() => V) | V): V {\n return typeof value === 'function' ? (value as () => V)() : value;\n}\n\n/**\n * Subtract two sets. Why isn't this a standard method on Sets?\n */\nexport function subtract<C extends Scalar>(xs: Set<C>, ys: Set<C>): Set<C> {\n const result = new Set<C>();\n for (const x of xs) {\n if (!ys.has(x)) {\n result.add(x);\n }\n }\n return result;\n}\n\n/**\n * Is value is a valid Date instance, then return that. If not, then return\n * null.\n */\nexport function asDate(value: unknown): Date | null {\n //\n // `x instanceof Date` checks are unreliable across stack frames (that\n // information might get lost by the JS runtime), so we'll have to reside\n // to more runtime inspection checks.\n //\n // Taken from https://stackoverflow.com/a/44198641\n //\n return !!value &&\n Object.prototype.toString.call(value) === '[object Date]' &&\n !isNaN(value as number)\n ? (value as Date)\n : null;\n}\n\nexport function isPojo(value: unknown): value is Record<string, unknown> {\n return (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n // This still seems to be the only reliable way to determine whether\n // something is a pojo... ¯\\_(ツ)_/¯\n Object.prototype.toString.call(value) === '[object Object]'\n );\n}\n\nexport function isMultiline(s: string): boolean {\n return s.indexOf('\\n') >= 0;\n}\n\nexport function indent(s: string, prefix: string = INDENT): string {\n if (isMultiline(s)) {\n return s\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n');\n } else {\n return `${prefix}${s}`;\n }\n}\n\n/**\n * Walks the annotation tree and emits the annotation's key path within the\n * object tree, and the message as a series of messages (array of strings).\n */\nexport function summarize(\n ann: Annotation,\n keypath: readonly (number | string)[] = [],\n): string[] {\n const result: string[] = [];\n\n if (ann.type === 'array') {\n const items = ann.items;\n let index = 0;\n for (const ann of items) {\n for (const item of summarize(ann, [...keypath, index++])) {\n // Collect to results\n result.push(item);\n }\n }\n } else if (ann.type === 'object') {\n const fields = ann.fields;\n for (const key of Object.keys(fields)) {\n const value = fields[key];\n for (const item of summarize(value, [...keypath, key])) {\n // Collect to results\n result.push(item);\n }\n }\n }\n\n const text = ann.text;\n if (!text) {\n return result;\n }\n\n let prefix: string;\n if (keypath.length === 0) {\n prefix = '';\n } else if (keypath.length === 1) {\n prefix =\n typeof keypath[0] === 'number'\n ? `Value at index ${keypath[0]}: `\n : `Value at key ${JSON.stringify(keypath[0])}: `;\n } else {\n prefix = `Value at keypath ${keypath.map(String).join('.')}: `;\n }\n return [...result, `${prefix}${text}`];\n}\n","import { isPojo } from './_utils';\n\nconst _register: WeakSet<Annotation> = new WeakSet();\n\nexport interface ObjectAnnotation {\n readonly type: 'object';\n readonly fields: { readonly [key: string]: Annotation };\n readonly text?: string;\n}\n\nexport interface ArrayAnnotation {\n readonly type: 'array';\n readonly items: readonly Annotation[];\n readonly text?: string;\n}\n\nexport interface ScalarAnnotation {\n readonly type: 'scalar';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport interface FunctionAnnotation {\n readonly type: 'function';\n readonly text?: string;\n}\n\nexport interface CircularRefAnnotation {\n readonly type: 'circular-ref';\n readonly text?: string;\n}\n\nexport interface UnknownAnnotation {\n readonly type: 'unknown';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport type Annotation =\n | ObjectAnnotation\n | ArrayAnnotation\n | ScalarAnnotation\n | FunctionAnnotation\n | CircularRefAnnotation\n | UnknownAnnotation;\n\nfunction brand<A extends Annotation>(ann: A): A {\n _register.add(ann);\n return ann;\n}\n\nexport function object(\n fields: { readonly [key: string]: Annotation },\n text?: string,\n): ObjectAnnotation {\n return brand({ type: 'object', fields, text });\n}\n\nexport function array(items: readonly Annotation[], text?: string): ArrayAnnotation {\n return brand({\n type: 'array',\n items,\n text,\n });\n}\n\nexport function func(text?: string): FunctionAnnotation {\n return brand({\n type: 'function',\n text,\n });\n}\n\nexport function unknown(value: unknown, text?: string): UnknownAnnotation {\n return brand({\n type: 'unknown',\n value,\n text,\n });\n}\n\nexport function scalar(value: unknown, text?: string): ScalarAnnotation {\n return brand({\n type: 'scalar',\n value,\n text,\n });\n}\n\nexport function circularRef(text?: string): CircularRefAnnotation {\n return brand({\n type: 'circular-ref',\n text,\n });\n}\n\n/**\n * Given an existing Annotation, set the annotation's text to a new value.\n */\nexport function updateText<A extends Annotation>(annotation: A, text?: string): A {\n if (text !== undefined) {\n return brand({ ...annotation, text });\n } else {\n return annotation;\n }\n}\n\n/**\n * Given an existing ObjectAnnotation, merges new Annotations in there.\n */\nexport function merge(\n objAnnotation: ObjectAnnotation,\n fields: { readonly [key: string]: Annotation },\n): ObjectAnnotation {\n const newFields = { ...objAnnotation.fields, ...fields };\n return object(newFields, objAnnotation.text);\n}\n\nexport function asAnnotation(thing: unknown): Annotation | undefined {\n return typeof thing === 'object' && thing !== null && _register.has(thing as Annotation)\n ? (thing as Annotation)\n : undefined;\n}\n\ntype RefSet = WeakSet<object>;\n\n/** @internal */\nfunction annotateArray(\n value: readonly unknown[],\n text: string | undefined,\n seen: RefSet,\n): ArrayAnnotation | CircularRefAnnotation {\n seen.add(value);\n\n const items = value.map((v) => annotate(v, undefined, seen));\n return array(items, text);\n}\n\n/** @internal */\nfunction annotateObject(\n obj: Record<string, unknown>,\n text: string | undefined,\n seen: RefSet,\n): ObjectAnnotation {\n seen.add(obj);\n\n const fields: Record<string, Annotation> = {};\n for (const key of Object.keys(obj)) {\n const value = obj[key];\n fields[key] = annotate(value, undefined, seen);\n }\n return object(fields, text);\n}\n\n/** @internal */\nfunction annotate(value: unknown, text: string | undefined, seen: RefSet): Annotation {\n if (\n value === null ||\n value === undefined ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'symbol' ||\n typeof (value as Record<string, unknown>).getMonth === 'function'\n ) {\n return scalar(value, text);\n }\n\n const ann = asAnnotation(value);\n if (ann) {\n return updateText(ann, text);\n }\n\n if (Array.isArray(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateArray(value, text, seen);\n }\n }\n\n if (isPojo(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateObject(value, text, seen);\n }\n }\n\n if (typeof value === 'function') {\n return func(text);\n }\n\n return unknown(value, text);\n}\n\nfunction public_annotate(value: unknown, text?: string): Annotation {\n return annotate(value, text, new WeakSet());\n}\n\nfunction public_annotateObject(\n obj: { readonly [field: string]: unknown },\n text?: string,\n): ObjectAnnotation {\n return annotateObject(obj, text, new WeakSet());\n}\n\nexport {\n // This construct just ensures the \"seen\" weakmap (used for circular\n // reference detection) isn't made part of the public API.\n public_annotate as annotate,\n public_annotateObject as annotateObject,\n\n /** @internal */\n annotate as __private_annotate,\n};\n","import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils';\nimport type { Annotation, ArrayAnnotation, ObjectAnnotation } from './annotate';\n\nexport type Formatter = (err: Annotation) => string | Error;\n\nfunction serializeString(s: string, width: number = 80): string {\n // Full string\n // Abbreviated to $maxlen i.e. \"Vincent Driess...\" [truncated]\n let ser = JSON.stringify(s);\n if (ser.length <= width) {\n return ser;\n }\n\n // Cut off a bit\n const truncated = `${s.substring(0, width - 15)}...`;\n ser = `${JSON.stringify(truncated)} [truncated]`;\n return ser;\n}\n\nfunction serializeArray(annotation: ArrayAnnotation, prefix: string): string {\n const { items } = annotation;\n if (items.length === 0) {\n return '[]';\n }\n\n const result: string[] = [];\n for (const item of items) {\n const [ser, ann] = serializeAnnotation(item, `${prefix}${INDENT}`);\n result.push(`${prefix}${INDENT}${ser}${','}`);\n if (ann !== undefined) {\n result.push(indent(ann, `${prefix}${INDENT}`));\n }\n }\n return ['[', ...result, `${prefix}]`].join('\\n');\n}\n\nfunction serializeObject(annotation: ObjectAnnotation, prefix: string): string {\n const { fields } = annotation;\n\n const fieldNames = Object.keys(fields);\n if (fieldNames.length === 0) {\n return '{}';\n }\n\n const result: string[] = [];\n for (const key of fieldNames) {\n const valueAnnotation = fields[key];\n const kser = serializeValue(key);\n\n const valPrefix = `${prefix}${INDENT}${' '.repeat(kser.length + 2)}`;\n const [vser, vann] = serializeAnnotation(valueAnnotation, `${prefix}${INDENT}`);\n\n result.push(`${prefix}${INDENT}${kser}: ${vser},`);\n if (vann !== undefined) {\n result.push(indent(vann, valPrefix));\n }\n }\n return ['{', ...result, `${prefix}}`].join('\\n');\n}\n\nexport function serializeValue(value: unknown): string {\n if (typeof value === 'string') {\n return serializeString(value);\n } else if (typeof value === 'number' || typeof value === 'boolean') {\n return value.toString();\n } else if (value === null) {\n return 'null';\n } else if (value === undefined) {\n return 'undefined';\n } else {\n const valueAsDate = asDate(value);\n if (valueAsDate !== null) {\n return `new Date(${JSON.stringify(valueAsDate.toISOString())})`;\n } else if (value instanceof Date) {\n // NOTE: Using `instanceof Date` is unreliable way of checking dates.\n // If this case occurs (and it didn't pass the prior asDate())\n // check, then this must be the case where it's an invalid date.\n return '(Invalid Date)';\n } else {\n return '(unserializable)';\n }\n }\n}\n\nexport function serializeAnnotation(\n ann: Annotation,\n prefix: string = '',\n): [string, string | undefined] {\n // The serialized data (the input object echoed back)\n let serialized;\n if (ann.type === 'array') {\n serialized = serializeArray(ann, prefix);\n } else if (ann.type === 'object') {\n serialized = serializeObject(ann, prefix);\n } else if (ann.type === 'function') {\n serialized = '<function>';\n } else if (ann.type === 'circular-ref') {\n serialized = '<circular ref>';\n } else if (ann.type === 'unknown') {\n serialized = '???';\n } else {\n serialized = serializeValue(ann.value);\n }\n\n const text = ann.text;\n if (text !== undefined) {\n const sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length);\n return [serialized, [sep, text].join(isMultiline(text) ? '\\n' : ' ')];\n } else {\n return [serialized, undefined];\n }\n}\n\nexport function formatInline(ann: Annotation): string {\n const [serialized, annotation] = serializeAnnotation(ann);\n if (annotation !== undefined) {\n return `${serialized}\\n${annotation}`;\n } else {\n return serialized;\n }\n}\n\nexport function formatShort(ann: Annotation): string {\n return _summarize(ann, []).join('\\n');\n}\n","/**\n * Result <value> <error>\n * = Ok <value>\n * | Err <error>\n */\nexport type Ok<T> = {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n};\n\nexport type Err<E> = {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n};\n\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Create a new Result instance representing a successful computation.\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: undefined };\n}\n\n/**\n * Create a new Result instance representing a failed computation.\n */\nexport function err<E>(error: E): Err<E> {\n return { ok: false, value: undefined, error };\n}\n","import { annotate } from './annotate';\nimport { formatInline } from './format';\nimport { err as makeErr, ok as makeOk } from './result';\nimport type { Annotation } from './annotate';\nimport type { Formatter } from './format';\nimport type { Result } from './result';\n\nexport type Scalar = string | number | boolean | symbol | undefined | null;\n\nexport type DecodeResult<T> = Result<T, Annotation>;\n\nexport type AcceptanceFn<T, InputT = unknown> = (\n blob: InputT,\n ok: (value: T) => DecodeResult<T>,\n err: (msg: string | Annotation) => DecodeResult<T>,\n) => DecodeResult<T>;\n\nexport interface Decoder<T> {\n /**\n * Verifies untrusted input. Either returns a value, or throws a decoding\n * error.\n */\n verify(blob: unknown, formatterFn?: (ann: Annotation) => string | Error): T;\n\n /**\n * Verifies untrusted input. Either returns a value, or returns undefined.\n */\n value(blob: unknown): T | undefined;\n\n /**\n * Verifies untrusted input. Always returns a DecodeResult, which is either\n * an \"ok\" value or an \"error\" annotation.\n */\n decode(blob: unknown): DecodeResult<T>;\n\n /**\n * Build a new decoder from the the current one, with an extra acceptance\n * criterium.\n */\n refine<N extends T>(predicate: (value: T) => value is N, msg: string): Decoder<N>;\n refine(predicate: (value: T) => boolean, msg: string): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, with an extra rejection\n * criterium.\n */\n reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, modifying its outputted value.\n */\n transform<V>(transformFn: (value: T) => V): Decoder<V>;\n\n /**\n * Build a new decoder from the current one, with a mutated error message\n * in case of a rejection.\n */\n describe(message: string): Decoder<T>;\n\n /**\n * Chain together the current decoder with another acceptance function.\n */\n then<V>(next: AcceptanceFn<V, T>): Decoder<V>;\n\n // Experimental APIs (please don't rely on these yet)\n peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V>;\n}\n\n/**\n * Helper type to return the \"type\" of a Decoder.\n *\n * You can use it on types:\n *\n * DecoderType<Decoder<string>> // string\n * DecoderType<Decoder<number[]>> // number[]\n *\n * Or on \"values\", by using the `typeof` keyword:\n *\n * DecoderType<typeof string> // string\n * DecoderType<typeof truthy> // boolean\n *\n */\nexport type DecoderType<D extends Decoder<any>> = D extends Decoder<infer T> ? T : never;\n\nfunction noThrow<T, V>(fn: (value: T) => V): (blob: T) => DecodeResult<V> {\n return (t) => {\n try {\n const v = fn(t);\n return makeOk(v);\n } catch (e) {\n return makeErr(annotate(t, e instanceof Error ? e.message : String(e)));\n }\n };\n}\n\nfunction format(err: Annotation, formatter: Formatter): Error {\n const formatted = formatter(err);\n\n // Formatter functions may return a string or an error for convenience of\n // writing them. If it already returns an Error, return it unmodified. If\n // it returns a string, wrap it in a \"Decoding error\" instance.\n if (typeof formatted === 'string') {\n const err = new Error(`\\n${formatted}`);\n err.name = 'Decoding error';\n return err;\n } else {\n return formatted;\n }\n}\n\n/**\n * Defines a new `Decoder<T>`, by implementing a custom acceptance function.\n * The function receives three arguments:\n *\n * 1. `blob` - the raw/unknown input (aka your external data)\n * 2. `ok` - Call `ok(value)` to accept the input and return ``value``\n * 3. `err` - Call `err(message)` to reject the input with error ``message``\n *\n * The expected return value should be a `DecodeResult<T>`, which can be\n * obtained by returning the result of calling the provided `ok` or `err`\n * helper functions. Please note that `ok()` and `err()` don't perform side\n * effects! You'll need to _return_ those values.\n */\nexport function define<T>(fn: AcceptanceFn<T>): Decoder<T> {\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n *\n * Contrasted with `.verify()`, calls to `.decode()` will never fail and\n * instead return a result type.\n */\n function decode(blob: unknown): DecodeResult<T> {\n return fn(blob, makeOk, (msg: Annotation | string) =>\n makeErr(typeof msg === 'string' ? annotate(blob, msg) : msg),\n );\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns a value of type `T`. Otherwise fail with\n * a runtime error.\n */\n function verify(blob: unknown, formatter: Formatter = formatInline): T {\n const result = decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n throw format(result.error, formatter);\n }\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns the decoded `T` value directly. Otherwise returns\n * `undefined`.\n *\n * Use this when you're not interested in programmatically handling the\n * error message.\n */\n function value(blob: unknown): T | undefined {\n return decode(blob).value;\n }\n\n /**\n * Accepts any value the given decoder accepts, and on success, will call\n * the given function **on the decoded result**. If the transformation\n * function throws an error, the whole decoder will fail using the error\n * message as the failure reason.\n */\n function transform<V>(transformFn: (result: T) => V): Decoder<V> {\n return then(noThrow(transformFn));\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that also meet the\n * predicate.\n */\n function refine(predicateFn: (value: T) => boolean, errmsg: string): Decoder<T> {\n return reject((value) =>\n predicateFn(value)\n ? // Don't reject\n null\n : // Reject with the given error message\n errmsg,\n );\n }\n\n /**\n * Chain together the current decoder with another.\n *\n * > _**NOTE:** This is an advanced, low-level, API. It's not recommended\n * > to reach for this construct unless there is no other way. Most cases can\n * > be covered more elegantly by `.transform()` or `.refine()` instead._\n *\n * If the current decoder accepts an input, the resulting ``T`` value will\n * get passed into the given ``next`` acceptance function to further decide\n * whether or not the value should get accepted or rejected.\n *\n * This works similar to how you would `define()` a new decoder, except\n * that the ``blob`` param will now be ``T`` (a known type), rather than\n * ``unknown``. This will allow the function to make a stronger assumption\n * about its input and avoid re-refining inputs.\n *\n * If it helps, you can think of `define(...)` as equivalent to\n * `unknown.then(...)`.\n */\n function then<V>(next: AcceptanceFn<V, T>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next(result.value, ok, err) : result;\n });\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that aren't rejected by the\n * given function.\n *\n * The given function can return `null` to accept the decoded value, or\n * return a specific error message to reject.\n *\n * Unlike `.refine()`, you can use this function to return a dynamic error\n * message.\n */\n function reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T> {\n return then((value, ok, err) => {\n const errmsg = rejectFn(value);\n return errmsg === null\n ? ok(value)\n : err(typeof errmsg === 'string' ? annotate(value, errmsg) : errmsg);\n });\n }\n\n /**\n * Uses the given decoder, but will use an alternative error message in\n * case it rejects. This can be used to simplify or shorten otherwise\n * long or low-level/technical errors.\n */\n function describe(message: string): Decoder<T> {\n return define((blob, _, err) => {\n // Decode using the given decoder...\n const result = decode(blob);\n if (result.ok) {\n return result;\n } else {\n // ...but in case of error, annotate this with the custom given\n // message instead\n return err(annotate(result.error, message));\n }\n });\n }\n\n /**\n * WARNING: This is an EXPERIMENTAL API that will likely change in the\n * future. Please DO NOT rely on it.\n *\n * Chain together the current decoder with another, but also pass along\n * the original input.\n *\n * This is like `.then()`, but instead of this function receiving just\n * the decoded result ``T``, it also receives the original input.\n *\n * This is an advanced, low-level, decoder.\n */\n function peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next([blob, result.value], ok, err) : result;\n });\n }\n\n return Object.freeze({\n verify,\n value,\n decode,\n transform,\n refine,\n reject,\n describe,\n then,\n\n // EXPERIMENTAL - please DO NOT rely on this method\n peek_UNSTABLE,\n });\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { annotateObject, merge, updateText } from '../annotate';\nimport { define } from '../Decoder';\nimport { subtract, isPojo } from '../_utils';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\nimport type { UndefinedToOptional } from './_helpers';\n\ntype ObjectDecoderType<T> = UndefinedToOptional<{\n [K in keyof T]: T[K] extends Decoder<infer V> ? V : never;\n}>;\n\n/**\n * Accepts any \"plain old JavaScript object\", but doesn't validate its keys or\n * values further.\n */\nexport const pojo: Decoder<Record<string, unknown>> = define((blob, ok, err) =>\n isPojo(blob) ? ok(blob) : err('Must be an object'),\n);\n\n/**\n * Accepts objects with fields matching the given decoders. Extra fields that\n * exist on the input object are ignored and will not be returned.\n */\nexport function object(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>> {\n // Compute this set at decoder definition time\n const knownKeys = new Set(Object.keys(decodersByKey));\n\n return pojo.then((plainObj, ok, err) => {\n const actualKeys = new Set(Object.keys(plainObj));\n\n // At this point, \"missingKeys\" will also include all fields that may\n // validly be optional. We'll let the underlying decoder decide and\n // remove the key from this missing set if the decoder accepts the\n // value.\n const missingKeys = subtract(knownKeys, actualKeys);\n\n const record = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(decodersByKey)) {\n const decoder = decodersByKey[key];\n const rawValue = plainObj[key];\n const result: DecodeResult<unknown> = decoder.decode(rawValue);\n\n if (result.ok) {\n const value = result.value;\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n record[key] = value;\n }\n\n // If this succeeded, remove the key from the missing keys\n // tracker\n missingKeys.delete(key);\n } else {\n const ann = result.error;\n\n // Keep track of the annotation, but don't return just yet. We\n // want to collect more error information.\n if (rawValue === undefined) {\n // Explicitly add it to the missing set if the value is\n // undefined. This covers explicit undefineds to be\n // treated the same as implicit undefineds (aka missing\n // keys).\n missingKeys.add(key);\n } else {\n if (errors === null) {\n errors = {};\n }\n errors[key] = ann;\n }\n }\n }\n\n // Deal with errors now. There are two classes of errors we want to\n // report. First of all, we want to report any inline errors in this\n // object. Lastly, any fields that are missing should be annotated on\n // the outer object itself.\n if (errors || missingKeys.size > 0) {\n let objAnn = annotateObject(plainObj);\n\n if (errors) {\n objAnn = merge(objAnn, errors);\n }\n\n if (missingKeys.size > 0) {\n const errMsg = Array.from(missingKeys)\n .map((key) => `\"${key}\"`)\n .join(', ');\n const pluralized = missingKeys.size > 1 ? 'keys' : 'key';\n objAnn = updateText(objAnn, `Missing ${pluralized}: ${errMsg}`);\n }\n\n return err(objAnn);\n }\n\n return ok(record as ObjectDecoderType<DS>);\n });\n}\n\n/**\n * Like `object()`, but will reject inputs that contain extra fields that are\n * not specified explicitly.\n */\nexport function exact(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }> {\n // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n // Ditto (see above)\n\n // Compute this set at decoder definition time\n const allowedKeys = new Set(Object.keys(decodersByKey));\n\n // Check the inputted object for any unexpected extra keys\n const checked = pojo.reject((plainObj) => {\n const actualKeys = new Set(Object.keys(plainObj));\n const extraKeys = subtract(actualKeys, allowedKeys);\n return extraKeys.size > 0\n ? `Unexpected extra keys: ${Array.from(extraKeys).join(', ')}`\n : // Don't reject\n null;\n });\n\n // Defer to the \"object\" decoder for doing the real decoding work. Since\n // we made sure there are no superfluous keys in this structure, it's now\n // safe to force-cast it to an $Exact<> type.\n return checked.then(object(decodersByKey).decode);\n}\n\n/**\n * Like `object()`, but will pass through any extra fields on the input object\n * unvalidated that will thus be of `unknown` type statically.\n */\nexport function inexact(\n decodersByKey: Record<any, never>,\n): Decoder<Record<string, unknown>>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n> {\n return pojo.then((plainObj) => {\n const allkeys = new Set(Object.keys(plainObj));\n const decoder = object(decodersByKey).transform((safepart) => {\n const safekeys = new Set(Object.keys(decodersByKey));\n\n // To account for hard-coded keys that aren't part of the input\n for (const k of safekeys) allkeys.add(k);\n\n const rv = {} as {\n [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K];\n } & Record<string, unknown>;\n for (const k of allkeys) {\n if (safekeys.has(k)) {\n const value = safepart[k];\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n rv[k] = value;\n }\n } else {\n // @ts-expect-error - look into this later\n rv[k] = plainObj[k];\n }\n }\n return rv;\n });\n return decoder.decode(plainObj);\n });\n}\n\n/**\n * Accepts objects where all values match the given decoder, and returns the\n * result as a `Record<string, T>`.\n *\n * The main difference between `object()` and `dict()` is that you'd typically\n * use `object()` if this is a record-like object, where all field names are\n * known and the values are heterogeneous. Whereas with `dict()` the keys are\n * typically dynamic and the values homogeneous, like in a dictionary,\n * a lookup table, or a cache.\n */\nexport function dict<T>(decoder: Decoder<T>): Decoder<Record<string, T>> {\n return pojo.then((plainObj, ok, err) => {\n let rv: Record<string, T> = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(plainObj)) {\n const value = plainObj[key];\n const result = decoder.decode(value);\n if (result.ok) {\n if (errors === null) {\n rv[key] = result.value;\n }\n } else {\n rv = {}; // Clear the success value so it can get garbage collected early\n if (errors === null) {\n errors = {};\n }\n errors[key] = result.error;\n }\n }\n\n if (errors !== null) {\n return err(merge(annotateObject(plainObj), errors));\n } else {\n return ok(rv);\n }\n });\n}\n\n/**\n * Similar to `dict()`, but returns the result as a `Map<string, T>` (an [ES6\n * Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map))\n * instead.\n */\nexport function mapping<T>(decoder: Decoder<T>): Decoder<Map<string, T>> {\n return dict(decoder).transform(\n (obj) =>\n new Map(\n // This is effectively Object.entries(obj), but in a way that Flow\n // will know the types are okay\n Object.keys(obj).map((key) => [key, obj[key]]),\n ),\n );\n}\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport interface Klass<T> extends Function {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: readonly any[]): T;\n}\n\nexport type Instance<K> = K extends Klass<infer T> ? T : never;\n\n/**\n * Accepts any value that is an ``instanceof`` the given class.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instanceOf<K extends Klass<any>>(klass: K): Decoder<Instance<K>> {\n return define((blob, ok, err) =>\n blob instanceof klass ? ok(blob) : err(`Must be ${klass.name} instance`),\n );\n}\n\n/**\n * Lazily evaluate the given decoder. This is useful to build self-referential\n * types for recursive data structures.\n */\nexport function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T> {\n return define((blob) => decoderFn().decode(blob));\n}\n\n/**\n * Pre-process the data input before passing it into the decoder. This gives\n * you the ability to arbitrarily customize the input on the fly before passing\n * it to the decoder. Of course, the input value at that point is still of\n * ``unknown`` type, so you will have to deal with that accordingly.\n */\nexport function prep<T>(\n mapperFn: (blob: unknown) => unknown,\n decoder: Decoder<T>,\n): Decoder<T> {\n return define((originalInput, _, err) => {\n let blob;\n try {\n blob = mapperFn(originalInput);\n } catch (e: unknown) {\n return err(\n annotate(\n originalInput,\n // istanbul ignore next\n e instanceof Error ? e.message : String(e),\n ),\n );\n }\n\n const r = decoder.decode(blob);\n return r.ok ? r : err(annotate(originalInput, r.error.text));\n // ^^^^^^^^^^^^^\n // Annotates the _original_ input value\n // (instead of echoing back blob)\n });\n}\n\n/**\n * Rejects all inputs, and always fails with the given error message. May be\n * useful for explicitly disallowing keys, or for testing purposes.\n */\nexport function never(msg: string): Decoder<never> {\n return define((_, __, err) => err(msg));\n}\n\n/**\n * Alias of never().\n */\nexport const fail = never;\n","import { define } from '../Decoder';\nimport { indent, summarize } from '../_utils';\nimport { object } from './objects';\nimport { prep } from './utilities';\nimport type { Decoder, DecoderType, DecodeResult, Scalar } from '../Decoder';\nimport type { Ok } from '../result';\n\ntype Values<T extends object> = T[keyof T];\n\ntype DecoderTypes<T> = T extends readonly Decoder<infer U>[] ? U : never;\n\nconst EITHER_PREFIX = 'Either:\\n';\n\n/**\n * Indents and adds a dash in front of this (potentially multiline) string.\n */\nfunction itemize(s: string): string {\n return `-${indent(s).substring(1)}`;\n}\n\n/**\n * Nests another error as an item under a new-to-be-created \"Either error\". If\n * the given subitem already is an \"Either error\" of itself, don't indent, but\n * just \"inject\" its items at the same error level, for nicely flattened either\n * expressions.\n *\n * Avoids:\n *\n * Either:\n * - Either:\n * - Must be P\n * - Either:\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n * And \"flattens\" these to:\n *\n * Either:\n * - Must be P\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n */\nfunction nest(errText: string): string {\n return errText.startsWith(EITHER_PREFIX)\n ? errText.substr(EITHER_PREFIX.length)\n : itemize(errText);\n}\n\n/**\n * Accepts values accepted by any of the given decoders.\n *\n * The decoders are tried on the input one by one, in the given order. The\n * first one that accepts the input \"wins\". If all decoders reject the input,\n * the input gets rejected.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function either<T extends readonly Decoder<any>[]>(\n ...decoders: T\n): Decoder<DecoderTypes<T>> {\n if (decoders.length === 0) {\n throw new Error('Pass at least one decoder to either()');\n }\n\n return define((blob, _, err) => {\n // Collect errors here along the way\n const errors = [];\n\n for (let i = 0; i < decoders.length; i++) {\n const result: DecodeResult<unknown> = decoders[i].decode(blob);\n if (result.ok) {\n return result as Ok<DecoderTypes<T>>;\n } else {\n errors.push(result.error);\n }\n }\n\n // Decoding all alternatives failed, return the combined error message\n const text =\n EITHER_PREFIX + errors.map((err) => nest(summarize(err).join('\\n'))).join('\\n');\n return err(text);\n });\n}\n\n/**\n * Accepts any value that is strictly-equal (using `===`) to one of the\n * specified values.\n */\nexport function oneOf<C extends Scalar>(constants: readonly C[]): Decoder<C> {\n return define((blob, ok, err) => {\n const winner = constants.find((c) => c === blob);\n if (winner !== undefined) {\n return ok(winner);\n }\n return err(\n `Must be one of ${constants.map((value) => JSON.stringify(value)).join(', ')}`,\n );\n });\n}\n\n/**\n * If you are decoding tagged unions you may want to use the `taggedUnion()`\n * decoder instead of the general purpose `either()` decoder to get better\n * error messages and better performance.\n *\n * This decoder is optimized for [tagged\n * unions](https://en.wikipedia.org/wiki/Tagged_union), i.e. a union of\n * objects where one field is used as the discriminator.\n *\n * ```ts\n * const A = object({ tag: constant('A'), foo: string });\n * const B = object({ tag: constant('B'), bar: number });\n *\n * const AorB = taggedUnion('tag', { A, B });\n * // ^^^\n * ```\n *\n * Decoding now works in two steps:\n *\n * 1. Look at the `'tag'` field in the incoming object (this is the field\n * that decides which decoder will be used)\n * 2. If the value is `'A'`, then decoder `A` will be used. If it's `'B'`, then\n * decoder `B` will be used. Otherwise, this will fail.\n *\n * This is effectively equivalent to `either(A, B)`, but will provide better\n * error messages and is more performant at runtime because it doesn't have to\n * try all decoders one by one.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function taggedUnion<O extends Record<string, Decoder<any>>>(\n field: string,\n mapping: O,\n): Decoder<Values<{ [key in keyof O]: DecoderType<O[key]> }>> {\n const base: Decoder<string> = object({\n [field]: prep(String, oneOf(Object.keys(mapping))),\n }).transform((o) => o[field]);\n return base.peek_UNSTABLE(([blob, key]) => {\n const decoder = mapping[key];\n return decoder.decode(blob);\n });\n}\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport type { Decoder, Scalar } from '../Decoder';\nimport { lazyval } from '../_utils';\n\n/**\n * Accepts and returns only the literal `null` value.\n */\nexport const null_: Decoder<null> = define((blob, ok, err) =>\n blob === null ? ok(blob) : err('Must be null'),\n);\n\n/**\n * Accepts and returns only the literal `undefined` value.\n */\nexport const undefined_: Decoder<undefined> = define((blob, ok, err) =>\n blob === undefined ? ok(blob) : err('Must be undefined'),\n);\n\nconst undefined_or_null: Decoder<null | undefined> = define((blob, ok, err) =>\n blob === undefined || blob === null\n ? ok(blob)\n : // Combine error message into a single line for readability\n err('Must be undefined or null'),\n);\n\n/**\n * Accepts whatever the given decoder accepts, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `undefined` case.\n */\nexport function optional<T>(decoder: Decoder<T>): Decoder<T | undefined>;\nexport function optional<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function optional<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function optional<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | undefined> {\n const rv = either(undefined_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts whatever the given decoder accepts, or `null`.\n *\n * If a default value is explicitly provided, return that instead in the `null`\n * case.\n */\nexport function nullable<T>(decoder: Decoder<T>): Decoder<T | null>;\nexport function nullable<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function nullable<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function nullable<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null> {\n const rv = either(null_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts whatever the given decoder accepts, or `null`, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `null`/`undefined` case.\n */\nexport function maybe<T>(decoder: Decoder<T>): Decoder<T | null | undefined>;\nexport function maybe<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function maybe<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function maybe<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null | undefined> {\n const rv = either(undefined_or_null, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts only the given constant value.\n */\nexport function constant<C extends Scalar>(value: C): Decoder<C> {\n return define((blob, ok, err) =>\n blob === value ? ok(value) : err(`Must be constant ${String(value)}`),\n );\n}\n\n/**\n * Accepts anything, completely ignores it, and always returns the provided\n * value instead.\n *\n * This is useful to manually add extra fields to object decoders.\n */\nexport function always<C extends Scalar>(value: C): Decoder<C>;\nexport function always<T>(value: (() => T) | T): Decoder<T>;\nexport function always<T>(value: (() => T) | T): Decoder<T> {\n return define(\n typeof value === 'function'\n ? (_, ok) => ok((value as () => T)())\n : (_, ok) => ok(value),\n );\n}\n\n/**\n * Alias of always.\n */\nexport const hardcoded = always;\n\n/**\n * Accepts anything and returns it unchanged.\n *\n * Useful for situation in which you don't know or expect a specific type. Of\n * course, the downside is that you won't know the type of the value statically\n * and you'll have to further refine it yourself.\n */\nexport const unknown: Decoder<unknown> = define((blob, ok, _) => ok(blob));\n\n/**\n * Alias of unknown.\n */\nexport const mixed = unknown;\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\n\n/**\n * Accepts any array, but doesn't validate its items further.\n *\n * \"poja\" means \"plain old JavaScript array\", a play on `pojo()`.\n */\nexport const poja: Decoder<unknown[]> = define((blob, ok, err) => {\n if (!Array.isArray(blob)) {\n return err('Must be an array');\n }\n return ok(blob as unknown[]);\n});\n\n/**\n * Given an array of Result instances, loop over them all and return:\n * - An [index, err] tuple, indicating the (index of the) first Err instance\n * encountered; or\n * - a new Ok with an array of all unwrapped Ok'ed values\n */\nfunction all<T>(\n items: readonly DecodeResult<T>[],\n blobs: readonly unknown[],\n\n // TODO: Make this less ugly\n ok: (value: T[]) => DecodeResult<T[]>,\n err: (ann: Annotation) => DecodeResult<T[]>,\n): DecodeResult<T[]> {\n const results: T[] = [];\n for (let index = 0; index < items.length; ++index) {\n const result = items[index];\n if (result.ok) {\n results.push(result.value);\n } else {\n const ann = result.error;\n\n // Rewrite the annotation to include the index information, and inject it into the original blob\n const clone = blobs.slice();\n clone.splice(\n index,\n 1,\n annotate(ann, ann.text ? `${ann.text} (at index ${index})` : `index ${index}`),\n );\n\n return err(annotate(clone));\n }\n }\n return ok(results);\n}\n\n/**\n * Accepts arrays of whatever the given decoder accepts.\n */\nexport function array<T>(decoder: Decoder<T>): Decoder<T[]> {\n const decodeFn = decoder.decode;\n return poja.then((blobs: readonly unknown[], ok, err) => {\n const results = blobs.map(decodeFn);\n return all(results, blobs, ok, err);\n });\n}\n\nfunction isNonEmpty<T>(arr: readonly T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Like `array()`, but will reject arrays with 0 elements.\n */\nexport function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<[T, ...T[]]> {\n return array(decoder).refine(isNonEmpty, 'Must be non-empty array');\n}\n\n/**\n * Similar to `array()`, but returns the result as an [ES6\n * Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).\n */\nexport function set<T>(decoder: Decoder<T>): Decoder<Set<T>> {\n return array(decoder).transform((items) => new Set(items));\n}\n\nconst ntuple = (n: number) =>\n poja.refine((arr) => arr.length === n, `Must be a ${n}-tuple`);\n\n/**\n * Accepts a tuple (an array with exactly _n_ items) of values accepted by the\n * _n_ given decoders.\n */\nexport function tuple<A>(a: Decoder<A>): Decoder<[A]>;\nexport function tuple<A, B>(a: Decoder<A>, b: Decoder<B>): Decoder<[A, B]>;\nexport function tuple<A, B, C>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n): Decoder<[A, B, C]>;\nexport function tuple<A, B, C, D>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n): Decoder<[A, B, C, D]>;\nexport function tuple<A, B, C, D, E>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n): Decoder<[A, B, C, D, E]>;\nexport function tuple<A, B, C, D, E, F>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n f: Decoder<F>,\n): Decoder<[A, B, C, D, E, F]>;\nexport function tuple(...decoders: readonly Decoder<unknown>[]): Decoder<unknown[]> {\n return ntuple(decoders.length).then((blobs, ok, err) => {\n let allOk = true;\n\n const rvs = decoders.map((decoder, i) => {\n const blob = blobs[i];\n const result = decoder.decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n allOk = false;\n return result.error;\n }\n });\n\n if (allOk) {\n return ok(rvs);\n } else {\n // If a decoder error has happened while unwrapping all the\n // results, try to construct a good error message\n return err(annotate(rvs));\n }\n });\n}\n","import { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts any valid ``number`` value.\n *\n * This also accepts special values like `NaN` and `Infinity`. Unless you\n * want to deliberately accept those, you'll likely want to use the\n * `number` decoder instead.\n */\nexport const anyNumber: Decoder<number> = define((blob, ok, err) =>\n typeof blob === 'number' ? ok(blob) : err('Must be number'),\n);\n\n/**\n * Accepts finite numbers (can be integer or float values). Values `NaN`,\n * or positive and negative `Infinity` will get rejected.\n */\nexport const number: Decoder<number> = anyNumber.refine(\n (n) => Number.isFinite(n),\n 'Number must be finite',\n);\n\n/**\n * Accepts only finite whole numbers.\n */\nexport const integer: Decoder<number> = number.refine(\n (n) => Number.isInteger(n),\n 'Number must be an integer',\n);\n\n/**\n * Accepts only non-negative (zero or positive) finite numbers.\n */\nexport const positiveNumber: Decoder<number> = number\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n\n/**\n * Accepts only non-negative (zero or positive) finite whole numbers.\n */\nexport const positiveInteger: Decoder<number> = integer\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n","import { define } from '../Decoder';\nimport { number } from './numbers';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts and returns booleans.\n */\nexport const boolean: Decoder<boolean> = define((blob, ok, err) => {\n return typeof blob === 'boolean' ? ok(blob) : err('Must be boolean');\n});\n\n/**\n * Accepts anything and will return its \"truth\" value. Will never reject.\n */\nexport const truthy: Decoder<boolean> = define((blob, ok, _) => ok(!!blob));\n\n/**\n * Accepts numbers, but return their boolean representation.\n */\nexport const numericBoolean: Decoder<boolean> = number.transform((n) => !!n);\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport { instanceOf } from './utilities';\nimport type { Decoder } from '../Decoder';\n\n/** Match groups in this regex:\n * \\1 - the scheme\n * \\2 - the username/password (optional)\n * \\3 - the host\n * \\4 - the port (optional)\n * \\5 - the path (optional)\n */\nconst url_re =\n /^([A-Za-z]{3,9}(?:[+][A-Za-z]{3,9})?):\\/\\/(?:([-;:&=+$,\\w]+)@)?(?:([A-Za-z0-9.-]+)(?::([0-9]{2,5}))?)(\\/(?:[-+~%/.,\\w]*)?(?:\\?[-+=&;%@.,/\\w]*)?(?:#[.,!/\\w]*)?)?$/;\n\n/**\n * Accepts and returns strings.\n */\nexport const string: Decoder<string> = define((blob, ok, err) =>\n typeof blob === 'string' ? ok(blob) : err('Must be string'),\n);\n\n/**\n * Like `string`, but will reject the empty string or strings containing only whitespace.\n */\nexport const nonEmptyString: Decoder<string> = regex(/\\S/, 'Must be non-empty string');\n\n/**\n * Accepts and returns strings that match the given regular expression.\n */\nexport function regex(regex: RegExp, msg: string): Decoder<string> {\n return string.refine((s) => regex.test(s), msg);\n}\n\n/**\n * Accepts and returns strings that are syntactically valid email addresses.\n * (This will not mean that the email address actually exist.)\n */\nexport const email: Decoder<string> = regex(\n // The almost perfect email regex, taken from https://emailregex.com/\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n 'Must be email',\n);\n\n/**\n * Accepts strings that are valid URLs, returns the value as a URL instance.\n */\nexport const url: Decoder<URL> = either(\n regex(url_re, 'Must be URL').transform((value) => new URL(value)),\n instanceOf(URL),\n);\n\n/**\n * Accepts strings that are valid URLs, but only HTTPS ones. Returns the value\n * as a URL instance.\n */\nexport const httpsUrl: Decoder<URL> = url.refine(\n (value) => value.protocol === 'https:',\n 'Must be an HTTPS URL',\n);\n\n/**\n * Accepts strings that are valid\n * [UUIDs](https://en.wikipedia.org/wiki/universally_unique_identifier)\n * (universally unique identifier).\n */\nexport const uuid: Decoder<string> = regex(\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,\n 'Must be uuid',\n);\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv1](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_%28date-time_and_MAC_address%29)\n * strings.\n */\nexport const uuidv1: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)\n uuid.refine((value) => value[14] === '1', 'Must be uuidv1');\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_%28random%29)\n * strings.\n */\nexport const uuidv4: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)\n uuid.refine((value) => value[14] === '4', 'Must be uuidv4');\n","import { asDate } from '../_utils';\nimport { define } from '../Decoder';\nimport { regex } from './strings';\nimport type { Decoder } from '../Decoder';\n\n// Only matches the shape. This \"over-matches\" some values that still aren't\n// valid dates (like 9999-99-99), but those will be caught by JS Date's\n// internal validations\nconst iso8601_re =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:[.]\\d+)?(?:Z|[+-]\\d{2}:?\\d{2})$/;\n\n/**\n * Accepts and returns `Date` instances.\n */\nexport const date: Decoder<Date> = define((blob, ok, err) => {\n const date = asDate(blob);\n return date !== null ? ok(date) : err('Must be a Date');\n});\n\n/**\n * Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,\n * returns them as `Date` instances.\n *\n * This is very useful for working with dates in APIs: serialize them as\n * `.toISOString()` when sending, decode them with `iso8601` when receiving.\n */\nexport const iso8601: Decoder<Date> =\n // Input itself needs to match the ISO8601 regex...\n regex(iso8601_re, 'Must be ISO8601 format').transform(\n // Make sure it is a _valid_ date\n (value: string) => {\n const date = new Date(value);\n if (isNaN(date.getTime())) {\n throw new Error('Must be valid date/time value');\n }\n return date;\n },\n );\n","import { array } from './arrays';\nimport { boolean } from './booleans';\nimport { dict } from './objects';\nimport { either } from './unions';\nimport { lazy } from './utilities';\nimport { null_ } from './basics';\nimport { number } from './numbers';\nimport { string } from './strings';\nimport type { Decoder } from '../Decoder';\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\nexport type JSONObject = { [key: string]: JSONValue | undefined };\nexport type JSONArray = JSONValue[];\n\n/**\n * Accepts objects that contain only valid JSON values.\n */\nexport const jsonObject: Decoder<JSONObject> = lazy(() => dict(json));\n\n/**\n * Accepts arrays that contain only valid JSON values.\n */\nexport const jsonArray: Decoder<JSONArray> = lazy(() => array(json));\n\n/**\n * Accepts any value that's a valid JSON value.\n *\n * In other words: any value returned by `JSON.parse()` should decode without\n * failure.\n *\n * ```typescript\n * type JSONValue =\n * | null\n * | string\n * | number\n * | boolean\n * | { [string]: JSONValue }\n * | JSONValue[]\n * ```\n */\nexport const json: Decoder<JSONValue> = either(\n null_,\n string,\n number,\n boolean,\n jsonObject,\n jsonArray,\n).describe('Must be valid JSON value');\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/_utils.ts","../src/annotate.ts","../src/format.ts","../src/result.ts","../src/Decoder.ts","../src/lib/objects.ts","../src/lib/utilities.ts","../src/lib/unions.ts","../src/lib/basics.ts","../src/lib/arrays.ts","../src/lib/numbers.ts","../src/lib/booleans.ts","../src/lib/strings.ts","../src/lib/dates.ts","../src/lib/json.ts"],"names":["ann","err","value","ok","object","mapping","unknown","array","regex","date"],"mappings":";AAIO,IAAM,SAAS;AAEf,SAAS,QAAW,OAAyB;AAClD,SAAO,OAAO,UAAU,aAAc,MAAkB,IAAI;AAC9D;AAKO,SAAS,SAA2B,IAAY,IAAoB;AACzE,QAAM,SAAS,oBAAI,IAAO;AAC1B,aAAW,KAAK,IAAI;AAClB,QAAI,CAAC,GAAG,IAAI,CAAC,GAAG;AACd,aAAO,IAAI,CAAC;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,OAAO,OAA6B;AAQlD,SAAO,CAAC,CAAC,SACP,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,mBAC1C,CAAC,MAAM,KAAe,IACnB,QACD;AACN;AAEO,SAAS,OAAO,OAAkD;AACvE,SACE,UAAU,QACV,UAAU,UACV,OAAO,UAAU;AAAA;AAAA,EAGjB,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM;AAE9C;AAEO,SAAS,YAAY,GAAoB;AAC9C,SAAO,EAAE,QAAQ,IAAI,KAAK;AAC5B;AAEO,SAAS,OAAO,GAAW,SAAiB,QAAgB;AACjE,MAAI,YAAY,CAAC,GAAG;AAClB,WAAO,EACJ,MAAM,IAAI,EACV,IAAI,CAAC,SAAS,GAAG,MAAM,GAAG,IA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AAAA,EAEX,KAAK,OAAO,CAAC,UAAU,MAAM,EAAE,MAAM,KAAK,gBAAgB;AAAA;;;AC/E5D,IAAM,aACJ;AAKK,IAAM,OAAsB,OAAO,CAAC,MAAML,KAAIF,SAAQ;AAC3D,QAAMQ,QAAO,OAAO,IAAI;AACxB,SAAOA,UAAS,OAAON,IAAGM,KAAI,IAAIR,KAAI,gBAAgB;AACxD,CAAC;AASM,IAAM;AAAA;AAAA,EAEX,MAAM,YAAY,wBAAwB,EAAE;AAAA;AAAA,IAE1C,CAAC,UAAkB;AACjB,YAAMQ,QAAO,IAAI,KAAK,KAAK;AAC3B,UAAI,MAAMA,MAAK,QAAQ,CAAC,GAAG;AACzB,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,aAAOA;AAAA,IACT;AAAA,EACF;AAAA;;;ACpBK,IAAM,aAAkC,KAAK,MAAM,KAAK,IAAI,CAAC;AAK7D,IAAM,YAAgC,KAAK,MAAMF,OAAM,IAAI,CAAC;AAkB5D,IAAM,OAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,SAAS,0BAA0B","sourcesContent":["import type { Annotation } from './annotate';\nimport type { Scalar } from './Decoder';\n\n// Two spaces of indentation\nexport const INDENT = ' ';\n\nexport function lazyval<V>(value: (() => V) | V): V {\n return typeof value === 'function' ? (value as () => V)() : value;\n}\n\n/**\n * Subtract two sets. Why isn't this a standard method on Sets?\n */\nexport function subtract<C extends Scalar>(xs: Set<C>, ys: Set<C>): Set<C> {\n const result = new Set<C>();\n for (const x of xs) {\n if (!ys.has(x)) {\n result.add(x);\n }\n }\n return result;\n}\n\n/**\n * Is value is a valid Date instance, then return that. If not, then return\n * null.\n */\nexport function asDate(value: unknown): Date | null {\n //\n // `x instanceof Date` checks are unreliable across stack frames (that\n // information might get lost by the JS runtime), so we'll have to reside\n // to more runtime inspection checks.\n //\n // Taken from https://stackoverflow.com/a/44198641\n //\n return !!value &&\n Object.prototype.toString.call(value) === '[object Date]' &&\n !isNaN(value as number)\n ? (value as Date)\n : null;\n}\n\nexport function isPojo(value: unknown): value is Record<string, unknown> {\n return (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n // This still seems to be the only reliable way to determine whether\n // something is a pojo... ¯\\_(ツ)_/¯\n Object.prototype.toString.call(value) === '[object Object]'\n );\n}\n\nexport function isMultiline(s: string): boolean {\n return s.indexOf('\\n') >= 0;\n}\n\nexport function indent(s: string, prefix: string = INDENT): string {\n if (isMultiline(s)) {\n return s\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n');\n } else {\n return `${prefix}${s}`;\n }\n}\n\n/**\n * Walks the annotation tree and emits the annotation's key path within the\n * object tree, and the message as a series of messages (array of strings).\n */\nexport function summarize(\n ann: Annotation,\n keypath: readonly (number | string)[] = [],\n): string[] {\n const result: string[] = [];\n\n if (ann.type === 'array') {\n const items = ann.items;\n let index = 0;\n for (const ann of items) {\n for (const item of summarize(ann, [...keypath, index++])) {\n // Collect to results\n result.push(item);\n }\n }\n } else if (ann.type === 'object') {\n const fields = ann.fields;\n for (const key of Object.keys(fields)) {\n const value = fields[key];\n for (const item of summarize(value, [...keypath, key])) {\n // Collect to results\n result.push(item);\n }\n }\n }\n\n const text = ann.text;\n if (!text) {\n return result;\n }\n\n let prefix: string;\n if (keypath.length === 0) {\n prefix = '';\n } else if (keypath.length === 1) {\n prefix =\n typeof keypath[0] === 'number'\n ? `Value at index ${keypath[0]}: `\n : `Value at key ${JSON.stringify(keypath[0])}: `;\n } else {\n prefix = `Value at keypath ${keypath.map(String).join('.')}: `;\n }\n return [...result, `${prefix}${text}`];\n}\n","import { isPojo } from './_utils';\n\nconst _register: WeakSet<Annotation> = new WeakSet();\n\nexport interface ObjectAnnotation {\n readonly type: 'object';\n readonly fields: { readonly [key: string]: Annotation };\n readonly text?: string;\n}\n\nexport interface ArrayAnnotation {\n readonly type: 'array';\n readonly items: readonly Annotation[];\n readonly text?: string;\n}\n\nexport interface ScalarAnnotation {\n readonly type: 'scalar';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport interface FunctionAnnotation {\n readonly type: 'function';\n readonly text?: string;\n}\n\nexport interface CircularRefAnnotation {\n readonly type: 'circular-ref';\n readonly text?: string;\n}\n\nexport interface UnknownAnnotation {\n readonly type: 'unknown';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport type Annotation =\n | ObjectAnnotation\n | ArrayAnnotation\n | ScalarAnnotation\n | FunctionAnnotation\n | CircularRefAnnotation\n | UnknownAnnotation;\n\nfunction brand<A extends Annotation>(ann: A): A {\n _register.add(ann);\n return ann;\n}\n\nexport function object(\n fields: { readonly [key: string]: Annotation },\n text?: string,\n): ObjectAnnotation {\n return brand({ type: 'object', fields, text });\n}\n\nexport function array(items: readonly Annotation[], text?: string): ArrayAnnotation {\n return brand({\n type: 'array',\n items,\n text,\n });\n}\n\nexport function func(text?: string): FunctionAnnotation {\n return brand({\n type: 'function',\n text,\n });\n}\n\nexport function unknown(value: unknown, text?: string): UnknownAnnotation {\n return brand({\n type: 'unknown',\n value,\n text,\n });\n}\n\nexport function scalar(value: unknown, text?: string): ScalarAnnotation {\n return brand({\n type: 'scalar',\n value,\n text,\n });\n}\n\nexport function circularRef(text?: string): CircularRefAnnotation {\n return brand({\n type: 'circular-ref',\n text,\n });\n}\n\n/**\n * Given an existing Annotation, set the annotation's text to a new value.\n */\nexport function updateText<A extends Annotation>(annotation: A, text?: string): A {\n if (text !== undefined) {\n return brand({ ...annotation, text });\n } else {\n return annotation;\n }\n}\n\n/**\n * Given an existing ObjectAnnotation, merges new Annotations in there.\n */\nexport function merge(\n objAnnotation: ObjectAnnotation,\n fields: { readonly [key: string]: Annotation },\n): ObjectAnnotation {\n const newFields = { ...objAnnotation.fields, ...fields };\n return object(newFields, objAnnotation.text);\n}\n\nexport function asAnnotation(thing: unknown): Annotation | undefined {\n return typeof thing === 'object' && thing !== null && _register.has(thing as Annotation)\n ? (thing as Annotation)\n : undefined;\n}\n\ntype RefSet = WeakSet<object>;\n\n/** @internal */\nfunction annotateArray(\n value: readonly unknown[],\n text: string | undefined,\n seen: RefSet,\n): ArrayAnnotation | CircularRefAnnotation {\n seen.add(value);\n\n const items = value.map((v) => annotate(v, undefined, seen));\n return array(items, text);\n}\n\n/** @internal */\nfunction annotateObject(\n obj: Record<string, unknown>,\n text: string | undefined,\n seen: RefSet,\n): ObjectAnnotation {\n seen.add(obj);\n\n const fields: Record<string, Annotation> = {};\n for (const key of Object.keys(obj)) {\n const value = obj[key];\n fields[key] = annotate(value, undefined, seen);\n }\n return object(fields, text);\n}\n\n/** @internal */\nfunction annotate(value: unknown, text: string | undefined, seen: RefSet): Annotation {\n if (\n value === null ||\n value === undefined ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'symbol' ||\n typeof (value as Record<string, unknown>).getMonth === 'function'\n ) {\n return scalar(value, text);\n }\n\n const ann = asAnnotation(value);\n if (ann) {\n return updateText(ann, text);\n }\n\n if (Array.isArray(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateArray(value, text, seen);\n }\n }\n\n if (isPojo(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateObject(value, text, seen);\n }\n }\n\n if (typeof value === 'function') {\n return func(text);\n }\n\n return unknown(value, text);\n}\n\nfunction public_annotate(value: unknown, text?: string): Annotation {\n return annotate(value, text, new WeakSet());\n}\n\nfunction public_annotateObject(\n obj: { readonly [field: string]: unknown },\n text?: string,\n): ObjectAnnotation {\n return annotateObject(obj, text, new WeakSet());\n}\n\nexport {\n // This construct just ensures the \"seen\" weakmap (used for circular\n // reference detection) isn't made part of the public API.\n public_annotate as annotate,\n public_annotateObject as annotateObject,\n\n /** @internal */\n annotate as __private_annotate,\n};\n","import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils';\nimport type { Annotation, ArrayAnnotation, ObjectAnnotation } from './annotate';\n\nexport type Formatter = (err: Annotation) => string | Error;\n\nfunction serializeString(s: string, width: number = 80): string {\n // Full string\n // Abbreviated to $maxlen i.e. \"Vincent Driess...\" [truncated]\n let ser = JSON.stringify(s);\n if (ser.length <= width) {\n return ser;\n }\n\n // Cut off a bit\n const truncated = `${s.substring(0, width - 15)}...`;\n ser = `${JSON.stringify(truncated)} [truncated]`;\n return ser;\n}\n\nfunction serializeArray(annotation: ArrayAnnotation, prefix: string): string {\n const { items } = annotation;\n if (items.length === 0) {\n return '[]';\n }\n\n const result: string[] = [];\n for (const item of items) {\n const [ser, ann] = serializeAnnotation(item, `${prefix}${INDENT}`);\n result.push(`${prefix}${INDENT}${ser}${','}`);\n if (ann !== undefined) {\n result.push(indent(ann, `${prefix}${INDENT}`));\n }\n }\n return ['[', ...result, `${prefix}]`].join('\\n');\n}\n\nfunction serializeObject(annotation: ObjectAnnotation, prefix: string): string {\n const { fields } = annotation;\n\n const fieldNames = Object.keys(fields);\n if (fieldNames.length === 0) {\n return '{}';\n }\n\n const result: string[] = [];\n for (const key of fieldNames) {\n const valueAnnotation = fields[key];\n const kser = serializeValue(key);\n\n const valPrefix = `${prefix}${INDENT}${' '.repeat(kser.length + 2)}`;\n const [vser, vann] = serializeAnnotation(valueAnnotation, `${prefix}${INDENT}`);\n\n result.push(`${prefix}${INDENT}${kser}: ${vser},`);\n if (vann !== undefined) {\n result.push(indent(vann, valPrefix));\n }\n }\n return ['{', ...result, `${prefix}}`].join('\\n');\n}\n\nexport function serializeValue(value: unknown): string {\n if (typeof value === 'string') {\n return serializeString(value);\n } else if (typeof value === 'number' || typeof value === 'boolean') {\n return value.toString();\n } else if (value === null) {\n return 'null';\n } else if (value === undefined) {\n return 'undefined';\n } else {\n const valueAsDate = asDate(value);\n if (valueAsDate !== null) {\n return `new Date(${JSON.stringify(valueAsDate.toISOString())})`;\n } else if (value instanceof Date) {\n // NOTE: Using `instanceof Date` is unreliable way of checking dates.\n // If this case occurs (and it didn't pass the prior asDate())\n // check, then this must be the case where it's an invalid date.\n return '(Invalid Date)';\n } else {\n return '(unserializable)';\n }\n }\n}\n\nexport function serializeAnnotation(\n ann: Annotation,\n prefix: string = '',\n): [string, string | undefined] {\n // The serialized data (the input object echoed back)\n let serialized;\n if (ann.type === 'array') {\n serialized = serializeArray(ann, prefix);\n } else if (ann.type === 'object') {\n serialized = serializeObject(ann, prefix);\n } else if (ann.type === 'function') {\n serialized = '<function>';\n } else if (ann.type === 'circular-ref') {\n serialized = '<circular ref>';\n } else if (ann.type === 'unknown') {\n serialized = '???';\n } else {\n serialized = serializeValue(ann.value);\n }\n\n const text = ann.text;\n if (text !== undefined) {\n const sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length);\n return [serialized, [sep, text].join(isMultiline(text) ? '\\n' : ' ')];\n } else {\n return [serialized, undefined];\n }\n}\n\nexport function formatInline(ann: Annotation): string {\n const [serialized, annotation] = serializeAnnotation(ann);\n if (annotation !== undefined) {\n return `${serialized}\\n${annotation}`;\n } else {\n return serialized;\n }\n}\n\nexport function formatShort(ann: Annotation): string {\n return _summarize(ann, []).join('\\n');\n}\n","/**\n * Result <value> <error>\n * = Ok <value>\n * | Err <error>\n */\nexport type Ok<T> = {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n};\n\nexport type Err<E> = {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n};\n\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Create a new Result instance representing a successful computation.\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: undefined };\n}\n\n/**\n * Create a new Result instance representing a failed computation.\n */\nexport function err<E>(error: E): Err<E> {\n return { ok: false, value: undefined, error };\n}\n","import { annotate } from './annotate';\nimport { formatInline } from './format';\nimport { err as makeErr, ok as makeOk } from './result';\nimport type { Annotation } from './annotate';\nimport type { Formatter } from './format';\nimport type { Result } from './result';\n\nexport type Scalar = string | number | boolean | symbol | undefined | null;\n\nexport type DecodeResult<T> = Result<T, Annotation>;\n\nexport type AcceptanceFn<T, InputT = unknown> = (\n blob: InputT,\n ok: (value: T) => DecodeResult<T>,\n err: (msg: string | Annotation) => DecodeResult<T>,\n) => DecodeResult<T>;\n\nexport interface Decoder<T> {\n /**\n * Verifies untrusted input. Either returns a value, or throws a decoding\n * error.\n */\n verify(blob: unknown, formatterFn?: (ann: Annotation) => string | Error): T;\n\n /**\n * Verifies untrusted input. Either returns a value, or returns undefined.\n */\n value(blob: unknown): T | undefined;\n\n /**\n * Verifies untrusted input. Always returns a DecodeResult, which is either\n * an \"ok\" value or an \"error\" annotation.\n */\n decode(blob: unknown): DecodeResult<T>;\n\n /**\n * Build a new decoder from the the current one, with an extra acceptance\n * criterium.\n */\n refine<N extends T>(predicate: (value: T) => value is N, msg: string): Decoder<N>;\n refine(predicate: (value: T) => boolean, msg: string): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, with an extra rejection\n * criterium.\n */\n reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, modifying its outputted value.\n */\n transform<V>(transformFn: (value: T) => V): Decoder<V>;\n\n /**\n * Build a new decoder from the current one, with a mutated error message\n * in case of a rejection.\n */\n describe(message: string): Decoder<T>;\n\n /**\n * Chain together the current decoder with another acceptance function.\n */\n then<V>(next: AcceptanceFn<V, T>): Decoder<V>;\n\n // Experimental APIs (please don't rely on these yet)\n peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V>;\n}\n\n/**\n * Helper type to return the \"type\" of a Decoder.\n *\n * You can use it on types:\n *\n * DecoderType<Decoder<string>> // string\n * DecoderType<Decoder<number[]>> // number[]\n *\n * Or on \"values\", by using the `typeof` keyword:\n *\n * DecoderType<typeof string> // string\n * DecoderType<typeof truthy> // boolean\n *\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DecoderType<D extends Decoder<any>> = D extends Decoder<infer T> ? T : never;\n\nfunction noThrow<T, V>(fn: (value: T) => V): (blob: T) => DecodeResult<V> {\n return (t) => {\n try {\n const v = fn(t);\n return makeOk(v);\n } catch (e) {\n return makeErr(annotate(t, e instanceof Error ? e.message : String(e)));\n }\n };\n}\n\nfunction format(err: Annotation, formatter: Formatter): Error {\n const formatted = formatter(err);\n\n // Formatter functions may return a string or an error for convenience of\n // writing them. If it already returns an Error, return it unmodified. If\n // it returns a string, wrap it in a \"Decoding error\" instance.\n if (typeof formatted === 'string') {\n const err = new Error(`\\n${formatted}`);\n err.name = 'Decoding error';\n return err;\n } else {\n return formatted;\n }\n}\n\n/**\n * Defines a new `Decoder<T>`, by implementing a custom acceptance function.\n * The function receives three arguments:\n *\n * 1. `blob` - the raw/unknown input (aka your external data)\n * 2. `ok` - Call `ok(value)` to accept the input and return ``value``\n * 3. `err` - Call `err(message)` to reject the input with error ``message``\n *\n * The expected return value should be a `DecodeResult<T>`, which can be\n * obtained by returning the result of calling the provided `ok` or `err`\n * helper functions. Please note that `ok()` and `err()` don't perform side\n * effects! You'll need to _return_ those values.\n */\nexport function define<T>(fn: AcceptanceFn<T>): Decoder<T> {\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n *\n * Contrasted with `.verify()`, calls to `.decode()` will never fail and\n * instead return a result type.\n */\n function decode(blob: unknown): DecodeResult<T> {\n return fn(blob, makeOk, (msg: Annotation | string) =>\n makeErr(typeof msg === 'string' ? annotate(blob, msg) : msg),\n );\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns a value of type `T`. Otherwise fail with\n * a runtime error.\n */\n function verify(blob: unknown, formatter: Formatter = formatInline): T {\n const result = decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n throw format(result.error, formatter);\n }\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns the decoded `T` value directly. Otherwise returns\n * `undefined`.\n *\n * Use this when you're not interested in programmatically handling the\n * error message.\n */\n function value(blob: unknown): T | undefined {\n return decode(blob).value;\n }\n\n /**\n * Accepts any value the given decoder accepts, and on success, will call\n * the given function **on the decoded result**. If the transformation\n * function throws an error, the whole decoder will fail using the error\n * message as the failure reason.\n */\n function transform<V>(transformFn: (result: T) => V): Decoder<V> {\n return then(noThrow(transformFn));\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that also meet the\n * predicate.\n */\n function refine(predicateFn: (value: T) => boolean, errmsg: string): Decoder<T> {\n return reject((value) =>\n predicateFn(value)\n ? // Don't reject\n null\n : // Reject with the given error message\n errmsg,\n );\n }\n\n /**\n * Chain together the current decoder with another.\n *\n * > _**NOTE:** This is an advanced, low-level, API. It's not recommended\n * > to reach for this construct unless there is no other way. Most cases can\n * > be covered more elegantly by `.transform()` or `.refine()` instead._\n *\n * If the current decoder accepts an input, the resulting ``T`` value will\n * get passed into the given ``next`` acceptance function to further decide\n * whether or not the value should get accepted or rejected.\n *\n * This works similar to how you would `define()` a new decoder, except\n * that the ``blob`` param will now be ``T`` (a known type), rather than\n * ``unknown``. This will allow the function to make a stronger assumption\n * about its input and avoid re-refining inputs.\n *\n * If it helps, you can think of `define(...)` as equivalent to\n * `unknown.then(...)`.\n */\n function then<V>(next: AcceptanceFn<V, T>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next(result.value, ok, err) : result;\n });\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that aren't rejected by the\n * given function.\n *\n * The given function can return `null` to accept the decoded value, or\n * return a specific error message to reject.\n *\n * Unlike `.refine()`, you can use this function to return a dynamic error\n * message.\n */\n function reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T> {\n return then((value, ok, err) => {\n const errmsg = rejectFn(value);\n return errmsg === null\n ? ok(value)\n : err(typeof errmsg === 'string' ? annotate(value, errmsg) : errmsg);\n });\n }\n\n /**\n * Uses the given decoder, but will use an alternative error message in\n * case it rejects. This can be used to simplify or shorten otherwise\n * long or low-level/technical errors.\n */\n function describe(message: string): Decoder<T> {\n return define((blob, _, err) => {\n // Decode using the given decoder...\n const result = decode(blob);\n if (result.ok) {\n return result;\n } else {\n // ...but in case of error, annotate this with the custom given\n // message instead\n return err(annotate(result.error, message));\n }\n });\n }\n\n /**\n * WARNING: This is an EXPERIMENTAL API that will likely change in the\n * future. Please DO NOT rely on it.\n *\n * Chain together the current decoder with another, but also pass along\n * the original input.\n *\n * This is like `.then()`, but instead of this function receiving just\n * the decoded result ``T``, it also receives the original input.\n *\n * This is an advanced, low-level, decoder.\n */\n function peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next([blob, result.value], ok, err) : result;\n });\n }\n\n return Object.freeze({\n verify,\n value,\n decode,\n transform,\n refine,\n reject,\n describe,\n then,\n\n // EXPERIMENTAL - please DO NOT rely on this method\n peek_UNSTABLE,\n });\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { annotateObject, merge, updateText } from '../annotate';\nimport { define } from '../Decoder';\nimport { subtract, isPojo } from '../_utils';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\nimport type { UndefinedToOptional } from './_helpers';\n\ntype ObjectDecoderType<T> = UndefinedToOptional<{\n [K in keyof T]: T[K] extends Decoder<infer V> ? V : never;\n}>;\n\n/**\n * Accepts any \"plain old JavaScript object\", but doesn't validate its keys or\n * values further.\n */\nexport const pojo: Decoder<Record<string, unknown>> = define((blob, ok, err) =>\n isPojo(blob) ? ok(blob) : err('Must be an object'),\n);\n\n/**\n * Accepts objects with fields matching the given decoders. Extra fields that\n * exist on the input object are ignored and will not be returned.\n */\nexport function object(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>> {\n // Compute this set at decoder definition time\n const knownKeys = new Set(Object.keys(decodersByKey));\n\n return pojo.then((plainObj, ok, err) => {\n const actualKeys = new Set(Object.keys(plainObj));\n\n // At this point, \"missingKeys\" will also include all fields that may\n // validly be optional. We'll let the underlying decoder decide and\n // remove the key from this missing set if the decoder accepts the\n // value.\n const missingKeys = subtract(knownKeys, actualKeys);\n\n const record = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(decodersByKey)) {\n const decoder = decodersByKey[key];\n const rawValue = plainObj[key];\n const result: DecodeResult<unknown> = decoder.decode(rawValue);\n\n if (result.ok) {\n const value = result.value;\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n record[key] = value;\n }\n\n // If this succeeded, remove the key from the missing keys\n // tracker\n missingKeys.delete(key);\n } else {\n const ann = result.error;\n\n // Keep track of the annotation, but don't return just yet. We\n // want to collect more error information.\n if (rawValue === undefined) {\n // Explicitly add it to the missing set if the value is\n // undefined. This covers explicit undefineds to be\n // treated the same as implicit undefineds (aka missing\n // keys).\n missingKeys.add(key);\n } else {\n if (errors === null) {\n errors = {};\n }\n errors[key] = ann;\n }\n }\n }\n\n // Deal with errors now. There are two classes of errors we want to\n // report. First of all, we want to report any inline errors in this\n // object. Lastly, any fields that are missing should be annotated on\n // the outer object itself.\n if (errors || missingKeys.size > 0) {\n let objAnn = annotateObject(plainObj);\n\n if (errors) {\n objAnn = merge(objAnn, errors);\n }\n\n if (missingKeys.size > 0) {\n const errMsg = Array.from(missingKeys)\n .map((key) => `\"${key}\"`)\n .join(', ');\n const pluralized = missingKeys.size > 1 ? 'keys' : 'key';\n objAnn = updateText(objAnn, `Missing ${pluralized}: ${errMsg}`);\n }\n\n return err(objAnn);\n }\n\n return ok(record as ObjectDecoderType<DS>);\n });\n}\n\n/**\n * Like `object()`, but will reject inputs that contain extra fields that are\n * not specified explicitly.\n */\nexport function exact(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }> {\n // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n // Ditto (see above)\n\n // Compute this set at decoder definition time\n const allowedKeys = new Set(Object.keys(decodersByKey));\n\n // Check the inputted object for any unexpected extra keys\n const checked = pojo.reject((plainObj) => {\n const actualKeys = new Set(Object.keys(plainObj));\n const extraKeys = subtract(actualKeys, allowedKeys);\n return extraKeys.size > 0\n ? `Unexpected extra keys: ${Array.from(extraKeys).join(', ')}`\n : // Don't reject\n null;\n });\n\n // Defer to the \"object\" decoder for doing the real decoding work. Since\n // we made sure there are no superfluous keys in this structure, it's now\n // safe to force-cast it to an $Exact<> type.\n return checked.then(object(decodersByKey).decode);\n}\n\n/**\n * Like `object()`, but will pass through any extra fields on the input object\n * unvalidated that will thus be of `unknown` type statically.\n */\nexport function inexact(\n decodersByKey: Record<any, never>,\n): Decoder<Record<string, unknown>>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n> {\n return pojo.then((plainObj) => {\n const allkeys = new Set(Object.keys(plainObj));\n const decoder = object(decodersByKey).transform((safepart) => {\n const safekeys = new Set(Object.keys(decodersByKey));\n\n // To account for hard-coded keys that aren't part of the input\n for (const k of safekeys) allkeys.add(k);\n\n const rv = {} as {\n [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K];\n } & Record<string, unknown>;\n for (const k of allkeys) {\n if (safekeys.has(k)) {\n const value = safepart[k];\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n rv[k] = value;\n }\n } else {\n // @ts-expect-error - look into this later\n rv[k] = plainObj[k];\n }\n }\n return rv;\n });\n return decoder.decode(plainObj);\n });\n}\n\n/**\n * Accepts objects where all values match the given decoder, and returns the\n * result as a `Record<string, T>`.\n *\n * The main difference between `object()` and `dict()` is that you'd typically\n * use `object()` if this is a record-like object, where all field names are\n * known and the values are heterogeneous. Whereas with `dict()` the keys are\n * typically dynamic and the values homogeneous, like in a dictionary,\n * a lookup table, or a cache.\n */\nexport function dict<T>(decoder: Decoder<T>): Decoder<Record<string, T>> {\n return pojo.then((plainObj, ok, err) => {\n let rv: Record<string, T> = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(plainObj)) {\n const value = plainObj[key];\n const result = decoder.decode(value);\n if (result.ok) {\n if (errors === null) {\n rv[key] = result.value;\n }\n } else {\n rv = {}; // Clear the success value so it can get garbage collected early\n if (errors === null) {\n errors = {};\n }\n errors[key] = result.error;\n }\n }\n\n if (errors !== null) {\n return err(merge(annotateObject(plainObj), errors));\n } else {\n return ok(rv);\n }\n });\n}\n\n/**\n * Similar to `dict()`, but returns the result as a `Map<string, T>` (an [ES6\n * Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map))\n * instead.\n */\nexport function mapping<T>(decoder: Decoder<T>): Decoder<Map<string, T>> {\n return dict(decoder).transform(\n (obj) =>\n new Map(\n // This is effectively Object.entries(obj), but in a way that Flow\n // will know the types are okay\n Object.keys(obj).map((key) => [key, obj[key]]),\n ),\n );\n}\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport interface Klass<T> extends Function {\n new (...args: readonly any[]): T;\n}\n\nexport type Instance<K> = K extends Klass<infer T> ? T : never;\n\n/**\n * Accepts any value that is an ``instanceof`` the given class.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instanceOf<K extends Klass<any>>(klass: K): Decoder<Instance<K>> {\n return define((blob, ok, err) =>\n blob instanceof klass ? ok(blob) : err(`Must be ${klass.name} instance`),\n );\n}\n\n/**\n * Lazily evaluate the given decoder. This is useful to build self-referential\n * types for recursive data structures.\n */\nexport function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T> {\n return define((blob) => decoderFn().decode(blob));\n}\n\n/**\n * Pre-process the data input before passing it into the decoder. This gives\n * you the ability to arbitrarily customize the input on the fly before passing\n * it to the decoder. Of course, the input value at that point is still of\n * ``unknown`` type, so you will have to deal with that accordingly.\n */\nexport function prep<T>(\n mapperFn: (blob: unknown) => unknown,\n decoder: Decoder<T>,\n): Decoder<T> {\n return define((originalInput, _, err) => {\n let blob;\n try {\n blob = mapperFn(originalInput);\n } catch (e: unknown) {\n return err(\n annotate(\n originalInput,\n // istanbul ignore next\n e instanceof Error ? e.message : String(e),\n ),\n );\n }\n\n const r = decoder.decode(blob);\n return r.ok ? r : err(annotate(originalInput, r.error.text));\n // ^^^^^^^^^^^^^\n // Annotates the _original_ input value\n // (instead of echoing back blob)\n });\n}\n","import { define } from '../Decoder';\nimport { indent, summarize } from '../_utils';\nimport { object } from './objects';\nimport { prep } from './utilities';\nimport type { Decoder, DecoderType, DecodeResult, Scalar } from '../Decoder';\nimport type { Ok } from '../result';\n\ntype Values<T extends object> = T[keyof T];\n\ntype DecoderTypes<T> = T extends readonly Decoder<infer U>[] ? U : never;\n\nconst EITHER_PREFIX = 'Either:\\n';\n\n/**\n * Indents and adds a dash in front of this (potentially multiline) string.\n */\nfunction itemize(s: string): string {\n return `-${indent(s).substring(1)}`;\n}\n\n/**\n * Nests another error as an item under a new-to-be-created \"Either error\". If\n * the given subitem already is an \"Either error\" of itself, don't indent, but\n * just \"inject\" its items at the same error level, for nicely flattened either\n * expressions.\n *\n * Avoids:\n *\n * Either:\n * - Either:\n * - Must be P\n * - Either:\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n * And \"flattens\" these to:\n *\n * Either:\n * - Must be P\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n */\nfunction nest(errText: string): string {\n return errText.startsWith(EITHER_PREFIX)\n ? errText.substr(EITHER_PREFIX.length)\n : itemize(errText);\n}\n\n/**\n * Accepts values accepted by any of the given decoders.\n *\n * The decoders are tried on the input one by one, in the given order. The\n * first one that accepts the input \"wins\". If all decoders reject the input,\n * the input gets rejected.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function either<T extends readonly Decoder<any>[]>(\n ...decoders: T\n): Decoder<DecoderTypes<T>> {\n if (decoders.length === 0) {\n throw new Error('Pass at least one decoder to either()');\n }\n\n return define((blob, _, err) => {\n // Collect errors here along the way\n const errors = [];\n\n for (let i = 0; i < decoders.length; i++) {\n const result: DecodeResult<unknown> = decoders[i].decode(blob);\n if (result.ok) {\n return result as Ok<DecoderTypes<T>>;\n } else {\n errors.push(result.error);\n }\n }\n\n // Decoding all alternatives failed, return the combined error message\n const text =\n EITHER_PREFIX + errors.map((err) => nest(summarize(err).join('\\n'))).join('\\n');\n return err(text);\n });\n}\n\n/**\n * Accepts any value that is strictly-equal (using `===`) to one of the\n * specified values.\n */\nexport function oneOf<C extends Scalar>(constants: readonly C[]): Decoder<C> {\n return define((blob, ok, err) => {\n const winner = constants.find((c) => c === blob);\n if (winner !== undefined) {\n return ok(winner);\n }\n return err(\n `Must be one of ${constants.map((value) => JSON.stringify(value)).join(', ')}`,\n );\n });\n}\n\n/**\n * If you are decoding tagged unions you may want to use the `taggedUnion()`\n * decoder instead of the general purpose `either()` decoder to get better\n * error messages and better performance.\n *\n * This decoder is optimized for [tagged\n * unions](https://en.wikipedia.org/wiki/Tagged_union), i.e. a union of\n * objects where one field is used as the discriminator.\n *\n * ```ts\n * const A = object({ tag: constant('A'), foo: string });\n * const B = object({ tag: constant('B'), bar: number });\n *\n * const AorB = taggedUnion('tag', { A, B });\n * // ^^^\n * ```\n *\n * Decoding now works in two steps:\n *\n * 1. Look at the `'tag'` field in the incoming object (this is the field\n * that decides which decoder will be used)\n * 2. If the value is `'A'`, then decoder `A` will be used. If it's `'B'`, then\n * decoder `B` will be used. Otherwise, this will fail.\n *\n * This is effectively equivalent to `either(A, B)`, but will provide better\n * error messages and is more performant at runtime because it doesn't have to\n * try all decoders one by one.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function taggedUnion<O extends Record<string, Decoder<any>>>(\n field: string,\n mapping: O,\n): Decoder<Values<{ [key in keyof O]: DecoderType<O[key]> }>> {\n const base: Decoder<string> = object({\n [field]: prep(String, oneOf(Object.keys(mapping))),\n }).transform((o) => o[field]);\n return base.peek_UNSTABLE(([blob, key]) => {\n const decoder = mapping[key];\n return decoder.decode(blob);\n });\n}\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport type { Decoder, Scalar } from '../Decoder';\nimport { lazyval } from '../_utils';\n\n/**\n * Accepts and returns only the literal `null` value.\n */\nexport const null_ = constant(null);\n\n/**\n * Accepts and returns only the literal `undefined` value.\n */\nexport const undefined_ = constant(undefined);\n\nconst nullish_: Decoder<null | undefined> = define((blob, ok, err) =>\n blob == null /* or undefined */\n ? ok(blob)\n : // Combine error message into a single line for readability\n err('Must be undefined or null'),\n);\n\n/**\n * Accepts whatever the given decoder accepts, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `undefined` case.\n */\nexport function optional<T>(decoder: Decoder<T>): Decoder<T | undefined>;\nexport function optional<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function optional<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function optional<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | undefined> {\n const rv = either(undefined_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts whatever the given decoder accepts, or `null`.\n *\n * If a default value is explicitly provided, return that instead in the `null`\n * case.\n */\nexport function nullable<T>(decoder: Decoder<T>): Decoder<T | null>;\nexport function nullable<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function nullable<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function nullable<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null> {\n const rv = either(null_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * @deprecated\n * Alias of nullish().\n */\nexport const maybe = nullish;\n\n/**\n * Accepts whatever the given decoder accepts, or `null`, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `null`/`undefined` case.\n */\nexport function nullish<T>(decoder: Decoder<T>): Decoder<T | null | undefined>;\nexport function nullish<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function nullish<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function nullish<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null | undefined> {\n const rv = either(nullish_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts only the given constant value.\n */\nexport function constant<C extends Scalar>(value: C): Decoder<C> {\n return define((blob, ok, err) =>\n blob === value ? ok(value) : err(`Must be ${JSON.stringify(value)}`),\n );\n}\n\n/**\n * Accepts anything, completely ignores it, and always returns the provided\n * value instead.\n *\n * This is useful to manually add extra fields to object decoders.\n */\nexport function always<C extends Scalar>(value: C): Decoder<C>;\nexport function always<T>(value: (() => T) | T): Decoder<T>;\nexport function always<T>(value: (() => T) | T): Decoder<T> {\n return define(\n typeof value === 'function'\n ? (_, ok) => ok((value as () => T)())\n : (_, ok) => ok(value),\n );\n}\n\n/**\n * Rejects all inputs, and always fails with the given error message. May be\n * useful for explicitly disallowing keys, or for testing purposes.\n */\nexport function never(msg: string): Decoder<never> {\n return define((_, __, err) => err(msg));\n}\n\n/**\n * Alias of never().\n */\nexport const fail = never;\n\n/**\n * @deprecated\n * Alias of always.\n */\nexport const hardcoded = always;\n\n/**\n * Accepts anything and returns it unchanged.\n *\n * Useful for situation in which you don't know or expect a specific type. Of\n * course, the downside is that you won't know the type of the value statically\n * and you'll have to further refine it yourself.\n */\nexport const unknown: Decoder<unknown> = define((blob, ok, _) => ok(blob));\n\n/**\n * @deprecated\n * Alias of unknown.\n */\nexport const mixed = unknown;\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\n\n/**\n * Accepts any array, but doesn't validate its items further.\n *\n * \"poja\" means \"plain old JavaScript array\", a play on `pojo()`.\n */\nexport const poja: Decoder<unknown[]> = define((blob, ok, err) => {\n if (!Array.isArray(blob)) {\n return err('Must be an array');\n }\n return ok(blob as unknown[]);\n});\n\n/**\n * Given an array of Result instances, loop over them all and return:\n * - An [index, err] tuple, indicating the (index of the) first Err instance\n * encountered; or\n * - a new Ok with an array of all unwrapped Ok'ed values\n */\nfunction all<T>(\n items: readonly DecodeResult<T>[],\n blobs: readonly unknown[],\n\n // TODO: Make this less ugly\n ok: (value: T[]) => DecodeResult<T[]>,\n err: (ann: Annotation) => DecodeResult<T[]>,\n): DecodeResult<T[]> {\n const results: T[] = [];\n for (let index = 0; index < items.length; ++index) {\n const result = items[index];\n if (result.ok) {\n results.push(result.value);\n } else {\n const ann = result.error;\n\n // Rewrite the annotation to include the index information, and inject it into the original blob\n const clone = blobs.slice();\n clone.splice(\n index,\n 1,\n annotate(ann, ann.text ? `${ann.text} (at index ${index})` : `index ${index}`),\n );\n\n return err(annotate(clone));\n }\n }\n return ok(results);\n}\n\n/**\n * Accepts arrays of whatever the given decoder accepts.\n */\nexport function array<T>(decoder: Decoder<T>): Decoder<T[]> {\n const decodeFn = decoder.decode;\n return poja.then((blobs: readonly unknown[], ok, err) => {\n const results = blobs.map(decodeFn);\n return all(results, blobs, ok, err);\n });\n}\n\nfunction isNonEmpty<T>(arr: readonly T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Like `array()`, but will reject arrays with 0 elements.\n */\nexport function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<[T, ...T[]]> {\n return array(decoder).refine(isNonEmpty, 'Must be non-empty array');\n}\n\n/**\n * Similar to `array()`, but returns the result as an [ES6\n * Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).\n */\nexport function set<T>(decoder: Decoder<T>): Decoder<Set<T>> {\n return array(decoder).transform((items) => new Set(items));\n}\n\nconst ntuple = (n: number) =>\n poja.refine((arr) => arr.length === n, `Must be a ${n}-tuple`);\n\n/**\n * Accepts a tuple (an array with exactly _n_ items) of values accepted by the\n * _n_ given decoders.\n */\nexport function tuple<A>(a: Decoder<A>): Decoder<[A]>;\nexport function tuple<A, B>(a: Decoder<A>, b: Decoder<B>): Decoder<[A, B]>;\nexport function tuple<A, B, C>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n): Decoder<[A, B, C]>;\nexport function tuple<A, B, C, D>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n): Decoder<[A, B, C, D]>;\nexport function tuple<A, B, C, D, E>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n): Decoder<[A, B, C, D, E]>;\nexport function tuple<A, B, C, D, E, F>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n f: Decoder<F>,\n): Decoder<[A, B, C, D, E, F]>;\nexport function tuple(...decoders: readonly Decoder<unknown>[]): Decoder<unknown[]> {\n return ntuple(decoders.length).then((blobs, ok, err) => {\n let allOk = true;\n\n const rvs = decoders.map((decoder, i) => {\n const blob = blobs[i];\n const result = decoder.decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n allOk = false;\n return result.error;\n }\n });\n\n if (allOk) {\n return ok(rvs);\n } else {\n // If a decoder error has happened while unwrapping all the\n // results, try to construct a good error message\n return err(annotate(rvs));\n }\n });\n}\n","import { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts any valid ``number`` value.\n *\n * This also accepts special values like `NaN` and `Infinity`. Unless you\n * want to deliberately accept those, you'll likely want to use the\n * `number` decoder instead.\n */\nexport const anyNumber: Decoder<number> = define((blob, ok, err) =>\n typeof blob === 'number' ? ok(blob) : err('Must be number'),\n);\n\n/**\n * Accepts finite numbers (can be integer or float values). Values `NaN`,\n * or positive and negative `Infinity` will get rejected.\n */\nexport const number: Decoder<number> = anyNumber.refine(\n (n) => Number.isFinite(n),\n 'Number must be finite',\n);\n\n/**\n * Accepts only finite whole numbers.\n */\nexport const integer: Decoder<number> = number.refine(\n (n) => Number.isInteger(n),\n 'Number must be an integer',\n);\n\n/**\n * Accepts only non-negative (zero or positive) finite numbers.\n */\nexport const positiveNumber: Decoder<number> = number\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n\n/**\n * Accepts only non-negative (zero or positive) finite whole numbers.\n */\nexport const positiveInteger: Decoder<number> = integer\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n","import { define } from '../Decoder';\nimport { number } from './numbers';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts and returns booleans.\n */\nexport const boolean: Decoder<boolean> = define((blob, ok, err) => {\n return typeof blob === 'boolean' ? ok(blob) : err('Must be boolean');\n});\n\n/**\n * Accepts anything and will return its \"truth\" value. Will never reject.\n */\nexport const truthy: Decoder<boolean> = define((blob, ok, _) => ok(!!blob));\n\n/**\n * Accepts numbers, but return their boolean representation.\n */\nexport const numericBoolean: Decoder<boolean> = number.transform((n) => !!n);\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport { instanceOf } from './utilities';\nimport type { Decoder } from '../Decoder';\n\n/** Match groups in this regex:\n * \\1 - the scheme\n * \\2 - the username/password (optional)\n * \\3 - the host\n * \\4 - the port (optional)\n * \\5 - the path (optional)\n */\nconst url_re =\n /^([A-Za-z]{3,9}(?:[+][A-Za-z]{3,9})?):\\/\\/(?:([-;:&=+$,\\w]+)@)?(?:([A-Za-z0-9.-]+)(?::([0-9]{2,5}))?)(\\/(?:[-+~%/.,\\w]*)?(?:\\?[-+=&;%@.,/\\w]*)?(?:#[.,!/\\w]*)?)?$/;\n\n/**\n * Accepts and returns strings.\n */\nexport const string: Decoder<string> = define((blob, ok, err) =>\n typeof blob === 'string' ? ok(blob) : err('Must be string'),\n);\n\n/**\n * Like `string`, but will reject the empty string or strings containing only whitespace.\n */\nexport const nonEmptyString: Decoder<string> = regex(/\\S/, 'Must be non-empty string');\n\n/**\n * Accepts and returns strings that match the given regular expression.\n */\nexport function regex(regex: RegExp, msg: string): Decoder<string> {\n return string.refine((s) => regex.test(s), msg);\n}\n\n/**\n * Accepts and returns strings that are syntactically valid email addresses.\n * (This will not mean that the email address actually exist.)\n */\nexport const email: Decoder<string> = regex(\n // The almost perfect email regex, taken from https://emailregex.com/\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n 'Must be email',\n);\n\n/**\n * Accepts strings that are valid URLs, returns the value as a URL instance.\n */\nexport const url: Decoder<URL> = either(\n regex(url_re, 'Must be URL').transform((value) => new URL(value)),\n instanceOf(URL),\n);\n\n/**\n * Accepts strings that are valid URLs, but only HTTPS ones. Returns the value\n * as a URL instance.\n */\nexport const httpsUrl: Decoder<URL> = url.refine(\n (value) => value.protocol === 'https:',\n 'Must be an HTTPS URL',\n);\n\n/**\n * Accepts strings that are valid\n * [UUIDs](https://en.wikipedia.org/wiki/universally_unique_identifier)\n * (universally unique identifier).\n */\nexport const uuid: Decoder<string> = regex(\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,\n 'Must be uuid',\n);\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv1](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_%28date-time_and_MAC_address%29)\n * strings.\n */\nexport const uuidv1: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)\n uuid.refine((value) => value[14] === '1', 'Must be uuidv1');\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_%28random%29)\n * strings.\n */\nexport const uuidv4: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)\n uuid.refine((value) => value[14] === '4', 'Must be uuidv4');\n","import { asDate } from '../_utils';\nimport { define } from '../Decoder';\nimport { regex } from './strings';\nimport type { Decoder } from '../Decoder';\n\n// Only matches the shape. This \"over-matches\" some values that still aren't\n// valid dates (like 9999-99-99), but those will be caught by JS Date's\n// internal validations\nconst iso8601_re =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:[.]\\d+)?(?:Z|[+-]\\d{2}:?\\d{2})$/;\n\n/**\n * Accepts and returns `Date` instances.\n */\nexport const date: Decoder<Date> = define((blob, ok, err) => {\n const date = asDate(blob);\n return date !== null ? ok(date) : err('Must be a Date');\n});\n\n/**\n * Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,\n * returns them as `Date` instances.\n *\n * This is very useful for working with dates in APIs: serialize them as\n * `.toISOString()` when sending, decode them with `iso8601` when receiving.\n */\nexport const iso8601: Decoder<Date> =\n // Input itself needs to match the ISO8601 regex...\n regex(iso8601_re, 'Must be ISO8601 format').transform(\n // Make sure it is a _valid_ date\n (value: string) => {\n const date = new Date(value);\n if (isNaN(date.getTime())) {\n throw new Error('Must be valid date/time value');\n }\n return date;\n },\n );\n","import { array } from './arrays';\nimport { boolean } from './booleans';\nimport { dict } from './objects';\nimport { either } from './unions';\nimport { lazy } from './utilities';\nimport { null_ } from './basics';\nimport { number } from './numbers';\nimport { string } from './strings';\nimport type { Decoder } from '../Decoder';\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\nexport type JSONObject = { [key: string]: JSONValue | undefined };\nexport type JSONArray = JSONValue[];\n\n/**\n * Accepts objects that contain only valid JSON values.\n */\nexport const jsonObject: Decoder<JSONObject> = lazy(() => dict(json));\n\n/**\n * Accepts arrays that contain only valid JSON values.\n */\nexport const jsonArray: Decoder<JSONArray> = lazy(() => array(json));\n\n/**\n * Accepts any value that's a valid JSON value.\n *\n * In other words: any value returned by `JSON.parse()` should decode without\n * failure.\n *\n * ```typescript\n * type JSONValue =\n * | null\n * | string\n * | number\n * | boolean\n * | { [string]: JSONValue }\n * | JSONValue[]\n * ```\n */\nexport const json: Decoder<JSONValue> = either(\n null_,\n string,\n number,\n boolean,\n jsonObject,\n jsonArray,\n).describe('Must be valid JSON value');\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -186,15 +186,20 @@ declare function optional<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V
|
|
|
186
186
|
declare function nullable<T>(decoder: Decoder<T>): Decoder<T | null>;
|
|
187
187
|
declare function nullable<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>;
|
|
188
188
|
declare function nullable<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated
|
|
191
|
+
* Alias of nullish().
|
|
192
|
+
*/
|
|
193
|
+
declare const maybe: typeof nullish;
|
|
189
194
|
/**
|
|
190
195
|
* Accepts whatever the given decoder accepts, or `null`, or `undefined`.
|
|
191
196
|
*
|
|
192
197
|
* If a default value is explicitly provided, return that instead in the
|
|
193
198
|
* `null`/`undefined` case.
|
|
194
199
|
*/
|
|
195
|
-
declare function
|
|
196
|
-
declare function
|
|
197
|
-
declare function
|
|
200
|
+
declare function nullish<T>(decoder: Decoder<T>): Decoder<T | null | undefined>;
|
|
201
|
+
declare function nullish<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>;
|
|
202
|
+
declare function nullish<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>;
|
|
198
203
|
/**
|
|
199
204
|
* Accepts only the given constant value.
|
|
200
205
|
*/
|
|
@@ -208,6 +213,16 @@ declare function constant<C extends Scalar>(value: C): Decoder<C>;
|
|
|
208
213
|
declare function always<C extends Scalar>(value: C): Decoder<C>;
|
|
209
214
|
declare function always<T>(value: (() => T) | T): Decoder<T>;
|
|
210
215
|
/**
|
|
216
|
+
* Rejects all inputs, and always fails with the given error message. May be
|
|
217
|
+
* useful for explicitly disallowing keys, or for testing purposes.
|
|
218
|
+
*/
|
|
219
|
+
declare function never(msg: string): Decoder<never>;
|
|
220
|
+
/**
|
|
221
|
+
* Alias of never().
|
|
222
|
+
*/
|
|
223
|
+
declare const fail: typeof never;
|
|
224
|
+
/**
|
|
225
|
+
* @deprecated
|
|
211
226
|
* Alias of always.
|
|
212
227
|
*/
|
|
213
228
|
declare const hardcoded: typeof always;
|
|
@@ -220,6 +235,7 @@ declare const hardcoded: typeof always;
|
|
|
220
235
|
*/
|
|
221
236
|
declare const unknown: Decoder<unknown>;
|
|
222
237
|
/**
|
|
238
|
+
* @deprecated
|
|
223
239
|
* Alias of unknown.
|
|
224
240
|
*/
|
|
225
241
|
declare const mixed: Decoder<unknown>;
|
|
@@ -469,15 +485,6 @@ declare function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T>;
|
|
|
469
485
|
* ``unknown`` type, so you will have to deal with that accordingly.
|
|
470
486
|
*/
|
|
471
487
|
declare function prep<T>(mapperFn: (blob: unknown) => unknown, decoder: Decoder<T>): Decoder<T>;
|
|
472
|
-
/**
|
|
473
|
-
* Rejects all inputs, and always fails with the given error message. May be
|
|
474
|
-
* useful for explicitly disallowing keys, or for testing purposes.
|
|
475
|
-
*/
|
|
476
|
-
declare function never(msg: string): Decoder<never>;
|
|
477
|
-
/**
|
|
478
|
-
* Alias of never().
|
|
479
|
-
*/
|
|
480
|
-
declare const fail: typeof never;
|
|
481
488
|
|
|
482
489
|
/**
|
|
483
490
|
* Accepts any valid ``number`` value.
|
|
@@ -509,4 +516,4 @@ type Formatter = (err: Annotation) => string | Error;
|
|
|
509
516
|
declare function formatInline(ann: Annotation): string;
|
|
510
517
|
declare function formatShort(ann: Annotation): string;
|
|
511
518
|
|
|
512
|
-
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, always, anyNumber, array, boolean, constant, date, define, dict, either, email, err, exact, fail, formatInline, formatShort, hardcoded, httpsUrl, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, never, nonEmptyArray, nonEmptyString, null_, nullable, number, numericBoolean, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, regex, set, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
|
519
|
+
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, always, anyNumber, array, boolean, constant, date, define, dict, either, email, err, exact, fail, formatInline, formatShort, hardcoded, httpsUrl, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numericBoolean, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, regex, set, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
package/dist/index.d.ts
CHANGED
|
@@ -186,15 +186,20 @@ declare function optional<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V
|
|
|
186
186
|
declare function nullable<T>(decoder: Decoder<T>): Decoder<T | null>;
|
|
187
187
|
declare function nullable<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>;
|
|
188
188
|
declare function nullable<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated
|
|
191
|
+
* Alias of nullish().
|
|
192
|
+
*/
|
|
193
|
+
declare const maybe: typeof nullish;
|
|
189
194
|
/**
|
|
190
195
|
* Accepts whatever the given decoder accepts, or `null`, or `undefined`.
|
|
191
196
|
*
|
|
192
197
|
* If a default value is explicitly provided, return that instead in the
|
|
193
198
|
* `null`/`undefined` case.
|
|
194
199
|
*/
|
|
195
|
-
declare function
|
|
196
|
-
declare function
|
|
197
|
-
declare function
|
|
200
|
+
declare function nullish<T>(decoder: Decoder<T>): Decoder<T | null | undefined>;
|
|
201
|
+
declare function nullish<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>;
|
|
202
|
+
declare function nullish<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>;
|
|
198
203
|
/**
|
|
199
204
|
* Accepts only the given constant value.
|
|
200
205
|
*/
|
|
@@ -208,6 +213,16 @@ declare function constant<C extends Scalar>(value: C): Decoder<C>;
|
|
|
208
213
|
declare function always<C extends Scalar>(value: C): Decoder<C>;
|
|
209
214
|
declare function always<T>(value: (() => T) | T): Decoder<T>;
|
|
210
215
|
/**
|
|
216
|
+
* Rejects all inputs, and always fails with the given error message. May be
|
|
217
|
+
* useful for explicitly disallowing keys, or for testing purposes.
|
|
218
|
+
*/
|
|
219
|
+
declare function never(msg: string): Decoder<never>;
|
|
220
|
+
/**
|
|
221
|
+
* Alias of never().
|
|
222
|
+
*/
|
|
223
|
+
declare const fail: typeof never;
|
|
224
|
+
/**
|
|
225
|
+
* @deprecated
|
|
211
226
|
* Alias of always.
|
|
212
227
|
*/
|
|
213
228
|
declare const hardcoded: typeof always;
|
|
@@ -220,6 +235,7 @@ declare const hardcoded: typeof always;
|
|
|
220
235
|
*/
|
|
221
236
|
declare const unknown: Decoder<unknown>;
|
|
222
237
|
/**
|
|
238
|
+
* @deprecated
|
|
223
239
|
* Alias of unknown.
|
|
224
240
|
*/
|
|
225
241
|
declare const mixed: Decoder<unknown>;
|
|
@@ -469,15 +485,6 @@ declare function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T>;
|
|
|
469
485
|
* ``unknown`` type, so you will have to deal with that accordingly.
|
|
470
486
|
*/
|
|
471
487
|
declare function prep<T>(mapperFn: (blob: unknown) => unknown, decoder: Decoder<T>): Decoder<T>;
|
|
472
|
-
/**
|
|
473
|
-
* Rejects all inputs, and always fails with the given error message. May be
|
|
474
|
-
* useful for explicitly disallowing keys, or for testing purposes.
|
|
475
|
-
*/
|
|
476
|
-
declare function never(msg: string): Decoder<never>;
|
|
477
|
-
/**
|
|
478
|
-
* Alias of never().
|
|
479
|
-
*/
|
|
480
|
-
declare const fail: typeof never;
|
|
481
488
|
|
|
482
489
|
/**
|
|
483
490
|
* Accepts any valid ``number`` value.
|
|
@@ -509,4 +516,4 @@ type Formatter = (err: Annotation) => string | Error;
|
|
|
509
516
|
declare function formatInline(ann: Annotation): string;
|
|
510
517
|
declare function formatShort(ann: Annotation): string;
|
|
511
518
|
|
|
512
|
-
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, always, anyNumber, array, boolean, constant, date, define, dict, either, email, err, exact, fail, formatInline, formatShort, hardcoded, httpsUrl, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, never, nonEmptyArray, nonEmptyString, null_, nullable, number, numericBoolean, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, regex, set, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
|
519
|
+
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, always, anyNumber, array, boolean, constant, date, define, dict, either, email, err, exact, fail, formatInline, formatShort, hardcoded, httpsUrl, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numericBoolean, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, regex, set, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
package/dist/index.js
CHANGED
|
@@ -519,10 +519,6 @@ function prep(mapperFn, decoder) {
|
|
|
519
519
|
return r.ok ? r : err2(public_annotate(originalInput, r.error.text));
|
|
520
520
|
});
|
|
521
521
|
}
|
|
522
|
-
function never(msg) {
|
|
523
|
-
return define((_, __, err2) => err2(msg));
|
|
524
|
-
}
|
|
525
|
-
var fail = never;
|
|
526
522
|
|
|
527
523
|
// src/lib/unions.ts
|
|
528
524
|
var EITHER_PREFIX = "Either:\n";
|
|
@@ -572,14 +568,10 @@ function taggedUnion(field, mapping2) {
|
|
|
572
568
|
}
|
|
573
569
|
|
|
574
570
|
// src/lib/basics.ts
|
|
575
|
-
var null_ =
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
(blob, ok2, err2) => blob === void 0 ? ok2(blob) : err2("Must be undefined")
|
|
580
|
-
);
|
|
581
|
-
var undefined_or_null = define(
|
|
582
|
-
(blob, ok2, err2) => blob === void 0 || blob === null ? ok2(blob) : (
|
|
571
|
+
var null_ = constant(null);
|
|
572
|
+
var undefined_ = constant(void 0);
|
|
573
|
+
var nullish_ = define(
|
|
574
|
+
(blob, ok2, err2) => blob == null ? ok2(blob) : (
|
|
583
575
|
// Combine error message into a single line for readability
|
|
584
576
|
err2("Must be undefined or null")
|
|
585
577
|
)
|
|
@@ -592,13 +584,14 @@ function nullable(decoder, defaultValue) {
|
|
|
592
584
|
const rv = either(null_, decoder);
|
|
593
585
|
return arguments.length >= 2 ? rv.transform((value) => value ?? lazyval(defaultValue)) : rv;
|
|
594
586
|
}
|
|
595
|
-
|
|
596
|
-
|
|
587
|
+
var maybe = nullish;
|
|
588
|
+
function nullish(decoder, defaultValue) {
|
|
589
|
+
const rv = either(nullish_, decoder);
|
|
597
590
|
return arguments.length >= 2 ? rv.transform((value) => value ?? lazyval(defaultValue)) : rv;
|
|
598
591
|
}
|
|
599
592
|
function constant(value) {
|
|
600
593
|
return define(
|
|
601
|
-
(blob, ok2, err2) => blob === value ? ok2(value) : err2(`Must be
|
|
594
|
+
(blob, ok2, err2) => blob === value ? ok2(value) : err2(`Must be ${JSON.stringify(value)}`)
|
|
602
595
|
);
|
|
603
596
|
}
|
|
604
597
|
function always(value) {
|
|
@@ -606,6 +599,10 @@ function always(value) {
|
|
|
606
599
|
typeof value === "function" ? (_, ok2) => ok2(value()) : (_, ok2) => ok2(value)
|
|
607
600
|
);
|
|
608
601
|
}
|
|
602
|
+
function never(msg) {
|
|
603
|
+
return define((_, __, err2) => err2(msg));
|
|
604
|
+
}
|
|
605
|
+
var fail = never;
|
|
609
606
|
var hardcoded = always;
|
|
610
607
|
var unknown2 = define((blob, ok2, _) => ok2(blob));
|
|
611
608
|
var mixed = unknown2;
|
|
@@ -796,6 +793,7 @@ export {
|
|
|
796
793
|
nonEmptyString,
|
|
797
794
|
null_,
|
|
798
795
|
nullable,
|
|
796
|
+
nullish,
|
|
799
797
|
number,
|
|
800
798
|
numericBoolean,
|
|
801
799
|
object2 as object,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/_utils.ts","../src/annotate.ts","../src/format.ts","../src/result.ts","../src/Decoder.ts","../src/lib/objects.ts","../src/lib/utilities.ts","../src/lib/unions.ts","../src/lib/basics.ts","../src/lib/arrays.ts","../src/lib/numbers.ts","../src/lib/booleans.ts","../src/lib/strings.ts","../src/lib/dates.ts","../src/lib/json.ts"],"sourcesContent":["import type { Annotation } from './annotate';\nimport type { Scalar } from './Decoder';\n\n// Two spaces of indentation\nexport const INDENT = ' ';\n\nexport function lazyval<V>(value: (() => V) | V): V {\n return typeof value === 'function' ? (value as () => V)() : value;\n}\n\n/**\n * Subtract two sets. Why isn't this a standard method on Sets?\n */\nexport function subtract<C extends Scalar>(xs: Set<C>, ys: Set<C>): Set<C> {\n const result = new Set<C>();\n for (const x of xs) {\n if (!ys.has(x)) {\n result.add(x);\n }\n }\n return result;\n}\n\n/**\n * Is value is a valid Date instance, then return that. If not, then return\n * null.\n */\nexport function asDate(value: unknown): Date | null {\n //\n // `x instanceof Date` checks are unreliable across stack frames (that\n // information might get lost by the JS runtime), so we'll have to reside\n // to more runtime inspection checks.\n //\n // Taken from https://stackoverflow.com/a/44198641\n //\n return !!value &&\n Object.prototype.toString.call(value) === '[object Date]' &&\n !isNaN(value as number)\n ? (value as Date)\n : null;\n}\n\nexport function isPojo(value: unknown): value is Record<string, unknown> {\n return (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n // This still seems to be the only reliable way to determine whether\n // something is a pojo... ¯\\_(ツ)_/¯\n Object.prototype.toString.call(value) === '[object Object]'\n );\n}\n\nexport function isMultiline(s: string): boolean {\n return s.indexOf('\\n') >= 0;\n}\n\nexport function indent(s: string, prefix: string = INDENT): string {\n if (isMultiline(s)) {\n return s\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n');\n } else {\n return `${prefix}${s}`;\n }\n}\n\n/**\n * Walks the annotation tree and emits the annotation's key path within the\n * object tree, and the message as a series of messages (array of strings).\n */\nexport function summarize(\n ann: Annotation,\n keypath: readonly (number | string)[] = [],\n): string[] {\n const result: string[] = [];\n\n if (ann.type === 'array') {\n const items = ann.items;\n let index = 0;\n for (const ann of items) {\n for (const item of summarize(ann, [...keypath, index++])) {\n // Collect to results\n result.push(item);\n }\n }\n } else if (ann.type === 'object') {\n const fields = ann.fields;\n for (const key of Object.keys(fields)) {\n const value = fields[key];\n for (const item of summarize(value, [...keypath, key])) {\n // Collect to results\n result.push(item);\n }\n }\n }\n\n const text = ann.text;\n if (!text) {\n return result;\n }\n\n let prefix: string;\n if (keypath.length === 0) {\n prefix = '';\n } else if (keypath.length === 1) {\n prefix =\n typeof keypath[0] === 'number'\n ? `Value at index ${keypath[0]}: `\n : `Value at key ${JSON.stringify(keypath[0])}: `;\n } else {\n prefix = `Value at keypath ${keypath.map(String).join('.')}: `;\n }\n return [...result, `${prefix}${text}`];\n}\n","import { isPojo } from './_utils';\n\nconst _register: WeakSet<Annotation> = new WeakSet();\n\nexport interface ObjectAnnotation {\n readonly type: 'object';\n readonly fields: { readonly [key: string]: Annotation };\n readonly text?: string;\n}\n\nexport interface ArrayAnnotation {\n readonly type: 'array';\n readonly items: readonly Annotation[];\n readonly text?: string;\n}\n\nexport interface ScalarAnnotation {\n readonly type: 'scalar';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport interface FunctionAnnotation {\n readonly type: 'function';\n readonly text?: string;\n}\n\nexport interface CircularRefAnnotation {\n readonly type: 'circular-ref';\n readonly text?: string;\n}\n\nexport interface UnknownAnnotation {\n readonly type: 'unknown';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport type Annotation =\n | ObjectAnnotation\n | ArrayAnnotation\n | ScalarAnnotation\n | FunctionAnnotation\n | CircularRefAnnotation\n | UnknownAnnotation;\n\nfunction brand<A extends Annotation>(ann: A): A {\n _register.add(ann);\n return ann;\n}\n\nexport function object(\n fields: { readonly [key: string]: Annotation },\n text?: string,\n): ObjectAnnotation {\n return brand({ type: 'object', fields, text });\n}\n\nexport function array(items: readonly Annotation[], text?: string): ArrayAnnotation {\n return brand({\n type: 'array',\n items,\n text,\n });\n}\n\nexport function func(text?: string): FunctionAnnotation {\n return brand({\n type: 'function',\n text,\n });\n}\n\nexport function unknown(value: unknown, text?: string): UnknownAnnotation {\n return brand({\n type: 'unknown',\n value,\n text,\n });\n}\n\nexport function scalar(value: unknown, text?: string): ScalarAnnotation {\n return brand({\n type: 'scalar',\n value,\n text,\n });\n}\n\nexport function circularRef(text?: string): CircularRefAnnotation {\n return brand({\n type: 'circular-ref',\n text,\n });\n}\n\n/**\n * Given an existing Annotation, set the annotation's text to a new value.\n */\nexport function updateText<A extends Annotation>(annotation: A, text?: string): A {\n if (text !== undefined) {\n return brand({ ...annotation, text });\n } else {\n return annotation;\n }\n}\n\n/**\n * Given an existing ObjectAnnotation, merges new Annotations in there.\n */\nexport function merge(\n objAnnotation: ObjectAnnotation,\n fields: { readonly [key: string]: Annotation },\n): ObjectAnnotation {\n const newFields = { ...objAnnotation.fields, ...fields };\n return object(newFields, objAnnotation.text);\n}\n\nexport function asAnnotation(thing: unknown): Annotation | undefined {\n return typeof thing === 'object' && thing !== null && _register.has(thing as Annotation)\n ? (thing as Annotation)\n : undefined;\n}\n\ntype RefSet = WeakSet<object>;\n\n/** @internal */\nfunction annotateArray(\n value: readonly unknown[],\n text: string | undefined,\n seen: RefSet,\n): ArrayAnnotation | CircularRefAnnotation {\n seen.add(value);\n\n const items = value.map((v) => annotate(v, undefined, seen));\n return array(items, text);\n}\n\n/** @internal */\nfunction annotateObject(\n obj: Record<string, unknown>,\n text: string | undefined,\n seen: RefSet,\n): ObjectAnnotation {\n seen.add(obj);\n\n const fields: Record<string, Annotation> = {};\n for (const key of Object.keys(obj)) {\n const value = obj[key];\n fields[key] = annotate(value, undefined, seen);\n }\n return object(fields, text);\n}\n\n/** @internal */\nfunction annotate(value: unknown, text: string | undefined, seen: RefSet): Annotation {\n if (\n value === null ||\n value === undefined ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'symbol' ||\n typeof (value as Record<string, unknown>).getMonth === 'function'\n ) {\n return scalar(value, text);\n }\n\n const ann = asAnnotation(value);\n if (ann) {\n return updateText(ann, text);\n }\n\n if (Array.isArray(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateArray(value, text, seen);\n }\n }\n\n if (isPojo(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateObject(value, text, seen);\n }\n }\n\n if (typeof value === 'function') {\n return func(text);\n }\n\n return unknown(value, text);\n}\n\nfunction public_annotate(value: unknown, text?: string): Annotation {\n return annotate(value, text, new WeakSet());\n}\n\nfunction public_annotateObject(\n obj: { readonly [field: string]: unknown },\n text?: string,\n): ObjectAnnotation {\n return annotateObject(obj, text, new WeakSet());\n}\n\nexport {\n // This construct just ensures the \"seen\" weakmap (used for circular\n // reference detection) isn't made part of the public API.\n public_annotate as annotate,\n public_annotateObject as annotateObject,\n\n /** @internal */\n annotate as __private_annotate,\n};\n","import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils';\nimport type { Annotation, ArrayAnnotation, ObjectAnnotation } from './annotate';\n\nexport type Formatter = (err: Annotation) => string | Error;\n\nfunction serializeString(s: string, width: number = 80): string {\n // Full string\n // Abbreviated to $maxlen i.e. \"Vincent Driess...\" [truncated]\n let ser = JSON.stringify(s);\n if (ser.length <= width) {\n return ser;\n }\n\n // Cut off a bit\n const truncated = `${s.substring(0, width - 15)}...`;\n ser = `${JSON.stringify(truncated)} [truncated]`;\n return ser;\n}\n\nfunction serializeArray(annotation: ArrayAnnotation, prefix: string): string {\n const { items } = annotation;\n if (items.length === 0) {\n return '[]';\n }\n\n const result: string[] = [];\n for (const item of items) {\n const [ser, ann] = serializeAnnotation(item, `${prefix}${INDENT}`);\n result.push(`${prefix}${INDENT}${ser}${','}`);\n if (ann !== undefined) {\n result.push(indent(ann, `${prefix}${INDENT}`));\n }\n }\n return ['[', ...result, `${prefix}]`].join('\\n');\n}\n\nfunction serializeObject(annotation: ObjectAnnotation, prefix: string): string {\n const { fields } = annotation;\n\n const fieldNames = Object.keys(fields);\n if (fieldNames.length === 0) {\n return '{}';\n }\n\n const result: string[] = [];\n for (const key of fieldNames) {\n const valueAnnotation = fields[key];\n const kser = serializeValue(key);\n\n const valPrefix = `${prefix}${INDENT}${' '.repeat(kser.length + 2)}`;\n const [vser, vann] = serializeAnnotation(valueAnnotation, `${prefix}${INDENT}`);\n\n result.push(`${prefix}${INDENT}${kser}: ${vser},`);\n if (vann !== undefined) {\n result.push(indent(vann, valPrefix));\n }\n }\n return ['{', ...result, `${prefix}}`].join('\\n');\n}\n\nexport function serializeValue(value: unknown): string {\n if (typeof value === 'string') {\n return serializeString(value);\n } else if (typeof value === 'number' || typeof value === 'boolean') {\n return value.toString();\n } else if (value === null) {\n return 'null';\n } else if (value === undefined) {\n return 'undefined';\n } else {\n const valueAsDate = asDate(value);\n if (valueAsDate !== null) {\n return `new Date(${JSON.stringify(valueAsDate.toISOString())})`;\n } else if (value instanceof Date) {\n // NOTE: Using `instanceof Date` is unreliable way of checking dates.\n // If this case occurs (and it didn't pass the prior asDate())\n // check, then this must be the case where it's an invalid date.\n return '(Invalid Date)';\n } else {\n return '(unserializable)';\n }\n }\n}\n\nexport function serializeAnnotation(\n ann: Annotation,\n prefix: string = '',\n): [string, string | undefined] {\n // The serialized data (the input object echoed back)\n let serialized;\n if (ann.type === 'array') {\n serialized = serializeArray(ann, prefix);\n } else if (ann.type === 'object') {\n serialized = serializeObject(ann, prefix);\n } else if (ann.type === 'function') {\n serialized = '<function>';\n } else if (ann.type === 'circular-ref') {\n serialized = '<circular ref>';\n } else if (ann.type === 'unknown') {\n serialized = '???';\n } else {\n serialized = serializeValue(ann.value);\n }\n\n const text = ann.text;\n if (text !== undefined) {\n const sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length);\n return [serialized, [sep, text].join(isMultiline(text) ? '\\n' : ' ')];\n } else {\n return [serialized, undefined];\n }\n}\n\nexport function formatInline(ann: Annotation): string {\n const [serialized, annotation] = serializeAnnotation(ann);\n if (annotation !== undefined) {\n return `${serialized}\\n${annotation}`;\n } else {\n return serialized;\n }\n}\n\nexport function formatShort(ann: Annotation): string {\n return _summarize(ann, []).join('\\n');\n}\n","/**\n * Result <value> <error>\n * = Ok <value>\n * | Err <error>\n */\nexport type Ok<T> = {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n};\n\nexport type Err<E> = {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n};\n\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Create a new Result instance representing a successful computation.\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: undefined };\n}\n\n/**\n * Create a new Result instance representing a failed computation.\n */\nexport function err<E>(error: E): Err<E> {\n return { ok: false, value: undefined, error };\n}\n","import { annotate } from './annotate';\nimport { formatInline } from './format';\nimport { err as makeErr, ok as makeOk } from './result';\nimport type { Annotation } from './annotate';\nimport type { Formatter } from './format';\nimport type { Result } from './result';\n\nexport type Scalar = string | number | boolean | symbol | undefined | null;\n\nexport type DecodeResult<T> = Result<T, Annotation>;\n\nexport type AcceptanceFn<T, InputT = unknown> = (\n blob: InputT,\n ok: (value: T) => DecodeResult<T>,\n err: (msg: string | Annotation) => DecodeResult<T>,\n) => DecodeResult<T>;\n\nexport interface Decoder<T> {\n /**\n * Verifies untrusted input. Either returns a value, or throws a decoding\n * error.\n */\n verify(blob: unknown, formatterFn?: (ann: Annotation) => string | Error): T;\n\n /**\n * Verifies untrusted input. Either returns a value, or returns undefined.\n */\n value(blob: unknown): T | undefined;\n\n /**\n * Verifies untrusted input. Always returns a DecodeResult, which is either\n * an \"ok\" value or an \"error\" annotation.\n */\n decode(blob: unknown): DecodeResult<T>;\n\n /**\n * Build a new decoder from the the current one, with an extra acceptance\n * criterium.\n */\n refine<N extends T>(predicate: (value: T) => value is N, msg: string): Decoder<N>;\n refine(predicate: (value: T) => boolean, msg: string): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, with an extra rejection\n * criterium.\n */\n reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, modifying its outputted value.\n */\n transform<V>(transformFn: (value: T) => V): Decoder<V>;\n\n /**\n * Build a new decoder from the current one, with a mutated error message\n * in case of a rejection.\n */\n describe(message: string): Decoder<T>;\n\n /**\n * Chain together the current decoder with another acceptance function.\n */\n then<V>(next: AcceptanceFn<V, T>): Decoder<V>;\n\n // Experimental APIs (please don't rely on these yet)\n peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V>;\n}\n\n/**\n * Helper type to return the \"type\" of a Decoder.\n *\n * You can use it on types:\n *\n * DecoderType<Decoder<string>> // string\n * DecoderType<Decoder<number[]>> // number[]\n *\n * Or on \"values\", by using the `typeof` keyword:\n *\n * DecoderType<typeof string> // string\n * DecoderType<typeof truthy> // boolean\n *\n */\nexport type DecoderType<D extends Decoder<any>> = D extends Decoder<infer T> ? T : never;\n\nfunction noThrow<T, V>(fn: (value: T) => V): (blob: T) => DecodeResult<V> {\n return (t) => {\n try {\n const v = fn(t);\n return makeOk(v);\n } catch (e) {\n return makeErr(annotate(t, e instanceof Error ? e.message : String(e)));\n }\n };\n}\n\nfunction format(err: Annotation, formatter: Formatter): Error {\n const formatted = formatter(err);\n\n // Formatter functions may return a string or an error for convenience of\n // writing them. If it already returns an Error, return it unmodified. If\n // it returns a string, wrap it in a \"Decoding error\" instance.\n if (typeof formatted === 'string') {\n const err = new Error(`\\n${formatted}`);\n err.name = 'Decoding error';\n return err;\n } else {\n return formatted;\n }\n}\n\n/**\n * Defines a new `Decoder<T>`, by implementing a custom acceptance function.\n * The function receives three arguments:\n *\n * 1. `blob` - the raw/unknown input (aka your external data)\n * 2. `ok` - Call `ok(value)` to accept the input and return ``value``\n * 3. `err` - Call `err(message)` to reject the input with error ``message``\n *\n * The expected return value should be a `DecodeResult<T>`, which can be\n * obtained by returning the result of calling the provided `ok` or `err`\n * helper functions. Please note that `ok()` and `err()` don't perform side\n * effects! You'll need to _return_ those values.\n */\nexport function define<T>(fn: AcceptanceFn<T>): Decoder<T> {\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n *\n * Contrasted with `.verify()`, calls to `.decode()` will never fail and\n * instead return a result type.\n */\n function decode(blob: unknown): DecodeResult<T> {\n return fn(blob, makeOk, (msg: Annotation | string) =>\n makeErr(typeof msg === 'string' ? annotate(blob, msg) : msg),\n );\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns a value of type `T`. Otherwise fail with\n * a runtime error.\n */\n function verify(blob: unknown, formatter: Formatter = formatInline): T {\n const result = decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n throw format(result.error, formatter);\n }\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns the decoded `T` value directly. Otherwise returns\n * `undefined`.\n *\n * Use this when you're not interested in programmatically handling the\n * error message.\n */\n function value(blob: unknown): T | undefined {\n return decode(blob).value;\n }\n\n /**\n * Accepts any value the given decoder accepts, and on success, will call\n * the given function **on the decoded result**. If the transformation\n * function throws an error, the whole decoder will fail using the error\n * message as the failure reason.\n */\n function transform<V>(transformFn: (result: T) => V): Decoder<V> {\n return then(noThrow(transformFn));\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that also meet the\n * predicate.\n */\n function refine(predicateFn: (value: T) => boolean, errmsg: string): Decoder<T> {\n return reject((value) =>\n predicateFn(value)\n ? // Don't reject\n null\n : // Reject with the given error message\n errmsg,\n );\n }\n\n /**\n * Chain together the current decoder with another.\n *\n * > _**NOTE:** This is an advanced, low-level, API. It's not recommended\n * > to reach for this construct unless there is no other way. Most cases can\n * > be covered more elegantly by `.transform()` or `.refine()` instead._\n *\n * If the current decoder accepts an input, the resulting ``T`` value will\n * get passed into the given ``next`` acceptance function to further decide\n * whether or not the value should get accepted or rejected.\n *\n * This works similar to how you would `define()` a new decoder, except\n * that the ``blob`` param will now be ``T`` (a known type), rather than\n * ``unknown``. This will allow the function to make a stronger assumption\n * about its input and avoid re-refining inputs.\n *\n * If it helps, you can think of `define(...)` as equivalent to\n * `unknown.then(...)`.\n */\n function then<V>(next: AcceptanceFn<V, T>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next(result.value, ok, err) : result;\n });\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that aren't rejected by the\n * given function.\n *\n * The given function can return `null` to accept the decoded value, or\n * return a specific error message to reject.\n *\n * Unlike `.refine()`, you can use this function to return a dynamic error\n * message.\n */\n function reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T> {\n return then((value, ok, err) => {\n const errmsg = rejectFn(value);\n return errmsg === null\n ? ok(value)\n : err(typeof errmsg === 'string' ? annotate(value, errmsg) : errmsg);\n });\n }\n\n /**\n * Uses the given decoder, but will use an alternative error message in\n * case it rejects. This can be used to simplify or shorten otherwise\n * long or low-level/technical errors.\n */\n function describe(message: string): Decoder<T> {\n return define((blob, _, err) => {\n // Decode using the given decoder...\n const result = decode(blob);\n if (result.ok) {\n return result;\n } else {\n // ...but in case of error, annotate this with the custom given\n // message instead\n return err(annotate(result.error, message));\n }\n });\n }\n\n /**\n * WARNING: This is an EXPERIMENTAL API that will likely change in the\n * future. Please DO NOT rely on it.\n *\n * Chain together the current decoder with another, but also pass along\n * the original input.\n *\n * This is like `.then()`, but instead of this function receiving just\n * the decoded result ``T``, it also receives the original input.\n *\n * This is an advanced, low-level, decoder.\n */\n function peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next([blob, result.value], ok, err) : result;\n });\n }\n\n return Object.freeze({\n verify,\n value,\n decode,\n transform,\n refine,\n reject,\n describe,\n then,\n\n // EXPERIMENTAL - please DO NOT rely on this method\n peek_UNSTABLE,\n });\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { annotateObject, merge, updateText } from '../annotate';\nimport { define } from '../Decoder';\nimport { subtract, isPojo } from '../_utils';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\nimport type { UndefinedToOptional } from './_helpers';\n\ntype ObjectDecoderType<T> = UndefinedToOptional<{\n [K in keyof T]: T[K] extends Decoder<infer V> ? V : never;\n}>;\n\n/**\n * Accepts any \"plain old JavaScript object\", but doesn't validate its keys or\n * values further.\n */\nexport const pojo: Decoder<Record<string, unknown>> = define((blob, ok, err) =>\n isPojo(blob) ? ok(blob) : err('Must be an object'),\n);\n\n/**\n * Accepts objects with fields matching the given decoders. Extra fields that\n * exist on the input object are ignored and will not be returned.\n */\nexport function object(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>> {\n // Compute this set at decoder definition time\n const knownKeys = new Set(Object.keys(decodersByKey));\n\n return pojo.then((plainObj, ok, err) => {\n const actualKeys = new Set(Object.keys(plainObj));\n\n // At this point, \"missingKeys\" will also include all fields that may\n // validly be optional. We'll let the underlying decoder decide and\n // remove the key from this missing set if the decoder accepts the\n // value.\n const missingKeys = subtract(knownKeys, actualKeys);\n\n const record = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(decodersByKey)) {\n const decoder = decodersByKey[key];\n const rawValue = plainObj[key];\n const result: DecodeResult<unknown> = decoder.decode(rawValue);\n\n if (result.ok) {\n const value = result.value;\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n record[key] = value;\n }\n\n // If this succeeded, remove the key from the missing keys\n // tracker\n missingKeys.delete(key);\n } else {\n const ann = result.error;\n\n // Keep track of the annotation, but don't return just yet. We\n // want to collect more error information.\n if (rawValue === undefined) {\n // Explicitly add it to the missing set if the value is\n // undefined. This covers explicit undefineds to be\n // treated the same as implicit undefineds (aka missing\n // keys).\n missingKeys.add(key);\n } else {\n if (errors === null) {\n errors = {};\n }\n errors[key] = ann;\n }\n }\n }\n\n // Deal with errors now. There are two classes of errors we want to\n // report. First of all, we want to report any inline errors in this\n // object. Lastly, any fields that are missing should be annotated on\n // the outer object itself.\n if (errors || missingKeys.size > 0) {\n let objAnn = annotateObject(plainObj);\n\n if (errors) {\n objAnn = merge(objAnn, errors);\n }\n\n if (missingKeys.size > 0) {\n const errMsg = Array.from(missingKeys)\n .map((key) => `\"${key}\"`)\n .join(', ');\n const pluralized = missingKeys.size > 1 ? 'keys' : 'key';\n objAnn = updateText(objAnn, `Missing ${pluralized}: ${errMsg}`);\n }\n\n return err(objAnn);\n }\n\n return ok(record as ObjectDecoderType<DS>);\n });\n}\n\n/**\n * Like `object()`, but will reject inputs that contain extra fields that are\n * not specified explicitly.\n */\nexport function exact(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }> {\n // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n // Ditto (see above)\n\n // Compute this set at decoder definition time\n const allowedKeys = new Set(Object.keys(decodersByKey));\n\n // Check the inputted object for any unexpected extra keys\n const checked = pojo.reject((plainObj) => {\n const actualKeys = new Set(Object.keys(plainObj));\n const extraKeys = subtract(actualKeys, allowedKeys);\n return extraKeys.size > 0\n ? `Unexpected extra keys: ${Array.from(extraKeys).join(', ')}`\n : // Don't reject\n null;\n });\n\n // Defer to the \"object\" decoder for doing the real decoding work. Since\n // we made sure there are no superfluous keys in this structure, it's now\n // safe to force-cast it to an $Exact<> type.\n return checked.then(object(decodersByKey).decode);\n}\n\n/**\n * Like `object()`, but will pass through any extra fields on the input object\n * unvalidated that will thus be of `unknown` type statically.\n */\nexport function inexact(\n decodersByKey: Record<any, never>,\n): Decoder<Record<string, unknown>>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n> {\n return pojo.then((plainObj) => {\n const allkeys = new Set(Object.keys(plainObj));\n const decoder = object(decodersByKey).transform((safepart) => {\n const safekeys = new Set(Object.keys(decodersByKey));\n\n // To account for hard-coded keys that aren't part of the input\n for (const k of safekeys) allkeys.add(k);\n\n const rv = {} as {\n [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K];\n } & Record<string, unknown>;\n for (const k of allkeys) {\n if (safekeys.has(k)) {\n const value = safepart[k];\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n rv[k] = value;\n }\n } else {\n // @ts-expect-error - look into this later\n rv[k] = plainObj[k];\n }\n }\n return rv;\n });\n return decoder.decode(plainObj);\n });\n}\n\n/**\n * Accepts objects where all values match the given decoder, and returns the\n * result as a `Record<string, T>`.\n *\n * The main difference between `object()` and `dict()` is that you'd typically\n * use `object()` if this is a record-like object, where all field names are\n * known and the values are heterogeneous. Whereas with `dict()` the keys are\n * typically dynamic and the values homogeneous, like in a dictionary,\n * a lookup table, or a cache.\n */\nexport function dict<T>(decoder: Decoder<T>): Decoder<Record<string, T>> {\n return pojo.then((plainObj, ok, err) => {\n let rv: Record<string, T> = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(plainObj)) {\n const value = plainObj[key];\n const result = decoder.decode(value);\n if (result.ok) {\n if (errors === null) {\n rv[key] = result.value;\n }\n } else {\n rv = {}; // Clear the success value so it can get garbage collected early\n if (errors === null) {\n errors = {};\n }\n errors[key] = result.error;\n }\n }\n\n if (errors !== null) {\n return err(merge(annotateObject(plainObj), errors));\n } else {\n return ok(rv);\n }\n });\n}\n\n/**\n * Similar to `dict()`, but returns the result as a `Map<string, T>` (an [ES6\n * Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map))\n * instead.\n */\nexport function mapping<T>(decoder: Decoder<T>): Decoder<Map<string, T>> {\n return dict(decoder).transform(\n (obj) =>\n new Map(\n // This is effectively Object.entries(obj), but in a way that Flow\n // will know the types are okay\n Object.keys(obj).map((key) => [key, obj[key]]),\n ),\n );\n}\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport interface Klass<T> extends Function {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: readonly any[]): T;\n}\n\nexport type Instance<K> = K extends Klass<infer T> ? T : never;\n\n/**\n * Accepts any value that is an ``instanceof`` the given class.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instanceOf<K extends Klass<any>>(klass: K): Decoder<Instance<K>> {\n return define((blob, ok, err) =>\n blob instanceof klass ? ok(blob) : err(`Must be ${klass.name} instance`),\n );\n}\n\n/**\n * Lazily evaluate the given decoder. This is useful to build self-referential\n * types for recursive data structures.\n */\nexport function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T> {\n return define((blob) => decoderFn().decode(blob));\n}\n\n/**\n * Pre-process the data input before passing it into the decoder. This gives\n * you the ability to arbitrarily customize the input on the fly before passing\n * it to the decoder. Of course, the input value at that point is still of\n * ``unknown`` type, so you will have to deal with that accordingly.\n */\nexport function prep<T>(\n mapperFn: (blob: unknown) => unknown,\n decoder: Decoder<T>,\n): Decoder<T> {\n return define((originalInput, _, err) => {\n let blob;\n try {\n blob = mapperFn(originalInput);\n } catch (e: unknown) {\n return err(\n annotate(\n originalInput,\n // istanbul ignore next\n e instanceof Error ? e.message : String(e),\n ),\n );\n }\n\n const r = decoder.decode(blob);\n return r.ok ? r : err(annotate(originalInput, r.error.text));\n // ^^^^^^^^^^^^^\n // Annotates the _original_ input value\n // (instead of echoing back blob)\n });\n}\n\n/**\n * Rejects all inputs, and always fails with the given error message. May be\n * useful for explicitly disallowing keys, or for testing purposes.\n */\nexport function never(msg: string): Decoder<never> {\n return define((_, __, err) => err(msg));\n}\n\n/**\n * Alias of never().\n */\nexport const fail = never;\n","import { define } from '../Decoder';\nimport { indent, summarize } from '../_utils';\nimport { object } from './objects';\nimport { prep } from './utilities';\nimport type { Decoder, DecoderType, DecodeResult, Scalar } from '../Decoder';\nimport type { Ok } from '../result';\n\ntype Values<T extends object> = T[keyof T];\n\ntype DecoderTypes<T> = T extends readonly Decoder<infer U>[] ? U : never;\n\nconst EITHER_PREFIX = 'Either:\\n';\n\n/**\n * Indents and adds a dash in front of this (potentially multiline) string.\n */\nfunction itemize(s: string): string {\n return `-${indent(s).substring(1)}`;\n}\n\n/**\n * Nests another error as an item under a new-to-be-created \"Either error\". If\n * the given subitem already is an \"Either error\" of itself, don't indent, but\n * just \"inject\" its items at the same error level, for nicely flattened either\n * expressions.\n *\n * Avoids:\n *\n * Either:\n * - Either:\n * - Must be P\n * - Either:\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n * And \"flattens\" these to:\n *\n * Either:\n * - Must be P\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n */\nfunction nest(errText: string): string {\n return errText.startsWith(EITHER_PREFIX)\n ? errText.substr(EITHER_PREFIX.length)\n : itemize(errText);\n}\n\n/**\n * Accepts values accepted by any of the given decoders.\n *\n * The decoders are tried on the input one by one, in the given order. The\n * first one that accepts the input \"wins\". If all decoders reject the input,\n * the input gets rejected.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function either<T extends readonly Decoder<any>[]>(\n ...decoders: T\n): Decoder<DecoderTypes<T>> {\n if (decoders.length === 0) {\n throw new Error('Pass at least one decoder to either()');\n }\n\n return define((blob, _, err) => {\n // Collect errors here along the way\n const errors = [];\n\n for (let i = 0; i < decoders.length; i++) {\n const result: DecodeResult<unknown> = decoders[i].decode(blob);\n if (result.ok) {\n return result as Ok<DecoderTypes<T>>;\n } else {\n errors.push(result.error);\n }\n }\n\n // Decoding all alternatives failed, return the combined error message\n const text =\n EITHER_PREFIX + errors.map((err) => nest(summarize(err).join('\\n'))).join('\\n');\n return err(text);\n });\n}\n\n/**\n * Accepts any value that is strictly-equal (using `===`) to one of the\n * specified values.\n */\nexport function oneOf<C extends Scalar>(constants: readonly C[]): Decoder<C> {\n return define((blob, ok, err) => {\n const winner = constants.find((c) => c === blob);\n if (winner !== undefined) {\n return ok(winner);\n }\n return err(\n `Must be one of ${constants.map((value) => JSON.stringify(value)).join(', ')}`,\n );\n });\n}\n\n/**\n * If you are decoding tagged unions you may want to use the `taggedUnion()`\n * decoder instead of the general purpose `either()` decoder to get better\n * error messages and better performance.\n *\n * This decoder is optimized for [tagged\n * unions](https://en.wikipedia.org/wiki/Tagged_union), i.e. a union of\n * objects where one field is used as the discriminator.\n *\n * ```ts\n * const A = object({ tag: constant('A'), foo: string });\n * const B = object({ tag: constant('B'), bar: number });\n *\n * const AorB = taggedUnion('tag', { A, B });\n * // ^^^\n * ```\n *\n * Decoding now works in two steps:\n *\n * 1. Look at the `'tag'` field in the incoming object (this is the field\n * that decides which decoder will be used)\n * 2. If the value is `'A'`, then decoder `A` will be used. If it's `'B'`, then\n * decoder `B` will be used. Otherwise, this will fail.\n *\n * This is effectively equivalent to `either(A, B)`, but will provide better\n * error messages and is more performant at runtime because it doesn't have to\n * try all decoders one by one.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function taggedUnion<O extends Record<string, Decoder<any>>>(\n field: string,\n mapping: O,\n): Decoder<Values<{ [key in keyof O]: DecoderType<O[key]> }>> {\n const base: Decoder<string> = object({\n [field]: prep(String, oneOf(Object.keys(mapping))),\n }).transform((o) => o[field]);\n return base.peek_UNSTABLE(([blob, key]) => {\n const decoder = mapping[key];\n return decoder.decode(blob);\n });\n}\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport type { Decoder, Scalar } from '../Decoder';\nimport { lazyval } from '../_utils';\n\n/**\n * Accepts and returns only the literal `null` value.\n */\nexport const null_: Decoder<null> = define((blob, ok, err) =>\n blob === null ? ok(blob) : err('Must be null'),\n);\n\n/**\n * Accepts and returns only the literal `undefined` value.\n */\nexport const undefined_: Decoder<undefined> = define((blob, ok, err) =>\n blob === undefined ? ok(blob) : err('Must be undefined'),\n);\n\nconst undefined_or_null: Decoder<null | undefined> = define((blob, ok, err) =>\n blob === undefined || blob === null\n ? ok(blob)\n : // Combine error message into a single line for readability\n err('Must be undefined or null'),\n);\n\n/**\n * Accepts whatever the given decoder accepts, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `undefined` case.\n */\nexport function optional<T>(decoder: Decoder<T>): Decoder<T | undefined>;\nexport function optional<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function optional<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function optional<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | undefined> {\n const rv = either(undefined_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts whatever the given decoder accepts, or `null`.\n *\n * If a default value is explicitly provided, return that instead in the `null`\n * case.\n */\nexport function nullable<T>(decoder: Decoder<T>): Decoder<T | null>;\nexport function nullable<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function nullable<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function nullable<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null> {\n const rv = either(null_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts whatever the given decoder accepts, or `null`, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `null`/`undefined` case.\n */\nexport function maybe<T>(decoder: Decoder<T>): Decoder<T | null | undefined>;\nexport function maybe<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function maybe<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function maybe<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null | undefined> {\n const rv = either(undefined_or_null, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts only the given constant value.\n */\nexport function constant<C extends Scalar>(value: C): Decoder<C> {\n return define((blob, ok, err) =>\n blob === value ? ok(value) : err(`Must be constant ${String(value)}`),\n );\n}\n\n/**\n * Accepts anything, completely ignores it, and always returns the provided\n * value instead.\n *\n * This is useful to manually add extra fields to object decoders.\n */\nexport function always<C extends Scalar>(value: C): Decoder<C>;\nexport function always<T>(value: (() => T) | T): Decoder<T>;\nexport function always<T>(value: (() => T) | T): Decoder<T> {\n return define(\n typeof value === 'function'\n ? (_, ok) => ok((value as () => T)())\n : (_, ok) => ok(value),\n );\n}\n\n/**\n * Alias of always.\n */\nexport const hardcoded = always;\n\n/**\n * Accepts anything and returns it unchanged.\n *\n * Useful for situation in which you don't know or expect a specific type. Of\n * course, the downside is that you won't know the type of the value statically\n * and you'll have to further refine it yourself.\n */\nexport const unknown: Decoder<unknown> = define((blob, ok, _) => ok(blob));\n\n/**\n * Alias of unknown.\n */\nexport const mixed = unknown;\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\n\n/**\n * Accepts any array, but doesn't validate its items further.\n *\n * \"poja\" means \"plain old JavaScript array\", a play on `pojo()`.\n */\nexport const poja: Decoder<unknown[]> = define((blob, ok, err) => {\n if (!Array.isArray(blob)) {\n return err('Must be an array');\n }\n return ok(blob as unknown[]);\n});\n\n/**\n * Given an array of Result instances, loop over them all and return:\n * - An [index, err] tuple, indicating the (index of the) first Err instance\n * encountered; or\n * - a new Ok with an array of all unwrapped Ok'ed values\n */\nfunction all<T>(\n items: readonly DecodeResult<T>[],\n blobs: readonly unknown[],\n\n // TODO: Make this less ugly\n ok: (value: T[]) => DecodeResult<T[]>,\n err: (ann: Annotation) => DecodeResult<T[]>,\n): DecodeResult<T[]> {\n const results: T[] = [];\n for (let index = 0; index < items.length; ++index) {\n const result = items[index];\n if (result.ok) {\n results.push(result.value);\n } else {\n const ann = result.error;\n\n // Rewrite the annotation to include the index information, and inject it into the original blob\n const clone = blobs.slice();\n clone.splice(\n index,\n 1,\n annotate(ann, ann.text ? `${ann.text} (at index ${index})` : `index ${index}`),\n );\n\n return err(annotate(clone));\n }\n }\n return ok(results);\n}\n\n/**\n * Accepts arrays of whatever the given decoder accepts.\n */\nexport function array<T>(decoder: Decoder<T>): Decoder<T[]> {\n const decodeFn = decoder.decode;\n return poja.then((blobs: readonly unknown[], ok, err) => {\n const results = blobs.map(decodeFn);\n return all(results, blobs, ok, err);\n });\n}\n\nfunction isNonEmpty<T>(arr: readonly T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Like `array()`, but will reject arrays with 0 elements.\n */\nexport function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<[T, ...T[]]> {\n return array(decoder).refine(isNonEmpty, 'Must be non-empty array');\n}\n\n/**\n * Similar to `array()`, but returns the result as an [ES6\n * Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).\n */\nexport function set<T>(decoder: Decoder<T>): Decoder<Set<T>> {\n return array(decoder).transform((items) => new Set(items));\n}\n\nconst ntuple = (n: number) =>\n poja.refine((arr) => arr.length === n, `Must be a ${n}-tuple`);\n\n/**\n * Accepts a tuple (an array with exactly _n_ items) of values accepted by the\n * _n_ given decoders.\n */\nexport function tuple<A>(a: Decoder<A>): Decoder<[A]>;\nexport function tuple<A, B>(a: Decoder<A>, b: Decoder<B>): Decoder<[A, B]>;\nexport function tuple<A, B, C>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n): Decoder<[A, B, C]>;\nexport function tuple<A, B, C, D>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n): Decoder<[A, B, C, D]>;\nexport function tuple<A, B, C, D, E>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n): Decoder<[A, B, C, D, E]>;\nexport function tuple<A, B, C, D, E, F>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n f: Decoder<F>,\n): Decoder<[A, B, C, D, E, F]>;\nexport function tuple(...decoders: readonly Decoder<unknown>[]): Decoder<unknown[]> {\n return ntuple(decoders.length).then((blobs, ok, err) => {\n let allOk = true;\n\n const rvs = decoders.map((decoder, i) => {\n const blob = blobs[i];\n const result = decoder.decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n allOk = false;\n return result.error;\n }\n });\n\n if (allOk) {\n return ok(rvs);\n } else {\n // If a decoder error has happened while unwrapping all the\n // results, try to construct a good error message\n return err(annotate(rvs));\n }\n });\n}\n","import { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts any valid ``number`` value.\n *\n * This also accepts special values like `NaN` and `Infinity`. Unless you\n * want to deliberately accept those, you'll likely want to use the\n * `number` decoder instead.\n */\nexport const anyNumber: Decoder<number> = define((blob, ok, err) =>\n typeof blob === 'number' ? ok(blob) : err('Must be number'),\n);\n\n/**\n * Accepts finite numbers (can be integer or float values). Values `NaN`,\n * or positive and negative `Infinity` will get rejected.\n */\nexport const number: Decoder<number> = anyNumber.refine(\n (n) => Number.isFinite(n),\n 'Number must be finite',\n);\n\n/**\n * Accepts only finite whole numbers.\n */\nexport const integer: Decoder<number> = number.refine(\n (n) => Number.isInteger(n),\n 'Number must be an integer',\n);\n\n/**\n * Accepts only non-negative (zero or positive) finite numbers.\n */\nexport const positiveNumber: Decoder<number> = number\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n\n/**\n * Accepts only non-negative (zero or positive) finite whole numbers.\n */\nexport const positiveInteger: Decoder<number> = integer\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n","import { define } from '../Decoder';\nimport { number } from './numbers';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts and returns booleans.\n */\nexport const boolean: Decoder<boolean> = define((blob, ok, err) => {\n return typeof blob === 'boolean' ? ok(blob) : err('Must be boolean');\n});\n\n/**\n * Accepts anything and will return its \"truth\" value. Will never reject.\n */\nexport const truthy: Decoder<boolean> = define((blob, ok, _) => ok(!!blob));\n\n/**\n * Accepts numbers, but return their boolean representation.\n */\nexport const numericBoolean: Decoder<boolean> = number.transform((n) => !!n);\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport { instanceOf } from './utilities';\nimport type { Decoder } from '../Decoder';\n\n/** Match groups in this regex:\n * \\1 - the scheme\n * \\2 - the username/password (optional)\n * \\3 - the host\n * \\4 - the port (optional)\n * \\5 - the path (optional)\n */\nconst url_re =\n /^([A-Za-z]{3,9}(?:[+][A-Za-z]{3,9})?):\\/\\/(?:([-;:&=+$,\\w]+)@)?(?:([A-Za-z0-9.-]+)(?::([0-9]{2,5}))?)(\\/(?:[-+~%/.,\\w]*)?(?:\\?[-+=&;%@.,/\\w]*)?(?:#[.,!/\\w]*)?)?$/;\n\n/**\n * Accepts and returns strings.\n */\nexport const string: Decoder<string> = define((blob, ok, err) =>\n typeof blob === 'string' ? ok(blob) : err('Must be string'),\n);\n\n/**\n * Like `string`, but will reject the empty string or strings containing only whitespace.\n */\nexport const nonEmptyString: Decoder<string> = regex(/\\S/, 'Must be non-empty string');\n\n/**\n * Accepts and returns strings that match the given regular expression.\n */\nexport function regex(regex: RegExp, msg: string): Decoder<string> {\n return string.refine((s) => regex.test(s), msg);\n}\n\n/**\n * Accepts and returns strings that are syntactically valid email addresses.\n * (This will not mean that the email address actually exist.)\n */\nexport const email: Decoder<string> = regex(\n // The almost perfect email regex, taken from https://emailregex.com/\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n 'Must be email',\n);\n\n/**\n * Accepts strings that are valid URLs, returns the value as a URL instance.\n */\nexport const url: Decoder<URL> = either(\n regex(url_re, 'Must be URL').transform((value) => new URL(value)),\n instanceOf(URL),\n);\n\n/**\n * Accepts strings that are valid URLs, but only HTTPS ones. Returns the value\n * as a URL instance.\n */\nexport const httpsUrl: Decoder<URL> = url.refine(\n (value) => value.protocol === 'https:',\n 'Must be an HTTPS URL',\n);\n\n/**\n * Accepts strings that are valid\n * [UUIDs](https://en.wikipedia.org/wiki/universally_unique_identifier)\n * (universally unique identifier).\n */\nexport const uuid: Decoder<string> = regex(\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,\n 'Must be uuid',\n);\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv1](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_%28date-time_and_MAC_address%29)\n * strings.\n */\nexport const uuidv1: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)\n uuid.refine((value) => value[14] === '1', 'Must be uuidv1');\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_%28random%29)\n * strings.\n */\nexport const uuidv4: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)\n uuid.refine((value) => value[14] === '4', 'Must be uuidv4');\n","import { asDate } from '../_utils';\nimport { define } from '../Decoder';\nimport { regex } from './strings';\nimport type { Decoder } from '../Decoder';\n\n// Only matches the shape. This \"over-matches\" some values that still aren't\n// valid dates (like 9999-99-99), but those will be caught by JS Date's\n// internal validations\nconst iso8601_re =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:[.]\\d+)?(?:Z|[+-]\\d{2}:?\\d{2})$/;\n\n/**\n * Accepts and returns `Date` instances.\n */\nexport const date: Decoder<Date> = define((blob, ok, err) => {\n const date = asDate(blob);\n return date !== null ? ok(date) : err('Must be a Date');\n});\n\n/**\n * Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,\n * returns them as `Date` instances.\n *\n * This is very useful for working with dates in APIs: serialize them as\n * `.toISOString()` when sending, decode them with `iso8601` when receiving.\n */\nexport const iso8601: Decoder<Date> =\n // Input itself needs to match the ISO8601 regex...\n regex(iso8601_re, 'Must be ISO8601 format').transform(\n // Make sure it is a _valid_ date\n (value: string) => {\n const date = new Date(value);\n if (isNaN(date.getTime())) {\n throw new Error('Must be valid date/time value');\n }\n return date;\n },\n );\n","import { array } from './arrays';\nimport { boolean } from './booleans';\nimport { dict } from './objects';\nimport { either } from './unions';\nimport { lazy } from './utilities';\nimport { null_ } from './basics';\nimport { number } from './numbers';\nimport { string } from './strings';\nimport type { Decoder } from '../Decoder';\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\nexport type JSONObject = { [key: string]: JSONValue | undefined };\nexport type JSONArray = JSONValue[];\n\n/**\n * Accepts objects that contain only valid JSON values.\n */\nexport const jsonObject: Decoder<JSONObject> = lazy(() => dict(json));\n\n/**\n * Accepts arrays that contain only valid JSON values.\n */\nexport const jsonArray: Decoder<JSONArray> = lazy(() => array(json));\n\n/**\n * Accepts any value that's a valid JSON value.\n *\n * In other words: any value returned by `JSON.parse()` should decode without\n * failure.\n *\n * ```typescript\n * type JSONValue =\n * | null\n * | string\n * | number\n * | boolean\n * | { [string]: JSONValue }\n * | JSONValue[]\n * ```\n */\nexport const json: Decoder<JSONValue> = either(\n null_,\n string,\n number,\n boolean,\n jsonObject,\n jsonArray,\n).describe('Must be valid JSON value');\n"],"mappings":";AAIO,IAAM,SAAS;AAEf,SAAS,QAAW,OAAyB;AAClD,SAAO,OAAO,UAAU,aAAc,MAAkB,IAAI;AAC9D;AAKO,SAAS,SAA2B,IAAY,IAAoB;AACzE,QAAM,SAAS,oBAAI,IAAO;AAC1B,aAAW,KAAK,IAAI;AAClB,QAAI,CAAC,GAAG,IAAI,CAAC,GAAG;AACd,aAAO,IAAI,CAAC;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,OAAO,OAA6B;AAQlD,SAAO,CAAC,CAAC,SACP,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,mBAC1C,CAAC,MAAM,KAAe,IACnB,QACD;AACN;AAEO,SAAS,OAAO,OAAkD;AACvE,SACE,UAAU,QACV,UAAU,UACV,OAAO,UAAU;AAAA;AAAA,EAGjB,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM;AAE9C;AAEO,SAAS,YAAY,GAA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EAC/B,MAAM,QAAQ,aAAa,EAAE,UAAU,CAAC,UAAU,IAAI,IAAI,KAAK,CAAC;AAAA,EAChE,WAAW,GAAG;AAChB;AAMO,IAAM,WAAyB,IAAI;AAAA,EACxC,CAAC,UAAU,MAAM,aAAa;AAAA,EAC9B;AACF;AAOO,IAAM,OAAwB;AAAA,EACnC;AAAA,EACA;AACF;AAOO,IAAM;AAAA;AAAA,EAEX,KAAK,OAAO,CAAC,UAAU,MAAM,EAAE,MAAM,KAAK,gBAAgB;AAAA;AAOrD,IAAM;AAAA;AAAA,EAEX,KAAK,OAAO,CAAC,UAAU,MAAM,EAAE,MAAM,KAAK,gBAAgB;AAAA;;;AC/E5D,IAAM,aACJ;AAKK,IAAM,OAAsB,OAAO,CAAC,MAAMC,KAAIC,SAAQ;AAC3D,QAAMC,QAAO,OAAO,IAAI;AACxB,SAAOA,UAAS,OAAOF,IAAGE,KAAI,IAAID,KAAI,gBAAgB;AACxD,CAAC;AASM,IAAM;AAAA;AAAA,EAEX,MAAM,YAAY,wBAAwB,EAAE;AAAA;AAAA,IAE1C,CAAC,UAAkB;AACjB,YAAMC,QAAO,IAAI,KAAK,KAAK;AAC3B,UAAI,MAAMA,MAAK,QAAQ,CAAC,GAAG;AACzB,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,aAAOA;AAAA,IACT;AAAA,EACF;AAAA;;;ACpBK,IAAM,aAAkC,KAAK,MAAM,KAAK,IAAI,CAAC;AAK7D,IAAM,YAAgC,KAAK,MAAMC,OAAM,IAAI,CAAC;AAkB5D,IAAM,OAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,SAAS,0BAA0B;","names":["ann","err","value","ok","ok","err","object","ok","err","err","ok","mapping","object","ok","err","unknown","ok","err","array","ok","err","ok","err","ok","err","regex","ok","err","date","array"]}
|
|
1
|
+
{"version":3,"sources":["../src/_utils.ts","../src/annotate.ts","../src/format.ts","../src/result.ts","../src/Decoder.ts","../src/lib/objects.ts","../src/lib/utilities.ts","../src/lib/unions.ts","../src/lib/basics.ts","../src/lib/arrays.ts","../src/lib/numbers.ts","../src/lib/booleans.ts","../src/lib/strings.ts","../src/lib/dates.ts","../src/lib/json.ts"],"sourcesContent":["import type { Annotation } from './annotate';\nimport type { Scalar } from './Decoder';\n\n// Two spaces of indentation\nexport const INDENT = ' ';\n\nexport function lazyval<V>(value: (() => V) | V): V {\n return typeof value === 'function' ? (value as () => V)() : value;\n}\n\n/**\n * Subtract two sets. Why isn't this a standard method on Sets?\n */\nexport function subtract<C extends Scalar>(xs: Set<C>, ys: Set<C>): Set<C> {\n const result = new Set<C>();\n for (const x of xs) {\n if (!ys.has(x)) {\n result.add(x);\n }\n }\n return result;\n}\n\n/**\n * Is value is a valid Date instance, then return that. If not, then return\n * null.\n */\nexport function asDate(value: unknown): Date | null {\n //\n // `x instanceof Date` checks are unreliable across stack frames (that\n // information might get lost by the JS runtime), so we'll have to reside\n // to more runtime inspection checks.\n //\n // Taken from https://stackoverflow.com/a/44198641\n //\n return !!value &&\n Object.prototype.toString.call(value) === '[object Date]' &&\n !isNaN(value as number)\n ? (value as Date)\n : null;\n}\n\nexport function isPojo(value: unknown): value is Record<string, unknown> {\n return (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n // This still seems to be the only reliable way to determine whether\n // something is a pojo... ¯\\_(ツ)_/¯\n Object.prototype.toString.call(value) === '[object Object]'\n );\n}\n\nexport function isMultiline(s: string): boolean {\n return s.indexOf('\\n') >= 0;\n}\n\nexport function indent(s: string, prefix: string = INDENT): string {\n if (isMultiline(s)) {\n return s\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n');\n } else {\n return `${prefix}${s}`;\n }\n}\n\n/**\n * Walks the annotation tree and emits the annotation's key path within the\n * object tree, and the message as a series of messages (array of strings).\n */\nexport function summarize(\n ann: Annotation,\n keypath: readonly (number | string)[] = [],\n): string[] {\n const result: string[] = [];\n\n if (ann.type === 'array') {\n const items = ann.items;\n let index = 0;\n for (const ann of items) {\n for (const item of summarize(ann, [...keypath, index++])) {\n // Collect to results\n result.push(item);\n }\n }\n } else if (ann.type === 'object') {\n const fields = ann.fields;\n for (const key of Object.keys(fields)) {\n const value = fields[key];\n for (const item of summarize(value, [...keypath, key])) {\n // Collect to results\n result.push(item);\n }\n }\n }\n\n const text = ann.text;\n if (!text) {\n return result;\n }\n\n let prefix: string;\n if (keypath.length === 0) {\n prefix = '';\n } else if (keypath.length === 1) {\n prefix =\n typeof keypath[0] === 'number'\n ? `Value at index ${keypath[0]}: `\n : `Value at key ${JSON.stringify(keypath[0])}: `;\n } else {\n prefix = `Value at keypath ${keypath.map(String).join('.')}: `;\n }\n return [...result, `${prefix}${text}`];\n}\n","import { isPojo } from './_utils';\n\nconst _register: WeakSet<Annotation> = new WeakSet();\n\nexport interface ObjectAnnotation {\n readonly type: 'object';\n readonly fields: { readonly [key: string]: Annotation };\n readonly text?: string;\n}\n\nexport interface ArrayAnnotation {\n readonly type: 'array';\n readonly items: readonly Annotation[];\n readonly text?: string;\n}\n\nexport interface ScalarAnnotation {\n readonly type: 'scalar';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport interface FunctionAnnotation {\n readonly type: 'function';\n readonly text?: string;\n}\n\nexport interface CircularRefAnnotation {\n readonly type: 'circular-ref';\n readonly text?: string;\n}\n\nexport interface UnknownAnnotation {\n readonly type: 'unknown';\n readonly value: unknown;\n readonly text?: string;\n}\n\nexport type Annotation =\n | ObjectAnnotation\n | ArrayAnnotation\n | ScalarAnnotation\n | FunctionAnnotation\n | CircularRefAnnotation\n | UnknownAnnotation;\n\nfunction brand<A extends Annotation>(ann: A): A {\n _register.add(ann);\n return ann;\n}\n\nexport function object(\n fields: { readonly [key: string]: Annotation },\n text?: string,\n): ObjectAnnotation {\n return brand({ type: 'object', fields, text });\n}\n\nexport function array(items: readonly Annotation[], text?: string): ArrayAnnotation {\n return brand({\n type: 'array',\n items,\n text,\n });\n}\n\nexport function func(text?: string): FunctionAnnotation {\n return brand({\n type: 'function',\n text,\n });\n}\n\nexport function unknown(value: unknown, text?: string): UnknownAnnotation {\n return brand({\n type: 'unknown',\n value,\n text,\n });\n}\n\nexport function scalar(value: unknown, text?: string): ScalarAnnotation {\n return brand({\n type: 'scalar',\n value,\n text,\n });\n}\n\nexport function circularRef(text?: string): CircularRefAnnotation {\n return brand({\n type: 'circular-ref',\n text,\n });\n}\n\n/**\n * Given an existing Annotation, set the annotation's text to a new value.\n */\nexport function updateText<A extends Annotation>(annotation: A, text?: string): A {\n if (text !== undefined) {\n return brand({ ...annotation, text });\n } else {\n return annotation;\n }\n}\n\n/**\n * Given an existing ObjectAnnotation, merges new Annotations in there.\n */\nexport function merge(\n objAnnotation: ObjectAnnotation,\n fields: { readonly [key: string]: Annotation },\n): ObjectAnnotation {\n const newFields = { ...objAnnotation.fields, ...fields };\n return object(newFields, objAnnotation.text);\n}\n\nexport function asAnnotation(thing: unknown): Annotation | undefined {\n return typeof thing === 'object' && thing !== null && _register.has(thing as Annotation)\n ? (thing as Annotation)\n : undefined;\n}\n\ntype RefSet = WeakSet<object>;\n\n/** @internal */\nfunction annotateArray(\n value: readonly unknown[],\n text: string | undefined,\n seen: RefSet,\n): ArrayAnnotation | CircularRefAnnotation {\n seen.add(value);\n\n const items = value.map((v) => annotate(v, undefined, seen));\n return array(items, text);\n}\n\n/** @internal */\nfunction annotateObject(\n obj: Record<string, unknown>,\n text: string | undefined,\n seen: RefSet,\n): ObjectAnnotation {\n seen.add(obj);\n\n const fields: Record<string, Annotation> = {};\n for (const key of Object.keys(obj)) {\n const value = obj[key];\n fields[key] = annotate(value, undefined, seen);\n }\n return object(fields, text);\n}\n\n/** @internal */\nfunction annotate(value: unknown, text: string | undefined, seen: RefSet): Annotation {\n if (\n value === null ||\n value === undefined ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'symbol' ||\n typeof (value as Record<string, unknown>).getMonth === 'function'\n ) {\n return scalar(value, text);\n }\n\n const ann = asAnnotation(value);\n if (ann) {\n return updateText(ann, text);\n }\n\n if (Array.isArray(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateArray(value, text, seen);\n }\n }\n\n if (isPojo(value)) {\n // \"Circular references\" can only exist in objects or arrays\n if (seen.has(value)) {\n return circularRef(text);\n } else {\n return annotateObject(value, text, seen);\n }\n }\n\n if (typeof value === 'function') {\n return func(text);\n }\n\n return unknown(value, text);\n}\n\nfunction public_annotate(value: unknown, text?: string): Annotation {\n return annotate(value, text, new WeakSet());\n}\n\nfunction public_annotateObject(\n obj: { readonly [field: string]: unknown },\n text?: string,\n): ObjectAnnotation {\n return annotateObject(obj, text, new WeakSet());\n}\n\nexport {\n // This construct just ensures the \"seen\" weakmap (used for circular\n // reference detection) isn't made part of the public API.\n public_annotate as annotate,\n public_annotateObject as annotateObject,\n\n /** @internal */\n annotate as __private_annotate,\n};\n","import { summarize as _summarize, asDate, INDENT, indent, isMultiline } from './_utils';\nimport type { Annotation, ArrayAnnotation, ObjectAnnotation } from './annotate';\n\nexport type Formatter = (err: Annotation) => string | Error;\n\nfunction serializeString(s: string, width: number = 80): string {\n // Full string\n // Abbreviated to $maxlen i.e. \"Vincent Driess...\" [truncated]\n let ser = JSON.stringify(s);\n if (ser.length <= width) {\n return ser;\n }\n\n // Cut off a bit\n const truncated = `${s.substring(0, width - 15)}...`;\n ser = `${JSON.stringify(truncated)} [truncated]`;\n return ser;\n}\n\nfunction serializeArray(annotation: ArrayAnnotation, prefix: string): string {\n const { items } = annotation;\n if (items.length === 0) {\n return '[]';\n }\n\n const result: string[] = [];\n for (const item of items) {\n const [ser, ann] = serializeAnnotation(item, `${prefix}${INDENT}`);\n result.push(`${prefix}${INDENT}${ser}${','}`);\n if (ann !== undefined) {\n result.push(indent(ann, `${prefix}${INDENT}`));\n }\n }\n return ['[', ...result, `${prefix}]`].join('\\n');\n}\n\nfunction serializeObject(annotation: ObjectAnnotation, prefix: string): string {\n const { fields } = annotation;\n\n const fieldNames = Object.keys(fields);\n if (fieldNames.length === 0) {\n return '{}';\n }\n\n const result: string[] = [];\n for (const key of fieldNames) {\n const valueAnnotation = fields[key];\n const kser = serializeValue(key);\n\n const valPrefix = `${prefix}${INDENT}${' '.repeat(kser.length + 2)}`;\n const [vser, vann] = serializeAnnotation(valueAnnotation, `${prefix}${INDENT}`);\n\n result.push(`${prefix}${INDENT}${kser}: ${vser},`);\n if (vann !== undefined) {\n result.push(indent(vann, valPrefix));\n }\n }\n return ['{', ...result, `${prefix}}`].join('\\n');\n}\n\nexport function serializeValue(value: unknown): string {\n if (typeof value === 'string') {\n return serializeString(value);\n } else if (typeof value === 'number' || typeof value === 'boolean') {\n return value.toString();\n } else if (value === null) {\n return 'null';\n } else if (value === undefined) {\n return 'undefined';\n } else {\n const valueAsDate = asDate(value);\n if (valueAsDate !== null) {\n return `new Date(${JSON.stringify(valueAsDate.toISOString())})`;\n } else if (value instanceof Date) {\n // NOTE: Using `instanceof Date` is unreliable way of checking dates.\n // If this case occurs (and it didn't pass the prior asDate())\n // check, then this must be the case where it's an invalid date.\n return '(Invalid Date)';\n } else {\n return '(unserializable)';\n }\n }\n}\n\nexport function serializeAnnotation(\n ann: Annotation,\n prefix: string = '',\n): [string, string | undefined] {\n // The serialized data (the input object echoed back)\n let serialized;\n if (ann.type === 'array') {\n serialized = serializeArray(ann, prefix);\n } else if (ann.type === 'object') {\n serialized = serializeObject(ann, prefix);\n } else if (ann.type === 'function') {\n serialized = '<function>';\n } else if (ann.type === 'circular-ref') {\n serialized = '<circular ref>';\n } else if (ann.type === 'unknown') {\n serialized = '???';\n } else {\n serialized = serializeValue(ann.value);\n }\n\n const text = ann.text;\n if (text !== undefined) {\n const sep = '^'.repeat(isMultiline(serialized) ? 1 : serialized.length);\n return [serialized, [sep, text].join(isMultiline(text) ? '\\n' : ' ')];\n } else {\n return [serialized, undefined];\n }\n}\n\nexport function formatInline(ann: Annotation): string {\n const [serialized, annotation] = serializeAnnotation(ann);\n if (annotation !== undefined) {\n return `${serialized}\\n${annotation}`;\n } else {\n return serialized;\n }\n}\n\nexport function formatShort(ann: Annotation): string {\n return _summarize(ann, []).join('\\n');\n}\n","/**\n * Result <value> <error>\n * = Ok <value>\n * | Err <error>\n */\nexport type Ok<T> = {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n};\n\nexport type Err<E> = {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n};\n\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Create a new Result instance representing a successful computation.\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: undefined };\n}\n\n/**\n * Create a new Result instance representing a failed computation.\n */\nexport function err<E>(error: E): Err<E> {\n return { ok: false, value: undefined, error };\n}\n","import { annotate } from './annotate';\nimport { formatInline } from './format';\nimport { err as makeErr, ok as makeOk } from './result';\nimport type { Annotation } from './annotate';\nimport type { Formatter } from './format';\nimport type { Result } from './result';\n\nexport type Scalar = string | number | boolean | symbol | undefined | null;\n\nexport type DecodeResult<T> = Result<T, Annotation>;\n\nexport type AcceptanceFn<T, InputT = unknown> = (\n blob: InputT,\n ok: (value: T) => DecodeResult<T>,\n err: (msg: string | Annotation) => DecodeResult<T>,\n) => DecodeResult<T>;\n\nexport interface Decoder<T> {\n /**\n * Verifies untrusted input. Either returns a value, or throws a decoding\n * error.\n */\n verify(blob: unknown, formatterFn?: (ann: Annotation) => string | Error): T;\n\n /**\n * Verifies untrusted input. Either returns a value, or returns undefined.\n */\n value(blob: unknown): T | undefined;\n\n /**\n * Verifies untrusted input. Always returns a DecodeResult, which is either\n * an \"ok\" value or an \"error\" annotation.\n */\n decode(blob: unknown): DecodeResult<T>;\n\n /**\n * Build a new decoder from the the current one, with an extra acceptance\n * criterium.\n */\n refine<N extends T>(predicate: (value: T) => value is N, msg: string): Decoder<N>;\n refine(predicate: (value: T) => boolean, msg: string): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, with an extra rejection\n * criterium.\n */\n reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T>;\n\n /**\n * Build a new decoder from the current one, modifying its outputted value.\n */\n transform<V>(transformFn: (value: T) => V): Decoder<V>;\n\n /**\n * Build a new decoder from the current one, with a mutated error message\n * in case of a rejection.\n */\n describe(message: string): Decoder<T>;\n\n /**\n * Chain together the current decoder with another acceptance function.\n */\n then<V>(next: AcceptanceFn<V, T>): Decoder<V>;\n\n // Experimental APIs (please don't rely on these yet)\n peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V>;\n}\n\n/**\n * Helper type to return the \"type\" of a Decoder.\n *\n * You can use it on types:\n *\n * DecoderType<Decoder<string>> // string\n * DecoderType<Decoder<number[]>> // number[]\n *\n * Or on \"values\", by using the `typeof` keyword:\n *\n * DecoderType<typeof string> // string\n * DecoderType<typeof truthy> // boolean\n *\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DecoderType<D extends Decoder<any>> = D extends Decoder<infer T> ? T : never;\n\nfunction noThrow<T, V>(fn: (value: T) => V): (blob: T) => DecodeResult<V> {\n return (t) => {\n try {\n const v = fn(t);\n return makeOk(v);\n } catch (e) {\n return makeErr(annotate(t, e instanceof Error ? e.message : String(e)));\n }\n };\n}\n\nfunction format(err: Annotation, formatter: Formatter): Error {\n const formatted = formatter(err);\n\n // Formatter functions may return a string or an error for convenience of\n // writing them. If it already returns an Error, return it unmodified. If\n // it returns a string, wrap it in a \"Decoding error\" instance.\n if (typeof formatted === 'string') {\n const err = new Error(`\\n${formatted}`);\n err.name = 'Decoding error';\n return err;\n } else {\n return formatted;\n }\n}\n\n/**\n * Defines a new `Decoder<T>`, by implementing a custom acceptance function.\n * The function receives three arguments:\n *\n * 1. `blob` - the raw/unknown input (aka your external data)\n * 2. `ok` - Call `ok(value)` to accept the input and return ``value``\n * 3. `err` - Call `err(message)` to reject the input with error ``message``\n *\n * The expected return value should be a `DecodeResult<T>`, which can be\n * obtained by returning the result of calling the provided `ok` or `err`\n * helper functions. Please note that `ok()` and `err()` don't perform side\n * effects! You'll need to _return_ those values.\n */\nexport function define<T>(fn: AcceptanceFn<T>): Decoder<T> {\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n *\n * Contrasted with `.verify()`, calls to `.decode()` will never fail and\n * instead return a result type.\n */\n function decode(blob: unknown): DecodeResult<T> {\n return fn(blob, makeOk, (msg: Annotation | string) =>\n makeErr(typeof msg === 'string' ? annotate(blob, msg) : msg),\n );\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns a value of type `T`. Otherwise fail with\n * a runtime error.\n */\n function verify(blob: unknown, formatter: Formatter = formatInline): T {\n const result = decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n throw format(result.error, formatter);\n }\n }\n\n /**\n * Verifies the untrusted/unknown input and either accepts or rejects it.\n * When accepted, returns the decoded `T` value directly. Otherwise returns\n * `undefined`.\n *\n * Use this when you're not interested in programmatically handling the\n * error message.\n */\n function value(blob: unknown): T | undefined {\n return decode(blob).value;\n }\n\n /**\n * Accepts any value the given decoder accepts, and on success, will call\n * the given function **on the decoded result**. If the transformation\n * function throws an error, the whole decoder will fail using the error\n * message as the failure reason.\n */\n function transform<V>(transformFn: (result: T) => V): Decoder<V> {\n return then(noThrow(transformFn));\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that also meet the\n * predicate.\n */\n function refine(predicateFn: (value: T) => boolean, errmsg: string): Decoder<T> {\n return reject((value) =>\n predicateFn(value)\n ? // Don't reject\n null\n : // Reject with the given error message\n errmsg,\n );\n }\n\n /**\n * Chain together the current decoder with another.\n *\n * > _**NOTE:** This is an advanced, low-level, API. It's not recommended\n * > to reach for this construct unless there is no other way. Most cases can\n * > be covered more elegantly by `.transform()` or `.refine()` instead._\n *\n * If the current decoder accepts an input, the resulting ``T`` value will\n * get passed into the given ``next`` acceptance function to further decide\n * whether or not the value should get accepted or rejected.\n *\n * This works similar to how you would `define()` a new decoder, except\n * that the ``blob`` param will now be ``T`` (a known type), rather than\n * ``unknown``. This will allow the function to make a stronger assumption\n * about its input and avoid re-refining inputs.\n *\n * If it helps, you can think of `define(...)` as equivalent to\n * `unknown.then(...)`.\n */\n function then<V>(next: AcceptanceFn<V, T>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next(result.value, ok, err) : result;\n });\n }\n\n /**\n * Adds an extra predicate to a decoder. The new decoder is like the\n * original decoder, but only accepts values that aren't rejected by the\n * given function.\n *\n * The given function can return `null` to accept the decoded value, or\n * return a specific error message to reject.\n *\n * Unlike `.refine()`, you can use this function to return a dynamic error\n * message.\n */\n function reject(rejectFn: (value: T) => string | Annotation | null): Decoder<T> {\n return then((value, ok, err) => {\n const errmsg = rejectFn(value);\n return errmsg === null\n ? ok(value)\n : err(typeof errmsg === 'string' ? annotate(value, errmsg) : errmsg);\n });\n }\n\n /**\n * Uses the given decoder, but will use an alternative error message in\n * case it rejects. This can be used to simplify or shorten otherwise\n * long or low-level/technical errors.\n */\n function describe(message: string): Decoder<T> {\n return define((blob, _, err) => {\n // Decode using the given decoder...\n const result = decode(blob);\n if (result.ok) {\n return result;\n } else {\n // ...but in case of error, annotate this with the custom given\n // message instead\n return err(annotate(result.error, message));\n }\n });\n }\n\n /**\n * WARNING: This is an EXPERIMENTAL API that will likely change in the\n * future. Please DO NOT rely on it.\n *\n * Chain together the current decoder with another, but also pass along\n * the original input.\n *\n * This is like `.then()`, but instead of this function receiving just\n * the decoded result ``T``, it also receives the original input.\n *\n * This is an advanced, low-level, decoder.\n */\n function peek_UNSTABLE<V>(next: AcceptanceFn<V, [unknown, T]>): Decoder<V> {\n return define((blob, ok, err) => {\n const result = decode(blob);\n return result.ok ? next([blob, result.value], ok, err) : result;\n });\n }\n\n return Object.freeze({\n verify,\n value,\n decode,\n transform,\n refine,\n reject,\n describe,\n then,\n\n // EXPERIMENTAL - please DO NOT rely on this method\n peek_UNSTABLE,\n });\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { annotateObject, merge, updateText } from '../annotate';\nimport { define } from '../Decoder';\nimport { subtract, isPojo } from '../_utils';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\nimport type { UndefinedToOptional } from './_helpers';\n\ntype ObjectDecoderType<T> = UndefinedToOptional<{\n [K in keyof T]: T[K] extends Decoder<infer V> ? V : never;\n}>;\n\n/**\n * Accepts any \"plain old JavaScript object\", but doesn't validate its keys or\n * values further.\n */\nexport const pojo: Decoder<Record<string, unknown>> = define((blob, ok, err) =>\n isPojo(blob) ? ok(blob) : err('Must be an object'),\n);\n\n/**\n * Accepts objects with fields matching the given decoders. Extra fields that\n * exist on the input object are ignored and will not be returned.\n */\nexport function object(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>>;\nexport function object<DS extends Record<string, Decoder<any>>>(\n decodersByKey: DS,\n): Decoder<ObjectDecoderType<DS>> {\n // Compute this set at decoder definition time\n const knownKeys = new Set(Object.keys(decodersByKey));\n\n return pojo.then((plainObj, ok, err) => {\n const actualKeys = new Set(Object.keys(plainObj));\n\n // At this point, \"missingKeys\" will also include all fields that may\n // validly be optional. We'll let the underlying decoder decide and\n // remove the key from this missing set if the decoder accepts the\n // value.\n const missingKeys = subtract(knownKeys, actualKeys);\n\n const record = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(decodersByKey)) {\n const decoder = decodersByKey[key];\n const rawValue = plainObj[key];\n const result: DecodeResult<unknown> = decoder.decode(rawValue);\n\n if (result.ok) {\n const value = result.value;\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n record[key] = value;\n }\n\n // If this succeeded, remove the key from the missing keys\n // tracker\n missingKeys.delete(key);\n } else {\n const ann = result.error;\n\n // Keep track of the annotation, but don't return just yet. We\n // want to collect more error information.\n if (rawValue === undefined) {\n // Explicitly add it to the missing set if the value is\n // undefined. This covers explicit undefineds to be\n // treated the same as implicit undefineds (aka missing\n // keys).\n missingKeys.add(key);\n } else {\n if (errors === null) {\n errors = {};\n }\n errors[key] = ann;\n }\n }\n }\n\n // Deal with errors now. There are two classes of errors we want to\n // report. First of all, we want to report any inline errors in this\n // object. Lastly, any fields that are missing should be annotated on\n // the outer object itself.\n if (errors || missingKeys.size > 0) {\n let objAnn = annotateObject(plainObj);\n\n if (errors) {\n objAnn = merge(objAnn, errors);\n }\n\n if (missingKeys.size > 0) {\n const errMsg = Array.from(missingKeys)\n .map((key) => `\"${key}\"`)\n .join(', ');\n const pluralized = missingKeys.size > 1 ? 'keys' : 'key';\n objAnn = updateText(objAnn, `Missing ${pluralized}: ${errMsg}`);\n }\n\n return err(objAnn);\n }\n\n return ok(record as ObjectDecoderType<DS>);\n });\n}\n\n/**\n * Like `object()`, but will reject inputs that contain extra fields that are\n * not specified explicitly.\n */\nexport function exact(decodersByKey: Record<any, never>): Decoder<Record<string, never>>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }>;\nexport function exact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<{ [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] }> {\n // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n // Ditto (see above)\n\n // Compute this set at decoder definition time\n const allowedKeys = new Set(Object.keys(decodersByKey));\n\n // Check the inputted object for any unexpected extra keys\n const checked = pojo.reject((plainObj) => {\n const actualKeys = new Set(Object.keys(plainObj));\n const extraKeys = subtract(actualKeys, allowedKeys);\n return extraKeys.size > 0\n ? `Unexpected extra keys: ${Array.from(extraKeys).join(', ')}`\n : // Don't reject\n null;\n });\n\n // Defer to the \"object\" decoder for doing the real decoding work. Since\n // we made sure there are no superfluous keys in this structure, it's now\n // safe to force-cast it to an $Exact<> type.\n return checked.then(object(decodersByKey).decode);\n}\n\n/**\n * Like `object()`, but will pass through any extra fields on the input object\n * unvalidated that will thus be of `unknown` type statically.\n */\nexport function inexact(\n decodersByKey: Record<any, never>,\n): Decoder<Record<string, unknown>>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n>;\nexport function inexact<O extends Record<string, Decoder<any>>>(\n decodersByKey: O,\n): Decoder<\n { [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K] } & Record<string, unknown>\n> {\n return pojo.then((plainObj) => {\n const allkeys = new Set(Object.keys(plainObj));\n const decoder = object(decodersByKey).transform((safepart) => {\n const safekeys = new Set(Object.keys(decodersByKey));\n\n // To account for hard-coded keys that aren't part of the input\n for (const k of safekeys) allkeys.add(k);\n\n const rv = {} as {\n [K in keyof ObjectDecoderType<O>]: ObjectDecoderType<O>[K];\n } & Record<string, unknown>;\n for (const k of allkeys) {\n if (safekeys.has(k)) {\n const value = safepart[k];\n if (value !== undefined) {\n // @ts-expect-error - look into this later\n rv[k] = value;\n }\n } else {\n // @ts-expect-error - look into this later\n rv[k] = plainObj[k];\n }\n }\n return rv;\n });\n return decoder.decode(plainObj);\n });\n}\n\n/**\n * Accepts objects where all values match the given decoder, and returns the\n * result as a `Record<string, T>`.\n *\n * The main difference between `object()` and `dict()` is that you'd typically\n * use `object()` if this is a record-like object, where all field names are\n * known and the values are heterogeneous. Whereas with `dict()` the keys are\n * typically dynamic and the values homogeneous, like in a dictionary,\n * a lookup table, or a cache.\n */\nexport function dict<T>(decoder: Decoder<T>): Decoder<Record<string, T>> {\n return pojo.then((plainObj, ok, err) => {\n let rv: Record<string, T> = {};\n let errors: Record<string, Annotation> | null = null;\n\n for (const key of Object.keys(plainObj)) {\n const value = plainObj[key];\n const result = decoder.decode(value);\n if (result.ok) {\n if (errors === null) {\n rv[key] = result.value;\n }\n } else {\n rv = {}; // Clear the success value so it can get garbage collected early\n if (errors === null) {\n errors = {};\n }\n errors[key] = result.error;\n }\n }\n\n if (errors !== null) {\n return err(merge(annotateObject(plainObj), errors));\n } else {\n return ok(rv);\n }\n });\n}\n\n/**\n * Similar to `dict()`, but returns the result as a `Map<string, T>` (an [ES6\n * Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map))\n * instead.\n */\nexport function mapping<T>(decoder: Decoder<T>): Decoder<Map<string, T>> {\n return dict(decoder).transform(\n (obj) =>\n new Map(\n // This is effectively Object.entries(obj), but in a way that Flow\n // will know the types are okay\n Object.keys(obj).map((key) => [key, obj[key]]),\n ),\n );\n}\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport interface Klass<T> extends Function {\n new (...args: readonly any[]): T;\n}\n\nexport type Instance<K> = K extends Klass<infer T> ? T : never;\n\n/**\n * Accepts any value that is an ``instanceof`` the given class.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instanceOf<K extends Klass<any>>(klass: K): Decoder<Instance<K>> {\n return define((blob, ok, err) =>\n blob instanceof klass ? ok(blob) : err(`Must be ${klass.name} instance`),\n );\n}\n\n/**\n * Lazily evaluate the given decoder. This is useful to build self-referential\n * types for recursive data structures.\n */\nexport function lazy<T>(decoderFn: () => Decoder<T>): Decoder<T> {\n return define((blob) => decoderFn().decode(blob));\n}\n\n/**\n * Pre-process the data input before passing it into the decoder. This gives\n * you the ability to arbitrarily customize the input on the fly before passing\n * it to the decoder. Of course, the input value at that point is still of\n * ``unknown`` type, so you will have to deal with that accordingly.\n */\nexport function prep<T>(\n mapperFn: (blob: unknown) => unknown,\n decoder: Decoder<T>,\n): Decoder<T> {\n return define((originalInput, _, err) => {\n let blob;\n try {\n blob = mapperFn(originalInput);\n } catch (e: unknown) {\n return err(\n annotate(\n originalInput,\n // istanbul ignore next\n e instanceof Error ? e.message : String(e),\n ),\n );\n }\n\n const r = decoder.decode(blob);\n return r.ok ? r : err(annotate(originalInput, r.error.text));\n // ^^^^^^^^^^^^^\n // Annotates the _original_ input value\n // (instead of echoing back blob)\n });\n}\n","import { define } from '../Decoder';\nimport { indent, summarize } from '../_utils';\nimport { object } from './objects';\nimport { prep } from './utilities';\nimport type { Decoder, DecoderType, DecodeResult, Scalar } from '../Decoder';\nimport type { Ok } from '../result';\n\ntype Values<T extends object> = T[keyof T];\n\ntype DecoderTypes<T> = T extends readonly Decoder<infer U>[] ? U : never;\n\nconst EITHER_PREFIX = 'Either:\\n';\n\n/**\n * Indents and adds a dash in front of this (potentially multiline) string.\n */\nfunction itemize(s: string): string {\n return `-${indent(s).substring(1)}`;\n}\n\n/**\n * Nests another error as an item under a new-to-be-created \"Either error\". If\n * the given subitem already is an \"Either error\" of itself, don't indent, but\n * just \"inject\" its items at the same error level, for nicely flattened either\n * expressions.\n *\n * Avoids:\n *\n * Either:\n * - Either:\n * - Must be P\n * - Either:\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n * And \"flattens\" these to:\n *\n * Either:\n * - Must be P\n * - Must be Q\n * - Must be R\n * - Must be S\n *\n */\nfunction nest(errText: string): string {\n return errText.startsWith(EITHER_PREFIX)\n ? errText.substr(EITHER_PREFIX.length)\n : itemize(errText);\n}\n\n/**\n * Accepts values accepted by any of the given decoders.\n *\n * The decoders are tried on the input one by one, in the given order. The\n * first one that accepts the input \"wins\". If all decoders reject the input,\n * the input gets rejected.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function either<T extends readonly Decoder<any>[]>(\n ...decoders: T\n): Decoder<DecoderTypes<T>> {\n if (decoders.length === 0) {\n throw new Error('Pass at least one decoder to either()');\n }\n\n return define((blob, _, err) => {\n // Collect errors here along the way\n const errors = [];\n\n for (let i = 0; i < decoders.length; i++) {\n const result: DecodeResult<unknown> = decoders[i].decode(blob);\n if (result.ok) {\n return result as Ok<DecoderTypes<T>>;\n } else {\n errors.push(result.error);\n }\n }\n\n // Decoding all alternatives failed, return the combined error message\n const text =\n EITHER_PREFIX + errors.map((err) => nest(summarize(err).join('\\n'))).join('\\n');\n return err(text);\n });\n}\n\n/**\n * Accepts any value that is strictly-equal (using `===`) to one of the\n * specified values.\n */\nexport function oneOf<C extends Scalar>(constants: readonly C[]): Decoder<C> {\n return define((blob, ok, err) => {\n const winner = constants.find((c) => c === blob);\n if (winner !== undefined) {\n return ok(winner);\n }\n return err(\n `Must be one of ${constants.map((value) => JSON.stringify(value)).join(', ')}`,\n );\n });\n}\n\n/**\n * If you are decoding tagged unions you may want to use the `taggedUnion()`\n * decoder instead of the general purpose `either()` decoder to get better\n * error messages and better performance.\n *\n * This decoder is optimized for [tagged\n * unions](https://en.wikipedia.org/wiki/Tagged_union), i.e. a union of\n * objects where one field is used as the discriminator.\n *\n * ```ts\n * const A = object({ tag: constant('A'), foo: string });\n * const B = object({ tag: constant('B'), bar: number });\n *\n * const AorB = taggedUnion('tag', { A, B });\n * // ^^^\n * ```\n *\n * Decoding now works in two steps:\n *\n * 1. Look at the `'tag'` field in the incoming object (this is the field\n * that decides which decoder will be used)\n * 2. If the value is `'A'`, then decoder `A` will be used. If it's `'B'`, then\n * decoder `B` will be used. Otherwise, this will fail.\n *\n * This is effectively equivalent to `either(A, B)`, but will provide better\n * error messages and is more performant at runtime because it doesn't have to\n * try all decoders one by one.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function taggedUnion<O extends Record<string, Decoder<any>>>(\n field: string,\n mapping: O,\n): Decoder<Values<{ [key in keyof O]: DecoderType<O[key]> }>> {\n const base: Decoder<string> = object({\n [field]: prep(String, oneOf(Object.keys(mapping))),\n }).transform((o) => o[field]);\n return base.peek_UNSTABLE(([blob, key]) => {\n const decoder = mapping[key];\n return decoder.decode(blob);\n });\n}\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport type { Decoder, Scalar } from '../Decoder';\nimport { lazyval } from '../_utils';\n\n/**\n * Accepts and returns only the literal `null` value.\n */\nexport const null_ = constant(null);\n\n/**\n * Accepts and returns only the literal `undefined` value.\n */\nexport const undefined_ = constant(undefined);\n\nconst nullish_: Decoder<null | undefined> = define((blob, ok, err) =>\n blob == null /* or undefined */\n ? ok(blob)\n : // Combine error message into a single line for readability\n err('Must be undefined or null'),\n);\n\n/**\n * Accepts whatever the given decoder accepts, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `undefined` case.\n */\nexport function optional<T>(decoder: Decoder<T>): Decoder<T | undefined>;\nexport function optional<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function optional<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function optional<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | undefined> {\n const rv = either(undefined_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts whatever the given decoder accepts, or `null`.\n *\n * If a default value is explicitly provided, return that instead in the `null`\n * case.\n */\nexport function nullable<T>(decoder: Decoder<T>): Decoder<T | null>;\nexport function nullable<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function nullable<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function nullable<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null> {\n const rv = either(null_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * @deprecated\n * Alias of nullish().\n */\nexport const maybe = nullish;\n\n/**\n * Accepts whatever the given decoder accepts, or `null`, or `undefined`.\n *\n * If a default value is explicitly provided, return that instead in the\n * `null`/`undefined` case.\n */\nexport function nullish<T>(decoder: Decoder<T>): Decoder<T | null | undefined>;\nexport function nullish<T, C extends Scalar>(decoder: Decoder<T>, defaultValue: (() => C) | C): Decoder<NonNullable<T> | C>; // prettier-ignore\nexport function nullish<T, V>(decoder: Decoder<T>, defaultValue: (() => V) | V): Decoder<NonNullable<T> | V>; // prettier-ignore\nexport function nullish<T, V>(\n decoder: Decoder<T>,\n defaultValue?: (() => V) | V,\n): Decoder<T | V | null | undefined> {\n const rv = either(nullish_, decoder);\n return arguments.length >= 2\n ? rv.transform((value) => value ?? lazyval(defaultValue as (() => V) | V))\n : rv;\n}\n\n/**\n * Accepts only the given constant value.\n */\nexport function constant<C extends Scalar>(value: C): Decoder<C> {\n return define((blob, ok, err) =>\n blob === value ? ok(value) : err(`Must be ${JSON.stringify(value)}`),\n );\n}\n\n/**\n * Accepts anything, completely ignores it, and always returns the provided\n * value instead.\n *\n * This is useful to manually add extra fields to object decoders.\n */\nexport function always<C extends Scalar>(value: C): Decoder<C>;\nexport function always<T>(value: (() => T) | T): Decoder<T>;\nexport function always<T>(value: (() => T) | T): Decoder<T> {\n return define(\n typeof value === 'function'\n ? (_, ok) => ok((value as () => T)())\n : (_, ok) => ok(value),\n );\n}\n\n/**\n * Rejects all inputs, and always fails with the given error message. May be\n * useful for explicitly disallowing keys, or for testing purposes.\n */\nexport function never(msg: string): Decoder<never> {\n return define((_, __, err) => err(msg));\n}\n\n/**\n * Alias of never().\n */\nexport const fail = never;\n\n/**\n * @deprecated\n * Alias of always.\n */\nexport const hardcoded = always;\n\n/**\n * Accepts anything and returns it unchanged.\n *\n * Useful for situation in which you don't know or expect a specific type. Of\n * course, the downside is that you won't know the type of the value statically\n * and you'll have to further refine it yourself.\n */\nexport const unknown: Decoder<unknown> = define((blob, ok, _) => ok(blob));\n\n/**\n * @deprecated\n * Alias of unknown.\n */\nexport const mixed = unknown;\n","import { annotate } from '../annotate';\nimport { define } from '../Decoder';\nimport type { Annotation } from '../annotate';\nimport type { Decoder, DecodeResult } from '../Decoder';\n\n/**\n * Accepts any array, but doesn't validate its items further.\n *\n * \"poja\" means \"plain old JavaScript array\", a play on `pojo()`.\n */\nexport const poja: Decoder<unknown[]> = define((blob, ok, err) => {\n if (!Array.isArray(blob)) {\n return err('Must be an array');\n }\n return ok(blob as unknown[]);\n});\n\n/**\n * Given an array of Result instances, loop over them all and return:\n * - An [index, err] tuple, indicating the (index of the) first Err instance\n * encountered; or\n * - a new Ok with an array of all unwrapped Ok'ed values\n */\nfunction all<T>(\n items: readonly DecodeResult<T>[],\n blobs: readonly unknown[],\n\n // TODO: Make this less ugly\n ok: (value: T[]) => DecodeResult<T[]>,\n err: (ann: Annotation) => DecodeResult<T[]>,\n): DecodeResult<T[]> {\n const results: T[] = [];\n for (let index = 0; index < items.length; ++index) {\n const result = items[index];\n if (result.ok) {\n results.push(result.value);\n } else {\n const ann = result.error;\n\n // Rewrite the annotation to include the index information, and inject it into the original blob\n const clone = blobs.slice();\n clone.splice(\n index,\n 1,\n annotate(ann, ann.text ? `${ann.text} (at index ${index})` : `index ${index}`),\n );\n\n return err(annotate(clone));\n }\n }\n return ok(results);\n}\n\n/**\n * Accepts arrays of whatever the given decoder accepts.\n */\nexport function array<T>(decoder: Decoder<T>): Decoder<T[]> {\n const decodeFn = decoder.decode;\n return poja.then((blobs: readonly unknown[], ok, err) => {\n const results = blobs.map(decodeFn);\n return all(results, blobs, ok, err);\n });\n}\n\nfunction isNonEmpty<T>(arr: readonly T[]): arr is [T, ...T[]] {\n return arr.length > 0;\n}\n\n/**\n * Like `array()`, but will reject arrays with 0 elements.\n */\nexport function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<[T, ...T[]]> {\n return array(decoder).refine(isNonEmpty, 'Must be non-empty array');\n}\n\n/**\n * Similar to `array()`, but returns the result as an [ES6\n * Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).\n */\nexport function set<T>(decoder: Decoder<T>): Decoder<Set<T>> {\n return array(decoder).transform((items) => new Set(items));\n}\n\nconst ntuple = (n: number) =>\n poja.refine((arr) => arr.length === n, `Must be a ${n}-tuple`);\n\n/**\n * Accepts a tuple (an array with exactly _n_ items) of values accepted by the\n * _n_ given decoders.\n */\nexport function tuple<A>(a: Decoder<A>): Decoder<[A]>;\nexport function tuple<A, B>(a: Decoder<A>, b: Decoder<B>): Decoder<[A, B]>;\nexport function tuple<A, B, C>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n): Decoder<[A, B, C]>;\nexport function tuple<A, B, C, D>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n): Decoder<[A, B, C, D]>;\nexport function tuple<A, B, C, D, E>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n): Decoder<[A, B, C, D, E]>;\nexport function tuple<A, B, C, D, E, F>(\n a: Decoder<A>,\n b: Decoder<B>,\n c: Decoder<C>,\n d: Decoder<D>,\n e: Decoder<E>,\n f: Decoder<F>,\n): Decoder<[A, B, C, D, E, F]>;\nexport function tuple(...decoders: readonly Decoder<unknown>[]): Decoder<unknown[]> {\n return ntuple(decoders.length).then((blobs, ok, err) => {\n let allOk = true;\n\n const rvs = decoders.map((decoder, i) => {\n const blob = blobs[i];\n const result = decoder.decode(blob);\n if (result.ok) {\n return result.value;\n } else {\n allOk = false;\n return result.error;\n }\n });\n\n if (allOk) {\n return ok(rvs);\n } else {\n // If a decoder error has happened while unwrapping all the\n // results, try to construct a good error message\n return err(annotate(rvs));\n }\n });\n}\n","import { define } from '../Decoder';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts any valid ``number`` value.\n *\n * This also accepts special values like `NaN` and `Infinity`. Unless you\n * want to deliberately accept those, you'll likely want to use the\n * `number` decoder instead.\n */\nexport const anyNumber: Decoder<number> = define((blob, ok, err) =>\n typeof blob === 'number' ? ok(blob) : err('Must be number'),\n);\n\n/**\n * Accepts finite numbers (can be integer or float values). Values `NaN`,\n * or positive and negative `Infinity` will get rejected.\n */\nexport const number: Decoder<number> = anyNumber.refine(\n (n) => Number.isFinite(n),\n 'Number must be finite',\n);\n\n/**\n * Accepts only finite whole numbers.\n */\nexport const integer: Decoder<number> = number.refine(\n (n) => Number.isInteger(n),\n 'Number must be an integer',\n);\n\n/**\n * Accepts only non-negative (zero or positive) finite numbers.\n */\nexport const positiveNumber: Decoder<number> = number\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n\n/**\n * Accepts only non-negative (zero or positive) finite whole numbers.\n */\nexport const positiveInteger: Decoder<number> = integer\n .refine((n) => n >= 0, 'Number must be positive')\n .transform(Math.abs); // Just here to handle the -0 case\n","import { define } from '../Decoder';\nimport { number } from './numbers';\nimport type { Decoder } from '../Decoder';\n\n/**\n * Accepts and returns booleans.\n */\nexport const boolean: Decoder<boolean> = define((blob, ok, err) => {\n return typeof blob === 'boolean' ? ok(blob) : err('Must be boolean');\n});\n\n/**\n * Accepts anything and will return its \"truth\" value. Will never reject.\n */\nexport const truthy: Decoder<boolean> = define((blob, ok, _) => ok(!!blob));\n\n/**\n * Accepts numbers, but return their boolean representation.\n */\nexport const numericBoolean: Decoder<boolean> = number.transform((n) => !!n);\n","import { define } from '../Decoder';\nimport { either } from './unions';\nimport { instanceOf } from './utilities';\nimport type { Decoder } from '../Decoder';\n\n/** Match groups in this regex:\n * \\1 - the scheme\n * \\2 - the username/password (optional)\n * \\3 - the host\n * \\4 - the port (optional)\n * \\5 - the path (optional)\n */\nconst url_re =\n /^([A-Za-z]{3,9}(?:[+][A-Za-z]{3,9})?):\\/\\/(?:([-;:&=+$,\\w]+)@)?(?:([A-Za-z0-9.-]+)(?::([0-9]{2,5}))?)(\\/(?:[-+~%/.,\\w]*)?(?:\\?[-+=&;%@.,/\\w]*)?(?:#[.,!/\\w]*)?)?$/;\n\n/**\n * Accepts and returns strings.\n */\nexport const string: Decoder<string> = define((blob, ok, err) =>\n typeof blob === 'string' ? ok(blob) : err('Must be string'),\n);\n\n/**\n * Like `string`, but will reject the empty string or strings containing only whitespace.\n */\nexport const nonEmptyString: Decoder<string> = regex(/\\S/, 'Must be non-empty string');\n\n/**\n * Accepts and returns strings that match the given regular expression.\n */\nexport function regex(regex: RegExp, msg: string): Decoder<string> {\n return string.refine((s) => regex.test(s), msg);\n}\n\n/**\n * Accepts and returns strings that are syntactically valid email addresses.\n * (This will not mean that the email address actually exist.)\n */\nexport const email: Decoder<string> = regex(\n // The almost perfect email regex, taken from https://emailregex.com/\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n 'Must be email',\n);\n\n/**\n * Accepts strings that are valid URLs, returns the value as a URL instance.\n */\nexport const url: Decoder<URL> = either(\n regex(url_re, 'Must be URL').transform((value) => new URL(value)),\n instanceOf(URL),\n);\n\n/**\n * Accepts strings that are valid URLs, but only HTTPS ones. Returns the value\n * as a URL instance.\n */\nexport const httpsUrl: Decoder<URL> = url.refine(\n (value) => value.protocol === 'https:',\n 'Must be an HTTPS URL',\n);\n\n/**\n * Accepts strings that are valid\n * [UUIDs](https://en.wikipedia.org/wiki/universally_unique_identifier)\n * (universally unique identifier).\n */\nexport const uuid: Decoder<string> = regex(\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,\n 'Must be uuid',\n);\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv1](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_%28date-time_and_MAC_address%29)\n * strings.\n */\nexport const uuidv1: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)\n uuid.refine((value) => value[14] === '1', 'Must be uuidv1');\n\n/**\n * Like `uuid`, but only accepts\n * [UUIDv4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_%28random%29)\n * strings.\n */\nexport const uuidv4: Decoder<string> =\n // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)\n uuid.refine((value) => value[14] === '4', 'Must be uuidv4');\n","import { asDate } from '../_utils';\nimport { define } from '../Decoder';\nimport { regex } from './strings';\nimport type { Decoder } from '../Decoder';\n\n// Only matches the shape. This \"over-matches\" some values that still aren't\n// valid dates (like 9999-99-99), but those will be caught by JS Date's\n// internal validations\nconst iso8601_re =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:[.]\\d+)?(?:Z|[+-]\\d{2}:?\\d{2})$/;\n\n/**\n * Accepts and returns `Date` instances.\n */\nexport const date: Decoder<Date> = define((blob, ok, err) => {\n const date = asDate(blob);\n return date !== null ? ok(date) : err('Must be a Date');\n});\n\n/**\n * Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,\n * returns them as `Date` instances.\n *\n * This is very useful for working with dates in APIs: serialize them as\n * `.toISOString()` when sending, decode them with `iso8601` when receiving.\n */\nexport const iso8601: Decoder<Date> =\n // Input itself needs to match the ISO8601 regex...\n regex(iso8601_re, 'Must be ISO8601 format').transform(\n // Make sure it is a _valid_ date\n (value: string) => {\n const date = new Date(value);\n if (isNaN(date.getTime())) {\n throw new Error('Must be valid date/time value');\n }\n return date;\n },\n );\n","import { array } from './arrays';\nimport { boolean } from './booleans';\nimport { dict } from './objects';\nimport { either } from './unions';\nimport { lazy } from './utilities';\nimport { null_ } from './basics';\nimport { number } from './numbers';\nimport { string } from './strings';\nimport type { Decoder } from '../Decoder';\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\nexport type JSONObject = { [key: string]: JSONValue | undefined };\nexport type JSONArray = JSONValue[];\n\n/**\n * Accepts objects that contain only valid JSON values.\n */\nexport const jsonObject: Decoder<JSONObject> = lazy(() => dict(json));\n\n/**\n * Accepts arrays that contain only valid JSON values.\n */\nexport const jsonArray: Decoder<JSONArray> = lazy(() => array(json));\n\n/**\n * Accepts any value that's a valid JSON value.\n *\n * In other words: any value returned by `JSON.parse()` should decode without\n * failure.\n *\n * ```typescript\n * type JSONValue =\n * | null\n * | string\n * | number\n * | boolean\n * | { [string]: JSONValue }\n * | JSONValue[]\n * ```\n */\nexport const json: Decoder<JSONValue> = either(\n null_,\n string,\n number,\n boolean,\n jsonObject,\n jsonArray,\n).describe('Must be valid JSON value');\n"],"mappings":";AAIO,IAAM,SAAS;AAEf,SAAS,QAAW,OAAyB;AAClD,SAAO,OAAO,UAAU,aAAc,MAAkB,IAAI;AAC9D;AAKO,SAAS,SAA2B,IAAY,IAAoB;AACzE,QAAM,SAAS,oBAAI,IAAO;AAC1B,aAAW,KAAK,IAAI;AAClB,QAAI,CAAC,GAAG,IAAI,CAAC,GAAG;AACd,aAAO,IAAI,CAAC;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,OAAO,OAA6B;AAQlD,SAAO,CAAC,CAAC,SACP,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,mBAC1C,CAAC,MAAM,KAAe,IACnB,QACD;AACN;AAEO,SAAS,OAAO,OAAkD;AACvE,SACE,UAAU,QACV,UAAU,UACV,OAAO,UAAU;AAAA;AAAA,EAGjB,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM;AAE9C;AAEO,SAAS,YAAY,GAAoB;AAC9C,SAAO,EAAE,QAAQ,IAAI,KAAK;AAC5B;AAEO,SAAS,OAAO,GAAW,SAAiB,QAAgB;AACjE,MAAI,YAAY,CAAC,GAAG;AAClB,WAAO,EACJ,MAAM,IAAI,EACV,IAAI,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI,EAAE,EAChC,KAAK,IAAI;AAAA,EACd,OAAO;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E,MAAM,KAAK,gBAAgB;AAAA;;;AC/E5D,IAAM,aACJ;AAKK,IAAM,OAAsB,OAAO,CAAC,MAAMC,KAAIC,SAAQ;AAC3D,QAAMC,QAAO,OAAO,IAAI;AACxB,SAAOA,UAAS,OAAOF,IAAGE,KAAI,IAAID,KAAI,gBAAgB;AACxD,CAAC;AASM,IAAM;AAAA;AAAA,EAEX,MAAM,YAAY,wBAAwB,EAAE;AAAA;AAAA,IAE1C,CAAC,UAAkB;AACjB,YAAMC,QAAO,IAAI,KAAK,KAAK;AAC3B,UAAI,MAAMA,MAAK,QAAQ,CAAC,GAAG;AACzB,cAAM,IAAI,MAAM,+BAA+B;AAAA,MACjD;AACA,aAAOA;AAAA,IACT;AAAA,EACF;AAAA;;;ACpBK,IAAM,aAAkC,KAAK,MAAM,KAAK,IAAI,CAAC;AAK7D,IAAM,YAAgC,KAAK,MAAMC,OAAM,IAAI,CAAC;AAkB5D,IAAM,OAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,SAAS,0BAA0B;","names":["ann","err","value","ok","ok","err","object","ok","err","err","ok","mapping","object","ok","err","unknown","ok","err","array","ok","err","ok","err","ok","err","regex","ok","err","date","array"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decoders",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-test2",
|
|
4
4
|
"description": "Elegant and battle-tested validation library for type-safe input data for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"actually-prepublish": "echo \"\\n\\nPlease run \\`bin/publish.sh <options>\\` instead.\\n\\n\" && exit 2",
|
|
39
39
|
"build": "tsup",
|
|
40
40
|
"docs": "cog -cr docs/*.md",
|
|
41
|
-
"lint": "eslint --color --report-unused-disable-directives src
|
|
41
|
+
"lint": "eslint --color --report-unused-disable-directives src/ test/ && prettier --list-different src/ test/ test-d/",
|
|
42
42
|
"lint:docs": "cog -c --check docs/*.md || (npm run docs; git diff; echo 'Error: docs not up-to-date, please re-run \"npm docs\" to update them.' && exit 1)",
|
|
43
43
|
"lint:package": "publint --strict && attw --pack",
|
|
44
|
-
"format": "eslint --report-unused-disable-directives --fix src && prettier --write
|
|
44
|
+
"format": "eslint --color --report-unused-disable-directives --fix src/ test/ && prettier --write src/ test/ test-d/",
|
|
45
45
|
"test": "vitest run --coverage",
|
|
46
46
|
"test:completeness": "./bin/check.sh",
|
|
47
47
|
"test:typescript": "tsc --noEmit",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
],
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@arethetypeswrong/cli": "^0.13.5",
|
|
65
|
+
"@release-it/keep-a-changelog": "^5.0.0",
|
|
65
66
|
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
66
67
|
"@typescript-eslint/parser": "^6.17.0",
|
|
67
68
|
"@vitest/coverage-istanbul": "^1.1.1",
|