@bigmistqke/lexicon-to-valibot 0.1.1 → 0.1.3
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 +55 -47
- package/dist/index.js +10450 -16
- 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<{
|
|
@@ -198,6 +202,8 @@ interface LexiconInput {
|
|
|
198
202
|
interface LexiconToValibotOptions {
|
|
199
203
|
/** External ref schemas (e.g., com.atproto.repo.strongRef) */
|
|
200
204
|
externalRefs?: Record<string, v.GenericSchema>;
|
|
205
|
+
/** Format for blob validation: 'sdk' for parsing fetched records, 'wire' for outgoing. Default: 'sdk' */
|
|
206
|
+
format?: 'sdk' | 'wire';
|
|
201
207
|
}
|
|
202
208
|
|
|
203
209
|
type InferSchemaOutputs<T extends Record<string, v.GenericSchema>> = {
|
|
@@ -207,15 +213,17 @@ type InferSchemaOutputs<T extends Record<string, v.GenericSchema>> = {
|
|
|
207
213
|
* Convert a lexicon to valibot schemas for records and objects.
|
|
208
214
|
* Skips XRPC types (query, procedure, subscription) - use xrpcToValibot for those.
|
|
209
215
|
*/
|
|
210
|
-
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?: {
|
|
211
217
|
externalRefs?: ExtRefs;
|
|
212
|
-
|
|
218
|
+
format?: Format;
|
|
219
|
+
}): InferLexiconValidators<T, InferSchemaOutputs<ExtRefs>, Format>;
|
|
213
220
|
/**
|
|
214
221
|
* Convert a lexicon to valibot validators for XRPC endpoints.
|
|
215
222
|
* Only handles query, procedure, and subscription types.
|
|
216
223
|
*/
|
|
217
|
-
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?: {
|
|
218
225
|
externalRefs?: ExtRefs;
|
|
219
|
-
|
|
226
|
+
format?: Format;
|
|
227
|
+
}): InferXrpcValidators<T, InferSchemaOutputs<ExtRefs>, Format>;
|
|
220
228
|
|
|
221
|
-
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 };
|