~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0
main
273 lines · 7.9 KB Raw History
/**
 * Core com.atproto lexicon schemas.
 * These are bundled because they aren't published via DNS-based lexicon resolution.
 * Source: https://github.com/bluesky-social/atproto/tree/main/lexicons/com/atproto
 */

/** @type {import('@bigmoves/lexicon').Lexicon} */
export const 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' },
      },
    },
  },
};

/** @type {import('@bigmoves/lexicon').Lexicon} */
export const comAtprotoRepoDefs = {
  lexicon: 1,
  id: 'com.atproto.repo.defs',
  defs: {
    commitMeta: {
      type: 'object',
      required: ['cid', 'rev'],
      properties: {
        cid: { type: 'string', format: 'cid' },
        rev: { type: 'string', format: 'tid' },
      },
    },
  },
};

/** @type {import('@bigmoves/lexicon').Lexicon} */
export const 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: '#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',
      ],
    },
  },
};

/** @type {import('@bigmoves/lexicon').Lexicon} */
export const comAtprotoModerationDefs = {
  lexicon: 1,
  id: 'com.atproto.moderation.defs',
  defs: {
    reasonType: {
      type: 'string',
      knownValues: [
        'com.atproto.moderation.defs#reasonSpam',
        'com.atproto.moderation.defs#reasonViolation',
        'com.atproto.moderation.defs#reasonMisleading',
        'com.atproto.moderation.defs#reasonSexual',
        'com.atproto.moderation.defs#reasonRude',
        'com.atproto.moderation.defs#reasonOther',
        'com.atproto.moderation.defs#reasonAppeal',
      ],
    },
    reasonSpam: {
      type: 'token',
      description: 'Spam: frequent unwanted promotion, replies, mentions.',
    },
    reasonViolation: {
      type: 'token',
      description: 'Direct violation of server rules, laws, terms of service.',
    },
    reasonMisleading: {
      type: 'token',
      description: 'Misleading identity, affiliation, or content.',
    },
    reasonSexual: {
      type: 'token',
      description: 'Unwanted or mislabeled sexual content.',
    },
    reasonRude: {
      type: 'token',
      description:
        'Rude, harassing, explicit, or otherwise unwelcoming behavior.',
    },
    reasonOther: {
      type: 'token',
      description: 'Reports not falling under another report category.',
    },
    reasonAppeal: {
      type: 'token',
      description: 'Appeal a previously taken moderation action.',
    },
    subjectType: {
      type: 'string',
      description: 'Tag describing a type of subject that might be reported.',
      knownValues: ['account', 'record', 'chat'],
    },
  },
};

/** All core com.atproto schemas */
export const coreSchemas = [
  comAtprotoRepoStrongRef,
  comAtprotoRepoDefs,
  comAtprotoLabelDefs,
  comAtprotoModerationDefs,
];