{"id":27603808,"url":"https://github.com/constraintautomaton/cache-query-triple-project","last_synced_at":"2025-04-22T19:19:41.042Z","repository":{"id":283695598,"uuid":"948530184","full_name":"constraintAutomaton/cache-query-triple-project","owner":"constraintAutomaton","description":"A TypeScript library for working with remote SPARQL query result caches.","archived":false,"fork":false,"pushed_at":"2025-04-10T14:20:54.000Z","size":228,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-22T19:19:37.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sparql-cache-client","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/constraintAutomaton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-03-14T13:55:09.000Z","updated_at":"2025-04-10T14:20:57.000Z","dependencies_parsed_at":"2025-03-21T16:55:38.920Z","dependency_job_id":"71a95ce2-63c9-4f8f-8b15-742504b20bed","html_url":"https://github.com/constraintAutomaton/cache-query-triple-project","commit_stats":null,"previous_names":["constraintautomaton/cache-query-triple-project"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constraintAutomaton%2Fcache-query-triple-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constraintAutomaton%2Fcache-query-triple-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constraintAutomaton%2Fcache-query-triple-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constraintAutomaton%2Fcache-query-triple-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/constraintAutomaton","download_url":"https://codeload.github.com/constraintAutomaton/cache-query-triple-project/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306602,"owners_count":21408927,"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":"2025-04-22T19:19:40.475Z","updated_at":"2025-04-22T19:19:41.032Z","avatar_url":"https://github.com/constraintAutomaton.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sparql-cache-client\n\n\n![npm version](https://img.shields.io/npm/v/sparql-cache-client)\n![Unit Tests Status](https://img.shields.io/github/actions/workflow/status/constraintAutomaton/cache-query-triple-project/ci.yml?label=unit+test\n)\n![Lint](https://img.shields.io/github/actions/workflow/status/constraintAutomaton/cache-query-triple-project/format.yml?label=linter\n)\n\nA TypeScript library for working with remote SPARQL query result caches.\n\nIt allows you to:\n\n- Parse and inspect SPARQL query caches\n- Define custom cache-hit strategies\n- Retrieve cached query results (as URLs or bindings)\n\n## Instalation\n\n```bash\nnpm i sparql-cache-client\n```\n\n## Cache format\n\nThe cache is expected to be in an RDF serialization and respect the [vocabulary of the example below](./cache_example.ttl). \n\n```ttl\n\u003c#Nu2rZB\u003e a \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QueryForm\u003e, \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QuerySelect\u003e, \u003chttp://www.w3.org/ns/shacl#SPARQLExecutable\u003e;\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#query\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/Nu2rZB.rq\u003e;\n    \u003chttp://www.w3.org/ns/shacl#select\u003e \"SELECT DISTINCT ?p WHERE {\\n\\t?s ?p ?o .\\n}LIMIT 10\";\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/Nu2rZB.json\u003e;\n    \u003chttp://www.w3.org/ns/sparql-service-description#endpoint\u003e \u003c#384404ed-bbc7-4f35-a4e3-efa7c31b518a\u003e;\n    \u003chttp://purl.org/dc/terms/created\u003e \"2025-04-09T11:17:29.434Z\"^^\u003chttp://www.w3.org/2001/XMLSchema#dateTime\u003e.\n\u003c#384404ed-bbc7-4f35-a4e3-efa7c31b518a\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#first\u003e \u003chttps://sparql.rhea-db.org/sparql/\u003e;\n    \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#rest\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#nil\u003e.\n\u003c#C7ialK\u003e a \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QueryForm\u003e, \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QuerySelect\u003e, \u003chttp://www.w3.org/ns/shacl#SPARQLExecutable\u003e;\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#query\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/C7ialK.rq\u003e;\n    \u003chttp://www.w3.org/ns/shacl#select\u003e \"PREFIX rh: \u003chttp://rdf.rhea-db.org/\u003e\\nPREFIX taxon: \u003chttp://purl.uniprot.org/taxonomy/\u003e\\nPREFIX up: \u003chttp://purl.uniprot.org/core/\u003e\\nSELECT ?uniprot ?mnemo ?rhea ?accession ?equation \\nWHERE {\\n\\tSERVICE \u003chttps://sparql.uniprot.org/sparql\u003e {\\n\\t\\tVALUES (?taxid) { (taxon:83333) }\\n\\t\\tGRAPH \u003chttp://sparql.uniprot.org/uniprot\u003e {\\n\\t\\t\\t?uniprot up:reviewed true .\\n\\t\\t\\t?uniprot up:mnemonic ?mnemo .\\n\\t\\t\\t?uniprot up:organism ?taxid .\\n\\t\\t\\t?uniprot up:annotation/up:catalyticActivity/up:catalyzedReaction ?rhea .\\n\\t\\t}\\n\\t}\\n\\t?rhea rh:accession ?accession .\\n\\t?rhea rh:equation ?equation .\\n}\";\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/C7ialK.json\u003e;\n    \u003chttp://www.w3.org/ns/sparql-service-description#endpoint\u003e \u003c#1b7d61ea-d142-4be2-8e9b-b3b7f117b9ae\u003e;\n    \u003chttp://purl.org/dc/terms/created\u003e \"2025-04-09T11:19:23.986Z\"^^\u003chttp://www.w3.org/2001/XMLSchema#dateTime\u003e;\n    \u003chttps://purl.expasy.org/sparql-examples/ontology#federatesWith\u003e \u003chttps://sparql.uniprot.org/sparql\u003e.\n\u003c#1b7d61ea-d142-4be2-8e9b-b3b7f117b9ae\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#first\u003e \u003chttps://sparql.rhea-db.org/sparql/\u003e;\n    \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#rest\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#nil\u003e.\n\u003c#qeSzrD\u003e a \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QueryForm\u003e, \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QuerySelect\u003e, \u003chttp://www.w3.org/ns/shacl#SPARQLExecutable\u003e;\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#query\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/qeSzrD.rq\u003e;\n    \u003chttp://www.w3.org/ns/shacl#select\u003e \"PREFIX rh: \u003chttp://rdf.rhea-db.org/\u003e\\nPREFIX taxon: \u003chttp://purl.uniprot.org/taxonomy/\u003e\\nPREFIX up: \u003chttp://purl.uniprot.org/core/\u003e\\nSELECT ?uniprot ?mnemo ?rhea ?accession ?equation \\nWHERE {\\n\\t{\\n\\t\\tVALUES (?taxid) { (taxon:83333) }\\n\\t\\tGRAPH \u003chttp://sparql.uniprot.org/uniprot\u003e {\\n\\t\\t\\t?uniprot up:reviewed true .\\n\\t\\t\\t?uniprot up:mnemonic ?mnemo .\\n\\t\\t\\t?uniprot up:organism ?taxid .\\n\\t\\t\\t?uniprot up:annotation/up:catalyticActivity/up:catalyzedReaction ?rhea .\\n\\t\\t}\\n\\t}\\n\\t?rhea rh:accession ?accession .\\n\\t?rhea rh:equation ?equation .\\n}\";\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/qeSzrD.json\u003e;\n    \u003chttp://www.w3.org/ns/sparql-service-description#endpoint\u003e \u003c#25892f49-953b-4742-be4f-c2431ee7f758\u003e;\n    \u003chttp://purl.org/dc/terms/created\u003e \"2025-04-09T11:21:05.649Z\"^^\u003chttp://www.w3.org/2001/XMLSchema#dateTime\u003e.\n\u003c#25892f49-953b-4742-be4f-c2431ee7f758\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#first\u003e \u003chttps://sparql.rhea-db.org/sparql/\u003e;\n    \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#rest\u003e \u003c#a5c4faeb-3f1a-45bb-b246-ccc93e563a61\u003e.\n\u003c#a5c4faeb-3f1a-45bb-b246-ccc93e563a61\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#first\u003e \u003chttps://sparql.uniprot.org/sparql\u003e;\n    \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#rest\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#nil\u003e.\n\u003c#385VC2\u003e a \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QueryForm\u003e, \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#QuerySelect\u003e, \u003chttp://www.w3.org/ns/shacl#SPARQLExecutable\u003e;\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-query#query\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/385VC2.rq\u003e;\n    \u003chttp://www.w3.org/ns/shacl#select\u003e \"SELECT DISTINCT ?p WHERE {\\n\\t?s ?p ?o .\\n}LIMIT 10\";\n    \u003chttp://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result\u003e \u003chttps://triple.ilabt.imec.be/test/querycache/385VC2.json\u003e;\n    \u003chttp://www.w3.org/ns/sparql-service-description#endpoint\u003e \u003c#79ab3c14-89ac-4bd1-b45b-bff650405ac0\u003e;\n    \u003chttp://purl.org/dc/terms/created\u003e \"2025-04-09T11:24:11.307Z\"^^\u003chttp://www.w3.org/2001/XMLSchema#dateTime\u003e.\n\u003c#79ab3c14-89ac-4bd1-b45b-bff650405ac0\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#first\u003e \u003chttps://triple.ilabt.imec.be/test/\u003e;\n    \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#rest\u003e \u003chttp://www.w3.org/1999/02/22-rdf-syntax-ns#nil\u003e.\n```\n\n## Usage\n\n**We rely on the [`result-interface`](https://www.npmjs.com/package/result-interface) and [`sparqlalgebrajs`](https://www.npmjs.com/package/sparqlalgebrajs) libraries in the examples**\n\nUse `parseCache` to load a Cache file:\n\n```ts\nimport { parseCache } from 'sparql-cache-client';\nimport { isError } from 'result-interface';\n\nconst cacheUrl = \"https://triple.ilabt.imec.be/test/querycache/queries.ttl\";\n\n// Retrieve and parse the cache\nconst response = await parseCache(cacheUrl);\n\n// Handle error response if any\nif (isError(response)) {\n    console.error(`Unable to retrieve cache. Reason: ${response.error}`);\n    process.exit(1);\n}\n\n// Log the entries in the cache\nconsole.log(`The cache contains ${response.value.size} entries:`);\n\nfor (const [endpoint, cachedQueries] of response.value) {\n    console.log(`- ${endpoint}`);\n    let i = 0;\n    for (const cacheInfo of cachedQueries.values()) {\n        console.log(`\\t[q${i}]: ${JSON.stringify(cacheInfo)}`);\n        i++;\n    }\n}\n```\nUse `getCachedQuads` to query a cache with a custom cache hit algorithm:\n\n```ts\nimport { Algebra, toSparql, translate } from 'sparqlalgebrajs';\nimport {\n  CacheHitFunction,\n  getCachedQuads,\n  IOptions,\n  OutputOption,\n  type ICacheQueryInput\n} from 'sparql-cache-client';\nimport { isError, SafePromise } from 'result-interface';\n\nconst CACHE_URL = 'https://triple.ilabt.imec.be/test/querycache/queries.ttl';\n\n// Query that we looking into the cache\nconst query = translate(`\n  PREFIX rh: \u003chttp://rdf.rhea-db.org/\u003e\n  PREFIX taxon: \u003chttp://purl.uniprot.org/taxonomy/\u003e\n  PREFIX up: \u003chttp://purl.uniprot.org/core/\u003e\n  SELECT ?uniprot ?mnemo ?rhea ?accession ?equation \n  WHERE {\n    SERVICE \u003chttps://sparql.uniprot.org/sparql\u003e {\n      VALUES (?taxid) { (taxon:83333) }\n      GRAPH \u003chttp://sparql.uniprot.org/uniprot\u003e {\n        ?uniprot up:reviewed true .\n        ?uniprot up:mnemonic ?mnemo .\n        ?uniprot up:organism ?taxid .\n        ?uniprot up:annotation/up:catalyticActivity/up:catalyzedReaction ?rhea .\n      }\n    }\n    ?rhea rh:accession ?accession .\n    ?rhea rh:equation ?equation .\n  }\n`);\n\n// Simple cache hit function: checks structural equality via SPARQL string comparison\nconst simpleCacheHit: CacheHitFunction = async (\n  q1: Readonly\u003cAlgebra.Operation\u003e,\n  q2: Readonly\u003cAlgebra.Operation\u003e,\n  _options?: IOptions\n): SafePromise\u003cboolean\u003e =\u003e {\n  return {\n    value: toSparql(q1) === toSparql(q2)\n  };\n};\n\nconst input: ICacheQueryInput = {\n  cache: CACHE_URL,\n  query,\n  // Only includes non-SERVICE endpoint(s)\n  endpoints: ['https://sparql.rhea-db.org/sparql/'],\n  cacheHitAlgorithms: [\n    {\n      algorithm: simpleCacheHit,\n      time_limit: 1_000 // 1 second\n    }\n  ],\n  maxConcurentExecCacheHitAlgorithm: undefined,\n  // Request the URL of the cached result (instead of full result bindings)\n  outputOption: OutputOption.URL\n};\n\nconst cacheResult = await getCachedQuads(input);\n\nif (isError(cacheResult)) {\n  console.error(`Failed to access cache: ${cacheResult.error}`);\n  process.exit(1);\n}\n\nconsole.log(`Cache result is available at: ${cacheResult.value?.cache}`);\n\n```\n\n\n## Testing\n\n```\nbun test\n```\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more information.\n\n## Idea\n\n- Make the parsing of cache work with local files\n- Give the option to start reading the cache while it is parsing\n- Give the option to use web worker to run the cache hit algorithms","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstraintautomaton%2Fcache-query-triple-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconstraintautomaton%2Fcache-query-triple-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstraintautomaton%2Fcache-query-triple-project/lists"}