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

smallapi-js

v1.0.0

Published

smallapi-js

Downloads

998

Readme

Smallapi-js

Known Vulnerabilities

NPM

Smallapi client API wrapper

What is Smallapi-js?

Smallapi-js is a small wrapper wrote in javascript that allows smallapi users to uses their APIs cloud functions from the client side.

Table of contents

Prerequisites

This package requires NodeJS and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following commands:

node --version
# v21.5.0

npm --version
# 10.2.4

Installation

BEFORE YOU INSTALL: please read the prerequisites

Install the package using npm:

npm i -S smallapi-js

Usage

import { smallapi } from 'smallapi-js';

const api = await smallapi('https://my-api-url.com/', {
  apiKey: 'my-secret-key',
});

const createdUser = await api.createUser({
  firstName: 'John',
  lastName: 'Doe',
  email: `[email protected]`,
  age: 32,
});

Example

A repository with complete examples can be found here: https://github.com/tutanck/small-demo.

Typescript support

This package export a type definition file so you can use it, out of the box, inside your Typescript project.

import { smallapi, Api, Config } from 'smallapi-js';

const myApiUrl: string = 'https://my-api-url.com/';

const myConfig: Config = {
  apiKey: 'my-secret-key',
};

const api: Api = await smallapi(myApiUrl, myConfig);

const userInfos: object = {
  firstName: 'John',
  lastName: 'Doe',
  email: `[email protected]`,
  age: 32,
};

const createdUser: object = await api.createUser(userInfos);

API

Here is the list of cloud functions generated when you create a model called {Model} on the smallapi platform:

count{Model}Documents(query): number

Counts the number of documents matching the query parameter in the {{modelName}} collection.

Parameters:

query : Object • Indicates how to filter the documents in the collection {{modelName}}.

Returns:

Number • The number of documents matching the query parameter in the collection {{modelName}}

Examples:
const resultsCount = count{Model}Documents(query)
More:

Learn more about queries


create{Model}(docs): documents

Insert one document or an array of documents to the {{modelName}} collection.

Parameters:

docs : Array|Object • The documents to insert in the collection {{modelName}}.

Returns:

Document|Array<Document> • The list of documents inserted in the collection {{modelName}}.

Examples:
const results = create{Model}(docs)
More:

Learn more about documents


find{Model}ById(id, [projection], [options]): document

Finds a single document by its _id field in the {{modelName}} collection.

Parameters:
  • id : ObjectId • Required • value of _id field to query by {{modelName}} collection.

  • [projection] : Object|String|Array<String> • Optional • fields to return from the document found in the collection {{modelName}}.

  • [options] : Object • Optional • Additional options to apply while querying the collection {{modelName}}.

The following options are available:

  • limit
  • skip
  • sort
  • populate • Object|String • Populate the specified path.
    • path • String • Specify the name of the property to be populated.
    • select • String • Specify the fields to fetch from the referenced document.
Returns:

Document • The document identified by its _id in the collection {{modelName}}.

Examples:
const result = find{Model}ById(id)


const result = find{Model}ById(id, { propertyA: 1, propertyB: -1 }, options)

const result = find{Model}ById(id, "propertyA -propertyB", options)

const result = find{Model}ById(id, ["propertyA", "propertyC"], options)
More:

Learn more about field selection

Learn more about the populate option


find{Model}ByQuery(query, [projection], [options]): documents

Find the documents matching the query parameter in the {{modelName}} collection.

Parameters:
  • query : Object • Indicates how to filter the documents in the collection {{modelName}}.

  • [projection] : Object|String|Array<String> • Optional • fields to return from the document found in the collection {{modelName}}.

  • [options] : Object • Optional • Additional options to apply while querying the collection {{modelName}}.

The following options are available:

  • limit
  • skip
  • sort
  • populate • Object|String • Populate the specified path.
    • path • String • Specify the name of the property to be populated.
    • select • String • Specify the fields to fetch from the referenced document.
  • useFindOne : true|false • If set to true the driver will use findOne instead of find • default to false.
Returns:

Array<Document> • The documents matching the query parameter in the collection {{modelName}}

Examples:
const result = find{Model}ByQuery(query)


const result = find{Model}ByQuery(query, { propertyA: 1, propertyB: -1 }, options)

const result = find{Model}ByQuery(query, "propertyA -propertyB", options)

const result = find{Model}ByQuery(query, ["propertyA", "propertyC"], options)
More:

Learn more about queries

Learn more about field selection

Learn more about the populate option


remove{Model}ById(id, [options]): document

Delete a single document by its _id field in the {{modelName}} collection.

Parameters:
  • id : ObjectId • Required • value of _id field to query by {{modelName}} collection.

  • [options] : Object • Optional • Additional options to apply while querying the collection {{modelName}}.

The following options are available:

  • sort
  • populate • Object|String • Populate the specified path.
    • path • String • Specify the name of the property to be populated.
    • select • String • Specify the fields to fetch from the referenced document.- populate
Returns:

Document • The document identified by its _id in the collection {{modelName}}.

Examples:
const result = remove{Model}ById(id, options)
More:

Learn more about the populate option


remove{Model}ByQuery(query, [options]): documents

Delete all the documents matching the query parameter in the {{modelName}} collection.

Parameters:
  • query : Object • Indicates how to filter the documents in the collection {{modelName}}.

  • [options] : Object • Optional • Additional options to apply while querying the collection {{modelName}}.

The following options are available:

  • sort • Works only if useFindOne is set to true.
  • populate • Object|String • Populate the specified path • Works only if useFindOne is set to true.
    • path • String • Specify the name of the property to be populated.
    • select • String • Specify the fields to fetch from the referenced document.
  • useFindOne : true|false • If set to true the driver will use findOneAndDelete instead of deleteMany • default to false.
Returns:

DeleteResult|Document • an object with the property deletedCount containing the number of documents deleted OR the document matching the query parameter in the collection {{modelName}} if useFindOne is set to true.

Examples:
const result = remove{Model}ByQuery(query, options)
More:

Learn more about queries

Learn more about the populate option


update{Model}ById(id, update, [options]): document

Updates a single document by its _id field in the {{modelName}} collection.

Parameters:
  • id : ObjectId • Required • value of _id field to query by {{modelName}} collection.

  • [update] : Object • Required • The update object to replace the one found while querying the collection {{modelName}}.

  • [options] : Object • Optional • Additional options to apply while querying the collection {{modelName}}.

The following options are available:

  • upsert : true|false • if true, and no documents found, insert a new document • default to false.
  • new : true|false • if true, return the modified document rather than the original • default to true.
  • runValidators : true|false • if true, validate the update operation against the model's definition first • default to true.
  • select Object|String • sets the document fields to return.
  • sort
  • populate • Object|String • Populate the specified path.
    • path • String • Specify the name of the property to be populated.
    • select • String • Specify the fields to fetch from the referenced document.
Returns:

Document • The document identified by its _id in the collection {{modelName}}.

Examples:
const result = update{Model}ById(id, update, options)
More:

Learn more about field selection

Learn more about the populate option


update{Model}ByQuery(query, update, [options]): document

Updates all the documents matching the query parameter in the {{modelName}} collection.

Parameters:
  • query : Object • Required • value of _id field to query by {{modelName}} collection.

  • [update] : Object • Required • The update object to replace the one found while querying the collection {{modelName}}.

  • [options] : Object • Optional • Additional options to apply while querying the collection {{modelName}}.

The following options are available:

  • upsert : true|false • if true, and no documents found, insert a new document • default to false.
  • new : true|false • if true, return the modified document rather than the original • default to false • Works only if useFindOne is set to true.
  • runValidators : true|false • if true, validate the update operation against the model's definition first • default to false • Works only if useFindOne is set to true.
  • fields Object|String • sets the document fields to return • Works only if useFindOne is set to true.
  • sort• Works only if useFindOne is set to true.
  • populate • Object|String • Populate the specified path • Works only if useFindOne is set to true.
    • path • String • Specify the name of the property to be populated.
    • select • String • Specify the fields to fetch from the referenced document.
  • useFindOne : true|false • If set to true the driver will use findOneAndDelete instead of deleteMany • default to false.
Returns:

UpdateResult|Document • an UpdateResult object OR the document matching the query parameter in the collection {{modelName}} if useFindOne is set to true.

Examples:
const result = update{Model}ByQuery(id, update, options)
More:

Learn more about queries

Learn more about field selection

Learn more about the populate option


Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request :sunglasses:

License

MIT License © Anagbla Joan (tutanck)

Contributors ✨

Thanks goes to these wonderful people for their contribution:

This project follows the all-contributors specification. Contributions of any kind welcome!