@seda-protocol/utils

1.3.0 • Public • Published

seda-utils

This library contains utility functions that are used throughout SEDA Typescript projects. It's part of the explorer monorepo as this tends to use most of the code which makes testing it a little easier.

Using the library

There are two main entrypoints to this library:

@seda-protocol/utils

The @seda-protocol/utils entrypoint contains the main library code and types. You can import it into the application code directly and make use of the provided functions.

Example:

import { tryAsync } from "@seda-protocol/utils";

const result = await tryAsync(async () => {
	const response = await fetch("https://api.seda.xyz/v1/health");
	return response.json();
});

if (result.isErr) {
	console.error(result.error);
	return;
}

// Safe to access the value
const data = result.value;

@seda-protocol/utils/testing

The @seda-protocol/utils/testing entrypoint contains custom matchers which can be used in tests. Most likely you will want to create a setup.ts file which will import this library and pass that file to Bun's test runner with the --preload flag.

Example:

// setup.ts
import "@seda-protocol/utils/testing";
bun test --preload=./setup.ts

In addition to the matchers this entrypoint also exports other utilities which might be useful in tests.

Example:

import { unwrapResult } from "@seda-protocol/utils/testing";

const result = doCoolThingWhichMightFail();
// Directly access the value, will fail if the result is an error
const value = unwrapResult(result);

Developing

Assumptions

As we target Bun as the runtime the library directly exposes the TypeScript files and doesn't any build/transpilation step.

Dependencies

This library should list dependencies as peerDependencies. This allows consuming projects to have more control over the dependency versions.

Readme

Keywords

none

Package Sidebar

Install

npm i @seda-protocol/utils

Weekly Downloads

8

Version

1.3.0

License

none

Unpacked Size

17.4 kB

Total Files

12

Last publish

Collaborators

  • mariocao
  • thomasvdam
  • franklin-waller