Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved the authorize function inside Quebrix Client #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 The Russel Project
Copyright (c) 2024 The Quebrix Project

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
80 changes: 36 additions & 44 deletions ReadMe.MD
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
# 🚀 Russel Client in TypeScript
# 🚀 Quebrix Client in TypeScript

Welcome to the **Russel Client** package! This library, crafted in TypeScript, enables seamless integration with the Russel service.
Welcome to the **Quebrix Client** package! This library, crafted in TypeScript, enables seamless integration with the Quebrix service.

## ⚙️ Setup

Get started by installing the package:

```bash
# npm
npm install russel-ts
npm install Quebrix-ts
```
Russel uses Authorization in order to set clusters. so you need to authorize yourself first.
Quebrix uses Authorization in order to set clusters. so you need to authorize yourself first.

## 🔒 Authorization

After installing the russel application. russel by default creates a user with this credentials
After installing the Quebrix application. Quebrix by default creates a user with this credentials

```bash
admin // username
123456 // password
```
This is the default user with the highest priority that can add and remove profiles.

Now, before using the `russel-ts` API you need to call `authorize` function when a new client is created.

```typescript

// Example usage:
const russelClient = new RusselClient();
russelClient.authorize();
```

If you need to authorize as another user, there are two different ways to do so.

Expand All @@ -38,61 +30,61 @@ If you need to authorize as another user, there are two different ways to do so.
```typescript

// Example usage:
const russelClient = new RusselClient('admin','123456'); // first arg is username and second is password
russelClient.authorize();
const QuebrixClient = new QuebrixClient('admin','123456'); // first arg is username and second is password

```

## 2. Set user in russelConfig
## 2. Set user in QuebrixConfig

```typescript

// Example usage:
const russelClient = new RusselClient(); // first arg is username and second is password
russelClient.setRusselConfig({
const QuebrixClient = new QuebrixClient(); // first arg is username and second is password
QuebrixClient.setQuebrixConfig({
username:'admin',
password:123456
})
russelClient.authorize();

```

# 🛠️ Types & Interfaces

russel-ts comes with three essential interfaces that you can leverage to configure and interact with Russel:
Quebrix-ts comes with three essential interfaces that you can leverage to configure and interact with Quebrix:

`IRusselConfig`
`IQuebrixConfig`

Defines the configuration settings for the Russel client.
Defines the configuration settings for the Quebrix client.

```typescript
interface IRusselConfig {
interface IQuebrixConfig {
baseUrl?: string // default: 'http://127.0.0.1'
port?: number // default: 6022
username?:string,
password?:string
}

// Example usage:
const russelClient = new RusselClient();
russelClient.setRusselConfig({
const QuebrixClient = new QuebrixClient();
QuebrixClient.setQuebrixConfig({
// your configuration goes here...
});
```

`IRusselPayload`
`IQuebrixPayload`

Specifies the structure for setting data within a cluster.


```typescript
interface IRusselPayload {
interface IQuebrixPayload {
cluster: string // cluster name
key: string // key name
value: string // value name
ttl?: number // expiration time in seconds
}

// Example usage:
await russelClient.set({
await QuebrixClient.set({
cluster: 'foo',
key: 'bar',
value: 'fooBar',
Expand All @@ -101,33 +93,33 @@ await russelClient.set({
```


`IRusselPartials`
`IQuebrixPartials`

Defines the structure for retrieving data from a cluster.


```typescript
interface IRusselPartials {
interface IQuebrixPartials {
cluster: string // cluster name
key: string // key name
}

// Example usage:
await russelClient.get({
await QuebrixClient.get({
cluster: 'foo',
key: 'bar',
});
```

# 📬 Handling Responses
Russel-ts offers two ways to handle responses from your client operations:
Quebrix-ts offers two ways to handle responses from your client operations:

1. Raw value

Retrieve the raw value directly:

```typescript
const res = await russelClient.get({
const res = await QuebrixClient.get({
cluster: 'foo',
key: 'bar',
});
Expand All @@ -142,7 +134,7 @@ console.log(res); // raw value
Alternatively, decode the value using the built-in function:

```typescript
const res = await russelClient.get({
const res = await QuebrixClient.get({
cluster: 'foo',
key: 'bar',
});
Expand All @@ -153,14 +145,14 @@ console.log(res.decodeData()); // decoded value


# 🔄 Internal Functions
`russel-ts` provides a straightforward API for CRUD operations. Here's a step-by-step guide on using its functionalities:
`Quebrix-ts` provides a straightforward API for CRUD operations. Here's a step-by-step guide on using its functionalities:


## Set a Value in a Cluster

```typescript
try {
const res = await russelClient.set({
const res = await QuebrixClient.set({
cluster: 'foo',
key: 'bar',
value: 'fooBar',
Expand All @@ -174,7 +166,7 @@ try {

```typescript
try {
const res = await russelClient.getCluster({
const res = await QuebrixClient.getCluster({
cluster: 'foo',
key: 'bar',
});
Expand All @@ -189,7 +181,7 @@ try {

```typescript
try {
const res = await russelClient.deleteCluster({
const res = await QuebrixClient.deleteCluster({
cluster: 'foo',
key: 'bar',
});
Expand All @@ -204,7 +196,7 @@ try {

```typescript
try {
const res = await russelClient.clearCluster('foo'); // cluster name
const res = await QuebrixClient.clearCluster('foo'); // cluster name
console.log('Cluster cleared');
} catch (error) {
console.error(error);
Expand All @@ -217,7 +209,7 @@ try {

```typescript
try {
const res = await russelClient.getKeysOfCluster('foo'); // cluster name
const res = await QuebrixClient.getKeysOfCluster('foo'); // cluster name
console.log(res); // ['bar']
} catch (error) {
console.error(error);
Expand All @@ -231,7 +223,7 @@ try {

```typescript
try {
const res = await russelClient.setCluster('foo'); // cluster name
const res = await QuebrixClient.setCluster('foo'); // cluster name
console.log('Cluster created');
} catch (error) {
console.error(error);
Expand All @@ -240,11 +232,11 @@ try {

```

## Check Russel-ts Connection
## Check Quebrix-ts Connection

```typescript
try {
const res = await russelClient.checkConnection();
const res = await QuebrixClient.checkConnection();
console.log('Connection successful');
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -275,7 +267,7 @@ In case of errors, the response will include is_success set to false:

```

For more details, visit our [GitHub organization](https://github.com/russel-io/). Happy coding! 🎉
For more details, visit our [GitHub organization](https://github.com/Quebrix-io/). Happy coding! 🎉



4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "russel-ts",
"name": "Quebrix-ts",
"version": "1.0.0",
"description": "russel client with type script",
"main": "src/RusselClient",
"description": "Quebrix client with type script",
"main": "src/QuebrixClient",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
7 changes: 2 additions & 5 deletions playground/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import RusselClient from "../src/russelClient";
import QuebrixClient from "../src/QuebrixClient";

async function main() {
const testClient = new RusselClient('admin', '123456');
testClient.setRusselConfig({
const testClient = new QuebrixClient('admin', '123456');

})
await testClient.authorize()
try {
await testClient.set({
cluster:'test',
Expand Down
8 changes: 4 additions & 4 deletions src/endPoints.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {errorHandler} from "./utilities/globalErrorHandler";
import {customFetch} from "./utilities/customFetch";
import {partialItemEncoder} from "./utilities/UrlCreator";
import {IRusselPartials, IRusselSetPayload} from "./models/IRusselPayload";
import {IQuebrixPartials, IQuebrixSetPayload} from "./models/IQuebrixPayload";
import {IApiResponseData} from "./models/IApiResponse";
import {ServiceResult} from "./utilities/ServiceResult";

async function setKey(baseUrl: string, payload: IRusselSetPayload): Promise<IApiResponseData> {
async function setKey(baseUrl: string, payload: IQuebrixSetPayload): Promise<IApiResponseData> {
try {
const url = `${baseUrl}/set`;
const response = await customFetch(url, {
Expand All @@ -20,7 +20,7 @@ async function setKey(baseUrl: string, payload: IRusselSetPayload): Promise<IApi
}
}

async function getCluster(baseUrl: string, partials: IRusselPartials) {
async function getCluster(baseUrl: string, partials: IQuebrixPartials) {
/// expected payload {
// cluster
// key
Expand All @@ -38,7 +38,7 @@ async function getCluster(baseUrl: string, partials: IRusselPartials) {
}
}

async function deleteCluster(baseUrl: string, partials: IRusselPartials) {
async function deleteCluster(baseUrl: string, partials: IQuebrixPartials) {
/// expected payload {
// cluster
// key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IRusselConfig {
export interface IQuebrixConfig {
baseUrl?: string,
port?: number,
username?:string,
Expand Down
10 changes: 10 additions & 0 deletions src/models/IQuebrixPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface IQuebrixSetPayload {
cluster: string,
key: string,
value: string,
ttl?: number
}

export interface IQuebrixPartials extends Omit<IQuebrixSetPayload, 'value' | 'ttl'> {

}
10 changes: 0 additions & 10 deletions src/models/IRusselPayload.ts

This file was deleted.

Loading