{"id":13554466,"url":"https://github.com/LDflex/Query-Solid","last_synced_at":"2025-04-03T07:31:29.564Z","repository":{"id":43897934,"uuid":"149042124","full_name":"LDflex/Query-Solid","owner":"LDflex","description":"Simple access to data in Solid pods through LDflex expressions","archived":false,"fork":false,"pushed_at":"2022-02-14T00:57:23.000Z","size":38559,"stargazers_count":65,"open_issues_count":28,"forks_count":15,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-05-11T12:04:23.636Z","etag":null,"topics":["running-code"],"latest_commit_sha":null,"homepage":"https://solid.github.io/query-ldflex/","language":"JavaScript","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/LDflex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-16T22:47:16.000Z","updated_at":"2024-04-23T18:29:49.000Z","dependencies_parsed_at":"2022-08-03T00:15:12.947Z","dependency_job_id":null,"html_url":"https://github.com/LDflex/Query-Solid","commit_stats":null,"previous_names":["solid/query-ldflex"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LDflex%2FQuery-Solid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LDflex%2FQuery-Solid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LDflex%2FQuery-Solid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LDflex%2FQuery-Solid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LDflex","download_url":"https://codeload.github.com/LDflex/Query-Solid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246956453,"owners_count":20860440,"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":["running-code"],"created_at":"2024-08-01T12:02:48.377Z","updated_at":"2025-04-03T07:31:29.236Z","avatar_url":"https://github.com/LDflex.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"# LDflex for Solid\nSimple access to data in [Solid](https://solidproject.org/) pods\nthrough [LDflex](https://github.com/RubenVerborgh/LDflex) expressions\n\n[![npm version](https://img.shields.io/npm/v/@solid/query-ldflex.svg)](https://www.npmjs.com/package/@solid/query-ldflex)\n[![Build Status](https://travis-ci.com/solid/query-ldflex.svg?branch=master)](https://travis-ci.com/solid/query-ldflex)\n[![Coverage Status](https://coveralls.io/repos/github/solid/query-ldflex/badge.svg?branch=master)](https://coveralls.io/github/solid/query-ldflex?branch=master)\n[![Dependency Status](https://david-dm.org/solid/query-ldflex.svg)](https://david-dm.org/solid/query-ldflex)\n\nThis library is a _configuration_ of\nthe [LDflex](https://github.com/RubenVerborgh/LDflex) language\nfor the Solid ecosystem.\nIt configures LDflex with:\n\n1. a [JSON-LD context for Solid](https://github.com/solid/context)\n2. a Solid-authenticated query engine ([Comunica](https://github.com/RubenVerborgh/LDflex-Comunica) or [rdflib.js](https://github.com/LDflex/LDflex-rdflib/))\n3. useful [data paths](#data-paths) for Solid\n\nLDflex expressions occur for example\non [Solid React components](https://github.com/solid/react-components),\nwhere they make it easy for developers\nto specify what data they want to show.\nThey can also be used as an expression language\nin any other Solid project or framework.\n\n## Creating data paths\nOnce you [obtain the `solid.data` object](#usage),\nstart writing data paths from the following entry points.\n\n### The `user` entry point\nThe `solid.data.user` path can query data about the currently logged in user,\nsuch as:\n- `solid.data.user.firstName` yields the user's first name(s)\n- `solid.data.user.email` yields the user's email address(es)\n- `solid.data.user.friends` yields the user's friend(s)\n- `solid.data.user.friends.firstName` yields the user's friends' first name(s)\n\n### The _any URL_ entry point\nThe `solid.data[url]` path can query data about any subject by URL,\nsuch as:\n- `solid.data['https://ruben.verborgh.org/profile/#me'].firstName`\n- `solid.data['https://ruben.verborgh.org/profile/#me'].email`\n- `solid.data['https://ruben.verborgh.org/profile/#me'].friends`\n- `solid.data['https://ruben.verborgh.org/profile/#me'].friends.firstName`\n\n### Specifying properties\nAs you can see in the above examples,\nan LDflex path starts with an entry point\nand is followed by property names,\nwhich can be:\n\n- **abbreviations**\n  such as `firstName`\n  (which expands to `http://xmlns.com/foaf/0.1/givenName`)\n- **prefixed names**\n  such as `foaf:givenName`\n  (which expands to `http://xmlns.com/foaf/0.1/givenName`)\n- **full URLs**\n  such as `http://xmlns.com/foaf/0.1/givenName`\n\nThe abbreviations and prefixed names are expanded\nusing a [JSON-LD context](https://github.com/solid/context/blob/master/context.json).\nYou can find some inspiration about what to ask for in this context.\n\nYou can access data using any vocabulary you want\nand, when included in the JSON-LD context, in multiple ways.\nFor example:\n- FOAF:\n  - `solid.data.user.name`\n  - `solid.data.user.foaf_name`\n  - `solid.data.user.foaf$name`\n  - `solid.data.user['foaf:name']`\n  - `solid.data.user['http://xmlns.com/foaf/0.1/name']`\n- vCard:\n  - `solid.data.user.vcard_fn`\n  - `solid.data.user.vcard$fn`\n  - `solid.data.user['vcard:fn']`\n  - `solid.data.user['http://www.w3.org/2006/vcard/ns#fn']`\n- Schema.org:\n  - `solid.data.user.schema_name`\n  - `solid.data.user.schema$name`\n  - `solid.data.user['schema:name']`\n  - `solid.data.user['http://www.schema.org/name']`\n- Custom:\n  - `solid.data.user['http://example.org/my-ontology/name']`\n\nThe traditional colon syntax for prefixes (`schema:name`) \ncan be substituted with an underscore (`schema_name`)\nor dollar sign (`schema$name`).\nThis is because JavaScript keys with a colon\nrequire quotes (`user['schema:name']`)\nwhereas underscores and dollar signs\ncan be used freely (`user.schema_name`, `user.schema$name`).\n\n\n## Installation\n```bash\nnpm install @solid/query-ldflex\n```\n\n## Usage\n### Within Node.js environments\n```javascript\nconst { default: data } = require('@solid/query-ldflex');\n\nconst ruben = data['https://ruben.verborgh.org/profile/#me'];\nshowProfile(ruben);\n\nasync function showProfile(person) {\n  const label = await person.label;\n  console.log(`\\nNAME: ${label}`);\n\n  console.log('\\nTYPES');\n  for await (const type of person.type)\n    console.log(`  - ${type}`);\n\n  console.log('\\nFRIENDS');\n  for await (const name of person.friends.firstName)\n    console.log(`  - ${name} is a friend`);\n}\n\n```\n\nIf, instead of Comunica,\nyou want to use the rdflib.js query engine,\ninstall `@ldflex/rdflib` as a dependency of your project\nand use\n\n```javascript\nconst { default: data } = require('@solid/query-ldflex/lib/exports/rdflib');\n```\n\nWhen creating browser builds,\nit can be easier to simply tell webpack\nto replace `@ldflex/comunica` by `@ldflex/rdflib`.\n\n\n### In the browser\n```html\n\u003cscript src=\"solid-auth-client.bundle.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"solid-query-ldflex.bundle.js\"\u003e\u003c/script\u003e\n```\n\n```javascript\ndocument.addEventListener('DOMContentLoaded', async () =\u003e {\n  const user = solid.data.user;\n  alert(`Welcome, ${await user.firstName}!`);\n});\n\n```\n\nTo replace Comunica by rdflib.js,\nopt for\n\n```html\n\u003cscript src=\"solid-auth-client.bundle.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"rdflib.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"solid-query-ldflex.rdflib.js\"\u003e\u003c/script\u003e\n```\n\n### Adding a custom JSON-LD context\nIn addition to the [default properties](https://github.com/solid/context/blob/master/context.json),\nyou might want to support your own:\n\n```javascript\nconsole.log(solid.data.context);       // the raw default JSON-LD context\nawait solid.data.context.extend({      // add new JSON-LD context\n  con: 'http://www.w3.org/2000/10/swap/pim/contact#',\n  preferred: 'con:preferredURI',\n});\nconsole.log(await solid.data.context); // the expanded JSON-LD context\n\n// Now we can use both existing and new properties\nconst ruben = solid.data['https://ruben.verborgh.org/profile/#me'];\nconsole.log(await ruben.name);\nconsole.log(await ruben.preferred);\n```\n\nBe aware though that this leads to expressions that are less portable,\nbecause they only work when the additional context is added.\n\n### Resolving string expressions\nLDflex expressions are actual JavaScript—not strings.\nThere are times when strings are more useful though,\nsuch as when building\n[declarative components that take LDflex expressions](https://github.com/solid/react-components).\n\nThe `solid.data` object exports a `resolve` interface\nthat transforms a string expression into an actual LDflex path.\nThis string is appended to `solid.data` to obtain the resulting path.\nFor example:\n- `solid.data.resolve('.user.firstName')` becomes the path `solid.data.user.firstName`\n- `solid.data.resolve('[\"https://example.org/\"].label')` becomes the path `solid.data[\"https://example.org/\"].label`\n\nFor convenience, the starting dot\nand quotes inside of brackets can be omitted.\nIf the path is a single URL,\nquotes and brackets can be omitted.\nThe following strings will all resolve:\n- `'.user.firstName'`\n- `'user.firstName'`\n- `'[\"https://example.org/\"].label'`\n- `'[https://example.org/].label'`\n- `'https://example.org/'`\n\n## License\n©2018–present [Ruben Verborgh](https://ruben.verborgh.org/),\n[MIT License](https://github.com/solid/query-ldflex/blob/master/LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLDflex%2FQuery-Solid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLDflex%2FQuery-Solid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLDflex%2FQuery-Solid/lists"}