@atproto/lexicon 0.6.1 → 0.7.0-next.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 +28 -0
- package/dist/blob-refs.d.ts +4 -4
- package/dist/blob-refs.d.ts.map +1 -1
- package/dist/blob-refs.js +20 -46
- 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.d.ts.map +1 -1
- package/dist/serialize.js +22 -32
- package/dist/serialize.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +193 -204
- 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 -51
- 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.js → jest.config.cjs} +8 -1
- package/package.json +17 -9
- package/src/blob-refs.ts +0 -2
- package/src/index.ts +4 -4
- package/src/lexicons.ts +4 -4
- package/src/serialize.ts +1 -3
- package/src/types.ts +1 -3
- 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 -4
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexicons } from '../lexicons';
|
|
2
|
-
import { LexUserType, ValidationResult } from '../types';
|
|
1
|
+
import { Lexicons } from '../lexicons.js';
|
|
2
|
+
import { LexUserType, ValidationResult } from '../types.js';
|
|
3
3
|
export declare function validate(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
|
|
4
4
|
//# sourceMappingURL=primitives.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/validators/primitives.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/validators/primitives.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAKL,WAAW,EAEX,gBAAgB,EACjB,MAAM,aAAa,CAAA;AAGpB,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,OAAO,GACb,gBAAgB,CAoBlB"}
|
|
@@ -1,44 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.validate = validate;
|
|
37
|
-
const cid_1 = require("multiformats/cid");
|
|
38
|
-
const common_web_1 = require("@atproto/common-web");
|
|
39
|
-
const types_1 = require("../types");
|
|
40
|
-
const formats = __importStar(require("./formats"));
|
|
41
|
-
function validate(lexicons, path, def, value) {
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { graphemeLen, utf8Len } from '@atproto/common-web';
|
|
3
|
+
import { ValidationError, } from '../types.js';
|
|
4
|
+
import * as formats from './formats.js';
|
|
5
|
+
export function validate(lexicons, path, def, value) {
|
|
42
6
|
switch (def.type) {
|
|
43
7
|
case 'boolean':
|
|
44
8
|
return boolean(lexicons, path, def, value);
|
|
@@ -55,7 +19,7 @@ function validate(lexicons, path, def, value) {
|
|
|
55
19
|
default:
|
|
56
20
|
return {
|
|
57
21
|
success: false,
|
|
58
|
-
error: new
|
|
22
|
+
error: new ValidationError(`Unexpected lexicon type: ${def.type}`),
|
|
59
23
|
};
|
|
60
24
|
}
|
|
61
25
|
}
|
|
@@ -69,13 +33,13 @@ function boolean(lexicons, path, def, value) {
|
|
|
69
33
|
}
|
|
70
34
|
return {
|
|
71
35
|
success: false,
|
|
72
|
-
error: new
|
|
36
|
+
error: new ValidationError(`${path} must be a boolean`),
|
|
73
37
|
};
|
|
74
38
|
}
|
|
75
39
|
else if (type !== 'boolean') {
|
|
76
40
|
return {
|
|
77
41
|
success: false,
|
|
78
|
-
error: new
|
|
42
|
+
error: new ValidationError(`${path} must be a boolean`),
|
|
79
43
|
};
|
|
80
44
|
}
|
|
81
45
|
// const
|
|
@@ -83,7 +47,7 @@ function boolean(lexicons, path, def, value) {
|
|
|
83
47
|
if (value !== def.const) {
|
|
84
48
|
return {
|
|
85
49
|
success: false,
|
|
86
|
-
error: new
|
|
50
|
+
error: new ValidationError(`${path} must be ${def.const}`),
|
|
87
51
|
};
|
|
88
52
|
}
|
|
89
53
|
}
|
|
@@ -99,13 +63,13 @@ function integer(lexicons, path, def, value) {
|
|
|
99
63
|
}
|
|
100
64
|
return {
|
|
101
65
|
success: false,
|
|
102
|
-
error: new
|
|
66
|
+
error: new ValidationError(`${path} must be an integer`),
|
|
103
67
|
};
|
|
104
68
|
}
|
|
105
69
|
else if (!Number.isInteger(value)) {
|
|
106
70
|
return {
|
|
107
71
|
success: false,
|
|
108
|
-
error: new
|
|
72
|
+
error: new ValidationError(`${path} must be an integer`),
|
|
109
73
|
};
|
|
110
74
|
}
|
|
111
75
|
// const
|
|
@@ -113,7 +77,7 @@ function integer(lexicons, path, def, value) {
|
|
|
113
77
|
if (value !== def.const) {
|
|
114
78
|
return {
|
|
115
79
|
success: false,
|
|
116
|
-
error: new
|
|
80
|
+
error: new ValidationError(`${path} must be ${def.const}`),
|
|
117
81
|
};
|
|
118
82
|
}
|
|
119
83
|
}
|
|
@@ -122,7 +86,7 @@ function integer(lexicons, path, def, value) {
|
|
|
122
86
|
if (!def.enum.includes(value)) {
|
|
123
87
|
return {
|
|
124
88
|
success: false,
|
|
125
|
-
error: new
|
|
89
|
+
error: new ValidationError(`${path} must be one of (${def.enum.join('|')})`),
|
|
126
90
|
};
|
|
127
91
|
}
|
|
128
92
|
}
|
|
@@ -131,7 +95,7 @@ function integer(lexicons, path, def, value) {
|
|
|
131
95
|
if (value > def.maximum) {
|
|
132
96
|
return {
|
|
133
97
|
success: false,
|
|
134
|
-
error: new
|
|
98
|
+
error: new ValidationError(`${path} can not be greater than ${def.maximum}`),
|
|
135
99
|
};
|
|
136
100
|
}
|
|
137
101
|
}
|
|
@@ -140,7 +104,7 @@ function integer(lexicons, path, def, value) {
|
|
|
140
104
|
if (value < def.minimum) {
|
|
141
105
|
return {
|
|
142
106
|
success: false,
|
|
143
|
-
error: new
|
|
107
|
+
error: new ValidationError(`${path} can not be less than ${def.minimum}`),
|
|
144
108
|
};
|
|
145
109
|
}
|
|
146
110
|
}
|
|
@@ -155,13 +119,13 @@ function string(lexicons, path, def, value) {
|
|
|
155
119
|
}
|
|
156
120
|
return {
|
|
157
121
|
success: false,
|
|
158
|
-
error: new
|
|
122
|
+
error: new ValidationError(`${path} must be a string`),
|
|
159
123
|
};
|
|
160
124
|
}
|
|
161
125
|
else if (typeof value !== 'string') {
|
|
162
126
|
return {
|
|
163
127
|
success: false,
|
|
164
|
-
error: new
|
|
128
|
+
error: new ValidationError(`${path} must be a string`),
|
|
165
129
|
};
|
|
166
130
|
}
|
|
167
131
|
// const
|
|
@@ -169,7 +133,7 @@ function string(lexicons, path, def, value) {
|
|
|
169
133
|
if (value !== def.const) {
|
|
170
134
|
return {
|
|
171
135
|
success: false,
|
|
172
|
-
error: new
|
|
136
|
+
error: new ValidationError(`${path} must be ${def.const}`),
|
|
173
137
|
};
|
|
174
138
|
}
|
|
175
139
|
}
|
|
@@ -178,7 +142,7 @@ function string(lexicons, path, def, value) {
|
|
|
178
142
|
if (!def.enum.includes(value)) {
|
|
179
143
|
return {
|
|
180
144
|
success: false,
|
|
181
|
-
error: new
|
|
145
|
+
error: new ValidationError(`${path} must be one of (${def.enum.join('|')})`),
|
|
182
146
|
};
|
|
183
147
|
}
|
|
184
148
|
}
|
|
@@ -189,7 +153,7 @@ function string(lexicons, path, def, value) {
|
|
|
189
153
|
if (typeof def.minLength === 'number' && value.length * 3 < def.minLength) {
|
|
190
154
|
return {
|
|
191
155
|
success: false,
|
|
192
|
-
error: new
|
|
156
|
+
error: new ValidationError(`${path} must not be shorter than ${def.minLength} characters`),
|
|
193
157
|
};
|
|
194
158
|
}
|
|
195
159
|
// If the JavaScript string length * 3 is within the maximum limit,
|
|
@@ -202,12 +166,12 @@ function string(lexicons, path, def, value) {
|
|
|
202
166
|
canSkipUtf8LenChecks = true;
|
|
203
167
|
}
|
|
204
168
|
if (!canSkipUtf8LenChecks) {
|
|
205
|
-
const len =
|
|
169
|
+
const len = utf8Len(value);
|
|
206
170
|
if (typeof def.maxLength === 'number') {
|
|
207
171
|
if (len > def.maxLength) {
|
|
208
172
|
return {
|
|
209
173
|
success: false,
|
|
210
|
-
error: new
|
|
174
|
+
error: new ValidationError(`${path} must not be longer than ${def.maxLength} characters`),
|
|
211
175
|
};
|
|
212
176
|
}
|
|
213
177
|
}
|
|
@@ -215,7 +179,7 @@ function string(lexicons, path, def, value) {
|
|
|
215
179
|
if (len < def.minLength) {
|
|
216
180
|
return {
|
|
217
181
|
success: false,
|
|
218
|
-
error: new
|
|
182
|
+
error: new ValidationError(`${path} must not be shorter than ${def.minLength} characters`),
|
|
219
183
|
};
|
|
220
184
|
}
|
|
221
185
|
}
|
|
@@ -243,7 +207,7 @@ function string(lexicons, path, def, value) {
|
|
|
243
207
|
// Fail early.
|
|
244
208
|
return {
|
|
245
209
|
success: false,
|
|
246
|
-
error: new
|
|
210
|
+
error: new ValidationError(`${path} must not be shorter than ${def.minGraphemes} graphemes`),
|
|
247
211
|
};
|
|
248
212
|
}
|
|
249
213
|
else {
|
|
@@ -251,12 +215,12 @@ function string(lexicons, path, def, value) {
|
|
|
251
215
|
}
|
|
252
216
|
}
|
|
253
217
|
if (needsMaxGraphemesCheck || needsMinGraphemesCheck) {
|
|
254
|
-
const len =
|
|
218
|
+
const len = graphemeLen(value);
|
|
255
219
|
if (typeof def.maxGraphemes === 'number') {
|
|
256
220
|
if (len > def.maxGraphemes) {
|
|
257
221
|
return {
|
|
258
222
|
success: false,
|
|
259
|
-
error: new
|
|
223
|
+
error: new ValidationError(`${path} must not be longer than ${def.maxGraphemes} graphemes`),
|
|
260
224
|
};
|
|
261
225
|
}
|
|
262
226
|
}
|
|
@@ -264,7 +228,7 @@ function string(lexicons, path, def, value) {
|
|
|
264
228
|
if (len < def.minGraphemes) {
|
|
265
229
|
return {
|
|
266
230
|
success: false,
|
|
267
|
-
error: new
|
|
231
|
+
error: new ValidationError(`${path} must not be shorter than ${def.minGraphemes} graphemes`),
|
|
268
232
|
};
|
|
269
233
|
}
|
|
270
234
|
}
|
|
@@ -303,7 +267,7 @@ function bytes(lexicons, path, def, value) {
|
|
|
303
267
|
if (!value || !(value instanceof Uint8Array)) {
|
|
304
268
|
return {
|
|
305
269
|
success: false,
|
|
306
|
-
error: new
|
|
270
|
+
error: new ValidationError(`${path} must be a byte array`),
|
|
307
271
|
};
|
|
308
272
|
}
|
|
309
273
|
// maxLength
|
|
@@ -311,7 +275,7 @@ function bytes(lexicons, path, def, value) {
|
|
|
311
275
|
if (value.byteLength > def.maxLength) {
|
|
312
276
|
return {
|
|
313
277
|
success: false,
|
|
314
|
-
error: new
|
|
278
|
+
error: new ValidationError(`${path} must not be larger than ${def.maxLength} bytes`),
|
|
315
279
|
};
|
|
316
280
|
}
|
|
317
281
|
}
|
|
@@ -320,17 +284,17 @@ function bytes(lexicons, path, def, value) {
|
|
|
320
284
|
if (value.byteLength < def.minLength) {
|
|
321
285
|
return {
|
|
322
286
|
success: false,
|
|
323
|
-
error: new
|
|
287
|
+
error: new ValidationError(`${path} must not be smaller than ${def.minLength} bytes`),
|
|
324
288
|
};
|
|
325
289
|
}
|
|
326
290
|
}
|
|
327
291
|
return { success: true, value };
|
|
328
292
|
}
|
|
329
293
|
function cidLink(lexicons, path, def, value) {
|
|
330
|
-
if (
|
|
294
|
+
if (CID.asCID(value) === null) {
|
|
331
295
|
return {
|
|
332
296
|
success: false,
|
|
333
|
-
error: new
|
|
297
|
+
error: new ValidationError(`${path} must be a CID`),
|
|
334
298
|
};
|
|
335
299
|
}
|
|
336
300
|
return { success: true, value };
|
|
@@ -340,7 +304,7 @@ function unknown(lexicons, path, def, value) {
|
|
|
340
304
|
if (!value || typeof value !== 'object') {
|
|
341
305
|
return {
|
|
342
306
|
success: false,
|
|
343
|
-
error: new
|
|
307
|
+
error: new ValidationError(`${path} must be an object`),
|
|
344
308
|
};
|
|
345
309
|
}
|
|
346
310
|
return { success: true, value };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/validators/primitives.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,4BAyBC;AAvCD,0CAAsC;AACtC,oDAA0D;AAE1D,oCAQiB;AACjB,mDAAoC;AAEpC,SAAgB,QAAQ,CACtB,QAAkB,EAClB,IAAY,EACZ,GAAgB,EAChB,KAAc;IAEd,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC5C,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,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AAI,EAAE,CAAC;QAC9B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,uBAAe,CAAC,GAAG,IAAI,gBAAgB,CAAC;SACpD,CAAA;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACjC,CAAC;AAED,SAAS,OAAO,CACd,QAAkB,EAClB,IAAY,EACZ,GAAgB,EAChB,KAAc;IAEd,OAAO;IACP,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,uBAAe,CAAC,GAAG,IAAI,oBAAoB,CAAC;SACxD,CAAA;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACjC,CAAC","sourcesContent":["import { CID } from 'multiformats/cid'\nimport { graphemeLen, utf8Len } from '@atproto/common-web'\nimport { Lexicons } from '../lexicons'\nimport {\n LexBoolean,\n LexBytes,\n LexInteger,\n LexString,\n LexUserType,\n ValidationError,\n ValidationResult,\n} from '../types'\nimport * as formats from './formats'\n\nexport function validate(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n switch (def.type) {\n case 'boolean':\n return boolean(lexicons, path, def, value)\n case 'integer':\n return integer(lexicons, path, def, value)\n case 'string':\n return string(lexicons, path, def, value)\n case 'bytes':\n return bytes(lexicons, path, def, value)\n case 'cid-link':\n return cidLink(lexicons, path, def, value)\n case 'unknown':\n return unknown(lexicons, path, def, value)\n default:\n return {\n success: false,\n error: new ValidationError(`Unexpected lexicon type: ${def.type}`),\n }\n }\n}\n\nfunction boolean(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexBoolean\n\n // type\n const type = typeof value\n if (type === 'undefined') {\n if (typeof def.default === 'boolean') {\n return { success: true, value: def.default }\n }\n return {\n success: false,\n error: new ValidationError(`${path} must be a boolean`),\n }\n } else if (type !== 'boolean') {\n return {\n success: false,\n error: new ValidationError(`${path} must be a boolean`),\n }\n }\n\n // const\n if (typeof def.const === 'boolean') {\n if (value !== def.const) {\n return {\n success: false,\n error: new ValidationError(`${path} must be ${def.const}`),\n }\n }\n }\n\n return { success: true, value }\n}\n\nfunction integer(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexInteger\n\n // type\n const type = typeof value\n if (type === 'undefined') {\n if (typeof def.default === 'number') {\n return { success: true, value: def.default }\n }\n return {\n success: false,\n error: new ValidationError(`${path} must be an integer`),\n }\n } else if (!Number.isInteger(value)) {\n return {\n success: false,\n error: new ValidationError(`${path} must be an integer`),\n }\n }\n\n // const\n if (typeof def.const === 'number') {\n if (value !== def.const) {\n return {\n success: false,\n error: new ValidationError(`${path} must be ${def.const}`),\n }\n }\n }\n\n // enum\n if (Array.isArray(def.enum)) {\n if (!def.enum.includes(value as number)) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must be one of (${def.enum.join('|')})`,\n ),\n }\n }\n }\n\n // maximum\n if (typeof def.maximum === 'number') {\n if ((value as number) > def.maximum) {\n return {\n success: false,\n error: new ValidationError(\n `${path} can not be greater than ${def.maximum}`,\n ),\n }\n }\n }\n\n // minimum\n if (typeof def.minimum === 'number') {\n if ((value as number) < def.minimum) {\n return {\n success: false,\n error: new ValidationError(\n `${path} can not be less than ${def.minimum}`,\n ),\n }\n }\n }\n\n return { success: true, value }\n}\n\nfunction string(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexString\n\n // type\n if (typeof value === 'undefined') {\n if (typeof def.default === 'string') {\n return { success: true, value: def.default }\n }\n return {\n success: false,\n error: new ValidationError(`${path} must be a string`),\n }\n } else if (typeof value !== 'string') {\n return {\n success: false,\n error: new ValidationError(`${path} must be a string`),\n }\n }\n\n // const\n if (typeof def.const === 'string') {\n if (value !== def.const) {\n return {\n success: false,\n error: new ValidationError(`${path} must be ${def.const}`),\n }\n }\n }\n\n // enum\n if (Array.isArray(def.enum)) {\n if (!def.enum.includes(value as string)) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must be one of (${def.enum.join('|')})`,\n ),\n }\n }\n }\n\n // maxLength and minLength\n if (typeof def.minLength === 'number' || typeof def.maxLength === 'number') {\n // If the JavaScript string length * 3 is below the maximum limit,\n // its UTF8 length (which <= .length * 3) will also be below.\n if (typeof def.minLength === 'number' && value.length * 3 < def.minLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minLength} characters`,\n ),\n }\n }\n\n // If the JavaScript string length * 3 is within the maximum limit,\n // its UTF8 length (which <= .length * 3) will also be within.\n // When there's no minimal length, this lets us skip the UTF8 length check.\n let canSkipUtf8LenChecks = false\n if (\n typeof def.minLength === 'undefined' &&\n typeof def.maxLength === 'number' &&\n value.length * 3 <= def.maxLength\n ) {\n canSkipUtf8LenChecks = true\n }\n\n if (!canSkipUtf8LenChecks) {\n const len = utf8Len(value)\n\n if (typeof def.maxLength === 'number') {\n if (len > def.maxLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be longer than ${def.maxLength} characters`,\n ),\n }\n }\n }\n\n if (typeof def.minLength === 'number') {\n if (len < def.minLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minLength} characters`,\n ),\n }\n }\n }\n }\n }\n\n // maxGraphemes and minGraphemes\n if (\n typeof def.maxGraphemes === 'number' ||\n typeof def.minGraphemes === 'number'\n ) {\n let needsMaxGraphemesCheck = false\n let needsMinGraphemesCheck = false\n\n if (typeof def.maxGraphemes === 'number') {\n if (value.length <= def.maxGraphemes) {\n // If the JavaScript string length (UTF-16) is within the maximum limit,\n // its grapheme length (which <= .length) will also be within.\n needsMaxGraphemesCheck = false\n } else {\n needsMaxGraphemesCheck = true\n }\n }\n\n if (typeof def.minGraphemes === 'number') {\n if (value.length < def.minGraphemes) {\n // If the JavaScript string length (UTF-16) is below the minimal limit,\n // its grapheme length (which <= .length) will also be below.\n // Fail early.\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minGraphemes} graphemes`,\n ),\n }\n } else {\n needsMinGraphemesCheck = true\n }\n }\n\n if (needsMaxGraphemesCheck || needsMinGraphemesCheck) {\n const len = graphemeLen(value)\n\n if (typeof def.maxGraphemes === 'number') {\n if (len > def.maxGraphemes) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be longer than ${def.maxGraphemes} graphemes`,\n ),\n }\n }\n }\n\n if (typeof def.minGraphemes === 'number') {\n if (len < def.minGraphemes) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minGraphemes} graphemes`,\n ),\n }\n }\n }\n }\n }\n\n if (typeof def.format === 'string') {\n switch (def.format) {\n case 'datetime':\n return formats.datetime(path, value)\n case 'uri':\n return formats.uri(path, value)\n case 'at-uri':\n return formats.atUri(path, value)\n case 'did':\n return formats.did(path, value)\n case 'handle':\n return formats.handle(path, value)\n case 'at-identifier':\n return formats.atIdentifier(path, value)\n case 'nsid':\n return formats.nsid(path, value)\n case 'cid':\n return formats.cid(path, value)\n case 'language':\n return formats.language(path, value)\n case 'tid':\n return formats.tid(path, value)\n case 'record-key':\n return formats.recordKey(path, value)\n }\n }\n\n return { success: true, value }\n}\n\nfunction bytes(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexBytes\n\n if (!value || !(value instanceof Uint8Array)) {\n return {\n success: false,\n error: new ValidationError(`${path} must be a byte array`),\n }\n }\n\n // maxLength\n if (typeof def.maxLength === 'number') {\n if (value.byteLength > def.maxLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be larger than ${def.maxLength} bytes`,\n ),\n }\n }\n }\n\n // minLength\n if (typeof def.minLength === 'number') {\n if (value.byteLength < def.minLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be smaller than ${def.minLength} bytes`,\n ),\n }\n }\n }\n\n return { success: true, value }\n}\n\nfunction cidLink(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n if (CID.asCID(value) === null) {\n return {\n success: false,\n error: new ValidationError(`${path} must be a CID`),\n }\n }\n\n return { success: true, value }\n}\n\nfunction unknown(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n // type\n if (!value || typeof value !== 'object') {\n return {\n success: false,\n error: new ValidationError(`${path} must be an object`),\n }\n }\n\n return { success: true, value }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/validators/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,EAML,eAAe,GAEhB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,MAAM,UAAU,QAAQ,CACtB,QAAkB,EAClB,IAAY,EACZ,GAAgB,EAChB,KAAc;IAEd,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC5C,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC5C,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC3C,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC1C,KAAK,UAAU;YACb,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,G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K,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,eAAe,CAAC,GAAG,IAAI,oBAAoB,CAAC;SACxD,CAAA;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACjC,CAAC","sourcesContent":["import { CID } from 'multiformats/cid'\nimport { graphemeLen, utf8Len } from '@atproto/common-web'\nimport { Lexicons } from '../lexicons.js'\nimport {\n LexBoolean,\n LexBytes,\n LexInteger,\n LexString,\n LexUserType,\n ValidationError,\n ValidationResult,\n} from '../types.js'\nimport * as formats from './formats.js'\n\nexport function validate(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n switch (def.type) {\n case 'boolean':\n return boolean(lexicons, path, def, value)\n case 'integer':\n return integer(lexicons, path, def, value)\n case 'string':\n return string(lexicons, path, def, value)\n case 'bytes':\n return bytes(lexicons, path, def, value)\n case 'cid-link':\n return cidLink(lexicons, path, def, value)\n case 'unknown':\n return unknown(lexicons, path, def, value)\n default:\n return {\n success: false,\n error: new ValidationError(`Unexpected lexicon type: ${def.type}`),\n }\n }\n}\n\nfunction boolean(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexBoolean\n\n // type\n const type = typeof value\n if (type === 'undefined') {\n if (typeof def.default === 'boolean') {\n return { success: true, value: def.default }\n }\n return {\n success: false,\n error: new ValidationError(`${path} must be a boolean`),\n }\n } else if (type !== 'boolean') {\n return {\n success: false,\n error: new ValidationError(`${path} must be a boolean`),\n }\n }\n\n // const\n if (typeof def.const === 'boolean') {\n if (value !== def.const) {\n return {\n success: false,\n error: new ValidationError(`${path} must be ${def.const}`),\n }\n }\n }\n\n return { success: true, value }\n}\n\nfunction integer(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexInteger\n\n // type\n const type = typeof value\n if (type === 'undefined') {\n if (typeof def.default === 'number') {\n return { success: true, value: def.default }\n }\n return {\n success: false,\n error: new ValidationError(`${path} must be an integer`),\n }\n } else if (!Number.isInteger(value)) {\n return {\n success: false,\n error: new ValidationError(`${path} must be an integer`),\n }\n }\n\n // const\n if (typeof def.const === 'number') {\n if (value !== def.const) {\n return {\n success: false,\n error: new ValidationError(`${path} must be ${def.const}`),\n }\n }\n }\n\n // enum\n if (Array.isArray(def.enum)) {\n if (!def.enum.includes(value as number)) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must be one of (${def.enum.join('|')})`,\n ),\n }\n }\n }\n\n // maximum\n if (typeof def.maximum === 'number') {\n if ((value as number) > def.maximum) {\n return {\n success: false,\n error: new ValidationError(\n `${path} can not be greater than ${def.maximum}`,\n ),\n }\n }\n }\n\n // minimum\n if (typeof def.minimum === 'number') {\n if ((value as number) < def.minimum) {\n return {\n success: false,\n error: new ValidationError(\n `${path} can not be less than ${def.minimum}`,\n ),\n }\n }\n }\n\n return { success: true, value }\n}\n\nfunction string(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexString\n\n // type\n if (typeof value === 'undefined') {\n if (typeof def.default === 'string') {\n return { success: true, value: def.default }\n }\n return {\n success: false,\n error: new ValidationError(`${path} must be a string`),\n }\n } else if (typeof value !== 'string') {\n return {\n success: false,\n error: new ValidationError(`${path} must be a string`),\n }\n }\n\n // const\n if (typeof def.const === 'string') {\n if (value !== def.const) {\n return {\n success: false,\n error: new ValidationError(`${path} must be ${def.const}`),\n }\n }\n }\n\n // enum\n if (Array.isArray(def.enum)) {\n if (!def.enum.includes(value as string)) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must be one of (${def.enum.join('|')})`,\n ),\n }\n }\n }\n\n // maxLength and minLength\n if (typeof def.minLength === 'number' || typeof def.maxLength === 'number') {\n // If the JavaScript string length * 3 is below the maximum limit,\n // its UTF8 length (which <= .length * 3) will also be below.\n if (typeof def.minLength === 'number' && value.length * 3 < def.minLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minLength} characters`,\n ),\n }\n }\n\n // If the JavaScript string length * 3 is within the maximum limit,\n // its UTF8 length (which <= .length * 3) will also be within.\n // When there's no minimal length, this lets us skip the UTF8 length check.\n let canSkipUtf8LenChecks = false\n if (\n typeof def.minLength === 'undefined' &&\n typeof def.maxLength === 'number' &&\n value.length * 3 <= def.maxLength\n ) {\n canSkipUtf8LenChecks = true\n }\n\n if (!canSkipUtf8LenChecks) {\n const len = utf8Len(value)\n\n if (typeof def.maxLength === 'number') {\n if (len > def.maxLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be longer than ${def.maxLength} characters`,\n ),\n }\n }\n }\n\n if (typeof def.minLength === 'number') {\n if (len < def.minLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minLength} characters`,\n ),\n }\n }\n }\n }\n }\n\n // maxGraphemes and minGraphemes\n if (\n typeof def.maxGraphemes === 'number' ||\n typeof def.minGraphemes === 'number'\n ) {\n let needsMaxGraphemesCheck = false\n let needsMinGraphemesCheck = false\n\n if (typeof def.maxGraphemes === 'number') {\n if (value.length <= def.maxGraphemes) {\n // If the JavaScript string length (UTF-16) is within the maximum limit,\n // its grapheme length (which <= .length) will also be within.\n needsMaxGraphemesCheck = false\n } else {\n needsMaxGraphemesCheck = true\n }\n }\n\n if (typeof def.minGraphemes === 'number') {\n if (value.length < def.minGraphemes) {\n // If the JavaScript string length (UTF-16) is below the minimal limit,\n // its grapheme length (which <= .length) will also be below.\n // Fail early.\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minGraphemes} graphemes`,\n ),\n }\n } else {\n needsMinGraphemesCheck = true\n }\n }\n\n if (needsMaxGraphemesCheck || needsMinGraphemesCheck) {\n const len = graphemeLen(value)\n\n if (typeof def.maxGraphemes === 'number') {\n if (len > def.maxGraphemes) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be longer than ${def.maxGraphemes} graphemes`,\n ),\n }\n }\n }\n\n if (typeof def.minGraphemes === 'number') {\n if (len < def.minGraphemes) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be shorter than ${def.minGraphemes} graphemes`,\n ),\n }\n }\n }\n }\n }\n\n if (typeof def.format === 'string') {\n switch (def.format) {\n case 'datetime':\n return formats.datetime(path, value)\n case 'uri':\n return formats.uri(path, value)\n case 'at-uri':\n return formats.atUri(path, value)\n case 'did':\n return formats.did(path, value)\n case 'handle':\n return formats.handle(path, value)\n case 'at-identifier':\n return formats.atIdentifier(path, value)\n case 'nsid':\n return formats.nsid(path, value)\n case 'cid':\n return formats.cid(path, value)\n case 'language':\n return formats.language(path, value)\n case 'tid':\n return formats.tid(path, value)\n case 'record-key':\n return formats.recordKey(path, value)\n }\n }\n\n return { success: true, value }\n}\n\nfunction bytes(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n def = def as LexBytes\n\n if (!value || !(value instanceof Uint8Array)) {\n return {\n success: false,\n error: new ValidationError(`${path} must be a byte array`),\n }\n }\n\n // maxLength\n if (typeof def.maxLength === 'number') {\n if (value.byteLength > def.maxLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be larger than ${def.maxLength} bytes`,\n ),\n }\n }\n }\n\n // minLength\n if (typeof def.minLength === 'number') {\n if (value.byteLength < def.minLength) {\n return {\n success: false,\n error: new ValidationError(\n `${path} must not be smaller than ${def.minLength} bytes`,\n ),\n }\n }\n }\n\n return { success: true, value }\n}\n\nfunction cidLink(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n if (CID.asCID(value) === null) {\n return {\n success: false,\n error: new ValidationError(`${path} must be a CID`),\n }\n }\n\n return { success: true, value }\n}\n\nfunction unknown(\n lexicons: Lexicons,\n path: string,\n def: LexUserType,\n value: unknown,\n): ValidationResult {\n // type\n if (!value || typeof value !== 'object') {\n return {\n success: false,\n error: new ValidationError(`${path} must be an object`),\n }\n }\n\n return { success: true, value }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexicons } from '../lexicons';
|
|
2
|
-
import { LexXrpcParameters, ValidationResult } from '../types';
|
|
1
|
+
import { Lexicons } from '../lexicons.js';
|
|
2
|
+
import { LexXrpcParameters, ValidationResult } from '../types.js';
|
|
3
3
|
export declare function params(lexicons: Lexicons, path: string, def: LexXrpcParameters, val: unknown): ValidationResult<Record<string, unknown>>;
|
|
4
4
|
//# sourceMappingURL=xrpc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc.d.ts","sourceRoot":"","sources":["../../src/validators/xrpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"xrpc.d.ts","sourceRoot":"","sources":["../../src/validators/xrpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EACL,iBAAiB,EAEjB,gBAAgB,EACjB,MAAM,aAAa,CAAA;AAIpB,wBAAgB,MAAM,CACpB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,iBAAiB,EACtB,GAAG,EAAE,OAAO,GACX,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsC3C"}
|
package/dist/validators/xrpc.js
CHANGED
|
@@ -1,43 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.params = params;
|
|
37
|
-
const types_1 = require("../types");
|
|
38
|
-
const complex_1 = require("./complex");
|
|
39
|
-
const PrimitiveValidators = __importStar(require("./primitives"));
|
|
40
|
-
function params(lexicons, path, def, val) {
|
|
1
|
+
import { ValidationError, } from '../types.js';
|
|
2
|
+
import { array } from './complex.js';
|
|
3
|
+
import * as PrimitiveValidators from './primitives.js';
|
|
4
|
+
export function params(lexicons, path, def, val) {
|
|
41
5
|
// type
|
|
42
6
|
const value = val && typeof val === 'object' ? val : {};
|
|
43
7
|
const requiredProps = new Set(def.required ?? []);
|
|
@@ -47,7 +11,7 @@ function params(lexicons, path, def, val) {
|
|
|
47
11
|
for (const key in def.properties) {
|
|
48
12
|
const propDef = def.properties[key];
|
|
49
13
|
const validated = propDef.type === 'array'
|
|
50
|
-
?
|
|
14
|
+
? array(lexicons, key, propDef, value[key])
|
|
51
15
|
: PrimitiveValidators.validate(lexicons, key, propDef, value[key]);
|
|
52
16
|
const propValue = validated.success ? validated.value : value[key];
|
|
53
17
|
const propIsUndefined = typeof propValue === 'undefined';
|
|
@@ -55,7 +19,7 @@ function params(lexicons, path, def, val) {
|
|
|
55
19
|
if (propIsUndefined && requiredProps.has(key)) {
|
|
56
20
|
return {
|
|
57
21
|
success: false,
|
|
58
|
-
error: new
|
|
22
|
+
error: new ValidationError(`${path} must have the property "${key}"`),
|
|
59
23
|
};
|
|
60
24
|
}
|
|
61
25
|
else if (!propIsUndefined && !validated.success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../../src/validators/xrpc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../../src/validators/xrpc.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,GAEhB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,KAAK,mBAAmB,MAAM,iBAAiB,CAAA;AAEtD,MAAM,UAAU,MAAM,CACpB,QAAkB,EAClB,IAAY,EACZ,GAAsB,EACtB,GAAY;IAEZ,OAAO;IACP,MAAM,KAAK,GAAG,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IAEvD,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;IAEjD,aAAa;IACb,IAAI,WAAW,GAAG,KAAgC,CAAA;IAClD,IAAI,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QACvC,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,GAAG,C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ameters,\n ValidationError,\n ValidationResult,\n} from '../types.js'\nimport { array } from './complex.js'\nimport * as PrimitiveValidators from './primitives.js'\n\nexport function params(\n lexicons: Lexicons,\n path: string,\n def: LexXrpcParameters,\n val: unknown,\n): ValidationResult<Record<string, unknown>> {\n // type\n const value = val && typeof val === 'object' ? val : {}\n\n const requiredProps = new Set(def.required ?? [])\n\n // properties\n let resultValue = value as Record<string, unknown>\n if (typeof def.properties === 'object') {\n for (const key in def.properties) {\n const propDef = def.properties[key]\n const validated =\n propDef.type === 'array'\n ? array(lexicons, key, propDef, value[key])\n : PrimitiveValidators.validate(lexicons, key, propDef, value[key])\n const propValue = validated.success ? validated.value : value[key]\n const propIsUndefined = typeof propValue === 'undefined'\n // Return error for bad validation, giving required rule precedence\n if (propIsUndefined && requiredProps.has(key)) {\n return {\n success: false,\n error: new ValidationError(`${path} must have the property \"${key}\"`),\n }\n } else if (!propIsUndefined && !validated.success) {\n return validated\n }\n // Adjust value based on e.g. applied defaults, cloning shallowly if there was a changed value\n if (propValue !== value[key]) {\n if (resultValue === value) {\n // Lazy shallow clone\n resultValue = { ...value }\n }\n resultValue[key] = propValue\n }\n }\n }\n\n return { success: true, value: resultValue }\n}\n"]}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/** @type {import('jest').Config} */
|
|
2
2
|
module.exports = {
|
|
3
3
|
displayName: 'Lexicon',
|
|
4
|
-
transform: {
|
|
4
|
+
transform: {
|
|
5
|
+
'^.+\\.(t|j)s$': [
|
|
6
|
+
'@swc/jest',
|
|
7
|
+
{ jsc: { transform: {} }, module: { type: 'es6' } },
|
|
8
|
+
],
|
|
9
|
+
},
|
|
10
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
11
|
+
transformIgnorePatterns: [],
|
|
5
12
|
setupFiles: ['<rootDir>/../../jest.setup.ts'],
|
|
6
13
|
moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
|
|
7
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lexicon",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-next.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
4
7
|
"license": "MIT",
|
|
5
8
|
"description": "atproto Lexicon schema language library",
|
|
6
9
|
"keywords": [
|
|
@@ -13,21 +16,26 @@
|
|
|
13
16
|
"url": "https://github.com/bluesky-social/atproto",
|
|
14
17
|
"directory": "packages/lexicon"
|
|
15
18
|
},
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"types": "dist/index.d.ts",
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"iso-datestring-validator": "^2.2.2",
|
|
20
|
-
"multiformats": "^
|
|
21
|
+
"multiformats": "^13.0.0",
|
|
21
22
|
"zod": "^3.23.8",
|
|
22
|
-
"@atproto/
|
|
23
|
-
"@atproto/
|
|
23
|
+
"@atproto/syntax": "^0.6.0-next.0",
|
|
24
|
+
"@atproto/common-web": "^0.5.0-next.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"jest": "^
|
|
27
|
-
"typescript": "^
|
|
27
|
+
"jest": "^30.0.0",
|
|
28
|
+
"typescript": "^6.0.3"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
28
36
|
},
|
|
29
37
|
"scripts": {
|
|
30
|
-
"test": "jest",
|
|
38
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
31
39
|
"build": "tsc --build tsconfig.build.json"
|
|
32
40
|
}
|
|
33
41
|
}
|
package/src/blob-refs.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './types'
|
|
2
|
-
export * from './lexicons'
|
|
3
|
-
export * from './blob-refs'
|
|
4
|
-
export * from './serialize'
|
|
1
|
+
export * from './types.js'
|
|
2
|
+
export * from './lexicons.js'
|
|
3
|
+
export * from './blob-refs.js'
|
|
4
|
+
export * from './serialize.js'
|
package/src/lexicons.ts
CHANGED
|
@@ -7,16 +7,16 @@ import {
|
|
|
7
7
|
ValidationError,
|
|
8
8
|
ValidationResult,
|
|
9
9
|
isObj,
|
|
10
|
-
} from './types'
|
|
11
|
-
import { toLexUri } from './util'
|
|
10
|
+
} from './types.js'
|
|
11
|
+
import { toLexUri } from './util.js'
|
|
12
12
|
import {
|
|
13
13
|
assertValidRecord,
|
|
14
14
|
assertValidXrpcInput,
|
|
15
15
|
assertValidXrpcMessage,
|
|
16
16
|
assertValidXrpcOutput,
|
|
17
17
|
assertValidXrpcParams,
|
|
18
|
-
} from './validation'
|
|
19
|
-
import { object as validateObject } from './validators/complex'
|
|
18
|
+
} from './validation.js'
|
|
19
|
+
import { object as validateObject } from './validators/complex.js'
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* A collection of compiled lexicons.
|
package/src/serialize.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable import/no-deprecated */
|
|
2
|
-
|
|
3
1
|
import { CID } from 'multiformats/cid'
|
|
4
2
|
import {
|
|
5
3
|
IpldValue,
|
|
@@ -8,7 +6,7 @@ import {
|
|
|
8
6
|
ipldToJson,
|
|
9
7
|
jsonToIpld,
|
|
10
8
|
} from '@atproto/common-web'
|
|
11
|
-
import { BlobRef, jsonBlobRef } from './blob-refs'
|
|
9
|
+
import { BlobRef, jsonBlobRef } from './blob-refs.js'
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* @note this is equivalent to `unknown` because of {@link IpldValue} being `unknown`.
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/* eslint-disable import/no-deprecated */
|
|
2
|
-
|
|
3
1
|
import { z } from 'zod'
|
|
4
2
|
import { validateLanguage } from '@atproto/common-web'
|
|
5
3
|
import { isValidNsid } from '@atproto/syntax'
|
|
6
|
-
import { requiredPropertiesRefinement } from './util'
|
|
4
|
+
import { requiredPropertiesRefinement } from './util.js'
|
|
7
5
|
|
|
8
6
|
export const languageSchema = z
|
|
9
7
|
.string()
|
package/src/validation.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexicons } from './lexicons'
|
|
1
|
+
import { Lexicons } from './lexicons.js'
|
|
2
2
|
import {
|
|
3
3
|
LexRecord,
|
|
4
4
|
LexRefVariant,
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
LexXrpcProcedure,
|
|
7
7
|
LexXrpcQuery,
|
|
8
8
|
LexXrpcSubscription,
|
|
9
|
-
} from './types'
|
|
10
|
-
import { object, validateOneOf } from './validators/complex'
|
|
11
|
-
import { params } from './validators/xrpc'
|
|
9
|
+
} from './types.js'
|
|
10
|
+
import { object, validateOneOf } from './validators/complex.js'
|
|
11
|
+
import { params } from './validators/xrpc.js'
|
|
12
12
|
|
|
13
13
|
export function assertValidRecord(
|
|
14
14
|
lexicons: Lexicons,
|