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

@giancosta86/jardinero-sdk

v2.0.0

Published

TypeScript kit for creating JardineroJS linguistic plugins

Downloads

1

Readme

JardineroJS - SDK

TypeScript kit for creating JardineroJS linguistic plugins

GitHub CI npm version MIT License

Overview

JardineroJS - SDK is the TypeScript library enabling developers to create plugins for JardineroJS - the NodeJS implementation of the web architecture devoted to linguistic analysis.

Basically speaking, a plugin is a concrete subclass of LinguisticPlugin, providing JardineroJS with:

  • a unique id - used, for example, to allocate a dedicated SQLite database for each plugin

  • instructions related to the process of dictionary creation:

    • the DDL code to set up the SQLite schema

    • the chain of source streams - that will be parsed to extract source pages

    • the chain of transform streams to extract data - especially terms - from each page

    • the SqliteWritableBuilder - from the sqlite-writable library - used to create the Writable stream that will store the above data to the SQLite db

Installation

npm install @giancosta86/jardinero-sdk

or

yarn add @giancosta86/jardinero-sdk

The public API entirely resides in the root package index, so you shouldn't reference specific modules.

Usage

In order to create a linguistic plugin for JardineroJS, you'll need to:

  1. Import the LinguisticPlugin abstract class and extend it:

    import { LinguisticPlugin } from "@giancosta86/jardinero-sdk";
    
    export class MyLinguisticPlugin extends LinguisticPlugin {
      //Here, implement the abstract methods
    }
  2. Export the custom plugin class itself - usually, in the index module of your package - and mark it as the default export:

    export default MyLinguisticPlugin;
  3. To run your plugin in JardineroJS, you'll need to invoke the jardinero command, passing the module id (usually, the path) of the above module

Implementing LinguisticPlugin

  • getId(): must return a string that identifies your plugin in a unique way; an effective strategy could be a reverse-domain notation à la Java, but the choice is yours. Please, note that each plugin has an isolated db, whose path is

    $HOME/.jardinero/<plugin id>/dictionary.db

  • getName(): returns a string displayed in the title of the current browser tab

  • getSqliteSchema(): must return the DDL code executed when initializing the db

  • createSourceStreams(): must create an array containing a Readable stream, maybe followed by a sequence of Transform streams; the output of the last stream in the sequence will be piped into the transforms produced by createExtractionTransforms(), described below

    The two steps are structurally decoupled for a few reasons - in particular, to simplify testing.

  • createExtractionTransforms(): an array containing one or more Transform streams; this chain of transforms receives the source pages produced by createSourceStreams() and must return objects that will be serialized to the plugin's SQLite db

  • createSqliteWritableBuilder(): must return a SqliteWritableBuilder - provided by the sqlite-writable library, to actually serialize the linguistic terms to db.

    In particular, you'll probably need to call a few methods of the newly-instantiated builder, before returning it:

    • .withSafeType<T> or withType<T>: to register each type that will flow into the db

    • .withMaxObjectsInTransaction(): setting a value higher than the default might be hyper-effective in terms of performances when storing remarkable quantities of items

Please, note: when implementing LinguisticPlugin:

  • most methods actually support not only a T return value, but also Promise<T> - as you prefer

  • in lieu of an array, a method can actually return just a single item, with no array notation. In both cases, the above sync/async note still applies

Optional methods

Optionally, a plugin can override predefined behavior:

  • getStartupQuery() returns the query string initially displayed in the query input box of the app. Default: empty string

  • translateQueryToSql(): since every Jardinero plugin reads data from its dedicated SQLite database, this method allows you to translate the input query written by the user, within the UI, into the actual SQL code executed by the db - thus enabling the creation of arbitrary domain-specific languages. It can return a string or a Promise<string> - whichever you prefer

    By default, it just returns the input query, assuming the user is already writing SQL code.

Logging

Your method implementations can access:

  • the this.logger field, whose Logger type is declared by the unified-logging library

  • the this.pipelineOutput field, for sending user-friendly text messages to the pipeline

Further reference

Please, feel free to explore:

  • the CervantesJS project - a vast, sophisticated plugin devoted to the analysis of the Spanish language

  • RayonJS - the hyper-performant, SAX-based plugin dedicated to the analysis of the French language

  • JardineroJS - the web architecture itself