instaserve 0.0.26 → 0.0.29

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/db.json CHANGED
@@ -1 +1,11 @@
1
- [["user:admin",{"type":"user","name":"admin","pass":"01b613da484bee91c3f3806b52a6f40fd61ade874b5ffc0f62a2091cce38158b","id":"user:admin"}]]
1
+ [
2
+ [
3
+ "user:admin",
4
+ {
5
+ "type": "user",
6
+ "name": "admin",
7
+ "pass": "01b613da484bee91c3f3806b52a6f40fd61ade874b5ffc0f62a2091cce38158b",
8
+ "id": "user:admin"
9
+ }
10
+ ]
11
+ ]
package/index.mjs CHANGED
@@ -14,13 +14,15 @@ if (!fs.existsSync(routesfile)) {
14
14
  fs.writeFileSync(routesfile, `import fs from 'node:fs'
15
15
  export default {
16
16
  _debug: ({ r, s, db }) => console.log(r.url, r.method),
17
- '/': ({ s }) => s.end(fs.readFileSync('index.html', 'utf-8')),
17
+ '/': e => e.s.end(fs.readFileSync('index.html', 'utf-8')),
18
+ '/post': ({ e, body }) => db.set(body),
19
+ '/tables': ({s}) => s.endJSON(db.getView(tables, 'user)),
18
20
  'tables': name => ([k, v]) => k.match(name + ':')
19
21
  }`)
20
22
  }
21
23
  if (!fs.existsSync(indexfile)) {
22
24
  fs.writeFileSync(indexfile, `<!DOCTYPE html>
23
-
25
+ <link rel="icon" href="data:,">
24
26
  <script>navigator.serviceWorker.register('sw.js')</script>
25
27
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css'>
26
28
  <script src='https://unpkg.com/enigmatic/enigmatic.js'></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instaserve",
3
- "version": "0.0.26",
3
+ "version": "0.0.29",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "bin": "./index.mjs"
package/test.mjs ADDED
@@ -0,0 +1,22 @@
1
+ import Vast from './vastdb.mjs'
2
+ const db = new Vast()
3
+
4
+ db.views = {
5
+ tables: ([k, v]) => k.match('user')
6
+ }
7
+
8
+ db.triggers = {
9
+ test_trigger: record => record.value = 100
10
+ }
11
+
12
+ db.workflows = {
13
+ 'testwf' : {
14
+ start: db => 'wait_two_sec',
15
+ wait_two_sec: db => new Promise(r => setTimeout(r('end'), 2000)),
16
+ end: db => console.log('done')
17
+ }
18
+ }
19
+
20
+ //console.log(db.getView('tables'))
21
+ db.set({name: 'testrec', value: 0})
22
+ console.log(db)
package/vastdb.mjs CHANGED
@@ -4,6 +4,7 @@ export default class VastDB extends Map {
4
4
  super();
5
5
  this.filename = `${process.cwd()}/db.json`;
6
6
  this.views = v
7
+ this.triggers = []
7
8
  if (!fs.existsSync(this.filename)) {
8
9
  this.set({
9
10
  type: 'user',
@@ -22,21 +23,21 @@ export default class VastDB extends Map {
22
23
  query(q = () => false) {
23
24
  return [...this].filter(q).map(([k, v]) => v)
24
25
  }
25
- getView(name, param) {
26
- const res = [...this].filter(this.views[name](param));
27
- return res.map(([k, v]) => v);
26
+ getView(name) {
27
+ if(!this.views[name]) throw `view ${name} does not exist`
28
+ return this.query(this.views[name])
28
29
  }
29
30
  set(arr) {
30
31
  if (!arr.push) arr = [arr];
31
32
  for (const o of arr) {
32
33
  if (!o.name || !o.type) return false;
33
34
  if (!o.id) o.id = o.type + ':' + o.name;
35
+ this.triggers.map(t => o = t(o))
34
36
  }
35
37
  arr.map((o) => super.set(o.id, o));
36
- if(this.event) this.event(arr)
37
38
  this.save();
38
39
  }
39
40
  save() {
40
- fs.writeFileSync(this.filename, JSON.stringify([...this.entries()]));
41
+ fs.writeFileSync(this.filename, JSON.stringify([...this.entries()], null, 2));
41
42
  }
42
43
  }
package/components.mjs DELETED
@@ -1,5 +0,0 @@
1
- export default {
2
- 'h-w': {
3
- template: 'Hello world'
4
- }
5
- }
package/index.html DELETED
@@ -1,7 +0,0 @@
1
- <!DOCTYPE html>
2
-
3
- <script>navigator.serviceWorker.register('sw.js')</script>
4
- <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css'>
5
- <script src='https://unpkg.com/enigmatic/enigmatic.js'></script>
6
-
7
- <div class='bg-yellow-200'>hello</div>
package/routes.mjs DELETED
@@ -1,5 +0,0 @@
1
- export default {
2
- _debug: ({ r, s, db }) => console.log(r.url, r.method),
3
- '/': ({ s }) => s.end(fs.readFileSync('index.html', 'utf-8')),
4
- 'tables': name => ([k, v]) => k.match(`${name}:`)
5
- }