Commit 6a6f0b821f7d42f8ea24c3bc6b6ad61ce422e8d4
Render patchgraph updates
cel committed on 11/27/2020, 3:27:52 PMParent: 1bf5278d3088c9b366c19937130c030b41c7cee0
Files changed
README.md | changed |
doc/install-guide.html | changed |
lib/render-msg.js | changed |
package.json | changed |
README.md | |||
---|---|---|---|
@@ -81,9 +81,9 @@ | |||
81 | 81 … | ||
82 | 82 … | ```sh | |
83 | 83 … | git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo | |
84 | 84 … | cd patchfoo | |
85 | -ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 | ||
85 … | +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256 | ||
86 | 86 … | npm start | |
87 | 87 … | ``` | |
88 | 88 … | ||
89 | 89 … | #### as a ssb-server plugin | |
@@ -93,9 +93,9 @@ | |||
93 | 93 … | ```sh | |
94 | 94 … | cd ~/.ssb/node_modules | |
95 | 95 … | git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo | |
96 | 96 … | cd patchfoo | |
97 | -ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 | ||
97 … | +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256 | ||
98 | 98 … | node enable-plugin.js | |
99 | 99 … | ``` | |
100 | 100 … | ||
101 | 101 … | ### Install via ssb-npm | |
@@ -117,17 +117,17 @@ | |||
117 | 117 … | ||
118 | 118 … | Note: if you previously installed a patchfoo binary release, [ssb-]npm will not overwrite it. You must manually remove it (e.g. `rm ~/.local/bin/patchfoo`) before installing via ssb-npm. | |
119 | 119 … | ||
120 | 120 … | ```sh | |
121 | -ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 | ||
121 … | +ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256 | ||
122 | 122 … | ``` | |
123 | 123 … | ||
124 | 124 … | ### as a ssb-server plugin | |
125 | 125 … | ||
126 | 126 … | This does a global ssb-npm install and then symlinks it into place and installs it with ssb-server as a plugin. | |
127 | 127 … | ||
128 | 128 … | ```sh | |
129 | -ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 | ||
129 … | +ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256 | ||
130 | 130 … | dir=$(dirname $(realpath $(which patchfoo))) | |
131 | 131 … | ln -s "$dir" ~/.ssb/node_modules/ | |
132 | 132 … | node "$dir/enable-plugin.js" | |
133 | 133 … | ``` |
doc/install-guide.html | ||
---|---|---|
@@ -41,9 +41,9 @@ | ||
41 | 41 … | <h4>As a standalone program (ssb-client):</h4> |
42 | 42 … | <pre> |
43 | 43 … | git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo |
44 | 44 … | cd patchfoo |
45 | -ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 | |
45 … | +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256 | |
46 | 46 … | npm start |
47 | 47 … | </pre> |
48 | 48 … | |
49 | 49 … | <h4>or as a sbot plugin:</h4> |
@@ -51,9 +51,9 @@ | ||
51 | 51 … | mkdir ~/.ssb/node_modules |
52 | 52 … | cd ~/.ssb/node_modules |
53 | 53 … | git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo |
54 | 54 … | cd patchfoo |
55 | -ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 | |
55 … | +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256 | |
56 | 56 … | node enable-plugin.js |
57 | 57 … | </pre> |
58 | 58 … | <p>Restart ssb-server or Patchwork.</p> |
59 | 59 … | <p>Visit patchfoo at <a href="http://localhost:8027/">http://localhost:8027/</a>.</p> |
lib/render-msg.js | ||
---|---|---|
@@ -4,8 +4,9 @@ | ||
4 | 4 … | var u = require('./util') |
5 | 5 … | var mdInline = require('./markdown-inline') |
6 | 6 … | var ssbKeys = require('ssb-keys') |
7 | 7 … | var qs = require('querystring') |
8 … | +var sparql = require('sparqljs') | |
8 | 9 … | |
9 | 10 … | module.exports = RenderMsg |
10 | 11 … | |
11 | 12 … | function RenderMsg(render, app, msg, opts) { |
@@ -391,8 +392,9 @@ | ||
391 | 392 … | case 'ipfstryme': |
392 | 393 … | case 'cesium_geoPoint.lat': |
393 | 394 … | case 'cesium_geoPoint.lon': return this.astroport(cb) |
394 | 395 … | case 'delete': return this.delete(cb) |
396 … | + case 'patchgraph-update': return this.patchgraphUpdate(cb) | |
395 | 397 … | default: return this.object(cb) |
396 | 398 … | } |
397 | 399 … | } |
398 | 400 … | |
@@ -2520,4 +2522,75 @@ | ||
2520 | 2522 … | link |
2521 | 2523 … | ], cb) |
2522 | 2524 … | }) |
2523 | 2525 … | } |
2526 … | + | |
2527 … | +RenderMsg.prototype.rdfLiteral = function (term) { | |
2528 … | + if (term.datatype && term.datatype.termType === 'NamedNode' && | |
2529 … | + term.datatype === 'http://www.w3.org/2001/XMLSchema#string') { | |
2530 … | + return h('div', {innerHTML: term.value}) | |
2531 … | + } | |
2532 … | + return this.valueTable(term.value, 2, function () {}) | |
2533 … | +} | |
2534 … | + | |
2535 … | +RenderMsg.prototype.rdfTerm = function (term) { | |
2536 … | + switch (term.termType) { | |
2537 … | + case 'Literal': return this.rdfLiteral(term) | |
2538 … | + case 'NamedNode': return this.valueTable(term.value, 2, function () {}) | |
2539 … | + default: return this.valueTable(term, 2, function () {}) | |
2540 … | + } | |
2541 … | +} | |
2542 … | + | |
2543 … | +RenderMsg.prototype.patchgraphUpdate = function (cb) { | |
2544 … | + var self = this | |
2545 … | + var query | |
2546 … | + try { | |
2547 … | + var parser = new sparql.Parser() | |
2548 … | + query = parser.parse(self.c.value) | |
2549 … | + } catch(e) { | |
2550 … | + return self.wrap(h('div', [ | |
2551 … | + h('div', 'patchgraph update:'), | |
2552 … | + h('pre', u.toString(self.c.value)) | |
2553 … | + ]), cb) | |
2554 … | + } | |
2555 … | + | |
2556 … | + if (query && query.type === 'update' && Array.isArray(query.updates) | |
2557 … | + && query.updates.every(function (update) { | |
2558 … | + return update && update.updateType === 'insert' | |
2559 … | + && Array.isArray(update.insert) | |
2560 … | + && update.insert.every(function (insert) { | |
2561 … | + return insert.type === 'bgp' | |
2562 … | + && Array.isArray(insert.triples) | |
2563 … | + }) | |
2564 … | + })) { | |
2565 … | + var triples = [] | |
2566 … | + query.updates.forEach(function (update) { | |
2567 … | + update.insert.forEach(function (insert) { | |
2568 … | + insert.triples.forEach(function (triple) { | |
2569 … | + triples.push(triple) | |
2570 … | + }) | |
2571 … | + }) | |
2572 … | + }) | |
2573 … | + return self.wrap(h('div', [ | |
2574 … | + h('div', 'patchgraph insert:'), | |
2575 … | + h('table.ssb-object', [ | |
2576 … | + h('tr', [ | |
2577 … | + h('th', 'subject'), | |
2578 … | + h('th', 'predicate'), | |
2579 … | + h('th', 'object') | |
2580 … | + ]), | |
2581 … | + triples.map(function (triple) { | |
2582 … | + return h('tr', [ | |
2583 … | + h('td', self.rdfTerm(triple.subject)), | |
2584 … | + h('td', self.rdfTerm(triple.predicate)), | |
2585 … | + h('td', self.rdfTerm(triple.object)), | |
2586 … | + ]) | |
2587 … | + }) | |
2588 … | + ]), | |
2589 … | + ]), cb) | |
2590 … | + } | |
2591 … | + | |
2592 … | + self.wrap(h('div', [ | |
2593 … | + h('div', 'patchgraph update:'), | |
2594 … | + self.valueTable(query, 1, function () {}) | |
2595 … | + ]), cb) | |
2596 … | +} |
package.json | ||
---|---|---|
@@ -30,8 +30,9 @@ | ||
30 | 30 … | "pull-reader": "^1.2.9", |
31 | 31 … | "pull-split": "^0.2.0", |
32 | 32 … | "pull-stream": "^3.5.0", |
33 | 33 … | "pull-utf8-decoder": "^1.0.2", |
34 … | + "sparqljs": "^3.2.0", | |
34 | 35 … | "ssb-client": "^4.7.8", |
35 | 36 … | "ssb-git": "^1.1.0", |
36 | 37 … | "ssb-markdown": "^6.0.0", |
37 | 38 … | "ssb-mentions": "^0.5.0", |
Built with git-ssb-web