sendscript 2.1.0 → 2.2.0

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,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
+ #### [v2.2.0](https://github.com/bas080/sendscript/compare/v2.1.0...v2.2.0)
8
+
9
+ - Have default leaf serializer throw if value has no JSON equivalant [`6752f2f`](https://github.com/bas080/sendscript/commit/6752f2f3ed51e252ab93a31b632fe8fbae51d7cb)
10
+ - Test that prototype chain works when parsing [`2cf0e7e`](https://github.com/bas080/sendscript/commit/2cf0e7e7ced32258102382e7ff1e3f8e91a2cc77)
11
+
7
12
  #### [v2.1.0](https://github.com/bas080/sendscript/compare/v2.0.1...v2.1.0)
8
13
 
14
+ > 9 April 2026
15
+
9
16
  - Make eval order when using await inline with JS [`00db8aa`](https://github.com/bas080/sendscript/commit/00db8aaa563378db814035e3e550269593ed82e2)
10
17
  - Merge release workflow into publish [`6a5db12`](https://github.com/bas080/sendscript/commit/6a5db128b659dd295390505b2e470c5913617abf)
11
18
  - Fix the cli repl [`3cf8b0d`](https://github.com/bas080/sendscript/commit/3cf8b0d9b4531989fb01a53fa9ab4cb6a011c183)
package/README.md CHANGED
@@ -429,19 +429,19 @@ npm t -- report text-summary
429
429
  ```
430
430
  ```
431
431
 
432
- > sendscript@2.1.0 test
432
+ > sendscript@2.2.0 test
433
433
  > tap -R silent
434
434
 
435
435
 
436
- > sendscript@2.1.0 test
436
+ > sendscript@2.2.0 test
437
437
  > tap report text-summary
438
438
 
439
439
 
440
440
  =============================== Coverage summary ===============================
441
- Statements : 100% ( 326/326 )
442
- Branches : 100% ( 118/118 )
443
- Functions : 100% ( 21/21 )
444
- Lines : 100% ( 326/326 )
441
+ Statements : 100% ( 338/338 )
442
+ Branches : 100% ( 123/123 )
443
+ Functions : 100% ( 22/22 )
444
+ Lines : 100% ( 338/338 )
445
445
  ================================================================================
446
446
  ```
447
447
 
package/error.mjs CHANGED
@@ -1,2 +1,3 @@
1
1
  export class SendScriptError extends Error {}
2
2
  export class SendScriptReferenceError extends SendScriptError {}
3
+ export class SendScriptSerializationError extends SendScriptError {}
@@ -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/3d843187a56e23f0e70f11e904832efb1abd9cf1/example/typescript/math.ts#L1)
11
+ Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/2cf0e7e7ced32258102382e7ff1e3f8e91a2cc77/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/3d843187a56e23f0e70f11e904832efb1abd9cf1/example/typescript/math.ts#L2)
11
+ Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/2cf0e7e7ced32258102382e7ff1e3f8e91a2cc77/example/typescript/math.ts#L2)
12
12
 
13
13
  ## Parameters
14
14
 
package/index.test.mjs CHANGED
@@ -2,10 +2,11 @@ import { test } from 'tap'
2
2
  import Stringify from './stringify.mjs'
3
3
  import references from './references.mjs'
4
4
  import Parse from './parse.mjs'
5
+ import { SendScriptSerializationError } from './error.mjs'
5
6
 
6
7
  const order = []
7
8
 
8
- const myModule = {
9
+ const myModuleOrig = {
9
10
  nested: {
10
11
  again: {
11
12
  T: () => true
@@ -45,7 +46,10 @@ const myModule = {
45
46
  Promise
46
47
  }
47
48
 
48
- const schema = Object.keys(myModule)
49
+ // We want to support prototype chain when parsing.
50
+ const myModule = Object.create(myModuleOrig)
51
+ const schema = Object.keys(myModuleOrig)
52
+
49
53
  schema.push(['nested', [
50
54
  ['again', ['T']]
51
55
  ]])
@@ -225,12 +229,30 @@ test('should evaluate basic expressions correctly', async (t) => {
225
229
  t.end()
226
230
  })
227
231
 
232
+ t.test('throws if stringify returns undefined', t => {
233
+ // This is to prevent accidentally sending payloads that make little sense.
234
+
235
+ // Check if it throw the expected error type.
236
+ try {
237
+ run(undefined)
238
+ } catch (error) {
239
+ t.ok(error instanceof SendScriptSerializationError)
240
+ }
241
+
242
+ t.throws(() => run(undefined))
243
+ t.throws(() => run(new Set()))
244
+ t.throws(() => run(identity(undefined)))
245
+ t.throws(() => run(() => {}))
246
+
247
+ t.end()
248
+ })
249
+
228
250
  t.test('basic types and identity', (t) => {
229
251
  t.equal(run(identity(null)), null)
230
- t.equal(run(identity(undefined)), null)
231
252
  t.equal(run(noop()), undefined)
232
253
  t.equal(run(identity(1)), 1)
233
254
  t.strictSame(run(identity([])), [])
255
+ t.strictSame(run(identity({})), {})
234
256
  t.strictSame(run(identity([identity(1), 2, 3])), [1, 2, 3])
235
257
  t.strictSame(run(always('hello')()), 'hello')
236
258
  t.end()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sendscript",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Blur the line between server and client code.",
5
5
  "module": true,
6
6
  "main": "index.mjs",
package/stringify.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import Debug from './debug.mjs'
2
+ import { SendScriptSerializationError } from './error.mjs'
2
3
  import {
3
4
  awaitSymbol,
4
5
  call,
@@ -69,7 +70,17 @@ function transformValue (value, leafSerializer) {
69
70
  return ['leaf', leafSerializer(value)]
70
71
  }
71
72
 
72
- export default function stringify (leafSerializer = JSON.stringify) {
73
+ function strictStringify (x) {
74
+ const typeOf = typeof x
75
+
76
+ if (typeOf === 'object' || typeOf === 'function' || x === undefined) {
77
+ throw new SendScriptSerializationError(`Cannot and should not attempt to serialize ${x}`)
78
+ }
79
+
80
+ return JSON.stringify(x)
81
+ }
82
+
83
+ export default function stringify (leafSerializer = strictStringify) {
73
84
  function stringify (program) {
74
85
  return JSON.stringify(transformValue(program, leafSerializer))
75
86
  }