{"id":23626293,"url":"https://github.com/yetanalytics/xapi-schema","last_synced_at":"2025-04-07T12:10:21.213Z","repository":{"id":31989053,"uuid":"35559543","full_name":"yetanalytics/xapi-schema","owner":"yetanalytics","description":"Clojure(script) schema for the Experience API","archived":false,"fork":false,"pushed_at":"2025-01-09T23:45:29.000Z","size":514,"stargazers_count":23,"open_issues_count":4,"forks_count":8,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-31T11:04:26.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yetanalytics.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-13T16:10:09.000Z","updated_at":"2024-09-24T18:53:12.000Z","dependencies_parsed_at":"2024-01-17T17:37:46.704Z","dependency_job_id":"4b44bebf-11a4-4514-ad3d-0c4f380ecec8","html_url":"https://github.com/yetanalytics/xapi-schema","commit_stats":{"total_commits":339,"total_committers":9,"mean_commits":"37.666666666666664","dds":0.6460176991150443,"last_synced_commit":"00cd10891822bb99e54be0b77b500ca0339730cd"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fxapi-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fxapi-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fxapi-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetanalytics%2Fxapi-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yetanalytics","download_url":"https://codeload.github.com/yetanalytics/xapi-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-27T22:52:49.676Z","updated_at":"2025-04-07T12:10:21.184Z","avatar_url":"https://github.com/yetanalytics.png","language":"Clojure","readme":"#+TITLE: xapi-schema\n#+AUTHOR: Milt Reder\n#+EMAIL: milt@yetanalytics.com\n\n[[https://github.com/yetanalytics/xapi-schema/actions/workflows/main.yml][https://github.com/yetanalytics/xapi-schema/actions/workflows/main.yml/badge.svg]]\n[[https://www.eclipse.org/legal/epl-v10.html][https://img.shields.io/badge/license-Eclipse-blue.svg]]\n[[https://clojars.org/com.yetanalytics/xapi-schema][https://img.shields.io/clojars/v/com.yetanalytics/xapi-schema.svg]]\n\nClojure(script) schema for Experience API 1.0.3. Provides validation of Statements and other xAPI objects.\n\n** Demo\n\nYou can use xapi-schema to validate (and generate) statements in real-time [[http://yetanalytics.github.io/xapi-schema-demo/][with this demo]].\n\n** Getting Started\n1. Add to your project dependencies:\n  #+BEGIN_SRC clojure\n  [[com.yetanalytics/xapi-schema \"1.3.0\"]]\n  #+END_SRC\n2. Require in your project:\n  #+BEGIN_SRC clojure\n    (ns your-project.core\n      (:require [xapi-schema.core :as xs]))\n  #+END_SRC\n\n** Usage\n*** Clojure(script)\n**** Validate a Statement or Statements in edn\n#+BEGIN_SRC clojure\n  (def statement\n    {\"id\" \"fd41c918-b88b-4b20-a0a5-a4c32391aaa0\"\n     \"actor\" {\"objectType\" \"Agent\"\n              \"name\" \"Project Tin Can API\"\n              \"mbox\" \"mailto:user@example.com\"}\n     \"verb\" {\"id\" \"http://example.com/xapi/verbs#sent-a-statement\",\n             \"display\" {\"en-US\" \"sent\"}}\n     \"object\" {\"id\" \"http://example.com/xapi/activity/simplestatement\",\n               \"definition\"\n               {\"name\" {\"en-US\" \"simple statement\"}\n                \"description\"\n                {\"en-US\" \"A simple Experience API statement. Note that the LRS\n                  does not need to have any prior information about the Actor (learner), the\n                  verb, or the Activity/object.\"}}}})\n\n  (xs/validate-statement-data statement) ;; =\u003e returns the statement\n\n  (xs/validate-statement-data [stmt1 stmt2 stmt3]) ;; =\u003e returns the statements\n\n  (let [bad-statement (dissoc statement \"actor\")]\n    (xs/validate-statement-data bad-statement))  ;; =\u003e throws ExceptionInfo\n\n#+END_SRC\n\n**** Validate a Statement from JSON (Clojurescript)\n\n#+BEGIN_SRC clojure\n(let [json-statement (clj-\u003ejs statement)]\n  (xs/validate-statement-data-js json-statement)) ;; =\u003e returns the statement\n#+END_SRC\n\n**** Validate a Statement from a JSON string (Clojure(script))\n\n#+BEGIN_SRC clojure\n(def statement-str\n  \"{\\\"object\\\":{\\\"id\\\":\\\"http://example.com/xapi/activity/simplestatement\\\",\n  \\\"definition\\\":{\\\"name\\\":{\\\"en-US\\\":\\\"simple statement\\\"},\\\"description\\\":\n  {\\\"en-US\\\":\\\"A simple Experience API statement. Note that the LRS\\\\n\n  does not need to have any prior information about the Actor (learner), the\\\\n\n  verb, or the Activity/object.\\\"}}},\\\"verb\\\":{\\\"id\\\":\\\"http://example.com/xapi\n  /verbs#sent-a-statement\\\",\\\"display\\\":{\\\"en-US\\\":\\\"sent\\\"}},\\\"id\\\":\\\"fd41c918-\n  b88b-4b20-a0a5-a4c32391aaa0\\\",\\\"actor\\\":{\\\"mbox\\\":\\\"mailto:user@example.com\\\"\n  ,\\\"name\\\":\\\"Project Tin Can API\\\",\\\"objectType\\\":\\\"Agent\\\"}}\")\n\n(xs/validate-statement-data statement-str) ;; =\u003e returns statement edn\n#+END_SRC\n\n**** 'Check' a Statement\n\nChecking a statement will return nil if it is valid, or a map of errors.\n\n#+BEGIN_SRC clojure\n(xs/statement-checker statement) ;; =\u003e nil\n(let [bad-statement (-\u003e statement\n                        (dissoc \"actor\")\n                        (assoc \"id\" 123)]\n  (xs/statement-checker bad-statement)))\n  ;; =\u003e {:cljs.spec.alpha/problems (...\n#+END_SRC\n\n**** Use SubSchemata\n\nAll of the subschemata in =xapi-schema.spec= are valid [[https://clojure.org/guides/spec][Clojure Specs]]:\n\n#+BEGIN_SRC clojure\n(ns your-project.core\n  (:require [xapi-schema.core :as xs]\n            [xapi-schema.spec :as json]\n            [clojure.spec.alpha :as s]))\n(s/explain-data ::json/agent {\"mbox\" \"mailto:bob@example.com\"}) ;; =\u003e nil\n#+END_SRC\n\n**** Generate Statements\n\nYou can use spec's generation functions to generate conformant statements containing random data:\n\n1. Include the =test.check= dependency:\n  #+BEGIN_SRC clojure\n  [[com.yetanalytics/xapi-schema \"1.0.0-alpha2\"]\n   [org.clojure/test.check \"0.10.0-alpha2\"]]\n  #+END_SRC\n2. Include the extra namespaces and generate!\n  #+BEGIN_SRC clojure\n  (ns your-project.core\n    (:require [xapi-schema.spec :as xapispec]\n              [clojure.spec.alpha :as s :include-macros true]\n              [clojure.spec.gen.alpha :as sgen :include-macros true]\n               clojure.test.check.generators))\n  (sgen/generate (s/gen ::xapispec/statement)) ;; =\u003e {\"actor\" {...\n  #+END_SRC\n\n*** Plain ol' JavaScript\n\nIf you want to use validations from JavaScript, first build the js:\n=$ lein do cljx, cljsbuild once release=. Then include the generated file,\n=target/js/xapi_schema.js= and invoke:\n\n#+BEGIN_SRC javascript\nvar statement_str = '{\"id\":\"fd41c918-b88b-4b20-a0a5-a4c32391aaa0\", \"actor\":{\"objectType\": \"Agent\",\"name\":\"Project Tin Can API\",\"mbox\":\"mailto:user@example.com\"},\"verb\":{\"id\":\"http://example.com/xapi/verbs#sent-a-statement\",\"display\":{ \"en-US\":\"sent\" }},\"object\":{\"id\":\"http://example.com/xapi/activity/simplestatement\",\"definition\":{\"name\":{ \"en-US\":\"simple statement\" },\"description\":{ \"en-US\":\"A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object.\" }}}}';\nvar statement_json = JSON.parse(s);\nxapi_schema.core.validate_statement_data_js(statement_str); // =\u003e statement JSON\nxapi_schema.core.validate_statement_data_js(statement_json); // =\u003e statement JSON\n#+END_SRC\n\n** Testing\n\n*** Clojure\n\n=$ make test-clj=\n\n*** ClojureScript\n\n=$ make test-cljs=\n\n*** Both\n\n=$ make ci=\n\n** License\n\nCopyright © 2015-2024 Yet Analytics, Inc.\n\nDistributed under the Eclipse Public License, the same as Clojure.\nSee the file [[file:LICENSE][LICENSE]] for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetanalytics%2Fxapi-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyetanalytics%2Fxapi-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetanalytics%2Fxapi-schema/lists"}