`$ deno fmt`

This commit is contained in:
Roj Serbest 2021-10-10 19:02:22 +03:00
parent d672354ad1
commit 5e3290fa08
16 changed files with 54 additions and 58 deletions

View File

@ -1,14 +1,18 @@
# SocialvoidJS
> [Deno](https://deno.land), [Node.js](https://nodejs.org) & 2 variant browser Socialvoid client.
> [Deno](https://deno.land), [Node.js](https://nodejs.org) & 2 variant browser
> Socialvoid client.
## Introduction
SocialvoidJS is a Deno Socialvoid client which can be backported to Node.js using the tool `deno2node`. Also, it can be bundled for browsers using the bundle command of Deno and Webpack.
SocialvoidJS is a Deno Socialvoid client which can be backported to Node.js
using the tool `deno2node`. Also, it can be bundled for browsers using the
bundle command of Deno and Webpack.
### Features
- Everything works on Node.js, Deno and browsers ([2 ways](#bundling-for-browsers)).
- Everything works on Node.js, Deno and browsers
([2 ways](#bundling-for-browsers)).
- Multiple ways to store session and other data: MemoryStore, FileStore,
LocalStorageStore and the ones you define!
- Socialvoid types in classes and applicable for instanceof.
@ -22,23 +26,15 @@ SocialvoidJS is a Deno Socialvoid client which can be backported to Node.js usin
### Method 1: Deno's bundle command (recommended)
```bash
deno bundle socialvoid/mod.ts socialvoid.js
npm run bundle:deno
```
### Method 2: Webpack
1. Convert to Node.js:
```bash
npm run build
```
2. Build:
```bash
NODE_ENV=production npx webpack
```
## Examples
See [`examples/`](./examples).

View File

@ -13,7 +13,7 @@ async function login(client, greet = true) {
await client.session.authenticateUser(
username,
password,
otp == "" ? undefined : otp
otp == "" ? undefined : otp,
);
}

View File

@ -13,7 +13,7 @@ const client = new Client();
await client.session.authenticateUser(
prompt("Username:")!,
prompt("Password:")!,
prompt("OTP (if set):")!
prompt("OTP (if set):")!,
);
}

View File

@ -15,7 +15,7 @@ export default class BaseClient {
constructor(
public readonly rpcEndpoint: string,
public readonly cdnEndpoint: string
public readonly cdnEndpoint: string,
) {}
async sessionId() {
@ -29,7 +29,7 @@ export default class BaseClient {
client_public_hash: this._session.publicHash,
challenge_answer: await answerChallenge(
this._session.privateHash,
this._session.challenge
this._session.challenge,
),
},
};
@ -52,13 +52,13 @@ export default class BaseClient {
async invokeRequests(...requests: Request[]) {
if (!requests) {
throw new Error(
"The parameter `requests` cannot be `undefined` or empty"
"The parameter `requests` cannot be `undefined` or empty",
);
}
const toReturn = new Array<Response>();
const result = parseResponses(
await this.send(serializeRequests(...requests))
await this.send(serializeRequests(...requests)),
);
if (result) {

View File

@ -1,4 +1,4 @@
import { os, isBrowser } from "./deps.deno.ts";
import { isBrowser, os } from "./deps.deno.ts";
export const IS_BROWSER = isBrowser;
export const NAME = "SocialvoidJS";

View File

@ -19,4 +19,4 @@ export const getRandomValues = (size: number) => {
return crypto.getRandomValues(new Uint8Array(size)).buffer;
};
export { OTPAuth, jsSHA };
export { jsSHA, OTPAuth };

View File

@ -23,4 +23,4 @@ export const getRandomValues = (size: number) => {
return randomBytes(size).buffer;
};
export { OTPAuth, jsSHA };
export { jsSHA, OTPAuth };

View File

@ -9,7 +9,7 @@ export default class Account extends MethodBase {
deleteProfilePicture() {
return this.client.invokeRequest(
new Request("account.delete_profile_picture"),
true
true,
);
}
@ -25,7 +25,7 @@ export default class Account extends MethodBase {
new Request("account.set_profile_picture", {
document,
}),
true
true,
);
}
}

View File

@ -11,7 +11,7 @@ export default class CDN extends MethodBase {
});
return Document.fromObject(
(await this.client.invokeCDNRequest(form)).results
(await this.client.invokeCDNRequest(form)).results,
);
}

View File

@ -14,8 +14,8 @@ export default class Cloud extends MethodBase {
new Request("cloud.get_document", {
document,
}),
true
)
true,
),
);
}
}

View File

@ -11,8 +11,8 @@ export default class Help extends MethodBase {
async getCommunityGuidelines() {
return HelpDocument.fromObject(
await this.client.invokeRequest(
new Request("help.get_community_guidelines")
)
new Request("help.get_community_guidelines"),
),
);
}
@ -21,7 +21,7 @@ export default class Help extends MethodBase {
*/
async getPrivacyPolicy() {
return HelpDocument.fromObject(
await this.client.invokeRequest(new Request("help.get_privacy_policy"))
await this.client.invokeRequest(new Request("help.get_privacy_policy")),
);
}
@ -35,8 +35,8 @@ export default class Help extends MethodBase {
return ServerInformation.fromObject(
await this.client.invokeRequest(
new Request("help.get_server_information")
)
new Request("help.get_server_information"),
),
);
}
@ -45,7 +45,7 @@ export default class Help extends MethodBase {
*/
async getTermsOfService() {
return HelpDocument.fromObject(
await this.client.invokeRequest(new Request("help.get_terms_of_service"))
await this.client.invokeRequest(new Request("help.get_terms_of_service")),
);
}
}

View File

@ -8,7 +8,7 @@ export default class Network extends MethodBase {
*/
async getMe() {
return Peer.fromObject(
await this.client.invokeRequest(new Request("network.get_me"), true)
await this.client.invokeRequest(new Request("network.get_me"), true),
);
}
}

View File

@ -19,7 +19,7 @@ export default class Session extends MethodBase {
privateHash: string,
name = NAME,
version = VERSION,
platform = PLATFORM
platform = PLATFORM,
) {
return this.client.invokeRequest(
new Request("session.create", {
@ -28,7 +28,7 @@ export default class Session extends MethodBase {
name,
version,
platform,
})
}),
);
}
@ -37,7 +37,7 @@ export default class Session extends MethodBase {
*/
async get() {
return types.Session.fromObject(
await this.client.invokeRequest(new Request("session.get"), true)
await this.client.invokeRequest(new Request("session.get"), true),
);
}
@ -62,7 +62,7 @@ export default class Session extends MethodBase {
password,
otp,
}),
true
true,
);
}
@ -80,7 +80,7 @@ export default class Session extends MethodBase {
username: string,
password: string,
firstName: string,
lastName?: string
lastName?: string,
) {
return types.Peer.fromObject(
await this.client.invokeRequest(
@ -92,8 +92,8 @@ export default class Session extends MethodBase {
first_name: firstName,
last_name: lastName,
}),
true
)
true,
),
);
}
}

View File

@ -1,6 +1,6 @@
import { IS_BROWSER } from "../constants.ts";
import Store from "./Store.ts";
import { writeTextFileSync, readTextFileSync } from "../deps.deno.ts";
import { readTextFileSync, writeTextFileSync } from "../deps.deno.ts";
export default class FileStore extends Store {
data: { [key: string]: any };

View File

@ -15,7 +15,7 @@ export class ServerInformation extends TypeBase {
public retrieveRepliesMaxLimit: number,
public retrieveQuotesMaxLimit: number,
public retrieveFollowersMaxLimit: number,
public retrieveFollowingMaxLimit: number
public retrieveFollowingMaxLimit: number,
) {
super();
}
@ -33,7 +33,7 @@ export class ServerInformation extends TypeBase {
obj.retrieve_replies_max_limit,
obj.retrieve_quotes_max_limit,
obj.retrieve_followers_max_limit,
obj.retrieve_following_max_limit
obj.retrieve_following_max_limit,
);
}
}
@ -44,7 +44,7 @@ export class Peer extends TypeBase {
public type: string,
public name: string,
public username: string,
public flags: string[]
public flags: string[],
) {
super();
}
@ -60,7 +60,7 @@ export class Session extends TypeBase {
public flags: string[],
public authenticated: boolean,
public created: number,
public expires: number
public expires: number,
) {
super();
}
@ -71,7 +71,7 @@ export class Session extends TypeBase {
obj.flags,
obj.authenticated,
obj.created,
obj.expires
obj.expires,
);
}
}
@ -84,7 +84,7 @@ export class Document extends TypeBase {
public fileSize: number,
public fileType: string,
public flags: string[],
public createdTimestamp: number
public createdTimestamp: number,
) {
super();
}
@ -97,7 +97,7 @@ export class Document extends TypeBase {
obj.file_size,
obj.file_type,
obj.flags,
obj.created_timestamp
obj.created_timestamp,
);
}
}
@ -106,7 +106,7 @@ export class HelpDocument extends TypeBase {
constructor(
public id: string,
public text: string,
public entities: TextEntity[]
public entities: TextEntity[],
) {
super();
}
@ -120,7 +120,7 @@ export class DisplayPictureSize extends TypeBase {
constructor(
public width: number,
public height: number,
public document: Document
public document: Document,
) {
super();
}
@ -140,7 +140,7 @@ export class Profile extends TypeBase {
public url: string | null,
public followersCount: number,
public followingCount: number,
public displayPictureSizes: DisplayPictureSize[]
public displayPictureSizes: DisplayPictureSize[],
) {
super();
}
@ -155,7 +155,7 @@ export class Profile extends TypeBase {
obj.url,
obj.followers_count,
obj.following_count,
obj.display_picture_sizes
obj.display_picture_sizes,
);
}
}
@ -164,7 +164,7 @@ export class SessionIdentification extends TypeBase {
constructor(
public sessionId: string,
public clientPublicHash: string,
public challengeAnswer: string
public challengeAnswer: string,
) {
super();
}
@ -173,7 +173,7 @@ export class SessionIdentification extends TypeBase {
return new this(
obj.session_id,
obj.client_public_hash,
obj.challenge_answer
obj.challenge_answer,
);
}
}
@ -193,7 +193,7 @@ export class TextEntity extends TypeBase {
public type: string,
public offset: number,
public length: number,
public value: string | null
public value: string | null,
) {
super();
}

View File

@ -1,7 +1,7 @@
// import { crypto } from "https://deno.land/std@0.110.0/crypto/mod.ts";
import Request from "./Request.ts";
import Response from "./Response.ts";
import { jsSHA, OTPAuth, getRandomValues } from "./deps.deno.ts";
import { getRandomValues, jsSHA, OTPAuth } from "./deps.deno.ts";
import map, { SocialvoidError } from "./errors.ts";
export function throwError(code: number, message: string) {
@ -45,8 +45,8 @@ export function parseResponses(body: any): Response | Response[] | undefined {
return Array.isArray(body)
? body
.filter((item: any) => "id" in item)
.map((item: any) => new Response(item))
.filter((item: any) => "id" in item)
.map((item: any) => new Response(item))
: "id" in body
? new Response(body)
: undefined;