Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplemented using Typescript #5

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
68e1742
build: use yarn
vsimko Oct 19, 2018
76aa5c6
test: add blazegraph docker image for testing
vsimko Oct 19, 2018
afccd28
dev: add scripts to control the testing docker container
vsimko Oct 19, 2018
e65e80b
dev: support for unit testing using jest
vsimko Oct 19, 2018
985f551
fix: use `axios` instead of `request`
vsimko Oct 19, 2018
4972a6a
feat: new SPARQL Template literal
vsimko Oct 19, 2018
e47b414
feat: new sparql updater module writtein in FP-style
vsimko Oct 19, 2018
9ff48e8
chore: remove deprecated sparqlUpdate QueryFactory
vsimko Oct 19, 2018
bf4f657
fix: convert validation functions to lambdas
vsimko Oct 19, 2018
f8090f1
feat: new API in functional programming style
vsimko Oct 19, 2018
c2cf766
test: test of the new FP-style API
vsimko Oct 19, 2018
adaa57f
doc: update README with examples
vsimko Oct 19, 2018
ca90403
doc: update changelog
vsimko Oct 19, 2018
01d8522
chore: use mocha for testing and eslint with double quotes rule
vsimko Dec 6, 2018
4c854c8
fix: I used ts-check in vscode IDE to find some bugs
vsimko Dec 6, 2018
71846d8
chore(release): 1.0.0
vsimko Dec 7, 2018
89a894a
chore(release): 1.0.0
vsimko Dec 7, 2018
52257ec
feat: redesigned the API, added type annotations for easier developme…
vsimko Dec 8, 2018
ee349f6
chore(release): 2.0.0
vsimko Dec 8, 2018
d05c60a
fix: deleteQuads repsponse
vsimko Dec 8, 2018
5f56a89
docs: udpate README.md
vsimko Dec 8, 2018
2a25873
chore(release): 2.0.1
vsimko Dec 8, 2018
4350744
chore(release): 2.0.2
vsimko Dec 9, 2018
341df64
fix: type TemplateStringsArray instead of string[]
vsimko Dec 9, 2018
cc254c4
chore(release): 2.0.3
vsimko Dec 9, 2018
3a55b31
fixed security dependecy for axios
Jun 4, 2019
ce9fc56
chore: update deps and fix some ts-check errors
vsimko Nov 20, 2019
6284e8d
chore(release): 2.0.5
vsimko Nov 20, 2019
10ed4fd
Update package dependencies
ipa-bak May 6, 2021
e720b73
add .idea folder to gitignore
vsimko Dec 27, 2021
77d906a
upgraded docker container used for testing
vsimko Dec 27, 2021
a930db7
major rewrite using typescript
vsimko Dec 27, 2021
168936b
update tsconfig.json
vsimko Dec 27, 2021
1bb516e
add generated js files to git
vsimko Dec 27, 2021
6d7d64c
generate dist with comments
vsimko Dec 27, 2021
48ada0f
bump version
vsimko Dec 27, 2021
4e819aa
chore(release): 3.0.3
vsimko Dec 27, 2021
592b357
split tsconfig.json for dev and build
vsimko Dec 27, 2021
6ca9bcb
chore(release): 3.0.4
vsimko Dec 27, 2021
5578aa4
chore(release): 3.0.5
vsimko Dec 27, 2021
8c21b6a
added immer as a dependency
vsimko Dec 28, 2021
c43c023
refactor: remove "compose" from SPARQL function
vsimko Dec 28, 2021
4c5fd16
refactor: split zod types into multiple files
vsimko Dec 28, 2021
b80b9b5
chore(release): 3.0.6
vsimko Dec 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
{
"extends": "nelson"
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"mocha": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
]
},
"ignorePatterns": [
"node_modules",
"build"
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
gitignore
.vscode
.idea

# Logs
logs
Expand Down
99 changes: 99 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,104 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [3.0.6](https://github.com/nelson-ai/blazegraph-js/compare/v3.0.5...v3.0.6) (2021-12-28)

### [3.0.5](https://github.com/nelson-ai/blazegraph-js/compare/v3.0.4...v3.0.5) (2021-12-27)

### [3.0.4](https://github.com/nelson-ai/blazegraph-js/compare/v3.0.3...v3.0.4) (2021-12-27)

### [3.0.3](https://github.com/nelson-ai/blazegraph-js/compare/v2.0.5...v3.0.3) (2021-12-27)

### [2.0.7](https://github.com/nelson-ai/blazegraph-js/compare/v2.0.4...v2.0.7) (2021-05-06)

### [2.0.6](https://github.com/nelson-ai/blazegraph-js/compare/v2.0.4...v2.0.6) (2021-05-06)

### [2.0.5](https://github.com/nelson-ai/blazegraph-js/compare/v2.0.4...v2.0.5) (2019-11-20)

<a name="2.0.3"></a>
## [2.0.3](https://github.com/nelson-ai/blazegraph-js/compare/v2.0.2...v2.0.3) (2018-12-09)


### Bug Fixes

* type TemplateStringsArray instead of string[] ([341df64](https://github.com/nelson-ai/blazegraph-js/commit/341df64))



<a name="2.0.2"></a>
## [2.0.2](https://github.com/nelson-ai/blazegraph-js/compare/v2.0.1...v2.0.2) (2018-12-09)



<a name="2.0.1"></a>
## [2.0.1](https://github.com/nelson-ai/blazegraph-js/compare/v2.0.0...v2.0.1) (2018-12-08)


### Bug Fixes

* deleteQuads repsponse ([d05c60a](https://github.com/nelson-ai/blazegraph-js/commit/d05c60a))



<a name="2.0.0"></a>
# [2.0.0](https://github.com/nelson-ai/blazegraph-js/compare/v1.0.0...v2.0.0) (2018-12-08)


### Features

* redesigned the API, added type annotations for easier development (e.g. in vscode) ([52257ec](https://github.com/nelson-ai/blazegraph-js/commit/52257ec))


### BREAKING CHANGES

* - all functions are now provided through the prepareBlaze factory
the function parametrized everything with the provided config structure
- SELECT, UPDATE, DELETE are literal templates



<a name="1.0.0"></a>
# [1.0.0](https://github.com/nelson-ai/blazegraph-js/compare/v0.2.0...v1.0.0) (2018-12-07)


### Bug Fixes

* convert validation functions to lambdas ([bf4f657](https://github.com/nelson-ai/blazegraph-js/commit/bf4f657))
* I used ts-check in vscode IDE to find some bugs ([4c854c8](https://github.com/nelson-ai/blazegraph-js/commit/4c854c8))
* missing variable blazename ([5bc93d8](https://github.com/nelson-ai/blazegraph-js/commit/5bc93d8))
* use `axios` instead of `request` ([985f551](https://github.com/nelson-ai/blazegraph-js/commit/985f551))


### Features

* new API in functional programming style ([f8090f1](https://github.com/nelson-ai/blazegraph-js/commit/f8090f1))
* new SPARQL Template literal ([4972a6a](https://github.com/nelson-ai/blazegraph-js/commit/4972a6a))
* new sparql updater module writtein in FP-style ([e47b414](https://github.com/nelson-ai/blazegraph-js/commit/e47b414))


### BREAKING CHANGES

* the url config now accepts `hostname`
instead of `host`.
* completely different API which uses template literals
* replaces the original sparqlUpdateQueryFactory



# Changelog

## 0.3.0

**Breaking changes:**
- new, functional style API (with the help of `ramda`)
- using `axios` instead of `request`
- deprecated `SparqlUpdateQuery.js` and replaced with functional-style API in `src/updater.js`

**New features:**
- unit tests including a docker-compose.yml
- using `SELECT`, `UPDATE`, `DELETE` template literals

## 0.2.0

**Breaking changes:**
Expand Down
50 changes: 35 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
# Blazegraph JavaScript API

[![npm version](https://badge.fury.io/js/blazegraph.svg)](https://www.npmjs.com/package/blazegraph)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](#contributing)
# Blazegraph Javascript API (Written in Typescript)

[Blazegraph](https://www.blazegraph.com/) JavaScript API.
This version has been completely rewritten and the new API is still evolving.

## Installation

`npm install blazegraph --save`
`yarn add https://github.com/seronet-project/blazegraph-js`

## Usage

Many (undocumented yet) methods are available. Have a look at the source for more info.

### preparation

```js
const db = require('blazegraph')({
host: 'localhost',
const { prepareBlaze } = require("blazegraph");
const { SELECT, UPDATE } = prepareBlaze({
host: "localhost",
port: 9999,
namespace: 'kb', // Those are the default values, passing no params yields the same result
namespace: "kb" // Those are the default values, passing no params yields the same result
});
```

db.readQuads({
predicate: '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>',
object: '<http://example.com/Person>',
})
.then(quads => {
console.log(quads); // An array of objects of the shape { subject, predicate, object, graph }
});
### sparql query - output written to the console

```js
// simple async example
const results = await SELECT`select * { ?s ?p ?o } limit 10`;
console.log(results);
```

### sparql query - asynchronous pipeline with ramda

```js
const { pipeP, pluck } = require("ramda");
await pipeP(
() => SELECT`select * {?s ?p ?o}`, // 1. query
pluck("p"), // 2. extract only properties
pluck("value"), // 3. extract value from each property
console.log // 4. write results to console
)();
```

## Note
Expand All @@ -38,6 +51,13 @@ The current API is quite specific to Nelson, but feel free to PR breaking change

Yes, thank you. Please lint, ~~update/write tests~~ and add your name to the package.json file before you PR.

## Original version available here:

[![npm version](https://badge.fury.io/js/blazegraph.svg)](https://www.npmjs.com/package/blazegraph)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](#contributing)

`npm install blazegraph --save`

## License

Blazegraph-js is released under the MIT license.
Expand Down
56 changes: 56 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { BlazegraphConfig } from "./types";
export declare const prepareBlaze: (userConfig?: Partial<BlazegraphConfig>) => {
config: {
port: number;
hostname: string;
namespace: string;
blazename: string;
};
blazeUri: string;
UPDATE: (str: TemplateStringsArray, ...vars: string[]) => Promise<import("./middleware").CommitStats>;
DELETE: (str: TemplateStringsArray, ...vars: string[]) => Promise<Record<string, {
type: string;
value: string;
}>[]>;
/** Use as: SELECT`your sparql query` = querySparql without inferred triples. */
SELECT: (str: TemplateStringsArray, ...vars: string[]) => Promise<Record<string, {
type: string;
value: string;
}>[]>;
/** Use as: SELECT`your sparql query` = querySparql with inferred triples. */
SELECTWI: (str: TemplateStringsArray, ...vars: string[]) => Promise<Record<string, {
type: string;
value: string;
}>[]>;
deleteSparql: (query: string) => Promise<Record<string, {
type: string;
value: string;
}>[]>;
querySparql: (query: string, withInferred?: boolean) => Promise<Record<string, {
type: string;
value: string;
}>[]>;
updateSparql: (query: string) => Promise<import("./middleware").CommitStats>;
createQuads: (input: unknown) => Promise<string>;
deleteQuads: (input: Partial<{
object: string | import("n3").Literal;
subject: string;
predicate: string;
graph: string;
}>) => Promise<string>;
readQuads: (input: {
object?: string | import("n3").Literal | undefined;
subject?: string | undefined;
predicate?: string | undefined;
graph?: string | undefined;
graphs?: string[] | undefined;
}, withInferred?: boolean) => Promise<import("n3").Quad[]>;
updateQuad: (input: unknown) => Promise<string>;
checkPatternExistence: (input: {
object?: string | import("n3").Literal | undefined;
subject?: string | undefined;
predicate?: string | undefined;
graph?: string | undefined;
graphs?: string[] | undefined;
}, withInferred?: boolean) => Promise<boolean>;
};
42 changes: 42 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareBlaze = void 0;
const ramda_1 = require("ramda");
const sparql_1 = require("./sparql");
const middleware_1 = require("./middleware");
const types_1 = require("./types");
const defaultConfig = {
hostname: "localhost",
port: 9999,
namespace: "kb",
blazename: "bigdata" // it was 'blazegraph' in older versions
};
/** Helper function that wraps other functions as template literals. */
const tmpl = (fn) => (str, ...vars) => {
const sparql = (0, sparql_1.SPARQL)(str, ...vars);
return fn(sparql);
};
const prepareBlaze = (userConfig = {}) => {
const config = types_1.ZBlazegraphConfig.parse((0, ramda_1.merge)(defaultConfig, userConfig));
const { hostname, port, blazename, namespace } = config;
const blazeUri = `http://${hostname}:${port}/${blazename}/namespace/${namespace}/sparql`;
return {
config,
blazeUri,
UPDATE: tmpl((0, middleware_1.updateSparql)(blazeUri)),
DELETE: tmpl((0, middleware_1.deleteSparql)(blazeUri)),
/** Use as: SELECT`your sparql query` = querySparql without inferred triples. */
SELECT: tmpl((0, middleware_1.querySparql)(blazeUri)),
/** Use as: SELECT`your sparql query` = querySparql with inferred triples. */
SELECTWI: tmpl(str => (0, middleware_1.querySparql)(blazeUri)(str, true)),
deleteSparql: (0, middleware_1.deleteSparql)(blazeUri),
querySparql: (0, middleware_1.querySparql)(blazeUri),
updateSparql: (0, middleware_1.updateSparql)(blazeUri),
createQuads: (0, middleware_1.createQuads)(blazeUri),
deleteQuads: (0, middleware_1.deleteQuads)(blazeUri),
readQuads: (0, middleware_1.readQuads)(blazeUri),
updateQuad: (0, middleware_1.updateQuad)(blazeUri),
checkPatternExistence: (0, middleware_1.checkPatternExistence)(blazeUri)
};
};
exports.prepareBlaze = prepareBlaze;
35 changes: 35 additions & 0 deletions dist/middleware.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Quad } from "n3";
import { BindingResult, PartialGraphPattern, QuadPattern, UpdateQuadPattern } from "./types";
/**
* Perform a SPARQL query
* NOTE: this does not allow to perform a SPARQL update query
*/
export declare const querySparql: (blazeUrl: string) => (query: string, withInferred?: boolean) => Promise<BindingResult[]>;
export interface CommitStats {
query: Record<string, string>;
update: Record<string, string>;
}
/**
* Perform a SPARQL update, insert or delete.
* NOTE: this does not allow to perform any other SPARQL query.
* TODO: parse result as HTML and extract more parameters
*/
export declare const updateSparql: (blazeUrl: string) => (query: string) => Promise<CommitStats>;
/**
* Delete statements using a SPARQL CONSTRUCT or DESCRIBE query.
* NOTE: this does not allow to perform any other SPARQL query.
* TODO: this function has never been tested
*/
export declare const deleteSparql: (blazeUrl: string) => (query: string) => Promise<BindingResult[]>;
/**
* Returns true is some quads match a pattern.
*/
export declare const checkPatternExistence: (blazeUrl: string) => (input: PartialGraphPattern, withInferred?: boolean) => Promise<boolean>;
/** Read all quads matching a pattern. */
export declare const readQuads: (blazeUrl: string) => (input: PartialGraphPattern, withInferred?: boolean) => Promise<Quad[]>;
/** Create one or more quads. */
export declare const createQuads: (blazeUrl: string) => (input: QuadPattern | unknown | (QuadPattern | unknown)[]) => Promise<string>;
/** Update a quad knowing its old statement. */
export declare const updateQuad: (blazeUrl: string) => (input: UpdateQuadPattern | unknown) => Promise<string>;
/** Delete all quads matching a pattern. */
export declare const deleteQuads: (blazeUrl: string) => (input: Partial<QuadPattern>) => Promise<string>;
Loading