-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
96 lines (92 loc) · 2.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import fs from 'fs'
import path from 'path'
import net from 'net'
import { Cell, jam, Atom, cue } from '@urbit/nockjs'
import { python } from 'pythonia'
import { newtEncode, newtDecode, primitiveToAtom, atomToPrimitive } from './lib/bytes.js'
import { nounToTree, unwrapUnit } from './lib/noun.js'
import { Fyrd, Thread, parseThreadResponse, sendKahn } from './lib/khan.js'
function Clack({ ship }) {
return {
ship,
createDesk: async function (deskName) {
return await sendKahn({
ship,
noun: await Thread(`
=/ m (strand ,vase)
;< [=ship =desk =case] bind:m get-beak
;< ~ bind:m
(poke-our %hood %kiln-merge !>([${deskName} ship %base case %auto]))
(pure:m !>('success'))
`),
responseParser: parseThreadResponse
})
},
mountDesk: async function (deskName) {
return await sendKahn({
ship,
noun: await Thread(`
=/ m (strand ,vase)
;< [=ship =desk =case] bind:m get-beak
;< ~ bind:m
=/ pax=path (en-beam [ship ${deskName} case] /)
(poke-our %hood %kiln-mount !>([pax ${deskName}]))
(pure:m !>('success'))
`),
responseParser: parseThreadResponse
})
},
commitDesk: async function (deskName) {
return await sendKahn({
ship,
noun: await Thread(`
=/ m (strand ,vase)
;< [=ship =desk =case] bind:m get-beak
;< ~ bind:m
(poke-our %hood %kiln-commit !>([${deskName} |]))
(pure:m !>('success'))
`),
responseParser: parseThreadResponse
})
},
reviveDesk: async function (deskName) {
return await sendKahn({
ship,
noun: await Thread(`
=/ m (strand ,vase)
;< [=ship =desk =case] bind:m get-beak
;< ~ bind:m
(poke-our %hood %kiln-revive !>(${deskName}))
(pure:m !>('success'))
`),
responseParser: parseThreadResponse
})
},
runThread: async function (thread, responseParser=parseThreadResponse) {
return await sendKahn({
ship,
noun: thread,
responseParser,
})
},
close: async function() {
python.exit()
}
}
}
function closeClack () {
python.exit()
}
export {
Clack,
closeClack,
primitiveToAtom,
atomToPrimitive,
newtDecode,
newtEncode,
nounToTree,
Fyrd,
Thread,
parseThreadResponse,
sendKahn,
}