Commit

Author:

Hash:

Timestamp:

+31 -34 +/-1 browse

Kevin Schoon [me@kevinschoon.com]

1fb9cc7d11edb5716906262944ce303f11145487

Sun, 07 Dec 2025 17:39:32 +0000 (11 hours ago)

continued cleanup of verifier.js
1diff --git a/static/verifier.js b/static/verifier.js
2index 0e2429d..4f4ab75 100644
3--- a/static/verifier.js
4+++ b/static/verifier.js
5 @@ -18,19 +18,43 @@ function newRecorder() {
6 }
7
8 // TODO
9- function constraint(kind, values = []) {
10+ function constraint(kind, values) {
11 if (kind == Kind.HREF) {
12- function check_href() {
13- // TODO
14+ function check_href(object, recorder) {
15+ if (!('href' in object)) {
16+ recorder.error(Kind.HREF, object, "href not in link",)
17+ }
18+ if (URL.parse(object["href"]) == null) {
19+ recorder.error(Kind.HREF, object, "href value is not a parsable URL: " + object["href"]);
20+ }
21+ recorder.ok(Kind.HREF, object);
22 };
23 return { kind: Kind.HREF, check: check_href }
24 } else if (kind == Kind.PROPERTIES) {
25- function check_properties() {
26- // TODO
27+ function check_properties(object, recorder) {
28+ if (!('properties' in object)) {
29+ recorder.error(Kind.PROPERTIES, object, "properties not present in link");
30+ };
31+ let properties = object['properties'];
32+ let keys = Object.keys(values);
33+ for (let i = 0; i < values.length; i++) {
34+ let name = keys[i];
35+ if (!(name in properties)) {
36+ recorder.error(Kind.PROPERTIES, object, "Missing property: " + name);
37+ };
38+ // TODO check values
39+ }
40+ recorder.ok(Kind.PROPERTIES, object);
41+ return null;
42 };
43 return { kind: Kind.PROPERTIES, check: check_properties }
44 } else if (kind == Kind.TITLES) {
45- function check_titles() { };
46+ function check_titles(object, recorder) {
47+ if (!('titles' in object)) {
48+ recorder.error(Kind.TITLES, object, "titles not present in object");
49+ };
50+ recorder.ok(Kind.TITLES, object);
51+ };
52 return { kind: Kind.TITLES, check: check_titles }
53 }
54 }
55 @@ -38,34 +62,7 @@ function constraint(kind, values = []) {
56 function validateLink(object, recorder, constraints = []) {
57 for (let i = 0; i < constraints.length; i++) {
58 let constraint = constraints[i];
59- if (constraint.kind == Kind.HREF) {
60- if (!('href' in object)) {
61- recorder.error(Kind.HREF, object, "href not in link",)
62- continue;
63- }
64- recorder.ok(Kind.HREF, object);
65- if ('check' in constraint) {
66- constraint.check(object["properties"], recorder);
67- };
68- } else if (constraint.kind == Kind.PROPERTIES) {
69- if (!('properties' in object)) {
70- recorder.error(Kind.PROPERTIES, object, "properties not present in link");
71- continue;
72- };
73- recorder.ok(Kind.PROPERTIES, object);
74- if ('check' in constraint) {
75- constraint.check(object["properties"], recorder);
76- };
77- } else if (constraint.kind == Kind.TITLES) {
78- if (!('titles' in object)) {
79- recorder.error(Kind.TITLES, object, "titles not present in object");
80- continue;
81- };
82- recorder.ok(Kind.TITLES, object);
83- if ('check' in constraint) {
84- constraint.check(object["titles"], recorder);
85- };
86- }
87+ constraint.check(object, recorder);
88 }
89 }
90