|
7 | 7 | MailToIRIRegEx |
8 | 8 | UuidRegEx |
9 | 9 | TimestampRegEx |
| 10 | + TimestampRegEx200 |
10 | 11 | xAPIVersionRegEx |
| 12 | + xAPIVersionRegEx200 |
11 | 13 | DurationRegEx |
| 14 | + DurationRegEx200 |
12 | 15 | Sha1RegEx |
13 | 16 | Sha2RegEx]] |
14 | 17 | [clojure.spec.alpha :as s #?@(:cljs [:include-macros true])] |
|
22 | 25 | "When true, coerce 0.95 context activities to conform." |
23 | 26 | true) |
24 | 27 |
|
| 28 | +(def ^:dynamic *xapi-version* |
| 29 | + "xAPI Statement Version to Conform" |
| 30 | + "1.0.3") |
| 31 | + |
25 | 32 | ;; Utils |
26 | 33 |
|
27 | 34 | (def double-conformer |
|
234 | 241 | [timestamp] |
235 | 242 | (letfn [(parse-int [s] #?(:clj (Integer/parseInt s) :cljs (js/parseInt s)))] |
236 | 243 | (let [[ts year month day _hour _min _sec _sec-frac _offset] |
237 | | - (re-matches TimestampRegEx timestamp) |
| 244 | + (re-matches |
| 245 | + (case *xapi-version* |
| 246 | + "1.0.3" TimestampRegEx |
| 247 | + "2.0.0" TimestampRegEx200) |
| 248 | + timestamp) |
238 | 249 | month-int (when month (parse-int month)) |
239 | 250 | year-int (when year (parse-int year)) |
240 | 251 | day-int (when day (parse-int day))] |
|
269 | 280 | (s/def ::duration |
270 | 281 | (s/with-gen |
271 | 282 | (s/and string? |
272 | | - (partial re-matches DurationRegEx)) |
| 283 | + #(re-matches |
| 284 | + (case *xapi-version* |
| 285 | + "1.0.3" DurationRegEx |
| 286 | + "2.0.0" DurationRegEx200) |
| 287 | + %)) |
273 | 288 | #(sgen/fmap (fn [[h m s]] |
274 | 289 | (#?(:clj format |
275 | 290 | :cljs gstring/format) "PT%dH%sM%dS" h m s)) |
|
280 | 295 | (s/def ::version |
281 | 296 | (s/with-gen |
282 | 297 | (s/and string? |
283 | | - (partial re-matches xAPIVersionRegEx)) |
284 | | - #(sgen/return "2.0.0"))) |
| 298 | + #(re-matches |
| 299 | + (case *xapi-version* |
| 300 | + "1.0.3" xAPIVersionRegEx |
| 301 | + "2.0.0" xAPIVersionRegEx200) |
| 302 | + %)) |
| 303 | + #(sgen/return *xapi-version*))) |
285 | 304 |
|
286 | 305 | (s/def ::sha2 |
287 | 306 | (s/with-gen |
|
1015 | 1034 | (s/every ::context-group |
1016 | 1035 | :into [])) |
1017 | 1036 |
|
| 1037 | +;; multispec for dynamic params |
| 1038 | +(defmulti context-version (fn [_] *xapi-version*)) |
| 1039 | + |
| 1040 | +(defmethod context-version "1.0.3" [_] |
| 1041 | + (conform-ns |
| 1042 | + "context" |
| 1043 | + (s/and |
| 1044 | + (s/keys :opt [:context/registration |
| 1045 | + :context/instructor |
| 1046 | + :context/team |
| 1047 | + :context/contextActivities |
| 1048 | + :context/revision |
| 1049 | + :context/platform |
| 1050 | + :context/language |
| 1051 | + :context/statement |
| 1052 | + :context/extensions]) |
| 1053 | + (restrict-keys :context/registration |
| 1054 | + :context/instructor |
| 1055 | + :context/team |
| 1056 | + :context/contextActivities |
| 1057 | + :context/revision |
| 1058 | + :context/platform |
| 1059 | + :context/language |
| 1060 | + :context/statement |
| 1061 | + :context/extensions)))) |
| 1062 | + |
| 1063 | +(defmethod context-version "2.0.0" [_] |
| 1064 | + (conform-ns |
| 1065 | + "context" |
| 1066 | + (s/and |
| 1067 | + (s/keys :opt [:context/registration |
| 1068 | + :context/instructor |
| 1069 | + :context/team |
| 1070 | + :context/contextActivities |
| 1071 | + :context/revision |
| 1072 | + :context/platform |
| 1073 | + :context/language |
| 1074 | + :context/statement |
| 1075 | + :context/extensions |
| 1076 | + :context/contextAgents |
| 1077 | + :context/contextGroups]) |
| 1078 | + (restrict-keys :context/registration |
| 1079 | + :context/instructor |
| 1080 | + :context/team |
| 1081 | + :context/contextActivities |
| 1082 | + :context/revision |
| 1083 | + :context/platform |
| 1084 | + :context/language |
| 1085 | + :context/statement |
| 1086 | + :context/extensions |
| 1087 | + :context/contextAgents |
| 1088 | + :context/contextGroups)))) |
| 1089 | + |
1018 | 1090 | (s/def ::context |
1019 | | - (conform-ns "context" |
1020 | | - (s/and |
1021 | | - (s/keys :opt [:context/registration |
1022 | | - :context/instructor |
1023 | | - :context/team |
1024 | | - :context/contextActivities |
1025 | | - :context/revision |
1026 | | - :context/platform |
1027 | | - :context/language |
1028 | | - :context/statement |
1029 | | - :context/extensions |
1030 | | - :context/contextAgents |
1031 | | - :context/contextGroups]) |
1032 | | - (restrict-keys :context/registration |
1033 | | - :context/instructor |
1034 | | - :context/team |
1035 | | - :context/contextActivities |
1036 | | - :context/revision |
1037 | | - :context/platform |
1038 | | - :context/language |
1039 | | - :context/statement |
1040 | | - :context/extensions |
1041 | | - :context/contextAgents |
1042 | | - :context/contextGroups)))) |
| 1091 | + (s/multi-spec context-version (fn [gen-val _] |
| 1092 | + gen-val) )) |
1043 | 1093 |
|
1044 | 1094 | ;; Attachments |
1045 | 1095 |
|
|
0 commit comments