@xata.io/client 0.18.2 → 0.18.3
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 +6 -0
- package/dist/index.cjs +37 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +37 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
@@ -150,7 +150,7 @@ function getFetchImplementation(userFetch) {
|
|
150
150
|
return fetchImpl;
|
151
151
|
}
|
152
152
|
|
153
|
-
const VERSION = "0.18.
|
153
|
+
const VERSION = "0.18.3";
|
154
154
|
|
155
155
|
class ErrorWithCause extends Error {
|
156
156
|
constructor(message, options) {
|
@@ -1690,7 +1690,7 @@ class RestRepository extends Query {
|
|
1690
1690
|
...fetchProps
|
1691
1691
|
});
|
1692
1692
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1693
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1693
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1694
1694
|
} catch (e) {
|
1695
1695
|
if (isObject(e) && e.status === 404) {
|
1696
1696
|
return null;
|
@@ -1836,7 +1836,7 @@ class RestRepository extends Query {
|
|
1836
1836
|
...fetchProps
|
1837
1837
|
});
|
1838
1838
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1839
|
-
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1839
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
1840
1840
|
});
|
1841
1841
|
}
|
1842
1842
|
async query(query) {
|
@@ -1858,7 +1858,9 @@ class RestRepository extends Query {
|
|
1858
1858
|
...fetchProps
|
1859
1859
|
});
|
1860
1860
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1861
|
-
const records = objects.map(
|
1861
|
+
const records = objects.map(
|
1862
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
1863
|
+
);
|
1862
1864
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1863
1865
|
return new Page(query, meta, records);
|
1864
1866
|
});
|
@@ -1885,7 +1887,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1885
1887
|
...fetchProps
|
1886
1888
|
});
|
1887
1889
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1888
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1890
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1889
1891
|
};
|
1890
1892
|
_insertRecordWithId = new WeakSet();
|
1891
1893
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1903,7 +1905,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1903
1905
|
...fetchProps
|
1904
1906
|
});
|
1905
1907
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1906
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1908
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1907
1909
|
};
|
1908
1910
|
_bulkInsertTableRecords = new WeakSet();
|
1909
1911
|
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
@@ -1919,7 +1921,7 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1919
1921
|
throw new Error("Request included columns but server didn't include them");
|
1920
1922
|
}
|
1921
1923
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1922
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1924
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
1923
1925
|
};
|
1924
1926
|
_updateRecordWithID = new WeakSet();
|
1925
1927
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1933,7 +1935,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1933
1935
|
...fetchProps
|
1934
1936
|
});
|
1935
1937
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1936
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1938
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1937
1939
|
} catch (e) {
|
1938
1940
|
if (isObject(e) && e.status === 404) {
|
1939
1941
|
return null;
|
@@ -1951,7 +1953,7 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1951
1953
|
...fetchProps
|
1952
1954
|
});
|
1953
1955
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1954
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1956
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1955
1957
|
};
|
1956
1958
|
_deleteRecord = new WeakSet();
|
1957
1959
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
@@ -1963,7 +1965,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
1963
1965
|
...fetchProps
|
1964
1966
|
});
|
1965
1967
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1966
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1968
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1967
1969
|
} catch (e) {
|
1968
1970
|
if (isObject(e) && e.status === 404) {
|
1969
1971
|
return null;
|
@@ -2006,7 +2008,7 @@ const transformObjectLinks = (object) => {
|
|
2006
2008
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
2007
2009
|
}, {});
|
2008
2010
|
};
|
2009
|
-
const initObject = (db, schemaTables, table, object) => {
|
2011
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2010
2012
|
const result = {};
|
2011
2013
|
const { xata, ...rest } = object ?? {};
|
2012
2014
|
Object.assign(result, rest);
|
@@ -2014,6 +2016,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
2014
2016
|
if (!columns)
|
2015
2017
|
console.error(`Table ${table} not found in schema`);
|
2016
2018
|
for (const column of columns ?? []) {
|
2019
|
+
if (!isValidColumn(selectedColumns, column))
|
2020
|
+
continue;
|
2017
2021
|
const value = result[column.name];
|
2018
2022
|
switch (column.type) {
|
2019
2023
|
case "datetime": {
|
@@ -2030,7 +2034,17 @@ const initObject = (db, schemaTables, table, object) => {
|
|
2030
2034
|
if (!linkTable) {
|
2031
2035
|
console.error(`Failed to parse link for field ${column.name}`);
|
2032
2036
|
} else if (isObject(value)) {
|
2033
|
-
|
2037
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2038
|
+
if (item === column.name) {
|
2039
|
+
return [...acc, "*"];
|
2040
|
+
}
|
2041
|
+
if (item.startsWith(`${column.name}.`)) {
|
2042
|
+
const [, ...path] = item.split(".");
|
2043
|
+
return [...acc, path.join(".")];
|
2044
|
+
}
|
2045
|
+
return acc;
|
2046
|
+
}, []);
|
2047
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2034
2048
|
} else {
|
2035
2049
|
result[column.name] = null;
|
2036
2050
|
}
|
@@ -2078,6 +2092,15 @@ function cleanFilter(filter) {
|
|
2078
2092
|
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2079
2093
|
return values.length > 0 ? filter : void 0;
|
2080
2094
|
}
|
2095
|
+
function isValidColumn(columns, column) {
|
2096
|
+
if (columns.includes("*"))
|
2097
|
+
return true;
|
2098
|
+
if (column.type === "link") {
|
2099
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2100
|
+
return linkColumns.length > 0;
|
2101
|
+
}
|
2102
|
+
return columns.includes(column.name);
|
2103
|
+
}
|
2081
2104
|
|
2082
2105
|
var __accessCheck$3 = (obj, member, msg) => {
|
2083
2106
|
if (!member.has(obj))
|
@@ -2243,7 +2266,7 @@ class SearchPlugin extends XataPlugin {
|
|
2243
2266
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
2244
2267
|
return records.map((record) => {
|
2245
2268
|
const { table = "orphan" } = record.xata;
|
2246
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
2269
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
2247
2270
|
});
|
2248
2271
|
},
|
2249
2272
|
byTable: async (query, options = {}) => {
|
@@ -2252,7 +2275,7 @@ class SearchPlugin extends XataPlugin {
|
|
2252
2275
|
return records.reduce((acc, record) => {
|
2253
2276
|
const { table = "orphan" } = record.xata;
|
2254
2277
|
const items = acc[table] ?? [];
|
2255
|
-
const item = initObject(this.db, schemaTables, table, record);
|
2278
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
2256
2279
|
return { ...acc, [table]: [...items, item] };
|
2257
2280
|
}, {});
|
2258
2281
|
}
|