Node and browser package
Validate stimulus data and build session records in JavaScript.
@sstim/core is the JavaScript validation/session package (distinct from the @sstim/mcp executable). It checks conformance, profile containment and namespace discipline. Its Full-profile SHACL result is PARTIAL because the JavaScript validator does not evaluate sh:sparql constraints.
Example 01
Validate a Core stimulus from the command line
Add SSTIM conformance checks to a Node or CI project.
- Install the JavaScript client. Download a validated starter file.
- Use the Core profile when the dataset describes signals and renderings, without Full-only terms.
npm install @sstim/core
curl -fsSL https://raw.githubusercontent.com/w3c-cg/sstim/main/examples/01-stimulus-core.ttl -o stimulus.ttl
npx sstim validate stimulus.ttl --profile core --version 0.19.0Example 02
Check file conformance in a Node application
Validate a generated Turtle document before sending it to a collaborator.
- Call validate and inspect report.ok.
- For Full-profile records, inspect partial and unevaluated; rerun using the Python client for all SHACL-SPARQL checks.
import { validate } from '@sstim/core'
const report = await validate('stimulus.ttl', {
profile: 'core', version: '0.19.0'
})
if (!report.ok) throw new Error(String(report))
console.log('SSTIM Core validation passed')Example 03
Pin one closure across a whole data export
Avoid drift when generating many RDF files in a Node service.
- Resolve the profile once for the frozen release.
- Reuse the closure for all validation calls instead of resolving release metadata for every file.
import { resolveProfile, validate } from '@sstim/core'
const closure = await resolveProfile('core', { version: '0.19.0' })
for (const path of files) {
const report = await validate(path, { closure })
if (!report.ok) console.error(path, String(report))
}Example 04
Log an auditory-stimulation block with the browser audio clock
Export an ontology-aligned session record from your application without inventing event timings.
- Use the Session builder with a real AudioContext clock and your already-running audio engine.
- Add the signal and channel description, call event when playback actually starts, then close it after playback and export the Turtle file.
import { Session } from '@sstim/core/session'
const session = new Session('https://example.org/lab/run-001/', {
label: 'Auditory modulation block', duration: 60,
masterVolume: 0.5, timing: 'audio-hardware', clock: ctx.currentTime
})
const tone = session.signal({ hz: 40, shape: 'sine' })
session.channel('Headphones', {
modality: 'auditory', medium: 'air-conducted-sound',
placement: 'ears', signal: tone, parameter: 'amplitude',
mechanism: 'amplitude-modulation', carrierHz: 1000
})
// When the existing audio engine actually begins playback:
session.event('playback-start', { at: ctx.currentTime })
// After playback finishes, close the record and call session.toTurtle().Here ctx is your actual AudioContext. The snippet does not create or play an audio stimulus by itself.
Example 05
Know when the JS report is only partial
Avoid claiming complete Full-profile validation when SPARQL constraints were not evaluated.
- For kernel/core/core-plus, JavaScript SHACL checks can run completely.
- For full, the package explicitly reports PARTIAL and an unevaluated count. Use Python sstim or pySHACL for complete Full validation.