@atproto/lexicon 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './lexicons';
@@ -0,0 +1,15 @@
1
+ import { LexiconDoc, LexUserType } from './types';
2
+ export declare class Lexicons {
3
+ docs: Map<string, LexiconDoc>;
4
+ defs: Map<string, LexUserType>;
5
+ constructor(docs?: unknown[]);
6
+ add(doc: unknown): void;
7
+ remove(uri: string): void;
8
+ get(uri: string): LexiconDoc | undefined;
9
+ getDef(uri: string): LexUserType | undefined;
10
+ getDefOrThrow(uri: string, types?: string[]): LexUserType;
11
+ assertValidRecord(lexUri: string, value: unknown): void;
12
+ assertValidXrpcParams(lexUri: string, value: unknown): void;
13
+ assertValidXrpcInput(lexUri: string, value: unknown): void;
14
+ assertValidXrpcOutput(lexUri: string, value: unknown): void;
15
+ }
@@ -0,0 +1,4 @@
1
+ export * from './schema';
2
+ export * from './schemas';
3
+ export * from './validator';
4
+ export * from './validation';
@@ -0,0 +1,9 @@
1
+ import { ValidateFunction } from 'ajv';
2
+ import { RecordSchema } from '../types';
3
+ export declare class CompiledRecordSchema {
4
+ def: RecordSchema;
5
+ id: string;
6
+ validate?: ValidateFunction;
7
+ constructor(def: RecordSchema);
8
+ }
9
+ export default CompiledRecordSchema;
@@ -0,0 +1,10 @@
1
+ import CompiledRecordSchema from './schema';
2
+ import RecordValidator, { RecordValidatorDescription } from './validator';
3
+ export declare class RecordSchemas {
4
+ schemas: Map<string, CompiledRecordSchema>;
5
+ add(schemaDef: unknown): void;
6
+ remove(key: string): void;
7
+ get(key: string): CompiledRecordSchema | undefined;
8
+ createRecordValidator(desc: string | string[] | RecordValidatorDescription): RecordValidator;
9
+ }
10
+ export default RecordSchemas;
@@ -0,0 +1 @@
1
+ export declare const isRecord: (obj: unknown) => obj is Record<string, unknown>;
@@ -0,0 +1,24 @@
1
+ import { ValidateFunction } from 'ajv';
2
+ import CompiledRecordSchema from './schema';
3
+ export declare class ValidationError extends Error {
4
+ code: ValidationResultCode;
5
+ messages: string[];
6
+ constructor(res: ValidationResult);
7
+ }
8
+ export declare enum ValidationResultCode {
9
+ Full = "full",
10
+ Partial = "partial",
11
+ Incompatible = "incompatible",
12
+ Invalid = "invalid"
13
+ }
14
+ export declare class ValidationResult {
15
+ code: ValidationResultCode;
16
+ error: string | undefined;
17
+ fallbacks: string[];
18
+ messages: string[];
19
+ get valid(): boolean;
20
+ get fullySupported(): boolean;
21
+ get compatible(): boolean;
22
+ _t(to: ValidationResultCode, message?: string): void;
23
+ _fail(schema: CompiledRecordSchema, validator: ValidateFunction): void;
24
+ }
@@ -0,0 +1,17 @@
1
+ import CompiledRecordSchema from './schema';
2
+ import RecordSchemas from './schemas';
3
+ import { ValidationResult } from './validation';
4
+ export interface RecordValidatorDescription {
5
+ type: string | string[];
6
+ ext?: string | string[];
7
+ }
8
+ export declare class RecordValidator {
9
+ private schemas;
10
+ type: CompiledRecordSchema[];
11
+ ext: CompiledRecordSchema[];
12
+ constructor(schemas: RecordSchemas, type: CompiledRecordSchema[], ext: CompiledRecordSchema[]);
13
+ validate(value: unknown): ValidationResult;
14
+ isValid(value: unknown): boolean;
15
+ assertValid(value: unknown): ValidationResult;
16
+ }
17
+ export default RecordValidator;