sendscript 2.3.3 → 2.3.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.
package/CHANGELOG.md CHANGED
@@ -4,8 +4,20 @@ 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.3.5](https://github.com/bas080/sendscript/compare/v2.3.4...v2.3.5)
8
+
9
+ - Have reference and parse reference same schema type [`0a05608`](https://github.com/bas080/sendscript/commit/0a0560828b78d297bfa5b12639a5e54774c089bd)
10
+
11
+ #### [v2.3.4](https://github.com/bas080/sendscript/compare/v2.3.3...v2.3.4)
12
+
13
+ > 14 April 2026
14
+
15
+ - Improve naming in JSDocs [`669a40e`](https://github.com/bas080/sendscript/commit/669a40e28a5c77963d855dd4e2122d0ba2c074cd)
16
+
7
17
  #### [v2.3.3](https://github.com/bas080/sendscript/compare/v2.3.2...v2.3.3)
8
18
 
19
+ > 14 April 2026
20
+
9
21
  - Add JSDoc to relevant function for docs [`d1d3709`](https://github.com/bas080/sendscript/commit/d1d3709088a51b71651170ef642b013eedc9ca3a)
10
22
  - Remove tests section from README [`5da7bb3`](https://github.com/bas080/sendscript/commit/5da7bb3f3b1dc8078683e076fe2b520bc6d28896)
11
23
  - Add generated from JSDoc reference section [`08eb266`](https://github.com/bas080/sendscript/commit/08eb266b06d8998e6849dbc5c9738fbe782ada18)
package/CONTRIBUTING.md CHANGED
@@ -40,7 +40,7 @@ Generate the README from the mz file.
40
40
  ```bash bash
41
41
  markatzea ./README.mz | tee ./README.md
42
42
 
43
- npx documentation readme references.mjs parse.mjs stringify.mjs -s Reference --github --a public --markdown-toc false
43
+ npx documentation readme schema.mjs references.mjs stringify.mjs parse.mjs -s Reference --github --a public --markdown-toc false
44
44
 
45
45
  npx markdown-toc --maxdepth 3 -i README.md
46
46
 
package/README.md CHANGED
@@ -11,11 +11,12 @@ Write JS code that you can run on servers, browsers or other clients.
11
11
 
12
12
  - [Introduction](#introduction)
13
13
  - [Reference](#reference)
14
- * [defaultLeafDeserializer](#defaultleafdeserializer)
14
+ * [defaultLeafParse](#defaultleafparse)
15
15
  * [Parse](#parse)
16
16
  * [parse](#parse)
17
17
  * [References](#references)
18
- * [strictStringify](#strictstringify)
18
+ * [Schema](#schema)
19
+ * [defaultLeafStringify](#defaultleafstringify)
19
20
  * [Stringify](#stringify)
20
21
  * [stringify](#stringify)
21
22
  - [Socket example](#socket-example)
@@ -121,7 +122,7 @@ of communication between servers and clients that best fits your needs.
121
122
 
122
123
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
123
124
 
124
- ### defaultLeafDeserializer
125
+ ### defaultLeafParse
125
126
 
126
127
  Default deserializer for leaf nodes.
127
128
 
@@ -133,20 +134,13 @@ Returns **any**&#x20;
133
134
 
134
135
  ### Parse
135
136
 
136
- Creates a program parser for a given schema and environment.
137
-
138
- The parser:
139
-
140
- * resolves references into runtime functions
141
- * deserializes leaf nodes
142
- * collects and executes async awaits
143
- * evaluates AST-like JSON programs
144
-
145
137
  #### Parameters
146
138
 
147
- * `schemaArg` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | \[[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)])>**&#x20;
148
- * `env` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** runtime environment for refs
149
- * `deserialize` (optional, default `defaultLeafDeserializer`)
139
+ * `schema` **[Schema](#schema)**&#x20;
140
+ * `env` **Env** runtime environment for refs
141
+ * `leafParse` (optional, default `defaultLeafParse`)
142
+
143
+ Returns **[parse](#parse)**&#x20;
150
144
 
151
145
  ### parse
152
146
 
@@ -169,7 +163,7 @@ Schema supports:
169
163
 
170
164
  #### Parameters
171
165
 
172
- * `schema` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | \[[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)])>**&#x20;
166
+ * `schema` **[Schema](#schema)**&#x20;
173
167
  * `parentPath` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (optional, default `[]`)
174
168
 
175
169
  <!---->
@@ -178,7 +172,16 @@ Schema supports:
178
172
 
179
173
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Nested instrumented API object
180
174
 
181
- ### strictStringify
175
+ ### Schema
176
+
177
+ A schema defines the structure of the runtime API tree.
178
+
179
+ * string → leaf node
180
+ * \[name, children] → namespace
181
+
182
+ Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | \[[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)])>
183
+
184
+ ### defaultLeafStringify
182
185
 
183
186
  Default strict serializer for leaf values.
184
187
 
@@ -196,7 +199,7 @@ Creates a stringify function for SendScript AST structures.
196
199
 
197
200
  #### Parameters
198
201
 
199
- * `leafSerializer` (optional, default `strictStringify`)
202
+ * `leafStringify` (optional, default `defaultLeafStringify`)
200
203
 
201
204
  ### stringify
202
205
 
@@ -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/08eb266b06d8998e6849dbc5c9738fbe782ada18/example/typescript/math.ts#L1)
11
+ Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/0a0560828b78d297bfa5b12639a5e54774c089bd/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/08eb266b06d8998e6849dbc5c9738fbe782ada18/example/typescript/math.ts#L2)
11
+ Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/0a0560828b78d297bfa5b12639a5e54774c089bd/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.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "Blur the line between server and client code.",
5
5
  "module": true,
6
6
  "main": "index.mjs",
package/parse.mjs CHANGED
@@ -98,9 +98,12 @@ const evaluate = spy('eval', (value, awaits = []) => {
98
98
  * @returns {any}
99
99
  * @public
100
100
  */
101
- const defaultLeafDeserializer = (text) => JSON.parse(text)
101
+ const defaultLeafParse = (text) => JSON.parse(text)
102
102
 
103
103
  /**
104
+ * @template Env
105
+ * @typedef {(program: string) => any | Promise<any>} parse
106
+ *
104
107
  * Creates a program parser for a given schema and environment.
105
108
  *
106
109
  * The parser:
@@ -109,14 +112,14 @@ const defaultLeafDeserializer = (text) => JSON.parse(text)
109
112
  * - collects and executes async awaits
110
113
  * - evaluates AST-like JSON programs
111
114
  *
112
- * @param {Array<string | [string, Array]>} schemaArg
113
- * @param {Object} env - runtime environment for refs
114
- * @param {(text: string) => any} [deserialize=defaultLeafDeserializer]
115
- * @returns {(program: string) => any|Promise<any>}
115
+ * @param {Schema} schema
116
+ * @param {Env} env - runtime environment for refs
117
+ * @param {(text: string) => any} [leafParse=defaultLeafParse]
118
+ * @returns {parse}
116
119
  * @public
117
120
  */
118
- export default function Parse (schemaArg, env, deserialize = defaultLeafDeserializer) {
119
- const schema = flattenSchema(schemaArg)
121
+ export default function Parse (schema, env, leafParse = defaultLeafParse) {
122
+ const flatSchema = flattenSchema(schema)
120
123
 
121
124
  /**
122
125
  * Parses and executes a serialized program.
@@ -145,7 +148,7 @@ export default function Parse (schemaArg, env, deserialize = defaultLeafDeserial
145
148
  const [operator, ...rest] = value
146
149
 
147
150
  if (operator === 'leaf') {
148
- const leafValue = deserialize(rest[0])
151
+ const leafValue = leafParse(rest[0])
149
152
  return leafValue === undefined ? undefinedSentinel : leafValue
150
153
  }
151
154
 
@@ -157,7 +160,7 @@ export default function Parse (schemaArg, env, deserialize = defaultLeafDeserial
157
160
  if (operator === 'ref') {
158
161
  const path = rest
159
162
  let current = env
160
- let schemaCurrent = schema
163
+ let schemaCurrent = flatSchema
161
164
 
162
165
  for (const segment of path) {
163
166
  if (schemaCurrent && Object.hasOwn(schemaCurrent, segment)) {
package/references.mjs CHANGED
@@ -104,7 +104,7 @@ function instrument (path) {
104
104
  * - string => leaf function node
105
105
  * - [name, children] => namespace with nested schema
106
106
  *
107
- * @param {Array<string | [string, Array]>} schema
107
+ * @param {Schema} schema
108
108
  * @param {Array<string>} [parentPath=[]]
109
109
  * @returns {Object} Nested instrumented API object
110
110
  *
package/schema.mjs ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A schema defines the structure of the runtime API tree.
3
+ *
4
+ * - string → leaf node
5
+ * - [name, children] → namespace
6
+ *
7
+ * @typedef {Array<string | [string, Array]>} Schema
8
+ * @public
9
+ */
package/stringify.mjs CHANGED
@@ -89,7 +89,7 @@ function transformValue (value, leafSerializer) {
89
89
  * @returns {string}
90
90
  * @public
91
91
  */
92
- function strictStringify (x) {
92
+ function defaultLeafStringify (x) {
93
93
  const typeOf = typeof x
94
94
 
95
95
  if (typeOf === 'object' || typeOf === 'function' || x === undefined) {
@@ -108,7 +108,7 @@ function strictStringify (x) {
108
108
  * @returns {(program: any) => string}
109
109
  * @public
110
110
  */
111
- export default function Stringify (leafSerializer = strictStringify) {
111
+ export default function Stringify (leafStringify = defaultLeafStringify) {
112
112
  /**
113
113
  * Serializes a program into a JSON string representation.
114
114
  *
@@ -116,9 +116,7 @@ export default function Stringify (leafSerializer = strictStringify) {
116
116
  * @returns {string}
117
117
  * @public
118
118
  */
119
- function stringify (program) {
120
- return JSON.stringify(transformValue(program, leafSerializer))
119
+ return function stringify (program) {
120
+ return JSON.stringify(transformValue(program, leafStringify))
121
121
  }
122
-
123
- return stringify
124
122
  }