@consolidados/results
Version:
Result types, ease and simple
1 lines • 23.2 kB
Source Map (JSON)
{"version":3,"sources":["../../src/result/__internal__/return-types/err.ts","../../src/result/__internal__/return-types/ok.ts","../../src/result/result.ts","../../src/option/__internal__/return-types/some.ts","../../src/option/__internal__/return-types/none.ts","../../src/option/option.ts"],"names":["Ok","Err","Some","None"],"mappings":";;;AAOO,IAAM,GAAA,GAAN,MAAM,IAA6C,CAAA;AAAA,EAChD,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR,YAAY,KAAU,EAAA;AAEpB,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA;AAAA;AAMf;AAAA;AAAA;AAAA;AAAA,EAMA,IAA0B,GAAA;AACxB,IAAO,OAAA,KAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,KAAwB,GAAA;AACtB,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,MAAgB,GAAA;AACd,IAAM,MAAA,IAAI,MAAM,+BAA+B,CAAA;AAAA;AACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAO,GAAsD,EAAA;AAC3D,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAU,EAA+C,EAAA;AACvD,IAAA,OAAO,IAAI,IAAA,CAAO,EAAG,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA;AAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,QACE,GACwB,EAAA;AACxB,IAAO,OAAA,IAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA,EAMA,SAAe,GAAA;AACb,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA;AACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAW,GAAA;AACT,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA;AACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAY,YAAo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AA;AAAA,EAQA,IAAO,GAAqC,EAAA;AAC1C,IAAA,OAAOA,KAAY,EAAA;AAAA;AACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAW,GAA6C,EAAA;AACtD,IAAA,OAAOA,KAAY,EAAA;AAAA;AACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAY,YAAoB,EAAA;AAC9B,IAAO,OAAA,YAAA;AAAA;AACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,aAAgB,EAAgB,EAAA;AAC9B,IAAA,OAAO,EAAG,EAAA;AAAA;AACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAQ,KAAU,EAAA;AAChB,IAAA,OAAOF,KAAI,KAAK,CAAA;AAAA;AAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAU,UAAkD,EAAA;AAC1D,IAAA,OAAOE,KAAY,EAAA;AAAA;AAEvB,CAAA;;;ACrFA,SAASD,MAAQ,KAAuB,EAAA;AACvC,EAAO,OAAA,IAAIA,MAAS,KAAK,CAAA;AAC1B;AAEA,IAAI,aAAiC,GAAA,IAAA;AAWrC,SAASC,KAAiB,GAAA;AACzB,EAAA,IAAI,CAAC,aAAe,EAAA;AACnB,IAAA,aAAA,GAAgB,IAAIA,KAAS,EAAA;AAAA;AAE9B,EAAO,OAAA,aAAA;AACR;AAEC,UAAA,CAAmB,IAAOD,GAAAA,KAAAA;AAC1B,UAAA,CAAmB,IAAOC,GAAAA,KAAAA","file":"option.cjs","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`. Can be any type (Error, string, enum, etc).\n */\nexport class Err<E> implements ResultDefinition<never, E> {\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance. Can be any type.\n */\n constructor(error: E) {\n // Store error as-is - conversion is handled by factory function\n this.error = error;\n // Object.setPrototypeOf(this, Err.prototype);\n //\n // if (Error.captureStackTrace) {\n // Error.captureStackTrace(this, Err);\n // }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error. Can be any type.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @template F The type of the error in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance cast to the new error type.\n */\n flatMap<U, F = E>(\n _fn: (value: never) => ResultDefinition<U, F>,\n ): ResultDefinition<U, E> {\n return this as unknown as ResultDefinition<U, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Returns the inner error. After an `isErr()` type guard, TypeScript narrows the return type to `E`.\n * Without a type guard, returns `T | E` (use `isOk()` or `isErr()` for type narrowing).\n * @returns The error value contained in this `Err`.\n */\n value(): E {\n return this.error;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise returns the provided default value.\n * @template U The type of the default value.\n * @param defaultValue The value to return since this is an `Err`.\n * @returns The provided default value.\n */\n unwrapOr<U>(defaultValue: U): U {\n return defaultValue;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise computes and returns the result of the provided function.\n * @template U The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The result of calling the provided function with the error.\n */\n unwrapOrElse<U>(fn: (error: E) => U): U {\n return fn(this.error);\n }\n\n /**\n * Returns this `Err` if it is `Err`, otherwise returns the result of the provided function.\n * @template T The type of the alternative success value.\n * @template F The type of the alternative error.\n * @param fn The function to compute the alternative result.\n * @returns The result of calling the provided function with the error.\n */\n orElse<T, F>(\n fn: (error: E) => ResultDefinition<T, F>,\n ): ResultDefinition<T, F> {\n return fn(this.error);\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param _value The value to wrap in the `Ok` instance.\n */\n constructor(private _value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this._value;\n }\n\n /**\n * Returns the inner value. After an `isOk()` type guard, TypeScript narrows the return type to `T`.\n * Without a type guard, returns `T | E` (use `isOk()` or `isErr()` for type narrowing).\n * @returns The value contained in this `Ok`.\n */\n value(): T {\n return this._value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this._value)) as unknown as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @template E The type of the error in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U, E = never>(\n fn: (value: T) => ResultDefinition<U, E>,\n ): ResultDefinition<U, E> {\n return fn(this._value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`). Can be any type.\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n mapErr<U>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise returns the provided default value.\n * @template U The type of the default value.\n * @param defaultValue The value to return if this is an `Err`.\n * @returns The value contained in this `Ok`.\n */\n unwrapOr<U>(defaultValue: U): T {\n return this._value;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise computes and returns the result of the provided function.\n * @template U The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The value contained in this `Ok`.\n */\n unwrapOrElse<U>(fn: (error: never) => U): T {\n return this._value;\n }\n\n /**\n * Returns this `Ok` if it is `Ok`, otherwise returns the result of the provided function.\n * @template F The type of the alternative error.\n * @param fn The function to compute the alternative result.\n * @returns The original `Ok` instance.\n */\n orElse<F>(fn: (error: never) => ResultDefinition<T, F>): ResultDefinition<T, F> {\n return this as unknown as ResultDefinition<T, F>;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return Some(this._value);\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates an Err - strings are converted to Error, everything else preserved\n */\nfunction Err<E>(error: E): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(globalThis as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(globalThis as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n","import type { None as NoneType } from \"./none\";\nimport type { Option } from \"./option\";\nimport { None } from \"../../option\";\nimport { Ok } from \"@/result\";\n\n/**\n * Represents a `Some` option, which holds a value.\n * @template T The type of the value held by this `Some` instance.\n */\nexport class Some<T> {\n /**\n * Creates a new `Some` option with the given value.\n * @param _value The value to be wrapped in the `Some` option.\n */\n constructor(private _value: T) { }\n\n /**\n * Checks if this option is a `Some`.\n * @returns `true` if this option is a `Some`, otherwise `false`.\n */\n isSome(): this is Some<T> {\n return true;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `false` because this is a `Some`.\n */\n isNone(): this is NoneType {\n return false;\n }\n\n /**\n * Unwraps the value held by this `Some` option.\n * @returns The value held by this `Some` option.\n */\n unwrap(): T {\n return this._value;\n }\n\n /**\n * Returns the inner value. After an `isSome()` type guard, TypeScript narrows the return type to `T`.\n * Without a type guard, returns `T | undefined` (use `isSome()` or `isNone()` for type narrowing).\n * @returns The value held by this `Some` option.\n */\n value(): T {\n return this._value;\n }\n\n /**\n * Applies a transformation function to the value held by this `Some` option and returns a new `Option` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Some` option containing the transformed value.\n */\n map<U>(fn: (value: T) => U): Option<U> {\n return new Some(fn(this._value));\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value held by this `Some` option.\n * @template U The type of the value in the resulting `Option`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(this._value);\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the default value provided.\n * @param _ A default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOr(_: T): T {\n return this._value;\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the function provided.\n * @template U The type of the default value.\n * @param _fn A function to compute the default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOrElse<U>(_fn: () => U): T {\n return this._value;\n }\n\n /**\n * Converts this `Option` to a `Result`, using the provided error value if this is `None`.\n * @template E The type of the error.\n * @param _error The error value to use if this is `None` (ignored since this is `Some`).\n * @returns An `Ok` result containing the value from this `Some`.\n */\n okOr<E>(_error: E) {\n return Ok(this._value);\n }\n\n /**\n * Filters this `Option` based on a predicate function.\n * @param predicate The function to test the value.\n * @returns This `Some` if the predicate returns true, otherwise `None`.\n */\n filter(predicate: (value: T) => boolean): Option<T> {\n return predicate(this._value) ? this : None();\n }\n}\n","import type { Some } from \"./some\";\nimport type { Option } from \"./option\";\nimport { None as NoneFactory } from \"../../option\";\nimport { Err } from \"@/result\";\n\n/**\n * Represents a `None` option, which holds no value.\n */\nexport class None {\n /**\n * Checks if this option is a `Some`.\n * @returns `false` because this is a `None`.\n */\n isSome(): this is Some<never> {\n return false;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `true` because this is a `None`.\n */\n isNone(): this is None {\n return true;\n }\n\n /**\n * Attempts to unwrap the value from this `None` option.\n * @throws An error because `None` has no value.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on a None value\");\n }\n\n /**\n * Returns `undefined` for a `None` option. After an `isNone()` type guard, TypeScript narrows the return type to `undefined`.\n * Without a type guard, returns `T | undefined` (use `isSome()` or `isNone()` for type narrowing).\n * Unlike `unwrap()`, this method does not throw an error.\n * @returns `undefined` because this is a `None`.\n */\n value(): undefined {\n return undefined;\n }\n\n /**\n * Applies a transformation function to the value (which does not exist) of this `None` option.\n * @template U The type of the value that would have been returned.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The singleton `None` instance.\n */\n map<U>(_fn: (value: never) => U): Option<U> {\n return NoneFactory();\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value (which does not exist) of this `None` option.\n * @template U The type of the value in the resulting `Option`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The singleton `None` instance.\n */\n flatMap<U>(_fn: (value: never) => Option<U>): Option<U> {\n return NoneFactory();\n }\n\n /**\n * Returns the default value provided, since `None` has no value.\n * @template T The type of the default value.\n * @param defaultValue The value to return.\n * @returns The default value provided.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n /**\n * Computes and returns the default value using the provided function, since `None` has no value.\n * @template T The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The result of calling the provided function.\n */\n unwrapOrElse<T>(fn: () => T): T {\n return fn();\n }\n\n /**\n * Converts this `Option` to a `Result`, using the provided error value since this is `None`.\n * @template E The type of the error.\n * @param error The error value to use.\n * @returns An `Err` result containing the provided error.\n */\n okOr<E>(error: E) {\n return Err(error);\n }\n\n /**\n * Filters this `Option` based on a predicate function.\n * @param _predicate The function to test the value (ignored since this is `None`).\n * @returns `None` since there is no value to filter.\n */\n filter<T>(_predicate: (value: never) => boolean): Option<T> {\n return NoneFactory();\n }\n}\n","import {\n\tSome as SomeType,\n\tNone as NoneType,\n\ttype Option,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Some` instance, representing an `Option` with a value.\n * @template T The type of the value contained in the `Some`.\n * @param value The value to wrap in the `Some` instance.\n * @returns A `Some` instance containing the given value.\n * @example\n * const option = Some(42);\n * console.log(option.isSome()); // true\n * console.log(option.unwrap()); // 42\n */\nfunction Some<T>(value: T): SomeType<T> {\n\treturn new SomeType(value);\n}\n\nlet NONE_INSTANCE: NoneType | null = null;\n\n/**\n * Returns the singleton `None` instance, representing an `Option` with no value.\n * Uses a singleton pattern to reduce memory allocations.\n * @returns The singleton `None` instance.\n * @example\n * const option = None();\n * console.log(option.isNone()); // true\n * console.log(option.unwrap()); // throws Error: \"Called unwrap on a None value\"\n */\nfunction None(): NoneType {\n\tif (!NONE_INSTANCE) {\n\t\tNONE_INSTANCE = new NoneType();\n\t}\n\treturn NONE_INSTANCE;\n}\n\n(globalThis as any).Some = Some;\n(globalThis as any).None = None;\n\nexport { None, Some, Option };\n"]}