Comparing version 0.15.0 to 0.20.0-beta
@@ -222,2 +222,21 @@ import * as wasm from './polar_wasm_api_bg.wasm'; | ||
} | ||
/** | ||
* @param {string} types | ||
* @param {string} partial_results | ||
* @param {string} variable | ||
* @param {string} class_tag | ||
* @returns {any} | ||
*/ | ||
buildFilterPlan(types, partial_results, variable, class_tag) { | ||
var ptr0 = passStringToWasm0(types, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
var ptr1 = passStringToWasm0(partial_results, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len1 = WASM_VECTOR_LEN; | ||
var ptr2 = passStringToWasm0(variable, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len2 = WASM_VECTOR_LEN; | ||
var ptr3 = passStringToWasm0(class_tag, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len3 = WASM_VECTOR_LEN; | ||
var ret = wasm.polar_buildFilterPlan(this.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3); | ||
return takeObject(ret); | ||
} | ||
} | ||
@@ -295,2 +314,13 @@ /** | ||
/** | ||
* @param {string} name | ||
* @param {string} value | ||
*/ | ||
bind(name, value) { | ||
var ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
var ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len1 = WASM_VECTOR_LEN; | ||
wasm.query_bind(this.ptr, ptr0, len0, ptr1, len1); | ||
} | ||
/** | ||
* @param {string | undefined} rust_log | ||
@@ -365,3 +395,3 @@ * @param {string | undefined} polar_log | ||
export const __wbg_error_55270a6c82201b23 = function(arg0, arg1) { | ||
export const __wbg_error_41f20ae0b8f787b8 = function(arg0, arg1) { | ||
console.error(getStringFromWasm0(arg0, arg1)); | ||
@@ -368,0 +398,0 @@ }; |
@@ -16,2 +16,3 @@ /* tslint:disable */ | ||
export function polar_nextMessage(a: number): number; | ||
export function polar_buildFilterPlan(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): number; | ||
export function __wbg_query_free(a: number): void; | ||
@@ -25,2 +26,3 @@ export function query_nextEvent(a: number): number; | ||
export function query_source(a: number): number; | ||
export function query_bind(a: number, b: number, c: number, d: number, e: number): void; | ||
export function query_setLoggingOptions(a: number, b: number, c: number, d: number, e: number): void; | ||
@@ -27,0 +29,0 @@ export function __wbindgen_malloc(a: number): number; |
@@ -52,2 +52,10 @@ /* tslint:disable */ | ||
nextMessage(): any; | ||
/** | ||
* @param {string} types | ||
* @param {string} partial_results | ||
* @param {string} variable | ||
* @param {string} class_tag | ||
* @returns {any} | ||
*/ | ||
buildFilterPlan(types: string, partial_results: string, variable: string, class_tag: string): any; | ||
} | ||
@@ -89,2 +97,7 @@ /** | ||
/** | ||
* @param {string} name | ||
* @param {string} value | ||
*/ | ||
bind(name: string, value: string): void; | ||
/** | ||
* @param {string | undefined} rust_log | ||
@@ -91,0 +104,0 @@ * @param {string | undefined} polar_log |
@@ -64,4 +64,8 @@ "use strict"; | ||
return parseExternalIsSubspecializer(event['ExternalIsSubSpecializer']); | ||
case event['ExternalIsSubclass'] !== undefined: | ||
return parseExternalIsSubclass(event['ExternalIsSubclass']); | ||
case event['ExternalIsa'] !== undefined: | ||
return parseExternalIsa(event['ExternalIsa']); | ||
case event['ExternalIsaWithPath'] !== undefined: | ||
return parseExternalIsaWithPath(event['ExternalIsaWithPath']); | ||
case event['Debug'] !== undefined: | ||
@@ -176,2 +180,18 @@ return parseDebug(event['Debug']); | ||
* Try to parse a JSON payload received from across the WebAssembly boundary as | ||
* an [[`ExternalIsSubclass`]]. | ||
* | ||
* @internal | ||
*/ | ||
function parseExternalIsSubclass({ call_id: callId, left_class_tag: leftTag, right_class_tag: rightTag, }) { | ||
if (!Number.isSafeInteger(callId) || | ||
typeof leftTag !== 'string' || | ||
typeof rightTag !== 'string') | ||
throw new Error(); | ||
return { | ||
kind: types_1.QueryEventKind.ExternalIsSubclass, | ||
data: { callId, leftTag, rightTag }, | ||
}; | ||
} | ||
/** | ||
* Try to parse a JSON payload received from across the WebAssembly boundary as | ||
* an [[`ExternalIsa`]]. | ||
@@ -193,2 +213,18 @@ * | ||
* Try to parse a JSON payload received from across the WebAssembly boundary as | ||
* an [[`ExternalIsa`]]. | ||
* | ||
* @internal | ||
*/ | ||
function parseExternalIsaWithPath({ call_id: callId, base_tag: baseTag, path, class_tag: classTag, }) { | ||
if (!Number.isSafeInteger(callId) || | ||
typeof classTag !== 'string' || | ||
typeof baseTag !== 'string') | ||
throw new Error(); | ||
return { | ||
kind: types_1.QueryEventKind.ExternalIsaWithPath, | ||
data: { callId, baseTag, path, classTag }, | ||
}; | ||
} | ||
/** | ||
* Try to parse a JSON payload received from across the WebAssembly boundary as | ||
* an [[`ExternalOp`]]. | ||
@@ -195,0 +231,0 @@ * |
@@ -10,2 +10,5 @@ import type { Polar as FfiPolar } from './polar_wasm_api'; | ||
#private; | ||
clsNames: Map<Class, string>; | ||
types: Map<string, Map<string, any>>; | ||
fetchers: Map<string, any>; | ||
/** | ||
@@ -81,2 +84,8 @@ * Shallow clone a host to extend its state for the duration of a particular | ||
/** | ||
* Check if the left class is a subclass of the right class. | ||
* | ||
* @internal | ||
*/ | ||
isSubclass(left: string, right: string): Promise<boolean>; | ||
/** | ||
* Check if the given instance is an instance of a particular class. | ||
@@ -88,2 +97,9 @@ * | ||
/** | ||
* Check if a sequence of field accesses on the given class is an | ||
* instance of another class. | ||
* | ||
* @internal | ||
*/ | ||
isaWithPath(baseTag: string, path: string[], classTag: string): Promise<boolean>; | ||
/** | ||
* Check if the given instances conform to the operator. | ||
@@ -90,0 +106,0 @@ * |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
var _Host_ffiPolar, _Host_classes, _Host_instances, _Host_equalityFn; | ||
var _Host_ffiPolar, _Host_classes, _Host_classIds, _Host_instances, _Host_equalityFn; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -34,2 +34,3 @@ exports.Host = void 0; | ||
_Host_classes.set(this, void 0); | ||
_Host_classIds.set(this, void 0); | ||
_Host_instances.set(this, void 0); | ||
@@ -40,2 +41,6 @@ _Host_equalityFn.set(this, void 0); | ||
__classPrivateFieldSet(this, _Host_instances, new Map(), "f"); | ||
__classPrivateFieldSet(this, _Host_classIds, new Map(), "f"); | ||
this.clsNames = new Map(); | ||
this.types = new Map(); | ||
this.fetchers = new Map(); | ||
__classPrivateFieldSet(this, _Host_equalityFn, equalityFn, "f"); | ||
@@ -53,2 +58,6 @@ } | ||
__classPrivateFieldSet(clone, _Host_instances, new Map(__classPrivateFieldGet(host, _Host_instances, "f")), "f"); | ||
__classPrivateFieldSet(clone, _Host_classIds, new Map(__classPrivateFieldGet(host, _Host_classIds, "f")), "f"); | ||
clone.clsNames = new Map(host.clsNames); | ||
clone.types = new Map(host.types); | ||
clone.fetchers = new Map(host.fetchers); | ||
return clone; | ||
@@ -170,2 +179,13 @@ } | ||
/** | ||
* Check if the left class is a subclass of the right class. | ||
* | ||
* @internal | ||
*/ | ||
async isSubclass(left, right) { | ||
const leftCls = this.getClass(left); | ||
const rightCls = this.getClass(right); | ||
const mro = helpers_1.ancestors(leftCls); | ||
return mro.includes(rightCls); | ||
} | ||
/** | ||
* Check if the given instance is an instance of a particular class. | ||
@@ -181,2 +201,21 @@ * | ||
/** | ||
* Check if a sequence of field accesses on the given class is an | ||
* instance of another class. | ||
* | ||
* @internal | ||
*/ | ||
async isaWithPath(baseTag, path, classTag) { | ||
return (classTag == | ||
path.reduce((k, field) => { | ||
if (k != undefined) { | ||
const l = this.types.get(k); | ||
if (l != undefined) | ||
k = this.clsNames.get(l.get(field)); | ||
else | ||
k = l; | ||
} | ||
return k; | ||
}, baseTag)); | ||
} | ||
/** | ||
* Check if the given instances conform to the operator. | ||
@@ -249,3 +288,3 @@ * | ||
case v instanceof Pattern_1.Pattern: | ||
const dict = this.toPolar(v.fields).value; | ||
let dict = this.toPolar(v.fields).value; | ||
if (v.tag === undefined) { | ||
@@ -255,2 +294,6 @@ return { value: { Pattern: dict } }; | ||
else { | ||
let d = dict.Dictionary; | ||
if (d == undefined) { | ||
d = { fields: new Map() }; | ||
} | ||
return { | ||
@@ -261,3 +304,3 @@ value: { | ||
tag: v.tag, | ||
fields: dict.Dictionary, | ||
fields: d, | ||
}, | ||
@@ -365,3 +408,3 @@ }, | ||
exports.Host = Host; | ||
_Host_ffiPolar = new WeakMap(), _Host_classes = new WeakMap(), _Host_instances = new WeakMap(), _Host_equalityFn = new WeakMap(); | ||
_Host_ffiPolar = new WeakMap(), _Host_classes = new WeakMap(), _Host_classIds = new WeakMap(), _Host_instances = new WeakMap(), _Host_equalityFn = new WeakMap(); | ||
//# sourceMappingURL=Host.js.map |
@@ -16,2 +16,3 @@ /* tslint:disable */ | ||
export function polar_nextMessage(a: number): number; | ||
export function polar_buildFilterPlan(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): number; | ||
export function __wbg_query_free(a: number): void; | ||
@@ -25,2 +26,3 @@ export function query_nextEvent(a: number): number; | ||
export function query_source(a: number): number; | ||
export function query_bind(a: number, b: number, c: number, d: number, e: number): void; | ||
export function query_setLoggingOptions(a: number, b: number, c: number, d: number, e: number): void; | ||
@@ -27,0 +29,0 @@ export function __wbindgen_malloc(a: number): number; |
@@ -52,2 +52,10 @@ /* tslint:disable */ | ||
nextMessage(): any; | ||
/** | ||
* @param {string} types | ||
* @param {string} partial_results | ||
* @param {string} variable | ||
* @param {string} class_tag | ||
* @returns {any} | ||
*/ | ||
buildFilterPlan(types: string, partial_results: string, variable: string, class_tag: string): any; | ||
} | ||
@@ -89,2 +97,7 @@ /** | ||
/** | ||
* @param {string} name | ||
* @param {string} value | ||
*/ | ||
bind(name: string, value: string): void; | ||
/** | ||
* @param {string | undefined} rust_log | ||
@@ -91,0 +104,0 @@ * @param {string | undefined} polar_log |
@@ -221,2 +221,21 @@ let imports = {}; | ||
} | ||
/** | ||
* @param {string} types | ||
* @param {string} partial_results | ||
* @param {string} variable | ||
* @param {string} class_tag | ||
* @returns {any} | ||
*/ | ||
buildFilterPlan(types, partial_results, variable, class_tag) { | ||
var ptr0 = passStringToWasm0(types, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
var ptr1 = passStringToWasm0(partial_results, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len1 = WASM_VECTOR_LEN; | ||
var ptr2 = passStringToWasm0(variable, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len2 = WASM_VECTOR_LEN; | ||
var ptr3 = passStringToWasm0(class_tag, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len3 = WASM_VECTOR_LEN; | ||
var ret = wasm.polar_buildFilterPlan(this.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3); | ||
return takeObject(ret); | ||
} | ||
} | ||
@@ -295,2 +314,13 @@ module.exports.Polar = Polar; | ||
/** | ||
* @param {string} name | ||
* @param {string} value | ||
*/ | ||
bind(name, value) { | ||
var ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len0 = WASM_VECTOR_LEN; | ||
var ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
var len1 = WASM_VECTOR_LEN; | ||
wasm.query_bind(this.ptr, ptr0, len0, ptr1, len1); | ||
} | ||
/** | ||
* @param {string | undefined} rust_log | ||
@@ -366,3 +396,3 @@ * @param {string | undefined} polar_log | ||
module.exports.__wbg_error_55270a6c82201b23 = function(arg0, arg1) { | ||
module.exports.__wbg_error_41f20ae0b8f787b8 = function(arg0, arg1) { | ||
console.error(getStringFromWasm0(arg0, arg1)); | ||
@@ -369,0 +399,0 @@ }; |
import { Host } from './Host'; | ||
import { Predicate } from './Predicate'; | ||
import type { Class, Options, QueryResult } from './types'; | ||
import { Class, Options, QueryResult } from './types'; | ||
/** Create and manage an instance of the Polar runtime. */ | ||
@@ -58,4 +58,8 @@ export declare class Polar { | ||
*/ | ||
query(q: Predicate | string): QueryResult; | ||
query(q: Predicate | string, bindings?: Map<string, any>): QueryResult; | ||
/** | ||
* Query for a Polar rule with bindings. | ||
*/ | ||
queryRuleWithBindings(name: string, bindings: Map<string, any>, ...args: unknown[]): QueryResult; | ||
/** | ||
* Query for a Polar rule. | ||
@@ -67,3 +71,3 @@ */ | ||
*/ | ||
registerClass<T>(cls: Class<T>, alias?: string): void; | ||
registerClass<T>(cls: Class<T>, alias?: string, types?: Map<string, any>, fetcher?: any): void; | ||
/** | ||
@@ -73,2 +77,6 @@ * Register a JavaScript value for use in Polar policies. | ||
registerConstant(value: any, name: string): void; | ||
/** | ||
* Returns all the resources the actor is allowed to perform some action on. | ||
*/ | ||
getAllowedResources(actor: any, action: any, cls: any): Promise<any>; | ||
/** Start a REPL session. */ | ||
@@ -75,0 +83,0 @@ repl(files?: string[]): Promise<void>; |
@@ -26,2 +26,6 @@ "use strict"; | ||
const helpers_1 = require("./helpers"); | ||
const Variable_1 = require("./Variable"); | ||
const Expression_1 = require("./Expression"); | ||
const Pattern_1 = require("./Pattern"); | ||
const dataFiltering_1 = require("./dataFiltering"); | ||
/** Create and manage an instance of the Polar runtime. */ | ||
@@ -49,4 +53,23 @@ class Polar { | ||
_Polar_rolesEnabled.set(this, void 0); | ||
function defaultEqual(a, b) { | ||
if (a && | ||
b && // good grief!! | ||
typeof a === typeof b && | ||
typeof a === 'object' && | ||
a.__proto__ === b.__proto__) { | ||
let check = new Map(); | ||
for (let x in a) { | ||
if (!defaultEqual(a[x], b[x])) | ||
return false; | ||
check.set(x, true); | ||
} | ||
for (let x in b) | ||
if (!check.get(x)) | ||
return false; | ||
return true; | ||
} | ||
return a == b; | ||
} | ||
__classPrivateFieldSet(this, _Polar_ffiPolar, new polar_wasm_api_1.Polar(), "f"); | ||
const equalityFn = opts.equalityFn || ((x, y) => x == y); | ||
const equalityFn = opts.equalityFn || defaultEqual; | ||
__classPrivateFieldSet(this, _Polar_host, new Host_1.Host(__classPrivateFieldGet(this, _Polar_ffiPolar, "f"), equalityFn), "f"); | ||
@@ -199,3 +222,3 @@ __classPrivateFieldSet(this, _Polar_rolesEnabled, false, "f"); | ||
*/ | ||
query(q) { | ||
query(q, bindings) { | ||
const host = Host_1.Host.clone(__classPrivateFieldGet(this, _Polar_host, "f")); | ||
@@ -211,5 +234,11 @@ let ffiQuery; | ||
this.processMessages(); | ||
return new Query_1.Query(ffiQuery, host).results; | ||
return new Query_1.Query(ffiQuery, host, bindings).results; | ||
} | ||
/** | ||
* Query for a Polar rule with bindings. | ||
*/ | ||
queryRuleWithBindings(name, bindings, ...args) { | ||
return this.query(new Predicate_1.Predicate(name, args), bindings); | ||
} | ||
/** | ||
* Query for a Polar rule. | ||
@@ -223,7 +252,14 @@ */ | ||
*/ | ||
registerClass(cls, alias) { | ||
registerClass(cls, alias, types, fetcher) { | ||
if (!helpers_1.isConstructor(cls)) | ||
throw new errors_1.InvalidConstructorError(cls); | ||
const name = __classPrivateFieldGet(this, _Polar_host, "f").cacheClass(cls, alias); | ||
this.registerConstant(cls, name); | ||
const clsName = __classPrivateFieldGet(this, _Polar_host, "f").cacheClass(cls, alias); | ||
this.registerConstant(cls, clsName); | ||
__classPrivateFieldGet(this, _Polar_host, "f").clsNames.set(cls, clsName); | ||
if (types != null) { | ||
__classPrivateFieldGet(this, _Polar_host, "f").types.set(clsName, types); | ||
} | ||
if (fetcher != null) { | ||
__classPrivateFieldGet(this, _Polar_host, "f").fetchers.set(clsName, fetcher); | ||
} | ||
} | ||
@@ -237,2 +273,34 @@ /** | ||
} | ||
/** | ||
* Returns all the resources the actor is allowed to perform some action on. | ||
*/ | ||
async getAllowedResources(actor, action, cls) { | ||
const resource = new Variable_1.Variable('resource'); | ||
const clsName = __classPrivateFieldGet(this, _Polar_host, "f").clsNames.get(cls); | ||
const constraint = new Expression_1.Expression('And', [ | ||
new Expression_1.Expression('Isa', [ | ||
resource, | ||
new Pattern_1.Pattern({ tag: clsName, fields: {} }), | ||
]), | ||
]); | ||
let bindings = new Map(); | ||
bindings.set('resource', constraint); | ||
let results = this.queryRuleWithBindings('allow', bindings, actor, action, resource); | ||
const queryResults = []; | ||
for await (const result of results) { | ||
queryResults.push(result); | ||
} | ||
let jsonResults = queryResults.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; | ||
}, {}), | ||
})); | ||
let resultsStr = JSON.stringify(jsonResults); | ||
let typesStr = dataFiltering_1.serializeTypes(__classPrivateFieldGet(this, _Polar_host, "f").types, __classPrivateFieldGet(this, _Polar_host, "f").clsNames); | ||
let plan = __classPrivateFieldGet(this, _Polar_ffiPolar, "f").buildFilterPlan(typesStr, resultsStr, 'resource', clsName); | ||
return await dataFiltering_1.filterData(__classPrivateFieldGet(this, _Polar_host, "f"), plan); | ||
} | ||
/** Start a REPL session. */ | ||
@@ -239,0 +307,0 @@ async repl(files) { |
@@ -12,3 +12,3 @@ import type { Query as FfiQuery } from './polar_wasm_api'; | ||
results: QueryResult; | ||
constructor(ffiQuery: FfiQuery, host: Host); | ||
constructor(ffiQuery: FfiQuery, host: Host, bindings?: Map<string, any>); | ||
/** | ||
@@ -19,2 +19,8 @@ * Process messages received from the Polar VM. | ||
*/ | ||
private bind; | ||
/** | ||
* Process messages received from the Polar VM. | ||
* | ||
* @internal | ||
*/ | ||
private processMessages; | ||
@@ -21,0 +27,0 @@ /** |
@@ -22,2 +22,3 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
const dataFiltering_1 = require("./dataFiltering"); | ||
function getLogLevelsFromEnv() { | ||
@@ -34,3 +35,3 @@ if (typeof (process === null || process === void 0 ? void 0 : process.env) === 'undefined') | ||
class Query { | ||
constructor(ffiQuery, host) { | ||
constructor(ffiQuery, host, bindings) { | ||
_Query_ffiQuery.set(this, void 0); | ||
@@ -43,2 +44,5 @@ _Query_calls.set(this, void 0); | ||
__classPrivateFieldSet(this, _Query_host, host, "f"); | ||
for (const k in bindings) { | ||
this.bind(k, bindings.get(k)); | ||
} | ||
this.results = this.start(); | ||
@@ -51,2 +55,10 @@ } | ||
*/ | ||
bind(name, value) { | ||
__classPrivateFieldGet(this, _Query_ffiQuery, "f").bind(name, JSON.stringify(__classPrivateFieldGet(this, _Query_host, "f").toPolar(value))); | ||
} | ||
/** | ||
* Process messages received from the Polar VM. | ||
* | ||
* @internal | ||
*/ | ||
processMessages() { | ||
@@ -106,12 +118,43 @@ while (true) { | ||
const receiver = await __classPrivateFieldGet(this, _Query_host, "f").toJs(instance); | ||
value = receiver[attr]; | ||
if (args !== undefined) { | ||
if (typeof value === 'function') { | ||
// If value is a function, call it with the provided args. | ||
const jsArgs = args.map(async (a) => await __classPrivateFieldGet(this, _Query_host, "f").toJs(a)); | ||
value = receiver[attr](...(await Promise.all(jsArgs))); | ||
// Check if it's a relationship | ||
if (receiver != undefined) { | ||
const clsName = __classPrivateFieldGet(this, _Query_host, "f").clsNames.get(receiver.constructor); | ||
if (clsName != null) { | ||
const typedef = __classPrivateFieldGet(this, _Query_host, "f").types.get(clsName); | ||
if (typedef != null) { | ||
const fieldType = typedef.get(attr); | ||
if (fieldType != null) { | ||
if (fieldType instanceof dataFiltering_1.Relationship) { | ||
// Use the fetcher for the other type to traverse | ||
// the relationship. | ||
const otherClsFetcher = __classPrivateFieldGet(this, _Query_host, "f").fetchers.get(fieldType.otherType); | ||
const constraint = new dataFiltering_1.Constraint('Eq', fieldType.otherField, receiver[fieldType.myField]); | ||
const constraints = [constraint]; | ||
let results = otherClsFetcher(constraints); | ||
results = await Promise.resolve(results); | ||
if (fieldType.kind == 'parent') { | ||
if (results.length != 1) | ||
throw new Error('Wrong number of parents: ' + results.length); | ||
value = results[0]; | ||
} | ||
else { | ||
value = results; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
// Error on attempt to call non-function. | ||
throw new errors_1.InvalidCallError(receiver, attr); | ||
} | ||
if (value == undefined) { | ||
value = receiver[attr]; | ||
if (args !== undefined) { | ||
if (typeof value === 'function') { | ||
// If value is a function, call it with the provided args. | ||
const jsArgs = args.map(async (a) => await __classPrivateFieldGet(this, _Query_host, "f").toJs(a)); | ||
value = receiver[attr](...(await Promise.all(jsArgs))); | ||
} | ||
else { | ||
// Error on attempt to call non-function. | ||
throw new errors_1.InvalidCallError(receiver, attr); | ||
} | ||
} | ||
@@ -205,2 +248,8 @@ } | ||
} | ||
case types_1.QueryEventKind.ExternalIsSubclass: { | ||
const { leftTag, rightTag, callId } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _Query_host, "f").isSubclass(leftTag, rightTag); | ||
this.questionResult(answer, callId); | ||
break; | ||
} | ||
case types_1.QueryEventKind.ExternalOp: { | ||
@@ -218,2 +267,8 @@ const { args, callId, operator } = event.data; | ||
} | ||
case types_1.QueryEventKind.ExternalIsaWithPath: { | ||
const { baseTag, path, classTag, callId } = event.data; | ||
const answer = await __classPrivateFieldGet(this, _Query_host, "f").isaWithPath(baseTag, path, classTag); | ||
this.questionResult(answer, callId); | ||
break; | ||
} | ||
case types_1.QueryEventKind.NextExternal: { | ||
@@ -220,0 +275,0 @@ const { callId, iterable } = event.data; |
@@ -300,2 +300,25 @@ /** | ||
/** | ||
* 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: string[]; | ||
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. | ||
@@ -379,7 +402,9 @@ * | ||
ExternalIsa = 3, | ||
ExternalIsSubspecializer = 4, | ||
ExternalOp = 5, | ||
MakeExternal = 6, | ||
NextExternal = 7, | ||
Result = 8 | ||
ExternalIsaWithPath = 4, | ||
ExternalIsSubspecializer = 5, | ||
ExternalIsSubclass = 6, | ||
ExternalOp = 7, | ||
MakeExternal = 8, | ||
NextExternal = 9, | ||
Result = 10 | ||
} | ||
@@ -393,3 +418,3 @@ /** | ||
kind: QueryEventKind; | ||
data?: Debug | ExternalCall | ExternalIsa | ExternalIsSubspecializer | ExternalOp | MakeExternal | NextExternal | Result; | ||
data?: Debug | ExternalCall | ExternalIsa | ExternalIsaWithPath | ExternalIsSubspecializer | ExternalIsSubclass | ExternalOp | MakeExternal | NextExternal | Result; | ||
} | ||
@@ -396,0 +421,0 @@ /** |
@@ -197,7 +197,9 @@ "use strict"; | ||
QueryEventKind[QueryEventKind["ExternalIsa"] = 3] = "ExternalIsa"; | ||
QueryEventKind[QueryEventKind["ExternalIsSubspecializer"] = 4] = "ExternalIsSubspecializer"; | ||
QueryEventKind[QueryEventKind["ExternalOp"] = 5] = "ExternalOp"; | ||
QueryEventKind[QueryEventKind["MakeExternal"] = 6] = "MakeExternal"; | ||
QueryEventKind[QueryEventKind["NextExternal"] = 7] = "NextExternal"; | ||
QueryEventKind[QueryEventKind["Result"] = 8] = "Result"; | ||
QueryEventKind[QueryEventKind["ExternalIsaWithPath"] = 4] = "ExternalIsaWithPath"; | ||
QueryEventKind[QueryEventKind["ExternalIsSubspecializer"] = 5] = "ExternalIsSubspecializer"; | ||
QueryEventKind[QueryEventKind["ExternalIsSubclass"] = 6] = "ExternalIsSubclass"; | ||
QueryEventKind[QueryEventKind["ExternalOp"] = 7] = "ExternalOp"; | ||
QueryEventKind[QueryEventKind["MakeExternal"] = 8] = "MakeExternal"; | ||
QueryEventKind[QueryEventKind["NextExternal"] = 9] = "NextExternal"; | ||
QueryEventKind[QueryEventKind["Result"] = 10] = "Result"; | ||
})(QueryEventKind = exports.QueryEventKind || (exports.QueryEventKind = {})); | ||
@@ -204,0 +206,0 @@ /** |
{ | ||
"name": "oso", | ||
"version": "0.15.0", | ||
"version": "0.20.0-beta", | ||
"description": "oso authorization library.", | ||
@@ -42,3 +42,3 @@ "bin": "bin/repl.js", | ||
"@types/jest": "^26.0.9", | ||
"@types/node": "^15.0.0", | ||
"@types/node": "^15.14.7", | ||
"chokidar-cli": "^2.1.0", | ||
@@ -48,2 +48,4 @@ "gts": "^3.1.0", | ||
"live-server": "^1.2.1", | ||
"reflect-metadata": "^0.1.13", | ||
"sqlite3": "^5.0.2", | ||
"temp-write": "^4.0.0", | ||
@@ -53,4 +55,5 @@ "ts-jest": "^27.0.3", | ||
"typedoc": "^0.21.0", | ||
"typeorm": "^0.2.37", | ||
"typescript": "^4.3.4" | ||
} | ||
} | ||
} |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
3121760
60
4141
14
9