git ssb

0+

Piet / ssb-loomio



Commit d022ea7ba118fcb624a4afe57ec5b1be07d30313

all the changes needed to actually use this module

mix irving committed on 3/8/2018, 10:31:48 AM
Parent: 4360b02f347aa3bea29d3e95dda409fe21bc3c45

Files changed

index.jschanged
lib/inject.jschanged
methods.jschanged
package-lock.jsonchanged
package.jsonchanged
poll/async/chooseOne.jsadded
poll/schema/poll.jschanged
test/poll/async/get.test.jschanged
test/poll/sync/chooseOne.test.jschanged
test/poll/sync/isPoll.test.jschanged
index.jsView
@@ -1,9 +1,12 @@
11 const raw = require('./methods')
22 const PLUGIN_DEPS = ['backlinks']
33
44 const niceMappings = {
5- isPoll: raw.poll.sync.isPoll
5 + isPoll: raw.poll.sync.isPoll,
6 + // publish: {
7 + // chooseOne: raw.poll.async.chooseOne
8 + // }
69 }
710 // by following this pattern you can write your own API
811
912 module.exports = function (server, opts) {
lib/inject.jsView
@@ -1,7 +1,7 @@
11 const { map } = require('libnested')
2-const { onceTrue, watch } = require('mutant')
3-const Struct = require('../struct')
2 +const { onceTrue, watch, Value } = require('mutant')
3 +// const Struct = require('../struct')
44
55 // auto-inject the ssb-server to all methods to reduce repitition
66 module.exports = function inject (server, methods, pluginDeps = []) {
77 switch (typeof server) {
@@ -16,13 +16,14 @@
1616 throw new Error('scuttle-blog expects an ssb server (or obs that contains one)')
1717 }
1818 }
1919
20-function injectObsServer (server, methods, pluginDeps) {
20 +//TODO fix this plugins Deps thing D:
21 +function injectObsServer (server, methods, pluginDeps = []) {
2122 onceTrue(server, server => checkPlugins(server, pluginDeps))
2223
2324 return map(methods, (fn, path) => {
24- if (path[0] === 'async') {
25 + if (path.includes('async')) {
2526 return function () {
2627 onceTrue(
2728 server,
2829 server => fn(server).apply(null, arguments)
@@ -31,10 +32,10 @@
3132 }
3233
3334 // NOTE - both `obs` and `sync` methods will return observeables
3435 return function () {
35- // var result = Value({})
36- var result = Struct({}) // WARNING - this shouldn't be copied for other apps, only works with obs.get method here. Probably breaks sync.isBlog
36 + var result = Value({})
37 + // var result = Struct({}) // WARNING - this shouldn't be copied for other apps, only works with obs.get method here. Probably breaks sync.isBlog
3738 onceTrue(
3839 server,
3940 server => {
4041 var res = fn(server).apply(null, arguments)
@@ -45,9 +46,9 @@
4546 }
4647 })
4748 }
4849
49-function checkPlugins (server) {
50- PLUGIN_DEPS.forEach(p => {
50 +function checkPlugins (server, pluginDeps) {
51 + pluginDeps.forEach(p => {
5152 if (!server[p]) throw new Error(`scuttle-blog needs a scuttlebot server with the ${p} plugin installed`)
5253 })
5354 }
methods.jsView
@@ -2,9 +2,10 @@
22
33 module.exports = {
44 poll: {
55 async: {
6- // publishPoll: require('./async/publishPoll')
6 + chooseOne: require('./poll/async/chooseOne'),
7 + get: require('./poll/async/get')
78 },
89 sync: {
910 isPoll: require('./poll/sync/isPoll')
1011 // Poll: // this is not exported - doesn't follow the inject pattern atm
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 174269 bytes
New file size: 174788 bytes
package.jsonView
@@ -33,8 +33,9 @@
3333 "is-my-json-valid": "^2.17.1",
3434 "isarray": "^2.0.4",
3535 "libnested": "^1.2.1",
3636 "lodash.clonedeep": "^4.5.0",
37 + "mutant": "^3.22.1",
3738 "pull-stream": "^3.6.2",
3839 "ssb-msg-schemas": "^6.3.0",
3940 "ssb-ref": "^2.9.0"
4041 }
poll/async/chooseOne.jsView
@@ -1,0 +1,13 @@
1 +const ChooseOne = require('../sync/chooseOne')
2 +const isPoll = require('../../isPoll')
3 +
4 +module.exports = function (server) {
5 + return function publishChooseOne (opts, cb) {
6 + const poll = ChooseOne(opts)
7 + console.log('poll', poll)
8 + console.log('isChooseOnePoll', require('../../isPoll'))
9 + if (!isPoll.chooseOne(poll)) return cb(isPoll.chooseOne.errors)
10 +
11 + server.publish(poll, cb)
12 + }
13 +}
poll/schema/poll.jsView
@@ -28,9 +28,9 @@
2828 // { $ref: '#/definitions/pollDetails/meeting'},
2929 ]
3030 },
3131 title: { type: 'string' },
32- closesAt: { type: 'integer' },
32 + closesAt: { type: 'string', format: 'date-time' },
3333 body: { type: 'string' },
3434 mentions: { $ref: '#/definitions/mentions/any' },
3535 recps: { $ref: '#/definitions/recps' }
3636 },
test/poll/async/get.test.jsView
@@ -67,7 +67,8 @@
6767 }
6868
6969 function nDaysTime (n) {
7070 var d = new Date()
71- return d.setDate(d.getDate() + n)
72- // returns integer!
71 + d.setDate(d.getDate() + n)
72 +
73 + return d.toISOString()
7374 }
test/poll/sync/chooseOne.test.jsView
@@ -9,9 +9,9 @@
99
1010 var validPoll = ChooseOne({
1111 title: 'how many food',
1212 choices: [1, 2, 'three'],
13- closesAt: Date.now()
13 + closesAt: new Date().toISOString()
1414 })
1515 t.true(isPoll(validPoll), 'simple (passes isPoll)')
1616 t.true(isPoll.chooseOne(validPoll), 'simple (passes isPoll.chooseOne)')
1717
test/poll/sync/isPoll.test.jsView
@@ -7,9 +7,9 @@
77
88 test('Poll - common requirements', function (t) {
99 var missingTitle = ChooseOne({
1010 choices: [1, 2, 'three'],
11- closesAt: Date.now()
11 + closesAt: new Date().toISOString()
1212 })
1313 t.false(isPoll(missingTitle), 'needs title')
1414
1515 var missingClosesAt = ChooseOne({
@@ -17,13 +17,20 @@
1717 title: 'how many food'
1818 })
1919 t.false(isPoll(missingClosesAt), 'needs closes at')
2020
21 + var malformedClosesAt = ChooseOne({
22 + choices: [1, 2, 'three'],
23 + title: 'how many food',
24 + closesAt: 'tomorrow'
25 + })
26 + t.false(isPoll(missingClosesAt), 'needs ISOString closes at')
27 +
2128 var missingDetails = {
2229 type: 'poll',
2330 pollDetails: undefined,
2431 title: 'how many food',
25- closesAt: Date.now()
32 + closesAt: new Date().toISOString()
2633 }
2734 t.false(isPoll(missingDetails), 'needs details')
2835 t.true(isPoll.errors, 'failing validations have errors')
2936
@@ -44,9 +51,9 @@
4451 recps: [
4552 '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519',
4653 {name: 'mix', link: '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519'}
4754 ],
48- closesAt: Date.now()
55 + closesAt: new Date().toISOString()
4956 }
5057 t.true(isPoll(fullyFeatured), 'fully featured')
5158
5259 t.end()

Built with git-ssb-web