Skip to content

Commit 20ca0f9

Browse files
committed
2.3.2
1 parent 45659c5 commit 20ca0f9

8 files changed

Lines changed: 93 additions & 93 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ 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+
#### [v2.3.2](https://github.com/bas080/sendscript/compare/v2.3.1...v2.3.2)
8+
9+
- Format the README.mz file [`df43dbb`](https://github.com/bas080/sendscript/commit/df43dbb8b790cfc612536f49571f9fe4aad03837)
10+
- Move some commands from README to CONTRIBUTING [`45659c5`](https://github.com/bas080/sendscript/commit/45659c51354ac3bbe3bed5ef3826785d8a1a4a32)
11+
- Add format markdown check in contributing md [`e68d4d6`](https://github.com/bas080/sendscript/commit/e68d4d6aea26a7a54c2f933ad98a8e363d7f3357)
12+
713
#### [v2.3.1](https://github.com/bas080/sendscript/compare/v2.3.0...v2.3.1)
814

15+
> 14 April 2026
16+
917
- Update typedoc dev dep to 0.28.19 [`69e8cc4`](https://github.com/bas080/sendscript/commit/69e8cc48251af650c02faf3214ff0f9c2b61dbc9)
1018

1119
#### [v2.3.0](https://github.com/bas080/sendscript/compare/v2.2.0...v2.3.0)

README.md

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@ Write JS code that you can run on servers, browsers or other clients.
2626
- [Leaf Serializer](#leaf-serializer)
2727
* [Example with superjson](#example-with-superjson)
2828
- [Tests](#tests)
29-
- [Formatting](#formatting)
3029
- [Changelog](#changelog)
31-
- [Dependencies](#dependencies)
3230
- [License](#license)
3331
- [Roadmap](#roadmap)
3432

3533
<!-- tocstop -->
3634

3735
## Introduction
3836

39-
There has been interest in improving APIs by allowing aggregations in a
40-
single request. Examples include
37+
There has been interest in improving APIs by allowing aggregations in a single
38+
request. Examples include
4139

42-
- [JSON-RPC](https://json-rpc.dev/) which allows you to do multiple requests
43-
but it does not allow you to compose the return value of one endpoint to be the
40+
- [JSON-RPC](https://json-rpc.dev/) which allows you to do multiple requests but
41+
it does not allow you to compose the return value of one endpoint to be the
4442
input/arguments of another.
4543

46-
- [GraphQL](https://graphql.org/) is very cool but also introduces a new languages and the
47-
tooling that is required to wield it.
44+
- [GraphQL](https://graphql.org/) is very cool but also introduces a new
45+
languages and the tooling that is required to wield it.
4846

49-
What SendScript attempts is to allow for very expressive queries and mutations to be performed
50-
that read and write like ordinary JS. That means that the queries and complete programs
51-
that are sent to the server from a client can also just run on the server as is. The only
52-
limitation being the serialization which by default is limited by JSON and could be extended by
53-
using more advanced (de)serialization libraries.
47+
What SendScript attempts is to allow for very expressive queries and mutations
48+
to be performed that read and write like ordinary JS. That means that the
49+
queries and complete programs that are sent to the server from a client can also
50+
just run on the server as is. The only limitation being the serialization which
51+
by default is limited by JSON and could be extended by using more advanced
52+
(de)serialization libraries.
5453

55-
SendScript produces an intermediate JSON representation of the program. Let's see what that looks like.
54+
SendScript produces an intermediate JSON representation of the program. Let's
55+
see what that looks like.
5656

5757
```js
5858
import Stringify from 'sendscript/stringify.mjs'
@@ -91,22 +91,22 @@ console.log(parse(program))
9191
SendScript does more than a simple function call. It supports function
9292
composition and even await.
9393

94-
This package is nothing more than the absolute core of sendscript. It
95-
includes:
94+
This package is nothing more than the absolute core of sendscript. It includes:
9695

9796
- The `references` function to create stubs to write the programs.
9897
- `stringify` which takes the program and returns a JSON string.
99-
- `parse` which takes the `stringify` JSON string and a real module and returns the result.
98+
- `parse` which takes the `stringify` JSON string and a real module and returns
99+
the result.
100100

101-
The naming could use more love and there are many things to solve either in the core or around it.
102-
Things like supporting more complex (de)serializers, errors and maybe mixing client functions with
103-
sendscript programs. Contact me if I have piqued your interest.
101+
The naming could use more love and there are many things to solve either in the
102+
core or around it. Things like supporting more complex (de)serializers, errors
103+
and maybe mixing client functions with sendscript programs. Contact me if I have
104+
piqued your interest.
104105

105106
---
106107

107-
SendScript leaves it up to you to choose HTTP, web-sockets or any other
108-
method of communication between servers and clients that best fits your
109-
needs.
108+
SendScript leaves it up to you to choose HTTP, web-sockets or any other method
109+
of communication between servers and clients that best fits your needs.
110110

111111
## Socket example
112112

@@ -120,7 +120,7 @@ We write a simple module.
120120
// ./example/math.mjs
121121

122122
export const add = (a, b) => a + b
123-
export const square = a => a * a
123+
export const square = (a) => a * a
124124
```
125125

126126
### Server
@@ -172,12 +172,10 @@ const stringify = Stringify()
172172
const port = process.env.PORT || 3000
173173
const client = socketClient(`http://localhost:${port}`)
174174

175-
const send = program => {
175+
const send = (program) => {
176176
return new Promise((resolve, reject) => {
177177
client.emit('message', stringify(program), (error, result) => {
178-
error
179-
? reject(error)
180-
: resolve(result)
178+
error ? reject(error) : resolve(result)
181179
})
182180
})
183181
}
@@ -213,9 +211,11 @@ Result: 100
213211

214212
## Repl
215213

216-
Sendscript ships with a barebones (no-dependencies) node-repl script. One can run it by simply typing `sendscript` in their console.
214+
Sendscript ships with a barebones (no-dependencies) node-repl script. One can
215+
run it by simply typing `sendscript` in their console.
217216

218-
> Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for printingonly sendscript logs.
217+
> Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for
218+
> printingonly sendscript logs.
219219
220220
## Promises
221221

@@ -227,27 +227,33 @@ Supported since vs `v2.3`.
227227
const getOrCreatePost = send(createPost(title).catch(createPost(title)))
228228
```
229229

230-
You will likely need to define better helpers that makes it safer to handle rejections and work with promises. It is however sensible to have
231-
this basic behavior for the sendscript DSL and parser.
230+
You will likely need to define better helpers that makes it safer to handle
231+
rejections and work with promises. It is however sensible to have this basic
232+
behavior for the sendscript DSL and parser.
232233

233234
### await
234235

235-
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.
236+
SendScript supports async/await seamlessly within a single request. This avoids
237+
the performance pitfalls of waterfall-style messaging, which can be especially
238+
slow on high-latency networks.
236239

237-
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.
240+
While it's possible to chain promises manually or use utility functions, native
241+
async/await support makes your code more readable, modern, and easier to reason
242+
about — aligning SendScript with today’s JavaScript best practices.
238243

239244
```js
240245
const userId = 'user-123'
241246
const program = {
242247
unread: await fetchUnreadMessages(userId),
243248
emptyTrash: await emptyTrash(userId),
244-
archived: await archiveMessages(selectMessages({ old: true }))
249+
archived: await archiveMessages(selectMessages({ old: true })),
245250
}
246251

247252
const result = await send(program)
248253
```
249254

250-
This operation is done in a single round-trip. The result is an object with the defined properties and returned values.
255+
This operation is done in a single round-trip. The result is an object with the
256+
defined properties and returned values.
251257

252258
## TypeScript
253259

@@ -300,15 +306,16 @@ npx typedoc --plugin typedoc-plugin-markdown --out ./example/typescript/docs ./e
300306

301307
You can see the docs [here](./example/typescript/docs/globals.md)
302308

303-
> [!NOTE]
304-
> Although type coercion on the client side can improve the development
305-
> experience, it does not represent the actual type.
306-
> Values are subject to serialization and deserialization.
307-
309+
> [!NOTE] Although type coercion on the client side can improve the development
310+
> experience, it does not represent the actual type. Values are subject to
311+
> serialization and deserialization.
308312
309313
## Schema and Nested Modules
310314

311-
Sendscript allows you to define your API as a **nested object of functions**, making it easy to organize your DSL into modules and submodules. Each function is instrumented so that when serialized, it produces a structured reference that can be safely sent and executed elsewhere.
315+
Sendscript allows you to define your API as a **nested object of functions**,
316+
making it easy to organize your DSL into modules and submodules. Each function
317+
is instrumented so that when serialized, it produces a structured reference that
318+
can be safely sent and executed elsewhere.
312319

313320
### Defining a Nested Module
314321

@@ -340,25 +347,21 @@ Functions are referenced via their **path in the module tree**:
340347
```js
341348
const { math, vector } = references(schema)
342349

343-
math.add(
344-
1,
345-
vector.length(
346-
vector.multiply([1,2], 3)
347-
)
348-
)
350+
math.add(1, vector.length(vector.multiply([1, 2], 3)))
349351
```
350352

351353
## Validation (using Zod)
352354

353-
SendScript focuses on program serialization and execution. For runtime input validation, you can use [Zod](https://zod.dev).
355+
SendScript focuses on program serialization and execution. For runtime input
356+
validation, you can use [Zod](https://zod.dev).
354357

355358
### Validating structured input
356359

357360
```js
358361
const userSchema = z.object({
359362
id: z.string().uuid(),
360363
name: z.string(),
361-
roles: z.array(z.string())
364+
roles: z.array(z.string()),
362365
})
363366

364367
export function createUser(user) {
@@ -376,13 +379,19 @@ export function createUser(user) {
376379

377380
## Leaf Serializer
378381

379-
By default, SendScript uses JSON for serialization, which limits support to primitives and plain objects/arrays. To support richer JavaScript types like `Date`, `RegExp`, `BigInt`, `Map`, `Set`, and `undefined`, you can provide custom serialization functions.
382+
By default, SendScript uses JSON for serialization, which limits support to
383+
primitives and plain objects/arrays. To support richer JavaScript types like
384+
`Date`, `RegExp`, `BigInt`, `Map`, `Set`, and `undefined`, you can provide
385+
custom serialization functions.
380386

381-
The `stringify` function accepts an optional `leafSerializer` parameter, and `parse` accepts an optional `leafDeserializer` parameter. These functions control how non-SendScript values (leaves) are encoded and decoded.
387+
The `stringify` function accepts an optional `leafSerializer` parameter, and
388+
`parse` accepts an optional `leafDeserializer` parameter. These functions
389+
control how non-SendScript values (leaves) are encoded and decoded.
382390

383391
### Example with superjson
384392

385-
Here's how to use [superjson](https://github.com/blitz-js/superjson) to support extended types:
393+
Here's how to use [superjson](https://github.com/blitz-js/superjson) to support
394+
extended types:
386395

387396
```js
388397
import SuperJSON from 'superjson'
@@ -412,7 +421,10 @@ const program = {
412421
pattern: /foo/gi,
413422
count: BigInt('9007199254740992'),
414423
items: new Set([1, 2, 3]),
415-
mapping: new Map([['a', 1], ['b', 2]])
424+
mapping: new Map([
425+
['a', 1],
426+
['b', 2],
427+
]),
416428
}
417429

418430
// Serialize with custom leaf serializer
@@ -422,8 +434,8 @@ const json = stringify(processData(program))
422434
const env = {
423435
processData: (data) => ({
424436
success: true,
425-
received: data
426-
})
437+
received: data,
438+
}),
427439
}
428440

429441
// Parse with custom leaf deserializer
@@ -432,7 +444,8 @@ const parse = Parse(schema, env, leadDeserializer)
432444
const result = parse(json)
433445
```
434446

435-
The leaf wrapper format is `['leaf', serializedPayload]`, making it unambiguous and safe from colliding with SendScript operators.
447+
The leaf wrapper format is `['leaf', serializedPayload]`, making it unambiguous
448+
and safe from colliding with SendScript operators.
436449

437450
## Tests
438451

@@ -444,11 +457,11 @@ npm t -- report text-summary
444457
```
445458
```
446459
447-
> sendscript@2.3.1 test
460+
> sendscript@2.3.2 test
448461
> tap -R silent
449462
450463
451-
> sendscript@2.3.1 test
464+
> sendscript@2.3.2 test
452465
> tap report text-summary
453466
454467
@@ -460,14 +473,6 @@ Lines : 100% ( 372/372 )
460473
================================================================================
461474
```
462475

463-
## Formatting
464-
465-
Standard because no config.
466-
467-
```bash
468-
npx standard
469-
```
470-
471476
## Changelog
472477

473478
The [changelog][changelog] is generated using the useful
@@ -477,17 +482,6 @@ The [changelog][changelog] is generated using the useful
477482
npx auto-changelog -p
478483
```
479484

480-
## Dependencies
481-
482-
Check if packages are up to date on release.
483-
484-
```bash
485-
npm outdated && echo 'No outdated packages found'
486-
```
487-
```
488-
No outdated packages found
489-
```
490-
491485
## License
492486

493487
See the [LICENSE.txt][license] file for details.
@@ -496,8 +490,8 @@ See the [LICENSE.txt][license] file for details.
496490

497491
- [ ] Support for simple lambdas to compose functions more easily.
498492

499-
[license]:./LICENSE.txt
500-
[socket.io]:https://socket.io/
501-
[changelog]:./CHANGELOG.md
502-
[auto-changelog]:https://www.npmjs.com/package/auto-changelog
503-
[typedoc]:https://github.com/TypeStrong/typedoc
493+
[license]: ./LICENSE.txt
494+
[socket.io]: https://socket.io/
495+
[changelog]: ./CHANGELOG.md
496+
[auto-changelog]: https://www.npmjs.com/package/auto-changelog
497+
[typedoc]: https://github.com/TypeStrong/typedoc

example/client.socket.io.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ const stringify = Stringify()
1111
const port = process.env.PORT || 3000
1212
const client = socketClient(`http://localhost:${port}`)
1313

14-
const send = program => {
14+
const send = (program) => {
1515
return new Promise((resolve, reject) => {
1616
client.emit('message', stringify(program), (error, result) => {
17-
error
18-
? reject(error)
19-
: resolve(result)
17+
error ? reject(error) : resolve(result)
2018
})
2119
})
2220
}

example/math.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// ./example/math.mjs
22

33
export const add = (a, b) => a + b
4-
export const square = a => a * a
4+
export const square = (a) => a * a

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/69e8cc48251af650c02faf3214ff0f9c2b61dbc9/example/typescript/math.ts#L1)
11+
Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/45659c51354ac3bbe3bed5ef3826785d8a1a4a32/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/69e8cc48251af650c02faf3214ff0f9c2b61dbc9/example/typescript/math.ts#L2)
11+
Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/45659c51354ac3bbe3bed5ef3826785d8a1a4a32/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.

0 commit comments

Comments
 (0)