Skip to content

Commit 6c8098d

Browse files
committed
add fix
1 parent 1ee1d39 commit 6c8098d

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

lib/connectionConfig.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// /@ts-check
22
// connectionConfig
3-
const { encodeURISegment } = require('./utils');
3+
const { encodeURISegment, URIEncodePayload } = require('./utils');
44

55
/**
66
* @file Terminus DB connection configuration
@@ -699,7 +699,6 @@ ConnectionConfig.prototype.prefixesURL = function () {
699699
ConnectionConfig.prototype.queryParameter = function (params) {
700700
if (!params || typeof params !== 'object') return '';
701701
const queryString = Object.keys(params).map((key) => `${key}=${encodeURISegment(params[key])}`).join('&');
702-
703702
return `?${queryString}`;
704703
};
705704

lib/dispatchRequest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function DispatchRequest(url, action, payload, local_auth, remote_auth = null, c
151151
case CONST.GET: {
152152
if (payload) {
153153
const ext = UTILS.URIEncodePayload(payload);
154+
console.log('getPayload', payload, ext);
154155
// eslint-disable-next-line no-param-reassign
155156
if (ext) url += `?${ext}`;
156157
}

lib/typedef.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const { ACTIONS } = Utils.ACTIONS;
2525
*@property {boolean} [as_list] default is false, If true, don't return a stream of json objects,
2626
but a json list.
2727
*@property {string} [graph_type] - instance|schema default value is instance
28+
*@property {object} [query] - object that descrive the document query
2829
*/
2930

3031
/**

lib/woqlClient.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ class WOQLClient {
7474
}
7575
}
7676

77-
/* function WOQLClient(serverUrl, params) {
78-
// current connection context variables
79-
this.connectionConfig = new ConnectionConfig(serverUrl, params);
80-
this.databaseList = [];
81-
this.organizationList = [];
82-
} */
83-
8477
/**
8578
* set the api key to access the cloud resources
8679
* @param {string} accessToken
@@ -1138,26 +1131,36 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
11381131

11391132
/**
11401133
*
1141-
* @param {typedef.DocParamsGet} [params] - the get parameters
1134+
* @param {typedef.DocParamsGet} [params] - the get parameters,
1135+
* you can pass document query search template with the params
11421136
* @param {string} [dbId] - the database id
11431137
* @param {string} [branch] - the database branch
11441138
* @param {string} [lastDataVersion] the last data version tracking id.
11451139
* @param {boolean} [getDataVersion] If true the function will return object having result
11461140
* and dataVersion.
1147-
* @param {object} [query] If a query object is provided, the function will use it to
1148-
* query the database.
1141+
* @param {object} [query] document query search template
11491142
* @returns {Promise} A promise that returns the call response object or object having *result*
11501143
* and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
11511144
* @example
11521145
* //return the schema graph as a json array
1153-
* client.getDocument({"graph_type":"schema","as_list":true})
1146+
* client.getDocument({"graph_type":"schema","as_list":true}).then(result={
1147+
* console.log(result)
1148+
* })
11541149
*
11551150
* //retutn the Country class document from the schema graph
1156-
* client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"})
1151+
* client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"}).then(result={
1152+
* console.log(result)
1153+
* })
11571154
*
1155+
* //pass a document query template to query the document interface
1156+
* const queryTemplate = { "name": "Ireland", "@type":"Country" }
1157+
* client.getDocument({"graph_type":"schema","as_list":true,
1158+
* query:queryTemplate}).then(result=>{
1159+
* console.log(result)
1160+
* })
11581161
*
1159-
* // Here we will pass true to show how to get dataVersion
11601162
*
1163+
* // Here we will pass true to show how to get dataVersion
11611164
* const response = await client.getDocument({"graph_type":"schema","as_list":true},
11621165
* "",
11631166
* "",
@@ -1192,12 +1195,19 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
11921195
if (typeof lastDataVersion === 'string' && lastDataVersion !== '') {
11931196
this.customHeaders({ 'TerminusDB-Data-Version': lastDataVersion });
11941197
}
1195-
1198+
let queryDoc;
11961199
if (query) {
1200+
queryDoc = query;
1201+
} else if (params && typeof params === 'object' && params.query) {
1202+
queryDoc = params.query;
1203+
delete params.query;
1204+
}
1205+
// if query we are send a get with a payload
1206+
if (queryDoc) {
11971207
return this.dispatch(
11981208
CONST.QUERY_DOCUMENT,
11991209
this.connectionConfig.documentURL(params),
1200-
query,
1210+
queryDoc,
12011211
getDataVersion,
12021212
);
12031213
}

0 commit comments

Comments
 (0)