diff --git a/@types/ipfs/index.d.ts b/@types/ipfs/index.d.ts index f393be2d4..ac8d8ab1b 100644 --- a/@types/ipfs/index.d.ts +++ b/@types/ipfs/index.d.ts @@ -4,95 +4,91 @@ declare module 'ipfs' { import type { Buffer } from 'buffer' import type { KuboRPCClient } from 'kubo-rpc-client' - declare export interface IPFSService extends CoreService { - pin: PinService; - files: FileService; - name: NameService; - object: ObjectService; - config: ConfigService; - dag: KuboRPCClient['dag']; - - stop(options?: TimeoutOptions): Promise - } - - declare export interface CoreService { - // TODO: cat returns AsyncIterable. see https://github.com/ipfs/js-kubo-rpc-client/blob/1ab7941819dd1a48df653ee159e6983608e72132/src/index.ts#L353C50-L353C75 - cat(pathOrCID: string | CID, options?: CatOptions): AsyncIterable; - ls(pathOrCID: string | CID, options?: ListOptions): AsyncIterable; - add(file: FileContent | FileObject, options?: AddOptions): Promise; - addAll(files: Iterable | AsyncIterable | ReadableStream, options?: AddOptions): AsyncIterable; - } - - declare export interface PinService { - add(cid: CID, options?: PinAddOptions): Promise; - ls(options?: PinListOptions): AsyncIterable; - rm(cid: CID, options?: PinRemoveOptions): Promise; - remote: RemotePinService; + declare export type UnixFSTime = { + secs: number, + nsecs: number } - declare export interface RemotePinServicesOptions { - cid: CID[]; - service: string; - } - declare export interface RemotePinService { - rm(options: RemotePinServicesOptions): Promise; + declare export type UnixFSEntry = { + path: string, + cid: CID, + mode: number, + mtime: UnixFSTime, + size: number } - declare export interface FileService { - stat(path: string, options?: FSStatOptions): Promise; - cp(from: string, to: string, options?: FSCopyOptions): Promise; - mv(from: string, to: string, options?: FSMoveOptions): Promise; - rm(path: string, options: FSRemoveOptions): Promise; - mkdir(path: string, options: FSMakDirectoryOptions): Promise; - } + declare type FileContent = + | Uint8Array + | Blob + | String + | AsyncIterable + | ReadableStream - declare export interface ConfigService { - get(key: string, options?: TimeoutOptions): Promise; - getAll(options?: TimeoutOptions): Promise; - set(key: string, value: string | number | null | boolean | Object, options?: TimeoutOptions): Promise; - replace(config: Object, options?: TimeoutOptions): Promise; + declare export type FileType = + | 'file' + | 'directory' - profiles: ConfigProfiles; + declare type FileObject = { + path?: string, + content?: FileContent, + mode?: number | string, + mtime?: Date | UnixFSTime | [number, number] } - declare export interface ConfigProfiles { - list(options?: TimeoutOptions): Promise>; - apply(name: string, options?: { dryRun?: boolean } & TimeoutOptions): Promise<{ original: Object, updated: Object }>; + declare export type TimeoutOptions = { + timeout?: number, + signal?: AbortSignal } - declare export interface NameService { - resolve(value: string, options?: NameResloveOptions): AsyncIterable - } + declare export type ListOptions = TimeoutOptions & {} - declare export interface SwarmService { - connect(addr: Multiaddr, options?: TimeoutOptions): Promise + declare export type CatOptions = TimeoutOptions & { + offset?: number; + length?: number; } - declare export interface ObjectService { - new: (options?: ObjectNewOptions) => Promise; - patch: ObjectPatchService + declare type LoadProgress = { + total: number, + loaded: number, + lengthComputable: boolean } - declare export interface ObjectPatchService { - addLink(cid: CID, link: DAGLink, options?: TimeoutOptions): Promise + declare export type AddOptions = TimeoutOptions & { + chunker?: string, + cidVersion?: number, + hashAlg?: number, + onlyHash?: boolean, + pin?: boolean, + progress?: (bytes: number, name:string) => void, + rawLeaves?: boolean, + trickle?: boolean, + wrapWithDirectory?: boolean, + onUploadProgress?: (progress: LoadProgress) => void, + onDownloadProgress?: (progress: LoadProgress) => void } - declare export type DAGLink = { + declare export type ListEntry = { + depth: number, name: string, + path: string, size: number, - cid: CID + cid: CID, + // IPFS is pretty inconsistent with type field see + // https://github.com/ipfs/js-ipfs/issues/3229 + type: FileType | 'dir', + mode: number, + mtime: { secs: number, nsecs?: number } } - declare export type Pin = { cid: CID } - - declare export type TimeoutOptions = { - timeout?: number, - signal?: AbortSignal + declare export interface CoreService { + // TODO: cat returns AsyncIterable. see https://github.com/ipfs/js-kubo-rpc-client/blob/1ab7941819dd1a48df653ee159e6983608e72132/src/index.ts#L353C50-L353C75 + cat(pathOrCID: string | CID, options?: CatOptions): AsyncIterable; + ls(pathOrCID: string | CID, options?: ListOptions): AsyncIterable; + add(file: FileContent | FileObject, options?: AddOptions): Promise; + addAll(files: Iterable | AsyncIterable | ReadableStream, options?: AddOptions): AsyncIterable; } - declare export type PinAddOptions = TimeoutOptions & { - recursive?: boolean, - } + declare export type Pin = { cid: CID } declare export type PinType = | 'recursive' @@ -113,12 +109,43 @@ declare module 'ipfs' { recursive?: boolean } + declare export type PinAddOptions = TimeoutOptions & { + recursive?: boolean, + } + + declare export interface RemotePinServicesOptions { + cid: CID[]; + service: string; + } + + declare export interface RemotePinService { + rm(options: RemotePinServicesOptions): Promise; + } + + declare export interface PinService { + add(cid: CID, options?: PinAddOptions): Promise; + ls(options?: PinListOptions): AsyncIterable; + rm(cid: CID, options?: PinRemoveOptions): Promise; + remote: RemotePinService; + } + declare export type FSStatOptions = TimeoutOptions & { hash?: boolean, size?: boolean, withLocal?: boolean } + declare export interface FileStat { + cid: CID; + size: number; + cumulativeSize: number; + type: FileType; + blocks: number; + withLocality: boolean; + local: boolean; + sizeLocal: number; + } + declare export type FSCopyOptions = TimeoutOptions & { parents?: boolean, flush?: boolean, @@ -149,19 +176,12 @@ declare module 'ipfs' { cidVersion?: number } - declare export type FileType = - | 'file' - | 'directory' - - declare export interface FileStat { - cid: CID; - size: number; - cumulativeSize: number; - type: FileType; - blocks: number; - withLocality: boolean; - local: boolean; - sizeLocal: number; + declare export interface FileService { + stat(path: string, options?: FSStatOptions): Promise; + cp(from: string, to: string, options?: FSCopyOptions): Promise; + mv(from: string, to: string, options?: FSMoveOptions): Promise; + rm(path: string, options: FSRemoveOptions): Promise; + mkdir(path: string, options: FSMakDirectoryOptions): Promise; } declare export type NameResloveOptions = TimeoutOptions & { @@ -169,80 +189,59 @@ declare module 'ipfs' { nocache?: boolean } + declare export interface NameService { + resolve(value: string, options?: NameResloveOptions): AsyncIterable + } + declare export type ObjectNewOptions = TimeoutOptions & { template?: string, recursive?: boolean, nocache?: boolean } - declare export type CatOptions = TimeoutOptions & { - offset?: number; - length?: number; - } - - declare export type ListOptions = TimeoutOptions & { - - } - - declare export type ListEntry = { - depth: number, + declare export type DAGLink = { name: string, - path: string, size: number, - cid: CID, - // IPFS is pretty inconsistent with type field see - // https://github.com/ipfs/js-ipfs/issues/3229 - type: FileType | 'dir', - mode: number, - mtime: { secs: number, nsecs?: number } + cid: CID } - declare type FileContent = - | Uint8Array - | Blob - | String - | AsyncIterable - | ReadableStream + declare export interface ObjectPatchService { + addLink(cid: CID, link: DAGLink, options?: TimeoutOptions): Promise + } - declare type FileObject = { - path?: string, - content?: FileContent, - mode?: number | string, - mtime?: Date | UnixFSTime | [number, number] + declare export interface ObjectService { + new: (options?: ObjectNewOptions) => Promise; + patch: ObjectPatchService } - declare export type AddOptions = TimeoutOptions & { - chunker?: string, - cidVersion?: number, - hashAlg?: number, - onlyHash?: boolean, - pin?: boolean, - progress?: (bytes: number, name:string) => void, - rawLeaves?: boolean, - trickle?: boolean, - wrapWithDirectory?: boolean, - onUploadProgress?: (progress: LoadProgress) => void, - onDownloadProgress?: (progress: LoadProgress) => void + declare export interface ConfigProfiles { + list(options?: TimeoutOptions): Promise>; + apply(name: string, options?: { dryRun?: boolean } & TimeoutOptions): Promise<{ original: Object, updated: Object }>; } - declare type LoadProgress = { - total: number, - loaded: number, - lengthComputable: boolean + declare export interface ConfigService { + get(key: string, options?: TimeoutOptions): Promise; + getAll(options?: TimeoutOptions): Promise; + set(key: string, value: string | number | null | boolean | Object, options?: TimeoutOptions): Promise; + replace(config: Object, options?: TimeoutOptions): Promise; + + profiles: ConfigProfiles; } - declare export type UnixFSEntry = { - path: string, - cid: CID, - mode: number, - mtime: UnixFSTime, - size: number + declare export interface IPFSService extends CoreService { + pin: PinService; + files: FileService; + name: NameService; + object: ObjectService; + config: ConfigService; + dag: KuboRPCClient['dag']; + + stop(options?: TimeoutOptions): Promise } - declare export type UnixFSTime = { - secs: number, - nsecs: number + declare export interface SwarmService { + connect(addr: Multiaddr, options?: TimeoutOptions): Promise } - declare export var IPFS: IPFSService + declare export let IPFS: IPFSService } diff --git a/@types/it-all/index.d.ts b/@types/it-all/index.d.ts index 098a459dd..fc284c1ee 100644 --- a/@types/it-all/index.d.ts +++ b/@types/it-all/index.d.ts @@ -1,5 +1,5 @@ -declare module "it-all" { +declare module 'it-all' { function all(source: AsyncIterable): Promise export default all -} \ No newline at end of file +} diff --git a/@types/it-first/index.d.ts b/@types/it-first/index.d.ts index fc3e0fd2c..d8136786a 100644 --- a/@types/it-first/index.d.ts +++ b/@types/it-first/index.d.ts @@ -1,4 +1,4 @@ -declare module "it-first" { +declare module 'it-first' { function first(input: AsyncIterable): Promise export default first diff --git a/@types/it-last/index.d.ts b/@types/it-last/index.d.ts index 9a28430ad..95413b54e 100644 --- a/@types/it-last/index.d.ts +++ b/@types/it-last/index.d.ts @@ -1,5 +1,5 @@ -declare module "it-last" { +declare module 'it-last' { function last(input: AsyncIterable): Promise export default last -} \ No newline at end of file +} diff --git a/@types/it-map/index.d.ts b/@types/it-map/index.d.ts index 3cb73a2dc..7d3a66d14 100644 --- a/@types/it-map/index.d.ts +++ b/@types/it-map/index.d.ts @@ -1,4 +1,4 @@ -declare module "it-map" { +declare module 'it-map' { function map(input: AsyncIterable, f: (input: I) => O): AsyncIterable export default map -} \ No newline at end of file +} diff --git a/@types/redux-bundler/index.d.ts b/@types/redux-bundler/index.d.ts index 70b5dfd0e..434e8874c 100644 --- a/@types/redux-bundler/index.d.ts +++ b/@types/redux-bundler/index.d.ts @@ -1,4 +1,4 @@ -declare module "redux-bundler" { +declare module 'redux-bundler' { interface CreateSelector { (n1: string, f: (inn: I) => O): (state: State) => O, @@ -14,15 +14,13 @@ declare module "redux-bundler" { (s1: (state: State) => I1, s2: (state: State) => I2, s3: (state: State) => I3, s4: (state: State) => I4, s5: (state: State) => I5, f: (i1: I1, i2: I2, i3: I3, i4: I4, i5: I5) => O): (state: State) => O } - declare export var createSelector: CreateSelector + declare export let createSelector: CreateSelector export type Selector = (state: State) => Data type Action = { type: string } - - export type BaseStore = { getState(): State dispatch(message: Message): void @@ -38,7 +36,6 @@ declare module "redux-bundler" { destroy(): void } & Ext - export type Context = { getState(): State dispatch(message: Message): void @@ -48,23 +45,24 @@ declare module "redux-bundler" { export type Reducer = (state?: State, message: Message) => State - export type BundleInit = + export type BundleInit = (store: Store) => void | (() => void) - export type Bundle = { + export type Bundle = { name: string reducer?: Reducer getReducer?: () => Reducer } - export type Selectors = { [K in keyof T]: T[K] extends Selector ? () => D : never } + type ParamsType = T extends (...args: infer P) => any ? P : never; + export type Actions = { [K in keyof T]: (...args: ParamsType) => ReturnType> } -} \ No newline at end of file +} diff --git a/package.json b/package.json index a3eb69bdf..4f842a712 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "start:win32": "@powershell -Command $env:REACT_APP_GIT_REV=(git rev-parse --short HEAD); react-app-rewired-esm start", "start:darwin:linux": "cross-env NODE_ENV=development REACT_APP_ENV=development REACT_APP_GIT_REV=`git rev-parse --short HEAD` react-app-rewired-esm start", "lint": "run-s eslint typecheck dep-check", - "eslint": "eslint src/ test/", + "eslint": "eslint .", "prebuild": "lol public/locales > src/lib/languages.json", "build": "run-script-os", "build:win32": "@powershell -Command $env:REACT_APP_GIT_REV=(git rev-parse --short HEAD); react-app-rewired-esm build", diff --git a/postcss.config.js b/postcss.config.js index 831553efe..746a5378a 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -6,7 +6,7 @@ module.exports = { plugins: [ require('postcss-flexbugs-fixes'), require('autoprefixer')({ - flexbox: 'no-2009', - }), - ], -}; + flexbox: 'no-2009' + }) + ] +} diff --git a/src/bundles/analytics.js b/src/bundles/analytics.js index f1c4c144d..766cc22b8 100644 --- a/src/bundles/analytics.js +++ b/src/bundles/analytics.js @@ -3,7 +3,7 @@ // @ts-ignore import root from 'window-or-global' import changeCase from 'change-case' -import * as Enum from '../lib/enum.js' +import { from } from '../lib/enum.js' import { createSelector } from 'redux-bundler' import { ACTIONS as FILES } from './files/consts.js' import { ACTIONS as CONIFG } from './config-save.js' @@ -79,10 +79,10 @@ const DISABLE_ALL_ANALYTICS = true // Unknown actions (can't seem to see anything // dispatching those). -const DESKTOP = Enum.from(['DESKTOP_SETTING_TOGGLE']) +const DESKTOP = from(['DESKTOP_SETTING_TOGGLE']) // Local action types -const ACTIONS = Enum.from([ +const ACTIONS = from([ 'ANALYTICS_ENABLED', 'ANALYTICS_DISABLED', 'ANALYTICS_ADD_CONSENT', @@ -136,10 +136,12 @@ const consentGroups = { * @param {Store} store */ function addConsent (consent, store) { - root.Countly.q.push(['add_consent', consent]) + const consentArray = Array.isArray(consent) ? consent : [consent] + + root.Countly.q.push(['add_consent', consentArray]) if (store.selectIsIpfsDesktop()) { - store.doDesktopAddConsent(consent) + store.doDesktopAddConsent(consentArray) } } @@ -148,10 +150,12 @@ function addConsent (consent, store) { * @param {Store} store */ function removeConsent (consent, store) { - root.Countly.q.push(['remove_consent', consent]) + const consentArray = Array.isArray(consent) ? consent : [consent] + + root.Countly.q.push(['remove_consent', consentArray]) if (store.selectIsIpfsDesktop()) { - store.doDesktopRemoveConsent(consent) + store.doDesktopRemoveConsent(consentArray) } } diff --git a/src/lib/enum.js b/src/lib/enum.js index 8f4c1475a..0a12a7ab5 100644 --- a/src/lib/enum.js +++ b/src/lib/enum.js @@ -1,5 +1,3 @@ -// @ts-check - /** * @template {string} T * @param {T[]} variants