succulent
Version:
Powerful and easy runtime type checking
8 lines (7 loc) • 31.1 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/index.ts", "../src/filters/length.ts", "../src/filters/matches.ts", "../src/filters/range.ts", "../src/base/errorMessages.ts", "../src/base/toDisplayKey.ts", "../src/base/toDisplayString.ts", "../src/base/indent.ts", "../src/base/trace.ts", "../src/base/keyReporter.ts", "../src/schema.ts", "../src/operators/check.ts", "../src/operators/is.ts", "../src/operators/iterables.ts", "../src/operators/logic.ts", "../src/types/array.ts", "../src/types/collections.ts", "../src/types/misc.ts", "../src/types/constants.ts", "../src/types/enum.ts", "../src/types/number.ts", "../src/types/object.ts", "../src/types/record.ts", "../src/types/string.ts", "../src/types/symbol.ts", "../src/types/tuple.ts", "../src/ref.ts"],
"sourcesContent": ["export * from \"./filters\";\nexport * from \"./operators\";\nexport * from \"./types\";\nexport * from \"./ref\";\nexport * from \"./schema\";\n", "type HasLength = { length: number };\n\nexport function hasLength(length: number) {\n\treturn (x: HasLength) => x.length === length;\n}\n\nexport function minLength(length: number) {\n\treturn (x: HasLength) => x.length >= length;\n}\n\nexport function maxLength(length: number) {\n\treturn (x: HasLength) => x.length <= length;\n}\n\nexport function nonEmpty(x: HasLength) {\n\treturn x.length > 0;\n}\n", "export function matches(expression: RegExp) {\n\treturn function (t: string) {\n\t\treturn expression.test(t);\n\t};\n}\n", "export function inRange(min: number, max: number) {\n\treturn (x: number) => min <= x && x <= max;\n}\n", "import { Schema, SchemaBase } from \"../schema\";\nimport { toDisplayKey } from \"./toDisplayKey\";\nimport { toDisplayString } from \"./toDisplayString\";\n\nexport function invalidProperty(key: unknown, schema: SchemaBase<unknown>) {\n\tconst displayKey = toDisplayKey(key);\n\tconst typeName = Schema.displayName(schema);\n\n\treturn `Expected property ${displayKey} to have type ${typeName}`;\n}\n\nexport function invalidValue(value: unknown, schema: SchemaBase<unknown>) {\n\tconst displayValue = toDisplayString(value);\n\tconst typeName = Schema.displayName(schema);\n\n\treturn `Expected ${typeName}, got ${displayValue}`;\n}\n", "export function toDisplayKey(x: unknown) {\n\tswitch (typeof x) {\n\t\tcase \"string\":\n\t\t\treturn x;\n\t\tdefault:\n\t\t\treturn `[${String(x)}]`;\n\t}\n}\n", "export function toDisplayString(x: unknown) {\n\tswitch (typeof x) {\n\t\tcase \"bigint\":\n\t\t\treturn `${x}n`;\n\t\tcase \"string\":\n\t\t\treturn `\"${x}\"`;\n\t\tdefault:\n\t\t\treturn String(x);\n\t}\n}\n", "export function indent(str: string, level: string | number = 2) {\n\tconst indentation = typeof level === \"number\" ? \" \".repeat(level) : level;\n\n\treturn str\n\t\t.split(\"\\n\")\n\t\t.map((line) => `${indentation}${line}`)\n\t\t.join(\"\\n\");\n}\n", "import { indent } from \"./indent\";\n\nexport function trace(message: string, error?: unknown) {\n\tif (error instanceof Error) {\n\t\treturn `${message}\\n${indent(error.message)}`;\n\t}\n\n\treturn message;\n}\n", "import { trace } from \"./trace\";\n\ntype Func<Args extends unknown[], R = void> = (...args: Args) => R;\ntype ReportFunc<Args extends unknown[]> = Func<Args>;\ntype ResolveFunc = () => boolean;\n\nexport function keyReporter<Args extends unknown[], Key>(\n\tcheck: Func<Args>,\n\tonError: Func<Args, string>,\n): [report: ReportFunc<Args>, resolve: ResolveFunc] {\n\tconst errorTraces: string[] = [];\n\n\tconst report: ReportFunc<Args> = (...args) => {\n\t\ttry {\n\t\t\tcheck(...args);\n\t\t} catch (error) {\n\t\t\terrorTraces.push(trace(onError(...args), error));\n\t\t}\n\t};\n\n\tconst resolve: ResolveFunc = () => {\n\t\tif (errorTraces.length > 0) {\n\t\t\tthrow new TypeError(errorTraces.join(\"\\n\"));\n\t\t}\n\n\t\treturn true;\n\t};\n\n\treturn [report, resolve];\n}\n", "import { messages, toDisplayString, trace } from \"./base\";\nimport type { ErrorRef } from \"./ref\";\n\nexport type Type<X> = Schema.Unwrap<X>;\nexport namespace Schema {\n\texport type Unwrap<X> = X extends Schema<infer T> ? T : never;\n\texport type UnwrapAll<X> = { [K in keyof X]: Unwrap<X[K]> };\n\texport type Wrap<X> = SchemaBase<X>;\n\texport type WrapAll<X> = { [K in keyof X]: Wrap<X[K]> };\n}\n\nexport type SchemaBase<T> = Schema<T> | (T extends LiteralSchema ? T : never);\nexport type LiteralSchema =\n\t| string\n\t| number\n\t| bigint\n\t| symbol\n\t| boolean\n\t| null\n\t| undefined;\n\ntype Filter<T> = (x: T) => boolean;\n\ninterface SchemaOptions<T> {\n\tdisplayName?: string;\n\titer?: () => Iterator<T>;\n}\n\nexport class Schema<T> {\n\tstatic check<T>(base: SchemaBase<T>, x: unknown): x is T {\n\t\tif (base instanceof Schema) {\n\t\t\treturn base.check(x);\n\t\t}\n\n\t\treturn new Schema(base).check(x);\n\t}\n\n\tstatic is<T>(base: SchemaBase<T>, x: unknown, ref?: ErrorRef): x is T {\n\t\ttry {\n\t\t\tSchema.check(base, x);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif (ref && error instanceof Error) ref.error = error;\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tstatic displayName<T>(base: SchemaBase<T>) {\n\t\treturn Schema.from(base).displayName;\n\t}\n\n\tstatic every<T>(\n\t\tbase: SchemaBase<T>,\n\t\tpredicate: (value: T, index: number, array: T[]) => boolean,\n\t): boolean {\n\t\treturn Array.from(Schema.from(base)).every(predicate);\n\t}\n\n\tstatic from<T>(base: SchemaBase<T>): Schema<T> {\n\t\tif (base instanceof Schema) {\n\t\t\treturn base;\n\t\t}\n\n\t\treturn new Schema(base);\n\t}\n\n\t/**\n\t * Used to iterate through all possible values accepted by the schema,\n\t * for certain finite types\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-empty-function, class-methods-use-this\n\treadonly [Symbol.iterator]: () => Iterator<T> = function* () {};\n\n\tprivate readonly _check: (x: unknown) => x is T;\n\n\tpublic readonly displayName: string = \"(unknown)\";\n\n\tconstructor(\n\t\tbase: ((x: unknown) => x is T) | SchemaBase<T>,\n\t\toptions: SchemaOptions<T> = {},\n\t) {\n\t\tconst { displayName, iter } = options;\n\n\t\t// Constructing a Schema from a previous Schema, just copy\n\t\tif (base instanceof Schema) {\n\t\t\tthis._check = base._check;\n\t\t\tthis.displayName = displayName || base.displayName;\n\t\t\tthis[Symbol.iterator] = iter ?? base[Symbol.iterator];\n\t\t\treturn;\n\t\t}\n\n\t\t// Constructing a Schema from a FunctionSchema\n\t\tif (typeof base === \"function\") {\n\t\t\tthis._check = base;\n\t\t\tif (displayName) this.displayName = displayName;\n\t\t\tif (iter) this[Symbol.iterator] = iter;\n\t\t\treturn;\n\t\t}\n\n\t\t// Constructing a Schema from a LiteralSchema\n\t\tthis._check = (x: unknown): x is T => Object.is(x, base);\n\t\tthis.displayName = displayName || toDisplayString(base);\n\t\tthis[Symbol.iterator] =\n\t\t\titer ??\n\t\t\tfunction* () {\n\t\t\t\tyield base;\n\t\t\t};\n\t}\n\n\t/**\n\t * A method used to check if a given value matches the schema\n\t */\n\tcheck(x: unknown): x is T {\n\t\tlet ok;\n\t\ttry {\n\t\t\tok = this._check(x);\n\t\t} catch (error) {\n\t\t\tthrow new TypeError(trace(messages.invalidValue(x, this), error));\n\t\t}\n\n\t\tif (!ok) {\n\t\t\tthrow new TypeError(messages.invalidValue(x, this));\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tthat(...filters: Array<Filter<T>>): Schema<T> {\n\t\treturn new Schema(\n\t\t\t(x: unknown): x is T => this.check(x) && filters.every((filter) => filter(x)),\n\t\t);\n\t}\n\n\ttoString(): string {\n\t\treturn this.displayName;\n\t}\n}\n", "import { Schema, SchemaBase } from \"../schema\";\n\nexport function check<T>(x: unknown, schema: SchemaBase<T>): asserts x is T {\n\tif (!Schema.check(schema, x)) {\n\t\tthrow new Error(\"check returned false instead of throwing, which is bad\");\n\t}\n}\n\nexport const guard = check;\n", "import type { ErrorRef } from \"../ref\";\nimport { Schema, SchemaBase } from \"../schema\";\n\nexport function is<T>(x: unknown, schema: SchemaBase<T>, ref?: ErrorRef): x is T {\n\treturn Schema.is(schema, x, ref);\n}\n", "import { Schema } from \"../schema\";\n\nexport function oneOf<T>(x: Iterable<T>): Schema<T> {\n\treturn new Schema((t: unknown): t is T => {\n\t\tfor (const value of x) {\n\t\t\tif (Object.is(t, value)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t});\n}\n", "import { Schema, SchemaBase } from \"../schema\";\nimport { is } from \"./is\";\n\nexport function union<T extends readonly unknown[]>(\n\t...schemas: readonly [...Schema.WrapAll<T>]\n): Schema<T[number]> {\n\treturn new Schema(\n\t\t(t: unknown): t is T[number] => schemas.some((schema) => is(t, schema)),\n\t\t{\n\t\t\tdisplayName: `(${schemas\n\t\t\t\t.map((schema) => Schema.from(schema).displayName)\n\t\t\t\t.join(\" | \")})`,\n\t\t\t*iter() {\n\t\t\t\tfor (const schema of schemas) yield* Schema.from(schema);\n\t\t\t},\n\t\t},\n\t);\n}\n\nexport function or<X, Y>(x: SchemaBase<X>, y: SchemaBase<Y>): Schema<X | Y> {\n\treturn new Schema((t: unknown): t is X | Y => is(t, x) || is(t, y), {\n\t\tdisplayName: `(${Schema.displayName(x)} | ${Schema.displayName(y)})`,\n\t\t*iter() {\n\t\t\tyield* Schema.from(x);\n\t\t\tyield* Schema.from(y);\n\t\t},\n\t});\n}\n\nexport function and<X, Y>(x: SchemaBase<X>, y: SchemaBase<Y>): Schema<X & Y> {\n\treturn new Schema((t: unknown): t is X & Y => is(t, x) && is(t, y), {\n\t\tdisplayName: `(${Schema.displayName(x)} & ${Schema.displayName(y)})`,\n\t});\n}\n", "import { Schema, SchemaBase } from \"../schema\";\n\nexport function $Array<T>(base: SchemaBase<T>): Schema<T[]> {\n\tconst itemSchema = Schema.from(base);\n\tconst baseDisplayName = itemSchema.displayName;\n\n\treturn new Schema(\n\t\t(t: unknown): t is T[] => {\n\t\t\tif (!Array.isArray(t)) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfor (const each of t) {\n\t\t\t\titemSchema.check(each);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t},\n\t\t{\n\t\t\tdisplayName: baseDisplayName.includes(\" \")\n\t\t\t\t? `${baseDisplayName}[]`\n\t\t\t\t: `Array<${baseDisplayName}>`,\n\t\t},\n\t);\n}\n", "import { Schema, SchemaBase } from \"../schema\";\n\nexport function $Map<K, V>(\n\tkeySchemaBase: SchemaBase<K>,\n\tvalueSchemaBase: SchemaBase<V>,\n): Schema<Map<K, V>> {\n\tconst keySchema = Schema.from(keySchemaBase);\n\tconst valueSchema = Schema.from(valueSchemaBase);\n\tconst keyTypeName = keySchema.displayName;\n\tconst valueTypeName = valueSchema.displayName;\n\n\treturn new Schema(\n\t\t(x: unknown): x is Map<K, V> => {\n\t\t\tif (!(x instanceof Map)) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfor (const [key, value] of x) {\n\t\t\t\tkeySchema.check(key);\n\t\t\t\tvalueSchema.check(value);\n\t\t\t}\n\n\t\t\t// If we made it through the whole map, and nothing failed, then everything passed!\n\t\t\treturn true;\n\t\t},\n\t\t{ displayName: `Map<${keyTypeName}, ${valueTypeName}>` },\n\t);\n}\n\nexport function $Set<K>(schemaBase: SchemaBase<K>): Schema<Set<K>> {\n\tconst schema = Schema.from(schemaBase);\n\n\treturn new Schema(\n\t\t(x: unknown): x is Set<K> => {\n\t\t\tif (!(x instanceof Set)) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfor (const key of x) {\n\t\t\t\tschema.check(key);\n\t\t\t}\n\n\t\t\t// If we made it through the whole set, and nothing failed, then everything passed!\n\t\t\treturn true;\n\t\t},\n\t\t{ displayName: `Set<${schema.displayName}>` },\n\t);\n}\n", "import { LiteralSchema, Schema, SchemaBase } from \"../schema\";\nimport { $undefined } from \"./constants\";\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function $instanceof<T extends Function>(t: T) {\n\treturn new Schema((x: unknown): x is T[\"prototype\"] => x instanceof t, {\n\t\tdisplayName: t.name,\n\t});\n}\n\n/**\n * Alias for $instanceof, i.e. checks if a value is \"a\"/an `T`\n */\nexport const a = $instanceof;\n\nexport function $literal<T extends LiteralSchema>(t: T) {\n\t// @ts-expect-error - This should be fine, because LiteralSchema is a\n\t// valid type to pass, but TypeScript is unhappy\n\treturn new Schema(t);\n}\n\n// Truthy is intentionally absent from this set because nearly anything can be truthy,\n// which is not very useful for type narrowing.\n\n// Notably missing is (typeof NaN), which can't be included because it just\n// evaluates to `number`, and the vast majority of numbers are not falsy\nexport type falsy = false | 0 | 0n | \"\" | nullish;\nexport type nullish = undefined | null;\n\nexport const $falsy = new Schema((x: unknown): x is falsy => !x, {\n\tdisplayName: \"falsy\",\n});\nexport const $nullish = new Schema((x: unknown): x is nullish => x == null, {\n\tdisplayName: \"nullish\",\n});\n\nexport function $optional<T>(base: SchemaBase<T>): Schema<T | undefined> {\n\tconst schema = Schema.from(base);\n\n\treturn new Schema(\n\t\t(x: unknown): x is T | undefined =>\n\t\t\tSchema.is(schema, x) || Schema.is($undefined, x),\n\t\t{ displayName: `${schema.displayName}?` },\n\t);\n}\n\nexport function $maybe<T>(base: SchemaBase<T>): Schema<T | nullish> {\n\tconst schema = Schema.from(base);\n\n\treturn new Schema(\n\t\t(x: unknown): x is T | undefined =>\n\t\t\tSchema.is(schema, x) || Schema.is($nullish, x),\n\t\t{ displayName: `maybe ${schema.displayName}` },\n\t);\n}\n\n/**\n * Probably shouldn't be used very frequently, but occasionally useful for\n * stuff like `$array($any)` or just specifying that an object should have a\n * key, without needing to specify the whole type. Basically the same kind of\n * cases you might want to use it in TypeScript.\n */\nexport const $any = new Schema((x: unknown): x is any => true, { displayName: \"any\" }); // eslint-disable-line @typescript-eslint/no-explicit-any\n\n/**\n * Mostly useful for tests to convey that something should never match, honestly\n * not very useful for anything else imho.\n */\nexport const $never = new Schema((x: unknown): x is never => false, {\n\tdisplayName: \"never\",\n});\n\n// export const $Blob = $instanceof(Blob);\nexport const $Date = $instanceof(Date);\n// export const $File = $instanceof(File);\nexport const $Error = $instanceof(Error);\nexport const $RegExp = $instanceof(RegExp);\nexport const $URL = $instanceof(URL);\n\nexport const $ArrayBuffer = $instanceof(ArrayBuffer);\nexport const $ArrayBufferView = new Schema(\n\t(x: unknown): x is ArrayBufferView => ArrayBuffer.isView(x),\n\t{ displayName: \"ArrayBufferView\" },\n);\n\nexport const $Int8Array = $instanceof(Int8Array);\nexport const $Int16Array = $instanceof(Int16Array);\nexport const $Int32Array = $instanceof(Int32Array);\nexport const $BigInt64Array = $instanceof(BigInt64Array);\nexport const $Uint8Array = $instanceof(Uint8Array);\nexport const $Uint8ClampedArray = $instanceof(Uint8ClampedArray);\nexport const $Uint16Array = $instanceof(Uint16Array);\nexport const $Uint32Array = $instanceof(Uint32Array);\nexport const $BigUint64Array = $instanceof(BigUint64Array);\nexport const $Float32Array = $instanceof(Float32Array);\nexport const $Float64Array = $instanceof(Float64Array);\n", "import { Schema } from \"../schema\";\nimport { $literal } from \"./misc\";\n\nexport const $boolean = new Schema((x: unknown): x is boolean => typeof x === \"boolean\", {\n\tdisplayName: \"boolean\",\n});\nexport const $NaN = new Schema((x: unknown): x is typeof NaN => x !== x, {\n\tdisplayName: \"NaN\",\n});\n\nexport const $false = $literal(false);\nexport const $true = $literal(true);\nexport const $undefined = $literal(undefined);\nexport const $null = $literal(null);\n", "import { Schema } from \"../schema\";\n\nfunction isEnumMemberName<E, K extends string | number | symbol>(\n\tx: unknown,\n\tenumObject: Record<K, E>,\n): x is E {\n\t// @ts-expect-error - This is some real fun voodoo :)\n\t// eslint-disable-next-line\n\treturn x in enumObject && typeof enumObject[enumObject[x]] !== \"number\";\n}\n\nfunction enumKeys<E, K extends string | number | symbol>(enumObject: Record<K, E>): K[] {\n\treturn Object.keys(enumObject).filter((key) =>\n\t\tisEnumMemberName(key, enumObject),\n\t) as K[];\n}\n\nexport interface EnumOptions {\n\tdisplayName?: string;\n}\n\nexport function $enum<E, K extends string | number | symbol>(\n\tenumObject: Record<K, E>,\n\toptions: EnumOptions = {},\n): Schema<E> {\n\tconst keys = enumKeys(enumObject);\n\tconst values = new Set(keys.map((key) => enumObject[key]));\n\n\t// eslint-disable-next-line\n\treturn new Schema((x: unknown): x is E => values.has(x as any), {\n\t\tdisplayName: options.displayName ?? `enum { ${keys.join(\", \")} }`,\n\t\t*iter() {\n\t\t\tyield* values;\n\t\t},\n\t});\n}\n", "import { Schema } from \"../schema\";\n\nexport const $number = new Schema(\n\t(x: unknown): x is number => typeof x === \"number\" && x === x,\n\t{ displayName: \"number\" },\n);\n\nexport const $int = new Schema((x: unknown): x is number => Number.isInteger(x), {\n\tdisplayName: \"int\",\n});\n\nexport const $finite = new Schema((x: unknown): x is number => Number.isFinite(x), {\n\tdisplayName: \"finite\",\n});\n\nexport const $bigint = new Schema((x: unknown): x is bigint => typeof x === \"bigint\", {\n\tdisplayName: \"bigint\",\n});\n", "import { keyReporter, messages, toDisplayKey } from \"../base\";\nimport { Schema, SchemaBase } from \"../schema\";\n\nfunction hasOwn(target: unknown, prop: string | symbol) {\n\tif (!{}.hasOwnProperty.call(target, prop)) {\n\t\tthrow null;\n\t}\n\n\treturn true;\n}\n\ntype KeyValuePair = readonly [key: unknown, valueSchema: SchemaBase<unknown>];\nconst toDisplayKeyValue = ([key, valueSchema]: KeyValuePair) =>\n\t`${toDisplayKey(key)}: ${Schema.displayName(valueSchema)}`;\n\nexport const $object = new Schema(\n\t(x: unknown): x is object => typeof x === \"object\" && x != null,\n\t{ displayName: \"object\" },\n);\n\nexport function $interface<T extends object>(template: {\n\t[K in keyof T]: SchemaBase<T[K]>;\n}): Schema<T> {\n\treturn new Schema(\n\t\t(x: unknown): x is T => {\n\t\t\tconst [report, resolve] = keyReporter(\n\t\t\t\t// @ts-expect-error - Can't quite get these types\n\t\t\t\t(key: string | symbol) => Schema.check(template[key], x[key]),\n\t\t\t\t// @ts-expect-error - Can't quite get these types\n\t\t\t\t(key) => messages.invalidProperty(key, template[key] as Schema<unknown>),\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t$object.check(x) && (Reflect.ownKeys(template).forEach(report), resolve())\n\t\t\t);\n\t\t},\n\n\t\t{\n\t\t\tdisplayName: `{${Reflect.ownKeys(template)\n\t\t\t\t// @ts-expect-error - Can't quite get these types\n\t\t\t\t.map((key) => [key, template[key]] as const)\n\t\t\t\t.map(toDisplayKeyValue)\n\t\t\t\t.join(\", \")}}`,\n\t\t},\n\t);\n}\n\nexport function $Exact<T extends object>(template: {\n\t[K in keyof T]: SchemaBase<T[K]>;\n}): Schema<T> {\n\treturn new Schema(\n\t\t(x: unknown): x is T => {\n\t\t\tconst [reportUnknown, resolveUnknown] = keyReporter(\n\t\t\t\t(key: string | symbol) => hasOwn(template, key),\n\t\t\t\t(key) => `Unexpected property ${toDisplayKey(key)}`,\n\t\t\t);\n\n\t\t\tconst [reportKnown, resolveKnown] = keyReporter(\n\t\t\t\t// @ts-expect-error - Can't quite get these types\n\t\t\t\t(key: string | symbol) => Schema.check(template[key], x[key]),\n\t\t\t\t// @ts-expect-error - Can't quite get these types\n\t\t\t\t(key) => messages.invalidProperty(key, template[key] as Schema<unknown>),\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t$object.check(x) &&\n\t\t\t\t(Reflect.ownKeys(x).forEach(reportUnknown), resolveUnknown()) &&\n\t\t\t\t(Reflect.ownKeys(template).forEach(reportKnown), resolveKnown())\n\t\t\t);\n\t\t},\n\t\t{\n\t\t\tdisplayName: `{|${Reflect.ownKeys(template)\n\t\t\t\t// @ts-expect-error - Can't quite get these types\n\t\t\t\t.map((key) => [key, template[key]] as const)\n\t\t\t\t.map(toDisplayKeyValue)\n\t\t\t\t.join(\", \")}|}`,\n\t\t},\n\t);\n}\n", "import { Schema, SchemaBase } from \"../schema\";\n\nexport function $Record<K extends string | number | symbol, T>(\n\tkeySchemaBase: SchemaBase<K>,\n\tvalueSchemaBase: SchemaBase<T>,\n): Schema<Record<K, T>> {\n\tconst keySchema = Schema.from(keySchemaBase);\n\tconst valueSchema = Schema.from(valueSchemaBase);\n\n\treturn new Schema(\n\t\t(x: unknown): x is Record<K, T> =>\n\t\t\ttypeof x === \"object\" &&\n\t\t\tx != null &&\n\t\t\tSchema.every(keySchema, (key) => ({}.hasOwnProperty.call(x, key))) &&\n\t\t\tObject.entries(x).every(([key, value]) =>\n\t\t\t\t// It doesn't hurt if there are extra keys that don't match, as long\n\t\t\t\t// as all of the ones that should do\n\t\t\t\tSchema.is(keySchema, key) ? Schema.is(valueSchema, value) : true,\n\t\t\t),\n\t\t{ displayName: `Record<${keySchema.displayName}, ${valueSchema.displayName}>` },\n\t);\n}\n", "import { Schema } from \"../schema\";\n\nexport const $string = new Schema((x: unknown): x is string => typeof x === \"string\", {\n\tdisplayName: \"string\",\n});\n", "import { Schema } from \"../schema\";\n\nexport const $symbol = new Schema((x: unknown): x is symbol => typeof x === \"symbol\", {\n\tdisplayName: \"symbol\",\n});\n", "import { Schema } from \"../schema\";\n\nexport function $Tuple<T extends unknown[]>(\n\t...schemas: [...Schema.WrapAll<T>]\n): Schema<T> {\n\treturn new Schema(\n\t\t(t: unknown): t is T =>\n\t\t\tArray.isArray(t) &&\n\t\t\tt.length === schemas.length &&\n\t\t\tschemas.every((schema, i) => Schema.check(schema, t[i])),\n\t\t{\n\t\t\tdisplayName: `[${schemas\n\t\t\t\t.map((schema) => Schema.displayName(schema))\n\t\t\t\t.join(\", \")}]`,\n\t\t},\n\t);\n}\n", "export interface ErrorRef {\n\terror: Error | null;\n}\n\nexport function createErrorRef(): ErrorRef {\n\treturn { error: null };\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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