@atproto/lexicon 0.0.1 → 0.0.2
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.js +15 -1
- package/dist/index.js.map +2 -2
- package/dist/src/lexicons.d.ts +2 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/lexicons.ts +21 -0
- package/src/types.ts +1 -1
- package/tests/general.test.ts +49 -0
package/dist/index.js
CHANGED
|
@@ -3216,7 +3216,7 @@ function isValidLexiconDoc(v) {
|
|
|
3216
3216
|
return lexiconDoc.safeParse(v).success;
|
|
3217
3217
|
}
|
|
3218
3218
|
function isObj(obj) {
|
|
3219
|
-
return
|
|
3219
|
+
return obj !== null && typeof obj === "object";
|
|
3220
3220
|
}
|
|
3221
3221
|
function hasProp(data, prop) {
|
|
3222
3222
|
return prop in data;
|
|
@@ -3793,6 +3793,20 @@ var Lexicons = class {
|
|
|
3793
3793
|
}
|
|
3794
3794
|
return def;
|
|
3795
3795
|
}
|
|
3796
|
+
validate(lexUri, value) {
|
|
3797
|
+
lexUri = toLexUri(lexUri);
|
|
3798
|
+
const def = this.getDefOrThrow(lexUri, ["record", "object"]);
|
|
3799
|
+
if (!isObj(value)) {
|
|
3800
|
+
throw new ValidationError(`Value must be an object`);
|
|
3801
|
+
}
|
|
3802
|
+
if (def.type === "record") {
|
|
3803
|
+
return object(this, "Record", def.record, value);
|
|
3804
|
+
} else if (def.type === "object") {
|
|
3805
|
+
return object(this, "Object", def, value);
|
|
3806
|
+
} else {
|
|
3807
|
+
throw new InvalidLexiconError("Definition must be a record or object");
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3796
3810
|
assertValidRecord(lexUri, value) {
|
|
3797
3811
|
lexUri = toLexUri(lexUri);
|
|
3798
3812
|
const def = this.getDefOrThrow(lexUri, ["record"]);
|