@centia-io/sdk 0.0.31 → 0.0.33

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.
@@ -358,7 +358,8 @@ var CodeFlow = class {
358
358
  params.delete("code");
359
359
  params.delete("state");
360
360
  const loc = window.location;
361
- loc.origin + loc.pathname + (params.size > 0 ? "?" + params.toString() : "");
361
+ const newUrl = loc.origin + loc.pathname + (params.size > 0 ? "?" + params.toString() : "");
362
+ history.pushState(null, "", newUrl);
362
363
  return Promise.resolve(true);
363
364
  } catch (e) {
364
365
  throw new Error(e.message);
@@ -374,7 +375,7 @@ var CodeFlow = class {
374
375
  }
375
376
  signOut() {
376
377
  this.clear();
377
- window.location = this.service.getSignOutURL();
378
+ window.location.assign(this.service.getSignOutURL());
378
379
  }
379
380
  clear() {
380
381
  clearTokens();
@@ -643,7 +644,7 @@ var SignUp = class {
643
644
  this.service = new Gc2Service(options);
644
645
  }
645
646
  async signUp() {
646
- window.location = this.service.getSignUpURL();
647
+ window.location.assign(this.service.getSignUpURL());
647
648
  }
648
649
  };
649
650
 
@@ -899,7 +900,7 @@ var TableQueryImpl = class {
899
900
  }
900
901
  parts.push(`select ${selectParts.join(", ")} from "${schema.name}"."${table.name}"`);
901
902
  for (const j of state.joins) {
902
- const onExpr = j.on.map((p$1) => `"${table.name}"."${p$1.left}" = "${j.target.name}"."${p$1.right}"`).join(" and ");
903
+ const onExpr = j.on.map((p$1) => `"${j.source.name}"."${p$1.left}" = "${j.target.name}"."${p$1.right}"`).join(" and ");
903
904
  parts.push(`${j.type} join "${schema.name}"."${j.target.name}" on ${onExpr}`);
904
905
  }
905
906
  const andParts = [];
@@ -1047,7 +1048,7 @@ var TableQueryImpl = class {
1047
1048
  if (state.offset !== void 0) parts.push("offset " + state.offset);
1048
1049
  return {
1049
1050
  q: parts.join(" "),
1050
- params,
1051
+ params: Object.keys(params).length > 0 ? params : void 0,
1051
1052
  type_hints: Object.keys(type_hints).length ? type_hints : void 0
1052
1053
  };
1053
1054
  };
@@ -1181,12 +1182,31 @@ var TableQueryImpl = class {
1181
1182
  }
1182
1183
  join(tableName, type = "inner") {
1183
1184
  const target = findTable(schema, String(tableName));
1184
- const pairs = findJoinOn(table, target);
1185
- if (!pairs || !pairs.length) throw new Error(`No foreign key relation found between ${table.name} and ${target.name}`);
1185
+ const sources = [];
1186
+ for (let i = this.s.joins.length - 1; i >= 0; i--) {
1187
+ const src = this.s.joins[i].target;
1188
+ if (!sources.some((s) => s.name === src.name)) sources.push(src);
1189
+ }
1190
+ if (!sources.some((s) => s.name === table.name)) sources.push(table);
1191
+ let pickedSource = null;
1192
+ let pairs = null;
1193
+ for (const src of sources) {
1194
+ const p = findJoinOn(src, target);
1195
+ if (p && p.length) {
1196
+ pickedSource = src;
1197
+ pairs = p;
1198
+ break;
1199
+ }
1200
+ }
1201
+ if (!pairs || !pickedSource) {
1202
+ const candidates = sources.map((s) => s.name).join(", ");
1203
+ throw new Error(`No foreign key relation found between any of [${candidates}] and ${target.name}`);
1204
+ }
1186
1205
  const jt = String(type);
1187
1206
  if (jt !== "inner" && jt !== "left" && jt !== "right" && jt !== "full") throw new Error(`Invalid join type: ${jt}. Allowed: inner | left | right | full`);
1188
1207
  this.s.joins.push({
1189
1208
  type: jt,
1209
+ source: pickedSource,
1190
1210
  target,
1191
1211
  on: pairs
1192
1212
  });
@@ -1228,7 +1248,7 @@ var TableQueryImpl = class {
1228
1248
  if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1229
1249
  return {
1230
1250
  q: parts.join(" "),
1231
- params,
1251
+ params: Object.keys(params).length > 0 ? params : void 0,
1232
1252
  type_hints: Object.keys(type_hints).length ? type_hints : void 0
1233
1253
  };
1234
1254
  };
@@ -1320,7 +1340,7 @@ var TableQueryImpl = class {
1320
1340
  if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1321
1341
  return {
1322
1342
  q: parts.join(" "),
1323
- params,
1343
+ params: Object.keys(params).length > 0 ? params : void 0,
1324
1344
  type_hints: Object.keys(type_hints).length ? type_hints : void 0
1325
1345
  };
1326
1346
  };
@@ -1393,7 +1413,7 @@ var TableQueryImpl = class {
1393
1413
  if (state.returning.length) parts.push("returning " + state.returning.join(", "));
1394
1414
  return {
1395
1415
  q: parts.join(" "),
1396
- params,
1416
+ params: Object.keys(params).length > 0 ? params : void 0,
1397
1417
  type_hints: Object.keys(type_hints).length ? type_hints : void 0
1398
1418
  };
1399
1419
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centia-io/sdk",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "Centia-io TypeScript SDK",
5
5
  "author": "Martin Høgh",
6
6
  "license": "MIT",