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.

no slow types in api

+35 -24
+4 -3
lex-gen/codegen/client.ts
··· 74 74 file.addImportDeclaration({ 75 75 moduleSpecifier: "@atp/xrpc", 76 76 namedImports: [ 77 - { name: "XrpcClient" }, 78 - { name: "FetchHandler", isTypeOnly: true }, 79 - { name: "FetchHandlerOptions", isTypeOnly: true }, 77 + { name: "XrpcClient" }, 78 + { name: "FetchHandler", isTypeOnly: true }, 79 + { name: "FetchHandlerOptions", isTypeOnly: true }, 80 80 ], 81 81 }); 82 82 //= import {schemas} from './lexicons.ts' ··· 637 637 name: "toKnownErr", 638 638 isExported: true, 639 639 parameters: [{ name: "e", type: "unknown" }], 640 + returnType: "unknown", 640 641 statements: customErrors.length 641 642 ? [ 642 643 "if (e instanceof XRPCError) {",
+29 -19
lex-gen/codegen/lex-gen.ts
··· 191 191 if (needsBlobRef) { 192 192 file.addImportDeclaration({ 193 193 isTypeOnly: true, 194 - moduleSpecifier: "@atp/lexicon", 194 + moduleSpecifier: "@atp/lexicon", 195 195 namedImports: [{ name: "BlobRef" }], 196 196 }); 197 197 } ··· 200 200 if (needsCID) { 201 201 file.addImportDeclaration({ 202 202 isTypeOnly: true, 203 - moduleSpecifier: "multiformats/cid", 203 + moduleSpecifier: "multiformats/cid", 204 204 namedImports: [{ name: "CID" }], 205 205 }); 206 206 } 207 207 208 208 const utilPath = `${ 209 - baseNsid 210 - .split(".") 211 - .map((_str) => "..") 212 - .join("/") 209 + baseNsid 210 + .split(".") 211 + .map((_str) => "..") 212 + .join("/") 213 213 }/util${importExtension}`; 214 214 215 215 if (needsTypedValidation) { ··· 225 225 }) 226 226 .addNamedImports([{ name: "validate", alias: "_validate" }]); 227 227 228 + //= import type { ValidationResult } from '@atp/lexicon' 229 + file.addImportDeclaration({ 230 + isTypeOnly: true, 231 + moduleSpecifier: "@atp/lexicon", 232 + namedImports: [{ name: "ValidationResult" }], 233 + }); 234 + 228 235 // tsc adds protection against circular imports, which hurts bundle size. 229 236 // Since we know that lexicon.ts and util.ts do not depend on the file being 230 237 // generated, we can safely bypass this protection. ··· 286 293 ): Map<string, Set<string>> { 287 294 const imports: Map<string, Set<string>> = new Map(); 288 295 const mappings = options?.mappings; 289 - 296 + 290 297 // Check if any records exist (which use ATP_METHODS) 291 298 const hasRecords = lexiconDocs.some((lexiconDoc) => 292 299 Object.values(lexiconDoc.defs).some((def) => def.type === "record") 293 300 ); 294 - 301 + 295 302 // Record classes use ATP_METHODS which may need external imports 296 303 // Note: put is commented out in genRecordCls, so we don't import it 297 304 if (hasRecords) { ··· 357 364 } 358 365 } else { 359 366 const targetPath = "/" + nsid.split(".").join("/") + importExtension; 360 - let resolvedPath = getRelativePath(startPath, targetPath); 361 - if (!resolvedPath.startsWith(".")) { 362 - resolvedPath = `./${resolvedPath}`; 363 - } 364 - file.addImportDeclaration({ 365 - isTypeOnly: true, 366 - moduleSpecifier: resolvedPath, 367 - namespaceImport: toTitleCase(nsid), 368 - }); 367 + let resolvedPath = getRelativePath(startPath, targetPath); 368 + if (!resolvedPath.startsWith(".")) { 369 + resolvedPath = `./${resolvedPath}`; 370 + } 371 + file.addImportDeclaration({ 372 + isTypeOnly: true, 373 + moduleSpecifier: resolvedPath, 374 + namespaceImport: toTitleCase(nsid), 375 + }); 369 376 } 370 377 } 371 378 } ··· 563 570 declarations: [ 564 571 { 565 572 name: toScreamingSnakeCase(getHash(lexUri)), 573 + type: "string", 566 574 initializer: `\`\${id}#${getHash(lexUri)}\``, 567 575 }, 568 576 ], ··· 868 876 869 877 const isX = toCamelCase(`is-${ifaceName}`); 870 878 871 - //= export function is{X}<V>(v: V) {...} 879 + //= export function is{X}<V>(v: V): v is {ifaceName} & V {...} 872 880 file 873 881 .addFunction({ 874 882 name: isX, 875 883 typeParameters: [{ name: `V` }], 876 884 parameters: [{ name: `v`, type: `V` }], 885 + returnType: `v is ${ifaceName} & V`, 877 886 isExported: true, 878 887 }) 879 888 .setBodyText(`return is$typed(v, id, ${hashVar})`); 880 889 881 890 const validateX = toCamelCase(`validate-${ifaceName}`); 882 891 883 - //= export function validate{X}(v: unknown) {...} 892 + //= export function validate{X}<V>(v: V): ValidationResult<{ifaceName} & V> {...} 884 893 file 885 894 .addFunction({ 886 895 name: validateX, 887 896 typeParameters: [{ name: `V` }], 888 897 parameters: [{ name: `v`, type: `V` }], 898 + returnType: `ValidationResult<${ifaceName} & V>`, 889 899 isExported: true, 890 900 }) 891 901 .setBodyText(
+2 -2
lex-gen/codegen/server.ts
··· 143 143 } 144 144 file.addImportDeclaration({ 145 145 isTypeOnly: true, 146 - moduleSpecifier: `./types/${ 147 - lexiconDoc.id.split(".").join("/") 146 + moduleSpecifier: `./types/${ 147 + lexiconDoc.id.split(".").join("/") 148 148 }${importExtension}`, 149 149 namespaceImport: toTitleCase(lexiconDoc.id), 150 150 });