@xata.io/client 0.0.0-alpha.vfbac5b5 → 0.0.0-alpha.vfc692f9
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 +26 -0
- package/Usage.md +33 -0
- package/dist/index.cjs +98 -135
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +397 -121
- package/dist/index.mjs +98 -136
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.15.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#496](https://github.com/xataio/client-ts/pull/496) [`e923d11`](https://github.com/xataio/client-ts/commit/e923d11fe357519dc4ca3ae722670e6e70ccd1c6) Thanks [@gimenete](https://github.com/gimenete)! - Ignore git output in Xata client
|
8
|
+
|
9
|
+
* [#481](https://github.com/xataio/client-ts/pull/481) [`599b52c`](https://github.com/xataio/client-ts/commit/599b52c3090222eedef85d1ad1e907874cd3e801) Thanks [@xata-bot](https://github.com/xata-bot)! - Add updateWorkspaceMemberInvite API method
|
10
|
+
|
11
|
+
## 0.14.0
|
12
|
+
|
13
|
+
### Minor Changes
|
14
|
+
|
15
|
+
- [#409](https://github.com/xataio/client-ts/pull/409) [`8812380`](https://github.com/xataio/client-ts/commit/881238062b5eeac2dc8b9ba156720e0acc22c5c5) Thanks [@SferaDev](https://github.com/SferaDev)! - Infer types from schema in codegen
|
16
|
+
|
17
|
+
* [#457](https://github.com/xataio/client-ts/pull/457) [`0584a5b`](https://github.com/xataio/client-ts/commit/0584a5b207a21dbc36ddc1d44b276f1d5bb60dc5) Thanks [@SferaDev](https://github.com/SferaDev)! - Load env variables so that code analysis detects them
|
18
|
+
|
19
|
+
- [#469](https://github.com/xataio/client-ts/pull/469) [`8d8a912`](https://github.com/xataio/client-ts/commit/8d8a9129e36452266c4c12fe35b421f66e572498) Thanks [@gimenete](https://github.com/gimenete)! - Treat branch name specified with third party env variables as git branches in the resolution algorithm
|
20
|
+
|
21
|
+
### Patch Changes
|
22
|
+
|
23
|
+
- [#462](https://github.com/xataio/client-ts/pull/462) [`7547b7e`](https://github.com/xataio/client-ts/commit/7547b7edbc9a95c6620784cc5348316f27502c73) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix bug with RecordArray.map
|
24
|
+
|
25
|
+
* [#472](https://github.com/xataio/client-ts/pull/472) [`e99010c`](https://github.com/xataio/client-ts/commit/e99010c9ab9d355abadcfbcf98b5a3fcc80c307a) Thanks [@SferaDev](https://github.com/SferaDev)! - Add id as entity property
|
26
|
+
|
27
|
+
- [#443](https://github.com/xataio/client-ts/pull/443) [`c4be404`](https://github.com/xataio/client-ts/commit/c4be404a3ecb34df9b1ef4501c92f5bdc221f19c) Thanks [@SferaDev](https://github.com/SferaDev)! - Improve performance with `create([])` operation
|
28
|
+
|
3
29
|
## 0.13.4
|
4
30
|
|
5
31
|
### Patch Changes
|
package/Usage.md
CHANGED
@@ -155,6 +155,13 @@ const user = await xata.db.users.read(object1);
|
|
155
155
|
const users = await xata.db.users.read([object1, object2]);
|
156
156
|
```
|
157
157
|
|
158
|
+
By default an object with the first level properties is returned. If you want to reduce or expand its columns, you can pass an array of columns to the `read()` method.
|
159
|
+
|
160
|
+
```ts
|
161
|
+
const user = await xata.db.users.read('rec_1234abcdef', ['fullName', 'team.name']);
|
162
|
+
const users = await xata.db.users.read(['rec_1234abcdef', 'rec_5678defgh'], ['fullName', 'team.name']);
|
163
|
+
```
|
164
|
+
|
158
165
|
### Creating Records
|
159
166
|
|
160
167
|
Both the `create()` and `createOrUpdate()` methods can be used to create a new record.
|
@@ -202,6 +209,19 @@ const users = await xata.db.users.createOrUpdate([
|
|
202
209
|
]);
|
203
210
|
```
|
204
211
|
|
212
|
+
By default, the `create` and `createOrUpdate` methods will return the created record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `create` or `createOrUpdate` method.
|
213
|
+
|
214
|
+
```ts
|
215
|
+
const user = await xata.db.users.create('user_admin', { fullName: 'John Smith' }, ['fullName', 'team.name']);
|
216
|
+
const users = await xata.db.users.createOrUpdate(
|
217
|
+
[
|
218
|
+
{ id: 'user_admin', fullName: 'John Smith' },
|
219
|
+
{ id: 'user_manager', fullName: 'Jane Doe' }
|
220
|
+
],
|
221
|
+
['fullName', 'team.name']
|
222
|
+
);
|
223
|
+
```
|
224
|
+
|
205
225
|
### Updating records
|
206
226
|
|
207
227
|
The `update()` method can be used to update an existing record. It will throw an `Error` if the record cannot be found.
|
@@ -225,6 +245,12 @@ const users = await xata.db.users.update([
|
|
225
245
|
]);
|
226
246
|
```
|
227
247
|
|
248
|
+
By default, the `update` method will return the updated record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `update` method.
|
249
|
+
|
250
|
+
```ts
|
251
|
+
const user = await xata.db.users.update('rec_1234abcdef', { fullName: 'John Smith' }, ['fullName', 'team.name']);
|
252
|
+
```
|
253
|
+
|
228
254
|
### Deleting Records
|
229
255
|
|
230
256
|
The `delete()` method can be used to delete an existing record. It will throw an `Error` if the record cannot be found.
|
@@ -373,6 +399,13 @@ user?.update({ fullName: 'John Doe' }); // Partially updates the record
|
|
373
399
|
user?.delete(); // Deletes the record
|
374
400
|
```
|
375
401
|
|
402
|
+
The `read` and `update` methods return the updated record with the first level properties. If you want to reduce or expand its columns, you can pass an array of columns to the `read` and `update` methods.
|
403
|
+
|
404
|
+
```ts
|
405
|
+
const user = await xata.db.users.read('rec_1234abcdef');
|
406
|
+
user?.read(['fullName', 'team.name']); // Reads the record again with the `fullName` and `team.name` columns
|
407
|
+
```
|
408
|
+
|
376
409
|
If the table contains a link property, it will be represented as a `Link` object containing its `id` property and methods to read again or update the linked record.
|
377
410
|
|
378
411
|
```ts
|
package/dist/index.cjs
CHANGED
@@ -35,6 +35,9 @@ function isDefined(value) {
|
|
35
35
|
function isString(value) {
|
36
36
|
return isDefined(value) && typeof value === "string";
|
37
37
|
}
|
38
|
+
function isStringArray(value) {
|
39
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
40
|
+
}
|
38
41
|
function toBase64(value) {
|
39
42
|
try {
|
40
43
|
return btoa(value);
|
@@ -107,18 +110,20 @@ function getGlobalFallbackBranch() {
|
|
107
110
|
}
|
108
111
|
async function getGitBranch() {
|
109
112
|
const cmd = ["git", "branch", "--show-current"];
|
113
|
+
const fullCmd = cmd.join(" ");
|
110
114
|
const nodeModule = ["child", "process"].join("_");
|
115
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
111
116
|
try {
|
112
117
|
if (typeof require === "function") {
|
113
|
-
return require(nodeModule).execSync(
|
118
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
114
119
|
}
|
115
120
|
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
116
|
-
return execSync(
|
121
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
117
122
|
} catch (err) {
|
118
123
|
}
|
119
124
|
try {
|
120
125
|
if (isObject(Deno)) {
|
121
|
-
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "
|
126
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
122
127
|
return new TextDecoder().decode(await process2.output()).trim();
|
123
128
|
}
|
124
129
|
} catch (err) {
|
@@ -143,7 +148,7 @@ function getFetchImplementation(userFetch) {
|
|
143
148
|
return fetchImpl;
|
144
149
|
}
|
145
150
|
|
146
|
-
const VERSION = "0.0.0-alpha.
|
151
|
+
const VERSION = "0.0.0-alpha.vfc692f9";
|
147
152
|
|
148
153
|
class ErrorWithCause extends Error {
|
149
154
|
constructor(message, options) {
|
@@ -308,6 +313,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
308
313
|
...variables
|
309
314
|
});
|
310
315
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
316
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
311
317
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
312
318
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
313
319
|
method: "delete",
|
@@ -356,11 +362,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
356
362
|
method: "get",
|
357
363
|
...variables
|
358
364
|
});
|
359
|
-
const createBranch = (variables) => fetch$1({
|
360
|
-
url: "/db/{dbBranchName}",
|
361
|
-
method: "put",
|
362
|
-
...variables
|
363
|
-
});
|
365
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
364
366
|
const deleteBranch = (variables) => fetch$1({
|
365
367
|
url: "/db/{dbBranchName}",
|
366
368
|
method: "delete",
|
@@ -434,11 +436,7 @@ const updateColumn = (variables) => fetch$1({
|
|
434
436
|
method: "patch",
|
435
437
|
...variables
|
436
438
|
});
|
437
|
-
const insertRecord = (variables) => fetch$1({
|
438
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
439
|
-
method: "post",
|
440
|
-
...variables
|
441
|
-
});
|
439
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
442
440
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
443
441
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
444
442
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -480,6 +478,7 @@ const operationsByTag = {
|
|
480
478
|
updateWorkspaceMemberRole,
|
481
479
|
removeWorkspaceMember,
|
482
480
|
inviteWorkspaceMember,
|
481
|
+
updateWorkspaceMemberInvite,
|
483
482
|
cancelWorkspaceMemberInvite,
|
484
483
|
resendWorkspaceMemberInvite,
|
485
484
|
acceptWorkspaceMemberInvite
|
@@ -711,6 +710,13 @@ class WorkspaceApi {
|
|
711
710
|
...this.extraProps
|
712
711
|
});
|
713
712
|
}
|
713
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
714
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
715
|
+
pathParams: { workspaceId, inviteId },
|
716
|
+
body: { role },
|
717
|
+
...this.extraProps
|
718
|
+
});
|
719
|
+
}
|
714
720
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
715
721
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
716
722
|
pathParams: { workspaceId, inviteId },
|
@@ -925,9 +931,10 @@ class RecordsApi {
|
|
925
931
|
constructor(extraProps) {
|
926
932
|
this.extraProps = extraProps;
|
927
933
|
}
|
928
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
934
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
929
935
|
return operationsByTag.records.insertRecord({
|
930
936
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
937
|
+
queryParams: options,
|
931
938
|
body: record,
|
932
939
|
...this.extraProps
|
933
940
|
});
|
@@ -956,21 +963,24 @@ class RecordsApi {
|
|
956
963
|
...this.extraProps
|
957
964
|
});
|
958
965
|
}
|
959
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
966
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
960
967
|
return operationsByTag.records.deleteRecord({
|
961
968
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
969
|
+
queryParams: options,
|
962
970
|
...this.extraProps
|
963
971
|
});
|
964
972
|
}
|
965
973
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
966
974
|
return operationsByTag.records.getRecord({
|
967
975
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
976
|
+
queryParams: options,
|
968
977
|
...this.extraProps
|
969
978
|
});
|
970
979
|
}
|
971
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
980
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
972
981
|
return operationsByTag.records.bulkInsertTableRecords({
|
973
982
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
983
|
+
queryParams: options,
|
974
984
|
body: { records },
|
975
985
|
...this.extraProps
|
976
986
|
});
|
@@ -1319,7 +1329,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1319
1329
|
__accessCheck$4(obj, member, "access private method");
|
1320
1330
|
return method;
|
1321
1331
|
};
|
1322
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1332
|
+
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1323
1333
|
class Repository extends Query {
|
1324
1334
|
}
|
1325
1335
|
class RestRepository extends Query {
|
@@ -1331,9 +1341,6 @@ class RestRepository extends Query {
|
|
1331
1341
|
__privateAdd$4(this, _updateRecordWithID);
|
1332
1342
|
__privateAdd$4(this, _upsertRecordWithID);
|
1333
1343
|
__privateAdd$4(this, _deleteRecord);
|
1334
|
-
__privateAdd$4(this, _invalidateCache);
|
1335
|
-
__privateAdd$4(this, _setCacheRecord);
|
1336
|
-
__privateAdd$4(this, _getCacheRecord);
|
1337
1344
|
__privateAdd$4(this, _setCacheQuery);
|
1338
1345
|
__privateAdd$4(this, _getCacheQuery);
|
1339
1346
|
__privateAdd$4(this, _getSchemaTables$1);
|
@@ -1347,51 +1354,51 @@ class RestRepository extends Query {
|
|
1347
1354
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1348
1355
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1349
1356
|
}
|
1350
|
-
async create(a, b) {
|
1357
|
+
async create(a, b, c) {
|
1351
1358
|
if (Array.isArray(a)) {
|
1352
1359
|
if (a.length === 0)
|
1353
1360
|
return [];
|
1354
|
-
const
|
1355
|
-
|
1356
|
-
return records;
|
1361
|
+
const columns = isStringArray(b) ? b : void 0;
|
1362
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1357
1363
|
}
|
1358
1364
|
if (isString(a) && isObject(b)) {
|
1359
1365
|
if (a === "")
|
1360
1366
|
throw new Error("The id can't be empty");
|
1361
|
-
const
|
1362
|
-
|
1363
|
-
return record;
|
1367
|
+
const columns = isStringArray(c) ? c : void 0;
|
1368
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1364
1369
|
}
|
1365
1370
|
if (isObject(a) && isString(a.id)) {
|
1366
1371
|
if (a.id === "")
|
1367
1372
|
throw new Error("The id can't be empty");
|
1368
|
-
const
|
1369
|
-
|
1370
|
-
return record;
|
1373
|
+
const columns = isStringArray(b) ? b : void 0;
|
1374
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1371
1375
|
}
|
1372
1376
|
if (isObject(a)) {
|
1373
|
-
const
|
1374
|
-
|
1375
|
-
return record;
|
1377
|
+
const columns = isStringArray(b) ? b : void 0;
|
1378
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1376
1379
|
}
|
1377
1380
|
throw new Error("Invalid arguments for create method");
|
1378
1381
|
}
|
1379
|
-
async read(a) {
|
1382
|
+
async read(a, b) {
|
1383
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1380
1384
|
if (Array.isArray(a)) {
|
1381
1385
|
if (a.length === 0)
|
1382
1386
|
return [];
|
1383
1387
|
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
1384
|
-
|
1388
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1389
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1390
|
+
acc[object.id] = object;
|
1391
|
+
return acc;
|
1392
|
+
}, {});
|
1393
|
+
return ids.map((id2) => dictionary[id2] ?? null);
|
1385
1394
|
}
|
1386
1395
|
const id = isString(a) ? a : a.id;
|
1387
1396
|
if (isString(id)) {
|
1388
|
-
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
|
1389
|
-
if (cacheRecord)
|
1390
|
-
return cacheRecord;
|
1391
1397
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1392
1398
|
try {
|
1393
1399
|
const response = await getRecord({
|
1394
1400
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1401
|
+
queryParams: { columns },
|
1395
1402
|
...fetchProps
|
1396
1403
|
});
|
1397
1404
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
@@ -1403,50 +1410,45 @@ class RestRepository extends Query {
|
|
1403
1410
|
throw e;
|
1404
1411
|
}
|
1405
1412
|
}
|
1413
|
+
return null;
|
1406
1414
|
}
|
1407
|
-
async update(a, b) {
|
1415
|
+
async update(a, b, c) {
|
1408
1416
|
if (Array.isArray(a)) {
|
1409
1417
|
if (a.length === 0)
|
1410
1418
|
return [];
|
1411
1419
|
if (a.length > 100) {
|
1412
1420
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1413
1421
|
}
|
1414
|
-
|
1422
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1423
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1415
1424
|
}
|
1416
1425
|
if (isString(a) && isObject(b)) {
|
1417
|
-
|
1418
|
-
|
1419
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1420
|
-
return record;
|
1426
|
+
const columns = isStringArray(c) ? c : void 0;
|
1427
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1421
1428
|
}
|
1422
1429
|
if (isObject(a) && isString(a.id)) {
|
1423
|
-
|
1424
|
-
|
1425
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1426
|
-
return record;
|
1430
|
+
const columns = isStringArray(b) ? b : void 0;
|
1431
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1427
1432
|
}
|
1428
1433
|
throw new Error("Invalid arguments for update method");
|
1429
1434
|
}
|
1430
|
-
async createOrUpdate(a, b) {
|
1435
|
+
async createOrUpdate(a, b, c) {
|
1431
1436
|
if (Array.isArray(a)) {
|
1432
1437
|
if (a.length === 0)
|
1433
1438
|
return [];
|
1434
1439
|
if (a.length > 100) {
|
1435
1440
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1436
1441
|
}
|
1437
|
-
|
1442
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1443
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1438
1444
|
}
|
1439
1445
|
if (isString(a) && isObject(b)) {
|
1440
|
-
|
1441
|
-
|
1442
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1443
|
-
return record;
|
1446
|
+
const columns = isStringArray(c) ? c : void 0;
|
1447
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1444
1448
|
}
|
1445
1449
|
if (isObject(a) && isString(a.id)) {
|
1446
|
-
|
1447
|
-
|
1448
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1449
|
-
return record;
|
1450
|
+
const columns = isStringArray(c) ? c : void 0;
|
1451
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1450
1452
|
}
|
1451
1453
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1452
1454
|
}
|
@@ -1462,12 +1464,10 @@ class RestRepository extends Query {
|
|
1462
1464
|
}
|
1463
1465
|
if (isString(a)) {
|
1464
1466
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1465
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1466
1467
|
return;
|
1467
1468
|
}
|
1468
1469
|
if (isObject(a) && isString(a.id)) {
|
1469
1470
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1470
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1471
1471
|
return;
|
1472
1472
|
}
|
1473
1473
|
throw new Error("Invalid arguments for delete method");
|
@@ -1479,8 +1479,10 @@ class RestRepository extends Query {
|
|
1479
1479
|
body: {
|
1480
1480
|
query,
|
1481
1481
|
fuzziness: options.fuzziness,
|
1482
|
+
prefix: options.prefix,
|
1482
1483
|
highlight: options.highlight,
|
1483
|
-
filter: options.filter
|
1484
|
+
filter: options.filter,
|
1485
|
+
boosters: options.boosters
|
1484
1486
|
},
|
1485
1487
|
...fetchProps
|
1486
1488
|
});
|
@@ -1515,7 +1517,7 @@ _getFetchProps = new WeakMap();
|
|
1515
1517
|
_cache = new WeakMap();
|
1516
1518
|
_schemaTables$2 = new WeakMap();
|
1517
1519
|
_insertRecordWithoutId = new WeakSet();
|
1518
|
-
insertRecordWithoutId_fn = async function(object) {
|
1520
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1519
1521
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1520
1522
|
const record = transformObjectLinks(object);
|
1521
1523
|
const response = await insertRecord({
|
@@ -1524,17 +1526,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1524
1526
|
dbBranchName: "{dbBranch}",
|
1525
1527
|
tableName: __privateGet$4(this, _table)
|
1526
1528
|
},
|
1529
|
+
queryParams: { columns },
|
1527
1530
|
body: record,
|
1528
1531
|
...fetchProps
|
1529
1532
|
});
|
1530
|
-
const
|
1531
|
-
|
1532
|
-
throw new Error("The server failed to save the record");
|
1533
|
-
}
|
1534
|
-
return finalObject;
|
1533
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1534
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1535
1535
|
};
|
1536
1536
|
_insertRecordWithId = new WeakSet();
|
1537
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1537
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1538
1538
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1539
1539
|
const record = transformObjectLinks(object);
|
1540
1540
|
const response = await insertRecordWithID({
|
@@ -1545,60 +1545,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1545
1545
|
recordId
|
1546
1546
|
},
|
1547
1547
|
body: record,
|
1548
|
-
queryParams: { createOnly: true },
|
1548
|
+
queryParams: { createOnly: true, columns },
|
1549
1549
|
...fetchProps
|
1550
1550
|
});
|
1551
|
-
const
|
1552
|
-
|
1553
|
-
throw new Error("The server failed to save the record");
|
1554
|
-
}
|
1555
|
-
return finalObject;
|
1551
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1552
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1556
1553
|
};
|
1557
1554
|
_bulkInsertTableRecords = new WeakSet();
|
1558
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1555
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1559
1556
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1560
1557
|
const records = objects.map((object) => transformObjectLinks(object));
|
1561
|
-
const
|
1558
|
+
const response = await bulkInsertTableRecords({
|
1562
1559
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1560
|
+
queryParams: { columns },
|
1563
1561
|
body: { records },
|
1564
1562
|
...fetchProps
|
1565
1563
|
});
|
1566
|
-
|
1567
|
-
|
1568
|
-
throw new Error("The server failed to save some records");
|
1564
|
+
if (!isResponseWithRecords(response)) {
|
1565
|
+
throw new Error("Request included columns but server didn't include them");
|
1569
1566
|
}
|
1570
|
-
const
|
1571
|
-
|
1572
|
-
return acc;
|
1573
|
-
}, {});
|
1574
|
-
return recordIDs.map((id) => dictionary[id]);
|
1567
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1568
|
+
return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1575
1569
|
};
|
1576
1570
|
_updateRecordWithID = new WeakSet();
|
1577
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1571
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1578
1572
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1579
1573
|
const record = transformObjectLinks(object);
|
1580
1574
|
const response = await updateRecordWithID({
|
1581
1575
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1576
|
+
queryParams: { columns },
|
1582
1577
|
body: record,
|
1583
1578
|
...fetchProps
|
1584
1579
|
});
|
1585
|
-
const
|
1586
|
-
|
1587
|
-
throw new Error("The server failed to save the record");
|
1588
|
-
return item;
|
1580
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1581
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1589
1582
|
};
|
1590
1583
|
_upsertRecordWithID = new WeakSet();
|
1591
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1584
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1592
1585
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1593
1586
|
const response = await upsertRecordWithID({
|
1594
1587
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1588
|
+
queryParams: { columns },
|
1595
1589
|
body: object,
|
1596
1590
|
...fetchProps
|
1597
1591
|
});
|
1598
|
-
const
|
1599
|
-
|
1600
|
-
throw new Error("The server failed to save the record");
|
1601
|
-
return item;
|
1592
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1593
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1602
1594
|
};
|
1603
1595
|
_deleteRecord = new WeakSet();
|
1604
1596
|
deleteRecord_fn = async function(recordId) {
|
@@ -1608,29 +1600,6 @@ deleteRecord_fn = async function(recordId) {
|
|
1608
1600
|
...fetchProps
|
1609
1601
|
});
|
1610
1602
|
};
|
1611
|
-
_invalidateCache = new WeakSet();
|
1612
|
-
invalidateCache_fn = async function(recordId) {
|
1613
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1614
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1615
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1616
|
-
for (const [key, value] of queries) {
|
1617
|
-
const ids = getIds(value);
|
1618
|
-
if (ids.includes(recordId))
|
1619
|
-
await __privateGet$4(this, _cache).delete(key);
|
1620
|
-
}
|
1621
|
-
};
|
1622
|
-
_setCacheRecord = new WeakSet();
|
1623
|
-
setCacheRecord_fn = async function(record) {
|
1624
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1625
|
-
return;
|
1626
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1627
|
-
};
|
1628
|
-
_getCacheRecord = new WeakSet();
|
1629
|
-
getCacheRecord_fn = async function(recordId) {
|
1630
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1631
|
-
return null;
|
1632
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1633
|
-
};
|
1634
1603
|
_setCacheQuery = new WeakSet();
|
1635
1604
|
setCacheQuery_fn = async function(query, meta, records) {
|
1636
1605
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1696,11 +1665,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1696
1665
|
}
|
1697
1666
|
}
|
1698
1667
|
}
|
1699
|
-
result.read = function() {
|
1700
|
-
return db[table].read(result["id"]);
|
1668
|
+
result.read = function(columns2) {
|
1669
|
+
return db[table].read(result["id"], columns2);
|
1701
1670
|
};
|
1702
|
-
result.update = function(data) {
|
1703
|
-
return db[table].update(result["id"], data);
|
1671
|
+
result.update = function(data, columns2) {
|
1672
|
+
return db[table].update(result["id"], data, columns2);
|
1704
1673
|
};
|
1705
1674
|
result.delete = function() {
|
1706
1675
|
return db[table].delete(result["id"]);
|
@@ -1714,14 +1683,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1714
1683
|
Object.freeze(result);
|
1715
1684
|
return result;
|
1716
1685
|
};
|
1717
|
-
function
|
1718
|
-
|
1719
|
-
return value.map((item) => getIds(item)).flat();
|
1720
|
-
}
|
1721
|
-
if (!isObject(value))
|
1722
|
-
return [];
|
1723
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1724
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1686
|
+
function isResponseWithRecords(value) {
|
1687
|
+
return isObject(value) && Array.isArray(value.records);
|
1725
1688
|
}
|
1726
1689
|
|
1727
1690
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1748,7 +1711,6 @@ class SimpleCache {
|
|
1748
1711
|
__privateAdd$3(this, _map, void 0);
|
1749
1712
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1750
1713
|
this.capacity = options.max ?? 500;
|
1751
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1752
1714
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1753
1715
|
}
|
1754
1716
|
async getAll() {
|
@@ -1825,7 +1787,7 @@ class SchemaPlugin extends XataPlugin {
|
|
1825
1787
|
if (!isString(table))
|
1826
1788
|
throw new Error("Invalid table name");
|
1827
1789
|
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1828
|
-
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
|
1790
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1829
1791
|
}
|
1830
1792
|
return __privateGet$2(this, _tables)[table];
|
1831
1793
|
}
|
@@ -1899,10 +1861,10 @@ _schemaTables = new WeakMap();
|
|
1899
1861
|
_search = new WeakSet();
|
1900
1862
|
search_fn = async function(query, options, getFetchProps) {
|
1901
1863
|
const fetchProps = await getFetchProps();
|
1902
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
1864
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1903
1865
|
const { records } = await searchBranch({
|
1904
1866
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1905
|
-
body: { tables, query, fuzziness, highlight },
|
1867
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1906
1868
|
...fetchProps
|
1907
1869
|
});
|
1908
1870
|
return records;
|
@@ -2048,7 +2010,7 @@ const buildClient = (plugins) => {
|
|
2048
2010
|
const fetch = getFetchImplementation(options?.fetch);
|
2049
2011
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2050
2012
|
const apiKey = options?.apiKey || getAPIKey();
|
2051
|
-
const cache = options?.cache ?? new SimpleCache({
|
2013
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2052
2014
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2053
2015
|
if (!databaseURL || !apiKey) {
|
2054
2016
|
throw new Error("Options databaseURL and apiKey are required");
|
@@ -2199,6 +2161,7 @@ exports.updateRecordWithID = updateRecordWithID;
|
|
2199
2161
|
exports.updateTable = updateTable;
|
2200
2162
|
exports.updateUser = updateUser;
|
2201
2163
|
exports.updateWorkspace = updateWorkspace;
|
2164
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2202
2165
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2203
2166
|
exports.upsertRecordWithID = upsertRecordWithID;
|
2204
2167
|
//# sourceMappingURL=index.cjs.map
|