index.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type { AnySchema, AnySchemaObject, AnyValidateFunction, EvaluatedProperties, EvaluatedItems } from "../types";
  2. import type Ajv from "../core";
  3. import type { InstanceOptions } from "../core";
  4. import { CodeGen, Name, Code, ValueScopeName } from "./codegen";
  5. import { LocalRefs } from "./resolve";
  6. import { JSONType } from "./rules";
  7. export declare type SchemaRefs = {
  8. [Ref in string]?: SchemaEnv | AnySchema;
  9. };
  10. export interface SchemaCxt {
  11. readonly gen: CodeGen;
  12. readonly allErrors?: boolean;
  13. readonly data: Name;
  14. readonly parentData: Name;
  15. readonly parentDataProperty: Code | number;
  16. readonly dataNames: Name[];
  17. readonly dataPathArr: (Code | number)[];
  18. readonly dataLevel: number;
  19. dataTypes: JSONType[];
  20. readonly topSchemaRef: Code;
  21. readonly validateName: Name;
  22. evaluated?: Name;
  23. readonly ValidationError?: Name;
  24. readonly schema: AnySchema;
  25. readonly schemaEnv: SchemaEnv;
  26. readonly strictSchema?: boolean;
  27. readonly rootId: string;
  28. baseId: string;
  29. readonly schemaPath: Code;
  30. readonly errSchemaPath: string;
  31. readonly errorPath: Code;
  32. readonly propertyName?: Name;
  33. readonly compositeRule?: boolean;
  34. props?: EvaluatedProperties | Name;
  35. items?: EvaluatedItems | Name;
  36. readonly createErrors?: boolean;
  37. readonly opts: InstanceOptions;
  38. readonly self: Ajv;
  39. }
  40. export interface SchemaObjCxt extends SchemaCxt {
  41. readonly schema: AnySchemaObject;
  42. }
  43. interface SchemaEnvArgs {
  44. readonly schema: AnySchema;
  45. readonly root?: SchemaEnv;
  46. readonly baseId?: string;
  47. readonly localRefs?: LocalRefs;
  48. readonly meta?: boolean;
  49. }
  50. export declare class SchemaEnv implements SchemaEnvArgs {
  51. readonly schema: AnySchema;
  52. readonly root: SchemaEnv;
  53. baseId: string;
  54. localRefs?: LocalRefs;
  55. readonly meta?: boolean;
  56. readonly $async?: boolean;
  57. readonly refs: SchemaRefs;
  58. readonly dynamicAnchors: {
  59. [Ref in string]?: true;
  60. };
  61. validate?: AnyValidateFunction;
  62. validateName?: ValueScopeName;
  63. constructor(env: SchemaEnvArgs);
  64. }
  65. export declare function compileSchema(this: Ajv, sch: SchemaEnv): SchemaEnv;
  66. export declare function resolveRef(this: Ajv, root: SchemaEnv, baseId: string, ref: string): AnySchema | SchemaEnv | undefined;
  67. export declare function resolveSchema(this: Ajv, root: SchemaEnv, // root object with properties schema, refs TODO below SchemaEnv is assigned to it
  68. ref: string): SchemaEnv | undefined;
  69. export {};