@xata.io/client 0.0.0-alpha.vecada6d → 0.0.0-alpha.vedd7251
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 +28 -0
- package/README.md +258 -1
- package/dist/index.cjs +75 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +188 -43
- package/dist/index.mjs +75 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
|
@@ -7,8 +7,11 @@ function compact(arr) {
|
|
|
7
7
|
function isObject(value) {
|
|
8
8
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
9
9
|
}
|
|
10
|
+
function isDefined(value) {
|
|
11
|
+
return value !== null && value !== void 0;
|
|
12
|
+
}
|
|
10
13
|
function isString(value) {
|
|
11
|
-
return value
|
|
14
|
+
return isDefined(value) && typeof value === "string";
|
|
12
15
|
}
|
|
13
16
|
function toBase64(value) {
|
|
14
17
|
try {
|
|
@@ -70,7 +73,12 @@ function getFetchImplementation(userFetch) {
|
|
|
70
73
|
return fetchImpl;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
class
|
|
76
|
+
class ErrorWithCause extends Error {
|
|
77
|
+
constructor(message, options) {
|
|
78
|
+
super(message, options);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class FetcherError extends ErrorWithCause {
|
|
74
82
|
constructor(status, data) {
|
|
75
83
|
super(getMessage(data));
|
|
76
84
|
this.status = status;
|
|
@@ -963,6 +971,9 @@ const PAGINATION_MAX_SIZE = 200;
|
|
|
963
971
|
const PAGINATION_DEFAULT_SIZE = 200;
|
|
964
972
|
const PAGINATION_MAX_OFFSET = 800;
|
|
965
973
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
|
974
|
+
function isCursorPaginationOptions(options) {
|
|
975
|
+
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
|
976
|
+
}
|
|
966
977
|
|
|
967
978
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
968
979
|
if (!member.has(obj))
|
|
@@ -984,7 +995,7 @@ var __privateSet$4 = (obj, member, value, setter) => {
|
|
|
984
995
|
};
|
|
985
996
|
var _table$1, _repository, _data;
|
|
986
997
|
const _Query = class {
|
|
987
|
-
constructor(repository, table, data,
|
|
998
|
+
constructor(repository, table, data, rawParent) {
|
|
988
999
|
__privateAdd$5(this, _table$1, void 0);
|
|
989
1000
|
__privateAdd$5(this, _repository, void 0);
|
|
990
1001
|
__privateAdd$5(this, _data, { filter: {} });
|
|
@@ -996,6 +1007,7 @@ const _Query = class {
|
|
|
996
1007
|
} else {
|
|
997
1008
|
__privateSet$4(this, _repository, this);
|
|
998
1009
|
}
|
|
1010
|
+
const parent = cleanParent(data, rawParent);
|
|
999
1011
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
|
1000
1012
|
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
|
1001
1013
|
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
|
@@ -1067,13 +1079,13 @@ const _Query = class {
|
|
|
1067
1079
|
}
|
|
1068
1080
|
async *getIterator(options = {}) {
|
|
1069
1081
|
const { batchSize = 1 } = options;
|
|
1070
|
-
let
|
|
1071
|
-
let
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1082
|
+
let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
|
|
1083
|
+
let more = page.hasNextPage();
|
|
1084
|
+
yield page.records;
|
|
1085
|
+
while (more) {
|
|
1086
|
+
page = await page.nextPage();
|
|
1087
|
+
more = page.hasNextPage();
|
|
1088
|
+
yield page.records;
|
|
1077
1089
|
}
|
|
1078
1090
|
}
|
|
1079
1091
|
async getMany(options = {}) {
|
|
@@ -1115,12 +1127,20 @@ let Query = _Query;
|
|
|
1115
1127
|
_table$1 = new WeakMap();
|
|
1116
1128
|
_repository = new WeakMap();
|
|
1117
1129
|
_data = new WeakMap();
|
|
1130
|
+
function cleanParent(data, parent) {
|
|
1131
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
|
1132
|
+
return { ...parent, sorting: void 0, filter: void 0 };
|
|
1133
|
+
}
|
|
1134
|
+
return parent;
|
|
1135
|
+
}
|
|
1118
1136
|
|
|
1119
1137
|
function isIdentifiable(x) {
|
|
1120
1138
|
return isObject(x) && isString(x?.id);
|
|
1121
1139
|
}
|
|
1122
1140
|
function isXataRecord(x) {
|
|
1123
|
-
|
|
1141
|
+
const record = x;
|
|
1142
|
+
const metadata = record?.getMetadata();
|
|
1143
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
|
1124
1144
|
}
|
|
1125
1145
|
|
|
1126
1146
|
function isSortFilterString(value) {
|
|
@@ -1197,6 +1217,8 @@ class RestRepository extends Query {
|
|
|
1197
1217
|
}
|
|
1198
1218
|
async create(a, b) {
|
|
1199
1219
|
if (Array.isArray(a)) {
|
|
1220
|
+
if (a.length === 0)
|
|
1221
|
+
return [];
|
|
1200
1222
|
const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
|
|
1201
1223
|
await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
|
|
1202
1224
|
return records;
|
|
@@ -1222,27 +1244,36 @@ class RestRepository extends Query {
|
|
|
1222
1244
|
}
|
|
1223
1245
|
throw new Error("Invalid arguments for create method");
|
|
1224
1246
|
}
|
|
1225
|
-
async read(
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1247
|
+
async read(a) {
|
|
1248
|
+
if (Array.isArray(a)) {
|
|
1249
|
+
if (a.length === 0)
|
|
1250
|
+
return [];
|
|
1251
|
+
return this.getAll({ filter: { id: { $any: a } } });
|
|
1252
|
+
}
|
|
1253
|
+
if (isString(a)) {
|
|
1254
|
+
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, a);
|
|
1255
|
+
if (cacheRecord)
|
|
1256
|
+
return cacheRecord;
|
|
1257
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1258
|
+
try {
|
|
1259
|
+
const response = await getRecord({
|
|
1260
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: a },
|
|
1261
|
+
...fetchProps
|
|
1262
|
+
});
|
|
1263
|
+
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
|
1264
|
+
return initObject(this.db, schema, __privateGet$4(this, _table), response);
|
|
1265
|
+
} catch (e) {
|
|
1266
|
+
if (isObject(e) && e.status === 404) {
|
|
1267
|
+
return null;
|
|
1268
|
+
}
|
|
1269
|
+
throw e;
|
|
1240
1270
|
}
|
|
1241
|
-
throw e;
|
|
1242
1271
|
}
|
|
1243
1272
|
}
|
|
1244
1273
|
async update(a, b) {
|
|
1245
1274
|
if (Array.isArray(a)) {
|
|
1275
|
+
if (a.length === 0)
|
|
1276
|
+
return [];
|
|
1246
1277
|
if (a.length > 100) {
|
|
1247
1278
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1248
1279
|
}
|
|
@@ -1264,6 +1295,8 @@ class RestRepository extends Query {
|
|
|
1264
1295
|
}
|
|
1265
1296
|
async createOrUpdate(a, b) {
|
|
1266
1297
|
if (Array.isArray(a)) {
|
|
1298
|
+
if (a.length === 0)
|
|
1299
|
+
return [];
|
|
1267
1300
|
if (a.length > 100) {
|
|
1268
1301
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1269
1302
|
}
|
|
@@ -1285,6 +1318,8 @@ class RestRepository extends Query {
|
|
|
1285
1318
|
}
|
|
1286
1319
|
async delete(a) {
|
|
1287
1320
|
if (Array.isArray(a)) {
|
|
1321
|
+
if (a.length === 0)
|
|
1322
|
+
return;
|
|
1288
1323
|
if (a.length > 100) {
|
|
1289
1324
|
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
1290
1325
|
}
|
|
@@ -1310,6 +1345,7 @@ class RestRepository extends Query {
|
|
|
1310
1345
|
body: {
|
|
1311
1346
|
query,
|
|
1312
1347
|
fuzziness: options.fuzziness,
|
|
1348
|
+
highlight: options.highlight,
|
|
1313
1349
|
filter: options.filter
|
|
1314
1350
|
},
|
|
1315
1351
|
...fetchProps
|
|
@@ -1494,7 +1530,8 @@ const transformObjectLinks = (object) => {
|
|
|
1494
1530
|
};
|
|
1495
1531
|
const initObject = (db, schema, table, object) => {
|
|
1496
1532
|
const result = {};
|
|
1497
|
-
|
|
1533
|
+
const { xata, ...rest } = object ?? {};
|
|
1534
|
+
Object.assign(result, rest);
|
|
1498
1535
|
const { columns } = schema.tables.find(({ name }) => name === table) ?? {};
|
|
1499
1536
|
if (!columns)
|
|
1500
1537
|
console.error(`Table ${table} not found in schema`);
|
|
@@ -1502,10 +1539,10 @@ const initObject = (db, schema, table, object) => {
|
|
|
1502
1539
|
const value = result[column.name];
|
|
1503
1540
|
switch (column.type) {
|
|
1504
1541
|
case "datetime": {
|
|
1505
|
-
const date = new Date(value);
|
|
1506
|
-
if (isNaN(date.getTime())) {
|
|
1542
|
+
const date = value !== void 0 ? new Date(value) : void 0;
|
|
1543
|
+
if (date && isNaN(date.getTime())) {
|
|
1507
1544
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
|
1508
|
-
} else {
|
|
1545
|
+
} else if (date) {
|
|
1509
1546
|
result[column.name] = date;
|
|
1510
1547
|
}
|
|
1511
1548
|
break;
|
|
@@ -1530,7 +1567,10 @@ const initObject = (db, schema, table, object) => {
|
|
|
1530
1567
|
result.delete = function() {
|
|
1531
1568
|
return db[table].delete(result["id"]);
|
|
1532
1569
|
};
|
|
1533
|
-
|
|
1570
|
+
result.getMetadata = function() {
|
|
1571
|
+
return xata;
|
|
1572
|
+
};
|
|
1573
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
|
1534
1574
|
Object.defineProperty(result, prop, { enumerable: false });
|
|
1535
1575
|
}
|
|
1536
1576
|
Object.freeze(result);
|
|
@@ -1712,10 +1752,10 @@ _schema = new WeakMap();
|
|
|
1712
1752
|
_search = new WeakSet();
|
|
1713
1753
|
search_fn = async function(query, options, getFetchProps) {
|
|
1714
1754
|
const fetchProps = await getFetchProps();
|
|
1715
|
-
const { tables, fuzziness } = options ?? {};
|
|
1755
|
+
const { tables, fuzziness, highlight } = options ?? {};
|
|
1716
1756
|
const { records } = await searchBranch({
|
|
1717
1757
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
1718
|
-
body: { tables, query, fuzziness },
|
|
1758
|
+
body: { tables, query, fuzziness, highlight },
|
|
1719
1759
|
...fetchProps
|
|
1720
1760
|
});
|
|
1721
1761
|
return records;
|
|
@@ -1933,5 +1973,5 @@ class XataError extends Error {
|
|
|
1933
1973
|
}
|
|
1934
1974
|
}
|
|
1935
1975
|
|
|
1936
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
|
1976
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
|
1937
1977
|
//# sourceMappingURL=index.mjs.map
|