@xata.io/client 0.0.0-next.v6c9e627772cbacc1977ba6ba82e6b403ac64c0b2 → 0.0.0-next.v83b49efdefdcee676ea1c61304ab4a0c5ac31054

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/dist/index.mjs CHANGED
@@ -526,7 +526,7 @@ function defaultOnOpen(response) {
526
526
  }
527
527
  }
528
528
 
529
- const VERSION = "0.29.1";
529
+ const VERSION = "0.29.2";
530
530
 
531
531
  class ErrorWithCause extends Error {
532
532
  constructor(message, options) {
@@ -738,6 +738,8 @@ async function fetch$1({
738
738
  "X-Xata-Client-ID": clientID ?? defaultClientID,
739
739
  "X-Xata-Session-ID": sessionID ?? generateUUID(),
740
740
  "X-Xata-Agent": xataAgent,
741
+ // Force field rename to xata_ internal properties
742
+ "X-Features": compact(["feat-internal-field-rename-api=1", customHeaders?.["X-Features"]]).join(" "),
741
743
  ...customHeaders,
742
744
  ...hostHeader(fullUrl),
743
745
  Authorization: `Bearer ${apiKey}`
@@ -2023,8 +2025,8 @@ cleanFilterConstraint_fn = function(column, value) {
2023
2025
  if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2024
2026
  return { $includes: value };
2025
2027
  }
2026
- if (columnType === "link" && isObject(value) && isString(value.id)) {
2027
- return value.id;
2028
+ if (columnType === "link" && isObject(value) && isString(value.xata_id)) {
2029
+ return value.xata_id;
2028
2030
  }
2029
2031
  return value;
2030
2032
  };
@@ -2052,12 +2054,7 @@ const RecordColumnTypes = [
2052
2054
  "json"
2053
2055
  ];
2054
2056
  function isIdentifiable(x) {
2055
- return isObject(x) && isString(x?.id);
2056
- }
2057
- function isXataRecord(x) {
2058
- const record = x;
2059
- const metadata = record?.getMetadata();
2060
- return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
2057
+ return isObject(x) && isString(x?.xata_id);
2061
2058
  }
2062
2059
 
2063
2060
  function isValidExpandedColumn(column) {
@@ -2184,11 +2181,14 @@ class RestRepository extends Query {
2184
2181
  const columns = isValidSelectableColumns(c) ? c : void 0;
2185
2182
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2186
2183
  }
2187
- if (isObject(a) && isString(a.id)) {
2188
- if (a.id === "")
2184
+ if (isObject(a) && isString(a.xata_id)) {
2185
+ if (a.xata_id === "")
2189
2186
  throw new Error("The id can't be empty");
2190
2187
  const columns = isValidSelectableColumns(b) ? b : void 0;
2191
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2188
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
2189
+ createOnly: true,
2190
+ ifVersion
2191
+ });
2192
2192
  }
2193
2193
  if (isObject(a)) {
2194
2194
  const columns = isValidSelectableColumns(b) ? b : void 0;
@@ -2204,9 +2204,9 @@ class RestRepository extends Query {
2204
2204
  if (a.length === 0)
2205
2205
  return [];
2206
2206
  const ids = a.map((item) => extractId(item));
2207
- const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
2207
+ const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
2208
2208
  const dictionary = finalObjects.reduce((acc, object) => {
2209
- acc[object.id] = object;
2209
+ acc[object.xata_id] = object;
2210
2210
  return acc;
2211
2211
  }, {});
2212
2212
  return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
@@ -2268,7 +2268,7 @@ class RestRepository extends Query {
2268
2268
  if (Array.isArray(a)) {
2269
2269
  if (a.length === 0)
2270
2270
  return [];
2271
- const existing = await this.read(a, ["id"]);
2271
+ const existing = await this.read(a, ["xata_id"]);
2272
2272
  const updates = a.filter((_item, index) => existing[index] !== null);
2273
2273
  await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2274
2274
  ifVersion,
@@ -2283,9 +2283,9 @@ class RestRepository extends Query {
2283
2283
  const columns = isValidSelectableColumns(c) ? c : void 0;
2284
2284
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2285
2285
  }
2286
- if (isObject(a) && isString(a.id)) {
2286
+ if (isObject(a) && isString(a.xata_id)) {
2287
2287
  const columns = isValidSelectableColumns(b) ? b : void 0;
2288
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2288
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2289
2289
  }
2290
2290
  } catch (error) {
2291
2291
  if (error.status === 422)
@@ -2334,16 +2334,16 @@ class RestRepository extends Query {
2334
2334
  const columns = isValidSelectableColumns(c) ? c : void 0;
2335
2335
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2336
2336
  }
2337
- if (isObject(a) && isString(a.id)) {
2338
- if (a.id === "")
2337
+ if (isObject(a) && isString(a.xata_id)) {
2338
+ if (a.xata_id === "")
2339
2339
  throw new Error("The id can't be empty");
2340
2340
  const columns = isValidSelectableColumns(c) ? c : void 0;
2341
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2341
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2342
2342
  }
2343
2343
  if (!isDefined(a) && isObject(b)) {
2344
2344
  return await this.create(b, c);
2345
2345
  }
2346
- if (isObject(a) && !isDefined(a.id)) {
2346
+ if (isObject(a) && !isDefined(a.xata_id)) {
2347
2347
  return await this.create(a, b);
2348
2348
  }
2349
2349
  throw new Error("Invalid arguments for createOrUpdate method");
@@ -2366,16 +2366,19 @@ class RestRepository extends Query {
2366
2366
  const columns = isValidSelectableColumns(c) ? c : void 0;
2367
2367
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2368
2368
  }
2369
- if (isObject(a) && isString(a.id)) {
2370
- if (a.id === "")
2369
+ if (isObject(a) && isString(a.xata_id)) {
2370
+ if (a.xata_id === "")
2371
2371
  throw new Error("The id can't be empty");
2372
2372
  const columns = isValidSelectableColumns(c) ? c : void 0;
2373
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2373
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
2374
+ createOnly: false,
2375
+ ifVersion
2376
+ });
2374
2377
  }
2375
2378
  if (!isDefined(a) && isObject(b)) {
2376
2379
  return await this.create(b, c);
2377
2380
  }
2378
- if (isObject(a) && !isDefined(a.id)) {
2381
+ if (isObject(a) && !isDefined(a.xata_id)) {
2379
2382
  return await this.create(a, b);
2380
2383
  }
2381
2384
  throw new Error("Invalid arguments for createOrReplace method");
@@ -2389,8 +2392,8 @@ class RestRepository extends Query {
2389
2392
  const ids = a.map((o) => {
2390
2393
  if (isString(o))
2391
2394
  return o;
2392
- if (isString(o.id))
2393
- return o.id;
2395
+ if (isString(o.xata_id))
2396
+ return o.xata_id;
2394
2397
  throw new Error("Invalid arguments for delete method");
2395
2398
  });
2396
2399
  const columns = isValidSelectableColumns(b) ? b : ["*"];
@@ -2401,8 +2404,8 @@ class RestRepository extends Query {
2401
2404
  if (isString(a)) {
2402
2405
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2403
2406
  }
2404
- if (isObject(a) && isString(a.id)) {
2405
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
2407
+ if (isObject(a) && isString(a.xata_id)) {
2408
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
2406
2409
  }
2407
2410
  throw new Error("Invalid arguments for delete method");
2408
2411
  });
@@ -2664,7 +2667,7 @@ _updateRecordWithID = new WeakSet();
2664
2667
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2665
2668
  if (!recordId)
2666
2669
  return null;
2667
- const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2670
+ const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2668
2671
  try {
2669
2672
  const response = await updateRecordWithID({
2670
2673
  pathParams: {
@@ -2689,9 +2692,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2689
2692
  };
2690
2693
  _updateRecords = new WeakSet();
2691
2694
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2692
- const operations = await promiseMap(objects, async ({ id, ...object }) => {
2695
+ const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
2693
2696
  const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2694
- return { update: { table: __privateGet$2(this, _table), id, ifVersion, upsert, fields } };
2697
+ return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
2695
2698
  });
2696
2699
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2697
2700
  const ids = [];
@@ -2796,12 +2799,12 @@ transformObjectToApi_fn = async function(object) {
2796
2799
  throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
2797
2800
  const result = {};
2798
2801
  for (const [key, value] of Object.entries(object)) {
2799
- if (key === "xata")
2802
+ if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
2800
2803
  continue;
2801
2804
  const type = schema.columns.find((column) => column.name === key)?.type;
2802
2805
  switch (type) {
2803
2806
  case "link": {
2804
- result[key] = isIdentifiable(value) ? value.id : value;
2807
+ result[key] = isIdentifiable(value) ? value.xata_id : value;
2805
2808
  break;
2806
2809
  }
2807
2810
  case "datetime": {
@@ -2825,8 +2828,7 @@ transformObjectToApi_fn = async function(object) {
2825
2828
  };
2826
2829
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2827
2830
  const data = {};
2828
- const { xata, ...rest } = object ?? {};
2829
- Object.assign(data, rest);
2831
+ Object.assign(data, { ...object });
2830
2832
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2831
2833
  if (!columns)
2832
2834
  console.error(`Table ${table} not found in schema`);
@@ -2889,28 +2891,21 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2889
2891
  }
2890
2892
  }
2891
2893
  const record = { ...data };
2892
- const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2893
2894
  record.read = function(columns2) {
2894
- return db[table].read(record["id"], columns2);
2895
+ return db[table].read(record["xata_id"], columns2);
2895
2896
  };
2896
2897
  record.update = function(data2, b, c) {
2897
2898
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2898
2899
  const ifVersion = parseIfVersion(b, c);
2899
- return db[table].update(record["id"], data2, columns2, { ifVersion });
2900
+ return db[table].update(record["xata_id"], data2, columns2, { ifVersion });
2900
2901
  };
2901
2902
  record.replace = function(data2, b, c) {
2902
2903
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2903
2904
  const ifVersion = parseIfVersion(b, c);
2904
- return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2905
+ return db[table].createOrReplace(record["xata_id"], data2, columns2, { ifVersion });
2905
2906
  };
2906
2907
  record.delete = function() {
2907
- return db[table].delete(record["id"]);
2908
- };
2909
- if (metadata !== void 0) {
2910
- record.xata = Object.freeze(metadata);
2911
- }
2912
- record.getMetadata = function() {
2913
- return record.xata;
2908
+ return db[table].delete(record["xata_id"]);
2914
2909
  };
2915
2910
  record.toSerializable = function() {
2916
2911
  return JSON.parse(JSON.stringify(record));
@@ -2918,7 +2913,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2918
2913
  record.toString = function() {
2919
2914
  return JSON.stringify(record);
2920
2915
  };
2921
- for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
2916
+ for (const prop of ["read", "update", "replace", "delete", "toSerializable", "toString"]) {
2922
2917
  Object.defineProperty(record, prop, { enumerable: false });
2923
2918
  }
2924
2919
  Object.freeze(record);
@@ -2927,8 +2922,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2927
2922
  function extractId(value) {
2928
2923
  if (isString(value))
2929
2924
  return value;
2930
- if (isObject(value) && isString(value.id))
2931
- return value.id;
2925
+ if (isObject(value) && isString(value.xata_id))
2926
+ return value.xata_id;
2932
2927
  return void 0;
2933
2928
  }
2934
2929
  function isValidColumn(columns, column) {
@@ -3116,7 +3111,7 @@ class SearchPlugin extends XataPlugin {
3116
3111
  return {
3117
3112
  totalCount,
3118
3113
  records: records.map((record) => {
3119
- const { table = "orphan" } = record.xata;
3114
+ const table = record.xata_table;
3120
3115
  return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
3121
3116
  })
3122
3117
  };
@@ -3124,7 +3119,7 @@ class SearchPlugin extends XataPlugin {
3124
3119
  byTable: async (query, options = {}) => {
3125
3120
  const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3126
3121
  const records = rawRecords.reduce((acc, record) => {
3127
- const { table = "orphan" } = record.xata;
3122
+ const table = record.xata_table;
3128
3123
  const items = acc[table] ?? [];
3129
3124
  const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
3130
3125
  return { ...acc, [table]: [...items, item] };
@@ -3462,5 +3457,5 @@ class XataError extends Error {
3462
3457
  }
3463
3458
  }
3464
3459
 
3465
- export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, PageRecordArray, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, adaptTable, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationJobStatus, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseSettings, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationHistory, getMigrationJobStatus, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateDatabaseSettings, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
3460
+ export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, PageRecordArray, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, adaptTable, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationJobStatus, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseSettings, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationHistory, getMigrationJobStatus, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateDatabaseSettings, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
3466
3461
  //# sourceMappingURL=index.mjs.map