{"id":17467308,"url":"https://github.com/kwijibo/changeset-sparql","last_synced_at":"2025-03-28T09:20:22.424Z","repository":{"id":57196922,"uuid":"87228631","full_name":"kwijibo/changeset-sparql","owner":"kwijibo","description":"applies a changeset via SPARQL Update","archived":false,"fork":false,"pushed_at":"2017-12-17T09:39:55.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T11:03:19.254Z","etag":null,"topics":["changeset","javascript","rdf","sparql"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kwijibo.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2017-04-04T19:50:25.000Z","updated_at":"2017-04-05T14:21:25.000Z","dependencies_parsed_at":"2022-09-16T10:50:35.343Z","dependency_job_id":null,"html_url":"https://github.com/kwijibo/changeset-sparql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwijibo%2Fchangeset-sparql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwijibo%2Fchangeset-sparql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwijibo%2Fchangeset-sparql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwijibo%2Fchangeset-sparql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kwijibo","download_url":"https://codeload.github.com/kwijibo/changeset-sparql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245999651,"owners_count":20707575,"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":["changeset","javascript","rdf","sparql"],"created_at":"2024-10-18T14:23:38.397Z","updated_at":"2025-03-28T09:20:22.408Z","avatar_url":"https://github.com/kwijibo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# changeset-sparql\nApplies a changeset via SPARQL Update\n/\n```\nnpm install changeset-sparql\n```\n\n#### Usage: \n\n\nFirst we make a changeset:\n\n```\nconst EX = 'http://example.info/'\nconst changeset = {\n    // an array of triples/quads to add\n     add: [{s: EX+'123', p: EX+'count', o_value: 0, o_type:'literal', o_datatype: EX+'integer', g: EX+'graphs/graph-name'}]\n    // triples/quads to remove (changeset will fail if they don't exist)\n   , remove: [{s: EX+'987', p: EX+'message',  o_value: \"Hello\", o_type:'literal', o_lang: 'en-gb'}]\n    // the URIs of the latest changesets for each subject we want to change\n   , previous: [\"urn:hash:sha1:jkhjkhkj2kjh3\", \"urn:hash:sha1:mnwejkljh7898c\"],\n\n}\n```\n\nNow we define two functions, one to do SPARQL queries, and one to do SPARQL updates. \n\nEach function should take two arguments: a query/update and a \"Node-style\" (`(err, data)=\u003e`) callback\n\n```\nconst request = require('request')\n\nconst endpoint = 'http://localhost:3030/TestData'\n\nconst query = (q, callback) =\u003e request({\n    url: endpoint+'/sparql',\n    body: q,\n    method: 'POST',\n    headers: {\n        'Accept': 'application/sparql-results+json',\n        'Content-type': 'application/sparql-query'\n    }\n}, (err, data)=\u003e err? callback(err) : callback(null, JSON.parse(data.body)))\n\nconst update = (q, callback) =\u003e request({\n    url: endpoint+'/update',\n    body: q,\n    method: 'POST',\n    headers: {\n        'Accept': 'application/sparql-results+json',\n        'Content-type': 'application/sparql-update'\n    }\n}, callback)\n\n```\n\nNow we pass those functions to `changsetSparql`, and get back a function that accepts a changeset, and a dictionary of callbacks:\n\n```\nconst changsetSparql = require('changeset-sparql')(query, update)\n```\n\n```\nchangsetSparql(changeset, {\n    error: console.error,\n    rejected: console.error,\n    ok: console.log\n})\n\n```\n- `error` Gets called with an error if there are problems running the updates or queries (ie: if `query` or `update` call the callback with an error). You may want to retry if this happens.\n- `rejected` gets called with an error message if the changeset was rejected. This happens if:\n    - the `previous` changeset URI given wasn't the latest changeset for that resource\n    - any `delete` triples/quads don't exist in the dataset.\n    You should not retry, but you may want to alter the changeset and resubmit.\n- `ok` Gets called with the URI of the changeset if:\n    - The update was successfully applied\n    - The changeset was already applied\n \n### Changeset Object Specification\n\n- *add*: optional, must be an Array of quads to be added to the dataset\n- *remove*: optional, must be an Array of quads to be removed from the dataset\n- *previous*: optional, must be an Array of URIs of latest changesets of each _subject_ \n\n#### Triple/Quad Specification\n\n(format of the objects in the `add` and `remove` Arrays)\n\n- *s*: required, URI (subject)\n- *p*: required, URI (predicate/property)\n- *o_value*: required (object value)\n- *o_type*: required, must be `uri` OR `literal`\n- *o_lang*: optional, must be valid language tag\n- *o_datatype*: optional, URI\n- *g*: optional, URI (graph)\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwijibo%2Fchangeset-sparql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwijibo%2Fchangeset-sparql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwijibo%2Fchangeset-sparql/lists"}