sendscript 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/CONTRIBUTING.md +24 -0
- package/README.md +73 -14
- package/README.mz +64 -12
- package/example/typescript/docs/functions/add.md +1 -1
- package/example/typescript/docs/functions/square.md +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
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
|
+
|
|
7
12
|
#### [v1.0.5](https://github.com/bas080/sendscript/compare/v1.0.4...v1.0.5)
|
|
8
13
|
|
|
14
|
+
> 5 April 2026
|
|
15
|
+
|
|
9
16
|
- Add publish to npm workflow [`aaaa97d`](https://github.com/bas080/sendscript/commit/aaaa97d1024d6b5ed574a2cd103035949ec8280d)
|
|
10
17
|
|
|
11
18
|
#### [v1.0.4](https://github.com/bas080/sendscript/compare/v1.0.3...v1.0.4)
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
For the README.mz examples to work we need sendscript to be linked.
|
|
5
|
+
|
|
6
|
+
```bash bash > /dev/null
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
npm link
|
|
10
|
+
npm link sendscript
|
|
11
|
+
cd ./example
|
|
12
|
+
npm ci
|
|
13
|
+
npm link sendscript
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Generate the README from the mz file.
|
|
17
|
+
|
|
18
|
+
```bash bash
|
|
19
|
+
markatzea ./README.mz | tee ./README.md
|
|
20
|
+
|
|
21
|
+
npx markdown-toc -i README.md
|
|
22
|
+
|
|
23
|
+
git add *.md ./example
|
|
24
|
+
```
|
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Write JS code that you can run on servers, browsers or other clients.
|
|
|
9
9
|
|
|
10
10
|
<!-- toc -->
|
|
11
11
|
|
|
12
|
+
- [Introduction](#introduction)
|
|
12
13
|
- [Socket example](#socket-example)
|
|
13
14
|
* [Module](#module)
|
|
14
15
|
* [Server](#server)
|
|
@@ -25,6 +26,75 @@ Write JS code that you can run on servers, browsers or other clients.
|
|
|
25
26
|
|
|
26
27
|
<!-- tocstop -->
|
|
27
28
|
|
|
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
|
+
|
|
28
98
|
SendScript leaves it up to you to choose HTTP, web-sockets or any other
|
|
29
99
|
method of communication between servers and clients that best fits your
|
|
30
100
|
needs.
|
|
@@ -33,17 +103,6 @@ needs.
|
|
|
33
103
|
|
|
34
104
|
For this example we'll use [socket.io][socket.io].
|
|
35
105
|
|
|
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
|
-
|
|
47
106
|
### Module
|
|
48
107
|
|
|
49
108
|
We write a simple module.
|
|
@@ -234,7 +293,7 @@ npm install --no-save \
|
|
|
234
293
|
typedoc \
|
|
235
294
|
typedoc-plugin-markdown
|
|
236
295
|
|
|
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
|
|
238
297
|
```
|
|
239
298
|
|
|
240
299
|
You can see the docs [here](./example/typescript/docs/globals.md)
|
|
@@ -254,11 +313,11 @@ npm t -- report text-summary
|
|
|
254
313
|
```
|
|
255
314
|
```
|
|
256
315
|
|
|
257
|
-
> sendscript@1.0.
|
|
316
|
+
> sendscript@1.0.6 test
|
|
258
317
|
> tap -R silent
|
|
259
318
|
|
|
260
319
|
|
|
261
|
-
> sendscript@1.0.
|
|
320
|
+
> sendscript@1.0.6 test
|
|
262
321
|
> tap report text-summary
|
|
263
322
|
|
|
264
323
|
|
package/README.mz
CHANGED
|
@@ -9,6 +9,69 @@ Write JS code that you can run on servers, browsers or other clients.
|
|
|
9
9
|
|
|
10
10
|
<!-- toc -->
|
|
11
11
|
|
|
12
|
+
## Introduction
|
|
13
|
+
|
|
14
|
+
There has been interest in improving APIs by allowing aggregations in a
|
|
15
|
+
single request. Examples include
|
|
16
|
+
|
|
17
|
+
- [JSON-RPC](https://json-rpc.dev/) which allows you to do multiple requests
|
|
18
|
+
but it does not allow you to compose the return value of one endpoint to be the
|
|
19
|
+
input/arguments of another.
|
|
20
|
+
|
|
21
|
+
- [GraphQL](https://graphql.org/) is very cool but also introduces a new languages and the
|
|
22
|
+
tooling that is required to wield it.
|
|
23
|
+
|
|
24
|
+
What SendScript attempts is to allow for very expressive queries and mutations to be performed
|
|
25
|
+
that read and write like ordinary JS. That means that the queries and complete programs
|
|
26
|
+
that are sent to the server from a client can also just run on the server as is. The only
|
|
27
|
+
limitation being the serialization which by default is limited by JSON and could be extended by
|
|
28
|
+
using more advanced (de)serialization libraries.
|
|
29
|
+
|
|
30
|
+
SendScript produces an intermediate JSON representation of the program. Let's see what that looks like.
|
|
31
|
+
|
|
32
|
+
```js|json node --input-type=module | tee /tmp/sendscript.json
|
|
33
|
+
import stringify from 'sendscript/stringify.mjs'
|
|
34
|
+
import module from 'sendscript/module.mjs'
|
|
35
|
+
|
|
36
|
+
const { add } = module(['add'])
|
|
37
|
+
|
|
38
|
+
console.log(stringify(add(1,2)))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
We can then parse that JSON and it will evaluate down to a value.
|
|
42
|
+
|
|
43
|
+
```js|json node --input-type=module
|
|
44
|
+
import Parse from 'sendscript/parse.mjs'
|
|
45
|
+
|
|
46
|
+
const module = {
|
|
47
|
+
add(a, b) {
|
|
48
|
+
return a + b
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const parse = Parse(module)
|
|
53
|
+
|
|
54
|
+
const program = '["call",["ref","add"],[1,2]]'
|
|
55
|
+
|
|
56
|
+
console.log(parse(program))
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
SendScript does more than a simple function call. It supports function
|
|
60
|
+
composition and even await.
|
|
61
|
+
|
|
62
|
+
This package is nothing more than the absolute core of sendscript. It
|
|
63
|
+
includes:
|
|
64
|
+
|
|
65
|
+
- The `module` function to create stubs to write the programs.
|
|
66
|
+
- `stringify` which takes the program and returns a JSON string.
|
|
67
|
+
- `parse` which takes the `stringify` JSON string and a real module and returns the result.
|
|
68
|
+
|
|
69
|
+
The naming could use more love and there are many things to solve either in the core or around it.
|
|
70
|
+
Things like supporting more complex (de)serializers, errors and maybe mixing client functions with
|
|
71
|
+
sendscript programs. Contact me if I have piqued your interest.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
12
75
|
SendScript leaves it up to you to choose HTTP, web-sockets or any other
|
|
13
76
|
method of communication between servers and clients that best fits your
|
|
14
77
|
needs.
|
|
@@ -17,17 +80,6 @@ needs.
|
|
|
17
80
|
|
|
18
81
|
For this example we'll use [socket.io][socket.io].
|
|
19
82
|
|
|
20
|
-
```bash bash > /dev/null
|
|
21
|
-
set -e
|
|
22
|
-
|
|
23
|
-
npm link
|
|
24
|
-
cd ./example
|
|
25
|
-
npm ci
|
|
26
|
-
npm link sendscript
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
> We use the `--no-save` option because it's only for demonstration purposes.
|
|
30
|
-
|
|
31
83
|
### Module
|
|
32
84
|
|
|
33
85
|
We write a simple module.
|
|
@@ -184,7 +236,7 @@ npm install --no-save \
|
|
|
184
236
|
typedoc \
|
|
185
237
|
typedoc-plugin-markdown
|
|
186
238
|
|
|
187
|
-
typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./example/typescript/math.ts
|
|
239
|
+
npx typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./example/typescript/math.ts
|
|
188
240
|
```
|
|
189
241
|
|
|
190
242
|
You can see the docs [here](./example/typescript/docs/globals.md)
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **add**(`a`, `b`): `number`
|
|
10
10
|
|
|
11
|
-
Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/
|
|
11
|
+
Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/c1769d9a24148e63d27b0e5a7456213bec64763e/example/typescript/math.ts#L1)
|
|
12
12
|
|
|
13
13
|
## Parameters
|
|
14
14
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **square**(`a`): `number`
|
|
10
10
|
|
|
11
|
-
Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/
|
|
11
|
+
Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/c1769d9a24148e63d27b0e5a7456213bec64763e/example/typescript/math.ts#L2)
|
|
12
12
|
|
|
13
13
|
## Parameters
|
|
14
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sendscript",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Blur the line between server and client code.",
|
|
5
5
|
"module": true,
|
|
6
6
|
"main": "index.mjs",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"test": "tap",
|
|
20
|
-
"version": "npm run docs
|
|
21
|
-
"docs": "markatzea
|
|
20
|
+
"version": "npm run docs",
|
|
21
|
+
"docs": "markatzea CONTRIBUTING.md"
|
|
22
22
|
},
|
|
23
23
|
"author": "Bas Huis",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"tap": "^21.6.
|
|
26
|
+
"tap": "^21.6.3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"debug": "^4.4.3"
|