@xata.io/client 0.26.2 → 0.26.3

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @xata.io/client@0.26.2 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.26.3 add-version /home/runner/work/client-ts/client-ts/packages/client
3
3
  > node ../../scripts/add-version-file.mjs
4
4
 
@@ -1,5 +1,5 @@
1
1
 
2
- > @xata.io/client@0.26.2 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.26.3 build /home/runner/work/client-ts/client-ts/packages/client
3
3
  > rimraf dist && rollup -c
4
4
 
5
5
  
@@ -7,7 +7,7 @@
7
7
  created dist/index.cjs in 1.3s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 964ms
10
+ created dist/index.mjs in 955ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 6.8s
13
+ created dist/index.d.ts in 11.6s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.26.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1144](https://github.com/xataio/client-ts/pull/1144) [`4910dce2`](https://github.com/xataio/client-ts/commit/4910dce29d3cc17d13aadf32e4eb476ffb571fad) Thanks [@SferaDev](https://github.com/SferaDev)! - Support for JSON and Revlinks
8
+
3
9
  ## 0.26.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -529,7 +529,7 @@ function defaultOnOpen(response) {
529
529
  }
530
530
  }
531
531
 
532
- const VERSION = "0.26.2";
532
+ const VERSION = "0.26.3";
533
533
 
534
534
  var __defProp$7 = Object.defineProperty;
535
535
  var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -2889,6 +2889,25 @@ function cleanFilter(filter) {
2889
2889
  return Object.keys(values).length > 0 ? values : void 0;
2890
2890
  }
2891
2891
 
2892
+ function stringifyJson(value) {
2893
+ if (!isDefined(value))
2894
+ return value;
2895
+ if (isString(value))
2896
+ return value;
2897
+ try {
2898
+ return JSON.stringify(value);
2899
+ } catch (e) {
2900
+ return value;
2901
+ }
2902
+ }
2903
+ function parseJson(value) {
2904
+ try {
2905
+ return JSON.parse(value);
2906
+ } catch (e) {
2907
+ return value;
2908
+ }
2909
+ }
2910
+
2892
2911
  var __defProp$5 = Object.defineProperty;
2893
2912
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2894
2913
  var __publicField$5 = (obj, key, value) => {
@@ -3359,6 +3378,24 @@ function isXataRecord(x) {
3359
3378
  return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
3360
3379
  }
3361
3380
 
3381
+ function isValidExpandedColumn(column) {
3382
+ return isObject(column) && isString(column.name);
3383
+ }
3384
+ function isValidSelectableColumns(columns) {
3385
+ if (!Array.isArray(columns)) {
3386
+ return false;
3387
+ }
3388
+ return columns.every((column) => {
3389
+ if (typeof column === "string") {
3390
+ return true;
3391
+ }
3392
+ if (typeof column === "object") {
3393
+ return isValidExpandedColumn(column);
3394
+ }
3395
+ return false;
3396
+ });
3397
+ }
3398
+
3362
3399
  function isSortFilterString(value) {
3363
3400
  return isString(value);
3364
3401
  }
@@ -3459,24 +3496,24 @@ class RestRepository extends Query {
3459
3496
  if (a.length === 0)
3460
3497
  return [];
3461
3498
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
3462
- const columns = isStringArray(b) ? b : ["*"];
3499
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3463
3500
  const result = await this.read(ids, columns);
3464
3501
  return result;
3465
3502
  }
3466
3503
  if (isString(a) && isObject(b)) {
3467
3504
  if (a === "")
3468
3505
  throw new Error("The id can't be empty");
3469
- const columns = isStringArray(c) ? c : void 0;
3506
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3470
3507
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
3471
3508
  }
3472
3509
  if (isObject(a) && isString(a.id)) {
3473
3510
  if (a.id === "")
3474
3511
  throw new Error("The id can't be empty");
3475
- const columns = isStringArray(b) ? b : void 0;
3512
+ const columns = isValidSelectableColumns(b) ? b : void 0;
3476
3513
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
3477
3514
  }
3478
3515
  if (isObject(a)) {
3479
- const columns = isStringArray(b) ? b : void 0;
3516
+ const columns = isValidSelectableColumns(b) ? b : void 0;
3480
3517
  return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
3481
3518
  }
3482
3519
  throw new Error("Invalid arguments for create method");
@@ -3484,7 +3521,7 @@ class RestRepository extends Query {
3484
3521
  }
3485
3522
  async read(a, b) {
3486
3523
  return __privateGet$4(this, _trace).call(this, "read", async () => {
3487
- const columns = isStringArray(b) ? b : ["*"];
3524
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3488
3525
  if (Array.isArray(a)) {
3489
3526
  if (a.length === 0)
3490
3527
  return [];
@@ -3511,7 +3548,13 @@ class RestRepository extends Query {
3511
3548
  ...__privateGet$4(this, _getFetchProps).call(this)
3512
3549
  });
3513
3550
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3514
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
3551
+ return initObject(
3552
+ __privateGet$4(this, _db),
3553
+ schemaTables,
3554
+ __privateGet$4(this, _table),
3555
+ response,
3556
+ columns
3557
+ );
3515
3558
  } catch (e) {
3516
3559
  if (isObject(e) && e.status === 404) {
3517
3560
  return null;
@@ -3553,17 +3596,17 @@ class RestRepository extends Query {
3553
3596
  ifVersion,
3554
3597
  upsert: false
3555
3598
  });
3556
- const columns = isStringArray(b) ? b : ["*"];
3599
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3557
3600
  const result = await this.read(a, columns);
3558
3601
  return result;
3559
3602
  }
3560
3603
  try {
3561
3604
  if (isString(a) && isObject(b)) {
3562
- const columns = isStringArray(c) ? c : void 0;
3605
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3563
3606
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3564
3607
  }
3565
3608
  if (isObject(a) && isString(a.id)) {
3566
- const columns = isStringArray(b) ? b : void 0;
3609
+ const columns = isValidSelectableColumns(b) ? b : void 0;
3567
3610
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3568
3611
  }
3569
3612
  } catch (error) {
@@ -3603,20 +3646,20 @@ class RestRepository extends Query {
3603
3646
  ifVersion,
3604
3647
  upsert: true
3605
3648
  });
3606
- const columns = isStringArray(b) ? b : ["*"];
3649
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3607
3650
  const result = await this.read(a, columns);
3608
3651
  return result;
3609
3652
  }
3610
3653
  if (isString(a) && isObject(b)) {
3611
3654
  if (a === "")
3612
3655
  throw new Error("The id can't be empty");
3613
- const columns = isStringArray(c) ? c : void 0;
3656
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3614
3657
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3615
3658
  }
3616
3659
  if (isObject(a) && isString(a.id)) {
3617
3660
  if (a.id === "")
3618
3661
  throw new Error("The id can't be empty");
3619
- const columns = isStringArray(c) ? c : void 0;
3662
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3620
3663
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3621
3664
  }
3622
3665
  if (!isDefined(a) && isObject(b)) {
@@ -3635,20 +3678,20 @@ class RestRepository extends Query {
3635
3678
  if (a.length === 0)
3636
3679
  return [];
3637
3680
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
3638
- const columns = isStringArray(b) ? b : ["*"];
3681
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3639
3682
  const result = await this.read(ids, columns);
3640
3683
  return result;
3641
3684
  }
3642
3685
  if (isString(a) && isObject(b)) {
3643
3686
  if (a === "")
3644
3687
  throw new Error("The id can't be empty");
3645
- const columns = isStringArray(c) ? c : void 0;
3688
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3646
3689
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
3647
3690
  }
3648
3691
  if (isObject(a) && isString(a.id)) {
3649
3692
  if (a.id === "")
3650
3693
  throw new Error("The id can't be empty");
3651
- const columns = isStringArray(c) ? c : void 0;
3694
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3652
3695
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3653
3696
  }
3654
3697
  if (!isDefined(a) && isObject(b)) {
@@ -3672,7 +3715,7 @@ class RestRepository extends Query {
3672
3715
  return o.id;
3673
3716
  throw new Error("Invalid arguments for delete method");
3674
3717
  });
3675
- const columns = isStringArray(b) ? b : ["*"];
3718
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3676
3719
  const result = await this.read(a, columns);
3677
3720
  await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
3678
3721
  return result;
@@ -3791,7 +3834,13 @@ class RestRepository extends Query {
3791
3834
  });
3792
3835
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3793
3836
  const records = objects.map(
3794
- (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
3837
+ (record) => initObject(
3838
+ __privateGet$4(this, _db),
3839
+ schemaTables,
3840
+ __privateGet$4(this, _table),
3841
+ record,
3842
+ data.columns ?? ["*"]
3843
+ )
3795
3844
  );
3796
3845
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
3797
3846
  return new Page(query, meta, records);
@@ -4097,6 +4146,9 @@ transformObjectToApi_fn = async function(object) {
4097
4146
  case "file[]":
4098
4147
  result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
4099
4148
  break;
4149
+ case "json":
4150
+ result[key] = stringifyJson(value);
4151
+ break;
4100
4152
  default:
4101
4153
  result[key] = value;
4102
4154
  }
@@ -4140,13 +4192,19 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4140
4192
  if (item === column.name) {
4141
4193
  return [...acc, "*"];
4142
4194
  }
4143
- if (item.startsWith(`${column.name}.`)) {
4195
+ if (isString(item) && item.startsWith(`${column.name}.`)) {
4144
4196
  const [, ...path] = item.split(".");
4145
4197
  return [...acc, path.join(".")];
4146
4198
  }
4147
4199
  return acc;
4148
4200
  }, []);
4149
- data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
4201
+ data[column.name] = initObject(
4202
+ db,
4203
+ schemaTables,
4204
+ linkTable,
4205
+ value,
4206
+ selectedLinkColumns
4207
+ );
4150
4208
  } else {
4151
4209
  data[column.name] = null;
4152
4210
  }
@@ -4158,6 +4216,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4158
4216
  case "file[]":
4159
4217
  data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
4160
4218
  break;
4219
+ case "json":
4220
+ data[column.name] = parseJson(value);
4221
+ break;
4161
4222
  default:
4162
4223
  data[column.name] = value ?? null;
4163
4224
  if (column.notNull === true && value === null) {
@@ -4173,12 +4234,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4173
4234
  return db[table].read(record["id"], columns2);
4174
4235
  };
4175
4236
  record.update = function(data2, b, c) {
4176
- const columns2 = isStringArray(b) ? b : ["*"];
4237
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
4177
4238
  const ifVersion = parseIfVersion(b, c);
4178
4239
  return db[table].update(record["id"], data2, columns2, { ifVersion });
4179
4240
  };
4180
4241
  record.replace = function(data2, b, c) {
4181
- const columns2 = isStringArray(b) ? b : ["*"];
4242
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
4182
4243
  const ifVersion = parseIfVersion(b, c);
4183
4244
  return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
4184
4245
  };
@@ -4211,7 +4272,7 @@ function extractId(value) {
4211
4272
  function isValidColumn(columns, column) {
4212
4273
  if (columns.includes("*"))
4213
4274
  return true;
4214
- return columns.filter((item) => item.startsWith(column.name)).length > 0;
4275
+ return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
4215
4276
  }
4216
4277
  function parseIfVersion(...args) {
4217
4278
  for (const arg of args) {
@@ -4896,6 +4957,8 @@ exports.isHostProviderAlias = isHostProviderAlias;
4896
4957
  exports.isHostProviderBuilder = isHostProviderBuilder;
4897
4958
  exports.isIdentifiable = isIdentifiable;
4898
4959
  exports.isNot = isNot;
4960
+ exports.isValidExpandedColumn = isValidExpandedColumn;
4961
+ exports.isValidSelectableColumns = isValidSelectableColumns;
4899
4962
  exports.isXataRecord = isXataRecord;
4900
4963
  exports.le = le;
4901
4964
  exports.lessEquals = lessEquals;