@@ -8,13 +8,14 @@ terminus-client
8
8
Promise based terminus client for the browser and node.js
9
9
10
10
## Requirements
11
- - [ TerminusDB] ( https://github.com/terminusdb/terminusdb )
11
+ - [ TerminusDB] ( https://github.com/terminusdb/terminus-server )
12
12
- [ NodeJS 8.1.4+] ( https://nodejs.org/en/ )
13
13
14
14
## Installation
15
15
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 .
17
17
18
+ ### NPM Module
18
19
Before installing, download and install Node.js. Node.js 0.10 or higher is required.
19
20
20
21
Installation is done using the npm install command:
@@ -25,25 +26,33 @@ Using npm:
25
26
$ npm install --save @terminusdb/terminus-client
26
27
```
27
28
29
+ ### Minified Script
30
+
28
31
Using cdn:
29
32
30
33
``` html
31
34
<script src =" https://unpkg.com/@terminusdb/terminus-client/dist/terminus-client.min.js" ></script >
32
35
```
33
36
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
+ ```
35
44
36
45
## Usage
37
46
38
47
``` javascript
39
48
//
40
49
const TerminusClient = require (' @terminusdb/terminus-client' );
41
50
42
- // Create a new instance of terminus client
51
+ // Create a new instance of terminusDB client
43
52
const client = new TerminusClient.WOQLClient ();
44
53
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 ' ).
47
56
.then (function (response ) {
48
57
// handle success
49
58
console .log (response);
@@ -60,7 +69,7 @@ client.connect("http://localhost/", 'secret').
60
69
// use async/await.
61
70
async function getCapabilities () {
62
71
try {
63
- const response = await client .connect (" http://localhost/" , ' secret ' );
72
+ const response = await client .connect (" http://localhost:6363 /" , ' myKey ' );
64
73
console .log (response);
65
74
} catch (err) {
66
75
console .error (err);
@@ -89,54 +98,267 @@ const client = new TerminusClient.WOQLClient({
89
98
90
99
## API
91
100
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
94
103
95
104
``` js
96
- var currentTerminusServerUrl= client .connectionConfig .dbURL ();
97
105
98
- var details= {
99
- " @context" : {
106
+
107
+ var details= {
108
+ " @context" : {
100
109
" 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/"
107
112
},
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"
111
128
},
112
- " terminus:allow_origin" : {
113
- " @type" : " xsd:string" ,
114
- " @value" : " *"
115
- }
129
+ " @type" : " terminus:APIUpdate"
116
130
}
117
131
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
118
140
119
- client .createDatabase (" newD" ,details,' root' );
141
+ // dburl is a full new TerminusDB url
142
+
143
+ client .createDatabase (" http://localhost:6363/myFirstTerminusDB" ,details,' mykey' );
120
144
121
145
...
122
146
123
147
```
124
148
125
- ### ` deleteDatabase():{[ dbUrl:string]} `
149
+ ##### ` deleteDatabase(dbUrl:String):Promise `
126
150
For delete a terminusDB
127
151
128
152
``` 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 ' );
131
155
132
156
or
133
157
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
+
136
218
...
137
219
138
220
```
139
221
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
+ ```
140
362
141
363
## Testing
142
364
* 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
158
380
159
381
The APACHE 2.0 License
160
382
161
- Copyright (c) 2019 ........
383
+ Copyright (c) 2019
162
384
0 commit comments