index.d.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. definedProperties: Set<string>;
  21. readonly topSchemaRef: Code;
  22. readonly validateName: Name;
  23. evaluated?: Name;
  24. readonly ValidationError?: Name;
  25. readonly schema: AnySchema;
  26. readonly schemaEnv: SchemaEnv;
  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. jtdDiscriminator?: string;
  37. jtdMetadata?: boolean;
  38. readonly createErrors?: boolean;
  39. readonly opts: InstanceOptions;
  40. readonly self: Ajv;
  41. }
  42. export interface SchemaObjCxt extends SchemaCxt {
  43. readonly schema: AnySchemaObject;
  44. }
  45. interface SchemaEnvArgs {
  46. readonly schema: AnySchema;
  47. readonly root?: SchemaEnv;
  48. readonly baseId?: string;
  49. readonly localRefs?: LocalRefs;
  50. readonly meta?: boolean;
  51. }
  52. export declare class SchemaEnv implements SchemaEnvArgs {
  53. readonly schema: AnySchema;
  54. readonly root: SchemaEnv;
  55. baseId: string;
  56. localRefs?: LocalRefs;
  57. readonly meta?: boolean;
  58. readonly $async?: boolean;
  59. readonly refs: SchemaRefs;
  60. readonly dynamicAnchors: {
  61. [Ref in string]?: true;
  62. };
  63. validate?: AnyValidateFunction;
  64. validateName?: ValueScopeName;
  65. serialize?: (data: unknown) => string;
  66. serializeName?: ValueScopeName;
  67. parse?: (data: string) => unknown;
  68. parseName?: ValueScopeName;
  69. constructor(env: SchemaEnvArgs);
  70. }
  71. export declare function compileSchema(this: Ajv, sch: SchemaEnv): SchemaEnv;
  72. export declare function resolveRef(this: Ajv, root: SchemaEnv, baseId: string, ref: string): AnySchema | SchemaEnv | undefined;
  73. export declare function getCompilingSchema(this: Ajv, schEnv: SchemaEnv): SchemaEnv | void;
  74. export declare function resolveSchema(this: Ajv, root: SchemaEnv, // root object with properties schema, refs TODO below SchemaEnv is assigned to it
  75. ref: string): SchemaEnv | undefined;
  76. export {};