@atproto/lexicon 0.0.4 → 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.
Files changed (47) hide show
  1. package/dist/blob-refs.d.ts +67 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +12944 -680
  4. package/dist/index.js.map +4 -4
  5. package/dist/lexicons.d.ts +6 -4
  6. package/dist/serialize.d.ts +12 -0
  7. package/dist/src/index.d.ts +2 -0
  8. package/dist/src/lexicons.d.ts +15 -0
  9. package/dist/src/record/index.d.ts +4 -0
  10. package/dist/src/record/schema.d.ts +9 -0
  11. package/dist/src/record/schemas.d.ts +10 -0
  12. package/dist/src/record/util.d.ts +1 -0
  13. package/dist/src/record/validation.d.ts +24 -0
  14. package/dist/src/record/validator.d.ts +17 -0
  15. package/dist/src/types.d.ts +30268 -0
  16. package/dist/src/util.d.ts +6 -0
  17. package/dist/src/validation.d.ts +6 -0
  18. package/dist/src/validators/blob.d.ts +6 -0
  19. package/dist/src/validators/complex.d.ts +5 -0
  20. package/dist/src/validators/primitives.d.ts +9 -0
  21. package/dist/src/validators/xrpc.d.ts +3 -0
  22. package/dist/tsconfig.build.tsbuildinfo +1 -0
  23. package/dist/types.d.ts +14999 -23510
  24. package/dist/util.d.ts +6 -1
  25. package/dist/validation.d.ts +6 -5
  26. package/dist/validators/blob.d.ts +0 -3
  27. package/dist/validators/complex.d.ts +2 -2
  28. package/dist/validators/formats.d.ts +10 -0
  29. package/dist/validators/primitives.d.ts +2 -2
  30. package/dist/validators/xrpc.d.ts +1 -1
  31. package/package.json +13 -4
  32. package/src/blob-refs.ts +70 -0
  33. package/src/index.ts +2 -0
  34. package/src/lexicons.ts +36 -5
  35. package/src/serialize.ts +93 -0
  36. package/src/types.ts +306 -180
  37. package/src/util.ts +64 -5
  38. package/src/validation.ts +28 -4
  39. package/src/validators/blob.ts +5 -43
  40. package/src/validators/complex.ts +31 -32
  41. package/src/validators/formats.ts +121 -0
  42. package/src/validators/primitives.ts +114 -67
  43. package/src/validators/xrpc.ts +29 -29
  44. package/tests/_scaffolds/lexicons.ts +178 -51
  45. package/tests/general.test.ts +496 -177
  46. package/tsconfig.build.tsbuildinfo +1 -1
  47. package/tsconfig.json +3 -1
@@ -9,8 +9,10 @@ export declare class Lexicons {
9
9
  getDef(uri: string): LexUserType | undefined;
10
10
  getDefOrThrow(uri: string, types?: string[]): LexUserType;
11
11
  validate(lexUri: string, value: unknown): ValidationResult;
12
- assertValidRecord(lexUri: string, value: unknown): void;
13
- assertValidXrpcParams(lexUri: string, value: unknown): void;
14
- assertValidXrpcInput(lexUri: string, value: unknown): void;
15
- assertValidXrpcOutput(lexUri: string, value: unknown): void;
12
+ assertValidRecord(lexUri: string, value: unknown): unknown;
13
+ assertValidXrpcParams(lexUri: string, value: unknown): unknown;
14
+ assertValidXrpcInput(lexUri: string, value: unknown): unknown;
15
+ assertValidXrpcOutput(lexUri: string, value: unknown): unknown;
16
+ assertValidXrpcMessage<T = unknown>(lexUri: string, value: unknown): T;
17
+ resolveLexUri(lexUri: string, ref: string): string;
16
18
  }
@@ -0,0 +1,12 @@
1
+ import { IpldValue, JsonValue } from '@atproto/common-web';
2
+ import { BlobRef } from './blob-refs';
3
+ export declare type LexValue = IpldValue | BlobRef | Array<LexValue> | {
4
+ [key: string]: LexValue;
5
+ };
6
+ export declare type RepoRecord = Record<string, LexValue>;
7
+ export declare const lexToIpld: (val: LexValue) => IpldValue;
8
+ export declare const ipldToLex: (val: IpldValue) => LexValue;
9
+ export declare const lexToJson: (val: LexValue) => JsonValue;
10
+ export declare const stringifyLex: (val: LexValue) => string;
11
+ export declare const jsonToLex: (val: JsonValue) => LexValue;
12
+ export declare const jsonStringToLex: (val: string) => LexValue;
@@ -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;