
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
A JavaScript framework using Dristriubted Data Protocol for the Semantic Web
Explore an example of beltline's usage at .
npm install beltline --save
To illustrait the usuage of beltline.js we'll be walking through how to build an application that keeps track of a list of people. An example can be seen here.
Publish methods only are executed on the server and use SPARQL CONSTRUCT
queries to define a subgraph. Later we will use "subscribe" methods on the client to subscribe to these publish methods.
The following example receives an "id" parameter from the client
personApi.js
export default function personApi(beltline) {
if (beltline.isServer) {
beltline.publish('person', ({ id }) => {
return `
PREFIX f: <http://example.com/owl/families#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT { ?s ?p ?o } WHERE {
f:${id} ?p ?o .
?s rdf:type f:Person .
?s ?p ?o
}
`;
});
}
}
Shared methods modify the database in some way. They are shared between both the client and the server. Calling a shared method on the client will update the data on the client, server, and all other clients that are subscribed to a subgraph that contains the modified data.
In this example, we define a method to change a person's name.
personApi.js
export default function personApi(beltline) {
// ...
beltline.method('changeName', async ({ id, newName }, db) => {
await db.execute(`
PREFIX f: <http://example.com/owl/families#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
DELETE { f:${id} rdf:name ?o }
INSERT { f:${id} rdf:name "${newName}"^^xsd:string }
WHERE { f:${id} rdf:name ?o }
`);
});
}
Attach your Node.js Server to Beltline by creating a database connection, providing beltline with than database connection, and adding your custom APIs to beltline.
server.js
import express from 'express'
import BeltlineServer from 'beltline';
import initDatabase from 'beltline-local-storage-database';
import personApi from './beltlineMethods/personApi';
const app = express();
const server = require('http').createServer(app);
initDatabase(async (db) => {
await db.load('text/turtle', turtleString);
const beltline = new BeltlineServer(server, db);
personApi(beltline);
});
server.listen(8080);
Point the beltline client to your server and initialize it with your custom api.
client.js
import BeltlineClient from 'beltline-client';
import personApi from '../../beltlineMethods/personApi';
const beltlineClient = new BeltlineClient('http://localhost:8080');
personApi(beltlineClient);
Subscribe to your publish methods by using the subscribe methods. Once you subscribe, the callback will be called with the current subgraph. It will also be called with any subsequent updates to this subgraph.
peopleActions.js
await beltline.subscribe(
'person',
{ id },
(newGraph) => {
// Do what you will with your new sub-graph
}
);
Modify your database with calls to your predefined methods.
peopleActions.js
beltline.call('changeName', { id, newName });
FAQs
A framework using Dristributed Data Protocol for the Semantic Web
We found that beltline demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.