Skip to content

Commit fec5a51

Browse files
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents b4ff0c5 + a50fdd7 commit fec5a51

File tree

5 files changed

+309
-38
lines changed

5 files changed

+309
-38
lines changed

Readme.md

Lines changed: 254 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ terminus-client
88
Promise based terminus client for the browser and node.js
99

1010
## Requirements
11-
- [TerminusDB](https://github.com/terminusdb/terminusdb)
11+
- [TerminusDB](https://github.com/terminusdb/terminus-server)
1212
- [NodeJS 8.1.4+](https://nodejs.org/en/)
1313

1414
## Installation
1515

16-
This is a Node.js module available through the npm registry.
16+
Terminus Client can be used as either a Node.js module available through the npm registry, or directly included in web-sites by including the script tag below.
1717

18+
### NPM Module
1819
Before installing, download and install Node.js. Node.js 0.10 or higher is required.
1920

2021
Installation is done using the npm install command:
@@ -25,25 +26,33 @@ Using npm:
2526
$ npm install --save @terminusdb/terminus-client
2627
```
2728

29+
### Minified Script
30+
2831
Using cdn:
2932

3033
```html
3134
<script src="https://unpkg.com/@terminusdb/terminus-client/dist/terminus-client.min.js"></script>
3235
```
3336

34-
## Docs & Community
37+
Downloading:
38+
39+
Download the terminus-client.min.js file from the /dist directory and save it to your location of choice, then:
40+
41+
```html
42+
<script src="http://my.saved.location/terminus-client.min.js"></script>
43+
```
3544

3645
## Usage
3746

3847
```javascript
3948
//
4049
const TerminusClient = require('@terminusdb/terminus-client');
4150

42-
//Create a new instance of terminus client
51+
//Create a new instance of terminusDB client
4352
const client = new TerminusClient.WOQLClient();
4453

45-
//Connect to a Terminus server at the given URI with an API key
46-
client.connect("http://localhost/", 'secret').
54+
//Connect to a TerminusDB server at the given URI with an API key
55+
client.connect("http://localhost:6363/", 'myKey').
4756
.then(function (response) {
4857
// handle success
4958
console.log(response);
@@ -60,7 +69,7 @@ client.connect("http://localhost/", 'secret').
6069
//use async/await.
6170
async function getCapabilities() {
6271
try {
63-
const response = await client.connect("http://localhost/", 'secret');
72+
const response = await client.connect("http://localhost:6363/", 'myKey');
6473
console.log(response);
6574
} catch (err) {
6675
console.error(err);
@@ -89,54 +98,267 @@ const client = new TerminusClient.WOQLClient({
8998

9099
## API
91100

92-
### `createDatabase([dburl:String, details:Object, key:String]):Object`
93-
Create a new terminusDB database in the current terminusDB server
101+
##### `createDatabase(dburl:String, details:Object, key:String):Promise`
102+
Create a new terminusDB database
94103

95104
```js
96-
var currentTerminusServerUrl=client.connectionConfig.dbURL();
97105

98-
var details={
99-
"@context":{
106+
107+
var details={
108+
"@context":{
100109
"rdfs":"http://www.w3.org/2000/01/rdf-schema#",
101-
"terminus":"https://datachemist.net/ontology/terminus#"
102-
},
103-
"@type":"terminus:Database",
104-
"rdfs:label":{
105-
"@language":"en",
106-
"@value":"test 01"
110+
"terminus":"http://terminusdb.com/schema/terminus#",
111+
"_":"http://localhost:6363/myFirstTerminusDB/"
107112
},
108-
"rdfs:comment":{
109-
"@language":"en",
110-
"@value":"description"
113+
"terminus:document":{
114+
"@type":"terminus:Database",
115+
"rdfs:label":{
116+
"@language":"en",
117+
"@value":"new db tests"
118+
},
119+
"rdfs:comment":{
120+
"@language":"en",
121+
"@value":"new db description"
122+
},
123+
"terminus:allow_origin":{
124+
"@type":"xsd:string",
125+
"@value":"*"
126+
},
127+
"@id":"http://localhost:6363/myFirstTerminusDB"
111128
},
112-
"terminus:allow_origin":{
113-
"@type":"xsd:string",
114-
"@value":"*"
115-
}
129+
"@type":"terminus:APIUpdate"
116130
}
117131

132+
//Create a new Database in the current terminusDB server using the terminusDB server Api key
133+
//dburl is the new Database Id
134+
135+
var currentTerminusDBServerUrl=client.connectionConfig.dbURL();
136+
137+
client.createDatabase("myFirstTerminusDB",details);
138+
139+
or
118140

119-
client.createDatabase("newD",details,'root');
141+
//dburl is a full new TerminusDB url
142+
143+
client.createDatabase("http://localhost:6363/myFirstTerminusDB",details,'mykey');
120144

121145
...
122146

123147
```
124148

125-
### `deleteDatabase():{[dbUrl:string]}`
149+
##### `deleteDatabase(dbUrl:String):Promise`
126150
For delete a terminusDB
127151

128152
```js
129-
//if authorized you can delete a terminusDB in the server myTerminusServer
130-
client.deleteDatabase("http://myTerminusServer/dbID");
153+
//if authorized you can delete a terminusDB in the a terminusDB server by full URL and Api key
154+
client.deleteDatabase("http://localhost:6363/myFirstTerminusDB",'mykey');
131155

132156
or
133157

134-
//you can delete a database in the current seleted server
135-
client.deleteDatabase("dbID");
158+
//you can delete a terminusDB in the current terminusDB server
159+
client.deleteDatabase("myFirstTerminusDB");
160+
...
161+
162+
```
163+
164+
##### `getSchema(schurl:String, opts:Object):Promise`
165+
For get a terminusDB schema
166+
167+
```js
168+
169+
//opts.terminus:encoding defines which format is requested
170+
//(*terminus:jsonld / terminus:turtle)
171+
//opts.terminus:user_key is an optional API key
172+
173+
const opts={terminus:encoding: "terminus:turtle",
174+
terminus:user_key: "root"}
175+
176+
//Retrieves the schema of the specified TerminusDB database by full Url
177+
client.getSchema("http://localhost:6363/myFirstTerminusDB/schema",opts);
178+
179+
or
180+
181+
const opts={terminus:encoding: "terminus:turtle"}
182+
183+
184+
//Retrieves the schema of the specified database by Id in the current server
185+
client.getSchema("myFirstTerminusDB",opts).then((response)=>{
186+
console.log("response")
187+
}).catch((err)=>{
188+
console.log(err);
189+
});
190+
...
191+
192+
```
193+
194+
195+
##### `updateSchema(schurl:String, doc:String, opts:Object):Promise`
196+
For Update a terminusDB schema
197+
schurl TerminusDB full URL or a valid TerminusDB Id or omitted
198+
doc is OWL schema String
199+
200+
For stating with an OWL schema go to [https://terminusdb.com/docs/](https://terminusdb.com/docs/)
201+
202+
In the documentation pages you'll find an example of an OWL schema
203+
Go to Quick Start > My First Knowledge Graph
204+
205+
```js
206+
207+
//OWL Schema
208+
const doc="@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.........."
209+
210+
const opts={terminus:encoding: "terminus:turtle"}
211+
212+
client.updateSchema('myFirstTerminusDB',doc,opts).then((response)=>{
213+
console.log(response)
214+
}).catch((err)=>{
215+
console.log(err)
216+
});
217+
136218
...
137219

138220
```
139221

222+
##### `createDocument(docurl:String, doc:Object, opts:Object):Promise`
223+
Creates a new document in the specified TerminusDB database
224+
225+
docurl TerminusDB document full URL or a valid TerminusDB document Id or omitted
226+
227+
doc is a document Object
228+
229+
```js
230+
231+
//Object
232+
const doc={
233+
"@context":{
234+
"doc":"http://localhost:6363/myFirstTerminusDB/document/",
235+
"owl":"http://www.w3.org/2002/07/owl#",
236+
"rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
237+
"rdfs":"http://www.w3.org/2000/01/rdf-schema#",
238+
"scm":"http://localhost:6363/myFirstTerminusDB/schema#",
239+
"tbs":"http://terminusdb.com/schema/tbs#",
240+
"tcs":"http://terminusdb.com/schema/tcs#",
241+
"terminus":"http://terminusdb.com/schema/terminus#",
242+
"vio":"http://terminusdb.com/schema/vio#",
243+
"xdd":"http://terminusdb.com/schema/xdd#",
244+
"xsd":"http://www.w3.org/2001/XMLSchema#",
245+
"_":"http://localhost:6363/myFirstTerminusDB/document/Rose/"
246+
},
247+
"terminus:document":{
248+
"tcs:member_of":[
249+
{
250+
"@id":"doc:yoga"
251+
}
252+
],
253+
"tcs:friend":[
254+
{
255+
"@id":"doc:Jane"
256+
}
257+
],
258+
"tcs:date_of_birth":[
259+
{
260+
"@value":"1976-05-12",
261+
"@type":"xsd:date"
262+
}
263+
],
264+
"rdfs:label":[
265+
{
266+
"@value":"Rose",
267+
"@type":"xsd:string"
268+
}
269+
],
270+
"rdfs:comment":[
271+
{
272+
"@value":"Steve is a person who is a member of Yoga group and are friends with Jane\n",
273+
"@type":"xsd:string"
274+
}
275+
],
276+
"tcs:identity":[
277+
{
278+
"tcs:website":[
279+
{
280+
"@value":"www.myWEBSite.com",
281+
"@type":"xdd:url"
282+
}
283+
],
284+
"tcs:twitter_handle":[
285+
{
286+
"@value":"https://twitter.com/Rose",
287+
"@type":"xsd:string"
288+
}
289+
],
290+
"tcs:email_address":[
291+
{
292+
"@value":"rose@gmail.com",
293+
"@type":"xdd:email"
294+
}
295+
],
296+
"@type":"tcs:Identifier",
297+
"@id":"_:x0ciuq1570113866176"
298+
}
299+
],
300+
"@type":"http://terminusdb.com/schema/tcs#Person",
301+
"@id":"http://localhost:6363/myFirstTerminusDB/document/Rose"
302+
},
303+
"@type":"terminus:APIUpdate"
304+
}
305+
306+
//opts.key is an optional API key
307+
308+
const opts={terminus:user_key: "root"}
309+
310+
client.updateSchema("myFirstTerminusDB",doc,opts).then((response)=>{
311+
console.log(response)
312+
}).catch((err)=>{
313+
console.log(err)
314+
});
315+
316+
...
317+
318+
```
319+
320+
##### `getDocument(docurl:String, opts:Object):Promise`
321+
Retrieves a document from the specified TerminusDb
322+
323+
docurl TerminusDB document full URL or a valid TerminusDB document Id or omitted
324+
325+
```js
326+
327+
//opts.terminus:encoding defines which format is requested
328+
//opts.key is an optional API key
329+
330+
const opts={terminus:encoding: "terminus:frame",
331+
terminus:user_key: "mykey"}
332+
333+
client.getDocument(http://localhost:6363/myFirstTerminusDB/document/Rose,opts).then((response)=>{
334+
console.log(response)
335+
}).catch((err)=>{
336+
console.log(err)
337+
});
338+
339+
...
340+
341+
```
342+
343+
##### `deleteDocument(docurl:String, opts:Object):Promise`
344+
Delete a document from the specified TerminusDb
345+
346+
docurl TerminusDB document full URL or a valid TerminusDB document Id or omitted
347+
348+
```js
349+
350+
//(opts) opts.key is an optional API key
351+
const opts={terminus:user_key: "root"}
352+
353+
client.deleteDocument(http://localhost:6363/myFirstTerminusDB/document/Rose,opts).then((response)=>{
354+
console.log(response)
355+
}).catch((err)=>{
356+
console.log(err)
357+
});
358+
359+
...
360+
361+
```
140362

141363
## Testing
142364
* Clone this repository
@@ -158,5 +380,5 @@ It will be nice, if you open an issue first so that we can know what is going on
158380

159381
The APACHE 2.0 License
160382

161-
Copyright (c) 2019 ........
383+
Copyright (c) 2019
162384

dist/terminus-client.min.js

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/terminus-client.min.js.map

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dispatchRequest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ function btoaImplementation(str) {
1919
}
2020

2121
function DispatchRequest(url, action, payload) {
22+
/*
23+
*CORS is only required when trying to fetch data from a browser,
24+
*as browsers by default will block requests to different origins
25+
*/
2226
const options = {
2327
mode: 'cors', // no-cors, cors, *same-origin
2428
redirect: 'follow', // manual, *follow, error

0 commit comments

Comments
 (0)