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

task-service

v1.0.4

Published

a task service

Downloads

5

Readme

task-service

a task service

Install

npm install task-service

Usage example

var better_sqlite3 = require("better-sqlite3");
var express = require("express");
var task_service = require("task-service");

var db = new better_sqlite3(...);

// prepare table
//task_service["better-sqlite3-api"].prepareTable(db, "test_tasks");  //can be set to be called at .getApi()

// get api
var api = task_service["better-sqlite3-api"].getApi(db, { tableName: "test_tasks", prepare: true });
var service = task_service.loadService(express.Router(), api);

var app = express();
app.use("/test-tasks", service);

var svr = http.createServer(app);
svr.listen(9900, "127.0.0.1", () => {
  //create task
  var req = http.request(
    { host: "127.0.0.1", port: 9900, path: "/test-tasks/", method: "POST" },
    ...
  );

  req.setHeader("CONTENT-TYPE", "application/json");
  req.write(JSON.stringify({ title: "title", expire_at: "2022-12-31 00:00:00" }));
  req.end();
});

Table Convention

CREATE TABLE IF NOT EXISTS ${tableName} (
	id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
	title TEXT NOT NULL,
	updated_at DATETIME NOT NULL,	-- UTC+0
	created_at DATETIME NOT NULL,	-- UTC+0
	expire_at DATETIME NOT NULL,	-- UTC+0
	done_at DATETIME		-- UTC+0
);

Api Convention


*  create one
  .create(row, cb)
    row
      {
        title: "title",
        expire_at: "YYYY-MM-dd hh:mm:ss",		//UTC+0
      }
    cb
      (err,rows)=>{...}
        rows: [ row1, row2, ... ]

* update one
  .update(row, cb)

* update one, done_at, update `done_at` to current time
  .updateDoneAt(id, cb)

* delete one
  .delete(id, cb)
    * return the deleted row in cb

* read one
  .read(id, cb)

* read all
  .readAll(cb)

* read all expire
  .readExpire(expire_at | null, cb)

Url Convention


* response
  {
    msg: "OK",
    rows: ...
  }
 
  or

  {
    error: "error"
  }

* create one, POST	/
  * data: row

* update one,	PUT	/
  * data: row

* update one, done_at,	PUT	/{id}/done		//update `done_at` to current time

* delete one,	DELETE	/{id}

* read one,	GET		/{id}

* read all,	GET		/

* read all, expire,	GET		/expire/YYYY-MM-dd hh:mm:ss
* read all, expire,	GET		/expire/all