sendscript 1.0.2 → 1.0.5

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.
@@ -0,0 +1,25 @@
1
+ name: Publish Package
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ id-token: write # Required for OIDC
10
+ contents: read
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v6
17
+
18
+ - uses: actions/setup-node@v6
19
+ with:
20
+ node-version: '24'
21
+ registry-url: 'https://registry.npmjs.org'
22
+ - run: npm ci
23
+ - run: npm run build --if-present
24
+ - run: npm test
25
+ - run: npm publish
package/CHANGELOG.md CHANGED
@@ -4,8 +4,29 @@ 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.5](https://github.com/bas080/sendscript/compare/v1.0.4...v1.0.5)
8
+
9
+ - Add publish to npm workflow [`aaaa97d`](https://github.com/bas080/sendscript/commit/aaaa97d1024d6b5ed574a2cd103035949ec8280d)
10
+
11
+ #### [v1.0.4](https://github.com/bas080/sendscript/compare/v1.0.3...v1.0.4)
12
+
13
+ > 5 April 2026
14
+
15
+ - Update tap and debug deps [`bd28139`](https://github.com/bas080/sendscript/commit/bd28139b633a04ac1b705b71c6bd24e98655d3b4)
16
+ - Give example its own package.json [`4307988`](https://github.com/bas080/sendscript/commit/4307988467d866f461f27c42a92a304bfe7617d6)
17
+ - Add cli with repl command [`d811fcb`](https://github.com/bas080/sendscript/commit/d811fcbf2d95fe8729c3782aceec6aea3bff1367)
18
+
19
+ #### [v1.0.3](https://github.com/bas080/sendscript/compare/v1.0.2...v1.0.3)
20
+
21
+ > 4 May 2025
22
+
23
+ - Make examples import module not relative file [`0a5e1c8`](https://github.com/bas080/sendscript/commit/0a5e1c8ec2527d63d1e248f63568668058de388c)
24
+ - Fix repository url in package.json [`d4f1e79`](https://github.com/bas080/sendscript/commit/d4f1e79a75daea28905c9b680b31e517526588d3)
25
+
7
26
  #### [v1.0.2](https://github.com/bas080/sendscript/compare/v1.0.1...v1.0.2)
8
27
 
28
+ > 4 May 2025
29
+
9
30
  - Improve the typescript example [`6f75ed6`](https://github.com/bas080/sendscript/commit/6f75ed6a4b4db94217fde41ae50bc6b92a2cffda)
10
31
  - Move errors to own module [`90d69a3`](https://github.com/bas080/sendscript/commit/90d69a337f92518c8dd5c2ad47dd9b1add80d0c3)
11
32
 
package/README.md CHANGED
@@ -13,6 +13,7 @@ Write JS code that you can run on servers, browsers or other clients.
13
13
  * [Module](#module)
14
14
  * [Server](#server)
15
15
  * [Client](#client)
16
+ - [Repl](#repl)
16
17
  - [Async/Await](#asyncawait)
17
18
  - [TypeScript](#typescript)
18
19
  - [Tests](#tests)
@@ -33,7 +34,12 @@ needs.
33
34
  For this example we'll use [socket.io][socket.io].
34
35
 
35
36
  ```bash
36
- npm install --no-save socket.io socket.io-client
37
+ set -e
38
+
39
+ npm link
40
+ cd ./example
41
+ npm ci
42
+ npm link sendscript
37
43
  ```
38
44
 
39
45
  > We use the `--no-save` option because it's only for demonstration purposes.
@@ -57,7 +63,7 @@ Here a socket.io server that runs SendScript programs.
57
63
  // ./example/server.socket.io.mjs
58
64
 
59
65
  import { Server } from 'socket.io'
60
- import Parse from '../parse.mjs'
66
+ import Parse from 'sendscript/parse.mjs'
61
67
  import * as math from './math.mjs'
62
68
 
63
69
  const parse = Parse(math)
@@ -87,8 +93,8 @@ Now for a client that sends a program to the server.
87
93
  // ./example/client.socket.io.mjs
88
94
 
89
95
  import socketClient from 'socket.io-client'
90
- import stringify from '../stringify.mjs'
91
- import module from '../module.mjs'
96
+ import stringify from 'sendscript/stringify.mjs'
97
+ import module from 'sendscript/module.mjs'
92
98
  import * as math from './math.mjs'
93
99
  import assert from 'node:assert'
94
100
 
@@ -136,6 +142,12 @@ pkill sendscript
136
142
  Result: 100
137
143
  ```
138
144
 
145
+ ## Repl
146
+
147
+ Sendscript ships with a barebones (no-dependencies) node-repl script. One can run it by simply typing `sendscript` in their console.
148
+
149
+ > Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for printingonly sendscript logs.
150
+
139
151
  ## Async/Await
140
152
 
141
153
  SendScript supports async/await seamlessly within a single request. This avoids the performance pitfalls of waterfall-style messaging, which can be especially slow on high-latency networks.
@@ -218,12 +230,12 @@ send(square(add(1, 2)))
218
230
  We'll also generate the docs for this module.
219
231
 
220
232
  ```bash
233
+ npm install --no-save \
234
+ typedoc \
235
+ typedoc-plugin-markdown
236
+
221
237
  typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./example/typescript/math.ts
222
238
  ```
223
- ```
224
- [info] Loaded plugin typedoc-plugin-markdown
225
- [info] markdown generated at ./example/typescript/docs
226
- ```
227
239
 
228
240
  You can see the docs [here](./example/typescript/docs/globals.md)
229
241
 
@@ -242,11 +254,11 @@ npm t -- report text-summary
242
254
  ```
243
255
  ```
244
256
 
245
- > sendscript@1.0.2 test
257
+ > sendscript@1.0.5 test
246
258
  > tap -R silent
247
259
 
248
260
 
249
- > sendscript@1.0.2 test
261
+ > sendscript@1.0.5 test
250
262
  > tap report text-summary
251
263
 
252
264
 
package/README.mz CHANGED
@@ -18,7 +18,12 @@ needs.
18
18
  For this example we'll use [socket.io][socket.io].
19
19
 
20
20
  ```bash bash > /dev/null
21
- npm install --no-save socket.io socket.io-client
21
+ set -e
22
+
23
+ npm link
24
+ cd ./example
25
+ npm ci
26
+ npm link sendscript
22
27
  ```
23
28
 
24
29
  > We use the `--no-save` option because it's only for demonstration purposes.
@@ -42,7 +47,7 @@ Here a socket.io server that runs SendScript programs.
42
47
  // ./example/server.socket.io.mjs
43
48
 
44
49
  import { Server } from 'socket.io'
45
- import Parse from '../parse.mjs'
50
+ import Parse from 'sendscript/parse.mjs'
46
51
  import * as math from './math.mjs'
47
52
 
48
53
  const parse = Parse(math)
@@ -72,8 +77,8 @@ Now for a client that sends a program to the server.
72
77
  // ./example/client.socket.io.mjs
73
78
 
74
79
  import socketClient from 'socket.io-client'
75
- import stringify from '../stringify.mjs'
76
- import module from '../module.mjs'
80
+ import stringify from 'sendscript/stringify.mjs'
81
+ import module from 'sendscript/module.mjs'
77
82
  import * as math from './math.mjs'
78
83
  import assert from 'node:assert'
79
84
 
@@ -118,6 +123,12 @@ node ./example/client.socket.io.mjs
118
123
  pkill sendscript
119
124
  ```
120
125
 
126
+ ## Repl
127
+
128
+ Sendscript ships with a barebones (no-dependencies) node-repl script. One can run it by simply typing `sendscript` in their console.
129
+
130
+ > Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for printingonly sendscript logs.
131
+
121
132
  ## Async/Await
122
133
 
123
134
  SendScript supports async/await seamlessly within a single request. This avoids the performance pitfalls of waterfall-style messaging, which can be especially slow on high-latency networks.
@@ -168,7 +179,11 @@ cat ./example/typescript/client.ts
168
179
 
169
180
  We'll also generate the docs for this module.
170
181
 
171
- ```bash bash
182
+ ```bash bash 1>&2
183
+ npm install --no-save \
184
+ typedoc \
185
+ typedoc-plugin-markdown
186
+
172
187
  typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./example/typescript/math.ts
173
188
  ```
174
189
 
package/cli.mjs ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'path'
4
+ import { pathToFileURL } from 'url'
5
+ import stringify from './stringify.mjs'
6
+ import repl from './repl.mjs'
7
+ import Parse from './parse.mjs'
8
+
9
+ const modulePath = pathToFileURL(path.resolve(process.cwd(), process.argv[2])).href
10
+ const mod = await import(modulePath)
11
+ const parse = Parse(mod)
12
+
13
+ const send = program => parse(stringify(program))
14
+
15
+ repl(send, mod)
@@ -0,0 +1,3 @@
1
+ # Sendscript Example
2
+
3
+ Showcases the use of sendscript in combination with TypeScript.
@@ -1,8 +1,8 @@
1
1
  // ./example/client.socket.io.mjs
2
2
 
3
3
  import socketClient from 'socket.io-client'
4
- import stringify from '../stringify.mjs'
5
- import module from '../module.mjs'
4
+ import stringify from 'sendscript/stringify.mjs'
5
+ import module from 'sendscript/module.mjs'
6
6
  import * as math from './math.mjs'
7
7
  import assert from 'node:assert'
8
8
 
@@ -0,0 +1,242 @@
1
+ {
2
+ "name": "sendscript-example",
3
+ "lockfileVersion": 3,
4
+ "requires": true,
5
+ "packages": {
6
+ "": {
7
+ "name": "sendscript-example",
8
+ "dependencies": {
9
+ "socket.io": "^4.8.1",
10
+ "socket.io-client": "^4.8.1"
11
+ }
12
+ },
13
+ "node_modules/@socket.io/component-emitter": {
14
+ "version": "3.1.2",
15
+ "license": "MIT"
16
+ },
17
+ "node_modules/@types/cors": {
18
+ "version": "2.8.18",
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@types/node": "*"
22
+ }
23
+ },
24
+ "node_modules/@types/node": {
25
+ "version": "22.15.17",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "undici-types": "~6.21.0"
29
+ }
30
+ },
31
+ "node_modules/accepts": {
32
+ "version": "1.3.8",
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "mime-types": "~2.1.34",
36
+ "negotiator": "0.6.3"
37
+ },
38
+ "engines": {
39
+ "node": ">= 0.6"
40
+ }
41
+ },
42
+ "node_modules/base64id": {
43
+ "version": "2.0.0",
44
+ "license": "MIT",
45
+ "engines": {
46
+ "node": "^4.5.0 || >= 5.9"
47
+ }
48
+ },
49
+ "node_modules/cookie": {
50
+ "version": "0.7.2",
51
+ "license": "MIT",
52
+ "engines": {
53
+ "node": ">= 0.6"
54
+ }
55
+ },
56
+ "node_modules/cors": {
57
+ "version": "2.8.5",
58
+ "license": "MIT",
59
+ "dependencies": {
60
+ "object-assign": "^4",
61
+ "vary": "^1"
62
+ },
63
+ "engines": {
64
+ "node": ">= 0.10"
65
+ }
66
+ },
67
+ "node_modules/debug": {
68
+ "version": "4.3.7",
69
+ "license": "MIT",
70
+ "dependencies": {
71
+ "ms": "^2.1.3"
72
+ },
73
+ "engines": {
74
+ "node": ">=6.0"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "supports-color": {
78
+ "optional": true
79
+ }
80
+ }
81
+ },
82
+ "node_modules/engine.io": {
83
+ "version": "6.6.4",
84
+ "license": "MIT",
85
+ "dependencies": {
86
+ "@types/cors": "^2.8.12",
87
+ "@types/node": ">=10.0.0",
88
+ "accepts": "~1.3.4",
89
+ "base64id": "2.0.0",
90
+ "cookie": "~0.7.2",
91
+ "cors": "~2.8.5",
92
+ "debug": "~4.3.1",
93
+ "engine.io-parser": "~5.2.1",
94
+ "ws": "~8.17.1"
95
+ },
96
+ "engines": {
97
+ "node": ">=10.2.0"
98
+ }
99
+ },
100
+ "node_modules/engine.io-client": {
101
+ "version": "6.6.3",
102
+ "license": "MIT",
103
+ "dependencies": {
104
+ "@socket.io/component-emitter": "~3.1.0",
105
+ "debug": "~4.3.1",
106
+ "engine.io-parser": "~5.2.1",
107
+ "ws": "~8.17.1",
108
+ "xmlhttprequest-ssl": "~2.1.1"
109
+ }
110
+ },
111
+ "node_modules/engine.io-parser": {
112
+ "version": "5.2.3",
113
+ "license": "MIT",
114
+ "engines": {
115
+ "node": ">=10.0.0"
116
+ }
117
+ },
118
+ "node_modules/mime-db": {
119
+ "version": "1.52.0",
120
+ "license": "MIT",
121
+ "engines": {
122
+ "node": ">= 0.6"
123
+ }
124
+ },
125
+ "node_modules/mime-types": {
126
+ "version": "2.1.35",
127
+ "license": "MIT",
128
+ "dependencies": {
129
+ "mime-db": "1.52.0"
130
+ },
131
+ "engines": {
132
+ "node": ">= 0.6"
133
+ }
134
+ },
135
+ "node_modules/ms": {
136
+ "version": "2.1.3",
137
+ "license": "MIT"
138
+ },
139
+ "node_modules/negotiator": {
140
+ "version": "0.6.3",
141
+ "license": "MIT",
142
+ "engines": {
143
+ "node": ">= 0.6"
144
+ }
145
+ },
146
+ "node_modules/object-assign": {
147
+ "version": "4.1.1",
148
+ "license": "MIT",
149
+ "engines": {
150
+ "node": ">=0.10.0"
151
+ }
152
+ },
153
+ "node_modules/socket.io": {
154
+ "version": "4.8.1",
155
+ "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.1.tgz",
156
+ "integrity": "sha512-oZ7iUCxph8WYRHHcjBEc9unw3adt5CmSNlppj/5Q4k2RIrhl8Z5yY2Xr4j9zj0+wzVZ0bxmYoGSzKJnRl6A4yg==",
157
+ "license": "MIT",
158
+ "dependencies": {
159
+ "accepts": "~1.3.4",
160
+ "base64id": "~2.0.0",
161
+ "cors": "~2.8.5",
162
+ "debug": "~4.3.2",
163
+ "engine.io": "~6.6.0",
164
+ "socket.io-adapter": "~2.5.2",
165
+ "socket.io-parser": "~4.2.4"
166
+ },
167
+ "engines": {
168
+ "node": ">=10.2.0"
169
+ }
170
+ },
171
+ "node_modules/socket.io-adapter": {
172
+ "version": "2.5.5",
173
+ "license": "MIT",
174
+ "dependencies": {
175
+ "debug": "~4.3.4",
176
+ "ws": "~8.17.1"
177
+ }
178
+ },
179
+ "node_modules/socket.io-client": {
180
+ "version": "4.8.1",
181
+ "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.8.1.tgz",
182
+ "integrity": "sha512-hJVXfu3E28NmzGk8o1sHhN3om52tRvwYeidbj7xKy2eIIse5IoKX3USlS6Tqt3BHAtflLIkCQBkzVrEEfWUyYQ==",
183
+ "license": "MIT",
184
+ "dependencies": {
185
+ "@socket.io/component-emitter": "~3.1.0",
186
+ "debug": "~4.3.2",
187
+ "engine.io-client": "~6.6.1",
188
+ "socket.io-parser": "~4.2.4"
189
+ },
190
+ "engines": {
191
+ "node": ">=10.0.0"
192
+ }
193
+ },
194
+ "node_modules/socket.io-parser": {
195
+ "version": "4.2.4",
196
+ "license": "MIT",
197
+ "dependencies": {
198
+ "@socket.io/component-emitter": "~3.1.0",
199
+ "debug": "~4.3.1"
200
+ },
201
+ "engines": {
202
+ "node": ">=10.0.0"
203
+ }
204
+ },
205
+ "node_modules/undici-types": {
206
+ "version": "6.21.0",
207
+ "license": "MIT"
208
+ },
209
+ "node_modules/vary": {
210
+ "version": "1.1.2",
211
+ "license": "MIT",
212
+ "engines": {
213
+ "node": ">= 0.8"
214
+ }
215
+ },
216
+ "node_modules/ws": {
217
+ "version": "8.17.1",
218
+ "license": "MIT",
219
+ "engines": {
220
+ "node": ">=10.0.0"
221
+ },
222
+ "peerDependencies": {
223
+ "bufferutil": "^4.0.1",
224
+ "utf-8-validate": ">=5.0.2"
225
+ },
226
+ "peerDependenciesMeta": {
227
+ "bufferutil": {
228
+ "optional": true
229
+ },
230
+ "utf-8-validate": {
231
+ "optional": true
232
+ }
233
+ }
234
+ },
235
+ "node_modules/xmlhttprequest-ssl": {
236
+ "version": "2.1.2",
237
+ "engines": {
238
+ "node": ">=0.4.0"
239
+ }
240
+ }
241
+ }
242
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "sendscript-example",
3
+ "private": true,
4
+ "type": "module",
5
+ "dependencies": {
6
+ "socket.io": "^4.8.1",
7
+ "socket.io-client": "^4.8.1"
8
+ }
9
+ }
@@ -1,7 +1,7 @@
1
1
  // ./example/server.socket.io.mjs
2
2
 
3
3
  import { Server } from 'socket.io'
4
- import Parse from '../parse.mjs'
4
+ import Parse from 'sendscript/parse.mjs'
5
5
  import * as math from './math.mjs'
6
6
 
7
7
  const parse = Parse(math)
@@ -1,207 +1,7 @@
1
- **sendscript**
1
+ **sendscript-example**
2
2
 
3
3
  ***
4
4
 
5
- # SendScript
5
+ # Sendscript Example
6
6
 
7
- Write JS code that you can run on servers, browsers or other clients.
8
-
9
- [![NPM](https://img.shields.io/npm/v/sendscript?color=blue&style=flat-square)](https://www.npmjs.com/package/sendscript)
10
- [![100% Code Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen?style=flat-square)](#tests)
11
- [![Standard Code Style](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)
12
- [![License](https://img.shields.io/npm/l/sendscript?color=brightgreen&style=flat-square)](./LICENSE.txt)
13
-
14
- <!-- toc -->
15
-
16
- SendScript leaves it up to you to choose HTTP, web-sockets or any other
17
- method of communication between servers and clients that best fits your
18
- needs.
19
-
20
- ## Socket example
21
-
22
- For this example we'll use [socket.io][socket.io].
23
-
24
- ```bash
25
- npm install --no-save socket.io socket.io-client
26
- ```
27
-
28
- > We use the `--no-save` option because it's only for demonstration purposes.
29
-
30
- ### Module
31
-
32
- We write a simple module.
33
-
34
- ```js
35
- // ./example/math.mjs
36
-
37
- export const add = (a, b) => a + b
38
- export const square = a => a * a
39
- ```
40
-
41
- ### Server
42
-
43
- Here a socket.io server that runs SendScript programs.
44
-
45
- ```js
46
- // ./example/server.socket.io.mjs
47
-
48
- import { Server } from 'socket.io'
49
- import Parse from '../parse.mjs'
50
- import * as math from './math.mjs'
51
-
52
- const parse = Parse(math)
53
- const server = new Server()
54
- const port = process.env.PORT || 3000
55
-
56
- server.on('connection', (socket) => {
57
- socket.on('message', async (program, callback) => {
58
- try {
59
- const result = parse(program)
60
- callback(null, result) // Pass null as the first argument to indicate success
61
- } catch (error) {
62
- callback(error) // Pass the error to the callback
63
- }
64
- })
65
- })
66
-
67
- server.listen(port)
68
- process.title = 'sendscript'
69
- ```
70
-
71
- ### Client
72
-
73
- Now for a client that sends a program to the server.
74
-
75
- ```js
76
- // ./example/client.socket.io.mjs
77
-
78
- import socketClient from 'socket.io-client'
79
- import stringify from '../stringify.mjs'
80
- import module from '../module.mjs'
81
- import * as math from './math.mjs'
82
- import assert from 'node:assert'
83
-
84
- const port = process.env.PORT || 3000
85
- const client = socketClient(`http://localhost:${port}`)
86
-
87
- const send = program => {
88
- return new Promise((resolve, reject) => {
89
- client.emit('message', stringify(program), (error, result) => {
90
- error
91
- ? reject(error)
92
- : resolve(result)
93
- })
94
- })
95
- }
96
-
97
- const { add, square } = module(math)
98
-
99
- // The program to be sent over the wire
100
- const program = square(add(1, add(add(2, 3), 4)))
101
-
102
- const result = await send(program)
103
-
104
- console.log('Result: ', result)
105
-
106
- assert.equal(result, 100)
107
-
108
- process.exit(0)
109
- ```
110
-
111
- Now we run this server and a client script.
112
-
113
- ```bash
114
- set -e
115
-
116
- # Run the server
117
- node ./example/server.socket.io.mjs&
118
-
119
- # Run the client example
120
- node ./example/client.socket.io.mjs
121
-
122
- pkill sendscript
123
- ```
124
- ```
125
- Result: 100
126
- ```
127
-
128
- ## Async/Await
129
-
130
- SendScript supports async/await seamlessly within a single request. This avoids the performance pitfalls of waterfall-style messaging, which can be especially slow on high-latency networks.
131
-
132
- While it's possible to chain promises manually or use utility functions, native async/await support makes your code more readable, modern, and easier to reason about — aligning SendScript with today’s JavaScript best practices.
133
-
134
- ```js
135
- const userId = 'user-123'
136
- const program = {
137
- unread: await fetchUnreadMessages(userId),
138
- emptyTrash: await emptyTrash(userId),
139
- archived: await archiveMessages(selectMessages({ old: true }))
140
- }
141
-
142
- const result = await send(program)
143
- ```
144
-
145
- This operation is done in a single round-trip. The result is an object with the defined properties and returned values.
146
-
147
- ## TypeScript
148
-
149
- There is a good use-case to write a module in TypeScript.
150
-
151
- 1. Obviously the module would have the benefits that TypeScript offers when
152
- coding.
153
- 2. You can use tools like [typedoc][typedoc] to generate docs from your types to
154
- share with consumers of your API.
155
- 3. You can use the types of the module to coerce your client to adopt the
156
- module's type.
157
-
158
- Let's say we have this module which we use on the server.
159
-
160
- ```bash
161
- cat ./example/typescript/math.ts
162
- ```
163
- ```ts
164
- export const add = (a: number, b: number) => a + b
165
- export const square = (a: number) => a * a
166
- ```
167
-
168
- 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.
169
-
170
- ```bash
171
- cat ./example/typescript/math.client.ts
172
- ```
173
- ```ts
174
- import module from 'sendscript/module.mjs'
175
- import type * as mathTypes from './math.ts'
176
-
177
- const math = module([
178
- 'add',
179
- 'square'
180
- ]) as typeof mathTypes
181
-
182
- export default math
183
- ```
184
-
185
- We now use the client version of this module.
186
-
187
- ```bash
188
- cat ./example/typescript/client.ts
189
- ```
190
- ```ts
191
- import stringify from 'sendscript/stringify.mjs'
192
-
193
- async function send<T>(program: T): Promise<T>{
194
- return (await fetch('/api', {
195
- method: 'POST',
196
- body: stringify(program)
197
- })).json()
198
- }
199
-
200
- import math from './math.client.ts'
201
-
202
- const { add, square } = math
203
-
204
- send(square(add(1, 2)))
205
- ```
206
-
207
- We'll also generate the docs for this module.
7
+ Showcases the use of sendscript in combination with TypeScript.
@@ -1,14 +1,14 @@
1
- [**sendscript**](../README.md)
1
+ [**sendscript-example**](../README.md)
2
2
 
3
3
  ***
4
4
 
5
- [sendscript](../globals.md) / add
5
+ [sendscript-example](../globals.md) / add
6
6
 
7
7
  # Function: add()
8
8
 
9
9
  > **add**(`a`, `b`): `number`
10
10
 
11
- Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/6f75ed6a4b4db94217fde41ae50bc6b92a2cffda/example/typescript/math.ts#L1)
11
+ Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/aaaa97d1024d6b5ed574a2cd103035949ec8280d/example/typescript/math.ts#L1)
12
12
 
13
13
  ## Parameters
14
14
 
@@ -1,14 +1,14 @@
1
- [**sendscript**](../README.md)
1
+ [**sendscript-example**](../README.md)
2
2
 
3
3
  ***
4
4
 
5
- [sendscript](../globals.md) / square
5
+ [sendscript-example](../globals.md) / square
6
6
 
7
7
  # Function: square()
8
8
 
9
9
  > **square**(`a`): `number`
10
10
 
11
- Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/6f75ed6a4b4db94217fde41ae50bc6b92a2cffda/example/typescript/math.ts#L2)
11
+ Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/aaaa97d1024d6b5ed574a2cd103035949ec8280d/example/typescript/math.ts#L2)
12
12
 
13
13
  ## Parameters
14
14
 
@@ -1,8 +1,8 @@
1
- [**sendscript**](README.md)
1
+ [**sendscript-example**](README.md)
2
2
 
3
3
  ***
4
4
 
5
- # sendscript
5
+ # sendscript-example
6
6
 
7
7
  ## Functions
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sendscript",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "Blur the line between server and client code.",
5
5
  "module": true,
6
6
  "main": "index.mjs",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "git@github.com:bas080/sendscript.git"
16
+ "url": "git+ssh://git@github.com/bas080/sendscript.git"
17
17
  },
18
18
  "scripts": {
19
19
  "test": "tap",
@@ -23,9 +23,9 @@
23
23
  "author": "Bas Huis",
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "tap": "^21.0.1"
26
+ "tap": "^21.6.2"
27
27
  },
28
28
  "dependencies": {
29
- "debug": "^4.3.7"
29
+ "debug": "^4.4.3"
30
30
  }
31
31
  }
package/repl.mjs ADDED
@@ -0,0 +1,15 @@
1
+ import instrument from './module.mjs'
2
+ import repl from 'node:repl'
3
+
4
+ export default async function sendscriptRepl (send, module) {
5
+ Object.assign(global, instrument(module))
6
+
7
+ async function cb (cmd, context, filename, callback) {
8
+ callback(null, await send(eval(cmd))) // eslint-disable-line no-eval
9
+ }
10
+
11
+ return repl.start({
12
+ prompt: '> ',
13
+ eval: cb
14
+ })
15
+ }
package/schema.json DELETED
@@ -1,53 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "title": "JSON S-expression Language Schema",
4
- "description": "Schema for a custom JSON S-expression language.",
5
- "definitions": {
6
- "ref": {
7
- "title": "Reference Operator",
8
- "description": "A reference to a function or identifier.",
9
- "type": "array",
10
- "minItems": 2,
11
- "maxItems": 2,
12
- "items": [
13
- { "enum": ["ref"], "title": "Operator", "description": "The operator type, representing a reference to a function or identifier." },
14
- { "type": "string", "title": "Identifier", "description": "The identifier or function name." }
15
- ]
16
- },
17
- "call": {
18
- "title": "Call Operator",
19
- "description": "A function call.",
20
- "type": "array",
21
- "minItems": 2,
22
- "maxItems": 3,
23
- "items": [
24
- { "const": "call", "title": "Operator", "description": "The operator type, representing a function call." },
25
- { "$ref": "#/definitions/ref", "title": "Reference", "description": "The reference to a function or identifier." },
26
- {
27
- "type": "array",
28
- "items": {
29
- "$ref": "#"
30
- },
31
- "title": "Arguments",
32
- "description": "The arguments passed to the function."
33
- }
34
- ]
35
- }
36
- },
37
- "oneOf": [
38
- { "$ref": "#/definitions/ref" },
39
- { "$ref": "#/definitions/call" },
40
- { "type": "number", "title": "Number", "description": "A JSON number." },
41
- { "type": "string", "title": "String", "description": "A JSON string." },
42
- { "type": "boolean", "title": "Boolean", "description": "A JSON boolean." },
43
- { "type": "null", "title": "Null", "description": "A JSON null value." },
44
- {
45
- "title": "Object",
46
- "description": "A generic JSON object with additional properties.",
47
- "type": "object",
48
- "additionalProperties": {
49
- "$ref": "#"
50
- }
51
- }
52
- ]
53
- }