@xata.io/client 0.0.0-alpha.fd777ef → 0.0.0-beta.09bfef8
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 +14 -0
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.js +8 -8
- package/dist/api/fetcher.d.ts +15 -0
- package/dist/api/fetcher.js +19 -13
- package/dist/schema/config.d.ts +4 -0
- package/dist/schema/config.js +83 -0
- package/dist/schema/filters.d.ts +16 -12
- package/dist/schema/operators.d.ts +17 -27
- package/dist/schema/operators.js +1 -14
- package/dist/schema/query.d.ts +3 -3
- package/dist/schema/repository.d.ts +56 -8
- package/dist/schema/repository.js +143 -54
- package/dist/schema/selection.d.ts +4 -3
- package/dist/schema/selection.spec.js +152 -58
- package/dist/schema/sorting.d.ts +8 -3
- package/dist/schema/sorting.js +18 -15
- package/dist/schema/sorting.spec.d.ts +1 -0
- package/dist/schema/sorting.spec.js +9 -0
- package/dist/util/environment.d.ts +5 -0
- package/dist/util/environment.js +68 -0
- package/dist/util/fetch.d.ts +2 -0
- package/dist/util/fetch.js +13 -0
- package/dist/util/lang.d.ts +1 -1
- package/dist/util/lang.js +1 -1
- package/package.json +2 -2
@@ -26,11 +26,13 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
26
26
|
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
27
27
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
28
28
|
};
|
29
|
-
var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _BaseClient_links, _BaseClient_branch;
|
29
|
+
var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _RestRepository_bulkInsertTableRecords, _RestRepository_updateRecordWithID, _RestRepository_upsertRecordWithID, _RestRepository_deleteRecord, _BaseClient_links, _BaseClient_branch;
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
31
31
|
exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
|
32
32
|
const api_1 = require("../api");
|
33
|
+
const fetch_1 = require("../util/fetch");
|
33
34
|
const lang_1 = require("../util/lang");
|
35
|
+
const config_1 = require("./config");
|
34
36
|
const pagination_1 = require("./pagination");
|
35
37
|
const query_1 = require("./query");
|
36
38
|
const record_1 = require("./record");
|
@@ -43,7 +45,6 @@ class Repository extends query_1.Query {
|
|
43
45
|
exports.Repository = Repository;
|
44
46
|
class RestRepository extends query_1.Query {
|
45
47
|
constructor(client, table) {
|
46
|
-
var _a;
|
47
48
|
super(null, table, {});
|
48
49
|
_RestRepository_instances.add(this);
|
49
50
|
_RestRepository_client.set(this, void 0);
|
@@ -51,80 +52,113 @@ class RestRepository extends query_1.Query {
|
|
51
52
|
_RestRepository_table.set(this, void 0);
|
52
53
|
__classPrivateFieldSet(this, _RestRepository_client, client, "f");
|
53
54
|
__classPrivateFieldSet(this, _RestRepository_table, table, "f");
|
54
|
-
|
55
|
-
const globalFetch = typeof fetch !== 'undefined' ? fetch : undefined;
|
56
|
-
const fetchImpl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch) !== null && _a !== void 0 ? _a : globalFetch;
|
57
|
-
if (!fetchImpl) {
|
58
|
-
/** @todo add a link after docs exist */
|
59
|
-
throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
|
60
|
-
}
|
61
|
-
__classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
|
55
|
+
__classPrivateFieldSet(this, _RestRepository_fetch, (0, fetch_1.getFetchImplementation)(__classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch), "f");
|
62
56
|
}
|
63
57
|
create(a, b) {
|
64
58
|
return __awaiter(this, void 0, void 0, function* () {
|
59
|
+
// Create many records
|
60
|
+
if (Array.isArray(a)) {
|
61
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_bulkInsertTableRecords).call(this, a);
|
62
|
+
}
|
63
|
+
// Create one record with id as param
|
65
64
|
if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
|
66
65
|
if (a === '')
|
67
66
|
throw new Error("The id can't be empty");
|
68
67
|
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a, b);
|
69
68
|
}
|
70
|
-
|
69
|
+
// Create one record with id as property
|
70
|
+
if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
|
71
71
|
if (a.id === '')
|
72
72
|
throw new Error("The id can't be empty");
|
73
73
|
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
|
74
74
|
}
|
75
|
-
|
75
|
+
// Create one record without id
|
76
|
+
if ((0, lang_1.isObject)(a)) {
|
76
77
|
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithoutId).call(this, a);
|
77
78
|
}
|
78
|
-
|
79
|
-
throw new Error('Invalid arguments for create method');
|
80
|
-
}
|
81
|
-
});
|
82
|
-
}
|
83
|
-
createMany(objects) {
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
85
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
86
|
-
const records = objects.map((object) => transformObjectLinks(object));
|
87
|
-
const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
|
88
|
-
const finalObjects = yield this.any(...response.recordIDs.map((id) => this.filter('id', id))).getAll();
|
89
|
-
if (finalObjects.length !== objects.length) {
|
90
|
-
throw new Error('The server failed to save some records');
|
91
|
-
}
|
92
|
-
return finalObjects;
|
79
|
+
throw new Error('Invalid arguments for create method');
|
93
80
|
});
|
94
81
|
}
|
95
82
|
// TODO: Add column support: https://github.com/xataio/openapi/issues/139
|
96
83
|
read(recordId) {
|
97
84
|
return __awaiter(this, void 0, void 0, function* () {
|
98
85
|
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
99
|
-
|
100
|
-
|
86
|
+
try {
|
87
|
+
const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
88
|
+
return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
|
89
|
+
}
|
90
|
+
catch (e) {
|
91
|
+
if ((0, lang_1.isObject)(e) && e.status === 404) {
|
92
|
+
return null;
|
93
|
+
}
|
94
|
+
throw e;
|
95
|
+
}
|
101
96
|
});
|
102
97
|
}
|
103
|
-
update(
|
98
|
+
update(a, b) {
|
104
99
|
return __awaiter(this, void 0, void 0, function* () {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
100
|
+
// Update many records
|
101
|
+
if (Array.isArray(a)) {
|
102
|
+
if (a.length > 100) {
|
103
|
+
// TODO: Implement bulk update when API has support for it
|
104
|
+
console.warn('Bulk update operation is not optimized in the Xata API yet, this request might be slow');
|
105
|
+
}
|
106
|
+
return Promise.all(a.map((object) => this.update(object)));
|
107
|
+
}
|
108
|
+
// Update one record with id as param
|
109
|
+
if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
|
110
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_updateRecordWithID).call(this, a, b);
|
111
|
+
}
|
112
|
+
// Update one record with id as property
|
113
|
+
if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
|
114
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_updateRecordWithID).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
|
115
|
+
}
|
116
|
+
throw new Error('Invalid arguments for update method');
|
112
117
|
});
|
113
118
|
}
|
114
|
-
createOrUpdate(
|
119
|
+
createOrUpdate(a, b) {
|
115
120
|
return __awaiter(this, void 0, void 0, function* () {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
121
|
+
// Create or update many records
|
122
|
+
if (Array.isArray(a)) {
|
123
|
+
if (a.length > 100) {
|
124
|
+
// TODO: Implement bulk update when API has support for it
|
125
|
+
console.warn('Bulk update operation is not optimized in the Xata API yet, this request might be slow');
|
126
|
+
}
|
127
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object)));
|
128
|
+
}
|
129
|
+
// Create or update one record with id as param
|
130
|
+
if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
|
131
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_upsertRecordWithID).call(this, a, b);
|
132
|
+
}
|
133
|
+
// Create or update one record with id as property
|
134
|
+
if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
|
135
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_upsertRecordWithID).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
|
136
|
+
}
|
137
|
+
throw new Error('Invalid arguments for createOrUpdate method');
|
122
138
|
});
|
123
139
|
}
|
124
140
|
delete(recordId) {
|
125
141
|
return __awaiter(this, void 0, void 0, function* () {
|
126
|
-
|
127
|
-
|
142
|
+
// Delete many records
|
143
|
+
if (Array.isArray(recordId)) {
|
144
|
+
if (recordId.length > 100) {
|
145
|
+
// TODO: Implement bulk delete when API has support for it
|
146
|
+
console.warn('Bulk delete operation is not optimized in the Xata API yet, this request might be slow');
|
147
|
+
}
|
148
|
+
yield Promise.all(recordId.map((id) => this.delete(id)));
|
149
|
+
return;
|
150
|
+
}
|
151
|
+
// Delete one record with id as param
|
152
|
+
if ((0, lang_1.isString)(recordId)) {
|
153
|
+
yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_deleteRecord).call(this, recordId);
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
// Delete one record with id as property
|
157
|
+
if ((0, lang_1.isObject)(recordId) && (0, lang_1.isString)(recordId.id)) {
|
158
|
+
yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_deleteRecord).call(this, recordId.id);
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
throw new Error('Invalid arguments for delete method');
|
128
162
|
});
|
129
163
|
}
|
130
164
|
query(query) {
|
@@ -133,7 +167,7 @@ class RestRepository extends query_1.Query {
|
|
133
167
|
const data = query.getQueryOptions();
|
134
168
|
const body = {
|
135
169
|
filter: Object.values((_a = data.filter) !== null && _a !== void 0 ? _a : {}).some(Boolean) ? data.filter : undefined,
|
136
|
-
sort: (0, sorting_1.buildSortFilter)(data.sort),
|
170
|
+
sort: data.sort ? (0, sorting_1.buildSortFilter)(data.sort) : undefined,
|
137
171
|
page: data.page,
|
138
172
|
columns: data.columns
|
139
173
|
};
|
@@ -146,11 +180,16 @@ class RestRepository extends query_1.Query {
|
|
146
180
|
}
|
147
181
|
exports.RestRepository = RestRepository;
|
148
182
|
_RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_getFetchProps = function _RestRepository_getFetchProps() {
|
183
|
+
var _a;
|
149
184
|
return __awaiter(this, void 0, void 0, function* () {
|
150
185
|
const branch = yield __classPrivateFieldGet(this, _RestRepository_client, "f").getBranch();
|
186
|
+
const apiKey = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.apiKey) !== null && _a !== void 0 ? _a : (0, config_1.getAPIKey)();
|
187
|
+
if (!apiKey) {
|
188
|
+
throw new Error('Could not resolve a valid apiKey');
|
189
|
+
}
|
151
190
|
return {
|
152
191
|
fetchImpl: __classPrivateFieldGet(this, _RestRepository_fetch, "f"),
|
153
|
-
apiKey
|
192
|
+
apiKey,
|
154
193
|
apiUrl: '',
|
155
194
|
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
156
195
|
workspacesApiUrl: (path, params) => {
|
@@ -193,6 +232,41 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
|
|
193
232
|
}
|
194
233
|
return finalObject;
|
195
234
|
});
|
235
|
+
}, _RestRepository_bulkInsertTableRecords = function _RestRepository_bulkInsertTableRecords(objects) {
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
237
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
238
|
+
const records = objects.map((object) => transformObjectLinks(object));
|
239
|
+
const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
|
240
|
+
const finalObjects = yield this.any(...response.recordIDs.map((id) => this.filter('id', id))).getAll();
|
241
|
+
if (finalObjects.length !== objects.length) {
|
242
|
+
throw new Error('The server failed to save some records');
|
243
|
+
}
|
244
|
+
return finalObjects;
|
245
|
+
});
|
246
|
+
}, _RestRepository_updateRecordWithID = function _RestRepository_updateRecordWithID(recordId, object) {
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
248
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
249
|
+
const record = transformObjectLinks(object);
|
250
|
+
const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: record }, fetchProps));
|
251
|
+
const item = yield this.read(response.id);
|
252
|
+
if (!item)
|
253
|
+
throw new Error('The server failed to save the record');
|
254
|
+
return item;
|
255
|
+
});
|
256
|
+
}, _RestRepository_upsertRecordWithID = function _RestRepository_upsertRecordWithID(recordId, object) {
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
258
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
259
|
+
const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
|
260
|
+
const item = yield this.read(response.id);
|
261
|
+
if (!item)
|
262
|
+
throw new Error('The server failed to save the record');
|
263
|
+
return item;
|
264
|
+
});
|
265
|
+
}, _RestRepository_deleteRecord = function _RestRepository_deleteRecord(recordId) {
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
267
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
268
|
+
yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
269
|
+
});
|
196
270
|
};
|
197
271
|
class RestRespositoryFactory {
|
198
272
|
createRepository(client, table) {
|
@@ -200,16 +274,31 @@ class RestRespositoryFactory {
|
|
200
274
|
}
|
201
275
|
}
|
202
276
|
exports.RestRespositoryFactory = RestRespositoryFactory;
|
277
|
+
function resolveXataClientOptions(options) {
|
278
|
+
const databaseURL = (options === null || options === void 0 ? void 0 : options.databaseURL) || (0, config_1.getDatabaseUrl)() || '';
|
279
|
+
const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (0, config_1.getAPIKey)() || '';
|
280
|
+
const branch = (options === null || options === void 0 ? void 0 : options.branch) ||
|
281
|
+
(() => (0, config_1.getBranch)({
|
282
|
+
apiKey,
|
283
|
+
apiUrl: databaseURL,
|
284
|
+
fetchImpl: (0, fetch_1.getFetchImplementation)(options === null || options === void 0 ? void 0 : options.fetch)
|
285
|
+
}));
|
286
|
+
if (!databaseURL || !apiKey) {
|
287
|
+
throw new Error('Options databaseURL and apiKey are required');
|
288
|
+
}
|
289
|
+
return Object.assign(Object.assign({}, options), { databaseURL,
|
290
|
+
apiKey,
|
291
|
+
branch });
|
292
|
+
}
|
203
293
|
class BaseClient {
|
204
|
-
constructor(options, links = {}) {
|
294
|
+
constructor(options = {}, links = {}) {
|
205
295
|
_BaseClient_links.set(this, void 0);
|
206
296
|
_BaseClient_branch.set(this, void 0);
|
207
|
-
|
208
|
-
|
209
|
-
}
|
210
|
-
this.options = options;
|
297
|
+
this.options = resolveXataClientOptions(options);
|
298
|
+
// Make this property not enumerable so it doesn't show up in console.dir, etc.
|
299
|
+
Object.defineProperty(this.options, 'apiKey', { enumerable: false });
|
211
300
|
__classPrivateFieldSet(this, _BaseClient_links, links, "f");
|
212
|
-
const factory = options.repositoryFactory || new RestRespositoryFactory();
|
301
|
+
const factory = this.options.repositoryFactory || new RestRespositoryFactory();
|
213
302
|
this.db = new Proxy({}, {
|
214
303
|
get: (_target, prop) => {
|
215
304
|
if (typeof prop !== 'string')
|
@@ -15,10 +15,11 @@ declare type NestedColumns<O, RecursivePath extends any[]> = RecursivePath['leng
|
|
15
15
|
}>, never>;
|
16
16
|
declare type DataProps<O> = Exclude<StringKeys<O>, StringKeys<XataRecord>>;
|
17
17
|
declare type NestedValueAtColumn<O, Key extends SelectableColumn<O>> = Key extends `${infer N}.${infer M}` ? N extends DataProps<O> ? {
|
18
|
-
[K in N]: M extends SelectableColumn<NonNullable<O[K]>> ? NestedValueAtColumn<NonNullable<O[K]>, M> & XataRecord : unknown;
|
18
|
+
[K in N]: M extends SelectableColumn<NonNullable<O[K]>> ? NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M> & XataRecord> : ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M>> : unknown;
|
19
19
|
} : unknown : Key extends DataProps<O> ? {
|
20
|
-
[K in Key]: NonNullable<O[K]> extends XataRecord ? SelectedPick<NonNullable<O[K]>, ['*']
|
20
|
+
[K in Key]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], SelectedPick<NonNullable<O[K]>, ['*']>> : O[K];
|
21
21
|
} : Key extends '*' ? {
|
22
|
-
[K in
|
22
|
+
[K in StringKeys<O>]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], Link<NonNullable<O[K]>>> : O[K];
|
23
23
|
} : unknown;
|
24
|
+
declare type ForwardNullable<T, R> = T extends NonNullable<T> ? R : R | null;
|
24
25
|
export {};
|
@@ -27,82 +27,176 @@ const labelsValue = ['foo'];
|
|
27
27
|
const invalidLabelsValue = [1];
|
28
28
|
// SelectedRecordPick<O, Key> //
|
29
29
|
// ---------------------------------------------------------------------------- //
|
30
|
-
function
|
30
|
+
function test1(user) {
|
31
31
|
var _a, _b, _c, _d;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
(_a =
|
32
|
+
user.id;
|
33
|
+
user.read();
|
34
|
+
user.full_name;
|
35
|
+
(_a = user.address) === null || _a === void 0 ? void 0 : _a.street;
|
36
36
|
// @ts-expect-error
|
37
|
-
|
38
|
-
(_b =
|
39
|
-
(_c =
|
37
|
+
user.team.id;
|
38
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.id;
|
39
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.read();
|
40
40
|
// @ts-expect-error
|
41
|
-
(_d =
|
42
|
-
|
43
|
-
|
41
|
+
(_d = user.team) === null || _d === void 0 ? void 0 : _d.name;
|
42
|
+
user.partner.id;
|
43
|
+
user.partner.read();
|
44
44
|
// @ts-expect-error
|
45
|
-
|
45
|
+
user.partner.full_name;
|
46
|
+
user.team = null;
|
47
|
+
// @ts-expect-error
|
48
|
+
user.partner = null;
|
46
49
|
}
|
47
|
-
function
|
50
|
+
function test2(user) {
|
48
51
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
(_a =
|
53
|
-
(_b =
|
54
|
-
(_c =
|
55
|
-
(_d =
|
56
|
-
(_f = (_e =
|
57
|
-
(_h = (_g =
|
58
|
-
// @ts-expect-error
|
59
|
-
(_k = (_j =
|
60
|
-
// @ts-expect-error
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
// @ts-expect-error
|
65
|
-
|
66
|
-
if (
|
52
|
+
user.id;
|
53
|
+
user.read();
|
54
|
+
user.full_name;
|
55
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
56
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
57
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
|
58
|
+
(_d = user.team) === null || _d === void 0 ? void 0 : _d.owner;
|
59
|
+
(_f = (_e = user.team) === null || _e === void 0 ? void 0 : _e.owner) === null || _f === void 0 ? void 0 : _f.id;
|
60
|
+
(_h = (_g = user.team) === null || _g === void 0 ? void 0 : _g.owner) === null || _h === void 0 ? void 0 : _h.read();
|
61
|
+
// @ts-expect-error
|
62
|
+
(_k = (_j = user.team) === null || _j === void 0 ? void 0 : _j.owner) === null || _k === void 0 ? void 0 : _k.full_name;
|
63
|
+
// @ts-expect-error
|
64
|
+
user.full_name = null;
|
65
|
+
user.email = null;
|
66
|
+
user.email = '';
|
67
|
+
// @ts-expect-error
|
68
|
+
user.email = 2;
|
69
|
+
if (user.team) {
|
67
70
|
// @ts-expect-error
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
user.team.name = null;
|
72
|
+
user.team.labels = null;
|
73
|
+
user.team.labels = ['foo'];
|
71
74
|
// @ts-expect-error
|
72
|
-
|
75
|
+
user.team.labels = [1];
|
73
76
|
}
|
74
77
|
}
|
75
|
-
function
|
78
|
+
function test3(user) {
|
76
79
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
77
|
-
|
78
|
-
|
80
|
+
user.id;
|
81
|
+
user.read();
|
79
82
|
// @ts-expect-error
|
80
|
-
|
81
|
-
(_a =
|
82
|
-
(_b =
|
83
|
+
user.full_name;
|
84
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
85
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
83
86
|
// @ts-expect-error
|
84
|
-
(_c =
|
85
|
-
(_e = (_d =
|
86
|
-
(_g = (_f =
|
87
|
-
(_j = (_h =
|
87
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
|
88
|
+
(_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
|
89
|
+
(_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
|
90
|
+
(_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
|
88
91
|
}
|
89
|
-
function
|
92
|
+
function test4(user) {
|
90
93
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
91
|
-
|
92
|
-
|
94
|
+
user.id;
|
95
|
+
user.read();
|
96
|
+
// @ts-expect-error
|
97
|
+
user.full_name;
|
98
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
99
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
100
|
+
// @ts-expect-error
|
101
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
|
102
|
+
(_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
|
103
|
+
(_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
|
104
|
+
// @ts-expect-error
|
105
|
+
(_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
|
106
|
+
(_l = (_k = user.team) === null || _k === void 0 ? void 0 : _k.owner) === null || _l === void 0 ? void 0 : _l.address;
|
107
|
+
(_p = (_o = (_m = user.team) === null || _m === void 0 ? void 0 : _m.owner) === null || _o === void 0 ? void 0 : _o.address) === null || _p === void 0 ? void 0 : _p.street;
|
108
|
+
(_s = (_r = (_q = user.team) === null || _q === void 0 ? void 0 : _q.owner) === null || _r === void 0 ? void 0 : _r.address) === null || _s === void 0 ? void 0 : _s.zipcode;
|
109
|
+
}
|
110
|
+
function test5(user) {
|
111
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
112
|
+
user.id;
|
113
|
+
user.read();
|
114
|
+
// @ts-expect-error
|
115
|
+
user.full_name;
|
116
|
+
user.settings;
|
117
|
+
(_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
|
118
|
+
(_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
|
119
|
+
(_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
|
120
|
+
(_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
|
121
|
+
(_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
|
122
|
+
// @ts-expect-error
|
123
|
+
(_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
|
124
|
+
// @ts-expect-error
|
125
|
+
(_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
|
126
|
+
// @ts-expect-error
|
127
|
+
(_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
|
128
|
+
user.settings = null;
|
129
|
+
user.nonNullable.nested.value = 2;
|
130
|
+
// @ts-expect-error
|
131
|
+
user.nonNullable = null;
|
132
|
+
// @ts-expect-error
|
133
|
+
user.nonNullable.nested.value = null;
|
134
|
+
}
|
135
|
+
function test6(user) {
|
136
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
137
|
+
user.id;
|
138
|
+
user.read();
|
139
|
+
// @ts-expect-error
|
140
|
+
user.full_name;
|
141
|
+
user.settings;
|
142
|
+
(_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
|
143
|
+
(_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
|
144
|
+
(_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
|
145
|
+
(_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
|
146
|
+
(_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
|
147
|
+
// @ts-expect-error
|
148
|
+
(_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
|
149
|
+
// @ts-expect-error
|
150
|
+
(_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
|
151
|
+
// @ts-expect-error
|
152
|
+
(_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
|
153
|
+
user.nonNullable.nested.value = 2;
|
154
|
+
user.nonNullable.nested.deep.depths.of.numbers = [1, 2, 3];
|
155
|
+
// @ts-expect-error
|
156
|
+
user.nonNullable.nested.deep.depths.of.numbers = 'invalid-string';
|
157
|
+
user.settings = null;
|
158
|
+
// @ts-expect-error
|
159
|
+
user.nonNullable = null;
|
160
|
+
// @ts-expect-error
|
161
|
+
user.nonNullable.nested.value = null;
|
162
|
+
}
|
163
|
+
function test7(user) {
|
164
|
+
var _a, _b;
|
165
|
+
user.partner;
|
166
|
+
user.partner.id;
|
167
|
+
user.partner.read();
|
168
|
+
user.partner.full_name;
|
169
|
+
// @ts-expect-error
|
170
|
+
user.partner.full_name = null;
|
171
|
+
user.partner.address;
|
172
|
+
// @ts-expect-error
|
173
|
+
user.team.id;
|
174
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
175
|
+
// @ts-expect-error
|
176
|
+
user.team.read();
|
177
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
178
|
+
// @ts-expect-error
|
179
|
+
user.partner = null;
|
180
|
+
user.team = null;
|
181
|
+
}
|
182
|
+
function test8(user) {
|
183
|
+
var _a, _b;
|
184
|
+
user.partner;
|
185
|
+
user.partner.id;
|
186
|
+
user.partner.read();
|
187
|
+
user.partner.full_name;
|
188
|
+
// @ts-expect-error
|
189
|
+
user.partner.full_name = null;
|
190
|
+
user.partner.address;
|
93
191
|
// @ts-expect-error
|
94
|
-
|
95
|
-
(_a =
|
96
|
-
(_b = selectedUserNestedRecord.team) === null || _b === void 0 ? void 0 : _b.read();
|
192
|
+
user.team.id;
|
193
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
97
194
|
// @ts-expect-error
|
98
|
-
|
99
|
-
(
|
100
|
-
(_g = (_f = selectedUserNestedRecord.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
|
195
|
+
user.team.read();
|
196
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
101
197
|
// @ts-expect-error
|
102
|
-
|
103
|
-
|
104
|
-
(_p = (_o = (_m = selectedUserNestedRecord.team) === null || _m === void 0 ? void 0 : _m.owner) === null || _o === void 0 ? void 0 : _o.address) === null || _p === void 0 ? void 0 : _p.street;
|
105
|
-
(_s = (_r = (_q = selectedUserNestedRecord.team) === null || _q === void 0 ? void 0 : _q.owner) === null || _r === void 0 ? void 0 : _r.address) === null || _s === void 0 ? void 0 : _s.zipcode;
|
198
|
+
user.partner = null;
|
199
|
+
user.team = null;
|
106
200
|
}
|
107
201
|
test('fake test', () => {
|
108
202
|
// This is a fake test to make sure that the type definitions in this file are working
|
package/dist/schema/sorting.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { SingleOrArray, Values } from '../util/types';
|
1
2
|
import { XataRecord } from './record';
|
2
3
|
import { SelectableColumn } from './selection';
|
3
4
|
export declare type SortDirection = 'asc' | 'desc';
|
@@ -6,7 +7,11 @@ export declare type SortFilterExtended<T extends XataRecord> = {
|
|
6
7
|
direction?: SortDirection;
|
7
8
|
};
|
8
9
|
export declare type SortFilter<T extends XataRecord> = SelectableColumn<T> | SortFilterExtended<T>;
|
10
|
+
export declare type ApiSortFilter<T extends XataRecord> = SingleOrArray<Values<{
|
11
|
+
[key in SelectableColumn<T>]: {
|
12
|
+
[K in key]: SortDirection;
|
13
|
+
};
|
14
|
+
}>>;
|
15
|
+
export declare function isSortFilterString<T extends XataRecord>(value: any): value is SelectableColumn<T>;
|
9
16
|
export declare function isSortFilterObject<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
|
10
|
-
export declare function buildSortFilter<T extends XataRecord>(filter
|
11
|
-
[key: string]: SortDirection;
|
12
|
-
} | undefined;
|
17
|
+
export declare function buildSortFilter<T extends XataRecord>(filter: SingleOrArray<SortFilter<T>>): ApiSortFilter<T>;
|
package/dist/schema/sorting.js
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.buildSortFilter = exports.isSortFilterObject = void 0;
|
3
|
+
exports.buildSortFilter = exports.isSortFilterObject = exports.isSortFilterString = void 0;
|
4
4
|
const lang_1 = require("../util/lang");
|
5
|
+
function isSortFilterString(value) {
|
6
|
+
return (0, lang_1.isString)(value);
|
7
|
+
}
|
8
|
+
exports.isSortFilterString = isSortFilterString;
|
5
9
|
function isSortFilterObject(filter) {
|
6
10
|
return (0, lang_1.isObject)(filter) && filter.column !== undefined;
|
7
11
|
}
|
8
12
|
exports.isSortFilterObject = isSortFilterObject;
|
9
13
|
function buildSortFilter(filter) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}, {});
|
14
|
+
var _a;
|
15
|
+
if (isSortFilterString(filter)) {
|
16
|
+
return { [filter]: 'asc' };
|
17
|
+
}
|
18
|
+
else if (Array.isArray(filter)) {
|
19
|
+
return filter.map((item) => buildSortFilter(item));
|
20
|
+
}
|
21
|
+
else if (isSortFilterObject(filter)) {
|
22
|
+
return { [filter.column]: (_a = filter.direction) !== null && _a !== void 0 ? _a : 'asc' };
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
throw new Error(`Invalid sort filter: ${filter}`);
|
26
|
+
}
|
24
27
|
}
|
25
28
|
exports.buildSortFilter = buildSortFilter;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
// Simple sorting
|
4
|
+
const simpleSorting = { name: 'asc' };
|
5
|
+
// Array of simple sorting
|
6
|
+
const arrayOfSimpleSorting = [{ name: 'asc' }, { age: 'desc' }];
|
7
|
+
test('fake test', () => {
|
8
|
+
// This is a fake test to make sure that the type definitions in this file are working
|
9
|
+
});
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/// <reference path="../../src/types/global-node.d.ts" />
|
2
|
+
/// <reference path="../../src/types/global-variables.d.ts" />
|
3
|
+
/// <reference path="../../src/types/global-deno.d.ts" />
|
4
|
+
export declare function getEnvVariable(name: string): string | undefined;
|
5
|
+
export declare function getGitBranch(): Promise<string | undefined>;
|