@atproto/lexicon 0.0.1

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.
Files changed (42) hide show
  1. package/README.md +31 -0
  2. package/build.js +22 -0
  3. package/dist/index.d.ts +126 -0
  4. package/dist/index.js +3897 -0
  5. package/dist/index.js.map +7 -0
  6. package/dist/src/index.d.ts +2 -0
  7. package/dist/src/lexicons.d.ts +15 -0
  8. package/dist/src/record/index.d.ts +4 -0
  9. package/dist/src/record/schema.d.ts +9 -0
  10. package/dist/src/record/schemas.d.ts +10 -0
  11. package/dist/src/record/util.d.ts +1 -0
  12. package/dist/src/record/validation.d.ts +24 -0
  13. package/dist/src/record/validator.d.ts +17 -0
  14. package/dist/src/record-validator.d.ts +17 -0
  15. package/dist/src/schema.d.ts +9 -0
  16. package/dist/src/schemas.d.ts +10 -0
  17. package/dist/src/types.d.ts +30268 -0
  18. package/dist/src/util.d.ts +6 -0
  19. package/dist/src/validation.d.ts +6 -0
  20. package/dist/src/validators/blob.d.ts +6 -0
  21. package/dist/src/validators/complex.d.ts +5 -0
  22. package/dist/src/validators/primitives.d.ts +9 -0
  23. package/dist/src/validators/xrpc.d.ts +3 -0
  24. package/dist/src/view-validator.d.ts +13 -0
  25. package/dist/tsconfig.build.tsbuildinfo +1 -0
  26. package/dist/types.d.ts +73 -0
  27. package/dist/types.js +35 -0
  28. package/jest.config.js +6 -0
  29. package/package.json +21 -0
  30. package/src/index.ts +2 -0
  31. package/src/lexicons.ts +203 -0
  32. package/src/types.ts +318 -0
  33. package/src/util.ts +107 -0
  34. package/src/validation.ts +48 -0
  35. package/src/validators/blob.ts +57 -0
  36. package/src/validators/complex.ts +152 -0
  37. package/src/validators/primitives.ts +300 -0
  38. package/src/validators/xrpc.ts +50 -0
  39. package/tests/_scaffolds/lexicons.ts +379 -0
  40. package/tests/general.test.ts +611 -0
  41. package/tsconfig.build.json +4 -0
  42. package/tsconfig.json +11 -0
@@ -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;
@@ -0,0 +1,17 @@
1
+ import AdxSchema from './schema';
2
+ import AdxSchemas from './schemas';
3
+ import { AdxValidationResult } from './validation';
4
+ export interface AdxRecordValidatorDescription {
5
+ type: string | string[];
6
+ ext?: string | string[];
7
+ }
8
+ export declare class AdxRecordValidator {
9
+ private schemas;
10
+ type: AdxSchema[];
11
+ ext: AdxSchema[];
12
+ constructor(schemas: AdxSchemas, type: AdxSchema[], ext: AdxSchema[]);
13
+ validate(value: unknown): AdxValidationResult;
14
+ isValid(value: unknown): boolean;
15
+ assertValid(value: unknown): AdxValidationResult;
16
+ }
17
+ export default AdxRecordValidator;
@@ -0,0 +1,9 @@
1
+ import { ValidateFunction } from 'ajv';
2
+ import { AdxSchemaDefinition } from './types';
3
+ export declare class AdxSchema {
4
+ def: AdxSchemaDefinition;
5
+ id: string;
6
+ validateRecord?: ValidateFunction;
7
+ constructor(def: AdxSchemaDefinition);
8
+ }
9
+ export default AdxSchema;
@@ -0,0 +1,10 @@
1
+ import AdxSchema from './schema';
2
+ import AdxRecordValidator, { AdxRecordValidatorDescription } from './record-validator';
3
+ export declare class AdxSchemas {
4
+ schemas: Map<string, AdxSchema>;
5
+ add(schemaDef: unknown): void;
6
+ remove(key: string): void;
7
+ get(key: string): AdxSchema | undefined;
8
+ createRecordValidator(desc: string | string[] | AdxRecordValidatorDescription): AdxRecordValidator;
9
+ }
10
+ export default AdxSchemas;