@droz-js/sdk 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@droz-js/sdk",
3
3
  "description": "Droz SDK",
4
- "version": "0.2.5",
4
+ "version": "0.2.7",
5
5
  "private": false,
6
- "main": "./src/index.js",
7
6
  "exports": {
7
+ ".": "./src/index.js",
8
8
  "./*": "./src/*.js",
9
9
  "./server": "./src/index.ts",
10
10
  "./server/*": "./src/*.ts"
@@ -58,23 +58,25 @@ class DrozSdk {
58
58
  }
59
59
  static async getOrDiscoverTenantConfig(tenant) {
60
60
  if (this.tenantConfigs.has(tenant)) {
61
- return this.tenantConfigs.get(tenant);
61
+ return await this.tenantConfigs.get(tenant);
62
62
  }
63
63
  return await this.discoverTenantConfig(tenant);
64
64
  }
65
- static async discoverTenantConfig(tenant) {
66
- // fetch instances from discovery service
67
- const data = await fetch(`${helpers_1.serviceDiscoveryEndpoint}/discover/${tenant}`);
68
- const json = await data.json();
69
- const instances = json.instances ?? [];
70
- // validate it's a valid tenant
71
- if (instances.length === 0) {
72
- throw new Error(`Invalid tenant '${tenant}', no instances found on service discovery`);
65
+ static discoverTenantConfig(tenant) {
66
+ async function promise() {
67
+ // fetch instances from discovery service
68
+ const data = await fetch(`${helpers_1.serviceDiscoveryEndpoint}/discover/${tenant}`);
69
+ const json = await data.json();
70
+ const instances = json.instances ?? [];
71
+ // validate it's a valid tenant
72
+ if (instances.length === 0) {
73
+ throw new Error(`Invalid tenant '${tenant}', no instances found on service discovery`);
74
+ }
75
+ // create tenant config and cache it
76
+ return new TenantConfig(tenant, instances);
73
77
  }
74
- // create tenant config and cache it
75
- const config = new TenantConfig(tenant, instances);
76
- this.tenantConfigs.set(tenant, config);
77
- return config;
78
+ this.tenantConfigs.set(tenant, promise());
79
+ return this.tenantConfigs.get(tenant);
78
80
  }
79
81
  }
80
82
  exports.DrozSdk = DrozSdk;
@@ -25,11 +25,9 @@ function emptyAsyncIterator() {
25
25
  };
26
26
  }
27
27
  function buildArgs(req) {
28
- const operationNames = Array.isArray(req) ? req.map(r => r.operationName) : [req.operationName];
29
- const params = new URLSearchParams();
30
- const uniques = new Set(operationNames);
31
- uniques.forEach(name => params.append('_', name));
32
- return params.toString();
28
+ const names = [].concat(req).map(each => each.operationName);
29
+ const uniques = [...new Set(names)].join(',');
30
+ return `_=${uniques}`;
33
31
  }
34
32
  class HttpRequester {
35
33
  serviceName;
package/src/client/ws.js CHANGED
@@ -31,6 +31,8 @@ class WsRequester {
31
31
  return this.requester.bind(this);
32
32
  }
33
33
  requester(query, variables) {
34
+ if (!this.client)
35
+ throw new Error('ws client not connected, you must call await client.connect(); first');
34
36
  const isSubscription = query.trim().startsWith('subscription ');
35
37
  const operation = { query, variables };
36
38
  const iterable = this.client.iterate(operation);