Suite of AT Protocol TypeScript libraries built on web standards
21
fork

Configure Feed

Select the types of activity you want to include in your feed.

split cli and lexgen

+109 -61
cli/codegen/client.ts lex-gen/codegen/client.ts
cli/codegen/common.ts lex-gen/codegen/common.ts
cli/codegen/lex-gen.ts lex-gen/codegen/lex-gen.ts
cli/codegen/server.ts lex-gen/codegen/server.ts
cli/codegen/util.ts lex-gen/codegen/util.ts
-12
cli/commands/lex.ts
··· 1 - import { Command } from "@cliffy/command"; 2 - import { genApi, genMd, genServer, genTsObj } from "./lex/index.ts"; 3 - 4 - export const lexCommand = new Command() 5 - .name("lex") 6 - .description("Lexicon-related commands"); 7 - 8 - lexCommand 9 - .command("gen-api", genApi) 10 - .command("gen-md", genMd) 11 - .command("gen-server", genServer) 12 - .command("gen-ts-obj", genTsObj);
+3 -3
cli/commands/lex/gen-api.ts lex-gen/cmd/gen-api.ts
··· 4 4 genFileDiff, 5 5 printFileDiff, 6 6 readAllLexicons, 7 - } from "../../util.ts"; 8 - import { genClientApi } from "../../codegen/client.ts"; 9 - import { formatGeneratedFiles } from "../../codegen/util.ts"; 7 + } from "../util.ts"; 8 + import { genClientApi } from "../codegen/client.ts"; 9 + import { formatGeneratedFiles } from "../codegen/util.ts"; 10 10 11 11 const command = new Command() 12 12 .description("Generate a TS client API")
+2 -2
cli/commands/lex/gen-md.ts lex-gen/cmd/gen-md.ts
··· 1 1 import { Command } from "@cliffy/command"; 2 - import { readAllLexicons } from "../../util.ts"; 3 - import * as mdGen from "../../mdgen/index.ts"; 2 + import { readAllLexicons } from "../util.ts"; 3 + import * as mdGen from "../mdgen/index.ts"; 4 4 import process from "node:process"; 5 5 6 6 const isDeno = typeof Deno !== "undefined";
+3 -3
cli/commands/lex/gen-server.ts lex-gen/cmd/gen-server.ts
··· 4 4 genFileDiff, 5 5 printFileDiff, 6 6 readAllLexicons, 7 - } from "../../util.ts"; 8 - import { formatGeneratedFiles } from "../../codegen/util.ts"; 9 - import { genServerApi } from "../../codegen/server.ts"; 7 + } from "../util.ts"; 8 + import { formatGeneratedFiles } from "../codegen/util.ts"; 9 + import { genServerApi } from "../codegen/server.ts"; 10 10 11 11 const command = new Command() 12 12 .description("Generate a TS server API")
+1 -1
cli/commands/lex/gen-ts-obj.ts lex-gen/cmd/gen-ts-obj.ts
··· 1 1 import { Command } from "@cliffy/command"; 2 - import { genTsObj, readAllLexicons } from "../../util.ts"; 2 + import { genTsObj, readAllLexicons } from "../util.ts"; 3 3 4 4 const command = new Command() 5 5 .description("Generate a TS file that exports an array of lexicons")
cli/commands/lex/index.ts lex-gen/cmd/index.ts
+1 -7
cli/deno.json
··· 5 5 "license": "MIT", 6 6 "imports": { 7 7 "@atproto/api": "npm:@atproto/api@^0.18.0", 8 - "@cliffy/ansi": "jsr:@cliffy/ansi@^1.0.0-rc.8", 9 8 "@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.8", 10 - "@cliffy/prompt": "jsr:@cliffy/prompt@^1.0.0-rc.8", 11 - "@std/fs": "jsr:@std/fs@^1.0.19", 12 - "@std/path": "jsr:@std/path@^1.1.2", 13 - "prettier": "npm:prettier@^3.6.2", 14 - "ts-morph": "jsr:@ts-morph/ts-morph@^26.0.0", 15 - "zod": "jsr:@zod/zod@^4.1.11" 9 + "@cliffy/prompt": "jsr:@cliffy/prompt@^1.0.0-rc.8" 16 10 }, 17 11 "tasks": { 18 12 "start": "deno run --allow-read --allow-write --allow-env mod.ts"
+20 -8
cli/get.ts
··· 20 20 recordAlreadyShown: boolean; 21 21 } 22 22 23 - async function resolveDid(input: string): Promise<string> { 24 - const idResolver = new IdResolver({}); 25 - 23 + async function resolveDid( 24 + input: string, 25 + idResolver: IdResolver, 26 + ): Promise<string> { 26 27 if (!input.startsWith("did:")) { 27 28 const handleResolution = await idResolver.handle.resolve(input); 28 29 if (!handleResolution) { ··· 34 35 return input; 35 36 } 36 37 37 - async function getPdsUrl(did: string): Promise<string> { 38 - const idResolver = new IdResolver({}); 38 + async function getPdsUrl(did: string, idResolver: IdResolver): Promise<string> { 39 39 const didDoc = await idResolver.did.resolve(did); 40 40 41 41 if (!didDoc?.service) { ··· 264 264 265 265 export async function handleGetCommand(input: string) { 266 266 try { 267 + const idResolver = new IdResolver({}); 267 268 const isFullUri = input.includes("/"); 268 269 let atUri: AtUri | null = null; 269 270 let did: string; 270 271 271 272 if (isFullUri) { 272 273 atUri = new AtUri(input); 273 - did = await resolveDid(atUri.hostname); 274 + did = await resolveDid(atUri.hostname, idResolver); 274 275 } else { 275 - did = await resolveDid(input); 276 + did = await resolveDid(input, idResolver); 276 277 } 277 278 278 - const pdsUrl = await getPdsUrl(did); 279 + const pdsUrl = await getPdsUrl(did, idResolver); 279 280 const xrpcClient = createXrpcClient(pdsUrl); 280 281 281 282 const state: PromptState = { ··· 283 284 rkey: atUri?.rkey, 284 285 recordAlreadyShown: false, 285 286 }; 287 + 288 + if (state.collection && state.rkey) { 289 + const record = await fetchRecord( 290 + xrpcClient, 291 + did, 292 + state.collection, 293 + state.rkey, 294 + ); 295 + console.log(JSON.stringify(record, null, 2)); 296 + return; 297 + } 286 298 287 299 const prompts: Array<{ 288 300 name: string;
cli/mdgen/index.ts lex-gen/mdgen/index.ts
+3 -17
cli/mod.ts
··· 3 3 * 4 4 * A general command-line interface for ATP development tools. 5 5 * 6 - * Previously @atp/lex-cli 7 - * 8 6 * ## Installation 9 7 * ```bash 10 - * deno install -g jsr:@atp/cli@latest --name atp 8 + * deno install -g jsr:@atp/cli --name atp 11 9 * ``` 12 10 * Alternatively, you can use it without installation by referring to 13 11 * it as `jsr:@atp/cli` instead of `atp`. 14 12 * 15 - * @example Generate Server from Lexicon 16 - * ```bash 17 - * atp lex gen-server -i <path/to/lexicon/dir> -o <output/path> 18 - * ``` 19 - * 20 - * @example Generate Client from Lexicon 21 - * ```bash 22 - * atp lex gen-api -i <path/to/lexicon/dir> -o <output/path> 23 - * ``` 24 - * 25 13 * @example Fetch Record from AT URI 26 14 * ```bash 27 - * atp fetch at://bsky.app/app.bsky.feed.post/3jrq7y2h2ts2b 15 + * atp at://bsky.app/app.bsky.feed.post/3jrq7y2h2ts2b 28 16 * ``` 29 17 * 30 18 * @module 31 19 */ 32 20 import { Command } from "@cliffy/command"; 33 - import { lexCommand } from "./commands/lex.ts"; 34 21 import { handleGetCommand } from "./get.ts"; 35 22 import process from "node:process"; 36 23 ··· 41 28 await new Command() 42 29 .name("atp") 43 30 .description( 44 - "ATP Development CLI. Use this command directly to fetch records from a URI.", 31 + "ATP Development CLI.", 45 32 ) 46 33 .arguments("<uri>") 47 34 .action(async (_options, input: string) => { ··· 57 44 else process.exit(1); 58 45 } 59 46 }) 60 - .command("lex", lexCommand) 61 47 .parse(args);
cli/types.ts lex-gen/types.ts
cli/util.ts lex-gen/util.ts
+2 -1
deno.json
··· 10 10 "xrpc", 11 11 "xrpc-server", 12 12 "sync", 13 - "cli" 13 + "cli", 14 + "lex-gen" 14 15 ], 15 16 "imports": { 16 17 "@std/assert": "jsr:@std/assert@^1.0.14"
+12 -7
deno.lock
··· 1193 1193 }, 1194 1194 "cli": { 1195 1195 "dependencies": [ 1196 - "jsr:@cliffy/ansi@^1.0.0-rc.8", 1197 1196 "jsr:@cliffy/command@^1.0.0-rc.8", 1198 1197 "jsr:@cliffy/prompt@^1.0.0-rc.8", 1199 - "jsr:@std/fs@^1.0.19", 1200 - "jsr:@std/path@^1.1.2", 1201 - "jsr:@ts-morph/ts-morph@26", 1202 - "jsr:@zod/zod@^4.1.11", 1203 - "npm:@atproto/api@0.18", 1204 - "npm:prettier@^3.6.2" 1198 + "npm:@atproto/api@0.18" 1205 1199 ] 1206 1200 }, 1207 1201 "common": { ··· 1228 1222 "npm:@did-plc/lib@^0.0.4", 1229 1223 "npm:@did-plc/server@^0.0.1", 1230 1224 "npm:get-port@^7.1.0" 1225 + ] 1226 + }, 1227 + "lex-gen": { 1228 + "dependencies": [ 1229 + "jsr:@cliffy/ansi@^1.0.0-rc.8", 1230 + "jsr:@cliffy/command@^1.0.0-rc.8", 1231 + "jsr:@std/fs@^1.0.19", 1232 + "jsr:@std/path@^1.1.2", 1233 + "jsr:@ts-morph/ts-morph@26", 1234 + "jsr:@zod/zod@^4.1.11", 1235 + "npm:prettier@^3.6.2" 1231 1236 ] 1232 1237 }, 1233 1238 "lexicon": {
+15
lex-gen/deno.json
··· 1 + { 2 + "name": "@atp/lex-gen", 3 + "version": "0.1.0-alpha.1", 4 + "exports": "./mod.ts", 5 + "license": "MIT", 6 + "imports": { 7 + "@cliffy/ansi": "jsr:@cliffy/ansi@^1.0.0-rc.8", 8 + "@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.8", 9 + "@std/fs": "jsr:@std/fs@^1.0.19", 10 + "@std/path": "jsr:@std/path@^1.1.2", 11 + "prettier": "npm:prettier@^3.6.2", 12 + "ts-morph": "jsr:@ts-morph/ts-morph@^26.0.0", 13 + "zod": "jsr:@zod/zod@^4.1.11" 14 + } 15 + }
+47
lex-gen/mod.ts
··· 1 + /** 2 + * # AT Protocol Lexicon Generator 3 + * 4 + * A command-line interface for generating docs, servers, and clients 5 + * from AT Protocol lexicon files. 6 + * 7 + * Previously named `lex-cli` 8 + * 9 + * Turn lexicon files into: 10 + * - Markdown documentation 11 + * - Server implementation 12 + * - TypeScript objects 13 + * - Client implementation 14 + * 15 + * ## Installation 16 + * ```bash 17 + * deno install -g jsr:@atp/lex-gen --name lex-gen 18 + * ``` 19 + * Alternatively, you can use it without installation by referring to 20 + * it as `jsr:@atp/lex-gen` instead of `lex-gen`. 21 + * 22 + * @example Generate Server 23 + * ```bash 24 + * lex-gen server -i <path/to/lexicon/dir> -o <output/path> 25 + * ``` 26 + * 27 + * @example Generate Client 28 + * ```bash 29 + * lex-gen api -i <path/to/lexicon/dir> -o <output/path> 30 + * ``` 31 + * 32 + * @module 33 + */ 34 + import { Command } from "@cliffy/command"; 35 + import { genApi, genMd, genServer, genTsObj } from "./cmd/index.ts"; 36 + import process from "node:process"; 37 + 38 + const isDeno = typeof Deno !== "undefined"; 39 + 40 + await new Command() 41 + .name("lex-gen") 42 + .description("Lexicon Generator") 43 + .command("api", genApi) 44 + .command("md", genMd) 45 + .command("server", genServer) 46 + .command("ts-obj", genTsObj) 47 + .parse(isDeno ? Deno.args : process.argv.slice(2));