Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/frontpage-atproto-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
15 changes: 9 additions & 6 deletions packages/frontpage-atproto-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@
"private": true,
"name": "@repo/frontpage-atproto-client",
"type": "module",
"main": "src/index.ts",
"exports": {
".": {
"import": "./src/index.ts"
"import": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./lexicons": {
"import": "./src/lexicons.ts"
"import": "./dist/src/lexicons.js",
"types": "./dist/src/lexicons.d.ts"
}
},
"scripts": {
"format:write": "prettier --write src",
"fetch-lexicons": "tsx ./fetch-lexicons.mts",
"type-check": "tsc --noEmit"
"type-check": "tsc --noEmit",
"build": "tsc"
},
"dependencies": {
"@atproto/lexicon": "^0.4.2",
"@atproto/xrpc": "^0.6.3",
"multiformats": "^13.3.0"
},
"devDependencies": {
"@atproto/lex-cli": "^0.5.1",
"@atproto/lex-cli": "^0.8.0",
"@repo/typescript-config": "workspace:*",
"@types/adm-zip": "^0.5.5",
"@types/node": "^20",
"adm-zip": "^0.5.16",
"tsx": "^4.16.5"
"tsx": "^4.16.5",
"typescript": "catalog:"
}
}
131 changes: 68 additions & 63 deletions packages/frontpage-atproto-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { XrpcClient, FetchHandler, FetchHandlerOptions } from "@atproto/xrpc";
import { schemas } from "./lexicons";
import {
XrpcClient,
type FetchHandler,
type FetchHandlerOptions,
} from "@atproto/xrpc";
import { schemas } from "./lexicons.js";
import { CID } from "multiformats/cid";
import * as ComAtprotoRepoApplyWrites from "./types/com/atproto/repo/applyWrites";
import * as ComAtprotoRepoCreateRecord from "./types/com/atproto/repo/createRecord";
import * as ComAtprotoRepoDefs from "./types/com/atproto/repo/defs";
import * as ComAtprotoRepoDeleteRecord from "./types/com/atproto/repo/deleteRecord";
import * as ComAtprotoRepoDescribeRepo from "./types/com/atproto/repo/describeRepo";
import * as ComAtprotoRepoGetRecord from "./types/com/atproto/repo/getRecord";
import * as ComAtprotoRepoImportRepo from "./types/com/atproto/repo/importRepo";
import * as ComAtprotoRepoListMissingBlobs from "./types/com/atproto/repo/listMissingBlobs";
import * as ComAtprotoRepoListRecords from "./types/com/atproto/repo/listRecords";
import * as ComAtprotoRepoPutRecord from "./types/com/atproto/repo/putRecord";
import * as ComAtprotoRepoStrongRef from "./types/com/atproto/repo/strongRef";
import * as ComAtprotoRepoUploadBlob from "./types/com/atproto/repo/uploadBlob";
import * as FyiUnravelFrontpageComment from "./types/fyi/unravel/frontpage/comment";
import * as FyiUnravelFrontpagePost from "./types/fyi/unravel/frontpage/post";
import * as FyiUnravelFrontpageVote from "./types/fyi/unravel/frontpage/vote";

export * as ComAtprotoRepoApplyWrites from "./types/com/atproto/repo/applyWrites";
export * as ComAtprotoRepoCreateRecord from "./types/com/atproto/repo/createRecord";
export * as ComAtprotoRepoDefs from "./types/com/atproto/repo/defs";
export * as ComAtprotoRepoDeleteRecord from "./types/com/atproto/repo/deleteRecord";
export * as ComAtprotoRepoDescribeRepo from "./types/com/atproto/repo/describeRepo";
export * as ComAtprotoRepoGetRecord from "./types/com/atproto/repo/getRecord";
export * as ComAtprotoRepoImportRepo from "./types/com/atproto/repo/importRepo";
export * as ComAtprotoRepoListMissingBlobs from "./types/com/atproto/repo/listMissingBlobs";
export * as ComAtprotoRepoListRecords from "./types/com/atproto/repo/listRecords";
export * as ComAtprotoRepoPutRecord from "./types/com/atproto/repo/putRecord";
export * as ComAtprotoRepoStrongRef from "./types/com/atproto/repo/strongRef";
export * as ComAtprotoRepoUploadBlob from "./types/com/atproto/repo/uploadBlob";
export * as FyiUnravelFrontpageComment from "./types/fyi/unravel/frontpage/comment";
export * as FyiUnravelFrontpagePost from "./types/fyi/unravel/frontpage/post";
export * as FyiUnravelFrontpageVote from "./types/fyi/unravel/frontpage/vote";
import { type OmitKey, type Un$Typed } from "./util.js";
import * as ComAtprotoRepoApplyWrites from "./types/com/atproto/repo/applyWrites.js";
import * as ComAtprotoRepoCreateRecord from "./types/com/atproto/repo/createRecord.js";
import * as ComAtprotoRepoDefs from "./types/com/atproto/repo/defs.js";
import * as ComAtprotoRepoDeleteRecord from "./types/com/atproto/repo/deleteRecord.js";
import * as ComAtprotoRepoDescribeRepo from "./types/com/atproto/repo/describeRepo.js";
import * as ComAtprotoRepoGetRecord from "./types/com/atproto/repo/getRecord.js";
import * as ComAtprotoRepoImportRepo from "./types/com/atproto/repo/importRepo.js";
import * as ComAtprotoRepoListMissingBlobs from "./types/com/atproto/repo/listMissingBlobs.js";
import * as ComAtprotoRepoListRecords from "./types/com/atproto/repo/listRecords.js";
import * as ComAtprotoRepoPutRecord from "./types/com/atproto/repo/putRecord.js";
import * as ComAtprotoRepoStrongRef from "./types/com/atproto/repo/strongRef.js";
import * as ComAtprotoRepoUploadBlob from "./types/com/atproto/repo/uploadBlob.js";
import * as FyiUnravelFrontpageComment from "./types/fyi/unravel/frontpage/comment.js";
import * as FyiUnravelFrontpagePost from "./types/fyi/unravel/frontpage/post.js";
import * as FyiUnravelFrontpageVote from "./types/fyi/unravel/frontpage/vote.js";

export * as ComAtprotoRepoApplyWrites from "./types/com/atproto/repo/applyWrites.js";
export * as ComAtprotoRepoCreateRecord from "./types/com/atproto/repo/createRecord.js";
export * as ComAtprotoRepoDefs from "./types/com/atproto/repo/defs.js";
export * as ComAtprotoRepoDeleteRecord from "./types/com/atproto/repo/deleteRecord.js";
export * as ComAtprotoRepoDescribeRepo from "./types/com/atproto/repo/describeRepo.js";
export * as ComAtprotoRepoGetRecord from "./types/com/atproto/repo/getRecord.js";
export * as ComAtprotoRepoImportRepo from "./types/com/atproto/repo/importRepo.js";
export * as ComAtprotoRepoListMissingBlobs from "./types/com/atproto/repo/listMissingBlobs.js";
export * as ComAtprotoRepoListRecords from "./types/com/atproto/repo/listRecords.js";
export * as ComAtprotoRepoPutRecord from "./types/com/atproto/repo/putRecord.js";
export * as ComAtprotoRepoStrongRef from "./types/com/atproto/repo/strongRef.js";
export * as ComAtprotoRepoUploadBlob from "./types/com/atproto/repo/uploadBlob.js";
export * as FyiUnravelFrontpageComment from "./types/fyi/unravel/frontpage/comment.js";
export * as FyiUnravelFrontpagePost from "./types/fyi/unravel/frontpage/post.js";
export * as FyiUnravelFrontpageVote from "./types/fyi/unravel/frontpage/vote.js";

export class AtpBaseClient extends XrpcClient {
com: ComNS;
Expand Down Expand Up @@ -217,27 +222,27 @@ export class FyiUnravelNS {

export class FyiUnravelFrontpageNS {
_client: XrpcClient;
comment: CommentRecord;
post: PostRecord;
vote: VoteRecord;
comment: FyiUnravelFrontpageCommentRecord;
post: FyiUnravelFrontpagePostRecord;
vote: FyiUnravelFrontpageVoteRecord;

constructor(client: XrpcClient) {
this._client = client;
this.comment = new CommentRecord(client);
this.post = new PostRecord(client);
this.vote = new VoteRecord(client);
this.comment = new FyiUnravelFrontpageCommentRecord(client);
this.post = new FyiUnravelFrontpagePostRecord(client);
this.vote = new FyiUnravelFrontpageVoteRecord(client);
}
}

export class CommentRecord {
export class FyiUnravelFrontpageCommentRecord {
_client: XrpcClient;

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

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, "collection">,
params: OmitKey<ComAtprotoRepoListRecords.QueryParams, "collection">,
): Promise<{
cursor?: string;
records: { uri: string; value: FyiUnravelFrontpageComment.Record }[];
Expand All @@ -250,7 +255,7 @@ export class CommentRecord {
}

async get(
params: Omit<ComAtprotoRepoGetRecord.QueryParams, "collection">,
params: OmitKey<ComAtprotoRepoGetRecord.QueryParams, "collection">,
): Promise<{
uri: string;
cid: string;
Expand All @@ -264,25 +269,25 @@ export class CommentRecord {
}

async create(
params: Omit<
params: OmitKey<
ComAtprotoRepoCreateRecord.InputSchema,
"collection" | "record"
>,
record: FyiUnravelFrontpageComment.Record,
record: Un$Typed<FyiUnravelFrontpageComment.Record>,
headers?: Record<string, string>,
): Promise<{ uri: string; cid: string }> {
record.$type = "fyi.unravel.frontpage.comment";
const collection = "fyi.unravel.frontpage.comment";
const res = await this._client.call(
"com.atproto.repo.createRecord",
undefined,
{ collection: "fyi.unravel.frontpage.comment", ...params, record },
{ collection, ...params, record: { ...record, $type: collection } },
{ encoding: "application/json", headers },
);
return res.data;
}

async delete(
params: Omit<ComAtprotoRepoDeleteRecord.InputSchema, "collection">,
params: OmitKey<ComAtprotoRepoDeleteRecord.InputSchema, "collection">,
headers?: Record<string, string>,
): Promise<void> {
await this._client.call(
Expand All @@ -294,15 +299,15 @@ export class CommentRecord {
}
}

export class PostRecord {
export class FyiUnravelFrontpagePostRecord {
_client: XrpcClient;

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

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, "collection">,
params: OmitKey<ComAtprotoRepoListRecords.QueryParams, "collection">,
): Promise<{
cursor?: string;
records: { uri: string; value: FyiUnravelFrontpagePost.Record }[];
Expand All @@ -315,7 +320,7 @@ export class PostRecord {
}

async get(
params: Omit<ComAtprotoRepoGetRecord.QueryParams, "collection">,
params: OmitKey<ComAtprotoRepoGetRecord.QueryParams, "collection">,
): Promise<{
uri: string;
cid: string;
Expand All @@ -329,25 +334,25 @@ export class PostRecord {
}

async create(
params: Omit<
params: OmitKey<
ComAtprotoRepoCreateRecord.InputSchema,
"collection" | "record"
>,
record: FyiUnravelFrontpagePost.Record,
record: Un$Typed<FyiUnravelFrontpagePost.Record>,
headers?: Record<string, string>,
): Promise<{ uri: string; cid: string }> {
record.$type = "fyi.unravel.frontpage.post";
const collection = "fyi.unravel.frontpage.post";
const res = await this._client.call(
"com.atproto.repo.createRecord",
undefined,
{ collection: "fyi.unravel.frontpage.post", ...params, record },
{ collection, ...params, record: { ...record, $type: collection } },
{ encoding: "application/json", headers },
);
return res.data;
}

async delete(
params: Omit<ComAtprotoRepoDeleteRecord.InputSchema, "collection">,
params: OmitKey<ComAtprotoRepoDeleteRecord.InputSchema, "collection">,
headers?: Record<string, string>,
): Promise<void> {
await this._client.call(
Expand All @@ -359,15 +364,15 @@ export class PostRecord {
}
}

export class VoteRecord {
export class FyiUnravelFrontpageVoteRecord {
_client: XrpcClient;

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

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, "collection">,
params: OmitKey<ComAtprotoRepoListRecords.QueryParams, "collection">,
): Promise<{
cursor?: string;
records: { uri: string; value: FyiUnravelFrontpageVote.Record }[];
Expand All @@ -380,7 +385,7 @@ export class VoteRecord {
}

async get(
params: Omit<ComAtprotoRepoGetRecord.QueryParams, "collection">,
params: OmitKey<ComAtprotoRepoGetRecord.QueryParams, "collection">,
): Promise<{
uri: string;
cid: string;
Expand All @@ -394,25 +399,25 @@ export class VoteRecord {
}

async create(
params: Omit<
params: OmitKey<
ComAtprotoRepoCreateRecord.InputSchema,
"collection" | "record"
>,
record: FyiUnravelFrontpageVote.Record,
record: Un$Typed<FyiUnravelFrontpageVote.Record>,
headers?: Record<string, string>,
): Promise<{ uri: string; cid: string }> {
record.$type = "fyi.unravel.frontpage.vote";
const collection = "fyi.unravel.frontpage.vote";
const res = await this._client.call(
"com.atproto.repo.createRecord",
undefined,
{ collection: "fyi.unravel.frontpage.vote", ...params, record },
{ collection, ...params, record: { ...record, $type: collection } },
{ encoding: "application/json", headers },
);
return res.data;
}

async delete(
params: Omit<ComAtprotoRepoDeleteRecord.InputSchema, "collection">,
params: OmitKey<ComAtprotoRepoDeleteRecord.InputSchema, "collection">,
headers?: Record<string, string>,
): Promise<void> {
await this._client.call(
Expand Down
43 changes: 39 additions & 4 deletions packages/frontpage-atproto-client/src/lexicons.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { LexiconDoc, Lexicons } from "@atproto/lexicon";
import {
type LexiconDoc,
Lexicons,
ValidationError,
type ValidationResult,
} from "@atproto/lexicon";
import { type $Typed, is$typed, maybe$typed } from "./util.js";

export const schemaDict = {
ComAtprotoRepoApplyWrites: {
Expand Down Expand Up @@ -858,9 +864,38 @@ export const schemaDict = {
},
},
},
};
export const schemas: LexiconDoc[] = Object.values(schemaDict) as LexiconDoc[];
} as const satisfies Record<string, LexiconDoc>;
export const schemas = Object.values(schemaDict) satisfies LexiconDoc[];
export const lexicons: Lexicons = new Lexicons(schemas);

export function validate<T extends { $type: string }>(
v: unknown,
id: string,
hash: string,
requiredType: true,
): ValidationResult<T>;
export function validate<T extends { $type?: string }>(
v: unknown,
id: string,
hash: string,
requiredType?: false,
): ValidationResult<T>;
export function validate(
v: unknown,
id: string,
hash: string,
requiredType?: boolean,
): ValidationResult {
return (requiredType ? is$typed : maybe$typed)(v, id, hash)
? lexicons.validate(`${id}#${hash}`, v)
: {
success: false,
error: new ValidationError(
`Must be an object with "${hash === "main" ? id : `${id}#${hash}`}" $type property`,
),
};
}

export const ids = {
ComAtprotoRepoApplyWrites: "com.atproto.repo.applyWrites",
ComAtprotoRepoCreateRecord: "com.atproto.repo.createRecord",
Expand All @@ -877,4 +912,4 @@ export const ids = {
FyiUnravelFrontpageComment: "fyi.unravel.frontpage.comment",
FyiUnravelFrontpagePost: "fyi.unravel.frontpage.post",
FyiUnravelFrontpageVote: "fyi.unravel.frontpage.vote",
};
} as const;
Loading