1.0.8 • Published 6 months ago

conserve-cloud-sdk v1.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Conserve Cloud SDK

NodeJS TypeScript NestJS

Overview

Conserve Cloud is an API-based cloud storage infrastructure. The increasing costs of today's cloud service providers and the deep configurations required by these services undermine the product development process of all developers, especially indie developers and their unique products. Conserve Cloud offers developers unlimited NoSQL database, Key-Value store and Logger infrastructures for a single fixed monthly price. Learn more on the Conserve Cloud website

By the way, I really mean it, Conserve Cloud infrastructure is a completely API-based infrastructure. You don't need any connection strings, connection pools or consistent server connection. This also means that we can use our cloud-storage infrastructure with serverless infrastructures such as Cloudflare Workers without any extra configuration.

Installation

$ npm install conserve-cloud-sdk

Quickstart

Conserve Cloud is designed to be very simple. Nowadays, when everything around us is evolving so fast, the projects we develop don't need deep configurations or expensive bills, we already take care of that for you. You just focus on shipping fast.

Setup

  1. After you have created an account on the Conserve Cloud website and verified your email, go to the Dashboard and go to the Datakeys tab. Here you will find a unique key for your account to access the entire Conserve Cloud infrastructure.

  2. And the last step (really simple, right?) is to install and use the conserve-cloud-sdk:

$ npm install conserve-cloud-sdk

Now, let's use it:

import { ConserveCloud, Types } from 'conserve-cloud-sdk';

const ccloud = new ConserveCloud('<YOUR-DATAKEY>');

const myDatabase = ccloud.NoSQL('<YOUR-DATABASE-UNIQUE-ID>');
const myKVStore = ccloud.KVStore('<YOUR-KVSTORE-UNIQUE-ID>');
const myLogger = ccloud.Logger('<YOUR-LOGGER-UNIQUE-ID>');

const createUser = async (name: string, lastname: string) => {
	await myDatabase.put({ name, lastname });
	await myKVStore.set('LAST_USERNAME', name);
	await myLogger.log('New user created!', Types.LogLevel.INFO);
};

createUser('John', 'Doe');

// and voila!

As a final note, please keep this in mind: You will create all your resources including NoSQL database, KV store and Logger through Conserve Cloud Dashboard. Then you can use these resources with their unique ids in the code - like the example above.

NoSQL Database

Conserve Cloud's NoSQL databases offer simple operation, zero configuration and database integrations to any system you can think of.

Setup

Create your NoSQL resource on the Conserve Cloud Dashboard by simply naming it and get the unique id of this resource. It's as simple as that. After doing this, the setup is as follows:

import { ConserveCloud } from 'conserve-cloud-sdk';

const ccloud = new ConserveCloud('<YOUR-DATAKEY>');
const nosql = ccloud.NoSQL('<YOUR-DATABASE-UNIQUE-ID>');

API Reference

put

This is a method to create a new object. It gets an object of type NoSQLValueType. A unique key value for all objects is automatically set at creation time. If you specify the key field yourself when the object is created, you will set the unique key value of the object yourself

NoSQL.put(data: NoSQLValueType) => Promise<void>

// Usage
await nosql.put({ name: 'John', lastname: 'Doe', victimAges: [45, 28, 76] });

fetch

Simply fetch and filter your NoSQL database. It also gets an object of type NoSQLValueType.

NoSQL.fetch(query: NoSQLValueType) => Promise<NoSQLValueType>

// Usage
const { data, count } = await nosql.fetch({ name: 'John' });

update

Updates the items with the unique key of the items. Gets key as NoSQLInsertKeyType and object of type NoSQLValueType. You can also insert new fields.

NoSQL.update(key: NoSQLInsertKeyType, updates: NoSQLValueType) => Promise<void>

// Usage
await nosql.update("<unique-key>", {lastname: "Cena", victimAges: [], victims: 0})

delete

Delete the item with it's unique key.

NoSQL.delete(key: NoSQLInsertKeyType) => Promise<void>

// Usage
await nosql.delete("<unique-key>")

KV Store

Conserve Cloud KV Store offers a Redis-like key-value storage infrastructure. Wouldn't it be great to be able to store your objects that you want to access quickly and make cache management simple in your development processes?

Setup

Create your KV Store resource on the Conserve Cloud Dashboard by simply naming it and get the unique id of this resource. It's as simple as that. After doing this, the setup is as follows:

import { ConserveCloud } from 'conserve-cloud-sdk';

const ccloud = new ConserveCloud('<YOUR-DATAKEY>');
const kv = ccloud.KVStore('<YOUR-STORE-UNIQUE-ID>');

API Reference

set

Creates a new cache object with 'key' and 'value' values. Later, when you want to fetch this cache object, the 'key' here is used.

KVStore.set(key: KVStoreInsertKeyType, value: KVStoreValueType) => Promise<void>

// Usage
await kv.set("LOCK", true)

get

Gets the specified cache object with the key.

KVStore.get(key: KVStoreInsertKeyType) => Promise<KVStoreValueType>

// Usage
const value = await kv.get("LOCK") // returns true

delete

Deletes the specified cache object with the key.

KVStore.delete(key: KVStoreInsertKeyType) => Promise<void>

// Usage
await kv.delete("LOCK")

Logger

Conserve Cloud also offers the Logger service, which is very important in development processes. Although this Logger service is developer-oriented, it was developed entirely for developers to debug and monitor critical moments.

Setup

Create your Logger resource on the Conserve Cloud Dashboard by simply naming it and get the unique id of this resource. It's as simple as that. After doing this, the setup is as follows:

import { ConserveCloud } from 'conserve-cloud-sdk';

const ccloud = new ConserveCloud('<YOUR-DATAKEY>');
const logger = ccloud.Logger('<YOUR-LOGGER-UNIQUE-ID>');

IMPORTANT NOTE: Logger class has only 1 method which is log. You can not get log items programmatically yet. Once you create your new log with log method, go back to Conserve Cloud Dashboard and go to Logger > "YOUR-LOGGER-RESOURCE" and inspect your logs.

API Reference

log

Creates new log item with message and level.

Logger.log(message: LoggerMessageType, level: LogLevel) => Promise<void>

// Usage
await logger.log("Server is down", LogLevel.CRITICAL)
1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago