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

+390 -92
+10 -11
common/ipld.ts
··· 7 7 import { schema } from "./types.ts"; 8 8 import * as check from "./check.ts"; 9 9 import { crypto } from "@std/crypto"; 10 - import { concat, equals } from "@std/bytes"; 10 + import { concat, equals, fromString, toString } from "@atp/ui8"; 11 11 12 12 export const cborEncode = cborCodec.encode; 13 13 export const cborDecode = cborCodec.decode; ··· 105 105 try { 106 106 const data = concat(this.chunks); 107 107 const hash = new Uint8Array( 108 - await crypto.subtle.digest("SHA-256", data), 108 + await crypto.subtle.digest("SHA-256", new Uint8Array(data)), 109 109 ); 110 110 const actual = sha256RawToCid(hash); 111 111 if (!actual.equals(cid)) { ··· 163 163 if (typeof obj["$link"] === "string" && Object.keys(obj).length === 1) { 164 164 return CID.parse(obj["$link"]); 165 165 } 166 - if (typeof obj["$bytes"] === "string" && Object.keys(obj).length === 1) { 167 - return new Uint8Array( 168 - atob(obj["$bytes"]).split("").map((c) => c.charCodeAt(0)), 169 - ); 166 + if (typeof obj["$bytes"] === "string" && Object.keys(val).length === 1) { 167 + return fromString(obj["$bytes"], "base64"); 170 168 } 171 169 // walk plain objects 172 170 const toReturn: Record<string, IpldValue> = {}; 173 171 for (const key of Object.keys(obj)) { 174 - toReturn[key] = jsonToIpld(obj[key] as JsonValue); 172 + toReturn[key] = jsonToIpld(obj[key]); 175 173 } 176 174 return toReturn; 177 175 } ··· 186 184 } 187 185 // objects 188 186 if (val && typeof val === "object") { 187 + const obj = val as Record<string, unknown>; 189 188 // convert bytes 190 189 if (val instanceof Uint8Array) { 191 190 return { 192 - $bytes: btoa(String.fromCharCode(...val)).replace(/=+$/, ""), 191 + $bytes: toString(val, "base64"), 193 192 }; 194 193 } 195 194 // convert cids ··· 200 199 } 201 200 // walk plain objects 202 201 const toReturn: Record<string, JsonValue> = {}; 203 - for (const key of Object.keys(val as Record<string, unknown>)) { 204 - toReturn[key] = ipldToJson((val as Record<string, IpldValue>)[key]); 202 + for (const key of Object.keys(obj)) { 203 + toReturn[key] = ipldToJson(obj[key]); 205 204 } 206 205 return toReturn; 207 206 } ··· 226 225 } 227 226 // check cids 228 227 if (CID.asCID(a) && CID.asCID(b)) { 229 - return CID.asCID(a)!.equals(CID.asCID(b)!); 228 + return CID.asCID(a)!.equals(CID.asCID(b)); 230 229 } 231 230 // walk plain objects 232 231 const objA = a as Record<string, IpldValue>;
+1 -1
common/types.ts
··· 7 7 8 8 if (cid == null) { 9 9 ctx.addIssue({ 10 - code: z.ZodIssueCode.custom, 10 + code: "custom", 11 11 message: "Not a valid CID", 12 12 }); 13 13 return z.NEVER;
+28 -7
lexicon/blob-refs.ts
··· 2 2 import { z } from "zod"; 3 3 import { check, ipldToJson, schema } from "@atp/common"; 4 4 5 - export const typedJsonBlobRef = z.strictObject({ 5 + export const typedJsonBlobRef: TypedJsonBlobRefType = z.strictObject({ 6 6 $type: z.literal("blob"), 7 7 ref: schema.cid, 8 8 mimeType: z.string(), 9 9 size: z.number(), 10 10 }); 11 - export type TypedJsonBlobRef = z.infer<typeof typedJsonBlobRef>; 11 + type TypedJsonBlobRefType = z.ZodObject<{ 12 + $type: z.ZodLiteral<"blob">; 13 + ref: typeof schema.cid; 14 + mimeType: z.ZodString; 15 + size: z.ZodNumber; 16 + }>; 17 + export type TypedJsonBlobRef = z.infer<TypedJsonBlobRefType>; 12 18 13 - export const untypedJsonBlobRef = z.strictObject({ 19 + export const untypedJsonBlobRef: UntypedJsonBlobRefType = z.strictObject({ 14 20 cid: z.string(), 15 21 mimeType: z.string(), 16 22 }); 17 - export type UntypedJsonBlobRef = z.infer<typeof untypedJsonBlobRef>; 23 + type UntypedJsonBlobRefType = z.ZodObject<{ 24 + cid: z.ZodString; 25 + mimeType: z.ZodString; 26 + }>; 27 + export type UntypedJsonBlobRef = z.infer<UntypedJsonBlobRefType>; 18 28 19 - export const jsonBlobRef = z.union([typedJsonBlobRef, untypedJsonBlobRef]); 20 - export type JsonBlobRef = z.infer<typeof jsonBlobRef>; 29 + export const jsonBlobRef: JsonBlobRefType = z.union([ 30 + typedJsonBlobRef, 31 + untypedJsonBlobRef, 32 + ]); 33 + type JsonBlobRefType = z.ZodUnion< 34 + [TypedJsonBlobRefType, UntypedJsonBlobRefType] 35 + >; 36 + export type JsonBlobRef = z.infer<JsonBlobRefType>; 21 37 22 38 export class BlobRef { 23 39 public original: JsonBlobRef; ··· 60 76 }; 61 77 } 62 78 63 - toJSON() { 79 + toJSON(): { 80 + $type: "blob"; 81 + ref: { $link: string }; 82 + mimeType: string; 83 + size: number; 84 + } { 64 85 return ipldToJson(this.ipld()) as { 65 86 $type: "blob"; 66 87 ref: { $link: string };
+8 -5
lexicon/lexicons.ts
··· 146 146 /** 147 147 * Validate a record and throw on any error. 148 148 */ 149 - assertValidRecord(lexUri: string, value: unknown) { 149 + assertValidRecord(lexUri: string, value: unknown): unknown { 150 150 if (!isObj(value)) { 151 151 throw new ValidationError(`Record must be an object`); 152 152 } ··· 172 172 /** 173 173 * Validate xrpc query params and throw on any error. 174 174 */ 175 - assertValidXrpcParams(lexUri: string, value: unknown) { 175 + assertValidXrpcParams( 176 + lexUri: string, 177 + value: unknown, 178 + ): Record<string, unknown> | undefined { 176 179 lexUri = toLexUri(lexUri); 177 180 const def = this.getDefOrThrow(lexUri, [ 178 181 "query", ··· 185 188 /** 186 189 * Validate xrpc input body and throw on any error. 187 190 */ 188 - assertValidXrpcInput(lexUri: string, value: unknown) { 191 + assertValidXrpcInput(lexUri: string, value: unknown): unknown { 189 192 lexUri = toLexUri(lexUri); 190 193 const def = this.getDefOrThrow(lexUri, ["procedure"]); 191 194 return assertValidXrpcInput(this, def, value); ··· 194 197 /** 195 198 * Validate xrpc output body and throw on any error. 196 199 */ 197 - assertValidXrpcOutput(lexUri: string, value: unknown) { 200 + assertValidXrpcOutput(lexUri: string, value: unknown): unknown { 198 201 lexUri = toLexUri(lexUri); 199 202 const def = this.getDefOrThrow(lexUri, ["query", "procedure"]); 200 203 return assertValidXrpcOutput(this, def, value); ··· 212 215 /** 213 216 * Resolve a lex uri given a ref 214 217 */ 215 - resolveLexUri(lexUri: string, ref: string) { 218 + resolveLexUri(lexUri: string, ref: string): string { 216 219 lexUri = toLexUri(lexUri); 217 220 return toLexUri(ref, lexUri); 218 221 }
+343 -68
lexicon/types.ts
··· 3 3 import { isValidNsid } from "@atp/syntax"; 4 4 import { requiredPropertiesRefinement } from "./util.ts"; 5 5 6 - export const languageSchema = z 6 + export const languageSchema: z.ZodString = z 7 7 .string() 8 8 .refine(validateLanguage, "Invalid BCP47 language tag"); 9 9 10 - export const lexLang = z.record(languageSchema, z.string().optional()); 10 + export const lexLang: LexLangType = z.record( 11 + languageSchema, 12 + z.string().optional(), 13 + ); 11 14 12 - export type LexLang = z.infer<typeof lexLang>; 15 + type LexLangType = z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>; 16 + export type LexLang = z.infer<LexLangType>; 13 17 14 18 // primitives 15 19 // = 16 20 17 - export const lexBoolean = z.object({ 21 + export const lexBoolean: LexBooleanType = z.object({ 18 22 type: z.literal("boolean"), 19 23 description: z.string().optional(), 20 24 default: z.boolean().optional(), 21 25 const: z.boolean().optional(), 22 26 }); 23 - export type LexBoolean = z.infer<typeof lexBoolean>; 27 + type LexBooleanType = z.ZodObject<{ 28 + type: z.ZodLiteral<"boolean">; 29 + description: z.ZodOptional<z.ZodString>; 30 + default: z.ZodOptional<z.ZodBoolean>; 31 + const: z.ZodOptional<z.ZodBoolean>; 32 + }, z.core.$strip>; 33 + export type LexBoolean = z.infer<LexBooleanType>; 24 34 25 - export const lexInteger = z.object({ 35 + export const lexInteger: LexIntegerType = z.object({ 26 36 type: z.literal("integer"), 27 37 description: z.string().optional(), 28 38 default: z.number().int().optional(), ··· 31 41 enum: z.number().int().array().optional(), 32 42 const: z.number().int().optional(), 33 43 }); 34 - export type LexInteger = z.infer<typeof lexInteger>; 44 + type LexIntegerType = z.ZodObject<{ 45 + type: z.ZodLiteral<"integer">; 46 + description: z.ZodOptional<z.ZodString>; 47 + default: z.ZodOptional<z.ZodNumber>; 48 + minimum: z.ZodOptional<z.ZodNumber>; 49 + maximum: z.ZodOptional<z.ZodNumber>; 50 + enum: z.ZodOptional<z.ZodArray<z.ZodNumber>>; 51 + const: z.ZodOptional<z.ZodNumber>; 52 + }, z.core.$strip>; 53 + export type LexInteger = z.infer<LexIntegerType>; 35 54 36 - export const lexStringFormat = z.enum([ 55 + export const lexStringFormat: LexStringFormatType = z.enum([ 37 56 "datetime", 38 57 "uri", 39 58 "at-uri", ··· 46 65 "tid", 47 66 "record-key", 48 67 ]); 49 - export type LexStringFormat = z.infer<typeof lexStringFormat>; 68 + type LexStringFormatType = z.ZodEnum<{ 69 + datetime: "datetime"; 70 + uri: "uri"; 71 + "at-uri": "at-uri"; 72 + did: "did"; 73 + handle: "handle"; 74 + "at-identifier": "at-identifier"; 75 + nsid: "nsid"; 76 + cid: "cid"; 77 + language: "language"; 78 + tid: "tid"; 79 + "record-key": "record-key"; 80 + }>; 81 + export type LexStringFormat = z.infer<LexStringFormatType>; 50 82 51 - export const lexString = z.object({ 83 + export const lexString: LexStringType = z.object({ 52 84 type: z.literal("string"), 53 85 format: lexStringFormat.optional(), 54 86 description: z.string().optional(), ··· 61 93 const: z.string().optional(), 62 94 knownValues: z.string().array().optional(), 63 95 }); 64 - export type LexString = z.infer<typeof lexString>; 96 + type LexStringType = z.ZodObject<{ 97 + type: z.ZodLiteral<"string">; 98 + format: z.ZodOptional< 99 + z.ZodEnum<{ 100 + datetime: "datetime"; 101 + uri: "uri"; 102 + "at-uri": "at-uri"; 103 + did: "did"; 104 + handle: "handle"; 105 + "at-identifier": "at-identifier"; 106 + nsid: "nsid"; 107 + cid: "cid"; 108 + language: "language"; 109 + tid: "tid"; 110 + "record-key": "record-key"; 111 + }> 112 + >; 113 + description: z.ZodOptional<z.ZodString>; 114 + default: z.ZodOptional<z.ZodString>; 115 + minLength: z.ZodOptional<z.ZodNumber>; 116 + maxLength: z.ZodOptional<z.ZodNumber>; 117 + minGraphemes: z.ZodOptional<z.ZodNumber>; 118 + maxGraphemes: z.ZodOptional<z.ZodNumber>; 119 + enum: z.ZodOptional<z.ZodArray<z.ZodString>>; 120 + const: z.ZodOptional<z.ZodString>; 121 + knownValues: z.ZodOptional<z.ZodArray<z.ZodString>>; 122 + }, z.core.$strip>; 123 + export type LexString = z.infer<LexStringType>; 65 124 66 - export const lexUnknown = z.object({ 125 + export const lexUnknown: LexUnknownType = z.object({ 67 126 type: z.literal("unknown"), 68 127 description: z.string().optional(), 69 128 }); 70 - export type LexUnknown = z.infer<typeof lexUnknown>; 129 + type LexUnknownType = z.ZodObject<{ 130 + type: z.ZodLiteral<"unknown">; 131 + description: z.ZodOptional<z.ZodString>; 132 + }, z.core.$strip>; 133 + export type LexUnknown = z.infer<LexUnknownType>; 71 134 72 - export const lexPrimitive = z.discriminatedUnion("type", [ 135 + export const lexPrimitive: LexPrimitiveType = z.discriminatedUnion("type", [ 73 136 lexBoolean, 74 137 lexInteger, 75 138 lexString, 76 139 lexUnknown, 77 140 ]); 78 - export type LexPrimitive = z.infer<typeof lexPrimitive>; 141 + type LexPrimitiveType = z.ZodDiscriminatedUnion< 142 + [LexBooleanType, LexIntegerType, LexStringType, LexUnknownType], 143 + "type" 144 + >; 145 + export type LexPrimitive = z.infer<LexPrimitiveType>; 79 146 80 147 // ipld types 81 148 // = 82 149 83 - export const lexBytes = z.object({ 150 + export const lexBytes: LexBytesType = z.object({ 84 151 type: z.literal("bytes"), 85 152 description: z.string().optional(), 86 153 maxLength: z.number().optional(), 87 154 minLength: z.number().optional(), 88 155 }); 89 - export type LexBytes = z.infer<typeof lexBytes>; 156 + type LexBytesType = z.ZodObject<{ 157 + type: z.ZodLiteral<"bytes">; 158 + description: z.ZodOptional<z.ZodString>; 159 + maxLength: z.ZodOptional<z.ZodNumber>; 160 + minLength: z.ZodOptional<z.ZodNumber>; 161 + }, z.core.$strip>; 162 + export type LexBytes = z.infer<LexBytesType>; 90 163 91 - export const lexCidLink = z.object({ 164 + export const lexCidLink: LexCidLinkType = z.object({ 92 165 type: z.literal("cid-link"), 93 166 description: z.string().optional(), 94 167 }); 95 - export type LexCidLink = z.infer<typeof lexCidLink>; 168 + type LexCidLinkType = z.ZodObject<{ 169 + type: z.ZodLiteral<"cid-link">; 170 + description: z.ZodOptional<z.ZodString>; 171 + }, z.core.$strip>; 172 + export type LexCidLink = z.infer<LexCidLinkType>; 96 173 97 - export const lexIpldType = z.discriminatedUnion("type", [lexBytes, lexCidLink]); 98 - export type LexIpldType = z.infer<typeof lexIpldType>; 174 + export const lexIpldType: LexIpldTypeType = z.discriminatedUnion("type", [ 175 + lexBytes, 176 + lexCidLink, 177 + ]); 178 + type LexIpldTypeType = z.ZodDiscriminatedUnion< 179 + [LexBytesType, LexCidLinkType], 180 + "type" 181 + >; 182 + export type LexIpldType = z.infer<LexIpldTypeType>; 99 183 100 184 // references 101 185 // = 102 186 103 - export const lexRef = z.object({ 187 + export const lexRef: LexRefType = z.object({ 104 188 type: z.literal("ref"), 105 189 description: z.string().optional(), 106 190 ref: z.string(), 107 191 }); 108 - export type LexRef = z.infer<typeof lexRef>; 192 + type LexRefType = z.ZodObject<{ 193 + type: z.ZodLiteral<"ref">; 194 + description: z.ZodOptional<z.ZodString>; 195 + ref: z.ZodString; 196 + }, z.core.$strip>; 197 + export type LexRef = z.infer<LexRefType>; 109 198 110 - export const lexRefUnion = z.object({ 199 + export const lexRefUnion: LexRefUnionType = z.object({ 111 200 type: z.literal("union"), 112 201 description: z.string().optional(), 113 202 refs: z.string().array(), 114 203 closed: z.boolean().optional(), 115 204 }); 116 - export type LexRefUnion = z.infer<typeof lexRefUnion>; 205 + type LexRefUnionType = z.ZodObject<{ 206 + type: z.ZodLiteral<"union">; 207 + description: z.ZodOptional<z.ZodString>; 208 + refs: z.ZodArray<z.ZodString>; 209 + closed: z.ZodOptional<z.ZodBoolean>; 210 + }, z.core.$strip>; 211 + export type LexRefUnion = z.infer<LexRefUnionType>; 117 212 118 - export const lexRefVariant = z.discriminatedUnion("type", [ 213 + export const lexRefVariant: LexRefVariantType = z.discriminatedUnion("type", [ 119 214 lexRef, 120 215 lexRefUnion, 121 216 ]); 122 - export type LexRefVariant = z.infer<typeof lexRefVariant>; 217 + type LexRefVariantType = z.ZodDiscriminatedUnion< 218 + [LexRefType, LexRefUnionType], 219 + "type" 220 + >; 221 + export type LexRefVariant = z.infer<LexRefVariantType>; 123 222 124 223 // blobs 125 224 // = 126 225 127 - export const lexBlob = z.object({ 226 + export const lexBlob: LexBlobType = z.object({ 128 227 type: z.literal("blob"), 129 228 description: z.string().optional(), 130 229 accept: z.string().array().optional(), 131 230 maxSize: z.number().optional(), 132 231 }); 133 - export type LexBlob = z.infer<typeof lexBlob>; 232 + type LexBlobType = z.ZodObject<{ 233 + type: z.ZodLiteral<"blob">; 234 + description: z.ZodOptional<z.ZodString>; 235 + accept: z.ZodOptional<z.ZodArray<z.ZodString>>; 236 + maxSize: z.ZodOptional<z.ZodNumber>; 237 + }, z.core.$strip>; 238 + export type LexBlob = z.infer<LexBlobType>; 134 239 135 240 // complex types 136 241 // = 137 242 138 - export const lexArray = z.object({ 243 + export const lexArray: LexArrayType = z.object({ 139 244 type: z.literal("array"), 140 245 description: z.string().optional(), 141 246 items: z.discriminatedUnion("type", [ ··· 156 261 minLength: z.number().int().optional(), 157 262 maxLength: z.number().int().optional(), 158 263 }); 159 - export type LexArray = z.infer<typeof lexArray>; 264 + type LexArrayType = z.ZodObject<{ 265 + type: z.ZodLiteral<"array">; 266 + description: z.ZodOptional<z.ZodString>; 267 + items: z.ZodDiscriminatedUnion< 268 + [ 269 + LexBooleanType, 270 + LexIntegerType, 271 + LexStringType, 272 + LexUnknownType, 273 + LexBytesType, 274 + LexCidLinkType, 275 + LexRefType, 276 + LexRefUnionType, 277 + LexBlobType, 278 + ], 279 + "type" 280 + >; 281 + minLength: z.ZodOptional<z.ZodNumber>; 282 + maxLength: z.ZodOptional<z.ZodNumber>; 283 + }, z.core.$strip>; 284 + export type LexArray = z.infer<LexArrayType>; 160 285 161 - export const lexPrimitiveArray = z.object({ 286 + export const lexPrimitiveArray: LexPrimitiveArrayType = z.object({ 162 287 ...lexArray.shape, 163 288 items: lexPrimitive, 164 289 }); 165 - 166 - export type LexPrimitiveArray = z.infer<typeof lexPrimitiveArray>; 290 + type LexPrimitiveArrayType = z.ZodObject<{ 291 + items: LexPrimitiveType; 292 + type: z.ZodLiteral<"array">; 293 + description: z.ZodOptional<z.ZodString>; 294 + minLength: z.ZodOptional<z.ZodNumber>; 295 + maxLength: z.ZodOptional<z.ZodNumber>; 296 + }, z.core.$strip>; 297 + export type LexPrimitiveArray = z.infer<LexPrimitiveArrayType>; 167 298 168 - export const lexToken = z.object({ 299 + export const lexToken: LexTokenType = z.object({ 169 300 type: z.literal("token"), 170 301 description: z.string().optional(), 171 302 }); 172 - export type LexToken = z.infer<typeof lexToken>; 303 + type LexTokenType = z.ZodObject<{ 304 + type: z.ZodLiteral<"token">; 305 + description: z.ZodOptional<z.ZodString>; 306 + }, z.core.$strip>; 307 + export type LexToken = z.infer<LexTokenType>; 173 308 174 - export const lexObject = z 309 + export const lexObject: LexObjectType = z 175 310 .object({ 176 311 type: z.literal("object"), 177 312 description: z.string().optional(), ··· 199 334 ), 200 335 }) 201 336 .superRefine(requiredPropertiesRefinement); 202 - export type LexObject = z.infer<typeof lexObject>; 337 + type LexObjectType = z.ZodObject<{ 338 + type: z.ZodLiteral<"object">; 339 + description: z.ZodOptional<z.ZodString>; 340 + required: z.ZodOptional<z.ZodArray<z.ZodString>>; 341 + nullable: z.ZodOptional<z.ZodArray<z.ZodString>>; 342 + properties: z.ZodRecord< 343 + z.ZodString, 344 + z.ZodDiscriminatedUnion< 345 + [ 346 + LexArrayType, 347 + LexBooleanType, 348 + LexIntegerType, 349 + LexStringType, 350 + LexUnknownType, 351 + LexBytesType, 352 + LexCidLinkType, 353 + LexRefType, 354 + LexRefUnionType, 355 + LexBlobType, 356 + ], 357 + "type" 358 + > 359 + >; 360 + }, z.core.$strip>; 361 + export type LexObject = z.infer<LexObjectType>; 203 362 204 363 // permissions 205 364 // = 206 365 207 - const lexPermission = z.intersection( 366 + const lexPermission: LexPermissionType = z.intersection( 208 367 z.object({ 209 368 type: z.literal("permission"), 210 369 resource: z.string().min(1), ··· 222 381 .optional(), 223 382 ), 224 383 ); 384 + type LexPermissionType = z.ZodIntersection< 385 + z.ZodObject<{ 386 + type: z.ZodLiteral<"permission">; 387 + resource: z.ZodString; 388 + }, z.core.$strip>, 389 + z.ZodRecord< 390 + z.ZodString, 391 + z.ZodOptional< 392 + z.ZodUnion< 393 + readonly [ 394 + z.ZodArray< 395 + z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]> 396 + >, 397 + z.ZodBoolean, 398 + z.ZodNumber, 399 + z.ZodString, 400 + ] 401 + > 402 + > 403 + > 404 + >; 405 + export type LexPermission = z.infer<LexPermissionType>; 225 406 226 - export type LexPermission = z.infer<typeof lexPermission>; 227 - 228 - export const lexPermissionSet = z.object({ 407 + export const lexPermissionSet: LexPermissionSetType = z.object({ 229 408 type: z.literal("permission-set"), 230 409 description: z.string().optional(), 231 410 title: z.string().optional(), ··· 234 413 "detail:lang": lexLang.optional(), 235 414 permissions: z.array(lexPermission), 236 415 }); 237 - 238 - export type LexPermissionSet = z.infer<typeof lexPermissionSet>; 416 + type LexPermissionSetType = z.ZodObject<{ 417 + type: z.ZodLiteral<"permission-set">; 418 + description: z.ZodOptional<z.ZodString>; 419 + title: z.ZodOptional<z.ZodString>; 420 + "title:lang": z.ZodOptional<LexLangType>; 421 + detail: z.ZodOptional<z.ZodString>; 422 + "detail:lang": z.ZodOptional<LexLangType>; 423 + permissions: z.ZodArray<LexPermissionType>; 424 + }, z.core.$strip>; 425 + export type LexPermissionSet = z.infer<LexPermissionSetType>; 239 426 240 427 // xrpc 241 428 // = 242 429 243 - export const lexXrpcParameters = z 430 + export const lexXrpcParameters: LexXrpcParametersType = z 244 431 .object({ 245 432 type: z.literal("params"), 246 433 description: z.string().optional(), ··· 259 446 ), 260 447 }) 261 448 .superRefine(requiredPropertiesRefinement); 262 - export type LexXrpcParameters = z.infer<typeof lexXrpcParameters>; 449 + type LexXrpcParametersType = z.ZodObject<{ 450 + type: z.ZodLiteral<"params">; 451 + description: z.ZodOptional<z.ZodString>; 452 + required: z.ZodOptional<z.ZodArray<z.ZodString>>; 453 + properties: z.ZodRecord< 454 + z.ZodString, 455 + z.ZodDiscriminatedUnion< 456 + [ 457 + LexPrimitiveArrayType, 458 + LexBooleanType, 459 + LexIntegerType, 460 + LexStringType, 461 + LexUnknownType, 462 + ], 463 + "type" 464 + > 465 + >; 466 + }, z.core.$strip>; 467 + export type LexXrpcParameters = z.infer<LexXrpcParametersType>; 263 468 264 - export const lexXrpcBody = z.object({ 469 + export const lexXrpcBody: LexXrpcBodyType = z.object({ 265 470 description: z.string().optional(), 266 471 encoding: z.string(), 267 472 // @NOTE using discriminatedUnion with a refined schema requires zod >= 4 268 473 schema: z.union([lexRefVariant, lexObject]).optional(), 269 474 }); 270 - export type LexXrpcBody = z.infer<typeof lexXrpcBody>; 475 + type LexXrpcBodyType = z.ZodObject<{ 476 + description: z.ZodOptional<z.ZodString>; 477 + encoding: z.ZodString; 478 + schema: z.ZodOptional< 479 + z.ZodUnion<readonly [LexRefVariantType, LexObjectType]> 480 + >; 481 + }, z.core.$strip>; 482 + export type LexXrpcBody = z.infer<LexXrpcBodyType>; 271 483 272 - export const lexXrpcSubscriptionMessage = z.object({ 273 - description: z.string().optional(), 274 - // @NOTE using discriminatedUnion with a refined schema requires zod >= 4 275 - schema: z.union([lexRefVariant, lexObject]).optional(), 276 - }); 484 + export const lexXrpcSubscriptionMessage: LexXrpcSubscriptionMessageType = z 485 + .object({ 486 + description: z.string().optional(), 487 + // @NOTE using discriminatedUnion with a refined schema requires zod >= 4 488 + schema: z.union([lexRefVariant, lexObject]).optional(), 489 + }); 490 + type LexXrpcSubscriptionMessageType = z.ZodObject<{ 491 + description: z.ZodOptional<z.ZodString>; 492 + schema: z.ZodOptional< 493 + z.ZodUnion<readonly [LexRefVariantType, LexObjectType]> 494 + >; 495 + }, z.core.$strip>; 277 496 export type LexXrpcSubscriptionMessage = z.infer< 278 - typeof lexXrpcSubscriptionMessage 497 + LexXrpcSubscriptionMessageType 279 498 >; 280 499 281 - export const lexXrpcError = z.object({ 500 + export const lexXrpcError: LexXrpcErrorType = z.object({ 282 501 name: z.string(), 283 502 description: z.string().optional(), 284 503 }); 285 - export type LexXrpcError = z.infer<typeof lexXrpcError>; 504 + type LexXrpcErrorType = z.ZodObject<{ 505 + name: z.ZodString; 506 + description: z.ZodOptional<z.ZodString>; 507 + }, z.core.$strip>; 508 + export type LexXrpcError = z.infer<LexXrpcErrorType>; 286 509 287 - export const lexXrpcQuery = z.object({ 510 + export const lexXrpcQuery: LexXrpcQueryType = z.object({ 288 511 type: z.literal("query"), 289 512 description: z.string().optional(), 290 513 parameters: lexXrpcParameters.optional(), 291 514 output: lexXrpcBody.optional(), 292 515 errors: lexXrpcError.array().optional(), 293 516 }); 294 - export type LexXrpcQuery = z.infer<typeof lexXrpcQuery>; 517 + type LexXrpcQueryType = z.ZodObject<{ 518 + type: z.ZodLiteral<"query">; 519 + description: z.ZodOptional<z.ZodString>; 520 + parameters: z.ZodOptional<LexXrpcParametersType>; 521 + output: z.ZodOptional<LexXrpcBodyType>; 522 + errors: z.ZodOptional<z.ZodArray<LexXrpcErrorType>>; 523 + }, z.core.$strip>; 524 + export type LexXrpcQuery = z.infer<LexXrpcQueryType>; 295 525 296 - export const lexXrpcProcedure = z.object({ 526 + export const lexXrpcProcedure: LexXrpcProcedureType = z.object({ 297 527 type: z.literal("procedure"), 298 528 description: z.string().optional(), 299 529 parameters: lexXrpcParameters.optional(), ··· 301 531 output: lexXrpcBody.optional(), 302 532 errors: lexXrpcError.array().optional(), 303 533 }); 304 - export type LexXrpcProcedure = z.infer<typeof lexXrpcProcedure>; 534 + type LexXrpcProcedureType = z.ZodObject<{ 535 + type: z.ZodLiteral<"procedure">; 536 + description: z.ZodOptional<z.ZodString>; 537 + parameters: z.ZodOptional<LexXrpcParametersType>; 538 + input: z.ZodOptional<LexXrpcBodyType>; 539 + output: z.ZodOptional<LexXrpcBodyType>; 540 + errors: z.ZodOptional<z.ZodArray<LexXrpcErrorType>>; 541 + }, z.core.$strip>; 542 + export type LexXrpcProcedure = z.infer<LexXrpcProcedureType>; 305 543 306 - export const lexXrpcSubscription = z.object({ 544 + export const lexXrpcSubscription: LexXrpcSubscriptionType = z.object({ 307 545 type: z.literal("subscription"), 308 546 description: z.string().optional(), 309 547 parameters: lexXrpcParameters.optional(), 310 548 message: lexXrpcSubscriptionMessage.optional(), 311 549 errors: lexXrpcError.array().optional(), 312 550 }); 313 - export type LexXrpcSubscription = z.infer<typeof lexXrpcSubscription>; 551 + type LexXrpcSubscriptionType = z.ZodObject<{ 552 + type: z.ZodLiteral<"subscription">; 553 + description: z.ZodOptional<z.ZodString>; 554 + parameters: z.ZodOptional<LexXrpcParametersType>; 555 + message: z.ZodOptional<LexXrpcSubscriptionMessageType>; 556 + errors: z.ZodOptional<z.ZodArray<LexXrpcErrorType>>; 557 + }, z.core.$strip>; 558 + export type LexXrpcSubscription = z.infer<LexXrpcSubscriptionType>; 314 559 315 560 // database 316 561 // = 317 562 318 - export const lexRecord = z.object({ 563 + export const lexRecord: LexRecordType = z.object({ 319 564 type: z.literal("record"), 320 565 description: z.string().optional(), 321 566 key: z.string().optional(), 322 567 record: lexObject, 323 568 }); 324 - export type LexRecord = z.infer<typeof lexRecord>; 569 + type LexRecordType = z.ZodObject<{ 570 + type: z.ZodLiteral<"record">; 571 + description: z.ZodOptional<z.ZodString>; 572 + key: z.ZodOptional<z.ZodString>; 573 + record: LexObjectType; 574 + }, z.core.$strip>; 575 + export type LexRecord = z.infer<LexRecordType>; 325 576 326 577 // core 327 578 // = ··· 330 581 // lexXrpcProperty and lexObject are refined 331 582 // `z.union` would work, but it's too slow 332 583 // see #915 for details 333 - export const lexUserType = z.custom< 584 + export const lexUserType: LexUserTypeType = z.custom< 334 585 | LexRecord 335 586 | LexPermissionSet 336 587 | LexXrpcQuery ··· 438 689 }, 439 690 }, 440 691 ); 441 - export type LexUserType = z.infer<typeof lexUserType>; 692 + type LexUserTypeType = z.ZodCustom< 693 + | LexRecord 694 + | LexPermissionSet 695 + | LexXrpcQuery 696 + | LexXrpcProcedure 697 + | LexXrpcSubscription 698 + | LexBlob 699 + | LexArray 700 + | LexToken 701 + | LexObject 702 + | LexBoolean 703 + | LexInteger 704 + | LexString 705 + | LexBytes 706 + | LexCidLink 707 + | LexUnknown 708 + >; 709 + export type LexUserType = z.infer<LexUserTypeType>; 442 710 443 - export const lexiconDoc = z 711 + export const lexiconDoc: LexiconDocType = z 444 712 .object({ 445 713 lexicon: z.literal(1), 446 714 id: z.string().refine(isValidNsid, { ··· 471 739 `Records, permission sets, procedures, queries, and subscriptions must be the main definition.`, 472 740 }, 473 741 ); 474 - export type LexiconDoc = z.infer<typeof lexiconDoc>; 742 + type LexiconDocType = z.ZodObject<{ 743 + lexicon: z.ZodLiteral<1>; 744 + id: z.ZodString; 745 + revision: z.ZodOptional<z.ZodNumber>; 746 + description: z.ZodOptional<z.ZodString>; 747 + defs: z.ZodRecord<z.ZodString, LexUserTypeType>; 748 + }, z.core.$strip>; 749 + export type LexiconDoc = z.infer<LexiconDocType>; 475 750 476 751 // helpers 477 752 // =