Files: 1e4019a1d10553a22d73ae01e3b773a750723c42 / poll.js
2617 bytesRaw
1 | var Validate = require('is-my-json-valid') |
2 | const { msgIdRegex, feedIdRegex, blobIdRegex } = require('ssb-ref') |
3 | |
4 | function create(){} |
5 | |
6 | const schema = { |
7 | $schema: 'http://json-schema.org/schema#', |
8 | type: 'object', |
9 | required: ['type', 'pollType'], |
10 | properties: { |
11 | type: { |
12 | type: 'string', |
13 | pattern: '^poll$' |
14 | }, |
15 | pollType: { |
16 | oneOf: [ |
17 | { $ref: '#/definitions/pollTypes/dot'}, |
18 | { $ref: '#/definitions/pollTypes/proposal'}, |
19 | { $ref: '#/definitions/pollTypes/rsvp'}, |
20 | { $ref: '#/definitions/pollTypes/meeting'}, |
21 | { $ref: '#/definitions/pollTypes/score'}, |
22 | ] |
23 | }, |
24 | text: { type: 'string' }, |
25 | mentions: { |
26 | oneOf: [ |
27 | { type: 'null' }, |
28 | { |
29 | type: 'array', |
30 | items: { |
31 | oneOf: [ |
32 | { $ref: '#/definitions/mentions/message' }, |
33 | { $ref: '#/definitions/mentions/feed' }, |
34 | { $ref: '#/definitions/mentions/blob' } |
35 | ] |
36 | } |
37 | } |
38 | ] |
39 | }, |
40 | recps: { |
41 | oneOf: [ |
42 | { type: 'null' }, |
43 | { |
44 | type: 'array', |
45 | items: { |
46 | oneOf: [ |
47 | { $ref: '#/definitions/feedId' }, |
48 | { $ref: '#/definitions/mentions/feed' }, |
49 | ] |
50 | } |
51 | } |
52 | ] |
53 | } |
54 | }, |
55 | definitions: { |
56 | |
57 | messageId: { |
58 | type: 'string', |
59 | pattern: msgIdRegex |
60 | }, |
61 | feedId: { |
62 | type: 'string', |
63 | pattern: feedIdRegex |
64 | }, |
65 | blobId: { |
66 | type: 'string', |
67 | pattern: blobIdRegex |
68 | }, |
69 | pollTypes: { |
70 | dot: { |
71 | type: 'object', |
72 | required: ['maxStanceScore', 'options'], |
73 | properties: { |
74 | maxStanceScore: { |
75 | type: 'integer', |
76 | minimum: 0 |
77 | }, |
78 | maxChoiceScore: { |
79 | type: 'integer', |
80 | minimum: 0 |
81 | }, |
82 | options: { |
83 | type: 'array', |
84 | } |
85 | } |
86 | } |
87 | }, |
88 | mentions: { |
89 | message: { |
90 | type: 'object', |
91 | required: ['link'], |
92 | properties: { |
93 | link: { $ref: '#/definitions/messageId'} |
94 | } |
95 | }, |
96 | feed: { |
97 | type: 'object', |
98 | required: ['link', 'name'], |
99 | properties: { |
100 | link: { $ref: '#/definitions/feedId'}, |
101 | name: { type: 'string' } |
102 | } |
103 | }, |
104 | blob: { |
105 | type: 'object', |
106 | required: ['link', 'name'], |
107 | properties: { |
108 | link: { $ref: '#/definitions/blobId'}, |
109 | name: { type: 'string' } |
110 | } |
111 | } |
112 | |
113 | } |
114 | }, |
115 | } |
116 | const validate = Validate(schema, { verbose: true }) |
117 | |
118 | module.exports = { |
119 | create, |
120 | schema, |
121 | validate |
122 | } |
123 |
Built with git-ssb-web