Scratch space for learning atproto app development

Change status lexicon to xyz.statusphere.status

Changed files
+21 -20
lexicons
src
lexicon
types
xyz
statusphere
+1 -1
lexicons/status.json
···
{
"lexicon": 1,
-
"id": "com.example.status",
+
"id": "xyz.statusphere.status",
"defs": {
"main": {
"type": "record",
+4 -4
src/ingester.ts
···
import { IdResolver } from '@atproto/identity'
import { Firehose } from '@atproto/sync'
import type { Database } from '#/db'
-
import * as Status from '#/lexicon/types/com/example/status'
+
import * as Status from '#/lexicon/types/xyz/statusphere/status'
export function createIngester(db: Database, idResolver: IdResolver) {
const logger = pino({ name: 'firehose ingestion' })
···
// If the write is a valid status update
if (
-
evt.collection === 'com.example.status' &&
+
evt.collection === 'xyz.statusphere.status' &&
Status.isRecord(record) &&
Status.validateRecord(record).success
) {
···
}
} else if (
evt.event === 'delete' &&
-
evt.collection === 'com.example.status'
+
evt.collection === 'xyz.statusphere.status'
) {
// Remove the status from our SQLite
await db.deleteFrom('status').where({ uri: evt.uri.toString() })
···
onError: (err) => {
logger.error({ err }, 'error on firehose ingestion')
},
-
filterCollections: ['com.example.status'],
+
filterCollections: ['xyz.statusphere.status'],
excludeIdentity: true,
excludeAccount: true,
})
+6 -6
src/lexicon/index.ts
···
export class Server {
xrpc: XrpcServer
app: AppNS
-
com: ComNS
+
xyz: XyzNS
constructor(options?: XrpcOptions) {
this.xrpc = createXrpcServer(schemas, options)
this.app = new AppNS(this)
-
this.com = new ComNS(this)
+
this.xyz = new XyzNS(this)
}
}
···
}
}
-
export class ComNS {
+
export class XyzNS {
_server: Server
-
example: ComExampleNS
+
statusphere: XyzStatusphereNS
constructor(server: Server) {
this._server = server
-
this.example = new ComExampleNS(server)
+
this.statusphere = new XyzStatusphereNS(server)
}
}
-
export class ComExampleNS {
+
export class XyzStatusphereNS {
_server: Server
constructor(server: Server) {
+4 -4
src/lexicon/lexicons.ts
···
},
},
},
-
ComExampleStatus: {
+
XyzStatusphereStatus: {
lexicon: 1,
-
id: 'com.example.status',
+
id: 'xyz.statusphere.status',
defs: {
main: {
type: 'record',
-
key: 'literal:self',
+
key: 'tid',
record: {
type: 'object',
required: ['status', 'createdAt'],
···
export const lexicons: Lexicons = new Lexicons(schemas)
export const ids = {
AppBskyActorProfile: 'app.bsky.actor.profile',
-
ComExampleStatus: 'com.example.status',
+
XyzStatusphereStatus: 'xyz.statusphere.status',
}
+3 -2
src/lexicon/types/com/example/status.ts src/lexicon/types/xyz/statusphere/status.ts
···
return (
isObj(v) &&
hasProp(v, '$type') &&
-
(v.$type === 'com.example.status#main' || v.$type === 'com.example.status')
+
(v.$type === 'xyz.statusphere.status#main' ||
+
v.$type === 'xyz.statusphere.status')
)
}
export function validateRecord(v: unknown): ValidationResult {
-
return lexicons.validate('com.example.status#main', v)
+
return lexicons.validate('xyz.statusphere.status#main', v)
}
+3 -3
src/routes.ts
···
import { login } from '#/pages/login'
import { env } from '#/lib/env'
import { page } from '#/lib/view'
-
import * as Status from '#/lexicon/types/com/example/status'
+
import * as Status from '#/lexicon/types/xyz/statusphere/status'
import * as Profile from '#/lexicon/types/app/bsky/actor/profile'
type Session = { did: string }
···
// Construct & validate their status record
const rkey = TID.nextStr()
const record = {
-
$type: 'com.example.status',
+
$type: 'xyz.statusphere.status',
status: req.body?.status,
createdAt: new Date().toISOString(),
}
···
// Write the status record to the user's repository
const res = await agent.com.atproto.repo.putRecord({
repo: agent.assertDid,
-
collection: 'com.example.status',
+
collection: 'xyz.statusphere.status',
rkey,
record,
validate: false,