git ssb

16+

cel / patchfoo



Commit 6a6f0b821f7d42f8ea24c3bc6b6ad61ce422e8d4

Render patchgraph updates

cel committed on 11/27/2020, 3:27:52 PM
Parent: 1bf5278d3088c9b366c19937130c030b41c7cee0

Files changed

README.mdchanged
doc/install-guide.htmlchanged
lib/render-msg.jschanged
package.jsonchanged
README.mdView
@@ -81,9 +81,9 @@
8181
8282 ```sh
8383 git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo
8484 cd patchfoo
85-ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256
85 +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256
8686 npm start
8787 ```
8888
8989 #### as a ssb-server plugin
@@ -93,9 +93,9 @@
9393 ```sh
9494 cd ~/.ssb/node_modules
9595 git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo
9696 cd patchfoo
97-ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256
97 +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256
9898 node enable-plugin.js
9999 ```
100100
101101 ### Install via ssb-npm
@@ -117,17 +117,17 @@
117117
118118 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.
119119
120120 ```sh
121-ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256
121 +ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256
122122 ```
123123
124124 ### as a ssb-server plugin
125125
126126 This does a global ssb-npm install and then symlinks it into place and installs it with ssb-server as a plugin.
127127
128128 ```sh
129-ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256
129 +ssb-npm install -g patchfoo --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256
130130 dir=$(dirname $(realpath $(which patchfoo)))
131131 ln -s "$dir" ~/.ssb/node_modules/
132132 node "$dir/enable-plugin.js"
133133 ```
doc/install-guide.htmlView
@@ -41,9 +41,9 @@
4141 <h4>As a standalone program (ssb-client):</h4>
4242 <pre>
4343 git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo
4444 cd patchfoo
45-ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256
45 +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256
4646 npm start
4747 </pre>
4848
4949 <h4>or as a sbot plugin:</h4>
@@ -51,9 +51,9 @@
5151 mkdir ~/.ssb/node_modules
5252 cd ~/.ssb/node_modules
5353 git clone ssb://%YAg1hicat+2GELjE2QJzDwlAWcx0ML+1sXEdsWwvdt8=.sha256 patchfoo
5454 cd patchfoo
55-ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256
55 +ssb-npm install --production --branch %HWJLkLhiapPIaWn2yBOsFIeLNwyrYdSn/Z8cDqiBBi4=.sha256 --branch %eNFBTxGjgxmiQMzNUnHrQqXuBmZ8lwdwlnCbvSG8Rb0=.sha256
5656 node enable-plugin.js
5757 </pre>
5858 <p>Restart ssb-server or Patchwork.</p>
5959 <p>Visit patchfoo at <a href="http://localhost:8027/">http://localhost:8027/</a>.</p>
lib/render-msg.jsView
@@ -4,8 +4,9 @@
44 var u = require('./util')
55 var mdInline = require('./markdown-inline')
66 var ssbKeys = require('ssb-keys')
77 var qs = require('querystring')
8 +var sparql = require('sparqljs')
89
910 module.exports = RenderMsg
1011
1112 function RenderMsg(render, app, msg, opts) {
@@ -391,8 +392,9 @@
391392 case 'ipfstryme':
392393 case 'cesium_geoPoint.lat':
393394 case 'cesium_geoPoint.lon': return this.astroport(cb)
394395 case 'delete': return this.delete(cb)
396 + case 'patchgraph-update': return this.patchgraphUpdate(cb)
395397 default: return this.object(cb)
396398 }
397399 }
398400
@@ -2520,4 +2522,75 @@
25202522 link
25212523 ], cb)
25222524 })
25232525 }
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.jsonView
@@ -30,8 +30,9 @@
3030 "pull-reader": "^1.2.9",
3131 "pull-split": "^0.2.0",
3232 "pull-stream": "^3.5.0",
3333 "pull-utf8-decoder": "^1.0.2",
34 + "sparqljs": "^3.2.0",
3435 "ssb-client": "^4.7.8",
3536 "ssb-git": "^1.1.0",
3637 "ssb-markdown": "^6.0.0",
3738 "ssb-mentions": "^0.5.0",

Built with git-ssb-web