@xata.io/client 0.0.0-next.v6c9e627772cbacc1977ba6ba82e6b403ac64c0b2 → 0.0.0-next.va2d8ec2a91aa05ba703071b545a477e727db67d6
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/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +5 -3
- package/dist/index.cjs +47 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +51 -79
- package/dist/index.mjs +48 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
|
2
|
-
> @xata.io/client@0.29.
|
2
|
+
> @xata.io/client@0.29.2 build /home/runner/work/client-ts/client-ts/packages/client
|
3
3
|
> rimraf dist && rollup -c
|
4
4
|
|
5
5
|
[36m
|
6
6
|
[1msrc/index.ts[22m → [1mdist/index.cjs[22m...[39m
|
7
|
-
[32mcreated [1mdist/index.cjs[22m in [
|
7
|
+
[32mcreated [1mdist/index.cjs[22m in [1m995ms[22m[39m
|
8
8
|
[36m
|
9
9
|
[1msrc/index.ts[22m → [1mdist/index.mjs[22m...[39m
|
10
|
-
[32mcreated [1mdist/index.mjs[22m in [
|
10
|
+
[32mcreated [1mdist/index.mjs[22m in [1m675ms[22m[39m
|
11
11
|
[36m
|
12
12
|
[1msrc/index.ts[22m → [1mdist/index.d.ts[22m...[39m
|
13
|
-
[32mcreated [1mdist/index.d.ts[22m in [
|
13
|
+
[32mcreated [1mdist/index.d.ts[22m in [1m4.3s[22m[39m
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
-
## 0.0.0-next.
|
3
|
+
## 0.0.0-next.va2d8ec2a91aa05ba703071b545a477e727db67d6
|
4
4
|
|
5
5
|
### Major Changes
|
6
6
|
|
7
|
-
- [`
|
7
|
+
- [`c775d76`](https://github.com/xataio/client-ts/commit/c775d76c92a8f5e816958707aa9f98da1dc46ee3) Thanks [@SferaDev](https://github.com/SferaDev)! - Make XataApiClient to use ES Proxies
|
8
8
|
|
9
|
-
- [`
|
9
|
+
- [`86fd7b0`](https://github.com/xataio/client-ts/commit/86fd7b013efcd37addaed8f7c2c2bc2867303378) Thanks [@SferaDev](https://github.com/SferaDev)! - Version 1.0
|
10
|
+
|
11
|
+
## 0.29.2
|
10
12
|
|
11
13
|
### Patch Changes
|
12
14
|
|
package/dist/index.cjs
CHANGED
@@ -528,7 +528,7 @@ function defaultOnOpen(response) {
|
|
528
528
|
}
|
529
529
|
}
|
530
530
|
|
531
|
-
const VERSION = "0.29.
|
531
|
+
const VERSION = "0.29.2";
|
532
532
|
|
533
533
|
class ErrorWithCause extends Error {
|
534
534
|
constructor(message, options) {
|
@@ -740,6 +740,8 @@ async function fetch$1({
|
|
740
740
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
741
741
|
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
742
742
|
"X-Xata-Agent": xataAgent,
|
743
|
+
// Force field rename to xata_ internal properties
|
744
|
+
"X-Features": compact(["feat-internal-field-rename-api=1", customHeaders?.["X-Features"]]).join(" "),
|
743
745
|
...customHeaders,
|
744
746
|
...hostHeader(fullUrl),
|
745
747
|
Authorization: `Bearer ${apiKey}`
|
@@ -2025,8 +2027,8 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2025
2027
|
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2026
2028
|
return { $includes: value };
|
2027
2029
|
}
|
2028
|
-
if (columnType === "link" && isObject(value) && isString(value.
|
2029
|
-
return value.
|
2030
|
+
if (columnType === "link" && isObject(value) && isString(value.xata_id)) {
|
2031
|
+
return value.xata_id;
|
2030
2032
|
}
|
2031
2033
|
return value;
|
2032
2034
|
};
|
@@ -2054,12 +2056,7 @@ const RecordColumnTypes = [
|
|
2054
2056
|
"json"
|
2055
2057
|
];
|
2056
2058
|
function isIdentifiable(x) {
|
2057
|
-
return isObject(x) && isString(x?.
|
2058
|
-
}
|
2059
|
-
function isXataRecord(x) {
|
2060
|
-
const record = x;
|
2061
|
-
const metadata = record?.getMetadata();
|
2062
|
-
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2059
|
+
return isObject(x) && isString(x?.xata_id);
|
2063
2060
|
}
|
2064
2061
|
|
2065
2062
|
function isValidExpandedColumn(column) {
|
@@ -2186,11 +2183,14 @@ class RestRepository extends Query {
|
|
2186
2183
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2187
2184
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2188
2185
|
}
|
2189
|
-
if (isObject(a) && isString(a.
|
2190
|
-
if (a.
|
2186
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2187
|
+
if (a.xata_id === "")
|
2191
2188
|
throw new Error("The id can't be empty");
|
2192
2189
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2193
|
-
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.
|
2190
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
|
2191
|
+
createOnly: true,
|
2192
|
+
ifVersion
|
2193
|
+
});
|
2194
2194
|
}
|
2195
2195
|
if (isObject(a)) {
|
2196
2196
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
@@ -2206,9 +2206,9 @@ class RestRepository extends Query {
|
|
2206
2206
|
if (a.length === 0)
|
2207
2207
|
return [];
|
2208
2208
|
const ids = a.map((item) => extractId(item));
|
2209
|
-
const finalObjects = await this.getAll({ filter: {
|
2209
|
+
const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
|
2210
2210
|
const dictionary = finalObjects.reduce((acc, object) => {
|
2211
|
-
acc[object.
|
2211
|
+
acc[object.xata_id] = object;
|
2212
2212
|
return acc;
|
2213
2213
|
}, {});
|
2214
2214
|
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
@@ -2270,7 +2270,7 @@ class RestRepository extends Query {
|
|
2270
2270
|
if (Array.isArray(a)) {
|
2271
2271
|
if (a.length === 0)
|
2272
2272
|
return [];
|
2273
|
-
const existing = await this.read(a, ["
|
2273
|
+
const existing = await this.read(a, ["xata_id"]);
|
2274
2274
|
const updates = a.filter((_item, index) => existing[index] !== null);
|
2275
2275
|
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2276
2276
|
ifVersion,
|
@@ -2285,9 +2285,9 @@ class RestRepository extends Query {
|
|
2285
2285
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2286
2286
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2287
2287
|
}
|
2288
|
-
if (isObject(a) && isString(a.
|
2288
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2289
2289
|
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2290
|
-
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.
|
2290
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
|
2291
2291
|
}
|
2292
2292
|
} catch (error) {
|
2293
2293
|
if (error.status === 422)
|
@@ -2336,16 +2336,16 @@ class RestRepository extends Query {
|
|
2336
2336
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2337
2337
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2338
2338
|
}
|
2339
|
-
if (isObject(a) && isString(a.
|
2340
|
-
if (a.
|
2339
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2340
|
+
if (a.xata_id === "")
|
2341
2341
|
throw new Error("The id can't be empty");
|
2342
2342
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2343
|
-
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.
|
2343
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
|
2344
2344
|
}
|
2345
2345
|
if (!isDefined(a) && isObject(b)) {
|
2346
2346
|
return await this.create(b, c);
|
2347
2347
|
}
|
2348
|
-
if (isObject(a) && !isDefined(a.
|
2348
|
+
if (isObject(a) && !isDefined(a.xata_id)) {
|
2349
2349
|
return await this.create(a, b);
|
2350
2350
|
}
|
2351
2351
|
throw new Error("Invalid arguments for createOrUpdate method");
|
@@ -2368,16 +2368,19 @@ class RestRepository extends Query {
|
|
2368
2368
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2369
2369
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2370
2370
|
}
|
2371
|
-
if (isObject(a) && isString(a.
|
2372
|
-
if (a.
|
2371
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2372
|
+
if (a.xata_id === "")
|
2373
2373
|
throw new Error("The id can't be empty");
|
2374
2374
|
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2375
|
-
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.
|
2375
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
|
2376
|
+
createOnly: false,
|
2377
|
+
ifVersion
|
2378
|
+
});
|
2376
2379
|
}
|
2377
2380
|
if (!isDefined(a) && isObject(b)) {
|
2378
2381
|
return await this.create(b, c);
|
2379
2382
|
}
|
2380
|
-
if (isObject(a) && !isDefined(a.
|
2383
|
+
if (isObject(a) && !isDefined(a.xata_id)) {
|
2381
2384
|
return await this.create(a, b);
|
2382
2385
|
}
|
2383
2386
|
throw new Error("Invalid arguments for createOrReplace method");
|
@@ -2391,8 +2394,8 @@ class RestRepository extends Query {
|
|
2391
2394
|
const ids = a.map((o) => {
|
2392
2395
|
if (isString(o))
|
2393
2396
|
return o;
|
2394
|
-
if (isString(o.
|
2395
|
-
return o.
|
2397
|
+
if (isString(o.xata_id))
|
2398
|
+
return o.xata_id;
|
2396
2399
|
throw new Error("Invalid arguments for delete method");
|
2397
2400
|
});
|
2398
2401
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
@@ -2403,8 +2406,8 @@ class RestRepository extends Query {
|
|
2403
2406
|
if (isString(a)) {
|
2404
2407
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
2405
2408
|
}
|
2406
|
-
if (isObject(a) && isString(a.
|
2407
|
-
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.
|
2409
|
+
if (isObject(a) && isString(a.xata_id)) {
|
2410
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
|
2408
2411
|
}
|
2409
2412
|
throw new Error("Invalid arguments for delete method");
|
2410
2413
|
});
|
@@ -2666,7 +2669,7 @@ _updateRecordWithID = new WeakSet();
|
|
2666
2669
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2667
2670
|
if (!recordId)
|
2668
2671
|
return null;
|
2669
|
-
const {
|
2672
|
+
const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2670
2673
|
try {
|
2671
2674
|
const response = await updateRecordWithID({
|
2672
2675
|
pathParams: {
|
@@ -2691,9 +2694,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2691
2694
|
};
|
2692
2695
|
_updateRecords = new WeakSet();
|
2693
2696
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2694
|
-
const operations = await promiseMap(objects, async ({
|
2697
|
+
const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
|
2695
2698
|
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2696
|
-
return { update: { table: __privateGet$2(this, _table), id, ifVersion, upsert, fields } };
|
2699
|
+
return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
|
2697
2700
|
});
|
2698
2701
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2699
2702
|
const ids = [];
|
@@ -2798,12 +2801,12 @@ transformObjectToApi_fn = async function(object) {
|
|
2798
2801
|
throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
|
2799
2802
|
const result = {};
|
2800
2803
|
for (const [key, value] of Object.entries(object)) {
|
2801
|
-
if (
|
2804
|
+
if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
|
2802
2805
|
continue;
|
2803
2806
|
const type = schema.columns.find((column) => column.name === key)?.type;
|
2804
2807
|
switch (type) {
|
2805
2808
|
case "link": {
|
2806
|
-
result[key] = isIdentifiable(value) ? value.
|
2809
|
+
result[key] = isIdentifiable(value) ? value.xata_id : value;
|
2807
2810
|
break;
|
2808
2811
|
}
|
2809
2812
|
case "datetime": {
|
@@ -2827,8 +2830,7 @@ transformObjectToApi_fn = async function(object) {
|
|
2827
2830
|
};
|
2828
2831
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2829
2832
|
const data = {};
|
2830
|
-
|
2831
|
-
Object.assign(data, rest);
|
2833
|
+
Object.assign(data, { ...object });
|
2832
2834
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2833
2835
|
if (!columns)
|
2834
2836
|
console.error(`Table ${table} not found in schema`);
|
@@ -2891,28 +2893,21 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2891
2893
|
}
|
2892
2894
|
}
|
2893
2895
|
const record = { ...data };
|
2894
|
-
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2895
2896
|
record.read = function(columns2) {
|
2896
|
-
return db[table].read(record["
|
2897
|
+
return db[table].read(record["xata_id"], columns2);
|
2897
2898
|
};
|
2898
2899
|
record.update = function(data2, b, c) {
|
2899
2900
|
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2900
2901
|
const ifVersion = parseIfVersion(b, c);
|
2901
|
-
return db[table].update(record["
|
2902
|
+
return db[table].update(record["xata_id"], data2, columns2, { ifVersion });
|
2902
2903
|
};
|
2903
2904
|
record.replace = function(data2, b, c) {
|
2904
2905
|
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2905
2906
|
const ifVersion = parseIfVersion(b, c);
|
2906
|
-
return db[table].createOrReplace(record["
|
2907
|
+
return db[table].createOrReplace(record["xata_id"], data2, columns2, { ifVersion });
|
2907
2908
|
};
|
2908
2909
|
record.delete = function() {
|
2909
|
-
return db[table].delete(record["
|
2910
|
-
};
|
2911
|
-
if (metadata !== void 0) {
|
2912
|
-
record.xata = Object.freeze(metadata);
|
2913
|
-
}
|
2914
|
-
record.getMetadata = function() {
|
2915
|
-
return record.xata;
|
2910
|
+
return db[table].delete(record["xata_id"]);
|
2916
2911
|
};
|
2917
2912
|
record.toSerializable = function() {
|
2918
2913
|
return JSON.parse(JSON.stringify(record));
|
@@ -2920,7 +2915,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2920
2915
|
record.toString = function() {
|
2921
2916
|
return JSON.stringify(record);
|
2922
2917
|
};
|
2923
|
-
for (const prop of ["read", "update", "replace", "delete", "
|
2918
|
+
for (const prop of ["read", "update", "replace", "delete", "toSerializable", "toString"]) {
|
2924
2919
|
Object.defineProperty(record, prop, { enumerable: false });
|
2925
2920
|
}
|
2926
2921
|
Object.freeze(record);
|
@@ -2929,8 +2924,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2929
2924
|
function extractId(value) {
|
2930
2925
|
if (isString(value))
|
2931
2926
|
return value;
|
2932
|
-
if (isObject(value) && isString(value.
|
2933
|
-
return value.
|
2927
|
+
if (isObject(value) && isString(value.xata_id))
|
2928
|
+
return value.xata_id;
|
2934
2929
|
return void 0;
|
2935
2930
|
}
|
2936
2931
|
function isValidColumn(columns, column) {
|
@@ -3118,7 +3113,7 @@ class SearchPlugin extends XataPlugin {
|
|
3118
3113
|
return {
|
3119
3114
|
totalCount,
|
3120
3115
|
records: records.map((record) => {
|
3121
|
-
const
|
3116
|
+
const table = record.xata_table;
|
3122
3117
|
return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
|
3123
3118
|
})
|
3124
3119
|
};
|
@@ -3126,7 +3121,7 @@ class SearchPlugin extends XataPlugin {
|
|
3126
3121
|
byTable: async (query, options = {}) => {
|
3127
3122
|
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3128
3123
|
const records = rawRecords.reduce((acc, record) => {
|
3129
|
-
const
|
3124
|
+
const table = record.xata_table;
|
3130
3125
|
const items = acc[table] ?? [];
|
3131
3126
|
const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
|
3132
3127
|
return { ...acc, [table]: [...items, item] };
|
@@ -3598,7 +3593,6 @@ exports.isIdentifiable = isIdentifiable;
|
|
3598
3593
|
exports.isNot = isNot;
|
3599
3594
|
exports.isValidExpandedColumn = isValidExpandedColumn;
|
3600
3595
|
exports.isValidSelectableColumns = isValidSelectableColumns;
|
3601
|
-
exports.isXataRecord = isXataRecord;
|
3602
3596
|
exports.le = le;
|
3603
3597
|
exports.lessEquals = lessEquals;
|
3604
3598
|
exports.lessThan = lessThan;
|