Comparing version 0.12.4 to 0.13.0
@@ -154,2 +154,15 @@ import * as wasm from './polar_wasm_api_bg.wasm'; | ||
*/ | ||
enableRoles() { | ||
wasm.polar_enableRoles(this.ptr); | ||
} | ||
/** | ||
* @param {string} validation_query_results | ||
*/ | ||
validateRolesConfig(validation_query_results) { | ||
var ptr0 = passStringToWasm0(validation_query_results, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
wasm.polar_validateRolesConfig(this.ptr, ptr0, len0); | ||
} | ||
/** | ||
*/ | ||
clearRules() { | ||
@@ -351,3 +364,3 @@ wasm.polar_clearRules(this.ptr); | ||
export const __wbg_error_a1bf577179c3874c = function(arg0, arg1) { | ||
export const __wbg_error_93aaa13138af264c = function(arg0, arg1) { | ||
console.error(getStringFromWasm0(arg0, arg1)); | ||
@@ -354,0 +367,0 @@ }; |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function __wbg_query_free(a: number): void; | ||
export function query_nextEvent(a: number): number; | ||
export function query_callResult(a: number, b: number, c: number, d: number): void; | ||
export function query_questionResult(a: number, b: number, c: number): void; | ||
export function query_debugCommand(a: number, b: number, c: number): void; | ||
export function query_appError(a: number, b: number, c: number): void; | ||
export function query_nextMessage(a: number): number; | ||
export function query_source(a: number): number; | ||
export function query_setLoggingOptions(a: number, b: number, c: number, d: number, e: number): void; | ||
export function __wbg_polar_free(a: number): void; | ||
export function polar_wasm_new(): number; | ||
export function polar_load(a: number, b: number, c: number, d: number, e: number): void; | ||
export function polar_enableRoles(a: number): void; | ||
export function polar_validateRolesConfig(a: number, b: number, c: number): void; | ||
export function polar_clearRules(a: number): void; | ||
@@ -23,4 +16,13 @@ export function polar_registerConstant(a: number, b: number, c: number, d: number, e: number): void; | ||
export function polar_nextMessage(a: number): number; | ||
export function __wbg_query_free(a: number): void; | ||
export function query_nextEvent(a: number): number; | ||
export function query_callResult(a: number, b: number, c: number, d: number): void; | ||
export function query_questionResult(a: number, b: number, c: number): void; | ||
export function query_debugCommand(a: number, b: number, c: number): void; | ||
export function query_appError(a: number, b: number, c: number): void; | ||
export function query_nextMessage(a: number): number; | ||
export function query_source(a: number): number; | ||
export function query_setLoggingOptions(a: number, b: number, c: number, d: number, e: number): void; | ||
export function __wbindgen_malloc(a: number): number; | ||
export function __wbindgen_realloc(a: number, b: number, c: number): number; | ||
export function __wbindgen_free(a: number, b: number): void; |
@@ -17,2 +17,9 @@ /* tslint:disable */ | ||
*/ | ||
enableRoles(): void; | ||
/** | ||
* @param {string} validation_query_results | ||
*/ | ||
validateRolesConfig(validation_query_results: string): void; | ||
/** | ||
*/ | ||
clearRules(): void; | ||
@@ -19,0 +26,0 @@ /** |
@@ -45,4 +45,1 @@ /** Base error type. */ | ||
} | ||
export declare class UnexpectedPolarTypeError extends PolarError { | ||
constructor(); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnexpectedPolarTypeError = exports.UnregisteredInstanceError = exports.UnregisteredClassError = exports.PolarFileNotFoundError = exports.PolarFileExtensionError = exports.KwargsError = exports.InvalidQueryEventError = exports.InvalidConstructorError = exports.InvalidIteratorError = exports.InvalidCallError = exports.InlineQueryFailedError = exports.DuplicateInstanceRegistrationError = exports.DuplicateClassAliasError = exports.PolarError = void 0; | ||
exports.UnregisteredInstanceError = exports.UnregisteredClassError = exports.PolarFileNotFoundError = exports.PolarFileExtensionError = exports.KwargsError = exports.InvalidQueryEventError = exports.InvalidConstructorError = exports.InvalidIteratorError = exports.InvalidCallError = exports.InlineQueryFailedError = exports.DuplicateInstanceRegistrationError = exports.DuplicateClassAliasError = exports.PolarError = void 0; | ||
const helpers_1 = require("./helpers"); | ||
@@ -97,10 +97,2 @@ /** Base error type. */ | ||
exports.UnregisteredInstanceError = UnregisteredInstanceError; | ||
class UnexpectedPolarTypeError extends PolarError { | ||
constructor() { | ||
// Doesn't have a tag because it doesn't seem we get this from the wasm API. | ||
super('Unexpected polar type.'); | ||
Object.setPrototypeOf(this, UnexpectedPolarTypeError.prototype); | ||
} | ||
} | ||
exports.UnexpectedPolarTypeError = UnexpectedPolarTypeError; | ||
//# sourceMappingURL=errors.js.map |
@@ -204,3 +204,3 @@ "use strict"; | ||
throw new Error(); | ||
if (!types_1.isPolarOperator(operator)) | ||
if (!types_1.isPolarComparisonOperator(operator)) | ||
throw new errors_1.PolarError(`Unsupported external operation '${repr(args[0])} ${operator} ${repr(args[1])}'`); | ||
@@ -290,2 +290,3 @@ return { | ||
try { | ||
// @ts-ignore | ||
Reflect.construct(String, [], f); | ||
@@ -292,0 +293,0 @@ return true; |
import type { Polar as FfiPolar } from './polar_wasm_api'; | ||
import type { Class, EqualityFn, PolarTerm } from './types'; | ||
import { PolarOperator } from './types'; | ||
import type { Class, EqualityFn, PolarComparisonOperator, PolarTerm } from './types'; | ||
/** | ||
@@ -91,3 +90,3 @@ * Translator between Polar and JavaScript. | ||
*/ | ||
externalOp(op: PolarOperator, left: PolarTerm, right: PolarTerm): Promise<boolean>; | ||
externalOp(op: PolarComparisonOperator, leftTerm: PolarTerm, rightTerm: PolarTerm): Promise<boolean>; | ||
/** | ||
@@ -94,0 +93,0 @@ * Check if two instances unify according to the [[`EqualityFn`]]. |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _ffiPolar, _classes, _instances, _equalityFn; | ||
var _Host_ffiPolar, _Host_classes, _Host_instances, _Host_equalityFn; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,6 +18,7 @@ exports.Host = void 0; | ||
const helpers_1 = require("./helpers"); | ||
const Expression_1 = require("./Expression"); | ||
const Pattern_1 = require("./Pattern"); | ||
const Predicate_1 = require("./Predicate"); | ||
const Variable_1 = require("./Variable"); | ||
const types_1 = require("./types"); | ||
const types_2 = require("./types"); | ||
/** | ||
@@ -33,10 +32,10 @@ * Translator between Polar and JavaScript. | ||
constructor(ffiPolar, equalityFn) { | ||
_ffiPolar.set(this, void 0); | ||
_classes.set(this, void 0); | ||
_instances.set(this, void 0); | ||
_equalityFn.set(this, void 0); | ||
__classPrivateFieldSet(this, _ffiPolar, ffiPolar); | ||
__classPrivateFieldSet(this, _classes, new Map()); | ||
__classPrivateFieldSet(this, _instances, new Map()); | ||
__classPrivateFieldSet(this, _equalityFn, equalityFn); | ||
_Host_ffiPolar.set(this, void 0); | ||
_Host_classes.set(this, void 0); | ||
_Host_instances.set(this, void 0); | ||
_Host_equalityFn.set(this, void 0); | ||
__classPrivateFieldSet(this, _Host_ffiPolar, ffiPolar, "f"); | ||
__classPrivateFieldSet(this, _Host_classes, new Map(), "f"); | ||
__classPrivateFieldSet(this, _Host_instances, new Map(), "f"); | ||
__classPrivateFieldSet(this, _Host_equalityFn, equalityFn, "f"); | ||
} | ||
@@ -50,5 +49,5 @@ /** | ||
static clone(host) { | ||
const clone = new Host(__classPrivateFieldGet(host, _ffiPolar), __classPrivateFieldGet(host, _equalityFn)); | ||
__classPrivateFieldSet(clone, _classes, new Map(__classPrivateFieldGet(host, _classes))); | ||
__classPrivateFieldSet(clone, _instances, new Map(__classPrivateFieldGet(host, _instances))); | ||
const clone = new Host(__classPrivateFieldGet(host, _Host_ffiPolar, "f"), __classPrivateFieldGet(host, _Host_equalityFn, "f")); | ||
__classPrivateFieldSet(clone, _Host_classes, new Map(__classPrivateFieldGet(host, _Host_classes, "f")), "f"); | ||
__classPrivateFieldSet(clone, _Host_instances, new Map(__classPrivateFieldGet(host, _Host_instances, "f")), "f"); | ||
return clone; | ||
@@ -64,3 +63,3 @@ } | ||
getClass(name) { | ||
const cls = __classPrivateFieldGet(this, _classes).get(name); | ||
const cls = __classPrivateFieldGet(this, _Host_classes, "f").get(name); | ||
if (cls === undefined) | ||
@@ -81,3 +80,3 @@ throw new errors_1.UnregisteredClassError(name); | ||
const clsName = name === undefined ? cls.name : name; | ||
const existing = __classPrivateFieldGet(this, _classes).get(clsName); | ||
const existing = __classPrivateFieldGet(this, _Host_classes, "f").get(clsName); | ||
if (existing !== undefined) | ||
@@ -89,3 +88,3 @@ throw new errors_1.DuplicateClassAliasError({ | ||
}); | ||
__classPrivateFieldGet(this, _classes).set(clsName, cls); | ||
__classPrivateFieldGet(this, _Host_classes, "f").set(clsName, cls); | ||
return clsName; | ||
@@ -101,3 +100,3 @@ } | ||
instances() { | ||
return Array.from(__classPrivateFieldGet(this, _instances).values()); | ||
return Array.from(__classPrivateFieldGet(this, _Host_instances, "f").values()); | ||
} | ||
@@ -110,3 +109,3 @@ /** | ||
hasInstance(id) { | ||
return __classPrivateFieldGet(this, _instances).has(id); | ||
return __classPrivateFieldGet(this, _Host_instances, "f").has(id); | ||
} | ||
@@ -123,3 +122,3 @@ /** | ||
throw new errors_1.UnregisteredInstanceError(id); | ||
return __classPrivateFieldGet(this, _instances).get(id); | ||
return __classPrivateFieldGet(this, _Host_instances, "f").get(id); | ||
} | ||
@@ -135,5 +134,5 @@ /** | ||
if (instanceId === undefined) { | ||
instanceId = __classPrivateFieldGet(this, _ffiPolar).newId(); | ||
instanceId = __classPrivateFieldGet(this, _Host_ffiPolar, "f").newId(); | ||
} | ||
__classPrivateFieldGet(this, _instances).set(instanceId, instance); | ||
__classPrivateFieldGet(this, _Host_instances, "f").set(instanceId, instance); | ||
return instanceId; | ||
@@ -148,3 +147,3 @@ } | ||
const cls = this.getClass(name); | ||
const args = await Promise.all(fields.map(async (f) => await this.toJs(f))); | ||
const args = await Promise.all(fields.map(f => this.toJs(f))); | ||
const instance = new cls(...args); | ||
@@ -192,18 +191,21 @@ this.cacheInstance(instance, id); | ||
*/ | ||
async externalOp(op, left, right) { | ||
const leftjs = await this.toJs(left); | ||
const rightjs = await this.toJs(right); | ||
async externalOp(op, leftTerm, rightTerm) { | ||
const left = await this.toJs(leftTerm); | ||
const right = await this.toJs(rightTerm); | ||
switch (op) { | ||
case types_1.PolarOperator.Eq: | ||
return __classPrivateFieldGet(this, _equalityFn).call(this, leftjs, rightjs); | ||
case types_1.PolarOperator.Geq: | ||
return leftjs >= rightjs; | ||
case types_1.PolarOperator.Gt: | ||
return leftjs > rightjs; | ||
case types_1.PolarOperator.Leq: | ||
return leftjs <= rightjs; | ||
case types_1.PolarOperator.Lt: | ||
return leftjs < rightjs; | ||
case types_1.PolarOperator.Neq: | ||
return !__classPrivateFieldGet(this, _equalityFn).call(this, leftjs, rightjs); | ||
case 'Eq': | ||
return __classPrivateFieldGet(this, _Host_equalityFn, "f").call(this, left, right); | ||
case 'Geq': | ||
return left >= right; | ||
case 'Gt': | ||
return left > right; | ||
case 'Leq': | ||
return left <= right; | ||
case 'Lt': | ||
return left < right; | ||
case 'Neq': | ||
return !__classPrivateFieldGet(this, _Host_equalityFn, "f").call(this, left, right); | ||
default: | ||
const _ = op; | ||
return _; | ||
} | ||
@@ -221,3 +223,3 @@ } | ||
right = right instanceof Promise ? await right : right; | ||
return __classPrivateFieldGet(this, _equalityFn).call(this, left, right); | ||
return __classPrivateFieldGet(this, _Host_equalityFn, "f").call(this, left, right); | ||
} | ||
@@ -256,2 +258,31 @@ /** | ||
return { value: { Variable: v.name } }; | ||
case v instanceof Expression_1.Expression: | ||
return { | ||
value: { | ||
Expression: { | ||
operator: v.operator, | ||
args: v.args.map((a) => this.toPolar(a)), | ||
}, | ||
}, | ||
}; | ||
case v instanceof Pattern_1.Pattern: | ||
const dict = this.toPolar(v.fields).value; | ||
if (v.tag === undefined) { | ||
return { value: { Pattern: dict } }; | ||
} | ||
else { | ||
return { | ||
value: { | ||
Pattern: { | ||
Instance: { | ||
tag: v.tag, | ||
fields: dict.Dictionary, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
case v instanceof types_1.Dict: | ||
const fields = new Map(Object.entries(v).map(([k, v]) => [k, this.toPolar(v)])); | ||
return { value: { Dictionary: { fields } } }; | ||
default: | ||
@@ -277,6 +308,6 @@ const instance_id = this.cacheInstance(v); | ||
const t = v.value; | ||
if (types_2.isPolarStr(t)) { | ||
if (types_1.isPolarStr(t)) { | ||
return t.String; | ||
} | ||
else if (types_2.isPolarNum(t)) { | ||
else if (types_1.isPolarNum(t)) { | ||
if ('Float' in t.Number) { | ||
@@ -301,33 +332,49 @@ const f = t.Number.Float; | ||
} | ||
else if (types_2.isPolarBool(t)) { | ||
else if (types_1.isPolarBool(t)) { | ||
return t.Boolean; | ||
} | ||
else if (types_2.isPolarList(t)) { | ||
else if (types_1.isPolarList(t)) { | ||
return await Promise.all(t.List.map(async (el) => await this.toJs(el))); | ||
} | ||
else if (types_2.isPolarDict(t)) { | ||
else if (types_1.isPolarDict(t)) { | ||
const valueToJs = ([k, v]) => this.toJs(v).then(v => [k, v]); | ||
const { fields } = t.Dictionary; | ||
let entries = typeof fields.entries === 'function' | ||
? Array.from(fields.entries()) | ||
: Object.entries(fields); | ||
entries = await Promise.all(entries.map(async ([k, v]) => [k, await this.toJs(v)])); | ||
return entries.reduce((obj, [k, v]) => { | ||
obj[k] = v; | ||
return obj; | ||
}, {}); | ||
const entries = await Promise.all([...fields.entries()].map(valueToJs)); | ||
return entries.reduce((dict, [k, v]) => { | ||
dict[k] = v; | ||
return dict; | ||
}, new types_1.Dict()); | ||
} | ||
else if (types_2.isPolarInstance(t)) { | ||
else if (types_1.isPolarInstance(t)) { | ||
const i = this.getInstance(t.ExternalInstance.instance_id); | ||
return i instanceof Promise ? await i : i; | ||
} | ||
else if (types_2.isPolarPredicate(t)) { | ||
else if (types_1.isPolarPredicate(t)) { | ||
let { name, args } = t.Call; | ||
args = await Promise.all(args.map(async (a) => await this.toJs(a))); | ||
args = await Promise.all(args.map(a => this.toJs(a))); | ||
return new Predicate_1.Predicate(name, args); | ||
} | ||
else if (types_2.isPolarVariable(t)) { | ||
else if (types_1.isPolarVariable(t)) { | ||
return new Variable_1.Variable(t.Variable); | ||
} | ||
else if (types_1.isPolarExpression(t)) { | ||
// TODO(gj): Only allow expressions if the flag has been frobbed. | ||
const { operator, args: argTerms } = t.Expression; | ||
const args = await Promise.all(argTerms.map(a => this.toJs(a))); | ||
return new Expression_1.Expression(operator, args); | ||
} | ||
else if (types_1.isPolarPattern(t)) { | ||
if ('Dictionary' in t.Pattern) { | ||
const fields = await this.toJs({ value: t.Pattern }); | ||
return new Pattern_1.Pattern({ fields }); | ||
} | ||
else { | ||
let { tag, fields: { fields }, } = t.Pattern.Instance; | ||
const dict = await this.toJs({ value: { Dictionary: { fields } } }); | ||
return new Pattern_1.Pattern({ tag, fields: dict }); | ||
} | ||
} | ||
else { | ||
throw new errors_1.UnexpectedPolarTypeError(); | ||
const _ = t; | ||
return _; | ||
} | ||
@@ -337,3 +384,3 @@ } | ||
exports.Host = Host; | ||
_ffiPolar = new WeakMap(), _classes = new WeakMap(), _instances = new WeakMap(), _equalityFn = new WeakMap(); | ||
_Host_ffiPolar = new WeakMap(), _Host_classes = new WeakMap(), _Host_instances = new WeakMap(), _Host_equalityFn = new WeakMap(); | ||
//# sourceMappingURL=Host.js.map |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function __wbg_query_free(a: number): void; | ||
export function query_nextEvent(a: number): number; | ||
export function query_callResult(a: number, b: number, c: number, d: number): void; | ||
export function query_questionResult(a: number, b: number, c: number): void; | ||
export function query_debugCommand(a: number, b: number, c: number): void; | ||
export function query_appError(a: number, b: number, c: number): void; | ||
export function query_nextMessage(a: number): number; | ||
export function query_source(a: number): number; | ||
export function query_setLoggingOptions(a: number, b: number, c: number, d: number, e: number): void; | ||
export function __wbg_polar_free(a: number): void; | ||
export function polar_wasm_new(): number; | ||
export function polar_load(a: number, b: number, c: number, d: number, e: number): void; | ||
export function polar_enableRoles(a: number): void; | ||
export function polar_validateRolesConfig(a: number, b: number, c: number): void; | ||
export function polar_clearRules(a: number): void; | ||
@@ -23,4 +16,13 @@ export function polar_registerConstant(a: number, b: number, c: number, d: number, e: number): void; | ||
export function polar_nextMessage(a: number): number; | ||
export function __wbg_query_free(a: number): void; | ||
export function query_nextEvent(a: number): number; | ||
export function query_callResult(a: number, b: number, c: number, d: number): void; | ||
export function query_questionResult(a: number, b: number, c: number): void; | ||
export function query_debugCommand(a: number, b: number, c: number): void; | ||
export function query_appError(a: number, b: number, c: number): void; | ||
export function query_nextMessage(a: number): number; | ||
export function query_source(a: number): number; | ||
export function query_setLoggingOptions(a: number, b: number, c: number, d: number, e: number): void; | ||
export function __wbindgen_malloc(a: number): number; | ||
export function __wbindgen_realloc(a: number, b: number, c: number): number; | ||
export function __wbindgen_free(a: number, b: number): void; |
@@ -17,2 +17,9 @@ /* tslint:disable */ | ||
*/ | ||
enableRoles(): void; | ||
/** | ||
* @param {string} validation_query_results | ||
*/ | ||
validateRolesConfig(validation_query_results: string): void; | ||
/** | ||
*/ | ||
clearRules(): void; | ||
@@ -19,0 +26,0 @@ /** |
@@ -153,2 +153,15 @@ let imports = {}; | ||
*/ | ||
enableRoles() { | ||
wasm.polar_enableRoles(this.ptr); | ||
} | ||
/** | ||
* @param {string} validation_query_results | ||
*/ | ||
validateRolesConfig(validation_query_results) { | ||
var ptr0 = passStringToWasm0(validation_query_results, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
wasm.polar_validateRolesConfig(this.ptr, ptr0, len0); | ||
} | ||
/** | ||
*/ | ||
clearRules() { | ||
@@ -352,3 +365,3 @@ wasm.polar_clearRules(this.ptr); | ||
module.exports.__wbg_error_a1bf577179c3874c = function(arg0, arg1) { | ||
module.exports.__wbg_error_93aaa13138af264c = function(arg0, arg1) { | ||
console.error(getStringFromWasm0(arg0, arg1)); | ||
@@ -355,0 +368,0 @@ }; |
@@ -33,2 +33,12 @@ import { Host } from './Host'; | ||
/** | ||
* Enable Oso's built-in roles feature. | ||
*/ | ||
enableRoles(): Promise<void>; | ||
/** | ||
* Validate Oso roles config. | ||
* | ||
* @internal | ||
*/ | ||
private validateRolesConfig; | ||
/** | ||
* Clear rules from the Polar KB, but | ||
@@ -35,0 +45,0 @@ * retain all registered classes and constants. |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _a, _b; | ||
var _ffiPolar, _host; | ||
var _Polar_ffiPolar, _Polar_host, _Polar_rolesEnabled; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -36,3 +34,3 @@ exports.Polar = void 0; | ||
*/ | ||
_ffiPolar.set(this, void 0); | ||
_Polar_ffiPolar.set(this, void 0); | ||
/** | ||
@@ -44,6 +42,13 @@ * Manages registration and comparison of JavaScript classes and instances | ||
*/ | ||
_host.set(this, void 0); | ||
__classPrivateFieldSet(this, _ffiPolar, new polar_wasm_api_1.Polar()); | ||
_Polar_host.set(this, void 0); | ||
/** | ||
* Flag that tracks if the Oso roles feature is enabled. | ||
* | ||
* @internal | ||
*/ | ||
_Polar_rolesEnabled.set(this, void 0); | ||
__classPrivateFieldSet(this, _Polar_ffiPolar, new polar_wasm_api_1.Polar(), "f"); | ||
const equalityFn = opts.equalityFn || ((x, y) => x == y); | ||
__classPrivateFieldSet(this, _host, new Host_1.Host(__classPrivateFieldGet(this, _ffiPolar), equalityFn)); | ||
__classPrivateFieldSet(this, _Polar_host, new Host_1.Host(__classPrivateFieldGet(this, _Polar_ffiPolar, "f"), equalityFn), "f"); | ||
__classPrivateFieldSet(this, _Polar_rolesEnabled, false, "f"); | ||
// Register global constants. | ||
@@ -71,3 +76,3 @@ this.registerConstant(null, 'nil'); | ||
free() { | ||
__classPrivateFieldGet(this, _ffiPolar).free(); | ||
__classPrivateFieldGet(this, _Polar_ffiPolar, "f").free(); | ||
} | ||
@@ -80,3 +85,3 @@ /** | ||
__host() { | ||
return __classPrivateFieldGet(this, _host); | ||
return __classPrivateFieldGet(this, _Polar_host, "f"); | ||
} | ||
@@ -90,3 +95,3 @@ /** | ||
while (true) { | ||
let msg = __classPrivateFieldGet(this, _ffiPolar).nextMessage(); | ||
let msg = __classPrivateFieldGet(this, _Polar_ffiPolar, "f").nextMessage(); | ||
if (msg === undefined) | ||
@@ -98,2 +103,47 @@ break; | ||
/** | ||
* Enable Oso's built-in roles feature. | ||
*/ | ||
async enableRoles() { | ||
if (!__classPrivateFieldGet(this, _Polar_rolesEnabled, "f")) { | ||
const helpers = { | ||
join: (sep, l, r) => [l, r].join(sep), | ||
}; | ||
this.registerConstant(helpers, '__oso_internal_roles_helpers__'); | ||
__classPrivateFieldGet(this, _Polar_ffiPolar, "f").enableRoles(); | ||
this.processMessages(); | ||
await this.validateRolesConfig(); | ||
__classPrivateFieldSet(this, _Polar_rolesEnabled, true, "f"); | ||
} | ||
} | ||
/** | ||
* Validate Oso roles config. | ||
* | ||
* @internal | ||
*/ | ||
async validateRolesConfig() { | ||
const validationQueryResults = []; | ||
while (true) { | ||
const query = __classPrivateFieldGet(this, _Polar_ffiPolar, "f").nextInlineQuery(); | ||
this.processMessages(); | ||
if (query === undefined) | ||
break; | ||
const { results } = new Query_1.Query(query, __classPrivateFieldGet(this, _Polar_host, "f")); | ||
const queryResults = []; | ||
for await (const result of results) { | ||
queryResults.push(result); | ||
} | ||
validationQueryResults.push(queryResults); | ||
} | ||
const results = validationQueryResults.map(results => results.map(result => ({ | ||
// `Map<string, any> -> {[key: string]: PolarTerm}` b/c Maps aren't | ||
// trivially `JSON.stringify()`-able. | ||
bindings: [...result.entries()].reduce((obj, [k, v]) => { | ||
obj[k] = __classPrivateFieldGet(this, _Polar_host, "f").toPolar(v); | ||
return obj; | ||
}, {}), | ||
}))); | ||
__classPrivateFieldGet(this, _Polar_ffiPolar, "f").validateRolesConfig(JSON.stringify(results)); | ||
this.processMessages(); | ||
} | ||
/** | ||
* Clear rules from the Polar KB, but | ||
@@ -103,4 +153,5 @@ * retain all registered classes and constants. | ||
clearRules() { | ||
__classPrivateFieldGet(this, _ffiPolar).clearRules(); | ||
__classPrivateFieldGet(this, _Polar_ffiPolar, "f").clearRules(); | ||
this.processMessages(); | ||
__classPrivateFieldSet(this, _Polar_rolesEnabled, false, "f"); | ||
} | ||
@@ -131,6 +182,6 @@ /** | ||
async loadStr(contents, name) { | ||
__classPrivateFieldGet(this, _ffiPolar).load(contents, name); | ||
__classPrivateFieldGet(this, _Polar_ffiPolar, "f").load(contents, name); | ||
this.processMessages(); | ||
while (true) { | ||
const query = __classPrivateFieldGet(this, _ffiPolar).nextInlineQuery(); | ||
const query = __classPrivateFieldGet(this, _Polar_ffiPolar, "f").nextInlineQuery(); | ||
this.processMessages(); | ||
@@ -140,3 +191,3 @@ if (query === undefined) | ||
const source = query.source(); | ||
const { results } = new Query_1.Query(query, __classPrivateFieldGet(this, _host)); | ||
const { results } = new Query_1.Query(query, __classPrivateFieldGet(this, _Polar_host, "f")); | ||
const { done } = await results.next(); | ||
@@ -147,2 +198,6 @@ results.return(); | ||
} | ||
if (__classPrivateFieldGet(this, _Polar_rolesEnabled, "f")) { | ||
__classPrivateFieldSet(this, _Polar_rolesEnabled, false, "f"); | ||
await this.enableRoles(); | ||
} | ||
} | ||
@@ -153,10 +208,10 @@ /** | ||
query(q) { | ||
const host = Host_1.Host.clone(__classPrivateFieldGet(this, _host)); | ||
const host = Host_1.Host.clone(__classPrivateFieldGet(this, _Polar_host, "f")); | ||
let ffiQuery; | ||
if (typeof q === 'string') { | ||
ffiQuery = __classPrivateFieldGet(this, _ffiPolar).newQueryFromStr(q); | ||
ffiQuery = __classPrivateFieldGet(this, _Polar_ffiPolar, "f").newQueryFromStr(q); | ||
} | ||
else { | ||
const term = JSON.stringify(host.toPolar(q)); | ||
ffiQuery = __classPrivateFieldGet(this, _ffiPolar).newQueryFromTerm(term); | ||
ffiQuery = __classPrivateFieldGet(this, _Polar_ffiPolar, "f").newQueryFromTerm(term); | ||
} | ||
@@ -178,3 +233,3 @@ this.processMessages(); | ||
throw new errors_1.InvalidConstructorError(cls); | ||
const name = __classPrivateFieldGet(this, _host).cacheClass(cls, alias); | ||
const name = __classPrivateFieldGet(this, _Polar_host, "f").cacheClass(cls, alias); | ||
this.registerConstant(cls, name); | ||
@@ -186,4 +241,4 @@ } | ||
registerConstant(value, name) { | ||
const term = __classPrivateFieldGet(this, _host).toPolar(value); | ||
__classPrivateFieldGet(this, _ffiPolar).registerConstant(name, JSON.stringify(term)); | ||
const term = __classPrivateFieldGet(this, _Polar_host, "f").toPolar(value); | ||
__classPrivateFieldGet(this, _Polar_ffiPolar, "f").registerConstant(name, JSON.stringify(term)); | ||
} | ||
@@ -241,4 +296,4 @@ /** Start a REPL session. */ | ||
if (input !== '') { | ||
const ffiQuery = __classPrivateFieldGet(this, _ffiPolar).newQueryFromStr(input); | ||
const query = new Query_1.Query(ffiQuery, __classPrivateFieldGet(this, _host)); | ||
const ffiQuery = __classPrivateFieldGet(this, _Polar_ffiPolar, "f").newQueryFromStr(input); | ||
const query = new Query_1.Query(ffiQuery, __classPrivateFieldGet(this, _Polar_host, "f")); | ||
const results = []; | ||
@@ -267,3 +322,3 @@ for await (const result of query.results) { | ||
exports.Polar = Polar; | ||
_ffiPolar = new WeakMap(), _host = new WeakMap(); | ||
_Polar_ffiPolar = new WeakMap(), _Polar_host = new WeakMap(), _Polar_rolesEnabled = new WeakMap(); | ||
//# sourceMappingURL=Polar.js.map |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _a; | ||
var _ffiQuery, _calls, _host; | ||
var _Query_ffiQuery, _Query_calls, _Query_host; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -36,9 +34,9 @@ exports.Query = void 0; | ||
constructor(ffiQuery, host) { | ||
_ffiQuery.set(this, void 0); | ||
_calls.set(this, void 0); | ||
_host.set(this, void 0); | ||
_Query_ffiQuery.set(this, void 0); | ||
_Query_calls.set(this, void 0); | ||
_Query_host.set(this, void 0); | ||
ffiQuery.setLoggingOptions(...getLogLevelsFromEnv()); | ||
__classPrivateFieldSet(this, _ffiQuery, ffiQuery); | ||
__classPrivateFieldSet(this, _calls, new Map()); | ||
__classPrivateFieldSet(this, _host, host); | ||
__classPrivateFieldSet(this, _Query_ffiQuery, ffiQuery, "f"); | ||
__classPrivateFieldSet(this, _Query_calls, new Map(), "f"); | ||
__classPrivateFieldSet(this, _Query_host, host, "f"); | ||
this.results = this.start(); | ||
@@ -53,3 +51,3 @@ } | ||
while (true) { | ||
let msg = __classPrivateFieldGet(this, _ffiQuery).nextMessage(); | ||
let msg = __classPrivateFieldGet(this, _Query_ffiQuery, "f").nextMessage(); | ||
if (msg === undefined) | ||
@@ -66,3 +64,3 @@ break; | ||
questionResult(result, callId) { | ||
__classPrivateFieldGet(this, _ffiQuery).questionResult(callId, result); | ||
__classPrivateFieldGet(this, _Query_ffiQuery, "f").questionResult(callId, result); | ||
} | ||
@@ -76,3 +74,3 @@ /** | ||
callResult(callId, result) { | ||
__classPrivateFieldGet(this, _ffiQuery).callResult(callId, result); | ||
__classPrivateFieldGet(this, _Query_ffiQuery, "f").callResult(callId, result); | ||
} | ||
@@ -86,6 +84,6 @@ /** | ||
async nextCallResult(callId) { | ||
const { done, value } = await __classPrivateFieldGet(this, _calls).get(callId).next(); | ||
const { done, value } = await __classPrivateFieldGet(this, _Query_calls, "f").get(callId).next(); | ||
if (done) | ||
return undefined; | ||
return JSON.stringify(__classPrivateFieldGet(this, _host).toPolar(value)); | ||
return JSON.stringify(__classPrivateFieldGet(this, _Query_host, "f").toPolar(value)); | ||
} | ||
@@ -98,3 +96,3 @@ /** | ||
applicationError(message) { | ||
__classPrivateFieldGet(this, _ffiQuery).appError(message); | ||
__classPrivateFieldGet(this, _Query_ffiQuery, "f").appError(message); | ||
} | ||
@@ -109,3 +107,3 @@ /** | ||
try { | ||
const receiver = await __classPrivateFieldGet(this, _host).toJs(instance); | ||
const receiver = await __classPrivateFieldGet(this, _Query_host, "f").toJs(instance); | ||
value = receiver[attr]; | ||
@@ -115,3 +113,3 @@ if (args !== undefined) { | ||
// If value is a function, call it with the provided args. | ||
const jsArgs = args.map(async (a) => await __classPrivateFieldGet(this, _host).toJs(a)); | ||
const jsArgs = args.map(async (a) => await __classPrivateFieldGet(this, _Query_host, "f").toJs(a)); | ||
value = receiver[attr](...(await Promise.all(jsArgs))); | ||
@@ -137,3 +135,3 @@ } | ||
value = await Promise.resolve(value); | ||
value = JSON.stringify(__classPrivateFieldGet(this, _host).toPolar(value)); | ||
value = JSON.stringify(__classPrivateFieldGet(this, _Query_host, "f").toPolar(value)); | ||
this.callResult(callId, value); | ||
@@ -143,4 +141,4 @@ } | ||
async handleNextExternal(callId, iterable) { | ||
if (!__classPrivateFieldGet(this, _calls).has(callId)) { | ||
const value = await __classPrivateFieldGet(this, _host).toJs(iterable); | ||
if (!__classPrivateFieldGet(this, _Query_calls, "f").has(callId)) { | ||
const value = await __classPrivateFieldGet(this, _Query_host, "f").toJs(iterable); | ||
const generator = (async function* () { | ||
@@ -167,3 +165,3 @@ if (types_1.isIterableIterator(value)) { | ||
})(); | ||
__classPrivateFieldGet(this, _calls).set(callId, generator); | ||
__classPrivateFieldGet(this, _Query_calls, "f").set(callId, generator); | ||
} | ||
@@ -181,3 +179,3 @@ const result = await this.nextCallResult(callId); | ||
while (true) { | ||
const nextEvent = __classPrivateFieldGet(this, _ffiQuery).nextEvent(); | ||
const nextEvent = __classPrivateFieldGet(this, _Query_ffiQuery, "f").nextEvent(); | ||
this.processMessages(); | ||
@@ -192,3 +190,3 @@ const event = helpers_1.parseQueryEvent(nextEvent); | ||
for (const [k, v] of bindings.entries()) { | ||
transformed.set(k, await __classPrivateFieldGet(this, _host).toJs(v)); | ||
transformed.set(k, await __classPrivateFieldGet(this, _Query_host, "f").toJs(v)); | ||
} | ||
@@ -199,9 +197,9 @@ yield transformed; | ||
const { instanceId, tag, fields } = event.data; | ||
if (__classPrivateFieldGet(this, _host).hasInstance(instanceId)) | ||
if (__classPrivateFieldGet(this, _Query_host, "f").hasInstance(instanceId)) | ||
throw new errors_1.DuplicateInstanceRegistrationError(instanceId); | ||
await __classPrivateFieldGet(this, _host).makeInstance(tag, fields, instanceId); | ||
await __classPrivateFieldGet(this, _Query_host, "f").makeInstance(tag, fields, instanceId); | ||
break; | ||
} | ||
case types_1.QueryEventKind.ExternalCall: { | ||
const { attribute, callId, instance, args, } = event.data; | ||
const { attribute, callId, instance, args } = event.data; | ||
await this.handleCall(attribute, callId, instance, args); | ||
@@ -211,4 +209,4 @@ break; | ||
case types_1.QueryEventKind.ExternalIsSubspecializer: { | ||
const { instanceId, leftTag, rightTag, callId, } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _host).isSubspecializer(instanceId, leftTag, rightTag); | ||
const { instanceId, leftTag, rightTag, callId } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _Query_host, "f").isSubspecializer(instanceId, leftTag, rightTag); | ||
this.questionResult(answer, callId); | ||
@@ -219,3 +217,3 @@ break; | ||
const { args, callId, operator } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _host).externalOp(operator, args[0], args[1]); | ||
const answer = await __classPrivateFieldGet(this, _Query_host, "f").externalOp(operator, args[0], args[1]); | ||
this.questionResult(answer, callId); | ||
@@ -226,3 +224,3 @@ break; | ||
const { instance, tag, callId } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _host).isa(instance, tag); | ||
const answer = await __classPrivateFieldGet(this, _Query_host, "f").isa(instance, tag); | ||
this.questionResult(answer, callId); | ||
@@ -233,3 +231,3 @@ break; | ||
const { leftId, rightId, callId } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _host).unify(leftId, rightId); | ||
const answer = await __classPrivateFieldGet(this, _Query_host, "f").unify(leftId, rightId); | ||
this.questionResult(answer, callId); | ||
@@ -258,4 +256,4 @@ break; | ||
const trimmed = line.trim().replace(/;+$/, ''); | ||
const command = __classPrivateFieldGet(this, _host).toPolar(trimmed); | ||
__classPrivateFieldGet(this, _ffiQuery).debugCommand(JSON.stringify(command)); | ||
const command = __classPrivateFieldGet(this, _Query_host, "f").toPolar(trimmed); | ||
__classPrivateFieldGet(this, _Query_ffiQuery, "f").debugCommand(JSON.stringify(command)); | ||
this.processMessages(); | ||
@@ -268,3 +266,3 @@ }); | ||
finally { | ||
__classPrivateFieldGet(this, _ffiQuery).free(); | ||
__classPrivateFieldGet(this, _Query_ffiQuery, "f").free(); | ||
} | ||
@@ -274,3 +272,3 @@ } | ||
exports.Query = Query; | ||
_ffiQuery = new WeakMap(), _calls = new WeakMap(), _host = new WeakMap(); | ||
_Query_ffiQuery = new WeakMap(), _Query_calls = new WeakMap(), _Query_host = new WeakMap(); | ||
//# sourceMappingURL=Query.js.map |
@@ -18,7 +18,7 @@ /** | ||
* Type guard to test if a string received from across the WebAssembly | ||
* boundary is a PolarOperator. | ||
* boundary is a PolarComparisonOperator. | ||
* | ||
* @internal | ||
*/ | ||
export declare function isPolarOperator(s: string): s is PolarOperator; | ||
export declare function isPolarComparisonOperator(s: string): s is PolarComparisonOperator; | ||
/** | ||
@@ -93,5 +93,3 @@ * Polar numeric type. | ||
Dictionary: { | ||
fields: Map<string, PolarTerm> | { | ||
[key: string]: PolarTerm; | ||
}; | ||
fields: Map<string, PolarTerm>; | ||
}; | ||
@@ -152,2 +150,40 @@ } | ||
/** | ||
* 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<string, PolarTerm>; | ||
}; | ||
}; | ||
} | ||
/** | ||
* 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 | ||
@@ -160,2 +196,16 @@ * boundary is a Polar application instance. | ||
/** | ||
* 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. | ||
@@ -165,3 +215,3 @@ * | ||
*/ | ||
declare type PolarValue = PolarStr | PolarNum | PolarBool | PolarList | PolarDict | PolarPredicate | PolarVariable | PolarInstance; | ||
declare type PolarValue = PolarStr | PolarNum | PolarBool | PolarList | PolarDict | PolarPredicate | PolarVariable | PolarInstance | PolarExpression | PolarPattern; | ||
/** | ||
@@ -255,18 +305,51 @@ * Union of Polar value types. | ||
/** | ||
* Polar operators. | ||
* Polar comparison operators. | ||
* | ||
* Currently, the only operators supported for external operations are | ||
* comparison operators. | ||
* Currently, these are the only operators supported for external operations. | ||
* | ||
* @internal | ||
*/ | ||
export declare enum PolarOperator { | ||
Eq = "Eq", | ||
Geq = "Geq", | ||
Gt = "Gt", | ||
Leq = "Leq", | ||
Lt = "Lt", | ||
Neq = "Neq" | ||
} | ||
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 | ||
@@ -280,3 +363,3 @@ * involving one or more application instances. | ||
callId: number; | ||
operator: PolarOperator; | ||
operator: PolarComparisonOperator; | ||
} | ||
@@ -380,2 +463,17 @@ /** | ||
export declare function isAsyncIterator(x: any): boolean; | ||
/** | ||
* 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]: any; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAsyncIterator = exports.isIterableIterator = exports.QueryEventKind = exports.PolarOperator = exports.isPolarTerm = exports.isPolarInstance = exports.isPolarVariable = exports.isPolarPredicate = exports.isPolarDict = exports.isPolarList = exports.isPolarBool = exports.isPolarNum = exports.isPolarOperator = exports.isPolarStr = void 0; | ||
exports.Dict = exports.isAsyncIterator = exports.isIterableIterator = exports.QueryEventKind = exports.isPolarTerm = exports.isPolarPattern = exports.isPolarExpression = exports.isPolarInstance = exports.isPolarVariable = exports.isPolarPredicate = exports.isPolarDict = exports.isPolarList = exports.isPolarBool = exports.isPolarNum = exports.isPolarComparisonOperator = exports.isPolarStr = void 0; | ||
/** | ||
@@ -16,10 +16,10 @@ * Type guard to test if a Polar value received from across the WebAssembly | ||
* Type guard to test if a string received from across the WebAssembly | ||
* boundary is a PolarOperator. | ||
* boundary is a PolarComparisonOperator. | ||
* | ||
* @internal | ||
*/ | ||
function isPolarOperator(s) { | ||
return s in PolarOperator; | ||
function isPolarComparisonOperator(s) { | ||
return s in comparisonOperators; | ||
} | ||
exports.isPolarOperator = isPolarOperator; | ||
exports.isPolarComparisonOperator = isPolarComparisonOperator; | ||
/** | ||
@@ -96,2 +96,22 @@ * Type guard to test if a Polar value received from across the WebAssembly | ||
/** | ||
* Type guard to test if a Polar value received from across the WebAssembly | ||
* boundary is a Polar expression. | ||
* | ||
* @internal | ||
*/ | ||
function isPolarExpression(v) { | ||
return v.Expression !== undefined; | ||
} | ||
exports.isPolarExpression = isPolarExpression; | ||
/** | ||
* Type guard to test if a Polar value received from across the WebAssembly | ||
* boundary is a Polar pattern. | ||
* | ||
* @internal | ||
*/ | ||
function isPolarPattern(v) { | ||
return v.Pattern !== undefined; | ||
} | ||
exports.isPolarPattern = isPolarPattern; | ||
/** | ||
* Type guard to test if a JSON payload received from across the WebAssembly | ||
@@ -112,3 +132,5 @@ * boundary contains a valid Polar value. | ||
isPolarVariable(v) || | ||
isPolarInstance(v)); | ||
isPolarInstance(v) || | ||
isPolarExpression(v) || | ||
isPolarPattern(v)); | ||
} | ||
@@ -126,19 +148,44 @@ /** | ||
/** | ||
* Polar operators. | ||
* Polar comparison operators. | ||
* | ||
* Currently, the only operators supported for external operations are | ||
* comparison operators. | ||
* Currently, these are the only operators supported for external operations. | ||
* | ||
* @internal | ||
*/ | ||
var PolarOperator; | ||
(function (PolarOperator) { | ||
PolarOperator["Eq"] = "Eq"; | ||
PolarOperator["Geq"] = "Geq"; | ||
PolarOperator["Gt"] = "Gt"; | ||
PolarOperator["Leq"] = "Leq"; | ||
PolarOperator["Lt"] = "Lt"; | ||
PolarOperator["Neq"] = "Neq"; | ||
})(PolarOperator = exports.PolarOperator || (exports.PolarOperator = {})); | ||
const comparisonOperators = { | ||
Eq: 'Eq', | ||
Geq: 'Geq', | ||
Gt: 'Gt', | ||
Leq: 'Leq', | ||
Lt: 'Lt', | ||
Neq: 'Neq', | ||
}; | ||
/** | ||
* Polar operators. | ||
* | ||
* @internal | ||
*/ | ||
const operators = { | ||
Add: 'Add', | ||
And: 'And', | ||
Assign: 'Assign', | ||
Cut: 'Cut', | ||
Debug: 'Debug', | ||
Div: 'Div', | ||
Dot: 'Dot', | ||
ForAll: 'ForAll', | ||
In: 'In', | ||
Isa: 'Isa', | ||
Mod: 'Mod', | ||
Mul: 'Mul', | ||
New: 'New', | ||
Not: 'Not', | ||
Or: 'Or', | ||
Print: 'Print', | ||
Rem: 'Rem', | ||
Sub: 'Sub', | ||
Unify: 'Unify', | ||
...comparisonOperators, | ||
}; | ||
/** | ||
* Union of all [[`QueryEvent`]] types. | ||
@@ -181,2 +228,17 @@ * | ||
exports.isAsyncIterator = isAsyncIterator; | ||
/** | ||
* 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 | ||
*/ | ||
class Dict extends Object { | ||
} | ||
exports.Dict = Dict; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "oso", | ||
"version": "0.12.4", | ||
"version": "0.13.0", | ||
"description": "oso authorization library.", | ||
@@ -29,3 +29,3 @@ "bin": "bin/repl.js", | ||
"scripts": { | ||
"check": "gts check", | ||
"lint": "gts lint", | ||
"clean": "gts clean", | ||
@@ -43,16 +43,13 @@ "fix": "gts fix", | ||
"@types/jest": "^26.0.9", | ||
"@types/lodash": "^4.14.158", | ||
"@types/node": "^14.0.14", | ||
"@types/node": "^15.0.0", | ||
"chokidar-cli": "^2.1.0", | ||
"gts": "^2.0.2", | ||
"jest": "^26.3.0", | ||
"gts": "^3.1.0", | ||
"jest": "^27.0.4", | ||
"live-server": "^1.2.1", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"temp-write": "^4.0.0", | ||
"ts-jest": "^26.2.0", | ||
"ts-jest": "^27.0.3", | ||
"ts-node": "^8.10.2", | ||
"typedoc": "^0.20.4", | ||
"typescript": "^3.9.5" | ||
"typedoc": "^0.21.0", | ||
"typescript": "^4.3.4" | ||
} | ||
} | ||
} |
@@ -60,3 +60,3 @@ # Oso | ||
- Maven: 3.6+ | ||
- Node.js: 10.14.2+ | ||
- Node.js: 12.20.0+ | ||
- Yarn 1.22+ | ||
@@ -63,0 +63,0 @@ - Python: 3.6+ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2449602
11
54
3646