@xata.io/client 0.8.2 → 0.9.0
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 +29 -0
- package/dist/index.cjs +1903 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3286 -7
- package/dist/index.mjs +1807 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -5
- package/rollup.config.js +29 -0
- package/tsconfig.json +5 -4
- package/dist/api/client.d.ts +0 -95
- package/dist/api/client.js +0 -251
- package/dist/api/components.d.ts +0 -1437
- package/dist/api/components.js +0 -998
- package/dist/api/fetcher.d.ts +0 -40
- package/dist/api/fetcher.js +0 -79
- package/dist/api/index.d.ts +0 -13
- package/dist/api/index.js +0 -40
- package/dist/api/parameters.d.ts +0 -16
- package/dist/api/parameters.js +0 -2
- package/dist/api/providers.d.ts +0 -8
- package/dist/api/providers.js +0 -30
- package/dist/api/responses.d.ts +0 -50
- package/dist/api/responses.js +0 -2
- package/dist/api/schemas.d.ts +0 -311
- package/dist/api/schemas.js +0 -2
- package/dist/client.d.ts +0 -27
- package/dist/client.js +0 -131
- package/dist/index.js +0 -30
- package/dist/plugins.d.ts +0 -7
- package/dist/plugins.js +0 -6
- package/dist/schema/filters.d.ts +0 -96
- package/dist/schema/filters.js +0 -2
- package/dist/schema/filters.spec.d.ts +0 -1
- package/dist/schema/filters.spec.js +0 -177
- package/dist/schema/index.d.ts +0 -24
- package/dist/schema/index.js +0 -60
- package/dist/schema/operators.d.ts +0 -74
- package/dist/schema/operators.js +0 -93
- package/dist/schema/pagination.d.ts +0 -83
- package/dist/schema/pagination.js +0 -93
- package/dist/schema/query.d.ts +0 -118
- package/dist/schema/query.js +0 -242
- package/dist/schema/record.d.ts +0 -66
- package/dist/schema/record.js +0 -13
- package/dist/schema/repository.d.ts +0 -135
- package/dist/schema/repository.js +0 -283
- package/dist/schema/selection.d.ts +0 -25
- package/dist/schema/selection.js +0 -2
- package/dist/schema/selection.spec.d.ts +0 -1
- package/dist/schema/selection.spec.js +0 -204
- package/dist/schema/sorting.d.ts +0 -22
- package/dist/schema/sorting.js +0 -35
- package/dist/schema/sorting.spec.d.ts +0 -1
- package/dist/schema/sorting.spec.js +0 -11
- package/dist/search/index.d.ts +0 -34
- package/dist/search/index.js +0 -55
- package/dist/util/branches.d.ts +0 -5
- package/dist/util/branches.js +0 -7
- package/dist/util/config.d.ts +0 -11
- package/dist/util/config.js +0 -121
- package/dist/util/environment.d.ts +0 -5
- package/dist/util/environment.js +0 -68
- package/dist/util/fetch.d.ts +0 -2
- package/dist/util/fetch.js +0 -13
- package/dist/util/lang.d.ts +0 -5
- package/dist/util/lang.js +0 -22
- package/dist/util/types.d.ts +0 -25
- package/dist/util/types.js +0 -2
package/dist/index.mjs
ADDED
@@ -0,0 +1,1807 @@
|
|
1
|
+
function notEmpty(value) {
|
2
|
+
return value !== null && value !== void 0;
|
3
|
+
}
|
4
|
+
function compact(arr) {
|
5
|
+
return arr.filter(notEmpty);
|
6
|
+
}
|
7
|
+
function isObject(value) {
|
8
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
9
|
+
}
|
10
|
+
function isString(value) {
|
11
|
+
return value !== void 0 && value !== null && typeof value === "string";
|
12
|
+
}
|
13
|
+
function toBase64(value) {
|
14
|
+
try {
|
15
|
+
return btoa(value);
|
16
|
+
} catch (err) {
|
17
|
+
return Buffer.from(value).toString("base64");
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
function getEnvVariable(name) {
|
22
|
+
try {
|
23
|
+
if (isObject(process) && isString(process?.env?.[name])) {
|
24
|
+
return process.env[name];
|
25
|
+
}
|
26
|
+
} catch (err) {
|
27
|
+
}
|
28
|
+
try {
|
29
|
+
if (isObject(Deno) && isString(Deno?.env?.get(name))) {
|
30
|
+
return Deno.env.get(name);
|
31
|
+
}
|
32
|
+
} catch (err) {
|
33
|
+
}
|
34
|
+
}
|
35
|
+
async function getGitBranch() {
|
36
|
+
try {
|
37
|
+
return require("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
38
|
+
} catch (err) {
|
39
|
+
}
|
40
|
+
try {
|
41
|
+
if (isObject(Deno)) {
|
42
|
+
const process2 = Deno.run({
|
43
|
+
cmd: ["git", "branch", "--show-current"],
|
44
|
+
stdout: "piped",
|
45
|
+
stderr: "piped"
|
46
|
+
});
|
47
|
+
return new TextDecoder().decode(await process2.output()).trim();
|
48
|
+
}
|
49
|
+
} catch (err) {
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
function getAPIKey() {
|
54
|
+
try {
|
55
|
+
return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
|
56
|
+
} catch (err) {
|
57
|
+
return void 0;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
function getFetchImplementation(userFetch) {
|
62
|
+
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
63
|
+
const fetchImpl = userFetch ?? globalFetch;
|
64
|
+
if (!fetchImpl) {
|
65
|
+
throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
|
66
|
+
}
|
67
|
+
return fetchImpl;
|
68
|
+
}
|
69
|
+
|
70
|
+
class FetcherError extends Error {
|
71
|
+
constructor(status, data) {
|
72
|
+
super(getMessage(data));
|
73
|
+
this.status = status;
|
74
|
+
this.errors = isBulkError(data) ? data.errors : void 0;
|
75
|
+
if (data instanceof Error) {
|
76
|
+
this.stack = data.stack;
|
77
|
+
this.cause = data.cause;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
function isBulkError(error) {
|
82
|
+
return isObject(error) && Array.isArray(error.errors);
|
83
|
+
}
|
84
|
+
function isErrorWithMessage(error) {
|
85
|
+
return isObject(error) && isString(error.message);
|
86
|
+
}
|
87
|
+
function getMessage(data) {
|
88
|
+
if (data instanceof Error) {
|
89
|
+
return data.message;
|
90
|
+
} else if (isString(data)) {
|
91
|
+
return data;
|
92
|
+
} else if (isErrorWithMessage(data)) {
|
93
|
+
return data.message;
|
94
|
+
} else if (isBulkError(data)) {
|
95
|
+
return "Bulk operation failed";
|
96
|
+
} else {
|
97
|
+
return "Unexpected error";
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
102
|
+
const query = new URLSearchParams(queryParams).toString();
|
103
|
+
const queryString = query.length > 0 ? `?${query}` : "";
|
104
|
+
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
|
105
|
+
};
|
106
|
+
function buildBaseUrl({
|
107
|
+
path,
|
108
|
+
workspacesApiUrl,
|
109
|
+
apiUrl,
|
110
|
+
pathParams
|
111
|
+
}) {
|
112
|
+
if (!pathParams?.workspace)
|
113
|
+
return `${apiUrl}${path}`;
|
114
|
+
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
115
|
+
return url.replace("{workspaceId}", pathParams.workspace);
|
116
|
+
}
|
117
|
+
function hostHeader(url) {
|
118
|
+
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
119
|
+
const { groups } = pattern.exec(url) ?? {};
|
120
|
+
return groups?.host ? { Host: groups.host } : {};
|
121
|
+
}
|
122
|
+
async function fetch$1({
|
123
|
+
url: path,
|
124
|
+
method,
|
125
|
+
body,
|
126
|
+
headers,
|
127
|
+
pathParams,
|
128
|
+
queryParams,
|
129
|
+
fetchImpl,
|
130
|
+
apiKey,
|
131
|
+
apiUrl,
|
132
|
+
workspacesApiUrl
|
133
|
+
}) {
|
134
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
135
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
136
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
137
|
+
const response = await fetchImpl(url, {
|
138
|
+
method: method.toUpperCase(),
|
139
|
+
body: body ? JSON.stringify(body) : void 0,
|
140
|
+
headers: {
|
141
|
+
"Content-Type": "application/json",
|
142
|
+
...headers,
|
143
|
+
...hostHeader(fullUrl),
|
144
|
+
Authorization: `Bearer ${apiKey}`
|
145
|
+
}
|
146
|
+
});
|
147
|
+
if (response.status === 204) {
|
148
|
+
return {};
|
149
|
+
}
|
150
|
+
try {
|
151
|
+
const jsonResponse = await response.json();
|
152
|
+
if (response.ok) {
|
153
|
+
return jsonResponse;
|
154
|
+
}
|
155
|
+
throw new FetcherError(response.status, jsonResponse);
|
156
|
+
} catch (error) {
|
157
|
+
throw new FetcherError(response.status, error);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
|
162
|
+
const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
|
163
|
+
const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
|
164
|
+
const getUserAPIKeys = (variables) => fetch$1({
|
165
|
+
url: "/user/keys",
|
166
|
+
method: "get",
|
167
|
+
...variables
|
168
|
+
});
|
169
|
+
const createUserAPIKey = (variables) => fetch$1({
|
170
|
+
url: "/user/keys/{keyName}",
|
171
|
+
method: "post",
|
172
|
+
...variables
|
173
|
+
});
|
174
|
+
const deleteUserAPIKey = (variables) => fetch$1({
|
175
|
+
url: "/user/keys/{keyName}",
|
176
|
+
method: "delete",
|
177
|
+
...variables
|
178
|
+
});
|
179
|
+
const createWorkspace = (variables) => fetch$1({
|
180
|
+
url: "/workspaces",
|
181
|
+
method: "post",
|
182
|
+
...variables
|
183
|
+
});
|
184
|
+
const getWorkspacesList = (variables) => fetch$1({
|
185
|
+
url: "/workspaces",
|
186
|
+
method: "get",
|
187
|
+
...variables
|
188
|
+
});
|
189
|
+
const getWorkspace = (variables) => fetch$1({
|
190
|
+
url: "/workspaces/{workspaceId}",
|
191
|
+
method: "get",
|
192
|
+
...variables
|
193
|
+
});
|
194
|
+
const updateWorkspace = (variables) => fetch$1({
|
195
|
+
url: "/workspaces/{workspaceId}",
|
196
|
+
method: "put",
|
197
|
+
...variables
|
198
|
+
});
|
199
|
+
const deleteWorkspace = (variables) => fetch$1({
|
200
|
+
url: "/workspaces/{workspaceId}",
|
201
|
+
method: "delete",
|
202
|
+
...variables
|
203
|
+
});
|
204
|
+
const getWorkspaceMembersList = (variables) => fetch$1({
|
205
|
+
url: "/workspaces/{workspaceId}/members",
|
206
|
+
method: "get",
|
207
|
+
...variables
|
208
|
+
});
|
209
|
+
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
210
|
+
const removeWorkspaceMember = (variables) => fetch$1({
|
211
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
212
|
+
method: "delete",
|
213
|
+
...variables
|
214
|
+
});
|
215
|
+
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
216
|
+
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
217
|
+
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
218
|
+
method: "delete",
|
219
|
+
...variables
|
220
|
+
});
|
221
|
+
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
222
|
+
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
223
|
+
method: "post",
|
224
|
+
...variables
|
225
|
+
});
|
226
|
+
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
227
|
+
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
228
|
+
method: "post",
|
229
|
+
...variables
|
230
|
+
});
|
231
|
+
const getDatabaseList = (variables) => fetch$1({
|
232
|
+
url: "/dbs",
|
233
|
+
method: "get",
|
234
|
+
...variables
|
235
|
+
});
|
236
|
+
const getBranchList = (variables) => fetch$1({
|
237
|
+
url: "/dbs/{dbName}",
|
238
|
+
method: "get",
|
239
|
+
...variables
|
240
|
+
});
|
241
|
+
const createDatabase = (variables) => fetch$1({
|
242
|
+
url: "/dbs/{dbName}",
|
243
|
+
method: "put",
|
244
|
+
...variables
|
245
|
+
});
|
246
|
+
const deleteDatabase = (variables) => fetch$1({
|
247
|
+
url: "/dbs/{dbName}",
|
248
|
+
method: "delete",
|
249
|
+
...variables
|
250
|
+
});
|
251
|
+
const getBranchDetails = (variables) => fetch$1({
|
252
|
+
url: "/db/{dbBranchName}",
|
253
|
+
method: "get",
|
254
|
+
...variables
|
255
|
+
});
|
256
|
+
const createBranch = (variables) => fetch$1({
|
257
|
+
url: "/db/{dbBranchName}",
|
258
|
+
method: "put",
|
259
|
+
...variables
|
260
|
+
});
|
261
|
+
const deleteBranch = (variables) => fetch$1({
|
262
|
+
url: "/db/{dbBranchName}",
|
263
|
+
method: "delete",
|
264
|
+
...variables
|
265
|
+
});
|
266
|
+
const updateBranchMetadata = (variables) => fetch$1({
|
267
|
+
url: "/db/{dbBranchName}/metadata",
|
268
|
+
method: "put",
|
269
|
+
...variables
|
270
|
+
});
|
271
|
+
const getBranchMetadata = (variables) => fetch$1({
|
272
|
+
url: "/db/{dbBranchName}/metadata",
|
273
|
+
method: "get",
|
274
|
+
...variables
|
275
|
+
});
|
276
|
+
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
277
|
+
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
278
|
+
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
279
|
+
const getBranchStats = (variables) => fetch$1({
|
280
|
+
url: "/db/{dbBranchName}/stats",
|
281
|
+
method: "get",
|
282
|
+
...variables
|
283
|
+
});
|
284
|
+
const createTable = (variables) => fetch$1({
|
285
|
+
url: "/db/{dbBranchName}/tables/{tableName}",
|
286
|
+
method: "put",
|
287
|
+
...variables
|
288
|
+
});
|
289
|
+
const deleteTable = (variables) => fetch$1({
|
290
|
+
url: "/db/{dbBranchName}/tables/{tableName}",
|
291
|
+
method: "delete",
|
292
|
+
...variables
|
293
|
+
});
|
294
|
+
const updateTable = (variables) => fetch$1({
|
295
|
+
url: "/db/{dbBranchName}/tables/{tableName}",
|
296
|
+
method: "patch",
|
297
|
+
...variables
|
298
|
+
});
|
299
|
+
const getTableSchema = (variables) => fetch$1({
|
300
|
+
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
301
|
+
method: "get",
|
302
|
+
...variables
|
303
|
+
});
|
304
|
+
const setTableSchema = (variables) => fetch$1({
|
305
|
+
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
306
|
+
method: "put",
|
307
|
+
...variables
|
308
|
+
});
|
309
|
+
const getTableColumns = (variables) => fetch$1({
|
310
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
311
|
+
method: "get",
|
312
|
+
...variables
|
313
|
+
});
|
314
|
+
const addTableColumn = (variables) => fetch$1({
|
315
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
316
|
+
method: "post",
|
317
|
+
...variables
|
318
|
+
});
|
319
|
+
const getColumn = (variables) => fetch$1({
|
320
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
321
|
+
method: "get",
|
322
|
+
...variables
|
323
|
+
});
|
324
|
+
const deleteColumn = (variables) => fetch$1({
|
325
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
326
|
+
method: "delete",
|
327
|
+
...variables
|
328
|
+
});
|
329
|
+
const updateColumn = (variables) => fetch$1({
|
330
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
331
|
+
method: "patch",
|
332
|
+
...variables
|
333
|
+
});
|
334
|
+
const insertRecord = (variables) => fetch$1({
|
335
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
336
|
+
method: "post",
|
337
|
+
...variables
|
338
|
+
});
|
339
|
+
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
340
|
+
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
341
|
+
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
342
|
+
const deleteRecord = (variables) => fetch$1({
|
343
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
344
|
+
method: "delete",
|
345
|
+
...variables
|
346
|
+
});
|
347
|
+
const getRecord = (variables) => fetch$1({
|
348
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
349
|
+
method: "get",
|
350
|
+
...variables
|
351
|
+
});
|
352
|
+
const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
|
353
|
+
const queryTable = (variables) => fetch$1({
|
354
|
+
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
355
|
+
method: "post",
|
356
|
+
...variables
|
357
|
+
});
|
358
|
+
const searchBranch = (variables) => fetch$1({
|
359
|
+
url: "/db/{dbBranchName}/search",
|
360
|
+
method: "post",
|
361
|
+
...variables
|
362
|
+
});
|
363
|
+
const operationsByTag = {
|
364
|
+
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
365
|
+
workspaces: {
|
366
|
+
createWorkspace,
|
367
|
+
getWorkspacesList,
|
368
|
+
getWorkspace,
|
369
|
+
updateWorkspace,
|
370
|
+
deleteWorkspace,
|
371
|
+
getWorkspaceMembersList,
|
372
|
+
updateWorkspaceMemberRole,
|
373
|
+
removeWorkspaceMember,
|
374
|
+
inviteWorkspaceMember,
|
375
|
+
cancelWorkspaceMemberInvite,
|
376
|
+
resendWorkspaceMemberInvite,
|
377
|
+
acceptWorkspaceMemberInvite
|
378
|
+
},
|
379
|
+
database: { getDatabaseList, createDatabase, deleteDatabase },
|
380
|
+
branch: {
|
381
|
+
getBranchList,
|
382
|
+
getBranchDetails,
|
383
|
+
createBranch,
|
384
|
+
deleteBranch,
|
385
|
+
updateBranchMetadata,
|
386
|
+
getBranchMetadata,
|
387
|
+
getBranchMigrationHistory,
|
388
|
+
executeBranchMigrationPlan,
|
389
|
+
getBranchMigrationPlan,
|
390
|
+
getBranchStats
|
391
|
+
},
|
392
|
+
table: {
|
393
|
+
createTable,
|
394
|
+
deleteTable,
|
395
|
+
updateTable,
|
396
|
+
getTableSchema,
|
397
|
+
setTableSchema,
|
398
|
+
getTableColumns,
|
399
|
+
addTableColumn,
|
400
|
+
getColumn,
|
401
|
+
deleteColumn,
|
402
|
+
updateColumn
|
403
|
+
},
|
404
|
+
records: {
|
405
|
+
insertRecord,
|
406
|
+
insertRecordWithID,
|
407
|
+
updateRecordWithID,
|
408
|
+
upsertRecordWithID,
|
409
|
+
deleteRecord,
|
410
|
+
getRecord,
|
411
|
+
bulkInsertTableRecords,
|
412
|
+
queryTable,
|
413
|
+
searchBranch
|
414
|
+
}
|
415
|
+
};
|
416
|
+
|
417
|
+
function getHostUrl(provider, type) {
|
418
|
+
if (isValidAlias(provider)) {
|
419
|
+
return providers[provider][type];
|
420
|
+
} else if (isValidBuilder(provider)) {
|
421
|
+
return provider[type];
|
422
|
+
}
|
423
|
+
throw new Error("Invalid API provider");
|
424
|
+
}
|
425
|
+
const providers = {
|
426
|
+
production: {
|
427
|
+
main: "https://api.xata.io",
|
428
|
+
workspaces: "https://{workspaceId}.xata.sh"
|
429
|
+
},
|
430
|
+
staging: {
|
431
|
+
main: "https://staging.xatabase.co",
|
432
|
+
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
433
|
+
}
|
434
|
+
};
|
435
|
+
function isValidAlias(alias) {
|
436
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
437
|
+
}
|
438
|
+
function isValidBuilder(builder) {
|
439
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
440
|
+
}
|
441
|
+
|
442
|
+
var __accessCheck$7 = (obj, member, msg) => {
|
443
|
+
if (!member.has(obj))
|
444
|
+
throw TypeError("Cannot " + msg);
|
445
|
+
};
|
446
|
+
var __privateGet$6 = (obj, member, getter) => {
|
447
|
+
__accessCheck$7(obj, member, "read from private field");
|
448
|
+
return getter ? getter.call(obj) : member.get(obj);
|
449
|
+
};
|
450
|
+
var __privateAdd$7 = (obj, member, value) => {
|
451
|
+
if (member.has(obj))
|
452
|
+
throw TypeError("Cannot add the same private member more than once");
|
453
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
454
|
+
};
|
455
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
456
|
+
__accessCheck$7(obj, member, "write to private field");
|
457
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
458
|
+
return value;
|
459
|
+
};
|
460
|
+
var _extraProps, _namespaces;
|
461
|
+
class XataApiClient {
|
462
|
+
constructor(options = {}) {
|
463
|
+
__privateAdd$7(this, _extraProps, void 0);
|
464
|
+
__privateAdd$7(this, _namespaces, {});
|
465
|
+
const provider = options.host ?? "production";
|
466
|
+
const apiKey = options?.apiKey ?? getAPIKey();
|
467
|
+
if (!apiKey) {
|
468
|
+
throw new Error("Could not resolve a valid apiKey");
|
469
|
+
}
|
470
|
+
__privateSet$5(this, _extraProps, {
|
471
|
+
apiUrl: getHostUrl(provider, "main"),
|
472
|
+
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
473
|
+
fetchImpl: getFetchImplementation(options.fetch),
|
474
|
+
apiKey
|
475
|
+
});
|
476
|
+
}
|
477
|
+
get user() {
|
478
|
+
if (!__privateGet$6(this, _namespaces).user)
|
479
|
+
__privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
|
480
|
+
return __privateGet$6(this, _namespaces).user;
|
481
|
+
}
|
482
|
+
get workspaces() {
|
483
|
+
if (!__privateGet$6(this, _namespaces).workspaces)
|
484
|
+
__privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
|
485
|
+
return __privateGet$6(this, _namespaces).workspaces;
|
486
|
+
}
|
487
|
+
get databases() {
|
488
|
+
if (!__privateGet$6(this, _namespaces).databases)
|
489
|
+
__privateGet$6(this, _namespaces).databases = new DatabaseApi(__privateGet$6(this, _extraProps));
|
490
|
+
return __privateGet$6(this, _namespaces).databases;
|
491
|
+
}
|
492
|
+
get branches() {
|
493
|
+
if (!__privateGet$6(this, _namespaces).branches)
|
494
|
+
__privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
|
495
|
+
return __privateGet$6(this, _namespaces).branches;
|
496
|
+
}
|
497
|
+
get tables() {
|
498
|
+
if (!__privateGet$6(this, _namespaces).tables)
|
499
|
+
__privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
|
500
|
+
return __privateGet$6(this, _namespaces).tables;
|
501
|
+
}
|
502
|
+
get records() {
|
503
|
+
if (!__privateGet$6(this, _namespaces).records)
|
504
|
+
__privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
|
505
|
+
return __privateGet$6(this, _namespaces).records;
|
506
|
+
}
|
507
|
+
}
|
508
|
+
_extraProps = new WeakMap();
|
509
|
+
_namespaces = new WeakMap();
|
510
|
+
class UserApi {
|
511
|
+
constructor(extraProps) {
|
512
|
+
this.extraProps = extraProps;
|
513
|
+
}
|
514
|
+
getUser() {
|
515
|
+
return operationsByTag.users.getUser({ ...this.extraProps });
|
516
|
+
}
|
517
|
+
updateUser(user) {
|
518
|
+
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
519
|
+
}
|
520
|
+
deleteUser() {
|
521
|
+
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
522
|
+
}
|
523
|
+
getUserAPIKeys() {
|
524
|
+
return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
|
525
|
+
}
|
526
|
+
createUserAPIKey(keyName) {
|
527
|
+
return operationsByTag.users.createUserAPIKey({
|
528
|
+
pathParams: { keyName },
|
529
|
+
...this.extraProps
|
530
|
+
});
|
531
|
+
}
|
532
|
+
deleteUserAPIKey(keyName) {
|
533
|
+
return operationsByTag.users.deleteUserAPIKey({
|
534
|
+
pathParams: { keyName },
|
535
|
+
...this.extraProps
|
536
|
+
});
|
537
|
+
}
|
538
|
+
}
|
539
|
+
class WorkspaceApi {
|
540
|
+
constructor(extraProps) {
|
541
|
+
this.extraProps = extraProps;
|
542
|
+
}
|
543
|
+
createWorkspace(workspaceMeta) {
|
544
|
+
return operationsByTag.workspaces.createWorkspace({
|
545
|
+
body: workspaceMeta,
|
546
|
+
...this.extraProps
|
547
|
+
});
|
548
|
+
}
|
549
|
+
getWorkspacesList() {
|
550
|
+
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
551
|
+
}
|
552
|
+
getWorkspace(workspaceId) {
|
553
|
+
return operationsByTag.workspaces.getWorkspace({
|
554
|
+
pathParams: { workspaceId },
|
555
|
+
...this.extraProps
|
556
|
+
});
|
557
|
+
}
|
558
|
+
updateWorkspace(workspaceId, workspaceMeta) {
|
559
|
+
return operationsByTag.workspaces.updateWorkspace({
|
560
|
+
pathParams: { workspaceId },
|
561
|
+
body: workspaceMeta,
|
562
|
+
...this.extraProps
|
563
|
+
});
|
564
|
+
}
|
565
|
+
deleteWorkspace(workspaceId) {
|
566
|
+
return operationsByTag.workspaces.deleteWorkspace({
|
567
|
+
pathParams: { workspaceId },
|
568
|
+
...this.extraProps
|
569
|
+
});
|
570
|
+
}
|
571
|
+
getWorkspaceMembersList(workspaceId) {
|
572
|
+
return operationsByTag.workspaces.getWorkspaceMembersList({
|
573
|
+
pathParams: { workspaceId },
|
574
|
+
...this.extraProps
|
575
|
+
});
|
576
|
+
}
|
577
|
+
updateWorkspaceMemberRole(workspaceId, userId, role) {
|
578
|
+
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
579
|
+
pathParams: { workspaceId, userId },
|
580
|
+
body: { role },
|
581
|
+
...this.extraProps
|
582
|
+
});
|
583
|
+
}
|
584
|
+
removeWorkspaceMember(workspaceId, userId) {
|
585
|
+
return operationsByTag.workspaces.removeWorkspaceMember({
|
586
|
+
pathParams: { workspaceId, userId },
|
587
|
+
...this.extraProps
|
588
|
+
});
|
589
|
+
}
|
590
|
+
inviteWorkspaceMember(workspaceId, email, role) {
|
591
|
+
return operationsByTag.workspaces.inviteWorkspaceMember({
|
592
|
+
pathParams: { workspaceId },
|
593
|
+
body: { email, role },
|
594
|
+
...this.extraProps
|
595
|
+
});
|
596
|
+
}
|
597
|
+
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
598
|
+
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
599
|
+
pathParams: { workspaceId, inviteId },
|
600
|
+
...this.extraProps
|
601
|
+
});
|
602
|
+
}
|
603
|
+
resendWorkspaceMemberInvite(workspaceId, inviteId) {
|
604
|
+
return operationsByTag.workspaces.resendWorkspaceMemberInvite({
|
605
|
+
pathParams: { workspaceId, inviteId },
|
606
|
+
...this.extraProps
|
607
|
+
});
|
608
|
+
}
|
609
|
+
acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
|
610
|
+
return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
|
611
|
+
pathParams: { workspaceId, inviteKey },
|
612
|
+
...this.extraProps
|
613
|
+
});
|
614
|
+
}
|
615
|
+
}
|
616
|
+
class DatabaseApi {
|
617
|
+
constructor(extraProps) {
|
618
|
+
this.extraProps = extraProps;
|
619
|
+
}
|
620
|
+
getDatabaseList(workspace) {
|
621
|
+
return operationsByTag.database.getDatabaseList({
|
622
|
+
pathParams: { workspace },
|
623
|
+
...this.extraProps
|
624
|
+
});
|
625
|
+
}
|
626
|
+
createDatabase(workspace, dbName, options = {}) {
|
627
|
+
return operationsByTag.database.createDatabase({
|
628
|
+
pathParams: { workspace, dbName },
|
629
|
+
body: options,
|
630
|
+
...this.extraProps
|
631
|
+
});
|
632
|
+
}
|
633
|
+
deleteDatabase(workspace, dbName) {
|
634
|
+
return operationsByTag.database.deleteDatabase({
|
635
|
+
pathParams: { workspace, dbName },
|
636
|
+
...this.extraProps
|
637
|
+
});
|
638
|
+
}
|
639
|
+
}
|
640
|
+
class BranchApi {
|
641
|
+
constructor(extraProps) {
|
642
|
+
this.extraProps = extraProps;
|
643
|
+
}
|
644
|
+
getBranchList(workspace, dbName) {
|
645
|
+
return operationsByTag.branch.getBranchList({
|
646
|
+
pathParams: { workspace, dbName },
|
647
|
+
...this.extraProps
|
648
|
+
});
|
649
|
+
}
|
650
|
+
getBranchDetails(workspace, database, branch) {
|
651
|
+
return operationsByTag.branch.getBranchDetails({
|
652
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
653
|
+
...this.extraProps
|
654
|
+
});
|
655
|
+
}
|
656
|
+
createBranch(workspace, database, branch, from = "", options = {}) {
|
657
|
+
return operationsByTag.branch.createBranch({
|
658
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
659
|
+
queryParams: { from },
|
660
|
+
body: options,
|
661
|
+
...this.extraProps
|
662
|
+
});
|
663
|
+
}
|
664
|
+
deleteBranch(workspace, database, branch) {
|
665
|
+
return operationsByTag.branch.deleteBranch({
|
666
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
667
|
+
...this.extraProps
|
668
|
+
});
|
669
|
+
}
|
670
|
+
updateBranchMetadata(workspace, database, branch, metadata = {}) {
|
671
|
+
return operationsByTag.branch.updateBranchMetadata({
|
672
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
673
|
+
body: metadata,
|
674
|
+
...this.extraProps
|
675
|
+
});
|
676
|
+
}
|
677
|
+
getBranchMetadata(workspace, database, branch) {
|
678
|
+
return operationsByTag.branch.getBranchMetadata({
|
679
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
680
|
+
...this.extraProps
|
681
|
+
});
|
682
|
+
}
|
683
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
684
|
+
return operationsByTag.branch.getBranchMigrationHistory({
|
685
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
686
|
+
body: options,
|
687
|
+
...this.extraProps
|
688
|
+
});
|
689
|
+
}
|
690
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
691
|
+
return operationsByTag.branch.executeBranchMigrationPlan({
|
692
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
693
|
+
body: migrationPlan,
|
694
|
+
...this.extraProps
|
695
|
+
});
|
696
|
+
}
|
697
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
698
|
+
return operationsByTag.branch.getBranchMigrationPlan({
|
699
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
700
|
+
body: schema,
|
701
|
+
...this.extraProps
|
702
|
+
});
|
703
|
+
}
|
704
|
+
getBranchStats(workspace, database, branch) {
|
705
|
+
return operationsByTag.branch.getBranchStats({
|
706
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
707
|
+
...this.extraProps
|
708
|
+
});
|
709
|
+
}
|
710
|
+
}
|
711
|
+
class TableApi {
|
712
|
+
constructor(extraProps) {
|
713
|
+
this.extraProps = extraProps;
|
714
|
+
}
|
715
|
+
createTable(workspace, database, branch, tableName) {
|
716
|
+
return operationsByTag.table.createTable({
|
717
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
718
|
+
...this.extraProps
|
719
|
+
});
|
720
|
+
}
|
721
|
+
deleteTable(workspace, database, branch, tableName) {
|
722
|
+
return operationsByTag.table.deleteTable({
|
723
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
724
|
+
...this.extraProps
|
725
|
+
});
|
726
|
+
}
|
727
|
+
updateTable(workspace, database, branch, tableName, options) {
|
728
|
+
return operationsByTag.table.updateTable({
|
729
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
730
|
+
body: options,
|
731
|
+
...this.extraProps
|
732
|
+
});
|
733
|
+
}
|
734
|
+
getTableSchema(workspace, database, branch, tableName) {
|
735
|
+
return operationsByTag.table.getTableSchema({
|
736
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
737
|
+
...this.extraProps
|
738
|
+
});
|
739
|
+
}
|
740
|
+
setTableSchema(workspace, database, branch, tableName, options) {
|
741
|
+
return operationsByTag.table.setTableSchema({
|
742
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
743
|
+
body: options,
|
744
|
+
...this.extraProps
|
745
|
+
});
|
746
|
+
}
|
747
|
+
getTableColumns(workspace, database, branch, tableName) {
|
748
|
+
return operationsByTag.table.getTableColumns({
|
749
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
750
|
+
...this.extraProps
|
751
|
+
});
|
752
|
+
}
|
753
|
+
addTableColumn(workspace, database, branch, tableName, column) {
|
754
|
+
return operationsByTag.table.addTableColumn({
|
755
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
756
|
+
body: column,
|
757
|
+
...this.extraProps
|
758
|
+
});
|
759
|
+
}
|
760
|
+
getColumn(workspace, database, branch, tableName, columnName) {
|
761
|
+
return operationsByTag.table.getColumn({
|
762
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
|
763
|
+
...this.extraProps
|
764
|
+
});
|
765
|
+
}
|
766
|
+
deleteColumn(workspace, database, branch, tableName, columnName) {
|
767
|
+
return operationsByTag.table.deleteColumn({
|
768
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
|
769
|
+
...this.extraProps
|
770
|
+
});
|
771
|
+
}
|
772
|
+
updateColumn(workspace, database, branch, tableName, columnName, options) {
|
773
|
+
return operationsByTag.table.updateColumn({
|
774
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
|
775
|
+
body: options,
|
776
|
+
...this.extraProps
|
777
|
+
});
|
778
|
+
}
|
779
|
+
}
|
780
|
+
class RecordsApi {
|
781
|
+
constructor(extraProps) {
|
782
|
+
this.extraProps = extraProps;
|
783
|
+
}
|
784
|
+
insertRecord(workspace, database, branch, tableName, record) {
|
785
|
+
return operationsByTag.records.insertRecord({
|
786
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
787
|
+
body: record,
|
788
|
+
...this.extraProps
|
789
|
+
});
|
790
|
+
}
|
791
|
+
insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
792
|
+
return operationsByTag.records.insertRecordWithID({
|
793
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
794
|
+
queryParams: options,
|
795
|
+
body: record,
|
796
|
+
...this.extraProps
|
797
|
+
});
|
798
|
+
}
|
799
|
+
updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
800
|
+
return operationsByTag.records.updateRecordWithID({
|
801
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
802
|
+
queryParams: options,
|
803
|
+
body: record,
|
804
|
+
...this.extraProps
|
805
|
+
});
|
806
|
+
}
|
807
|
+
upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
808
|
+
return operationsByTag.records.upsertRecordWithID({
|
809
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
810
|
+
queryParams: options,
|
811
|
+
body: record,
|
812
|
+
...this.extraProps
|
813
|
+
});
|
814
|
+
}
|
815
|
+
deleteRecord(workspace, database, branch, tableName, recordId) {
|
816
|
+
return operationsByTag.records.deleteRecord({
|
817
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
818
|
+
...this.extraProps
|
819
|
+
});
|
820
|
+
}
|
821
|
+
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
822
|
+
return operationsByTag.records.getRecord({
|
823
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
824
|
+
...this.extraProps
|
825
|
+
});
|
826
|
+
}
|
827
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
828
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
829
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
830
|
+
body: { records },
|
831
|
+
...this.extraProps
|
832
|
+
});
|
833
|
+
}
|
834
|
+
queryTable(workspace, database, branch, tableName, query) {
|
835
|
+
return operationsByTag.records.queryTable({
|
836
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
837
|
+
body: query,
|
838
|
+
...this.extraProps
|
839
|
+
});
|
840
|
+
}
|
841
|
+
searchBranch(workspace, database, branch, query) {
|
842
|
+
return operationsByTag.records.searchBranch({
|
843
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
844
|
+
body: query,
|
845
|
+
...this.extraProps
|
846
|
+
});
|
847
|
+
}
|
848
|
+
}
|
849
|
+
|
850
|
+
class XataApiPlugin {
|
851
|
+
async build(options) {
|
852
|
+
const { fetchImpl, apiKey } = await options.getFetchProps();
|
853
|
+
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
854
|
+
}
|
855
|
+
}
|
856
|
+
|
857
|
+
class XataPlugin {
|
858
|
+
}
|
859
|
+
|
860
|
+
var __accessCheck$6 = (obj, member, msg) => {
|
861
|
+
if (!member.has(obj))
|
862
|
+
throw TypeError("Cannot " + msg);
|
863
|
+
};
|
864
|
+
var __privateGet$5 = (obj, member, getter) => {
|
865
|
+
__accessCheck$6(obj, member, "read from private field");
|
866
|
+
return getter ? getter.call(obj) : member.get(obj);
|
867
|
+
};
|
868
|
+
var __privateAdd$6 = (obj, member, value) => {
|
869
|
+
if (member.has(obj))
|
870
|
+
throw TypeError("Cannot add the same private member more than once");
|
871
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
872
|
+
};
|
873
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
874
|
+
__accessCheck$6(obj, member, "write to private field");
|
875
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
876
|
+
return value;
|
877
|
+
};
|
878
|
+
var _query;
|
879
|
+
class Page {
|
880
|
+
constructor(query, meta, records = []) {
|
881
|
+
__privateAdd$6(this, _query, void 0);
|
882
|
+
__privateSet$4(this, _query, query);
|
883
|
+
this.meta = meta;
|
884
|
+
this.records = records;
|
885
|
+
}
|
886
|
+
async nextPage(size, offset) {
|
887
|
+
return __privateGet$5(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
|
888
|
+
}
|
889
|
+
async previousPage(size, offset) {
|
890
|
+
return __privateGet$5(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
|
891
|
+
}
|
892
|
+
async firstPage(size, offset) {
|
893
|
+
return __privateGet$5(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
|
894
|
+
}
|
895
|
+
async lastPage(size, offset) {
|
896
|
+
return __privateGet$5(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
|
897
|
+
}
|
898
|
+
hasNextPage() {
|
899
|
+
return this.meta.page.more;
|
900
|
+
}
|
901
|
+
}
|
902
|
+
_query = new WeakMap();
|
903
|
+
const PAGINATION_MAX_SIZE = 200;
|
904
|
+
const PAGINATION_DEFAULT_SIZE = 200;
|
905
|
+
const PAGINATION_MAX_OFFSET = 800;
|
906
|
+
const PAGINATION_DEFAULT_OFFSET = 0;
|
907
|
+
|
908
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
909
|
+
if (!member.has(obj))
|
910
|
+
throw TypeError("Cannot " + msg);
|
911
|
+
};
|
912
|
+
var __privateGet$4 = (obj, member, getter) => {
|
913
|
+
__accessCheck$5(obj, member, "read from private field");
|
914
|
+
return getter ? getter.call(obj) : member.get(obj);
|
915
|
+
};
|
916
|
+
var __privateAdd$5 = (obj, member, value) => {
|
917
|
+
if (member.has(obj))
|
918
|
+
throw TypeError("Cannot add the same private member more than once");
|
919
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
920
|
+
};
|
921
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
922
|
+
__accessCheck$5(obj, member, "write to private field");
|
923
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
924
|
+
return value;
|
925
|
+
};
|
926
|
+
var _table$1, _repository, _data;
|
927
|
+
const _Query = class {
|
928
|
+
constructor(repository, table, data, parent) {
|
929
|
+
__privateAdd$5(this, _table$1, void 0);
|
930
|
+
__privateAdd$5(this, _repository, void 0);
|
931
|
+
__privateAdd$5(this, _data, { filter: {} });
|
932
|
+
this.meta = { page: { cursor: "start", more: true } };
|
933
|
+
this.records = [];
|
934
|
+
__privateSet$3(this, _table$1, table);
|
935
|
+
if (repository) {
|
936
|
+
__privateSet$3(this, _repository, repository);
|
937
|
+
} else {
|
938
|
+
__privateSet$3(this, _repository, this);
|
939
|
+
}
|
940
|
+
__privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
941
|
+
__privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
942
|
+
__privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
943
|
+
__privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
944
|
+
__privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
945
|
+
__privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
|
946
|
+
__privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
|
947
|
+
__privateGet$4(this, _data).page = data.page ?? parent?.page;
|
948
|
+
__privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
|
949
|
+
this.any = this.any.bind(this);
|
950
|
+
this.all = this.all.bind(this);
|
951
|
+
this.not = this.not.bind(this);
|
952
|
+
this.filter = this.filter.bind(this);
|
953
|
+
this.sort = this.sort.bind(this);
|
954
|
+
this.none = this.none.bind(this);
|
955
|
+
Object.defineProperty(this, "table", { enumerable: false });
|
956
|
+
Object.defineProperty(this, "repository", { enumerable: false });
|
957
|
+
}
|
958
|
+
getQueryOptions() {
|
959
|
+
return __privateGet$4(this, _data);
|
960
|
+
}
|
961
|
+
key() {
|
962
|
+
const { columns = [], filter = {}, sort = [], page = {} } = __privateGet$4(this, _data);
|
963
|
+
const key = JSON.stringify({ columns, filter, sort, page });
|
964
|
+
return toBase64(key);
|
965
|
+
}
|
966
|
+
any(...queries) {
|
967
|
+
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
968
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
|
969
|
+
}
|
970
|
+
all(...queries) {
|
971
|
+
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
972
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
973
|
+
}
|
974
|
+
not(...queries) {
|
975
|
+
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
976
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
|
977
|
+
}
|
978
|
+
none(...queries) {
|
979
|
+
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
980
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
|
981
|
+
}
|
982
|
+
filter(a, b) {
|
983
|
+
if (arguments.length === 1) {
|
984
|
+
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
985
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
|
986
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
987
|
+
} else {
|
988
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
|
989
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
990
|
+
}
|
991
|
+
}
|
992
|
+
sort(column, direction) {
|
993
|
+
const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
|
994
|
+
const sort = [...originalSort, { column, direction }];
|
995
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
|
996
|
+
}
|
997
|
+
select(columns) {
|
998
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { columns }, __privateGet$4(this, _data));
|
999
|
+
}
|
1000
|
+
getPaginated(options = {}) {
|
1001
|
+
const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
|
1002
|
+
return __privateGet$4(this, _repository).query(query);
|
1003
|
+
}
|
1004
|
+
async *[Symbol.asyncIterator]() {
|
1005
|
+
for await (const [record] of this.getIterator(1)) {
|
1006
|
+
yield record;
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
async *getIterator(chunk, options = {}) {
|
1010
|
+
let offset = 0;
|
1011
|
+
let end = false;
|
1012
|
+
while (!end) {
|
1013
|
+
const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
|
1014
|
+
yield records;
|
1015
|
+
offset += chunk;
|
1016
|
+
end = !meta.page.more;
|
1017
|
+
}
|
1018
|
+
}
|
1019
|
+
async getMany(options = {}) {
|
1020
|
+
const { records } = await this.getPaginated(options);
|
1021
|
+
return records;
|
1022
|
+
}
|
1023
|
+
async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
|
1024
|
+
const results = [];
|
1025
|
+
for await (const page of this.getIterator(chunk, options)) {
|
1026
|
+
results.push(...page);
|
1027
|
+
}
|
1028
|
+
return results;
|
1029
|
+
}
|
1030
|
+
async getFirst(options = {}) {
|
1031
|
+
const records = await this.getMany({ ...options, page: { size: 1 } });
|
1032
|
+
return records[0] || null;
|
1033
|
+
}
|
1034
|
+
cache(ttl) {
|
1035
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
|
1036
|
+
}
|
1037
|
+
nextPage(size, offset) {
|
1038
|
+
return this.firstPage(size, offset);
|
1039
|
+
}
|
1040
|
+
previousPage(size, offset) {
|
1041
|
+
return this.firstPage(size, offset);
|
1042
|
+
}
|
1043
|
+
firstPage(size, offset) {
|
1044
|
+
return this.getPaginated({ page: { size, offset } });
|
1045
|
+
}
|
1046
|
+
lastPage(size, offset) {
|
1047
|
+
return this.getPaginated({ page: { size, offset, before: "end" } });
|
1048
|
+
}
|
1049
|
+
hasNextPage() {
|
1050
|
+
return this.meta.page.more;
|
1051
|
+
}
|
1052
|
+
};
|
1053
|
+
let Query = _Query;
|
1054
|
+
_table$1 = new WeakMap();
|
1055
|
+
_repository = new WeakMap();
|
1056
|
+
_data = new WeakMap();
|
1057
|
+
|
1058
|
+
function isIdentifiable(x) {
|
1059
|
+
return isObject(x) && isString(x?.id);
|
1060
|
+
}
|
1061
|
+
function isXataRecord(x) {
|
1062
|
+
return isIdentifiable(x) && typeof x?.xata === "object" && typeof x?.xata?.version === "number";
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
function isSortFilterString(value) {
|
1066
|
+
return isString(value);
|
1067
|
+
}
|
1068
|
+
function isSortFilterBase(filter) {
|
1069
|
+
return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
|
1070
|
+
}
|
1071
|
+
function isSortFilterObject(filter) {
|
1072
|
+
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
1073
|
+
}
|
1074
|
+
function buildSortFilter(filter) {
|
1075
|
+
if (isSortFilterString(filter)) {
|
1076
|
+
return { [filter]: "asc" };
|
1077
|
+
} else if (Array.isArray(filter)) {
|
1078
|
+
return filter.map((item) => buildSortFilter(item));
|
1079
|
+
} else if (isSortFilterBase(filter)) {
|
1080
|
+
return filter;
|
1081
|
+
} else if (isSortFilterObject(filter)) {
|
1082
|
+
return { [filter.column]: filter.direction ?? "asc" };
|
1083
|
+
} else {
|
1084
|
+
throw new Error(`Invalid sort filter: ${filter}`);
|
1085
|
+
}
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
1089
|
+
if (!member.has(obj))
|
1090
|
+
throw TypeError("Cannot " + msg);
|
1091
|
+
};
|
1092
|
+
var __privateGet$3 = (obj, member, getter) => {
|
1093
|
+
__accessCheck$4(obj, member, "read from private field");
|
1094
|
+
return getter ? getter.call(obj) : member.get(obj);
|
1095
|
+
};
|
1096
|
+
var __privateAdd$4 = (obj, member, value) => {
|
1097
|
+
if (member.has(obj))
|
1098
|
+
throw TypeError("Cannot add the same private member more than once");
|
1099
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1100
|
+
};
|
1101
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1102
|
+
__accessCheck$4(obj, member, "write to private field");
|
1103
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1104
|
+
return value;
|
1105
|
+
};
|
1106
|
+
var __privateMethod$2 = (obj, member, method) => {
|
1107
|
+
__accessCheck$4(obj, member, "access private method");
|
1108
|
+
return method;
|
1109
|
+
};
|
1110
|
+
var _table, _links, _getFetchProps, _cache, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn;
|
1111
|
+
class Repository extends Query {
|
1112
|
+
}
|
1113
|
+
class RestRepository extends Query {
|
1114
|
+
constructor(options) {
|
1115
|
+
super(null, options.table, {});
|
1116
|
+
__privateAdd$4(this, _insertRecordWithoutId);
|
1117
|
+
__privateAdd$4(this, _insertRecordWithId);
|
1118
|
+
__privateAdd$4(this, _bulkInsertTableRecords);
|
1119
|
+
__privateAdd$4(this, _updateRecordWithID);
|
1120
|
+
__privateAdd$4(this, _upsertRecordWithID);
|
1121
|
+
__privateAdd$4(this, _deleteRecord);
|
1122
|
+
__privateAdd$4(this, _invalidateCache);
|
1123
|
+
__privateAdd$4(this, _setCacheRecord);
|
1124
|
+
__privateAdd$4(this, _getCacheRecord);
|
1125
|
+
__privateAdd$4(this, _setCacheQuery);
|
1126
|
+
__privateAdd$4(this, _getCacheQuery);
|
1127
|
+
__privateAdd$4(this, _table, void 0);
|
1128
|
+
__privateAdd$4(this, _links, void 0);
|
1129
|
+
__privateAdd$4(this, _getFetchProps, void 0);
|
1130
|
+
__privateAdd$4(this, _cache, void 0);
|
1131
|
+
__privateSet$2(this, _table, options.table);
|
1132
|
+
__privateSet$2(this, _links, options.links ?? {});
|
1133
|
+
__privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1134
|
+
this.db = options.db;
|
1135
|
+
__privateSet$2(this, _cache, options.pluginOptions.cache);
|
1136
|
+
}
|
1137
|
+
async create(a, b) {
|
1138
|
+
if (Array.isArray(a)) {
|
1139
|
+
const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
|
1140
|
+
await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
|
1141
|
+
return records;
|
1142
|
+
}
|
1143
|
+
if (isString(a) && isObject(b)) {
|
1144
|
+
if (a === "")
|
1145
|
+
throw new Error("The id can't be empty");
|
1146
|
+
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
|
1147
|
+
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1148
|
+
return record;
|
1149
|
+
}
|
1150
|
+
if (isObject(a) && isString(a.id)) {
|
1151
|
+
if (a.id === "")
|
1152
|
+
throw new Error("The id can't be empty");
|
1153
|
+
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
|
1154
|
+
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1155
|
+
return record;
|
1156
|
+
}
|
1157
|
+
if (isObject(a)) {
|
1158
|
+
const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
|
1159
|
+
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1160
|
+
return record;
|
1161
|
+
}
|
1162
|
+
throw new Error("Invalid arguments for create method");
|
1163
|
+
}
|
1164
|
+
async read(recordId) {
|
1165
|
+
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
|
1166
|
+
if (cacheRecord)
|
1167
|
+
return cacheRecord;
|
1168
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1169
|
+
try {
|
1170
|
+
const response = await getRecord({
|
1171
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
|
1172
|
+
...fetchProps
|
1173
|
+
});
|
1174
|
+
return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
|
1175
|
+
} catch (e) {
|
1176
|
+
if (isObject(e) && e.status === 404) {
|
1177
|
+
return null;
|
1178
|
+
}
|
1179
|
+
throw e;
|
1180
|
+
}
|
1181
|
+
}
|
1182
|
+
async update(a, b) {
|
1183
|
+
if (Array.isArray(a)) {
|
1184
|
+
if (a.length > 100) {
|
1185
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1186
|
+
}
|
1187
|
+
return Promise.all(a.map((object) => this.update(object)));
|
1188
|
+
}
|
1189
|
+
if (isString(a) && isObject(b)) {
|
1190
|
+
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1191
|
+
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1192
|
+
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1193
|
+
return record;
|
1194
|
+
}
|
1195
|
+
if (isObject(a) && isString(a.id)) {
|
1196
|
+
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1197
|
+
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1198
|
+
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1199
|
+
return record;
|
1200
|
+
}
|
1201
|
+
throw new Error("Invalid arguments for update method");
|
1202
|
+
}
|
1203
|
+
async createOrUpdate(a, b) {
|
1204
|
+
if (Array.isArray(a)) {
|
1205
|
+
if (a.length > 100) {
|
1206
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1207
|
+
}
|
1208
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object)));
|
1209
|
+
}
|
1210
|
+
if (isString(a) && isObject(b)) {
|
1211
|
+
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1212
|
+
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
|
1213
|
+
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1214
|
+
return record;
|
1215
|
+
}
|
1216
|
+
if (isObject(a) && isString(a.id)) {
|
1217
|
+
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1218
|
+
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1219
|
+
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1220
|
+
return record;
|
1221
|
+
}
|
1222
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1223
|
+
}
|
1224
|
+
async delete(a) {
|
1225
|
+
if (Array.isArray(a)) {
|
1226
|
+
if (a.length > 100) {
|
1227
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1228
|
+
}
|
1229
|
+
await Promise.all(a.map((id) => this.delete(id)));
|
1230
|
+
return;
|
1231
|
+
}
|
1232
|
+
if (isString(a)) {
|
1233
|
+
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1234
|
+
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1235
|
+
return;
|
1236
|
+
}
|
1237
|
+
if (isObject(a) && isString(a.id)) {
|
1238
|
+
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1239
|
+
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1240
|
+
return;
|
1241
|
+
}
|
1242
|
+
throw new Error("Invalid arguments for delete method");
|
1243
|
+
}
|
1244
|
+
async search(query, options = {}) {
|
1245
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1246
|
+
const { records } = await searchBranch({
|
1247
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1248
|
+
body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
|
1249
|
+
...fetchProps
|
1250
|
+
});
|
1251
|
+
return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
|
1252
|
+
}
|
1253
|
+
async query(query) {
|
1254
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1255
|
+
if (cacheQuery)
|
1256
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1257
|
+
const data = query.getQueryOptions();
|
1258
|
+
const body = {
|
1259
|
+
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1260
|
+
sort: data.sort ? buildSortFilter(data.sort) : void 0,
|
1261
|
+
page: data.page,
|
1262
|
+
columns: data.columns
|
1263
|
+
};
|
1264
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1265
|
+
const { meta, records: objects } = await queryTable({
|
1266
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
|
1267
|
+
body,
|
1268
|
+
...fetchProps
|
1269
|
+
});
|
1270
|
+
const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
|
1271
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1272
|
+
return new Page(query, meta, records);
|
1273
|
+
}
|
1274
|
+
}
|
1275
|
+
_table = new WeakMap();
|
1276
|
+
_links = new WeakMap();
|
1277
|
+
_getFetchProps = new WeakMap();
|
1278
|
+
_cache = new WeakMap();
|
1279
|
+
_insertRecordWithoutId = new WeakSet();
|
1280
|
+
insertRecordWithoutId_fn = async function(object) {
|
1281
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1282
|
+
const record = transformObjectLinks(object);
|
1283
|
+
const response = await insertRecord({
|
1284
|
+
pathParams: {
|
1285
|
+
workspace: "{workspaceId}",
|
1286
|
+
dbBranchName: "{dbBranch}",
|
1287
|
+
tableName: __privateGet$3(this, _table)
|
1288
|
+
},
|
1289
|
+
body: record,
|
1290
|
+
...fetchProps
|
1291
|
+
});
|
1292
|
+
const finalObject = await this.read(response.id);
|
1293
|
+
if (!finalObject) {
|
1294
|
+
throw new Error("The server failed to save the record");
|
1295
|
+
}
|
1296
|
+
return finalObject;
|
1297
|
+
};
|
1298
|
+
_insertRecordWithId = new WeakSet();
|
1299
|
+
insertRecordWithId_fn = async function(recordId, object) {
|
1300
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1301
|
+
const record = transformObjectLinks(object);
|
1302
|
+
const response = await insertRecordWithID({
|
1303
|
+
pathParams: {
|
1304
|
+
workspace: "{workspaceId}",
|
1305
|
+
dbBranchName: "{dbBranch}",
|
1306
|
+
tableName: __privateGet$3(this, _table),
|
1307
|
+
recordId
|
1308
|
+
},
|
1309
|
+
body: record,
|
1310
|
+
queryParams: { createOnly: true },
|
1311
|
+
...fetchProps
|
1312
|
+
});
|
1313
|
+
const finalObject = await this.read(response.id);
|
1314
|
+
if (!finalObject) {
|
1315
|
+
throw new Error("The server failed to save the record");
|
1316
|
+
}
|
1317
|
+
return finalObject;
|
1318
|
+
};
|
1319
|
+
_bulkInsertTableRecords = new WeakSet();
|
1320
|
+
bulkInsertTableRecords_fn = async function(objects) {
|
1321
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1322
|
+
const records = objects.map((object) => transformObjectLinks(object));
|
1323
|
+
const response = await bulkInsertTableRecords({
|
1324
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
|
1325
|
+
body: { records },
|
1326
|
+
...fetchProps
|
1327
|
+
});
|
1328
|
+
const finalObjects = await this.any(...response.recordIDs.map((id) => this.filter("id", id))).getAll();
|
1329
|
+
if (finalObjects.length !== objects.length) {
|
1330
|
+
throw new Error("The server failed to save some records");
|
1331
|
+
}
|
1332
|
+
return finalObjects;
|
1333
|
+
};
|
1334
|
+
_updateRecordWithID = new WeakSet();
|
1335
|
+
updateRecordWithID_fn = async function(recordId, object) {
|
1336
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1337
|
+
const record = transformObjectLinks(object);
|
1338
|
+
const response = await updateRecordWithID({
|
1339
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
|
1340
|
+
body: record,
|
1341
|
+
...fetchProps
|
1342
|
+
});
|
1343
|
+
const item = await this.read(response.id);
|
1344
|
+
if (!item)
|
1345
|
+
throw new Error("The server failed to save the record");
|
1346
|
+
return item;
|
1347
|
+
};
|
1348
|
+
_upsertRecordWithID = new WeakSet();
|
1349
|
+
upsertRecordWithID_fn = async function(recordId, object) {
|
1350
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1351
|
+
const response = await upsertRecordWithID({
|
1352
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
|
1353
|
+
body: object,
|
1354
|
+
...fetchProps
|
1355
|
+
});
|
1356
|
+
const item = await this.read(response.id);
|
1357
|
+
if (!item)
|
1358
|
+
throw new Error("The server failed to save the record");
|
1359
|
+
return item;
|
1360
|
+
};
|
1361
|
+
_deleteRecord = new WeakSet();
|
1362
|
+
deleteRecord_fn = async function(recordId) {
|
1363
|
+
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1364
|
+
await deleteRecord({
|
1365
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
|
1366
|
+
...fetchProps
|
1367
|
+
});
|
1368
|
+
};
|
1369
|
+
_invalidateCache = new WeakSet();
|
1370
|
+
invalidateCache_fn = async function(recordId) {
|
1371
|
+
await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
|
1372
|
+
const cacheItems = await __privateGet$3(this, _cache).getAll();
|
1373
|
+
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1374
|
+
for (const [key, value] of queries) {
|
1375
|
+
const ids = getIds(value);
|
1376
|
+
if (ids.includes(recordId))
|
1377
|
+
await __privateGet$3(this, _cache).delete(key);
|
1378
|
+
}
|
1379
|
+
};
|
1380
|
+
_setCacheRecord = new WeakSet();
|
1381
|
+
setCacheRecord_fn = async function(record) {
|
1382
|
+
if (!__privateGet$3(this, _cache).cacheRecords)
|
1383
|
+
return;
|
1384
|
+
await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
|
1385
|
+
};
|
1386
|
+
_getCacheRecord = new WeakSet();
|
1387
|
+
getCacheRecord_fn = async function(recordId) {
|
1388
|
+
if (!__privateGet$3(this, _cache).cacheRecords)
|
1389
|
+
return null;
|
1390
|
+
return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
|
1391
|
+
};
|
1392
|
+
_setCacheQuery = new WeakSet();
|
1393
|
+
setCacheQuery_fn = async function(query, meta, records) {
|
1394
|
+
await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
1395
|
+
};
|
1396
|
+
_getCacheQuery = new WeakSet();
|
1397
|
+
getCacheQuery_fn = async function(query) {
|
1398
|
+
const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
|
1399
|
+
const result = await __privateGet$3(this, _cache).get(key);
|
1400
|
+
if (!result)
|
1401
|
+
return null;
|
1402
|
+
const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
|
1403
|
+
if (!ttl || ttl < 0)
|
1404
|
+
return result;
|
1405
|
+
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1406
|
+
return hasExpired ? null : result;
|
1407
|
+
};
|
1408
|
+
const transformObjectLinks = (object) => {
|
1409
|
+
return Object.entries(object).reduce((acc, [key, value]) => {
|
1410
|
+
if (key === "xata")
|
1411
|
+
return acc;
|
1412
|
+
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1413
|
+
}, {});
|
1414
|
+
};
|
1415
|
+
const initObject = (db, links, table, object) => {
|
1416
|
+
const result = {};
|
1417
|
+
Object.assign(result, object);
|
1418
|
+
const tableLinks = links[table] || [];
|
1419
|
+
for (const link of tableLinks) {
|
1420
|
+
const [field, linkTable] = link;
|
1421
|
+
const value = result[field];
|
1422
|
+
if (value && isObject(value)) {
|
1423
|
+
result[field] = initObject(db, links, linkTable, value);
|
1424
|
+
}
|
1425
|
+
}
|
1426
|
+
result.read = function() {
|
1427
|
+
return db[table].read(result["id"]);
|
1428
|
+
};
|
1429
|
+
result.update = function(data) {
|
1430
|
+
return db[table].update(result["id"], data);
|
1431
|
+
};
|
1432
|
+
result.delete = function() {
|
1433
|
+
return db[table].delete(result["id"]);
|
1434
|
+
};
|
1435
|
+
for (const prop of ["read", "update", "delete"]) {
|
1436
|
+
Object.defineProperty(result, prop, { enumerable: false });
|
1437
|
+
}
|
1438
|
+
Object.freeze(result);
|
1439
|
+
return result;
|
1440
|
+
};
|
1441
|
+
function getIds(value) {
|
1442
|
+
if (Array.isArray(value)) {
|
1443
|
+
return value.map((item) => getIds(item)).flat();
|
1444
|
+
}
|
1445
|
+
if (!isObject(value))
|
1446
|
+
return [];
|
1447
|
+
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1448
|
+
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1449
|
+
}
|
1450
|
+
|
1451
|
+
var __accessCheck$3 = (obj, member, msg) => {
|
1452
|
+
if (!member.has(obj))
|
1453
|
+
throw TypeError("Cannot " + msg);
|
1454
|
+
};
|
1455
|
+
var __privateGet$2 = (obj, member, getter) => {
|
1456
|
+
__accessCheck$3(obj, member, "read from private field");
|
1457
|
+
return getter ? getter.call(obj) : member.get(obj);
|
1458
|
+
};
|
1459
|
+
var __privateAdd$3 = (obj, member, value) => {
|
1460
|
+
if (member.has(obj))
|
1461
|
+
throw TypeError("Cannot add the same private member more than once");
|
1462
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1463
|
+
};
|
1464
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
1465
|
+
__accessCheck$3(obj, member, "write to private field");
|
1466
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1467
|
+
return value;
|
1468
|
+
};
|
1469
|
+
var _map;
|
1470
|
+
class SimpleCache {
|
1471
|
+
constructor(options = {}) {
|
1472
|
+
__privateAdd$3(this, _map, void 0);
|
1473
|
+
__privateSet$1(this, _map, /* @__PURE__ */ new Map());
|
1474
|
+
this.capacity = options.max ?? 500;
|
1475
|
+
this.cacheRecords = options.cacheRecords ?? true;
|
1476
|
+
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1477
|
+
}
|
1478
|
+
async getAll() {
|
1479
|
+
return Object.fromEntries(__privateGet$2(this, _map));
|
1480
|
+
}
|
1481
|
+
async get(key) {
|
1482
|
+
return __privateGet$2(this, _map).get(key) ?? null;
|
1483
|
+
}
|
1484
|
+
async set(key, value) {
|
1485
|
+
await this.delete(key);
|
1486
|
+
__privateGet$2(this, _map).set(key, value);
|
1487
|
+
if (__privateGet$2(this, _map).size > this.capacity) {
|
1488
|
+
const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
|
1489
|
+
await this.delete(leastRecentlyUsed);
|
1490
|
+
}
|
1491
|
+
}
|
1492
|
+
async delete(key) {
|
1493
|
+
__privateGet$2(this, _map).delete(key);
|
1494
|
+
}
|
1495
|
+
async clear() {
|
1496
|
+
return __privateGet$2(this, _map).clear();
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
_map = new WeakMap();
|
1500
|
+
|
1501
|
+
const gt = (value) => ({ $gt: value });
|
1502
|
+
const ge = (value) => ({ $ge: value });
|
1503
|
+
const gte = (value) => ({ $ge: value });
|
1504
|
+
const lt = (value) => ({ $lt: value });
|
1505
|
+
const lte = (value) => ({ $le: value });
|
1506
|
+
const le = (value) => ({ $le: value });
|
1507
|
+
const exists = (column) => ({ $exists: column });
|
1508
|
+
const notExists = (column) => ({ $notExists: column });
|
1509
|
+
const startsWith = (value) => ({ $startsWith: value });
|
1510
|
+
const endsWith = (value) => ({ $endsWith: value });
|
1511
|
+
const pattern = (value) => ({ $pattern: value });
|
1512
|
+
const is = (value) => ({ $is: value });
|
1513
|
+
const isNot = (value) => ({ $isNot: value });
|
1514
|
+
const contains = (value) => ({ $contains: value });
|
1515
|
+
const includes = (value) => ({ $includes: value });
|
1516
|
+
const includesAll = (value) => ({ $includesAll: value });
|
1517
|
+
const includesNone = (value) => ({ $includesNone: value });
|
1518
|
+
const includesAny = (value) => ({ $includesAny: value });
|
1519
|
+
|
1520
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
1521
|
+
if (!member.has(obj))
|
1522
|
+
throw TypeError("Cannot " + msg);
|
1523
|
+
};
|
1524
|
+
var __privateGet$1 = (obj, member, getter) => {
|
1525
|
+
__accessCheck$2(obj, member, "read from private field");
|
1526
|
+
return getter ? getter.call(obj) : member.get(obj);
|
1527
|
+
};
|
1528
|
+
var __privateAdd$2 = (obj, member, value) => {
|
1529
|
+
if (member.has(obj))
|
1530
|
+
throw TypeError("Cannot add the same private member more than once");
|
1531
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1532
|
+
};
|
1533
|
+
var _tables;
|
1534
|
+
class SchemaPlugin extends XataPlugin {
|
1535
|
+
constructor(links, tableNames) {
|
1536
|
+
super();
|
1537
|
+
this.links = links;
|
1538
|
+
this.tableNames = tableNames;
|
1539
|
+
__privateAdd$2(this, _tables, {});
|
1540
|
+
}
|
1541
|
+
build(pluginOptions) {
|
1542
|
+
const links = this.links;
|
1543
|
+
const db = new Proxy({}, {
|
1544
|
+
get: (_target, table) => {
|
1545
|
+
if (!isString(table))
|
1546
|
+
throw new Error("Invalid table name");
|
1547
|
+
if (!__privateGet$1(this, _tables)[table]) {
|
1548
|
+
__privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
|
1549
|
+
}
|
1550
|
+
return __privateGet$1(this, _tables)[table];
|
1551
|
+
}
|
1552
|
+
});
|
1553
|
+
for (const table of this.tableNames ?? []) {
|
1554
|
+
db[table] = new RestRepository({ db, pluginOptions, table, links });
|
1555
|
+
}
|
1556
|
+
return db;
|
1557
|
+
}
|
1558
|
+
}
|
1559
|
+
_tables = new WeakMap();
|
1560
|
+
|
1561
|
+
var __accessCheck$1 = (obj, member, msg) => {
|
1562
|
+
if (!member.has(obj))
|
1563
|
+
throw TypeError("Cannot " + msg);
|
1564
|
+
};
|
1565
|
+
var __privateAdd$1 = (obj, member, value) => {
|
1566
|
+
if (member.has(obj))
|
1567
|
+
throw TypeError("Cannot add the same private member more than once");
|
1568
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1569
|
+
};
|
1570
|
+
var __privateMethod$1 = (obj, member, method) => {
|
1571
|
+
__accessCheck$1(obj, member, "access private method");
|
1572
|
+
return method;
|
1573
|
+
};
|
1574
|
+
var _search, search_fn;
|
1575
|
+
class SearchPlugin extends XataPlugin {
|
1576
|
+
constructor(db, links) {
|
1577
|
+
super();
|
1578
|
+
this.db = db;
|
1579
|
+
this.links = links;
|
1580
|
+
__privateAdd$1(this, _search);
|
1581
|
+
}
|
1582
|
+
build({ getFetchProps }) {
|
1583
|
+
return {
|
1584
|
+
all: async (query, options = {}) => {
|
1585
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1586
|
+
return records.map((record) => {
|
1587
|
+
const { table = "orphan" } = record.xata;
|
1588
|
+
return { table, record: initObject(this.db, this.links, table, record) };
|
1589
|
+
});
|
1590
|
+
},
|
1591
|
+
byTable: async (query, options = {}) => {
|
1592
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1593
|
+
return records.reduce((acc, record) => {
|
1594
|
+
const { table = "orphan" } = record.xata;
|
1595
|
+
const items = acc[table] ?? [];
|
1596
|
+
const item = initObject(this.db, this.links, table, record);
|
1597
|
+
return { ...acc, [table]: [...items, item] };
|
1598
|
+
}, {});
|
1599
|
+
}
|
1600
|
+
};
|
1601
|
+
}
|
1602
|
+
}
|
1603
|
+
_search = new WeakSet();
|
1604
|
+
search_fn = async function(query, options, getFetchProps) {
|
1605
|
+
const fetchProps = await getFetchProps();
|
1606
|
+
const { tables, fuzziness } = options ?? {};
|
1607
|
+
const { records } = await searchBranch({
|
1608
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1609
|
+
body: { tables, query, fuzziness },
|
1610
|
+
...fetchProps
|
1611
|
+
});
|
1612
|
+
return records;
|
1613
|
+
};
|
1614
|
+
|
1615
|
+
const isBranchStrategyBuilder = (strategy) => {
|
1616
|
+
return typeof strategy === "function";
|
1617
|
+
};
|
1618
|
+
|
1619
|
+
const envBranchNames = [
|
1620
|
+
"XATA_BRANCH",
|
1621
|
+
"VERCEL_GIT_COMMIT_REF",
|
1622
|
+
"CF_PAGES_BRANCH",
|
1623
|
+
"BRANCH"
|
1624
|
+
];
|
1625
|
+
const defaultBranch = "main";
|
1626
|
+
async function getCurrentBranchName(options) {
|
1627
|
+
const env = await getBranchByEnvVariable();
|
1628
|
+
if (env)
|
1629
|
+
return env;
|
1630
|
+
const branch = await getGitBranch();
|
1631
|
+
if (!branch)
|
1632
|
+
return defaultBranch;
|
1633
|
+
const details = await getDatabaseBranch(branch, options);
|
1634
|
+
if (details)
|
1635
|
+
return branch;
|
1636
|
+
return defaultBranch;
|
1637
|
+
}
|
1638
|
+
async function getCurrentBranchDetails(options) {
|
1639
|
+
const env = await getBranchByEnvVariable();
|
1640
|
+
if (env)
|
1641
|
+
return getDatabaseBranch(env, options);
|
1642
|
+
const branch = await getGitBranch();
|
1643
|
+
if (!branch)
|
1644
|
+
return getDatabaseBranch(defaultBranch, options);
|
1645
|
+
const details = await getDatabaseBranch(branch, options);
|
1646
|
+
if (details)
|
1647
|
+
return details;
|
1648
|
+
return getDatabaseBranch(defaultBranch, options);
|
1649
|
+
}
|
1650
|
+
async function getDatabaseBranch(branch, options) {
|
1651
|
+
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1652
|
+
const apiKey = options?.apiKey || getAPIKey();
|
1653
|
+
if (!databaseURL)
|
1654
|
+
throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
|
1655
|
+
if (!apiKey)
|
1656
|
+
throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
|
1657
|
+
const [protocol, , host, , database] = databaseURL.split("/");
|
1658
|
+
const [workspace] = host.split(".");
|
1659
|
+
const dbBranchName = `${database}:${branch}`;
|
1660
|
+
try {
|
1661
|
+
return await getBranchDetails({
|
1662
|
+
apiKey,
|
1663
|
+
apiUrl: databaseURL,
|
1664
|
+
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1665
|
+
workspacesApiUrl: `${protocol}//${host}`,
|
1666
|
+
pathParams: {
|
1667
|
+
dbBranchName,
|
1668
|
+
workspace
|
1669
|
+
}
|
1670
|
+
});
|
1671
|
+
} catch (err) {
|
1672
|
+
if (isObject(err) && err.status === 404)
|
1673
|
+
return null;
|
1674
|
+
throw err;
|
1675
|
+
}
|
1676
|
+
}
|
1677
|
+
function getBranchByEnvVariable() {
|
1678
|
+
for (const name of envBranchNames) {
|
1679
|
+
const value = getEnvVariable(name);
|
1680
|
+
if (value) {
|
1681
|
+
return value;
|
1682
|
+
}
|
1683
|
+
}
|
1684
|
+
try {
|
1685
|
+
return XATA_BRANCH;
|
1686
|
+
} catch (err) {
|
1687
|
+
}
|
1688
|
+
}
|
1689
|
+
function getDatabaseURL() {
|
1690
|
+
try {
|
1691
|
+
return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
|
1692
|
+
} catch (err) {
|
1693
|
+
return void 0;
|
1694
|
+
}
|
1695
|
+
}
|
1696
|
+
|
1697
|
+
var __accessCheck = (obj, member, msg) => {
|
1698
|
+
if (!member.has(obj))
|
1699
|
+
throw TypeError("Cannot " + msg);
|
1700
|
+
};
|
1701
|
+
var __privateGet = (obj, member, getter) => {
|
1702
|
+
__accessCheck(obj, member, "read from private field");
|
1703
|
+
return getter ? getter.call(obj) : member.get(obj);
|
1704
|
+
};
|
1705
|
+
var __privateAdd = (obj, member, value) => {
|
1706
|
+
if (member.has(obj))
|
1707
|
+
throw TypeError("Cannot add the same private member more than once");
|
1708
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1709
|
+
};
|
1710
|
+
var __privateSet = (obj, member, value, setter) => {
|
1711
|
+
__accessCheck(obj, member, "write to private field");
|
1712
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1713
|
+
return value;
|
1714
|
+
};
|
1715
|
+
var __privateMethod = (obj, member, method) => {
|
1716
|
+
__accessCheck(obj, member, "access private method");
|
1717
|
+
return method;
|
1718
|
+
};
|
1719
|
+
const buildClient = (plugins) => {
|
1720
|
+
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1721
|
+
return _a = class {
|
1722
|
+
constructor(options = {}, links, tables) {
|
1723
|
+
__privateAdd(this, _parseOptions);
|
1724
|
+
__privateAdd(this, _getFetchProps);
|
1725
|
+
__privateAdd(this, _evaluateBranch);
|
1726
|
+
__privateAdd(this, _branch, void 0);
|
1727
|
+
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
1728
|
+
const pluginOptions = {
|
1729
|
+
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1730
|
+
cache: safeOptions.cache
|
1731
|
+
};
|
1732
|
+
const db = new SchemaPlugin(links, tables).build(pluginOptions);
|
1733
|
+
const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
|
1734
|
+
this.db = db;
|
1735
|
+
this.search = search;
|
1736
|
+
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
1737
|
+
if (!namespace)
|
1738
|
+
continue;
|
1739
|
+
const result = namespace.build(pluginOptions);
|
1740
|
+
if (result instanceof Promise) {
|
1741
|
+
void result.then((namespace2) => {
|
1742
|
+
this[key] = namespace2;
|
1743
|
+
});
|
1744
|
+
} else {
|
1745
|
+
this[key] = result;
|
1746
|
+
}
|
1747
|
+
}
|
1748
|
+
}
|
1749
|
+
}, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1750
|
+
const fetch = getFetchImplementation(options?.fetch);
|
1751
|
+
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1752
|
+
const apiKey = options?.apiKey || getAPIKey();
|
1753
|
+
const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
|
1754
|
+
const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1755
|
+
if (!databaseURL || !apiKey) {
|
1756
|
+
throw new Error("Options databaseURL and apiKey are required");
|
1757
|
+
}
|
1758
|
+
return { fetch, databaseURL, apiKey, branch, cache };
|
1759
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
1760
|
+
fetch,
|
1761
|
+
apiKey,
|
1762
|
+
databaseURL,
|
1763
|
+
branch
|
1764
|
+
}) {
|
1765
|
+
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1766
|
+
if (!branchValue)
|
1767
|
+
throw new Error("Unable to resolve branch value");
|
1768
|
+
return {
|
1769
|
+
fetchImpl: fetch,
|
1770
|
+
apiKey,
|
1771
|
+
apiUrl: "",
|
1772
|
+
workspacesApiUrl: (path, params) => {
|
1773
|
+
const hasBranch = params.dbBranchName ?? params.branch;
|
1774
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
1775
|
+
return databaseURL + newPath;
|
1776
|
+
}
|
1777
|
+
};
|
1778
|
+
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
1779
|
+
if (__privateGet(this, _branch))
|
1780
|
+
return __privateGet(this, _branch);
|
1781
|
+
if (!param)
|
1782
|
+
return void 0;
|
1783
|
+
const strategies = Array.isArray(param) ? [...param] : [param];
|
1784
|
+
const evaluateBranch = async (strategy) => {
|
1785
|
+
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
1786
|
+
};
|
1787
|
+
for await (const strategy of strategies) {
|
1788
|
+
const branch = await evaluateBranch(strategy);
|
1789
|
+
if (branch) {
|
1790
|
+
__privateSet(this, _branch, branch);
|
1791
|
+
return branch;
|
1792
|
+
}
|
1793
|
+
}
|
1794
|
+
}, _a;
|
1795
|
+
};
|
1796
|
+
class BaseClient extends buildClient() {
|
1797
|
+
}
|
1798
|
+
|
1799
|
+
class XataError extends Error {
|
1800
|
+
constructor(message, status) {
|
1801
|
+
super(message);
|
1802
|
+
this.status = status;
|
1803
|
+
}
|
1804
|
+
}
|
1805
|
+
|
1806
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeWorkspaceMember, resendWorkspaceMemberInvite, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
1807
|
+
//# sourceMappingURL=index.mjs.map
|