git ssb

0+

Piet / ssb-loomio



Tree: e602c7f5b93b901ece225fec5f2fc495eeaed73d

Files: e602c7f5b93b901ece225fec5f2fc495eeaed73d / schema / position.js

2829 bytesRaw
1const Validate = require('is-my-json-valid')
2const { msgIdRegex, feedIdRegex, blobIdRegex } = require('ssb-ref')
3// what would a message look like?
4//
5// well for a chooseOne:
6// {
7// pollId: msgId,
8// choice: 'apple', //what if this is a key? Or a key and index number? I wonder if this is an argument for making each choice a separate message?
9// reason: "I don't like doctorbs",
10// }
11// When do the various validations happen?
12// - when we're counting votes. We need to check it's a valid position for the type of poll
13// - when we try and create the vote?
14//
15// Can a schema always capture the types we need. Max stance score is 1 for a chooseOne.
16
17const schema = {
18 $schema: 'http://json-schema.org/schema#',
19 type: 'object',
20 required: ['root', 'branch'],
21 properties: {
22 version: {
23 type: 'string',
24 pattern: '^0.1.0$'
25 },
26 type: {
27 type: 'string',
28 pattern: '^position$'
29 },
30 text: { type: 'string' },
31 mentions: {
32 oneOf: [
33 { type: 'null' },
34 {
35 type: 'array',
36 items: {
37 oneOf: [
38 { $ref: '#/definitions/mentions/message' },
39 { $ref: '#/definitions/mentions/feed' },
40 { $ref: '#/definitions/mentions/blob' }
41 ]
42 }
43 }
44 ]
45 },
46 recps: {
47 oneOf: [
48 { type: 'null' },
49 {
50 type: 'array',
51 items: {
52 oneOf: [
53 { $ref: '#/definitions/feedId' },
54 { $ref: '#/definitions/mentions/feed' }
55 ]
56 }
57 }
58 ]
59 }
60 },
61 definitions: {
62
63 messageId: {
64 type: 'string',
65 pattern: msgIdRegex
66 },
67 rootId: {
68 type: 'string',
69 pattern: msgIdRegex
70 },
71 branchId: {
72 oneOf: [
73 {
74 type: 'string',
75 pattern: msgIdRegex
76 },
77 {
78 type: 'array',
79 items: {
80 type: 'string',
81 pattern: msgIdRegex
82 }
83 }
84 ]
85 },
86 feedId: {
87 type: 'string',
88 pattern: feedIdRegex
89 },
90 blobId: {
91 type: 'string',
92 pattern: blobIdRegex
93 },
94 mentions: {
95 message: {
96 type: 'object',
97 required: ['link'],
98 properties: {
99 link: { $ref: '#/definitions/messageId'}
100 }
101 },
102 feed: {
103 type: 'object',
104 required: ['link', 'name'],
105 properties: {
106 link: { $ref: '#/definitions/feedId'},
107 name: { type: 'string' }
108 }
109 },
110 blob: {
111 type: 'object',
112 required: ['link', 'name'],
113 properties: {
114 link: { $ref: '#/definitions/blobId'},
115 name: { type: 'string' }
116 }
117 }
118 }
119 }
120}
121
122const validate = Validate(schema, { verbose: true })
123
124module.exports = {
125 schema,
126 validate
127}
128

Built with git-ssb-web