import type { Relation } from './filter'; /** * Polar string type. * * @internal */ interface PolarStr { String: string; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar string. * * @internal */ export declare function isPolarStr(v: PolarValue): v is PolarStr; /** * Type guard to test if a string received from across the WebAssembly * boundary is a PolarComparisonOperator. * * @internal */ export declare function isPolarComparisonOperator(s: string): s is PolarComparisonOperator; /** * Polar numeric type. * * @internal */ interface PolarNum { Number: PolarFloat | PolarInt; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar numeric. * * @internal */ export declare function isPolarNum(v: PolarValue): v is PolarNum; /** * Polar floating point type. * The string variant is to support ±∞ and NaN. * * @internal */ interface PolarFloat { Float: number | string; } /** * Polar integer type. * * @internal */ interface PolarInt { Integer: number; } /** * Polar boolean type. * * @internal */ interface PolarBool { Boolean: boolean; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar boolean. * * @internal */ export declare function isPolarBool(v: PolarValue): v is PolarBool; /** * Polar list type. * * @internal */ interface PolarList { List: PolarTerm[]; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar list. * * @internal */ export declare function isPolarList(v: PolarValue): v is PolarList; /** * Polar dictionary type. * * @internal */ interface PolarDict { Dictionary: { fields: Map; }; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar dictionary. * * @internal */ export declare function isPolarDict(v: PolarValue): v is PolarDict; /** * Polar predicate type. * * @internal */ interface PolarPredicate { Call: { name: string; args: PolarTerm[]; }; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar predicate. * * @internal */ export declare function isPolarPredicate(v: PolarValue): v is PolarPredicate; /** * Polar variable type. * * @internal */ interface PolarVariable { Variable: string; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar variable. * * @internal */ export declare function isPolarVariable(v: PolarValue): v is PolarVariable; /** * Polar application instance type. * * @internal */ interface PolarInstance { ExternalInstance: { instance_id: number; repr: string; class_repr?: string; class_id?: number; constructor?: PolarTerm; }; } /** * Polar expression type. * * @internal */ interface PolarExpression { Expression: { args: PolarTerm[]; operator: PolarOperator; }; } /** * Polar instance (tagged dict) pattern variant. * * @internal */ interface PolarInstancePattern { Instance: { tag?: string; fields: { fields: Map; }; }; } /** * Polar (untagged) dict pattern variant. * * @internal */ export declare type PolarDictPattern = PolarDict; /** * Polar pattern type. * * @internal */ interface PolarPattern { Pattern: PolarDictPattern | PolarInstancePattern; } /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar application instance. * * @internal */ export declare function isPolarInstance(v: PolarValue): v is PolarInstance; /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar expression. * * @internal */ export declare function isPolarExpression(v: PolarValue): v is PolarExpression; /** * Type guard to test if a Polar value received from across the WebAssembly * boundary is a Polar pattern. * * @internal */ export declare function isPolarPattern(v: PolarValue): v is PolarPattern; /** * Union of Polar value types. * * @internal */ export declare type PolarValue = PolarStr | PolarNum | PolarBool | PolarList | PolarDict | PolarPredicate | PolarVariable | PolarInstance | PolarExpression | PolarPattern; /** * Union of Polar value types. * * @internal */ export interface PolarTerm { value: PolarValue; } /** * Type guard to test if a JSON payload received from across the WebAssembly * boundary contains a valid Polar term. * * @internal */ export declare function isPolarTerm(v: unknown): v is PolarTerm; /** * A constructable (via the `new` keyword) application class. * * @internal */ export declare type Class = new (...args: any[]) => T; /** * The `Result` [[`QueryEvent`]] represents a single result from a query * containing any variables bound during the evaluation of the query. * * @internal */ export interface Result { bindings: Map; } /** * The `MakeExternal` [[`QueryEvent`]] is how Polar constructs application * instances during the evaluation of a query. * * @internal */ export interface MakeExternal { instanceId: number; tag: string; fields: PolarTerm[]; } /** * The `NextExternal` [[`QueryEvent`]] is how Polar iterates * through iterable host values. * * @internal */ export interface NextExternal { callId: number; iterable: PolarTerm; } /** * The `ExternalCall` [[`QueryEvent`]] is how Polar invokes JavaScript * functions registered as constants, methods on built-in types, and methods on * registered application classes during the evaluation of a query. * * @internal */ export interface ExternalCall { callId: number; instance: PolarTerm; attribute: string; args?: PolarTerm[]; } /** * The `ExternalIsSubspecializer` [[`QueryEvent`]] is how Polar determines * which of two classes is more specific with respect to a given instance. * * @internal */ export interface ExternalIsSubspecializer { instanceId: number; leftTag: string; rightTag: string; callId: number; } /** * The `ExternalIsa` [[`QueryEvent`]] is how Polar determines whether a given * value is an instance of a particular class. * * @internal */ export interface ExternalIsa { instance: PolarTerm; tag: string; callId: number; } /** * The `ExternalIsaWithPath` [[`QueryEvent`]] is how Polar determines whether a given * sequence of field accesses on a value is an instance of a particular class. * * @internal */ export interface ExternalIsaWithPath { baseTag: string; path: PolarTerm[]; classTag: string; callId: number; } /** * The `ExternalIsSubclass` [[`QueryEvent`]] is how Polar determines whether a given * class is a subclass of a particular class. * * @internal */ export interface ExternalIsSubclass { leftTag: string; rightTag: string; callId: number; } /** * Polar comparison operators. * * Currently, these are the only operators supported for external operations. * * @internal */ declare const comparisonOperators: { readonly Eq: "Eq"; readonly Geq: "Geq"; readonly Gt: "Gt"; readonly Leq: "Leq"; readonly Lt: "Lt"; readonly Neq: "Neq"; }; export declare type PolarComparisonOperator = keyof typeof comparisonOperators; /** * Polar operators. * * @internal */ declare const operators: { readonly Eq: "Eq"; readonly Geq: "Geq"; readonly Gt: "Gt"; readonly Leq: "Leq"; readonly Lt: "Lt"; readonly Neq: "Neq"; readonly Add: "Add"; readonly And: "And"; readonly Assign: "Assign"; readonly Cut: "Cut"; readonly Debug: "Debug"; readonly Div: "Div"; readonly Dot: "Dot"; readonly ForAll: "ForAll"; readonly In: "In"; readonly Isa: "Isa"; readonly Mod: "Mod"; readonly Mul: "Mul"; readonly New: "New"; readonly Not: "Not"; readonly Or: "Or"; readonly Print: "Print"; readonly Rem: "Rem"; readonly Sub: "Sub"; readonly Unify: "Unify"; }; export declare type PolarOperator = keyof typeof operators; /** * The `ExternalOp` [[`QueryEvent`]] is how Polar evaluates an operation * involving one or more application instances. * * @internal */ export interface ExternalOp { args: PolarTerm[]; callId: number; operator: PolarComparisonOperator; } /** * The `Debug` [[`QueryEvent`]] is how Polar relays debugging messages to * JavaScript from the internal debugger attached to the Polar VM. * * @internal */ export interface Debug { message: string; } /** * Union of all [[`QueryEvent`]] types. * * @internal */ export declare enum QueryEventKind { Debug = 0, Done = 1, ExternalCall = 2, ExternalIsa = 3, ExternalIsaWithPath = 4, ExternalIsSubspecializer = 5, ExternalIsSubclass = 6, ExternalOp = 7, MakeExternal = 8, NextExternal = 9, Result = 10 } /** * An event from the Polar VM. * * @internal */ export interface QueryEvent { kind: QueryEventKind; data?: Debug | ExternalCall | ExternalIsa | ExternalIsaWithPath | ExternalIsSubspecializer | ExternalIsSubclass | ExternalOp | MakeExternal | NextExternal | Result; } /** * An `AsyncGenerator` over query results. * * Each result is a `Map` of variables bound during the computation of that * result. * * If you don't need access to the bindings and only wish to know whether a * query succeeded or failed, you may check the `done` property of the yielded * value (and then optionally "complete" the generator by calling and awaiting its * `return()` method). If `done` is `true`, the query failed. If `done` is * `false`, the query yielded at least one result and therefore succeeded. */ export declare type QueryResult = AsyncGenerator, void, undefined | void>; /** * Optional configuration for [[`Polar.query`]] and [[`Polar.queryRule`]]. */ export declare type QueryOpts = { /** * Opt-in flag indicating whether [[`Host`]] can receive [[`Expression`]]s * from core for duration of query. When `false`, [[`Host`]] errors on * receiving [[`Expression`]] from core. Main use is for indicating whether * the consumer of the result bindings is prepared to handle constraints * ([[`Expression`]]s) received from core for data filtering purposes. */ acceptExpression?: boolean; /** * Bind keys to values in VM for duration of query. */ bindings?: Map; }; /** * Required configuration for [[`Host`]]. * * @internal */ export declare type HostOpts = { /** * Opt-in flag indicating whether [[`Host`]] can receive [[`Expression`]]s * from core. When `false`, [[`Host`]] errors on receiving [[`Expression`]] * from core. Main use is for indicating whether the consumer of the result * bindings is prepared to handle constraints ([[`Expression`]]s) received * from core for data filtering purposes. */ acceptExpression: boolean; equalityFn: EqualityFn; }; /** * An object with string keys. * * @hidden */ export declare type obj = { [key: string]: T; }; /** * A function that compares two values and returns `true` if they are equal and * `false` otherwise. * * A custom `EqualityFn` may be passed in the [[`Options`]] provided to the * [[`Oso.constructor`]] in order to override the default equality function, * which uses `isEqual` from the `lodash.isequal` package. */ export declare type EqualityFn = (x: unknown, y: unknown) => boolean; export declare type CustomError = new (...args: any[]) => Error; /** * Optional configuration for the [[`Oso.constructor`]]. */ export interface Options { equalityFn?: EqualityFn; /** * Optionally override the "not found" error class thrown by `authorize`. * Defaults to {@link NotFoundError}. */ notFoundError?: CustomError; /** * Optionally override the "forbidden" error class thrown by the `authorize*` * methods. Defaults to {@link ForbiddenError}. */ forbiddenError?: CustomError; /** * The action used by the `authorize` method to determine whether an * authorization failure should raise a `NotFoundError` or a `ForbiddenError`. */ readAction?: unknown; } /** * Type guard to test if a value conforms to both the iterable and iterator * protocols. This is basically a slightly relaxed check for whether the value * is a `Generator`. * * @internal */ export declare function isIterableIterator(x: unknown): x is IterableIterator; /** * Type guard to test if a value is an `Iterable`. * * @internal */ export declare function isIterable(x: unknown): x is Iterable; /** * Type guard to test if a value is an `AsyncIterable`. * * @internal */ export declare function isAsyncIterable(x: unknown): x is AsyncIterable; /** * JS analogue of Polar's Dictionary type. * * Polar dictionaries allow field access via the dot operator, which mirrors * the way JS objects behave. However, if we translate Polar dictionaries into * JS objects, we lose the ability to distinguish between dictionaries and * instances, since all JS instances are objects. By subclassing `Object`, we * can use `instanceof` to determine if a JS value should be serialized as a * Polar dictionary or external instance. * * @internal */ export declare class Dict extends Object { [index: string]: unknown; constructor(obj?: Object); } export declare type IsaCheck = (instance: any) => boolean; /** * Optional parameters for [[`Polar.registerClass`]] and [[`Host.cacheClass`]]. */ export interface ClassParams { /** * Explicit name to use for the class in Polar. Defaults to the class's * `name` property. */ name?: string; /** * A Map or object with string keys containing types for fields. Used for * data filtering. */ fields?: obj | Map; isaCheck?: IsaCheck; } /** * Parameters for [[`UserType`]]. */ export interface UserTypeParams { /** * Class registered as a user type. */ cls: Type; /** * Explicit name to use for the class in Polar. */ name: string; /** * A Map with string keys containing types for fields. Used for data * filtering. */ fields: Map; /** * Polar instance ID for the registered class. * * @internal */ id: number; isaCheck: IsaCheck; } /** * Utility type to represent a JS value that either does or does not have a * constructor property. * * NOTE(gj): I *think* `null` & `undefined` are the only JS values w/o a * `constructor` property (e.g., `(1).constructor` returns `[Function: * Number]`), but I'm not 100% sure of that. */ export declare type NullishOrHasConstructor = { constructor: Class; } | null | undefined; export declare type HostTypes = Map>; export declare class UserType, T = any> { name: string; cls: Type; id: number; fields: Map; isaCheck: IsaCheck; constructor({ name, cls, id, fields, isaCheck }: UserTypeParams); } export {};