Comparing version 0.11.0 to 0.11.1
@@ -39,5 +39,2 @@ /** Base error type. */ | ||
} | ||
export declare class UnimplementedOperationError extends PolarError { | ||
constructor(operation: string); | ||
} | ||
export declare class UnregisteredClassError extends PolarError { | ||
@@ -44,0 +41,0 @@ constructor(name: string); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnexpectedPolarTypeError = exports.UnregisteredInstanceError = exports.UnregisteredClassError = exports.UnimplementedOperationError = 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.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; | ||
const helpers_1 = require("./helpers"); | ||
@@ -83,9 +83,2 @@ /** Base error type. */ | ||
exports.PolarFileNotFoundError = PolarFileNotFoundError; | ||
class UnimplementedOperationError extends PolarError { | ||
constructor(operation) { | ||
super(`${operation} are unimplemented in the oso Node.js library`); | ||
Object.setPrototypeOf(this, UnimplementedOperationError.prototype); | ||
} | ||
} | ||
exports.UnimplementedOperationError = UnimplementedOperationError; | ||
class UnregisteredClassError extends PolarError { | ||
@@ -92,0 +85,0 @@ constructor(name) { |
@@ -71,3 +71,3 @@ "use strict"; | ||
case event['ExternalOp'] !== undefined: | ||
throw new errors_1.UnimplementedOperationError('comparison operators'); | ||
return parseExternalOp(event['ExternalOp']); | ||
default: | ||
@@ -194,2 +194,26 @@ throw new Error(); | ||
* Try to parse a JSON payload received from across the WebAssembly boundary as | ||
* an [[`ExternalOp`]]. | ||
* | ||
* @internal | ||
*/ | ||
function parseExternalOp({ call_id: callId, args, operator }) { | ||
if (!Number.isSafeInteger(callId) || | ||
(args !== undefined && | ||
(!Array.isArray(args) || | ||
args.length !== 2 || | ||
args.some((a) => !types_1.isPolarTerm(a))))) | ||
throw new Error(); | ||
if (!types_1.isPolarOperator(operator)) | ||
throw new errors_1.PolarError(`Unsupported external operation '${repr(args[0])} ${operator} ${repr(args[1])}'`); | ||
return { | ||
kind: types_1.QueryEventKind.ExternalOp, | ||
data: { | ||
args, | ||
callId, | ||
operator, | ||
}, | ||
}; | ||
} | ||
/** | ||
* Try to parse a JSON payload received from across the WebAssembly boundary as | ||
* an [[`ExternalUnify`]]. | ||
@@ -196,0 +220,0 @@ * |
import type { Polar as FfiPolar } from './polar_wasm_api'; | ||
import type { Class, EqualityFn, PolarTerm } from './types'; | ||
import { PolarOperator } from './types'; | ||
/** | ||
@@ -86,2 +87,8 @@ * Translator between Polar and JavaScript. | ||
/** | ||
* Check if the given instances conform to the operator. | ||
* | ||
* @internal | ||
*/ | ||
externalOp(op: PolarOperator, left: PolarTerm, right: PolarTerm): Promise<boolean>; | ||
/** | ||
* Check if two instances unify according to the [[`EqualityFn`]]. | ||
@@ -88,0 +95,0 @@ * |
@@ -23,2 +23,3 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
const types_2 = require("./types"); | ||
/** | ||
@@ -177,2 +178,25 @@ * Translator between Polar and JavaScript. | ||
/** | ||
* Check if the given instances conform to the operator. | ||
* | ||
* @internal | ||
*/ | ||
async externalOp(op, left, right) { | ||
const leftjs = await this.toJs(left); | ||
const rightjs = await this.toJs(right); | ||
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); | ||
} | ||
} | ||
/** | ||
* Check if two instances unify according to the [[`EqualityFn`]]. | ||
@@ -241,6 +265,6 @@ * | ||
const t = v.value; | ||
if (types_1.isPolarStr(t)) { | ||
if (types_2.isPolarStr(t)) { | ||
return t.String; | ||
} | ||
else if (types_1.isPolarNum(t)) { | ||
else if (types_2.isPolarNum(t)) { | ||
if ('Float' in t.Number) { | ||
@@ -265,9 +289,9 @@ const f = t.Number.Float; | ||
} | ||
else if (types_1.isPolarBool(t)) { | ||
else if (types_2.isPolarBool(t)) { | ||
return t.Boolean; | ||
} | ||
else if (types_1.isPolarList(t)) { | ||
else if (types_2.isPolarList(t)) { | ||
return await Promise.all(t.List.map(async (el) => await this.toJs(el))); | ||
} | ||
else if (types_1.isPolarDict(t)) { | ||
else if (types_2.isPolarDict(t)) { | ||
const { fields } = t.Dictionary; | ||
@@ -283,7 +307,7 @@ let entries = typeof fields.entries === 'function' | ||
} | ||
else if (types_1.isPolarInstance(t)) { | ||
else if (types_2.isPolarInstance(t)) { | ||
const i = this.getInstance(t.ExternalInstance.instance_id); | ||
return i instanceof Promise ? await i : i; | ||
} | ||
else if (types_1.isPolarPredicate(t)) { | ||
else if (types_2.isPolarPredicate(t)) { | ||
let { name, args } = t.Call; | ||
@@ -293,3 +317,3 @@ args = await Promise.all(args.map(async (a) => await this.toJs(a))); | ||
} | ||
else if (types_1.isPolarVariable(t)) { | ||
else if (types_2.isPolarVariable(t)) { | ||
return new Variable_1.Variable(t.Variable); | ||
@@ -296,0 +320,0 @@ } |
@@ -196,2 +196,8 @@ "use strict"; | ||
} | ||
case types_1.QueryEventKind.ExternalOp: { | ||
const { args, callId, operator } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _host).externalOp(operator, args[0], args[1]); | ||
this.questionResult(answer, callId); | ||
break; | ||
} | ||
case types_1.QueryEventKind.ExternalIsa: { | ||
@@ -198,0 +204,0 @@ const { instance, tag, callId } = event.data; |
@@ -17,2 +17,9 @@ /** | ||
/** | ||
* Type guard to test if a string received from across the WebAssembly | ||
* boundary is a PolarOperator. | ||
* | ||
* @internal | ||
*/ | ||
export declare function isPolarOperator(s: string): s is PolarOperator; | ||
/** | ||
* Polar numeric type. | ||
@@ -251,9 +258,9 @@ * | ||
*/ | ||
declare enum PolarOperator { | ||
Eq = 0, | ||
Geq = 1, | ||
Gt = 2, | ||
Leq = 3, | ||
Lt = 4, | ||
Neq = 5 | ||
export declare enum PolarOperator { | ||
Eq = "Eq", | ||
Geq = "Geq", | ||
Gt = "Gt", | ||
Leq = "Leq", | ||
Lt = "Lt", | ||
Neq = "Neq" | ||
} | ||
@@ -260,0 +267,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAsyncIterator = exports.isIterableIterator = exports.QueryEventKind = exports.isPolarTerm = exports.isPolarInstance = exports.isPolarVariable = exports.isPolarPredicate = exports.isPolarDict = exports.isPolarList = exports.isPolarBool = exports.isPolarNum = exports.isPolarStr = void 0; | ||
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; | ||
/** | ||
@@ -15,2 +15,12 @@ * 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. | ||
* | ||
* @internal | ||
*/ | ||
function isPolarOperator(s) { | ||
return s in PolarOperator; | ||
} | ||
exports.isPolarOperator = isPolarOperator; | ||
/** | ||
* Type guard to test if a Polar value received from across the WebAssembly | ||
@@ -123,9 +133,9 @@ * boundary is a Polar numeric. | ||
(function (PolarOperator) { | ||
PolarOperator[PolarOperator["Eq"] = 0] = "Eq"; | ||
PolarOperator[PolarOperator["Geq"] = 1] = "Geq"; | ||
PolarOperator[PolarOperator["Gt"] = 2] = "Gt"; | ||
PolarOperator[PolarOperator["Leq"] = 3] = "Leq"; | ||
PolarOperator[PolarOperator["Lt"] = 4] = "Lt"; | ||
PolarOperator[PolarOperator["Neq"] = 5] = "Neq"; | ||
})(PolarOperator || (PolarOperator = {})); | ||
PolarOperator["Eq"] = "Eq"; | ||
PolarOperator["Geq"] = "Geq"; | ||
PolarOperator["Gt"] = "Gt"; | ||
PolarOperator["Leq"] = "Leq"; | ||
PolarOperator["Lt"] = "Lt"; | ||
PolarOperator["Neq"] = "Neq"; | ||
})(PolarOperator = exports.PolarOperator || (exports.PolarOperator = {})); | ||
/** | ||
@@ -132,0 +142,0 @@ * Union of all [[`QueryEvent`]] types. |
{ | ||
"name": "oso", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "oso authorization library.", | ||
@@ -5,0 +5,0 @@ "bin": "bin/repl.js", |
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
3230
2487991