@atproto/lexicon 0.6.2 → 0.7.0
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/CHANGELOG.md +18 -0
- package/dist/blob-refs.d.ts +4 -4
- package/dist/blob-refs.js +20 -45
- package/dist/blob-refs.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -20
- package/dist/index.js.map +1 -1
- package/dist/lexicons.d.ts +1 -1
- package/dist/lexicons.d.ts.map +1 -1
- package/dist/lexicons.js +40 -54
- package/dist/lexicons.js.map +1 -1
- package/dist/serialize.js +22 -31
- package/dist/serialize.js.map +1 -1
- package/dist/types.js +193 -203
- package/dist/types.js.map +1 -1
- package/dist/util.js +6 -10
- package/dist/util.js.map +1 -1
- package/dist/validation.d.ts +2 -2
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +10 -17
- package/dist/validation.js.map +1 -1
- package/dist/validators/blob.d.ts +2 -2
- package/dist/validators/blob.d.ts.map +1 -1
- package/dist/validators/blob.js +5 -8
- package/dist/validators/blob.js.map +1 -1
- package/dist/validators/complex.d.ts +2 -2
- package/dist/validators/complex.d.ts.map +1 -1
- package/dist/validators/complex.js +20 -26
- package/dist/validators/complex.js.map +1 -1
- package/dist/validators/formats.d.ts +1 -1
- package/dist/validators/formats.d.ts.map +1 -1
- package/dist/validators/formats.js +38 -50
- package/dist/validators/formats.js.map +1 -1
- package/dist/validators/primitives.d.ts +2 -2
- package/dist/validators/primitives.d.ts.map +1 -1
- package/dist/validators/primitives.js +33 -69
- package/dist/validators/primitives.js.map +1 -1
- package/dist/validators/xrpc.d.ts +2 -2
- package/dist/validators/xrpc.d.ts.map +1 -1
- package/dist/validators/xrpc.js +6 -42
- package/dist/validators/xrpc.js.map +1 -1
- package/jest.config.cjs +21 -0
- package/package.json +17 -9
- package/src/index.ts +4 -4
- package/src/lexicons.ts +4 -4
- package/src/serialize.ts +1 -1
- package/src/types.ts +1 -1
- package/src/validation.ts +4 -4
- package/src/validators/blob.ts +3 -3
- package/src/validators/complex.ts +5 -5
- package/src/validators/formats.ts +3 -2
- package/src/validators/primitives.ts +3 -3
- package/src/validators/xrpc.ts +8 -4
- package/tests/_scaffolds/lexicons.ts +1 -1
- package/tests/general.test.ts +5 -5
- package/tsconfig.build.tsbuildinfo +1 -1
- package/jest.config.js +0 -7
package/dist/serialize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"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","sourcesContent":["import { CID } from 'multiformats/cid'\nimport {\n IpldValue,\n JsonValue,\n check,\n ipldToJson,\n jsonToIpld,\n} from '@atproto/common-web'\nimport { BlobRef, jsonBlobRef } from './blob-refs.js'\n\n/**\n * @note this is equivalent to `unknown` because of {@link IpldValue} being `unknown`.\n * @deprecated Use {@link Lex} from `@atproto/lex-data` instead.\n */\nexport type LexValue = unknown\n\n/**\n * @deprecated Use {@link TypedLexMap} from `@atproto/lex-data` instead.\n */\nexport type RepoRecord = Record<string, LexValue>\n\n// @NOTE avoiding use of check.is() here only because it makes\n// these implementations slow, and they often live in hot paths.\n\n/**\n * @deprecated Use `LexValue` from `@atproto/lex-data` instead (which doesn't need conversion to IPLD).\n */\nexport const lexToIpld = (val: LexValue): IpldValue => {\n // walk arrays\n if (Array.isArray(val)) {\n return val.map((item) => lexToIpld(item))\n }\n // objects\n if (val && typeof val === 'object') {\n // convert blobs, leaving the original encoding so that we don't change CIDs on re-encode\n if (val instanceof BlobRef) {\n return val.original\n }\n // retain cids & bytes\n if (CID.asCID(val) || val instanceof Uint8Array) {\n return val\n }\n // walk plain objects\n const toReturn = {}\n for (const key of Object.keys(val)) {\n toReturn[key] = lexToIpld(val[key])\n }\n return toReturn\n }\n // pass through\n return val\n}\n\n/**\n * @deprecated Use `LexValue` from `@atproto/lex-data` instead instead (which doesn't need conversion to IPLD).\n */\nexport const ipldToLex = (val: IpldValue): LexValue => {\n // map arrays\n if (Array.isArray(val)) {\n return val.map((item) => ipldToLex(item))\n }\n // objects\n if (val && typeof val === 'object') {\n // convert blobs, using hints to avoid expensive is() check\n if (\n (val['$type'] === 'blob' ||\n (typeof val['cid'] === 'string' &&\n typeof val['mimeType'] === 'string')) &&\n check.is(val, jsonBlobRef)\n ) {\n return BlobRef.fromJsonRef(val)\n }\n // retain cids, bytes\n if (CID.asCID(val) || val instanceof Uint8Array) {\n return val\n }\n // map plain objects\n const toReturn = {}\n for (const key of Object.keys(val)) {\n toReturn[key] = ipldToLex(val[key])\n }\n return toReturn\n }\n // pass through\n return val\n}\n\nexport const lexToJson = (val: LexValue): JsonValue => {\n return ipldToJson(lexToIpld(val))\n}\n\nexport const stringifyLex = (val: LexValue): string => {\n return JSON.stringify(lexToJson(val))\n}\n\nexport const jsonToLex = (val: JsonValue): LexValue => {\n return ipldToLex(jsonToIpld(val))\n}\n\nexport const jsonStringToLex = (val: string): LexValue => {\n return jsonToLex(JSON.parse(val))\n}\n"]}
|
package/dist/types.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.isDiscriminatedObject = isDiscriminatedObject;
|
|
7
|
-
exports.parseLexiconDoc = parseLexiconDoc;
|
|
8
|
-
const zod_1 = require("zod");
|
|
9
|
-
const common_web_1 = require("@atproto/common-web");
|
|
10
|
-
const syntax_1 = require("@atproto/syntax");
|
|
11
|
-
const util_1 = require("./util");
|
|
12
|
-
exports.languageSchema = zod_1.z
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { validateLanguage } from '@atproto/common-web';
|
|
3
|
+
import { isValidNsid } from '@atproto/syntax';
|
|
4
|
+
import { requiredPropertiesRefinement } from './util.js';
|
|
5
|
+
export const languageSchema = z
|
|
13
6
|
.string()
|
|
14
|
-
.refine(
|
|
15
|
-
|
|
7
|
+
.refine(validateLanguage, 'Invalid BCP47 language tag');
|
|
8
|
+
export const lexLang = z.record(languageSchema, z.string().optional());
|
|
16
9
|
// primitives
|
|
17
10
|
// =
|
|
18
|
-
|
|
19
|
-
type:
|
|
20
|
-
description:
|
|
21
|
-
default:
|
|
22
|
-
const:
|
|
11
|
+
export const lexBoolean = z.object({
|
|
12
|
+
type: z.literal('boolean'),
|
|
13
|
+
description: z.string().optional(),
|
|
14
|
+
default: z.boolean().optional(),
|
|
15
|
+
const: z.boolean().optional(),
|
|
23
16
|
});
|
|
24
|
-
|
|
25
|
-
type:
|
|
26
|
-
description:
|
|
27
|
-
default:
|
|
28
|
-
minimum:
|
|
29
|
-
maximum:
|
|
30
|
-
enum:
|
|
31
|
-
const:
|
|
17
|
+
export const lexInteger = z.object({
|
|
18
|
+
type: z.literal('integer'),
|
|
19
|
+
description: z.string().optional(),
|
|
20
|
+
default: z.number().int().optional(),
|
|
21
|
+
minimum: z.number().int().optional(),
|
|
22
|
+
maximum: z.number().int().optional(),
|
|
23
|
+
enum: z.number().int().array().optional(),
|
|
24
|
+
const: z.number().int().optional(),
|
|
32
25
|
});
|
|
33
|
-
|
|
26
|
+
export const lexStringFormat = z.enum([
|
|
34
27
|
'datetime',
|
|
35
28
|
'uri',
|
|
36
29
|
'at-uri',
|
|
@@ -43,199 +36,199 @@ exports.lexStringFormat = zod_1.z.enum([
|
|
|
43
36
|
'tid',
|
|
44
37
|
'record-key',
|
|
45
38
|
]);
|
|
46
|
-
|
|
47
|
-
type:
|
|
48
|
-
format:
|
|
49
|
-
description:
|
|
50
|
-
default:
|
|
51
|
-
minLength:
|
|
52
|
-
maxLength:
|
|
53
|
-
minGraphemes:
|
|
54
|
-
maxGraphemes:
|
|
55
|
-
enum:
|
|
56
|
-
const:
|
|
57
|
-
knownValues:
|
|
39
|
+
export const lexString = z.object({
|
|
40
|
+
type: z.literal('string'),
|
|
41
|
+
format: lexStringFormat.optional(),
|
|
42
|
+
description: z.string().optional(),
|
|
43
|
+
default: z.string().optional(),
|
|
44
|
+
minLength: z.number().int().optional(),
|
|
45
|
+
maxLength: z.number().int().optional(),
|
|
46
|
+
minGraphemes: z.number().int().optional(),
|
|
47
|
+
maxGraphemes: z.number().int().optional(),
|
|
48
|
+
enum: z.string().array().optional(),
|
|
49
|
+
const: z.string().optional(),
|
|
50
|
+
knownValues: z.string().array().optional(),
|
|
58
51
|
});
|
|
59
|
-
|
|
60
|
-
type:
|
|
61
|
-
description:
|
|
52
|
+
export const lexUnknown = z.object({
|
|
53
|
+
type: z.literal('unknown'),
|
|
54
|
+
description: z.string().optional(),
|
|
62
55
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
export const lexPrimitive = z.discriminatedUnion('type', [
|
|
57
|
+
lexBoolean,
|
|
58
|
+
lexInteger,
|
|
59
|
+
lexString,
|
|
60
|
+
lexUnknown,
|
|
68
61
|
]);
|
|
69
62
|
// ipld types
|
|
70
63
|
// =
|
|
71
|
-
|
|
72
|
-
type:
|
|
73
|
-
description:
|
|
74
|
-
maxLength:
|
|
75
|
-
minLength:
|
|
64
|
+
export const lexBytes = z.object({
|
|
65
|
+
type: z.literal('bytes'),
|
|
66
|
+
description: z.string().optional(),
|
|
67
|
+
maxLength: z.number().optional(),
|
|
68
|
+
minLength: z.number().optional(),
|
|
76
69
|
});
|
|
77
|
-
|
|
78
|
-
type:
|
|
79
|
-
description:
|
|
70
|
+
export const lexCidLink = z.object({
|
|
71
|
+
type: z.literal('cid-link'),
|
|
72
|
+
description: z.string().optional(),
|
|
80
73
|
});
|
|
81
|
-
|
|
74
|
+
export const lexIpldType = z.discriminatedUnion('type', [lexBytes, lexCidLink]);
|
|
82
75
|
// references
|
|
83
76
|
// =
|
|
84
|
-
|
|
85
|
-
type:
|
|
86
|
-
description:
|
|
87
|
-
ref:
|
|
77
|
+
export const lexRef = z.object({
|
|
78
|
+
type: z.literal('ref'),
|
|
79
|
+
description: z.string().optional(),
|
|
80
|
+
ref: z.string(),
|
|
88
81
|
});
|
|
89
|
-
|
|
90
|
-
type:
|
|
91
|
-
description:
|
|
92
|
-
refs:
|
|
93
|
-
closed:
|
|
82
|
+
export const lexRefUnion = z.object({
|
|
83
|
+
type: z.literal('union'),
|
|
84
|
+
description: z.string().optional(),
|
|
85
|
+
refs: z.string().array(),
|
|
86
|
+
closed: z.boolean().optional(),
|
|
94
87
|
});
|
|
95
|
-
|
|
88
|
+
export const lexRefVariant = z.discriminatedUnion('type', [lexRef, lexRefUnion]);
|
|
96
89
|
// blobs
|
|
97
90
|
// =
|
|
98
|
-
|
|
99
|
-
type:
|
|
100
|
-
description:
|
|
101
|
-
accept:
|
|
102
|
-
maxSize:
|
|
91
|
+
export const lexBlob = z.object({
|
|
92
|
+
type: z.literal('blob'),
|
|
93
|
+
description: z.string().optional(),
|
|
94
|
+
accept: z.string().array().optional(),
|
|
95
|
+
maxSize: z.number().optional(),
|
|
103
96
|
});
|
|
104
97
|
// complex types
|
|
105
98
|
// =
|
|
106
|
-
|
|
107
|
-
type:
|
|
108
|
-
description:
|
|
109
|
-
items:
|
|
99
|
+
export const lexArray = z.object({
|
|
100
|
+
type: z.literal('array'),
|
|
101
|
+
description: z.string().optional(),
|
|
102
|
+
items: z.discriminatedUnion('type', [
|
|
110
103
|
// lexPrimitive
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
lexBoolean,
|
|
105
|
+
lexInteger,
|
|
106
|
+
lexString,
|
|
107
|
+
lexUnknown,
|
|
115
108
|
// lexIpldType
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
lexBytes,
|
|
110
|
+
lexCidLink,
|
|
118
111
|
// lexRefVariant
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
lexRef,
|
|
113
|
+
lexRefUnion,
|
|
121
114
|
// other
|
|
122
|
-
|
|
115
|
+
lexBlob,
|
|
123
116
|
]),
|
|
124
|
-
minLength:
|
|
125
|
-
maxLength:
|
|
117
|
+
minLength: z.number().int().optional(),
|
|
118
|
+
maxLength: z.number().int().optional(),
|
|
126
119
|
});
|
|
127
|
-
|
|
128
|
-
items:
|
|
120
|
+
export const lexPrimitiveArray = lexArray.merge(z.object({
|
|
121
|
+
items: lexPrimitive,
|
|
129
122
|
}));
|
|
130
|
-
|
|
131
|
-
type:
|
|
132
|
-
description:
|
|
123
|
+
export const lexToken = z.object({
|
|
124
|
+
type: z.literal('token'),
|
|
125
|
+
description: z.string().optional(),
|
|
133
126
|
});
|
|
134
|
-
|
|
127
|
+
export const lexObject = z
|
|
135
128
|
.object({
|
|
136
|
-
type:
|
|
137
|
-
description:
|
|
138
|
-
required:
|
|
139
|
-
nullable:
|
|
140
|
-
properties:
|
|
141
|
-
|
|
129
|
+
type: z.literal('object'),
|
|
130
|
+
description: z.string().optional(),
|
|
131
|
+
required: z.string().array().optional(),
|
|
132
|
+
nullable: z.string().array().optional(),
|
|
133
|
+
properties: z.record(z.string(), z.discriminatedUnion('type', [
|
|
134
|
+
lexArray,
|
|
142
135
|
// lexPrimitive
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
136
|
+
lexBoolean,
|
|
137
|
+
lexInteger,
|
|
138
|
+
lexString,
|
|
139
|
+
lexUnknown,
|
|
147
140
|
// lexIpldType
|
|
148
|
-
|
|
149
|
-
|
|
141
|
+
lexBytes,
|
|
142
|
+
lexCidLink,
|
|
150
143
|
// lexRefVariant
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
lexRef,
|
|
145
|
+
lexRefUnion,
|
|
153
146
|
// other
|
|
154
|
-
|
|
147
|
+
lexBlob,
|
|
155
148
|
])),
|
|
156
149
|
})
|
|
157
|
-
.superRefine(
|
|
150
|
+
.superRefine(requiredPropertiesRefinement);
|
|
158
151
|
// permissions
|
|
159
152
|
// =
|
|
160
|
-
const lexPermission =
|
|
161
|
-
type:
|
|
162
|
-
resource:
|
|
163
|
-
}),
|
|
153
|
+
const lexPermission = z.intersection(z.object({
|
|
154
|
+
type: z.literal('permission'),
|
|
155
|
+
resource: z.string().nonempty(),
|
|
156
|
+
}), z.record(z.string(), z
|
|
164
157
|
.union([
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
158
|
+
z.array(z.union([z.string(), z.number().int(), z.boolean()])),
|
|
159
|
+
z.boolean(),
|
|
160
|
+
z.number().int(),
|
|
161
|
+
z.string(),
|
|
169
162
|
])
|
|
170
163
|
.optional()));
|
|
171
|
-
|
|
172
|
-
type:
|
|
173
|
-
description:
|
|
174
|
-
title:
|
|
175
|
-
'title:lang':
|
|
176
|
-
detail:
|
|
177
|
-
'detail:lang':
|
|
178
|
-
permissions:
|
|
164
|
+
export const lexPermissionSet = z.object({
|
|
165
|
+
type: z.literal('permission-set'),
|
|
166
|
+
description: z.string().optional(),
|
|
167
|
+
title: z.string().optional(),
|
|
168
|
+
'title:lang': lexLang.optional(),
|
|
169
|
+
detail: z.string().optional(),
|
|
170
|
+
'detail:lang': lexLang.optional(),
|
|
171
|
+
permissions: z.array(lexPermission),
|
|
179
172
|
});
|
|
180
173
|
// xrpc
|
|
181
174
|
// =
|
|
182
|
-
|
|
175
|
+
export const lexXrpcParameters = z
|
|
183
176
|
.object({
|
|
184
|
-
type:
|
|
185
|
-
description:
|
|
186
|
-
required:
|
|
187
|
-
properties:
|
|
188
|
-
|
|
177
|
+
type: z.literal('params'),
|
|
178
|
+
description: z.string().optional(),
|
|
179
|
+
required: z.string().array().optional(),
|
|
180
|
+
properties: z.record(z.string(), z.discriminatedUnion('type', [
|
|
181
|
+
lexPrimitiveArray,
|
|
189
182
|
// lexPrimitive
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
lexBoolean,
|
|
184
|
+
lexInteger,
|
|
185
|
+
lexString,
|
|
186
|
+
lexUnknown,
|
|
194
187
|
])),
|
|
195
188
|
})
|
|
196
|
-
.superRefine(
|
|
197
|
-
|
|
198
|
-
description:
|
|
199
|
-
encoding:
|
|
189
|
+
.superRefine(requiredPropertiesRefinement);
|
|
190
|
+
export const lexXrpcBody = z.object({
|
|
191
|
+
description: z.string().optional(),
|
|
192
|
+
encoding: z.string(),
|
|
200
193
|
// @NOTE using discriminatedUnion with a refined schema requires zod >= 4
|
|
201
|
-
schema:
|
|
194
|
+
schema: z.union([lexRefVariant, lexObject]).optional(),
|
|
202
195
|
});
|
|
203
|
-
|
|
204
|
-
name:
|
|
205
|
-
description:
|
|
196
|
+
export const lexXrpcError = z.object({
|
|
197
|
+
name: z.string(),
|
|
198
|
+
description: z.string().optional(),
|
|
206
199
|
});
|
|
207
|
-
|
|
208
|
-
type:
|
|
209
|
-
description:
|
|
210
|
-
parameters:
|
|
211
|
-
output:
|
|
212
|
-
errors:
|
|
200
|
+
export const lexXrpcQuery = z.object({
|
|
201
|
+
type: z.literal('query'),
|
|
202
|
+
description: z.string().optional(),
|
|
203
|
+
parameters: lexXrpcParameters.optional(),
|
|
204
|
+
output: lexXrpcBody.optional(),
|
|
205
|
+
errors: lexXrpcError.array().optional(),
|
|
213
206
|
});
|
|
214
|
-
|
|
215
|
-
type:
|
|
216
|
-
description:
|
|
217
|
-
parameters:
|
|
218
|
-
input:
|
|
219
|
-
output:
|
|
220
|
-
errors:
|
|
207
|
+
export const lexXrpcProcedure = z.object({
|
|
208
|
+
type: z.literal('procedure'),
|
|
209
|
+
description: z.string().optional(),
|
|
210
|
+
parameters: lexXrpcParameters.optional(),
|
|
211
|
+
input: lexXrpcBody.optional(),
|
|
212
|
+
output: lexXrpcBody.optional(),
|
|
213
|
+
errors: lexXrpcError.array().optional(),
|
|
221
214
|
});
|
|
222
|
-
|
|
223
|
-
type:
|
|
224
|
-
description:
|
|
225
|
-
parameters:
|
|
226
|
-
message:
|
|
227
|
-
description:
|
|
228
|
-
schema:
|
|
215
|
+
export const lexXrpcSubscription = z.object({
|
|
216
|
+
type: z.literal('subscription'),
|
|
217
|
+
description: z.string().optional(),
|
|
218
|
+
parameters: lexXrpcParameters.optional(),
|
|
219
|
+
message: z.object({
|
|
220
|
+
description: z.string().optional(),
|
|
221
|
+
schema: lexRefUnion,
|
|
229
222
|
}),
|
|
230
|
-
errors:
|
|
223
|
+
errors: lexXrpcError.array().optional(),
|
|
231
224
|
});
|
|
232
225
|
// database
|
|
233
226
|
// =
|
|
234
|
-
|
|
235
|
-
type:
|
|
236
|
-
description:
|
|
237
|
-
key:
|
|
238
|
-
record:
|
|
227
|
+
export const lexRecord = z.object({
|
|
228
|
+
type: z.literal('record'),
|
|
229
|
+
description: z.string().optional(),
|
|
230
|
+
key: z.string().optional(),
|
|
231
|
+
record: lexObject,
|
|
239
232
|
});
|
|
240
233
|
// core
|
|
241
234
|
// =
|
|
@@ -243,7 +236,7 @@ exports.lexRecord = zod_1.z.object({
|
|
|
243
236
|
// lexXrpcProperty and lexObject are refined
|
|
244
237
|
// `z.union` would work, but it's too slow
|
|
245
238
|
// see #915 for details
|
|
246
|
-
|
|
239
|
+
export const lexUserType = z.custom((val) => {
|
|
247
240
|
if (!val || typeof val !== 'object') {
|
|
248
241
|
return;
|
|
249
242
|
}
|
|
@@ -252,35 +245,35 @@ exports.lexUserType = zod_1.z.custom((val) => {
|
|
|
252
245
|
}
|
|
253
246
|
switch (val['type']) {
|
|
254
247
|
case 'record':
|
|
255
|
-
return
|
|
248
|
+
return lexRecord.parse(val);
|
|
256
249
|
case 'permission-set':
|
|
257
|
-
return
|
|
250
|
+
return lexPermissionSet.parse(val);
|
|
258
251
|
case 'query':
|
|
259
|
-
return
|
|
252
|
+
return lexXrpcQuery.parse(val);
|
|
260
253
|
case 'procedure':
|
|
261
|
-
return
|
|
254
|
+
return lexXrpcProcedure.parse(val);
|
|
262
255
|
case 'subscription':
|
|
263
|
-
return
|
|
256
|
+
return lexXrpcSubscription.parse(val);
|
|
264
257
|
case 'blob':
|
|
265
|
-
return
|
|
258
|
+
return lexBlob.parse(val);
|
|
266
259
|
case 'array':
|
|
267
|
-
return
|
|
260
|
+
return lexArray.parse(val);
|
|
268
261
|
case 'token':
|
|
269
|
-
return
|
|
262
|
+
return lexToken.parse(val);
|
|
270
263
|
case 'object':
|
|
271
|
-
return
|
|
264
|
+
return lexObject.parse(val);
|
|
272
265
|
case 'boolean':
|
|
273
|
-
return
|
|
266
|
+
return lexBoolean.parse(val);
|
|
274
267
|
case 'integer':
|
|
275
|
-
return
|
|
268
|
+
return lexInteger.parse(val);
|
|
276
269
|
case 'string':
|
|
277
|
-
return
|
|
270
|
+
return lexString.parse(val);
|
|
278
271
|
case 'bytes':
|
|
279
|
-
return
|
|
272
|
+
return lexBytes.parse(val);
|
|
280
273
|
case 'cid-link':
|
|
281
|
-
return
|
|
274
|
+
return lexCidLink.parse(val);
|
|
282
275
|
case 'unknown':
|
|
283
|
-
return
|
|
276
|
+
return lexUnknown.parse(val);
|
|
284
277
|
}
|
|
285
278
|
}, (val) => {
|
|
286
279
|
if (!val || typeof val !== 'object') {
|
|
@@ -306,15 +299,15 @@ exports.lexUserType = zod_1.z.custom((val) => {
|
|
|
306
299
|
fatal: true,
|
|
307
300
|
};
|
|
308
301
|
});
|
|
309
|
-
|
|
302
|
+
export const lexiconDoc = z
|
|
310
303
|
.object({
|
|
311
|
-
lexicon:
|
|
312
|
-
id:
|
|
304
|
+
lexicon: z.literal(1),
|
|
305
|
+
id: z.string().refine(isValidNsid, {
|
|
313
306
|
message: 'Must be a valid NSID',
|
|
314
307
|
}),
|
|
315
|
-
revision:
|
|
316
|
-
description:
|
|
317
|
-
defs:
|
|
308
|
+
revision: z.number().optional(),
|
|
309
|
+
description: z.string().optional(),
|
|
310
|
+
defs: z.record(z.string(), lexUserType),
|
|
318
311
|
})
|
|
319
312
|
.refine((doc) => {
|
|
320
313
|
for (const [defId, def] of Object.entries(doc.defs)) {
|
|
@@ -333,26 +326,23 @@ exports.lexiconDoc = zod_1.z
|
|
|
333
326
|
});
|
|
334
327
|
// helpers
|
|
335
328
|
// =
|
|
336
|
-
function isValidLexiconDoc(v) {
|
|
337
|
-
return
|
|
329
|
+
export function isValidLexiconDoc(v) {
|
|
330
|
+
return lexiconDoc.safeParse(v).success;
|
|
338
331
|
}
|
|
339
|
-
function isObj(v) {
|
|
332
|
+
export function isObj(v) {
|
|
340
333
|
return v != null && typeof v === 'object';
|
|
341
334
|
}
|
|
342
|
-
function isDiscriminatedObject(v) {
|
|
335
|
+
export function isDiscriminatedObject(v) {
|
|
343
336
|
return isObj(v) && '$type' in v && typeof v.$type === 'string';
|
|
344
337
|
}
|
|
345
|
-
function parseLexiconDoc(v) {
|
|
346
|
-
|
|
338
|
+
export function parseLexiconDoc(v) {
|
|
339
|
+
lexiconDoc.parse(v);
|
|
347
340
|
return v;
|
|
348
341
|
}
|
|
349
|
-
class ValidationError extends Error {
|
|
342
|
+
export class ValidationError extends Error {
|
|
350
343
|
}
|
|
351
|
-
|
|
352
|
-
class InvalidLexiconError extends Error {
|
|
344
|
+
export class InvalidLexiconError extends Error {
|
|
353
345
|
}
|
|
354
|
-
|
|
355
|
-
class LexiconDefNotFoundError extends Error {
|
|
346
|
+
export class LexiconDefNotFoundError extends Error {
|
|
356
347
|
}
|
|
357
|
-
exports.LexiconDefNotFoundError = LexiconDefNotFoundError;
|
|
358
348
|
//# sourceMappingURL=types.js.map
|