sendscript 2.4.0 → 2.4.1

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 CHANGED
@@ -4,8 +4,16 @@ 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
+ #### [v2.4.1](https://github.com/bas080/sendscript/compare/v2.4.0...v2.4.1)
8
+
9
+ - Update tap and typedoc version [`3f10410`](https://github.com/bas080/sendscript/commit/3f1041020e00331ff30ffb5f972738dbaf7a50f3)
10
+ - Update tap to 21.7.1 [`d1b5bbd`](https://github.com/bas080/sendscript/commit/d1b5bbd4cb7012e6606973d3d23d08df56cadca2)
11
+ - Document limitations of sendscript [`f577499`](https://github.com/bas080/sendscript/commit/f577499279b85e04ea589a3bcb1866d145216f00)
12
+
7
13
  #### [v2.4.0](https://github.com/bas080/sendscript/compare/v2.3.9...v2.4.0)
8
14
 
15
+ > 16 April 2026
16
+
9
17
  - Update tap to 4.5.4 [`5249a85`](https://github.com/bas080/sendscript/commit/5249a85a08b10485f0d64058fd2c8bcaae84edda)
10
18
  - Add fn and args support [`6110654`](https://github.com/bas080/sendscript/commit/6110654fa039d17cd9ba0e15f749756b615b5d09)
11
19
  - Move transport agnostic section to socket example [`3a92257`](https://github.com/bas080/sendscript/commit/3a9225787df16a0fd83293bfa14d91b74a46d070)
package/CONTRIBUTING.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Contributing
2
2
 
3
+ The pre-push git hook.
4
+
5
+ ```bash cat - > .git/hooks/pre-push
6
+ #!/usr/bin/env bash
7
+
8
+ set -xeuo pipefail
9
+
10
+ npm t
11
+ npx standard
12
+ npx prettier -c --parser markdown *.mz
13
+ ```
14
+
3
15
  For the README.mz examples to work we need sendscript to be linked.
4
16
 
5
17
  ```bash bash > /dev/null
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SendScript
2
2
 
3
- Write JS code that you can run on servers, browsers or other clients.
3
+ RPC and no-build with composable function calls in a single payload.
4
4
 
5
5
  [![NPM](https://img.shields.io/npm/v/sendscript?color=blue\&style=flat-square)](https://www.npmjs.com/package/sendscript)
6
6
  [![100% Code Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen?style=flat-square)](#tests)
@@ -25,10 +25,12 @@ Write JS code that you can run on servers, browsers or other clients.
25
25
  * [Server](#server)
26
26
  * [Client](#client)
27
27
  - [Repl](#repl)
28
- - [Functions](#functions)
29
28
  - [Promises](#promises)
30
29
  * [.then / .catch](#then--catch)
31
30
  * [await](#await)
31
+ - [Promises](#promises-1)
32
+ * [.then / .catch](#then--catch-1)
33
+ * [await](#await-1)
32
34
  - [TypeScript](#typescript)
33
35
  - [Schema and Nested Modules](#schema-and-nested-modules)
34
36
  * [Defining a Nested Module](#defining-a-nested-module)
@@ -36,6 +38,12 @@ Write JS code that you can run on servers, browsers or other clients.
36
38
  * [Validating structured input](#validating-structured-input)
37
39
  - [Leaf Serializer](#leaf-serializer)
38
40
  * [Example with superjson](#example-with-superjson)
41
+ - [Limitations](#limitations)
42
+ * [Chaining APIs](#chaining-apis)
43
+ * [Callbacks](#callbacks)
44
+ * [Error handling](#error-handling)
45
+ - [Tests](#tests)
46
+ - [Formatting](#formatting)
39
47
  - [Changelog](#changelog)
40
48
  - [License](#license)
41
49
  - [Issues](#issues)
@@ -121,7 +129,7 @@ piqued your interest.
121
129
 
122
130
  ### defaultLeafParse
123
131
 
124
- [parse.mjs:49-49](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/parse.mjs#L49-L49 "Source code on GitHub")
132
+ [parse.mjs:49-49](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/parse.mjs#L49-L49 "Source code on GitHub")
125
133
 
126
134
  Default deserializer for leaf nodes.
127
135
 
@@ -133,7 +141,7 @@ Returns **any** 
133
141
 
134
142
  ### Parse
135
143
 
136
- [parse.mjs:68-215](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/parse.mjs#L68-L215 "Source code on GitHub")
144
+ [parse.mjs:68-215](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/parse.mjs#L68-L215 "Source code on GitHub")
137
145
 
138
146
  #### Parameters
139
147
 
@@ -145,7 +153,7 @@ Returns **[parse](#parse)** 
145
153
 
146
154
  ### parse
147
155
 
148
- [parse.mjs:78-214](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/parse.mjs#L78-L214 "Source code on GitHub")
156
+ [parse.mjs:78-214](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/parse.mjs#L78-L214 "Source code on GitHub")
149
157
 
150
158
  Parses and executes a serialized program.
151
159
 
@@ -157,7 +165,7 @@ Returns **(any | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Ref
157
165
 
158
166
  ### References
159
167
 
160
- [references.mjs:109-127](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/references.mjs#L109-L127 "Source code on GitHub")
168
+ [references.mjs:109-127](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/references.mjs#L109-L127 "Source code on GitHub")
161
169
 
162
170
  Builds a nested API structure from a schema definition.
163
171
 
@@ -174,7 +182,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
174
182
 
175
183
  ### SchemaNode
176
184
 
177
- [schema.mjs:1-19](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/schema.mjs#L1-L6 "Source code on GitHub")
185
+ [schema.mjs:1-19](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/schema.mjs#L1-L6 "Source code on GitHub")
178
186
 
179
187
  A single schema node.
180
188
 
@@ -182,7 +190,7 @@ Type: ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Glob
182
190
 
183
191
  ### Schema
184
192
 
185
- [schema.mjs:1-19](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/schema.mjs#L8-L18 "Source code on GitHub")
193
+ [schema.mjs:1-19](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/schema.mjs#L8-L18 "Source code on GitHub")
186
194
 
187
195
  A schema defines the structure of the runtime API tree.
188
196
 
@@ -195,7 +203,7 @@ Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global
195
203
 
196
204
  ### defaultLeafStringify
197
205
 
198
- [stringify.mjs:37-47](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/stringify.mjs#L37-L47 "Source code on GitHub")
206
+ [stringify.mjs:37-47](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/stringify.mjs#L37-L47 "Source code on GitHub")
199
207
 
200
208
  Default strict serializer for leaf values.
201
209
 
@@ -209,7 +217,7 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
209
217
 
210
218
  ### Stringify
211
219
 
212
- [stringify.mjs:56-157](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/stringify.mjs#L56-L157 "Source code on GitHub")
220
+ [stringify.mjs:56-157](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/stringify.mjs#L56-L157 "Source code on GitHub")
213
221
 
214
222
  Creates a stringify function for SendScript AST structures.
215
223
 
@@ -221,7 +229,7 @@ Returns **[stringify](#stringify)** 
221
229
 
222
230
  ### stringify
223
231
 
224
- [stringify.mjs:64-156](https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/stringify.mjs#L64-L156 "Source code on GitHub")
232
+ [stringify.mjs:64-156](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/stringify.mjs#L64-L156 "Source code on GitHub")
225
233
 
226
234
  Serializes a program into a JSON string representation.
227
235
 
@@ -336,13 +344,27 @@ pkill sendscript
336
344
 
337
345
  ## Repl
338
346
 
339
- Sendscript ships with a barebones (no-dependencies) node-repl script. One can
347
+ Sendscript ships with a bare-bones (no-dependencies) node-repl script. One can
340
348
  run it by simply typing `sendscript` in their console.
341
349
 
342
- > Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for
343
- > printingonly sendscript logs.
350
+ > Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for printing
351
+ > only sendscript logs.
344
352
 
345
- ## Functions
353
+ ## Promises
354
+
355
+ ### .then / .catch
356
+
357
+ Supported since vs `v2.3`.
358
+
359
+ ```js
360
+ const getOrCreatePost = send(createPost(title).catch(createPost(title)))
361
+ ```
362
+
363
+ You will likely need to define better helpers that makes it safer to handle
364
+ rejections and work with promises. It is however sensible to have this basic
365
+ behavior for the sendscript DSL and parser.
366
+
367
+ ### await
346
368
 
347
369
  SendScript as of `v2.4` supports functions to do basic templating. It does not
348
370
  support async functions and will throw an error when you define one.
@@ -584,7 +606,7 @@ const env = {
584
606
  }
585
607
 
586
608
  // Parse with custom leaf deserializer
587
- const parse = Parse(schema, env, leadDeserializer)
609
+ const parse = Parse(schema, env, leafDeserializer)
588
610
 
589
611
  const result = parse(json)
590
612
  ```
@@ -592,6 +614,93 @@ const result = parse(json)
592
614
  The leaf wrapper format is `['leaf', serializedPayload]`, making it unambiguous
593
615
  and safe from colliding with SendScript operators.
594
616
 
617
+ ## Limitations
618
+
619
+ The stubs the `references` function returns are limited in the way they can be
620
+ used. This has to do with the fact that they are to be serialized.
621
+
622
+ ### Chaining APIs
623
+
624
+ Currently you cannot do chaining APIs. `lib().doThis().doThat()`. It likely is
625
+ possible to implement but will require more extensive schemas and obviously more
626
+ code to create the AST.
627
+
628
+ ### Callbacks
629
+
630
+ Although it is possible to mix client and server functions, it works very
631
+ different to ordinary functions. Client functions can be used but should be seen
632
+ as a templating tool to make sendscript programs; just like one would use
633
+ JavaScript with react templates. `items.map(deleteItem)` would return an array
634
+ of sendscript function calls which can be given to sendscript's parse.
635
+
636
+ Client functions cannot be called by sendscript functions (as of yet) since we
637
+ cannot serialize client functions. No work has been done to have the server send
638
+ back intermediate values to perform client function calls or by performing
639
+ smaller sendscript program payloads that are passed to the client. Very
640
+ interesting stuff to look into. You can achieve this now but it looks less clean
641
+ because you have to do `send` calls which is a bit manual.
642
+
643
+ ```js
644
+ await send(updateUser(id, merge(await send(getUser(id)), { ...newValues })))
645
+ ```
646
+
647
+ It might be interesting to allow configuration to create references that will
648
+ trigger a send whenever await is called. That would remove the ability to create
649
+ a single payload whenever using await. You can then write the above in the
650
+ following manner.
651
+
652
+ ```js
653
+ await updateUser(id, merge(await getUser(id), { ...newValues }))
654
+ ```
655
+
656
+ Possible footgun is that updateUser is only performed when awaited (.then is
657
+ called). This lazy behavior can trip users. This footgun could be resolved by
658
+ checking if any outstanding work exists at the end of a step or the beginning of
659
+ a new step.
660
+
661
+ ### Error handling
662
+
663
+ Sendscript does not have builtin tools to handle errors. You can write your own
664
+ utilities for that or use things like \[Ramda's tryCatch]\[tryCatch]. This will
665
+ likely never be supported as JS try catch does not have a return value. It might
666
+ make sense to wrap everything that can throw in promises which is easy to do
667
+ with async functions.
668
+
669
+ ## Tests
670
+
671
+ Tests with 100% code coverage.
672
+
673
+ ```bash
674
+ npm t -- -R silent
675
+ npm t -- report text-summary
676
+ ```
677
+
678
+ ```
679
+
680
+ > sendscript@2.4.1 test
681
+ > tap -R silent
682
+
683
+
684
+ > sendscript@2.4.1 test
685
+ > tap report text-summary
686
+
687
+
688
+ =============================== Coverage summary ===============================
689
+ Statements : 100% ( 523/523 )
690
+ Branches : 100% ( 153/153 )
691
+ Functions : 100% ( 25/25 )
692
+ Lines : 100% ( 523/523 )
693
+ ================================================================================
694
+ ```
695
+
696
+ ## Formatting
697
+
698
+ Standard because no config.
699
+
700
+ ```bash
701
+ npx standard
702
+ ```
703
+
595
704
  ## Changelog
596
705
 
597
706
  The [changelog][changelog] is generated using the useful
package/README.mz CHANGED
@@ -1,6 +1,6 @@
1
1
  # SendScript
2
2
 
3
- Write JS code that you can run on servers, browsers or other clients.
3
+ RPC and no-build with composable function calls in a single payload.
4
4
 
5
5
  [![NPM](https://img.shields.io/npm/v/sendscript?color=blue&style=flat-square)](https://www.npmjs.com/package/sendscript)
6
6
  [![100% Code Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen?style=flat-square)](#tests)
@@ -181,13 +181,27 @@ pkill sendscript
181
181
 
182
182
  ## Repl
183
183
 
184
- Sendscript ships with a barebones (no-dependencies) node-repl script. One can
184
+ Sendscript ships with a bare-bones (no-dependencies) node-repl script. One can
185
185
  run it by simply typing `sendscript` in their console.
186
186
 
187
- > Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for
188
- > printingonly sendscript logs.
187
+ > Use the `DEBUG='*'` to enable all logs or `DEBUG='sendscript:*'` for printing
188
+ > only sendscript logs.
189
189
 
190
- ## Functions
190
+ ## Promises
191
+
192
+ ### .then / .catch
193
+
194
+ Supported since vs `v2.3`.
195
+
196
+ ```js
197
+ const getOrCreatePost = send(createPost(title).catch(createPost(title)))
198
+ ```
199
+
200
+ You will likely need to define better helpers that makes it safer to handle
201
+ rejections and work with promises. It is however sensible to have this basic
202
+ behavior for the sendscript DSL and parser.
203
+
204
+ ### await
191
205
 
192
206
  SendScript as of `v2.4` supports functions to do basic templating. It does not
193
207
  support async functions and will throw an error when you define one.
@@ -407,7 +421,7 @@ const env = {
407
421
  }
408
422
 
409
423
  // Parse with custom leaf deserializer
410
- const parse = Parse(schema, env, leadDeserializer)
424
+ const parse = Parse(schema, env, leafDeserializer)
411
425
 
412
426
  const result = parse(json)
413
427
  ```
@@ -415,6 +429,75 @@ const result = parse(json)
415
429
  The leaf wrapper format is `['leaf', serializedPayload]`, making it unambiguous
416
430
  and safe from colliding with SendScript operators.
417
431
 
432
+ ## Limitations
433
+
434
+ The stubs the `references` function returns are limited in the way they can be
435
+ used. This has to do with the fact that they are to be serialized.
436
+
437
+ ### Chaining APIs
438
+
439
+ Currently you cannot do chaining APIs. `lib().doThis().doThat()`. It likely is
440
+ possible to implement but will require more extensive schemas and obviously more
441
+ code to create the AST.
442
+
443
+ ### Callbacks
444
+
445
+ Although it is possible to mix client and server functions, it works very
446
+ different to ordinary functions. Client functions can be used but should be seen
447
+ as a templating tool to make sendscript programs; just like one would use
448
+ JavaScript with react templates. `items.map(deleteItem)` would return an array
449
+ of sendscript function calls which can be given to sendscript's parse.
450
+
451
+ Client functions cannot be called by sendscript functions (as of yet) since we
452
+ cannot serialize client functions. No work has been done to have the server send
453
+ back intermediate values to perform client function calls or by performing
454
+ smaller sendscript program payloads that are passed to the client. Very
455
+ interesting stuff to look into. You can achieve this now but it looks less clean
456
+ because you have to do `send` calls which is a bit manual.
457
+
458
+ ```js
459
+ await send(updateUser(id, merge(await send(getUser(id)), { ...newValues })))
460
+ ```
461
+
462
+ It might be interesting to allow configuration to create references that will
463
+ trigger a send whenever await is called. That would remove the ability to create
464
+ a single payload whenever using await. You can then write the above in the
465
+ following manner.
466
+
467
+ ```js
468
+ await updateUser(id, merge(await getUser(id), { ...newValues }))
469
+ ```
470
+
471
+ Possible footgun is that updateUser is only performed when awaited (.then is
472
+ called). This lazy behavior can trip users. This footgun could be resolved by
473
+ checking if any outstanding work exists at the end of a step or the beginning of
474
+ a new step.
475
+
476
+ ### Error handling
477
+
478
+ Sendscript does not have builtin tools to handle errors. You can write your own
479
+ utilities for that or use things like [Ramda's tryCatch][tryCatch]. This will
480
+ likely never be supported as JS try catch does not have a return value. It might
481
+ make sense to wrap everything that can throw in promises which is easy to do
482
+ with async functions.
483
+
484
+ ## Tests
485
+
486
+ Tests with 100% code coverage.
487
+
488
+ ```bash bash
489
+ npm t -- -R silent
490
+ npm t -- report text-summary
491
+ ```
492
+
493
+ ## Formatting
494
+
495
+ Standard because no config.
496
+
497
+ ```bash bash
498
+ npx standard
499
+ ```
500
+
418
501
  ## Changelog
419
502
 
420
503
  The [changelog][changelog] is generated using the useful
@@ -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/5249a85a08b10485f0d64058fd2c8bcaae84edda/example/typescript/math.ts#L1)
11
+ Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/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/5249a85a08b10485f0d64058fd2c8bcaae84edda/example/typescript/math.ts#L2)
11
+ Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/3f1041020e00331ff30ffb5f972738dbaf7a50f3/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": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Blur the line between server and client code.",
5
5
  "module": true,
6
6
  "main": "index.mjs",
@@ -25,7 +25,7 @@
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
27
  "superjson": "^2.2.6",
28
- "tap": "^21.6.3",
28
+ "tap": "^21.7.1",
29
29
  "tape-check": "^1.0.0-rc.0",
30
30
  "typedoc": "^0.28.18",
31
31
  "typedoc-plugin-markdown": "^4.11.0"