Commit fb405437d59c9c1d0fb22d32e745ae27cad05e24
Strip out all the things
Piet Geursen committed on 3/15/2018, 2:12:27 AMParent: 9144ab97554ad603dd57ff8d50d81940ac397cc6
Files changed
NOTES.md | ||
---|---|---|
@@ -21,8 +21,8 @@ | ||
21 | 21 | - Decorate |
22 | 22 | - Opinionated folder structure. Human readable API. |
23 | 23 | - Testing |
24 | 24 | - Linting with ale |
25 | -- Give your test files *.test.js filenames. It helps with readability when there are errors. | |
25 | +- Give your test files `*.test.js` filenames. It helps with readability when there are errors. | |
26 | 26 | - the inject pattern |
27 | 27 | - prefer passing a single object rather than ordered args |
28 | 28 | - don't modify data passed into a function |
lib/ssbSchemaDefintions.js | ||
---|---|---|
@@ -1,70 +1,0 @@ | ||
1 | -const { msgIdRegex, feedIdRegex, blobIdRegex } = require('ssb-ref') | |
2 | - | |
3 | -module.exports = { | |
4 | - messageId: { | |
5 | - type: 'string', | |
6 | - pattern: msgIdRegex | |
7 | - }, | |
8 | - feedId: { | |
9 | - type: 'string', | |
10 | - pattern: feedIdRegex | |
11 | - }, | |
12 | - blobId: { | |
13 | - type: 'string', | |
14 | - pattern: blobIdRegex | |
15 | - }, | |
16 | - mentions: { | |
17 | - message: { | |
18 | - type: 'object', | |
19 | - required: ['link'], | |
20 | - properties: { | |
21 | - link: { $ref: '#/definitions/messageId' } | |
22 | - } | |
23 | - }, | |
24 | - feed: { | |
25 | - type: 'object', | |
26 | - required: ['link', 'name'], | |
27 | - properties: { | |
28 | - link: { $ref: '#/definitions/feedId' }, | |
29 | - name: { type: 'string' } | |
30 | - } | |
31 | - }, | |
32 | - blob: { | |
33 | - type: 'object', | |
34 | - required: ['link', 'name'], | |
35 | - properties: { | |
36 | - link: { $ref: '#/definitions/blobId' }, | |
37 | - name: { type: 'string' } | |
38 | - } | |
39 | - }, | |
40 | - any: { | |
41 | - oneOf: [ | |
42 | - { type: 'null' }, | |
43 | - { | |
44 | - type: 'array', | |
45 | - items: { | |
46 | - oneOf: [ | |
47 | - { $ref: '#/definitions/mentions/message' }, | |
48 | - { $ref: '#/definitions/mentions/feed' }, | |
49 | - { $ref: '#/definitions/mentions/blob' } | |
50 | - ] | |
51 | - } | |
52 | - } | |
53 | - ] | |
54 | - } | |
55 | - }, | |
56 | - recps: { | |
57 | - oneOf: [ | |
58 | - { type: 'null' }, | |
59 | - { | |
60 | - type: 'array', | |
61 | - items: { | |
62 | - oneOf: [ | |
63 | - { $ref: '#/definitions/feedId' }, | |
64 | - { $ref: '#/definitions/mentions/feed' } | |
65 | - ] | |
66 | - } | |
67 | - } | |
68 | - ] | |
69 | - } | |
70 | -} |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 174754 bytes New file size: 193125 bytes |
package.json | ||
---|---|---|
@@ -36,7 +36,8 @@ | ||
36 | 36 | "lodash.clonedeep": "^4.5.0", |
37 | 37 | "mutant": "^3.22.1", |
38 | 38 | "pull-stream": "^3.6.2", |
39 | 39 | "ssb-msg-schemas": "^6.3.0", |
40 | + "ssb-poll-schema": "^1.0.1", | |
40 | 41 | "ssb-ref": "^2.9.0" |
41 | 42 | } |
42 | 43 | } |
poll/sync/isChooseOnePoll.js | ||
---|---|---|
@@ -1,16 +1,0 @@ | ||
1 | -const Validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/chooseOnePoll') | |
3 | -const validator = Validator(schema, {verbose: true}) | |
4 | -const getMsgContent = require('../../lib/getMsgContent') | |
5 | - | |
6 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
7 | -module.exports = function (server) { | |
8 | - return function isChooseOnePoll (obj) { | |
9 | - const result = validator(getMsgContent(obj)) | |
10 | - | |
11 | - // exposes error messages provided by is-my-json-valid | |
12 | - isChooseOnePoll.errors = validator.errors | |
13 | - | |
14 | - return result | |
15 | - } | |
16 | -} |
poll/sync/isPoll.js | ||
---|---|---|
@@ -1,25 +1,0 @@ | ||
1 | -const Validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/poll') | |
3 | -const validator = Validator(schema, {verbose: true}) | |
4 | -const getMsgContent = require('../../lib/getMsgContent') | |
5 | -const { CHOOSE_ONE } = require('../../types') | |
6 | - | |
7 | -const isChooseOnePoll = require('./isChooseOnePoll')() | |
8 | - | |
9 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
10 | -module.exports = function (server) { | |
11 | - function isPoll (obj) { | |
12 | - const result = validator(getMsgContent(obj)) | |
13 | - | |
14 | - // exposes error messages provided by is-my-json-valid | |
15 | - isPoll.errors = validator.errors | |
16 | - | |
17 | - return result | |
18 | - } | |
19 | - | |
20 | - isPoll[CHOOSE_ONE] = isChooseOnePoll | |
21 | - // isPoll[DOT] = isDotPoll | |
22 | - // isPoll[SCORE] = isScorePoll | |
23 | - | |
24 | - return isPoll | |
25 | -} |
poll/schema/chooseOnePoll.js | ||
---|---|---|
@@ -1,9 +1,0 @@ | ||
1 | -const pollSchema = require('./poll') | |
2 | -const cloneDeep = require('lodash.clonedeep') | |
3 | - | |
4 | -const chooseOneSchema = cloneDeep(pollSchema) | |
5 | - | |
6 | -// collapse the details down to be ONLY chooseOne | |
7 | -chooseOneSchema.properties.details = { $ref: '#/definitions/details/chooseOne' } | |
8 | - | |
9 | -module.exports = chooseOneSchema |
poll/schema/details/chooseOne.js | ||
---|---|---|
@@ -1,18 +1,0 @@ | ||
1 | -const { CHOOSE_ONE } = require('../../../types') | |
2 | -const typeStringPattern = `^${CHOOSE_ONE}$` | |
3 | - | |
4 | -var schema = { | |
5 | - type: 'object', | |
6 | - required: ['type', 'choices'], | |
7 | - properties: { | |
8 | - type: { | |
9 | - type: 'string', | |
10 | - pattern: typeStringPattern | |
11 | - }, | |
12 | - choices: { | |
13 | - type: 'array' | |
14 | - } | |
15 | - } | |
16 | -} | |
17 | - | |
18 | -module.exports = schema |
poll/schema/details/dot.js | ||
---|---|---|
@@ -1,19 +1,0 @@ | ||
1 | -var schema = { | |
2 | - type: 'object', | |
3 | - required: ['type', 'maxStanceScore', 'choices'], | |
4 | - properties: { | |
5 | - type: { | |
6 | - type: 'string', | |
7 | - pattern: '^dot$' | |
8 | - }, | |
9 | - numDots: { | |
10 | - type: 'integer', | |
11 | - minimum: 1 | |
12 | - }, | |
13 | - choices: { | |
14 | - type: 'array' | |
15 | - } | |
16 | - } | |
17 | -} | |
18 | - | |
19 | -module.exports = schema |
poll/schema/details/proposal.js | ||
---|---|---|
@@ -1,15 +1,0 @@ | ||
1 | -var schema = { | |
2 | - type: 'object', | |
3 | - required: ['type', 'proposal'], | |
4 | - properties: { | |
5 | - type: { | |
6 | - type: 'string', | |
7 | - pattern: '^proposal$' | |
8 | - }, | |
9 | - proposal: { | |
10 | - type: 'string' | |
11 | - } | |
12 | - } | |
13 | -} | |
14 | - | |
15 | -module.exports = schema |
poll/schema/details/score.js | ||
---|---|---|
@@ -1,19 +1,0 @@ | ||
1 | -const schema = { | |
2 | - type: 'object', | |
3 | - required: ['type', 'maxChoiceScore', 'choices'], | |
4 | - properties: { | |
5 | - type: { | |
6 | - type: 'string', | |
7 | - pattern: '^score$' | |
8 | - }, | |
9 | - maxChoiceScore: { | |
10 | - type: 'integer', | |
11 | - minimum: 2 | |
12 | - }, | |
13 | - choices: { | |
14 | - type: 'array' | |
15 | - } | |
16 | - } | |
17 | -} | |
18 | - | |
19 | -module.exports = schema |
poll/schema/poll.js | ||
---|---|---|
@@ -1,48 +1,0 @@ | ||
1 | -const dotDetails = require('./details/dot.js') | |
2 | -const proposalDetails = require('./details/proposal.js') | |
3 | -const scoreDetails = require('./details/score.js') | |
4 | -const chooseOneDetails = require('./details/chooseOne.js') | |
5 | - | |
6 | -const ssbSchemaDefintions = require('../../lib/ssbSchemaDefintions') | |
7 | - | |
8 | -const schema = { | |
9 | - $schema: 'http://json-schema.org/schema#', | |
10 | - type: 'object', | |
11 | - required: ['type', 'details', 'title', 'closesAt'], | |
12 | - properties: { | |
13 | - version: { | |
14 | - type: 'string', | |
15 | - pattern: '^0.1.0$' | |
16 | - }, | |
17 | - type: { | |
18 | - type: 'string', | |
19 | - pattern: '^poll$' | |
20 | - }, | |
21 | - details: { | |
22 | - oneOf: [ | |
23 | - // { $ref: '#/definitions/details/dot'}, | |
24 | - // { $ref: '#/definitions/details/proposal'}, | |
25 | - // { $ref: '#/definitions/details/score'}, | |
26 | - { $ref: '#/definitions/details/chooseOne' } | |
27 | - // { $ref: '#/definitions/details/rsvp'}, | |
28 | - // { $ref: '#/definitions/details/meeting'}, | |
29 | - ] | |
30 | - }, | |
31 | - title: { type: 'string' }, | |
32 | - closesAt: { type: 'string', format: 'date-time' }, | |
33 | - body: { type: 'string' }, | |
34 | - mentions: { $ref: '#/definitions/mentions/any' }, | |
35 | - recps: { $ref: '#/definitions/recps' } | |
36 | - }, | |
37 | - definitions: Object.assign({}, ssbSchemaDefintions, { | |
38 | - details: { | |
39 | - type: 'object', | |
40 | - dot: dotDetails, | |
41 | - proposal: proposalDetails, | |
42 | - score: scoreDetails, | |
43 | - chooseOne: chooseOneDetails | |
44 | - } | |
45 | - }) | |
46 | -} | |
47 | - | |
48 | -module.exports = schema |
position/sync/isChooseOnePosition.js | ||
---|---|---|
@@ -1,16 +1,0 @@ | ||
1 | -const Validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/chooseOnePosition') | |
3 | -const validator = Validator(schema, {verbose: true}) | |
4 | -const getMsgContent = require('../../lib/getMsgContent') | |
5 | - | |
6 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
7 | -module.exports = function (server) { | |
8 | - return function isChooseOnePosition (obj) { | |
9 | - const result = validator(getMsgContent(obj)) | |
10 | - | |
11 | - // exposes error messages provided by is-my-json-valid | |
12 | - isChooseOnePosition.errors = validator.errors | |
13 | - | |
14 | - return result | |
15 | - } | |
16 | -} |
position/sync/isPosition.js | ||
---|---|---|
@@ -1,23 +1,0 @@ | ||
1 | -const validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/position') | |
3 | -const isPositionContent = validator(schema, {verbose: true}) | |
4 | -const getMsgContent = require('../../lib/getMsgContent') | |
5 | -const { CHOOSE_ONE } = require('../../types') | |
6 | - | |
7 | -const isChooseOnePosition = require('./isChooseOnePosition')() | |
8 | - | |
9 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
10 | -module.exports = function (server) { | |
11 | - function isPosition (obj) { | |
12 | - const result = isPositionContent(getMsgContent(obj)) | |
13 | - | |
14 | - // exposes error messages provided by is-my-json-valid | |
15 | - isPosition.errors = isPositionContent.errors | |
16 | - | |
17 | - return result | |
18 | - } | |
19 | - | |
20 | - isPosition[CHOOSE_ONE] = isChooseOnePosition | |
21 | - | |
22 | - return isPosition | |
23 | -} |
position/schema/chooseOnePosition.js | ||
---|---|---|
@@ -1,9 +1,0 @@ | ||
1 | -const positionSchema = require('./position') | |
2 | -const cloneDeep = require('lodash.clonedeep') | |
3 | - | |
4 | -const chooseOneSchema = cloneDeep(positionSchema) | |
5 | - | |
6 | -// collapse the details down to be ONLY chooseOne | |
7 | -chooseOneSchema.properties.details = { $ref: '#/definitions/details/chooseOne' } | |
8 | - | |
9 | -module.exports = chooseOneSchema |
position/schema/details/chooseOne.js | ||
---|---|---|
@@ -1,19 +1,0 @@ | ||
1 | -const { CHOOSE_ONE } = require('../../../types') | |
2 | -const typeStringPattern = `^${CHOOSE_ONE}$` | |
3 | - | |
4 | -var schema = { | |
5 | - type: 'object', | |
6 | - required: ['type', 'choice'], | |
7 | - properties: { | |
8 | - type: { | |
9 | - type: 'string', | |
10 | - pattern: typeStringPattern | |
11 | - }, | |
12 | - choice: { | |
13 | - type: 'integer', | |
14 | - minimum: 0 | |
15 | - } | |
16 | - } | |
17 | -} | |
18 | - | |
19 | -module.exports = schema |
position/schema/position.js | ||
---|---|---|
@@ -1,45 +1,0 @@ | ||
1 | -const Validate = require('is-my-json-valid') | |
2 | -const chooseOneDetails = require('./details/chooseOne') | |
3 | - | |
4 | -const ssbSchemaDefintions = require('../../lib/ssbSchemaDefintions') | |
5 | - | |
6 | -const schema = { | |
7 | - $schema: 'http://json-schema.org/schema#', | |
8 | - type: 'object', | |
9 | - required: ['type', 'root', 'details'], | |
10 | - properties: { | |
11 | - version: { | |
12 | - type: 'string', | |
13 | - pattern: '^0.1.0$' | |
14 | - }, | |
15 | - type: { | |
16 | - type: 'string', | |
17 | - pattern: '^position$' | |
18 | - }, | |
19 | - root: { | |
20 | - $ref: '#/definitions/messageId' | |
21 | - }, | |
22 | - text: { type: 'string' }, | |
23 | - reason: { type: 'string' }, | |
24 | - details: { | |
25 | - oneOf: [ | |
26 | - // { $ref: '#/definitions/details/dot'}, | |
27 | - // { $ref: '#/definitions/details/proposal'}, | |
28 | - // { $ref: '#/definitions/details/score'}, | |
29 | - { $ref: '#/definitions/details/chooseOne' } | |
30 | - // { $ref: '#/definitions/details/rsvp'}, | |
31 | - // { $ref: '#/definitions/details/meeting'}, | |
32 | - ] | |
33 | - }, | |
34 | - mentions: { $ref: '#/definitions/mentions/any' }, | |
35 | - recps: { $ref: '#/definitions/recps' } | |
36 | - }, | |
37 | - definitions: Object.assign({}, ssbSchemaDefintions, { | |
38 | - details: { | |
39 | - type: 'object', | |
40 | - chooseOne: chooseOneDetails | |
41 | - } | |
42 | - }) | |
43 | -} | |
44 | - | |
45 | -module.exports = schema |
test/poll/sync/isPoll.test.js | ||
---|---|---|
@@ -1,60 +1,0 @@ | ||
1 | -const test = require('tape') | |
2 | -const ChooseOne = require('../../../poll/sync/chooseOne') | |
3 | -const isPoll = require('../../../isPoll') | |
4 | -const { CHOOSE_ONE } = require('../../../types') | |
5 | - | |
6 | -// this is for testing the attributes that are required for all polls | |
7 | - | |
8 | -test('Poll - common requirements', function (t) { | |
9 | - var missingTitle = ChooseOne({ | |
10 | - choices: [1, 2, 'three'], | |
11 | - closesAt: new Date().toISOString() | |
12 | - }) | |
13 | - t.false(isPoll(missingTitle), 'needs title') | |
14 | - | |
15 | - var missingClosesAt = ChooseOne({ | |
16 | - choices: [1, 2, 'three'], | |
17 | - title: 'how many food' | |
18 | - }) | |
19 | - t.false(isPoll(missingClosesAt), 'needs closes at') | |
20 | - | |
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 | - | |
28 | - var missingDetails = { | |
29 | - type: 'poll', | |
30 | - details: undefined, | |
31 | - title: 'how many food', | |
32 | - closesAt: new Date().toISOString() | |
33 | - } | |
34 | - t.false(isPoll(missingDetails), 'needs details') | |
35 | - t.true(isPoll.errors, 'failing validations have errors') | |
36 | - | |
37 | - var fullyFeatured = { | |
38 | - type: 'poll', | |
39 | - details: { | |
40 | - type: CHOOSE_ONE, | |
41 | - title: 'how many dogs?', | |
42 | - choices: [1, 2, 3] | |
43 | - }, | |
44 | - title: 'how many food', | |
45 | - body: 'this is really important, please let me know', | |
46 | - mentions: [ | |
47 | - {name: 'mix', link: '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519'}, | |
48 | - {name: 'sweet drawing', link: '&mwILr7kd1Tug/4vX5nW6YORhyununwkO4cF6jbiSyoA=.sha256'}, | |
49 | - {link: '%s8uVi560mwpE8ncjT+eMz5XBQBREdk4exvM3D6dIg9g=.sha256'} | |
50 | - ], | |
51 | - recps: [ | |
52 | - '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519', | |
53 | - {name: 'mix', link: '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519'} | |
54 | - ], | |
55 | - closesAt: new Date().toISOString() | |
56 | - } | |
57 | - t.true(isPoll(fullyFeatured), 'fully featured') | |
58 | - | |
59 | - t.end() | |
60 | -}) |
test/position/sync/isPosition.test.js | ||
---|---|---|
@@ -1,25 +1,0 @@ | ||
1 | -const test = require('tape') | |
2 | -const isPosition = require('../../../isPosition') | |
3 | -const { CHOOSE_ONE } = require('../../../types') | |
4 | - | |
5 | -// this is for testing the attributes that are required for all polls | |
6 | -test('position - common requirements', function (t) { | |
7 | - var missingDetails = { | |
8 | - type: 'position', | |
9 | - poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256', | |
10 | - details: undefined | |
11 | - } | |
12 | - t.false(isPosition(missingDetails), 'needs details') | |
13 | - t.true(isPosition.errors, 'failing validations have errors') | |
14 | - | |
15 | - var missingPoll = { | |
16 | - type: 'position', | |
17 | - details: { | |
18 | - type: CHOOSE_ONE, | |
19 | - choice: 0 | |
20 | - } | |
21 | - } | |
22 | - t.false(isPosition(missingPoll), 'needs poll') | |
23 | - | |
24 | - t.end() | |
25 | -}) |
test/errors/sync/index.test.js | ||
---|---|---|
@@ -1,71 +1,0 @@ | ||
1 | -const test = require('tape') | |
2 | -const pull = require('pull-stream') | |
3 | -const pullAsync = require('pull-async') | |
4 | - | |
5 | -const isPositionChoiceError = require('../../../errors/sync/isPositionChoiceError')() | |
6 | -const isPositionLateError = require('../../../errors/sync/isPositionLateError')() | |
7 | -const isPositionTypeError = require('../../../errors/sync/isPositionTypeError')() | |
8 | - | |
9 | -const PositionTypeError = require('../../../errors/sync/positionTypeError') | |
10 | -const PositionLateError = require('../../../errors/sync/positionLateError') | |
11 | -const PositionChoiceError = require('../../../errors/sync/positionChoiceError') | |
12 | - | |
13 | -const ChooseOne = require('../../../position/async/chooseOne')() | |
14 | - | |
15 | -test('positionTypeError', function (t) { | |
16 | - pull( | |
17 | - pullAsync(cb => { | |
18 | - ChooseOne({ | |
19 | - poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256', | |
20 | - choice: 0 | |
21 | - }, cb) | |
22 | - }), | |
23 | - pull.drain(validPosition => { | |
24 | - var invalidError = PositionTypeError({}) | |
25 | - t.false(isPositionTypeError(invalidError), 'catches invalid error') | |
26 | - | |
27 | - var validError = PositionTypeError({position: validPosition}) | |
28 | - t.true(isPositionTypeError(validError), 'validates valid error') | |
29 | - t.end() | |
30 | - }) | |
31 | - | |
32 | - ) | |
33 | -}) | |
34 | - | |
35 | -test('positionLateError', function (t) { | |
36 | - pull( | |
37 | - pullAsync(cb => { | |
38 | - ChooseOne({ | |
39 | - poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256', | |
40 | - choice: 0 | |
41 | - }, cb) | |
42 | - }), | |
43 | - pull.drain(validPosition => { | |
44 | - var invalidError = PositionLateError({}) | |
45 | - t.false(isPositionTypeError(invalidError), 'catches invalid error') | |
46 | - | |
47 | - var validError = PositionLateError({position: validPosition}) | |
48 | - t.true(isPositionLateError(validError), 'validates valid error') | |
49 | - t.end() | |
50 | - }) | |
51 | - ) | |
52 | -}) | |
53 | - | |
54 | -test('positionChoiceError', function (t) { | |
55 | - pull( | |
56 | - pullAsync(cb => { | |
57 | - ChooseOne({ | |
58 | - poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256', | |
59 | - choice: 0 | |
60 | - }, cb) | |
61 | - }), | |
62 | - pull.drain(validPosition => { | |
63 | - var invalidError = PositionChoiceError({}) | |
64 | - t.false(isPositionChoiceError(invalidError), 'catches invalid error') | |
65 | - | |
66 | - var validError = PositionChoiceError({position: validPosition}) | |
67 | - t.true(isPositionChoiceError(validError), 'validates valid error') | |
68 | - t.end() | |
69 | - }) | |
70 | - ) | |
71 | -}) |
errors/schema/positionChoiceError.js | ||
---|---|---|
@@ -1,9 +1,0 @@ | ||
1 | -const errorSchema = require('./positionError') | |
2 | -const cloneDeep = require('lodash.clonedeep') | |
3 | - | |
4 | -const schema = cloneDeep(errorSchema) | |
5 | - | |
6 | -// collapse the details down to be ONLY choice error | |
7 | -schema.properties.type = { $ref: '#/definitions/errorTypes/errorChoice' } | |
8 | - | |
9 | -module.exports = schema |
errors/schema/positionError.js | ||
---|---|---|
@@ -1,39 +1,0 @@ | ||
1 | -const { ERROR_POSITION_CHOICE, ERROR_POSITION_TYPE, ERROR_POSITION_LATE } = require('../../types') | |
2 | - | |
3 | -var schema = { | |
4 | - type: 'object', | |
5 | - required: ['type', 'position', 'message'], | |
6 | - properties: { | |
7 | - type: { | |
8 | - oneOf: [ | |
9 | - { $ref: '#/definitions/errorTypes/errorChoice' }, | |
10 | - { $ref: '#/definitions/errorTypes/errorTypes' }, | |
11 | - { $ref: '#/definitions/errorTypes/errorLate' } | |
12 | - ] | |
13 | - }, | |
14 | - position: { | |
15 | - type: 'object' | |
16 | - }, | |
17 | - message: { | |
18 | - type: 'string' | |
19 | - }, | |
20 | - definitions: { | |
21 | - errorTypes: { | |
22 | - errorChoice: { | |
23 | - type: 'string', | |
24 | - pattern: `^${ERROR_POSITION_CHOICE}$` | |
25 | - }, | |
26 | - errorType: { | |
27 | - type: 'string', | |
28 | - pattern: `^${ERROR_POSITION_TYPE}$` | |
29 | - }, | |
30 | - errorLate: { | |
31 | - type: 'string', | |
32 | - pattern: `^${ERROR_POSITION_LATE}$` | |
33 | - } | |
34 | - } | |
35 | - } | |
36 | - } | |
37 | -} | |
38 | - | |
39 | -module.exports = schema |
errors/schema/positionLateError.js | ||
---|---|---|
@@ -1,9 +1,0 @@ | ||
1 | -const errorSchema = require('./positionError') | |
2 | -const cloneDeep = require('lodash.clonedeep') | |
3 | - | |
4 | -const schema = cloneDeep(errorSchema) | |
5 | - | |
6 | -// collapse the details down to be ONLY late error | |
7 | -schema.properties.type = { $ref: '#/definitions/errorTypes/errorLate' } | |
8 | - | |
9 | -module.exports = schema |
errors/schema/positionTypeError.js | ||
---|---|---|
@@ -1,9 +1,0 @@ | ||
1 | -const errorSchema = require('./positionError') | |
2 | -const cloneDeep = require('lodash.clonedeep') | |
3 | - | |
4 | -const schema = cloneDeep(errorSchema) | |
5 | - | |
6 | -// collapse the details down to be ONLY type error | |
7 | -schema.properties.type = { $ref: '#/definitions/errorTypes/errorType' } | |
8 | - | |
9 | -module.exports = schema |
errors/sync/isPositionChoiceError.js | ||
---|---|---|
@@ -1,15 +1,0 @@ | ||
1 | -const Validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/positionChoiceError') | |
3 | -const validator = Validator(schema, {verbose: true}) | |
4 | - | |
5 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
6 | -module.exports = function (server) { | |
7 | - return function isError (obj) { | |
8 | - const result = validator(obj) | |
9 | - | |
10 | - // exposes error messages provided by is-my-json-valid | |
11 | - isError.errors = validator.errors | |
12 | - | |
13 | - return result | |
14 | - } | |
15 | -} |
errors/sync/isPositionLateError.js | ||
---|---|---|
@@ -1,15 +1,0 @@ | ||
1 | -const Validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/positionLateError') | |
3 | -const validator = Validator(schema, {verbose: true}) | |
4 | - | |
5 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
6 | -module.exports = function (server) { | |
7 | - return function isError (obj) { | |
8 | - const result = validator(obj) | |
9 | - | |
10 | - // exposes error messages provided by is-my-json-valid | |
11 | - isError.errors = validator.errors | |
12 | - | |
13 | - return result | |
14 | - } | |
15 | -} |
errors/sync/isPositionTypeError.js | ||
---|---|---|
@@ -1,15 +1,0 @@ | ||
1 | -const Validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/positionTypeError') | |
3 | -const validator = Validator(schema, {verbose: true}) | |
4 | - | |
5 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
6 | -module.exports = function (server) { | |
7 | - return function isError (obj) { | |
8 | - const result = validator(obj) | |
9 | - | |
10 | - // exposes error messages provided by is-my-json-valid | |
11 | - isError.errors = validator.errors | |
12 | - | |
13 | - return result | |
14 | - } | |
15 | -} |
errors/sync/isPostionError.js | ||
---|---|---|
@@ -1,15 +1,0 @@ | ||
1 | -const Validator = require('is-my-json-valid') | |
2 | -const schema = require('../schema/postionError') | |
3 | -const validator = Validator(schema, {verbose: true}) | |
4 | - | |
5 | -// server is not used here. Closure pattern is just for consistency of use with other functions. | |
6 | -module.exports = function (server) { | |
7 | - return function isError (obj) { | |
8 | - const result = validator(obj) | |
9 | - | |
10 | - // exposes error messages provided by is-my-json-valid | |
11 | - isError.errors = validator.errors | |
12 | - | |
13 | - return result | |
14 | - } | |
15 | -} |
errors/sync/positionChoiceError.js | ||
---|---|---|
@@ -1,6 +1,0 @@ | ||
1 | -var { ERROR_POSITION_CHOICE } = require('../../types') | |
2 | -var Error = require('./positionError') | |
3 | - | |
4 | -module.exports = function ({position}) { | |
5 | - return Error({type: ERROR_POSITION_CHOICE, position, message: 'Postion choice was not a valid choice for the poll'}) | |
6 | -} |
errors/sync/positionError.js | ||
---|---|---|
@@ -1,5 +1,0 @@ | ||
1 | -module.exports = function PositionError ({type, position, message}) { | |
2 | - var error = {type, position, message} | |
3 | - | |
4 | - return error | |
5 | -} |
errors/sync/positionLateError.js | ||
---|---|---|
@@ -1,6 +1,0 @@ | ||
1 | -var { ERROR_POSITION_LATE } = require('../../types') | |
2 | -var Error = require('./positionError') | |
3 | - | |
4 | -module.exports = function ({position}) { | |
5 | - return Error({type: ERROR_POSITION_LATE, position, message: 'Postion stated after the poll closed'}) | |
6 | -} |
errors/sync/positionTypeError.js | ||
---|---|---|
@@ -1,6 +1,0 @@ | ||
1 | -var { ERROR_POSITION_TYPE } = require('../../types') | |
2 | -var Error = require('./positionError') | |
3 | - | |
4 | -module.exports = function ({position}) { | |
5 | - return Error({type: ERROR_POSITION_TYPE, position, message: 'Postion stated was the wrong type for this poll'}) | |
6 | -} |
isPoll.js | ||
---|---|---|
@@ -1,1 +1,0 @@ | ||
1 | -module.exports = require('./poll/sync/isPoll')() |
isPosition.js | ||
---|---|---|
@@ -1,1 +1,0 @@ | ||
1 | -module.exports = require('./position/sync/isPosition')() |
Built with git-ssb-web