@xata.io/client 0.0.0-alpha.vfbbe3c7 → 0.0.0-alpha.vfbe46c7
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 +100 -0
- package/README.md +27 -25
- package/Usage.md +29 -6
- package/dist/index.cjs +1018 -355
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2521 -291
- package/dist/index.mjs +986 -356
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
@@ -20,6 +20,28 @@ function _interopNamespace(e) {
|
|
20
20
|
return Object.freeze(n);
|
21
21
|
}
|
22
22
|
|
23
|
+
const defaultTrace = async (_name, fn, _options) => {
|
24
|
+
return await fn({
|
25
|
+
setAttributes: () => {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
});
|
29
|
+
};
|
30
|
+
const TraceAttributes = {
|
31
|
+
KIND: "xata.trace.kind",
|
32
|
+
VERSION: "xata.sdk.version",
|
33
|
+
TABLE: "xata.table",
|
34
|
+
HTTP_REQUEST_ID: "http.request_id",
|
35
|
+
HTTP_STATUS_CODE: "http.status_code",
|
36
|
+
HTTP_HOST: "http.host",
|
37
|
+
HTTP_SCHEME: "http.scheme",
|
38
|
+
HTTP_USER_AGENT: "http.user_agent",
|
39
|
+
HTTP_METHOD: "http.method",
|
40
|
+
HTTP_URL: "http.url",
|
41
|
+
HTTP_ROUTE: "http.route",
|
42
|
+
HTTP_TARGET: "http.target"
|
43
|
+
};
|
44
|
+
|
23
45
|
function notEmpty(value) {
|
24
46
|
return value !== null && value !== void 0;
|
25
47
|
}
|
@@ -143,12 +165,14 @@ function getFetchImplementation(userFetch) {
|
|
143
165
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
144
166
|
const fetchImpl = userFetch ?? globalFetch;
|
145
167
|
if (!fetchImpl) {
|
146
|
-
throw new Error(
|
168
|
+
throw new Error(
|
169
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
170
|
+
);
|
147
171
|
}
|
148
172
|
return fetchImpl;
|
149
173
|
}
|
150
174
|
|
151
|
-
const VERSION = "0.0.0-alpha.
|
175
|
+
const VERSION = "0.0.0-alpha.vfbe46c7";
|
152
176
|
|
153
177
|
class ErrorWithCause extends Error {
|
154
178
|
constructor(message, options) {
|
@@ -199,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
199
223
|
}, {});
|
200
224
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
201
225
|
const queryString = query.length > 0 ? `?${query}` : "";
|
202
|
-
|
226
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
227
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
228
|
+
}, {});
|
229
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
203
230
|
};
|
204
231
|
function buildBaseUrl({
|
205
232
|
path,
|
@@ -207,10 +234,10 @@ function buildBaseUrl({
|
|
207
234
|
apiUrl,
|
208
235
|
pathParams
|
209
236
|
}) {
|
210
|
-
if (
|
237
|
+
if (pathParams?.workspace === void 0)
|
211
238
|
return `${apiUrl}${path}`;
|
212
239
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
213
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
240
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
214
241
|
}
|
215
242
|
function hostHeader(url) {
|
216
243
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -227,243 +254,362 @@ async function fetch$1({
|
|
227
254
|
fetchImpl,
|
228
255
|
apiKey,
|
229
256
|
apiUrl,
|
230
|
-
workspacesApiUrl
|
257
|
+
workspacesApiUrl,
|
258
|
+
trace,
|
259
|
+
signal
|
231
260
|
}) {
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
261
|
+
return trace(
|
262
|
+
`${method.toUpperCase()} ${path}`,
|
263
|
+
async ({ setAttributes }) => {
|
264
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
265
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
266
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
267
|
+
setAttributes({
|
268
|
+
[TraceAttributes.HTTP_URL]: url,
|
269
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
270
|
+
});
|
271
|
+
const response = await fetchImpl(url, {
|
272
|
+
method: method.toUpperCase(),
|
273
|
+
body: body ? JSON.stringify(body) : void 0,
|
274
|
+
headers: {
|
275
|
+
"Content-Type": "application/json",
|
276
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
277
|
+
...headers,
|
278
|
+
...hostHeader(fullUrl),
|
279
|
+
Authorization: `Bearer ${apiKey}`
|
280
|
+
},
|
281
|
+
signal
|
282
|
+
});
|
283
|
+
if (response.status === 204) {
|
284
|
+
return {};
|
285
|
+
}
|
286
|
+
const { host, protocol } = parseUrl(response.url);
|
287
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
288
|
+
setAttributes({
|
289
|
+
[TraceAttributes.KIND]: "http",
|
290
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
291
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
292
|
+
[TraceAttributes.HTTP_HOST]: host,
|
293
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
294
|
+
});
|
295
|
+
try {
|
296
|
+
const jsonResponse = await response.json();
|
297
|
+
if (response.ok) {
|
298
|
+
return jsonResponse;
|
299
|
+
}
|
300
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
301
|
+
} catch (error) {
|
302
|
+
throw new FetcherError(response.status, error, requestId);
|
303
|
+
}
|
304
|
+
},
|
305
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
306
|
+
);
|
307
|
+
}
|
308
|
+
function parseUrl(url) {
|
250
309
|
try {
|
251
|
-
const
|
252
|
-
|
253
|
-
return jsonResponse;
|
254
|
-
}
|
255
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
310
|
+
const { host, protocol } = new URL(url);
|
311
|
+
return { host, protocol };
|
256
312
|
} catch (error) {
|
257
|
-
|
313
|
+
return {};
|
258
314
|
}
|
259
315
|
}
|
260
316
|
|
261
|
-
const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
|
262
|
-
const updateUser = (variables) => fetch$1({
|
263
|
-
|
264
|
-
|
317
|
+
const getUser = (variables, signal) => fetch$1({ url: "/user", method: "get", ...variables, signal });
|
318
|
+
const updateUser = (variables, signal) => fetch$1({
|
319
|
+
url: "/user",
|
320
|
+
method: "put",
|
321
|
+
...variables,
|
322
|
+
signal
|
323
|
+
});
|
324
|
+
const deleteUser = (variables, signal) => fetch$1({ url: "/user", method: "delete", ...variables, signal });
|
325
|
+
const getUserAPIKeys = (variables, signal) => fetch$1({
|
265
326
|
url: "/user/keys",
|
266
327
|
method: "get",
|
267
|
-
...variables
|
328
|
+
...variables,
|
329
|
+
signal
|
268
330
|
});
|
269
|
-
const createUserAPIKey = (variables) => fetch$1({
|
331
|
+
const createUserAPIKey = (variables, signal) => fetch$1({
|
270
332
|
url: "/user/keys/{keyName}",
|
271
333
|
method: "post",
|
272
|
-
...variables
|
334
|
+
...variables,
|
335
|
+
signal
|
273
336
|
});
|
274
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
337
|
+
const deleteUserAPIKey = (variables, signal) => fetch$1({
|
275
338
|
url: "/user/keys/{keyName}",
|
276
339
|
method: "delete",
|
277
|
-
...variables
|
340
|
+
...variables,
|
341
|
+
signal
|
278
342
|
});
|
279
|
-
const createWorkspace = (variables) => fetch$1({
|
343
|
+
const createWorkspace = (variables, signal) => fetch$1({
|
280
344
|
url: "/workspaces",
|
281
345
|
method: "post",
|
282
|
-
...variables
|
346
|
+
...variables,
|
347
|
+
signal
|
283
348
|
});
|
284
|
-
const getWorkspacesList = (variables) => fetch$1({
|
349
|
+
const getWorkspacesList = (variables, signal) => fetch$1({
|
285
350
|
url: "/workspaces",
|
286
351
|
method: "get",
|
287
|
-
...variables
|
352
|
+
...variables,
|
353
|
+
signal
|
288
354
|
});
|
289
|
-
const getWorkspace = (variables) => fetch$1({
|
355
|
+
const getWorkspace = (variables, signal) => fetch$1({
|
290
356
|
url: "/workspaces/{workspaceId}",
|
291
357
|
method: "get",
|
292
|
-
...variables
|
358
|
+
...variables,
|
359
|
+
signal
|
293
360
|
});
|
294
|
-
const updateWorkspace = (variables) => fetch$1({
|
361
|
+
const updateWorkspace = (variables, signal) => fetch$1({
|
295
362
|
url: "/workspaces/{workspaceId}",
|
296
363
|
method: "put",
|
297
|
-
...variables
|
364
|
+
...variables,
|
365
|
+
signal
|
298
366
|
});
|
299
|
-
const deleteWorkspace = (variables) => fetch$1({
|
367
|
+
const deleteWorkspace = (variables, signal) => fetch$1({
|
300
368
|
url: "/workspaces/{workspaceId}",
|
301
369
|
method: "delete",
|
302
|
-
...variables
|
370
|
+
...variables,
|
371
|
+
signal
|
303
372
|
});
|
304
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
373
|
+
const getWorkspaceMembersList = (variables, signal) => fetch$1({
|
305
374
|
url: "/workspaces/{workspaceId}/members",
|
306
375
|
method: "get",
|
307
|
-
...variables
|
376
|
+
...variables,
|
377
|
+
signal
|
308
378
|
});
|
309
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
310
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
379
|
+
const updateWorkspaceMemberRole = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
380
|
+
const removeWorkspaceMember = (variables, signal) => fetch$1({
|
311
381
|
url: "/workspaces/{workspaceId}/members/{userId}",
|
312
382
|
method: "delete",
|
313
|
-
...variables
|
383
|
+
...variables,
|
384
|
+
signal
|
314
385
|
});
|
315
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
316
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
317
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
386
|
+
const inviteWorkspaceMember = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
387
|
+
const updateWorkspaceMemberInvite = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
388
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
318
389
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
319
390
|
method: "delete",
|
320
|
-
...variables
|
391
|
+
...variables,
|
392
|
+
signal
|
321
393
|
});
|
322
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
394
|
+
const resendWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
323
395
|
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
324
396
|
method: "post",
|
325
|
-
...variables
|
397
|
+
...variables,
|
398
|
+
signal
|
326
399
|
});
|
327
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
400
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
328
401
|
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
329
402
|
method: "post",
|
330
|
-
...variables
|
403
|
+
...variables,
|
404
|
+
signal
|
331
405
|
});
|
332
|
-
const getDatabaseList = (variables) => fetch$1({
|
406
|
+
const getDatabaseList = (variables, signal) => fetch$1({
|
333
407
|
url: "/dbs",
|
334
408
|
method: "get",
|
335
|
-
...variables
|
409
|
+
...variables,
|
410
|
+
signal
|
336
411
|
});
|
337
|
-
const getBranchList = (variables) => fetch$1({
|
412
|
+
const getBranchList = (variables, signal) => fetch$1({
|
338
413
|
url: "/dbs/{dbName}",
|
339
414
|
method: "get",
|
340
|
-
...variables
|
415
|
+
...variables,
|
416
|
+
signal
|
341
417
|
});
|
342
|
-
const createDatabase = (variables) => fetch$1({
|
418
|
+
const createDatabase = (variables, signal) => fetch$1({
|
343
419
|
url: "/dbs/{dbName}",
|
344
420
|
method: "put",
|
345
|
-
...variables
|
421
|
+
...variables,
|
422
|
+
signal
|
346
423
|
});
|
347
|
-
const deleteDatabase = (variables) => fetch$1({
|
424
|
+
const deleteDatabase = (variables, signal) => fetch$1({
|
348
425
|
url: "/dbs/{dbName}",
|
349
426
|
method: "delete",
|
350
|
-
...variables
|
427
|
+
...variables,
|
428
|
+
signal
|
351
429
|
});
|
352
|
-
const
|
353
|
-
|
354
|
-
|
355
|
-
|
430
|
+
const getDatabaseMetadata = (variables, signal) => fetch$1({
|
431
|
+
url: "/dbs/{dbName}/metadata",
|
432
|
+
method: "get",
|
433
|
+
...variables,
|
434
|
+
signal
|
435
|
+
});
|
436
|
+
const updateDatabaseMetadata = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
437
|
+
const getGitBranchesMapping = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
438
|
+
const addGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
439
|
+
const removeGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
440
|
+
const resolveBranch = (variables, signal) => fetch$1({
|
356
441
|
url: "/dbs/{dbName}/resolveBranch",
|
357
442
|
method: "get",
|
358
|
-
...variables
|
443
|
+
...variables,
|
444
|
+
signal
|
359
445
|
});
|
360
|
-
const
|
446
|
+
const queryMigrationRequests = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
447
|
+
const createMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
448
|
+
const getMigrationRequest = (variables, signal) => fetch$1({
|
449
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
450
|
+
method: "get",
|
451
|
+
...variables,
|
452
|
+
signal
|
453
|
+
});
|
454
|
+
const updateMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
455
|
+
const listMigrationRequestsCommits = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
456
|
+
const compareMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
457
|
+
const getMigrationRequestIsMerged = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
458
|
+
const mergeMigrationRequest = (variables, signal) => fetch$1({
|
459
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
460
|
+
method: "post",
|
461
|
+
...variables,
|
462
|
+
signal
|
463
|
+
});
|
464
|
+
const getBranchDetails = (variables, signal) => fetch$1({
|
361
465
|
url: "/db/{dbBranchName}",
|
362
466
|
method: "get",
|
363
|
-
...variables
|
467
|
+
...variables,
|
468
|
+
signal
|
364
469
|
});
|
365
|
-
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
366
|
-
const deleteBranch = (variables) => fetch$1({
|
470
|
+
const createBranch = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
471
|
+
const deleteBranch = (variables, signal) => fetch$1({
|
367
472
|
url: "/db/{dbBranchName}",
|
368
473
|
method: "delete",
|
369
|
-
...variables
|
474
|
+
...variables,
|
475
|
+
signal
|
370
476
|
});
|
371
|
-
const updateBranchMetadata = (variables) => fetch$1({
|
477
|
+
const updateBranchMetadata = (variables, signal) => fetch$1({
|
372
478
|
url: "/db/{dbBranchName}/metadata",
|
373
479
|
method: "put",
|
374
|
-
...variables
|
480
|
+
...variables,
|
481
|
+
signal
|
375
482
|
});
|
376
|
-
const getBranchMetadata = (variables) => fetch$1({
|
483
|
+
const getBranchMetadata = (variables, signal) => fetch$1({
|
377
484
|
url: "/db/{dbBranchName}/metadata",
|
378
485
|
method: "get",
|
379
|
-
...variables
|
486
|
+
...variables,
|
487
|
+
signal
|
380
488
|
});
|
381
|
-
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
382
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
383
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
384
|
-
const
|
489
|
+
const getBranchMigrationHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
490
|
+
const executeBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
491
|
+
const getBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
492
|
+
const compareBranchWithUserSchema = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
493
|
+
const compareBranchSchemas = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
494
|
+
const updateBranchSchema = (variables, signal) => fetch$1({
|
495
|
+
url: "/db/{dbBranchName}/schema/update",
|
496
|
+
method: "post",
|
497
|
+
...variables,
|
498
|
+
signal
|
499
|
+
});
|
500
|
+
const previewBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
501
|
+
const applyBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
502
|
+
const getBranchSchemaHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
503
|
+
const getBranchStats = (variables, signal) => fetch$1({
|
385
504
|
url: "/db/{dbBranchName}/stats",
|
386
505
|
method: "get",
|
387
|
-
...variables
|
506
|
+
...variables,
|
507
|
+
signal
|
388
508
|
});
|
389
|
-
const createTable = (variables) => fetch$1({
|
509
|
+
const createTable = (variables, signal) => fetch$1({
|
390
510
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
391
511
|
method: "put",
|
392
|
-
...variables
|
512
|
+
...variables,
|
513
|
+
signal
|
393
514
|
});
|
394
|
-
const deleteTable = (variables) => fetch$1({
|
515
|
+
const deleteTable = (variables, signal) => fetch$1({
|
395
516
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
396
517
|
method: "delete",
|
397
|
-
...variables
|
518
|
+
...variables,
|
519
|
+
signal
|
398
520
|
});
|
399
|
-
const updateTable = (variables) => fetch$1({
|
521
|
+
const updateTable = (variables, signal) => fetch$1({
|
400
522
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
401
523
|
method: "patch",
|
402
|
-
...variables
|
524
|
+
...variables,
|
525
|
+
signal
|
403
526
|
});
|
404
|
-
const getTableSchema = (variables) => fetch$1({
|
527
|
+
const getTableSchema = (variables, signal) => fetch$1({
|
405
528
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
406
529
|
method: "get",
|
407
|
-
...variables
|
530
|
+
...variables,
|
531
|
+
signal
|
408
532
|
});
|
409
|
-
const setTableSchema = (variables) => fetch$1({
|
533
|
+
const setTableSchema = (variables, signal) => fetch$1({
|
410
534
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
411
535
|
method: "put",
|
412
|
-
...variables
|
536
|
+
...variables,
|
537
|
+
signal
|
413
538
|
});
|
414
|
-
const getTableColumns = (variables) => fetch$1({
|
539
|
+
const getTableColumns = (variables, signal) => fetch$1({
|
415
540
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
416
541
|
method: "get",
|
417
|
-
...variables
|
542
|
+
...variables,
|
543
|
+
signal
|
418
544
|
});
|
419
|
-
const addTableColumn = (variables) => fetch$1({
|
545
|
+
const addTableColumn = (variables, signal) => fetch$1({
|
420
546
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
421
547
|
method: "post",
|
422
|
-
...variables
|
548
|
+
...variables,
|
549
|
+
signal
|
423
550
|
});
|
424
|
-
const getColumn = (variables) => fetch$1({
|
551
|
+
const getColumn = (variables, signal) => fetch$1({
|
425
552
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
426
553
|
method: "get",
|
427
|
-
...variables
|
554
|
+
...variables,
|
555
|
+
signal
|
428
556
|
});
|
429
|
-
const deleteColumn = (variables) => fetch$1({
|
557
|
+
const deleteColumn = (variables, signal) => fetch$1({
|
430
558
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
431
559
|
method: "delete",
|
432
|
-
...variables
|
560
|
+
...variables,
|
561
|
+
signal
|
433
562
|
});
|
434
|
-
const updateColumn = (variables) => fetch$1({
|
563
|
+
const updateColumn = (variables, signal) => fetch$1({
|
435
564
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
436
565
|
method: "patch",
|
437
|
-
...variables
|
566
|
+
...variables,
|
567
|
+
signal
|
438
568
|
});
|
439
|
-
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
440
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
441
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
442
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
443
|
-
const deleteRecord = (variables) => fetch$1({
|
569
|
+
const insertRecord = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
570
|
+
const insertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
571
|
+
const updateRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
572
|
+
const upsertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
573
|
+
const deleteRecord = (variables, signal) => fetch$1({
|
444
574
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
445
575
|
method: "delete",
|
446
|
-
...variables
|
576
|
+
...variables,
|
577
|
+
signal
|
447
578
|
});
|
448
|
-
const getRecord = (variables) => fetch$1({
|
579
|
+
const getRecord = (variables, signal) => fetch$1({
|
449
580
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
450
581
|
method: "get",
|
451
|
-
...variables
|
582
|
+
...variables,
|
583
|
+
signal
|
452
584
|
});
|
453
|
-
const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
|
454
|
-
const queryTable = (variables) => fetch$1({
|
585
|
+
const bulkInsertTableRecords = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
586
|
+
const queryTable = (variables, signal) => fetch$1({
|
455
587
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
456
588
|
method: "post",
|
457
|
-
...variables
|
589
|
+
...variables,
|
590
|
+
signal
|
458
591
|
});
|
459
|
-
const searchTable = (variables) => fetch$1({
|
592
|
+
const searchTable = (variables, signal) => fetch$1({
|
460
593
|
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
461
594
|
method: "post",
|
462
|
-
...variables
|
595
|
+
...variables,
|
596
|
+
signal
|
463
597
|
});
|
464
|
-
const searchBranch = (variables) => fetch$1({
|
598
|
+
const searchBranch = (variables, signal) => fetch$1({
|
465
599
|
url: "/db/{dbBranchName}/search",
|
466
600
|
method: "post",
|
601
|
+
...variables,
|
602
|
+
signal
|
603
|
+
});
|
604
|
+
const summarizeTable = (variables, signal) => fetch$1({
|
605
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
606
|
+
method: "post",
|
607
|
+
...variables,
|
608
|
+
signal
|
609
|
+
});
|
610
|
+
const aggregateTable = (variables) => fetch$1({
|
611
|
+
url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
|
612
|
+
method: "post",
|
467
613
|
...variables
|
468
614
|
});
|
469
615
|
const operationsByTag = {
|
@@ -487,6 +633,8 @@ const operationsByTag = {
|
|
487
633
|
getDatabaseList,
|
488
634
|
createDatabase,
|
489
635
|
deleteDatabase,
|
636
|
+
getDatabaseMetadata,
|
637
|
+
updateDatabaseMetadata,
|
490
638
|
getGitBranchesMapping,
|
491
639
|
addGitBranchesEntry,
|
492
640
|
removeGitBranchesEntry,
|
@@ -499,10 +647,28 @@ const operationsByTag = {
|
|
499
647
|
deleteBranch,
|
500
648
|
updateBranchMetadata,
|
501
649
|
getBranchMetadata,
|
650
|
+
getBranchStats
|
651
|
+
},
|
652
|
+
migrationRequests: {
|
653
|
+
queryMigrationRequests,
|
654
|
+
createMigrationRequest,
|
655
|
+
getMigrationRequest,
|
656
|
+
updateMigrationRequest,
|
657
|
+
listMigrationRequestsCommits,
|
658
|
+
compareMigrationRequest,
|
659
|
+
getMigrationRequestIsMerged,
|
660
|
+
mergeMigrationRequest
|
661
|
+
},
|
662
|
+
branchSchema: {
|
502
663
|
getBranchMigrationHistory,
|
503
664
|
executeBranchMigrationPlan,
|
504
665
|
getBranchMigrationPlan,
|
505
|
-
|
666
|
+
compareBranchWithUserSchema,
|
667
|
+
compareBranchSchemas,
|
668
|
+
updateBranchSchema,
|
669
|
+
previewBranchSchemaEdit,
|
670
|
+
applyBranchSchemaEdit,
|
671
|
+
getBranchSchemaHistory
|
506
672
|
},
|
507
673
|
table: {
|
508
674
|
createTable,
|
@@ -526,14 +692,16 @@ const operationsByTag = {
|
|
526
692
|
bulkInsertTableRecords,
|
527
693
|
queryTable,
|
528
694
|
searchTable,
|
529
|
-
searchBranch
|
695
|
+
searchBranch,
|
696
|
+
summarizeTable,
|
697
|
+
aggregateTable
|
530
698
|
}
|
531
699
|
};
|
532
700
|
|
533
701
|
function getHostUrl(provider, type) {
|
534
|
-
if (
|
702
|
+
if (isHostProviderAlias(provider)) {
|
535
703
|
return providers[provider][type];
|
536
|
-
} else if (
|
704
|
+
} else if (isHostProviderBuilder(provider)) {
|
537
705
|
return provider[type];
|
538
706
|
}
|
539
707
|
throw new Error("Invalid API provider");
|
@@ -548,12 +716,21 @@ const providers = {
|
|
548
716
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
549
717
|
}
|
550
718
|
};
|
551
|
-
function
|
719
|
+
function isHostProviderAlias(alias) {
|
552
720
|
return isString(alias) && Object.keys(providers).includes(alias);
|
553
721
|
}
|
554
|
-
function
|
722
|
+
function isHostProviderBuilder(builder) {
|
555
723
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
556
724
|
}
|
725
|
+
function parseProviderString(provider = "production") {
|
726
|
+
if (isHostProviderAlias(provider)) {
|
727
|
+
return provider;
|
728
|
+
}
|
729
|
+
const [main, workspaces] = provider.split(",");
|
730
|
+
if (!main || !workspaces)
|
731
|
+
return null;
|
732
|
+
return { main, workspaces };
|
733
|
+
}
|
557
734
|
|
558
735
|
var __accessCheck$7 = (obj, member, msg) => {
|
559
736
|
if (!member.has(obj))
|
@@ -579,7 +756,8 @@ class XataApiClient {
|
|
579
756
|
__privateAdd$7(this, _extraProps, void 0);
|
580
757
|
__privateAdd$7(this, _namespaces, {});
|
581
758
|
const provider = options.host ?? "production";
|
582
|
-
const apiKey = options
|
759
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
760
|
+
const trace = options.trace ?? defaultTrace;
|
583
761
|
if (!apiKey) {
|
584
762
|
throw new Error("Could not resolve a valid apiKey");
|
585
763
|
}
|
@@ -587,7 +765,8 @@ class XataApiClient {
|
|
587
765
|
apiUrl: getHostUrl(provider, "main"),
|
588
766
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
589
767
|
fetchImpl: getFetchImplementation(options.fetch),
|
590
|
-
apiKey
|
768
|
+
apiKey,
|
769
|
+
trace
|
591
770
|
});
|
592
771
|
}
|
593
772
|
get user() {
|
@@ -620,6 +799,16 @@ class XataApiClient {
|
|
620
799
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
621
800
|
return __privateGet$7(this, _namespaces).records;
|
622
801
|
}
|
802
|
+
get migrationRequests() {
|
803
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
804
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
805
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
806
|
+
}
|
807
|
+
get branchSchema() {
|
808
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
809
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
810
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
811
|
+
}
|
623
812
|
}
|
624
813
|
_extraProps = new WeakMap();
|
625
814
|
_namespaces = new WeakMap();
|
@@ -759,6 +948,19 @@ class DatabaseApi {
|
|
759
948
|
...this.extraProps
|
760
949
|
});
|
761
950
|
}
|
951
|
+
getDatabaseMetadata(workspace, dbName) {
|
952
|
+
return operationsByTag.database.getDatabaseMetadata({
|
953
|
+
pathParams: { workspace, dbName },
|
954
|
+
...this.extraProps
|
955
|
+
});
|
956
|
+
}
|
957
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
958
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
959
|
+
pathParams: { workspace, dbName },
|
960
|
+
body: options,
|
961
|
+
...this.extraProps
|
962
|
+
});
|
963
|
+
}
|
762
964
|
getGitBranchesMapping(workspace, dbName) {
|
763
965
|
return operationsByTag.database.getGitBranchesMapping({
|
764
966
|
pathParams: { workspace, dbName },
|
@@ -830,27 +1032,6 @@ class BranchApi {
|
|
830
1032
|
...this.extraProps
|
831
1033
|
});
|
832
1034
|
}
|
833
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
834
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
835
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
836
|
-
body: options,
|
837
|
-
...this.extraProps
|
838
|
-
});
|
839
|
-
}
|
840
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
841
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
842
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
843
|
-
body: migrationPlan,
|
844
|
-
...this.extraProps
|
845
|
-
});
|
846
|
-
}
|
847
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
848
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
849
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
850
|
-
body: schema,
|
851
|
-
...this.extraProps
|
852
|
-
});
|
853
|
-
}
|
854
1035
|
getBranchStats(workspace, database, branch) {
|
855
1036
|
return operationsByTag.branch.getBranchStats({
|
856
1037
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -1006,6 +1187,145 @@ class RecordsApi {
|
|
1006
1187
|
...this.extraProps
|
1007
1188
|
});
|
1008
1189
|
}
|
1190
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1191
|
+
return operationsByTag.records.summarizeTable({
|
1192
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1193
|
+
body: query,
|
1194
|
+
...this.extraProps
|
1195
|
+
});
|
1196
|
+
}
|
1197
|
+
aggregateTable(workspace, database, branch, tableName, query) {
|
1198
|
+
return operationsByTag.records.aggregateTable({
|
1199
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1200
|
+
body: query,
|
1201
|
+
...this.extraProps
|
1202
|
+
});
|
1203
|
+
}
|
1204
|
+
}
|
1205
|
+
class MigrationRequestsApi {
|
1206
|
+
constructor(extraProps) {
|
1207
|
+
this.extraProps = extraProps;
|
1208
|
+
}
|
1209
|
+
queryMigrationRequests(workspace, database, options = {}) {
|
1210
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1211
|
+
pathParams: { workspace, dbName: database },
|
1212
|
+
body: options,
|
1213
|
+
...this.extraProps
|
1214
|
+
});
|
1215
|
+
}
|
1216
|
+
createMigrationRequest(workspace, database, options) {
|
1217
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1218
|
+
pathParams: { workspace, dbName: database },
|
1219
|
+
body: options,
|
1220
|
+
...this.extraProps
|
1221
|
+
});
|
1222
|
+
}
|
1223
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1224
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1225
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1226
|
+
...this.extraProps
|
1227
|
+
});
|
1228
|
+
}
|
1229
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1230
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1231
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1232
|
+
body: options,
|
1233
|
+
...this.extraProps
|
1234
|
+
});
|
1235
|
+
}
|
1236
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1237
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1238
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1239
|
+
body: options,
|
1240
|
+
...this.extraProps
|
1241
|
+
});
|
1242
|
+
}
|
1243
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1244
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1245
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1246
|
+
...this.extraProps
|
1247
|
+
});
|
1248
|
+
}
|
1249
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1250
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1251
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1252
|
+
...this.extraProps
|
1253
|
+
});
|
1254
|
+
}
|
1255
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1256
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1257
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1258
|
+
...this.extraProps
|
1259
|
+
});
|
1260
|
+
}
|
1261
|
+
}
|
1262
|
+
class BranchSchemaApi {
|
1263
|
+
constructor(extraProps) {
|
1264
|
+
this.extraProps = extraProps;
|
1265
|
+
}
|
1266
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1267
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1268
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1269
|
+
body: options,
|
1270
|
+
...this.extraProps
|
1271
|
+
});
|
1272
|
+
}
|
1273
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1274
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1275
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1276
|
+
body: migrationPlan,
|
1277
|
+
...this.extraProps
|
1278
|
+
});
|
1279
|
+
}
|
1280
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1281
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1282
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1283
|
+
body: schema,
|
1284
|
+
...this.extraProps
|
1285
|
+
});
|
1286
|
+
}
|
1287
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1288
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1289
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1290
|
+
body: { schema },
|
1291
|
+
...this.extraProps
|
1292
|
+
});
|
1293
|
+
}
|
1294
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1295
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1296
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1297
|
+
body: { schema },
|
1298
|
+
...this.extraProps
|
1299
|
+
});
|
1300
|
+
}
|
1301
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1302
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1303
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1304
|
+
body: migration,
|
1305
|
+
...this.extraProps
|
1306
|
+
});
|
1307
|
+
}
|
1308
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1309
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1310
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1311
|
+
body: migration,
|
1312
|
+
...this.extraProps
|
1313
|
+
});
|
1314
|
+
}
|
1315
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1316
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1317
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1318
|
+
body: { edits },
|
1319
|
+
...this.extraProps
|
1320
|
+
});
|
1321
|
+
}
|
1322
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1323
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1324
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1325
|
+
body: options,
|
1326
|
+
...this.extraProps
|
1327
|
+
});
|
1328
|
+
}
|
1009
1329
|
}
|
1010
1330
|
|
1011
1331
|
class XataApiPlugin {
|
@@ -1131,9 +1451,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1131
1451
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1132
1452
|
return value;
|
1133
1453
|
};
|
1134
|
-
var
|
1454
|
+
var __privateMethod$3 = (obj, member, method) => {
|
1455
|
+
__accessCheck$5(obj, member, "access private method");
|
1456
|
+
return method;
|
1457
|
+
};
|
1458
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1135
1459
|
const _Query = class {
|
1136
1460
|
constructor(repository, table, data, rawParent) {
|
1461
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1137
1462
|
__privateAdd$5(this, _table$1, void 0);
|
1138
1463
|
__privateAdd$5(this, _repository, void 0);
|
1139
1464
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -1190,21 +1515,29 @@ const _Query = class {
|
|
1190
1515
|
}
|
1191
1516
|
filter(a, b) {
|
1192
1517
|
if (arguments.length === 1) {
|
1193
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
1518
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1519
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1520
|
+
}));
|
1194
1521
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1195
1522
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1196
1523
|
} else {
|
1197
|
-
const
|
1524
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1525
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1198
1526
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1199
1527
|
}
|
1200
1528
|
}
|
1201
|
-
sort(column, direction) {
|
1529
|
+
sort(column, direction = "asc") {
|
1202
1530
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1203
1531
|
const sort = [...originalSort, { column, direction }];
|
1204
1532
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1205
1533
|
}
|
1206
1534
|
select(columns) {
|
1207
|
-
return new _Query(
|
1535
|
+
return new _Query(
|
1536
|
+
__privateGet$5(this, _repository),
|
1537
|
+
__privateGet$5(this, _table$1),
|
1538
|
+
{ columns },
|
1539
|
+
__privateGet$5(this, _data)
|
1540
|
+
);
|
1208
1541
|
}
|
1209
1542
|
getPaginated(options = {}) {
|
1210
1543
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1227,11 +1560,20 @@ const _Query = class {
|
|
1227
1560
|
}
|
1228
1561
|
}
|
1229
1562
|
async getMany(options = {}) {
|
1230
|
-
const
|
1563
|
+
const { pagination = {}, ...rest } = options;
|
1564
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1565
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1566
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1567
|
+
const results = [...page.records];
|
1568
|
+
while (page.hasNextPage() && results.length < size) {
|
1569
|
+
page = await page.nextPage();
|
1570
|
+
results.push(...page.records);
|
1571
|
+
}
|
1231
1572
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1232
1573
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1233
1574
|
}
|
1234
|
-
|
1575
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1576
|
+
return array;
|
1235
1577
|
}
|
1236
1578
|
async getAll(options = {}) {
|
1237
1579
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1245,6 +1587,12 @@ const _Query = class {
|
|
1245
1587
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1246
1588
|
return records[0] ?? null;
|
1247
1589
|
}
|
1590
|
+
async getFirstOrThrow(options = {}) {
|
1591
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1592
|
+
if (records[0] === void 0)
|
1593
|
+
throw new Error("No results found.");
|
1594
|
+
return records[0];
|
1595
|
+
}
|
1248
1596
|
cache(ttl) {
|
1249
1597
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1250
1598
|
}
|
@@ -1268,6 +1616,17 @@ let Query = _Query;
|
|
1268
1616
|
_table$1 = new WeakMap();
|
1269
1617
|
_repository = new WeakMap();
|
1270
1618
|
_data = new WeakMap();
|
1619
|
+
_cleanFilterConstraint = new WeakSet();
|
1620
|
+
cleanFilterConstraint_fn = function(column, value) {
|
1621
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1622
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1623
|
+
return { $includes: value };
|
1624
|
+
}
|
1625
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
1626
|
+
return value.id;
|
1627
|
+
}
|
1628
|
+
return value;
|
1629
|
+
};
|
1271
1630
|
function cleanParent(data, parent) {
|
1272
1631
|
if (isCursorPaginationOptions(data.pagination)) {
|
1273
1632
|
return { ...parent, sorting: void 0, filter: void 0 };
|
@@ -1329,12 +1688,16 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1329
1688
|
__accessCheck$4(obj, member, "access private method");
|
1330
1689
|
return method;
|
1331
1690
|
};
|
1332
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1691
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1333
1692
|
class Repository extends Query {
|
1334
1693
|
}
|
1335
1694
|
class RestRepository extends Query {
|
1336
1695
|
constructor(options) {
|
1337
|
-
super(
|
1696
|
+
super(
|
1697
|
+
null,
|
1698
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1699
|
+
{}
|
1700
|
+
);
|
1338
1701
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1339
1702
|
__privateAdd$4(this, _insertRecordWithId);
|
1340
1703
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
@@ -1346,176 +1709,274 @@ class RestRepository extends Query {
|
|
1346
1709
|
__privateAdd$4(this, _getSchemaTables$1);
|
1347
1710
|
__privateAdd$4(this, _table, void 0);
|
1348
1711
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1712
|
+
__privateAdd$4(this, _db, void 0);
|
1349
1713
|
__privateAdd$4(this, _cache, void 0);
|
1350
1714
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1715
|
+
__privateAdd$4(this, _trace, void 0);
|
1351
1716
|
__privateSet$4(this, _table, options.table);
|
1352
1717
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1353
|
-
this
|
1718
|
+
__privateSet$4(this, _db, options.db);
|
1354
1719
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1355
1720
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1721
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1722
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1723
|
+
return trace(name, fn, {
|
1724
|
+
...options2,
|
1725
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1726
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1727
|
+
[TraceAttributes.VERSION]: VERSION
|
1728
|
+
});
|
1729
|
+
});
|
1356
1730
|
}
|
1357
1731
|
async create(a, b, c) {
|
1358
|
-
|
1359
|
-
if (a
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
if (a
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
if (a.id
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1732
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1733
|
+
if (Array.isArray(a)) {
|
1734
|
+
if (a.length === 0)
|
1735
|
+
return [];
|
1736
|
+
const columns = isStringArray(b) ? b : void 0;
|
1737
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1738
|
+
}
|
1739
|
+
if (isString(a) && isObject(b)) {
|
1740
|
+
if (a === "")
|
1741
|
+
throw new Error("The id can't be empty");
|
1742
|
+
const columns = isStringArray(c) ? c : void 0;
|
1743
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1744
|
+
}
|
1745
|
+
if (isObject(a) && isString(a.id)) {
|
1746
|
+
if (a.id === "")
|
1747
|
+
throw new Error("The id can't be empty");
|
1748
|
+
const columns = isStringArray(b) ? b : void 0;
|
1749
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1750
|
+
}
|
1751
|
+
if (isObject(a)) {
|
1752
|
+
const columns = isStringArray(b) ? b : void 0;
|
1753
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1754
|
+
}
|
1755
|
+
throw new Error("Invalid arguments for create method");
|
1756
|
+
});
|
1381
1757
|
}
|
1382
1758
|
async read(a, b) {
|
1383
|
-
|
1384
|
-
|
1385
|
-
if (a
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
acc
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1759
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1760
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1761
|
+
if (Array.isArray(a)) {
|
1762
|
+
if (a.length === 0)
|
1763
|
+
return [];
|
1764
|
+
const ids = a.map((item) => extractId(item));
|
1765
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1766
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1767
|
+
acc[object.id] = object;
|
1768
|
+
return acc;
|
1769
|
+
}, {});
|
1770
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1771
|
+
}
|
1772
|
+
const id = extractId(a);
|
1773
|
+
if (id) {
|
1774
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1775
|
+
try {
|
1776
|
+
const response = await getRecord({
|
1777
|
+
pathParams: {
|
1778
|
+
workspace: "{workspaceId}",
|
1779
|
+
dbBranchName: "{dbBranch}",
|
1780
|
+
tableName: __privateGet$4(this, _table),
|
1781
|
+
recordId: id
|
1782
|
+
},
|
1783
|
+
queryParams: { columns },
|
1784
|
+
...fetchProps
|
1785
|
+
});
|
1786
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1787
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1788
|
+
} catch (e) {
|
1789
|
+
if (isObject(e) && e.status === 404) {
|
1790
|
+
return null;
|
1791
|
+
}
|
1792
|
+
throw e;
|
1409
1793
|
}
|
1410
|
-
throw e;
|
1411
1794
|
}
|
1412
|
-
|
1413
|
-
|
1795
|
+
return null;
|
1796
|
+
});
|
1797
|
+
}
|
1798
|
+
async readOrThrow(a, b) {
|
1799
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1800
|
+
const result = await this.read(a, b);
|
1801
|
+
if (Array.isArray(result)) {
|
1802
|
+
const missingIds = compact(
|
1803
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1804
|
+
);
|
1805
|
+
if (missingIds.length > 0) {
|
1806
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1807
|
+
}
|
1808
|
+
return result;
|
1809
|
+
}
|
1810
|
+
if (result === null) {
|
1811
|
+
const id = extractId(a) ?? "unknown";
|
1812
|
+
throw new Error(`Record with id ${id} not found`);
|
1813
|
+
}
|
1814
|
+
return result;
|
1815
|
+
});
|
1414
1816
|
}
|
1415
1817
|
async update(a, b, c) {
|
1416
|
-
|
1417
|
-
if (a
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1818
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1819
|
+
if (Array.isArray(a)) {
|
1820
|
+
if (a.length === 0)
|
1821
|
+
return [];
|
1822
|
+
if (a.length > 100) {
|
1823
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1824
|
+
}
|
1825
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1826
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1421
1827
|
}
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1828
|
+
if (isString(a) && isObject(b)) {
|
1829
|
+
const columns = isStringArray(c) ? c : void 0;
|
1830
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1831
|
+
}
|
1832
|
+
if (isObject(a) && isString(a.id)) {
|
1833
|
+
const columns = isStringArray(b) ? b : void 0;
|
1834
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1835
|
+
}
|
1836
|
+
throw new Error("Invalid arguments for update method");
|
1837
|
+
});
|
1838
|
+
}
|
1839
|
+
async updateOrThrow(a, b, c) {
|
1840
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1841
|
+
const result = await this.update(a, b, c);
|
1842
|
+
if (Array.isArray(result)) {
|
1843
|
+
const missingIds = compact(
|
1844
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1845
|
+
);
|
1846
|
+
if (missingIds.length > 0) {
|
1847
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1848
|
+
}
|
1849
|
+
return result;
|
1850
|
+
}
|
1851
|
+
if (result === null) {
|
1852
|
+
const id = extractId(a) ?? "unknown";
|
1853
|
+
throw new Error(`Record with id ${id} not found`);
|
1854
|
+
}
|
1855
|
+
return result;
|
1856
|
+
});
|
1434
1857
|
}
|
1435
1858
|
async createOrUpdate(a, b, c) {
|
1436
|
-
|
1437
|
-
if (a
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1859
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1860
|
+
if (Array.isArray(a)) {
|
1861
|
+
if (a.length === 0)
|
1862
|
+
return [];
|
1863
|
+
if (a.length > 100) {
|
1864
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1865
|
+
}
|
1866
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1867
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1441
1868
|
}
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
if (isString(a) && isObject(b)) {
|
1446
|
-
const columns = isStringArray(c) ? c : void 0;
|
1447
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1448
|
-
}
|
1449
|
-
if (isObject(a) && isString(a.id)) {
|
1450
|
-
const columns = isStringArray(c) ? c : void 0;
|
1451
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1452
|
-
}
|
1453
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1454
|
-
}
|
1455
|
-
async delete(a) {
|
1456
|
-
if (Array.isArray(a)) {
|
1457
|
-
if (a.length === 0)
|
1458
|
-
return;
|
1459
|
-
if (a.length > 100) {
|
1460
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1869
|
+
if (isString(a) && isObject(b)) {
|
1870
|
+
const columns = isStringArray(c) ? c : void 0;
|
1871
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1461
1872
|
}
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1873
|
+
if (isObject(a) && isString(a.id)) {
|
1874
|
+
const columns = isStringArray(c) ? c : void 0;
|
1875
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1876
|
+
}
|
1877
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1878
|
+
});
|
1879
|
+
}
|
1880
|
+
async delete(a, b) {
|
1881
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1882
|
+
if (Array.isArray(a)) {
|
1883
|
+
if (a.length === 0)
|
1884
|
+
return [];
|
1885
|
+
if (a.length > 100) {
|
1886
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1887
|
+
}
|
1888
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1889
|
+
}
|
1890
|
+
if (isString(a)) {
|
1891
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1892
|
+
}
|
1893
|
+
if (isObject(a) && isString(a.id)) {
|
1894
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1895
|
+
}
|
1896
|
+
throw new Error("Invalid arguments for delete method");
|
1897
|
+
});
|
1898
|
+
}
|
1899
|
+
async deleteOrThrow(a, b) {
|
1900
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1901
|
+
const result = await this.delete(a, b);
|
1902
|
+
if (Array.isArray(result)) {
|
1903
|
+
const missingIds = compact(
|
1904
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1905
|
+
);
|
1906
|
+
if (missingIds.length > 0) {
|
1907
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1908
|
+
}
|
1909
|
+
return result;
|
1910
|
+
} else if (result === null) {
|
1911
|
+
const id = extractId(a) ?? "unknown";
|
1912
|
+
throw new Error(`Record with id ${id} not found`);
|
1913
|
+
}
|
1914
|
+
return result;
|
1915
|
+
});
|
1474
1916
|
}
|
1475
1917
|
async search(query, options = {}) {
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1918
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1919
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1920
|
+
const { records } = await searchTable({
|
1921
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1922
|
+
body: {
|
1923
|
+
query,
|
1924
|
+
fuzziness: options.fuzziness,
|
1925
|
+
prefix: options.prefix,
|
1926
|
+
highlight: options.highlight,
|
1927
|
+
filter: options.filter,
|
1928
|
+
boosters: options.boosters
|
1929
|
+
},
|
1930
|
+
...fetchProps
|
1931
|
+
});
|
1932
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1933
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
1934
|
+
});
|
1935
|
+
}
|
1936
|
+
async aggregate(aggs, filter) {
|
1937
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
1938
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1939
|
+
const result = await aggregateTable({
|
1940
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1941
|
+
body: { aggs, filter },
|
1942
|
+
...fetchProps
|
1943
|
+
});
|
1944
|
+
return result;
|
1488
1945
|
});
|
1489
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1490
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1491
1946
|
}
|
1492
1947
|
async query(query) {
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1948
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1949
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1950
|
+
if (cacheQuery)
|
1951
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1952
|
+
const data = query.getQueryOptions();
|
1953
|
+
const body = {
|
1954
|
+
filter: cleanFilter(data.filter),
|
1955
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1956
|
+
page: data.pagination,
|
1957
|
+
columns: data.columns
|
1958
|
+
};
|
1959
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1960
|
+
const { meta, records: objects } = await queryTable({
|
1961
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1962
|
+
body,
|
1963
|
+
...fetchProps
|
1964
|
+
});
|
1965
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1966
|
+
const records = objects.map(
|
1967
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
1968
|
+
);
|
1969
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1970
|
+
return new Page(query, meta, records);
|
1508
1971
|
});
|
1509
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1510
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1511
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1512
|
-
return new Page(query, meta, records);
|
1513
1972
|
}
|
1514
1973
|
}
|
1515
1974
|
_table = new WeakMap();
|
1516
1975
|
_getFetchProps = new WeakMap();
|
1976
|
+
_db = new WeakMap();
|
1517
1977
|
_cache = new WeakMap();
|
1518
1978
|
_schemaTables$2 = new WeakMap();
|
1979
|
+
_trace = new WeakMap();
|
1519
1980
|
_insertRecordWithoutId = new WeakSet();
|
1520
1981
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1521
1982
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1531,7 +1992,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1531
1992
|
...fetchProps
|
1532
1993
|
});
|
1533
1994
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1534
|
-
return initObject(this
|
1995
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1535
1996
|
};
|
1536
1997
|
_insertRecordWithId = new WeakSet();
|
1537
1998
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1549,7 +2010,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1549
2010
|
...fetchProps
|
1550
2011
|
});
|
1551
2012
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1552
|
-
return initObject(this
|
2013
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1553
2014
|
};
|
1554
2015
|
_bulkInsertTableRecords = new WeakSet();
|
1555
2016
|
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
@@ -1565,20 +2026,27 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1565
2026
|
throw new Error("Request included columns but server didn't include them");
|
1566
2027
|
}
|
1567
2028
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1568
|
-
return response.records?.map((item) => initObject(this
|
2029
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
1569
2030
|
};
|
1570
2031
|
_updateRecordWithID = new WeakSet();
|
1571
2032
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1572
2033
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1573
2034
|
const record = transformObjectLinks(object);
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
2035
|
+
try {
|
2036
|
+
const response = await updateRecordWithID({
|
2037
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
2038
|
+
queryParams: { columns },
|
2039
|
+
body: record,
|
2040
|
+
...fetchProps
|
2041
|
+
});
|
2042
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2043
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2044
|
+
} catch (e) {
|
2045
|
+
if (isObject(e) && e.status === 404) {
|
2046
|
+
return null;
|
2047
|
+
}
|
2048
|
+
throw e;
|
2049
|
+
}
|
1582
2050
|
};
|
1583
2051
|
_upsertRecordWithID = new WeakSet();
|
1584
2052
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1590,15 +2058,25 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1590
2058
|
...fetchProps
|
1591
2059
|
});
|
1592
2060
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1593
|
-
return initObject(this
|
2061
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1594
2062
|
};
|
1595
2063
|
_deleteRecord = new WeakSet();
|
1596
|
-
deleteRecord_fn = async function(recordId) {
|
2064
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1597
2065
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
2066
|
+
try {
|
2067
|
+
const response = await deleteRecord({
|
2068
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
2069
|
+
queryParams: { columns },
|
2070
|
+
...fetchProps
|
2071
|
+
});
|
2072
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2073
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2074
|
+
} catch (e) {
|
2075
|
+
if (isObject(e) && e.status === 404) {
|
2076
|
+
return null;
|
2077
|
+
}
|
2078
|
+
throw e;
|
2079
|
+
}
|
1602
2080
|
};
|
1603
2081
|
_setCacheQuery = new WeakSet();
|
1604
2082
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1635,7 +2113,7 @@ const transformObjectLinks = (object) => {
|
|
1635
2113
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1636
2114
|
}, {});
|
1637
2115
|
};
|
1638
|
-
const initObject = (db, schemaTables, table, object) => {
|
2116
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
1639
2117
|
const result = {};
|
1640
2118
|
const { xata, ...rest } = object ?? {};
|
1641
2119
|
Object.assign(result, rest);
|
@@ -1643,6 +2121,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1643
2121
|
if (!columns)
|
1644
2122
|
console.error(`Table ${table} not found in schema`);
|
1645
2123
|
for (const column of columns ?? []) {
|
2124
|
+
if (!isValidColumn(selectedColumns, column))
|
2125
|
+
continue;
|
1646
2126
|
const value = result[column.name];
|
1647
2127
|
switch (column.type) {
|
1648
2128
|
case "datetime": {
|
@@ -1659,10 +2139,28 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1659
2139
|
if (!linkTable) {
|
1660
2140
|
console.error(`Failed to parse link for field ${column.name}`);
|
1661
2141
|
} else if (isObject(value)) {
|
1662
|
-
|
2142
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2143
|
+
if (item === column.name) {
|
2144
|
+
return [...acc, "*"];
|
2145
|
+
}
|
2146
|
+
if (item.startsWith(`${column.name}.`)) {
|
2147
|
+
const [, ...path] = item.split(".");
|
2148
|
+
return [...acc, path.join(".")];
|
2149
|
+
}
|
2150
|
+
return acc;
|
2151
|
+
}, []);
|
2152
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2153
|
+
} else {
|
2154
|
+
result[column.name] = null;
|
1663
2155
|
}
|
1664
2156
|
break;
|
1665
2157
|
}
|
2158
|
+
default:
|
2159
|
+
result[column.name] = value ?? null;
|
2160
|
+
if (column.notNull === true && value === null) {
|
2161
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2162
|
+
}
|
2163
|
+
break;
|
1666
2164
|
}
|
1667
2165
|
}
|
1668
2166
|
result.read = function(columns2) {
|
@@ -1686,6 +2184,28 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1686
2184
|
function isResponseWithRecords(value) {
|
1687
2185
|
return isObject(value) && Array.isArray(value.records);
|
1688
2186
|
}
|
2187
|
+
function extractId(value) {
|
2188
|
+
if (isString(value))
|
2189
|
+
return value;
|
2190
|
+
if (isObject(value) && isString(value.id))
|
2191
|
+
return value.id;
|
2192
|
+
return void 0;
|
2193
|
+
}
|
2194
|
+
function cleanFilter(filter) {
|
2195
|
+
if (!filter)
|
2196
|
+
return void 0;
|
2197
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2198
|
+
return values.length > 0 ? filter : void 0;
|
2199
|
+
}
|
2200
|
+
function isValidColumn(columns, column) {
|
2201
|
+
if (columns.includes("*"))
|
2202
|
+
return true;
|
2203
|
+
if (column.type === "link") {
|
2204
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2205
|
+
return linkColumns.length > 0;
|
2206
|
+
}
|
2207
|
+
return columns.includes(column.name);
|
2208
|
+
}
|
1689
2209
|
|
1690
2210
|
var __accessCheck$3 = (obj, member, msg) => {
|
1691
2211
|
if (!member.has(obj))
|
@@ -1736,18 +2256,25 @@ class SimpleCache {
|
|
1736
2256
|
}
|
1737
2257
|
_map = new WeakMap();
|
1738
2258
|
|
1739
|
-
const
|
1740
|
-
const
|
1741
|
-
const
|
1742
|
-
const
|
1743
|
-
const
|
1744
|
-
const
|
2259
|
+
const greaterThan = (value) => ({ $gt: value });
|
2260
|
+
const gt = greaterThan;
|
2261
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2262
|
+
const greaterEquals = greaterThanEquals;
|
2263
|
+
const gte = greaterThanEquals;
|
2264
|
+
const ge = greaterThanEquals;
|
2265
|
+
const lessThan = (value) => ({ $lt: value });
|
2266
|
+
const lt = lessThan;
|
2267
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2268
|
+
const lessEquals = lessThanEquals;
|
2269
|
+
const lte = lessThanEquals;
|
2270
|
+
const le = lessThanEquals;
|
1745
2271
|
const exists = (column) => ({ $exists: column });
|
1746
2272
|
const notExists = (column) => ({ $notExists: column });
|
1747
2273
|
const startsWith = (value) => ({ $startsWith: value });
|
1748
2274
|
const endsWith = (value) => ({ $endsWith: value });
|
1749
2275
|
const pattern = (value) => ({ $pattern: value });
|
1750
2276
|
const is = (value) => ({ $is: value });
|
2277
|
+
const equals = is;
|
1751
2278
|
const isNot = (value) => ({ $isNot: value });
|
1752
2279
|
const contains = (value) => ({ $contains: value });
|
1753
2280
|
const includes = (value) => ({ $includes: value });
|
@@ -1782,16 +2309,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1782
2309
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1783
2310
|
}
|
1784
2311
|
build(pluginOptions) {
|
1785
|
-
const db = new Proxy(
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
2312
|
+
const db = new Proxy(
|
2313
|
+
{},
|
2314
|
+
{
|
2315
|
+
get: (_target, table) => {
|
2316
|
+
if (!isString(table))
|
2317
|
+
throw new Error("Invalid table name");
|
2318
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2319
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2320
|
+
}
|
2321
|
+
return __privateGet$2(this, _tables)[table];
|
1791
2322
|
}
|
1792
|
-
return __privateGet$2(this, _tables)[table];
|
1793
2323
|
}
|
1794
|
-
|
2324
|
+
);
|
1795
2325
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1796
2326
|
for (const table of tableNames) {
|
1797
2327
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1841,7 +2371,7 @@ class SearchPlugin extends XataPlugin {
|
|
1841
2371
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1842
2372
|
return records.map((record) => {
|
1843
2373
|
const { table = "orphan" } = record.xata;
|
1844
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
2374
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1845
2375
|
});
|
1846
2376
|
},
|
1847
2377
|
byTable: async (query, options = {}) => {
|
@@ -1850,7 +2380,7 @@ class SearchPlugin extends XataPlugin {
|
|
1850
2380
|
return records.reduce((acc, record) => {
|
1851
2381
|
const { table = "orphan" } = record.xata;
|
1852
2382
|
const items = acc[table] ?? [];
|
1853
|
-
const item = initObject(this.db, schemaTables, table, record);
|
2383
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1854
2384
|
return { ...acc, [table]: [...items, item] };
|
1855
2385
|
}, {});
|
1856
2386
|
}
|
@@ -1905,9 +2435,13 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1905
2435
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1906
2436
|
const apiKey = options?.apiKey || getAPIKey();
|
1907
2437
|
if (!databaseURL)
|
1908
|
-
throw new Error(
|
2438
|
+
throw new Error(
|
2439
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2440
|
+
);
|
1909
2441
|
if (!apiKey)
|
1910
|
-
throw new Error(
|
2442
|
+
throw new Error(
|
2443
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2444
|
+
);
|
1911
2445
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1912
2446
|
const [workspace] = host.split(".");
|
1913
2447
|
const { fallbackBranch } = getEnvironment();
|
@@ -1917,7 +2451,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1917
2451
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1918
2452
|
workspacesApiUrl: `${protocol}//${host}`,
|
1919
2453
|
pathParams: { dbName, workspace },
|
1920
|
-
queryParams: { gitBranch, fallbackBranch }
|
2454
|
+
queryParams: { gitBranch, fallbackBranch },
|
2455
|
+
trace: defaultTrace
|
1921
2456
|
});
|
1922
2457
|
return branch;
|
1923
2458
|
}
|
@@ -1925,9 +2460,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1925
2460
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1926
2461
|
const apiKey = options?.apiKey || getAPIKey();
|
1927
2462
|
if (!databaseURL)
|
1928
|
-
throw new Error(
|
2463
|
+
throw new Error(
|
2464
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2465
|
+
);
|
1929
2466
|
if (!apiKey)
|
1930
|
-
throw new Error(
|
2467
|
+
throw new Error(
|
2468
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2469
|
+
);
|
1931
2470
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1932
2471
|
const [workspace] = host.split(".");
|
1933
2472
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1937,7 +2476,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1937
2476
|
apiUrl: databaseURL,
|
1938
2477
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1939
2478
|
workspacesApiUrl: `${protocol}//${host}`,
|
1940
|
-
pathParams: { dbBranchName, workspace }
|
2479
|
+
pathParams: { dbBranchName, workspace },
|
2480
|
+
trace: defaultTrace
|
1941
2481
|
});
|
1942
2482
|
} catch (err) {
|
1943
2483
|
if (isObject(err) && err.status === 404)
|
@@ -1977,17 +2517,20 @@ var __privateMethod = (obj, member, method) => {
|
|
1977
2517
|
return method;
|
1978
2518
|
};
|
1979
2519
|
const buildClient = (plugins) => {
|
1980
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2520
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1981
2521
|
return _a = class {
|
1982
2522
|
constructor(options = {}, schemaTables) {
|
1983
2523
|
__privateAdd(this, _parseOptions);
|
1984
2524
|
__privateAdd(this, _getFetchProps);
|
1985
2525
|
__privateAdd(this, _evaluateBranch);
|
1986
2526
|
__privateAdd(this, _branch, void 0);
|
2527
|
+
__privateAdd(this, _options, void 0);
|
1987
2528
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2529
|
+
__privateSet(this, _options, safeOptions);
|
1988
2530
|
const pluginOptions = {
|
1989
2531
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1990
|
-
cache: safeOptions.cache
|
2532
|
+
cache: safeOptions.cache,
|
2533
|
+
trace: safeOptions.trace
|
1991
2534
|
};
|
1992
2535
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1993
2536
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2006,22 +2549,26 @@ const buildClient = (plugins) => {
|
|
2006
2549
|
}
|
2007
2550
|
}
|
2008
2551
|
}
|
2009
|
-
|
2552
|
+
async getConfig() {
|
2553
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2554
|
+
const branch = await __privateGet(this, _options).branch();
|
2555
|
+
return { databaseURL, branch };
|
2556
|
+
}
|
2557
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
2010
2558
|
const fetch = getFetchImplementation(options?.fetch);
|
2011
2559
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2012
2560
|
const apiKey = options?.apiKey || getAPIKey();
|
2013
2561
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2562
|
+
const trace = options?.trace ?? defaultTrace;
|
2014
2563
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2015
|
-
if (!
|
2016
|
-
throw new Error("
|
2564
|
+
if (!apiKey) {
|
2565
|
+
throw new Error("Option apiKey is required");
|
2017
2566
|
}
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
apiKey,
|
2022
|
-
|
2023
|
-
branch
|
2024
|
-
}) {
|
2567
|
+
if (!databaseURL) {
|
2568
|
+
throw new Error("Option databaseURL is required");
|
2569
|
+
}
|
2570
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2571
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2025
2572
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2026
2573
|
if (!branchValue)
|
2027
2574
|
throw new Error("Unable to resolve branch value");
|
@@ -2031,9 +2578,10 @@ const buildClient = (plugins) => {
|
|
2031
2578
|
apiUrl: "",
|
2032
2579
|
workspacesApiUrl: (path, params) => {
|
2033
2580
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2034
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2581
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2035
2582
|
return databaseURL + newPath;
|
2036
|
-
}
|
2583
|
+
},
|
2584
|
+
trace
|
2037
2585
|
};
|
2038
2586
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2039
2587
|
if (__privateGet(this, _branch))
|
@@ -2056,6 +2604,88 @@ const buildClient = (plugins) => {
|
|
2056
2604
|
class BaseClient extends buildClient() {
|
2057
2605
|
}
|
2058
2606
|
|
2607
|
+
const META = "__";
|
2608
|
+
const VALUE = "___";
|
2609
|
+
class Serializer {
|
2610
|
+
constructor() {
|
2611
|
+
this.classes = {};
|
2612
|
+
}
|
2613
|
+
add(clazz) {
|
2614
|
+
this.classes[clazz.name] = clazz;
|
2615
|
+
}
|
2616
|
+
toJSON(data) {
|
2617
|
+
function visit(obj) {
|
2618
|
+
if (Array.isArray(obj))
|
2619
|
+
return obj.map(visit);
|
2620
|
+
const type = typeof obj;
|
2621
|
+
if (type === "undefined")
|
2622
|
+
return { [META]: "undefined" };
|
2623
|
+
if (type === "bigint")
|
2624
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2625
|
+
if (obj === null || type !== "object")
|
2626
|
+
return obj;
|
2627
|
+
const constructor = obj.constructor;
|
2628
|
+
const o = { [META]: constructor.name };
|
2629
|
+
for (const [key, value] of Object.entries(obj)) {
|
2630
|
+
o[key] = visit(value);
|
2631
|
+
}
|
2632
|
+
if (constructor === Date)
|
2633
|
+
o[VALUE] = obj.toISOString();
|
2634
|
+
if (constructor === Map)
|
2635
|
+
o[VALUE] = Object.fromEntries(obj);
|
2636
|
+
if (constructor === Set)
|
2637
|
+
o[VALUE] = [...obj];
|
2638
|
+
return o;
|
2639
|
+
}
|
2640
|
+
return JSON.stringify(visit(data));
|
2641
|
+
}
|
2642
|
+
fromJSON(json) {
|
2643
|
+
return JSON.parse(json, (key, value) => {
|
2644
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2645
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2646
|
+
const constructor = this.classes[clazz];
|
2647
|
+
if (constructor) {
|
2648
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2649
|
+
}
|
2650
|
+
if (clazz === "Date")
|
2651
|
+
return new Date(val);
|
2652
|
+
if (clazz === "Set")
|
2653
|
+
return new Set(val);
|
2654
|
+
if (clazz === "Map")
|
2655
|
+
return new Map(Object.entries(val));
|
2656
|
+
if (clazz === "bigint")
|
2657
|
+
return BigInt(val);
|
2658
|
+
if (clazz === "undefined")
|
2659
|
+
return void 0;
|
2660
|
+
return rest;
|
2661
|
+
}
|
2662
|
+
return value;
|
2663
|
+
});
|
2664
|
+
}
|
2665
|
+
}
|
2666
|
+
const defaultSerializer = new Serializer();
|
2667
|
+
const serialize = (data) => {
|
2668
|
+
return defaultSerializer.toJSON(data);
|
2669
|
+
};
|
2670
|
+
const deserialize = (json) => {
|
2671
|
+
return defaultSerializer.fromJSON(json);
|
2672
|
+
};
|
2673
|
+
|
2674
|
+
function buildWorkerRunner(config) {
|
2675
|
+
return function xataWorker(name, _worker) {
|
2676
|
+
return async (...args) => {
|
2677
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2678
|
+
const result = await fetch(url, {
|
2679
|
+
method: "POST",
|
2680
|
+
headers: { "Content-Type": "application/json" },
|
2681
|
+
body: serialize({ args })
|
2682
|
+
});
|
2683
|
+
const text = await result.text();
|
2684
|
+
return deserialize(text);
|
2685
|
+
};
|
2686
|
+
};
|
2687
|
+
}
|
2688
|
+
|
2059
2689
|
class XataError extends Error {
|
2060
2690
|
constructor(message, status) {
|
2061
2691
|
super(message);
|
@@ -2076,6 +2706,7 @@ exports.Repository = Repository;
|
|
2076
2706
|
exports.RestRepository = RestRepository;
|
2077
2707
|
exports.SchemaPlugin = SchemaPlugin;
|
2078
2708
|
exports.SearchPlugin = SearchPlugin;
|
2709
|
+
exports.Serializer = Serializer;
|
2079
2710
|
exports.SimpleCache = SimpleCache;
|
2080
2711
|
exports.XataApiClient = XataApiClient;
|
2081
2712
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2084,12 +2715,19 @@ exports.XataPlugin = XataPlugin;
|
|
2084
2715
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2085
2716
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2086
2717
|
exports.addTableColumn = addTableColumn;
|
2718
|
+
exports.aggregateTable = aggregateTable;
|
2719
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
2087
2720
|
exports.buildClient = buildClient;
|
2721
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2088
2722
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2089
2723
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2724
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
2725
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
2726
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2090
2727
|
exports.contains = contains;
|
2091
2728
|
exports.createBranch = createBranch;
|
2092
2729
|
exports.createDatabase = createDatabase;
|
2730
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2093
2731
|
exports.createTable = createTable;
|
2094
2732
|
exports.createUserAPIKey = createUserAPIKey;
|
2095
2733
|
exports.createWorkspace = createWorkspace;
|
@@ -2101,7 +2739,9 @@ exports.deleteTable = deleteTable;
|
|
2101
2739
|
exports.deleteUser = deleteUser;
|
2102
2740
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2103
2741
|
exports.deleteWorkspace = deleteWorkspace;
|
2742
|
+
exports.deserialize = deserialize;
|
2104
2743
|
exports.endsWith = endsWith;
|
2744
|
+
exports.equals = equals;
|
2105
2745
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2106
2746
|
exports.exists = exists;
|
2107
2747
|
exports.ge = ge;
|
@@ -2111,13 +2751,18 @@ exports.getBranchList = getBranchList;
|
|
2111
2751
|
exports.getBranchMetadata = getBranchMetadata;
|
2112
2752
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2113
2753
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
2754
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2114
2755
|
exports.getBranchStats = getBranchStats;
|
2115
2756
|
exports.getColumn = getColumn;
|
2116
2757
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
2117
2758
|
exports.getCurrentBranchName = getCurrentBranchName;
|
2118
2759
|
exports.getDatabaseList = getDatabaseList;
|
2760
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2119
2761
|
exports.getDatabaseURL = getDatabaseURL;
|
2120
2762
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
2763
|
+
exports.getHostUrl = getHostUrl;
|
2764
|
+
exports.getMigrationRequest = getMigrationRequest;
|
2765
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
2121
2766
|
exports.getRecord = getRecord;
|
2122
2767
|
exports.getTableColumns = getTableColumns;
|
2123
2768
|
exports.getTableSchema = getTableSchema;
|
@@ -2126,6 +2771,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2126
2771
|
exports.getWorkspace = getWorkspace;
|
2127
2772
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2128
2773
|
exports.getWorkspacesList = getWorkspacesList;
|
2774
|
+
exports.greaterEquals = greaterEquals;
|
2775
|
+
exports.greaterThan = greaterThan;
|
2776
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2129
2777
|
exports.gt = gt;
|
2130
2778
|
exports.gte = gte;
|
2131
2779
|
exports.includes = includes;
|
@@ -2137,15 +2785,25 @@ exports.insertRecordWithID = insertRecordWithID;
|
|
2137
2785
|
exports.inviteWorkspaceMember = inviteWorkspaceMember;
|
2138
2786
|
exports.is = is;
|
2139
2787
|
exports.isCursorPaginationOptions = isCursorPaginationOptions;
|
2788
|
+
exports.isHostProviderAlias = isHostProviderAlias;
|
2789
|
+
exports.isHostProviderBuilder = isHostProviderBuilder;
|
2140
2790
|
exports.isIdentifiable = isIdentifiable;
|
2141
2791
|
exports.isNot = isNot;
|
2142
2792
|
exports.isXataRecord = isXataRecord;
|
2143
2793
|
exports.le = le;
|
2794
|
+
exports.lessEquals = lessEquals;
|
2795
|
+
exports.lessThan = lessThan;
|
2796
|
+
exports.lessThanEquals = lessThanEquals;
|
2797
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
2144
2798
|
exports.lt = lt;
|
2145
2799
|
exports.lte = lte;
|
2800
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2146
2801
|
exports.notExists = notExists;
|
2147
2802
|
exports.operationsByTag = operationsByTag;
|
2803
|
+
exports.parseProviderString = parseProviderString;
|
2148
2804
|
exports.pattern = pattern;
|
2805
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
2806
|
+
exports.queryMigrationRequests = queryMigrationRequests;
|
2149
2807
|
exports.queryTable = queryTable;
|
2150
2808
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2151
2809
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
@@ -2153,10 +2811,15 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2153
2811
|
exports.resolveBranch = resolveBranch;
|
2154
2812
|
exports.searchBranch = searchBranch;
|
2155
2813
|
exports.searchTable = searchTable;
|
2814
|
+
exports.serialize = serialize;
|
2156
2815
|
exports.setTableSchema = setTableSchema;
|
2157
2816
|
exports.startsWith = startsWith;
|
2817
|
+
exports.summarizeTable = summarizeTable;
|
2158
2818
|
exports.updateBranchMetadata = updateBranchMetadata;
|
2819
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2159
2820
|
exports.updateColumn = updateColumn;
|
2821
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
2822
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2160
2823
|
exports.updateRecordWithID = updateRecordWithID;
|
2161
2824
|
exports.updateTable = updateTable;
|
2162
2825
|
exports.updateUser = updateUser;
|