Skip to content

Commit b979a48

Browse files
committed
1.0.6
1 parent c1769d9 commit b979a48

6 files changed

Lines changed: 85 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [v1.0.6](https://github.com/bas080/sendscript/compare/v1.0.5...v1.0.6)
8+
9+
- Update tap to 21.6.3 [`c1769d9`](https://github.com/bas080/sendscript/commit/c1769d9a24148e63d27b0e5a7456213bec64763e)
10+
- Add introduction to readme [`a21a494`](https://github.com/bas080/sendscript/commit/a21a494616d5ad8c99f9a2904ef529ea85104a99)
11+
712
#### [v1.0.5](https://github.com/bas080/sendscript/compare/v1.0.4...v1.0.5)
813

14+
> 5 April 2026
15+
916
- Add publish to npm workflow [`aaaa97d`](https://github.com/bas080/sendscript/commit/aaaa97d1024d6b5ed574a2cd103035949ec8280d)
1017

1118
#### [v1.0.4](https://github.com/bas080/sendscript/compare/v1.0.3...v1.0.4)

README.md

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Write JS code that you can run on servers, browsers or other clients.
99

1010
<!-- toc -->
1111

12+
- [Introduction](#introduction)
1213
- [Socket example](#socket-example)
1314
* [Module](#module)
1415
* [Server](#server)
@@ -25,6 +26,75 @@ Write JS code that you can run on servers, browsers or other clients.
2526

2627
<!-- tocstop -->
2728

29+
## Introduction
30+
31+
There has been interest in improving APIs by allowing aggregations in a
32+
single request. Examples include
33+
34+
- [JSON-RPC](https://json-rpc.dev/) which allows you to do multiple requests
35+
but it does not allow you to compose the return value of one endpoint to be the
36+
input/arguments of another.
37+
38+
- [GraphQL](https://graphql.org/) is very cool but also introduces a new languages and the
39+
tooling that is required to wield it.
40+
41+
What SendScript attempts is to allow for very expressive queries and mutations to be performed
42+
that read and write like ordinary JS. That means that the queries and complete programs
43+
that are sent to the server from a client can also just run on the server as is. The only
44+
limitation being the serialization which by default is limited by JSON and could be extended by
45+
using more advanced (de)serialization libraries.
46+
47+
SendScript produces an intermediate JSON representation of the program. Let's see what that looks like.
48+
49+
```js
50+
import stringify from 'sendscript/stringify.mjs'
51+
import module from 'sendscript/module.mjs'
52+
53+
const { add } = module(['add'])
54+
55+
console.log(stringify(add(1,2)))
56+
```
57+
```json
58+
["call",["ref","add"],[1,2]]
59+
```
60+
61+
We can then parse that JSON and it will evaluate down to a value.
62+
63+
```js
64+
import Parse from 'sendscript/parse.mjs'
65+
66+
const module = {
67+
add(a, b) {
68+
return a + b
69+
}
70+
}
71+
72+
const parse = Parse(module)
73+
74+
const program = '["call",["ref","add"],[1,2]]'
75+
76+
console.log(parse(program))
77+
```
78+
```json
79+
3
80+
```
81+
82+
SendScript does more than a simple function call. It supports function
83+
composition and even await.
84+
85+
This package is nothing more than the absolute core of sendscript. It
86+
includes:
87+
88+
- The `module` function to create stubs to write the programs.
89+
- `stringify` which takes the program and returns a JSON string.
90+
- `parse` which takes the `stringify` JSON string and a real module and returns the result.
91+
92+
The naming could use more love and there are many things to solve either in the core or around it.
93+
Things like supporting more complex (de)serializers, errors and maybe mixing client functions with
94+
sendscript programs. Contact me if I have piqued your interest.
95+
96+
---
97+
2898
SendScript leaves it up to you to choose HTTP, web-sockets or any other
2999
method of communication between servers and clients that best fits your
30100
needs.
@@ -33,17 +103,6 @@ needs.
33103

34104
For this example we'll use [socket.io][socket.io].
35105

36-
```bash
37-
set -e
38-
39-
npm link
40-
cd ./example
41-
npm ci
42-
npm link sendscript
43-
```
44-
45-
> We use the `--no-save` option because it's only for demonstration purposes.
46-
47106
### Module
48107

49108
We write a simple module.
@@ -234,7 +293,7 @@ npm install --no-save \
234293
typedoc \
235294
typedoc-plugin-markdown
236295

237-
typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./example/typescript/math.ts
296+
npx typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./example/typescript/math.ts
238297
```
239298

240299
You can see the docs [here](./example/typescript/docs/globals.md)
@@ -254,11 +313,11 @@ npm t -- report text-summary
254313
```
255314
```
256315
257-
> sendscript@1.0.5 test
316+
> sendscript@1.0.6 test
258317
> tap -R silent
259318
260319
261-
> sendscript@1.0.5 test
320+
> sendscript@1.0.6 test
262321
> tap report text-summary
263322
264323

example/typescript/docs/functions/add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **add**(`a`, `b`): `number`
1010
11-
Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/aaaa97d1024d6b5ed574a2cd103035949ec8280d/example/typescript/math.ts#L1)
11+
Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/c1769d9a24148e63d27b0e5a7456213bec64763e/example/typescript/math.ts#L1)
1212

1313
## Parameters
1414

example/typescript/docs/functions/square.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> **square**(`a`): `number`
1010
11-
Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/aaaa97d1024d6b5ed574a2cd103035949ec8280d/example/typescript/math.ts#L2)
11+
Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/c1769d9a24148e63d27b0e5a7456213bec64763e/example/typescript/math.ts#L2)
1212

1313
## Parameters
1414

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sendscript",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Blur the line between server and client code.",
55
"module": true,
66
"main": "index.mjs",

0 commit comments

Comments
 (0)