@xata.io/client 0.0.0-beta.64a31a3 → 0.0.0-beta.7c075f4
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/api/client.d.ts +4 -1
- package/dist/api/client.js +9 -0
- package/dist/api/components.d.ts +36 -50
- package/dist/api/components.js +8 -21
- package/dist/api/fetcher.js +9 -9
- package/dist/api/index.js +5 -1
- package/dist/api/parameters.d.ts +0 -1
- package/dist/api/responses.d.ts +6 -0
- package/dist/api/schemas.d.ts +1 -1
- package/dist/index.d.ts +0 -57
- package/dist/index.js +6 -236
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +13 -1
- package/dist/schema/query.d.ts +1 -1
- package/dist/schema/query.js +4 -4
- package/dist/schema/record.d.ts +10 -0
- package/dist/schema/record.js +2 -0
- package/dist/schema/repository.d.ts +52 -0
- package/dist/schema/repository.js +260 -0
- package/dist/schema/selection.d.ts +3 -7
- package/dist/util/lang.d.ts +1 -0
- package/package.json +2 -2
package/dist/api/client.d.ts
CHANGED
@@ -81,10 +81,13 @@ declare class RecordsApi {
|
|
81
81
|
private extraProps;
|
82
82
|
constructor(extraProps: FetcherExtraProps);
|
83
83
|
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<
|
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<Responses.RecordUpdateResponse>;
|
85
|
+
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>;
|
86
|
+
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
87
|
deleteRecord(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID): Promise<void>;
|
86
88
|
getRecord(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, recordId: Schemas.RecordID, options?: Types.GetRecordRequestBody): Promise<Schemas.XataRecord>;
|
87
89
|
bulkInsertTableRecords(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, records: Record<string, any>[]): Promise<Types.BulkInsertTableRecordsResponse>;
|
88
90
|
queryTable(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, tableName: Schemas.TableName, query: Types.QueryTableRequestBody): Promise<Responses.QueryResponse>;
|
91
|
+
searchBranch(workspace: Schemas.WorkspaceID, database: Schemas.DBName, branch: Schemas.BranchName, query: Types.SearchBranchRequestBody): Promise<Responses.SearchResponse>;
|
89
92
|
}
|
90
93
|
export {};
|
package/dist/api/client.js
CHANGED
@@ -205,6 +205,12 @@ class RecordsApi {
|
|
205
205
|
insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
206
206
|
return components_1.operationsByTag.records.insertRecordWithID(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId }, queryParams: options, body: record }, this.extraProps));
|
207
207
|
}
|
208
|
+
updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
209
|
+
return components_1.operationsByTag.records.updateRecordWithID(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId }, queryParams: options, body: record }, this.extraProps));
|
210
|
+
}
|
211
|
+
upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
212
|
+
return components_1.operationsByTag.records.upsertRecordWithID(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId }, queryParams: options, body: record }, this.extraProps));
|
213
|
+
}
|
208
214
|
deleteRecord(workspace, database, branch, tableName, recordId) {
|
209
215
|
return components_1.operationsByTag.records.deleteRecord(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId } }, this.extraProps));
|
210
216
|
}
|
@@ -217,4 +223,7 @@ class RecordsApi {
|
|
217
223
|
queryTable(workspace, database, branch, tableName, query) {
|
218
224
|
return components_1.operationsByTag.records.queryTable(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName }, body: query }, this.extraProps));
|
219
225
|
}
|
226
|
+
searchBranch(workspace, database, branch, query) {
|
227
|
+
return components_1.operationsByTag.records.searchBranch(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` }, body: query }, this.extraProps));
|
228
|
+
}
|
220
229
|
}
|
package/dist/api/components.d.ts
CHANGED
@@ -161,44 +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
|
-
export declare type CancelWorkspaceMemberInvitePathParams = {
|
181
|
-
workspaceId: Schemas.WorkspaceID;
|
182
|
-
inviteId: Schemas.InviteID;
|
183
|
-
};
|
184
|
-
export declare type CancelWorkspaceMemberInviteVariables = {
|
185
|
-
pathParams: CancelWorkspaceMemberInvitePathParams;
|
186
|
-
} & FetcherExtraProps;
|
187
|
-
/**
|
188
|
-
* This operation provides a way to cancel invites by deleting them. Already accepted invites cannot be deleted.
|
189
|
-
*/
|
190
|
-
export declare const cancelWorkspaceMemberInvite: (variables: CancelWorkspaceMemberInviteVariables) => Promise<undefined>;
|
191
|
-
export declare type ResendWorkspaceMemberInvitePathParams = {
|
192
|
-
workspaceId: Schemas.WorkspaceID;
|
193
|
-
inviteId: Schemas.InviteID;
|
194
|
-
};
|
195
|
-
export declare type ResendWorkspaceMemberInviteVariables = {
|
196
|
-
pathParams: ResendWorkspaceMemberInvitePathParams;
|
197
|
-
} & FetcherExtraProps;
|
198
|
-
/**
|
199
|
-
* This operation provides a way to resend an Invite notification. Invite notifications can only be sent for Invites not yet accepted.
|
200
|
-
*/
|
201
|
-
export declare const resendWorkspaceMemberInvite: (variables: ResendWorkspaceMemberInviteVariables) => Promise<undefined>;
|
202
164
|
export declare type AcceptWorkspaceMemberInvitePathParams = {
|
203
165
|
workspaceId: Schemas.WorkspaceID;
|
204
166
|
inviteKey: Schemas.InviteKey;
|
@@ -566,12 +528,6 @@ export declare type InsertRecordWithIDQueryParams = {
|
|
566
528
|
createOnly?: boolean;
|
567
529
|
ifVersion?: number;
|
568
530
|
};
|
569
|
-
export declare type InsertRecordWithIDResponse = {
|
570
|
-
id: string;
|
571
|
-
xata: {
|
572
|
-
version: number;
|
573
|
-
};
|
574
|
-
};
|
575
531
|
export declare type InsertRecordWithIDVariables = {
|
576
532
|
body?: Record<string, any>;
|
577
533
|
pathParams: InsertRecordWithIDPathParams;
|
@@ -580,7 +536,37 @@ export declare type InsertRecordWithIDVariables = {
|
|
580
536
|
/**
|
581
537
|
* 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
538
|
*/
|
583
|
-
export declare const insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<
|
539
|
+
export declare const insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
|
540
|
+
export declare type UpdateRecordWithIDPathParams = {
|
541
|
+
dbBranchName: Schemas.DBBranchName;
|
542
|
+
tableName: Schemas.TableName;
|
543
|
+
recordId: Schemas.RecordID;
|
544
|
+
workspace: string;
|
545
|
+
};
|
546
|
+
export declare type UpdateRecordWithIDQueryParams = {
|
547
|
+
ifVersion?: number;
|
548
|
+
};
|
549
|
+
export declare type UpdateRecordWithIDVariables = {
|
550
|
+
body?: Record<string, any>;
|
551
|
+
pathParams: UpdateRecordWithIDPathParams;
|
552
|
+
queryParams?: UpdateRecordWithIDQueryParams;
|
553
|
+
} & FetcherExtraProps;
|
554
|
+
export declare const updateRecordWithID: (variables: UpdateRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
|
555
|
+
export declare type UpsertRecordWithIDPathParams = {
|
556
|
+
dbBranchName: Schemas.DBBranchName;
|
557
|
+
tableName: Schemas.TableName;
|
558
|
+
recordId: Schemas.RecordID;
|
559
|
+
workspace: string;
|
560
|
+
};
|
561
|
+
export declare type UpsertRecordWithIDQueryParams = {
|
562
|
+
ifVersion?: number;
|
563
|
+
};
|
564
|
+
export declare type UpsertRecordWithIDVariables = {
|
565
|
+
body?: Record<string, any>;
|
566
|
+
pathParams: UpsertRecordWithIDPathParams;
|
567
|
+
queryParams?: UpsertRecordWithIDQueryParams;
|
568
|
+
} & FetcherExtraProps;
|
569
|
+
export declare const upsertRecordWithID: (variables: UpsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
|
584
570
|
export declare type DeleteRecordPathParams = {
|
585
571
|
dbBranchName: Schemas.DBBranchName;
|
586
572
|
tableName: Schemas.TableName;
|
@@ -1356,13 +1342,14 @@ export declare type SearchBranchPathParams = {
|
|
1356
1342
|
export declare type SearchBranchRequestBody = {
|
1357
1343
|
tables?: string[];
|
1358
1344
|
query: string;
|
1345
|
+
fuzziness?: number;
|
1359
1346
|
};
|
1360
1347
|
export declare type SearchBranchVariables = {
|
1361
1348
|
body: SearchBranchRequestBody;
|
1362
1349
|
pathParams: SearchBranchPathParams;
|
1363
1350
|
} & FetcherExtraProps;
|
1364
1351
|
/**
|
1365
|
-
* Run a free text search operation across the
|
1352
|
+
* Run a free text search operation across the database branch.
|
1366
1353
|
*/
|
1367
1354
|
export declare const searchBranch: (variables: SearchBranchVariables) => Promise<Responses.SearchResponse>;
|
1368
1355
|
export declare const operationsByTag: {
|
@@ -1384,9 +1371,6 @@ export declare const operationsByTag: {
|
|
1384
1371
|
updateWorkspaceMemberRole: (variables: UpdateWorkspaceMemberRoleVariables) => Promise<undefined>;
|
1385
1372
|
removeWorkspaceMember: (variables: RemoveWorkspaceMemberVariables) => Promise<undefined>;
|
1386
1373
|
inviteWorkspaceMember: (variables: InviteWorkspaceMemberVariables) => Promise<Schemas.WorkspaceInvite>;
|
1387
|
-
updateWorkspaceMemberInvite: (variables: UpdateWorkspaceMemberInviteVariables) => Promise<Schemas.WorkspaceInvite>;
|
1388
|
-
cancelWorkspaceMemberInvite: (variables: CancelWorkspaceMemberInviteVariables) => Promise<undefined>;
|
1389
|
-
resendWorkspaceMemberInvite: (variables: ResendWorkspaceMemberInviteVariables) => Promise<undefined>;
|
1390
1374
|
acceptWorkspaceMemberInvite: (variables: AcceptWorkspaceMemberInviteVariables) => Promise<undefined>;
|
1391
1375
|
};
|
1392
1376
|
database: {
|
@@ -1420,7 +1404,9 @@ export declare const operationsByTag: {
|
|
1420
1404
|
};
|
1421
1405
|
records: {
|
1422
1406
|
insertRecord: (variables: InsertRecordVariables) => Promise<InsertRecordResponse>;
|
1423
|
-
insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<
|
1407
|
+
insertRecordWithID: (variables: InsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
|
1408
|
+
updateRecordWithID: (variables: UpdateRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
|
1409
|
+
upsertRecordWithID: (variables: UpsertRecordWithIDVariables) => Promise<Responses.RecordUpdateResponse>;
|
1424
1410
|
deleteRecord: (variables: DeleteRecordVariables) => Promise<undefined>;
|
1425
1411
|
getRecord: (variables: GetRecordVariables) => Promise<Schemas.XataRecord>;
|
1426
1412
|
bulkInsertTableRecords: (variables: BulkInsertTableRecordsVariables) => Promise<BulkInsertTableRecordsResponse>;
|
package/dist/api/components.js
CHANGED
@@ -1,6 +1,6 @@
|
|
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.
|
3
|
+
exports.operationsByTag = 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.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
4
|
/**
|
5
5
|
* Generated by @openapi-codegen
|
6
6
|
*
|
@@ -82,22 +82,6 @@ exports.removeWorkspaceMember = removeWorkspaceMember;
|
|
82
82
|
*/
|
83
83
|
const inviteWorkspaceMember = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites', method: 'post' }, variables));
|
84
84
|
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
|
-
/**
|
92
|
-
* This operation provides a way to cancel invites by deleting them. Already accepted invites cannot be deleted.
|
93
|
-
*/
|
94
|
-
const cancelWorkspaceMemberInvite = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites/{inviteId}', method: 'delete' }, variables));
|
95
|
-
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
96
|
-
/**
|
97
|
-
* This operation provides a way to resend an Invite notification. Invite notifications can only be sent for Invites not yet accepted.
|
98
|
-
*/
|
99
|
-
const resendWorkspaceMemberInvite = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites/{inviteId}/resend', method: 'post' }, variables));
|
100
|
-
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
101
85
|
/**
|
102
86
|
* Accept the invitation to join a workspace. If the operation succeeds the user will be a member of the workspace
|
103
87
|
*/
|
@@ -222,6 +206,10 @@ exports.insertRecord = insertRecord;
|
|
222
206
|
*/
|
223
207
|
const insertRecordWithID = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'put' }, variables));
|
224
208
|
exports.insertRecordWithID = insertRecordWithID;
|
209
|
+
const updateRecordWithID = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'patch' }, variables));
|
210
|
+
exports.updateRecordWithID = updateRecordWithID;
|
211
|
+
const upsertRecordWithID = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'post' }, variables));
|
212
|
+
exports.upsertRecordWithID = upsertRecordWithID;
|
225
213
|
const deleteRecord = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/data/{recordId}', method: 'delete' }, variables));
|
226
214
|
exports.deleteRecord = deleteRecord;
|
227
215
|
/**
|
@@ -943,7 +931,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
943
931
|
const queryTable = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/tables/{tableName}/query', method: 'post' }, variables));
|
944
932
|
exports.queryTable = queryTable;
|
945
933
|
/**
|
946
|
-
* Run a free text search operation across the
|
934
|
+
* Run a free text search operation across the database branch.
|
947
935
|
*/
|
948
936
|
const searchBranch = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/db/{dbBranchName}/search', method: 'post' }, variables));
|
949
937
|
exports.searchBranch = searchBranch;
|
@@ -959,9 +947,6 @@ exports.operationsByTag = {
|
|
959
947
|
updateWorkspaceMemberRole: exports.updateWorkspaceMemberRole,
|
960
948
|
removeWorkspaceMember: exports.removeWorkspaceMember,
|
961
949
|
inviteWorkspaceMember: exports.inviteWorkspaceMember,
|
962
|
-
updateWorkspaceMemberInvite: exports.updateWorkspaceMemberInvite,
|
963
|
-
cancelWorkspaceMemberInvite: exports.cancelWorkspaceMemberInvite,
|
964
|
-
resendWorkspaceMemberInvite: exports.resendWorkspaceMemberInvite,
|
965
950
|
acceptWorkspaceMemberInvite: exports.acceptWorkspaceMemberInvite
|
966
951
|
},
|
967
952
|
database: { getDatabaseList: exports.getDatabaseList, createDatabase: exports.createDatabase, deleteDatabase: exports.deleteDatabase },
|
@@ -992,6 +977,8 @@ exports.operationsByTag = {
|
|
992
977
|
records: {
|
993
978
|
insertRecord: exports.insertRecord,
|
994
979
|
insertRecordWithID: exports.insertRecordWithID,
|
980
|
+
updateRecordWithID: exports.updateRecordWithID,
|
981
|
+
upsertRecordWithID: exports.upsertRecordWithID,
|
995
982
|
deleteRecord: exports.deleteRecord,
|
996
983
|
getRecord: exports.getRecord,
|
997
984
|
bulkInsertTableRecords: exports.bulkInsertTableRecords,
|
package/dist/api/fetcher.js
CHANGED
@@ -20,27 +20,27 @@ function buildBaseUrl({ path, workspacesApiUrl, apiUrl, pathParams }) {
|
|
20
20
|
if (!(pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace))
|
21
21
|
return `${apiUrl}${path}`;
|
22
22
|
const url = typeof workspacesApiUrl === 'string' ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
23
|
-
// Node.js on localhost won't resolve localhost subdomains unless mapped in /etc/hosts
|
24
|
-
// So, instead, we use localhost without subdomains, but will add a Host header
|
25
|
-
if (typeof window === 'undefined' && url.includes('localhost:')) {
|
26
|
-
return url.replace('{workspaceId}.', '');
|
27
|
-
}
|
28
23
|
return url.replace('{workspaceId}', pathParams.workspace);
|
29
24
|
}
|
30
|
-
|
25
|
+
// The host header is needed by Node.js on localhost.
|
26
|
+
// It is ignored by fetch() in the frontend
|
27
|
+
function hostHeader(url) {
|
31
28
|
var _a;
|
32
29
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
33
30
|
const { groups } = (_a = pattern.exec(url)) !== null && _a !== void 0 ? _a : {};
|
34
|
-
return groups === null || groups === void 0 ? void 0 : groups.host;
|
31
|
+
return (groups === null || groups === void 0 ? void 0 : groups.host) ? { Host: groups.host } : {};
|
35
32
|
}
|
36
33
|
function fetch({ url: path, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }) {
|
37
34
|
return __awaiter(this, void 0, void 0, function* () {
|
38
35
|
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
39
|
-
const
|
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
40
|
const response = yield fetchImpl(url, {
|
41
41
|
method: method.toUpperCase(),
|
42
42
|
body: body ? JSON.stringify(body) : undefined,
|
43
|
-
headers: Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, headers), { Authorization: `Bearer ${apiKey}` })
|
43
|
+
headers: Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, headers), hostHeader(fullUrl)), { Authorization: `Bearer ${apiKey}` })
|
44
44
|
});
|
45
45
|
// No content
|
46
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.
|
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];
|
package/dist/api/parameters.d.ts
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
*/
|
6
6
|
import type * as Schemas from './schemas';
|
7
7
|
export declare type APIKeyNameParam = Schemas.APIKeyName;
|
8
|
-
export declare type InviteIDParam = Schemas.InviteID;
|
9
8
|
export declare type InviteKeyParam = Schemas.InviteKey;
|
10
9
|
export declare type UserIDParam = Schemas.UserID;
|
11
10
|
export declare type WorkspaceIDParam = Schemas.WorkspaceID;
|
package/dist/api/responses.d.ts
CHANGED
@@ -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/api/schemas.d.ts
CHANGED
@@ -130,7 +130,7 @@ export declare type Table = {
|
|
130
130
|
*/
|
131
131
|
export declare type Column = {
|
132
132
|
name: string;
|
133
|
-
type: 'bool' | 'int' | '
|
133
|
+
type: 'bool' | 'int' | 'string' | 'text' | 'email' | 'multiple' | 'link' | 'object';
|
134
134
|
link?: {
|
135
135
|
table: string;
|
136
136
|
};
|
package/dist/index.d.ts
CHANGED
@@ -1,63 +1,6 @@
|
|
1
|
-
import { FetchImpl } from './api/fetcher';
|
2
|
-
import { Page } from './schema/pagination';
|
3
|
-
import { Query, QueryOptions } from './schema/query';
|
4
|
-
import { Selectable, SelectableColumn, Select } from './schema/selection';
|
5
|
-
export interface XataRecord {
|
6
|
-
id: string;
|
7
|
-
xata: {
|
8
|
-
version: number;
|
9
|
-
};
|
10
|
-
read(): Promise<this>;
|
11
|
-
update(data: Selectable<this>): Promise<this>;
|
12
|
-
delete(): Promise<void>;
|
13
|
-
}
|
14
|
-
export declare abstract class Repository<T extends XataRecord> extends Query<T> {
|
15
|
-
abstract create(object: Selectable<T>): Promise<T>;
|
16
|
-
abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
|
17
|
-
abstract read(id: string): Promise<T | null>;
|
18
|
-
abstract update(id: string, object: Partial<T>): Promise<T>;
|
19
|
-
abstract delete(id: string): void;
|
20
|
-
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>>;
|
21
|
-
}
|
22
|
-
export declare class RestRepository<T extends XataRecord> extends Repository<T> {
|
23
|
-
#private;
|
24
|
-
constructor(client: BaseClient<any>, table: string);
|
25
|
-
create(object: T): Promise<T>;
|
26
|
-
createMany(objects: T[]): Promise<T[]>;
|
27
|
-
read(recordId: string): Promise<T | null>;
|
28
|
-
update(recordId: string, object: Partial<T>): Promise<T>;
|
29
|
-
delete(recordId: 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?: FetchImpl;
|
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
|
-
#private;
|
51
|
-
options: XataClientOptions;
|
52
|
-
db: D;
|
53
|
-
constructor(options: XataClientOptions, links: Links);
|
54
|
-
initObject<T>(table: string, object: object): T;
|
55
|
-
getBranch(): Promise<string>;
|
56
|
-
}
|
57
1
|
export declare class XataError extends Error {
|
58
2
|
readonly status: number;
|
59
3
|
constructor(message: string, status: number);
|
60
4
|
}
|
61
|
-
export declare type Links = Record<string, Array<string[]>>;
|
62
5
|
export * from './api';
|
63
6
|
export * from './schema';
|
package/dist/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.
|
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];
|
@@ -9,230 +13,8 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
15
|
};
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
19
|
-
});
|
20
|
-
};
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
24
|
-
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");
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
26
|
-
};
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
29
|
-
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");
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
31
|
-
};
|
32
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
33
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
34
|
-
var m = o[Symbol.asyncIterator], i;
|
35
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
36
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
37
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
38
|
-
};
|
39
|
-
var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _BaseClient_links, _BaseClient_branch;
|
40
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
41
|
-
exports.XataError =
|
42
|
-
const api_1 = require("./api");
|
43
|
-
const filters_1 = require("./schema/filters");
|
44
|
-
const pagination_1 = require("./schema/pagination");
|
45
|
-
const query_1 = require("./schema/query");
|
46
|
-
class Repository extends query_1.Query {
|
47
|
-
}
|
48
|
-
exports.Repository = Repository;
|
49
|
-
class RestRepository extends Repository {
|
50
|
-
constructor(client, table) {
|
51
|
-
super(null, table, {});
|
52
|
-
_RestRepository_instances.add(this);
|
53
|
-
_RestRepository_client.set(this, void 0);
|
54
|
-
_RestRepository_fetch.set(this, void 0);
|
55
|
-
_RestRepository_table.set(this, void 0);
|
56
|
-
__classPrivateFieldSet(this, _RestRepository_client, client, "f");
|
57
|
-
__classPrivateFieldSet(this, _RestRepository_table, table, "f");
|
58
|
-
// TODO: Remove when integrating with API client
|
59
|
-
const fetchImpl = typeof fetch !== 'undefined' ? fetch : __classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch;
|
60
|
-
if (!fetchImpl) {
|
61
|
-
throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
|
62
|
-
}
|
63
|
-
__classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
|
64
|
-
}
|
65
|
-
create(object) {
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
67
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
68
|
-
const record = transformObjectLinks(object);
|
69
|
-
const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: record }, fetchProps));
|
70
|
-
const finalObject = yield this.read(response.id);
|
71
|
-
if (!finalObject) {
|
72
|
-
throw new Error('The server failed to save the record');
|
73
|
-
}
|
74
|
-
return finalObject;
|
75
|
-
});
|
76
|
-
}
|
77
|
-
createMany(objects) {
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
79
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
80
|
-
const records = objects.map((object) => transformObjectLinks(object));
|
81
|
-
const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
|
82
|
-
// TODO: Use filer.$any() to get all the records
|
83
|
-
const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
|
84
|
-
if (finalObjects.some((object) => !object)) {
|
85
|
-
throw new Error('The server failed to save the record');
|
86
|
-
}
|
87
|
-
return finalObjects;
|
88
|
-
});
|
89
|
-
}
|
90
|
-
read(recordId) {
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
92
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
93
|
-
const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
94
|
-
return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
|
95
|
-
});
|
96
|
-
}
|
97
|
-
update(recordId, object) {
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
99
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
100
|
-
const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
|
101
|
-
// TODO: Review this, not sure we are properly initializing the object
|
102
|
-
return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
|
103
|
-
});
|
104
|
-
}
|
105
|
-
delete(recordId) {
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
107
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
108
|
-
yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
109
|
-
});
|
110
|
-
}
|
111
|
-
query(query, options) {
|
112
|
-
var _a, _b, _c;
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
114
|
-
const data = query.getQueryOptions();
|
115
|
-
const body = {
|
116
|
-
filter: Object.values(data.filter).some(Boolean) ? data.filter : undefined,
|
117
|
-
sort: (_a = (0, filters_1.buildSortFilter)(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : data.sort,
|
118
|
-
page: (_b = options === null || options === void 0 ? void 0 : options.page) !== null && _b !== void 0 ? _b : data.page,
|
119
|
-
columns: (_c = options === null || options === void 0 ? void 0 : options.columns) !== null && _c !== void 0 ? _c : data.columns
|
120
|
-
};
|
121
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
122
|
-
const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
|
123
|
-
const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), record));
|
124
|
-
// TODO: We should properly type this any
|
125
|
-
return new pagination_1.Page(query, meta, records);
|
126
|
-
});
|
127
|
-
}
|
128
|
-
}
|
129
|
-
exports.RestRepository = RestRepository;
|
130
|
-
_RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_getFetchProps = function _RestRepository_getFetchProps() {
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
132
|
-
const branch = yield __classPrivateFieldGet(this, _RestRepository_client, "f").getBranch();
|
133
|
-
return {
|
134
|
-
fetchImpl: __classPrivateFieldGet(this, _RestRepository_fetch, "f"),
|
135
|
-
apiKey: __classPrivateFieldGet(this, _RestRepository_client, "f").options.apiKey,
|
136
|
-
apiUrl: '',
|
137
|
-
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
138
|
-
workspacesApiUrl: (path, params) => {
|
139
|
-
var _a, _b;
|
140
|
-
const baseUrl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.databaseURL) !== null && _a !== void 0 ? _a : '';
|
141
|
-
const hasBranch = (_b = params.dbBranchName) !== null && _b !== void 0 ? _b : params.branch;
|
142
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branch}` : '');
|
143
|
-
return baseUrl + newPath;
|
144
|
-
}
|
145
|
-
};
|
146
|
-
});
|
147
|
-
};
|
148
|
-
class RestRespositoryFactory {
|
149
|
-
createRepository(client, table) {
|
150
|
-
return new RestRepository(client, table);
|
151
|
-
}
|
152
|
-
}
|
153
|
-
exports.RestRespositoryFactory = RestRespositoryFactory;
|
154
|
-
class BaseClient {
|
155
|
-
constructor(options, links) {
|
156
|
-
_BaseClient_links.set(this, void 0);
|
157
|
-
_BaseClient_branch.set(this, void 0);
|
158
|
-
if (!options.databaseURL || !options.apiKey || !options.branch) {
|
159
|
-
throw new Error('Options databaseURL, apiKey and branch are required');
|
160
|
-
}
|
161
|
-
this.options = options;
|
162
|
-
__classPrivateFieldSet(this, _BaseClient_links, links, "f");
|
163
|
-
}
|
164
|
-
initObject(table, object) {
|
165
|
-
const o = {};
|
166
|
-
Object.assign(o, object);
|
167
|
-
const tableLinks = __classPrivateFieldGet(this, _BaseClient_links, "f")[table] || [];
|
168
|
-
for (const link of tableLinks) {
|
169
|
-
const [field, linkTable] = link;
|
170
|
-
const value = o[field];
|
171
|
-
if (value && typeof value === 'object') {
|
172
|
-
const { id } = value;
|
173
|
-
if (Object.keys(value).find((col) => col === 'id')) {
|
174
|
-
o[field] = this.initObject(linkTable, value);
|
175
|
-
}
|
176
|
-
else if (id) {
|
177
|
-
o[field] = {
|
178
|
-
id,
|
179
|
-
get: () => {
|
180
|
-
this.db[linkTable].read(id);
|
181
|
-
}
|
182
|
-
};
|
183
|
-
}
|
184
|
-
}
|
185
|
-
}
|
186
|
-
const db = this.db;
|
187
|
-
o.read = function () {
|
188
|
-
return db[table].read(o['id']);
|
189
|
-
};
|
190
|
-
o.update = function (data) {
|
191
|
-
return db[table].update(o['id'], data);
|
192
|
-
};
|
193
|
-
o.delete = function () {
|
194
|
-
return db[table].delete(o['id']);
|
195
|
-
};
|
196
|
-
for (const prop of ['read', 'update', 'delete']) {
|
197
|
-
Object.defineProperty(o, prop, { enumerable: false });
|
198
|
-
}
|
199
|
-
// TODO: links and rev links
|
200
|
-
Object.freeze(o);
|
201
|
-
return o;
|
202
|
-
}
|
203
|
-
getBranch() {
|
204
|
-
var e_1, _a;
|
205
|
-
return __awaiter(this, void 0, void 0, function* () {
|
206
|
-
if (__classPrivateFieldGet(this, _BaseClient_branch, "f"))
|
207
|
-
return __classPrivateFieldGet(this, _BaseClient_branch, "f");
|
208
|
-
const { branch: param } = this.options;
|
209
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
210
|
-
const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
|
211
|
-
return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
|
212
|
-
});
|
213
|
-
try {
|
214
|
-
for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
|
215
|
-
const strategy = strategies_1_1.value;
|
216
|
-
const branch = yield evaluateBranch(strategy);
|
217
|
-
if (branch) {
|
218
|
-
__classPrivateFieldSet(this, _BaseClient_branch, branch, "f");
|
219
|
-
return branch;
|
220
|
-
}
|
221
|
-
}
|
222
|
-
}
|
223
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
224
|
-
finally {
|
225
|
-
try {
|
226
|
-
if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
|
227
|
-
}
|
228
|
-
finally { if (e_1) throw e_1.error; }
|
229
|
-
}
|
230
|
-
throw new Error('Unable to resolve branch value');
|
231
|
-
});
|
232
|
-
}
|
233
|
-
}
|
234
|
-
exports.BaseClient = BaseClient;
|
235
|
-
_BaseClient_links = new WeakMap(), _BaseClient_branch = new WeakMap();
|
17
|
+
exports.XataError = void 0;
|
236
18
|
class XataError extends Error {
|
237
19
|
constructor(message, status) {
|
238
20
|
super(message);
|
@@ -240,17 +22,5 @@ class XataError extends Error {
|
|
240
22
|
}
|
241
23
|
}
|
242
24
|
exports.XataError = XataError;
|
243
|
-
const isBranchStrategyBuilder = (strategy) => {
|
244
|
-
return typeof strategy === 'function';
|
245
|
-
};
|
246
|
-
// TODO: We can find a better implementation for links
|
247
|
-
const transformObjectLinks = (object) => {
|
248
|
-
return Object.entries(object).reduce((acc, [key, value]) => {
|
249
|
-
if (value && typeof value === 'object' && typeof value.id === 'string') {
|
250
|
-
return Object.assign(Object.assign({}, acc), { [key]: value.id });
|
251
|
-
}
|
252
|
-
return Object.assign(Object.assign({}, acc), { [key]: value });
|
253
|
-
}, {});
|
254
|
-
};
|
255
25
|
__exportStar(require("./api"), exports);
|
256
26
|
__exportStar(require("./schema"), exports);
|
package/dist/schema/index.d.ts
CHANGED
package/dist/schema/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.
|
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];
|
@@ -10,4 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
15
|
};
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
exports.Query = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
|
13
18
|
__exportStar(require("./operators"), exports);
|
19
|
+
var repository_1 = require("./repository");
|
20
|
+
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
|
21
|
+
Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_1.RestRepository; } });
|
22
|
+
Object.defineProperty(exports, "RestRespositoryFactory", { enumerable: true, get: function () { return repository_1.RestRespositoryFactory; } });
|
23
|
+
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
|
24
|
+
var query_1 = require("./query");
|
25
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
|
package/dist/schema/query.d.ts
CHANGED
@@ -3,7 +3,7 @@ import { FilterExpression, SortExpression, PageConfig, ColumnsFilter } from '../
|
|
3
3
|
import { DeepConstraint, FilterConstraints, SortDirection, SortFilter } from './filters';
|
4
4
|
import { PaginationOptions, Page, Paginable, PaginationQueryMeta } from './pagination';
|
5
5
|
import { Selectable, SelectableColumn, Select } from './selection';
|
6
|
-
export declare type QueryOptions<T> = {
|
6
|
+
export declare type QueryOptions<T extends XataRecord> = {
|
7
7
|
page?: PaginationOptions;
|
8
8
|
columns?: Extract<keyof Selectable<T>, string>[];
|
9
9
|
sort?: SortFilter<T> | SortFilter<T>[];
|
package/dist/schema/query.js
CHANGED
@@ -77,19 +77,19 @@ class Query {
|
|
77
77
|
return __classPrivateFieldGet(this, _Query_data, "f");
|
78
78
|
}
|
79
79
|
any(...queries) {
|
80
|
-
const $any =
|
80
|
+
const $any = queries.map((query) => query.getQueryOptions().filter);
|
81
81
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
82
82
|
}
|
83
83
|
all(...queries) {
|
84
|
-
const $all =
|
84
|
+
const $all = queries.map((query) => query.getQueryOptions().filter);
|
85
85
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
86
86
|
}
|
87
87
|
not(...queries) {
|
88
|
-
const $not =
|
88
|
+
const $not = queries.map((query) => query.getQueryOptions().filter);
|
89
89
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
90
90
|
}
|
91
91
|
none(...queries) {
|
92
|
-
const $none =
|
92
|
+
const $none = queries.map((query) => query.getQueryOptions().filter);
|
93
93
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
94
94
|
}
|
95
95
|
filter(a, b) {
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { FetchImpl } from '../api/fetcher';
|
2
|
+
import { Page } from './pagination';
|
3
|
+
import { Query, QueryOptions } from './query';
|
4
|
+
import { XataRecord } from './record';
|
5
|
+
import { Selectable, SelectableColumn, Select } from './selection';
|
6
|
+
export declare type Links = Record<string, Array<string[]>>;
|
7
|
+
export declare abstract class Repository<T extends XataRecord> extends Query<T> {
|
8
|
+
abstract create(object: Selectable<T>): Promise<T>;
|
9
|
+
abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
|
10
|
+
abstract read(id: string): Promise<T | null>;
|
11
|
+
abstract update(id: string, object: Partial<Selectable<T>>): Promise<T>;
|
12
|
+
abstract upsert(id: string, object: Selectable<T>): Promise<T>;
|
13
|
+
abstract delete(id: string): void;
|
14
|
+
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>>;
|
15
|
+
}
|
16
|
+
export declare class RestRepository<T extends XataRecord> extends Repository<T> {
|
17
|
+
#private;
|
18
|
+
constructor(client: BaseClient<any>, table: string);
|
19
|
+
create(object: Selectable<T>): Promise<T>;
|
20
|
+
createMany(objects: T[]): Promise<T[]>;
|
21
|
+
read(recordId: string): Promise<T | null>;
|
22
|
+
update(recordId: string, object: Partial<Selectable<T>>): Promise<T>;
|
23
|
+
upsert(recordId: string, object: Selectable<T>): Promise<T>;
|
24
|
+
delete(recordId: string): Promise<void>;
|
25
|
+
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>>;
|
26
|
+
}
|
27
|
+
interface RepositoryFactory {
|
28
|
+
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
29
|
+
}
|
30
|
+
export declare class RestRespositoryFactory implements RepositoryFactory {
|
31
|
+
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
32
|
+
}
|
33
|
+
declare type BranchStrategyValue = string | undefined | null;
|
34
|
+
declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
|
35
|
+
declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
|
36
|
+
declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
|
37
|
+
export declare type XataClientOptions = {
|
38
|
+
fetch?: FetchImpl;
|
39
|
+
databaseURL?: string;
|
40
|
+
branch: BranchStrategyOption;
|
41
|
+
apiKey: string;
|
42
|
+
repositoryFactory?: RepositoryFactory;
|
43
|
+
};
|
44
|
+
export declare class BaseClient<D extends Record<string, Repository<any>>> {
|
45
|
+
#private;
|
46
|
+
options: XataClientOptions;
|
47
|
+
db: D;
|
48
|
+
constructor(options: XataClientOptions, links: Links);
|
49
|
+
initObject<T>(table: string, object: object): T;
|
50
|
+
getBranch(): Promise<string>;
|
51
|
+
}
|
52
|
+
export {};
|
@@ -0,0 +1,260 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
14
|
+
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");
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
16
|
+
};
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
19
|
+
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");
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
21
|
+
};
|
22
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
23
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
24
|
+
var m = o[Symbol.asyncIterator], i;
|
25
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
26
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
27
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
28
|
+
};
|
29
|
+
var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _BaseClient_links, _BaseClient_branch;
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
31
|
+
exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
|
32
|
+
const api_1 = require("../api");
|
33
|
+
const filters_1 = require("./filters");
|
34
|
+
const pagination_1 = require("./pagination");
|
35
|
+
const query_1 = require("./query");
|
36
|
+
class Repository extends query_1.Query {
|
37
|
+
}
|
38
|
+
exports.Repository = Repository;
|
39
|
+
class RestRepository extends Repository {
|
40
|
+
constructor(client, table) {
|
41
|
+
super(null, table, {});
|
42
|
+
_RestRepository_instances.add(this);
|
43
|
+
_RestRepository_client.set(this, void 0);
|
44
|
+
_RestRepository_fetch.set(this, void 0);
|
45
|
+
_RestRepository_table.set(this, void 0);
|
46
|
+
__classPrivateFieldSet(this, _RestRepository_client, client, "f");
|
47
|
+
__classPrivateFieldSet(this, _RestRepository_table, table, "f");
|
48
|
+
// TODO: Remove when integrating with API client
|
49
|
+
const fetchImpl = typeof fetch !== 'undefined' ? fetch : __classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch;
|
50
|
+
if (!fetchImpl) {
|
51
|
+
throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
|
52
|
+
}
|
53
|
+
__classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
|
54
|
+
}
|
55
|
+
create(object) {
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
57
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
58
|
+
const record = transformObjectLinks(object);
|
59
|
+
const response = object.id
|
60
|
+
? yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
|
61
|
+
workspace: '{workspaceId}',
|
62
|
+
dbBranchName: '{dbBranch}',
|
63
|
+
tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
|
64
|
+
recordId: object.id
|
65
|
+
}, body: record }, fetchProps))
|
66
|
+
: yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
|
67
|
+
workspace: '{workspaceId}',
|
68
|
+
dbBranchName: '{dbBranch}',
|
69
|
+
tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
|
70
|
+
}, body: record }, fetchProps));
|
71
|
+
const finalObject = yield this.read(response.id);
|
72
|
+
if (!finalObject) {
|
73
|
+
throw new Error('The server failed to save the record');
|
74
|
+
}
|
75
|
+
return finalObject;
|
76
|
+
});
|
77
|
+
}
|
78
|
+
createMany(objects) {
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
80
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
81
|
+
const records = objects.map((object) => transformObjectLinks(object));
|
82
|
+
const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
|
83
|
+
// TODO: Use filer.$any() to get all the records
|
84
|
+
const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
|
85
|
+
if (finalObjects.some((object) => !object)) {
|
86
|
+
throw new Error('The server failed to save the record');
|
87
|
+
}
|
88
|
+
return finalObjects;
|
89
|
+
});
|
90
|
+
}
|
91
|
+
read(recordId) {
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
93
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
94
|
+
const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
95
|
+
return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
|
96
|
+
});
|
97
|
+
}
|
98
|
+
update(recordId, object) {
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
100
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
101
|
+
const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
|
102
|
+
const item = yield this.read(response.id);
|
103
|
+
if (!item)
|
104
|
+
throw new Error('The server failed to save the record');
|
105
|
+
return item;
|
106
|
+
});
|
107
|
+
}
|
108
|
+
upsert(recordId, object) {
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
110
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
111
|
+
const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
|
112
|
+
const item = yield this.read(response.id);
|
113
|
+
if (!item)
|
114
|
+
throw new Error('The server failed to save the record');
|
115
|
+
return item;
|
116
|
+
});
|
117
|
+
}
|
118
|
+
delete(recordId) {
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
120
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
121
|
+
yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
122
|
+
});
|
123
|
+
}
|
124
|
+
query(query, options) {
|
125
|
+
var _a, _b, _c;
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
127
|
+
const data = query.getQueryOptions();
|
128
|
+
const body = {
|
129
|
+
filter: Object.values(data.filter).some(Boolean) ? data.filter : undefined,
|
130
|
+
sort: (_a = (0, filters_1.buildSortFilter)(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : data.sort,
|
131
|
+
page: (_b = options === null || options === void 0 ? void 0 : options.page) !== null && _b !== void 0 ? _b : data.page,
|
132
|
+
columns: (_c = options === null || options === void 0 ? void 0 : options.columns) !== null && _c !== void 0 ? _c : data.columns
|
133
|
+
};
|
134
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
135
|
+
const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
|
136
|
+
const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), record));
|
137
|
+
// TODO: We should properly type this any
|
138
|
+
return new pagination_1.Page(query, meta, records);
|
139
|
+
});
|
140
|
+
}
|
141
|
+
}
|
142
|
+
exports.RestRepository = RestRepository;
|
143
|
+
_RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_getFetchProps = function _RestRepository_getFetchProps() {
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
145
|
+
const branch = yield __classPrivateFieldGet(this, _RestRepository_client, "f").getBranch();
|
146
|
+
return {
|
147
|
+
fetchImpl: __classPrivateFieldGet(this, _RestRepository_fetch, "f"),
|
148
|
+
apiKey: __classPrivateFieldGet(this, _RestRepository_client, "f").options.apiKey,
|
149
|
+
apiUrl: '',
|
150
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
151
|
+
workspacesApiUrl: (path, params) => {
|
152
|
+
var _a, _b;
|
153
|
+
const baseUrl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.databaseURL) !== null && _a !== void 0 ? _a : '';
|
154
|
+
const hasBranch = (_b = params.dbBranchName) !== null && _b !== void 0 ? _b : params.branch;
|
155
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branch}` : '');
|
156
|
+
return baseUrl + newPath;
|
157
|
+
}
|
158
|
+
};
|
159
|
+
});
|
160
|
+
};
|
161
|
+
class RestRespositoryFactory {
|
162
|
+
createRepository(client, table) {
|
163
|
+
return new RestRepository(client, table);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
exports.RestRespositoryFactory = RestRespositoryFactory;
|
167
|
+
class BaseClient {
|
168
|
+
constructor(options, links) {
|
169
|
+
_BaseClient_links.set(this, void 0);
|
170
|
+
_BaseClient_branch.set(this, void 0);
|
171
|
+
if (!options.databaseURL || !options.apiKey || !options.branch) {
|
172
|
+
throw new Error('Options databaseURL, apiKey and branch are required');
|
173
|
+
}
|
174
|
+
this.options = options;
|
175
|
+
__classPrivateFieldSet(this, _BaseClient_links, links, "f");
|
176
|
+
}
|
177
|
+
initObject(table, object) {
|
178
|
+
const o = {};
|
179
|
+
Object.assign(o, object);
|
180
|
+
const tableLinks = __classPrivateFieldGet(this, _BaseClient_links, "f")[table] || [];
|
181
|
+
for (const link of tableLinks) {
|
182
|
+
const [field, linkTable] = link;
|
183
|
+
const value = o[field];
|
184
|
+
if (value && typeof value === 'object') {
|
185
|
+
const { id } = value;
|
186
|
+
if (Object.keys(value).find((col) => col === 'id')) {
|
187
|
+
o[field] = this.initObject(linkTable, value);
|
188
|
+
}
|
189
|
+
else if (id) {
|
190
|
+
o[field] = {
|
191
|
+
id,
|
192
|
+
get: () => {
|
193
|
+
this.db[linkTable].read(id);
|
194
|
+
}
|
195
|
+
};
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
const db = this.db;
|
200
|
+
o.read = function () {
|
201
|
+
return db[table].read(o['id']);
|
202
|
+
};
|
203
|
+
o.update = function (data) {
|
204
|
+
return db[table].update(o['id'], data);
|
205
|
+
};
|
206
|
+
o.delete = function () {
|
207
|
+
return db[table].delete(o['id']);
|
208
|
+
};
|
209
|
+
for (const prop of ['read', 'update', 'delete']) {
|
210
|
+
Object.defineProperty(o, prop, { enumerable: false });
|
211
|
+
}
|
212
|
+
// TODO: links and rev links
|
213
|
+
Object.freeze(o);
|
214
|
+
return o;
|
215
|
+
}
|
216
|
+
getBranch() {
|
217
|
+
var e_1, _a;
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
219
|
+
if (__classPrivateFieldGet(this, _BaseClient_branch, "f"))
|
220
|
+
return __classPrivateFieldGet(this, _BaseClient_branch, "f");
|
221
|
+
const { branch: param } = this.options;
|
222
|
+
const strategies = Array.isArray(param) ? [...param] : [param];
|
223
|
+
const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
|
224
|
+
return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
|
225
|
+
});
|
226
|
+
try {
|
227
|
+
for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
|
228
|
+
const strategy = strategies_1_1.value;
|
229
|
+
const branch = yield evaluateBranch(strategy);
|
230
|
+
if (branch) {
|
231
|
+
__classPrivateFieldSet(this, _BaseClient_branch, branch, "f");
|
232
|
+
return branch;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
237
|
+
finally {
|
238
|
+
try {
|
239
|
+
if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
|
240
|
+
}
|
241
|
+
finally { if (e_1) throw e_1.error; }
|
242
|
+
}
|
243
|
+
throw new Error('Unable to resolve branch value');
|
244
|
+
});
|
245
|
+
}
|
246
|
+
}
|
247
|
+
exports.BaseClient = BaseClient;
|
248
|
+
_BaseClient_links = new WeakMap(), _BaseClient_branch = new WeakMap();
|
249
|
+
const isBranchStrategyBuilder = (strategy) => {
|
250
|
+
return typeof strategy === 'function';
|
251
|
+
};
|
252
|
+
// TODO: We can find a better implementation for links
|
253
|
+
const transformObjectLinks = (object) => {
|
254
|
+
return Object.entries(object).reduce((acc, [key, value]) => {
|
255
|
+
if (value && typeof value === 'object' && typeof value.id === 'string') {
|
256
|
+
return Object.assign(Object.assign({}, acc), { [key]: value.id });
|
257
|
+
}
|
258
|
+
return Object.assign(Object.assign({}, acc), { [key]: value });
|
259
|
+
}, {});
|
260
|
+
};
|
@@ -1,16 +1,12 @@
|
|
1
1
|
import { XataRecord } from '..';
|
2
|
+
import { PartialBy } from '../util/lang';
|
2
3
|
import { StringKeys, UnionToIntersection, Values } from '../util/types';
|
3
4
|
import { Query } from './query';
|
4
5
|
declare type Queries<T> = {
|
5
6
|
[key in keyof T as T[key] extends Query<any> ? key : never]: T[key];
|
6
7
|
};
|
7
|
-
declare type
|
8
|
-
|
9
|
-
};
|
10
|
-
declare type OmitMethods<T> = {
|
11
|
-
[key in keyof T as T[key] extends Function ? never : key]: T[key];
|
12
|
-
};
|
13
|
-
export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>;
|
8
|
+
declare type InternalProperties = keyof Omit<XataRecord, 'id'>;
|
9
|
+
export declare type Selectable<T extends XataRecord> = Omit<PartialBy<T, 'id'>, InternalProperties>;
|
14
10
|
export declare type SelectableColumn<O> = '*' | (O extends Array<unknown> ? never : O extends Record<string, any> ? '*' | Values<{
|
15
11
|
[K in StringKeys<O>]: O[K] extends Record<string, any> ? `${K}.${SelectableColumn<O[K]>}` : K;
|
16
12
|
}> : '');
|
package/dist/util/lang.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@xata.io/client",
|
3
|
-
"version": "0.0.0-beta.
|
3
|
+
"version": "0.0.0-beta.7c075f4",
|
4
4
|
"description": "Xata.io SDK for TypeScript and JavaScript",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.ts",
|
@@ -20,5 +20,5 @@
|
|
20
20
|
"url": "https://github.com/xataio/client-ts/issues"
|
21
21
|
},
|
22
22
|
"homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
|
23
|
-
"gitHead": "
|
23
|
+
"gitHead": "7c075f4a300a067f7b9f50aa7e7d7e5294a5f900"
|
24
24
|
}
|