UNPKG

@dialog-db/query

Version:

Datalog query engine inspired by Datomic

526 lines 16.5 kB
export function fact<The extends string, Schema extends API.RuleDescriptor>({ the, ...source }: Schema & { the?: The; this?: ObjectConstructor | { Entity: {}; }; _?: never; }): API.Claim<API.FactView<The, Omit<Schema, "the"> & { this: ObjectConstructor; }>, The, Omit<Schema, "the"> & { this: ObjectConstructor; }, {}>; export function claim<The extends string, Schema extends API.RuleDescriptor>({ the, ...source }: Schema & { the?: The; this?: ObjectConstructor | { Entity: {}; }; _?: never; }): API.Claim<API.FactView<The, Omit<Schema, "the"> & { this: ObjectConstructor; }>, The, Omit<Schema, "the"> & { this: ObjectConstructor; }, {}>; /** * @template Terms * @template {(terms: any) => API.Constraint} F * @extends {Callable<F>} */ export class Operator<Terms, F extends (terms: any) => API.Constraint> extends Callable<F> { /** * @template Terms * @template {(terms: Terms) => API.Constraint} Formula * @param {Formula} match * @returns {Operator<Terms, Formula>} */ static for<Terms_1, Formula extends (terms: Terms_1) => API.Constraint>(match: Formula): Operator<Terms_1, Formula>; /** * @param {F} match */ constructor(match: F); match: F; /** * @param {Terms} terms * @returns {API.Negation} */ not(terms: Terms): API.Negation; } export const Collection: Operator<any, <Member extends API.Scalar>(terms: { this: API.Term<API.Entity>; of: API.Term<Member>; at?: API.Term<string> | undefined; }) => { match: { the: API.Term<string> | undefined; of: API.Term<API.Entity>; is: API.Term<Member>; }; fact: {}; }>; export function text(term: API.Term<string>): TextVariable; export class Text { static match: Operator<any, ({ this: text, pattern: like }: { this: API.Term<string>; pattern: API.Term<string>; }) => { match: { text: API.Term<string>; pattern: API.Term<string>; }; operator: "text/like"; }>; /** * @param {object} terms * @param {API.Term<string>} terms.this * @param {API.Term<string>} terms.pattern */ static not(terms: { this: API.Term<string>; pattern: API.Term<string>; }): { not: { match: { text: API.Term<string>; pattern: API.Term<string>; }; operator: "text/like"; }; }; static includes: Operator<any, ({ this: source, slice }: { this: API.Term<string>; slice: API.Term<string>; }) => { match: { this: API.Term<string>; slice: API.Term<string>; }; operator: "text/includes"; }>; static Concat: Operator<any, ({ of: [left, right], is }: { of: [left: API.Term<string>, right: API.Term<string>]; is?: API.Term<string> | undefined; }) => API.SystemOperator>; static Words: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<string> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/words"; }>; static Lines: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<string> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/lines"; }>; static UpperCase: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<string> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/case/upper"; }>; static LowerCase: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<string> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/case/lower"; }>; static Trim: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<string> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/trim"; }>; static TrimStart: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<string> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/trim/start"; }>; static TrimEnd: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<string> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/trim/end"; }>; static Length: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<number> | undefined; }) => { match: { of: API.Term<string>; is: API.Term<number> | undefined; }; operator: "text/length"; }>; /** * @param {API.Term<string>} source */ constructor(source: API.Term<string>); #private; } export class UTF8 { static ToText: Operator<any, ({ of, is }: { of: API.Term<Uint8Array>; is?: API.Term<string> | undefined; }) => API.SystemOperator>; static FromText: Operator<any, ({ of, is }: { of: API.Term<string>; is?: API.Term<Uint8Array<ArrayBufferLike>> | undefined; }) => API.SystemOperator>; } export class Data { static same: (<This extends API.Scalar, As extends API.Scalar>({ this: of, as }: { this: API.Term<This>; as?: API.Term<As> | undefined; }) => API.SystemOperator) & { /** * @template {API.Scalar} This * @template {API.Scalar} As * @param {object} terms * @param {API.Term<This>} terms.this * @param {API.Term<As>} [terms.as] * @returns {API.Negation} */ not: <This extends API.Scalar, As extends API.Scalar>(terms: { this: API.Term<This>; as?: API.Term<As> | undefined; }) => API.Negation; }; static not: Operator<any, (terms: { of: API.Term<boolean>; is: API.Term<boolean>; }) => API.SystemOperator>; static "!": Operator<any, (terms: { of: API.Term<boolean>; is: API.Term<boolean>; }) => API.SystemOperator>; static greater: Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static ">": Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static greaterOrEqual: Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static ">=": Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static less: Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static "<": Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static lessOrEqual: Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static "<=": Operator<any, <T extends number | string>(terms: { this: API.Term<T>; than: API.Term<T>; }) => API.SystemOperator>; static Type: Operator<any, ({ of, is }: { of: API.Term<API.Scalar>; is?: string | API.Variable<string> | API.Variable<API.TypeName> | undefined; }) => API.SystemOperator>; static Reference: Operator<any, ({ of, is }: { of: API.Term<any>; is?: API.Term<API.Entity> | undefined; }) => { match: { of: API.Term; is?: API.Term<API.Entity>; }; operator: "data/refer"; }>; static Fact: Operator<any, <Terms extends Record<string, API.Term> & { this?: API.Term<API.Entity>; }>({ this: is, ...of }: Terms) => { match: Omit<Terms, "this"> & { is?: API.Term<API.Entity>; }; operator: "data/refer"; }>; } export class Math { static Sum: Operator<any, ({ of, with: by, is }: { of: API.Term<API.Numeric>; with: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static "+": Operator<any, ({ of, with: by, is }: { of: API.Term<API.Numeric>; with: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static Subtraction: Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static "-": Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static Multiplication: Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static "*": Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static Division: Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static "/": Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static Modulo: Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static "%": Operator<any, (terms: { of: API.Term<API.Numeric>; by: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static Power: Operator<any, ({ of, exponent, is }: { of: API.Term<API.Numeric>; exponent: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static "**": Operator<any, ({ of, exponent, is }: { of: API.Term<API.Numeric>; exponent: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; static Absolute: Operator<any, ({ of, is }: { of: API.Term<API.Numeric>; is?: API.Term<API.Numeric> | undefined; }) => API.SystemOperator>; } export const same: (<This extends API.Scalar, As extends API.Scalar>(terms: { this: API.Term<This>; as: API.Term<As>; }) => Match<{ this: any; as: any; }>) & { /** * @template {API.Scalar} This * @template {API.Scalar} As * @param {{this: API.Term<This>, as: API.Term<As>}} terms */ not<This extends API.Scalar, As extends API.Scalar>(terms: { this: API.Term<This>; as: API.Term<As>; }): Match<{ this: any; as: any; }>; }; export type Circuit<Schema extends API.FactSchema, Fact> = { cells: API.InferSchemaAttributes<Schema>; apply: (terms: API.InferSchemaTerms<Schema>) => API.RuleApplicationSyntax<API.InferSchemaAttributes<Schema>>; recur: (terms: API.InferSchemaTerms<Schema>) => API.MatchView; assert: (claim: API.InferAssert<Schema>) => Fact; }; import * as API from './api.js'; import { $ } from './$.js'; import { _ } from './$.js'; import { Callable } from './syntax/callable.js'; declare class TextVariable { /** * @param {API.Term<string>} term */ constructor(term: API.Term<string>); /** * @param {API.Term<string>} pattern */ like(pattern: API.Term<string>): { match: { text: API.Term<string>; pattern: API.Term<string>; }; operator: "text/like"; }; /** * @param {API.Term<string>} slice */ includes(slice: API.Term<string>): { match: { this: API.Term<string>; slice: API.Term<string>; }; operator: "text/includes"; }; /** * @param {object} terms * @param {API.Term<string>} terms.with * @param {API.Term<string>} terms.is */ concat(terms: { with: API.Term<string>; is: API.Term<string>; }): API.SystemOperator; words(): { /** * @param {API.Term<string>} is */ is(is: API.Term<string>): { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/words"; }; }; lines(): { /** * @param {API.Term<string>} is */ is(is: API.Term<string>): { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/lines"; }; }; toUpperCase(): { /** * @param {API.Term<string>} is */ is(is: API.Term<string>): { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/case/upper"; }; /** * @param {API.Term<string>} is */ not(is: API.Term<string>): { not: { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/case/upper"; }; }; }; /** */ toLowerCase(): { /** * @param {API.Term<string>} is */ is(is: API.Term<string>): { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/case/lower"; }; /** * @param {API.Term<string>} is */ not(is: API.Term<string>): { not: { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/case/lower"; }; }; }; /** * @param {API.Term<string>} is */ trim(is: API.Term<string>): { match: { of: API.Term<string>; is: API.Term<string> | undefined; }; operator: "text/trim"; }; #private; } /** * @template {API.RuleDescriptor} Schema */ declare class Match<Schema extends API.RuleDescriptor> { /** * @param {API.DeductiveRuleSyntax<API.InferSchemaAttributes<Schema>>} rule * @param {API.InferSchemaTerms<Schema>} terms */ constructor(rule: API.DeductiveRuleSyntax<API.InferSchemaAttributes<Schema>>, terms: API.InferSchemaTerms<Schema>); rule: API.DeductiveRuleSyntax<API.InferSchemaAttributes<Schema>>; terms: API.InferSchemaTerms<Schema>; get form(): API.RuleApplicationSyntax<API.InferSchemaAttributes<Schema>>; get plan(): API.RuleApplicationPlan<API.InferSchemaAttributes<Schema>>; toJSON(): object; /** * @param {{ from: API.Querier }} source */ execute(source: { from: API.Querier; }): Generator<typeof Task.SUSPEND | Task.Join | Task.Throw<Error>, API.InferBindings<API.InferSchemaTerms<Schema>>[], unknown>; /** * @param {{ from: API.Querier }} source */ query(source: { from: API.Querier; }): Task.Invocation<API.InferBindings<API.InferSchemaTerms<Schema>>[], Error>; [Symbol.iterator](): Generator<API.RuleApplicationSyntax<API.InferSchemaAttributes<Schema>>, void, unknown>; #private; } import * as Task from './task.js'; export { $, _ }; //# sourceMappingURL=builder.d.ts.map