sendscript 0.1.0 → 0.1.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 +8 -0
- package/README.md +45 -15
- package/README.mz +39 -0
- package/api.mjs +13 -5
- package/{promise-only.mjs → await-when.mjs} +1 -3
- package/exec.mjs +2 -2
- package/exec.test.mjs +5 -0
- package/package.json +1 -1
- package/schema.json +53 -0
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
|
+
#### [v0.1.1](https://github.com/bas080/sendscript/compare/v0.1.0...v0.1.1)
|
|
8
|
+
|
|
9
|
+
- Add a json schema for the sendscript program [`2acf884`](https://github.com/bas080/sendscript/commit/2acf8848134e1ae175afc0af9c5f1e93c4039f8f)
|
|
10
|
+
- Document a way of using sendscript with typescript [`2683c28`](https://github.com/bas080/sendscript/commit/2683c2873b8c4833711cdb00c777792c0630954a)
|
|
11
|
+
- Improve naming of promise helper [`e177f39`](https://github.com/bas080/sendscript/commit/e177f39c740bc16864f1ed4fc90a6daa3321751f)
|
|
12
|
+
|
|
7
13
|
#### [v0.1.0](https://github.com/bas080/sendscript/compare/v0.0.4...v0.1.0)
|
|
8
14
|
|
|
15
|
+
> 21 October 2023
|
|
16
|
+
|
|
9
17
|
- Allow nesting arrays, calls and args [`48e5804`](https://github.com/bas080/sendscript/commit/48e5804891db0ee0ed8c274f20f81d49d6609a54)
|
|
10
18
|
|
|
11
19
|
#### [v0.0.4](https://github.com/bas080/sendscript/compare/v0.0.3...v0.0.4)
|
package/README.md
CHANGED
|
@@ -16,11 +16,11 @@ Write JS code that you can run on servers, browsers or other clients.
|
|
|
16
16
|
- [Reference](#reference)
|
|
17
17
|
* [`sendscript/api.mjs`](#sendscriptapimjs)
|
|
18
18
|
* [`sendscript/exec.mjs`](#sendscriptexecmjs)
|
|
19
|
+
- [TypeScript](#typescript)
|
|
19
20
|
- [Tests](#tests)
|
|
20
21
|
- [Formatting](#formatting)
|
|
21
22
|
- [Changelog](#changelog)
|
|
22
23
|
- [Dependencies](#dependencies)
|
|
23
|
-
- [License](#license)
|
|
24
24
|
|
|
25
25
|
<!-- tocstop -->
|
|
26
26
|
|
|
@@ -184,6 +184,44 @@ The array you see here is the LISP that SendScript uses to represent programs.
|
|
|
184
184
|
You could use SendScript without knowing the details of how the LISP works. It
|
|
185
185
|
is an implementation detail and might change over time.
|
|
186
186
|
|
|
187
|
+
## TypeScript
|
|
188
|
+
|
|
189
|
+
There is a good use-case to write an environment module in TypeScript.
|
|
190
|
+
|
|
191
|
+
1. Obviously the module would have the benefits that TypeScript offers when
|
|
192
|
+
coding.
|
|
193
|
+
2. You can use tools like [typedoc][typedoc] to generate docs from your types to
|
|
194
|
+
share with consumers of your API.
|
|
195
|
+
3. You can generate a .d.ts with `tsc --declaration` and use it to coerce your
|
|
196
|
+
client to adopt the modules type.
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Create pretty docs for your module.
|
|
200
|
+
npx typedoc my-module.ts
|
|
201
|
+
|
|
202
|
+
# Create the .d.ts file for your module.
|
|
203
|
+
tsc --declaration
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Now we can use the `my-module.d.ts` file for the client API.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import type * as MyModule from './my-module.d.ts'
|
|
210
|
+
|
|
211
|
+
import sendScriptApi from 'sendscript/api.mjs'
|
|
212
|
+
|
|
213
|
+
export default sendScriptApi([
|
|
214
|
+
fnOne,
|
|
215
|
+
fnTwo,
|
|
216
|
+
], /* perform websocket request */) as typeof MyModule
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
> [!NOTE]
|
|
220
|
+
> Although type coercion on the client side can improve the development
|
|
221
|
+
> experience, it does not represent the actual type.
|
|
222
|
+
> Values are likely subject to serialization and deserialization,
|
|
223
|
+
> particularly when interfacing with JSON formats.
|
|
224
|
+
|
|
187
225
|
## Tests
|
|
188
226
|
|
|
189
227
|
Tests with 100% code coverage.
|
|
@@ -194,19 +232,19 @@ npm t -- report text-summary
|
|
|
194
232
|
```
|
|
195
233
|
```
|
|
196
234
|
|
|
197
|
-
> sendscript@0.1.
|
|
235
|
+
> sendscript@0.1.1 test
|
|
198
236
|
> tap -R silent
|
|
199
237
|
|
|
200
238
|
|
|
201
|
-
> sendscript@0.1.
|
|
239
|
+
> sendscript@0.1.1 test
|
|
202
240
|
> tap report text-summary
|
|
203
241
|
|
|
204
242
|
|
|
205
243
|
=============================== Coverage summary ===============================
|
|
206
|
-
Statements : 100% (
|
|
244
|
+
Statements : 100% ( 98/98 )
|
|
207
245
|
Branches : 100% ( 30/30 )
|
|
208
246
|
Functions : 100% ( 10/10 )
|
|
209
|
-
Lines : 100% (
|
|
247
|
+
Lines : 100% ( 98/98 )
|
|
210
248
|
================================================================================
|
|
211
249
|
```
|
|
212
250
|
|
|
@@ -235,14 +273,6 @@ Check if packages are up to date on release.
|
|
|
235
273
|
npm outdated && echo 'No outdated packages found'
|
|
236
274
|
```
|
|
237
275
|
```
|
|
238
|
-
|
|
276
|
+
Package Current Wanted Latest Location Depended by
|
|
277
|
+
tap 18.5.2 18.6.1 18.6.1 node_modules/tap sendscript
|
|
239
278
|
```
|
|
240
|
-
|
|
241
|
-
## License
|
|
242
|
-
|
|
243
|
-
See the [LICENSE.txt][license] file for details.
|
|
244
|
-
|
|
245
|
-
[license]:./LICENSE.txt
|
|
246
|
-
[socket.io]:https://socket.io/
|
|
247
|
-
[changelog]:./CHANGELOG.md
|
|
248
|
-
[auto-changelog]:https://www.npmjs.com/package/auto-changelog
|
package/README.mz
CHANGED
|
@@ -166,6 +166,44 @@ The array you see here is the LISP that SendScript uses to represent programs.
|
|
|
166
166
|
You could use SendScript without knowing the details of how the LISP works. It
|
|
167
167
|
is an implementation detail and might change over time.
|
|
168
168
|
|
|
169
|
+
## TypeScript
|
|
170
|
+
|
|
171
|
+
There is a good use-case to write an environment module in TypeScript.
|
|
172
|
+
|
|
173
|
+
1. Obviously the module would have the benefits that TypeScript offers when
|
|
174
|
+
coding.
|
|
175
|
+
2. You can use tools like [typedoc][typedoc] to generate docs from your types to
|
|
176
|
+
share with consumers of your API.
|
|
177
|
+
3. You can generate a .d.ts with `tsc --declaration` and use it to coerce your
|
|
178
|
+
client to adopt the modules type.
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Create pretty docs for your module.
|
|
182
|
+
npx typedoc my-module.ts
|
|
183
|
+
|
|
184
|
+
# Create the .d.ts file for your module.
|
|
185
|
+
tsc --declaration
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Now we can use the `my-module.d.ts` file for the client API.
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
import type * as MyModule from './my-module.d.ts'
|
|
192
|
+
|
|
193
|
+
import sendScriptApi from 'sendscript/api.mjs'
|
|
194
|
+
|
|
195
|
+
export default sendScriptApi([
|
|
196
|
+
fnOne,
|
|
197
|
+
fnTwo,
|
|
198
|
+
], /* perform websocket request */) as typeof MyModule
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
> [!NOTE]
|
|
202
|
+
> Although type coercion on the client side can improve the development
|
|
203
|
+
> experience, it does not represent the actual type.
|
|
204
|
+
> Values are likely subject to serialization and deserialization,
|
|
205
|
+
> particularly when interfacing with JSON formats.
|
|
206
|
+
|
|
169
207
|
## Tests
|
|
170
208
|
|
|
171
209
|
Tests with 100% code coverage.
|
|
@@ -208,3 +246,4 @@ See the [LICENSE.txt][license] file for details.
|
|
|
208
246
|
[socket.io]:https://socket.io/
|
|
209
247
|
[changelog]:./CHANGELOG.md
|
|
210
248
|
[auto-changelog]:https://www.npmjs.com/package/auto-changelog
|
|
249
|
+
[typedoc]:https://github.com/TypeStrong/typedoc
|
package/api.mjs
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import awaitWhen from './await-when.mjs'
|
|
2
2
|
|
|
3
3
|
const symbol = Symbol('api')
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const isNotStub = v => v?.[symbol] !== symbol
|
|
5
|
+
const awaitWhenNotStub = awaitWhen(isNotStub)
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Create stubs to be used to build the program.
|
|
9
|
+
*
|
|
10
|
+
* @param {string[]} schema - Names of stubs.
|
|
11
|
+
* @param {Function} call - Function to call when awaited.
|
|
12
|
+
*
|
|
13
|
+
* @return {Object} An object containing the named stubs.
|
|
14
|
+
*/
|
|
7
15
|
export default function api (schema, call) {
|
|
8
16
|
return schema.reduce((api, name) => {
|
|
9
17
|
const then = (program) => (resolve, reject) =>
|
|
10
18
|
Promise.resolve(call(program)).then(resolve, reject)
|
|
11
19
|
|
|
12
20
|
const fn = (...args) => {
|
|
13
|
-
const toJSON = () => ['call', fn,
|
|
21
|
+
const toJSON = () => ['call', fn, args]
|
|
14
22
|
|
|
15
23
|
return {
|
|
16
24
|
[symbol]: symbol,
|
|
17
25
|
toJSON,
|
|
18
26
|
async then (resolve, reject) {
|
|
19
|
-
return then(await
|
|
27
|
+
return then(await awaitWhenNotStub(toJSON()))(resolve, reject)
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import curry from './curry.mjs'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default curry(function awaitWhen (when, array) {
|
|
4
4
|
return array.reduce(async (asyncAcc, item) => {
|
|
5
5
|
const acc = await asyncAcc
|
|
6
6
|
|
|
@@ -9,5 +9,3 @@ const promiseOnly = curry(function promiseOnly (when, array) {
|
|
|
9
9
|
return acc
|
|
10
10
|
}, [])
|
|
11
11
|
})
|
|
12
|
-
|
|
13
|
-
export default promiseOnly
|
package/exec.mjs
CHANGED
|
@@ -13,9 +13,9 @@ const exec = curry(async (env, expression) => {
|
|
|
13
13
|
const [operator, ...args] = expression
|
|
14
14
|
|
|
15
15
|
if (operator === 'call') {
|
|
16
|
-
const [
|
|
16
|
+
const [fnRef, fnArgs] = args
|
|
17
17
|
|
|
18
|
-
const fn = await exec(env,
|
|
18
|
+
const fn = await exec(env, fnRef)
|
|
19
19
|
return fn.apply(env, await exec(env, fnArgs))
|
|
20
20
|
}
|
|
21
21
|
|
package/exec.test.mjs
CHANGED
package/package.json
CHANGED
package/schema.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
}
|