From 17b9d45a3c6b0002fbf8ecd2a0e2c9200c38bcfc Mon Sep 17 00:00:00 2001 From: Rolands Date: Fri, 1 Nov 2024 09:44:51 +0100 Subject: [PATCH] went back to old tsconfig --- core/admin-client.ts | 6 +++--- core/admin-server.ts | 6 +++--- core/chat.ts | 6 +++--- core/core-client.ts | 31 ++++++++++++++++++++----------- core/core-server.ts | 20 ++++++++++---------- core/core-session.ts | 10 +++++----- core/fs-utils.ts | 6 ++---- core/ratelimit.ts | 2 +- core/secure.ts | 4 ++-- core/sql-parsing.ts | 2 +- core/tsconfig.json | 10 +++++----- core/utils.ts | 2 +- 12 files changed, 56 insertions(+), 49 deletions(-) diff --git a/core/admin-client.ts b/core/admin-client.ts index f54f0cf..99f3473 100644 --- a/core/admin-client.ts +++ b/core/admin-client.ts @@ -1,8 +1,8 @@ //If God did not exist, it would be necessary to invent Him. /Voltaire/ -import { E } from "./logging"; -import { SocioClient, SocioClientOptions } from './core-client'; -import { CoreMessageKind } from './utils'; +import { E } from "./logging.js"; +import { SocioClient, SocioClientOptions } from './core-client.js'; +import { CoreMessageKind } from './utils.js'; //types type AdminClientOptions = { url:string, client_secret: string, socio_client_opts: SocioClientOptions } diff --git a/core/admin-server.ts b/core/admin-server.ts index 55aea30..74d3321 100644 --- a/core/admin-server.ts +++ b/core/admin-server.ts @@ -1,12 +1,12 @@ //If God did not exist, it would be necessary to invent Him. /Voltaire/ -import { LogHandler, E } from "./logging"; +import { LogHandler, E } from "./logging.js"; import { WebSocket as nodeWebSocket } from "ws"; -import { yaml_parse, yaml_stringify } from './utils'; +import { yaml_parse, yaml_stringify } from './utils.js'; //types import type { id, PropValue, LoggingOpts } from './types.d.ts'; -import { ClientMessageKind } from './core-client'; +import { ClientMessageKind } from './core-client.js'; type MessageDataObj = { id: id, status?: string, result?: string | object | boolean | PropValue, data?: object }; type AdminClientOptions = { url: string, client_secret: string } & LoggingOpts; diff --git a/core/chat.ts b/core/chat.ts index 2c1ca31..997d7ab 100644 --- a/core/chat.ts +++ b/core/chat.ts @@ -3,8 +3,8 @@ //types import type { ClientID, S_SERV_data, ServerMessageDataObj } from "./types.d.ts"; -import type { SocioSession } from "./core-session"; -import { E, log } from "./logging"; +import type { SocioSession } from "./core-session.js"; +import { E, log } from "./logging.js"; export type User = { client_id: ClientID, username?: string }; export type ChatRoomMessage = { user: User, ts: number, text:string}; type ServerInterfaceFunction = (client_ids: string[], data: object) => void; @@ -43,7 +43,7 @@ export class ServerChatRoom{ const new_message = { user: { client_id }, ts: (new Date()).getTime(), text }; this.#messages.add(new_message); if(this.#messages.size > this.history_length) - this.#messages.delete(this.#messages.values().next().value); //remove the first message, if over history limit + this.#messages.delete(this.#messages.values().next().value as ChatRoomMessage); //remove the first message, if over history limit //send new message to clients const clients = [...this.#users.values()].map(c => c.client_id); //could filter out the current client as well, but that actually complicates things more than solves diff --git a/core/core-client.ts b/core/core-client.ts index 6802e37..4f96489 100644 --- a/core/core-client.ts +++ b/core/core-client.ts @@ -3,8 +3,8 @@ import pako from 'pako'; //https://github.com/nodeca/pako import * as diff_lib from 'recursive-diff'; //https://www.npmjs.com/package/recursive-diff -import { LogHandler, E, err, log, info, done } from './logging'; -import { yaml_parse, yaml_stringify, clamp, CoreMessageKind } from './utils'; +import { LogHandler, E, err, log, info, done } from './logging.js'; +import { yaml_parse, yaml_stringify, clamp, CoreMessageKind } from './utils.js'; //types import type { id, PropKey, PropValue, PropOpts, Bit, ClientLifecycleHooks, ClientID, SocioFiles, LoggingOpts, ClientSubscribeOpts, data_result_block } from './types.d.ts'; @@ -16,7 +16,7 @@ import type { data_base, C_RES_data, C_CON_data, C_UPD_data, C_AUTH_data, C_GET_ import type { S_SUB_data, S_UNSUB_data, S_SQL_data, S_AUTH_data, S_GET_PERM_data, S_PROP_SUB_data, S_PROP_UNSUB_data, S_PROP_GET_data, S_PROP_SET_data, S_PROP_REG_data, S_RECON_GET_data, S_RECON_USE_data, S_UP_FILES_data, S_GET_FILES_data } from './types.d.ts'; import type { ClientMessageDataObj } from './types.d.ts'; -import type { RateLimit } from './ratelimit'; +import type { RateLimit } from './ratelimit.js'; type SubscribeCallbackObjectSuccess = ((res: object | object[]) => void) | null; type SubscribeCallbackObject = { success: SubscribeCallbackObjectSuccess, error?: Function}; type QueryObject = ClientSubscribeOpts & { onUpdate: SubscribeCallbackObject }; @@ -499,18 +499,27 @@ export class SocioClient extends LogHandler { // async Prop(prop_name: PropKey){ // const client_this = this; //use for inside the Proxy scope // const prop_proxy = new Proxy(await this.GetProp(prop_name), { - // async get(p: PropValue, property) { - // const res = await client_this.GetProp.bind(client_this)(prop_name); - // return res?.result?.success === 1 ? res?.result?.res[property] : p[property]; + // get(p: PropValue, property) { + // return p[property]; + // // const res = await client_this.GetProp.bind(client_this)(prop_name); + // // return res?.result?.success === 1 ? res?.result?.res[property] : p[property]; // }, - // // @ts-expect-error - // async set(p: PropValue, property, new_val) { //ive run tests in other projects and the async set does work fine. TS doesnt want to allow it for some reason - // p[property] = new_val; - // return (await client_this.SetProp.bind(client_this)(prop_name, p))?.result?.success === 1; + // //ive run tests in other projects and the async set does work fine. TS doesnt want to allow it for some reason + // set(p: PropValue, property, new_val) { + // //the sub will run this too, which means the value would've already been set + // if (p[property] !== new_val){ + // p[property] = new_val; + // client_this.SetProp.bind(client_this)(prop_name, p); + // } + + // return true; + // // return (await client_this.SetProp.bind(client_this)(prop_name, p))?.result?.success === 1; // } // }); - // this.SubscribeProp(prop_name, (new_val) => { prop_proxy[]}) + // this.SubscribeProp(prop_name, (new_val) => { + // for(const [key, val] of Object.entries(new_val)) prop_proxy[key] = val; //set each key, bcs cant just assign the new obj, bcs then it wouldnt be a proxy anymore + // }); // return prop_proxy; // } diff --git a/core/core-server.ts b/core/core-server.ts index 4280e1f..8720033 100644 --- a/core/core-server.ts +++ b/core/core-server.ts @@ -6,13 +6,13 @@ import { WebSocketServer } from 'ws'; //https://github.com/websockets/ws https:/ import * as diff_lib from 'recursive-diff'; //https://www.npmjs.com/package/recursive-diff //mine -import { QueryIsSelect, ParseQueryTables, ParseQueryVerb } from './sql-parsing'; -import { SocioStringParse, GetAllMethodNamesOf, yaml_parse } from './utils'; -import { E, LogHandler, err, log, info, done } from './logging'; -import { UUID, type SocioSecurity } from './secure'; -import { SocioSession, type SubObj } from './core-session'; -import { RateLimiter } from './ratelimit'; -import { CoreMessageKind } from './utils'; +import { QueryIsSelect, ParseQueryTables, ParseQueryVerb } from './sql-parsing.js'; +import { SocioStringParse, GetAllMethodNamesOf, yaml_parse } from './utils.js'; +import { E, LogHandler, err, log, info, done } from './logging.js'; +import { UUID, type SocioSecurity } from './secure.js'; +import { SocioSession, type SubObj } from './core-session.js'; +import { RateLimiter } from './ratelimit.js'; +import { CoreMessageKind } from './utils.js'; //types import type { ServerOptions, WebSocket, AddressInfo } from 'ws'; @@ -25,9 +25,9 @@ import type { data_base, S_SUB_data, ServerMessageDataObj, S_UNSUB_data, S_SQL_d import type { C_RES_data, C_CON_data, C_UPD_data, C_AUTH_data, C_GET_PERM_data, C_PROP_UPD_data, C_RECON_Data, C_RECV_FILES_Data } from './types.d.ts'; //types over network for the data object import type { id, PropKey, PropValue, PropAssigner, PropOpts, ClientID, FS_Util_Response, ServerLifecycleHooks, LoggingOpts, Bit, SessionOpts } from './types.d.ts'; -import { ClientMessageKind } from './core-client'; -import type { RateLimit } from './ratelimit'; -import type { SocioStringObj } from './sql-parsing'; +import { ClientMessageKind } from './core-client.js'; +import type { RateLimit } from './ratelimit.js'; +import type { SocioStringObj } from './sql-parsing.js'; export type QueryFuncParams = { id?: id, sql: string, params?: any }; export type QueryFunction = (client: SocioSession, id: id, sql: string, params?: any) => Promise; diff --git a/core/core-session.ts b/core/core-session.ts index cbc5f02..35ce2a5 100644 --- a/core/core-session.ts +++ b/core/core-session.ts @@ -1,14 +1,14 @@ //Homo vitae commodatus non donatus est. - Man's life is lent, not given. /Syrus/ -import { LogHandler, E, log, info, done } from './logging'; -import { RateLimiter } from './ratelimit'; -import { yaml_stringify, FastHash } from './utils'; -import { ClientMessageKind } from './core-client'; +import { LogHandler, E, log, info, done } from './logging.js'; +import { RateLimiter } from './ratelimit.js'; +import { yaml_stringify, FastHash } from './utils.js'; +import { ClientMessageKind } from './core-client.js'; //types import type { WebSocket } from 'ws'; //https://github.com/websockets/ws https://github.com/websockets/ws/blob/master/doc/ws.md import type { id, Bit, LoggingOpts, SessionOpts, Auth_Hook } from './types.d.ts'; -import type { RateLimit } from './ratelimit'; +import type { RateLimit } from './ratelimit.js'; export type SubObj = { tables: string[], diff --git a/core/fs-utils.ts b/core/fs-utils.ts index 0830b0a..e868c3c 100644 --- a/core/fs-utils.ts +++ b/core/fs-utils.ts @@ -12,8 +12,7 @@ export function SaveFilesToDiskPath(string_array_path: string[], files: SocioFil if (!string_array_path || !files) return rej({ result: 0, error: 'function arguments are falsy' }); for (const [filename, file_data] of files.entries()) { const file_path = os_path.join(...string_array_path, filename); - //@ts-expect-error - const bin = pako.inflate(Buffer.from(file_data.bin, 'base64')); //file_data.bin should be a base64 encoded string, so make a buffer from it and decompress with pako + const bin = pako.inflate(Buffer.from(file_data.bin, 'base64').buffer as ArrayBuffer); //file_data.bin should be a base64 encoded string, so make a buffer from it and decompress with pako fs.writeFileSync(file_path, bin, { flag: 'w' }); } res({ result: 1 }); @@ -28,8 +27,7 @@ export function ReadFilesFromDisk(file_paths: string[]): Promise