Skip to content

Commit

Permalink
Forbid use of implicit any
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Mar 7, 2025
1 parent 80c4bb5 commit 2df2a88
Show file tree
Hide file tree
Showing 187 changed files with 1,541 additions and 1,201 deletions.
30 changes: 30 additions & 0 deletions .changeset/eighty-carrots-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@atproto/oauth-client-browser-example": patch
"@atproto-labs/handle-resolver-node": patch
"@atproto-labs/simple-store-memory": patch
"@atproto/oauth-client-browser": patch
"@atproto/oauth-provider": patch
"@atproto-labs/fetch-node": patch
"@atproto/oauth-client": patch
"@atproto/oauth-types": patch
"@atproto-labs/fetch": patch
"@atproto/xrpc-server": patch
"@atproto/common-web": patch
"@atproto/dev-env": patch
"@atproto/lex-cli": patch
"@atproto/lexicon": patch
"@atproto/common": patch
"@atproto/syntax": patch
"@atproto/bsync": patch
"@atproto/ozone": patch
"@atproto/bsky": patch
"@atproto/repo": patch
"@atproto/sync": patch
"@atproto/xrpc": patch
"@atproto/api": patch
"@atproto/aws": patch
"@atproto/did": patch
"@atproto/pds": patch
---

Fix "implicit any" types
5 changes: 5 additions & 0 deletions .changeset/eleven-dolphins-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/common-web": patch
---

Expose isCid utility function
5 changes: 5 additions & 0 deletions .changeset/twelve-trainers-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/lexicon": patch
---

Small performance improvements
4 changes: 2 additions & 2 deletions packages/api/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class Agent extends XrpcClient {
})

// assemble a map of labeler dids to the interpreted label value definitions
const labelDefs = {}
const labelDefs: Record<string, InterpretedLabelValueDefinition[]> = {}
if (labelers.data) {
for (const labeler of labelers.data
.views as AppBskyLabelerDefs.LabelerViewDetailed[]) {
Expand Down Expand Up @@ -1407,7 +1407,7 @@ export class Agent extends XrpcClient {
.filter((pref) => !AppBskyActorDefs.isSavedFeedsPref(pref))
.concat(feedsPref)
})
return res
return res!
}

private async updateSavedFeedsV2Preferences(
Expand Down
14 changes: 9 additions & 5 deletions packages/api/src/moderation/decision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ export class ModerationDecision {

addLabel(target: LabelTarget, label: Label, opts: ModerationOpts) {
// look up the label definition
const labelDef = CUSTOM_LABEL_VALUE_RE.test(label.val)
? opts.labelDefs?.[label.src]?.find(
(def) => def.identifier === label.val,
) || LABELS[label.val]
: LABELS[label.val]
const labelDef =
(CUSTOM_LABEL_VALUE_RE.test(label.val)
? opts.labelDefs?.[label.src]?.find(
(def) => def.identifier === label.val,
)
: undefined) ||
(Object.hasOwn(LABELS, label.val)
? LABELS[label.val as keyof typeof LABELS]
: undefined)
if (!labelDef) {
// ignore labels we don't understand
return
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/moderation/subjects/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function checkMutedWords(
hasMutedWord({
mutedWords,
text: image.alt,
languages: AppBskyFeedPost.isRecord(embeddedPost.record)
languages: AppBskyFeedPost.isRecord(embeddedPost['record'])
? embeddedPost.langs
: [],
actor: embedAuthor,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/rich-text/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function detectFacets(text: UnicodeString): Facet[] | undefined {
while ((match = re.exec(text.utf16))) {
let uri = match[2]
if (!uri.startsWith('http')) {
const domain = match.groups?.domain
const domain = match.groups?.['domain']
if (!domain || !isValidDomain(domain)) {
continue
}
Expand Down
3 changes: 2 additions & 1 deletion packages/api/tests/atp-agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3508,4 +3508,5 @@ describe('agent', () => {
})
})

const byType = (a, b) => a.$type.localeCompare(b.$type)
const byType = (a: { $type: string }, b: { $type: string }) =>
a.$type.localeCompare(b.$type)
8 changes: 8 additions & 0 deletions packages/api/tests/dispatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,19 @@ describe('AtpAgent', () => {
const agent2 = new AtpAgent({ service: `http://localhost:${port}` })

const res1 = await agent.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res1.data['atproto-accept-labelers']).toEqual(
`${BSKY_LABELER_DID};redact`,
)

AtpAgent.configure({ appLabelers: ['did:plc:test1', 'did:plc:test2'] })
const res2 = await agent.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res2.data['atproto-accept-labelers']).toEqual(
'did:plc:test1;redact, did:plc:test2;redact',
)
const res3 = await agent2.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res3.data['atproto-accept-labelers']).toEqual(
'did:plc:test1;redact, did:plc:test2;redact',
)
Expand All @@ -476,12 +479,14 @@ describe('AtpAgent', () => {

agent.configureLabelers(['did:plc:test1'])
const res1 = await agent.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res1.data['atproto-accept-labelers']).toEqual(
`${BSKY_LABELER_DID};redact, did:plc:test1`,
)

agent.configureLabelers(['did:plc:test1', 'did:plc:test2'])
const res2 = await agent.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res2.data['atproto-accept-labelers']).toEqual(
`${BSKY_LABELER_DID};redact, did:plc:test1, did:plc:test2`,
)
Expand All @@ -497,17 +502,20 @@ describe('AtpAgent', () => {
const agent = new AtpAgent({ service: `http://localhost:${port}` })

const res1 = await agent.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res1.data['atproto-proxy']).toBeFalsy()

agent.configureProxy('did:plc:test1#atproto_labeler')
const res2 = await agent.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res2.data['atproto-proxy']).toEqual(
'did:plc:test1#atproto_labeler',
)

const res3 = await agent
.withProxy('atproto_labeler', 'did:plc:test2')
.com.atproto.server.describeServer()
// @ts-expect-error unspecced
expect(res3.data['atproto-proxy']).toEqual(
'did:plc:test2#atproto_labeler',
)
Expand Down
26 changes: 13 additions & 13 deletions packages/api/tests/moderation-prefs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ describe('agent', () => {
(l) => l.did === 'did:plc:other',
)

expect(moderationPrefs.labels.porn).toEqual('hide')
expect(labeler?.labels?.porn).toEqual('hide')
expect(moderationPrefs.labels['porn']).toEqual('hide')
expect(labeler?.labels?.['porn']).toEqual('hide')
})

it(`double-write for legacy: 'graphic-media' in sync with 'gore'`, async () => {
Expand All @@ -284,13 +284,13 @@ describe('agent', () => {
await agent.setContentLabelPref('graphic-media', 'hide')
const a = await agent.getPreferences()

expect(a.moderationPrefs.labels.gore).toEqual('hide')
expect(a.moderationPrefs.labels['gore']).toEqual('hide')
expect(a.moderationPrefs.labels['graphic-media']).toEqual('hide')

await agent.setContentLabelPref('graphic-media', 'warn')
const b = await agent.getPreferences()

expect(b.moderationPrefs.labels.gore).toEqual('warn')
expect(b.moderationPrefs.labels['gore']).toEqual('warn')
expect(b.moderationPrefs.labels['graphic-media']).toEqual('warn')
})

Expand All @@ -306,14 +306,14 @@ describe('agent', () => {
await agent.setContentLabelPref('porn', 'hide')
const a = await agent.getPreferences()

expect(a.moderationPrefs.labels.nsfw).toEqual('hide')
expect(a.moderationPrefs.labels.porn).toEqual('hide')
expect(a.moderationPrefs.labels['nsfw']).toEqual('hide')
expect(a.moderationPrefs.labels['porn']).toEqual('hide')

await agent.setContentLabelPref('porn', 'warn')
const b = await agent.getPreferences()

expect(b.moderationPrefs.labels.nsfw).toEqual('warn')
expect(b.moderationPrefs.labels.porn).toEqual('warn')
expect(b.moderationPrefs.labels['nsfw']).toEqual('warn')
expect(b.moderationPrefs.labels['porn']).toEqual('warn')
})

it(`double-write for legacy: 'sexual' in sync with 'suggestive'`, async () => {
Expand All @@ -328,14 +328,14 @@ describe('agent', () => {
await agent.setContentLabelPref('sexual', 'hide')
const a = await agent.getPreferences()

expect(a.moderationPrefs.labels.sexual).toEqual('hide')
expect(a.moderationPrefs.labels.suggestive).toEqual('hide')
expect(a.moderationPrefs.labels['sexual']).toEqual('hide')
expect(a.moderationPrefs.labels['suggestive']).toEqual('hide')

await agent.setContentLabelPref('sexual', 'warn')
const b = await agent.getPreferences()

expect(b.moderationPrefs.labels.sexual).toEqual('warn')
expect(b.moderationPrefs.labels.suggestive).toEqual('warn')
expect(b.moderationPrefs.labels['sexual']).toEqual('warn')
expect(b.moderationPrefs.labels['suggestive']).toEqual('warn')
})

it(`double-write for legacy: filters out existing old label pref if double-written`, async () => {
Expand Down Expand Up @@ -371,7 +371,7 @@ describe('agent', () => {
await agent.setContentLabelPref('suggestive', 'hide')
const a = await agent.getPreferences()

expect(a.moderationPrefs.labels.porn).toEqual('hide')
expect(a.moderationPrefs.labels['porn']).toEqual('hide')
expect(a.moderationPrefs.labels['graphic-media']).toEqual('hide')
expect(a.moderationPrefs.labels['sexual']).toEqual('hide')
})
Expand Down
2 changes: 1 addition & 1 deletion packages/aws/src/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class S3BlobStore implements BlobStore {
}
}

const handleErr = (err: unknown) => {
const handleErr = (err: any) => {
if (err?.['Code'] === 'NoSuchKey') {
throw new BlobNotFoundError()
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/bsky/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@
"@bufbuild/protoc-gen-es": "^1.5.0",
"@connectrpc/protoc-gen-connect-es": "^1.1.4",
"@did-plc/server": "^0.0.1",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/express-serve-static-core": "^4.17.36",
"@types/http-errors": "^2.0.1",
"@types/pg": "^8.6.6",
"@types/qs": "^6.9.7",
"jest": "^28.1.2",
Expand Down
17 changes: 9 additions & 8 deletions packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export default function (server: Server, ctx: AppContext) {
})
}

const FILTER_TO_FEED_TYPE = {
posts_with_replies: undefined, // default: all posts, replies, and reposts
posts_no_replies: FeedType.POSTS_NO_REPLIES,
posts_with_media: FeedType.POSTS_WITH_MEDIA,
posts_and_author_threads: FeedType.POSTS_AND_AUTHOR_THREADS,
posts_with_video: FeedType.POSTS_WITH_VIDEO,
}
const FILTER_TO_FEED_TYPE = new Map<string, undefined | FeedType>([
['posts_with_replies', undefined], // default: all posts, replies, and reposts
['posts_no_replies', FeedType.POSTS_NO_REPLIES],
['posts_with_media', FeedType.POSTS_WITH_MEDIA],
['posts_and_author_threads', FeedType.POSTS_AND_AUTHOR_THREADS],
['posts_with_video', FeedType.POSTS_WITH_VIDEO],
])

export const skeleton = async (inputs: {
ctx: Context
Expand Down Expand Up @@ -94,7 +94,8 @@ export const skeleton = async (inputs: {
actorDid: did,
limit: params.limit,
cursor: params.cursor,
feedType: FILTER_TO_FEED_TYPE[params.filter],
// @NOTE An invalid "filter" param will result on the same as "posts_with_replies"
feedType: FILTER_TO_FEED_TYPE.get(params.filter),
})

let items: FeedItem[] = res.items.map((item) => ({
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/src/api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ResHeaderOpts = {
export const resHeaders = (
opts: Partial<ResHeaderOpts>,
): Record<string, string> => {
const headers = {}
const headers: Record<string, string> = {}
if (opts.labelers) {
headers[ATPROTO_CONTENT_LABELERS] = formatLabelerHeader(opts.labelers)
}
Expand Down
13 changes: 6 additions & 7 deletions packages/bsky/src/cache/read-through.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,18 @@ export class ReadThroughCache<T> {
if (opts?.revalidate) {
return this.fetchAndCacheMany(keys)
}
let cached: Record<string, string>
try {
cached = await this.redis.getMulti(keys)
} catch (err) {
cached = {}

const cached = await this.redis.getMulti(keys).catch((err) => {
log.warn({ keys, err }, 'failed to fetch values from cache')
}
return null
})

const stale: string[] = []
const toFetch: string[] = []
const results: Record<string, T> = {}
for (const key of keys) {
const val = cached[key] ? (JSON.parse(cached[key]) as CacheItem<T>) : null
const cachedVal = cached?.get(key)
const val = cachedVal ? (JSON.parse(cachedVal) as CacheItem<T>) : null
if (!val || this.isExpired(val)) {
toFetch.push(key)
continue
Expand Down
Loading

0 comments on commit 2df2a88

Please sign in to comment.