@xata.io/client 0.19.1 → 0.20.1
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 +22 -0
- package/README.md +2 -2
- package/Usage.md +5 -5
- package/dist/index.cjs +64 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +282 -50
- package/dist/index.mjs +64 -30
- package/dist/index.mjs.map +1 -1
- package/mod.ts +2 -0
- package/package.json +1 -1
- package/{rollup.config.js → rollup.config.mjs} +0 -0
- package/tsconfig.json +1 -1
package/dist/index.mjs
CHANGED
@@ -94,6 +94,25 @@ function getEnvironment() {
|
|
94
94
|
fallbackBranch: getGlobalFallbackBranch()
|
95
95
|
};
|
96
96
|
}
|
97
|
+
function getEnableBrowserVariable() {
|
98
|
+
try {
|
99
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
100
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
101
|
+
}
|
102
|
+
} catch (err) {
|
103
|
+
}
|
104
|
+
try {
|
105
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
106
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
107
|
+
}
|
108
|
+
} catch (err) {
|
109
|
+
}
|
110
|
+
try {
|
111
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
112
|
+
} catch (err) {
|
113
|
+
return void 0;
|
114
|
+
}
|
115
|
+
}
|
97
116
|
function getGlobalApiKey() {
|
98
117
|
try {
|
99
118
|
return XATA_API_KEY;
|
@@ -164,7 +183,7 @@ function getFetchImplementation(userFetch) {
|
|
164
183
|
return fetchImpl;
|
165
184
|
}
|
166
185
|
|
167
|
-
const VERSION = "0.
|
186
|
+
const VERSION = "0.20.1";
|
168
187
|
|
169
188
|
class ErrorWithCause extends Error {
|
170
189
|
constructor(message, options) {
|
@@ -254,7 +273,8 @@ async function fetch$1({
|
|
254
273
|
trace,
|
255
274
|
signal,
|
256
275
|
clientID,
|
257
|
-
sessionID
|
276
|
+
sessionID,
|
277
|
+
fetchOptions = {}
|
258
278
|
}) {
|
259
279
|
return trace(
|
260
280
|
`${method.toUpperCase()} ${path}`,
|
@@ -267,6 +287,7 @@ async function fetch$1({
|
|
267
287
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
268
288
|
});
|
269
289
|
const response = await fetchImpl(url, {
|
290
|
+
...fetchOptions,
|
270
291
|
method: method.toUpperCase(),
|
271
292
|
body: body ? JSON.stringify(body) : void 0,
|
272
293
|
headers: {
|
@@ -365,6 +386,7 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
365
386
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
366
387
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
367
388
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
389
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
368
390
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
369
391
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
370
392
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -495,6 +517,16 @@ const operationsByTag$2 = {
|
|
495
517
|
previewBranchSchemaEdit,
|
496
518
|
applyBranchSchemaEdit
|
497
519
|
},
|
520
|
+
records: {
|
521
|
+
branchTransaction,
|
522
|
+
insertRecord,
|
523
|
+
getRecord,
|
524
|
+
insertRecordWithID,
|
525
|
+
updateRecordWithID,
|
526
|
+
upsertRecordWithID,
|
527
|
+
deleteRecord,
|
528
|
+
bulkInsertTableRecords
|
529
|
+
},
|
498
530
|
migrationRequests: {
|
499
531
|
queryMigrationRequests,
|
500
532
|
createMigrationRequest,
|
@@ -517,15 +549,6 @@ const operationsByTag$2 = {
|
|
517
549
|
updateColumn,
|
518
550
|
deleteColumn
|
519
551
|
},
|
520
|
-
records: {
|
521
|
-
insertRecord,
|
522
|
-
getRecord,
|
523
|
-
insertRecordWithID,
|
524
|
-
updateRecordWithID,
|
525
|
-
upsertRecordWithID,
|
526
|
-
deleteRecord,
|
527
|
-
bulkInsertTableRecords
|
528
|
-
},
|
529
552
|
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
530
553
|
};
|
531
554
|
|
@@ -1357,11 +1380,12 @@ class SearchAndFilterApi {
|
|
1357
1380
|
filter,
|
1358
1381
|
sort,
|
1359
1382
|
page,
|
1360
|
-
columns
|
1383
|
+
columns,
|
1384
|
+
consistency
|
1361
1385
|
}) {
|
1362
1386
|
return operationsByTag.searchAndFilter.queryTable({
|
1363
1387
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1364
|
-
body: { filter, sort, page, columns },
|
1388
|
+
body: { filter, sort, page, columns, consistency },
|
1365
1389
|
...this.extraProps
|
1366
1390
|
});
|
1367
1391
|
}
|
@@ -1413,11 +1437,12 @@ class SearchAndFilterApi {
|
|
1413
1437
|
summaries,
|
1414
1438
|
sort,
|
1415
1439
|
summariesFilter,
|
1416
|
-
page
|
1440
|
+
page,
|
1441
|
+
consistency
|
1417
1442
|
}) {
|
1418
1443
|
return operationsByTag.searchAndFilter.summarizeTable({
|
1419
1444
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1420
|
-
body: { filter, columns, summaries, sort, summariesFilter, page },
|
1445
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
1421
1446
|
...this.extraProps
|
1422
1447
|
});
|
1423
1448
|
}
|
@@ -1777,11 +1802,11 @@ class Page {
|
|
1777
1802
|
async previousPage(size, offset) {
|
1778
1803
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1779
1804
|
}
|
1780
|
-
async
|
1781
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1805
|
+
async startPage(size, offset) {
|
1806
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1782
1807
|
}
|
1783
|
-
async
|
1784
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1808
|
+
async endPage(size, offset) {
|
1809
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1785
1810
|
}
|
1786
1811
|
hasNextPage() {
|
1787
1812
|
return this.meta.page.more;
|
@@ -1793,7 +1818,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1793
1818
|
const PAGINATION_MAX_OFFSET = 800;
|
1794
1819
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1795
1820
|
function isCursorPaginationOptions(options) {
|
1796
|
-
return isDefined(options) && (isDefined(options.
|
1821
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1797
1822
|
}
|
1798
1823
|
const _RecordArray = class extends Array {
|
1799
1824
|
constructor(...args) {
|
@@ -1825,12 +1850,12 @@ const _RecordArray = class extends Array {
|
|
1825
1850
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1826
1851
|
return new _RecordArray(newPage);
|
1827
1852
|
}
|
1828
|
-
async
|
1829
|
-
const newPage = await __privateGet$6(this, _page).
|
1853
|
+
async startPage(size, offset) {
|
1854
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1830
1855
|
return new _RecordArray(newPage);
|
1831
1856
|
}
|
1832
|
-
async
|
1833
|
-
const newPage = await __privateGet$6(this, _page).
|
1857
|
+
async endPage(size, offset) {
|
1858
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1834
1859
|
return new _RecordArray(newPage);
|
1835
1860
|
}
|
1836
1861
|
hasNextPage() {
|
@@ -1887,6 +1912,7 @@ const _Query = class {
|
|
1887
1912
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
1888
1913
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1889
1914
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
1915
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1890
1916
|
this.any = this.any.bind(this);
|
1891
1917
|
this.all = this.all.bind(this);
|
1892
1918
|
this.not = this.not.bind(this);
|
@@ -2014,15 +2040,15 @@ const _Query = class {
|
|
2014
2040
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2015
2041
|
}
|
2016
2042
|
nextPage(size, offset) {
|
2017
|
-
return this.
|
2043
|
+
return this.startPage(size, offset);
|
2018
2044
|
}
|
2019
2045
|
previousPage(size, offset) {
|
2020
|
-
return this.
|
2046
|
+
return this.startPage(size, offset);
|
2021
2047
|
}
|
2022
|
-
|
2048
|
+
startPage(size, offset) {
|
2023
2049
|
return this.getPaginated({ pagination: { size, offset } });
|
2024
2050
|
}
|
2025
|
-
|
2051
|
+
endPage(size, offset) {
|
2026
2052
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2027
2053
|
}
|
2028
2054
|
hasNextPage() {
|
@@ -2418,6 +2444,7 @@ class RestRepository extends Query {
|
|
2418
2444
|
page: data.pagination,
|
2419
2445
|
columns: data.columns ?? ["*"]
|
2420
2446
|
},
|
2447
|
+
fetchOptions: data.fetchOptions,
|
2421
2448
|
...fetchProps
|
2422
2449
|
});
|
2423
2450
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
@@ -3076,6 +3103,13 @@ const buildClient = (plugins) => {
|
|
3076
3103
|
return { databaseURL, branch };
|
3077
3104
|
}
|
3078
3105
|
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3106
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3107
|
+
const isBrowser = typeof window !== "undefined";
|
3108
|
+
if (isBrowser && !enableBrowser) {
|
3109
|
+
throw new Error(
|
3110
|
+
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
3111
|
+
);
|
3112
|
+
}
|
3079
3113
|
const fetch = getFetchImplementation(options?.fetch);
|
3080
3114
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3081
3115
|
const apiKey = options?.apiKey || getAPIKey();
|
@@ -3088,7 +3122,7 @@ const buildClient = (plugins) => {
|
|
3088
3122
|
if (!databaseURL) {
|
3089
3123
|
throw new Error("Option databaseURL is required");
|
3090
3124
|
}
|
3091
|
-
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID() };
|
3125
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
|
3092
3126
|
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
|
3093
3127
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3094
3128
|
if (!branchValue)
|
@@ -3215,5 +3249,5 @@ class XataError extends Error {
|
|
3215
3249
|
}
|
3216
3250
|
}
|
3217
3251
|
|
3218
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, dEPRECATEDcreateDatabase, dEPRECATEDdeleteDatabase, dEPRECATEDgetDatabaseList, dEPRECATEDgetDatabaseMetadata, dEPRECATEDupdateDatabaseMetadata, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
3252
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, dEPRECATEDcreateDatabase, dEPRECATEDdeleteDatabase, dEPRECATEDgetDatabaseList, dEPRECATEDgetDatabaseMetadata, dEPRECATEDupdateDatabaseMetadata, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
3219
3253
|
//# sourceMappingURL=index.mjs.map
|