sendscript
Advanced tools
Comparing version
@@ -7,4 +7,11 @@ ### Changelog | ||
#### [v1.0.2](https://github.com/bas080/sendscript/compare/v1.0.1...v1.0.2) | ||
- Improve the typescript example [`6f75ed6`](https://github.com/bas080/sendscript/commit/6f75ed6a4b4db94217fde41ae50bc6b92a2cffda) | ||
- Move errors to own module [`90d69a3`](https://github.com/bas080/sendscript/commit/90d69a337f92518c8dd5c2ad47dd9b1add80d0c3) | ||
#### [v1.0.1](https://github.com/bas080/sendscript/compare/v1.0.0...v1.0.1) | ||
> 3 May 2025 | ||
- Add async await section to readme [`7e56024`](https://github.com/bas080/sendscript/commit/7e560246e2a7b5b34f1de0ce5eb0df62897cc454) | ||
@@ -11,0 +18,0 @@ |
{ | ||
"name": "sendscript", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Blur the line between server and client code.", | ||
@@ -5,0 +5,0 @@ "module": true, |
@@ -169,13 +169,63 @@ # SendScript | ||
Let's say we have this module which we use on the server. | ||
```bash | ||
cat ./example/typescript/math.ts | ||
``` | ||
```ts | ||
import type * as math from './example/math.ts' | ||
export const add = (a: number, b: number) => a + b | ||
export const square = (a: number) => a * a | ||
``` | ||
We want to use this module on the client. We create a client version of that module and coerce the types to match those of the server. | ||
```bash | ||
cat ./example/typescript/math.client.ts | ||
``` | ||
```ts | ||
import module from 'sendscript/module.mjs' | ||
import type * as mathTypes from './math.ts' | ||
export default module([ | ||
add, | ||
squer, | ||
]) as typeof math | ||
const math = module([ | ||
'add', | ||
'square' | ||
]) as typeof mathTypes | ||
export default math | ||
``` | ||
We now use the client version of this module. | ||
```bash | ||
cat ./example/typescript/client.ts | ||
``` | ||
```ts | ||
import stringify from 'sendscript/stringify.mjs' | ||
async function send<T>(program: T): Promise<T>{ | ||
return (await fetch('/api', { | ||
method: 'POST', | ||
body: stringify(program) | ||
})).json() | ||
} | ||
import math from './math.client.ts' | ||
const { add, square } = math | ||
send(square(add(1, 2))) | ||
``` | ||
We'll also generate the docs for this module. | ||
```bash | ||
typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./example/typescript/math.ts | ||
``` | ||
``` | ||
[96m[info][0m Loaded plugin typedoc-plugin-markdown | ||
[96m[info][0m markdown generated at ./example/typescript/docs | ||
``` | ||
You can see the docs [here](./example/typescript/docs/globals.md) | ||
> [!NOTE] | ||
@@ -196,7 +246,7 @@ > Although type coercion on the client side can improve the development | ||
> sendscript@1.0.1 test | ||
> sendscript@1.0.2 test | ||
> tap -R silent | ||
> sendscript@1.0.1 test | ||
> sendscript@1.0.2 test | ||
> tap report text-summary | ||
@@ -206,6 +256,6 @@ | ||
=============================== Coverage summary =============================== | ||
Statements : 100% ( 239/239 ) | ||
Branches : 100% ( 71/71 ) | ||
Statements : 100% ( 245/245 ) | ||
Branches : 100% ( 74/74 ) | ||
Functions : 100% ( 18/18 ) | ||
Lines : 100% ( 239/239 ) | ||
Lines : 100% ( 245/245 ) | ||
================================================================================ | ||
@@ -212,0 +262,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39671
26.42%27
35%508
3.25%302
19.84%