@xata.io/client 0.0.0-beta.bdce130 → 0.0.0-beta.ccaf25d

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/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # @xata.io/client
2
+
3
+ ## 0.4.0
4
+
5
+ ### Patch Changes
6
+
7
+ - b951331: Add support for new float column
8
+ - d470610: Add new getAll() method
9
+ - eaf92a8: Expose pagination constants (size and offset limits)
10
+ - 57fde77: Reduce subrequests for createMany
11
+ - eaf92a8: Implement schema-less client
12
+ - 97a3caa: Make createBranch from optional with empty branch
13
+
14
+ ## 0.3.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 1c0a454: Add API Client and internally use it
19
+
20
+ ### Patch Changes
21
+
22
+ - 122321c: Fix client in CF workers and Deno
23
+ - a2671b5: Allow cancel or resend workspace invites
24
+ - e73d470: Split insert and create
@@ -9,7 +9,7 @@ export interface XataApiClientOptions {
9
9
  host?: HostProvider;
10
10
  }
11
11
  export declare class XataApiClient {
12
- private extraProps;
12
+ #private;
13
13
  constructor(options: XataApiClientOptions);
14
14
  get user(): UserApi;
15
15
  get workspaces(): WorkspaceApi;
@@ -40,6 +40,8 @@ declare class WorkspaceApi {
40
40
  updateWorkspaceMemberRole(workspaceId: Schemas.WorkspaceID, userId: Schemas.UserID, role: Schemas.Role): Promise<void>;
41
41
  removeWorkspaceMember(workspaceId: Schemas.WorkspaceID, userId: Schemas.UserID): Promise<void>;
42
42
  inviteWorkspaceMember(workspaceId: Schemas.WorkspaceID, email: string, role: Schemas.Role): Promise<Schemas.WorkspaceInvite>;
43
+ cancelWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteId: Schemas.InviteID): Promise<void>;
44
+ resendWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteId: Schemas.InviteID): Promise<void>;
43
45
  acceptWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteKey: Schemas.InviteKey): Promise<void>;
44
46
  }
45
47
  declare class DatabaseApi {
@@ -81,10 +83,13 @@ declare class RecordsApi {
81
83
  private extraProps;
82
84
  constructor(extraProps: FetcherExtraProps);
83
85
  insertRecord(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, record: Record<string, any>): Promise<Types.InsertRecordResponse>;
84
- insertRecordWithID(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID, record: Record<string, any>, options?: Types.InsertRecordWithIDQueryParams): Promise<Types.InsertRecordWithIDResponse>;
86
+ insertRecordWithID(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID, record: Record<string, any>, options?: Types.InsertRecordWithIDQueryParams): Promise<Responses.RecordUpdateResponse>;
87
+ updateRecordWithID(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID, record: Record<string, any>, options?: Types.UpdateRecordWithIDQueryParams): Promise<Responses.RecordUpdateResponse>;
88
+ upsertRecordWithID(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID, record: Record<string, any>, options?: Types.UpsertRecordWithIDQueryParams): Promise<Responses.RecordUpdateResponse>;
85
89
  deleteRecord(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID): Promise<void>;
86
90
  getRecord(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID, options?: Types.GetRecordRequestBody): Promise<Schemas.XataRecord>;
87
91
  bulkInsertTableRecords(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, records: Record<string, any>[]): Promise<Types.BulkInsertTableRecordsResponse>;
88
92
  queryTable(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, query: Types.QueryTableRequestBody): Promise<Responses.QueryResponse>;
93
+ searchBranch(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, query: Types.SearchBranchRequestBody): Promise<Responses.SearchResponse>;
89
94
  }
90
95
  export {};
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _XataApiClient_extraProps;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.XataApiClient = void 0;
4
16
  const components_1 = require("./components");
@@ -6,39 +18,41 @@ const providers_1 = require("./providers");
6
18
  class XataApiClient {
7
19
  constructor(options) {
8
20
  var _a;
21
+ _XataApiClient_extraProps.set(this, void 0);
9
22
  const fetchImpl = typeof fetch !== 'undefined' ? fetch : options.fetch;
10
23
  if (!fetchImpl) {
11
24
  /** @todo add a link after docs exist */
12
25
  throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
13
26
  }
14
27
  const provider = (_a = options.host) !== null && _a !== void 0 ? _a : 'production';
15
- this.extraProps = {
28
+ __classPrivateFieldSet(this, _XataApiClient_extraProps, {
16
29
  apiUrl: (0, providers_1.getHostUrl)(provider, 'main'),
17
30
  workspacesApiUrl: (0, providers_1.getHostUrl)(provider, 'workspaces'),
18
31
  fetchImpl,
19
32
  apiKey: options.apiKey
20
- };
33
+ }, "f");
21
34
  }
22
35
  get user() {
23
- return new UserApi(this.extraProps);
36
+ return new UserApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
24
37
  }
25
38
  get workspaces() {
26
- return new WorkspaceApi(this.extraProps);
39
+ return new WorkspaceApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
27
40
  }
28
41
  get databases() {
29
- return new DatabaseApi(this.extraProps);
42
+ return new DatabaseApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
30
43
  }
31
44
  get branches() {
32
- return new BranchApi(this.extraProps);
45
+ return new BranchApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
33
46
  }
34
47
  get tables() {
35
- return new TableApi(this.extraProps);
48
+ return new TableApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
36
49
  }
37
50
  get records() {
38
- return new RecordsApi(this.extraProps);
51
+ return new RecordsApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
39
52
  }
40
53
  }
41
54
  exports.XataApiClient = XataApiClient;
55
+ _XataApiClient_extraProps = new WeakMap();
42
56
  class UserApi {
43
57
  constructor(extraProps) {
44
58
  this.extraProps = extraProps;
@@ -93,6 +107,12 @@ class WorkspaceApi {
93
107
  inviteWorkspaceMember(workspaceId, email, role) {
94
108
  return components_1.operationsByTag.workspaces.inviteWorkspaceMember(Object.assign({ pathParams: { workspaceId }, body: { email, role } }, this.extraProps));
95
109
  }
110
+ cancelWorkspaceMemberInvite(workspaceId, inviteId) {
111
+ return components_1.operationsByTag.workspaces.cancelWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteId } }, this.extraProps));
112
+ }
113
+ resendWorkspaceMemberInvite(workspaceId, inviteId) {
114
+ return components_1.operationsByTag.workspaces.resendWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteId } }, this.extraProps));
115
+ }
96
116
  acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
97
117
  return components_1.operationsByTag.workspaces.acceptWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteKey } }, this.extraProps));
98
118
  }
@@ -121,7 +141,7 @@ class BranchApi {
121
141
  getBranchDetails(workspace, database, branch) {
122
142
  return components_1.operationsByTag.branch.getBranchDetails(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` } }, this.extraProps));
123
143
  }
124
- createBranch(workspace, database, branch, from, options = {}) {
144
+ createBranch(workspace, database, branch, from = '', options = {}) {
125
145
  return components_1.operationsByTag.branch.createBranch(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` }, queryParams: { from }, body: options }, this.extraProps));
126
146
  }
127
147
  deleteBranch(workspace, database, branch) {
@@ -191,6 +211,12 @@ class RecordsApi {
191
211
  insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
192
212
  return components_1.operationsByTag.records.insertRecordWithID(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId }, queryParams: options, body: record }, this.extraProps));
193
213
  }
214
+ updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
215
+ return components_1.operationsByTag.records.updateRecordWithID(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId }, queryParams: options, body: record }, this.extraProps));
216
+ }
217
+ upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
218
+ return components_1.operationsByTag.records.upsertRecordWithID(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId }, queryParams: options, body: record }, this.extraProps));
219
+ }
194
220
  deleteRecord(workspace, database, branch, tableName, recordId) {
195
221
  return components_1.operationsByTag.records.deleteRecord(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId } }, this.extraProps));
196
222
  }
@@ -203,4 +229,7 @@ class RecordsApi {
203
229
  queryTable(workspace, database, branch, tableName, query) {
204
230
  return components_1.operationsByTag.records.queryTable(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName }, body: query }, this.extraProps));
205
231
  }
232
+ searchBranch(workspace, database, branch, query) {
233
+ return components_1.operationsByTag.records.searchBranch(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` }, body: query }, this.extraProps));
234
+ }
206
235
  }
@@ -161,22 +161,6 @@ export declare type InviteWorkspaceMemberVariables = {
161
161
  * Invite some user to join the workspace with the given role
162
162
  */
163
163
  export declare const inviteWorkspaceMember: (variables: InviteWorkspaceMemberVariables) => Promise<Schemas.WorkspaceInvite>;
164
- export declare type UpdateWorkspaceMemberInvitePathParams = {
165
- workspaceId: Schemas.WorkspaceID;
166
- inviteId: Schemas.InviteID;
167
- };
168
- export declare type UpdateWorkspaceMemberInviteRequestBody = {
169
- role: Schemas.Role;
170
- };
171
- export declare type UpdateWorkspaceMemberInviteVariables = {
172
- body: UpdateWorkspaceMemberInviteRequestBody;
173
- pathParams: UpdateWorkspaceMemberInvitePathParams;
174
- } & FetcherExtraProps;
175
- /**
176
- * This operation provides a way to update an invite.
177
- * The role can be updated while the email cannot.
178
- */
179
- export declare const updateWorkspaceMemberInvite: (variables: UpdateWorkspaceMemberInviteVariables) => Promise<Schemas.WorkspaceInvite>;
180
164
  export declare type CancelWorkspaceMemberInvitePathParams = {
181
165
  workspaceId: Schemas.WorkspaceID;
182
166
  inviteId: Schemas.InviteID;
@@ -566,12 +550,6 @@ export declare type InsertRecordWithIDQueryParams = {
566
550
  createOnly?: boolean;
567
551
  ifVersion?: number;
568
552
  };
569
- export declare type InsertRecordWithIDResponse = {
570
- id: string;
571
- xata: {
572
- version: number;
573
- };
574
- };
575
553
  export declare type InsertRecordWithIDVariables = {
576
554
  body?: Record<string, any>;
577
555
  pathParams: InsertRecordWithIDPathParams;
@@ -580,7 +558,37 @@ export declare type InsertRecordWithIDVariables = {
580
558
  /**
581
559
  * By default, IDs are auto-generated when data is insterted into Xata. Sending a request to this endpoint allows us to insert a record with a pre-existing ID, bypassing the default automatic ID generation.
582
560
  */
583
- export declare const insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<InsertRecordWithIDResponse>;
561
+ export declare const insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
562
+ export declare type UpdateRecordWithIDPathParams = {
563
+ dbBranchName: Schemas.DBBranchName;
564
+ tableName: Schemas.TableName;
565
+ recordId: Schemas.RecordID;
566
+ workspace: string;
567
+ };
568
+ export declare type UpdateRecordWithIDQueryParams = {
569
+ ifVersion?: number;
570
+ };
571
+ export declare type UpdateRecordWithIDVariables = {
572
+ body?: Record<string, any>;
573
+ pathParams: UpdateRecordWithIDPathParams;
574
+ queryParams?: UpdateRecordWithIDQueryParams;
575
+ } & FetcherExtraProps;
576
+ export declare const updateRecordWithID: (variables: UpdateRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
577
+ export declare type UpsertRecordWithIDPathParams = {
578
+ dbBranchName: Schemas.DBBranchName;
579
+ tableName: Schemas.TableName;
580
+ recordId: Schemas.RecordID;
581
+ workspace: string;
582
+ };
583
+ export declare type UpsertRecordWithIDQueryParams = {
584
+ ifVersion?: number;
585
+ };
586
+ export declare type UpsertRecordWithIDVariables = {
587
+ body?: Record<string, any>;
588
+ pathParams: UpsertRecordWithIDPathParams;
589
+ queryParams?: UpsertRecordWithIDQueryParams;
590
+ } & FetcherExtraProps;
591
+ export declare const upsertRecordWithID: (variables: UpsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
584
592
  export declare type DeleteRecordPathParams = {
585
593
  dbBranchName: Schemas.DBBranchName;
586
594
  tableName: Schemas.TableName;
@@ -1356,13 +1364,14 @@ export declare type SearchBranchPathParams = {
1356
1364
  export declare type SearchBranchRequestBody = {
1357
1365
  tables?: string[];
1358
1366
  query: string;
1367
+ fuzziness?: number;
1359
1368
  };
1360
1369
  export declare type SearchBranchVariables = {
1361
1370
  body: SearchBranchRequestBody;
1362
1371
  pathParams: SearchBranchPathParams;
1363
1372
  } & FetcherExtraProps;
1364
1373
  /**
1365
- * Run a free text search operation across the Database.
1374
+ * Run a free text search operation across the database branch.
1366
1375
  */
1367
1376
  export declare const searchBranch: (variables: SearchBranchVariables) => Promise<Responses.SearchResponse>;
1368
1377
  export declare const operationsByTag: {
@@ -1384,7 +1393,6 @@ export declare const operationsByTag: {
1384
1393
  updateWorkspaceMemberRole: (variables: UpdateWorkspaceMemberRoleVariables) => Promise<undefined>;
1385
1394
  removeWorkspaceMember: (variables: RemoveWorkspaceMemberVariables) => Promise<undefined>;
1386
1395
  inviteWorkspaceMember: (variables: InviteWorkspaceMemberVariables) => Promise<Schemas.WorkspaceInvite>;
1387
- updateWorkspaceMemberInvite: (variables: UpdateWorkspaceMemberInviteVariables) => Promise<Schemas.WorkspaceInvite>;
1388
1396
  cancelWorkspaceMemberInvite: (variables: CancelWorkspaceMemberInviteVariables) => Promise<undefined>;
1389
1397
  resendWorkspaceMemberInvite: (variables: ResendWorkspaceMemberInviteVariables) => Promise<undefined>;
1390
1398
  acceptWorkspaceMemberInvite: (variables: AcceptWorkspaceMemberInviteVariables) => Promise<undefined>;
@@ -1420,7 +1428,9 @@ export declare const operationsByTag: {
1420
1428
  };
1421
1429
  records: {
1422
1430
  insertRecord: (variables: InsertRecordVariables) => Promise<InsertRecordResponse>;
1423
- insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<InsertRecordWithIDResponse>;
1431
+ insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
1432
+ updateRecordWithID: (variables: UpdateRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
1433
+ upsertRecordWithID: (variables: UpsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
1424
1434
  deleteRecord: (variables: DeleteRecordVariables) => Promise<undefined>;
1425
1435
  getRecord: (variables: GetRecordVariables) => Promise<Schemas.XataRecord>;
1426
1436
  bulkInsertTableRecords: (variables: BulkInsertTableRecordsVariables) => Promise<BulkInsertTableRecordsResponse>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.operationsByTag = exports.searchBranch = exports.queryTable = exports.bulkInsertTableRecords = exports.getRecord = exports.deleteRecord = exports.insertRecordWithID = exports.insertRecord = exports.updateColumn = exports.deleteColumn = exports.getColumn = exports.addTableColumn = exports.getTableColumns = exports.setTableSchema = exports.getTableSchema = exports.updateTable = exports.deleteTable = exports.createTable = exports.getBranchStats = exports.getBranchMigrationPlan = exports.executeBranchMigrationPlan = exports.getBranchMigrationHistory = exports.getBranchMetadata = exports.updateBranchMetadata = exports.deleteBranch = exports.createBranch = exports.getBranchDetails = exports.deleteDatabase = exports.createDatabase = exports.getBranchList = exports.getDatabaseList = exports.acceptWorkspaceMemberInvite = exports.resendWorkspaceMemberInvite = exports.cancelWorkspaceMemberInvite = exports.updateWorkspaceMemberInvite = exports.inviteWorkspaceMember = exports.removeWorkspaceMember = exports.updateWorkspaceMemberRole = exports.getWorkspaceMembersList = exports.deleteWorkspace = exports.updateWorkspace = exports.getWorkspace = exports.getWorkspacesList = exports.createWorkspace = exports.deleteUserAPIKey = exports.createUserAPIKey = exports.getUserAPIKeys = exports.deleteUser = exports.updateUser = exports.getUser = void 0;
3
+ exports.searchBranch = exports.queryTable = exports.bulkInsertTableRecords = exports.getRecord = exports.deleteRecord = exports.upsertRecordWithID = exports.updateRecordWithID = exports.insertRecordWithID = exports.insertRecord = exports.updateColumn = exports.deleteColumn = exports.getColumn = exports.addTableColumn = exports.getTableColumns = exports.setTableSchema = exports.getTableSchema = exports.updateTable = exports.deleteTable = exports.createTable = exports.getBranchStats = exports.getBranchMigrationPlan = exports.executeBranchMigrationPlan = exports.getBranchMigrationHistory = exports.getBranchMetadata = exports.updateBranchMetadata = exports.deleteBranch = exports.createBranch = exports.getBranchDetails = exports.deleteDatabase = exports.createDatabase = exports.getBranchList = exports.getDatabaseList = exports.acceptWorkspaceMemberInvite = exports.resendWorkspaceMemberInvite = exports.cancelWorkspaceMemberInvite = exports.inviteWorkspaceMember = exports.removeWorkspaceMember = exports.updateWorkspaceMemberRole = exports.getWorkspaceMembersList = exports.deleteWorkspace = exports.updateWorkspace = exports.getWorkspace = exports.getWorkspacesList = exports.createWorkspace = exports.deleteUserAPIKey = exports.createUserAPIKey = exports.getUserAPIKeys = exports.deleteUser = exports.updateUser = exports.getUser = void 0;
4
+ exports.operationsByTag = void 0;
4
5
  /**
5
6
  * Generated by @openapi-codegen
6
7
  *
@@ -82,12 +83,6 @@ exports.removeWorkspaceMember = removeWorkspaceMember;
82
83
  */
83
84
  const inviteWorkspaceMember = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites', method: 'post' }, variables));
84
85
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
85
- /**
86
- * This operation provides a way to update an invite.
87
- * The role can be updated while the email cannot.
88
- */
89
- const updateWorkspaceMemberInvite = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites/{inviteId}', method: 'patch' }, variables));
90
- exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
91
86
  /**
92
87
  * This operation provides a way to cancel invites by deleting them. Already accepted invites cannot be deleted.
93
88
  */
@@ -222,6 +217,10 @@ exports.insertRecord = insertRecord;
222
217
  */
223
218
  const insertRecordWithID = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'put' }, variables));
224
219
  exports.insertRecordWithID = insertRecordWithID;
220
+ const updateRecordWithID = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'patch' }, variables));
221
+ exports.updateRecordWithID = updateRecordWithID;
222
+ const upsertRecordWithID = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'post' }, variables));
223
+ exports.upsertRecordWithID = upsertRecordWithID;
225
224
  const deleteRecord = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'delete' }, variables));
226
225
  exports.deleteRecord = deleteRecord;
227
226
  /**
@@ -943,7 +942,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
943
942
  const queryTable = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/query', method: 'post' }, variables));
944
943
  exports.queryTable = queryTable;
945
944
  /**
946
- * Run a free text search operation across the Database.
945
+ * Run a free text search operation across the database branch.
947
946
  */
948
947
  const searchBranch = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/search', method: 'post' }, variables));
949
948
  exports.searchBranch = searchBranch;
@@ -959,7 +958,6 @@ exports.operationsByTag = {
959
958
  updateWorkspaceMemberRole: exports.updateWorkspaceMemberRole,
960
959
  removeWorkspaceMember: exports.removeWorkspaceMember,
961
960
  inviteWorkspaceMember: exports.inviteWorkspaceMember,
962
- updateWorkspaceMemberInvite: exports.updateWorkspaceMemberInvite,
963
961
  cancelWorkspaceMemberInvite: exports.cancelWorkspaceMemberInvite,
964
962
  resendWorkspaceMemberInvite: exports.resendWorkspaceMemberInvite,
965
963
  acceptWorkspaceMemberInvite: exports.acceptWorkspaceMemberInvite
@@ -992,6 +990,8 @@ exports.operationsByTag = {
992
990
  records: {
993
991
  insertRecord: exports.insertRecord,
994
992
  insertRecordWithID: exports.insertRecordWithID,
993
+ updateRecordWithID: exports.updateRecordWithID,
994
+ upsertRecordWithID: exports.upsertRecordWithID,
995
995
  deleteRecord: exports.deleteRecord,
996
996
  getRecord: exports.getRecord,
997
997
  bulkInsertTableRecords: exports.bulkInsertTableRecords,
@@ -7,9 +7,10 @@ export declare type FetchImpl = (url: string, init?: {
7
7
  status: number;
8
8
  json(): Promise<any>;
9
9
  }>;
10
+ export declare type WorkspaceApiUrlBuilder = (path: string, pathParams: Record<string, string>) => string;
10
11
  export declare type FetcherExtraProps = {
11
12
  apiUrl: string;
12
- workspacesApiUrl: string;
13
+ workspacesApiUrl: string | WorkspaceApiUrlBuilder;
13
14
  fetchImpl: FetchImpl;
14
15
  apiKey: string;
15
16
  };
@@ -21,4 +22,4 @@ export declare type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> =
21
22
  queryParams?: TQueryParams;
22
23
  pathParams?: TPathParams;
23
24
  };
24
- export declare function fetch<TData, TBody extends Record<string, unknown> | undefined, THeaders extends Record<string, unknown>, TQueryParams extends Record<string, unknown>, TPathParams extends Record<string, string>>({ url, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> & FetcherExtraProps): Promise<TData>;
25
+ export declare function fetch<TData, TBody extends Record<string, unknown> | undefined, THeaders extends Record<string, unknown>, TQueryParams extends Record<string, unknown>, TPathParams extends Record<string, string>>({ url: path, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> & FetcherExtraProps): Promise<TData>;
@@ -16,28 +16,31 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
16
16
  return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
17
17
  };
18
18
  const fallbackError = { message: 'Network response was not ok' };
19
- function baseURLForWorkspace(workspacesApiUrl, workspace) {
20
- // Node.js on localhost won't resolve localhost subdomains unless mapped in /etc/hosts
21
- // So, instead, we use localhost without subdomains, but will add a Host header
22
- if (typeof window === 'undefined' && workspacesApiUrl.includes('localhost:')) {
23
- return workspacesApiUrl.replace('{workspaceId}.', '');
24
- }
25
- return workspacesApiUrl.replace('{workspaceId}', workspace);
19
+ function buildBaseUrl({ path, workspacesApiUrl, apiUrl, pathParams }) {
20
+ if (!(pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace))
21
+ return `${apiUrl}${path}`;
22
+ const url = typeof workspacesApiUrl === 'string' ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
23
+ return url.replace('{workspaceId}', pathParams.workspace);
26
24
  }
27
- function hostHeaderForWorkspace(workspacesApiUrl, workspace) {
28
- const url = baseURLForWorkspace(workspacesApiUrl, workspace);
29
- if (!url)
30
- return;
31
- const [, hostname] = url.split('://');
32
- return hostname;
25
+ // The host header is needed by Node.js on localhost.
26
+ // It is ignored by fetch() in the frontend
27
+ function hostHeader(url) {
28
+ var _a;
29
+ const pattern = /.*:\/\/(?<host>[^/]+).*/;
30
+ const { groups } = (_a = pattern.exec(url)) !== null && _a !== void 0 ? _a : {};
31
+ return (groups === null || groups === void 0 ? void 0 : groups.host) ? { Host: groups.host } : {};
33
32
  }
34
- function fetch({ url, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }) {
33
+ function fetch({ url: path, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }) {
35
34
  return __awaiter(this, void 0, void 0, function* () {
36
- const baseURL = (pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace) ? baseURLForWorkspace(workspacesApiUrl, pathParams.workspace) : apiUrl;
37
- const response = yield fetchImpl(`${baseURL}${resolveUrl(url, queryParams, pathParams)}`, {
35
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
36
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
37
+ // Node.js on localhost won't resolve localhost subdomains unless mapped in /etc/hosts
38
+ // So, instead, we use localhost without subdomains, but will add a Host header
39
+ const url = fullUrl.includes('localhost') ? fullUrl.replace(/^[^.]+\./, 'http://') : fullUrl;
40
+ const response = yield fetchImpl(url, {
38
41
  method: method.toUpperCase(),
39
42
  body: body ? JSON.stringify(body) : undefined,
40
- headers: Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, headers), { Authorization: `Bearer ${apiKey}` }), ((pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace) ? { Host: hostHeaderForWorkspace(workspacesApiUrl, pathParams.workspace) } : {}))
43
+ headers: Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, headers), hostHeader(fullUrl)), { Authorization: `Bearer ${apiKey}` })
41
44
  });
42
45
  // No content
43
46
  if (response.status === 204) {
package/dist/api/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -23,6 +23,12 @@ export declare type BranchMigrationPlan = {
23
23
  version: number;
24
24
  migration: Schemas.BranchMigration;
25
25
  };
26
+ export declare type RecordUpdateResponse = {
27
+ id: string;
28
+ xata: {
29
+ version: number;
30
+ };
31
+ };
26
32
  export declare type QueryResponse = {
27
33
  records: Schemas.XataRecord[];
28
34
  meta: Schemas.RecordsMetadata;
package/dist/index.d.ts CHANGED
@@ -1,64 +1,6 @@
1
- import { Page } from './schema/pagination';
2
- import { Query, QueryOptions } from './schema/query';
3
- import { Selectable, SelectableColumn, Select } from './schema/selection';
4
- export interface XataRecord {
5
- id: string;
6
- xata: {
7
- version: number;
8
- };
9
- read(): Promise<this>;
10
- update(data: Selectable<this>): Promise<this>;
11
- delete(): Promise<void>;
12
- }
13
- export declare abstract class Repository<T extends XataRecord> extends Query<T> {
14
- abstract create(object: Selectable<T>): Promise<T>;
15
- abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
16
- abstract read(id: string): Promise<T | null>;
17
- abstract update(id: string, object: Partial<T>): Promise<T>;
18
- abstract delete(id: string): void;
19
- abstract query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
20
- }
21
- export declare class RestRepository<T extends XataRecord> extends Repository<T> {
22
- #private;
23
- constructor(client: BaseClient<any>, table: string);
24
- request<T>(method: string, path: string, body?: unknown): Promise<T | undefined>;
25
- create(object: T): Promise<T>;
26
- createMany(objects: T[]): Promise<T[]>;
27
- read(id: string): Promise<T | null>;
28
- update(id: string, object: Partial<T>): Promise<T>;
29
- delete(id: string): Promise<void>;
30
- query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
31
- }
32
- interface RepositoryFactory {
33
- createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
34
- }
35
- export declare class RestRespositoryFactory implements RepositoryFactory {
36
- createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
37
- }
38
- declare type BranchStrategyValue = string | undefined | null;
39
- declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
40
- declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
41
- declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
42
- export declare type XataClientOptions = {
43
- fetch?: unknown;
44
- databaseURL?: string;
45
- branch: BranchStrategyOption;
46
- apiKey: string;
47
- repositoryFactory?: RepositoryFactory;
48
- };
49
- export declare class BaseClient<D extends Record<string, Repository<any>>> {
50
- options: XataClientOptions;
51
- private links;
52
- private branch;
53
- db: D;
54
- constructor(options: XataClientOptions, links: Links);
55
- initObject<T>(table: string, object: object): T;
56
- getBranch(): Promise<string>;
57
- }
58
1
  export declare class XataError extends Error {
59
2
  readonly status: number;
60
3
  constructor(message: string, status: number);
61
4
  }
62
- export declare type Links = Record<string, Array<string[]>>;
63
5
  export * from './api';
64
6
  export * from './schema';