@xata.io/client 0.21.6 → 0.22.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/.eslintrc.cjs +2 -1
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +18 -0
- package/LICENSE +201 -0
- package/README.md +3 -269
- package/dist/index.cjs +98 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1042 -883
- package/dist/index.mjs +96 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/Usage.md +0 -451
package/dist/index.cjs
CHANGED
@@ -302,7 +302,7 @@ function generateUUID() {
|
|
302
302
|
});
|
303
303
|
}
|
304
304
|
|
305
|
-
const VERSION = "0.
|
305
|
+
const VERSION = "0.22.1";
|
306
306
|
|
307
307
|
class ErrorWithCause extends Error {
|
308
308
|
constructor(message, options) {
|
@@ -396,12 +396,13 @@ async function fetch$1({
|
|
396
396
|
clientID,
|
397
397
|
sessionID,
|
398
398
|
clientName,
|
399
|
+
xataAgentExtra,
|
399
400
|
fetchOptions = {}
|
400
401
|
}) {
|
401
402
|
pool.setFetch(fetchImpl);
|
402
403
|
return await trace(
|
403
404
|
`${method.toUpperCase()} ${path}`,
|
404
|
-
async ({
|
405
|
+
async ({ setAttributes }) => {
|
405
406
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
406
407
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
407
408
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
@@ -412,7 +413,8 @@ async function fetch$1({
|
|
412
413
|
const xataAgent = compact([
|
413
414
|
["client", "TS_SDK"],
|
414
415
|
["version", VERSION],
|
415
|
-
isDefined(clientName) ? ["service", clientName] : void 0
|
416
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
417
|
+
...Object.entries(xataAgentExtra ?? {})
|
416
418
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
417
419
|
const headers = {
|
418
420
|
"Accept-Encoding": "identity",
|
@@ -514,7 +516,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
514
516
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
515
517
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
516
518
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
517
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
518
519
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
519
520
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
520
521
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -581,6 +582,7 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
581
582
|
...variables,
|
582
583
|
signal
|
583
584
|
});
|
585
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
584
586
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
585
587
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
586
588
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
@@ -638,16 +640,6 @@ const operationsByTag$2 = {
|
|
638
640
|
previewBranchSchemaEdit,
|
639
641
|
applyBranchSchemaEdit
|
640
642
|
},
|
641
|
-
records: {
|
642
|
-
branchTransaction,
|
643
|
-
insertRecord,
|
644
|
-
getRecord,
|
645
|
-
insertRecordWithID,
|
646
|
-
updateRecordWithID,
|
647
|
-
upsertRecordWithID,
|
648
|
-
deleteRecord,
|
649
|
-
bulkInsertTableRecords
|
650
|
-
},
|
651
643
|
migrationRequests: {
|
652
644
|
queryMigrationRequests,
|
653
645
|
createMigrationRequest,
|
@@ -670,6 +662,16 @@ const operationsByTag$2 = {
|
|
670
662
|
updateColumn,
|
671
663
|
deleteColumn
|
672
664
|
},
|
665
|
+
records: {
|
666
|
+
branchTransaction,
|
667
|
+
insertRecord,
|
668
|
+
getRecord,
|
669
|
+
insertRecordWithID,
|
670
|
+
updateRecordWithID,
|
671
|
+
upsertRecordWithID,
|
672
|
+
deleteRecord,
|
673
|
+
bulkInsertTableRecords
|
674
|
+
},
|
673
675
|
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
674
676
|
};
|
675
677
|
|
@@ -769,6 +771,9 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
769
771
|
});
|
770
772
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
771
773
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
774
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
775
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
776
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
772
777
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
773
778
|
url: "/workspaces/{workspaceId}/regions",
|
774
779
|
method: "get",
|
@@ -801,6 +806,9 @@ const operationsByTag$1 = {
|
|
801
806
|
deleteDatabase,
|
802
807
|
getDatabaseMetadata,
|
803
808
|
updateDatabaseMetadata,
|
809
|
+
getDatabaseGithubSettings,
|
810
|
+
updateDatabaseGithubSettings,
|
811
|
+
deleteDatabaseGithubSettings,
|
804
812
|
listRegions
|
805
813
|
}
|
806
814
|
};
|
@@ -845,7 +853,8 @@ function parseWorkspacesUrlParts(url) {
|
|
845
853
|
return null;
|
846
854
|
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
847
855
|
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
|
848
|
-
const
|
856
|
+
const regexDev = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xata\.tech.*/;
|
857
|
+
const match = url.match(regex) || url.match(regexStaging) || url.match(regexDev);
|
849
858
|
if (!match)
|
850
859
|
return null;
|
851
860
|
return { workspace: match[1], region: match[2] };
|
@@ -888,6 +897,7 @@ class XataApiClient {
|
|
888
897
|
apiKey,
|
889
898
|
trace,
|
890
899
|
clientName: options.clientName,
|
900
|
+
xataAgentExtra: options.xataAgentExtra,
|
891
901
|
clientID
|
892
902
|
});
|
893
903
|
}
|
@@ -1763,11 +1773,13 @@ class MigrationsApi {
|
|
1763
1773
|
region,
|
1764
1774
|
database,
|
1765
1775
|
branch,
|
1766
|
-
schema
|
1776
|
+
schema,
|
1777
|
+
schemaOperations,
|
1778
|
+
branchOperations
|
1767
1779
|
}) {
|
1768
1780
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1769
1781
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1770
|
-
body: { schema },
|
1782
|
+
body: { schema, schemaOperations, branchOperations },
|
1771
1783
|
...this.extraProps
|
1772
1784
|
});
|
1773
1785
|
}
|
@@ -1777,11 +1789,12 @@ class MigrationsApi {
|
|
1777
1789
|
database,
|
1778
1790
|
branch,
|
1779
1791
|
compare,
|
1780
|
-
|
1792
|
+
sourceBranchOperations,
|
1793
|
+
targetBranchOperations
|
1781
1794
|
}) {
|
1782
1795
|
return operationsByTag.migrations.compareBranchSchemas({
|
1783
1796
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1784
|
-
body: {
|
1797
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1785
1798
|
...this.extraProps
|
1786
1799
|
});
|
1787
1800
|
}
|
@@ -1875,6 +1888,35 @@ class DatabaseApi {
|
|
1875
1888
|
...this.extraProps
|
1876
1889
|
});
|
1877
1890
|
}
|
1891
|
+
getDatabaseGithubSettings({
|
1892
|
+
workspace,
|
1893
|
+
database
|
1894
|
+
}) {
|
1895
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
1896
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1897
|
+
...this.extraProps
|
1898
|
+
});
|
1899
|
+
}
|
1900
|
+
updateDatabaseGithubSettings({
|
1901
|
+
workspace,
|
1902
|
+
database,
|
1903
|
+
settings
|
1904
|
+
}) {
|
1905
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
1906
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1907
|
+
body: settings,
|
1908
|
+
...this.extraProps
|
1909
|
+
});
|
1910
|
+
}
|
1911
|
+
deleteDatabaseGithubSettings({
|
1912
|
+
workspace,
|
1913
|
+
database
|
1914
|
+
}) {
|
1915
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
1916
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1917
|
+
...this.extraProps
|
1918
|
+
});
|
1919
|
+
}
|
1878
1920
|
listRegions({ workspace }) {
|
1879
1921
|
return operationsByTag.databases.listRegions({
|
1880
1922
|
pathParams: { workspaceId: workspace },
|
@@ -1969,6 +2011,12 @@ const _RecordArray = class extends Array {
|
|
1969
2011
|
toArray() {
|
1970
2012
|
return new Array(...this);
|
1971
2013
|
}
|
2014
|
+
toSerializable() {
|
2015
|
+
return JSON.parse(this.toString());
|
2016
|
+
}
|
2017
|
+
toString() {
|
2018
|
+
return JSON.stringify(this.toArray());
|
2019
|
+
}
|
1972
2020
|
map(callbackfn, thisArg) {
|
1973
2021
|
return this.toArray().map(callbackfn, thisArg);
|
1974
2022
|
}
|
@@ -2936,7 +2984,13 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2936
2984
|
record.getMetadata = function() {
|
2937
2985
|
return xata;
|
2938
2986
|
};
|
2939
|
-
|
2987
|
+
record.toSerializable = function() {
|
2988
|
+
return JSON.parse(JSON.stringify(transformObjectLinks(data)));
|
2989
|
+
};
|
2990
|
+
record.toString = function() {
|
2991
|
+
return JSON.stringify(transformObjectLinks(data));
|
2992
|
+
};
|
2993
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2940
2994
|
Object.defineProperty(record, prop, { enumerable: false });
|
2941
2995
|
}
|
2942
2996
|
Object.freeze(record);
|
@@ -3228,7 +3282,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
3228
3282
|
pathParams: { dbName, workspace, region },
|
3229
3283
|
queryParams: { gitBranch, fallbackBranch },
|
3230
3284
|
trace: defaultTrace,
|
3231
|
-
clientName: options?.clientName
|
3285
|
+
clientName: options?.clientName,
|
3286
|
+
xataAgentExtra: options?.xataAgentExtra
|
3232
3287
|
});
|
3233
3288
|
return branch;
|
3234
3289
|
}
|
@@ -3348,11 +3403,13 @@ const buildClient = (plugins) => {
|
|
3348
3403
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3349
3404
|
const trace = options?.trace ?? defaultTrace;
|
3350
3405
|
const clientName = options?.clientName;
|
3406
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3351
3407
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3352
3408
|
apiKey,
|
3353
3409
|
databaseURL,
|
3354
3410
|
fetchImpl: options?.fetch,
|
3355
|
-
clientName
|
3411
|
+
clientName,
|
3412
|
+
xataAgentExtra
|
3356
3413
|
});
|
3357
3414
|
if (!apiKey) {
|
3358
3415
|
throw new Error("Option apiKey is required");
|
@@ -3360,7 +3417,18 @@ const buildClient = (plugins) => {
|
|
3360
3417
|
if (!databaseURL) {
|
3361
3418
|
throw new Error("Option databaseURL is required");
|
3362
3419
|
}
|
3363
|
-
return {
|
3420
|
+
return {
|
3421
|
+
fetch,
|
3422
|
+
databaseURL,
|
3423
|
+
apiKey,
|
3424
|
+
branch,
|
3425
|
+
cache,
|
3426
|
+
trace,
|
3427
|
+
clientID: generateUUID(),
|
3428
|
+
enableBrowser,
|
3429
|
+
clientName,
|
3430
|
+
xataAgentExtra
|
3431
|
+
};
|
3364
3432
|
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
3365
3433
|
fetch,
|
3366
3434
|
apiKey,
|
@@ -3368,7 +3436,8 @@ const buildClient = (plugins) => {
|
|
3368
3436
|
branch,
|
3369
3437
|
trace,
|
3370
3438
|
clientID,
|
3371
|
-
clientName
|
3439
|
+
clientName,
|
3440
|
+
xataAgentExtra
|
3372
3441
|
}) {
|
3373
3442
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3374
3443
|
if (!branchValue)
|
@@ -3384,7 +3453,8 @@ const buildClient = (plugins) => {
|
|
3384
3453
|
},
|
3385
3454
|
trace,
|
3386
3455
|
clientID,
|
3387
|
-
clientName
|
3456
|
+
clientName,
|
3457
|
+
xataAgentExtra
|
3388
3458
|
};
|
3389
3459
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3390
3460
|
if (__privateGet(this, _branch))
|
@@ -3539,6 +3609,7 @@ exports.createWorkspace = createWorkspace;
|
|
3539
3609
|
exports.deleteBranch = deleteBranch;
|
3540
3610
|
exports.deleteColumn = deleteColumn;
|
3541
3611
|
exports.deleteDatabase = deleteDatabase;
|
3612
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
3542
3613
|
exports.deleteRecord = deleteRecord;
|
3543
3614
|
exports.deleteTable = deleteTable;
|
3544
3615
|
exports.deleteUser = deleteUser;
|
@@ -3561,6 +3632,7 @@ exports.getBranchStats = getBranchStats;
|
|
3561
3632
|
exports.getColumn = getColumn;
|
3562
3633
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
3563
3634
|
exports.getCurrentBranchName = getCurrentBranchName;
|
3635
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3564
3636
|
exports.getDatabaseList = getDatabaseList;
|
3565
3637
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
3566
3638
|
exports.getDatabaseURL = getDatabaseURL;
|
@@ -3625,6 +3697,7 @@ exports.summarizeTable = summarizeTable;
|
|
3625
3697
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3626
3698
|
exports.updateBranchSchema = updateBranchSchema;
|
3627
3699
|
exports.updateColumn = updateColumn;
|
3700
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3628
3701
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3629
3702
|
exports.updateMigrationRequest = updateMigrationRequest;
|
3630
3703
|
exports.updateRecordWithID = updateRecordWithID;
|