@atproto/lex-schema 0.0.5 → 0.0.7
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 +30 -0
- package/dist/core/$type.d.ts +6 -3
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js.map +1 -1
- package/dist/core/property-key.d.ts.map +1 -0
- package/dist/core/property-key.js.map +1 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/validation-error.d.ts +19 -0
- package/dist/core/validation-error.d.ts.map +1 -0
- package/dist/{validation → core}/validation-error.js +12 -5
- package/dist/core/validation-error.js.map +1 -0
- package/dist/{validation → core}/validation-issue.d.ts +43 -0
- package/dist/core/validation-issue.d.ts.map +1 -0
- package/dist/{validation → core}/validation-issue.js +45 -0
- package/dist/core/validation-issue.js.map +1 -0
- package/dist/{validation → core}/validator.d.ts +1 -1
- package/dist/core/validator.d.ts.map +1 -0
- package/dist/{validation → core}/validator.js +4 -4
- package/dist/core/validator.js.map +1 -0
- package/dist/core.d.ts +5 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +5 -0
- package/dist/core.js.map +1 -1
- package/dist/external.d.ts +15 -16
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +38 -55
- package/dist/external.js.map +1 -1
- package/dist/helpers.d.ts +7 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +10 -0
- package/dist/helpers.js.map +1 -1
- package/dist/schema/_parameters.d.ts +1 -1
- package/dist/schema/_parameters.d.ts.map +1 -1
- package/dist/schema/_parameters.js.map +1 -1
- package/dist/schema/array.d.ts +1 -1
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +2 -2
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +3 -7
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +2 -2
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.d.ts +1 -1
- package/dist/schema/boolean.d.ts.map +1 -1
- package/dist/schema/boolean.js +2 -2
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.d.ts +1 -1
- package/dist/schema/bytes.d.ts.map +1 -1
- package/dist/schema/bytes.js +2 -2
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +1 -1
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +2 -2
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.d.ts +1 -1
- package/dist/schema/custom.d.ts.map +1 -1
- package/dist/schema/custom.js +3 -3
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +1 -1
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +2 -2
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +1 -1
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +2 -2
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.d.ts +1 -1
- package/dist/schema/enum.d.ts.map +1 -1
- package/dist/schema/enum.js +2 -2
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.d.ts +1 -1
- package/dist/schema/integer.d.ts.map +1 -1
- package/dist/schema/integer.js +4 -4
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +1 -2
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +2 -2
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/literal.d.ts +1 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +2 -2
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.d.ts +1 -1
- package/dist/schema/never.d.ts.map +1 -1
- package/dist/schema/never.js +2 -2
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.d.ts +1 -1
- package/dist/schema/null.d.ts.map +1 -1
- package/dist/schema/null.js +2 -2
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +1 -1
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +2 -2
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +1 -2
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +2 -2
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +1 -1
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +2 -2
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +1 -2
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +2 -2
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +1 -1
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/record.d.ts +9 -14
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +5 -3
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +1 -1
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +2 -2
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +18 -1
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js +2 -2
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.d.ts +1 -1
- package/dist/schema/regexp.d.ts.map +1 -1
- package/dist/schema/regexp.js +2 -2
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +1 -2
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +1 -2
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +1 -2
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +1 -1
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +2 -2
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +8 -13
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +5 -3
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +1 -1
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +2 -2
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +2 -3
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +2 -2
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +1 -1
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +3 -3
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown-object.d.ts +1 -2
- package/dist/schema/unknown-object.d.ts.map +1 -1
- package/dist/schema/unknown-object.js +2 -2
- package/dist/schema/unknown-object.js.map +1 -1
- package/dist/schema/unknown.d.ts +1 -1
- package/dist/schema/unknown.d.ts.map +1 -1
- package/dist/schema/unknown.js +2 -2
- package/dist/schema/unknown.js.map +1 -1
- package/dist/util/memoize.d.ts +3 -0
- package/dist/util/memoize.d.ts.map +1 -0
- package/dist/util/memoize.js +52 -0
- package/dist/util/memoize.js.map +1 -0
- package/package.json +6 -6
- package/src/core/$type.ts +13 -2
- package/src/{validation → core}/validation-error.ts +11 -3
- package/src/{validation → core}/validation-issue.ts +52 -0
- package/src/{validation → core}/validator.ts +1 -1
- package/src/core.ts +5 -0
- package/src/external.ts +67 -48
- package/src/helpers.test.ts +1 -0
- package/src/helpers.ts +16 -2
- package/src/schema/_parameters.test.ts +1 -0
- package/src/schema/_parameters.ts +1 -1
- package/src/schema/array.test.ts +1 -0
- package/src/schema/array.ts +1 -1
- package/src/schema/blob.test.ts +1 -0
- package/src/schema/blob.ts +3 -6
- package/src/schema/boolean.test.ts +1 -0
- package/src/schema/boolean.ts +1 -1
- package/src/schema/bytes.test.ts +1 -0
- package/src/schema/bytes.ts +1 -1
- package/src/schema/cid.test.ts +1 -0
- package/src/schema/cid.ts +1 -1
- package/src/schema/custom.test.ts +3 -2
- package/src/schema/custom.ts +1 -1
- package/src/schema/dict.test.ts +1 -0
- package/src/schema/dict.ts +1 -1
- package/src/schema/discriminated-union.test.ts +1 -0
- package/src/schema/discriminated-union.ts +1 -1
- package/src/schema/enum.test.ts +1 -0
- package/src/schema/enum.ts +1 -1
- package/src/schema/integer.test.ts +1 -0
- package/src/schema/integer.ts +3 -3
- package/src/schema/intersection.test.ts +1 -0
- package/src/schema/intersection.ts +2 -2
- package/src/schema/literal.test.ts +1 -0
- package/src/schema/literal.ts +1 -1
- package/src/schema/never.test.ts +1 -0
- package/src/schema/never.ts +1 -1
- package/src/schema/null.test.ts +1 -0
- package/src/schema/null.ts +1 -1
- package/src/schema/nullable.test.ts +1 -0
- package/src/schema/nullable.ts +1 -1
- package/src/schema/object.test.ts +1 -0
- package/src/schema/object.ts +3 -3
- package/src/schema/optional.test.ts +1 -0
- package/src/schema/optional.ts +1 -1
- package/src/schema/params.test.ts +1 -0
- package/src/schema/params.ts +3 -3
- package/src/schema/payload.test.ts +1 -0
- package/src/schema/payload.ts +1 -1
- package/src/schema/permission-set.test.ts +1 -0
- package/src/schema/permission.test.ts +1 -0
- package/src/schema/procedure.test.ts +1 -0
- package/src/schema/query.test.ts +1 -0
- package/src/schema/record.test.ts +1 -0
- package/src/schema/record.ts +11 -9
- package/src/schema/ref.test.ts +2 -1
- package/src/schema/ref.ts +1 -1
- package/src/schema/refine.test.ts +1 -0
- package/src/schema/refine.ts +18 -1
- package/src/schema/regexp.test.ts +1 -0
- package/src/schema/regexp.ts +1 -1
- package/src/schema/string.test.ts +1 -0
- package/src/schema/string.ts +8 -2
- package/src/schema/subscription.test.ts +1 -0
- package/src/schema/subscription.ts +1 -2
- package/src/schema/token.test.ts +1 -0
- package/src/schema/token.ts +1 -1
- package/src/schema/typed-object.test.ts +1 -0
- package/src/schema/typed-object.ts +10 -6
- package/src/schema/typed-ref.test.ts +1 -0
- package/src/schema/typed-ref.ts +1 -1
- package/src/schema/typed-union.test.ts +1 -0
- package/src/schema/typed-union.ts +4 -4
- package/src/schema/union.test.ts +1 -0
- package/src/schema/union.ts +1 -1
- package/src/schema/unknown-object.test.ts +1 -0
- package/src/schema/unknown-object.ts +1 -2
- package/src/schema/unknown.test.ts +1 -0
- package/src/schema/unknown.ts +1 -1
- package/src/util/array-agg.test.ts +1 -0
- package/src/util/memoize.ts +57 -0
- package/tsconfig.tests.json +1 -1
- package/dist/validation/property-key.d.ts.map +0 -1
- package/dist/validation/property-key.js.map +0 -1
- package/dist/validation/schema.d.ts.map +0 -1
- package/dist/validation/schema.js.map +0 -1
- package/dist/validation/validation-error.d.ts +0 -9
- package/dist/validation/validation-error.d.ts.map +0 -1
- package/dist/validation/validation-error.js.map +0 -1
- package/dist/validation/validation-issue.d.ts.map +0 -1
- package/dist/validation/validation-issue.js.map +0 -1
- package/dist/validation/validator.d.ts.map +0 -1
- package/dist/validation/validator.js.map +0 -1
- package/dist/validation.d.ts +0 -6
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -9
- package/dist/validation.js.map +0 -1
- package/src/validation.ts +0 -5
- /package/dist/{validation → core}/property-key.d.ts +0 -0
- /package/dist/{validation → core}/property-key.js +0 -0
- /package/dist/{validation → core}/schema.d.ts +0 -0
- /package/dist/{validation → core}/schema.js +0 -0
- /package/src/{validation → core}/property-key.ts +0 -0
- /package/src/{validation → core}/schema.ts +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Restricted,
|
|
2
|
-
import { Infer, Schema, ValidationResult, ValidatorContext } from '../validation.js';
|
|
1
|
+
import { Infer, Restricted, Schema, ValidationResult, ValidatorContext } from '../core.js';
|
|
3
2
|
import { TypedRefSchema, TypedRefSchemaOutput } from './typed-ref.js';
|
|
4
3
|
export type TypedRef<T extends {
|
|
5
4
|
$type?: string;
|
|
6
5
|
}> = TypedRefSchemaOutput<T>;
|
|
7
6
|
export type TypedObject = {
|
|
8
|
-
$type:
|
|
7
|
+
$type: string;
|
|
9
8
|
} & {
|
|
10
9
|
[K in string]: Restricted<'Unknown property'>;
|
|
11
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-union.d.ts","sourceRoot":"","sources":["../../src/schema/typed-union.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"typed-union.d.ts","sourceRoot":"","sources":["../../src/schema/typed-union.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAErE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAE5E,MAAM,MAAM,WAAW,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;KAgB3C,CAAC,IAAI,MAAM,GAAG,UAAU,CAAC,kBAAkB,CAAC;CAC9C,CAAA;AAED,KAAK,sBAAsB,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE,IAAI;KAChE,CAAC,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5B,CAAC,MAAM,CAAC,CAAA;AAET,MAAM,MAAM,sBAAsB,CAChC,SAAS,SAAS,SAAS,cAAc,EAAE,EAC3C,MAAM,SAAS,OAAO,IACpB,MAAM,SAAS,IAAI,GACnB,sBAAsB,CAAC,SAAS,CAAC,GACjC,sBAAsB,CAAC,SAAS,CAAC,GAAG,WAAW,CAAA;AAEnD,qBAAa,gBAAgB,CAC3B,SAAS,SAAS,SAAS,cAAc,EAAE,GAAG,GAAG,EACjD,MAAM,SAAS,OAAO,GAAG,GAAG,CAC5B,SAAQ,MAAM,CAAC,sBAAsB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAEvD,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS;aAClB,MAAM,EAAE,MAAM;gBADX,IAAI,EAAE,SAAS,EAClB,MAAM,EAAE,MAAM;IAShC,IAAI,OAAO,IAAI,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAK7C;IAED,IAAI,MAAM,cAET;IAED,iBAAiB,CACf,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACpB,gBAAgB,CAAC,sBAAsB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;CAwB/D"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypedUnionSchema = void 0;
|
|
4
4
|
const lex_data_1 = require("@atproto/lex-data");
|
|
5
|
+
const core_js_1 = require("../core.js");
|
|
5
6
|
const lazy_property_js_1 = require("../util/lazy-property.js");
|
|
6
|
-
|
|
7
|
-
class TypedUnionSchema extends validation_js_1.Schema {
|
|
7
|
+
class TypedUnionSchema extends core_js_1.Schema {
|
|
8
8
|
refs;
|
|
9
9
|
closed;
|
|
10
10
|
constructor(refs, closed) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-union.js","sourceRoot":"","sources":["../../src/schema/typed-union.ts"],"names":[],"mappings":";;;AAAA,gDAAiD;
|
|
1
|
+
{"version":3,"file":"typed-union.js","sourceRoot":"","sources":["../../src/schema/typed-union.ts"],"names":[],"mappings":";;;AAAA,gDAAiD;AACjD,wCAMmB;AACnB,+DAAuD;AAmCvD,MAAa,gBAGX,SAAQ,gBAAiD;IAEpC;IACH;IAFlB,YACqB,IAAe,EAClB,MAAc;QAE9B,0EAA0E;QAC1E,2EAA2E;QAC3E,UAAU;QAEV,KAAK,EAAE,CAAA;QAPY,SAAI,GAAJ,IAAI,CAAW;QAClB,WAAM,GAAN,MAAM,CAAQ;IAOhC,CAAC;IAED,IAAI,OAAO;QACT,MAAM,GAAG,GAAG,IAAI,GAAG,EAA8B,CAAA;QACjD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAEpD,OAAO,IAAA,+BAAY,EAAC,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,MAAM;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,iBAAiB,CACf,KAAc,EACd,GAAqB;QAErB,IAAI,CAAC,IAAA,wBAAa,EAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,KAAK,CAAC,EAAE,CAAC;YACjD,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC9C,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAA;QAEvB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACnC,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YACvC,OAAO,MAEN,CAAA;QACH,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,GAAG,CAAC,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACnE,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC/D,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAkD,CAAC,CAAA;IACxE,CAAC;CACF;AArDD,4CAqDC","sourcesContent":["import { isPlainObject } from '@atproto/lex-data'\nimport {\n Infer,\n Restricted,\n Schema,\n ValidationResult,\n ValidatorContext,\n} from '../core.js'\nimport { lazyProperty } from '../util/lazy-property.js'\nimport { TypedRefSchema, TypedRefSchemaOutput } from './typed-ref.js'\n\nexport type TypedRef<T extends { $type?: string }> = TypedRefSchemaOutput<T>\n\nexport type TypedObject = { $type: string } & {\n // In order to prevent places that expect an open union from accepting an\n // invalid version of the known typed objects, we need to prevent any other\n // properties from being present.\n //\n // For example, if an open union expects:\n // ```ts\n // TypedObject | { $type: 'A'; a: number }\n // ```\n // we don't want it to accept:\n // ```ts\n // { $type: 'A' }\n // ```\n // Which would be the case as `{ $type: 'A' }` is a valid\n // `TypedObject`. By adding an index signature that forbids any\n // property, we ensure that only valid known typed objects can be used.\n [K in string]: Restricted<'Unknown property'>\n}\n\ntype TypedRefSchemasToUnion<T extends readonly TypedRefSchema[]> = {\n [K in keyof T]: Infer<T[K]>\n}[number]\n\nexport type TypedUnionSchemaOutput<\n TypedRefs extends readonly TypedRefSchema[],\n Closed extends boolean,\n> = Closed extends true\n ? TypedRefSchemasToUnion<TypedRefs>\n : TypedRefSchemasToUnion<TypedRefs> | TypedObject\n\nexport class TypedUnionSchema<\n TypedRefs extends readonly TypedRefSchema[] = any,\n Closed extends boolean = any,\n> extends Schema<TypedUnionSchemaOutput<TypedRefs, Closed>> {\n constructor(\n protected readonly refs: TypedRefs,\n public readonly closed: Closed,\n ) {\n // @NOTE In order to avoid circular dependency issues, we don't access the\n // refs's schema (or $type) here. Instead, we access them lazily when first\n // needed.\n\n super()\n }\n\n get refsMap(): Map<unknown, TypedRefs[number]> {\n const map = new Map<unknown, TypedRefs[number]>()\n for (const ref of this.refs) map.set(ref.$type, ref)\n\n return lazyProperty(this, 'refsMap', map)\n }\n\n get $types() {\n return Array.from(this.refsMap.keys())\n }\n\n validateInContext(\n input: unknown,\n ctx: ValidatorContext,\n ): ValidationResult<TypedUnionSchemaOutput<TypedRefs, Closed>> {\n if (!isPlainObject(input) || !('$type' in input)) {\n return ctx.issueInvalidType(input, '$typed')\n }\n\n const { $type } = input\n\n const def = this.refsMap.get($type)\n if (def) {\n const result = ctx.validate(input, def)\n return result as ValidationResult<\n TypedUnionSchemaOutput<TypedRefs, Closed>\n >\n }\n\n if (this.closed) {\n return ctx.issueInvalidPropertyValue(input, '$type', this.$types)\n }\n if (typeof $type !== 'string') {\n return ctx.issueInvalidPropertyType(input, '$type', 'string')\n }\n\n return ctx.success(input as TypedUnionSchemaOutput<TypedRefs, Closed>)\n }\n}\n"]}
|
package/dist/schema/union.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Infer, Schema, ValidationResult, Validator, ValidatorContext } from '../
|
|
1
|
+
import { Infer, Schema, ValidationResult, Validator, ValidatorContext } from '../core.js';
|
|
2
2
|
export type UnionSchemaValidators = readonly [Validator, ...Validator[]];
|
|
3
3
|
export type UnionSchemaOutput<V extends readonly Validator[]> = Infer<V[number]>;
|
|
4
4
|
export declare class UnionSchema<V extends UnionSchemaValidators = any> extends Schema<UnionSchemaOutput<V>> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/schema/union.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,EAGN,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EACjB,MAAM,
|
|
1
|
+
{"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/schema/union.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,EAGN,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,qBAAqB,GAAG,SAAS,CAAC,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC,CAAA;AACxE,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,SAAS,SAAS,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAEhF,qBAAa,WAAW,CAAC,CAAC,SAAS,qBAAqB,GAAG,GAAG,CAAE,SAAQ,MAAM,CAC5E,iBAAiB,CAAC,CAAC,CAAC,CACrB;IACa,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;gBAAb,UAAU,EAAE,CAAC;IAI5C,iBAAiB,CACf,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACpB,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAc1C"}
|
package/dist/schema/union.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnionSchema = void 0;
|
|
4
|
-
const
|
|
5
|
-
class UnionSchema extends
|
|
4
|
+
const core_js_1 = require("../core.js");
|
|
5
|
+
class UnionSchema extends core_js_1.Schema {
|
|
6
6
|
validators;
|
|
7
7
|
constructor(validators) {
|
|
8
8
|
super();
|
|
@@ -19,7 +19,7 @@ class UnionSchema extends validation_js_1.Schema {
|
|
|
19
19
|
failures.push(result);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
return ctx.failure(
|
|
22
|
+
return ctx.failure(core_js_1.ValidationError.fromFailures(failures));
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.UnionSchema = UnionSchema;
|
package/dist/schema/union.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/schema/union.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/schema/union.ts"],"names":[],"mappings":";;;AAAA,wCAQmB;AAKnB,MAAa,WAAmD,SAAQ,gBAEvE;IACgC;IAA/B,YAA+B,UAAa;QAC1C,KAAK,EAAE,CAAA;QADsB,eAAU,GAAV,UAAU,CAAG;IAE5C,CAAC;IAED,iBAAiB,CACf,KAAc,EACd,GAAqB;QAErB,MAAM,QAAQ,GAAwB,EAAE,CAAA;QAExC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;YAC7C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,MAAgD,CAAA;YACzD,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACvB,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAe,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC5D,CAAC;CACF;AAxBD,kCAwBC","sourcesContent":["import {\n Infer,\n Schema,\n ValidationError,\n ValidationFailure,\n ValidationResult,\n Validator,\n ValidatorContext,\n} from '../core.js'\n\nexport type UnionSchemaValidators = readonly [Validator, ...Validator[]]\nexport type UnionSchemaOutput<V extends readonly Validator[]> = Infer<V[number]>\n\nexport class UnionSchema<V extends UnionSchemaValidators = any> extends Schema<\n UnionSchemaOutput<V>\n> {\n constructor(protected readonly validators: V) {\n super()\n }\n\n validateInContext(\n input: unknown,\n ctx: ValidatorContext,\n ): ValidationResult<UnionSchemaOutput<V>> {\n const failures: ValidationFailure[] = []\n\n for (const validator of this.validators) {\n const result = ctx.validate(input, validator)\n if (result.success) {\n return result as ValidationResult<UnionSchemaOutput<V>>\n } else {\n failures.push(result)\n }\n }\n\n return ctx.failure(ValidationError.fromFailures(failures))\n }\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LexMap } from '@atproto/lex-data';
|
|
2
|
-
import { Schema, ValidationResult, ValidatorContext } from '../
|
|
3
|
-
export type { LexMap };
|
|
2
|
+
import { Schema, ValidationResult, ValidatorContext } from '../core.js';
|
|
4
3
|
export type UnknownObjectOutput = LexMap;
|
|
5
4
|
export declare class UnknownObjectSchema extends Schema<UnknownObjectOutput> {
|
|
6
5
|
validateInContext(input: unknown, ctx: ValidatorContext): ValidationResult<UnknownObjectOutput>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown-object.d.ts","sourceRoot":"","sources":["../../src/schema/unknown-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"unknown-object.d.ts","sourceRoot":"","sources":["../../src/schema/unknown-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEvE,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAExC,qBAAa,mBAAoB,SAAQ,MAAM,CAAC,mBAAmB,CAAC;IAClE,iBAAiB,CACf,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACpB,gBAAgB,CAAC,mBAAmB,CAAC;CAOzC"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnknownObjectSchema = void 0;
|
|
4
4
|
const lex_data_1 = require("@atproto/lex-data");
|
|
5
|
-
const
|
|
6
|
-
class UnknownObjectSchema extends
|
|
5
|
+
const core_js_1 = require("../core.js");
|
|
6
|
+
class UnknownObjectSchema extends core_js_1.Schema {
|
|
7
7
|
validateInContext(input, ctx) {
|
|
8
8
|
if ((0, lex_data_1.isLexMap)(input)) {
|
|
9
9
|
return ctx.success(input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown-object.js","sourceRoot":"","sources":["../../src/schema/unknown-object.ts"],"names":[],"mappings":";;;AAAA,gDAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"unknown-object.js","sourceRoot":"","sources":["../../src/schema/unknown-object.ts"],"names":[],"mappings":";;;AAAA,gDAAoD;AACpD,wCAAuE;AAIvE,MAAa,mBAAoB,SAAQ,gBAA2B;IAClE,iBAAiB,CACf,KAAc,EACd,GAAqB;QAErB,IAAI,IAAA,mBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAC/C,CAAC;CACF;AAXD,kDAWC","sourcesContent":["import { LexMap, isLexMap } from '@atproto/lex-data'\nimport { Schema, ValidationResult, ValidatorContext } from '../core.js'\n\nexport type UnknownObjectOutput = LexMap\n\nexport class UnknownObjectSchema extends Schema<UnknownObjectOutput> {\n validateInContext(\n input: unknown,\n ctx: ValidatorContext,\n ): ValidationResult<UnknownObjectOutput> {\n if (isLexMap(input)) {\n return ctx.success(input)\n }\n\n return ctx.issueInvalidType(input, 'unknown')\n }\n}\n"]}
|
package/dist/schema/unknown.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema, ValidationResult, ValidatorContext } from '../
|
|
1
|
+
import { Schema, ValidationResult, ValidatorContext } from '../core.js';
|
|
2
2
|
export declare class UnknownSchema extends Schema<unknown> {
|
|
3
3
|
validateInContext(input: unknown, ctx: ValidatorContext): ValidationResult<unknown>;
|
|
4
4
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown.d.ts","sourceRoot":"","sources":["../../src/schema/unknown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"unknown.d.ts","sourceRoot":"","sources":["../../src/schema/unknown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEvE,qBAAa,aAAc,SAAQ,MAAM,CAAC,OAAO,CAAC;IAChD,iBAAiB,CACf,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACpB,gBAAgB,CAAC,OAAO,CAAC;CAG7B"}
|
package/dist/schema/unknown.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnknownSchema = void 0;
|
|
4
|
-
const
|
|
5
|
-
class UnknownSchema extends
|
|
4
|
+
const core_js_1 = require("../core.js");
|
|
5
|
+
class UnknownSchema extends core_js_1.Schema {
|
|
6
6
|
validateInContext(input, ctx) {
|
|
7
7
|
return ctx.success(input);
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../src/schema/unknown.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../src/schema/unknown.ts"],"names":[],"mappings":";;;AAAA,wCAAuE;AAEvE,MAAa,aAAc,SAAQ,gBAAe;IAChD,iBAAiB,CACf,KAAc,EACd,GAAqB;QAErB,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AAPD,sCAOC","sourcesContent":["import { Schema, ValidationResult, ValidatorContext } from '../core.js'\n\nexport class UnknownSchema extends Schema<unknown> {\n validateInContext(\n input: unknown,\n ctx: ValidatorContext,\n ): ValidationResult<unknown> {\n return ctx.success(input)\n }\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function memoizedOptions<F extends (options?: NonNullable<unknown>) => any>(fn: F, keyFn?: (options: NonNullable<Parameters<F>[0]>) => string | number | boolean | null | void): F;
|
|
2
|
+
export declare function memoizedTransformer<F extends (arg: any) => any>(fn: F): F;
|
|
3
|
+
//# sourceMappingURL=memoize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/util/memoize.ts"],"names":[],"mappings":"AACA,wBAAgB,eAAe,CAC7B,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,GAAG,EAEjD,EAAE,EAAE,CAAC,EACL,KAAK,CAAC,EAAE,CACN,OAAO,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KACnC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,GAC3C,CAAC,CAoCH;AAGD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CASzE"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memoizedOptions = memoizedOptions;
|
|
4
|
+
exports.memoizedTransformer = memoizedTransformer;
|
|
5
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
6
|
+
function memoizedOptions(fn, keyFn) {
|
|
7
|
+
let emptyOptionsValue;
|
|
8
|
+
if (keyFn) {
|
|
9
|
+
const cache = new Map();
|
|
10
|
+
const fromCache = (options) => {
|
|
11
|
+
const key = keyFn(options);
|
|
12
|
+
if (key !== undefined) {
|
|
13
|
+
const cached = cache.get(key);
|
|
14
|
+
if (cached)
|
|
15
|
+
return cached;
|
|
16
|
+
const result = fn(options);
|
|
17
|
+
cache.set(key, result);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
return fn(options);
|
|
21
|
+
};
|
|
22
|
+
return ((options) => {
|
|
23
|
+
// Non-empty options case
|
|
24
|
+
if (options)
|
|
25
|
+
for (const _ in options)
|
|
26
|
+
return fromCache(options);
|
|
27
|
+
// Empty or missing options case
|
|
28
|
+
return (emptyOptionsValue ??= fn(options));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return ((options) => {
|
|
32
|
+
// Non-empty options case
|
|
33
|
+
if (options)
|
|
34
|
+
for (const _ in options)
|
|
35
|
+
return fn(options);
|
|
36
|
+
// Empty or missing options case
|
|
37
|
+
return (emptyOptionsValue ??= fn(options));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
41
|
+
function memoizedTransformer(fn) {
|
|
42
|
+
const cache = new WeakMap();
|
|
43
|
+
return ((arg) => {
|
|
44
|
+
const cached = cache.get(arg);
|
|
45
|
+
if (cached)
|
|
46
|
+
return cached;
|
|
47
|
+
const result = fn(arg);
|
|
48
|
+
cache.set(arg, result);
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=memoize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/util/memoize.ts"],"names":[],"mappings":";;AACA,0CA2CC;AAGD,kDASC;AAxDD,wBAAwB;AACxB,SAAgB,eAAe,CAG7B,EAAK,EACL,KAE4C;IAE5C,IAAI,iBAA4C,CAAA;IAEhD,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmD,CAAA;QACxE,MAAM,SAAS,GAAG,CAChB,OAAsC,EACvB,EAAE;YACjB,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA;YAC1B,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBAC7B,IAAI,MAAM;oBAAE,OAAO,MAAM,CAAA;gBACzB,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAkB,CAAA;gBAC3C,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;gBACtB,OAAO,MAAM,CAAA;YACf,CAAC;YAED,OAAO,EAAE,CAAC,OAAO,CAAC,CAAA;QACpB,CAAC,CAAA;QAED,OAAO,CAAC,CAAC,OAAyB,EAAiB,EAAE;YACnD,yBAAyB;YACzB,IAAI,OAAO;gBAAE,KAAK,MAAM,CAAC,IAAI,OAAO;oBAAE,OAAO,SAAS,CAAC,OAAO,CAAC,CAAA;YAE/D,gCAAgC;YAChC,OAAO,CAAC,iBAAiB,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;QAC5C,CAAC,CAAM,CAAA;IACT,CAAC;IAED,OAAO,CAAC,CAAC,OAAyB,EAAiB,EAAE;QACnD,yBAAyB;QACzB,IAAI,OAAO;YAAE,KAAK,MAAM,CAAC,IAAI,OAAO;gBAAE,OAAO,EAAE,CAAC,OAAO,CAAC,CAAA;QAExD,gCAAgC;QAChC,OAAO,CAAC,iBAAiB,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5C,CAAC,CAAM,CAAA;AACT,CAAC;AAED,wBAAwB;AACxB,SAAgB,mBAAmB,CAA8B,EAAK;IACpE,MAAM,KAAK,GAAG,IAAI,OAAO,EAAyB,CAAA;IAClD,OAAO,CAAC,CAAC,GAAqB,EAAiB,EAAE;QAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,MAAM;YAAE,OAAO,MAAM,CAAA;QACzB,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAkB,CAAA;QACvC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACtB,OAAO,MAAM,CAAA;IACf,CAAC,CAAM,CAAA;AACT,CAAC","sourcesContent":["/*@__NO_SIDE_EFFECTS__*/\nexport function memoizedOptions<\n F extends (options?: NonNullable<unknown>) => any,\n>(\n fn: F,\n keyFn?: (\n options: NonNullable<Parameters<F>[0]>,\n ) => string | number | boolean | null | void,\n): F {\n let emptyOptionsValue: ReturnType<F> | undefined\n\n if (keyFn) {\n const cache = new Map<string | number | boolean | null, ReturnType<F>>()\n const fromCache = (\n options: NonNullable<Parameters<F>[0]>,\n ): ReturnType<F> => {\n const key = keyFn(options)\n if (key !== undefined) {\n const cached = cache.get(key)\n if (cached) return cached\n const result = fn(options) as ReturnType<F>\n cache.set(key, result)\n return result\n }\n\n return fn(options)\n }\n\n return ((options: Parameters<F>[0]): ReturnType<F> => {\n // Non-empty options case\n if (options) for (const _ in options) return fromCache(options)\n\n // Empty or missing options case\n return (emptyOptionsValue ??= fn(options))\n }) as F\n }\n\n return ((options: Parameters<F>[0]): ReturnType<F> => {\n // Non-empty options case\n if (options) for (const _ in options) return fn(options)\n\n // Empty or missing options case\n return (emptyOptionsValue ??= fn(options))\n }) as F\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function memoizedTransformer<F extends (arg: any) => any>(fn: F): F {\n const cache = new WeakMap<object, ReturnType<F>>()\n return ((arg: Parameters<F>[0]): ReturnType<F> => {\n const cached = cache.get(arg)\n if (cached) return cached\n const result = fn(arg) as ReturnType<F>\n cache.set(arg, result)\n return result\n }) as F\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Lexicon schema system for AT Lexicons",
|
|
6
6
|
"keywords": [
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
31
32
|
"browser": "./dist/index.js",
|
|
32
33
|
"import": "./dist/index.js",
|
|
33
|
-
"require": "./dist/index.js"
|
|
34
|
-
"types": "./dist/index.d.ts"
|
|
34
|
+
"require": "./dist/index.js"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"tslib": "^2.8.1",
|
|
39
39
|
"@atproto/syntax": "0.4.2",
|
|
40
|
-
"@atproto/lex-data": "0.0.
|
|
40
|
+
"@atproto/lex-data": "0.0.6"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"
|
|
43
|
+
"vitest": "^4.0.16"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsc --build tsconfig.build.json",
|
|
47
|
-
"test": "
|
|
47
|
+
"test": "vitest run"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/src/core/$type.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NsidString } from './string-format.js'
|
|
2
|
-
import { OmitKey } from './types.js'
|
|
2
|
+
import { OmitKey, Simplify } from './types.js'
|
|
3
3
|
|
|
4
4
|
export type $Type<
|
|
5
5
|
N extends NsidString = NsidString,
|
|
@@ -22,5 +22,16 @@ export function $type<N extends NsidString, H extends string>(
|
|
|
22
22
|
return (hash === 'main' ? nsid : `${nsid}#${hash}`) as $Type<N, H>
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type $Typed<V, T extends string = string> =
|
|
25
|
+
export type $Typed<V, T extends string = string> = Simplify<
|
|
26
|
+
V & {
|
|
27
|
+
$type: T
|
|
28
|
+
}
|
|
29
|
+
>
|
|
30
|
+
|
|
31
|
+
export type $TypedMaybe<V, T extends string = string> = Simplify<
|
|
32
|
+
V & {
|
|
33
|
+
$type?: T
|
|
34
|
+
}
|
|
35
|
+
>
|
|
36
|
+
|
|
26
37
|
export type Un$Typed<V extends { $type?: string }> = OmitKey<V, '$type'>
|
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LexError } from '@atproto/lex-data'
|
|
2
2
|
import { arrayAgg } from '../util/array-agg.js'
|
|
3
|
+
import { ResultFailure, failureReason } from './result.js'
|
|
3
4
|
import {
|
|
4
5
|
Issue,
|
|
5
6
|
IssueInvalidType,
|
|
6
7
|
IssueInvalidValue,
|
|
7
8
|
} from './validation-issue.js'
|
|
8
9
|
|
|
9
|
-
export class ValidationError extends
|
|
10
|
+
export class ValidationError extends LexError {
|
|
10
11
|
name = 'ValidationError'
|
|
11
12
|
|
|
12
13
|
readonly issues: Issue[]
|
|
13
14
|
|
|
14
15
|
constructor(issues: Issue[], options?: ErrorOptions) {
|
|
15
16
|
const issuesAgg = aggregateIssues(issues)
|
|
16
|
-
super(issuesAgg.join(', '), options)
|
|
17
|
+
super('InvalidRequest', issuesAgg.join(', '), options)
|
|
17
18
|
this.issues = issuesAgg
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
...super.toJSON(),
|
|
24
|
+
issues: this.issues.map((issue) => issue.toJSON()),
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
static fromFailures(
|
|
21
29
|
failures: ResultFailure<ValidationError>[],
|
|
22
30
|
): ValidationError {
|
|
@@ -9,6 +9,14 @@ export abstract class Issue {
|
|
|
9
9
|
) {}
|
|
10
10
|
|
|
11
11
|
abstract toString(): string
|
|
12
|
+
|
|
13
|
+
toJSON() {
|
|
14
|
+
return {
|
|
15
|
+
code: this.code,
|
|
16
|
+
path: this.path,
|
|
17
|
+
message: this.toString(),
|
|
18
|
+
}
|
|
19
|
+
}
|
|
12
20
|
}
|
|
13
21
|
|
|
14
22
|
export class IssueCustom extends Issue {
|
|
@@ -39,6 +47,13 @@ export class IssueInvalidFormat extends Issue {
|
|
|
39
47
|
return `Invalid ${this.formatDescription} format${this.message ? ` (${this.message})` : ''}${stringifyPath(this.path)} (got ${stringifyValue(this.input)})`
|
|
40
48
|
}
|
|
41
49
|
|
|
50
|
+
toJSON() {
|
|
51
|
+
return {
|
|
52
|
+
...super.toJSON(),
|
|
53
|
+
format: this.format,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
get formatDescription(): string {
|
|
43
58
|
switch (this.format) {
|
|
44
59
|
case 'at-identifier':
|
|
@@ -71,6 +86,13 @@ export class IssueInvalidType extends Issue {
|
|
|
71
86
|
toString() {
|
|
72
87
|
return `Expected ${oneOf(this.expected.map(stringifyExpectedType))} value type${stringifyPath(this.path)} (got ${stringifyType(this.input)})`
|
|
73
88
|
}
|
|
89
|
+
|
|
90
|
+
toJSON() {
|
|
91
|
+
return {
|
|
92
|
+
...super.toJSON(),
|
|
93
|
+
expected: this.expected,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
74
96
|
}
|
|
75
97
|
|
|
76
98
|
export class IssueInvalidValue extends Issue {
|
|
@@ -85,6 +107,13 @@ export class IssueInvalidValue extends Issue {
|
|
|
85
107
|
toString() {
|
|
86
108
|
return `Expected ${oneOf(this.values.map(stringifyValue))}${stringifyPath(this.path)} (got ${stringifyValue(this.input)})`
|
|
87
109
|
}
|
|
110
|
+
|
|
111
|
+
toJSON() {
|
|
112
|
+
return {
|
|
113
|
+
...super.toJSON(),
|
|
114
|
+
values: this.values,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
88
117
|
}
|
|
89
118
|
|
|
90
119
|
export class IssueRequiredKey extends Issue {
|
|
@@ -99,6 +128,13 @@ export class IssueRequiredKey extends Issue {
|
|
|
99
128
|
toString() {
|
|
100
129
|
return `Missing required key "${String(this.key)}"${stringifyPath(this.path)}`
|
|
101
130
|
}
|
|
131
|
+
|
|
132
|
+
toJSON() {
|
|
133
|
+
return {
|
|
134
|
+
...super.toJSON(),
|
|
135
|
+
key: this.key,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
102
138
|
}
|
|
103
139
|
|
|
104
140
|
export type MeasurableType =
|
|
@@ -123,6 +159,14 @@ export class IssueTooBig extends Issue {
|
|
|
123
159
|
toString() {
|
|
124
160
|
return `${this.type} too big (maximum ${this.maximum})${stringifyPath(this.path)} (got ${this.actual})`
|
|
125
161
|
}
|
|
162
|
+
|
|
163
|
+
toJSON() {
|
|
164
|
+
return {
|
|
165
|
+
...super.toJSON(),
|
|
166
|
+
type: this.type,
|
|
167
|
+
maximum: this.maximum,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
126
170
|
}
|
|
127
171
|
|
|
128
172
|
export class IssueTooSmall extends Issue {
|
|
@@ -139,6 +183,14 @@ export class IssueTooSmall extends Issue {
|
|
|
139
183
|
toString() {
|
|
140
184
|
return `${this.type} too small (minimum ${this.minimum})${stringifyPath(this.path)} (got ${this.actual})`
|
|
141
185
|
}
|
|
186
|
+
|
|
187
|
+
toJSON() {
|
|
188
|
+
return {
|
|
189
|
+
...super.toJSON(),
|
|
190
|
+
type: this.type,
|
|
191
|
+
minimum: this.minimum,
|
|
192
|
+
}
|
|
193
|
+
}
|
|
142
194
|
}
|
|
143
195
|
|
|
144
196
|
function stringifyExpectedType(expected: string): string {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ResultFailure, ResultSuccess, failure, success } from '../core.js'
|
|
2
1
|
import { PropertyKey } from './property-key.js'
|
|
2
|
+
import { ResultFailure, ResultSuccess, failure, success } from './result.js'
|
|
3
3
|
import { ValidationError } from './validation-error.js'
|
|
4
4
|
import {
|
|
5
5
|
Issue,
|
package/src/core.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export * from './core/$type.js'
|
|
2
|
+
export * from './core/property-key.js'
|
|
2
3
|
export * from './core/record-key.js'
|
|
3
4
|
export * from './core/result.js'
|
|
5
|
+
export * from './core/schema.js'
|
|
4
6
|
export * from './core/string-format.js'
|
|
5
7
|
export * from './core/types.js'
|
|
8
|
+
export * from './core/validation-error.js'
|
|
9
|
+
export * from './core/validation-issue.js'
|
|
10
|
+
export * from './core/validator.js'
|
package/src/external.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
$Type,
|
|
3
|
+
$TypeOf,
|
|
4
|
+
$type,
|
|
5
|
+
Infer,
|
|
6
|
+
LexiconRecordKey,
|
|
7
|
+
NsidString,
|
|
8
|
+
PropertyKey,
|
|
9
|
+
Schema,
|
|
10
|
+
Validator,
|
|
11
|
+
} from './core.js'
|
|
2
12
|
import {
|
|
3
13
|
ArraySchema,
|
|
4
14
|
ArraySchemaOptions,
|
|
@@ -57,29 +67,25 @@ import {
|
|
|
57
67
|
UnknownSchema,
|
|
58
68
|
refine,
|
|
59
69
|
} from './schema.js'
|
|
60
|
-
import {
|
|
70
|
+
import { memoizedOptions, memoizedTransformer } from './util/memoize.js'
|
|
61
71
|
|
|
62
72
|
export * from './core.js'
|
|
63
73
|
export * from './helpers.js'
|
|
64
74
|
export * from './schema.js'
|
|
65
|
-
export * from './validation.js'
|
|
66
75
|
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
export { _null as null }
|
|
77
|
+
|
|
78
|
+
export const never = /*#__PURE__*/ memoizedOptions(function () {
|
|
69
79
|
return new NeverSchema()
|
|
70
|
-
}
|
|
80
|
+
})
|
|
71
81
|
|
|
72
|
-
|
|
73
|
-
export function unknown() {
|
|
82
|
+
export const unknown = /*#__PURE__*/ memoizedOptions(function () {
|
|
74
83
|
return new UnknownSchema()
|
|
75
|
-
}
|
|
84
|
+
})
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
export function _null() {
|
|
86
|
+
const _null = /*#__PURE__*/ memoizedOptions(function () {
|
|
79
87
|
return new NullSchema()
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { _null as null }
|
|
88
|
+
})
|
|
83
89
|
|
|
84
90
|
/*@__NO_SIDE_EFFECTS__*/
|
|
85
91
|
export function literal<const V extends null | string | number | boolean>(
|
|
@@ -100,39 +106,45 @@ export function _enum<const V extends null | string | number | boolean>(
|
|
|
100
106
|
// @NOTE "enum" is a reserved keyword in JS/TS
|
|
101
107
|
export { _enum as enum }
|
|
102
108
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
export const boolean = /*#__PURE__*/ memoizedOptions(
|
|
110
|
+
function (options?: BooleanSchemaOptions) {
|
|
111
|
+
return new BooleanSchema(options)
|
|
112
|
+
},
|
|
113
|
+
(options) => {
|
|
114
|
+
const keys = Object.keys(options)
|
|
115
|
+
if (keys.length === 1 && keys[0] === 'default') return options.default!
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
export const integer = /*#__PURE__*/ memoizedOptions(function (
|
|
120
|
+
options?: IntegerSchemaOptions,
|
|
121
|
+
) {
|
|
110
122
|
return new IntegerSchema(options)
|
|
111
|
-
}
|
|
123
|
+
})
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
|
|
125
|
+
export const cidLink = /*#__PURE__*/ memoizedOptions(function (
|
|
126
|
+
options?: CidSchemaOptions,
|
|
127
|
+
) {
|
|
115
128
|
return new CidSchema(options)
|
|
116
|
-
}
|
|
129
|
+
})
|
|
117
130
|
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
export const bytes = /*#__PURE__*/ memoizedOptions(function (
|
|
132
|
+
options?: BytesSchemaOptions,
|
|
133
|
+
) {
|
|
120
134
|
return new BytesSchema(options)
|
|
121
|
-
}
|
|
135
|
+
})
|
|
122
136
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
) {
|
|
137
|
+
export const blob = /*#__PURE__*/ memoizedOptions(function <
|
|
138
|
+
O extends BlobSchemaOptions = NonNullable<unknown>,
|
|
139
|
+
>(options: O = {} as O) {
|
|
127
140
|
return new BlobSchema(options)
|
|
128
|
-
}
|
|
141
|
+
})
|
|
129
142
|
|
|
130
|
-
|
|
131
|
-
export function string<
|
|
143
|
+
export const string = /*#__PURE__*/ memoizedOptions(function <
|
|
132
144
|
const O extends StringSchemaOptions = NonNullable<unknown>,
|
|
133
145
|
>(options: StringSchemaOptions & O = {} as O) {
|
|
134
146
|
return new StringSchema<O>(options)
|
|
135
|
-
}
|
|
147
|
+
})
|
|
136
148
|
|
|
137
149
|
/*@__NO_SIDE_EFFECTS__*/
|
|
138
150
|
export function regexp<T extends string = string>(pattern: RegExp) {
|
|
@@ -171,10 +183,9 @@ export function dict<
|
|
|
171
183
|
// Utility
|
|
172
184
|
export type { UnknownObjectOutput as UnknownObject }
|
|
173
185
|
|
|
174
|
-
|
|
175
|
-
export function unknownObject() {
|
|
186
|
+
export const unknownObject = /*#__PURE__*/ memoizedOptions(function () {
|
|
176
187
|
return new UnknownObjectSchema()
|
|
177
|
-
}
|
|
188
|
+
})
|
|
178
189
|
|
|
179
190
|
/*@__NO_SIDE_EFFECTS__*/
|
|
180
191
|
export function ref<T>(get: RefSchemaGetter<T>) {
|
|
@@ -190,15 +201,17 @@ export function custom<T>(
|
|
|
190
201
|
return new CustomSchema<T>(assertion, message, path)
|
|
191
202
|
}
|
|
192
203
|
|
|
193
|
-
|
|
194
|
-
|
|
204
|
+
export const nullable = /*#__PURE__*/ memoizedTransformer(function <
|
|
205
|
+
const S extends Validator,
|
|
206
|
+
>(schema: S) {
|
|
195
207
|
return new NullableSchema<Infer<S>>(schema)
|
|
196
|
-
}
|
|
208
|
+
})
|
|
197
209
|
|
|
198
|
-
|
|
199
|
-
|
|
210
|
+
export const optional = /*#__PURE__*/ memoizedTransformer(function <
|
|
211
|
+
const S extends Validator,
|
|
212
|
+
>(schema: S) {
|
|
200
213
|
return new OptionalSchema<Infer<S>>(schema)
|
|
201
|
-
}
|
|
214
|
+
})
|
|
202
215
|
|
|
203
216
|
/*@__NO_SIDE_EFFECTS__*/
|
|
204
217
|
export function union<const V extends UnionSchemaValidators>(validators: V) {
|
|
@@ -325,12 +338,11 @@ export function record<
|
|
|
325
338
|
return new RecordSchema<K, T, S>(key, type, schema)
|
|
326
339
|
}
|
|
327
340
|
|
|
328
|
-
|
|
329
|
-
export function params<
|
|
341
|
+
export const params = /*#__PURE__*/ memoizedOptions(function <
|
|
330
342
|
const P extends ParamsSchemaShape = NonNullable<unknown>,
|
|
331
343
|
>(properties: P = {} as P) {
|
|
332
344
|
return new ParamsSchema<P>(properties)
|
|
333
|
-
}
|
|
345
|
+
})
|
|
334
346
|
|
|
335
347
|
/*@__NO_SIDE_EFFECTS__*/
|
|
336
348
|
export function payload<
|
|
@@ -340,6 +352,13 @@ export function payload<
|
|
|
340
352
|
return new Payload<E, S>(encoding, schema)
|
|
341
353
|
}
|
|
342
354
|
|
|
355
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
356
|
+
export function jsonPayload<const P extends ObjectSchemaShape>(
|
|
357
|
+
properties: P,
|
|
358
|
+
): Payload<'application/json', ObjectSchema<P>> {
|
|
359
|
+
return payload('application/json', object(properties))
|
|
360
|
+
}
|
|
361
|
+
|
|
343
362
|
/*@__NO_SIDE_EFFECTS__*/
|
|
344
363
|
export function query<
|
|
345
364
|
const N extends NsidString,
|