tangled
alpha
login
or
join now
graham.systems
/
statusphere-react
forked from
samuel.fm/statusphere-react
0
fork
atom
the statusphere demo reworked into a vite/react app in a monorepo
0
fork
atom
overview
issues
pulls
pipelines
Change status lexicon to xyz.statusphere.status
Paul Frazee
2 years ago
f4e8b484
ac3eb927
+21
-20
6 changed files
expand all
collapse all
unified
split
lexicons
status.json
src
ingester.ts
lexicon
index.ts
lexicons.ts
types
xyz
statusphere
status.ts
routes.ts
+1
-1
lexicons/status.json
···
1
{
2
"lexicon": 1,
3
-
"id": "com.example.status",
4
"defs": {
5
"main": {
6
"type": "record",
···
1
{
2
"lexicon": 1,
3
+
"id": "xyz.statusphere.status",
4
"defs": {
5
"main": {
6
"type": "record",
+4
-4
src/ingester.ts
···
2
import { IdResolver } from '@atproto/identity'
3
import { Firehose } from '@atproto/sync'
4
import type { Database } from '#/db'
5
-
import * as Status from '#/lexicon/types/com/example/status'
6
7
export function createIngester(db: Database, idResolver: IdResolver) {
8
const logger = pino({ name: 'firehose ingestion' })
···
15
16
// If the write is a valid status update
17
if (
18
-
evt.collection === 'com.example.status' &&
19
Status.isRecord(record) &&
20
Status.validateRecord(record).success
21
) {
···
39
}
40
} else if (
41
evt.event === 'delete' &&
42
-
evt.collection === 'com.example.status'
43
) {
44
// Remove the status from our SQLite
45
await db.deleteFrom('status').where({ uri: evt.uri.toString() })
···
48
onError: (err) => {
49
logger.error({ err }, 'error on firehose ingestion')
50
},
51
-
filterCollections: ['com.example.status'],
52
excludeIdentity: true,
53
excludeAccount: true,
54
})
···
2
import { IdResolver } from '@atproto/identity'
3
import { Firehose } from '@atproto/sync'
4
import type { Database } from '#/db'
5
+
import * as Status from '#/lexicon/types/xyz/statusphere/status'
6
7
export function createIngester(db: Database, idResolver: IdResolver) {
8
const logger = pino({ name: 'firehose ingestion' })
···
15
16
// If the write is a valid status update
17
if (
18
+
evt.collection === 'xyz.statusphere.status' &&
19
Status.isRecord(record) &&
20
Status.validateRecord(record).success
21
) {
···
39
}
40
} else if (
41
evt.event === 'delete' &&
42
+
evt.collection === 'xyz.statusphere.status'
43
) {
44
// Remove the status from our SQLite
45
await db.deleteFrom('status').where({ uri: evt.uri.toString() })
···
48
onError: (err) => {
49
logger.error({ err }, 'error on firehose ingestion')
50
},
51
+
filterCollections: ['xyz.statusphere.status'],
52
excludeIdentity: true,
53
excludeAccount: true,
54
})
+6
-6
src/lexicon/index.ts
···
17
export class Server {
18
xrpc: XrpcServer
19
app: AppNS
20
-
com: ComNS
21
22
constructor(options?: XrpcOptions) {
23
this.xrpc = createXrpcServer(schemas, options)
24
this.app = new AppNS(this)
25
-
this.com = new ComNS(this)
26
}
27
}
28
···
54
}
55
}
56
57
-
export class ComNS {
58
_server: Server
59
-
example: ComExampleNS
60
61
constructor(server: Server) {
62
this._server = server
63
-
this.example = new ComExampleNS(server)
64
}
65
}
66
67
-
export class ComExampleNS {
68
_server: Server
69
70
constructor(server: Server) {
···
17
export class Server {
18
xrpc: XrpcServer
19
app: AppNS
20
+
xyz: XyzNS
21
22
constructor(options?: XrpcOptions) {
23
this.xrpc = createXrpcServer(schemas, options)
24
this.app = new AppNS(this)
25
+
this.xyz = new XyzNS(this)
26
}
27
}
28
···
54
}
55
}
56
57
+
export class XyzNS {
58
_server: Server
59
+
statusphere: XyzStatusphereNS
60
61
constructor(server: Server) {
62
this._server = server
63
+
this.statusphere = new XyzStatusphereNS(server)
64
}
65
}
66
67
+
export class XyzStatusphereNS {
68
_server: Server
69
70
constructor(server: Server) {
+4
-4
src/lexicon/lexicons.ts
···
59
},
60
},
61
},
62
-
ComExampleStatus: {
63
lexicon: 1,
64
-
id: 'com.example.status',
65
defs: {
66
main: {
67
type: 'record',
68
-
key: 'literal:self',
69
record: {
70
type: 'object',
71
required: ['status', 'createdAt'],
···
90
export const lexicons: Lexicons = new Lexicons(schemas)
91
export const ids = {
92
AppBskyActorProfile: 'app.bsky.actor.profile',
93
-
ComExampleStatus: 'com.example.status',
94
}
···
59
},
60
},
61
},
62
+
XyzStatusphereStatus: {
63
lexicon: 1,
64
+
id: 'xyz.statusphere.status',
65
defs: {
66
main: {
67
type: 'record',
68
+
key: 'tid',
69
record: {
70
type: 'object',
71
required: ['status', 'createdAt'],
···
90
export const lexicons: Lexicons = new Lexicons(schemas)
91
export const ids = {
92
AppBskyActorProfile: 'app.bsky.actor.profile',
93
+
XyzStatusphereStatus: 'xyz.statusphere.status',
94
}
+3
-2
src/lexicon/types/com/example/status.ts
src/lexicon/types/xyz/statusphere/status.ts
···
16
return (
17
isObj(v) &&
18
hasProp(v, '$type') &&
19
-
(v.$type === 'com.example.status#main' || v.$type === 'com.example.status')
0
20
)
21
}
22
23
export function validateRecord(v: unknown): ValidationResult {
24
-
return lexicons.validate('com.example.status#main', v)
25
}
···
16
return (
17
isObj(v) &&
18
hasProp(v, '$type') &&
19
+
(v.$type === 'xyz.statusphere.status#main' ||
20
+
v.$type === 'xyz.statusphere.status')
21
)
22
}
23
24
export function validateRecord(v: unknown): ValidationResult {
25
+
return lexicons.validate('xyz.statusphere.status#main', v)
26
}
+3
-3
src/routes.ts
···
12
import { login } from '#/pages/login'
13
import { env } from '#/lib/env'
14
import { page } from '#/lib/view'
15
-
import * as Status from '#/lexicon/types/com/example/status'
16
import * as Profile from '#/lexicon/types/app/bsky/actor/profile'
17
18
type Session = { did: string }
···
217
// Construct & validate their status record
218
const rkey = TID.nextStr()
219
const record = {
220
-
$type: 'com.example.status',
221
status: req.body?.status,
222
createdAt: new Date().toISOString(),
223
}
···
233
// Write the status record to the user's repository
234
const res = await agent.com.atproto.repo.putRecord({
235
repo: agent.assertDid,
236
-
collection: 'com.example.status',
237
rkey,
238
record,
239
validate: false,
···
12
import { login } from '#/pages/login'
13
import { env } from '#/lib/env'
14
import { page } from '#/lib/view'
15
+
import * as Status from '#/lexicon/types/xyz/statusphere/status'
16
import * as Profile from '#/lexicon/types/app/bsky/actor/profile'
17
18
type Session = { did: string }
···
217
// Construct & validate their status record
218
const rkey = TID.nextStr()
219
const record = {
220
+
$type: 'xyz.statusphere.status',
221
status: req.body?.status,
222
createdAt: new Date().toISOString(),
223
}
···
233
// Write the status record to the user's repository
234
const res = await agent.com.atproto.repo.putRecord({
235
repo: agent.assertDid,
236
+
collection: 'xyz.statusphere.status',
237
rkey,
238
record,
239
validate: false,