From ba652aa91b4afc869e67bcafc5ac1cda39ea6383 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 27 Nov 2024 15:25:12 +0100 Subject: [PATCH 1/2] [skjson/ts] Remove unused mappings --- skiplang/skjson/ts/src/skjson.ts | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/skiplang/skjson/ts/src/skjson.ts b/skiplang/skjson/ts/src/skjson.ts index c56ede2c8..b8f075d75 100644 --- a/skiplang/skjson/ts/src/skjson.ts +++ b/skiplang/skjson/ts/src/skjson.ts @@ -264,30 +264,6 @@ interface FromWasm extends WasmAccess { SKIP_SKJSON_createCJBool: (v: boolean) => ptr; } -class Mapping { - private nextID: number = 0; - private objects: any[] = []; - private freeIDs: int[] = []; - - register(v: any) { - const freeID = this.freeIDs.pop(); - const id = freeID ?? this.nextID++; - this.objects[id] = v; - return id; - } - - get(id: int): any { - return this.objects[id]; - } - - delete(id: int): any { - const current: unknown = this.objects[id]; - this.objects[id] = null; - this.freeIDs.push(id); - return current; - } -} - export type Json = number | boolean | string | (Json | null)[] | JsonObject; export type JsonObject = { [key: string]: Json | null }; @@ -353,16 +329,10 @@ class SKJSONShared implements SKJSON { } class LinksImpl implements Links { - env: Environment; - mapping: Mapping; - SKJSON_console!: (json: ptr) => void; SKJSON_error!: (json: ptr) => void; - constructor(env: Environment) { - this.env = env; - this.mapping = new Mapping(); - } + constructor(public env: Environment) {} complete = (utils: Utils, exports: object) => { const fromWasm = exports as FromWasm; From 627720dfdeae99893b3d399090211984519bccc2 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 25 Nov 2024 16:56:54 +0100 Subject: [PATCH 2/2] [ts] add readonly modifier to classes --- packages/dev/src/skdb-dev.ts | 8 +- skiplang/prelude/ts/src/sk_browser.ts | 6 +- skiplang/prelude/ts/src/sk_mem_utils.ts | 6 +- skiplang/prelude/ts/src/sk_node.ts | 6 +- skiplang/prelude/ts/src/sk_posix.ts | 8 +- skiplang/prelude/ts/src/sk_runtime.ts | 11 +-- skiplang/prelude/ts/src/sk_types.ts | 62 +++++-------- skiplang/prelude/ts/src/sk_worker.ts | 86 ++++++------------- skiplang/skjson/ts/src/skjson.ts | 8 +- skipruntime-ts/examples/groups.ts | 4 +- skipruntime-ts/examples/utils.ts | 27 +++--- skipruntime-ts/helpers/src/external.ts | 14 +-- skipruntime-ts/helpers/src/remote.ts | 6 +- skipruntime-ts/helpers/src/rest.ts | 2 +- skipruntime-ts/tests/src/tests.ts | 12 +-- .../wasm/src/internals/skipruntime_module.ts | 68 +++++++-------- sql/ts/src/skdb_database.ts | 10 +-- sql/ts/src/skdb_orchestration.ts | 20 ++--- sql/ts/src/skdb_skdb.ts | 47 +++------- sql/ts/src/skdb_storage.ts | 14 ++- sql/ts/src/skdb_util.ts | 18 ++-- sql/ts/src/skdb_wdatabase.ts | 13 ++- 22 files changed, 164 insertions(+), 292 deletions(-) diff --git a/packages/dev/src/skdb-dev.ts b/packages/dev/src/skdb-dev.ts index c9635beb5..cd5cbd0f4 100644 --- a/packages/dev/src/skdb-dev.ts +++ b/packages/dev/src/skdb-dev.ts @@ -21,10 +21,10 @@ async function getCreds(host: string, port: number, database: string) { } class DevServer { - database: string; - creds: Map; - host: string; - port: number; + private readonly database: string; + private creds: Map; + private readonly host: string; + private readonly port: number; constructor( database: string, diff --git a/skiplang/prelude/ts/src/sk_browser.ts b/skiplang/prelude/ts/src/sk_browser.ts index 78e8d336e..54dd61c4f 100644 --- a/skiplang/prelude/ts/src/sk_browser.ts +++ b/skiplang/prelude/ts/src/sk_browser.ts @@ -2,11 +2,7 @@ import type { float, int, Environment, Wrk, Shared } from "./sk_types.js"; import { MemFS, MemSys } from "./sk_mem_utils.js"; class WrkImpl implements Wrk { - worker: Worker; - - constructor(worker: Worker) { - this.worker = worker; - } + constructor(private readonly worker: Worker) {} static fromPath(url: URL, options?: WorkerOptions) { return new this(new Worker(url, options)); diff --git a/skiplang/prelude/ts/src/sk_mem_utils.ts b/skiplang/prelude/ts/src/sk_mem_utils.ts index 447ad221f..e98a02bc0 100644 --- a/skiplang/prelude/ts/src/sk_mem_utils.ts +++ b/skiplang/prelude/ts/src/sk_mem_utils.ts @@ -71,9 +71,9 @@ class File { } export class MemFS implements FileSystem { - private fileDescrs: Map; + private readonly fileDescrs: Map; private fileDescrNbr: int; - private files: File[]; + private readonly files: File[]; // invariant: range(fileDescrs) ⊆ domain(files) constructor() { @@ -153,7 +153,7 @@ export class MemFS implements FileSystem { } export class MemSys implements System { - private env: Map; + private readonly env: Map; constructor() { this.env = new Map(); diff --git a/skiplang/prelude/ts/src/sk_node.ts b/skiplang/prelude/ts/src/sk_node.ts index 329f3adef..b9267823b 100644 --- a/skiplang/prelude/ts/src/sk_node.ts +++ b/skiplang/prelude/ts/src/sk_node.ts @@ -9,11 +9,7 @@ import * as crypto from "crypto"; import { Worker } from "worker_threads"; class WrkImpl implements Wrk { - worker: Worker; - - constructor(worker: Worker) { - this.worker = worker; - } + constructor(private readonly worker: Worker) {} static fromPath(url: URL, options: WorkerOptions | undefined): Wrk { const filename = "./" + path.relative(process.cwd(), url.pathname); diff --git a/skiplang/prelude/ts/src/sk_posix.ts b/skiplang/prelude/ts/src/sk_posix.ts index 69e0bd682..7bb391989 100644 --- a/skiplang/prelude/ts/src/sk_posix.ts +++ b/skiplang/prelude/ts/src/sk_posix.ts @@ -32,7 +32,7 @@ interface ToWasm { } class LinksImpl implements Links, ToWasm { - private fs: FileSystem; + private readonly fs: FileSystem; SKIP_check_if_file_exists!: (skPath: ptr) => boolean; SKIP_js_open!: (skPath: ptr, flags: int, mode: int) => int; SKIP_js_close!: (fd: int) => void; @@ -126,11 +126,7 @@ class LinksImpl implements Links, ToWasm { } class Manager implements ToWasmManager { - private environment: Environment; - - constructor(environment: Environment) { - this.environment = environment; - } + constructor(private readonly environment: Environment) {} prepare = (wasm: object) => { const toWasm = wasm as ToWasm; diff --git a/skiplang/prelude/ts/src/sk_runtime.ts b/skiplang/prelude/ts/src/sk_runtime.ts index 18352aed9..6bb357b08 100644 --- a/skiplang/prelude/ts/src/sk_runtime.ts +++ b/skiplang/prelude/ts/src/sk_runtime.ts @@ -12,13 +12,10 @@ import { Stream } from "./sk_types.js"; import type * as Internal from "./sk_internal_types.js"; class LinksImpl implements Links { - env: Environment | undefined; lineBuffer!: int[]; lastTime!: int; - constructor(env?: Environment) { - this.env = env; - } + constructor(private readonly env?: Environment) {} SKIP_read_line_fill!: () => int; SKIP_read_to_end_fill!: () => int; @@ -193,11 +190,7 @@ class LinksImpl implements Links { } class Manager implements ToWasmManager { - env: Environment | undefined; - - constructor(env?: Environment) { - this.env = env; - } + constructor(private readonly env?: Environment) {} prepare = (wasm: object) => { const toWasm = wasm as ToWasm; diff --git a/skiplang/prelude/ts/src/sk_types.ts b/skiplang/prelude/ts/src/sk_types.ts index 5dd5ad9c5..8854859fa 100644 --- a/skiplang/prelude/ts/src/sk_types.ts +++ b/skiplang/prelude/ts/src/sk_types.ts @@ -61,28 +61,14 @@ const O_TRUNC = 1000; const O_APPEND = 4000; export class Options { - read: boolean; - write: boolean; - append: boolean; - truncate: boolean; - create: boolean; - create_new: boolean; - constructor( - read: boolean = true, - write: boolean = false, - append: boolean = false, - truncate: boolean = false, - create: boolean = true, - create_new: boolean = false, - ) { - this.read = read; - this.write = write; - this.append = append; - this.truncate = truncate; - this.create = create; - this.create_new = create_new; - } + public read: boolean = true, + public write: boolean = false, + public append: boolean = false, + public truncate: boolean = false, + public create: boolean = true, + public create_new: boolean = false, + ) {} static w() { return new Options(false, true); @@ -226,10 +212,10 @@ export type App = { }; export class Utils { - private exports: Exported; - private env: Environment; - private state: State; - private states: Map; + private readonly exports: Exported; + private readonly env: Environment; + private readonly state: State; + private readonly states: Map; args: string[]; private current_stdin: number; @@ -237,7 +223,7 @@ export class Utils { private stdout: string[]; private stderr: string[]; private stddebug: string[]; - private mainFn?: string; + private readonly mainFn?: string; private exception?: Error; private stacks: Map, string>; @@ -713,7 +699,7 @@ export interface Text { } export class Raw implements Text { - text: string; + private readonly text: string; constructor(text: string, _category?: string) { this.text = text; @@ -731,13 +717,10 @@ export class Raw implements Text { } export class Locale implements Text { - text: string; - category: Nullable; - - constructor(text: string, category?: string) { - this.text = text; - this.category = category ? category : null; - } + constructor( + private readonly text: string, + private readonly category: Nullable = null, + ) {} toJSON: () => object = () => { return { @@ -768,13 +751,10 @@ export const check: (value: Text | string) => Text = (value: Text | string) => { }; export class Format implements Text { - format: Text | string; - parameters: (Text | string)[]; - - constructor(format: Text | string, parameters: (Text | string)[]) { - this.format = format; - this.parameters = parameters; - } + constructor( + private readonly format: Text | string, + private readonly parameters: (Text | string)[], + ) {} toJSON: () => object = () => { return { diff --git a/skiplang/prelude/ts/src/sk_worker.ts b/skiplang/prelude/ts/src/sk_worker.ts index bfd49a00b..b0ca54239 100644 --- a/skiplang/prelude/ts/src/sk_worker.ts +++ b/skiplang/prelude/ts/src/sk_worker.ts @@ -7,19 +7,11 @@ export class Wrappable { class UnmanagedMessage extends Error {} export class Function { - fn: string; - parameters: any[]; - wrap?: { wrap: boolean; autoremove: boolean }; - constructor( - fn: string, - parameters: any[], - wrap?: { wrap: boolean; autoremove: boolean }, - ) { - this.fn = fn; - this.parameters = parameters; - this.wrap = wrap; - } + public fn: string, + public parameters: any[], + public wrap?: { wrap: boolean; autoremove: boolean }, + ) {} static as(obj: object) { if (!("fn" in obj) || !("parameters" in obj)) return null; @@ -37,22 +29,12 @@ export class Function { } export class Caller { - wrapped: number; - fn: string; - parameters: any[]; - remove: boolean; - constructor( - wrapped: number, - fn: string, - parameters: any[], - remove: boolean = false, - ) { - this.wrapped = wrapped; - this.fn = fn; - this.parameters = parameters; - this.remove = remove; - } + public wrapped: number, + public fn: string, + public parameters: any[], + public remove: boolean = false, + ) {} static convert(obj: object) { if ( @@ -77,13 +59,10 @@ export class Caller { } export class Return { - success: boolean; - value: any; - - constructor(success: boolean, value: any) { - this.success = success; - this.value = value; - } + constructor( + public success: boolean, + public value: any, + ) {} static as(obj: object) { if (!("success" in obj) || !("value" in obj)) return null; @@ -92,13 +71,10 @@ export class Return { } export class MessageId { - source: number; - id: number; - - constructor(source: number, id: number) { - this.source = source; - this.id = id; - } + constructor( + public source: number, + public id: number, + ) {} static as(obj: object) { if (!("source" in obj) || !("id" in obj)) return null; @@ -107,11 +83,7 @@ export class MessageId { } export class Wrapped { - wrapped: number; - - constructor(wrapped: number) { - this.wrapped = wrapped; - } + constructor(public wrapped: number) {} static as(obj: object) { if (!("wrapped" in obj)) return null; @@ -124,23 +96,17 @@ function asKey(messageId: MessageId) { } export class Sender { - close: () => void; - send: () => Promise; - - constructor(close: () => void, send: () => Promise) { - this.close = close; - this.send = send; - } + constructor( + public close: () => void, + public send: () => Promise, + ) {} } export class Message { - id: MessageId; - payload: unknown; - - constructor(id: MessageId, payload: unknown) { - this.id = id; - this.payload = payload; - } + constructor( + public id: MessageId, + public payload: unknown, + ) {} private static convert(f: (_: object) => unknown, obj: object) { if (!("id" in obj && typeof obj.id === "object")) return null; diff --git a/skiplang/skjson/ts/src/skjson.ts b/skiplang/skjson/ts/src/skjson.ts index b8f075d75..1cb1a8044 100644 --- a/skiplang/skjson/ts/src/skjson.ts +++ b/skiplang/skjson/ts/src/skjson.ts @@ -332,7 +332,7 @@ class LinksImpl implements Links { SKJSON_console!: (json: ptr) => void; SKJSON_error!: (json: ptr) => void; - constructor(public env: Environment) {} + constructor(private readonly env: Environment) {} complete = (utils: Utils, exports: object) => { const fromWasm = exports as FromWasm; @@ -405,11 +405,7 @@ class LinksImpl implements Links { } class Manager implements ToWasmManager { - env: Environment; - - constructor(env: Environment) { - this.env = env; - } + constructor(private readonly env: Environment) {} prepare = (wasm: object) => { const toWasm = wasm as ToWasm; diff --git a/skipruntime-ts/examples/groups.ts b/skipruntime-ts/examples/groups.ts index c5e72b3e8..4fe46a33f 100644 --- a/skipruntime-ts/examples/groups.ts +++ b/skipruntime-ts/examples/groups.ts @@ -56,7 +56,7 @@ class ActiveUsers implements Mapper { // Mapper function to filter out those active users who are also friends with `user` class FilterFriends implements Mapper { - constructor(private user: User) {} + constructor(private readonly user: User) {} mapEntry( gid: GroupID, @@ -71,7 +71,7 @@ class FilterFriends implements Mapper { } class ActiveFriends implements Resource { - private uid: UserID; + private readonly uid: UserID; constructor(params: { [param: string]: string }) { if (!params["uid"]) throw new Error("Missing required parameter 'uid'"); diff --git a/skipruntime-ts/examples/utils.ts b/skipruntime-ts/examples/utils.ts index 1300d683c..89cb314f1 100644 --- a/skipruntime-ts/examples/utils.ts +++ b/skipruntime-ts/examples/utils.ts @@ -24,7 +24,7 @@ export class SkipHttpAccessV1 { private service: SkipServiceBroker; constructor( - private streaming_port: number = 8080, + private readonly streaming_port: number = 8080, control_port: number = 8081, ) { this.service = new SkipServiceBroker({ @@ -118,21 +118,14 @@ interface DeleteQuery { export type Step = RequestQuery | LogQuery | WriteQuery | DeleteQuery; class Session { - scenario: Step[]; - perform: (l: Step) => void; - error: (e: string) => void; current = 0; on = false; constructor( - scenario: Step[], - perform: (l: Step) => void, - error: (e: string) => void, - ) { - this.scenario = scenario; - this.perform = perform; - this.error = error; - } + private readonly scenario: Step[], + private readonly perform: (l: Step) => void, + private readonly error: (e: string) => void, + ) {} next(): boolean { if (this.current >= this.scenario.length) { @@ -166,11 +159,11 @@ class Player { running?: Session; constructor( - private scenarios: Step[][], - private perform: (l: string) => void, - private send: (l: Step) => void, - private error: (e: string) => void, - private exit: () => void, + private readonly scenarios: Step[][], + private readonly perform: (l: string) => void, + private readonly send: (l: Step) => void, + private readonly error: (e: string) => void, + private readonly exit: () => void, ) {} start(idx: number) { diff --git a/skipruntime-ts/helpers/src/external.ts b/skipruntime-ts/helpers/src/external.ts index 951f91edb..5e33927a8 100644 --- a/skipruntime-ts/helpers/src/external.ts +++ b/skipruntime-ts/helpers/src/external.ts @@ -15,7 +15,9 @@ export interface ExternalResource { } export class GenericExternalService implements ExternalService { - constructor(private resources: { [name: string]: ExternalResource }) {} + constructor( + private readonly resources: { [name: string]: ExternalResource }, + ) {} subscribe( resourceName: string, @@ -53,7 +55,7 @@ export class GenericExternalService implements ExternalService { type Timeout = ReturnType; export class TimerResource implements ExternalResource { - private intervals = new Map(); + private readonly intervals = new Map(); open( params: { [param: string]: string | number }, @@ -96,12 +98,12 @@ export class TimerResource implements ExternalResource { export class Polled implements ExternalResource { - private intervals = new Map(); + private readonly intervals = new Map(); constructor( - private url: string, - private duration: number, - private conv: (data: S) => Entry[], + private readonly url: string, + private readonly duration: number, + private readonly conv: (data: S) => Entry[], ) {} open( diff --git a/skipruntime-ts/helpers/src/remote.ts b/skipruntime-ts/helpers/src/remote.ts index 22ebe024d..4b5a34c2d 100644 --- a/skipruntime-ts/helpers/src/remote.ts +++ b/skipruntime-ts/helpers/src/remote.ts @@ -11,11 +11,11 @@ interface Closable { } export class SkipExternalService implements ExternalService { - private resources = new Map(); + private readonly resources = new Map(); constructor( - private url: string, - private control_url: string, + private readonly url: string, + private readonly control_url: string, ) {} // TODO: Support Skip external services going through a gateway. diff --git a/skipruntime-ts/helpers/src/rest.ts b/skipruntime-ts/helpers/src/rest.ts index fbcb919b5..fe62f0aae 100644 --- a/skipruntime-ts/helpers/src/rest.ts +++ b/skipruntime-ts/helpers/src/rest.ts @@ -49,7 +49,7 @@ export async function fetchJSON( * `SkipServiceBroker` provides a method-call interface to the backing HTTP interface. */ export class SkipServiceBroker { - private entrypoint: string; + private readonly entrypoint: string; /** * Construct a broker for a Skip service at the given entry point. diff --git a/skipruntime-ts/tests/src/tests.ts b/skipruntime-ts/tests/src/tests.ts index d39f89145..03c927485 100644 --- a/skipruntime-ts/tests/src/tests.ts +++ b/skipruntime-ts/tests/src/tests.ts @@ -81,7 +81,7 @@ const map1Service: SkipService = { //// testMap2 class Map2 implements Mapper { - constructor(private other: EagerCollection) {} + constructor(private readonly other: EagerCollection) {} mapEntry( key: string, @@ -178,7 +178,7 @@ const oneToOneMapperService: SkipService = { //// testSize class SizeMapper implements Mapper { - constructor(private other: EagerCollection) {} + constructor(private readonly other: EagerCollection) {} mapEntry( key: number, @@ -233,7 +233,7 @@ const slicedMap1Service: SkipService = { //// testLazy class TestLazyAdd implements LazyCompute { - constructor(private other: EagerCollection) {} + constructor(private readonly other: EagerCollection) {} compute(_selfHdl: LazyCollection, key: number): number { return this.other.getUnique(key) + 2; @@ -241,7 +241,7 @@ class TestLazyAdd implements LazyCompute { } class MapLazy implements Mapper { - constructor(private other: LazyCollection) {} + constructor(private readonly other: LazyCollection) {} mapEntry( key: number, @@ -346,7 +346,7 @@ class JSONExtract implements Mapper { - constructor(private context: Context) {} + constructor(private readonly context: Context) {} mapEntry( key: number, @@ -428,7 +428,7 @@ class MockExternal implements ExternalService { } class MockExternalCheck implements Mapper { - constructor(private external: EagerCollection) {} + constructor(private readonly external: EagerCollection) {} mapEntry( key: number, diff --git a/skipruntime-ts/wasm/src/internals/skipruntime_module.ts b/skipruntime-ts/wasm/src/internals/skipruntime_module.ts index 9a6a234d0..f146874ee 100644 --- a/skipruntime-ts/wasm/src/internals/skipruntime_module.ts +++ b/skipruntime-ts/wasm/src/internals/skipruntime_module.ts @@ -139,7 +139,9 @@ export function deepFreeze(value: T): T & Param { class ResourceBuilder { constructor( - private builder: new (params: { [param: string]: string }) => Resource, + private readonly builder: new (params: { + [param: string]: string; + }) => Resource, ) {} build(parameters: { [param: string]: string }): Resource { @@ -489,8 +491,8 @@ interface ToWasm { class Handles { private nextID: number = 1; - private objects: any[] = []; - private freeIDs: int[] = []; + private readonly objects: any[] = []; + private readonly freeIDs: int[] = []; register(v: T): Handle { const freeID = this.freeIDs.pop(); @@ -521,7 +523,7 @@ class Handles { } class Stack { - stack: ptr[] = []; + private readonly stack: ptr[] = []; push(pointer: ptr) { this.stack.push(pointer); @@ -547,13 +549,13 @@ class Refs { } class LinksImpl implements Links { - private handles = new Handles(); - private stack = new Stack(); + private readonly handles = new Handles(); + private readonly stack = new Stack(); private utils!: Utils; private fromWasm!: FromWasm; skjson?: SKJSON; - constructor(private env: Environment) {} + constructor(private readonly env: Environment) {} complete(utils: Utils, exports: object) { this.utils = utils; @@ -895,8 +897,8 @@ class LazyCollectionImpl implements LazyCollection { constructor( - private lazyCollection: string, - private refs: Refs, + private readonly lazyCollection: string, + private readonly refs: Refs, ) { super(); Object.freeze(this); @@ -929,7 +931,7 @@ class EagerCollectionImpl { constructor( public collection: string, - private refs: Refs, + private readonly refs: Refs, ) { super(); Object.freeze(this); @@ -1058,7 +1060,7 @@ class EagerCollectionImpl class CollectionWriter { constructor( public collection: string, - private refs: Refs, + private readonly refs: Refs, ) {} update(values: Entry[], isInit: boolean): void { @@ -1109,7 +1111,7 @@ class CollectionWriter { } class ContextImpl extends SkFrozen implements Context { - constructor(private refs: Refs) { + constructor(private readonly refs: Refs) { super(); Object.freeze(this); } @@ -1159,7 +1161,9 @@ class ContextImpl extends SkFrozen implements Context { } export class ServiceInstanceFactory implements Shared { - constructor(private init: (service: SkipService) => ServiceInstance) {} + constructor( + private readonly init: (service: SkipService) => ServiceInstance, + ) {} initService(service: SkipService): ServiceInstance { return this.init(service); @@ -1187,10 +1191,10 @@ interface Checker { class AllChecker implements Checker { constructor( - private service: ServiceInstance, - private executor: Executor[]>, - private resource: string, - private params: { [param: string]: string }, + private readonly service: ServiceInstance, + private readonly executor: Executor[]>, + private readonly resource: string, + private readonly params: { [param: string]: string }, ) {} check(request: string): void { @@ -1209,11 +1213,11 @@ class AllChecker implements Checker { class OneChecker implements Checker { constructor( - private service: ServiceInstance, - private executor: Executor, - private resource: string, - private params: { [param: string]: string }, - private key: string | number, + private readonly service: ServiceInstance, + private readonly executor: Executor, + private readonly resource: string, + private readonly params: { [param: string]: string }, + private readonly key: string | number, ) {} check(request: string): void { @@ -1236,7 +1240,7 @@ class OneChecker implements Checker { * and operations to manage susbscriptions and the service itself. */ export class ServiceInstance { - constructor(private refs: Refs) {} + constructor(private readonly refs: Refs) {} /** * Instantiate a resource with some parameters and client session authentication token @@ -1441,19 +1445,11 @@ export class ServiceInstance { } class NonEmptyIteratorImpl implements NonEmptyIterator { - private skjson: SKJSON; - private exports: FromWasm; - private pointer: ptr; - constructor( - skjson: SKJSON, - exports: FromWasm, - pointer: ptr, - ) { - this.skjson = skjson; - this.exports = exports; - this.pointer = pointer; - } + private readonly skjson: SKJSON, + private readonly exports: FromWasm, + private readonly pointer: ptr, + ) {} next(): Nullable { return this.skjson.importOptJSON( @@ -1494,7 +1490,7 @@ class NonEmptyIteratorImpl implements NonEmptyIterator { } class Manager implements ToWasmManager { - constructor(private env: Environment) {} + constructor(private readonly env: Environment) {} // prepare(wasm: object) { diff --git a/sql/ts/src/skdb_database.ts b/sql/ts/src/skdb_database.ts index 82676c2fa..ce865fcf5 100644 --- a/sql/ts/src/skdb_database.ts +++ b/sql/ts/src/skdb_database.ts @@ -109,11 +109,11 @@ class SKDBMechanismImpl implements SKDBMechanism { } export class SKDBSyncImpl implements SKDBSync { - private environment: Environment; + private readonly environment: Environment; private subscriptionCount: number = 0; private clientUuid: string = ""; private accessKey?: string; - private fs: FileSystem; + private readonly fs: FileSystem; save!: () => Promise; runLocal!: (new_args: string[], new_stdin: string) => string; @@ -424,11 +424,7 @@ export class SKDBSyncImpl implements SKDBSync { } export class SKDBImpl implements SKDB { - private skdbSync: SKDBSync; - - constructor(skdbSync: SKDBSync) { - this.skdbSync = skdbSync; - } + constructor(private readonly skdbSync: SKDBSync) {} currentUser?: string; diff --git a/sql/ts/src/skdb_orchestration.ts b/sql/ts/src/skdb_orchestration.ts index 7514a0db8..e1a1aad01 100644 --- a/sql/ts/src/skdb_orchestration.ts +++ b/sql/ts/src/skdb_orchestration.ts @@ -245,7 +245,7 @@ function encodeProtoMsg(msg: ProtoMsg): ArrayBuffer { class ProtoMsgDecoder { private bufs: Uint8Array[] = []; - private msgs: (ProtoMsg | null)[] = []; + private readonly msgs: (ProtoMsg | null)[] = []; private popBufs(): ArrayBuffer { if (this.bufs.length == 1) { @@ -533,7 +533,7 @@ class ResilientMuxedSocket { } class ResilientStream { - private socket: ResilientMuxedSocket; + private readonly socket: ResilientMuxedSocket; private stream?: Stream; private failureDetectionTimeout?: number; @@ -689,7 +689,7 @@ export interface Creds { export class MuxedSocket { // constants - private reauthTimeoutMs = 5 * 60 * 1000; // 5 mins - half of the 10 min window + private readonly reauthTimeoutMs = 5 * 60 * 1000; // 5 mins - half of the 10 min window // state private state: MuxedSocketState = MuxedSocketState.IDLE; @@ -708,9 +708,9 @@ export class MuxedSocket { onError?: (errorCode: number, msg: string) => void; private constructor( - private socket: WebSocket, - private creds: Creds, - private env: Environment, + private readonly socket: WebSocket, + private readonly creds: Creds, + private readonly env: Environment, ) { // pre-condition: socket is open } @@ -1438,10 +1438,10 @@ class SKDBServer implements RemoteSKDB { private onRebootFn?: () => void; private constructor( - private env: Environment, - private client: SKDBMechanism, - private connection: ResilientMuxedSocket, - private creds: Creds, + private readonly env: Environment, + private readonly client: SKDBMechanism, + private readonly connection: ResilientMuxedSocket, + private readonly creds: Creds, ) {} static async connect( diff --git a/sql/ts/src/skdb_skdb.ts b/sql/ts/src/skdb_skdb.ts index d5fe7031c..2c96c9720 100644 --- a/sql/ts/src/skdb_skdb.ts +++ b/sql/ts/src/skdb_skdb.ts @@ -43,40 +43,21 @@ interface Exported { } class SKDBHandleImpl implements SKDBHandle { - runner: (fn: () => string) => SKDBTable; - main: (new_args: string[], new_stdin: string) => string; - watch: ( - query: string, - params: Params, - onChange: (rows: SKDBTable) => void, - ) => { close: () => void }; - watchChanges: ( - query: string, - params: Params, - init: (rows: SKDBTable) => void, - update: (added: SKDBTable, removed: SKDBTable) => void, - ) => { close: () => void }; - constructor( - main: (new_args: string[], new_stdin: string) => string, - runner: (fn: () => string) => SKDBTable, - watch: ( + public main: (new_args: string[], new_stdin: string) => string, + public runner: (fn: () => string) => SKDBTable, + public watch: ( query: string, params: Params, onChange: (rows: SKDBTable) => void, ) => { close: () => void }, - watchChanges: ( + public watchChanges: ( query: string, params: Params, init: (rows: SKDBTable) => void, update: (added: SKDBTable, removed: SKDBTable) => void, ) => { close: () => void }, - ) { - this.runner = runner; - this.main = main; - this.watch = watch; - this.watchChanges = watchChanges; - } + ) {} init() { this.main([], ""); @@ -101,11 +82,11 @@ interface ToWasm { } class SKDBMemory implements PagedMemory { - memory: ArrayBuffer; - persistentSize: number; - nbrInitPages: number; - pageSize: number; - popDirtyPage: () => number; + private readonly memory: ArrayBuffer; + private readonly persistentSize: number; + private readonly nbrInitPages: number; + private readonly pageSize: number; + private readonly popDirtyPage: () => number; private dirtyPagesMap!: number[]; private dirtyPages!: number[]; @@ -211,7 +192,7 @@ class SKDBSharedImpl implements SKDBShared { } class LinksImpl implements Links, ToWasm { - private environment: Environment; + private readonly environment: Environment; private state: ExternalFuns; private field_names: string[]; private objectIdx: number; @@ -533,11 +514,7 @@ class LinksImpl implements Links, ToWasm { } class Manager implements ToWasmManager { - private environment: Environment; - - constructor(environment: Environment) { - this.environment = environment; - } + constructor(private readonly environment: Environment) {} prepare = (wasm: object) => { const toWasm = wasm as ToWasm; diff --git a/sql/ts/src/skdb_storage.ts b/sql/ts/src/skdb_storage.ts index 5eccfca9d..d831ca6e7 100644 --- a/sql/ts/src/skdb_storage.ts +++ b/sql/ts/src/skdb_storage.ts @@ -56,15 +56,11 @@ function makeSKDBStore( } export class IDBStorage implements Storage { - private storeName: string; - private memory: PagedMemory; - private db: IDBDatabase; - - private constructor(storeName: string, db: IDBDatabase, memory: PagedMemory) { - this.storeName = storeName; - this.memory = memory; - this.db = db; - } + private constructor( + private readonly storeName: string, + private readonly db: IDBDatabase, + private readonly memory: PagedMemory, + ) {} static async create( dbName: string, diff --git a/sql/ts/src/skdb_util.ts b/sql/ts/src/skdb_util.ts index 54f27e066..14f3d6adc 100644 --- a/sql/ts/src/skdb_util.ts +++ b/sql/ts/src/skdb_util.ts @@ -4,11 +4,7 @@ import type { SKDB, Params } from "./skdb_types.js"; /* The type used to represent callable external functions. */ /* ***************************************************************************/ export class SKDBCallable<_T1, _T2> { - private id: number; - - constructor(id: number) { - this.id = id; - } + constructor(private readonly id: number) {} getId(): number { return this.id; @@ -16,11 +12,7 @@ export class SKDBCallable<_T1, _T2> { } export class ExternalFuns { - private externalFuns: ((obj: any) => any)[]; - - constructor() { - this.externalFuns = []; - } + private readonly externalFuns: ((obj: any) => any)[] = []; register(f: (obj: T1) => T2): SKDBCallable { if (typeof f != "function") { @@ -114,9 +106,9 @@ export class SKDBTable extends Array> { /* ***************************************************************************/ export class SKDBTransaction { - private params: Params; - private stmts: string[]; - private db_handle: SKDB; + private readonly params: Params; + private readonly stmts: string[]; + private readonly db_handle: SKDB; constructor(skdb: SKDB) { this.params = {}; diff --git a/sql/ts/src/skdb_wdatabase.ts b/sql/ts/src/skdb_wdatabase.ts index 88e6f3330..a4d4d2bfe 100644 --- a/sql/ts/src/skdb_wdatabase.ts +++ b/sql/ts/src/skdb_wdatabase.ts @@ -19,13 +19,10 @@ import { SKDBGroupImpl } from "./skdb_group.js"; /* eslint-disable @typescript-eslint/no-invalid-void-type */ class WrappedRemote implements RemoteSKDB { - private worker: PromiseWorker; - private wrapped: number; - - constructor(worker: PromiseWorker, wrapped: number) { - this.worker = worker; - this.wrapped = wrapped; - } + constructor( + private readonly worker: PromiseWorker, + private readonly wrapped: number, + ) {} createDatabase(dbName: string) { return this.worker @@ -109,7 +106,7 @@ class WrappedRemote implements RemoteSKDB { } export class SKDBWorker implements SKDB { - private worker: PromiseWorker; + private readonly worker: PromiseWorker; constructor(worker: Wrk) { this.worker = new PromiseWorker(worker);