Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ethan-arrowood/socket

A Node.js Implementation of the Cloudflare Socket API
https://github.com/ethan-arrowood/socket

Last synced: 6 days ago
JSON representation

A Node.js Implementation of the Cloudflare Socket API

Awesome Lists containing this project

README

        

# @arrowood.dev/socket

A Node.js Implementation of `connect()`, the [TCP Socket API](https://github.com/wintercg/proposal-sockets-api) proposed within WinterCG, and implemented in [Cloudflare Workers](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/).

You can use this to provide the `connect()` API in a Node.js environment.

If you need to provide an interface similar to `net.connect()` or `tls.connect()` from Node.js, from an environment, where only the proposed Socket API is available, [`pg-cloudflare`](https://github.com/brianc/node-postgres/blob/master/packages/pg-cloudflare/README.md) provides such an interface.

## Installation

```
npm i @arrowood.dev/socket
```

## Contributing

Requirements:

- Node.js v18.x
- pnpm v8.6.12 (recommend using corepack)

The formatting, linting, and typechecking of this repo are based off of [@vercel/style-guide](https://github.com/vercel/style-guide).

### Building

This project uses [TypeScript](https://www.typescriptlang.org/) for building. This must be manually executed using:

```sh
pnpm build
```

Output will be in the `dist` folder.

### Formatting

This project uses [prettier](https://prettier.io/) for formatting. Code is formatted automatically when you commit, and you can run the formatter manually using:

```sh
pnpm format
```

All files (except those listed in [.prettierignore](./.prettierignore)) will be formatted.

Prettier is configured by [.prettierrc.js](./.prettierrc.js). It is based on [@vercel/style-guide/prettier](https://github.com/vercel/style-guide#prettier).

### Linting

This project uses [eslint](https://eslint.org/) for linting. Code is linted automatically when you commit, and you can run the linter manually using:

```sh
pnpm lint
```

All files (except those listed in [.eslintignore](./.eslintignore)) will be linted.

ESLint is configured by [.eslintrc.js](./.eslintrc.js). It is based on [@vercel/style-guide/eslint/node](https://github.com/vercel/style-guide#eslint)

### Testing

This project uses [node-tap](https://node-tap.org/) for testing. Run tests using:

```sh
pnpm test
```

Only test files matching the pattern `test/*.test.ts` will be executed.

Testing utility functions should be stored in `test/utils.ts` and be well documented.

### Type Checking

To manually type-check the repo without producing a build, use:

```sh
pnpm type-check
```

This project uses [TypeScript](https://www.typescriptlang.org/). There exists multiple TypeScript config files; each serves a different purpose.

- [tsconfig.base.json](./tsconfig.base.json)
- The base configuration, itself based on [@vercel/style-guide/typescript](https://github.com/vercel/style-guide#typescript).
- It does **not** _include_ any files as it is meant to be extended from.
- [tsconfig.json](./tsconfig.json)
- The default configuration.
- Used by various tools such as [eslint](#linting), the [`test` command](#testing), and the `type-check`` command.
- Includes all TypeScript files in the repo.
- Does **not** output anything.
- [tsconfig.build.json](./tsconfig.build.json)
- The build configuration.
- Only includes the `src` directory
- Used by the [`build` command](#building) to output JavaScript