UNPKG

@cerbos/files

Version:
104 lines 2.73 kB
/** * Load Cerbos policies from YAML or JSON files. * * @packageDocumentation */ import type { Policy, SchemaInput } from "@cerbos/core"; /** * {@inheritDoc @cerbos/core#SchemaInput} * * @public */ export interface Schema extends SchemaInput { /** * {@inheritDoc @cerbos/core#SchemaInput.definition} */ definition: string; } /** * Parse a policy from a YAML- or JSON-encoded string. * * @param contents - the YAML- or JSON-encoded policy definition. * * @public */ export declare function parsePolicy(contents: string): Policy; /** * Read a policy from a YAML or JSON file. * * @param path - the path to the policy file. * * @public */ export declare function readPolicy(path: string): Promise<Policy>; /** * Serialize a policy to a JSON-encoded string. * * @param policy - the policy definition. * * @public */ export declare function serializePolicy(policy: Policy): string; /** * Write a policy to a JSON file. * * @param path - the path to the policy file. * @param policy - the policy definition. * * @public */ export declare function writePolicy(path: string, policy: Policy): Promise<void>; /** * Options for {@link readSchema}. * * @public */ export interface ReadSchemaOptions { /** * Unique ID for the schema, to be used to reference the schema from policies and from other schemas. * * @defaultValue (inferred from the schema file path) * * @remarks * If the schema is nested under a directory called `_schemas`, the default ID will be the file path * relative to the `_schemas` directory. Otherwise, the default ID will be the file's basename. */ id?: string | undefined; } /** * Read a schema from a JSON file. * * @param path - the path to the schema file. * @param options - additional settings. * * @public */ export declare function readSchema(path: string, options?: ReadSchemaOptions): Promise<Schema>; /** * The contents of a directory, returned by {@link readDirectory}. * * @public */ export interface DirectoryContents { /** * The policies found in the directory. */ policies: Policy[]; /** * The schemas found in the directory's `_schemas` subdirectory. */ schemas: Schema[]; } /** * Read the policy and schema files in a directory and its subdirectories. * * @param path - the path to the directory. * * @remarks * This function looks for policies and schemas stored in the * {@link https://docs.cerbos.dev/cerbos/latest/policies/best_practices#_policy_repository_layout | standard Cerbos directory layout}. * * @public */ export declare function readDirectory(path: string): Promise<DirectoryContents>; //# sourceMappingURL=index.d.ts.map