@xata.io/client 0.0.0-beta.f12621e → 0.0.0-beta.f2b2fa6
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/dist/api/client.d.ts +93 -0
- package/dist/api/client.js +229 -0
- package/dist/api/components.d.ts +1416 -0
- package/dist/api/components.js +988 -0
- package/dist/api/fetcher.d.ts +25 -0
- package/dist/api/fetcher.js +78 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +21 -0
- package/dist/api/parameters.d.ts +15 -0
- package/dist/api/parameters.js +2 -0
- package/dist/api/providers.d.ts +8 -0
- package/dist/api/providers.js +29 -0
- package/dist/api/responses.d.ts +44 -0
- package/dist/api/responses.js +2 -0
- package/dist/api/schemas.d.ts +311 -0
- package/dist/api/schemas.js +2 -0
- package/dist/index.d.ts +15 -16
- package/dist/index.js +105 -109
- package/dist/schema/index.js +5 -1
- package/dist/schema/pagination.d.ts +3 -4
- package/dist/schema/pagination.js +19 -5
- package/dist/schema/query.d.ts +20 -18
- package/dist/schema/query.js +54 -52
- package/dist/schema/selection.d.ts +3 -7
- package/dist/util/lang.d.ts +2 -0
- package/dist/util/lang.js +10 -0
- package/package.json +2 -2
- package/dist/util/errors.d.ts +0 -3
- package/dist/util/errors.js +0 -9
package/dist/schema/query.js
CHANGED
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
16
|
+
};
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
21
|
+
};
|
11
22
|
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
12
23
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
13
24
|
var m = o[Symbol.asyncIterator], i;
|
@@ -27,32 +38,32 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
27
38
|
function reject(value) { resume("throw", value); }
|
28
39
|
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
29
40
|
};
|
41
|
+
var _Query_table, _Query_repository, _Query_data;
|
30
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
31
43
|
exports.Query = void 0;
|
44
|
+
const lang_1 = require("../util/lang");
|
32
45
|
class Query {
|
33
46
|
constructor(repository, table, data, parent) {
|
34
|
-
|
35
|
-
|
36
|
-
this
|
47
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
48
|
+
_Query_table.set(this, void 0);
|
49
|
+
_Query_repository.set(this, void 0);
|
50
|
+
_Query_data.set(this, { filter: {} });
|
51
|
+
// Implements pagination
|
37
52
|
this.meta = { page: { cursor: 'start', more: true } };
|
38
53
|
this.records = [];
|
54
|
+
__classPrivateFieldSet(this, _Query_table, table, "f");
|
39
55
|
if (repository) {
|
40
|
-
this
|
56
|
+
__classPrivateFieldSet(this, _Query_repository, repository, "f");
|
41
57
|
}
|
42
58
|
else {
|
43
|
-
this
|
59
|
+
__classPrivateFieldSet(this, _Query_repository, this, "f");
|
44
60
|
}
|
45
|
-
this.
|
46
|
-
|
47
|
-
|
48
|
-
this.$
|
49
|
-
this
|
50
|
-
this
|
51
|
-
this.$none = parent === null || parent === void 0 ? void 0 : parent.$none;
|
52
|
-
this.$sort = parent === null || parent === void 0 ? void 0 : parent.$sort;
|
53
|
-
Object.assign(this, data);
|
54
|
-
// These bindings are used to support deconstructing
|
55
|
-
// const { any, not, filter, sort } = xata.users.query()
|
61
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$any = (_b = (_a = data.filter) === null || _a === void 0 ? void 0 : _a.$any) !== null && _b !== void 0 ? _b : (_c = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _c === void 0 ? void 0 : _c.$any;
|
62
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$all = (_e = (_d = data.filter) === null || _d === void 0 ? void 0 : _d.$all) !== null && _e !== void 0 ? _e : (_f = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _f === void 0 ? void 0 : _f.$all;
|
63
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$not = (_h = (_g = data.filter) === null || _g === void 0 ? void 0 : _g.$not) !== null && _h !== void 0 ? _h : (_j = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _j === void 0 ? void 0 : _j.$not;
|
64
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$none = (_l = (_k = data.filter) === null || _k === void 0 ? void 0 : _k.$none) !== null && _l !== void 0 ? _l : (_m = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _m === void 0 ? void 0 : _m.$none;
|
65
|
+
__classPrivateFieldGet(this, _Query_data, "f").sort = (_o = data.sort) !== null && _o !== void 0 ? _o : parent === null || parent === void 0 ? void 0 : parent.sort;
|
66
|
+
__classPrivateFieldGet(this, _Query_data, "f").columns = (_q = (_p = data.columns) !== null && _p !== void 0 ? _p : parent === null || parent === void 0 ? void 0 : parent.columns) !== null && _q !== void 0 ? _q : ['*'];
|
56
67
|
this.any = this.any.bind(this);
|
57
68
|
this.all = this.all.bind(this);
|
58
69
|
this.not = this.not.bind(this);
|
@@ -62,58 +73,51 @@ class Query {
|
|
62
73
|
Object.defineProperty(this, 'table', { enumerable: false });
|
63
74
|
Object.defineProperty(this, 'repository', { enumerable: false });
|
64
75
|
}
|
76
|
+
getQueryOptions() {
|
77
|
+
return __classPrivateFieldGet(this, _Query_data, "f");
|
78
|
+
}
|
65
79
|
any(...queries) {
|
66
|
-
|
67
|
-
|
68
|
-
}, this);
|
80
|
+
const $any = queries.map((query) => query.getQueryOptions().filter);
|
81
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
69
82
|
}
|
70
83
|
all(...queries) {
|
71
|
-
|
72
|
-
|
73
|
-
}, this);
|
84
|
+
const $all = queries.map((query) => query.getQueryOptions().filter);
|
85
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
74
86
|
}
|
75
87
|
not(...queries) {
|
76
|
-
|
77
|
-
|
78
|
-
}, this);
|
88
|
+
const $not = queries.map((query) => query.getQueryOptions().filter);
|
89
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
79
90
|
}
|
80
91
|
none(...queries) {
|
81
|
-
|
82
|
-
|
83
|
-
}, this);
|
92
|
+
const $none = queries.map((query) => query.getQueryOptions().filter);
|
93
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
84
94
|
}
|
85
95
|
filter(a, b) {
|
86
96
|
if (arguments.length === 1) {
|
87
|
-
const constraints = a;
|
88
|
-
const
|
89
|
-
|
90
|
-
queries.push({ [column]: constraint });
|
91
|
-
}
|
92
|
-
return new Query(this.repository, this.table, {
|
93
|
-
$all: (this.$all || []).concat(queries)
|
94
|
-
}, this);
|
97
|
+
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
98
|
+
const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat(constraints));
|
99
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
95
100
|
}
|
96
101
|
else {
|
97
102
|
const column = a;
|
98
103
|
const value = b;
|
99
|
-
|
100
|
-
|
101
|
-
}, this);
|
104
|
+
const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat({ [column]: value }));
|
105
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
102
106
|
}
|
103
107
|
}
|
104
108
|
sort(column, direction) {
|
105
|
-
const sort = Object.assign(Object.assign({}, this
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
return
|
109
|
+
const sort = Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Query_data, "f").sort), { [column]: direction });
|
110
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
|
111
|
+
}
|
112
|
+
select(columns) {
|
113
|
+
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { columns }, __classPrivateFieldGet(this, _Query_data, "f"));
|
110
114
|
}
|
111
115
|
getPaginated(options = {}) {
|
112
116
|
return __awaiter(this, void 0, void 0, function* () {
|
113
|
-
return this.
|
117
|
+
return __classPrivateFieldGet(this, _Query_repository, "f").query(this, options);
|
114
118
|
});
|
115
119
|
}
|
116
|
-
[Symbol.asyncIterator]() {
|
120
|
+
[(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
|
117
121
|
return __asyncGenerator(this, arguments, function* _a() {
|
118
122
|
var e_1, _b;
|
119
123
|
try {
|
@@ -155,12 +159,10 @@ class Query {
|
|
155
159
|
return records[0] || null;
|
156
160
|
});
|
157
161
|
}
|
158
|
-
deleteAll() {
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
});
|
163
|
-
}
|
162
|
+
/**async deleteAll(): Promise<number> {
|
163
|
+
// TODO: Return number of affected rows
|
164
|
+
return 0;
|
165
|
+
}**/
|
164
166
|
nextPage(size, offset) {
|
165
167
|
return __awaiter(this, void 0, void 0, function* () {
|
166
168
|
return this.firstPage(size, offset);
|
@@ -1,16 +1,12 @@
|
|
1
1
|
import { XataRecord } from '..';
|
2
|
+
import { PartialBy } from '../util/lang';
|
2
3
|
import { StringKeys, UnionToIntersection, Values } from '../util/types';
|
3
4
|
import { Query } from './query';
|
4
5
|
declare type Queries<T> = {
|
5
6
|
[key in keyof T as T[key] extends Query<any> ? key : never]: T[key];
|
6
7
|
};
|
7
|
-
declare type
|
8
|
-
|
9
|
-
};
|
10
|
-
declare type OmitMethods<T> = {
|
11
|
-
[key in keyof T as T[key] extends Function ? never : key]: T[key];
|
12
|
-
};
|
13
|
-
export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>;
|
8
|
+
declare type InternalProperties = keyof Omit<XataRecord, 'id'>;
|
9
|
+
export declare type Selectable<T extends XataRecord> = Omit<PartialBy<T, 'id'>, InternalProperties>;
|
14
10
|
export declare type SelectableColumn<O> = '*' | (O extends Array<unknown> ? never : O extends Record<string, any> ? '*' | Values<{
|
15
11
|
[K in StringKeys<O>]: O[K] extends Record<string, any> ? `${K}.${SelectableColumn<O[K]>}` : K;
|
16
12
|
}> : '');
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.compact = void 0;
|
4
|
+
function notEmpty(value) {
|
5
|
+
return value !== null && value !== undefined;
|
6
|
+
}
|
7
|
+
function compact(arr) {
|
8
|
+
return arr.filter(notEmpty);
|
9
|
+
}
|
10
|
+
exports.compact = compact;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@xata.io/client",
|
3
|
-
"version": "0.0.0-beta.
|
3
|
+
"version": "0.0.0-beta.f2b2fa6",
|
4
4
|
"description": "Xata.io SDK for TypeScript and JavaScript",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.ts",
|
@@ -20,5 +20,5 @@
|
|
20
20
|
"url": "https://github.com/xataio/client-ts/issues"
|
21
21
|
},
|
22
22
|
"homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
|
23
|
-
"gitHead": "
|
23
|
+
"gitHead": "f2b2fa66f3f7564de4e1110dc8d1933c31ec81a3"
|
24
24
|
}
|
package/dist/util/errors.d.ts
DELETED
package/dist/util/errors.js
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.errors = void 0;
|
4
|
-
exports.errors = {
|
5
|
-
falsyFetchImplementation: `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.
|
6
|
-
|
7
|
-
More in the docs:
|
8
|
-
` /** @todo add a link after docs exist */
|
9
|
-
};
|