@ atute/ 原子弹
AT 议定书 (com.atproto.*) 计划定义
npm install @atcute/atproto
使用量
import { ComAtprotoLabelDefs } from '@atcute/atproto';
import { is } from '@atcute/lexicons';
const label: ComAtprotoLabelDefs.Label = {
cts: '2024-11-13T04:46:40.254Z',
neg: false,
src: 'did:plc:wkoofae5uytcm7bjncmev6n6',
uri: 'did:plc:ia76kvnndjutgedggx2ibrem',
val: 'she-it',
ver: 1,
};
is(ComAtprotoLabelDefs.labelSchema, label);
// -> true
与 @atcute/client
选择这3个选项之一来登记环境声明
// file: tsconfig.json
{
"compilerOptions": {
"types": ["@atcute/atproto"],
},
}
// file: env.d.ts
/// <reference types="@atcute/atproto" />
// file: index.ts
import type {} from '@atcute/atproto';
现在所有 XRPC 操作都应该在客户端可见
import { Client, simpleFetchHandler } from '@atcute/client';
const client = new Client({ handler: simpleFetchHandler({ service: 'https://bsky.social' }) });
const response = await client.get('com.atproto.server.describeServer');
// ...
与 @atcute/lex-cli
在创建自己的参考 AT 协议类型的词典时,配置 lex-cli 从 此软件包 :
// file: lex.config.js
import { defineLexiconConfig } from '@atcute/lex-cli';
export default defineLexiconConfig({
files: ['lexicons/**/*.json'],
outdir: 'src/lexicons/',
imports: ['@atcute/atproto'],
});