@bigmistqke/lexicon-to-valibot 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +53 -49
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
export { InferOutput } from 'valibot';
|
|
3
|
+
import { BlobRef } from '@atproto/lexicon';
|
|
3
4
|
export { LexUserType, LexiconDoc } from '@atproto/lexicon';
|
|
4
5
|
|
|
5
6
|
interface QueryValidators {
|
|
@@ -19,7 +20,8 @@ interface SubscriptionValidators {
|
|
|
19
20
|
type Prettify<T> = {
|
|
20
21
|
[K in keyof T]: T[K];
|
|
21
22
|
} & {};
|
|
22
|
-
type
|
|
23
|
+
type BlobFormat = 'sdk' | 'wire';
|
|
24
|
+
type WireBlobRef = {
|
|
23
25
|
$type: "blob";
|
|
24
26
|
ref: {
|
|
25
27
|
$link: string;
|
|
@@ -31,12 +33,14 @@ type UntypedBlobRef = {
|
|
|
31
33
|
cid: string;
|
|
32
34
|
mimeType: string;
|
|
33
35
|
};
|
|
34
|
-
type
|
|
36
|
+
type SdkBlobRef = BlobRef | UntypedBlobRef;
|
|
37
|
+
type WireBlobRefUnion = WireBlobRef | UntypedBlobRef;
|
|
38
|
+
type InferBlobRef<Format extends BlobFormat> = Format extends 'sdk' ? SdkBlobRef : WireBlobRefUnion;
|
|
35
39
|
type CidLink = {
|
|
36
40
|
$link: string;
|
|
37
41
|
};
|
|
38
42
|
type ExternalRefsMap = Record<string, unknown>;
|
|
39
|
-
type InferLexType<T, Defs = {}, ExtRefs extends ExternalRefsMap = {}> = T extends {
|
|
43
|
+
type InferLexType<T, Defs = {}, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = T extends {
|
|
40
44
|
type: "boolean";
|
|
41
45
|
} ? T extends {
|
|
42
46
|
const: infer C extends boolean;
|
|
@@ -58,34 +62,34 @@ type InferLexType<T, Defs = {}, ExtRefs extends ExternalRefsMap = {}> = T extend
|
|
|
58
62
|
type: "bytes";
|
|
59
63
|
} ? Uint8Array : T extends {
|
|
60
64
|
type: "blob";
|
|
61
|
-
} ?
|
|
65
|
+
} ? InferBlobRef<Format> : T extends {
|
|
62
66
|
type: "cid-link";
|
|
63
67
|
} ? CidLink : T extends {
|
|
64
68
|
type: "token";
|
|
65
69
|
} ? string : T extends {
|
|
66
70
|
type: "array";
|
|
67
71
|
items: infer Items;
|
|
68
|
-
} ? InferLexType<Items, Defs, ExtRefs>[] : T extends {
|
|
72
|
+
} ? InferLexType<Items, Defs, ExtRefs, Format>[] : T extends {
|
|
69
73
|
type: "object";
|
|
70
74
|
properties?: infer Props;
|
|
71
|
-
} ? InferLexObject<Props, T, Defs, ExtRefs> : T extends {
|
|
75
|
+
} ? InferLexObject<Props, T, Defs, ExtRefs, Format> : T extends {
|
|
72
76
|
type: "ref";
|
|
73
77
|
ref: infer R extends string;
|
|
74
|
-
} ? InferLexRef<R, Defs, ExtRefs> : T extends {
|
|
78
|
+
} ? InferLexRef<R, Defs, ExtRefs, Format> : T extends {
|
|
75
79
|
type: "union";
|
|
76
80
|
refs: infer Refs extends readonly string[];
|
|
77
|
-
} ? InferLexUnion<Refs, Defs, ExtRefs> : T extends {
|
|
81
|
+
} ? InferLexUnion<Refs, Defs, ExtRefs, Format> : T extends {
|
|
78
82
|
type: "record";
|
|
79
83
|
record: infer Rec;
|
|
80
|
-
} ? InferLexType<Rec, Defs, ExtRefs> : unknown;
|
|
81
|
-
type InferLexObject<Props, Schema, Defs, ExtRefs extends ExternalRefsMap = {}> = Props extends Record<string, unknown> ? Prettify<{
|
|
82
|
-
[K in keyof Props as K extends RequiredKeys<Schema> ? K extends NullableKeys<Schema> ? never : K : never]: InferLexType<Props[K], Defs, ExtRefs>;
|
|
84
|
+
} ? InferLexType<Rec, Defs, ExtRefs, Format> : unknown;
|
|
85
|
+
type InferLexObject<Props, Schema, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = Props extends Record<string, unknown> ? Prettify<{
|
|
86
|
+
[K in keyof Props as K extends RequiredKeys<Schema> ? K extends NullableKeys<Schema> ? never : K : never]: InferLexType<Props[K], Defs, ExtRefs, Format>;
|
|
83
87
|
} & {
|
|
84
|
-
[K in keyof Props as K extends RequiredKeys<Schema> ? K extends NullableKeys<Schema> ? K : never : never]: InferLexType<Props[K], Defs, ExtRefs> | null;
|
|
88
|
+
[K in keyof Props as K extends RequiredKeys<Schema> ? K extends NullableKeys<Schema> ? K : never : never]: InferLexType<Props[K], Defs, ExtRefs, Format> | null;
|
|
85
89
|
} & {
|
|
86
|
-
[K in keyof Props as K extends RequiredKeys<Schema> ? never : K extends NullableKeys<Schema> ? never : K]?: InferLexType<Props[K], Defs, ExtRefs>;
|
|
90
|
+
[K in keyof Props as K extends RequiredKeys<Schema> ? never : K extends NullableKeys<Schema> ? never : K]?: InferLexType<Props[K], Defs, ExtRefs, Format>;
|
|
87
91
|
} & {
|
|
88
|
-
[K in keyof Props as K extends RequiredKeys<Schema> ? never : K extends NullableKeys<Schema> ? K : never]?: InferLexType<Props[K], Defs, ExtRefs> | null;
|
|
92
|
+
[K in keyof Props as K extends RequiredKeys<Schema> ? never : K extends NullableKeys<Schema> ? K : never]?: InferLexType<Props[K], Defs, ExtRefs, Format> | null;
|
|
89
93
|
}> : {};
|
|
90
94
|
type RequiredKeys<T> = T extends {
|
|
91
95
|
required: infer R extends readonly string[];
|
|
@@ -93,80 +97,80 @@ type RequiredKeys<T> = T extends {
|
|
|
93
97
|
type NullableKeys<T> = T extends {
|
|
94
98
|
nullable: infer N extends readonly string[];
|
|
95
99
|
} ? N[number] : never;
|
|
96
|
-
type InferLexRef<R extends string, Defs, ExtRefs extends ExternalRefsMap = {}> = R extends `#${infer DefName}` ? DefName extends keyof Defs ? InferLexType<Defs[DefName], Defs, ExtRefs> : unknown : R extends keyof ExtRefs ? ExtRefs[R] : `${R}#main` extends keyof ExtRefs ? ExtRefs[`${R}#main`] : unknown;
|
|
97
|
-
type InferLexUnion<Refs extends readonly string[], Defs, ExtRefs extends ExternalRefsMap = {}> = Refs extends readonly [
|
|
100
|
+
type InferLexRef<R extends string, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = R extends `#${infer DefName}` ? DefName extends keyof Defs ? InferLexType<Defs[DefName], Defs, ExtRefs, Format> : unknown : R extends keyof ExtRefs ? ExtRefs[R] : `${R}#main` extends keyof ExtRefs ? ExtRefs[`${R}#main`] : unknown;
|
|
101
|
+
type InferLexUnion<Refs extends readonly string[], Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = Refs extends readonly [
|
|
98
102
|
infer First extends string,
|
|
99
103
|
...infer Rest extends readonly string[]
|
|
100
|
-
] ? InferLexRef<First, Defs, ExtRefs> | InferLexUnion<Rest, Defs, ExtRefs> : never;
|
|
101
|
-
type InferLexParams<T, Defs, ExtRefs extends ExternalRefsMap = {}> = T extends {
|
|
104
|
+
] ? InferLexRef<First, Defs, ExtRefs, Format> | InferLexUnion<Rest, Defs, ExtRefs, Format> : never;
|
|
105
|
+
type InferLexParams<T, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = T extends {
|
|
102
106
|
type: "params";
|
|
103
107
|
properties?: infer Props;
|
|
104
108
|
required?: infer R extends readonly string[];
|
|
105
109
|
} ? Props extends Record<string, unknown> ? Prettify<{
|
|
106
|
-
[K in keyof Props as K extends R[number] ? K : never]: InferLexType<Props[K], Defs, ExtRefs>;
|
|
110
|
+
[K in keyof Props as K extends R[number] ? K : never]: InferLexType<Props[K], Defs, ExtRefs, Format>;
|
|
107
111
|
} & {
|
|
108
|
-
[K in keyof Props as K extends R[number] ? never : K]?: InferLexType<Props[K], Defs, ExtRefs>;
|
|
112
|
+
[K in keyof Props as K extends R[number] ? never : K]?: InferLexType<Props[K], Defs, ExtRefs, Format>;
|
|
109
113
|
}> : {} : {};
|
|
110
|
-
type InferLexBody<T, Defs, ExtRefs extends ExternalRefsMap = {}> = T extends {
|
|
114
|
+
type InferLexBody<T, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = T extends {
|
|
111
115
|
schema: infer S;
|
|
112
|
-
} ? InferLexType<S, Defs, ExtRefs> : unknown;
|
|
113
|
-
type InferQueryValidators<T, Defs, ExtRefs extends ExternalRefsMap = {}> = T extends {
|
|
116
|
+
} ? InferLexType<S, Defs, ExtRefs, Format> : unknown;
|
|
117
|
+
type InferQueryValidators<T, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = T extends {
|
|
114
118
|
type: "query";
|
|
115
119
|
} ? {
|
|
116
120
|
parameters: v.GenericSchema<InferLexParams<T extends {
|
|
117
121
|
parameters: infer P;
|
|
118
|
-
} ? P : never, Defs, ExtRefs>>;
|
|
122
|
+
} ? P : never, Defs, ExtRefs, Format>>;
|
|
119
123
|
output: v.GenericSchema<InferLexBody<T extends {
|
|
120
124
|
output: infer O;
|
|
121
|
-
} ? O : never, Defs, ExtRefs>>;
|
|
125
|
+
} ? O : never, Defs, ExtRefs, Format>>;
|
|
122
126
|
} : never;
|
|
123
|
-
type InferProcedureValidators<T, Defs, ExtRefs extends ExternalRefsMap = {}> = T extends {
|
|
127
|
+
type InferProcedureValidators<T, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = T extends {
|
|
124
128
|
type: "procedure";
|
|
125
129
|
} ? {
|
|
126
130
|
parameters: v.GenericSchema<InferLexParams<T extends {
|
|
127
131
|
parameters: infer P;
|
|
128
|
-
} ? P : never, Defs, ExtRefs>>;
|
|
132
|
+
} ? P : never, Defs, ExtRefs, Format>>;
|
|
129
133
|
input: v.GenericSchema<InferLexBody<T extends {
|
|
130
134
|
input: infer I;
|
|
131
|
-
} ? I : never, Defs, ExtRefs>>;
|
|
135
|
+
} ? I : never, Defs, ExtRefs, Format>>;
|
|
132
136
|
output: v.GenericSchema<InferLexBody<T extends {
|
|
133
137
|
output: infer O;
|
|
134
|
-
} ? O : never, Defs, ExtRefs>>;
|
|
138
|
+
} ? O : never, Defs, ExtRefs, Format>>;
|
|
135
139
|
} : never;
|
|
136
|
-
type InferSubscriptionValidators<T, Defs, ExtRefs extends ExternalRefsMap = {}> = T extends {
|
|
140
|
+
type InferSubscriptionValidators<T, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = T extends {
|
|
137
141
|
type: "subscription";
|
|
138
142
|
} ? {
|
|
139
143
|
parameters: v.GenericSchema<InferLexParams<T extends {
|
|
140
144
|
parameters: infer P;
|
|
141
|
-
} ? P : never, Defs, ExtRefs>>;
|
|
145
|
+
} ? P : never, Defs, ExtRefs, Format>>;
|
|
142
146
|
message: v.GenericSchema<InferLexBody<T extends {
|
|
143
147
|
message: infer M;
|
|
144
|
-
} ? M : never, Defs, ExtRefs>>;
|
|
148
|
+
} ? M : never, Defs, ExtRefs, Format>>;
|
|
145
149
|
} : never;
|
|
146
150
|
type IsXrpcType<T> = T extends {
|
|
147
151
|
type: "query" | "procedure" | "subscription";
|
|
148
152
|
} ? true : false;
|
|
149
|
-
type InferSchemaValidator<T, Defs, ExtRefs extends ExternalRefsMap = {}> = v.GenericSchema<InferLexType<T, Defs, ExtRefs>>;
|
|
150
|
-
type InferXrpcValidator<T, Defs, ExtRefs extends ExternalRefsMap = {}> = T extends {
|
|
153
|
+
type InferSchemaValidator<T, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = v.GenericSchema<InferLexType<T, Defs, ExtRefs, Format>>;
|
|
154
|
+
type InferXrpcValidator<T, Defs, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = T extends {
|
|
151
155
|
type: "query";
|
|
152
|
-
} ? InferQueryValidators<T, Defs, ExtRefs> : T extends {
|
|
156
|
+
} ? InferQueryValidators<T, Defs, ExtRefs, Format> : T extends {
|
|
153
157
|
type: "procedure";
|
|
154
|
-
} ? InferProcedureValidators<T, Defs, ExtRefs> : T extends {
|
|
158
|
+
} ? InferProcedureValidators<T, Defs, ExtRefs, Format> : T extends {
|
|
155
159
|
type: "subscription";
|
|
156
|
-
} ? InferSubscriptionValidators<T, Defs, ExtRefs> : never;
|
|
160
|
+
} ? InferSubscriptionValidators<T, Defs, ExtRefs, Format> : never;
|
|
157
161
|
type InferLexiconValidators<T extends {
|
|
158
162
|
defs: Record<string, unknown>;
|
|
159
|
-
}, ExtRefs extends ExternalRefsMap = {}> = {
|
|
160
|
-
[K in keyof T["defs"] as IsXrpcType<T["defs"][K]> extends true ? never : K]: InferSchemaValidator<T["defs"][K], T["defs"], ExtRefs>;
|
|
163
|
+
}, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = {
|
|
164
|
+
[K in keyof T["defs"] as IsXrpcType<T["defs"][K]> extends true ? never : K]: InferSchemaValidator<T["defs"][K], T["defs"], ExtRefs, Format>;
|
|
161
165
|
};
|
|
162
166
|
type InferXrpcValidators<T extends {
|
|
163
167
|
defs: Record<string, unknown>;
|
|
164
|
-
}, ExtRefs extends ExternalRefsMap = {}> = {
|
|
165
|
-
[K in keyof T["defs"] as IsXrpcType<T["defs"][K]> extends true ? K : never]: InferXrpcValidator<T["defs"][K], T["defs"], ExtRefs>;
|
|
168
|
+
}, ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = {
|
|
169
|
+
[K in keyof T["defs"] as IsXrpcType<T["defs"][K]> extends true ? K : never]: InferXrpcValidator<T["defs"][K], T["defs"], ExtRefs, Format>;
|
|
166
170
|
};
|
|
167
171
|
type InferLexiconOutput<T extends {
|
|
168
172
|
defs: Record<string, unknown>;
|
|
169
|
-
}, K extends keyof T["defs"], ExtRefs extends ExternalRefsMap = {}> = InferLexType<T["defs"][K], T["defs"], ExtRefs>;
|
|
173
|
+
}, K extends keyof T["defs"], ExtRefs extends ExternalRefsMap = {}, Format extends BlobFormat = 'sdk'> = InferLexType<T["defs"][K], T["defs"], ExtRefs, Format>;
|
|
170
174
|
|
|
171
175
|
declare const atprotoRefs: {
|
|
172
176
|
readonly "com.atproto.repo.strongRef": v.ObjectSchema<{
|
|
@@ -209,17 +213,17 @@ type InferSchemaOutputs<T extends Record<string, v.GenericSchema>> = {
|
|
|
209
213
|
* Convert a lexicon to valibot schemas for records and objects.
|
|
210
214
|
* Skips XRPC types (query, procedure, subscription) - use xrpcToValibot for those.
|
|
211
215
|
*/
|
|
212
|
-
declare function lexiconToValibot<T extends LexiconInput, ExtRefs extends Record<string, v.GenericSchema> = {}>(lexicon: T, options?: {
|
|
216
|
+
declare function lexiconToValibot<T extends LexiconInput, ExtRefs extends Record<string, v.GenericSchema> = {}, Format extends BlobFormat = 'sdk'>(lexicon: T, options?: {
|
|
213
217
|
externalRefs?: ExtRefs;
|
|
214
|
-
format?:
|
|
215
|
-
}): InferLexiconValidators<T, InferSchemaOutputs<ExtRefs
|
|
218
|
+
format?: Format;
|
|
219
|
+
}): InferLexiconValidators<T, InferSchemaOutputs<ExtRefs>, Format>;
|
|
216
220
|
/**
|
|
217
221
|
* Convert a lexicon to valibot validators for XRPC endpoints.
|
|
218
222
|
* Only handles query, procedure, and subscription types.
|
|
219
223
|
*/
|
|
220
|
-
declare function xrpcToValibot<T extends LexiconInput, ExtRefs extends Record<string, v.GenericSchema> = {}>(lexicon: T, options?: {
|
|
224
|
+
declare function xrpcToValibot<T extends LexiconInput, ExtRefs extends Record<string, v.GenericSchema> = {}, Format extends BlobFormat = 'sdk'>(lexicon: T, options?: {
|
|
221
225
|
externalRefs?: ExtRefs;
|
|
222
|
-
format?:
|
|
223
|
-
}): InferXrpcValidators<T, InferSchemaOutputs<ExtRefs
|
|
226
|
+
format?: Format;
|
|
227
|
+
}): InferXrpcValidators<T, InferSchemaOutputs<ExtRefs>, Format>;
|
|
224
228
|
|
|
225
|
-
export { type AtprotoRefs, type InferLexType, type InferLexiconOutput, type InferLexiconValidators, type LexiconInput, type LexiconToValibotOptions, type ProcedureValidators, type QueryValidators, type SubscriptionValidators, atprotoRefs, lexiconToValibot, xrpcToValibot };
|
|
229
|
+
export { type AtprotoRefs, type BlobFormat, type InferLexType, type InferLexiconOutput, type InferLexiconValidators, type LexiconInput, type LexiconToValibotOptions, type ProcedureValidators, type QueryValidators, type SubscriptionValidators, atprotoRefs, lexiconToValibot, xrpcToValibot };
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ function isWireBlobRef(value) {
|
|
|
11
11
|
function isSdkBlobRef(value) {
|
|
12
12
|
if (typeof value !== "object" || value === null) return false;
|
|
13
13
|
const obj = value;
|
|
14
|
-
return typeof obj.ref === "object" && obj.ref !== null && typeof obj.mimeType === "string" && typeof obj.size === "number";
|
|
14
|
+
return typeof obj.ref === "object" && obj.ref !== null && typeof obj.ref.toString === "function" && typeof obj.mimeType === "string" && typeof obj.size === "number" && typeof obj.original === "object";
|
|
15
15
|
}
|
|
16
16
|
function isUntypedBlobRef(value) {
|
|
17
17
|
if (typeof value !== "object" || value === null) return false;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/converters/atproto.ts","../src/converters/complex.ts","../src/converters/primitives.ts","../src/converters/xrpc.ts","../src/atproto-refs.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { convertBlob, convertCidLink, convertToken } from \"./converters/atproto.js\";\nimport { convertArray, convertObject, convertRef, convertUnion } from \"./converters/complex.js\";\nimport {\n convertBoolean,\n convertBytes,\n convertInteger,\n convertString,\n convertUnknown,\n} from \"./converters/primitives.js\";\nimport {\n convertProcedure,\n convertQuery,\n convertSubscription,\n type ProcedureValidators,\n type QueryValidators,\n type SubscriptionValidators,\n} from \"./converters/xrpc.js\";\nimport type {\n ConverterContext,\n LexArray,\n LexBlob,\n LexBoolean,\n LexBytes,\n LexCidLink,\n LexInteger,\n LexObject,\n LexRecord,\n LexRef,\n LexRefUnion,\n LexString,\n LexToken,\n LexUnknown,\n LexUserType,\n LexXrpcProcedure,\n LexXrpcQuery,\n LexXrpcSubscription\n} from \"./types.js\";\n\n// Flexible input type that accepts both LexiconDoc and const objects\nexport interface LexiconInput {\n lexicon: 1;\n id: string;\n defs: Record<string, unknown>;\n description?: string;\n revision?: number;\n}\n\n// Options for lexiconToValibot\nexport interface LexiconToValibotOptions {\n /** External ref schemas (e.g., com.atproto.repo.strongRef) */\n externalRefs?: Record<string, v.GenericSchema>;\n /** Format for blob validation: 'sdk' for parsing fetched records, 'wire' for outgoing. Default: 'sdk' */\n format?: 'sdk' | 'wire';\n}\n\nexport type { ProcedureValidators, QueryValidators, SubscriptionValidators };\n\ntype XrpcResult = QueryValidators | ProcedureValidators | SubscriptionValidators;\n\nfunction convertType(schema: unknown, ctx: ConverterContext): v.GenericSchema {\n if (typeof schema !== \"object\" || schema === null) {\n throw new Error(`Invalid schema: expected object, got ${typeof schema}`);\n }\n\n const schemaObj = schema as { type?: string };\n\n switch (schemaObj.type) {\n // Primitives\n case \"boolean\":\n return convertBoolean(schema as LexBoolean);\n case \"integer\":\n return convertInteger(schema as LexInteger);\n case \"string\":\n return convertString(schema as LexString);\n case \"unknown\":\n return convertUnknown(schema as LexUnknown);\n\n // IPLD types\n case \"bytes\":\n return convertBytes(schema as LexBytes);\n case \"cid-link\":\n return convertCidLink(schema as LexCidLink);\n\n // AT Protocol types\n case \"blob\":\n return convertBlob(schema as LexBlob, ctx.blobFormat);\n case \"token\":\n return convertToken(schema as LexToken);\n\n // Complex types\n case \"array\":\n return convertArray(schema as LexArray, ctx, convertType);\n case \"object\":\n return convertObject(schema as LexObject, ctx, convertType);\n case \"ref\":\n return convertRef(schema as LexRef, ctx);\n case \"union\":\n return convertUnion(schema as LexRefUnion, ctx);\n\n // Record type\n case \"record\":\n return convertObject((schema as LexRecord).record, ctx, convertType);\n\n default:\n throw new Error(`Unknown schema type: ${schemaObj.type}`);\n }\n}\n\n// Convert XRPC def - returns validators object\nfunction convertXrpcDef(schema: unknown, ctx: ConverterContext): XrpcResult {\n if (typeof schema !== \"object\" || schema === null) {\n throw new Error(`Invalid schema: expected object, got ${typeof schema}`);\n }\n\n const schemaObj = schema as { type?: string };\n\n switch (schemaObj.type) {\n case \"query\":\n return convertQuery(schema as LexXrpcQuery, ctx, convertType);\n case \"procedure\":\n return convertProcedure(schema as LexXrpcProcedure, ctx, convertType);\n case \"subscription\":\n return convertSubscription(schema as LexXrpcSubscription, ctx, convertType);\n default:\n throw new Error(`Not an XRPC type: ${schemaObj.type}`);\n }\n}\n\n// Check if a def is an XRPC type\nfunction isXrpcDef(schema: unknown): boolean {\n if (typeof schema !== \"object\" || schema === null) return false;\n const type = (schema as { type?: string }).type;\n return type === \"query\" || type === \"procedure\" || type === \"subscription\";\n}\n\n// Check if a def is a record type\nfunction isRecordDef(schema: unknown): boolean {\n if (typeof schema !== \"object\" || schema === null) return false;\n return (schema as { type?: string }).type === \"record\";\n}\n\nfunction createRefResolver(\n lexiconId: string,\n defs: Record<string, LexUserType>,\n cache: Map<string, v.GenericSchema>,\n externalRefs: Record<string, v.GenericSchema> = {},\n blobFormat: 'sdk' | 'wire' = 'sdk'\n): (ref: string) => v.GenericSchema {\n return (ref: string) => {\n // Parse the ref - could be:\n // - \"#defName\" (local ref)\n // - \"com.example.lexicon#defName\" (external ref)\n // - \"com.example.lexicon\" (main def of external lexicon)\n\n let resolvedRef = ref;\n\n if (ref.startsWith(\"#\")) {\n // Local ref\n resolvedRef = `${lexiconId}${ref}`;\n } else if (!ref.includes(\"#\")) {\n // External ref to main def\n resolvedRef = `${ref}#main`;\n }\n\n // Check cache first\n if (cache.has(resolvedRef)) {\n return cache.get(resolvedRef)!;\n }\n\n // Check external refs (try both original and resolved)\n if (externalRefs[ref]) {\n cache.set(resolvedRef, externalRefs[ref]);\n return externalRefs[ref];\n }\n if (externalRefs[resolvedRef]) {\n cache.set(resolvedRef, externalRefs[resolvedRef]);\n return externalRefs[resolvedRef];\n }\n\n // Parse the full ref\n const [nsid, defName] = resolvedRef.includes(\"#\")\n ? resolvedRef.split(\"#\")\n : [resolvedRef, \"main\"];\n\n // Only handle local refs\n if (nsid !== lexiconId) {\n // External ref not found in externalRefs\n console.warn(`External ref not resolved: ${ref} - provide it in externalRefs option`);\n return v.unknown();\n }\n\n const def = defs[defName];\n if (!def) {\n throw new Error(`Ref not found: ${ref} (resolved to ${resolvedRef})`);\n }\n\n // Create context for conversion\n const ctx: ConverterContext = {\n lexiconId,\n defs,\n resolveRef: createRefResolver(lexiconId, defs, cache, externalRefs, blobFormat),\n blobFormat,\n };\n\n // Convert and cache\n const schema = convertType(def, ctx);\n cache.set(resolvedRef, schema);\n return schema;\n };\n}\n\nimport type { InferLexiconValidators, InferXrpcValidators } from \"./infer.js\";\n\n// Helper type to convert schema map to output type map\ntype InferSchemaOutputs<T extends Record<string, v.GenericSchema>> = {\n [K in keyof T]: v.InferOutput<T[K]>;\n};\n\n/**\n * Convert a lexicon to valibot schemas for records and objects.\n * Skips XRPC types (query, procedure, subscription) - use xrpcToValibot for those.\n */\nexport function lexiconToValibot<\n T extends LexiconInput,\n ExtRefs extends Record<string, v.GenericSchema> = {}\n>(\n lexicon: T,\n options: { externalRefs?: ExtRefs; format?: 'sdk' | 'wire' } = {}\n): InferLexiconValidators<T, InferSchemaOutputs<ExtRefs>> {\n const blobFormat = options.format ?? 'sdk';\n const cache = new Map<string, v.GenericSchema>();\n const resolveRef = createRefResolver(\n lexicon.id,\n lexicon.defs as Record<string, LexUserType>,\n cache,\n options.externalRefs ?? {},\n blobFormat\n );\n\n const ctx: ConverterContext = {\n lexiconId: lexicon.id,\n defs: lexicon.defs,\n resolveRef,\n blobFormat,\n };\n\n const result: Record<string, v.GenericSchema> = {};\n\n for (const [defName, def] of Object.entries(lexicon.defs)) {\n // Skip XRPC types\n if (isXrpcDef(def)) continue;\n\n let schema = convertType(def, ctx);\n\n // For wire format, wrap record types with $type\n if (blobFormat === 'wire' && isRecordDef(def)) {\n const $type = defName === 'main' ? lexicon.id : `${lexicon.id}#${defName}`;\n schema = v.object({\n $type: v.literal($type),\n ...('entries' in schema ? (schema as v.ObjectSchema<v.ObjectEntries, undefined>).entries : {}),\n });\n }\n\n result[defName] = schema;\n }\n\n return result as InferLexiconValidators<T, InferSchemaOutputs<ExtRefs>>;\n}\n\n/**\n * Convert a lexicon to valibot validators for XRPC endpoints.\n * Only handles query, procedure, and subscription types.\n */\nexport function xrpcToValibot<\n T extends LexiconInput,\n ExtRefs extends Record<string, v.GenericSchema> = {}\n>(\n lexicon: T,\n options: { externalRefs?: ExtRefs; format?: 'sdk' | 'wire' } = {}\n): InferXrpcValidators<T, InferSchemaOutputs<ExtRefs>> {\n const blobFormat = options.format ?? 'sdk';\n const cache = new Map<string, v.GenericSchema>();\n const resolveRef = createRefResolver(\n lexicon.id,\n lexicon.defs as Record<string, LexUserType>,\n cache,\n options.externalRefs ?? {},\n blobFormat\n );\n\n const ctx: ConverterContext = {\n lexiconId: lexicon.id,\n defs: lexicon.defs,\n resolveRef,\n blobFormat,\n };\n\n const result: Record<string, XrpcResult> = {};\n\n for (const [defName, def] of Object.entries(lexicon.defs)) {\n // Only handle XRPC types\n if (!isXrpcDef(def)) continue;\n result[defName] = convertXrpcDef(def, ctx);\n }\n\n return result as InferXrpcValidators<T, InferSchemaOutputs<ExtRefs>>;\n}\n\n// Re-export valibot's InferOutput for convenience\nexport type { InferOutput } from \"valibot\";\n// Re-export built-in AT Protocol refs\nexport { atprotoRefs, type AtprotoRefs } from \"./atproto-refs.js\";\n\n// Re-export inference types\nexport type { InferLexiconOutput, InferLexiconValidators, InferLexType } from \"./infer.js\";\n// Re-export types\nexport type { LexiconDoc, LexUserType } from \"./types.js\";\n","import * as v from \"valibot\";\nimport type { BlobFormat, LexBlob, LexCidLink, LexToken } from \"../types.js\";\n\n// Blob reference types for AT Protocol\n\n// Wire format: what gets sent to/from PDS\ntype WireBlobRef = {\n $type: \"blob\";\n ref: { $link: string };\n mimeType: string;\n size: number;\n};\n\n// SDK format: what the SDK deserializes to (class instances)\ntype SdkBlobRef = {\n ref: object; // _CID instance\n mimeType: string;\n size: number;\n};\n\n// Untyped/legacy format\ntype UntypedBlobRef = {\n cid: string;\n mimeType: string;\n};\n\ntype BlobRef = WireBlobRef | SdkBlobRef | UntypedBlobRef;\n\n// Check for wire format: { $type: \"blob\", ref: { $link: string }, ... }\nfunction isWireBlobRef(value: unknown): value is WireBlobRef {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return (\n obj.$type === \"blob\" &&\n typeof obj.ref === \"object\" &&\n obj.ref !== null &&\n typeof (obj.ref as Record<string, unknown>).$link === \"string\" &&\n typeof obj.mimeType === \"string\" &&\n typeof obj.size === \"number\"\n );\n}\n\n// Check for SDK BlobRef class: { ref: CID, mimeType: string, size: number }\nfunction isSdkBlobRef(value: unknown): value is SdkBlobRef {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return (\n typeof obj.ref === \"object\" &&\n obj.ref !== null &&\n typeof obj.mimeType === \"string\" &&\n typeof obj.size === \"number\"\n );\n}\n\nfunction isUntypedBlobRef(value: unknown): value is UntypedBlobRef {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return typeof obj.cid === \"string\" && typeof obj.mimeType === \"string\";\n}\n\n// Validator for SDK format (incoming from PDS via SDK)\nconst blobSdkSchema = v.custom<SdkBlobRef | UntypedBlobRef>(\n (value) => isSdkBlobRef(value) || isUntypedBlobRef(value),\n \"Expected BlobRef (SDK format)\"\n);\n\n// Validator for wire format (outgoing to PDS)\nconst blobWireSchema = v.custom<WireBlobRef | UntypedBlobRef>(\n (value) => isWireBlobRef(value) || isUntypedBlobRef(value),\n \"Expected BlobRef (wire format)\"\n);\n\nexport function convertBlob(schema: LexBlob, format: BlobFormat): v.GenericSchema {\n // For now, we validate the structure but don't enforce accept/maxSize at runtime\n // Those would require access to the actual blob data\n return format === 'sdk' ? blobSdkSchema : blobWireSchema;\n}\n\n// CID link is represented as an object with $link property containing the CID string\nconst cidLinkSchema = v.object({\n $link: v.string(),\n});\n\nexport function convertCidLink(_schema: LexCidLink): v.GenericSchema {\n return cidLinkSchema;\n}\n\nexport function convertToken(schema: LexToken): v.GenericSchema {\n // Token is essentially a string literal representing a constant identifier\n // The value should be the full NSID#name reference\n return v.string();\n}\n","import * as v from \"valibot\";\nimport type { LexArray, LexObject, LexRef, LexRefUnion, ConverterContext } from \"../types.js\";\n\nexport function convertArray(\n schema: LexArray,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n const itemsSchema = convertType(schema.items, ctx);\n\n const checks: v.PipeItem<unknown[], unknown[], v.BaseIssue<unknown>>[] = [];\n\n if (schema.minLength !== undefined) {\n checks.push(v.minLength(schema.minLength));\n }\n if (schema.maxLength !== undefined) {\n checks.push(v.maxLength(schema.maxLength));\n }\n\n if (checks.length === 0) {\n return v.array(itemsSchema);\n }\n\n return v.pipe(v.array(itemsSchema), ...checks);\n}\n\nexport function convertObject(\n schema: LexObject,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n const properties: Record<string, v.GenericSchema> = {};\n const requiredSet = new Set(schema.required ?? []);\n const nullableSet = new Set(schema.nullable ?? []);\n\n if (schema.properties) {\n for (const [key, prop] of Object.entries(schema.properties)) {\n let propSchema = convertType(prop, ctx);\n\n // Handle nullable\n if (nullableSet.has(key)) {\n propSchema = v.nullable(propSchema);\n }\n\n // Handle optional (not in required list)\n if (!requiredSet.has(key)) {\n propSchema = v.optional(propSchema);\n }\n\n properties[key] = propSchema;\n }\n }\n\n return v.object(properties);\n}\n\nexport function convertRef(schema: LexRef, ctx: ConverterContext): v.GenericSchema {\n return v.lazy(() => ctx.resolveRef(schema.ref));\n}\n\nexport function convertUnion(\n schema: LexRefUnion,\n ctx: ConverterContext\n): v.GenericSchema {\n if (schema.refs.length === 0) {\n return v.never();\n }\n\n if (schema.refs.length === 1) {\n return v.lazy(() => ctx.resolveRef(schema.refs[0]));\n }\n\n // Create a union of lazy refs - we know there are at least 2 refs from the check above\n const [first, second, ...rest] = schema.refs.map((ref) =>\n v.lazy(() => ctx.resolveRef(ref))\n );\n\n return v.union([first, second, ...rest]);\n}\n","import * as v from \"valibot\";\nimport type { LexBoolean, LexInteger, LexString, LexUnknown, LexBytes } from \"../types.js\";\n\nexport function convertBoolean(schema: LexBoolean): v.GenericSchema {\n if (schema.const !== undefined) {\n return v.literal(schema.const);\n }\n return v.boolean();\n}\n\nexport function convertInteger(schema: LexInteger): v.GenericSchema {\n const checks: v.PipeItem<number, number, v.BaseIssue<unknown>>[] = [v.integer()];\n\n if (schema.minimum !== undefined) {\n checks.push(v.minValue(schema.minimum));\n }\n if (schema.maximum !== undefined) {\n checks.push(v.maxValue(schema.maximum));\n }\n\n if (schema.enum !== undefined && schema.enum.length > 0) {\n return v.picklist(schema.enum);\n }\n\n if (schema.const !== undefined) {\n return v.literal(schema.const);\n }\n\n return v.pipe(v.number(), ...checks);\n}\n\nconst graphemeSegmenter = new Intl.Segmenter(\"en\", { granularity: \"grapheme\" });\n\nfunction countGraphemes(str: string): number {\n return [...graphemeSegmenter.segment(str)].length;\n}\n\nexport function convertString(schema: LexString): v.GenericSchema {\n const checks: v.PipeItem<string, string, v.BaseIssue<unknown>>[] = [];\n\n if (schema.minLength !== undefined) {\n checks.push(v.minLength(schema.minLength));\n }\n if (schema.maxLength !== undefined) {\n checks.push(v.maxLength(schema.maxLength));\n }\n\n if (schema.minGraphemes !== undefined) {\n const min = schema.minGraphemes;\n checks.push(\n v.check(\n (value) => countGraphemes(value) >= min,\n `String must have at least ${min} grapheme(s)`\n )\n );\n }\n if (schema.maxGraphemes !== undefined) {\n const max = schema.maxGraphemes;\n checks.push(\n v.check(\n (value) => countGraphemes(value) <= max,\n `String must have at most ${max} grapheme(s)`\n )\n );\n }\n\n if (schema.enum !== undefined && schema.enum.length > 0) {\n return v.picklist(schema.enum);\n }\n\n if (schema.const !== undefined) {\n return v.literal(schema.const);\n }\n\n if (schema.format !== undefined) {\n switch (schema.format) {\n case \"datetime\":\n checks.push(v.isoTimestamp());\n break;\n case \"uri\":\n checks.push(v.url());\n break;\n case \"at-uri\":\n checks.push(v.regex(/^at:\\/\\/[a-zA-Z0-9._:%-]+\\/[a-zA-Z0-9.]+\\/[a-zA-Z0-9._~:@!$&')(*+,;=-]+$/));\n break;\n case \"did\":\n checks.push(v.regex(/^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/));\n break;\n case \"handle\":\n checks.push(v.regex(/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/));\n break;\n case \"nsid\":\n checks.push(v.regex(/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z]{0,61}[a-zA-Z])?)$/));\n break;\n case \"cid\":\n checks.push(v.regex(/^[a-zA-Z0-9+/=]+$/));\n break;\n case \"tid\":\n checks.push(v.regex(/^[234567abcdefghijklmnopqrstuvwxyz]{13}$/));\n break;\n case \"record-key\":\n checks.push(v.regex(/^[a-zA-Z0-9._:~-]+$/));\n break;\n case \"language\":\n checks.push(v.regex(/^[a-zA-Z]{2,3}(-[a-zA-Z0-9]+)*$/));\n break;\n case \"at-identifier\":\n // at-identifier can be a handle or a DID\n checks.push(v.regex(/^(did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]|([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)$/));\n break;\n }\n }\n\n if (checks.length === 0) {\n return v.string();\n }\n\n return v.pipe(v.string(), ...checks);\n}\n\nexport function convertUnknown(_schema: LexUnknown): v.GenericSchema {\n return v.unknown();\n}\n\nexport function convertBytes(schema: LexBytes): v.GenericSchema {\n const baseSchema = v.instance(Uint8Array);\n\n if (schema.minLength === undefined && schema.maxLength === undefined) {\n return baseSchema;\n }\n\n return v.pipe(\n baseSchema,\n v.check((value) => {\n if (schema.minLength !== undefined && value.length < schema.minLength) {\n return false;\n }\n if (schema.maxLength !== undefined && value.length > schema.maxLength) {\n return false;\n }\n return true;\n }, `Bytes length must be between ${schema.minLength ?? 0} and ${schema.maxLength ?? \"∞\"}`)\n );\n}\n","import * as v from \"valibot\";\nimport type { LexXrpcQuery, LexXrpcProcedure, LexXrpcSubscription, ConverterContext } from \"../types.js\";\n\nexport interface QueryValidators {\n parameters: v.GenericSchema;\n output: v.GenericSchema;\n}\n\nexport interface ProcedureValidators {\n parameters: v.GenericSchema;\n input: v.GenericSchema;\n output: v.GenericSchema;\n}\n\nexport interface SubscriptionValidators {\n parameters: v.GenericSchema;\n message: v.GenericSchema;\n}\n\n// Convert params object to valibot schema\nfunction convertParams(\n params: { type: \"params\"; required?: string[]; properties?: Record<string, unknown> } | undefined,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n if (!params?.properties) {\n return v.object({});\n }\n\n const properties: Record<string, v.GenericSchema> = {};\n const requiredSet = new Set(params.required ?? []);\n\n for (const [key, prop] of Object.entries(params.properties)) {\n let propSchema = convertType(prop, ctx);\n\n if (!requiredSet.has(key)) {\n propSchema = v.optional(propSchema);\n }\n\n properties[key] = propSchema;\n }\n\n return v.object(properties);\n}\n\n// Convert body (input/output/message) to valibot schema\nfunction convertBody(\n body: { schema?: unknown } | undefined,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n if (!body?.schema) {\n return v.unknown();\n }\n return convertType(body.schema, ctx);\n}\n\nexport function convertQuery(\n schema: LexXrpcQuery,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): QueryValidators {\n return {\n parameters: convertParams(schema.parameters, ctx, convertType),\n output: convertBody(schema.output, ctx, convertType),\n };\n}\n\nexport function convertProcedure(\n schema: LexXrpcProcedure,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): ProcedureValidators {\n return {\n parameters: convertParams(schema.parameters, ctx, convertType),\n input: convertBody(schema.input, ctx, convertType),\n output: convertBody(schema.output, ctx, convertType),\n };\n}\n\nexport function convertSubscription(\n schema: LexXrpcSubscription,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): SubscriptionValidators {\n return {\n parameters: convertParams(schema.parameters, ctx, convertType),\n message: convertBody(schema.message, ctx, convertType),\n };\n}\n","// Built-in AT Protocol type validators\n// Users can spread these into externalRefs option\n\nimport * as v from \"valibot\";\n\n// com.atproto.repo.strongRef - reference to another record\nconst strongRef = v.object({\n uri: v.string(),\n cid: v.string(),\n});\n\n// com.atproto.label.selfLabel\nconst selfLabel = v.object({\n val: v.string(),\n});\n\n// com.atproto.label.selfLabels\nconst selfLabels = v.object({\n values: v.array(selfLabel),\n});\n\nexport const atprotoRefs = {\n \"com.atproto.repo.strongRef\": strongRef,\n \"com.atproto.repo.strongRef#main\": strongRef,\n \"com.atproto.label.defs#selfLabel\": selfLabel,\n \"com.atproto.label.defs#selfLabels\": selfLabels,\n} as const;\n\nexport type AtprotoRefs = typeof atprotoRefs;"],"mappings":";AAAA,YAAYA,QAAO;;;ACAnB,YAAY,OAAO;AA6BnB,SAAS,cAAc,OAAsC;AAC3D,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,QAAM,MAAM;AACZ,SACE,IAAI,UAAU,UACd,OAAO,IAAI,QAAQ,YACnB,IAAI,QAAQ,QACZ,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AG;AAGjC,QAAI,eAAe,UAAU,YAAY,GAAG,GAAG;AAC7C,YAAM,QAAQ,YAAY,SAAS,QAAQ,KAAK,GAAG,QAAQ,EAAE,IAAI,OAAO;AACxE,eAAW,UAAO;AAAA,QAChB,OAAS,WAAQ,KAAK;AAAA,QACtB,GAAI,aAAa,SAAU,OAAsD,UAAU,CAAC;AAAA,MAC9F,CAAC;AAAA,IACH;AAEA,WAAO,OAAO,IAAI;AAAA,EACpB;AAEA,SAAO;AACT;AAMO,SAAS,cAId,SACA,UAA+D,CAAC,GACX;AACrD,QAAM,aAAa,QAAQ,UAAU;AACrC,QAAM,QAAQ,oBAAI,IAA6B;AAC/C,QAAM,aAAa;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR;AAAA,IACA,QAAQ,gBAAgB,CAAC;AAAA,IACzB;AAAA,EACF;AAEA,QAAM,MAAwB;AAAA,IAC5B,WAAW,QAAQ;AAAA,IACnB,MAAM,QAAQ;AAAA,IACd;AAAA,IACA;AAAA,EACF;AAEA,QAAM,SAAqC,CAAC;AAE5C,aAAW,CAAC,SAAS,GAAG,KAAK,OAAO,QAAQ,QAAQ,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU,GAAG,EAAG;AACrB,WAAO,OAAO,IAAI,eAAe,KAAK,GAAG;AAAA,EAC3C;AAEA,SAAO;AACT;","names":["v","v","convertType","v","v","convertType","v"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/converters/atproto.ts","../src/converters/complex.ts","../src/converters/primitives.ts","../src/converters/xrpc.ts","../src/atproto-refs.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { convertBlob, convertCidLink, convertToken } from \"./converters/atproto.js\";\nimport { convertArray, convertObject, convertRef, convertUnion } from \"./converters/complex.js\";\nimport {\n convertBoolean,\n convertBytes,\n convertInteger,\n convertString,\n convertUnknown,\n} from \"./converters/primitives.js\";\nimport {\n convertProcedure,\n convertQuery,\n convertSubscription,\n type ProcedureValidators,\n type QueryValidators,\n type SubscriptionValidators,\n} from \"./converters/xrpc.js\";\nimport type {\n ConverterContext,\n LexArray,\n LexBlob,\n LexBoolean,\n LexBytes,\n LexCidLink,\n LexInteger,\n LexObject,\n LexRecord,\n LexRef,\n LexRefUnion,\n LexString,\n LexToken,\n LexUnknown,\n LexUserType,\n LexXrpcProcedure,\n LexXrpcQuery,\n LexXrpcSubscription\n} from \"./types.js\";\n\n// Flexible input type that accepts both LexiconDoc and const objects\nexport interface LexiconInput {\n lexicon: 1;\n id: string;\n defs: Record<string, unknown>;\n description?: string;\n revision?: number;\n}\n\n// Options for lexiconToValibot\nexport interface LexiconToValibotOptions {\n /** External ref schemas (e.g., com.atproto.repo.strongRef) */\n externalRefs?: Record<string, v.GenericSchema>;\n /** Format for blob validation: 'sdk' for parsing fetched records, 'wire' for outgoing. Default: 'sdk' */\n format?: 'sdk' | 'wire';\n}\n\nexport type { ProcedureValidators, QueryValidators, SubscriptionValidators };\n\ntype XrpcResult = QueryValidators | ProcedureValidators | SubscriptionValidators;\n\nfunction convertType(schema: unknown, ctx: ConverterContext): v.GenericSchema {\n if (typeof schema !== \"object\" || schema === null) {\n throw new Error(`Invalid schema: expected object, got ${typeof schema}`);\n }\n\n const schemaObj = schema as { type?: string };\n\n switch (schemaObj.type) {\n // Primitives\n case \"boolean\":\n return convertBoolean(schema as LexBoolean);\n case \"integer\":\n return convertInteger(schema as LexInteger);\n case \"string\":\n return convertString(schema as LexString);\n case \"unknown\":\n return convertUnknown(schema as LexUnknown);\n\n // IPLD types\n case \"bytes\":\n return convertBytes(schema as LexBytes);\n case \"cid-link\":\n return convertCidLink(schema as LexCidLink);\n\n // AT Protocol types\n case \"blob\":\n return convertBlob(schema as LexBlob, ctx.blobFormat);\n case \"token\":\n return convertToken(schema as LexToken);\n\n // Complex types\n case \"array\":\n return convertArray(schema as LexArray, ctx, convertType);\n case \"object\":\n return convertObject(schema as LexObject, ctx, convertType);\n case \"ref\":\n return convertRef(schema as LexRef, ctx);\n case \"union\":\n return convertUnion(schema as LexRefUnion, ctx);\n\n // Record type\n case \"record\":\n return convertObject((schema as LexRecord).record, ctx, convertType);\n\n default:\n throw new Error(`Unknown schema type: ${schemaObj.type}`);\n }\n}\n\n// Convert XRPC def - returns validators object\nfunction convertXrpcDef(schema: unknown, ctx: ConverterContext): XrpcResult {\n if (typeof schema !== \"object\" || schema === null) {\n throw new Error(`Invalid schema: expected object, got ${typeof schema}`);\n }\n\n const schemaObj = schema as { type?: string };\n\n switch (schemaObj.type) {\n case \"query\":\n return convertQuery(schema as LexXrpcQuery, ctx, convertType);\n case \"procedure\":\n return convertProcedure(schema as LexXrpcProcedure, ctx, convertType);\n case \"subscription\":\n return convertSubscription(schema as LexXrpcSubscription, ctx, convertType);\n default:\n throw new Error(`Not an XRPC type: ${schemaObj.type}`);\n }\n}\n\n// Check if a def is an XRPC type\nfunction isXrpcDef(schema: unknown): boolean {\n if (typeof schema !== \"object\" || schema === null) return false;\n const type = (schema as { type?: string }).type;\n return type === \"query\" || type === \"procedure\" || type === \"subscription\";\n}\n\n// Check if a def is a record type\nfunction isRecordDef(schema: unknown): boolean {\n if (typeof schema !== \"object\" || schema === null) return false;\n return (schema as { type?: string }).type === \"record\";\n}\n\nfunction createRefResolver(\n lexiconId: string,\n defs: Record<string, LexUserType>,\n cache: Map<string, v.GenericSchema>,\n externalRefs: Record<string, v.GenericSchema> = {},\n blobFormat: 'sdk' | 'wire' = 'sdk'\n): (ref: string) => v.GenericSchema {\n return (ref: string) => {\n // Parse the ref - could be:\n // - \"#defName\" (local ref)\n // - \"com.example.lexicon#defName\" (external ref)\n // - \"com.example.lexicon\" (main def of external lexicon)\n\n let resolvedRef = ref;\n\n if (ref.startsWith(\"#\")) {\n // Local ref\n resolvedRef = `${lexiconId}${ref}`;\n } else if (!ref.includes(\"#\")) {\n // External ref to main def\n resolvedRef = `${ref}#main`;\n }\n\n // Check cache first\n if (cache.has(resolvedRef)) {\n return cache.get(resolvedRef)!;\n }\n\n // Check external refs (try both original and resolved)\n if (externalRefs[ref]) {\n cache.set(resolvedRef, externalRefs[ref]);\n return externalRefs[ref];\n }\n if (externalRefs[resolvedRef]) {\n cache.set(resolvedRef, externalRefs[resolvedRef]);\n return externalRefs[resolvedRef];\n }\n\n // Parse the full ref\n const [nsid, defName] = resolvedRef.includes(\"#\")\n ? resolvedRef.split(\"#\")\n : [resolvedRef, \"main\"];\n\n // Only handle local refs\n if (nsid !== lexiconId) {\n // External ref not found in externalRefs\n console.warn(`External ref not resolved: ${ref} - provide it in externalRefs option`);\n return v.unknown();\n }\n\n const def = defs[defName];\n if (!def) {\n throw new Error(`Ref not found: ${ref} (resolved to ${resolvedRef})`);\n }\n\n // Create context for conversion\n const ctx: ConverterContext = {\n lexiconId,\n defs,\n resolveRef: createRefResolver(lexiconId, defs, cache, externalRefs, blobFormat),\n blobFormat,\n };\n\n // Convert and cache\n const schema = convertType(def, ctx);\n cache.set(resolvedRef, schema);\n return schema;\n };\n}\n\nimport type { BlobFormat, InferLexiconValidators, InferXrpcValidators } from \"./infer.js\";\n\n// Helper type to convert schema map to output type map\ntype InferSchemaOutputs<T extends Record<string, v.GenericSchema>> = {\n [K in keyof T]: v.InferOutput<T[K]>;\n};\n\n/**\n * Convert a lexicon to valibot schemas for records and objects.\n * Skips XRPC types (query, procedure, subscription) - use xrpcToValibot for those.\n */\nexport function lexiconToValibot<\n T extends LexiconInput,\n ExtRefs extends Record<string, v.GenericSchema> = {},\n Format extends BlobFormat = 'sdk'\n>(\n lexicon: T,\n options: { externalRefs?: ExtRefs; format?: Format } = {}\n): InferLexiconValidators<T, InferSchemaOutputs<ExtRefs>, Format> {\n const blobFormat = options.format ?? 'sdk';\n const cache = new Map<string, v.GenericSchema>();\n const resolveRef = createRefResolver(\n lexicon.id,\n lexicon.defs as Record<string, LexUserType>,\n cache,\n options.externalRefs ?? {},\n blobFormat\n );\n\n const ctx: ConverterContext = {\n lexiconId: lexicon.id,\n defs: lexicon.defs,\n resolveRef,\n blobFormat,\n };\n\n const result: Record<string, v.GenericSchema> = {};\n\n for (const [defName, def] of Object.entries(lexicon.defs)) {\n // Skip XRPC types\n if (isXrpcDef(def)) continue;\n\n let schema = convertType(def, ctx);\n\n // For wire format, wrap record types with $type\n if (blobFormat === 'wire' && isRecordDef(def)) {\n const $type = defName === 'main' ? lexicon.id : `${lexicon.id}#${defName}`;\n schema = v.object({\n $type: v.literal($type),\n ...('entries' in schema ? (schema as v.ObjectSchema<v.ObjectEntries, undefined>).entries : {}),\n });\n }\n\n result[defName] = schema;\n }\n\n return result as InferLexiconValidators<T, InferSchemaOutputs<ExtRefs>, Format>;\n}\n\n/**\n * Convert a lexicon to valibot validators for XRPC endpoints.\n * Only handles query, procedure, and subscription types.\n */\nexport function xrpcToValibot<\n T extends LexiconInput,\n ExtRefs extends Record<string, v.GenericSchema> = {},\n Format extends BlobFormat = 'sdk'\n>(\n lexicon: T,\n options: { externalRefs?: ExtRefs; format?: Format } = {}\n): InferXrpcValidators<T, InferSchemaOutputs<ExtRefs>, Format> {\n const blobFormat = options.format ?? 'sdk';\n const cache = new Map<string, v.GenericSchema>();\n const resolveRef = createRefResolver(\n lexicon.id,\n lexicon.defs as Record<string, LexUserType>,\n cache,\n options.externalRefs ?? {},\n blobFormat\n );\n\n const ctx: ConverterContext = {\n lexiconId: lexicon.id,\n defs: lexicon.defs,\n resolveRef,\n blobFormat,\n };\n\n const result: Record<string, XrpcResult> = {};\n\n for (const [defName, def] of Object.entries(lexicon.defs)) {\n // Only handle XRPC types\n if (!isXrpcDef(def)) continue;\n result[defName] = convertXrpcDef(def, ctx);\n }\n\n return result as InferXrpcValidators<T, InferSchemaOutputs<ExtRefs>, Format>;\n}\n\n// Re-export valibot's InferOutput for convenience\nexport type { InferOutput } from \"valibot\";\n// Re-export built-in AT Protocol refs\nexport { atprotoRefs, type AtprotoRefs } from \"./atproto-refs.js\";\n\n// Re-export inference types\nexport type { BlobFormat, InferLexiconOutput, InferLexiconValidators, InferLexType } from \"./infer.js\";\n// Re-export types\nexport type { LexiconDoc, LexUserType } from \"./types.js\";\n","import type { BlobRef } from \"@atproto/lexicon\";\nimport * as v from \"valibot\";\nimport type { BlobFormat, LexBlob, LexCidLink, LexToken } from \"../types.js\";\n\n// Blob reference types for AT Protocol\n\n// Wire format: what gets sent to/from PDS\ntype WireBlobRef = {\n $type: \"blob\";\n ref: { $link: string };\n mimeType: string;\n size: number;\n};\n\n// Untyped/legacy format\ntype UntypedBlobRef = {\n cid: string;\n mimeType: string;\n};\n\n// Check for wire format: { $type: \"blob\", ref: { $link: string }, ... }\nfunction isWireBlobRef(value: unknown): value is WireBlobRef {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return (\n obj.$type === \"blob\" &&\n typeof obj.ref === \"object\" &&\n obj.ref !== null &&\n typeof (obj.ref as Record<string, unknown>).$link === \"string\" &&\n typeof obj.mimeType === \"string\" &&\n typeof obj.size === \"number\"\n );\n}\n\n// Check for SDK BlobRef class instance using duck typing\n// BlobRef has: ref (CID with toString), mimeType, size, original\nfunction isSdkBlobRef(value: unknown): value is BlobRef {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return (\n typeof obj.ref === \"object\" &&\n obj.ref !== null &&\n typeof (obj.ref as { toString?: unknown }).toString === \"function\" &&\n typeof obj.mimeType === \"string\" &&\n typeof obj.size === \"number\" &&\n typeof obj.original === \"object\"\n );\n}\n\nfunction isUntypedBlobRef(value: unknown): value is UntypedBlobRef {\n if (typeof value !== \"object\" || value === null) return false;\n const obj = value as Record<string, unknown>;\n return typeof obj.cid === \"string\" && typeof obj.mimeType === \"string\";\n}\n\n// Validator for SDK format (incoming from PDS via SDK)\nconst blobSdkSchema = v.custom<BlobRef | UntypedBlobRef>(\n (value) => isSdkBlobRef(value) || isUntypedBlobRef(value),\n \"Expected BlobRef (SDK format)\"\n);\n\n// Validator for wire format (outgoing to PDS)\nconst blobWireSchema = v.custom<WireBlobRef | UntypedBlobRef>(\n (value) => isWireBlobRef(value) || isUntypedBlobRef(value),\n \"Expected BlobRef (wire format)\"\n);\n\nexport function convertBlob(schema: LexBlob, format: BlobFormat): v.GenericSchema {\n // For now, we validate the structure but don't enforce accept/maxSize at runtime\n // Those would require access to the actual blob data\n return format === 'sdk' ? blobSdkSchema : blobWireSchema;\n}\n\n// CID link is represented as an object with $link property containing the CID string\nconst cidLinkSchema = v.object({\n $link: v.string(),\n});\n\nexport function convertCidLink(_schema: LexCidLink): v.GenericSchema {\n return cidLinkSchema;\n}\n\nexport function convertToken(schema: LexToken): v.GenericSchema {\n // Token is essentially a string literal representing a constant identifier\n // The value should be the full NSID#name reference\n return v.string();\n}\n","import * as v from \"valibot\";\nimport type { LexArray, LexObject, LexRef, LexRefUnion, ConverterContext } from \"../types.js\";\n\nexport function convertArray(\n schema: LexArray,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n const itemsSchema = convertType(schema.items, ctx);\n\n const checks: v.PipeItem<unknown[], unknown[], v.BaseIssue<unknown>>[] = [];\n\n if (schema.minLength !== undefined) {\n checks.push(v.minLength(schema.minLength));\n }\n if (schema.maxLength !== undefined) {\n checks.push(v.maxLength(schema.maxLength));\n }\n\n if (checks.length === 0) {\n return v.array(itemsSchema);\n }\n\n return v.pipe(v.array(itemsSchema), ...checks);\n}\n\nexport function convertObject(\n schema: LexObject,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n const properties: Record<string, v.GenericSchema> = {};\n const requiredSet = new Set(schema.required ?? []);\n const nullableSet = new Set(schema.nullable ?? []);\n\n if (schema.properties) {\n for (const [key, prop] of Object.entries(schema.properties)) {\n let propSchema = convertType(prop, ctx);\n\n // Handle nullable\n if (nullableSet.has(key)) {\n propSchema = v.nullable(propSchema);\n }\n\n // Handle optional (not in required list)\n if (!requiredSet.has(key)) {\n propSchema = v.optional(propSchema);\n }\n\n properties[key] = propSchema;\n }\n }\n\n return v.object(properties);\n}\n\nexport function convertRef(schema: LexRef, ctx: ConverterContext): v.GenericSchema {\n return v.lazy(() => ctx.resolveRef(schema.ref));\n}\n\nexport function convertUnion(\n schema: LexRefUnion,\n ctx: ConverterContext\n): v.GenericSchema {\n if (schema.refs.length === 0) {\n return v.never();\n }\n\n if (schema.refs.length === 1) {\n return v.lazy(() => ctx.resolveRef(schema.refs[0]));\n }\n\n // Create a union of lazy refs - we know there are at least 2 refs from the check above\n const [first, second, ...rest] = schema.refs.map((ref) =>\n v.lazy(() => ctx.resolveRef(ref))\n );\n\n return v.union([first, second, ...rest]);\n}\n","import * as v from \"valibot\";\nimport type { LexBoolean, LexInteger, LexString, LexUnknown, LexBytes } from \"../types.js\";\n\nexport function convertBoolean(schema: LexBoolean): v.GenericSchema {\n if (schema.const !== undefined) {\n return v.literal(schema.const);\n }\n return v.boolean();\n}\n\nexport function convertInteger(schema: LexInteger): v.GenericSchema {\n const checks: v.PipeItem<number, number, v.BaseIssue<unknown>>[] = [v.integer()];\n\n if (schema.minimum !== undefined) {\n checks.push(v.minValue(schema.minimum));\n }\n if (schema.maximum !== undefined) {\n checks.push(v.maxValue(schema.maximum));\n }\n\n if (schema.enum !== undefined && schema.enum.length > 0) {\n return v.picklist(schema.enum);\n }\n\n if (schema.const !== undefined) {\n return v.literal(schema.const);\n }\n\n return v.pipe(v.number(), ...checks);\n}\n\nconst graphemeSegmenter = new Intl.Segmenter(\"en\", { granularity: \"grapheme\" });\n\nfunction countGraphemes(str: string): number {\n return [...graphemeSegmenter.segment(str)].length;\n}\n\nexport function convertString(schema: LexString): v.GenericSchema {\n const checks: v.PipeItem<string, string, v.BaseIssue<unknown>>[] = [];\n\n if (schema.minLength !== undefined) {\n checks.push(v.minLength(schema.minLength));\n }\n if (schema.maxLength !== undefined) {\n checks.push(v.maxLength(schema.maxLength));\n }\n\n if (schema.minGraphemes !== undefined) {\n const min = schema.minGraphemes;\n checks.push(\n v.check(\n (value) => countGraphemes(value) >= min,\n `String must have at least ${min} grapheme(s)`\n )\n );\n }\n if (schema.maxGraphemes !== undefined) {\n const max = schema.maxGraphemes;\n checks.push(\n v.check(\n (value) => countGraphemes(value) <= max,\n `String must have at most ${max} grapheme(s)`\n )\n );\n }\n\n if (schema.enum !== undefined && schema.enum.length > 0) {\n return v.picklist(schema.enum);\n }\n\n if (schema.const !== undefined) {\n return v.literal(schema.const);\n }\n\n if (schema.format !== undefined) {\n switch (schema.format) {\n case \"datetime\":\n checks.push(v.isoTimestamp());\n break;\n case \"uri\":\n checks.push(v.url());\n break;\n case \"at-uri\":\n checks.push(v.regex(/^at:\\/\\/[a-zA-Z0-9._:%-]+\\/[a-zA-Z0-9.]+\\/[a-zA-Z0-9._~:@!$&')(*+,;=-]+$/));\n break;\n case \"did\":\n checks.push(v.regex(/^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/));\n break;\n case \"handle\":\n checks.push(v.regex(/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/));\n break;\n case \"nsid\":\n checks.push(v.regex(/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z]{0,61}[a-zA-Z])?)$/));\n break;\n case \"cid\":\n checks.push(v.regex(/^[a-zA-Z0-9+/=]+$/));\n break;\n case \"tid\":\n checks.push(v.regex(/^[234567abcdefghijklmnopqrstuvwxyz]{13}$/));\n break;\n case \"record-key\":\n checks.push(v.regex(/^[a-zA-Z0-9._:~-]+$/));\n break;\n case \"language\":\n checks.push(v.regex(/^[a-zA-Z]{2,3}(-[a-zA-Z0-9]+)*$/));\n break;\n case \"at-identifier\":\n // at-identifier can be a handle or a DID\n checks.push(v.regex(/^(did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]|([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)$/));\n break;\n }\n }\n\n if (checks.length === 0) {\n return v.string();\n }\n\n return v.pipe(v.string(), ...checks);\n}\n\nexport function convertUnknown(_schema: LexUnknown): v.GenericSchema {\n return v.unknown();\n}\n\nexport function convertBytes(schema: LexBytes): v.GenericSchema {\n const baseSchema = v.instance(Uint8Array);\n\n if (schema.minLength === undefined && schema.maxLength === undefined) {\n return baseSchema;\n }\n\n return v.pipe(\n baseSchema,\n v.check((value) => {\n if (schema.minLength !== undefined && value.length < schema.minLength) {\n return false;\n }\n if (schema.maxLength !== undefined && value.length > schema.maxLength) {\n return false;\n }\n return true;\n }, `Bytes length must be between ${schema.minLength ?? 0} and ${schema.maxLength ?? \"∞\"}`)\n );\n}\n","import * as v from \"valibot\";\nimport type { LexXrpcQuery, LexXrpcProcedure, LexXrpcSubscription, ConverterContext } from \"../types.js\";\n\nexport interface QueryValidators {\n parameters: v.GenericSchema;\n output: v.GenericSchema;\n}\n\nexport interface ProcedureValidators {\n parameters: v.GenericSchema;\n input: v.GenericSchema;\n output: v.GenericSchema;\n}\n\nexport interface SubscriptionValidators {\n parameters: v.GenericSchema;\n message: v.GenericSchema;\n}\n\n// Convert params object to valibot schema\nfunction convertParams(\n params: { type: \"params\"; required?: string[]; properties?: Record<string, unknown> } | undefined,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n if (!params?.properties) {\n return v.object({});\n }\n\n const properties: Record<string, v.GenericSchema> = {};\n const requiredSet = new Set(params.required ?? []);\n\n for (const [key, prop] of Object.entries(params.properties)) {\n let propSchema = convertType(prop, ctx);\n\n if (!requiredSet.has(key)) {\n propSchema = v.optional(propSchema);\n }\n\n properties[key] = propSchema;\n }\n\n return v.object(properties);\n}\n\n// Convert body (input/output/message) to valibot schema\nfunction convertBody(\n body: { schema?: unknown } | undefined,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): v.GenericSchema {\n if (!body?.schema) {\n return v.unknown();\n }\n return convertType(body.schema, ctx);\n}\n\nexport function convertQuery(\n schema: LexXrpcQuery,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): QueryValidators {\n return {\n parameters: convertParams(schema.parameters, ctx, convertType),\n output: convertBody(schema.output, ctx, convertType),\n };\n}\n\nexport function convertProcedure(\n schema: LexXrpcProcedure,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): ProcedureValidators {\n return {\n parameters: convertParams(schema.parameters, ctx, convertType),\n input: convertBody(schema.input, ctx, convertType),\n output: convertBody(schema.output, ctx, convertType),\n };\n}\n\nexport function convertSubscription(\n schema: LexXrpcSubscription,\n ctx: ConverterContext,\n convertType: (type: unknown, ctx: ConverterContext) => v.GenericSchema\n): SubscriptionValidators {\n return {\n parameters: convertParams(schema.parameters, ctx, convertType),\n message: convertBody(schema.message, ctx, convertType),\n };\n}\n","// Built-in AT Protocol type validators\n// Users can spread these into externalRefs option\n\nimport * as v from \"valibot\";\n\n// com.atproto.repo.strongRef - reference to another record\nconst strongRef = v.object({\n uri: v.string(),\n cid: v.string(),\n});\n\n// com.atproto.label.selfLabel\nconst selfLabel = v.object({\n val: v.string(),\n});\n\n// com.atproto.label.selfLabels\nconst selfLabels = v.object({\n values: v.array(selfLabel),\n});\n\nexport const atprotoRefs = {\n \"com.atproto.repo.strongRef\": strongRef,\n \"com.atproto.repo.strongRef#main\": strongRef,\n \"com.atproto.label.defs#selfLabel\": selfLabel,\n \"com.atproto.label.defs#selfLabels\": selfLabels,\n} as const;\n\nexport type AtprotoRefs = typeof atprotoRefs;"],"mappings":";AAAA,YAAYA,QAAO;;;ACCnB,YAAY,OAAO;AAoBnB,SAAS,cAAc,OAAsC;AAC3D,MAAI,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IACd;AAAA,IACA;AAAA,EACF;AAEA,QAAM,SAA0C,CAAC;AAEjD,aAAW,CAAC,SAAS,GAAG,KAAK,OAAO,QAAQ,QAAQ,IAAI,GAAG;AAEzD,QAAI,UAAU,GAAG,EAAG;AAEpB,QAAI,SAAS,YAAY,KAAK,GAAG;AAGjC,QAAI,eAAe,UAAU,YAAY,GAAG,GAAG;AAC7C,YAAM,QAAQ,YAAY,SAAS,QAAQ,KAAK,GAAG,QAAQ,EAAE,IAAI,OAAO;AACxE,eAAW,UAAO;AAAA,QAChB,OAAS,WAAQ,KAAK;AAAA,QACtB,GAAI,aAAa,SAAU,OAAsD,UAAU,CAAC;AAAA,MAC9F,CAAC;AAAA,IACH;AAEA,WAAO,OAAO,IAAI;AAAA,EACpB;AAEA,SAAO;AACT;AAMO,SAAS,cAKd,SACA,UAAuD,CAAC,GACK;AAC7D,QAAM,aAAa,QAAQ,UAAU;AACrC,QAAM,QAAQ,oBAAI,IAA6B;AAC/C,QAAM,aAAa;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR;AAAA,IACA,QAAQ,gBAAgB,CAAC;AAAA,IACzB;AAAA,EACF;AAEA,QAAM,MAAwB;AAAA,IAC5B,WAAW,QAAQ;AAAA,IACnB,MAAM,QAAQ;AAAA,IACd;AAAA,IACA;AAAA,EACF;AAEA,QAAM,SAAqC,CAAC;AAE5C,aAAW,CAAC,SAAS,GAAG,KAAK,OAAO,QAAQ,QAAQ,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU,GAAG,EAAG;AACrB,WAAO,OAAO,IAAI,eAAe,KAAK,GAAG;AAAA,EAC3C;AAEA,SAAO;AACT;","names":["v","v","convertType","v","v","convertType","v"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigmistqke/lexicon-to-valibot",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Convert AT Protocol Lexicon schemas to Valibot validators",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@atproto/lexicon": "^0.4.0",
|
|
30
30
|
"bumpp": "^9.0.0",
|
|
31
|
+
"multiformats": "^9.9.0",
|
|
31
32
|
"tsup": "^8.0.0",
|
|
32
33
|
"typescript": "^5.0.0",
|
|
33
34
|
"valibot": "^1.0.0",
|