Skip to content

Commit

Permalink
Add temp.fetchLabels method (#1858)
Browse files Browse the repository at this point in the history
* add temp.fetchLabels route

* update description
  • Loading branch information
dholms authored Nov 16, 2023
1 parent 1ef6da1 commit b05130d
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lexicons/com/atproto/temp/fetchLabels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"lexicon": 1,
"id": "com.atproto.temp.fetchLabels",
"defs": {
"main": {
"type": "query",
"description": "Fetch all labels from a labeler created after a certain date.",
"parameters": {
"type": "params",
"properties": {
"since": { "type": "integer" },
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 250,
"default": 50
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["labels"],
"properties": {
"labels": {
"type": "array",
"items": { "type": "ref", "ref": "com.atproto.label.defs#label" }
}
}
}
}
}
}
}
23 changes: 23 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
import * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
import * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
import * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
import * as AppBskyActorDefs from './types/app/bsky/actor/defs'
import * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
import * as AppBskyActorGetProfile from './types/app/bsky/actor/getProfile'
Expand Down Expand Up @@ -215,6 +216,7 @@ export * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
export * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
export * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
export * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
export * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
export * as AppBskyActorDefs from './types/app/bsky/actor/defs'
export * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
export * as AppBskyActorGetProfile from './types/app/bsky/actor/getProfile'
Expand Down Expand Up @@ -349,6 +351,7 @@ export class AtprotoNS {
repo: RepoNS
server: ServerNS
sync: SyncNS
temp: TempNS

constructor(service: AtpServiceClient) {
this._service = service
Expand All @@ -359,6 +362,7 @@ export class AtprotoNS {
this.repo = new RepoNS(service)
this.server = new ServerNS(service)
this.sync = new SyncNS(service)
this.temp = new TempNS(service)
}
}

Expand Down Expand Up @@ -1122,6 +1126,25 @@ export class SyncNS {
}
}

export class TempNS {
_service: AtpServiceClient

constructor(service: AtpServiceClient) {
this._service = service
}

fetchLabels(
params?: ComAtprotoTempFetchLabels.QueryParams,
opts?: ComAtprotoTempFetchLabels.CallOptions,
): Promise<ComAtprotoTempFetchLabels.Response> {
return this._service.xrpc
.call('com.atproto.temp.fetchLabels', params, undefined, opts)
.catch((e) => {
throw ComAtprotoTempFetchLabels.toKnownErr(e)
})
}
}

export class AppNS {
_service: AtpServiceClient
bsky: BskyNS
Expand Down
42 changes: 42 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,47 @@ export const schemaDict = {
},
},
},
ComAtprotoTempFetchLabels: {
lexicon: 1,
id: 'com.atproto.temp.fetchLabels',
defs: {
main: {
type: 'query',
description:
'Fetch all labels from a labeler created after a certain date.',
parameters: {
type: 'params',
properties: {
since: {
type: 'integer',
},
limit: {
type: 'integer',
minimum: 1,
maximum: 250,
default: 50,
},
},
},
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['labels'],
properties: {
labels: {
type: 'array',
items: {
type: 'ref',
ref: 'lex:com.atproto.label.defs#label',
},
},
},
},
},
},
},
},
AppBskyActorDefs: {
lexicon: 1,
id: 'app.bsky.actor.defs',
Expand Down Expand Up @@ -7659,6 +7700,7 @@ export const ids = {
ComAtprotoSyncNotifyOfUpdate: 'com.atproto.sync.notifyOfUpdate',
ComAtprotoSyncRequestCrawl: 'com.atproto.sync.requestCrawl',
ComAtprotoSyncSubscribeRepos: 'com.atproto.sync.subscribeRepos',
ComAtprotoTempFetchLabels: 'com.atproto.temp.fetchLabels',
AppBskyActorDefs: 'app.bsky.actor.defs',
AppBskyActorGetPreferences: 'app.bsky.actor.getPreferences',
AppBskyActorGetProfile: 'app.bsky.actor.getProfile',
Expand Down
37 changes: 37 additions & 0 deletions packages/api/src/client/types/com/atproto/temp/fetchLabels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { Headers, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'
import * as ComAtprotoLabelDefs from '../label/defs'

export interface QueryParams {
since?: number
limit?: number
}

export type InputSchema = undefined

export interface OutputSchema {
labels: ComAtprotoLabelDefs.Label[]
[k: string]: unknown
}

export interface CallOptions {
headers?: Headers
}

export interface Response {
success: boolean
headers: Headers
data: OutputSchema
}

export function toKnownErr(e: any) {
if (e instanceof XRPCError) {
}
return e
}
25 changes: 25 additions & 0 deletions packages/bsky/src/api/com/atproto/temp/fetchLabels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.temp.fetchLabels(async ({ params }) => {
const { limit } = params
const db = ctx.db.getReplica()
const since =
params.since !== undefined ? new Date(params.since).toISOString() : ''
const labels = await db.db
.selectFrom('label')
.selectAll()
.orderBy('label.cts', 'asc')
.where('cts', '>', since)
.limit(limit)
.execute()

return {
encoding: 'application/json',
body: {
labels,
},
}
})
}
2 changes: 2 additions & 0 deletions packages/bsky/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import getModerationReport from './com/atproto/admin/getModerationReport'
import getModerationReports from './com/atproto/admin/getModerationReports'
import resolveHandle from './com/atproto/identity/resolveHandle'
import getRecord from './com/atproto/repo/getRecord'
import fetchLabels from './com/atproto/temp/fetchLabels'

export * as health from './health'

Expand Down Expand Up @@ -116,5 +117,6 @@ export default function (server: Server, ctx: AppContext) {
getModerationReports(server, ctx)
resolveHandle(server, ctx)
getRecord(server, ctx)
fetchLabels(server, ctx)
return server
}
22 changes: 22 additions & 0 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
import * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
import * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
import * as ComAtprotoTempFetchLabels from './types/com/atproto/temp/fetchLabels'
import * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
import * as AppBskyActorGetProfile from './types/app/bsky/actor/getProfile'
import * as AppBskyActorGetProfiles from './types/app/bsky/actor/getProfiles'
Expand Down Expand Up @@ -175,6 +176,7 @@ export class AtprotoNS {
repo: RepoNS
server: ServerNS
sync: SyncNS
temp: TempNS

constructor(server: Server) {
this._server = server
Expand All @@ -185,6 +187,7 @@ export class AtprotoNS {
this.repo = new RepoNS(server)
this.server = new ServerNS(server)
this.sync = new SyncNS(server)
this.temp = new TempNS(server)
}
}

Expand Down Expand Up @@ -970,6 +973,25 @@ export class SyncNS {
}
}

export class TempNS {
_server: Server

constructor(server: Server) {
this._server = server
}

fetchLabels<AV extends AuthVerifier>(
cfg: ConfigOf<
AV,
ComAtprotoTempFetchLabels.Handler<ExtractAuth<AV>>,
ComAtprotoTempFetchLabels.HandlerReqCtx<ExtractAuth<AV>>
>,
) {
const nsid = 'com.atproto.temp.fetchLabels' // @ts-ignore
return this._server.xrpc.method(nsid, cfg)
}
}

export class AppNS {
_server: Server
bsky: BskyNS
Expand Down
42 changes: 42 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,47 @@ export const schemaDict = {
},
},
},
ComAtprotoTempFetchLabels: {
lexicon: 1,
id: 'com.atproto.temp.fetchLabels',
defs: {
main: {
type: 'query',
description:
'Fetch all labels from a labeler created after a certain date.',
parameters: {
type: 'params',
properties: {
since: {
type: 'integer',
},
limit: {
type: 'integer',
minimum: 1,
maximum: 250,
default: 50,
},
},
},
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['labels'],
properties: {
labels: {
type: 'array',
items: {
type: 'ref',
ref: 'lex:com.atproto.label.defs#label',
},
},
},
},
},
},
},
},
AppBskyActorDefs: {
lexicon: 1,
id: 'app.bsky.actor.defs',
Expand Down Expand Up @@ -7659,6 +7700,7 @@ export const ids = {
ComAtprotoSyncNotifyOfUpdate: 'com.atproto.sync.notifyOfUpdate',
ComAtprotoSyncRequestCrawl: 'com.atproto.sync.requestCrawl',
ComAtprotoSyncSubscribeRepos: 'com.atproto.sync.subscribeRepos',
ComAtprotoTempFetchLabels: 'com.atproto.temp.fetchLabels',
AppBskyActorDefs: 'app.bsky.actor.defs',
AppBskyActorGetPreferences: 'app.bsky.actor.getPreferences',
AppBskyActorGetProfile: 'app.bsky.actor.getProfile',
Expand Down
47 changes: 47 additions & 0 deletions packages/bsky/src/lexicon/types/com/atproto/temp/fetchLabels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import express from 'express'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'
import { HandlerAuth } from '@atproto/xrpc-server'
import * as ComAtprotoLabelDefs from '../label/defs'

export interface QueryParams {
since?: number
limit: number
}

export type InputSchema = undefined

export interface OutputSchema {
labels: ComAtprotoLabelDefs.Label[]
[k: string]: unknown
}

export type HandlerInput = undefined

export interface HandlerSuccess {
encoding: 'application/json'
body: OutputSchema
headers?: { [key: string]: string }
}

export interface HandlerError {
status: number
message?: string
}

export type HandlerOutput = HandlerError | HandlerSuccess
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA
params: QueryParams
input: HandlerInput
req: express.Request
res: express.Response
}
export type Handler<HA extends HandlerAuth = never> = (
ctx: HandlerReqCtx<HA>,
) => Promise<HandlerOutput> | HandlerOutput
Loading

0 comments on commit b05130d

Please sign in to comment.