• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

terminusdb / terminusdb-client-js / 5575214034

pending completion
5575214034

push

github

web-flow
Merge pull request #287 from terminusdb/fix-type

Fix type

856 of 4565 branches covered (18.75%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

2457 of 6467 relevant lines covered (37.99%)

4.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.47
/lib/connectionConfig.js
1
/// /@ts-check
2
// connectionConfig
3
const { encodeURISegment } = require('./utils');
1✔
4
// eslint-disable-next-line no-unused-vars
5
const typedef = require('./typedef');
1✔
6

7
/**
8
 * @file Terminus DB connection configuration
9
 * @license Apache Version 2
10
 * @description Object representing the state of a connection to a terminus db - these are:
11
 * provides methods for getting and setting connection parameters
12
 * @constructor
13
 * @param {string} serverUrl - the terminusdb server url
14
 * @param {typedef.ParamsObj} [params] - an object with the following connection parameters:
15
 */
16

17
function ConnectionConfig(serverUrl, params) {
18
  /**
19
     * @type {string}
20
     */
21
  this.server = undefined;
4✔
22

23
  // the base server url without the team name
24
  this.baseServer = undefined;
4✔
25

26
  // remote auth for authenticating to remote servers for push / fetch / clone
27
  /** @type {typedef.CredentialObj} */
28
  this.remote_auth = undefined;
4✔
29

30
  // basic auth string for authenticating to local server
31
  /** @type {typedef.CredentialObj } */
32
  this.local_auth = undefined;
4✔
33

34
  // these operate as cursors - where within the connected server context, we currently are
35
  /** @type {string | boolean} */
36
  this.organizationid = false;
4✔
37
  /** @type {string | boolean} */
38
  this.dbid = false;
4✔
39

40
  this.default_branch_id = params && params.default_branch_id ? params.default_branch_id : 'main';
4!
41
  this.default_repo_id = 'local';
4✔
42
  this.system_db = '_system';
4✔
43
  this.api_extension = 'api/';
4✔
44
  // default repository and branch ids
45
  this.branchid = this.default_branch_id;
4✔
46
  this.repoid = this.default_repo_id;
4✔
47
  // set if pointing at a commit within a branch
48
  /** @type {string | boolean} */
49
  this.refid = false;
4✔
50
  /** @type {string | boolean} */
51
  this.connection_error = false;
4✔
52
  // I can set serverURL only in constructor
53
  const surl = this.parseServerURL(serverUrl);
4✔
54

55
  this.server = surl;
4✔
56
  if (params) this.update(params);
4✔
57
}
58

59
/**
60
 * Creates a new connection config object and copies all the state information from this one into it
61
 * @returns {ConnectionConfig}
62
 */
63
ConnectionConfig.prototype.copy = function () {
1✔
64
  const other = new ConnectionConfig(this.server);
×
65
  other.api_extension = this.api_extension;
×
66
  other.remote_auth = this.remote_auth;
×
67
  other.local_auth = this.local_auth;
×
68
  other.organizationid = this.organizationid;
×
69
  other.dbid = this.dbid;
×
70
  other.branchid = this.branchid;
×
71
  other.repoid = this.repoid;
×
72
  other.refid = this.refid;
×
73
  return other;
×
74
};
75

76
/**
77
 * updates connection config with new parameters
78
 * @param {typedef.ParamsObj}  params - an object with the following connection parameters:
79
 */
80
// this is a general review
81
// I think we have to throw an error
82
// before a servercall
83
// when the user of key/jwt is not setted
84
ConnectionConfig.prototype.update = function (params) {
1✔
85
  if (!params) return;
4!
86
  const orgID = params.organization || params.user;
4✔
87
  // console.log("orgID",orgID,params)
88
  this.setOrganization(orgID);
4✔
89
  // if (typeof params.credential !== 'undefined')this.setTokenParameter(params.credential)
90
  if (typeof params.db !== 'undefined') this.setDB(params.db);
4✔
91
  // this to set the author and the jwt in creation
92
  if (typeof params.token !== 'undefined') this.setLocalBasicAuth(params.token, params.user, 'apikey');
4!
93
  // this is for jwt
94
  else if (typeof params.jwt !== 'undefined') this.setLocalBasicAuth(params.jwt, params.user, 'jwt');
4!
95
  // this is basic authO
96
  else if (typeof params.key !== 'undefined') this.setLocalBasicAuth(params.key, params.user);
4✔
97
  // If I set only the user I have to set the
98
  else if (typeof params.user !== 'undefined') this.setLocalBasicAuth(null, params.user);
1!
99
  if (typeof params.branch !== 'undefined') this.setBranch(params.branch);
4!
100
  if (typeof params.ref !== 'undefined') this.setRef(params.ref);
4!
101
  if (typeof params.repo !== 'undefined') this.setRepo(params.repo);
4!
102
};
103

104
/* ConnectionConfig.prototype.setTokenParameter = function(param){
105
    this.tokenParameter = param
106
} */
107

108
/**
109
 * Simple gets to retrieve current connection status
110
 * Gets the current server url
111
 * @returns {string}
112
 */
113
ConnectionConfig.prototype.serverURL = function () {
1✔
114
  return this.server;
4✔
115
};
116

117
/**
118
 * Simple gets to retrieve current connection status
119
 * Gets the current server url
120
 * @returns {string}
121
 */
122
ConnectionConfig.prototype.author = function () {
1✔
123
  return this.author;
×
124
};
125

126
/**
127
 * Gets the server connection url
128
 * @returns {string}
129
 */
130
ConnectionConfig.prototype.apiURL = function () {
1✔
131
  return this.server + this.api_extension;
29✔
132
};
133

134
/**
135
 * Gets the server connection url info
136
 * @returns {string}
137
 */
138
ConnectionConfig.prototype.apiURLInfo = function () {
1✔
139
  return `${this.apiURL()}info`;
1✔
140
};
141

142
/**
143
 * Gets the current database id
144
 * @returns {string | boolean}
145
 */
146
ConnectionConfig.prototype.db = function () {
1✔
147
  if (!this.dbid) throw new Error('Invalid database name');
60✔
148
  return this.dbid;
59✔
149
};
150

151
/**
152
 * Gets the current branch id
153
 * @returns {string}
154
 */
155
ConnectionConfig.prototype.branch = function () {
1✔
156
  return this.branchid;
42✔
157
};
158

159
/**
160
 * Gets the current commit ref id
161
 * @returns {string | boolean}
162
 */
163
ConnectionConfig.prototype.ref = function () {
1✔
164
  return this.refid;
18✔
165
};
166

167
/**
168
 * Gets the current organization id
169
 * @returns {string | boolean}
170
 */
171
ConnectionConfig.prototype.organization = function () {
1✔
172
  return this.organizationid;
27✔
173
};
174

175
/**
176
 * Gets the current organization id
177
 * @returns {string}
178
 */
179
ConnectionConfig.prototype.repo = function () {
1✔
180
  return this.repoid;
49✔
181
};
182

183
/**
184
 *Gets the local Authorization credentials
185
 *return {CredentialObj | boolean}
186
 */
187
ConnectionConfig.prototype.localAuth = function () {
1✔
188
  if (this.local_auth) return this.local_auth;
6!
189
  return false;
×
190
};
191

192
/**
193
 *Gets the local user name
194
 *return {string | boolean}
195
 */
196
ConnectionConfig.prototype.localUser = function () {
1✔
197
  if (this.local_auth) return this.local_auth.user;
1!
198
  return false;
×
199
};
200

201
/**
202
 *Gets the current user name
203
 *@param {boolean} [ignoreJwt]
204
 *return {string | boolean}
205
 */
206
ConnectionConfig.prototype.user = function (ignoreJwt) {
1✔
207
  if (!ignoreJwt && this.remote_auth && this.remote_auth.type === 'jwt') return this.remote_auth.user;
1!
208
  if (this.local_auth) {
1!
209
    return this.local_auth.user;
1✔
210
  }
211
  return false;
×
212
};
213

214
/**
215
 * Check the server URL
216
 * @param {string} str - the server url string
217
 * @returns {string}
218
 */
219

220
ConnectionConfig.prototype.parseServerURL = function (str) {
1✔
221
  if (str && (str.substring(0, 7) === 'http://' || str.substring(0, 8) === 'https://')) {
5✔
222
    if (str.lastIndexOf('/') !== str.length - 1) {
4!
223
      // eslint-disable-next-line no-param-reassign
224
      str += '/'; // always append slash to ensure regularity
×
225
    }
226
    return this.serverUrlEncoding(str);
4✔
227
  }
228
  // throw an error this is the
229
  // return false
230
  throw new Error(`Invalid Server URL: ${str}`);
1✔
231
};
232

233
ConnectionConfig.prototype.serverUrlEncoding = function (str) {
1✔
234
  const orgArr = str.split('/');
6✔
235
  if (orgArr.length > 4) {
6✔
236
    // we can need only the server baseurl
237
    this.baseServer = str.replace(`${orgArr[3]}/`, '');
4✔
238
    // const org = encodeURI(orgArr[3])
239
    /*
240
      * if we pass the organization name like Francesca-Bit-9e73
241
      * I need to encode it 2 times because in the database
242
      * when we create an id from a property it encodes the property value
243
      */
244
    const org = encodeURISegment(orgArr[3]);
4✔
245
    return str.replace(orgArr[3], org);
4✔
246
  }
247
  this.baseServer = str;
2✔
248
  return str;
2✔
249
};
250

251
/**
252
 * Clear cursor for connection
253
 */
254
ConnectionConfig.prototype.clearCursor = function () {
1✔
255
  this.branchid = this.default_branch_id;
1✔
256
  this.repoid = this.default_repo_id;
1✔
257
  this.organizationid = false;
1✔
258
  this.dbid = false;
1✔
259
  this.refid = false;
1✔
260
};
261

262
/**
263
 * @param {string | boolean} errorMessage
264
 */
265
ConnectionConfig.prototype.setError = function (errorMessage) {
1✔
266
  this.connection_error = errorMessage;
1✔
267
};
268

269
/**
270
 * Set the organization to which the connected db belongs
271
 * (not the users organization - set in capabilities)
272
 * @param {string | boolean} [orgId]
273
 */
274
ConnectionConfig.prototype.setOrganization = function (orgId = 'admin') {
6✔
275
  this.organizationid = orgId;
6✔
276
};
277

278
/**
279
 * Set the local identifier of db
280
 * @param {string | boolean} dbId - database Id
281
 */
282

283
ConnectionConfig.prototype.setDB = function (dbId) {
1✔
284
  this.dbid = dbId;
6✔
285
};
286

287
/**
288
 * Set the repository type |local|remote|
289
 * @param {typedef.RepoType | string} repoId - for the local server - identifier of repo
290
 */
291
ConnectionConfig.prototype.setRepo = function (repoId) {
1✔
292
  this.repoid = repoId;
1✔
293
};
294

295
/**
296
 * @param {string} [branchId] - id of branch
297
 */
298
ConnectionConfig.prototype.setBranch = function (branchId) {
1✔
299
  this.branchid = branchId || this.default_branch_id;
2✔
300
};
301

302
/**
303
 * Set an Reference ID or Commit ID.
304
 * Commit IDs are unique hashes that are created whenever a new commit is recorded
305
 * @param {string | boolean} refId - commit reference id
306
 */
307
ConnectionConfig.prototype.setRef = function (refId) {
1✔
308
  this.refid = refId;
2✔
309
  // return this.refid
310
};
311

312
/**
313
 * set the local database connection credential
314
 * @param {string} [remoteKey] - jwt auth api key
315
 * @param {string} [remoteUserID] - remote user id
316
 */
317
ConnectionConfig.prototype.setRemoteBasicAuth = function (remoteKey, remoteUserID) {
1✔
318
  if (!remoteKey) {
×
319
    this.remote_auth = undefined;
×
320
  } else {
321
    this.remote_auth = { type: 'jwt', user: remoteUserID, key: remoteKey };
×
322
  }
323
};
324

325
/**
326
 * set the local database connection credential
327
 * @param {string} [userKey] - basic auth api key
328
 * @param {string} [userId] -  user id
329
 * @param {string} [type] - basic|jwt|apikey
330
 */
331
// to be review this is ok for the basic Auth
332
ConnectionConfig.prototype.setLocalBasicAuth = function (userKey, userId = 'admin', type = 'basic') {
4!
333
  this.local_auth = { type, user: userId, key: userKey };
4✔
334
};
335

336
/**
337
 * Set the local server connection credential
338
 * @param {typedef.CredentialObj} newCredential
339
 */
340
ConnectionConfig.prototype.setLocalAuth = function (newCredential) {
1✔
341
  this.local_auth = newCredential;
1✔
342
};
343

344
/**
345
 * Set the remote server connection credential
346
 * @param {typedef.CredentialObj} newCredential
347
 */
348
ConnectionConfig.prototype.setRemoteAuth = function (newCredential) {
1✔
349
  this.remote_auth = newCredential;
1✔
350
};
351

352
/**
353
 *Gets the remote Authorization credentials
354
 *to connect the local db with a remote terminusdb database for push-pull-clone actions
355
 *return {CredentialObj| boolean}
356
 */
357
ConnectionConfig.prototype.remoteAuth = function () {
1✔
358
  if (this.remote_auth) return this.remote_auth;
5✔
359
  return false;
4✔
360
};
361

362
/**
363
 * Generate the db endpoit url for create / delete db
364
 * @returns {string}
365
 */
366
ConnectionConfig.prototype.dbURL = function () {
1✔
367
  return this.dbBase('db');
3✔
368
};
369

370
/**
371
 * Generate URL for the user's api endpoint
372
 * @param {string} [user] - the user id
373
 * @returns {string}
374
 */
375

376
ConnectionConfig.prototype.userURL = function (user) {
1✔
377
  let url = `${this.apiURL()}user`;
1✔
378
  if (user) url += `/${encodeURISegment(user)}`;
1!
379
  return url;
1✔
380
};
381

382
/**
383
 * Generate URL for the user's organization api endpoint
384
 * @param {string} orgId - the organization id
385
 * @param {string} [action] - the organization id
386
 * @returns {string}
387
 */
388
// encodeURIComponent
389
ConnectionConfig.prototype.organizationURL = function (orgId, action) {
1✔
390
  let url = `${this.apiURL()}organization`;
1✔
391
  // I have to encode the organization 2 times because it is saved encoded inside the database
392
  //
393
  if (orgId) url += `/${encodeURISegment(orgId)}`;
1!
394
  if (action) url += `/${encodeURISegment(action)}`;
1!
395
  return url;
1✔
396
};
397

398
/**
399
 * Generate URL for the user's organization api endpoint
400
 * @param {string} orgId - the organization id
401
 * @param {string} [action] - the organization id
402
 * @returns {string}
403
 */
404

405
ConnectionConfig.prototype.userOrganizationsURL = function () {
1✔
406
  const url = `${this.apiURL()}user_organizations`;
×
407
  return url;
×
408
};
409

410
/**
411
 * Generate URL for the user's roles api endpoint
412
 * @returns {string}
413
 */
414
ConnectionConfig.prototype.rolesURL = function () {
1✔
415
  return `${this.apiURL()}role`;
1✔
416
};
417

418
/**
419
 * Generate URL to update the user's role api endpoint
420
 * @returns {string}
421
 */
422

423
// REVIEW maybe it can be the same of roleURL but we can change the rest action in put.
424

425
ConnectionConfig.prototype.updateRolesURL = function () {
1✔
426
  return `${this.apiURL()}update_role`;
1✔
427
};
428

429
/**
430
 * Generate URL for create / delete graph api endpoint
431
 * @param {string} graphType
432
 * @returns {string}
433
 */
434
ConnectionConfig.prototype.graphURL = function (graphType) {
1✔
435
  return `${this.branchBase('graph')}/${graphType}/main`;
×
436
};
437

438
/**
439
 * Generate URL for get / set schema api endpoint
440
 * @param {string} graphType
441
 * @returns {string}
442
 */
443
ConnectionConfig.prototype.triplesURL = function (graphType) {
1✔
444
  // eslint-disable-next-line vars-on-top
445
  // eslint-disable-next-line no-var
446
  let url = '';
5✔
447
  if (this.db() === this.system_db) {
5!
448
    // eslint-disable-next-line no-unused-vars
449
    const s = this.dbBase('triples');
×
450
  } else {
451
    url = this.branchBase('triples');
5✔
452
  }
453

454
  url += `/${graphType}/main`;
5✔
455
  return url;
5✔
456
};
457

458
/**
459
 * Generate URL for add / get csv api endpoint
460
 * @returns {string}
461
 */
462

463
ConnectionConfig.prototype.csvURL = function () {
1✔
464
  const s = this.branchBase('csv');
×
465
  return s;
×
466
};
467

468
/**
469
 * Generate URL for woql query api endpoint
470
 * @returns {string}
471
 */
472
ConnectionConfig.prototype.queryURL = function () {
1✔
473
  if (this.db() === this.system_db) return this.dbBase('woql');
5!
474
  return this.branchBase('woql');
5✔
475
};
476

477
/**
478
 * Generate URL for get back the commits logs
479
 * @returns {string}
480
 */
481
ConnectionConfig.prototype.log = function () {
1✔
482
  if (this.db() === this.system_db) return this.dbBase('log');
1!
483
  return this.branchBase('log');
1✔
484
};
485

486
/**
487
 * get the url to update the organization role in the system database
488
 * don't change the end point (this is a terminus db server end point)
489
 * @returns {string}
490
 */
491
ConnectionConfig.prototype.updateOrganizationRoleURL = function () {
1✔
492
  return `${this.apiURL()}update_role`;
×
493
};
494

495
/**
496
 * Generate URL for clone db endpoint
497
 * @param  {string} [newRepoId] the repository id
498
 * @returns {string}
499
 */
500
ConnectionConfig.prototype.cloneURL = function (newRepoId) {
1✔
501
  let crl = `${this.apiURL()}clone/${this.organization()}`;
1✔
502
  if (newRepoId) crl += `/${newRepoId}`;
1!
503
  return crl;
1✔
504
};
505

506
/**
507
 * URL at which a db can be cloned
508
 * @returns {string}
509
 */
510
ConnectionConfig.prototype.cloneableURL = function () {
1✔
511
  return `${this.serverURL()}${this.organization()}/${this.db()}`;
1✔
512
};
513

514
/**
515
 * Generate URL for pull endpoint
516
 * @returns {string}
517
 */
518
ConnectionConfig.prototype.pullURL = function () {
1✔
519
  const purl = this.branchBase('pull');
1✔
520
  return purl;
1✔
521
};
522

523
/**
524
 * Generate URL for pull endpoint
525
 * @returns {string}
526
 */
527
ConnectionConfig.prototype.patchURL = function () {
1✔
528
  const purl = this.branchBase('patch');
×
529
  return purl;
×
530
};
531

532
/**
533
 * Generate URL for diff endpoint
534
 * @returns {string}
535
 */
536
ConnectionConfig.prototype.diffURL = function () {
1✔
537
  const purl = this.branchBase('diff');
×
538
  return purl;
×
539
};
540

541
/**
542
 * Generate URL for diff endpoint
543
 * @returns {string}
544
 */
545
ConnectionConfig.prototype.applyURL = function () {
1✔
546
  const purl = this.branchBase('apply');
×
547
  return purl;
×
548
};
549

550
/**
551
 * Generate url portion consisting of organization/dbid
552
 * (unless dbid = system dbname in which case there is no organization)
553
 * @property {typedef.DocParamsPost|Object} params
554
 */
555

556
ConnectionConfig.prototype.docHistoryURL = function (params) {
1✔
557
  const paramsStr = this.queryParameter(params);
×
558
  if (this.db() === this.system_db) {
×
559
    return this.dbBase('history') + paramsStr;
×
560
  }
561
  return this.branchBase('history') + paramsStr;
×
562
};
563

564
/**
565
 * Generate URL for fetch endpoint
566
 * @param {string} remoteName
567
 * @returns {string}
568
 */
569
ConnectionConfig.prototype.fetchURL = function (remoteName) {
1✔
570
  const purl = this.dbBase('fetch');
1✔
571
  return `${purl}/${remoteName}/_commits`;
1✔
572
};
573

574
/**
575
 * Generate URL for rebase endpoint
576
 * @returns {string}
577
 */
578
ConnectionConfig.prototype.rebaseURL = function () {
1✔
579
  const purl = this.branchBase('rebase');
1✔
580
  return purl;
1✔
581
};
582

583
/**
584
 * Generate URL for reset endpoint
585
 * @returns {string}
586
 */
587
ConnectionConfig.prototype.resetURL = function () {
1✔
588
  const purl = this.branchBase('reset');
1✔
589
  return purl;
1✔
590
};
591

592
/**
593
 * Generate URL for push endpoint
594
 * @returns {string}
595
 */
596
ConnectionConfig.prototype.pushURL = function () {
1✔
597
  const purl = this.branchBase('push');
1✔
598
  return purl;
1✔
599
};
600

601
/**
602
 * Generate URL for branch endpoint
603
 * @param {string} branchId - the branch id
604
 * @returns {string}
605
 */
606
ConnectionConfig.prototype.branchURL = function (branchId) {
1✔
607
  const url = this.repoBase('branch');
1✔
608
  return `${url}/branch/${branchId}`;
1✔
609
};
610

611
/**
612
 * Generate URL for branch squash endpoint
613
 */
614
ConnectionConfig.prototype.squashBranchURL = function (nuid) {
1✔
615
  const b = this.repoBase('squash');
×
616
  return `${b}/branch/${nuid}`;
×
617
};
618

619
/**
620
 * Generate URL for branch reset endpoint
621
 */
622
ConnectionConfig.prototype.resetBranchUrl = function (nuid) {
1✔
623
  const b = this.repoBase('reset');
×
624
  return `${b}/branch/${nuid}`;
×
625
};
626

627
/**
628
 * Generate URL for commit descriptor
629
 * @param {string} commitId
630
 * @returns {string} a commit pathname
631
 */
632
// this is not a url
633
ConnectionConfig.prototype.commitDescriptorUrl = function (commitId) {
1✔
634
  return `${this.organization()}/${this.db()}/${this.repoid}/commit/${commitId}`;
×
635
};
636

637
/**
638
 * Generate URL for optimizing db branch
639
 */
640
// encodeURI() will not encode: ~!@#$&*()=:/,;?+'
641
ConnectionConfig.prototype.optimizeBranchUrl = function (branchId) {
1✔
642
  // let o = this.optimizeBase()
643
  const dbBase = this.dbBase('optimize');
1✔
644
  return `${dbBase}/${this.repoid}/branch/${encodeURIComponent(branchId)}`;
1✔
645
  // return dbBase + `${this.user()}/${this.db()}/${this.repoid}/branch/${nuid}`
646
};
647

648
/**
649
 * Generate base db url consisting of server/action/organization/dbid
650
 * @param {typedef.ActionType} action
651
 * @returns {string}
652
 */
653
ConnectionConfig.prototype.dbBase = function (action) {
1✔
654
  return `${this.apiURL()}${action}/${this.dbURLFragment()}`;
22✔
655
};
656

657
// https://127.0.0.1:6363/api/document/admin/cloud-profiles/local/branch/main?graph_type=instance
658
// instance
659

660
/**
661
 * Generate base branch url consisting of server/action/organization/dbid/branchid
662
 * @param {typedef.ActionType} action
663
 * @returns {string}
664
 */
665
ConnectionConfig.prototype.repoBase = function (action) {
1✔
666
  let b = this.dbBase(action);
16✔
667
  if (this.repo()) b += `/${this.repo()}`;
16!
668
  else b += `/${this.default_repo_id}`;
×
669
  return b;
16✔
670
};
671

672
/**
673
 * Get database branch Url
674
 * Generate base branch url consisting of server/action/organization/dbid/branchid
675
 * @param {typedef.ActionType} action
676
 * @returns {string}
677
 */
678
ConnectionConfig.prototype.branchBase = function (action) {
1✔
679
  let b = this.repoBase(action);
15✔
680
  // _meta repo is magic - stores repository metadata
681
  if (this.repo() === '_meta') {
15!
682
    return b;
×
683
  }
684
  // _commits branch is magic - stores all commits for repo
685

686
  /*
687
    *https://127.0.0.1:6363/api/db/admin/profiles01/local/_commits
688
    */
689
  if (this.branch() === '_commits') {
15!
690
    return `${b}/${this.branch()}`;
×
691
  } if (this.ref()) {
15✔
692
    return `${b}/commit/${this.ref()}`;
2✔
693
  } if (this.branch()) {
13!
694
    return `${b}/branch/${encodeURIComponent(this.branch())}`;
13✔
695
  } b += `/branch/${this.default_branch_id}`;
×
696
  return b;
×
697
};
698

699
/**
700
 * Generate url portion consisting of organization/dbid
701
 * (unless dbid = system dbname in which case there is no organization)
702
 * @returns {string|boolean}
703
 */
704
// encodeURIComponent
705
ConnectionConfig.prototype.dbURLFragment = function () {
1✔
706
  if (this.db() === this.system_db) return this.db();
22!
707
  return `${encodeURISegment(this.organization())}/${encodeURISegment(this.db())}`;
22✔
708
};
709

710
/**
711
 * Generate url portion consisting of organization/dbid
712
 * (unless dbid = system dbname in which case there is no organization)
713
 * @property {typedef.DocParamsPost|Object} params
714
 */
715

716
ConnectionConfig.prototype.documentURL = function (params) {
1✔
717
  const paramsStr = this.queryParameter(params);
×
718
  if (this.db() === this.system_db) {
×
719
    return this.dbBase('document') + paramsStr;
×
720
  }
721
  return this.branchBase('document') + paramsStr;
×
722
};
723

724
ConnectionConfig.prototype.prefixesURL = function () {
1✔
725
  if (this.db() === this.system_db) {
×
726
    return this.dbBase('prefixes');
×
727
  }
728
  return this.branchBase('prefixes');
×
729
};
730

731
ConnectionConfig.prototype.queryParameter = function (params) {
1✔
732
  if (!params || typeof params !== 'object') return '';
×
733
  const queryString = Object.keys(params).map((key) => `${key}=${encodeURISegment(params[key])}`).join('&');
×
734
  return `?${queryString}`;
×
735
};
736

737
ConnectionConfig.prototype.jsonSchemaURL = function (params) {
1✔
738
  const paramsStr = this.queryParameter(params);
×
739
  if (this.db() === this.system_db) {
×
740
    return this.dbBase('schema') + paramsStr;
×
741
  }
742
  return this.branchBase('schema') + paramsStr;
×
743
};
744

745
module.exports = ConnectionConfig;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc