npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-comunica

v0.1.1

Published

This service makes it easier to use [Comunica](https://comunica.dev/) from an Angular app.

Downloads

2

Readme

Comunica for Angular

This service makes it easier to use Comunica from an Angular app.

Install

npm i --save ngx-comunica

Add to angular.json

"scripts": [
    ...
    "node_modules/ngx-comunica/assets/comunica-browser.js"
]

Add to app.module.ts

import { ComunicaModule } from 'ngx-comunica';

@NgModule({
  imports: [
    ...,
    ComunicaModule
  ]
})

Use

SELECT queries

Return query results one by one as an observable

This is the preferred approach since it provides the user with results immediately instead of having to wait for the whole query execution to be finished.

import { ComunicaService, ResponseType, Source, SourceType } from 'ngx-comunica';
import * as N3 from "n3";

export class MyComponent {

    public queryResults: any[] = [];
    public variables: string[] = [];
    public queryComplete: boolean = false;
    public store: N3.Store = new N3.Store();

    constructor(
        private _comunica: ComunicaService
    ) { }

    setStore(){
        const source = new Source(this.store, SourceType.RDFJS, "main");
        this._comunica.addSource(this.store);
    }

    executeQuery(query: string){

        this.queryResults = [];
        this.variables = [];
        this.queryComplete = false;

        const extensionFunctions = [];  // Optional extension functions
        this._comunica.selectQuery(query, extensionFunctions, ResponseType.SINGLE).subscribe({
            next: (res: any) => {

                if(res == undefined) return;

                // Extract variable names from first result
                if(!this.variables.length){
                    this.variables = Object.keys(res);
                }

                this.queryResults.push(res);

            },
            complete: () => this.queryComplete = true,
            error: (err) => console.log(err)
        })

    }

Return all query results when finished as promise

This approach is only recommended in situations where you need the full result once.

import { ComunicaService, ResponseType } from 'ngx-comunica';
import { lastValueFrom } from 'rxjs';
import * as N3 from "n3";

export class MyComponent {

    public queryResults: any[] = [];
    public variables: string[] = [];
    public queryComplete: boolean = false;
    public store: N3.Store = new N3.Store();

    // ...(see SELECT EXAMPLE)

    async executeQuery(query: string){

        this.queryResults = [];
        this.variables = [];
        this.queryComplete = false;

        try{
            const extensionFunctions = [];  // Optional extension functions
            this.queryResults = await lastValueFrom(this._comunica.selectQuery(query, extensionFunctions, ResponseType.ACCUMULATED));
            this.variables = Object.keys(this.queryResults[0]);
            this.queryComplete = true;
        }catch(err){
            console.log(err);
        }

    }

Update queries

It is possible to execute update queries. When doing so, the content of the store is extended (if there are matches to the query).

import { ComunicaService, Serialization } from 'ngx-comunica';
import { lastValueFrom } from 'rxjs';
import * as N3 from "n3";

export class MyComponent {

    public queryResult?: any;
    public queryComplete: boolean = false;
    public store: N3.Store = new N3.Store();

    // ...(see SELECT EXAMPLE)

    async executeQuery(query: string){

        this.queryResult = undefined;
        this.queryComplete = false;

        try{
            const extensionFunctions = [];  // Optional extension functions
            this.queryResult = await this._comunica.updateQuery(query, extensionFunctions);
            this.queryComplete = true;
        }catch(err){
            console.log(err);
        }

    }

Construct queries

Construct query results are returned as a promise in the desired serialization (Default is JSON-LD).

import { ComunicaService, Serialization } from 'ngx-comunica';
import { lastValueFrom } from 'rxjs';
import * as N3 from "n3";

export class MyComponent {

    public queryResult?: any;
    public queryComplete: boolean = false;
    public store: N3.Store = new N3.Store();

    // ...(see SELECT EXAMPLE)

    async executeQuery(query: string){

        this.queryResult = undefined;
        this.queryComplete = false;

        try{
            const extensionFunctions = [];  // Optional extension functions
            this.queryResult = await this._comunica.constructQuery(query, extensionFunctions, Serialization.Turtle);
            this.queryComplete = true;
        }catch(err){
            console.log(err);
        }

    }