instaserve 0.0.2 → 0.0.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/index.mjs CHANGED
@@ -1,8 +1,11 @@
1
1
  import http from 'node:http'
2
+ import fs from 'node:fs'
3
+ if (!fs.existsSync(`${process.cwd()}/routes.mjs`))
4
+ fs.copyFileSync('./routes.mjs', `${process.cwd()}/routes.mjs`)
2
5
  const routes = (await import(`${process.cwd()}/routes.mjs`)).default
3
6
  const VastDB = (await import(`./vastdb.mjs`)).default
4
7
  const db = new VastDB(routes)
5
- console.log(db.filename, db.views)
8
+ console.log(db.filename, routes)
6
9
 
7
10
  http
8
11
  .createServer(async (r, s) => {
@@ -14,11 +17,12 @@ http
14
17
  data = JSON.parse(data);
15
18
  } catch { }
16
19
  });
20
+ s.endJSON = o => s.end(JSON.stringify(o))
17
21
  const midware = Object.keys(routes)
18
22
  .filter((k) => k.startsWith('_'))
19
- .map((k) => routes[k]({ r, s, data }));
23
+ .map((k) => routes[k]({ r, s, data, db }));
20
24
  if (midware.includes(true)) return;
21
- if (routes[r.url]) return routes[r.url]({ r, s, data });
25
+ if (routes[r.url]) return routes[r.url]({ r, s, data, db });
22
26
  else s.writeHead(404).end()
23
27
  } catch (e) {
24
28
  console.log(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instaserve",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "bin": "./index.mjs"
package/routes.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  export default {
2
- _debug: ({ r, s }) => console.log(r.url, r.method),
3
- '/': ({ s }) => s.end('hello index'),
2
+ _debug: ({ r, s, db }) => console.log(r.url, r.method),
3
+ '/': ({ s }) => s.endJSON({ message: 'hello index' }),
4
4
  'tables': name => ([k, v]) => k.match(`${name}:`)
5
5
  }
package/vastdb.mjs CHANGED
@@ -31,6 +31,7 @@ export default class VastDB extends Map {
31
31
  if (!o.id) o.id = o.type + ':' + o.name;
32
32
  }
33
33
  arr.map((o) => super.set(o.id, o));
34
+ if(this.event) this.event(arr)
34
35
  this.save();
35
36
  }
36
37
  save() {