@atproto/lexicon 0.0.1 → 0.0.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 +2 -126
- package/dist/index.js +75 -3
- package/dist/index.js.map +4 -4
- package/dist/{src/lexicons.d.ts → lexicons.d.ts} +2 -1
- package/dist/types.d.ts +30254 -59
- package/dist/{src/util.d.ts → util.d.ts} +0 -0
- package/dist/{src/validation.d.ts → validation.d.ts} +0 -0
- package/dist/{src/validators → validators}/blob.d.ts +0 -0
- package/dist/{src/validators → validators}/complex.d.ts +0 -0
- package/dist/{src/validators → validators}/primitives.d.ts +0 -0
- package/dist/{src/validators → validators}/xrpc.d.ts +0 -0
- package/package.json +8 -3
- package/src/lexicons.ts +21 -0
- package/src/types.ts +1 -1
- package/src/validators/primitives.ts +2 -2
- package/tests/_scaffolds/lexicons.ts +17 -0
- package/tests/general.test.ts +69 -16
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +1 -0
- package/update-pkg.js +14 -0
- package/dist/src/index.d.ts +0 -2
- package/dist/src/record/index.d.ts +0 -4
- package/dist/src/record/schema.d.ts +0 -9
- package/dist/src/record/schemas.d.ts +0 -10
- package/dist/src/record/util.d.ts +0 -1
- package/dist/src/record/validation.d.ts +0 -24
- package/dist/src/record/validator.d.ts +0 -17
- package/dist/src/record-validator.d.ts +0 -17
- package/dist/src/schema.d.ts +0 -9
- package/dist/src/schemas.d.ts +0 -10
- package/dist/src/types.d.ts +0 -30268
- package/dist/src/view-validator.d.ts +0 -13
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types.js +0 -35
package/dist/index.d.ts
CHANGED
|
@@ -1,126 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare type SomeObject = Record<string, unknown>;
|
|
4
|
-
export interface AdxRecordValidatorDescription {
|
|
5
|
-
type: string | string[];
|
|
6
|
-
ext?: string | string[];
|
|
7
|
-
}
|
|
8
|
-
export * from './types.js';
|
|
9
|
-
/**
|
|
10
|
-
* A compiled schema.
|
|
11
|
-
*/
|
|
12
|
-
export declare class AdxSchema {
|
|
13
|
-
def: AdxSchemaDefinition;
|
|
14
|
-
id: string;
|
|
15
|
-
validateRecord?: ValidateFunction;
|
|
16
|
-
validateParams?: ValidateFunction;
|
|
17
|
-
validateResponse?: ValidateFunction;
|
|
18
|
-
get name(): string;
|
|
19
|
-
constructor(def: AdxSchemaDefinition);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* A collection of compiled schemas.
|
|
23
|
-
*/
|
|
24
|
-
export declare class AdxSchemas {
|
|
25
|
-
schemas: Map<string, AdxSchema>;
|
|
26
|
-
private _locale;
|
|
27
|
-
get locale(): string;
|
|
28
|
-
set locale(v: string);
|
|
29
|
-
/**
|
|
30
|
-
* Add a schema definition.
|
|
31
|
-
*/
|
|
32
|
-
add(schemaDef: unknown): void;
|
|
33
|
-
/**
|
|
34
|
-
* Remove a schema definition.
|
|
35
|
-
*/
|
|
36
|
-
remove(key: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Get a schema definition.
|
|
39
|
-
*/
|
|
40
|
-
get(key: string): AdxSchema | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Create a record validator out of one or more schemas.
|
|
43
|
-
*/
|
|
44
|
-
createRecordValidator(desc: string | string[] | AdxRecordValidatorDescription): AdxRecordValidator;
|
|
45
|
-
/**
|
|
46
|
-
* Create a view validator out of a schema.
|
|
47
|
-
*/
|
|
48
|
-
createViewValidator(view: string): AdxViewValidator;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Validates records using schemas.
|
|
52
|
-
*/
|
|
53
|
-
export declare class AdxRecordValidator {
|
|
54
|
-
private schemas;
|
|
55
|
-
type: AdxSchema[];
|
|
56
|
-
ext: AdxSchema[];
|
|
57
|
-
constructor(schemas: AdxSchemas, type: AdxSchema[], ext: AdxSchema[]);
|
|
58
|
-
/**
|
|
59
|
-
* Returns detailed information about validity and compatibility.
|
|
60
|
-
*/
|
|
61
|
-
validate(value: SomeObject): AdxValidationResult;
|
|
62
|
-
/**
|
|
63
|
-
* Provides a simple boolean check of validity.
|
|
64
|
-
*/
|
|
65
|
-
isValid(value: any): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Like validate() but throws if validation fails.
|
|
68
|
-
*/
|
|
69
|
-
assertValid(value: any): AdxValidationResult;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Validates views using schemas.
|
|
73
|
-
*/
|
|
74
|
-
export declare class AdxViewValidator {
|
|
75
|
-
view: AdxSchema;
|
|
76
|
-
constructor(view: AdxSchema);
|
|
77
|
-
/**
|
|
78
|
-
* Returns detailed information about validity and compatibility.
|
|
79
|
-
*/
|
|
80
|
-
validateResponse(value: SomeObject): AdxValidationResult;
|
|
81
|
-
/**
|
|
82
|
-
* Provides a simple boolean check of validity.
|
|
83
|
-
*/
|
|
84
|
-
isResponseValid(value: any): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Like validateResponse() but throws if validation fails.
|
|
87
|
-
*/
|
|
88
|
-
assertResponseValid(value: any): AdxValidationResult;
|
|
89
|
-
}
|
|
90
|
-
export declare enum AdxValidationResultCode {
|
|
91
|
-
Full = "full",
|
|
92
|
-
Partial = "partial",
|
|
93
|
-
Incompatible = "incompatible",
|
|
94
|
-
Invalid = "invalid"
|
|
95
|
-
}
|
|
96
|
-
export declare class AdxValidationResult {
|
|
97
|
-
code: AdxValidationResultCode;
|
|
98
|
-
/**
|
|
99
|
-
* The error message (if fatal)
|
|
100
|
-
*/
|
|
101
|
-
error: string | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* A collection of all fallback messages
|
|
104
|
-
*/
|
|
105
|
-
fallbacks: string[];
|
|
106
|
-
/**
|
|
107
|
-
* A collection of all messages
|
|
108
|
-
*/
|
|
109
|
-
messages: string[];
|
|
110
|
-
get valid(): boolean;
|
|
111
|
-
get fullySupported(): boolean;
|
|
112
|
-
get incompatible(): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Internal - used to transition the state machine.
|
|
115
|
-
*/
|
|
116
|
-
_t(to: AdxValidationResultCode, message?: string): void;
|
|
117
|
-
/**
|
|
118
|
-
* Internal - used to transition the state machine.
|
|
119
|
-
*/
|
|
120
|
-
_fail(schema: AdxSchema, validator: ValidateFunction): void;
|
|
121
|
-
}
|
|
122
|
-
export declare class AdxValidationError extends Error {
|
|
123
|
-
code: AdxValidationResultCode;
|
|
124
|
-
messages: string[];
|
|
125
|
-
constructor(res: AdxValidationResult);
|
|
126
|
-
}
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './lexicons';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
9
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,8 +20,61 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
24
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
25
|
+
mod2
|
|
26
|
+
));
|
|
18
27
|
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
19
28
|
|
|
29
|
+
// ../../node_modules/iso-datestring-validator/dist/index.js
|
|
30
|
+
var require_dist = __commonJS({
|
|
31
|
+
"../../node_modules/iso-datestring-validator/dist/index.js"(exports) {
|
|
32
|
+
(() => {
|
|
33
|
+
"use strict";
|
|
34
|
+
var e = { d: (t2, r2) => {
|
|
35
|
+
for (var n2 in r2)
|
|
36
|
+
e.o(r2, n2) && !e.o(t2, n2) && Object.defineProperty(t2, n2, { enumerable: true, get: r2[n2] });
|
|
37
|
+
}, o: (e2, t2) => Object.prototype.hasOwnProperty.call(e2, t2), r: (e2) => {
|
|
38
|
+
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e2, "__esModule", { value: true });
|
|
39
|
+
} }, t = {};
|
|
40
|
+
function r(e2, t2) {
|
|
41
|
+
return void 0 === t2 && (t2 = "-"), new RegExp("^(?!0{4}" + t2 + "0{2}" + t2 + "0{2})((?=[0-9]{4}" + t2 + "(((0[^2])|1[0-2])|02(?=" + t2 + "(([0-1][0-9])|2[0-8])))" + t2 + "[0-9]{2})|(?=((([13579][26])|([2468][048])|(0[48]))0{2})|([0-9]{2}((((0|[2468])[48])|[2468][048])|([13579][26])))" + t2 + "02" + t2 + "29))([0-9]{4})" + t2 + "(?!((0[469])|11)" + t2 + "31)((0[1,3-9]|1[0-2])|(02(?!" + t2 + "3)))" + t2 + "(0[1-9]|[1-2][0-9]|3[0-1])$").test(e2);
|
|
42
|
+
}
|
|
43
|
+
function n(e2) {
|
|
44
|
+
var t2 = /\D/.exec(e2);
|
|
45
|
+
return t2 ? t2[0] : "";
|
|
46
|
+
}
|
|
47
|
+
function i(e2, t2, r2) {
|
|
48
|
+
void 0 === t2 && (t2 = ":"), void 0 === r2 && (r2 = false);
|
|
49
|
+
var i2 = new RegExp("^([0-1]|2(?=([0-3])|4" + t2 + "00))[0-9]" + t2 + "[0-5][0-9](" + t2 + "([0-5]|6(?=0))[0-9])?(.[0-9]{1,9})?$");
|
|
50
|
+
if (!r2 || !/[Z+\-]/.test(e2))
|
|
51
|
+
return i2.test(e2);
|
|
52
|
+
if (/Z$/.test(e2))
|
|
53
|
+
return i2.test(e2.replace("Z", ""));
|
|
54
|
+
var o2 = e2.includes("+"), a2 = e2.split(/[+-]/), u2 = a2[0], d2 = a2[1];
|
|
55
|
+
return i2.test(u2) && function(e3, t3, r3) {
|
|
56
|
+
return void 0 === r3 && (r3 = ":"), new RegExp(t3 ? "^(0(?!(2" + r3 + "4)|0" + r3 + "3)|1(?=([0-1]|2(?=" + r3 + "[04])|[34](?=" + r3 + "0))))([03469](?=" + r3 + "[03])|[17](?=" + r3 + "0)|2(?=" + r3 + "[04])|5(?=" + r3 + "[034])|8(?=" + r3 + "[04]))" + r3 + "([03](?=0)|4(?=5))[05]$" : "^(0(?=[^0])|1(?=[0-2]))([39](?=" + r3 + "[03])|[0-24-8](?=" + r3 + "00))" + r3 + "[03]0$").test(e3);
|
|
57
|
+
}(d2, o2, n(d2));
|
|
58
|
+
}
|
|
59
|
+
function o(e2) {
|
|
60
|
+
var t2 = e2.split("T"), o2 = t2[0], a2 = t2[1], u2 = r(o2, n(o2));
|
|
61
|
+
if (!a2)
|
|
62
|
+
return false;
|
|
63
|
+
var d2, s = (d2 = a2.match(/([^Z+\-\d])(?=\d+\1)/), Array.isArray(d2) ? d2[0] : "");
|
|
64
|
+
return u2 && i(a2, s, true);
|
|
65
|
+
}
|
|
66
|
+
function a(e2, t2) {
|
|
67
|
+
return void 0 === t2 && (t2 = "-"), new RegExp("^[0-9]{4}" + t2 + "(0(?=[^0])|1(?=[0-2]))[0-9]$").test(e2);
|
|
68
|
+
}
|
|
69
|
+
e.r(t), e.d(t, { isValidDate: () => r, isValidISODateString: () => o, isValidTime: () => i, isValidYearMonth: () => a });
|
|
70
|
+
var u = exports;
|
|
71
|
+
for (var d in t)
|
|
72
|
+
u[d] = t[d];
|
|
73
|
+
t.__esModule && Object.defineProperty(u, "__esModule", { value: true });
|
|
74
|
+
})();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
20
78
|
// src/index.ts
|
|
21
79
|
var src_exports = {};
|
|
22
80
|
__export(src_exports, {
|
|
@@ -3216,7 +3274,7 @@ function isValidLexiconDoc(v) {
|
|
|
3216
3274
|
return lexiconDoc.safeParse(v).success;
|
|
3217
3275
|
}
|
|
3218
3276
|
function isObj(obj) {
|
|
3219
|
-
return
|
|
3277
|
+
return obj !== null && typeof obj === "object";
|
|
3220
3278
|
}
|
|
3221
3279
|
function hasProp(data, prop) {
|
|
3222
3280
|
return prop in data;
|
|
@@ -3242,6 +3300,7 @@ var LexiconDefNotFoundError = class extends Error {
|
|
|
3242
3300
|
};
|
|
3243
3301
|
|
|
3244
3302
|
// src/validators/primitives.ts
|
|
3303
|
+
var import_iso_datestring_validator = __toESM(require_dist());
|
|
3245
3304
|
function validate(lexicons, path, def, value) {
|
|
3246
3305
|
switch (def.type) {
|
|
3247
3306
|
case "boolean":
|
|
@@ -3429,8 +3488,7 @@ function datetime(lexicons, path, def, value) {
|
|
|
3429
3488
|
}
|
|
3430
3489
|
{
|
|
3431
3490
|
try {
|
|
3432
|
-
|
|
3433
|
-
if (value !== date.toISOString()) {
|
|
3491
|
+
if (typeof value !== "string" || !(0, import_iso_datestring_validator.isValidISODateString)(value)) {
|
|
3434
3492
|
throw new ValidationError(
|
|
3435
3493
|
`${path} must be an iso8601 formatted datetime`
|
|
3436
3494
|
);
|
|
@@ -3793,6 +3851,20 @@ var Lexicons = class {
|
|
|
3793
3851
|
}
|
|
3794
3852
|
return def;
|
|
3795
3853
|
}
|
|
3854
|
+
validate(lexUri, value) {
|
|
3855
|
+
lexUri = toLexUri(lexUri);
|
|
3856
|
+
const def = this.getDefOrThrow(lexUri, ["record", "object"]);
|
|
3857
|
+
if (!isObj(value)) {
|
|
3858
|
+
throw new ValidationError(`Value must be an object`);
|
|
3859
|
+
}
|
|
3860
|
+
if (def.type === "record") {
|
|
3861
|
+
return object(this, "Record", def.record, value);
|
|
3862
|
+
} else if (def.type === "object") {
|
|
3863
|
+
return object(this, "Object", def, value);
|
|
3864
|
+
} else {
|
|
3865
|
+
throw new InvalidLexiconError("Definition must be a record or object");
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3796
3868
|
assertValidRecord(lexUri, value) {
|
|
3797
3869
|
lexUri = toLexUri(lexUri);
|
|
3798
3870
|
const def = this.getDefOrThrow(lexUri, ["record"]);
|