Skip to content

Commit e499600

Browse files
Merge branch 'main' into add_method_to_Var
2 parents 9cd3bed + baedbb3 commit e499600

File tree

11 files changed

+85
-36
lines changed

11 files changed

+85
-36
lines changed

docs/api/typedef.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ the PUT document interface query parameters
4747
| Name | Type | Description |
4848
| --- | --- | --- |
4949
| [raw_json] | <code>boolean</code> | default is false, If true, the input documents are treated as raw JSON, inserted as type sys:JSONDocument and are not subject to schema restrictions. |
50+
| [create] | <code>boolean</code> | If true, the function will create a new document if it doesn't exist. |
5051
| [graph_type] | <code>GraphType</code> | default is instance, instance|schema Used to switch between getting documents from the instance or the schema graph. |
5152

5253

@@ -60,7 +61,7 @@ the DELETE document interface query parameters
6061
| --- | --- | --- |
6162
| [graph_type] | <code>GraphType</code> | default is instance, instance|schema Used to switch between getting documents from the instance or the schema graph. |
6263
| id | <code>string</code> \| <code>array</code> | a single id or a list of ids to delete. |
63-
| [nuke] | <code>booleam</code> | default is false, If true, delete everything at this resource location (dangerous!). |
64+
| [nuke] | <code>boolean</code> | default is false, If true, delete everything at this resource location (dangerous!). |
6465

6566

6667
## GraphRef

docs/api/woql.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,10 @@ const doc = WOQL.doc({ "@type": "Person", name: "Newperson" })
14551455
```
14561456

14571457
## client
1458-
##### WOQL.client(client) ⇒ <code>WOQLClient</code>
1459-
Gets/Sets woqlClient
1458+
##### ~~WOQL.client(client) ⇒ <code>WOQLClient</code>~~
1459+
***Deprecated***
1460+
1461+
Use instead to run your query woqlclient.query('myWOQLQuery')
14601462

14611463

14621464
| Param | Type |

docs/api/woqlclient.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ async function getSchema() {
5555
##### ~~woqlClient.connect([params]) ⇒ <code>Promise</code>~~
5656
***Deprecated***
5757

58-
Connect to a Terminus server at the given URI with an API key
59-
Stores the system:ServerCapability document returned
60-
in the connection register which stores, the url, key, capabilities,
61-
and database meta-data for the connected server
62-
this.connectionConfig.server will be used if present,
58+
You can call this to get the server info or override the start params
59+
configuration, this.connectionConfig.server will be used if present,
6360
or the promise will be rejected.
6461

6562
**Returns**: <code>Promise</code> - the connection capabilities response object or an error object
@@ -863,8 +860,8 @@ client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"}).then(r
863860
})
864861

865862
//pass a document query template to query the document interface
866-
const queryTemplate = { "name": "Ireland", "@type":"Country" }
867-
client.getDocument({"graph_type":"schema","as_list":true,
863+
const queryTemplate = { "name": "Ireland"}
864+
client.getDocument({"as_list":true, "@type":"Country"
868865
query:queryTemplate}).then(result=>{
869866
console.log(result)
870867
})
@@ -896,7 +893,7 @@ const response1 = await client.getDocument({"graph_type":"schema","as_list":true
896893
```
897894
898895
## updateDocument
899-
##### woqlClient.updateDocument(json, [params], [dbId], [message], [lastDataVersion], [getDataVersion], [create]) ⇒ <code>Promise</code>
896+
##### woqlClient.updateDocument(json, [params], [dbId], [message], [lastDataVersion], [getDataVersion], [compress], [create]) ⇒ <code>Promise</code>
900897
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
901898
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
902899
@@ -908,7 +905,8 @@ and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error
908905
| [message] | <code>\*</code> | the update commit message |
909906
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
910907
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
911-
| [create] | <code>boolean</code> | If true, the function will create a new document if it doesn't exist. |
908+
| [compress] | <code>boolean</code> | If true, the function will create a new document if it doesn't exist. |
909+
| [create] | <code>boolean</code> | Perform an *upsert* which inserts if the document is not present (also works on nested documents) |
912910
913911
**Example**
914912
```javascript
@@ -967,6 +965,17 @@ const response1 = await client.updateDocument(
967965
"",
968966
response.dataVersion
969967
);
968+
969+
// update a document and create the linked document together
970+
// we are update the document "Person/Person01"
971+
// and create a new document {"@type": "Person","name": "child01"} at the same time
972+
const response1 = await client.updateDocument(
973+
{
974+
"@id": "Person/Person01",
975+
"@type": "Person",
976+
"name": "Person01"
977+
"children":[{"@type": "Person","name": "child01"}]
978+
},{create:true})
970979
```
971980
972981
## deleteDocument

lib/connectionConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// /@ts-check
22
// connectionConfig
33
const { encodeURISegment } = require('./utils');
4+
// eslint-disable-next-line no-unused-vars
5+
const typedef = require('./typedef');
46

57
/**
68
* @file Terminus DB connection configuration

lib/dispatchRequest.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const UTILS = require('./utils');
55
const CONST = require('./const');
66
const ErrorMessage = require('./errorMessage');
77
const { version } = require('../package.json');
8+
// eslint-disable-next-line no-unused-vars
9+
const typedef = require('./typedef');
810
/**
911
* base 64 encodes a string using either the btoa implementation if available or the Buffer object.
1012
* @param {String} str string to be base 64 encoded
@@ -64,9 +66,12 @@ function checkPayload(payload, options, compress) {
6466
* @param {string} url API endpoint URL
6567
* @param {string} action API action
6668
* @param {object} payload data to be transmitted to endpoint
67-
* @param {string} key optional basic auth string to be passed
68-
* @param {object} customHeaders the unique reqID
69-
* @param {boolean} compress If true, compress the data with gzip if its size is bigger than 1024
69+
* @param {typedef.CredentialObj} local_auth the local authorization object
70+
* @param {typedef.CredentialObj} remote_auth the remote authoriuzation object
71+
* @param {object} customHeaders all the custom header to add to your call
72+
* @param {boolean} [getDataVersion] If true the function will return object having result
73+
* and dataVersion.
74+
* @param {boolean} [compress] If true, compress the data with gzip if its size is bigger than 1024
7075
*/
7176

7277
// eslint-disable-next-line max-len

lib/query/woqlBuilder.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121

2222
const WOQLQueryExt = require('./woqlQuery');
23+
24+
// eslint-disable-next-line no-unused-vars
25+
const typedef = require('../typedef');
2326
// const WOQLLibrary = require('./woqlLibrary');
2427

2528
class WOQLQuery extends WOQLQueryExt {
@@ -114,17 +117,17 @@ WOQLQuery.prototype.iri = function (s) {
114117
* @returns {WOQLQuery} A WOQLQuery which contains the a Update Triple Statement
115118
*/
116119

117-
WOQLQuery.prototype.update_triple = function (subject, predicate, new_object, old_object) {
118-
const tmp_name = old_object || `v:AnyObject__${this.counter += 1}`;
120+
WOQLQuery.prototype.update_triple = function (subject, predicate, newObjValue, oldObjValue) {
121+
const tmp_name = oldObjValue || `v:AnyObject__${this.counter += 1}`;
119122
return this.and(
120123
new WOQLQuery().opt(
121124
new WOQLQuery()
122125
.triple(subject, predicate, tmp_name)
123126
.delete_triple(subject, predicate, tmp_name)
124127
.not()
125-
.triple(subject, predicate, new_object),
128+
.triple(subject, predicate, newObjValue),
126129
),
127-
new WOQLQuery().add_triple(subject, predicate, new_object),
130+
new WOQLQuery().add_triple(subject, predicate, newObjValue),
128131
);
129132
};
130133

@@ -139,17 +142,17 @@ WOQLQuery.prototype.update_triple = function (subject, predicate, new_object, ol
139142
* @returns {WOQLQuery} A WOQLQuery which contains the a Update Quad Statement
140143
*/
141144

142-
WOQLQuery.prototype.update_quad = function (subject, predicate, new_object, graph) {
145+
WOQLQuery.prototype.update_quad = function (subject, predicate, newObject, graph) {
143146
const tmp_name = `v:AnyObject__${this.counter += 1}`;
144147
return this.and(
145148
new WOQLQuery().opt(
146149
new WOQLQuery()
147150
.quad(subject, predicate, tmp_name, graph)
148151
.delete_quad(subject, predicate, tmp_name, graph)
149152
.not()
150-
.quad(subject, predicate, new_object, graph),
153+
.quad(subject, predicate, newObject, graph),
151154
),
152-
new WOQLQuery().add_quad(subject, predicate, new_object, graph),
155+
new WOQLQuery().add_quad(subject, predicate, newObject, graph),
153156
);
154157
};
155158

@@ -199,9 +202,9 @@ WOQLQuery.prototype.node = function (node, type) {
199202
* be used for subsequent chained schema calls
200203
* @returns {WOQLQuery} A WOQLQuery which contains the partial Graph pattern matching expression
201204
*/
202-
WOQLQuery.prototype.graph = function (g) {
205+
WOQLQuery.prototype.graph = function (graphRef) {
203206
return this._set_context({
204-
graph: g,
207+
graph: graphRef,
205208
});
206209
};
207210
// do not remove

lib/query/woqlCore.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const UTILS = require('../utils');
1616
const WOQLPrinter = require('./woqlPrinter');
1717
const { Var, Vars, Doc } = require('./woqlDoc');
1818

19+
// eslint-disable-next-line no-unused-vars
20+
const typedef = require('../typedef');
21+
1922
/**
2023
* defines the internal functions of the woql query object - the
2124
* language API is defined in WOQLQuery
@@ -596,6 +599,8 @@ WOQLQuery.prototype.getVocabulary = function (vocab) {
596599
};
597600

598601
/**
602+
* Use instead woqlclient.query('myWOQLQuery')
603+
* @deprecated
599604
* Executes the query using the passed client to connect to a server
600605
*
601606
*/

lib/query/woqlQuery.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/* eslint-disable prefer-destructuring */
1111
/* eslint-disable guard-for-in */
1212
/* eslint-disable no-restricted-syntax */
13+
1314
/// /@ts-check
1415
// WOQLQuery
1516
/**
@@ -23,6 +24,8 @@
2324

2425
const WOQLCore = require('./woqlCore');
2526
const { Var, Vars, Doc } = require('./woqlDoc');
27+
// eslint-disable-next-line no-unused-vars
28+
const typedef = require('../typedef');
2629

2730
// I HAVE TO REVIEW THE Inheritance and the prototype chain
2831
class WOQLQuery extends WOQLCore {
@@ -390,7 +393,7 @@ WOQLQuery.prototype.and = function (...subqueries) {
390393

391394
/**
392395
* Creates a logical OR of the arguments
393-
* @param {...WOQLQuery} [subqueries] - A list of one or more woql queries
396+
* @param {...WOQLQuery} subqueries - A list of one or more woql queries
394397
* to execute as alternatives
395398
* @returns {WOQLQuery} - A WOQLQuery object containing the logical Or of the subqueries
396399
*/

lib/typedef.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const { ACTIONS } = Utils.ACTIONS;
4545
*@property {boolean} [raw_json] - default is false, If true, the input documents
4646
are treated as raw JSON, inserted as type sys:JSONDocument and are not subject
4747
to schema restrictions.
48+
*@property {boolean} [create] - If true, the function will create
49+
a new document if it doesn't exist.
4850
*@property {GraphType} [graph_type] - default is instance, instance|schema Used to switch between
4951
getting documents from the instance or the schema graph.
5052
*/
@@ -54,7 +56,7 @@ const { ACTIONS } = Utils.ACTIONS;
5456
*@property {GraphType} [graph_type] - default is instance, instance|schema Used to switch between
5557
getting documents from the instance or the schema graph.
5658
*@property {string|array} id - a single id or a list of ids to delete.
57-
*@property {booleam} [nuke] - default is false, If true, delete everything at this resource
59+
*@property {boolean} [nuke] - default is false, If true, delete everything at this resource
5860
location (dangerous!).
5961
*/
6062

lib/woql.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
const WOQLQuery = require('./query/woqlBuilder');
66
const WOQLLibrary = require('./query/woqlLibrary');
77
const { Vars, Var, Doc } = require('./query/woqlDoc');
8+
// eslint-disable-next-line no-unused-vars
9+
const typedef = require('./typedef');
10+
// eslint-disable-next-line no-unused-vars
11+
const WOQLClient = require('./woqlClient');
12+
813
/**
914
* @license Apache Version 2
1015
* @module WOQL
@@ -1359,6 +1364,8 @@ WOQL.doc = function (object) {
13591364
};
13601365

13611366
/**
1367+
* Use instead to run your query woqlclient.query('myWOQLQuery')
1368+
* @deprecated
13621369
* Gets/Sets woqlClient
13631370
* @param {WOQLClient}
13641371
* @returns {WOQLClient}

0 commit comments

Comments
 (0)