# tyfon

> typed functions over network

Latest version **0.2.10** (published 2021-02-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install tyfon
pnpm add tyfon
yarn add tyfon
bun add tyfon
```

Provides the command `tyfon`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.10 |
| Published | 2021-02-05 |
| First published | 2020-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 38 |
| Author | Eugene Ghanizadeh Khoub |
| Maintainers | lorean.victor |
| Keywords | rpc, cloud, serverless, typescript |

## Links

- npm: https://www.npmjs.com/package/tyfon
- Repository: https://github.com/loreanvictor/tyfon
- Homepage: https://loreanvictor.github.io/tyfon
- Issues: https://github.com/loreanvictor/tyfon/issues
- npm.io page: https://npm.io/package/tyfon

## Dependencies (14)

- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [rollup](https://npm.io/package/rollup.md) ^2.33.3
- [nodemon](https://npm.io/package/nodemon.md) ^2.0.6
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.4
- [ts-node](https://npm.io/package/ts-node.md) ^9.1.1
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.0
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1
- [strip-ansi](https://npm.io/package/strip-ansi.md) ^6.0.0
- [typescript](https://npm.io/package/typescript.md) ^4.0.5
- [ts-node-dev](https://npm.io/package/ts-node-dev.md) ^1.0.0
- [yargs-parser](https://npm.io/package/yargs-parser.md) ^20.2.4
- [callbag-common](https://npm.io/package/callbag-common.md) ^0.1.3
- [callbag-subject](https://npm.io/package/callbag-subject.md) ^2.1.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.10 (latest) — 2021-02-05
- 0.2.9 — 2021-01-13
- 0.2.8 — 2021-01-12
- 0.2.7 — 2021-01-12
- 0.2.6 — 2021-01-11
- 0.2.5 — 2020-11-26
- 0.2.4 — 2020-11-23
- 0.2.3 — 2020-11-23
- 0.2.2 — 2020-11-23
- 0.2.1 — 2020-11-23
- 0.2.0 — 2020-11-21
- 0.1.9 — 2020-11-20
- 0.1.8 — 2020-11-20
- 0.1.7 — 2020-11-19
- 0.1.6 — 2020-11-18
- … 14 more at https://npm.io/package/tyfon/versions

## README

<div align="center">
  <img src="/tyfon-type.svg" width="320px"/>
  <p align="center"><b>Ty</b>ped <b>F</b>unctions <b>O</b>ver <b>N</b>etwork</p>

  [![version](https://img.shields.io/npm/v/tyfon?logo=npm&style=flat-square)](https://www.npmjs.com/package/tyfon)
  [![docs](https://img.shields.io/badge/%20-docs-blue?logo=read%20the%20docs&logoColor=white&style=flat-square)](https://loreanvictor.github.io/tyfon/)

</div>

<br><br>

TyFON is a zero-config RPC for TypeScript. It automatically creates all required networking code on the server-side and generates client-side SDK using same type definitions for client-server consistency.

```ts
// server:

export async function getMessage(name: string) {
  return `Hellow ${name}!`;
}
```
```ts
// client:

import { getMessage } from '@api/my-server';

getMessage('World').then(console.log):
```

👉 [Read the docs](https://loreanvictor.github.io/tyfon).

<br><br>

# Installation

TyFON is a singular CLI tool that runs on Node, so you need Node.js installed beforehand.
```bash
npm i -g tyfon
```

<br><br>

# Usage

[Read the docs](https://loreanvictor.github.io/tyfon) for detailed usage information and
a getting-started tutorial.

<br>

## Server Side

Export your functions in `index.ts`:

```ts
export async const getMessage = name => `Hellow ${name}!`;
```

Now serve them:
```bash
tyfon serve
```

👉 Check it out on `localhost:8000/message?0="World"`.

<br><br>

## Client Side

Add the SDK on client side and use it:
```bash
tyfon i localhost:8000
```
```ts
import { getMessage } from '@api/my-server';

getMessage('World').then(console.log);
```

👉 The name `my-server` comes from `package.json` of your server code.

<br><br>

## Syncing Updates

Use `tyfon watch` while working on server and client simultaneously:
```bash
tyfon watch -c <client-path>     # --> run this on server side code
```

<br>

Or sync updates manually (in other situations):
- On server-side code, rebuild client SDK metadata and serve it again:
```bash
tyfon build                      # --> run this on server side code
```
```bash
tyfon serve                      # --> run this on server side code
```

- On client-side code, update TyFONs you are using:
```bash
tyfon i                          # --> run this on client side code
```

<br><br>

## Server Environment Variables

You can pass environment variables to `typhon serve` command using `-e` option:

```bash
typhon serve -e ENV=dev -e LOGS=verbose
```

<br><br>

## Client Environments

It is common practice for client-code to use different API URLs for different environments (i.e. development, production, staging, etc).
You can use the `--env` flag on `typhon i` command to mark the environment a TyFON should be used in:
```bash
tyfon i https://my-server.cloud --env production
tyfon i https://staging.my-server.cloud --env staging
tyfon i localhost:8000 --env dev
```

Now for building client-code in production, use the following command:
```bash
tyfon i --env production        # --> this will install all generic TyFONs and all production TyFONs
```

<br><br>

## Deploying

Run your TyFON in production mode:

```bash
tyfon serve --mode prod
```

### Docker

Build a docker image and deploy it:

```bash
tyfon build --image my-server

docker tag my-server https://my-registry.cloud/my-server
docker push my-server
```

👉 [docker](https://www.docker.com) **MUST** be installed for using this option.

<br><br>

# Conventions

TyFON leans heavily towards the _convention over configuration_ principle. It is pretty opinionated in how it wraps normal functions within
API end-points and how code should be structured, for example it picks endpoint methods based on the name of the function, or it expects
all API functions to be exported from `index.ts` from the root of the project.

👉 [Read the docs](https://loreanvictor.github.io/tyfon).

<br><br>

# CLI Commands

- [`tyfon init`](https://loreanvictor.github.io/tyfon/cli/init)
- [`tyfon build`](https://loreanvictor.github.io/tyfon/cli/build)
- [`tyfon serve`](https://loreanvictor.github.io/tyfon/cli/serve)
- [`tyfon install`](https://loreanvictor.github.io/tyfon/cli/install)
- [`tyfon uninstall`](https://loreanvictor.github.io/tyfon/cli/uninstall)
- [`tyfon help`](https://loreanvictor.github.io/tyfon/cli/help)
- [`tyfon version`](https://loreanvictor.github.io/tyfon/cli/version)

<br><br>

---
_Source: https://npm.io/package/tyfon · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
