From 8e8ab7cc81efeba885286f12e23384c0680a61b6 Mon Sep 17 00:00:00 2001 From: Roj Serbest Date: Thu, 18 Nov 2021 15:01:55 +0300 Subject: [PATCH] Deno lint --- generators/generate.ts | 2 +- socialvoid/base_client.ts | 3 +- socialvoid/deps.deno.ts | 6 +- socialvoid/deps.node.ts | 4 +- socialvoid/methods/cdn.ts | 1 + socialvoid/request.ts | 1 + socialvoid/response.ts | 1 + socialvoid/stores/file_store.ts | 2 + socialvoid/stores/localstorage_store.ts | 2 + socialvoid/stores/memory_store.ts | 2 + socialvoid/stores/store.ts | 2 + socialvoid/types.ts | 192 ++++++++++++------------ socialvoid/utils.ts | 7 +- 13 files changed, 121 insertions(+), 104 deletions(-) diff --git a/generators/generate.ts b/generators/generate.ts index 7774dc8..cc01f46 100644 --- a/generators/generate.ts +++ b/generators/generate.ts @@ -62,7 +62,7 @@ for (const typ of types) { for (const param of typ.parameters) { typs += `// ${param.description}\n`; - typs += `${param.name}`; + typs += `"${param.name}"`; if (!param.required) { typs += "?"; diff --git a/socialvoid/base_client.ts b/socialvoid/base_client.ts index dd55fac..82887a9 100644 --- a/socialvoid/base_client.ts +++ b/socialvoid/base_client.ts @@ -20,6 +20,7 @@ export class BaseClient { ) { } + // deno-lint-ignore require-await async getCDNEndpoint(): Promise { throw new Error("Not implemented"); } @@ -88,7 +89,7 @@ export class BaseClient { return stream ? await response.blob() : await response.arrayBuffer(); } - async send(data: any) { + async send(data: string) { return await ( await fetch(this.rpcEndpoint, { method: "POST", diff --git a/socialvoid/deps.deno.ts b/socialvoid/deps.deno.ts index 7ea1a37..5f96e89 100644 --- a/socialvoid/deps.deno.ts +++ b/socialvoid/deps.deno.ts @@ -7,9 +7,11 @@ export const isBrowser = typeof Deno === "undefined"; export const os = isBrowser ? "Browser" : Deno.build.os; -export const writeTextFileSync = isBrowser ? (...args: any) => {} : Deno.writeTextFileSync; +// deno-lint-ignore no-explicit-any +export const writeTextFileSync = isBrowser ? (..._args: any) => {} : Deno.writeTextFileSync; -export const readTextFileSync = isBrowser ? (...args: any) => "" : Deno.readTextFileSync; +// deno-lint-ignore no-explicit-any +export const readTextFileSync = isBrowser ? (..._args: any) => "" : Deno.readTextFileSync; export const getRandomValues = (size: number) => { return crypto.getRandomValues(new Uint8Array(size)).buffer; diff --git a/socialvoid/deps.node.ts b/socialvoid/deps.node.ts index d76e839..da99a1f 100644 --- a/socialvoid/deps.node.ts +++ b/socialvoid/deps.node.ts @@ -6,9 +6,9 @@ import jsSHA from "jssha"; import fetch from "node-fetch"; import FormData from "form-data"; -// @ts-ignore +// @ts-ignore: Node-side error globalThis.fetch = fetch; -// @ts-ignore +// @ts-ignore: Node-side error globalThis.FormData = FormData; export const isBrowser = typeof window !== "undefined"; diff --git a/socialvoid/methods/cdn.ts b/socialvoid/methods/cdn.ts index ccb74f8..f454188 100644 --- a/socialvoid/methods/cdn.ts +++ b/socialvoid/methods/cdn.ts @@ -8,6 +8,7 @@ export class CDN extends MethodBase { * * @param document The file, it can be a buffer or a readable stream. */ + // deno-lint-ignore no-explicit-any async upload(document: any): Promise { const form = formFromObj({ action: "upload", diff --git a/socialvoid/request.ts b/socialvoid/request.ts index b758279..d7d9bae 100644 --- a/socialvoid/request.ts +++ b/socialvoid/request.ts @@ -3,6 +3,7 @@ export class Request { constructor( public method: string, + // deno-lint-ignore no-explicit-any public params?: any, public notification = false, ) { diff --git a/socialvoid/response.ts b/socialvoid/response.ts index 95c6f08..a6f17b4 100644 --- a/socialvoid/response.ts +++ b/socialvoid/response.ts @@ -5,6 +5,7 @@ export class Response { success: boolean; error?: { code: number; message: string }; + // deno-lint-ignore no-explicit-any constructor(public data: any) { if (!this.data.id) { throw new Error(`Got invalid data: ${data}`); diff --git a/socialvoid/stores/file_store.ts b/socialvoid/stores/file_store.ts index 9b4b10f..e708fd9 100644 --- a/socialvoid/stores/file_store.ts +++ b/socialvoid/stores/file_store.ts @@ -3,6 +3,7 @@ import { Store } from "./store.ts"; import { readTextFileSync, writeTextFileSync } from "../deps.deno.ts"; export class FileStore extends Store { + // deno-lint-ignore no-explicit-any data: { [key: string]: any }; constructor(public readonly file: string) { @@ -21,6 +22,7 @@ export class FileStore extends Store { } } + // deno-lint-ignore no-explicit-any set(key: string, value: any) { this.data[key] = value; } diff --git a/socialvoid/stores/localstorage_store.ts b/socialvoid/stores/localstorage_store.ts index 5a30ea2..01ed5e0 100644 --- a/socialvoid/stores/localstorage_store.ts +++ b/socialvoid/stores/localstorage_store.ts @@ -1,6 +1,7 @@ import { IS_BROWSER } from "../constants.ts"; import { Store } from "./store.ts"; +// deno-lint-ignore no-explicit-any function resolveToBeSet(toBeSet: any) { return JSON.stringify(toBeSet); } @@ -22,6 +23,7 @@ export class LocalStorageStore extends Store { return key + this.id; } + // deno-lint-ignore no-explicit-any set(key: string, value: any) { localStorage.setItem(this.resolveKey(key), resolveToBeSet(value)); } diff --git a/socialvoid/stores/memory_store.ts b/socialvoid/stores/memory_store.ts index 2be5af1..5f5944f 100644 --- a/socialvoid/stores/memory_store.ts +++ b/socialvoid/stores/memory_store.ts @@ -1,6 +1,7 @@ import { Store } from "./store.ts"; export class MemoryStore extends Store { + // deno-lint-ignore no-explicit-any private data: { [key: string]: any }; constructor() { @@ -8,6 +9,7 @@ export class MemoryStore extends Store { this.data = {}; } + // deno-lint-ignore no-explicit-any set(key: string, value: any) { this.data[key] = value; } diff --git a/socialvoid/stores/store.ts b/socialvoid/stores/store.ts index 82efa77..ccb604b 100644 --- a/socialvoid/stores/store.ts +++ b/socialvoid/stores/store.ts @@ -1,5 +1,7 @@ export abstract class Store { + // deno-lint-ignore no-explicit-any abstract set(key: string, value: any): void; + // deno-lint-ignore no-explicit-any abstract get(key: string): any; abstract delete(key: string): void; abstract save(): void; diff --git a/socialvoid/types.ts b/socialvoid/types.ts index e3c38f0..9b467ff 100644 --- a/socialvoid/types.ts +++ b/socialvoid/types.ts @@ -1,259 +1,259 @@ // This object describes the size of a display picture followed by a document object that results in said display picture size. export interface DisplayPictureSize { // The width of the image - width: number; + "width": number; // The height of the image - height: number; + "height": number; // The document object that points to the display picture - document: Document; + "document": Document; } // A document object contains basic information about the file associated with the document and the document ID used to retrieve the document from the CDN Server export interface Document { // The ID of the document - id: string; + "id": string; // The Mime of the file - file_mime: string; + "file_mime": string; // The original name of the file - file_name: string; + "file_name": string; // The size of the file in bytes - file_size: number; + "file_size": number; // The type of file detected by the server - file_type: string; + "file_type": string; // An array of flags associated with this document - flags: string[]; + "flags": string[]; } // The object ErrorDefinition contains information about an error that the server is capable of returning if a method fails to execute. export interface ErrorDefinition { // The ID of the ErrorDefinition, which is a crc32 hash of the following value; :: (1.0:InternalServerError:16384) - id: string; + "id": string; // The name of the error, this is a unique value. - name: string; + "name": string; // A description of the error - description: string; + "description": string; // The error code, this is a unique value. - error_code: number; + "error_code": number; } // A help document is often retrieved from the server as a way to represent a document to the user for multiple purposes, from quick guides to server announcements or the legal documents required to be shown to the user before they register an account to the network. export interface HelpDocument { // The ID of the document, if the document gets updated then the ID will change - id: string; + "id": string; // The text contents of the document - text: string; + "text": string; // An array of text entities being represented in the text - entities: TextEntity[]; + "entities": TextEntity[]; } // The object MethodDefinition contains information about method, namespace, permission requirements and the parameters it accepts export interface MethodDefinition { // A crc32 hash of the methods's ID following the value; : eg; 1.0:timelime.compose - id: string; + "id": string; // The namespace of the method e.g., timeline, network, etc. - namespace: string; + "namespace": string; // The name of the method without the namespace compose, like, repost, etc. - method_name: string; + "method_name": string; // The full name of the method with the leading namespace e.g. timeline.compose, timeline.like - method: string; + "method": string; // The description of the method - description: string; + "description": string; // The array of permission requirements for this method - permission_requirements: string[]; + "permission_requirements": string[]; // An array of possible return types - return_types: TypeDefinition[]; + "return_types": TypeDefinition[]; } // The object ObjectDefinition explains the structure of a object that the server could return or work with. export interface ObjectDefinition { // A crc32 hash of the object's ID following the value; : eg; 1.0:Peer - id: string; + "id": string; // The name of the object - name: string; + "name": string; // A description of the object - description: string; + "description": string; // An array of ParameterDefinitions explaining the object structure - parameters: ParameterDefinition[]; + "parameters": ParameterDefinition[]; } // The object ParameterDefinition contains information about the parameters used and or available, usually represented within an array; this object indicates the availabe types, name, description and requirement of the parameter. This can be applied to object property structures or method parameters export interface ParameterDefinition { // The name of the parameter - name: string; + "name": string; // An array of types that are used for this parameter - types: TypeDefinition[]; + "types": TypeDefinition[]; // Indicates if this parameter is required or not, for objects this will always be true. - required: boolean; + "required": boolean; // The description of the parameter - description: string; + "description": string; } // A peer object provides a basic description and identification a peer entity that can contain information used to identify a peer on the client or basic flags and properties of the peer to pre-determine what actions are available for a peer. export interface Peer { // The ID of the document, if the document gets updated then the ID will change - id: string; + "id": string; // The type of the peer entity - type: string; + "type": string; // The display name of the peer - name: string; + "name": string; // The username associated with this peer - username: string; + "username": string; // Flags associated with this peer - flags: string[]; + "flags": string[]; } // A post object is used to represent a post submitted either by a peer, this object can contain recursive objects. export interface Post { // The unique ID for the post - id: string; + "id": string; // The post type used to represent the true intention of the post - type: string; + "type": string; // The author peer of the post, this property can be null if the post was deleted. - peer: Peer | null; + "peer": Peer | null; // The source for where this post was composed from or collected from (eg; the client the user is using or the third-party source that the post was collected. This is determined by the server). This property can be null if the post was deleted. - source: string | null; + "source": string | null; // The text content of the post source. This property can be null if the post has been deleted - text: string | null; + "text": string | null; // An array of attached documents to the post - attachments: Document[]; + "attachments": Document[]; // An array of entities extracted from the text, can be used by the client to highlight clickable entities that preforms an action. - entities: TextEntity[]; + "entities": TextEntity[]; // An array of resolved peers that was mentioned in the post text. - mentioned_peers: Peer[]; + "mentioned_peers": Peer[]; // The original post that this post is replying to if applicable, otherwise null. - reply_to_post: Post | null; + "reply_to_post": Post | null; // The original post that this post is quoting if applicable, otherwise null - quoted_post: Post | null; + "quoted_post": Post | null; // The original post that this post is reposting if applicable, otherwise null - reposted_post: Post | null; + "reposted_post": Post | null; // The original thread post, only applicable to replies. This value indicates the main thread post where all the replies originated from. This value will remain the same for all sub-replies of the main post. - original_thread_post: Post | null; + "original_thread_post": Post | null; // The amount of likes that this post has if applicable, otherwise null - like_count: number | null; + "like_count": number | null; // The amount of repost that this post has if applicable, otherwise null - repost_count: number | null; + "repost_count": number | null; // The amount of quoted posts that this post has if applicable, otherwise null - quote_count: number | null; + "quote_count": number | null; // The amount of replies that this post has if applicable, otherwise null - reply_count: number | null; + "reply_count": number | null; // The Unix Timestamp for when this post was created - posted_timestamp: number; + "posted_timestamp": number; // The flags associated with this post - flags: string[]; + "flags": string[]; } // The profile object provides a profile display for a peer entity, this is mainly used to represent a "Profile" display of a peer. export interface Profile { // The first name of the entity - first_name: string; + "first_name": string; // The last name of the entity - last_name: string | null; + "last_name": string | null; // The full display name of the entity - name: string; + "name": string; // A biography or description of the entity - biography: string | null; + "biography": string | null; // The location of the entity - location: string | null; + "location": string | null; // The URL of the entity (Can be a website or a blog, etc) - url: string | null; + "url": string | null; // The amount of followers that this entity has - followers_count: number; + "followers_count": number; // The amount of peers that this entity is following - following_count: number; + "following_count": number; // An array of display picture size objects that represents the entity's display picture - display_picture_sizes: DisplayPictureSize[]; + "display_picture_sizes": DisplayPictureSize[]; } // The ProtocolDefinitions object contains object definitions of what the server's version of the protocol has defined and what their use cases are. Much like a documentation representation in a object structure that can be understood by clients which allows for constructors during runtime. export interface ProtocolDefinitions { // The version of the protocol being used by the server, eg; 1.0 - version: string; + "version": string; // A list of error definitions defined by the server and protocol with their respective error codes and descriptions - errors: ErrorDefinition[]; + "errors": ErrorDefinition[]; // A list of object definitions defined by the server and protocol with their respective descriptions, names and parameters. - objects: ObjectDefinition[]; + "objects": ObjectDefinition[]; // A list of method definitions defined by the server and protocol with their respective descriptions, names and parameters. - methods: MethodDefinition[]; + "methods": MethodDefinition[]; } // The ServerInformation object is a simple object that gives details about the server's attributes and limits or location of other servers that the client should communicate to for other purposes such as a CDN. export interface ServerInformation { // The name of the network, eg; "Socialvoid" - network_name: string; + "network_name": string; // The version of the protocol standard that the server is using, eg; "1.0" - protocol_version: string; + "protocol_version": string; // The HTTP URL Endpoint for the CDN server of the network - cdn_server: string; + "cdn_server": string; // The maximum size of a file that you can upload to the CDN Server (in bytes) - upload_max_file_size: number; + "upload_max_file_size": number; // The maximum time-to-live (in seconds) that an unauthorized session may have. The server will often reset the expiration whenever the session is used. - unauthorized_session_ttl: number; + "unauthorized_session_ttl": number; // The maximum time-to-live (in seconds) that an authorized session may have. The server will often reset the expiration whenever the session is used. - authorized_session_ttl: number; + "authorized_session_ttl": number; // The maximum amount of likes a client can retrieve at once using the method timeline.get_likes via the page parameter - retrieve_likes_max_limit: number; + "retrieve_likes_max_limit": number; // The maximum amount of reposts a client can retrieve at once using the method timeline.get_reposted_peers via the page parameter - retrieve_reposts_max_limit: number; + "retrieve_reposts_max_limit": number; // The maximum amount of replies a client can retrieve at once using the method timeline.get_replies via the page parameter - retrieve_replies_max_limit: number; + "retrieve_replies_max_limit": number; // The maximum amount of quotes a client can retrieve at once using the method timeline.get_quotes via the page parameter - retrieve_quotes_max_limit: number; + "retrieve_quotes_max_limit": number; // The maximum amount of followers a client can retrieve at once using the method network.get_followers via the page parameter - retrieve_followers_max_limit: number; + "retrieve_followers_max_limit": number; // The maximum amount of following peers a client can retrieve at once using the method network.get_following via the page parameter - retrieve_following_max_limit: number; + "retrieve_following_max_limit": number; // The amount of posts a client can retrieve at once using the method timeline.retrieve_feed via the page parameter - retrieve_feed_max_limit: number; + "retrieve_feed_max_limit": number; } // A session object is contains basic information about the session. export interface Session { // The ID of the session obtained when establishing a session - id: string; + "id": string; // An array of flags that has been set to this session - flags: string[]; + "flags": string[]; // An array of permission sets that has been set to this session - permissions: string[]; + "permissions": string[]; // Indicates if the session is currently authenticated to a user - authenticated: boolean; + "authenticated": boolean; // The Unix Timestamp for when this session was first created - created: number; + "created": number; // The Unix Timestamp for when this session expires - expires: number; + "expires": number; } // A SessionEstablished object is returned when you create a session. This object returns basic information about the session that the server has created for you. export interface SessionEstablished { // The ID of the session obtained when establishing a session - id: string; + "id": string; // The TOTP based challenge secret - challenge: string[]; + "challenge": string[]; } // A SessionIdentification object allows your client to identify the session it's using and prove that it is the owner of the session, it proves as a identification effort and security effort. export interface SessionIdentification { // The ID of the session obtained when establishing a session - id: string; + "id": string; // The TOTP based challenge secret - challenge: string[]; + "challenge": string[]; } // The text entity object describes the text type, this is useful for clients to render the given text correctly. For example a "@mention" will have a TextEntity with the value mention. So that the client can perform an action when this entity is clicked. export interface TextEntity { // The text entity type - type: string; + "type": string; // The offset for when the entity begins in the text - offset: number; + "offset": number; // The length of the entity - length: number; + "length": number; // The value of the entity, for styling entities such as BOLD, ITALIC, etc. this value will be null, but for values such as MENTION, HASHTAG & URL the value will contain the respective value for the entity, for example a URL entity will contain a value of a http URL - value: string | null; + "value": string | null; } // The object TypeDefinition contains information about the defined type, the vector property can indicate if the type is being represented is a vector (list/array) and should be iterated export interface TypeDefinition { // The type of the value, can either be a builtin type or one of the pre-defined object being represented as a string, eg; string, Peer, null - type: string; + "type": string; // An array of types that are used for this parameterIndicates if the type is represented as a vector or not (List/Array) - vector: boolean; + "vector": boolean; } diff --git a/socialvoid/utils.ts b/socialvoid/utils.ts index 5a38530..6d0395f 100644 --- a/socialvoid/utils.ts +++ b/socialvoid/utils.ts @@ -33,6 +33,7 @@ export function answerChallenge(clientPrivateHash: string, challenge: string) { export const unixTimestampToDate = (unixTimestamp: number) => new Date(unixTimestamp * 1000); +// deno-lint-ignore no-explicit-any export function parseResponses(body: any): Response | Response[] | undefined { if (!body) { return undefined; @@ -44,7 +45,9 @@ export function parseResponses(body: any): Response | Response[] | undefined { return Array.isArray(body) ? body + // deno-lint-ignore no-explicit-any .filter((item: any) => "id" in item) + // deno-lint-ignore no-explicit-any .map((item: any) => new Response(item)) : "id" in body ? new Response(body) @@ -52,7 +55,7 @@ export function parseResponses(body: any): Response | Response[] | undefined { } export function serializeRequests(...requests: Request[]): string { - const toReturn: any[] = []; + const toReturn: (Request & { jsonrpc: "2.0" })[] = []; for (const request of requests) { toReturn.push({ ...request, jsonrpc: "2.0" }); @@ -65,7 +68,7 @@ export const newHash = () => { return bufferToHex(getRandomValues(32)); }; -export const formFromObj = (obj: { [key: string]: any }) => { +export const formFromObj = (obj: { [key: string]: FormDataEntryValue }) => { const form = new FormData(); for (const i in obj) {