Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@tpluscode/rdfine
Advanced tools
npm i @tplusode/rdfine
Also peer @types
dependencies:
npm i --save-dev @types/clownface @types/rdf-ext @types/rdfjs__namespace
While it is possible to inherit a base resource class, it's best to create partial mixin classes which implement part of the RDF model. Mixins are dynamically applied to compose a JavaScript object model closely matching the actual quad data.
// Person.ts
import { Constructor, namespace, property, RdfResource } from '@tplusode/rdfine'
import { Term } from 'rdf-js'
import { namedNode } from 'rdf-data-model'
// TS: define an interface for your object model
export interface Person extends RdfResource {
name: string
friends: Person[]
}
export function PersonMixin<Base extends Constructor>(base: Base) {
@namespace('http://schema.org/')
class P extends base implements Person {
// Literal property
// By default use the property's name with the annotated @namespace
@property.literal()
name!: string // http://schema.org/name
// Customize the getter to return objects of a certain property
@property.resource({
// http://schema.org/knows
path: 'knows',
// always return a JS array
values: 'array'
})
friends!: Person[]
// getting raw RDF/JS terms
// by annotating with plain @property
@property({
path: 'http://www.w3.org/2000/01/rdf-schema#label'
})
label: Term
// use _node property to access raw triples
// by traversing the graph with https://github.com/rdf-ext/clownface
get hasOccupation(): boolean {
return this._node
.out(namedNode('http://schema.org/hasOccupation'))
.terms.length > 0
}
}
return P
}
// add a function to decide if the underlying resource
// satisfies the Person interface
// for example by checking its RDF types
PersonMixin.shouldApply = (res: RdfResource) => {
return res.hasType('http://schema.org/Person')
}
Instead of directly creating resource types, which would require deciding up-front, which mixins to add to the constructed class, a factory can be used.
import { DatasetCore } from 'rdf-js'
import { namedNode } from 'rdf-data-model'
import { RdfResourceImpl } from '@tpluscode/rdfine'
import { Person, PersonMixin } from './Person'
// register the mixin type with the factory
factory.addMixin(PersonMixin)
// load you RDF triples into a RDF/JS dataset
let dataset: DatasetCore = loadRdfData()
const person = RdfResourceImpl.factory.createEntity<Person>({
dataset,
term: namedNode('http://example.com/gh/tpluscode')
})
The setters are immediately reflected in the underlying dataset. Note that any property can also be set with raw RDF term matching the annotated type
import { namedNode } from 'rdf-data-model'
person.name = "Tomasz"
person.friends = [
namedNode('http://example.com/gh/bergos'),
namedNode('http://example.com/gh/ktk')
] as any
console.log(person._node.dataset.toString())
The last line above will print triples equivalent to those below
@prefix schema: <http://schema.org/> .
<http://example.com/gh/tpluscode>
schema:name "Tomasz" ;
schema:knows <http://example.com/gh/bergos> , <http://example.com/gh/ktk> .
npm i -D @babel/preset-env @babel/plugin-proposal-decorators @babel/plugin-proposal-class-properties
.babelrc
)
{
"presets": [
[
"@babel/env"
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"decoratorsBeforeExport": true
}
],
[
"@babel/plugin-proposal-class-properties"
]
]
}
FAQs
RDF/JS idiomatic, native, effective
The npm package @tpluscode/rdfine receives a total of 0 weekly downloads. As such, @tpluscode/rdfine popularity was classified as not popular.
We found that @tpluscode/rdfine demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.