@atproto/lex-schema 0.0.9 → 0.0.11
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 +41 -0
- package/LICENSE.txt +1 -1
- package/dist/core/$type.d.ts +11 -0
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js +4 -0
- package/dist/core/$type.js.map +1 -1
- package/dist/core/schema.d.ts +31 -24
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +38 -8
- package/dist/core/schema.js.map +1 -1
- package/dist/core/string-format.d.ts +35 -35
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js +49 -91
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/validation-error.d.ts +1 -1
- package/dist/core/validation-issue.js +1 -1
- package/dist/core/validation-issue.js.map +1 -1
- package/dist/core/validator.d.ts +53 -32
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js +18 -22
- package/dist/core/validator.js.map +1 -1
- package/dist/external.d.ts +0 -85
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +0 -164
- package/dist/external.js.map +1 -1
- package/dist/helpers.d.ts +13 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +4 -4
- package/dist/helpers.js.map +1 -1
- package/dist/schema/array.d.ts +9 -5
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +14 -5
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +9 -7
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +9 -5
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.d.ts +3 -7
- package/dist/schema/boolean.d.ts.map +1 -1
- package/dist/schema/boolean.js +6 -7
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.d.ts +3 -2
- package/dist/schema/bytes.d.ts.map +1 -1
- package/dist/schema/bytes.js +7 -3
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +7 -7
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +5 -1
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.d.ts +6 -5
- package/dist/schema/custom.d.ts.map +1 -1
- package/dist/schema/custom.js +10 -4
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +8 -8
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +11 -2
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +21 -14
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +7 -0
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.d.ts +7 -9
- package/dist/schema/enum.d.ts.map +1 -1
- package/dist/schema/enum.js +8 -4
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.d.ts +5 -5
- package/dist/schema/integer.d.ts.map +1 -1
- package/dist/schema/integer.js +9 -5
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +4 -4
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +5 -0
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/literal.d.ts +6 -9
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -4
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.d.ts +3 -2
- package/dist/schema/never.d.ts.map +1 -1
- package/dist/schema/never.js +5 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.d.ts +4 -3
- package/dist/schema/null.d.ts.map +1 -1
- package/dist/schema/null.js +6 -4
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +6 -5
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +9 -5
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +10 -8
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +11 -3
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +7 -5
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +14 -6
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +26 -13
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +47 -25
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +12 -9
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js +11 -0
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +1 -0
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +5 -0
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +6 -5
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js +5 -0
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +2 -1
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +5 -0
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +2 -1
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +5 -0
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +48 -30
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +12 -9
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +9 -6
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +9 -16
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +4 -4
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.d.ts +4 -3
- package/dist/schema/regexp.d.ts.map +1 -1
- package/dist/schema/regexp.js +5 -0
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +7 -8
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +13 -19
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +2 -1
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js +5 -0
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +6 -5
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +5 -0
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +43 -26
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +6 -3
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +16 -25
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +7 -17
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +9 -21
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +15 -11
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +6 -6
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +7 -5
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown-object.d.ts +5 -4
- package/dist/schema/unknown-object.d.ts.map +1 -1
- package/dist/schema/unknown-object.js +5 -1
- package/dist/schema/unknown-object.js.map +1 -1
- package/dist/schema/unknown.d.ts +3 -2
- package/dist/schema/unknown.d.ts.map +1 -1
- package/dist/schema/unknown.js +5 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.d.ts +9 -0
- package/dist/schema/with-default.d.ts.map +1 -0
- package/dist/schema/with-default.js +27 -0
- package/dist/schema/with-default.js.map +1 -0
- package/dist/schema.d.ts +2 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -4
- package/dist/schema.js.map +1 -1
- package/dist/util/assertion-util.d.ts +0 -6
- package/dist/util/assertion-util.d.ts.map +1 -1
- package/dist/util/assertion-util.js +0 -28
- package/dist/util/assertion-util.js.map +1 -1
- package/dist/util/memoize.d.ts +2 -2
- package/dist/util/memoize.d.ts.map +1 -1
- package/dist/util/memoize.js +23 -39
- package/dist/util/memoize.js.map +1 -1
- package/package.json +3 -3
- package/src/core/$type.test.ts +20 -0
- package/src/core/$type.ts +30 -0
- package/src/core/schema.ts +86 -38
- package/src/core/string-format.ts +119 -158
- package/src/core/validation-issue.ts +1 -1
- package/src/core/validator.ts +93 -53
- package/src/external.ts +0 -404
- package/src/helpers.test.ts +22 -21
- package/src/helpers.ts +19 -14
- package/src/schema/array.test.ts +38 -40
- package/src/schema/array.ts +35 -13
- package/src/schema/blob.test.ts +21 -21
- package/src/schema/blob.ts +19 -17
- package/src/schema/boolean.test.ts +9 -8
- package/src/schema/boolean.ts +7 -13
- package/src/schema/bytes.test.ts +13 -13
- package/src/schema/bytes.ts +13 -8
- package/src/schema/cid.test.ts +3 -3
- package/src/schema/cid.ts +13 -12
- package/src/schema/custom.test.ts +26 -26
- package/src/schema/custom.ts +20 -13
- package/src/schema/dict.test.ts +21 -39
- package/src/schema/dict.ts +28 -19
- package/src/schema/discriminated-union.test.ts +128 -128
- package/src/schema/discriminated-union.ts +45 -26
- package/src/schema/enum.test.ts +17 -16
- package/src/schema/enum.ts +16 -16
- package/src/schema/integer.test.ts +22 -21
- package/src/schema/integer.ts +12 -9
- package/src/schema/intersection.test.ts +10 -10
- package/src/schema/intersection.ts +17 -14
- package/src/schema/literal.test.ts +35 -34
- package/src/schema/literal.ts +12 -15
- package/src/schema/never.test.ts +5 -5
- package/src/schema/never.ts +7 -2
- package/src/schema/null.test.ts +3 -3
- package/src/schema/null.ts +9 -9
- package/src/schema/nullable.test.ts +31 -42
- package/src/schema/nullable.ts +17 -9
- package/src/schema/object.test.ts +10 -12
- package/src/schema/object.ts +27 -18
- package/src/schema/optional.test.ts +21 -28
- package/src/schema/optional.ts +27 -10
- package/src/schema/params.test.ts +471 -47
- package/src/schema/params.ts +74 -38
- package/src/schema/payload.test.ts +150 -156
- package/src/schema/payload.ts +35 -19
- package/src/schema/permission-set.test.ts +206 -273
- package/src/schema/permission-set.ts +8 -0
- package/src/schema/permission.test.ts +177 -177
- package/src/schema/permission.ts +13 -5
- package/src/schema/procedure.test.ts +183 -242
- package/src/schema/procedure.ts +18 -5
- package/src/schema/query.test.ts +186 -200
- package/src/schema/query.ts +16 -4
- package/src/schema/record.test.ts +121 -101
- package/src/schema/record.ts +74 -40
- package/src/schema/ref.test.ts +101 -118
- package/src/schema/ref.ts +33 -28
- package/src/schema/refine.test.ts +28 -28
- package/src/schema/refine.ts +23 -20
- package/src/schema/regexp.test.ts +29 -33
- package/src/schema/regexp.ts +11 -7
- package/src/schema/string.test.ts +35 -35
- package/src/schema/string.ts +24 -33
- package/src/schema/subscription.test.ts +259 -387
- package/src/schema/subscription.ts +16 -4
- package/src/schema/token.test.ts +47 -324
- package/src/schema/token.ts +14 -7
- package/src/schema/typed-object.test.ts +98 -81
- package/src/schema/typed-object.ts +68 -33
- package/src/schema/typed-ref.test.ts +206 -234
- package/src/schema/typed-ref.ts +40 -42
- package/src/schema/typed-union.test.ts +40 -64
- package/src/schema/typed-union.ts +36 -58
- package/src/schema/union.test.ts +17 -27
- package/src/schema/union.ts +20 -16
- package/src/schema/unknown-object.test.ts +8 -8
- package/src/schema/unknown-object.ts +9 -7
- package/src/schema/unknown.test.ts +4 -4
- package/src/schema/unknown.ts +7 -5
- package/src/schema/with-default.ts +35 -0
- package/src/schema.ts +2 -6
- package/src/util/assertion-util.ts +0 -39
- package/src/util/memoize.ts +26 -46
- package/dist/schema/_parameters.d.ts +0 -17
- package/dist/schema/_parameters.d.ts.map +0 -1
- package/dist/schema/_parameters.js +0 -20
- package/dist/schema/_parameters.js.map +0 -1
- package/src/schema/_parameters.test.ts +0 -417
- package/src/schema/_parameters.ts +0 -26
package/dist/schema/literal.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { Schema,
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly value: Output;
|
|
7
|
-
readonly options?: LiteralSchemaOptions<Output> | undefined;
|
|
8
|
-
constructor(value: Output, options?: LiteralSchemaOptions<Output> | undefined);
|
|
9
|
-
validateInContext(input: unknown | undefined, ctx: ValidatorContext): ValidationResult<Output>;
|
|
1
|
+
import { Schema, ValidationContext } from '../core.js';
|
|
2
|
+
export declare class LiteralSchema<const TValue extends null | string | number | boolean> extends Schema<TValue> {
|
|
3
|
+
readonly value: TValue;
|
|
4
|
+
constructor(value: TValue);
|
|
5
|
+
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<TValue>;
|
|
10
6
|
}
|
|
7
|
+
export declare function literal<const V extends null | string | number | boolean>(value: V): LiteralSchema<V>;
|
|
11
8
|
//# sourceMappingURL=literal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/schema/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/schema/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEtD,qBAAa,aAAa,CACxB,KAAK,CAAC,MAAM,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CACrD,SAAQ,MAAM,CAAC,MAAM,CAAC;IACV,QAAQ,CAAC,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;IAIlC,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAGD,wBAAgB,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EACtE,KAAK,EAAE,CAAC,oBAGT"}
|
package/dist/schema/literal.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiteralSchema = void 0;
|
|
4
|
+
exports.literal = literal;
|
|
4
5
|
const core_js_1 = require("../core.js");
|
|
5
6
|
class LiteralSchema extends core_js_1.Schema {
|
|
6
7
|
value;
|
|
7
|
-
|
|
8
|
-
constructor(value, options) {
|
|
8
|
+
constructor(value) {
|
|
9
9
|
super();
|
|
10
10
|
this.value = value;
|
|
11
|
-
this.options = options;
|
|
12
11
|
}
|
|
13
|
-
validateInContext(input
|
|
12
|
+
validateInContext(input, ctx) {
|
|
14
13
|
if (input !== this.value) {
|
|
15
14
|
return ctx.issueInvalidValue(input, [this.value]);
|
|
16
15
|
}
|
|
@@ -18,4 +17,8 @@ class LiteralSchema extends core_js_1.Schema {
|
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
exports.LiteralSchema = LiteralSchema;
|
|
20
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
21
|
+
function literal(value) {
|
|
22
|
+
return new LiteralSchema(value);
|
|
23
|
+
}
|
|
21
24
|
//# sourceMappingURL=literal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../src/schema/literal.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../src/schema/literal.ts"],"names":[],"mappings":";;;AAmBA,0BAIC;AAvBD,wCAAsD;AAEtD,MAAa,aAEX,SAAQ,gBAAc;IACD;IAArB,YAAqB,KAAa;QAChC,KAAK,EAAE,CAAA;QADY,UAAK,GAAL,KAAK,CAAQ;IAElC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO,GAAG,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAChC,CAAC;CACF;AAdD,sCAcC;AAED,wBAAwB;AACxB,SAAgB,OAAO,CACrB,KAAQ;IAER,OAAO,IAAI,aAAa,CAAI,KAAK,CAAC,CAAA;AACpC,CAAC","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\n\nexport class LiteralSchema<\n const TValue extends null | string | number | boolean,\n> extends Schema<TValue> {\n constructor(readonly value: TValue) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (input !== this.value) {\n return ctx.issueInvalidValue(input, [this.value])\n }\n\n return ctx.success(this.value)\n }\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function literal<const V extends null | string | number | boolean>(\n value: V,\n) {\n return new LiteralSchema<V>(value)\n}\n"]}
|
package/dist/schema/never.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Schema,
|
|
1
|
+
import { Schema, ValidationContext } from '../core.js';
|
|
2
2
|
export declare class NeverSchema extends Schema<never> {
|
|
3
|
-
validateInContext(input: unknown, ctx:
|
|
3
|
+
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationFailure;
|
|
4
4
|
}
|
|
5
|
+
export declare const never: () => NeverSchema;
|
|
5
6
|
//# sourceMappingURL=never.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"never.d.ts","sourceRoot":"","sources":["../../src/schema/never.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"never.d.ts","sourceRoot":"","sources":["../../src/schema/never.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,qBAAa,WAAY,SAAQ,MAAM,CAAC,KAAK,CAAC;IAC5C,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAGzD;AAED,eAAO,MAAM,KAAK,mBAEhB,CAAA"}
|
package/dist/schema/never.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NeverSchema = void 0;
|
|
3
|
+
exports.never = exports.NeverSchema = void 0;
|
|
4
4
|
const core_js_1 = require("../core.js");
|
|
5
|
+
const memoize_js_1 = require("../util/memoize.js");
|
|
5
6
|
class NeverSchema extends core_js_1.Schema {
|
|
6
7
|
validateInContext(input, ctx) {
|
|
7
8
|
return ctx.issueInvalidType(input, 'never');
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
exports.NeverSchema = NeverSchema;
|
|
12
|
+
exports.never = (0, memoize_js_1.memoizedOptions)(function () {
|
|
13
|
+
return new NeverSchema();
|
|
14
|
+
});
|
|
11
15
|
//# sourceMappingURL=never.js.map
|
package/dist/schema/never.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"never.js","sourceRoot":"","sources":["../../src/schema/never.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"never.js","sourceRoot":"","sources":["../../src/schema/never.ts"],"names":[],"mappings":";;;AAAA,wCAAsD;AACtD,mDAAoD;AAEpD,MAAa,WAAY,SAAQ,gBAAa;IAC5C,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC7C,CAAC;CACF;AAJD,kCAIC;AAEY,QAAA,KAAK,GAAiB,IAAA,4BAAe,EAAC;IACjD,OAAO,IAAI,WAAW,EAAE,CAAA;AAC1B,CAAC,CAAC,CAAA","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport class NeverSchema extends Schema<never> {\n validateInContext(input: unknown, ctx: ValidationContext) {\n return ctx.issueInvalidType(input, 'never')\n }\n}\n\nexport const never = /*#__PURE__*/ memoizedOptions(function () {\n return new NeverSchema()\n})\n"]}
|
package/dist/schema/null.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Schema,
|
|
1
|
+
import { Schema, ValidationContext } from '../core.js';
|
|
2
2
|
export declare class NullSchema extends Schema<null> {
|
|
3
|
-
|
|
4
|
-
validateInContext(input: unknown, ctx: ValidatorContext): ValidationResult<null>;
|
|
3
|
+
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<null>;
|
|
5
4
|
}
|
|
5
|
+
export declare const nullSchema: () => NullSchema;
|
|
6
|
+
export { nullSchema as null };
|
|
6
7
|
//# sourceMappingURL=null.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"null.d.ts","sourceRoot":"","sources":["../../src/schema/null.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"null.d.ts","sourceRoot":"","sources":["../../src/schema/null.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,qBAAa,UAAW,SAAQ,MAAM,CAAC,IAAI,CAAC;IAC1C,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAED,eAAO,MAAM,UAAU,kBAErB,CAAA;AAEF,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,CAAA"}
|
package/dist/schema/null.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NullSchema = void 0;
|
|
3
|
+
exports.null = exports.nullSchema = exports.NullSchema = void 0;
|
|
4
4
|
const core_js_1 = require("../core.js");
|
|
5
|
+
const memoize_js_1 = require("../util/memoize.js");
|
|
5
6
|
class NullSchema extends core_js_1.Schema {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
}
|
|
9
7
|
validateInContext(input, ctx) {
|
|
10
8
|
if (input !== null) {
|
|
11
9
|
return ctx.issueInvalidType(input, 'null');
|
|
@@ -14,4 +12,8 @@ class NullSchema extends core_js_1.Schema {
|
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
14
|
exports.NullSchema = NullSchema;
|
|
15
|
+
exports.nullSchema = (0, memoize_js_1.memoizedOptions)(function () {
|
|
16
|
+
return new NullSchema();
|
|
17
|
+
});
|
|
18
|
+
exports.null = exports.nullSchema;
|
|
17
19
|
//# sourceMappingURL=null.js.map
|
package/dist/schema/null.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../src/schema/null.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../src/schema/null.ts"],"names":[],"mappings":";;;AAAA,wCAAsD;AACtD,mDAAoD;AAEpD,MAAa,UAAW,SAAQ,gBAAY;IAC1C,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC5C,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;CACF;AARD,gCAQC;AAEY,QAAA,UAAU,GAAiB,IAAA,4BAAe,EAAC;IACtD,OAAO,IAAI,UAAU,EAAE,CAAA;AACzB,CAAC,CAAC,CAAA;AAEqB,eAJV,kBAAU,CAII","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport class NullSchema extends Schema<null> {\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (input !== null) {\n return ctx.issueInvalidType(input, 'null')\n }\n\n return ctx.success(null)\n }\n}\n\nexport const nullSchema = /*#__PURE__*/ memoizedOptions(function () {\n return new NullSchema()\n})\n\nexport { nullSchema as null }\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Schema,
|
|
2
|
-
export declare class NullableSchema<
|
|
3
|
-
readonly
|
|
4
|
-
constructor(
|
|
5
|
-
validateInContext(input: unknown, ctx:
|
|
1
|
+
import { InferInput, InferOutput, Schema, ValidationContext, Validator } from '../core.js';
|
|
2
|
+
export declare class NullableSchema<const TValidator extends Validator> extends Schema<InferInput<TValidator> | null, InferOutput<TValidator> | null> {
|
|
3
|
+
readonly validator: TValidator;
|
|
4
|
+
constructor(validator: TValidator);
|
|
5
|
+
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationFailure | import("../core.js").ValidationSuccess<null> | import("../core.js").ValidationSuccess<InferInput<TValidator>>;
|
|
6
6
|
}
|
|
7
|
+
export declare const nullable: <const TValidator extends Validator>(validator: TValidator) => NullableSchema<TValidator>;
|
|
7
8
|
//# sourceMappingURL=nullable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nullable.d.ts","sourceRoot":"","sources":["../../src/schema/nullable.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,
|
|
1
|
+
{"version":3,"file":"nullable.d.ts","sourceRoot":"","sources":["../../src/schema/nullable.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAA;AAGnB,qBAAa,cAAc,CAAC,KAAK,CAAC,UAAU,SAAS,SAAS,CAAE,SAAQ,MAAM,CAC5E,UAAU,CAAC,UAAU,CAAC,GAAG,IAAI,EAC7B,WAAW,CAAC,UAAU,CAAC,GAAG,IAAI,CAC/B;IACa,QAAQ,CAAC,SAAS,EAAE,UAAU;gBAArB,SAAS,EAAE,UAAU;IAI1C,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAED,eAAO,MAAM,QAAQ,SACb,UAAU,SAAS,SAAS,aACvB,UAAU,+BAErB,CAAA"}
|
package/dist/schema/nullable.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NullableSchema = void 0;
|
|
3
|
+
exports.nullable = exports.NullableSchema = void 0;
|
|
4
4
|
const core_js_1 = require("../core.js");
|
|
5
|
+
const memoize_js_1 = require("../util/memoize.js");
|
|
5
6
|
class NullableSchema extends core_js_1.Schema {
|
|
6
|
-
|
|
7
|
-
constructor(
|
|
7
|
+
validator;
|
|
8
|
+
constructor(validator) {
|
|
8
9
|
super();
|
|
9
|
-
this.
|
|
10
|
+
this.validator = validator;
|
|
10
11
|
}
|
|
11
12
|
validateInContext(input, ctx) {
|
|
12
13
|
if (input === null) {
|
|
13
14
|
return ctx.success(null);
|
|
14
15
|
}
|
|
15
|
-
return ctx.validate(input, this.
|
|
16
|
+
return ctx.validate(input, this.validator);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
exports.NullableSchema = NullableSchema;
|
|
20
|
+
exports.nullable = (0, memoize_js_1.memoizedTransformer)(function (validator) {
|
|
21
|
+
return new NullableSchema(validator);
|
|
22
|
+
});
|
|
19
23
|
//# sourceMappingURL=nullable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../src/schema/nullable.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../src/schema/nullable.ts"],"names":[],"mappings":";;;AAAA,wCAMmB;AACnB,mDAAwD;AAExD,MAAa,cAAmD,SAAQ,gBAGvE;IACsB;IAArB,YAAqB,SAAqB;QACxC,KAAK,EAAE,CAAA;QADY,cAAS,GAAT,SAAS,CAAY;IAE1C,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC1B,CAAC;QAED,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IAC5C,CAAC;CACF;AAfD,wCAeC;AAEY,QAAA,QAAQ,GAAiB,IAAA,gCAAmB,EAAC,UAExD,SAAqB;IACrB,OAAO,IAAI,cAAc,CAAa,SAAS,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA","sourcesContent":["import {\n InferInput,\n InferOutput,\n Schema,\n ValidationContext,\n Validator,\n} from '../core.js'\nimport { memoizedTransformer } from '../util/memoize.js'\n\nexport class NullableSchema<const TValidator extends Validator> extends Schema<\n InferInput<TValidator> | null,\n InferOutput<TValidator> | null\n> {\n constructor(readonly validator: TValidator) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (input === null) {\n return ctx.success(null)\n }\n\n return ctx.validate(input, this.validator)\n }\n}\n\nexport const nullable = /*#__PURE__*/ memoizedTransformer(function <\n const TValidator extends Validator,\n>(validator: TValidator) {\n return new NullableSchema<TValidator>(validator)\n})\n"]}
|
package/dist/schema/object.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InferInput, InferOutput, Schema, ValidationContext, Validator, WithOptionalProperties } from '../core.js';
|
|
2
2
|
export type ObjectSchemaShape = Record<string, Validator>;
|
|
3
|
-
export
|
|
4
|
-
[K in keyof
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export declare class ObjectSchema<const TShape extends ObjectSchemaShape = any> extends Schema<WithOptionalProperties<{
|
|
4
|
+
[K in keyof TShape]: InferInput<TShape[K]>;
|
|
5
|
+
}>, WithOptionalProperties<{
|
|
6
|
+
[K in keyof TShape]: InferOutput<TShape[K]>;
|
|
7
|
+
}>> {
|
|
8
|
+
readonly shape: TShape;
|
|
9
|
+
constructor(shape: TShape);
|
|
9
10
|
get validatorsMap(): Map<string, Validator>;
|
|
10
|
-
validateInContext(input: unknown, ctx:
|
|
11
|
+
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<Record<string, unknown>>;
|
|
11
12
|
}
|
|
13
|
+
export declare function object<const TShape extends ObjectSchemaShape>(properties: TShape): ObjectSchema<TShape>;
|
|
12
14
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/schema/object.ts"],"names":[],"mappings":"AACA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/schema/object.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,SAAS,EACT,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAGnB,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAEzD,qBAAa,YAAY,CACvB,KAAK,CAAC,MAAM,SAAS,iBAAiB,GAAG,GAAG,CAC5C,SAAQ,MAAM,CACd,sBAAsB,CAAC;KACpB,CAAC,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC3C,CAAC,EACF,sBAAsB,CAAC;KACpB,CAAC,IAAI,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC,CACH;IACa,QAAQ,CAAC,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;IAIlC,IAAI,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAI1C;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAqCzD;AAGD,wBAAgB,MAAM,CAAC,KAAK,CAAC,MAAM,SAAS,iBAAiB,EAC3D,UAAU,EAAE,MAAM,wBAGnB"}
|
package/dist/schema/object.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectSchema = void 0;
|
|
4
|
+
exports.object = object;
|
|
4
5
|
const lex_data_1 = require("@atproto/lex-data");
|
|
5
6
|
const core_js_1 = require("../core.js");
|
|
6
7
|
const lazy_property_js_1 = require("../util/lazy-property.js");
|
|
@@ -33,14 +34,21 @@ class ObjectSchema extends core_js_1.Schema {
|
|
|
33
34
|
if (result.value === undefined && !(key in input)) {
|
|
34
35
|
continue;
|
|
35
36
|
}
|
|
36
|
-
if (result.value
|
|
37
|
+
if (!Object.is(result.value, input[key])) {
|
|
38
|
+
if (ctx.options.mode === 'validate') {
|
|
39
|
+
// In "validate" mode, we can't modify the input, so we issue an error
|
|
40
|
+
return ctx.issueInvalidPropertyValue(input, key, [result.value]);
|
|
41
|
+
}
|
|
37
42
|
copy ??= { ...input };
|
|
38
43
|
copy[key] = result.value;
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
return ctx.success(output);
|
|
46
|
+
return ctx.success(copy ?? input);
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
exports.ObjectSchema = ObjectSchema;
|
|
50
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
51
|
+
function object(properties) {
|
|
52
|
+
return new ObjectSchema(properties);
|
|
53
|
+
}
|
|
46
54
|
//# sourceMappingURL=object.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/schema/object.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/schema/object.ts"],"names":[],"mappings":";;;AAyEA,wBAIC;AA7ED,gDAAiD;AACjD,wCAOmB;AACnB,+DAAuD;AAIvD,MAAa,YAEX,SAAQ,gBAOT;IACsB;IAArB,YAAqB,KAAa;QAChC,KAAK,EAAE,CAAA;QADY,UAAK,GAAL,KAAK,CAAQ;IAElC,CAAC;IAED,IAAI,aAAa;QACf,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAE/C,OAAO,IAAA,+BAAY,EAAC,IAAI,EAAE,eAAe,EAAE,GAAG,CAAC,CAAA;IACjD,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC9C,CAAC;QAED,oBAAoB;QACpB,IAAI,IAAyC,CAAA;QAE7C,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;YACrD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,IAAI,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC;oBACpB,sCAAsC;oBACtC,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBACzC,CAAC;gBAED,OAAO,MAAM,CAAA;YACf,CAAC;YAED,uEAAuE;YACvE,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC;gBAClD,SAAQ;YACV,CAAC;YAED,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBACzC,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBACpC,sEAAsE;oBACtE,OAAO,GAAG,CAAC,yBAAyB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;gBAClE,CAAC;gBAED,IAAI,KAAK,EAAE,GAAG,KAAK,EAAE,CAAA;gBACrB,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAA;YAC1B,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC,CAAA;IACnC,CAAC;CACF;AAzDD,oCAyDC;AAED,wBAAwB;AACxB,SAAgB,MAAM,CACpB,UAAkB;IAElB,OAAO,IAAI,YAAY,CAAS,UAAU,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { isPlainObject } from '@atproto/lex-data'\nimport {\n InferInput,\n InferOutput,\n Schema,\n ValidationContext,\n Validator,\n WithOptionalProperties,\n} from '../core.js'\nimport { lazyProperty } from '../util/lazy-property.js'\n\nexport type ObjectSchemaShape = Record<string, Validator>\n\nexport class ObjectSchema<\n const TShape extends ObjectSchemaShape = any,\n> extends Schema<\n WithOptionalProperties<{\n [K in keyof TShape]: InferInput<TShape[K]>\n }>,\n WithOptionalProperties<{\n [K in keyof TShape]: InferOutput<TShape[K]>\n }>\n> {\n constructor(readonly shape: TShape) {\n super()\n }\n\n get validatorsMap(): Map<string, Validator> {\n const map = new Map(Object.entries(this.shape))\n\n return lazyProperty(this, 'validatorsMap', map)\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isPlainObject(input)) {\n return ctx.issueInvalidType(input, 'object')\n }\n\n // Lazily copy value\n let copy: undefined | Record<string, unknown>\n\n for (const [key, propDef] of this.validatorsMap) {\n const result = ctx.validateChild(input, key, propDef)\n if (!result.success) {\n if (!(key in input)) {\n // Transform into \"required key\" issue\n return ctx.issueRequiredKey(input, key)\n }\n\n return result\n }\n\n // Skip copying if key is not present in input (and value is undefined)\n if (result.value === undefined && !(key in input)) {\n continue\n }\n\n if (!Object.is(result.value, input[key])) {\n if (ctx.options.mode === 'validate') {\n // In \"validate\" mode, we can't modify the input, so we issue an error\n return ctx.issueInvalidPropertyValue(input, key, [result.value])\n }\n\n copy ??= { ...input }\n copy[key] = result.value\n }\n }\n\n return ctx.success(copy ?? input)\n }\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function object<const TShape extends ObjectSchemaShape>(\n properties: TShape,\n) {\n return new ObjectSchema<TShape>(properties)\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Schema,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { InferInput, InferOutput, Schema, UnwrapValidator, ValidationContext, Validator } from '../core.js';
|
|
2
|
+
import { WithDefaultSchema } from './with-default.js';
|
|
3
|
+
export declare class OptionalSchema<TValidator extends Validator> extends Schema<InferInput<TValidator> | undefined, UnwrapValidator<TValidator> extends WithDefaultSchema<infer TValidator> ? InferOutput<TValidator> : InferOutput<TValidator> | undefined> {
|
|
4
|
+
readonly validator: TValidator;
|
|
5
|
+
constructor(validator: TValidator);
|
|
6
|
+
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<undefined> | import("../core.js").ValidationSuccess<InferInput<TValidator>>;
|
|
6
7
|
}
|
|
8
|
+
export declare const optional: <const TValidator extends Validator>(validator: TValidator) => OptionalSchema<TValidator>;
|
|
7
9
|
//# sourceMappingURL=optional.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../../src/schema/optional.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,
|
|
1
|
+
{"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../../src/schema/optional.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,eAAe,EACf,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,qBAAa,cAAc,CAAC,UAAU,SAAS,SAAS,CAAE,SAAQ,MAAM,CACtE,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,EAClC,eAAe,CAAC,UAAU,CAAC,SAAS,iBAAiB,CAAC,MAAM,UAAU,CAAC,GACnE,WAAW,CAAC,UAAU,CAAC,GACvB,WAAW,CAAC,UAAU,CAAC,GAAG,SAAS,CACxC;IACa,QAAQ,CAAC,SAAS,EAAE,UAAU;gBAArB,SAAS,EAAE,UAAU;IAI1C,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAoBzD;AAED,eAAO,MAAM,QAAQ,SACb,UAAU,SAAS,SAAS,aACvB,UAAU,+BAErB,CAAA"}
|
package/dist/schema/optional.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OptionalSchema = void 0;
|
|
3
|
+
exports.optional = exports.OptionalSchema = void 0;
|
|
4
4
|
const core_js_1 = require("../core.js");
|
|
5
|
+
const memoize_js_1 = require("../util/memoize.js");
|
|
5
6
|
class OptionalSchema extends core_js_1.Schema {
|
|
6
|
-
|
|
7
|
-
constructor(
|
|
7
|
+
validator;
|
|
8
|
+
constructor(validator) {
|
|
8
9
|
super();
|
|
9
|
-
this.
|
|
10
|
+
this.validator = validator;
|
|
10
11
|
}
|
|
11
12
|
validateInContext(input, ctx) {
|
|
13
|
+
// Optimization: No need to apply child schema defaults in validation mode
|
|
14
|
+
if (input === undefined && ctx.options.mode === 'validate') {
|
|
15
|
+
return ctx.success(input);
|
|
16
|
+
}
|
|
12
17
|
// @NOTE The inner schema might apply a default value so we need to run it
|
|
13
|
-
//
|
|
14
|
-
const result = ctx.validate(input, this.
|
|
18
|
+
// even if input is undefined.
|
|
19
|
+
const result = ctx.validate(input, this.validator);
|
|
15
20
|
if (result.success) {
|
|
16
21
|
return result;
|
|
17
22
|
}
|
|
@@ -22,4 +27,7 @@ class OptionalSchema extends core_js_1.Schema {
|
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
exports.OptionalSchema = OptionalSchema;
|
|
30
|
+
exports.optional = (0, memoize_js_1.memoizedTransformer)(function (validator) {
|
|
31
|
+
return new OptionalSchema(validator);
|
|
32
|
+
});
|
|
25
33
|
//# sourceMappingURL=optional.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../src/schema/optional.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../src/schema/optional.ts"],"names":[],"mappings":";;;AAAA,wCAOmB;AACnB,mDAAwD;AAGxD,MAAa,cAA6C,SAAQ,gBAKjE;IACsB;IAArB,YAAqB,SAAqB;QACxC,KAAK,EAAE,CAAA;QADY,cAAS,GAAT,SAAS,CAAY;IAE1C,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,0EAA0E;QAC1E,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC3D,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,0EAA0E;QAC1E,8BAA8B;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QAElD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,MAAM,CAAA;QACf,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AA9BD,wCA8BC;AAEY,QAAA,QAAQ,GAAiB,IAAA,gCAAmB,EAAC,UAExD,SAAqB;IACrB,OAAO,IAAI,cAAc,CAAa,SAAS,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA","sourcesContent":["import {\n InferInput,\n InferOutput,\n Schema,\n UnwrapValidator,\n ValidationContext,\n Validator,\n} from '../core.js'\nimport { memoizedTransformer } from '../util/memoize.js'\nimport { WithDefaultSchema } from './with-default.js'\n\nexport class OptionalSchema<TValidator extends Validator> extends Schema<\n InferInput<TValidator> | undefined,\n UnwrapValidator<TValidator> extends WithDefaultSchema<infer TValidator>\n ? InferOutput<TValidator>\n : InferOutput<TValidator> | undefined\n> {\n constructor(readonly validator: TValidator) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n // Optimization: No need to apply child schema defaults in validation mode\n if (input === undefined && ctx.options.mode === 'validate') {\n return ctx.success(input)\n }\n\n // @NOTE The inner schema might apply a default value so we need to run it\n // even if input is undefined.\n const result = ctx.validate(input, this.validator)\n\n if (result.success) {\n return result\n }\n\n if (input === undefined) {\n return ctx.success(input)\n }\n\n return result\n }\n}\n\nexport const optional = /*#__PURE__*/ memoizedTransformer(function <\n const TValidator extends Validator,\n>(validator: TValidator) {\n return new OptionalSchema<TValidator>(validator)\n})\n"]}
|
package/dist/schema/params.d.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import { Infer, Schema,
|
|
2
|
-
import {
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}>;
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { Infer, InferInput, InferOutput, Schema, ValidationContext, Validator, WithOptionalProperties } from '../core.js';
|
|
2
|
+
import { StringSchema } from './string.js';
|
|
3
|
+
export type ParamScalar = Infer<typeof paramScalarSchema>;
|
|
4
|
+
declare const paramScalarSchema: import("./union.js").UnionSchema<readonly [import("./boolean.js").BooleanSchema, import("./integer.js").IntegerSchema, StringSchema<{}>]>;
|
|
5
|
+
export type Param = Infer<typeof paramSchema>;
|
|
6
|
+
export declare const paramSchema: import("./union.js").UnionSchema<readonly [import("./union.js").UnionSchema<readonly [import("./boolean.js").BooleanSchema, import("./integer.js").IntegerSchema, StringSchema<{}>]>, import("./array.js").ArraySchema<import("./union.js").UnionSchema<readonly [import("./boolean.js").BooleanSchema, import("./integer.js").IntegerSchema, StringSchema<{}>]>>]>;
|
|
7
|
+
export type Params = Infer<typeof paramsSchema>;
|
|
8
|
+
export declare const paramsSchema: import("./dict.js").DictSchema<StringSchema<{}>, import("./optional.js").OptionalSchema<import("./union.js").UnionSchema<readonly [import("./union.js").UnionSchema<readonly [import("./boolean.js").BooleanSchema, import("./integer.js").IntegerSchema, StringSchema<{}>]>, import("./array.js").ArraySchema<import("./union.js").UnionSchema<readonly [import("./boolean.js").BooleanSchema, import("./integer.js").IntegerSchema, StringSchema<{}>]>>]>>>;
|
|
9
|
+
export type ParamsSchemaShape = {
|
|
10
|
+
[x: string]: Validator<Param | undefined>;
|
|
11
|
+
};
|
|
12
|
+
export declare class ParamsSchema<const TShape extends ParamsSchemaShape = {
|
|
13
|
+
[x: string]: Validator<Param | undefined>;
|
|
14
|
+
}> extends Schema<WithOptionalProperties<{
|
|
15
|
+
[K in keyof TShape]: InferInput<TShape[K]>;
|
|
16
|
+
}>, WithOptionalProperties<{
|
|
17
|
+
[K in keyof TShape]: InferOutput<TShape[K]>;
|
|
18
|
+
}>> {
|
|
19
|
+
readonly shape: TShape;
|
|
20
|
+
constructor(shape: TShape);
|
|
21
|
+
get shapeValidators(): Map<string, Validator<Param | undefined>>;
|
|
22
|
+
validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<Record<string, unknown>>;
|
|
23
|
+
fromURLSearchParams(urlSearchParams: URLSearchParams): InferOutput<this>;
|
|
24
|
+
toURLSearchParams(input: InferInput<this>): URLSearchParams;
|
|
14
25
|
}
|
|
26
|
+
export declare const params: <const TShape extends ParamsSchemaShape = {}>(properties?: TShape) => ParamsSchema<TShape>;
|
|
27
|
+
export {};
|
|
15
28
|
//# sourceMappingURL=params.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/schema/params.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,MAAM,EACN,
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/schema/params.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,iBAAiB,EACjB,SAAS,EACT,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAQnB,OAAO,EAAE,YAAY,EAAU,MAAM,aAAa,CAAA;AAGlD,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AACzD,QAAA,MAAM,iBAAiB,2IAA0C,CAAA;AAEjE,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA;AAC7C,eAAO,MAAM,WAAW,qWAAuD,CAAA;AAE/E,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAC/C,eAAO,MAAM,YAAY,+bAAwC,CAAA;AAEjE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;CAC1C,CAAA;AAED,qBAAa,YAAY,CACvB,KAAK,CAAC,MAAM,SAAS,iBAAiB,GAAG;IACvC,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;CAC1C,CACD,SAAQ,MAAM,CACd,sBAAsB,CAAC;KACpB,CAAC,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC3C,CAAC,EACF,sBAAsB,CAAC;KACpB,CAAC,IAAI,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC,CACH;IACa,QAAQ,CAAC,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;IAIlC,IAAI,eAAe,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAI/D;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;IA0DxD,mBAAmB,CAAC,eAAe,EAAE,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC;IA6BxE,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,eAAe;CAmB5D;AAED,eAAO,MAAM,MAAM,SACX,MAAM,SAAS,iBAAiB,oBAC1B,MAAM,yBAElB,CAAA"}
|
package/dist/schema/params.js
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParamsSchema = void 0;
|
|
3
|
+
exports.params = exports.ParamsSchema = exports.paramsSchema = exports.paramSchema = void 0;
|
|
4
4
|
const lex_data_1 = require("@atproto/lex-data");
|
|
5
5
|
const core_js_1 = require("../core.js");
|
|
6
6
|
const lazy_property_js_1 = require("../util/lazy-property.js");
|
|
7
|
-
const
|
|
7
|
+
const memoize_js_1 = require("../util/memoize.js");
|
|
8
|
+
const array_js_1 = require("./array.js");
|
|
9
|
+
const boolean_js_1 = require("./boolean.js");
|
|
10
|
+
const dict_js_1 = require("./dict.js");
|
|
11
|
+
const integer_js_1 = require("./integer.js");
|
|
12
|
+
const optional_js_1 = require("./optional.js");
|
|
8
13
|
const string_js_1 = require("./string.js");
|
|
14
|
+
const union_js_1 = require("./union.js");
|
|
15
|
+
const paramScalarSchema = (0, union_js_1.union)([(0, boolean_js_1.boolean)(), (0, integer_js_1.integer)(), (0, string_js_1.string)()]);
|
|
16
|
+
exports.paramSchema = (0, union_js_1.union)([paramScalarSchema, (0, array_js_1.array)(paramScalarSchema)]);
|
|
17
|
+
exports.paramsSchema = (0, dict_js_1.dict)((0, string_js_1.string)(), (0, optional_js_1.optional)(exports.paramSchema));
|
|
9
18
|
class ParamsSchema extends core_js_1.Schema {
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
19
|
+
shape;
|
|
20
|
+
constructor(shape) {
|
|
12
21
|
super();
|
|
13
|
-
this.
|
|
22
|
+
this.shape = shape;
|
|
14
23
|
}
|
|
15
|
-
get
|
|
16
|
-
const map = new Map(Object.entries(this.
|
|
17
|
-
return (0, lazy_property_js_1.lazyProperty)(this, '
|
|
24
|
+
get shapeValidators() {
|
|
25
|
+
const map = new Map(Object.entries(this.shape));
|
|
26
|
+
return (0, lazy_property_js_1.lazyProperty)(this, 'shapeValidators', map);
|
|
18
27
|
}
|
|
19
|
-
validateInContext(input
|
|
28
|
+
validateInContext(input, ctx) {
|
|
29
|
+
// @TODO BETTER SUPPORT Input/Output
|
|
20
30
|
if (!(0, lex_data_1.isPlainObject)(input)) {
|
|
21
31
|
return ctx.issueInvalidType(input, 'object');
|
|
22
32
|
}
|
|
@@ -24,17 +34,21 @@ class ParamsSchema extends core_js_1.Schema {
|
|
|
24
34
|
let copy;
|
|
25
35
|
// Ensure that non-specified params conform to param schema
|
|
26
36
|
for (const key in input) {
|
|
27
|
-
if (this.
|
|
37
|
+
if (this.shapeValidators.has(key))
|
|
28
38
|
continue;
|
|
29
|
-
const result = ctx.validateChild(input, key,
|
|
39
|
+
const result = ctx.validateChild(input, key, exports.paramSchema);
|
|
30
40
|
if (!result.success)
|
|
31
41
|
return result;
|
|
32
42
|
if (result.value !== input[key]) {
|
|
43
|
+
if (ctx.options.mode === 'validate') {
|
|
44
|
+
// In "validate" mode, we can't modify the input, so we issue an error
|
|
45
|
+
return ctx.issueInvalidPropertyValue(input, key, [result.value]);
|
|
46
|
+
}
|
|
33
47
|
copy ??= { ...input };
|
|
34
48
|
copy[key] = result.value;
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
|
-
for (const [key, propDef] of this.
|
|
51
|
+
for (const [key, propDef] of this.shapeValidators) {
|
|
38
52
|
const result = ctx.validateChild(input, key, propDef);
|
|
39
53
|
if (!result.success) {
|
|
40
54
|
if (!(key in input)) {
|
|
@@ -47,19 +61,23 @@ class ParamsSchema extends core_js_1.Schema {
|
|
|
47
61
|
if (result.value === undefined && !(key in input)) {
|
|
48
62
|
continue;
|
|
49
63
|
}
|
|
50
|
-
if (result.value
|
|
64
|
+
if (!Object.is(result.value, input[key])) {
|
|
65
|
+
if (ctx.options.mode === 'validate') {
|
|
66
|
+
// In "validate" mode, we can't modify the input, so we issue an error
|
|
67
|
+
return ctx.issueInvalidPropertyValue(input, key, [result.value]);
|
|
68
|
+
}
|
|
51
69
|
// Copy on write
|
|
52
70
|
copy ??= { ...input };
|
|
53
71
|
copy[key] = result.value;
|
|
54
72
|
}
|
|
55
73
|
}
|
|
56
|
-
return ctx.success(
|
|
74
|
+
return ctx.success(copy ?? input);
|
|
57
75
|
}
|
|
58
76
|
fromURLSearchParams(urlSearchParams) {
|
|
59
77
|
const params = {};
|
|
60
78
|
for (const [key, value] of urlSearchParams.entries()) {
|
|
61
|
-
const validator = this.
|
|
62
|
-
const coerced = validator
|
|
79
|
+
const validator = this.shapeValidators.get(key);
|
|
80
|
+
const coerced = validator instanceof string_js_1.StringSchema
|
|
63
81
|
? value
|
|
64
82
|
: value === 'true'
|
|
65
83
|
? true
|
|
@@ -82,20 +100,24 @@ class ParamsSchema extends core_js_1.Schema {
|
|
|
82
100
|
}
|
|
83
101
|
toURLSearchParams(input) {
|
|
84
102
|
const urlSearchParams = new URLSearchParams();
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
else if (value !== undefined) {
|
|
93
|
-
urlSearchParams.append(key, String(value));
|
|
103
|
+
// @NOTE We apply defaults here to ensure that server with different
|
|
104
|
+
// defaults still receive all expected parameters.
|
|
105
|
+
const params = this.parse(input);
|
|
106
|
+
for (const [key, value] of Object.entries(params)) {
|
|
107
|
+
if (Array.isArray(value)) {
|
|
108
|
+
for (const v of value) {
|
|
109
|
+
urlSearchParams.append(key, String(v));
|
|
94
110
|
}
|
|
95
111
|
}
|
|
112
|
+
else if (value !== undefined) {
|
|
113
|
+
urlSearchParams.append(key, String(value));
|
|
114
|
+
}
|
|
96
115
|
}
|
|
97
116
|
return urlSearchParams;
|
|
98
117
|
}
|
|
99
118
|
}
|
|
100
119
|
exports.ParamsSchema = ParamsSchema;
|
|
120
|
+
exports.params = (0, memoize_js_1.memoizedOptions)(function params(properties = {}) {
|
|
121
|
+
return new ParamsSchema(properties);
|
|
122
|
+
});
|
|
101
123
|
//# sourceMappingURL=params.js.map
|