Skip to content

Commit d287c01

Browse files
authored
feat: Validation for labels (#1062)
* feat: Validation for labels * allow only uppercase for colors * v0.12.17
1 parent 89f9bb4 commit d287c01

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.12.16",
3+
"version": "0.12.17",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/schemas/space.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,41 @@
393393
"additionalProperties": false
394394
}
395395
},
396+
"labels": {
397+
"type": "array",
398+
"maxItems": 100,
399+
"uniqueItems": true,
400+
"items":{
401+
"type": "object",
402+
"properties": {
403+
"id":{
404+
"type": "string",
405+
"title": "Id",
406+
"minLength": 1,
407+
"maxLength": 8
408+
},
409+
"name": {
410+
"type": "string",
411+
"title": "Name",
412+
"minLength": 1,
413+
"maxLength": 32
414+
},
415+
"description": {
416+
"type": "string",
417+
"title": "Description",
418+
"minLength": 1,
419+
"maxLength": 100
420+
},
421+
"color": {
422+
"type": "string",
423+
"title": "Color",
424+
"format": "color"
425+
}
426+
},
427+
"required": ["id", "name", "description", "color"],
428+
"additionalProperties": false
429+
}
430+
},
396431
"parent": {
397432
"type": "string",
398433
"title": "parent"

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ ajv.addFormat('lowercase', {
117117
validate: (value: string) => value === value.toLowerCase()
118118
});
119119

120+
ajv.addFormat('color', {
121+
validate: (value: string) => {
122+
if (!value) return false;
123+
return !!value.match(/^#[0-9A-F]{6}$/);
124+
}
125+
});
126+
120127
ajv.addFormat('ethValue', {
121128
validate: (value: string) => {
122129
if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/)) return false;

test/examples/space.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,23 @@
3030
"name": "basic",
3131
"params": {}
3232
},
33-
"voting":{
33+
"voting": {
3434
"delay": 2592000,
3535
"period": 15552000,
3636
"quorum": 100
37-
}
37+
},
38+
"labels": [
39+
{
40+
"id": "4b6a8c88",
41+
"name": "Test 1",
42+
"description": "Test Description 1",
43+
"color": "#48CB0D"
44+
},
45+
{
46+
"id": "893b2f3",
47+
"name": "Test 2",
48+
"description": "Test Description 2",
49+
"color": "#FBE54E"
50+
}
51+
]
3852
}

0 commit comments

Comments
 (0)