@xata.io/client 0.21.5 → 0.22.0
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 +3 -2
- 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 +9 -2
- package/dist/index.cjs +47 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +892 -857
- package/dist/index.mjs +47 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rollup.config.mjs +28 -13
package/dist/index.mjs
CHANGED
@@ -170,9 +170,6 @@ async function getGitBranch() {
|
|
170
170
|
const nodeModule = ["child", "process"].join("_");
|
171
171
|
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
172
172
|
try {
|
173
|
-
if (typeof require === "function") {
|
174
|
-
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
175
|
-
}
|
176
173
|
const { execSync } = await import(nodeModule);
|
177
174
|
return execSync(fullCmd, execOptions).toString().trim();
|
178
175
|
} catch (err) {
|
@@ -302,7 +299,7 @@ function generateUUID() {
|
|
302
299
|
});
|
303
300
|
}
|
304
301
|
|
305
|
-
const VERSION = "0.
|
302
|
+
const VERSION = "0.22.0";
|
306
303
|
|
307
304
|
class ErrorWithCause extends Error {
|
308
305
|
constructor(message, options) {
|
@@ -401,7 +398,7 @@ async function fetch$1({
|
|
401
398
|
pool.setFetch(fetchImpl);
|
402
399
|
return await trace(
|
403
400
|
`${method.toUpperCase()} ${path}`,
|
404
|
-
async ({
|
401
|
+
async ({ setAttributes }) => {
|
405
402
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
406
403
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
407
404
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
@@ -514,7 +511,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
514
511
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
515
512
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
516
513
|
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
514
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
519
515
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
520
516
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -581,6 +577,7 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
581
577
|
...variables,
|
582
578
|
signal
|
583
579
|
});
|
580
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
584
581
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
585
582
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
586
583
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
@@ -638,16 +635,6 @@ const operationsByTag$2 = {
|
|
638
635
|
previewBranchSchemaEdit,
|
639
636
|
applyBranchSchemaEdit
|
640
637
|
},
|
641
|
-
records: {
|
642
|
-
branchTransaction,
|
643
|
-
insertRecord,
|
644
|
-
getRecord,
|
645
|
-
insertRecordWithID,
|
646
|
-
updateRecordWithID,
|
647
|
-
upsertRecordWithID,
|
648
|
-
deleteRecord,
|
649
|
-
bulkInsertTableRecords
|
650
|
-
},
|
651
638
|
migrationRequests: {
|
652
639
|
queryMigrationRequests,
|
653
640
|
createMigrationRequest,
|
@@ -670,6 +657,16 @@ const operationsByTag$2 = {
|
|
670
657
|
updateColumn,
|
671
658
|
deleteColumn
|
672
659
|
},
|
660
|
+
records: {
|
661
|
+
branchTransaction,
|
662
|
+
insertRecord,
|
663
|
+
getRecord,
|
664
|
+
insertRecordWithID,
|
665
|
+
updateRecordWithID,
|
666
|
+
upsertRecordWithID,
|
667
|
+
deleteRecord,
|
668
|
+
bulkInsertTableRecords
|
669
|
+
},
|
673
670
|
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
674
671
|
};
|
675
672
|
|
@@ -1969,6 +1966,12 @@ const _RecordArray = class extends Array {
|
|
1969
1966
|
toArray() {
|
1970
1967
|
return new Array(...this);
|
1971
1968
|
}
|
1969
|
+
toSerializable() {
|
1970
|
+
return JSON.parse(this.toString());
|
1971
|
+
}
|
1972
|
+
toString() {
|
1973
|
+
return JSON.stringify(this.toArray());
|
1974
|
+
}
|
1972
1975
|
map(callbackfn, thisArg) {
|
1973
1976
|
return this.toArray().map(callbackfn, thisArg);
|
1974
1977
|
}
|
@@ -2867,23 +2870,23 @@ const transformObjectLinks = (object) => {
|
|
2867
2870
|
}, {});
|
2868
2871
|
};
|
2869
2872
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2870
|
-
const
|
2873
|
+
const data = {};
|
2871
2874
|
const { xata, ...rest } = object ?? {};
|
2872
|
-
Object.assign(
|
2875
|
+
Object.assign(data, rest);
|
2873
2876
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2874
2877
|
if (!columns)
|
2875
2878
|
console.error(`Table ${table} not found in schema`);
|
2876
2879
|
for (const column of columns ?? []) {
|
2877
2880
|
if (!isValidColumn(selectedColumns, column))
|
2878
2881
|
continue;
|
2879
|
-
const value =
|
2882
|
+
const value = data[column.name];
|
2880
2883
|
switch (column.type) {
|
2881
2884
|
case "datetime": {
|
2882
2885
|
const date = value !== void 0 ? new Date(value) : null;
|
2883
2886
|
if (date !== null && isNaN(date.getTime())) {
|
2884
2887
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2885
2888
|
} else {
|
2886
|
-
|
2889
|
+
data[column.name] = date;
|
2887
2890
|
}
|
2888
2891
|
break;
|
2889
2892
|
}
|
@@ -2902,44 +2905,51 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2902
2905
|
}
|
2903
2906
|
return acc;
|
2904
2907
|
}, []);
|
2905
|
-
|
2908
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2906
2909
|
} else {
|
2907
|
-
|
2910
|
+
data[column.name] = null;
|
2908
2911
|
}
|
2909
2912
|
break;
|
2910
2913
|
}
|
2911
2914
|
default:
|
2912
|
-
|
2915
|
+
data[column.name] = value ?? null;
|
2913
2916
|
if (column.notNull === true && value === null) {
|
2914
2917
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2915
2918
|
}
|
2916
2919
|
break;
|
2917
2920
|
}
|
2918
2921
|
}
|
2919
|
-
|
2920
|
-
|
2922
|
+
const record = { ...data };
|
2923
|
+
record.read = function(columns2) {
|
2924
|
+
return db[table].read(record["id"], columns2);
|
2921
2925
|
};
|
2922
|
-
|
2926
|
+
record.update = function(data2, b, c) {
|
2923
2927
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2924
2928
|
const ifVersion = parseIfVersion(b, c);
|
2925
|
-
return db[table].update(
|
2929
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2926
2930
|
};
|
2927
|
-
|
2931
|
+
record.replace = function(data2, b, c) {
|
2928
2932
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2929
2933
|
const ifVersion = parseIfVersion(b, c);
|
2930
|
-
return db[table].createOrReplace(
|
2934
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2931
2935
|
};
|
2932
|
-
|
2933
|
-
return db[table].delete(
|
2936
|
+
record.delete = function() {
|
2937
|
+
return db[table].delete(record["id"]);
|
2934
2938
|
};
|
2935
|
-
|
2939
|
+
record.getMetadata = function() {
|
2936
2940
|
return xata;
|
2937
2941
|
};
|
2938
|
-
|
2939
|
-
|
2942
|
+
record.toSerializable = function() {
|
2943
|
+
return JSON.parse(JSON.stringify(transformObjectLinks(data)));
|
2944
|
+
};
|
2945
|
+
record.toString = function() {
|
2946
|
+
return JSON.stringify(transformObjectLinks(data));
|
2947
|
+
};
|
2948
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2949
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2940
2950
|
}
|
2941
|
-
Object.freeze(
|
2942
|
-
return
|
2951
|
+
Object.freeze(record);
|
2952
|
+
return record;
|
2943
2953
|
};
|
2944
2954
|
function extractId(value) {
|
2945
2955
|
if (isString(value))
|
@@ -3335,7 +3345,7 @@ const buildClient = (plugins) => {
|
|
3335
3345
|
}
|
3336
3346
|
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3337
3347
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3338
|
-
const isBrowser = typeof window !== "undefined";
|
3348
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3339
3349
|
if (isBrowser && !enableBrowser) {
|
3340
3350
|
throw new Error(
|
3341
3351
|
"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."
|