diff --git a/lexicons/defs.json b/lexicons/defs.json new file mode 100644 index 0000000..733e77e --- /dev/null +++ b/lexicons/defs.json @@ -0,0 +1,156 @@ +{ + "lexicon": 1, + "id": "com.atproto.label.defs", + "defs": { + "label": { + "type": "object", + "description": "Metadata tag on an atproto resource (eg, repo or record).", + "required": ["src", "uri", "val", "cts"], + "properties": { + "ver": { + "type": "integer", + "description": "The AT Protocol version of the label object." + }, + "src": { + "type": "string", + "format": "did", + "description": "DID of the actor who created this label." + }, + "uri": { + "type": "string", + "format": "uri", + "description": "AT URI of the record, repository (account), or other resource that this label applies to." + }, + "cid": { + "type": "string", + "format": "cid", + "description": "Optionally, CID specifying the specific version of 'uri' resource this label applies to." + }, + "val": { + "type": "string", + "maxLength": 128, + "description": "The short string name of the value or type of this label." + }, + "neg": { + "type": "boolean", + "description": "If true, this is a negation label, overwriting a previous label." + }, + "cts": { + "type": "string", + "format": "datetime", + "description": "Timestamp when this label was created." + }, + "exp": { + "type": "string", + "format": "datetime", + "description": "Timestamp at which this label expires (no longer applies)." + }, + "sig": { + "type": "bytes", + "description": "Signature of dag-cbor encoded label." + } + } + }, + "selfLabels": { + "type": "object", + "description": "Metadata tags on an atproto record, published by the author within the record.", + "required": ["values"], + "properties": { + "values": { + "type": "array", + "items": { "type": "ref", "ref": "#selfLabel" }, + "maxLength": 10 + } + } + }, + "selfLabel": { + "type": "object", + "description": "Metadata tag on an atproto record, published by the author within the record. Note that schemas should use #selfLabels, not #selfLabel.", + "required": ["val"], + "properties": { + "val": { + "type": "string", + "maxLength": 128, + "description": "The short string name of the value or type of this label." + } + } + }, + "labelValueDefinition": { + "type": "object", + "description": "Declares a label value and its expected interpretations and behaviors.", + "required": ["identifier", "severity", "blurs", "locales"], + "properties": { + "identifier": { + "type": "string", + "description": "The value of the label being defined. Must only include lowercase ascii and the '-' character ([a-z-]+).", + "maxLength": 100, + "maxGraphemes": 100 + }, + "severity": { + "type": "string", + "description": "How should a client visually convey this label? 'inform' means neutral and informational; 'alert' means negative and warning; 'none' means show nothing.", + "knownValues": ["inform", "alert", "none"] + }, + "blurs": { + "type": "string", + "description": "What should this label hide in the UI, if applied? 'content' hides all of the target; 'media' hides the images/video/audio; 'none' hides nothing.", + "knownValues": ["content", "media", "none"] + }, + "defaultSetting": { + "type": "string", + "description": "The default setting for this label.", + "knownValues": ["ignore", "warn", "hide"], + "default": "warn" + }, + "adultOnly": { + "type": "boolean", + "description": "Does the user need to have adult content enabled in order to configure this label?" + }, + "locales": { + "type": "array", + "items": { "type": "ref", "ref": "#labelValueDefinitionStrings" } + } + } + }, + "labelValueDefinitionStrings": { + "type": "object", + "description": "Strings which describe the label in the UI, localized into a specific language.", + "required": ["lang", "name", "description"], + "properties": { + "lang": { + "type": "string", + "description": "The code of the language these strings are written in.", + "format": "language" + }, + "name": { + "type": "string", + "description": "A short human-readable name for the label.", + "maxGraphemes": 64, + "maxLength": 640 + }, + "description": { + "type": "string", + "description": "A longer description of what the label means and why it might be applied.", + "maxGraphemes": 10000, + "maxLength": 100000 + } + } + }, + "labelValue": { + "type": "string", + "knownValues": [ + "!hide", + "!no-promote", + "!warn", + "!no-unauthenticated", + "dmca-violation", + "doxxing", + "porn", + "sexual", + "nudity", + "nsfl", + "gore" + ] + } + } + } \ No newline at end of file diff --git a/lexicons/strongRef.json b/lexicons/strongRef.json new file mode 100644 index 0000000..3a495f2 --- /dev/null +++ b/lexicons/strongRef.json @@ -0,0 +1,15 @@ +{ + "lexicon": 1, + "id": "com.atproto.repo.strongRef", + "description": "A URI with a content-hash fingerprint.", + "defs": { + "main": { + "type": "object", + "required": ["uri", "cid"], + "properties": { + "uri": { "type": "string", "format": "at-uri" }, + "cid": { "type": "string", "format": "cid" } + } + } + } + } \ No newline at end of file diff --git a/src/lexicon/index.ts b/src/lexicon/index.ts index 57d2cd6..ae51fd0 100644 --- a/src/lexicon/index.ts +++ b/src/lexicon/index.ts @@ -18,11 +18,13 @@ export class Server { xrpc: XrpcServer app: AppNS xyz: XyzNS + com: ComNS constructor(options?: XrpcOptions) { this.xrpc = createXrpcServer(schemas, options) this.app = new AppNS(this) this.xyz = new XyzNS(this) + this.com = new ComNS(this) } } @@ -72,6 +74,34 @@ export class XyzStatusphereNS { } } +export class ComNS { + _server: Server + atproto: ComAtprotoNS + + constructor(server: Server) { + this._server = server + this.atproto = new ComAtprotoNS(server) + } +} + +export class ComAtprotoNS { + _server: Server + repo: ComAtprotoRepoNS + + constructor(server: Server) { + this._server = server + this.repo = new ComAtprotoRepoNS(server) + } +} + +export class ComAtprotoRepoNS { + _server: Server + + constructor(server: Server) { + this._server = server + } +} + type SharedRateLimitOpts = { name: string calcKey?: (ctx: T) => string diff --git a/src/lexicon/lexicons.ts b/src/lexicon/lexicons.ts index b3a4596..f047e97 100644 --- a/src/lexicon/lexicons.ts +++ b/src/lexicon/lexicons.ts @@ -4,6 +4,185 @@ import { LexiconDoc, Lexicons } from '@atproto/lexicon' export const schemaDict = { + ComAtprotoLabelDefs: { + lexicon: 1, + id: 'com.atproto.label.defs', + defs: { + label: { + type: 'object', + description: + 'Metadata tag on an atproto resource (eg, repo or record).', + required: ['src', 'uri', 'val', 'cts'], + properties: { + ver: { + type: 'integer', + description: 'The AT Protocol version of the label object.', + }, + src: { + type: 'string', + format: 'did', + description: 'DID of the actor who created this label.', + }, + uri: { + type: 'string', + format: 'uri', + description: + 'AT URI of the record, repository (account), or other resource that this label applies to.', + }, + cid: { + type: 'string', + format: 'cid', + description: + "Optionally, CID specifying the specific version of 'uri' resource this label applies to.", + }, + val: { + type: 'string', + maxLength: 128, + description: + 'The short string name of the value or type of this label.', + }, + neg: { + type: 'boolean', + description: + 'If true, this is a negation label, overwriting a previous label.', + }, + cts: { + type: 'string', + format: 'datetime', + description: 'Timestamp when this label was created.', + }, + exp: { + type: 'string', + format: 'datetime', + description: + 'Timestamp at which this label expires (no longer applies).', + }, + sig: { + type: 'bytes', + description: 'Signature of dag-cbor encoded label.', + }, + }, + }, + selfLabels: { + type: 'object', + description: + 'Metadata tags on an atproto record, published by the author within the record.', + required: ['values'], + properties: { + values: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#selfLabel', + }, + maxLength: 10, + }, + }, + }, + selfLabel: { + type: 'object', + description: + 'Metadata tag on an atproto record, published by the author within the record. Note that schemas should use #selfLabels, not #selfLabel.', + required: ['val'], + properties: { + val: { + type: 'string', + maxLength: 128, + description: + 'The short string name of the value or type of this label.', + }, + }, + }, + labelValueDefinition: { + type: 'object', + description: + 'Declares a label value and its expected interpretations and behaviors.', + required: ['identifier', 'severity', 'blurs', 'locales'], + properties: { + identifier: { + type: 'string', + description: + "The value of the label being defined. Must only include lowercase ascii and the '-' character ([a-z-]+).", + maxLength: 100, + maxGraphemes: 100, + }, + severity: { + type: 'string', + description: + "How should a client visually convey this label? 'inform' means neutral and informational; 'alert' means negative and warning; 'none' means show nothing.", + knownValues: ['inform', 'alert', 'none'], + }, + blurs: { + type: 'string', + description: + "What should this label hide in the UI, if applied? 'content' hides all of the target; 'media' hides the images/video/audio; 'none' hides nothing.", + knownValues: ['content', 'media', 'none'], + }, + defaultSetting: { + type: 'string', + description: 'The default setting for this label.', + knownValues: ['ignore', 'warn', 'hide'], + default: 'warn', + }, + adultOnly: { + type: 'boolean', + description: + 'Does the user need to have adult content enabled in order to configure this label?', + }, + locales: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#labelValueDefinitionStrings', + }, + }, + }, + }, + labelValueDefinitionStrings: { + type: 'object', + description: + 'Strings which describe the label in the UI, localized into a specific language.', + required: ['lang', 'name', 'description'], + properties: { + lang: { + type: 'string', + description: + 'The code of the language these strings are written in.', + format: 'language', + }, + name: { + type: 'string', + description: 'A short human-readable name for the label.', + maxGraphemes: 64, + maxLength: 640, + }, + description: { + type: 'string', + description: + 'A longer description of what the label means and why it might be applied.', + maxGraphemes: 10000, + maxLength: 100000, + }, + }, + }, + labelValue: { + type: 'string', + knownValues: [ + '!hide', + '!no-promote', + '!warn', + '!no-unauthenticated', + 'dmca-violation', + 'doxxing', + 'porn', + 'sexual', + 'nudity', + 'nsfl', + 'gore', + ], + }, + }, + }, AppBskyActorProfile: { lexicon: 1, id: 'app.bsky.actor.profile', @@ -85,10 +264,33 @@ export const schemaDict = { }, }, }, + ComAtprotoRepoStrongRef: { + lexicon: 1, + id: 'com.atproto.repo.strongRef', + description: 'A URI with a content-hash fingerprint.', + defs: { + main: { + type: 'object', + required: ['uri', 'cid'], + properties: { + uri: { + type: 'string', + format: 'at-uri', + }, + cid: { + type: 'string', + format: 'cid', + }, + }, + }, + }, + }, } export const schemas: LexiconDoc[] = Object.values(schemaDict) as LexiconDoc[] export const lexicons: Lexicons = new Lexicons(schemas) export const ids = { + ComAtprotoLabelDefs: 'com.atproto.label.defs', AppBskyActorProfile: 'app.bsky.actor.profile', XyzStatusphereStatus: 'xyz.statusphere.status', + ComAtprotoRepoStrongRef: 'com.atproto.repo.strongRef', } diff --git a/src/lexicon/types/com/atproto/label/defs.ts b/src/lexicon/types/com/atproto/label/defs.ts new file mode 100644 index 0000000..348e985 --- /dev/null +++ b/src/lexicon/types/com/atproto/label/defs.ts @@ -0,0 +1,151 @@ +/** + * 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' + +/** Metadata tag on an atproto resource (eg, repo or record). */ +export interface Label { + /** The AT Protocol version of the label object. */ + ver?: number + /** DID of the actor who created this label. */ + src: string + /** AT URI of the record, repository (account), or other resource that this label applies to. */ + uri: string + /** Optionally, CID specifying the specific version of 'uri' resource this label applies to. */ + cid?: string + /** The short string name of the value or type of this label. */ + val: string + /** If true, this is a negation label, overwriting a previous label. */ + neg?: boolean + /** Timestamp when this label was created. */ + cts: string + /** Timestamp at which this label expires (no longer applies). */ + exp?: string + /** Signature of dag-cbor encoded label. */ + sig?: Uint8Array + [k: string]: unknown +} + +export function isLabel(v: unknown): v is Label { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.label.defs#label' + ) +} + +export function validateLabel(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.label.defs#label', v) +} + +/** Metadata tags on an atproto record, published by the author within the record. */ +export interface SelfLabels { + values: SelfLabel[] + [k: string]: unknown +} + +export function isSelfLabels(v: unknown): v is SelfLabels { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.label.defs#selfLabels' + ) +} + +export function validateSelfLabels(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.label.defs#selfLabels', v) +} + +/** Metadata tag on an atproto record, published by the author within the record. Note that schemas should use #selfLabels, not #selfLabel. */ +export interface SelfLabel { + /** The short string name of the value or type of this label. */ + val: string + [k: string]: unknown +} + +export function isSelfLabel(v: unknown): v is SelfLabel { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.label.defs#selfLabel' + ) +} + +export function validateSelfLabel(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.label.defs#selfLabel', v) +} + +/** Declares a label value and its expected interpretations and behaviors. */ +export interface LabelValueDefinition { + /** The value of the label being defined. Must only include lowercase ascii and the '-' character ([a-z-]+). */ + identifier: string + /** How should a client visually convey this label? 'inform' means neutral and informational; 'alert' means negative and warning; 'none' means show nothing. */ + severity: 'inform' | 'alert' | 'none' | (string & {}) + /** What should this label hide in the UI, if applied? 'content' hides all of the target; 'media' hides the images/video/audio; 'none' hides nothing. */ + blurs: 'content' | 'media' | 'none' | (string & {}) + /** The default setting for this label. */ + defaultSetting: 'ignore' | 'warn' | 'hide' | (string & {}) + /** Does the user need to have adult content enabled in order to configure this label? */ + adultOnly?: boolean + locales: LabelValueDefinitionStrings[] + [k: string]: unknown +} + +export function isLabelValueDefinition(v: unknown): v is LabelValueDefinition { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.label.defs#labelValueDefinition' + ) +} + +export function validateLabelValueDefinition(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.label.defs#labelValueDefinition', v) +} + +/** Strings which describe the label in the UI, localized into a specific language. */ +export interface LabelValueDefinitionStrings { + /** The code of the language these strings are written in. */ + lang: string + /** A short human-readable name for the label. */ + name: string + /** A longer description of what the label means and why it might be applied. */ + description: string + [k: string]: unknown +} + +export function isLabelValueDefinitionStrings( + v: unknown, +): v is LabelValueDefinitionStrings { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.label.defs#labelValueDefinitionStrings' + ) +} + +export function validateLabelValueDefinitionStrings( + v: unknown, +): ValidationResult { + return lexicons.validate( + 'com.atproto.label.defs#labelValueDefinitionStrings', + v, + ) +} + +export type LabelValue = + | '!hide' + | '!no-promote' + | '!warn' + | '!no-unauthenticated' + | 'dmca-violation' + | 'doxxing' + | 'porn' + | 'sexual' + | 'nudity' + | 'nsfl' + | 'gore' + | (string & {}) diff --git a/src/lexicon/types/com/atproto/repo/strongRef.ts b/src/lexicon/types/com/atproto/repo/strongRef.ts new file mode 100644 index 0000000..8b21a6d --- /dev/null +++ b/src/lexicon/types/com/atproto/repo/strongRef.ts @@ -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 Main { + uri: string + cid: string + [k: string]: unknown +} + +export function isMain(v: unknown): v is Main { + return ( + isObj(v) && + hasProp(v, '$type') && + (v.$type === 'com.atproto.repo.strongRef#main' || + v.$type === 'com.atproto.repo.strongRef') + ) +} + +export function validateMain(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.repo.strongRef#main', v) +}