Options
All
  • Public
  • Public/Protected
  • All
Menu

storage-map

Index

Functions

  • createStorageMap(storage: Pick<Storage, "clear" | "getItem" | "removeItem" | "setItem">): { clear: (() => { success: undefined; tag: "success" } | { failure: { storageError: unknown }; tag: "failure" }); getItem: (<Success, Failure, ResultLike>(key: string, map: ((value: unknown) => ResultLike)) => PrettyType<SuccessResult<SuccessOf<ReturnType<typeof map>>> | FailureResult<{ key: string; validationError: FailureOf<ReturnType<typeof map>> }> | FailureResult<{ key: string; keyNotExistError: undefined }> | FailureResult<{ key: string; mapError: unknown }> | FailureResult<{ key: string; storageError: unknown }>>); removeItem: ((key: string) => { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }); setItem: ((key: string, value: unknown) => { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }) }
  • Creates a storageMap from third-party Storage object.

    Parameters

    • storage: Pick<Storage, "clear" | "getItem" | "removeItem" | "setItem">

      A Storage-like object. Requires only setItem, getItem, removeItem and clear methods of standard Storage type to be defined.

    Returns { clear: (() => { success: undefined; tag: "success" } | { failure: { storageError: unknown }; tag: "failure" }); getItem: (<Success, Failure, ResultLike>(key: string, map: ((value: unknown) => ResultLike)) => PrettyType<SuccessResult<SuccessOf<ReturnType<typeof map>>> | FailureResult<{ key: string; validationError: FailureOf<ReturnType<typeof map>> }> | FailureResult<{ key: string; keyNotExistError: undefined }> | FailureResult<{ key: string; mapError: unknown }> | FailureResult<{ key: string; storageError: unknown }>>); removeItem: ((key: string) => { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }); setItem: ((key: string, value: unknown) => { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }) }

    • clear: (() => { success: undefined; tag: "success" } | { failure: { storageError: unknown }; tag: "failure" })
        • (): { success: undefined; tag: "success" } | { failure: { storageError: unknown }; tag: "failure" }
        • Calls underlying clear function.

          Returns { success: undefined; tag: "success" } | { failure: { storageError: unknown }; tag: "failure" }

          Success or failure result.

          • If underlying clear function did throw an error then a failure result containing an object with storageError property set to thrown value will be returned.
          • If underlying clear function did not throw an error then a success result containing an undefined value will be returned.
    • getItem: (<Success, Failure, ResultLike>(key: string, map: ((value: unknown) => ResultLike)) => PrettyType<SuccessResult<SuccessOf<ReturnType<typeof map>>> | FailureResult<{ key: string; validationError: FailureOf<ReturnType<typeof map>> }> | FailureResult<{ key: string; keyNotExistError: undefined }> | FailureResult<{ key: string; mapError: unknown }> | FailureResult<{ key: string; storageError: unknown }>>)
        • <Success, Failure, ResultLike>(key: string, map: ((value: unknown) => ResultLike)): PrettyType<SuccessResult<SuccessOf<ReturnType<typeof map>>> | FailureResult<{ key: string; validationError: FailureOf<ReturnType<typeof map>> }> | FailureResult<{ key: string; keyNotExistError: undefined }> | FailureResult<{ key: string; mapError: unknown }> | FailureResult<{ key: string; storageError: unknown }>>
        • Calls underlying getItem function with key argument, JSON.parses the received value and validates the result.

          Type Parameters

          • Success

          • Failure

          • ResultLike extends Result<Success, Failure>

          Parameters

          • key: string

            underlying getItem argument

          • map: ((value: unknown) => ResultLike)

            validating transform, if validation fails it it should return FailureResult and SuccessResult otherwise

              • (value: unknown): ResultLike
              • Parameters

                • value: unknown

                Returns ResultLike

          Returns PrettyType<SuccessResult<SuccessOf<ReturnType<typeof map>>> | FailureResult<{ key: string; validationError: FailureOf<ReturnType<typeof map>> }> | FailureResult<{ key: string; keyNotExistError: undefined }> | FailureResult<{ key: string; mapError: unknown }> | FailureResult<{ key: string; storageError: unknown }>>

          Success or failure result.

          • If underlying getItem function did throw an error then a failure result containing an object with key and storageError property set to thrown value will be returned.
          • If given key does not exist a failure result containing an object with key and keyNotExistError properties will be returned.
          • If validating transform did throw an error then a failure result containing an object with key and mapError property set to thrown value will be returned.
          • If validating transform did not throw an error but fail to validate the received value then a failure result containing an object with key and validationError property set to validation error will be returned.
          • If transform function succeed to validate the received value then a success result containing the transformed value will be returned.
    • removeItem: ((key: string) => { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" })
        • (key: string): { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }
        • Calls underlying removeItem function with key argument.

          Parameters

          • key: string

            underlying removeItem argument

          Returns { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }

          Success or failure result.

          • If underlying removeItem function did throw an error then a failure result containing an object with key and storageError property set to thrown value will be returned.
          • If underlying removeItem function did not throw an error then a success result containing an undefined value will be returned.
    • setItem: ((key: string, value: unknown) => { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" })
        • (key: string, value: unknown): { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }
        • Calls underlying setItem function with key and JSON.stringifyed value.

          Parameters

          • key: string

            underlying setItem first argument

          • value: unknown

            underlying setItem second argument

          Returns { success: undefined; tag: "success" } | { failure: { key: string; storageError: unknown }; tag: "failure" }

          Success or failure result.

          • If underlying setItem function did throw an error then a failure result containing an object with key and storageError property set to thrown value will be returned.
          • If underlying setItem function did not throw an error then a success result containing an undefined value will be returned.

Generated using TypeDoc