@xata.io/client 0.26.1 → 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.1 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,13 +1,13 @@
1
1
 
2
- > @xata.io/client@0.26.1 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
  
6
6
  src/index.ts → dist/index.cjs...
7
- created dist/index.cjs in 1.2s
7
+ created dist/index.cjs in 1.3s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 840ms
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 5.8s
13
+ created dist/index.d.ts in 11.6s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
9
+ ## 0.26.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1147](https://github.com/xataio/client-ts/pull/1147) [`22fccb51`](https://github.com/xataio/client-ts/commit/22fccb51709749c319897702c15749b74ce4b820) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose metadataSignedUrl
14
+
3
15
  ## 0.26.1
4
16
 
5
17
  ### 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.1";
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;
@@ -2850,7 +2850,8 @@ class XataFile {
2850
2850
  return {
2851
2851
  url: transformImage(this.url, ...options),
2852
2852
  signedUrl: transformImage(this.signedUrl, ...options),
2853
- metadataUrl: transformImage(this.url, ...options, { format: "json" })
2853
+ metadataUrl: transformImage(this.url, ...options, { format: "json" }),
2854
+ metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
2854
2855
  };
2855
2856
  }
2856
2857
  }
@@ -2888,6 +2889,25 @@ function cleanFilter(filter) {
2888
2889
  return Object.keys(values).length > 0 ? values : void 0;
2889
2890
  }
2890
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
+
2891
2911
  var __defProp$5 = Object.defineProperty;
2892
2912
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2893
2913
  var __publicField$5 = (obj, key, value) => {
@@ -3358,6 +3378,24 @@ function isXataRecord(x) {
3358
3378
  return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
3359
3379
  }
3360
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
+
3361
3399
  function isSortFilterString(value) {
3362
3400
  return isString(value);
3363
3401
  }
@@ -3458,24 +3496,24 @@ class RestRepository extends Query {
3458
3496
  if (a.length === 0)
3459
3497
  return [];
3460
3498
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
3461
- const columns = isStringArray(b) ? b : ["*"];
3499
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3462
3500
  const result = await this.read(ids, columns);
3463
3501
  return result;
3464
3502
  }
3465
3503
  if (isString(a) && isObject(b)) {
3466
3504
  if (a === "")
3467
3505
  throw new Error("The id can't be empty");
3468
- const columns = isStringArray(c) ? c : void 0;
3506
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3469
3507
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
3470
3508
  }
3471
3509
  if (isObject(a) && isString(a.id)) {
3472
3510
  if (a.id === "")
3473
3511
  throw new Error("The id can't be empty");
3474
- const columns = isStringArray(b) ? b : void 0;
3512
+ const columns = isValidSelectableColumns(b) ? b : void 0;
3475
3513
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
3476
3514
  }
3477
3515
  if (isObject(a)) {
3478
- const columns = isStringArray(b) ? b : void 0;
3516
+ const columns = isValidSelectableColumns(b) ? b : void 0;
3479
3517
  return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
3480
3518
  }
3481
3519
  throw new Error("Invalid arguments for create method");
@@ -3483,7 +3521,7 @@ class RestRepository extends Query {
3483
3521
  }
3484
3522
  async read(a, b) {
3485
3523
  return __privateGet$4(this, _trace).call(this, "read", async () => {
3486
- const columns = isStringArray(b) ? b : ["*"];
3524
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3487
3525
  if (Array.isArray(a)) {
3488
3526
  if (a.length === 0)
3489
3527
  return [];
@@ -3510,7 +3548,13 @@ class RestRepository extends Query {
3510
3548
  ...__privateGet$4(this, _getFetchProps).call(this)
3511
3549
  });
3512
3550
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3513
- 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
+ );
3514
3558
  } catch (e) {
3515
3559
  if (isObject(e) && e.status === 404) {
3516
3560
  return null;
@@ -3552,17 +3596,17 @@ class RestRepository extends Query {
3552
3596
  ifVersion,
3553
3597
  upsert: false
3554
3598
  });
3555
- const columns = isStringArray(b) ? b : ["*"];
3599
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3556
3600
  const result = await this.read(a, columns);
3557
3601
  return result;
3558
3602
  }
3559
3603
  try {
3560
3604
  if (isString(a) && isObject(b)) {
3561
- const columns = isStringArray(c) ? c : void 0;
3605
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3562
3606
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3563
3607
  }
3564
3608
  if (isObject(a) && isString(a.id)) {
3565
- const columns = isStringArray(b) ? b : void 0;
3609
+ const columns = isValidSelectableColumns(b) ? b : void 0;
3566
3610
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3567
3611
  }
3568
3612
  } catch (error) {
@@ -3602,20 +3646,20 @@ class RestRepository extends Query {
3602
3646
  ifVersion,
3603
3647
  upsert: true
3604
3648
  });
3605
- const columns = isStringArray(b) ? b : ["*"];
3649
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3606
3650
  const result = await this.read(a, columns);
3607
3651
  return result;
3608
3652
  }
3609
3653
  if (isString(a) && isObject(b)) {
3610
3654
  if (a === "")
3611
3655
  throw new Error("The id can't be empty");
3612
- const columns = isStringArray(c) ? c : void 0;
3656
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3613
3657
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
3614
3658
  }
3615
3659
  if (isObject(a) && isString(a.id)) {
3616
3660
  if (a.id === "")
3617
3661
  throw new Error("The id can't be empty");
3618
- const columns = isStringArray(c) ? c : void 0;
3662
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3619
3663
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
3620
3664
  }
3621
3665
  if (!isDefined(a) && isObject(b)) {
@@ -3634,20 +3678,20 @@ class RestRepository extends Query {
3634
3678
  if (a.length === 0)
3635
3679
  return [];
3636
3680
  const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
3637
- const columns = isStringArray(b) ? b : ["*"];
3681
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3638
3682
  const result = await this.read(ids, columns);
3639
3683
  return result;
3640
3684
  }
3641
3685
  if (isString(a) && isObject(b)) {
3642
3686
  if (a === "")
3643
3687
  throw new Error("The id can't be empty");
3644
- const columns = isStringArray(c) ? c : void 0;
3688
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3645
3689
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
3646
3690
  }
3647
3691
  if (isObject(a) && isString(a.id)) {
3648
3692
  if (a.id === "")
3649
3693
  throw new Error("The id can't be empty");
3650
- const columns = isStringArray(c) ? c : void 0;
3694
+ const columns = isValidSelectableColumns(c) ? c : void 0;
3651
3695
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
3652
3696
  }
3653
3697
  if (!isDefined(a) && isObject(b)) {
@@ -3671,7 +3715,7 @@ class RestRepository extends Query {
3671
3715
  return o.id;
3672
3716
  throw new Error("Invalid arguments for delete method");
3673
3717
  });
3674
- const columns = isStringArray(b) ? b : ["*"];
3718
+ const columns = isValidSelectableColumns(b) ? b : ["*"];
3675
3719
  const result = await this.read(a, columns);
3676
3720
  await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
3677
3721
  return result;
@@ -3790,7 +3834,13 @@ class RestRepository extends Query {
3790
3834
  });
3791
3835
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
3792
3836
  const records = objects.map(
3793
- (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
+ )
3794
3844
  );
3795
3845
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
3796
3846
  return new Page(query, meta, records);
@@ -4096,6 +4146,9 @@ transformObjectToApi_fn = async function(object) {
4096
4146
  case "file[]":
4097
4147
  result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
4098
4148
  break;
4149
+ case "json":
4150
+ result[key] = stringifyJson(value);
4151
+ break;
4099
4152
  default:
4100
4153
  result[key] = value;
4101
4154
  }
@@ -4139,13 +4192,19 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4139
4192
  if (item === column.name) {
4140
4193
  return [...acc, "*"];
4141
4194
  }
4142
- if (item.startsWith(`${column.name}.`)) {
4195
+ if (isString(item) && item.startsWith(`${column.name}.`)) {
4143
4196
  const [, ...path] = item.split(".");
4144
4197
  return [...acc, path.join(".")];
4145
4198
  }
4146
4199
  return acc;
4147
4200
  }, []);
4148
- 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
+ );
4149
4208
  } else {
4150
4209
  data[column.name] = null;
4151
4210
  }
@@ -4157,6 +4216,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4157
4216
  case "file[]":
4158
4217
  data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
4159
4218
  break;
4219
+ case "json":
4220
+ data[column.name] = parseJson(value);
4221
+ break;
4160
4222
  default:
4161
4223
  data[column.name] = value ?? null;
4162
4224
  if (column.notNull === true && value === null) {
@@ -4172,12 +4234,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
4172
4234
  return db[table].read(record["id"], columns2);
4173
4235
  };
4174
4236
  record.update = function(data2, b, c) {
4175
- const columns2 = isStringArray(b) ? b : ["*"];
4237
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
4176
4238
  const ifVersion = parseIfVersion(b, c);
4177
4239
  return db[table].update(record["id"], data2, columns2, { ifVersion });
4178
4240
  };
4179
4241
  record.replace = function(data2, b, c) {
4180
- const columns2 = isStringArray(b) ? b : ["*"];
4242
+ const columns2 = isValidSelectableColumns(b) ? b : ["*"];
4181
4243
  const ifVersion = parseIfVersion(b, c);
4182
4244
  return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
4183
4245
  };
@@ -4210,7 +4272,7 @@ function extractId(value) {
4210
4272
  function isValidColumn(columns, column) {
4211
4273
  if (columns.includes("*"))
4212
4274
  return true;
4213
- return columns.filter((item) => item.startsWith(column.name)).length > 0;
4275
+ return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
4214
4276
  }
4215
4277
  function parseIfVersion(...args) {
4216
4278
  for (const arg of args) {
@@ -4895,6 +4957,8 @@ exports.isHostProviderAlias = isHostProviderAlias;
4895
4957
  exports.isHostProviderBuilder = isHostProviderBuilder;
4896
4958
  exports.isIdentifiable = isIdentifiable;
4897
4959
  exports.isNot = isNot;
4960
+ exports.isValidExpandedColumn = isValidExpandedColumn;
4961
+ exports.isValidSelectableColumns = isValidSelectableColumns;
4898
4962
  exports.isXataRecord = isXataRecord;
4899
4963
  exports.le = le;
4900
4964
  exports.lessEquals = lessEquals;