Skip to content

Commit

Permalink
chore: upgrade deps (#10681)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Aug 31, 2023
1 parent f8b196c commit 7714e20
Show file tree
Hide file tree
Showing 146 changed files with 5,356 additions and 2,912 deletions.
8 changes: 8 additions & 0 deletions .changeset/cool-singers-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@masknet/typed-message-react': minor
'@masknet/typed-message': minor
'@masknet/encryption': minor
'@masknet/base': minor
---

refactor!: upgrade to ts-results-es 4.0.0
48 changes: 23 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@mui/system": "5.10.8",
"@tanstack/react-query": "^4.29.25",
"@types/masknet__global-types": "workspace:^",
"@types/react": "18.2.15",
"@types/react": "18.2.21",
"@types/react-dom": "^18.2.7",
"@typescript/lib-dom": "npm:@types/web@^0.0.109",
"i18next": "^23.2.11",
Expand All @@ -53,48 +53,47 @@
"react-dom": "0.0.0-experimental-0a360642d-20230711",
"react-i18next": "^13.0.2",
"ses": "0.18.7",
"ts-results-es": "^3.6.0"
"ts-results-es": "^4.0.0"
},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@commitlint/cli": "^17.6.7",
"@commitlint/config-conventional": "^17.6.7",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@magic-works/i18n-codegen": "^0.5.0",
"@masknet/cli": "workspace:^",
"@masknet/config": "workspace:^",
"@masknet/eslint-plugin": "^0.2.0",
"@masknet/serializer": "workspace:^",
"@nice-labs/git-rev": "^3.5.1",
"@swc/core": "1.3.70",
"@types/lodash-es": "^4.17.8",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@vitest/ui": "^0.33.0",
"cross-fetch": "3.1.5",
"cspell": "^6.31.2",
"eslint": "8.45.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-react": "^7.32.2",
"@swc/core": "1.3.81",
"@types/lodash-es": "^4.17.9",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"@vitest/ui": "^0.34.3",
"cross-fetch": "^4.0.0",
"cspell": "^7.2.0",
"eslint": "8.48.0",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-tss-unused-classes": "^0.0.4",
"eslint-plugin-unicorn": "^48.0.0",
"eslint-plugin-tss-unused-classes": "^1.0.1",
"eslint-plugin-unicorn": "^48.0.1",
"eslint-plugin-unused-imports": "^3.0.0",
"gulp": "^4.0.2",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
"lint-staged": "^14.0.1",
"msw": "^1.2.1",
"prettier": "^3.0.0",
"prettier": "^3.0.3",
"svgo": "^3.0.2",
"ts-node": "^10.9.1",
"typescript": "5.2.0-dev.20230630",
"vite": "^4.4.4",
"vitest": "^0.33.0"
"typescript": "5.3.0-dev.20230830",
"vite": "^4.4.9",
"vitest": "^0.34.3"
},
"pnpm": {
"overrides": {
"@types/node": "20.4.2",
"@types/react": "18.2.15",
"cross-fetch": "3.1.5",
"@types/node": "20.5.7",
"@types/react": "18.2.21",
"cross-blob": "3.0.1",
"i18next-translation-parser>html-parse-stringify2": "github:locize/html-parse-stringify2#d463109433b2c49c74a081044f54b2a6a1ccad7c",
"web3@0.20.7>bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934",
Expand Down Expand Up @@ -129,7 +128,6 @@
}
},
"patchedDependencies": {
"cross-fetch@3.1.5": "patches/cross-fetch@3.1.5.patch",
"@uniswap/v3-sdk@3.9.0": "patches/@uniswap__v3-sdk@3.9.0.patch",
"@ceramicnetwork/rpc-transport@0.3.1": "patches/@ceramicnetwork__rpc-transport@0.3.1.patch",
"gulp@4.0.2": "patches/gulp@4.0.2.patch",
Expand Down
10 changes: 5 additions & 5 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"cssnano": "^6.0.1",
"date-fns": "^2.30.0",
"idb": "^7.1.1",
"postcss": "^8.4.26",
"postcss": "^8.4.29",
"postcss-cli": "^10.1.0",
"purgecss": "^5.0.0",
"react-router-dom": "^6.14.2",
Expand All @@ -107,19 +107,19 @@
},
"devDependencies": {
"@nice-labs/emit-file-webpack-plugin": "^1.1.4",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@sinonjs/text-encoding": "^0.7.2",
"@types/terser-webpack-plugin": "^5.2.0",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
"html-webpack-plugin": "^5.5.3",
"react-refresh": "^0.14.0",
"source-map-loader": "^4.0.1",
"style-loader": "^3.3.3",
"swc-loader": "^0.2.3",
"terser-webpack-plugin": "^5.3.9",
"webpack": "Jack-Works/webpack#lazy-import",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"terser-webpack-plugin": "^5.3.9",
"@types/terser-webpack-plugin": "^5.2.0"
"webpack-dev-server": "^4.15.1"
}
}
2 changes: 1 addition & 1 deletion packages/app/src/main/Decrypt/useDecrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function main(version: string, data: string): Promise<false | TypedMessage
const payload = version === '1' ? await parsePayloadText(data) : await parsePayloadBinary(data)
if (!payload) return false

if (payload.encryption.ok && payload.encryption.val.type === 'E2E')
if (payload.encryption.isOk() && payload.encryption.value.type === 'E2E')
return new DecryptError(DecryptErrorReasons.PrivateKeyNotFound, undefined)

return decrypt(data, payload)
Expand Down
2 changes: 1 addition & 1 deletion packages/backup-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@masknet/shared-base": "workspace:^",
"@msgpack/msgpack": "^3.0.0-beta2",
"elliptic": "^6.5.4",
"pvtsutils": "^1.3.2"
"pvtsutils": "^1.3.5"
},
"devDependencies": {
"@types/elliptic": "^6.4.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/backup-format/src/utils/backupPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function getBackupSummary(json: NormalizedBackup.Data): BackupSummary {
files = Number((json.plugins?.['com.maskbook.fileservice'] as any)?.length || 0)
} catch {}

const ownerPersonas = [...json.personas.values()].filter((persona) => !persona.privateKey.none)
const ownerPersonas = [...json.personas.values()].filter((persona) => !persona.privateKey.isNone())
const ownerProfiles = flatten(ownerPersonas.map((persona) => [...persona.linkedProfiles.keys()])).map((item) =>
item.toText(),
)
Expand All @@ -31,7 +31,7 @@ export function getBackupSummary(json: NormalizedBackup.Data): BackupSummary {
.map((p) => p.nickname.unwrapOr(p.identifier.rawPublicKey).trim()),
)
const contacts = [...json.profiles.values()].filter((profile) => {
return !ownerProfiles.includes(profile.identifier.toText()) && profile.linkedPersona.some
return !ownerProfiles.includes(profile.identifier.toText()) && profile.linkedPersona.isSome()
})
return {
// Names or publicKeys */
Expand Down
4 changes: 2 additions & 2 deletions packages/backup-format/src/version-0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export async function normalizeBackupVersion0(file: BackupJSONFileVersion0): Pro
backup.personas.set(persona.identifier, persona)

const identifier = ProfileIdentifier.of('facebook.com', username)
if (identifier.some) {
if (identifier.isSome()) {
const profile: NormalizedBackup.ProfileBackup = {
identifier: identifier.val,
identifier: identifier.value,
linkedPersona: Some(persona.identifier),
createdAt: None,
updatedAt: None,
Expand Down
4 changes: 2 additions & 2 deletions packages/backup-format/src/version-1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export async function normalizeBackupVersion1(file: BackupJSONFileVersion1): Pro
}
if (isAESJsonWebKey(localKey)) {
profile.localKey = Some(localKey)
if (profile.linkedPersona.some && backup.personas.has(profile.linkedPersona.val)) {
backup.personas.get(profile.linkedPersona.val)!.localKey = Some(localKey)
if (profile.linkedPersona.isSome() && backup.personas.has(profile.linkedPersona.value)) {
backup.personas.get(profile.linkedPersona.value)!.localKey = Some(localKey)
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions packages/backup-format/src/version-2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export async function normalizeBackupVersion2(item: BackupJSONFileVersion2): Pro
}
for (const [profile] of persona.linkedProfiles) {
const id = ProfileIdentifier.from(profile)
if (id.none) continue
normalizedPersona.linkedProfiles.set(id.val, null)
if (id.isNone()) continue
normalizedPersona.linkedProfiles.set(id.value, null)
}
if (persona.mnemonic) {
const { words, parameter } = persona.mnemonic
Expand All @@ -65,16 +65,16 @@ export async function normalizeBackupVersion2(item: BackupJSONFileVersion2): Pro

for (const profile of profiles) {
const identifier = ProfileIdentifier.from(profile.identifier)
if (identifier.none) continue
if (identifier.isNone()) continue
const normalizedProfile: NormalizedBackup.ProfileBackup = {
identifier: identifier.val,
identifier: identifier.value,
createdAt: Some(new Date(profile.createdAt)),
updatedAt: Some(new Date(profile.updatedAt)),
nickname: profile.nickname ? Some(profile.nickname) : None,
linkedPersona: ECKeyIdentifier.from(profile.linkedPersona),
localKey: isAESJsonWebKey(profile.localKey) ? Some(profile.localKey) : None,
}
backup.profiles.set(identifier.val, normalizedProfile)
backup.profiles.set(identifier.value, normalizedProfile)
}

for (const persona of backup.personas.values()) {
Expand All @@ -92,10 +92,10 @@ export async function normalizeBackupVersion2(item: BackupJSONFileVersion2): Pro
const postBy = ProfileIdentifier.from(post.postBy)
const encryptBy = ECKeyIdentifier.from(post.encryptBy)

if (identifier.none) continue
if (identifier.isNone()) continue
const interestedMeta = new Map<string, any>()
const normalizedPost: NormalizedBackup.PostBackup = {
identifier: identifier.val,
identifier: identifier.value,
foundAt: new Date(post.foundAt),
postBy,
interestedMeta,
Expand All @@ -113,9 +113,9 @@ export async function normalizeBackupVersion2(item: BackupJSONFileVersion2): Pro
const map = new Map<ProfileIdentifier, NormalizedBackup.RecipientReason[]>()
for (const [recipient, { reason }] of post.recipients) {
const id = ProfileIdentifier.from(recipient)
if (id.none) continue
if (id.isNone()) continue
const reasons: NormalizedBackup.RecipientReason[] = []
map.set(id.val, reasons)
map.set(id.value, reasons)
for (const r of reason) {
// we ignore the original reason because we no longer support group / auto sharing
reasons.push({ type: 'direct', at: new Date(r.at) })
Expand All @@ -126,17 +126,17 @@ export async function normalizeBackupVersion2(item: BackupJSONFileVersion2): Pro
}
if (post.interestedMeta) normalizedPost.interestedMeta = MetaFromJson(post.interestedMeta)

backup.posts.set(identifier.val, normalizedPost)
backup.posts.set(identifier.value, normalizedPost)
}

for (const relation of relations || []) {
const { profile, persona, favor } = relation
const a = ProfileIdentifier.from(profile)
const b = ECKeyIdentifier.from(persona)
if (a.some && b.some) {
if (a.isSome() && b.isSome()) {
backup.relations.push({
profile: a.val,
persona: b.val,
profile: a.value,
persona: b.value,
favor,
})
}
Expand Down Expand Up @@ -232,7 +232,7 @@ export function generateBackupVersion2(item: NormalizedBackup.Data): BackupJSONF
const item: BackupJSONFileVersion2['posts'][0] = {
identifier: id.toText(),
foundAt: Number(data.foundAt),
postBy: data.postBy.some ? data.postBy.val.toText() : 'person:localhost/$unknown',
postBy: data.postBy.isSome() ? data.postBy.value.toText() : 'person:localhost/$unknown',
interestedMeta: MetaToJson(data.interestedMeta),
encryptBy: data.encryptBy.unwrapOr(undefined)?.toText(),
summary: data.summary.unwrapOr(undefined),
Expand All @@ -242,11 +242,11 @@ export function generateBackupVersion2(item: NormalizedBackup.Data): BackupJSONF
recipients: [],
}
result.posts.push(item)
if (data.recipients.some) {
if (data.recipients.val.type === 'public') item.recipients = 'everyone'
else if (data.recipients.val.type === 'e2e') {
if (data.recipients.isSome()) {
if (data.recipients.value.type === 'public') item.recipients = 'everyone'
else if (data.recipients.value.type === 'e2e') {
item.recipients = []
for (const [recipient, reasons] of data.recipients.val.receivers) {
for (const [recipient, reasons] of data.recipients.value.receivers) {
if (!reasons.length) continue
item.recipients.push([
recipient.toText(),
Expand All @@ -260,7 +260,7 @@ export function generateBackupVersion2(item: NormalizedBackup.Data): BackupJSONF
},
])
}
} else safeUnreachable(data.recipients.val)
} else safeUnreachable(data.recipients.value)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"dependencies": {
"@masknet/kit": "0.1.2",
"anchorme": "^2.1.2",
"pvtsutils": "^1.3.2",
"pvtsutils": "^1.3.5",
"tiny-secp256k1": "^2.2.3",
"ts-results-es": "^3.6.0"
"ts-results-es": "^4.0.0"
},
"files": [
"src",
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/Identifier/ec-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class ECKeyIdentifier extends Identifier {
if (!key.extractable) return Err('key is not extractable')
if ((key.algorithm as EcKeyAlgorithm).namedCurve !== 'K-256') return Err('curve is not K-256')
const jwk = await Result.wrapAsync(() => crypto.subtle.exportKey('jwk', key))
if (jwk.err) return jwk
return ECKeyIdentifier.fromJsonWebKey(jwk.val as EC_JsonWebKey)
if (jwk.isErr()) return jwk
return ECKeyIdentifier.fromJsonWebKey(jwk.value as EC_JsonWebKey)
}
async toJsonWebKey(usage: 'sign_and_verify' | 'derive'): Promise<EC_Public_JsonWebKey> {
const key = await decompressK256Key(this.rawPublicKey)
Expand Down
10 changes: 5 additions & 5 deletions packages/base/src/Identifier/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export function convertRawMapToIdentifierMap<T>(it: I<T>, ...of: unknown[]): Map
const droppedValues = new Map<string, T>()
for (const [key, value] of it) {
const id = Identifier.from(key)
if (id.none) {
if (id.isNone()) {
droppedValues.set(key, value)
continue
}

if (hasProfileIdentifier && id.val instanceof A) result.set(id.val, value)
else if (hasECKeyIdentifier && id.val instanceof B) result.set(id.val, value)
else if (hasPostIdentifier && id.val instanceof C) result.set(id.val, value)
else if (hasPostIVIdentifier && id.val instanceof D) result.set(id.val, value)
if (hasProfileIdentifier && id.value instanceof A) result.set(id.value, value)
else if (hasECKeyIdentifier && id.value instanceof B) result.set(id.value, value)
else if (hasPostIdentifier && id.value instanceof C) result.set(id.value, value)
else if (hasPostIVIdentifier && id.value instanceof D) result.set(id.value, value)
else droppedValues.set(key, value)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/Identifier/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function parse(input: string | null | undefined): Option<Identifier> {
} else if (input.startsWith('post:')) {
const [postID, ...rest] = input.slice('post:'.length).split('/')
const inner = parse(rest.join('/'))
if (inner.none) return None
if (inner.val instanceof ProfileIdentifier) return Some(new PostIdentifier(inner.val, postID))
if (inner.isNone()) return None
if (inner.value instanceof ProfileIdentifier) return Some(new PostIdentifier(inner.value, postID))
return None
} else if (input.startsWith('post_iv:')) {
const [network, postIV] = input.slice('post_iv:'.length).split('/')
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/ts-results/OptionalResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const OptionalResult = {
},
None: Ok(None) as OptionalResult<any, any>,
fromResult<T, E>(x: Result<T, CheckedError<E>>): OptionalResult<T, E> {
if (x.err) return x
return Ok(Some(x.val))
if (x.isErr()) return x
return Ok(Some(x.value))
},
}
4 changes: 2 additions & 2 deletions packages/base/src/ts-results/andThenAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export async function andThenAsync<T, E, Q, E2>(
mapper: (t: T) => Result<Q, E2> | Promise<Result<Q, E2>>,
): Promise<Result<Q, E | E2>> {
op = await op
if (op.err) return op
return mapper(op.val)
if (op.isErr()) return op
return mapper(op.value)
}
8 changes: 1 addition & 7 deletions packages/base/src/utils/parseURLs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ export function parseURLs(text: string, requireProtocol = true) {
.map((x) => x.string)
.filter((y) => {
if (!requireProtocol) return true

// See https://github.com/alexcorvi/anchorme.js/issues/109
try {
new URL(y)
return true
} catch {
return false
}
return URL.canParse(y)
})
}

0 comments on commit 7714e20

Please sign in to comment.