Commit 3bc106d06cd050c026b7934dacf2076f6d847894
first pass extracting common ssb schemas
mix irving committed on 3/5/2018, 5:24:52 AMParent: 07a5f24f2034628892c7c9ed0782b63b30fc7911
Files changed
lib/ssbSchemaDefintions.js | added |
poll/schema/poll.js | changed |
position/schema/position.js | changed |
lib/ssbSchemaDefintions.js | ||
---|---|---|
@@ -1,0 +1,41 @@ | ||
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 | + } | |
41 | +} |
poll/schema/poll.js | ||
---|---|---|
@@ -1,11 +1,11 @@ | ||
1 | -const { msgIdRegex, feedIdRegex, blobIdRegex } = require('ssb-ref') | |
2 | - | |
3 | 1 | const dotDetails = require('./details/dot.js') |
4 | 2 | const proposalDetails = require('./details/proposal.js') |
5 | 3 | const scoreDetails = require('./details/score.js') |
6 | 4 | const chooseOneDetails = require('./details/chooseOne.js') |
7 | 5 | |
6 | +const ssbSchemaDefintions = require('../../lib/ssbSchemaDefintions') | |
7 | + | |
8 | 8 | const schema = { |
9 | 9 | $schema: 'http://json-schema.org/schema#', |
10 | 10 | type: 'object', |
11 | 11 | required: ['type', 'pollDetails', 'title', 'closesAt'], |
@@ -60,53 +60,19 @@ | ||
60 | 60 | } |
61 | 61 | ] |
62 | 62 | } |
63 | 63 | }, |
64 | - definitions: { | |
65 | - messageId: { | |
66 | - type: 'string', | |
67 | - pattern: msgIdRegex | |
68 | - }, | |
69 | - feedId: { | |
70 | - type: 'string', | |
71 | - pattern: feedIdRegex | |
72 | - }, | |
73 | - blobId: { | |
74 | - type: 'string', | |
75 | - pattern: blobIdRegex | |
76 | - }, | |
77 | - pollDetails: { | |
78 | - type: 'object', | |
79 | - dot: dotDetails, | |
80 | - proposal: proposalDetails, | |
81 | - score: scoreDetails, | |
82 | - chooseOne: chooseOneDetails | |
83 | - }, | |
84 | - mentions: { | |
85 | - message: { | |
64 | + definitions: Object.assign({}, | |
65 | + ssbSchemaDefintions, | |
66 | + { | |
67 | + pollDetails: { | |
86 | 68 | type: 'object', |
87 | - required: ['link'], | |
88 | - properties: { | |
89 | - link: { $ref: '#/definitions/messageId' } | |
90 | - } | |
91 | - }, | |
92 | - feed: { | |
93 | - type: 'object', | |
94 | - required: ['link', 'name'], | |
95 | - properties: { | |
96 | - link: { $ref: '#/definitions/feedId' }, | |
97 | - name: { type: 'string' } | |
98 | - } | |
99 | - }, | |
100 | - blob: { | |
101 | - type: 'object', | |
102 | - required: ['link', 'name'], | |
103 | - properties: { | |
104 | - link: { $ref: '#/definitions/blobId' }, | |
105 | - name: { type: 'string' } | |
106 | - } | |
69 | + dot: dotDetails, | |
70 | + proposal: proposalDetails, | |
71 | + score: scoreDetails, | |
72 | + chooseOne: chooseOneDetails | |
107 | 73 | } |
108 | 74 | } |
109 | - } | |
75 | + ) | |
110 | 76 | } |
111 | 77 | |
112 | 78 | module.exports = schema |
position/schema/position.js | ||
---|---|---|
@@ -1,8 +1,9 @@ | ||
1 | 1 | const Validate = require('is-my-json-valid') |
2 | -const { msgIdRegex, feedIdRegex, blobIdRegex } = require('ssb-ref') | |
3 | 2 | const chooseOneDetails = require('./details/chooseOne') |
4 | 3 | |
4 | +const ssbSchemaDefintions = require('../../lib/ssbSchemaDefintions') | |
5 | + | |
5 | 6 | const schema = { |
6 | 7 | $schema: 'http://json-schema.org/schema#', |
7 | 8 | type: 'object', |
8 | 9 | required: ['type', 'positionDetails'], |
@@ -18,9 +19,14 @@ | ||
18 | 19 | text: { type: 'string' }, |
19 | 20 | reason: { type: 'string' }, |
20 | 21 | positionDetails: { |
21 | 22 | oneOf: [ |
23 | + // { $ref: '#/definitions/positionDetails/dot'}, | |
24 | + // { $ref: '#/definitions/positionDetails/proposal'}, | |
25 | + // { $ref: '#/definitions/positionDetails/score'}, | |
22 | 26 | { $ref: '#/definitions/positionDetails/chooseOne' } |
27 | + // { $ref: '#/definitions/positionDetails/rsvp'}, | |
28 | + // { $ref: '#/definitions/positionDetails/meeting'}, | |
23 | 29 | ] |
24 | 30 | }, |
25 | 31 | mentions: { |
26 | 32 | oneOf: [ |
@@ -51,70 +57,16 @@ | ||
51 | 57 | } |
52 | 58 | ] |
53 | 59 | } |
54 | 60 | }, |
55 | - definitions: { | |
56 | - | |
57 | - positionDetails: { | |
58 | - type: 'object', | |
59 | - chooseOne: chooseOneDetails | |
60 | - }, | |
61 | - messageId: { | |
62 | - type: 'string', | |
63 | - pattern: msgIdRegex | |
64 | - }, | |
65 | - rootId: { | |
66 | - type: 'string', | |
67 | - pattern: msgIdRegex | |
68 | - }, | |
69 | - branchId: { | |
70 | - oneOf: [ | |
71 | - { | |
72 | - type: 'string', | |
73 | - pattern: msgIdRegex | |
74 | - }, | |
75 | - { | |
76 | - type: 'array', | |
77 | - items: { | |
78 | - type: 'string', | |
79 | - pattern: msgIdRegex | |
80 | - } | |
81 | - } | |
82 | - ] | |
83 | - }, | |
84 | - feedId: { | |
85 | - type: 'string', | |
86 | - pattern: feedIdRegex | |
87 | - }, | |
88 | - blobId: { | |
89 | - type: 'string', | |
90 | - pattern: blobIdRegex | |
91 | - }, | |
92 | - mentions: { | |
93 | - message: { | |
61 | + definitions: Object.assign({}, | |
62 | + ssbSchemaDefintions, | |
63 | + { | |
64 | + positionDetails: { | |
94 | 65 | type: 'object', |
95 | - required: ['link'], | |
96 | - properties: { | |
97 | - link: { $ref: '#/definitions/messageId' } | |
98 | - } | |
99 | - }, | |
100 | - feed: { | |
101 | - type: 'object', | |
102 | - required: ['link', 'name'], | |
103 | - properties: { | |
104 | - link: { $ref: '#/definitions/feedId' }, | |
105 | - name: { type: 'string' } | |
106 | - } | |
107 | - }, | |
108 | - blob: { | |
109 | - type: 'object', | |
110 | - required: ['link', 'name'], | |
111 | - properties: { | |
112 | - link: { $ref: '#/definitions/blobId' }, | |
113 | - name: { type: 'string' } | |
114 | - } | |
66 | + chooseOne: chooseOneDetails | |
115 | 67 | } |
116 | 68 | } |
117 | - } | |
69 | + ) | |
118 | 70 | } |
119 | 71 | |
120 | 72 | module.exports = schema |
Built with git-ssb-web