Skip to content

Commit

Permalink
refactor: add type json to json imports (#11857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works authored Oct 14, 2024
1 parent 0a25f45 commit d3d148c
Show file tree
Hide file tree
Showing 101 changed files with 918 additions and 912 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-mangos-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@masknet/encryption': patch
---

chore: support type for ts 5.7
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"@emotion/react": "11.11.4",
"@emotion/serialize": "1.1.4",
"@emotion/styled": "11.11.5",
"@lingui/core": "^4.11.3",
"@lingui/react": "^4.11.3",
"@masknet/kit": "0.4.0",
"@lingui/core": "^4.12.0",
"@lingui/react": "^4.12.0",
"@masknet/kit": "0.4.1",
"@mui/base": "5.0.0-beta.40",
"@mui/icons-material": "5.15.21",
"@mui/lab": "5.0.0-alpha.170",
Expand All @@ -48,7 +48,7 @@
"@types/masknet__global-types": "workspace:^",
"@types/react": "npm:types-react@beta",
"@types/react-dom": "npm:types-react-dom@beta",
"@typescript/lib-dom": "npm:@types/web@^0.0.150",
"@typescript/lib-dom": "npm:@types/web@^0.0.171",
"i18next": "^23.11.5",
"knip": "^5.23.2",
"lodash-es": "^4.17.21",
Expand All @@ -64,16 +64,16 @@
"@commitlint/config-conventional": "^19.2.2",
"@eslint-react/eslint-plugin": "^1.14.3",
"@eslint/compat": "^1.1.1",
"@lingui/cli": "^4.11.3",
"@lingui/macro": "^4.11.3",
"@lingui/swc-plugin": "^4.0.8",
"@lingui/cli": "^4.12.0",
"@lingui/macro": "^4.12.0",
"@lingui/swc-plugin": "^4.0.10",
"@magic-works/i18n-codegen": "^0.6.1",
"@masknet/cli": "workspace:^",
"@masknet/config": "workspace:^",
"@masknet/eslint-plugin": "^0.3.0",
"@nice-labs/git-rev": "^3.5.1",
"@swc-node/register": "^1.10.9",
"@swc/core": "1.6.13",
"@swc/core": "1.7.35",
"@tanstack/eslint-plugin-query": "^5.59.7",
"@types/lodash-es": "^4.17.12",
"@vitest/ui": "^1.6.0",
Expand All @@ -92,7 +92,7 @@
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"svgo": "^3.3.2",
"typescript": "5.5.2",
"typescript": "5.7.0-beta",
"typescript-eslint": "^8.8.1",
"vite": "^5.3.2",
"vitest": "^1.6.0"
Expand All @@ -108,7 +108,7 @@
"@protobufjs/inquire": "1.1.0",
"@splinetool/runtime": "0.9.342",
"@tanstack/react-query": "^5.49.2",
"@types/node": "20.14.9",
"@types/node": "22.7.5",
"@types/react": "$@types/react",
"@types/react-dom": "$@types/react-dom",
"glob-stream": "7.0.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/backup-format/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ function getMagicHeader(version: SupportedVersions) {
}

/** @internal */
export async function createContainer(version: SupportedVersions, data: ArrayBuffer) {
export async function createContainer(version: SupportedVersions, data: ArrayBuffer | Uint8Array<ArrayBuffer>) {
const checksum = await crypto.subtle.digest({ name: 'SHA-256' }, data)
return concatArrayBuffer(getMagicHeader(version), data, checksum)
}

/** @internal */
export async function parseEncryptedJSONContainer(version: SupportedVersions, _container: ArrayBuffer) {
export async function parseEncryptedJSONContainer(
version: SupportedVersions,
_container: ArrayBuffer | ArrayLike<number>,
) {
const container = new Uint8Array(_container)

for (const [index, value] of getMagicHeader(version).entries()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/backup-format/src/version-3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export async function encryptBackup(password: BufferSource, binaryBackup: Buffer
const AESParam: AesGcmParams = { name: 'AES-GCM', iv: crypto.getRandomValues(new Uint8Array(16)) }

const encrypted = new Uint8Array(await crypto.subtle.encrypt(AESParam, AESKey, binaryBackup))
const container = encode([pbkdf2IV, AESParam.iv, encrypted])
const container = encode([pbkdf2IV, AESParam.iv, encrypted]) as Uint8Array<ArrayBuffer>
return createContainer(SupportedVersions.Version0, container)
}

export async function decryptBackup(password: BufferSource, data: ArrayBuffer) {
export async function decryptBackup(password: BufferSource, data: ArrayBuffer | ArrayLike<number>) {
const container = await parseEncryptedJSONContainer(SupportedVersions.Version0, data)

const _ = decode(container)
Expand Down
2 changes: 1 addition & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"types": "./dist/index.d.ts",
"dependencies": {
"@masknet/kit": "0.4.0",
"@masknet/kit": "0.4.1",
"anchorme": "^2.1.2",
"pvtsutils": "^1.3.5",
"tiny-secp256k1": "^2.2.3",
Expand Down
8 changes: 4 additions & 4 deletions packages/base/src/Identifier/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class ECKeyIdentifier extends Identifier {
}
declare [Symbol.toStringTag]: string
#ec: undefined
static [Symbol.hasInstance](x: any): boolean {
static override [Symbol.hasInstance](x: any): boolean {
return typeof x === 'object' && x !== null && #ec in x
}
static {
Expand Down Expand Up @@ -190,7 +190,7 @@ export class PostIVIdentifier extends Identifier {
}
declare [Symbol.toStringTag]: string
#post_iv: undefined
static [Symbol.hasInstance](x: any): boolean {
static override [Symbol.hasInstance](x: any): boolean {
return typeof x === 'object' && x !== null && #post_iv in x
}
static {
Expand Down Expand Up @@ -240,7 +240,7 @@ export class PostIdentifier extends Identifier {
}
declare [Symbol.toStringTag]: string
#post: undefined
static [Symbol.hasInstance](x: any): boolean {
static override [Symbol.hasInstance](x: any): boolean {
return typeof x === 'object' && x !== null && #post in x
}
static {
Expand Down Expand Up @@ -304,7 +304,7 @@ export class ProfileIdentifier extends Identifier {
}
declare [Symbol.toStringTag]: string
#profile: undefined
static [Symbol.hasInstance](x: any): boolean {
static override [Symbol.hasInstance](x: any): boolean {
return typeof x === 'object' && x !== null && #profile in x
}
static {
Expand Down
1 change: 1 addition & 0 deletions packages/config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"noImplicitThis": true,
// noPropertyAccessFromIndexSignature: false,
// noUncheckedIndexedAccess: false,
"noUncheckedSideEffectImports": true,
// noUnusedLocals: false,
// noUnusedParameters: false,
"useUnknownInCatchVariables": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/image-steganography/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface EncodeImageOptions extends SteganographyIO {
preset: SteganographyPreset
}

export async function steganographyEncodeImage(buf: ArrayBuffer, options: EncodeImageOptions) {
export async function steganographyEncodeImage(buf: ArrayLike<number> | ArrayBufferLike, options: EncodeImageOptions) {
const { downloadImage, data, password, grayscaleAlgorithm } = options
const preset = getPreset(options.preset)
if (!preset) throw new Error('Failed to find preset.')
Expand Down
4 changes: 2 additions & 2 deletions packages/injected-script/main/Patches/DataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class __FileList extends $unsafe.NewObject implements FileList {
if (!(#files in list)) return $.apply($.FileListPrototypeDesc.item.value!, this, arguments)
return list.#files[index] ?? null
}
[Symbol.iterator](): IterableIterator<File> {
[Symbol.iterator](): ArrayIterator<File> {
const list = $unsafe.unwrapXRayVision(this)
if (!(#files in list)) return $.apply($.FileListPrototypeDesc[Symbol.iterator].value!, this, arguments)
return $unsafe.Array_values(list.#files)
Expand Down Expand Up @@ -254,7 +254,7 @@ export class __DataTransferItemList extends $unsafe.NewObject implements DataTra
new $.DOMException('The object is in an invalid state.', 'InvalidStateError'),
)
}
[Symbol.iterator](): IterableIterator<DataTransferItem> {
[Symbol.iterator](): ArrayIterator<DataTransferItem> {
const list = $unsafe.unwrapXRayVision(this)
if (!(#items in list))
return $.apply($.DataTransferItemListPrototypeDesc[Symbol.iterator].value!, this, arguments)
Expand Down
2 changes: 1 addition & 1 deletion packages/mask-sdk/shared/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const [ArrayBufferEncode, ArrayBufferDecode] = createClassSerializer(
(e) => [...new Uint8Array(e)],
(e) => new Uint8Array(e).buffer,
)
const [U8ArrayEncode, U8ArrayDecode] = createClassSerializer(
const [U8ArrayEncode, U8ArrayDecode] = createClassSerializer<Uint8Array, number[]>(
Uint8Array,
(e) => [...e],
(e) => new Uint8Array(e),
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/background/database/persona/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function encryptByLocalKey(who: ProfileIdentifier, content: Uint8Ar
})
if (!key) throw new Error('No local key found')
const result = await crypto.subtle.encrypt({ iv, name: 'AES-GCM' }, key, content)
return result as Uint8Array
return result
}

async function getLocalKeyOf(id: ProfileIdentifier, tx: FullPersonaDBTransaction<'readonly'>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/background/services/crypto/steganography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function fetchImage(url: string) {
const steganographyDownloadImage = memoizePromise(memoize, fetchImage, (x) => x)

export function steganographyEncodeImage(
buf: ArrayBuffer,
buf: ArrayLike<number> | ArrayBufferLike,
options: Omit<EncodeImageOptions, 'downloadImage'>,
): Promise<Uint8Array> {
return __steganographyEncodeImage(buf, { ...options, downloadImage: steganographyDownloadImage })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ function deriveAES(key: CryptoKey, iv: ArrayBuffer) {
function createAES() {
return crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt'])
}
function encrypt(message: ArrayBuffer, key: CryptoKey, iv: ArrayBuffer) {
function encrypt(message: BufferSource, key: CryptoKey, iv: BufferSource) {
return crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, message)
}
function decrypt(message: ArrayBuffer, key: CryptoKey, iv: ArrayBuffer) {
function decrypt(message: BufferSource, key: CryptoKey, iv: BufferSource) {
return crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, message)
}
function wrapKey(key: CryptoKey, wrapKey: CryptoKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// Run `npx gulp sync-languages` to regenerate.
// Default fallback language in a family of languages are chosen by the alphabet order
// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts
import en_US from './en-US.json'
import ja_JP from './ja-JP.json'
import ko_KR from './ko-KR.json'
import qya_AA from './qya-AA.json'
import zh_CN from './zh-CN.json'
import zh_TW from './zh-TW.json'
import lingui_en_US from '../../../../shared-ui/locale/en-US.json'
import lingui_ja_JP from '../../../../shared-ui/locale/ja-JP.json'
import lingui_ko_KR from '../../../../shared-ui/locale/ko-KR.json'
import lingui_zh_CN from '../../../../shared-ui/locale/zh-CN.json'
import lingui_zh_TW from '../../../../shared-ui/locale/zh-TW.json'
import en_US from './en-US.json' with { type: 'json' }
import ja_JP from './ja-JP.json' with { type: 'json' }
import ko_KR from './ko-KR.json' with { type: 'json' }
import qya_AA from './qya-AA.json' with { type: 'json' }
import zh_CN from './zh-CN.json' with { type: 'json' }
import zh_TW from './zh-TW.json' with { type: 'json' }
import lingui_en_US from '../../../../shared-ui/locale/en-US.json' with { type: 'json' }
import lingui_ja_JP from '../../../../shared-ui/locale/ja-JP.json' with { type: 'json' }
import lingui_ko_KR from '../../../../shared-ui/locale/ko-KR.json' with { type: 'json' }
import lingui_zh_CN from '../../../../shared-ui/locale/zh-CN.json' with { type: 'json' }
import lingui_zh_TW from '../../../../shared-ui/locale/zh-TW.json' with { type: 'json' }
export const languages = {
en: en_US,
ja: ja_JP,
Expand Down
22 changes: 11 additions & 11 deletions packages/mask/dashboard/locales/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// Run `npx gulp sync-languages` to regenerate.
// Default fallback language in a family of languages are chosen by the alphabet order
// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts
import en_US from './en-US.json'
import ja_JP from './ja-JP.json'
import ko_KR from './ko-KR.json'
import qya_AA from './qya-AA.json'
import zh_CN from './zh-CN.json'
import zh_TW from './zh-TW.json'
import lingui_en_US from '../../shared-ui/locale/en-US.json'
import lingui_ja_JP from '../../shared-ui/locale/ja-JP.json'
import lingui_ko_KR from '../../shared-ui/locale/ko-KR.json'
import lingui_zh_CN from '../../shared-ui/locale/zh-CN.json'
import lingui_zh_TW from '../../shared-ui/locale/zh-TW.json'
import en_US from './en-US.json' with { type: 'json' }
import ja_JP from './ja-JP.json' with { type: 'json' }
import ko_KR from './ko-KR.json' with { type: 'json' }
import qya_AA from './qya-AA.json' with { type: 'json' }
import zh_CN from './zh-CN.json' with { type: 'json' }
import zh_TW from './zh-TW.json' with { type: 'json' }
import lingui_en_US from '../../shared-ui/locale/en-US.json' with { type: 'json' }
import lingui_ja_JP from '../../shared-ui/locale/ja-JP.json' with { type: 'json' }
import lingui_ko_KR from '../../shared-ui/locale/ko-KR.json' with { type: 'json' }
import lingui_zh_CN from '../../shared-ui/locale/zh-CN.json' with { type: 'json' }
import lingui_zh_TW from '../../shared-ui/locale/zh-TW.json' with { type: 'json' }
export const languages = {
en: en_US,
ja: ja_JP,
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/popups/pages/Wallet/ChangeOwner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom'
import type { AbiItem } from 'web3-utils'
import { useContainer } from '@masknet/shared-base-ui'
import { EVMContract, EVMExplorerResolver, EVMWeb3 } from '@masknet/web3-providers'
import WalletABI from '@masknet/web3-contracts/abis/Wallet.json'
import WalletABI from '@masknet/web3-contracts/abis/Wallet.json' with { type: 'json' }
import type { Wallet } from '@masknet/web3-contracts/types/Wallet.js'
import { Box, Link, Popover, Typography, alpha } from '@mui/material'
import { Icons } from '@masknet/icons'
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/popups/pages/Wallet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { BigNumber } from 'bignumber.js'
import * as web3_utils from /* webpackDefer: true */ 'web3-utils'
import type { AbiItem } from 'web3-utils'
import { EVMWeb3 } from '@masknet/web3-providers'
import ERC20_ABI from '@masknet/web3-contracts/abis/ERC20.json'
import ERC20_ABI from '@masknet/web3-contracts/abis/ERC20.json' with { type: 'json' }
import { toFixed, type RecentTransaction } from '@masknet/web3-shared-base'
import {
ProviderType,
Expand Down
10 changes: 5 additions & 5 deletions packages/mask/shared-ui/locale/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Run `npx gulp sync-languages` to regenerate.
// Default fallback language in a family of languages are chosen by the alphabet order
// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts
import en_US from './en-US.json'
import ja_JP from './ja-JP.json'
import ko_KR from './ko-KR.json'
import zh_CN from './zh-CN.json'
import zh_TW from './zh-TW.json'
import en_US from './en-US.json' with { type: 'json' }
import ja_JP from './ja-JP.json' with { type: 'json' }
import ko_KR from './ko-KR.json' with { type: 'json' }
import zh_CN from './zh-CN.json' with { type: 'json' }
import zh_TW from './zh-TW.json' with { type: 'json' }
export const languages = {
en: en_US,
ja: ja_JP,
Expand Down
22 changes: 11 additions & 11 deletions packages/mask/shared-ui/locales/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// Run `npx gulp sync-languages` to regenerate.
// Default fallback language in a family of languages are chosen by the alphabet order
// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts
import en_US from './en-US.json'
import ja_JP from './ja-JP.json'
import ko_KR from './ko-KR.json'
import qya_AA from './qya-AA.json'
import zh_CN from './zh-CN.json'
import zh_TW from './zh-TW.json'
import lingui_en_US from '../locale/en-US.json'
import lingui_ja_JP from '../locale/ja-JP.json'
import lingui_ko_KR from '../locale/ko-KR.json'
import lingui_zh_CN from '../locale/zh-CN.json'
import lingui_zh_TW from '../locale/zh-TW.json'
import en_US from './en-US.json' with { type: 'json' }
import ja_JP from './ja-JP.json' with { type: 'json' }
import ko_KR from './ko-KR.json' with { type: 'json' }
import qya_AA from './qya-AA.json' with { type: 'json' }
import zh_CN from './zh-CN.json' with { type: 'json' }
import zh_TW from './zh-TW.json' with { type: 'json' }
import lingui_en_US from '../locale/en-US.json' with { type: 'json' }
import lingui_ja_JP from '../locale/ja-JP.json' with { type: 'json' }
import lingui_ko_KR from '../locale/ko-KR.json' with { type: 'json' }
import lingui_zh_CN from '../locale/zh-CN.json' with { type: 'json' }
import lingui_zh_TW from '../locale/zh-TW.json' with { type: 'json' }
export const languages = {
en: en_US,
ja: ja_JP,
Expand Down
10 changes: 5 additions & 5 deletions packages/plugins/Approval/src/locale/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Run `npx gulp sync-languages` to regenerate.
// Default fallback language in a family of languages are chosen by the alphabet order
// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts
import en_US from './en-US.json'
import ja_JP from './ja-JP.json'
import ko_KR from './ko-KR.json'
import zh_CN from './zh-CN.json'
import zh_TW from './zh-TW.json'
import en_US from './en-US.json' with { type: 'json' }
import ja_JP from './ja-JP.json' with { type: 'json' }
import ko_KR from './ko-KR.json' with { type: 'json' }
import zh_CN from './zh-CN.json' with { type: 'json' }
import zh_TW from './zh-TW.json' with { type: 'json' }
export const languages = {
en: en_US,
ja: ja_JP,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AbiItem } from 'web3-utils'
import { useContract } from '@masknet/web3-hooks-evm'
import { type ChainId, useArtBlocksConstants } from '@masknet/web3-shared-evm'
import ArtBlocksCoreContractABI from '@masknet/web3-contracts/abis/ArtBlocksMinterContract.json'
import ArtBlocksCoreContractABI from '@masknet/web3-contracts/abis/ArtBlocksMinterContract.json' with { type: 'json' }

import type { ArtBlocksMinterContract } from '@masknet/web3-contracts/types/ArtBlocksMinterContract.js'

Expand Down
10 changes: 5 additions & 5 deletions packages/plugins/ArtBlocks/src/locale/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Run `npx gulp sync-languages` to regenerate.
// Default fallback language in a family of languages are chosen by the alphabet order
// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts
import en_US from './en-US.json'
import ja_JP from './ja-JP.json'
import ko_KR from './ko-KR.json'
import zh_CN from './zh-CN.json'
import zh_TW from './zh-TW.json'
import en_US from './en-US.json' with { type: 'json' }
import ja_JP from './ja-JP.json' with { type: 'json' }
import ko_KR from './ko-KR.json' with { type: 'json' }
import zh_CN from './zh-CN.json' with { type: 'json' }
import zh_TW from './zh-TW.json' with { type: 'json' }
export const languages = {
en: en_US,
ja: ja_JP,
Expand Down
Loading

0 comments on commit d3d148c

Please sign in to comment.