@xata.io/client 0.0.0-beta.c9e08d0 → 0.0.0-beta.ca9389a
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 +13 -0
- package/CHANGELOG.md +87 -0
- package/dist/api/client.d.ts +95 -0
- package/dist/api/client.js +251 -0
- package/dist/api/components.d.ts +1437 -0
- package/dist/api/components.js +998 -0
- package/dist/api/fetcher.d.ts +40 -0
- package/dist/api/fetcher.js +79 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +21 -0
- package/dist/api/parameters.d.ts +16 -0
- package/dist/api/parameters.js +2 -0
- package/dist/api/providers.d.ts +8 -0
- package/dist/api/providers.js +30 -0
- package/dist/api/responses.d.ts +50 -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/client.d.ts +39 -0
- package/dist/client.js +124 -0
- package/dist/index.d.ts +5 -182
- package/dist/index.js +19 -499
- package/dist/namespace.d.ts +7 -0
- package/dist/namespace.js +6 -0
- package/dist/schema/filters.d.ts +96 -0
- package/dist/schema/filters.js +2 -0
- package/dist/schema/filters.spec.d.ts +1 -0
- package/dist/schema/filters.spec.js +177 -0
- package/dist/schema/index.d.ts +21 -0
- package/dist/schema/index.js +49 -0
- package/dist/schema/operators.d.ts +74 -0
- package/dist/schema/operators.js +93 -0
- package/dist/schema/pagination.d.ts +83 -0
- package/dist/schema/pagination.js +93 -0
- package/dist/schema/query.d.ts +118 -0
- package/dist/schema/query.js +242 -0
- package/dist/schema/record.d.ts +66 -0
- package/dist/schema/record.js +13 -0
- package/dist/schema/repository.d.ts +134 -0
- package/dist/schema/repository.js +284 -0
- package/dist/schema/selection.d.ts +25 -0
- package/dist/schema/selection.js +2 -0
- package/dist/schema/selection.spec.d.ts +1 -0
- package/dist/schema/selection.spec.js +204 -0
- package/dist/schema/sorting.d.ts +17 -0
- package/dist/schema/sorting.js +28 -0
- package/dist/schema/sorting.spec.d.ts +1 -0
- package/dist/schema/sorting.spec.js +11 -0
- package/dist/search/index.d.ts +20 -0
- package/dist/search/index.js +30 -0
- package/dist/util/branches.d.ts +5 -0
- package/dist/util/branches.js +7 -0
- package/dist/util/config.d.ts +11 -0
- package/dist/util/config.js +121 -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 +5 -0
- package/dist/util/lang.js +22 -0
- package/dist/util/types.d.ts +25 -0
- package/dist/util/types.js +2 -0
- package/package.json +5 -2
- package/tsconfig.json +21 -0
- package/dist/util/errors.d.ts +0 -3
- package/dist/util/errors.js +0 -9
@@ -0,0 +1,284 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
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
|
+
};
|
22
|
+
var _RestRepository_instances, _RestRepository_table, _RestRepository_links, _RestRepository_getFetchProps, _RestRepository_schemaNamespace, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _RestRepository_bulkInsertTableRecords, _RestRepository_updateRecordWithID, _RestRepository_upsertRecordWithID, _RestRepository_deleteRecord, _RestRepository_initObject;
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
24
|
+
exports.RestRepository = exports.Repository = void 0;
|
25
|
+
const api_1 = require("../api");
|
26
|
+
const lang_1 = require("../util/lang");
|
27
|
+
const pagination_1 = require("./pagination");
|
28
|
+
const query_1 = require("./query");
|
29
|
+
const record_1 = require("./record");
|
30
|
+
const sorting_1 = require("./sorting");
|
31
|
+
/**
|
32
|
+
* Common interface for performing operations on a table.
|
33
|
+
*/
|
34
|
+
class Repository extends query_1.Query {
|
35
|
+
}
|
36
|
+
exports.Repository = Repository;
|
37
|
+
class RestRepository extends query_1.Query {
|
38
|
+
constructor(options) {
|
39
|
+
var _a;
|
40
|
+
super(null, options.table, {});
|
41
|
+
_RestRepository_instances.add(this);
|
42
|
+
_RestRepository_table.set(this, void 0);
|
43
|
+
_RestRepository_links.set(this, void 0);
|
44
|
+
_RestRepository_getFetchProps.set(this, void 0);
|
45
|
+
_RestRepository_schemaNamespace.set(this, void 0);
|
46
|
+
__classPrivateFieldSet(this, _RestRepository_table, options.table, "f");
|
47
|
+
__classPrivateFieldSet(this, _RestRepository_links, (_a = options.links) !== null && _a !== void 0 ? _a : {}, "f");
|
48
|
+
__classPrivateFieldSet(this, _RestRepository_getFetchProps, options.getFetchProps, "f");
|
49
|
+
__classPrivateFieldSet(this, _RestRepository_schemaNamespace, options.schemaNamespace, "f");
|
50
|
+
}
|
51
|
+
create(a, b) {
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
53
|
+
// Create many records
|
54
|
+
if (Array.isArray(a)) {
|
55
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_bulkInsertTableRecords).call(this, a);
|
56
|
+
}
|
57
|
+
// Create one record with id as param
|
58
|
+
if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
|
59
|
+
if (a === '')
|
60
|
+
throw new Error("The id can't be empty");
|
61
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a, b);
|
62
|
+
}
|
63
|
+
// Create one record with id as property
|
64
|
+
if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
|
65
|
+
if (a.id === '')
|
66
|
+
throw new Error("The id can't be empty");
|
67
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
|
68
|
+
}
|
69
|
+
// Create one record without id
|
70
|
+
if ((0, lang_1.isObject)(a)) {
|
71
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithoutId).call(this, a);
|
72
|
+
}
|
73
|
+
throw new Error('Invalid arguments for create method');
|
74
|
+
});
|
75
|
+
}
|
76
|
+
// TODO: Add column support: https://github.com/xataio/openapi/issues/139
|
77
|
+
read(recordId) {
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
79
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
80
|
+
try {
|
81
|
+
const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
82
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, __classPrivateFieldGet(this, _RestRepository_table, "f"), response);
|
83
|
+
}
|
84
|
+
catch (e) {
|
85
|
+
if ((0, lang_1.isObject)(e) && e.status === 404) {
|
86
|
+
return null;
|
87
|
+
}
|
88
|
+
throw e;
|
89
|
+
}
|
90
|
+
});
|
91
|
+
}
|
92
|
+
update(a, b) {
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
94
|
+
// Update many records
|
95
|
+
if (Array.isArray(a)) {
|
96
|
+
if (a.length > 100) {
|
97
|
+
// TODO: Implement bulk update when API has support for it
|
98
|
+
console.warn('Bulk update operation is not optimized in the Xata API yet, this request might be slow');
|
99
|
+
}
|
100
|
+
return Promise.all(a.map((object) => this.update(object)));
|
101
|
+
}
|
102
|
+
// Update one record with id as param
|
103
|
+
if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
|
104
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_updateRecordWithID).call(this, a, b);
|
105
|
+
}
|
106
|
+
// Update one record with id as property
|
107
|
+
if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
|
108
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_updateRecordWithID).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
|
109
|
+
}
|
110
|
+
throw new Error('Invalid arguments for update method');
|
111
|
+
});
|
112
|
+
}
|
113
|
+
createOrUpdate(a, b) {
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
115
|
+
// Create or update many records
|
116
|
+
if (Array.isArray(a)) {
|
117
|
+
if (a.length > 100) {
|
118
|
+
// TODO: Implement bulk update when API has support for it
|
119
|
+
console.warn('Bulk update operation is not optimized in the Xata API yet, this request might be slow');
|
120
|
+
}
|
121
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object)));
|
122
|
+
}
|
123
|
+
// Create or update one record with id as param
|
124
|
+
if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
|
125
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_upsertRecordWithID).call(this, a, b);
|
126
|
+
}
|
127
|
+
// Create or update one record with id as property
|
128
|
+
if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
|
129
|
+
return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_upsertRecordWithID).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
|
130
|
+
}
|
131
|
+
throw new Error('Invalid arguments for createOrUpdate method');
|
132
|
+
});
|
133
|
+
}
|
134
|
+
delete(recordId) {
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
136
|
+
// Delete many records
|
137
|
+
if (Array.isArray(recordId)) {
|
138
|
+
if (recordId.length > 100) {
|
139
|
+
// TODO: Implement bulk delete when API has support for it
|
140
|
+
console.warn('Bulk delete operation is not optimized in the Xata API yet, this request might be slow');
|
141
|
+
}
|
142
|
+
yield Promise.all(recordId.map((id) => this.delete(id)));
|
143
|
+
return;
|
144
|
+
}
|
145
|
+
// Delete one record with id as param
|
146
|
+
if ((0, lang_1.isString)(recordId)) {
|
147
|
+
yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_deleteRecord).call(this, recordId);
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
// Delete one record with id as property
|
151
|
+
if ((0, lang_1.isObject)(recordId) && (0, lang_1.isString)(recordId.id)) {
|
152
|
+
yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_deleteRecord).call(this, recordId.id);
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
throw new Error('Invalid arguments for delete method');
|
156
|
+
});
|
157
|
+
}
|
158
|
+
search(query, options = {}) {
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
160
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
161
|
+
const { records } = yield (0, api_1.searchBranch)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}' }, body: { tables: [__classPrivateFieldGet(this, _RestRepository_table, "f")], query, fuzziness: options.fuzziness } }, fetchProps));
|
162
|
+
return records.map((item) => __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, __classPrivateFieldGet(this, _RestRepository_table, "f"), item));
|
163
|
+
});
|
164
|
+
}
|
165
|
+
query(query) {
|
166
|
+
var _a;
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
168
|
+
const data = query.getQueryOptions();
|
169
|
+
const body = {
|
170
|
+
filter: Object.values((_a = data.filter) !== null && _a !== void 0 ? _a : {}).some(Boolean) ? data.filter : undefined,
|
171
|
+
sort: data.sort ? (0, sorting_1.buildSortFilter)(data.sort) : undefined,
|
172
|
+
page: data.page,
|
173
|
+
columns: data.columns
|
174
|
+
};
|
175
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
176
|
+
const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
|
177
|
+
const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, __classPrivateFieldGet(this, _RestRepository_table, "f"), record));
|
178
|
+
return new pagination_1.Page(query, meta, records);
|
179
|
+
});
|
180
|
+
}
|
181
|
+
}
|
182
|
+
exports.RestRepository = RestRepository;
|
183
|
+
_RestRepository_table = new WeakMap(), _RestRepository_links = new WeakMap(), _RestRepository_getFetchProps = new WeakMap(), _RestRepository_schemaNamespace = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_insertRecordWithoutId = function _RestRepository_insertRecordWithoutId(object) {
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
185
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
186
|
+
const record = transformObjectLinks(object);
|
187
|
+
const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
|
188
|
+
workspace: '{workspaceId}',
|
189
|
+
dbBranchName: '{dbBranch}',
|
190
|
+
tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
|
191
|
+
}, body: record }, fetchProps));
|
192
|
+
const finalObject = yield this.read(response.id);
|
193
|
+
if (!finalObject) {
|
194
|
+
throw new Error('The server failed to save the record');
|
195
|
+
}
|
196
|
+
return finalObject;
|
197
|
+
});
|
198
|
+
}, _RestRepository_insertRecordWithId = function _RestRepository_insertRecordWithId(recordId, object) {
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
200
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
201
|
+
const record = transformObjectLinks(object);
|
202
|
+
const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
|
203
|
+
workspace: '{workspaceId}',
|
204
|
+
dbBranchName: '{dbBranch}',
|
205
|
+
tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
|
206
|
+
recordId
|
207
|
+
}, body: record, queryParams: { createOnly: true } }, fetchProps));
|
208
|
+
const finalObject = yield this.read(response.id);
|
209
|
+
if (!finalObject) {
|
210
|
+
throw new Error('The server failed to save the record');
|
211
|
+
}
|
212
|
+
return finalObject;
|
213
|
+
});
|
214
|
+
}, _RestRepository_bulkInsertTableRecords = function _RestRepository_bulkInsertTableRecords(objects) {
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
216
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
217
|
+
const records = objects.map((object) => transformObjectLinks(object));
|
218
|
+
const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
|
219
|
+
const finalObjects = yield this.any(...response.recordIDs.map((id) => this.filter('id', id))).getAll();
|
220
|
+
if (finalObjects.length !== objects.length) {
|
221
|
+
throw new Error('The server failed to save some records');
|
222
|
+
}
|
223
|
+
return finalObjects;
|
224
|
+
});
|
225
|
+
}, _RestRepository_updateRecordWithID = function _RestRepository_updateRecordWithID(recordId, object) {
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
227
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
228
|
+
const record = transformObjectLinks(object);
|
229
|
+
const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: record }, fetchProps));
|
230
|
+
const item = yield this.read(response.id);
|
231
|
+
if (!item)
|
232
|
+
throw new Error('The server failed to save the record');
|
233
|
+
return item;
|
234
|
+
});
|
235
|
+
}, _RestRepository_upsertRecordWithID = function _RestRepository_upsertRecordWithID(recordId, object) {
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
237
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
238
|
+
const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
|
239
|
+
const item = yield this.read(response.id);
|
240
|
+
if (!item)
|
241
|
+
throw new Error('The server failed to save the record');
|
242
|
+
return item;
|
243
|
+
});
|
244
|
+
}, _RestRepository_deleteRecord = function _RestRepository_deleteRecord(recordId) {
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
246
|
+
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
247
|
+
yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
248
|
+
});
|
249
|
+
}, _RestRepository_initObject = function _RestRepository_initObject(table, object) {
|
250
|
+
const result = {};
|
251
|
+
Object.assign(result, object);
|
252
|
+
const tableLinks = __classPrivateFieldGet(this, _RestRepository_links, "f")[table] || [];
|
253
|
+
for (const link of tableLinks) {
|
254
|
+
const [field, linkTable] = link;
|
255
|
+
const value = result[field];
|
256
|
+
if (value && (0, lang_1.isObject)(value)) {
|
257
|
+
result[field] = __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, linkTable, value);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
const db = __classPrivateFieldGet(this, _RestRepository_schemaNamespace, "f");
|
261
|
+
result.read = function () {
|
262
|
+
return db[table].read(result['id']);
|
263
|
+
};
|
264
|
+
result.update = function (data) {
|
265
|
+
return db[table].update(result['id'], data);
|
266
|
+
};
|
267
|
+
result.delete = function () {
|
268
|
+
return db[table].delete(result['id']);
|
269
|
+
};
|
270
|
+
for (const prop of ['read', 'update', 'delete']) {
|
271
|
+
Object.defineProperty(result, prop, { enumerable: false });
|
272
|
+
}
|
273
|
+
Object.freeze(result);
|
274
|
+
return result;
|
275
|
+
};
|
276
|
+
const transformObjectLinks = (object) => {
|
277
|
+
return Object.entries(object).reduce((acc, [key, value]) => {
|
278
|
+
// Ignore internal properties
|
279
|
+
if (key === 'xata')
|
280
|
+
return acc;
|
281
|
+
// Transform links to identifier
|
282
|
+
return Object.assign(Object.assign({}, acc), { [key]: (0, record_1.isIdentifiable)(value) ? value.id : value });
|
283
|
+
}, {});
|
284
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { If, IsArray, IsObject, StringKeys, UnionToIntersection, Values } from '../util/types';
|
2
|
+
import { Link, XataRecord } from './record';
|
3
|
+
export declare type SelectableColumn<O, RecursivePath extends any[] = []> = '*' | 'id' | DataProps<O> | NestedColumns<O, RecursivePath>;
|
4
|
+
export declare type SelectedPick<O extends XataRecord, Key extends SelectableColumn<O>[]> = XataRecord & UnionToIntersection<Values<{
|
5
|
+
[K in Key[number]]: NestedValueAtColumn<O, K> & XataRecord;
|
6
|
+
}>>;
|
7
|
+
export declare type ValueAtColumn<O, P extends SelectableColumn<O>> = P extends '*' ? Values<O> : P extends 'id' ? string : P extends keyof O ? O[P] : P extends `${infer K}.${infer V}` ? K extends keyof O ? Values<O[K] extends XataRecord ? (V extends SelectableColumn<O[K]> ? {
|
8
|
+
V: ValueAtColumn<O[K], V>;
|
9
|
+
} : never) : O[K]> : never : never;
|
10
|
+
declare type MAX_RECURSION = 5;
|
11
|
+
declare type NestedColumns<O, RecursivePath extends any[]> = RecursivePath['length'] extends MAX_RECURSION ? never : If<IsObject<O>, Values<{
|
12
|
+
[K in DataProps<O>]: If<IsArray<NonNullable<O[K]>>, K, // If the property is an array, we stop recursion. We don't support object arrays yet
|
13
|
+
If<IsObject<NonNullable<O[K]>>, NonNullable<O[K]> extends XataRecord ? SelectableColumn<NonNullable<O[K]>, [...RecursivePath, O[K]]> extends string ? K | `${K}.${SelectableColumn<NonNullable<O[K]>, [...RecursivePath, O[K]]>}` : never : `${K}.${StringKeys<NonNullable<O[K]>> | '*'}`, // This allows usage of objects that are not links
|
14
|
+
K>>;
|
15
|
+
}>, never>;
|
16
|
+
declare type DataProps<O> = Exclude<StringKeys<O>, StringKeys<XataRecord>>;
|
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]>> ? NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M> & XataRecord> : ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M>> : unknown;
|
19
|
+
} : unknown : Key extends DataProps<O> ? {
|
20
|
+
[K in Key]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], SelectedPick<NonNullable<O[K]>, ['*']>> : O[K];
|
21
|
+
} : Key extends '*' ? {
|
22
|
+
[K in StringKeys<O>]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], Link<NonNullable<O[K]>>> : O[K];
|
23
|
+
} : unknown;
|
24
|
+
declare type ForwardNullable<T, R> = T extends NonNullable<T> ? R : R | null;
|
25
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,204 @@
|
|
1
|
+
"use strict";
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-floating-promises */
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
const vitest_1 = require("vitest");
|
5
|
+
// SelectableColumn<O> //
|
6
|
+
// --------------------------------------------------------------------------- //
|
7
|
+
const validTeamColumns = [
|
8
|
+
'*',
|
9
|
+
'id',
|
10
|
+
'name',
|
11
|
+
'owner.*',
|
12
|
+
'owner.address.*',
|
13
|
+
'owner.address',
|
14
|
+
'owner.address.street'
|
15
|
+
];
|
16
|
+
// @ts-expect-error
|
17
|
+
const invalidFullNameTeamColumn = 'full_name';
|
18
|
+
// @ts-expect-error
|
19
|
+
const invalidPartialTeamColumn = 'owner.address.';
|
20
|
+
// @ts-expect-error
|
21
|
+
const invalidDeleteTeamColumn = 'owner.delete';
|
22
|
+
// @ts-expect-error
|
23
|
+
const invalidReadTeamColumn = 'owner.read.*';
|
24
|
+
// ValueAtColumn<O, P> //
|
25
|
+
// --------------------------------------------------------------------------- //
|
26
|
+
const labelsValue = ['foo'];
|
27
|
+
// @ts-expect-error
|
28
|
+
const invalidLabelsValue = [1];
|
29
|
+
// SelectedRecordPick<O, Key> //
|
30
|
+
// ---------------------------------------------------------------------------- //
|
31
|
+
function test1(user) {
|
32
|
+
var _a, _b, _c, _d;
|
33
|
+
user.id;
|
34
|
+
user.read();
|
35
|
+
user.full_name;
|
36
|
+
(_a = user.address) === null || _a === void 0 ? void 0 : _a.street;
|
37
|
+
// @ts-expect-error
|
38
|
+
user.team.id;
|
39
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.id;
|
40
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.read();
|
41
|
+
// @ts-expect-error
|
42
|
+
(_d = user.team) === null || _d === void 0 ? void 0 : _d.name;
|
43
|
+
user.partner.id;
|
44
|
+
user.partner.read();
|
45
|
+
// @ts-expect-error
|
46
|
+
user.partner.full_name;
|
47
|
+
user.team = null;
|
48
|
+
// @ts-expect-error
|
49
|
+
user.partner = null;
|
50
|
+
}
|
51
|
+
function test2(user) {
|
52
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
53
|
+
user.id;
|
54
|
+
user.read();
|
55
|
+
user.full_name;
|
56
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
57
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
58
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
|
59
|
+
(_d = user.team) === null || _d === void 0 ? void 0 : _d.owner;
|
60
|
+
(_f = (_e = user.team) === null || _e === void 0 ? void 0 : _e.owner) === null || _f === void 0 ? void 0 : _f.id;
|
61
|
+
(_h = (_g = user.team) === null || _g === void 0 ? void 0 : _g.owner) === null || _h === void 0 ? void 0 : _h.read();
|
62
|
+
// @ts-expect-error
|
63
|
+
(_k = (_j = user.team) === null || _j === void 0 ? void 0 : _j.owner) === null || _k === void 0 ? void 0 : _k.full_name;
|
64
|
+
// @ts-expect-error
|
65
|
+
user.full_name = null;
|
66
|
+
user.email = null;
|
67
|
+
user.email = '';
|
68
|
+
// @ts-expect-error
|
69
|
+
user.email = 2;
|
70
|
+
if (user.team) {
|
71
|
+
// @ts-expect-error
|
72
|
+
user.team.name = null;
|
73
|
+
user.team.labels = null;
|
74
|
+
user.team.labels = ['foo'];
|
75
|
+
// @ts-expect-error
|
76
|
+
user.team.labels = [1];
|
77
|
+
}
|
78
|
+
}
|
79
|
+
function test3(user) {
|
80
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
81
|
+
user.id;
|
82
|
+
user.read();
|
83
|
+
// @ts-expect-error
|
84
|
+
user.full_name;
|
85
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
86
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
87
|
+
// @ts-expect-error
|
88
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
|
89
|
+
(_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
|
90
|
+
(_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
|
91
|
+
(_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
|
92
|
+
}
|
93
|
+
function test4(user) {
|
94
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
95
|
+
user.id;
|
96
|
+
user.read();
|
97
|
+
// @ts-expect-error
|
98
|
+
user.full_name;
|
99
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
100
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
101
|
+
// @ts-expect-error
|
102
|
+
(_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
|
103
|
+
(_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
|
104
|
+
(_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
|
105
|
+
// @ts-expect-error
|
106
|
+
(_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
|
107
|
+
(_l = (_k = user.team) === null || _k === void 0 ? void 0 : _k.owner) === null || _l === void 0 ? void 0 : _l.address;
|
108
|
+
(_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;
|
109
|
+
(_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;
|
110
|
+
}
|
111
|
+
function test5(user) {
|
112
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
113
|
+
user.id;
|
114
|
+
user.read();
|
115
|
+
// @ts-expect-error
|
116
|
+
user.full_name;
|
117
|
+
user.settings;
|
118
|
+
(_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
|
119
|
+
(_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
|
120
|
+
(_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
|
121
|
+
(_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
|
122
|
+
(_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
|
123
|
+
// @ts-expect-error
|
124
|
+
(_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
|
125
|
+
// @ts-expect-error
|
126
|
+
(_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
|
127
|
+
// @ts-expect-error
|
128
|
+
(_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
|
129
|
+
user.settings = null;
|
130
|
+
user.nonNullable.nested.value = 2;
|
131
|
+
// @ts-expect-error
|
132
|
+
user.nonNullable = null;
|
133
|
+
// @ts-expect-error
|
134
|
+
user.nonNullable.nested.value = null;
|
135
|
+
}
|
136
|
+
function test6(user) {
|
137
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
138
|
+
user.id;
|
139
|
+
user.read();
|
140
|
+
// @ts-expect-error
|
141
|
+
user.full_name;
|
142
|
+
user.settings;
|
143
|
+
(_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
|
144
|
+
(_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
|
145
|
+
(_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
|
146
|
+
(_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
|
147
|
+
(_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
|
148
|
+
// @ts-expect-error
|
149
|
+
(_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
|
150
|
+
// @ts-expect-error
|
151
|
+
(_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
|
152
|
+
// @ts-expect-error
|
153
|
+
(_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
|
154
|
+
user.nonNullable.nested.value = 2;
|
155
|
+
user.nonNullable.nested.deep.depths.of.numbers = [1, 2, 3];
|
156
|
+
// @ts-expect-error
|
157
|
+
user.nonNullable.nested.deep.depths.of.numbers = 'invalid-string';
|
158
|
+
user.settings = null;
|
159
|
+
// @ts-expect-error
|
160
|
+
user.nonNullable = null;
|
161
|
+
// @ts-expect-error
|
162
|
+
user.nonNullable.nested.value = null;
|
163
|
+
}
|
164
|
+
function test7(user) {
|
165
|
+
var _a, _b;
|
166
|
+
user.partner;
|
167
|
+
user.partner.id;
|
168
|
+
user.partner.read();
|
169
|
+
user.partner.full_name;
|
170
|
+
// @ts-expect-error
|
171
|
+
user.partner.full_name = null;
|
172
|
+
user.partner.address;
|
173
|
+
// @ts-expect-error
|
174
|
+
user.team.id;
|
175
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
176
|
+
// @ts-expect-error
|
177
|
+
user.team.read();
|
178
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
179
|
+
// @ts-expect-error
|
180
|
+
user.partner = null;
|
181
|
+
user.team = null;
|
182
|
+
}
|
183
|
+
function test8(user) {
|
184
|
+
var _a, _b;
|
185
|
+
user.partner;
|
186
|
+
user.partner.id;
|
187
|
+
user.partner.read();
|
188
|
+
user.partner.full_name;
|
189
|
+
// @ts-expect-error
|
190
|
+
user.partner.full_name = null;
|
191
|
+
user.partner.address;
|
192
|
+
// @ts-expect-error
|
193
|
+
user.team.id;
|
194
|
+
(_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
|
195
|
+
// @ts-expect-error
|
196
|
+
user.team.read();
|
197
|
+
(_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
|
198
|
+
// @ts-expect-error
|
199
|
+
user.partner = null;
|
200
|
+
user.team = null;
|
201
|
+
}
|
202
|
+
(0, vitest_1.test)('fake test', () => {
|
203
|
+
// This is a fake test to make sure that the type definitions in this file are working
|
204
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { SingleOrArray, Values } from '../util/types';
|
2
|
+
import { XataRecord } from './record';
|
3
|
+
import { SelectableColumn } from './selection';
|
4
|
+
export declare type SortDirection = 'asc' | 'desc';
|
5
|
+
export declare type SortFilterExtended<T extends XataRecord> = {
|
6
|
+
column: SelectableColumn<T>;
|
7
|
+
direction?: SortDirection;
|
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>;
|
16
|
+
export declare function isSortFilterObject<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
|
17
|
+
export declare function buildSortFilter<T extends XataRecord>(filter: SingleOrArray<SortFilter<T>>): ApiSortFilter<T>;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.buildSortFilter = exports.isSortFilterObject = exports.isSortFilterString = void 0;
|
4
|
+
const lang_1 = require("../util/lang");
|
5
|
+
function isSortFilterString(value) {
|
6
|
+
return (0, lang_1.isString)(value);
|
7
|
+
}
|
8
|
+
exports.isSortFilterString = isSortFilterString;
|
9
|
+
function isSortFilterObject(filter) {
|
10
|
+
return (0, lang_1.isObject)(filter) && filter.column !== undefined;
|
11
|
+
}
|
12
|
+
exports.isSortFilterObject = isSortFilterObject;
|
13
|
+
function buildSortFilter(filter) {
|
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
|
+
}
|
27
|
+
}
|
28
|
+
exports.buildSortFilter = buildSortFilter;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
4
|
+
const vitest_1 = require("vitest");
|
5
|
+
// Simple sorting
|
6
|
+
const simpleSorting = { name: 'asc' };
|
7
|
+
// Array of simple sorting
|
8
|
+
const arrayOfSimpleSorting = [{ name: 'asc' }, { age: 'desc' }];
|
9
|
+
(0, vitest_1.test)('fake test', () => {
|
10
|
+
// This is a fake test to make sure that the type definitions in this file are working
|
11
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Namespace, NamespaceBuildOptions } from '../namespace';
|
2
|
+
import { BaseData, XataRecord } from '../schema/record';
|
3
|
+
import { SelectedPick } from '../schema/selection';
|
4
|
+
import { GetArrayInnerType } from '../util/types';
|
5
|
+
export declare class SearchNamespace<Schemas extends Record<string, BaseData>> extends Namespace {
|
6
|
+
build({ getFetchProps }: NamespaceBuildOptions): <Tables extends Extract<keyof Schemas, string>>(query: string, options?: {
|
7
|
+
fuzziness?: number | undefined;
|
8
|
+
tables?: Tables[] | undefined;
|
9
|
+
} | undefined) => Promise<{ [Model in Tables]: SelectedPick<Schemas[Model] & XataRecord & {
|
10
|
+
xata: {
|
11
|
+
table: string;
|
12
|
+
};
|
13
|
+
}, ["*"]>[]; }>;
|
14
|
+
}
|
15
|
+
declare type SearchXataRecord = XataRecord & {
|
16
|
+
xata: {
|
17
|
+
table: string;
|
18
|
+
};
|
19
|
+
};
|
20
|
+
export {};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.SearchNamespace = void 0;
|
13
|
+
const api_1 = require("../api");
|
14
|
+
const namespace_1 = require("../namespace");
|
15
|
+
class SearchNamespace extends namespace_1.Namespace {
|
16
|
+
build({ getFetchProps }) {
|
17
|
+
return (query, options) => __awaiter(this, void 0, void 0, function* () {
|
18
|
+
const fetchProps = yield getFetchProps();
|
19
|
+
const { tables, fuzziness } = options !== null && options !== void 0 ? options : {};
|
20
|
+
const { records } = yield (0, api_1.searchBranch)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}' }, body: { tables, query, fuzziness } }, fetchProps));
|
21
|
+
return records.reduce((acc, record) => {
|
22
|
+
var _a;
|
23
|
+
const { table = 'orphan' } = record.xata;
|
24
|
+
const items = (_a = acc[table]) !== null && _a !== void 0 ? _a : [];
|
25
|
+
return Object.assign(Object.assign({}, acc), { [table]: [...items, record] });
|
26
|
+
}, {});
|
27
|
+
});
|
28
|
+
}
|
29
|
+
}
|
30
|
+
exports.SearchNamespace = SearchNamespace;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export declare type BranchStrategyValue = string | undefined | null;
|
2
|
+
export declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
|
3
|
+
export declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
|
4
|
+
export declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
|
5
|
+
export declare const isBranchStrategyBuilder: (strategy: BranchStrategy) => strategy is BranchStrategyBuilder;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isBranchStrategyBuilder = void 0;
|
4
|
+
const isBranchStrategyBuilder = (strategy) => {
|
5
|
+
return typeof strategy === 'function';
|
6
|
+
};
|
7
|
+
exports.isBranchStrategyBuilder = isBranchStrategyBuilder;
|