Skip to content

Commit

Permalink
lexicon schema for lexicon schema records (meta) (#3286)
Browse files Browse the repository at this point in the history
* lexicon schema for lexicon schema records (meta)

* defs are object/unknown, not array

* simplify just to 'lexicon' field

* codegen lexicon schema
  • Loading branch information
bnewbold authored Jan 15, 2025
1 parent 3f93d8c commit 07f11d3
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lexicons/com/atproto/lexicon/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"lexicon": 1,
"id": "com.atproto.lexicon.schema",
"defs": {
"main": {
"type": "record",
"description": "Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc).",
"key": "nsid",
"record": {
"type": "object",
"required": ["lexicon"],
"properties": {
"lexicon": {
"type": "integer",
"description": "Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system."
}
}
}
}
}
}
79 changes: 79 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import * as ComAtprotoIdentityUpdateHandle from './types/com/atproto/identity/up
import * as ComAtprotoLabelDefs from './types/com/atproto/label/defs'
import * as ComAtprotoLabelQueryLabels from './types/com/atproto/label/queryLabels'
import * as ComAtprotoLabelSubscribeLabels from './types/com/atproto/label/subscribeLabels'
import * as ComAtprotoLexiconSchema from './types/com/atproto/lexicon/schema'
import * as ComAtprotoModerationCreateReport from './types/com/atproto/moderation/createReport'
import * as ComAtprotoModerationDefs from './types/com/atproto/moderation/defs'
import * as ComAtprotoRepoApplyWrites from './types/com/atproto/repo/applyWrites'
Expand Down Expand Up @@ -256,6 +257,7 @@ export * as ComAtprotoIdentityUpdateHandle from './types/com/atproto/identity/up
export * as ComAtprotoLabelDefs from './types/com/atproto/label/defs'
export * as ComAtprotoLabelQueryLabels from './types/com/atproto/label/queryLabels'
export * as ComAtprotoLabelSubscribeLabels from './types/com/atproto/label/subscribeLabels'
export * as ComAtprotoLexiconSchema from './types/com/atproto/lexicon/schema'
export * as ComAtprotoModerationCreateReport from './types/com/atproto/moderation/createReport'
export * as ComAtprotoModerationDefs from './types/com/atproto/moderation/defs'
export * as ComAtprotoRepoApplyWrites from './types/com/atproto/repo/applyWrites'
Expand Down Expand Up @@ -535,6 +537,7 @@ export class ComAtprotoNS {
admin: ComAtprotoAdminNS
identity: ComAtprotoIdentityNS
label: ComAtprotoLabelNS
lexicon: ComAtprotoLexiconNS
moderation: ComAtprotoModerationNS
repo: ComAtprotoRepoNS
server: ComAtprotoServerNS
Expand All @@ -546,6 +549,7 @@ export class ComAtprotoNS {
this.admin = new ComAtprotoAdminNS(client)
this.identity = new ComAtprotoIdentityNS(client)
this.label = new ComAtprotoLabelNS(client)
this.lexicon = new ComAtprotoLexiconNS(client)
this.moderation = new ComAtprotoModerationNS(client)
this.repo = new ComAtprotoRepoNS(client)
this.server = new ComAtprotoServerNS(client)
Expand Down Expand Up @@ -830,6 +834,81 @@ export class ComAtprotoLabelNS {
}
}

export class ComAtprotoLexiconNS {
_client: XrpcClient
schema: SchemaRecord

constructor(client: XrpcClient) {
this._client = client
this.schema = new SchemaRecord(client)
}
}

export class SchemaRecord {
_client: XrpcClient

constructor(client: XrpcClient) {
this._client = client
}

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>,
): Promise<{
cursor?: string
records: { uri: string; value: ComAtprotoLexiconSchema.Record }[]
}> {
const res = await this._client.call('com.atproto.repo.listRecords', {
collection: 'com.atproto.lexicon.schema',
...params,
})
return res.data
}

async get(
params: Omit<ComAtprotoRepoGetRecord.QueryParams, 'collection'>,
): Promise<{
uri: string
cid: string
value: ComAtprotoLexiconSchema.Record
}> {
const res = await this._client.call('com.atproto.repo.getRecord', {
collection: 'com.atproto.lexicon.schema',
...params,
})
return res.data
}

async create(
params: Omit<
ComAtprotoRepoCreateRecord.InputSchema,
'collection' | 'record'
>,
record: ComAtprotoLexiconSchema.Record,
headers?: Record<string, string>,
): Promise<{ uri: string; cid: string }> {
record.$type = 'com.atproto.lexicon.schema'
const res = await this._client.call(
'com.atproto.repo.createRecord',
undefined,
{ collection: 'com.atproto.lexicon.schema', ...params, record },
{ encoding: 'application/json', headers },
)
return res.data
}

async delete(
params: Omit<ComAtprotoRepoDeleteRecord.InputSchema, 'collection'>,
headers?: Record<string, string>,
): Promise<void> {
await this._client.call(
'com.atproto.repo.deleteRecord',
undefined,
{ collection: 'com.atproto.lexicon.schema', ...params },
{ headers },
)
}
}

export class ComAtprotoModerationNS {
_client: XrpcClient

Expand Down
24 changes: 24 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,29 @@ export const schemaDict = {
},
},
},
ComAtprotoLexiconSchema: {
lexicon: 1,
id: 'com.atproto.lexicon.schema',
defs: {
main: {
type: 'record',
description:
"Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc).",
key: 'nsid',
record: {
type: 'object',
required: ['lexicon'],
properties: {
lexicon: {
type: 'integer',
description:
"Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system.",
},
},
},
},
},
},
ComAtprotoModerationCreateReport: {
lexicon: 1,
id: 'com.atproto.moderation.createReport',
Expand Down Expand Up @@ -13644,6 +13667,7 @@ export const ids = {
ComAtprotoLabelDefs: 'com.atproto.label.defs',
ComAtprotoLabelQueryLabels: 'com.atproto.label.queryLabels',
ComAtprotoLabelSubscribeLabels: 'com.atproto.label.subscribeLabels',
ComAtprotoLexiconSchema: 'com.atproto.lexicon.schema',
ComAtprotoModerationCreateReport: 'com.atproto.moderation.createReport',
ComAtprotoModerationDefs: 'com.atproto.moderation.defs',
ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites',
Expand Down
26 changes: 26 additions & 0 deletions packages/api/src/client/types/com/atproto/lexicon/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'

export interface Record {
/** Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system. */
lexicon: number
[k: string]: unknown
}

export function isRecord(v: unknown): v is Record {
return (
isObj(v) &&
hasProp(v, '$type') &&
(v.$type === 'com.atproto.lexicon.schema#main' ||
v.$type === 'com.atproto.lexicon.schema')
)
}

export function validateRecord(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.lexicon.schema#main', v)
}
10 changes: 10 additions & 0 deletions packages/bsky/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class ComAtprotoNS {
admin: ComAtprotoAdminNS
identity: ComAtprotoIdentityNS
label: ComAtprotoLabelNS
lexicon: ComAtprotoLexiconNS
moderation: ComAtprotoModerationNS
repo: ComAtprotoRepoNS
server: ComAtprotoServerNS
Expand All @@ -238,6 +239,7 @@ export class ComAtprotoNS {
this.admin = new ComAtprotoAdminNS(server)
this.identity = new ComAtprotoIdentityNS(server)
this.label = new ComAtprotoLabelNS(server)
this.lexicon = new ComAtprotoLexiconNS(server)
this.moderation = new ComAtprotoModerationNS(server)
this.repo = new ComAtprotoRepoNS(server)
this.server = new ComAtprotoServerNS(server)
Expand Down Expand Up @@ -516,6 +518,14 @@ export class ComAtprotoLabelNS {
}
}

export class ComAtprotoLexiconNS {
_server: Server

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

export class ComAtprotoModerationNS {
_server: Server

Expand Down
24 changes: 24 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,29 @@ export const schemaDict = {
},
},
},
ComAtprotoLexiconSchema: {
lexicon: 1,
id: 'com.atproto.lexicon.schema',
defs: {
main: {
type: 'record',
description:
"Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc).",
key: 'nsid',
record: {
type: 'object',
required: ['lexicon'],
properties: {
lexicon: {
type: 'integer',
description:
"Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system.",
},
},
},
},
},
},
ComAtprotoModerationCreateReport: {
lexicon: 1,
id: 'com.atproto.moderation.createReport',
Expand Down Expand Up @@ -10844,6 +10867,7 @@ export const ids = {
ComAtprotoLabelDefs: 'com.atproto.label.defs',
ComAtprotoLabelQueryLabels: 'com.atproto.label.queryLabels',
ComAtprotoLabelSubscribeLabels: 'com.atproto.label.subscribeLabels',
ComAtprotoLexiconSchema: 'com.atproto.lexicon.schema',
ComAtprotoModerationCreateReport: 'com.atproto.moderation.createReport',
ComAtprotoModerationDefs: 'com.atproto.moderation.defs',
ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites',
Expand Down
26 changes: 26 additions & 0 deletions packages/bsky/src/lexicon/types/com/atproto/lexicon/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'

export interface Record {
/** Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system. */
lexicon: number
[k: string]: unknown
}

export function isRecord(v: unknown): v is Record {
return (
isObj(v) &&
hasProp(v, '$type') &&
(v.$type === 'com.atproto.lexicon.schema#main' ||
v.$type === 'com.atproto.lexicon.schema')
)
}

export function validateRecord(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.lexicon.schema#main', v)
}
10 changes: 10 additions & 0 deletions packages/ozone/src/lexicon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export class ComAtprotoNS {
admin: ComAtprotoAdminNS
identity: ComAtprotoIdentityNS
label: ComAtprotoLabelNS
lexicon: ComAtprotoLexiconNS
moderation: ComAtprotoModerationNS
repo: ComAtprotoRepoNS
server: ComAtprotoServerNS
Expand All @@ -281,6 +282,7 @@ export class ComAtprotoNS {
this.admin = new ComAtprotoAdminNS(server)
this.identity = new ComAtprotoIdentityNS(server)
this.label = new ComAtprotoLabelNS(server)
this.lexicon = new ComAtprotoLexiconNS(server)
this.moderation = new ComAtprotoModerationNS(server)
this.repo = new ComAtprotoRepoNS(server)
this.server = new ComAtprotoServerNS(server)
Expand Down Expand Up @@ -559,6 +561,14 @@ export class ComAtprotoLabelNS {
}
}

export class ComAtprotoLexiconNS {
_server: Server

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

export class ComAtprotoModerationNS {
_server: Server

Expand Down
24 changes: 24 additions & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,29 @@ export const schemaDict = {
},
},
},
ComAtprotoLexiconSchema: {
lexicon: 1,
id: 'com.atproto.lexicon.schema',
defs: {
main: {
type: 'record',
description:
"Representation of Lexicon schemas themselves, when published as atproto records. Note that the schema language is not defined in Lexicon; this meta schema currently only includes a single version field ('lexicon'). See the atproto specifications for description of the other expected top-level fields ('id', 'defs', etc).",
key: 'nsid',
record: {
type: 'object',
required: ['lexicon'],
properties: {
lexicon: {
type: 'integer',
description:
"Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system.",
},
},
},
},
},
},
ComAtprotoModerationCreateReport: {
lexicon: 1,
id: 'com.atproto.moderation.createReport',
Expand Down Expand Up @@ -13644,6 +13667,7 @@ export const ids = {
ComAtprotoLabelDefs: 'com.atproto.label.defs',
ComAtprotoLabelQueryLabels: 'com.atproto.label.queryLabels',
ComAtprotoLabelSubscribeLabels: 'com.atproto.label.subscribeLabels',
ComAtprotoLexiconSchema: 'com.atproto.lexicon.schema',
ComAtprotoModerationCreateReport: 'com.atproto.moderation.createReport',
ComAtprotoModerationDefs: 'com.atproto.moderation.defs',
ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites',
Expand Down
26 changes: 26 additions & 0 deletions packages/ozone/src/lexicon/types/com/atproto/lexicon/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'

export interface Record {
/** Indicates the 'version' of the Lexicon language. Must be '1' for the current atproto/Lexicon schema system. */
lexicon: number
[k: string]: unknown
}

export function isRecord(v: unknown): v is Record {
return (
isObj(v) &&
hasProp(v, '$type') &&
(v.$type === 'com.atproto.lexicon.schema#main' ||
v.$type === 'com.atproto.lexicon.schema')
)
}

export function validateRecord(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.lexicon.schema#main', v)
}
Loading

0 comments on commit 07f11d3

Please sign in to comment.