pinokiod 2.15.19 → 2.15.21

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.
@@ -38,6 +38,23 @@ class FS {
38
38
  let data = await fs.promises.readFile(filepath, req.params.encoding)
39
39
  return data
40
40
  }
41
+ async cat(req, ondata, kernel) {
42
+ /*
43
+ params := {
44
+ path: <filepath>,
45
+ }
46
+ */
47
+ let cwd = (req.cwd ? req.cwd : kernel.api.userdir)
48
+ let filepath = kernel.api.filePath(req.params.path, cwd)
49
+ //let filepath = path.resolve(cwd, req.params.path)
50
+ let data = await fs.promises.readFile(filepath, "utf8")
51
+ ondata({
52
+ raw: data.replace(/\n/g, "\r\n")
53
+ })
54
+ ondata({
55
+ raw: "\r\n"
56
+ })
57
+ }
41
58
  // async unzip(req, ondata, kernel) {
42
59
  // /*
43
60
  // params := {
@@ -67,7 +84,6 @@ class FS {
67
84
  }
68
85
 
69
86
  async link(req, ondata, kernel) {
70
- console.log("FS.link", req)
71
87
  let response = await this.share(req, ondata, kernel)
72
88
  return response
73
89
  }
@@ -277,7 +293,7 @@ class FS {
277
293
  }
278
294
 
279
295
 
280
-
296
+ // fs.link should overwrite by default.
281
297
  if (req.params.options) {
282
298
  d.options = req.params.options
283
299
  } else {
@@ -311,7 +327,6 @@ class FS {
311
327
  ondata({
312
328
  raw: "\r\nLINKING DRIVES:\r\n" + JSON.stringify(d, null, 2).replace(/\n/g, "\r\n")
313
329
  })
314
- console.log("CREATE", JSON.stringify(d, null, 2))
315
330
  await drive.create(d)
316
331
  ondata({
317
332
  raw: "Done.\r\n"
@@ -56,14 +56,12 @@ class Api {
56
56
  this.checkProxy({ uri, name })
57
57
  // if the name exists, throw error
58
58
  // if the uri exists, throw error
59
- console.log("lproxy start", uri, options)
60
59
  let proxy_uri = await this.lproxy.start(uri, options)
61
60
  if (this.proxies[scriptPath]) {
62
61
  this.proxies[scriptPath].push({ target: uri, proxy: proxy_uri, name})
63
62
  } else {
64
63
  this.proxies[scriptPath] = [{ target: uri, proxy: proxy_uri, name }]
65
64
  }
66
- console.log("this.proxies", JSON.stringify(this.proxies, null, 2))
67
65
  return {
68
66
  target: uri,
69
67
  proxy: proxy_uri
@@ -92,7 +90,6 @@ class Api {
92
90
  })
93
91
  }
94
92
  }
95
- console.log("this.proxies", JSON.stringify(this.proxies, null, 2))
96
93
  }
97
94
  async init() {
98
95
  if (this.kernel.homedir) {
@@ -519,7 +516,6 @@ class Api {
519
516
  mods.push(r)
520
517
  }
521
518
  let mod = _.zipObjectDeep(paths, mods)
522
- console.log("MOD", mod)
523
519
  return mod
524
520
 
525
521
  }
@@ -559,7 +555,7 @@ class Api {
559
555
  // get fully resolved env
560
556
  let env = await Environment.get2(request.path, this.kernel)
561
557
  // set template
562
- this.kernel.template.update({ env })
558
+ this.kernel.template.update({ envs: env, env })
563
559
 
564
560
  // render until `{{ }}` pattern does not exist
565
561
  // 1. render once
@@ -567,6 +563,7 @@ class Api {
567
563
  let pass = 0;
568
564
  while(true) {
569
565
  rpc = this.kernel.template.render(rpc, memory)
566
+ let test = this.kernel.template.istemplate(rpc)
570
567
  if (this.kernel.template.istemplate(rpc)) {
571
568
  pass++;
572
569
  if (pass >= 4) {
@@ -1215,7 +1212,6 @@ class Api {
1215
1212
  // }
1216
1213
  // }
1217
1214
  // script = Object.assign(script, merge)
1218
- console.log("SCRIPT", script)
1219
1215
 
1220
1216
  return { cwd, script }
1221
1217
  }
@@ -0,0 +1,112 @@
1
+ const path = require('path')
2
+ const set = require("../set")
3
+ const rm = require("../rm")
4
+ class J {
5
+ async get(req, ondata, kernel) {
6
+ /*
7
+ // set local variables from json
8
+ req := {
9
+ "method": "json.get",
10
+ "params": {
11
+ "<key1>": <filepath1>,
12
+ "<key1>": <filepath2>
13
+ }
14
+ }
15
+ */
16
+ let params = {}
17
+ for(let key in req.params) {
18
+ let filepath = path.resolve(req.cwd, req.params[key])
19
+ if (filepath.endsWith(".json")) {
20
+ let j = (await kernel.loader.load(filepath)).resolved
21
+ params[key] = j
22
+ }
23
+ }
24
+ let converted = Object.assign({}, req, {
25
+ params: {
26
+ local: params
27
+ }
28
+ })
29
+ await set(converted, ondata, kernel)
30
+ }
31
+ async set(req, ondata, kernel) {
32
+ /*
33
+ req := {
34
+ "method": "json.set",
35
+ "params": {
36
+ "index.json": {
37
+ <key>: <val>,
38
+ <key>: <val>,
39
+ },
40
+ "data/models.json": {
41
+ <key>: <val>,
42
+ <key>: <val>,
43
+ }
44
+ }
45
+ }
46
+
47
+ equivalent to:
48
+
49
+ req := {
50
+ "method": "set",
51
+ "params": {
52
+ "json": {
53
+ "index.json": {
54
+ <key>: <val>,
55
+ <key>: <val>,
56
+ },
57
+ "data/models.json": {
58
+ <key>: <val>,
59
+ <key>: <val>,
60
+ }
61
+ }
62
+ }
63
+ }
64
+ */
65
+ let converted = Object.assign({}, req, {
66
+ params: {
67
+ json: req.params
68
+ }
69
+ })
70
+ let res = await set(converted, ondata, kernel)
71
+ return res
72
+ }
73
+ async rm(req, ondata, kernel) {
74
+ /*
75
+ req := {
76
+ "method": "json.rm",
77
+ "params": {
78
+ "index.json": {
79
+ "abc": "def"
80
+ },
81
+ "data/models.json": {
82
+ [ "attr", "a.b.c" ]
83
+ }
84
+ }
85
+ }
86
+
87
+ equivalent to:
88
+
89
+ req := {
90
+ "method": "rm",
91
+ "params": {
92
+ "json": {
93
+ "index.json": {
94
+ "abc": "def"
95
+ },
96
+ "data/models.json": {
97
+ [ "attr", "a.b.c" ]
98
+ }
99
+ }
100
+ }
101
+ }
102
+ */
103
+ let converted = Object.assign({}, req, {
104
+ params: {
105
+ json: req.params
106
+ }
107
+ })
108
+ let res = await rm(converted, ondata, kernel)
109
+ return res
110
+ }
111
+ }
112
+ module.exports = J
@@ -25,7 +25,6 @@ class Local {
25
25
  return res
26
26
  }
27
27
  async set(req, ondata, kernel) {
28
- console.log("SET", req)
29
28
  /*
30
29
  req := {
31
30
  "method": "local.set",
@@ -96,7 +95,6 @@ class Local {
96
95
  }
97
96
  }
98
97
  const p = new Proxy()
99
- console.log("> proxy", req)
100
98
  await p.start(req, ondata, kernel)
101
99
  }
102
100
  }
@@ -3,8 +3,31 @@ const fs = require('fs')
3
3
  const rm = (old, keys) => {
4
4
  for (let key of keys) {
5
5
  try {
6
- let fun = new Function('old', 'key', `delete old.${key}; return old;`);
7
- old = fun(old, key);
6
+ // let fun = new Function('old', 'key', `delete old.${key}; return old;`);
7
+ // old = fun(old, key);
8
+ let keypath = String(key).split(".")
9
+ // multiple keys. check if that path exists.
10
+ // if not, create the path
11
+ let next = old
12
+ for(let i=0; i<keypath.length; i++) {
13
+ if (i === keypath.length-1) {
14
+ // last
15
+ let path_key = keypath[i]
16
+ if (/^[0-9]+$/.test(path_key)) {
17
+ if (Array.isArray(next)) {
18
+ // array index
19
+ let index = Number(path_key)
20
+ next.splice(index, 1)
21
+ }
22
+ } else {
23
+ // key
24
+ delete next[path_key]
25
+ }
26
+ } else {
27
+ const key = keypath[i];
28
+ next = next[key];
29
+ }
30
+ }
8
31
  } catch (e) {
9
32
  }
10
33
  }
@@ -52,8 +75,12 @@ module.exports = async (req, ondata, kernel) => {
52
75
  }
53
76
  */
54
77
 
55
- if (req.params.self) {
56
- for(let relative_filepath in req.params.self) {
78
+ let self = req.params.self
79
+ if (!self) {
80
+ self = req.params.json
81
+ }
82
+ if (self) {
83
+ for(let relative_filepath in self) {
57
84
  let filepath = path.resolve(req.cwd, relative_filepath)
58
85
  // ensure that the filepath is .json
59
86
  if (filepath.endsWith(".json")) {
@@ -66,7 +93,7 @@ module.exports = async (req, ondata, kernel) => {
66
93
  let folder = path.dirname(filepath)
67
94
  await fs.promises.mkdir(folder, { recursive: true }).catch((e) => { })
68
95
  }
69
- let kv = req.params.self[relative_filepath]
96
+ let kv = self[relative_filepath]
70
97
 
71
98
 
72
99
  old = rm(old, kv)
@@ -1,42 +1,64 @@
1
1
  const path = require('path')
2
2
  const fs = require('fs')
3
3
  const set = async (old, kv, kernel, req, ondata) => {
4
- for (let key in kv) {
5
- try {
6
- if (key.startsWith('[')) {
7
- // array
8
- let fun = new Function(
9
- 'old',
10
- 'key',
11
- 'val',
12
- `old${key} = val; return old;`
13
- );
14
- old = fun(old, key, kv[key]);
15
- } else {
16
- let fun = new Function(
17
- 'old',
18
- 'key',
19
- 'val',
20
- //`old.${key} = val; return old;`
21
- `old["${key}"] = val; return old;`
22
- );
23
- old = fun(old, key, kv[key]);
24
- }
4
+ if (Array.isArray(kv)) {
5
+ old = kv
6
+ } else {
7
+ for (let key in kv) {
8
+ try {
9
+ if (key.startsWith('[')) {
10
+ // array
11
+ let fun = new Function(
12
+ 'old',
13
+ 'key',
14
+ 'val',
15
+ `old${key} = val; return old;`
16
+ );
17
+ old = fun(old, key, kv[key]);
18
+ } else {
19
+
20
+ let keypath = key.split(".")
21
+ // multiple keys. check if that path exists.
22
+ // if not, create the path
23
+ let next = old
24
+ for(let i=0; i<keypath.length; i++) {
25
+ if (i === keypath.length-1) {
26
+ // last
27
+ next[keypath[i]] = kv[key]
28
+ } else {
29
+ const key = keypath[i];
30
+ if (!(key in next)) {
31
+ next[key] = {}
32
+ }
33
+ next = next[key];
34
+ }
35
+ }
25
36
 
37
+ // let fun = new Function(
38
+ // 'old',
39
+ // 'key',
40
+ // 'val',
41
+ // //`old.${key} = val; return old;`
42
+ // `old["${key}"] = val; return old;`
43
+ // );
44
+ // old = fun(old, key, kv[key]);
45
+ }
26
46
 
27
- // // reserved variable: "url"
28
- // if (key === "url") {
29
- // // start proxy
30
- // ondata({
31
- // raw: `\r\n[Start proxy] ${kv[key]}\r\n`
32
- // })
33
- // let response = await kernel.api.startProxy(req.parent.path, kv[key], "Shared")
34
- // console.log("Response", response)
35
- // ondata({
36
- // raw: `Proxy Started ${JSON.stringify(response)}\r\n`
37
- // })
38
- // }
39
- } catch (e) {
47
+
48
+ // // reserved variable: "url"
49
+ // if (key === "url") {
50
+ // // start proxy
51
+ // ondata({
52
+ // raw: `\r\n[Start proxy] ${kv[key]}\r\n`
53
+ // })
54
+ // let response = await kernel.api.startProxy(req.parent.path, kv[key], "Shared")
55
+ // console.log("Response", response)
56
+ // ondata({
57
+ // raw: `Proxy Started ${JSON.stringify(response)}\r\n`
58
+ // })
59
+ // }
60
+ } catch (e) {
61
+ }
40
62
  }
41
63
  }
42
64
  return old
@@ -89,7 +111,6 @@ module.exports = async (req, ondata, kernel) => {
89
111
  // }
90
112
  }
91
113
  }
92
-
93
114
  // set self => save to the file
94
115
 
95
116
  /*
@@ -110,8 +131,12 @@ module.exports = async (req, ondata, kernel) => {
110
131
  }
111
132
  */
112
133
 
113
- if (req.params.self) {
114
- for(let relative_filepath in req.params.self) {
134
+ let self = req.params.self
135
+ if (!self) {
136
+ self = req.params.json
137
+ }
138
+ if (self) {
139
+ for(let relative_filepath in self) {
115
140
  let filepath = path.resolve(req.cwd, relative_filepath)
116
141
  // ensure that the filepath is .json
117
142
  if (filepath.endsWith(".json")) {
@@ -124,7 +149,7 @@ module.exports = async (req, ondata, kernel) => {
124
149
  let folder = path.dirname(filepath)
125
150
  await fs.promises.mkdir(folder, { recursive: true }).catch((e) => { })
126
151
  }
127
- let kv = req.params.self[relative_filepath]
152
+ let kv = self[relative_filepath]
128
153
 
129
154
  old = await set(old, kv, kernel, req, ondata)
130
155
 
@@ -207,7 +207,6 @@ class Bin {
207
207
  })
208
208
  let pipconfig_path = path.resolve(this.kernel.homedir, "pipconfig")
209
209
  let pipconfig_exists = await this.kernel.api.exists(pipconfig_path)
210
- console.log("pipconfig exists?", { pipconfig_path, pipconfig_exists })
211
210
  // if not, create one
212
211
  if (!pipconfig_exists) {
213
212
  const pipconfigStr = `[global]
@@ -371,9 +370,6 @@ class Bin {
371
370
  // console.log("metaFiles", metaFiles)
372
371
  // console.log("paths", paths)
373
372
 
374
- console.log("this.installed", this.installed)
375
-
376
-
377
373
 
378
374
  this.installed_initialized = true
379
375
 
@@ -0,0 +1,20 @@
1
+ const fs = require('fs')
2
+ const fetch = require('cross-fetch')
3
+ const { rimraf } = require('rimraf')
4
+ const decompress = require('decompress');
5
+ class UV {
6
+ async install(req, ondata) {
7
+ await this.kernel.bin.exec({
8
+ message: "conda install -y -c conda-forge uv",
9
+ }, ondata)
10
+ }
11
+ async installed() {
12
+ return this.kernel.bin.installed.conda.has("uv")
13
+ }
14
+ async uninstall(req, ondata) {
15
+ await this.kernel.bin.exec({
16
+ message: "conda remove uv",
17
+ }, ondata)
18
+ }
19
+ }
20
+ module.exports = UV
package/kernel/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const fs = require('fs')
2
- //const {JSONPath} = require('jsonpath-plus');
3
2
  const os = require("os")
4
3
  const jsdom = require("jsdom");
5
4
  const path = require('path')
@@ -359,6 +358,8 @@ class Kernel {
359
358
  system,
360
359
  platform: this.platform,
361
360
  arch: this.arch,
361
+ env: this.envs,
362
+ envs: this.envs,
362
363
  proxy: (port) => {
363
364
  return this.api.get_proxy_url("/proxy", port)
364
365
  },
package/kernel/shell.js CHANGED
@@ -403,9 +403,9 @@ class Shell {
403
403
  })
404
404
  cb()
405
405
  }, 1)
406
- term.onExit((result) => {
407
- console.log("onExit", { result })
408
- })
406
+ // term.onExit((result) => {
407
+ // console.log("onExit", { result })
408
+ // })
409
409
  term.onData((data) => {
410
410
  if (ready) {
411
411
  queue.push(data)
@@ -670,9 +670,9 @@ class Shell {
670
670
  this.queue.push(data)
671
671
  }
672
672
  });
673
- this.ptyProcess.onExit((result) => {
674
- console.log("onExit", result)
675
- })
673
+ // this.ptyProcess.onExit((result) => {
674
+ // console.log("onExit", result)
675
+ // })
676
676
  }
677
677
  } catch (e) {
678
678
  console.log("** Error", e)
package/kernel/shells.js CHANGED
@@ -41,8 +41,16 @@ class Shells {
41
41
  }, async (stream) => {
42
42
  process.stdout.write(stream.raw)
43
43
  })
44
- console.log(">>> sh.env =", sh.env)
44
+
45
45
  this.kernel.envs = sh.env
46
+ // also set the uppercase variables if they're not set
47
+ for(let key in sh.env) {
48
+ let up = key.toUpperCase()
49
+ if (!this.kernel.envs[up]) {
50
+ this.kernel.envs[up] = sh.env[key]
51
+ }
52
+ }
53
+
46
54
  }
47
55
  async launch(params, options, ondata) {
48
56
  // iterate through all the envs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "2.15.19",
3
+ "version": "2.15.21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  "http-proxy-middleware": "^3.0.0",
36
36
  "http-terminator": "^3.2.0",
37
37
  "isomorphic-git": "^1.23.0",
38
- "jimini": "^0.0.6",
38
+ "jimini": "^0.0.7",
39
39
  "jsdom": "^24.0.0",
40
40
  "key-store": "^1.2.0",
41
41
  "kleur": "^4.1.5",