@comunica/actor-abstract-bindings-hash
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -13,22 +13,2 @@ import { ActorQueryOperationTypedMediated, Bindings, IActorQueryOperationOutputBindings } from "@comunica/bus-query-operation"; | ||
/** | ||
* Check if the given hash algorithm (such as sha1) exists. | ||
* @param {string} hashAlgorithm A hash algorithm. | ||
* @return {boolean} If it exists. | ||
*/ | ||
static doesHashAlgorithmExist(hashAlgorithm: string): boolean; | ||
/** | ||
* Check if the given digest (such as base64) algorithm exists. | ||
* @param {string} digestAlgorithm A digest algorithm. | ||
* @return {boolean} If it exists. | ||
*/ | ||
static doesDigestAlgorithmExist(digestAlgorithm: string): boolean; | ||
/** | ||
* Create a string-based hash of the given object. | ||
* @param {string} hashAlgorithm A hash algorithm. | ||
* @param {string} digestAlgorithm A digest algorithm. | ||
* @param object The object to hash. | ||
* @return {string} The object's hash. | ||
*/ | ||
static hash(hashAlgorithm: string, digestAlgorithm: string, object: any): string; | ||
/** | ||
* Create a new filter function for the given hash algorithm and digest algorithm. | ||
@@ -35,0 +15,0 @@ * The given filter depends on the Algebraic operation |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const bus_query_operation_1 = require("@comunica/bus-query-operation"); | ||
const crypto_1 = require("crypto"); | ||
const AbstractFilterHash_1 = require("./AbstractFilterHash"); | ||
/** | ||
@@ -11,37 +11,9 @@ * A comunica Hash Query Operation Actor. | ||
super(args, operator); | ||
if (!AbstractBindingHash.doesHashAlgorithmExist(this.hashAlgorithm)) { | ||
if (!AbstractFilterHash_1.AbstractFilterHash.doesHashAlgorithmExist(this.hashAlgorithm)) { | ||
throw new Error("The given hash algorithm is not present in this version of Node: " + this.hashAlgorithm); | ||
} | ||
if (!AbstractBindingHash.doesDigestAlgorithmExist(this.digestAlgorithm)) { | ||
if (!AbstractFilterHash_1.AbstractFilterHash.doesDigestAlgorithmExist(this.digestAlgorithm)) { | ||
throw new Error("The given digest algorithm is not present in this version of Node: " + this.digestAlgorithm); | ||
} | ||
} | ||
/** | ||
* Check if the given hash algorithm (such as sha1) exists. | ||
* @param {string} hashAlgorithm A hash algorithm. | ||
* @return {boolean} If it exists. | ||
*/ | ||
static doesHashAlgorithmExist(hashAlgorithm) { | ||
return crypto_1.getHashes().indexOf(hashAlgorithm) >= 0; | ||
} | ||
/** | ||
* Check if the given digest (such as base64) algorithm exists. | ||
* @param {string} digestAlgorithm A digest algorithm. | ||
* @return {boolean} If it exists. | ||
*/ | ||
static doesDigestAlgorithmExist(digestAlgorithm) { | ||
return ["latin1", "hex", "base64"].indexOf(digestAlgorithm) >= 0; | ||
} | ||
/** | ||
* Create a string-based hash of the given object. | ||
* @param {string} hashAlgorithm A hash algorithm. | ||
* @param {string} digestAlgorithm A digest algorithm. | ||
* @param object The object to hash. | ||
* @return {string} The object's hash. | ||
*/ | ||
static hash(hashAlgorithm, digestAlgorithm, object) { | ||
const hash = crypto_1.createHash(hashAlgorithm); | ||
hash.update(require('json-stable-stringify')(object)); | ||
return hash.digest(digestAlgorithm); | ||
} | ||
async testOperation(pattern, context) { | ||
@@ -48,0 +20,0 @@ return true; |
@@ -1,2 +0,2 @@ | ||
import { ActorQueryOperationTypedMediated, IActorQueryOperationOutputBindings, IActorQueryOperationTypedMediatedArgs } from "@comunica/bus-query-operation"; | ||
import { ActorQueryOperationTypedMediated, Bindings, IActorQueryOperationOutputBindings, IActorQueryOperationTypedMediatedArgs } from "@comunica/bus-query-operation"; | ||
import { ActionContext, IActorTest } from "@comunica/core"; | ||
@@ -27,6 +27,6 @@ import { Algebra } from "sparqlalgebrajs"; | ||
* @param {string} digestAlgorithm A digest algorithm. | ||
* @param object The object to hash. | ||
* @param bindings The bindings to hash. | ||
* @return {string} The object's hash. | ||
*/ | ||
static hash(hashAlgorithm: string, digestAlgorithm: string, object: any): string; | ||
static hash(hashAlgorithm: string, digestAlgorithm: string, bindings: Bindings): string; | ||
testOperation(pattern: T, context: ActionContext): Promise<IActorTest>; | ||
@@ -33,0 +33,0 @@ abstract runOperation(pattern: T, context: ActionContext): Promise<IActorQueryOperationOutputBindings>; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const crypto_1 = require("crypto"); | ||
const rdf_string_1 = require("rdf-string"); | ||
/** | ||
@@ -39,8 +40,8 @@ * A comunica Hash Query Operation Actor. | ||
* @param {string} digestAlgorithm A digest algorithm. | ||
* @param object The object to hash. | ||
* @param bindings The bindings to hash. | ||
* @return {string} The object's hash. | ||
*/ | ||
static hash(hashAlgorithm, digestAlgorithm, object) { | ||
static hash(hashAlgorithm, digestAlgorithm, bindings) { | ||
const hash = crypto_1.createHash(hashAlgorithm); | ||
hash.update(require('json-stable-stringify')(object)); | ||
hash.update(require('json-stable-stringify')(bindings.map(rdf_string_1.termToString))); | ||
return hash.digest(digestAlgorithm); | ||
@@ -47,0 +48,0 @@ } |
{ | ||
"name": "@comunica/actor-abstract-bindings-hash", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "An abstract actor for handling binding query operators", | ||
@@ -43,4 +43,4 @@ "lsd:module": "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-abstract-bindings-hash", | ||
"devDependencies": { | ||
"@comunica/bus-query-operation": "^1.8.0", | ||
"@comunica/core": "^1.8.0" | ||
"@comunica/bus-query-operation": "^1.9.0", | ||
"@comunica/core": "^1.9.0" | ||
}, | ||
@@ -71,5 +71,6 @@ "jest": { | ||
"dependencies": { | ||
"json-stable-stringify": "^1.0.1" | ||
"json-stable-stringify": "^1.0.1", | ||
"rdf-string": "^1.3.1" | ||
}, | ||
"gitHead": "7e65817dad65cf10c032f7548b37cedf3055eea1" | ||
"gitHead": "2e0cba815fd65d5660f15c96ffc734f9099d8b6a" | ||
} |
14432
4
146
+ Addedrdf-string@^1.3.1