@xata.io/client 0.0.0-alpha.vfbac5b5 → 0.0.0-alpha.vfc5c289
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 +88 -0
- package/README.md +27 -25
- package/Usage.md +60 -6
- package/dist/index.cjs +770 -350
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1266 -209
- package/dist/index.mjs +743 -351
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
const defaultTrace = async (_name, fn, _options) => {
|
2
|
+
return await fn({
|
3
|
+
setAttributes: () => {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
});
|
7
|
+
};
|
8
|
+
const TraceAttributes = {
|
9
|
+
KIND: "xata.trace.kind",
|
10
|
+
VERSION: "xata.sdk.version",
|
11
|
+
TABLE: "xata.table",
|
12
|
+
HTTP_REQUEST_ID: "http.request_id",
|
13
|
+
HTTP_STATUS_CODE: "http.status_code",
|
14
|
+
HTTP_HOST: "http.host",
|
15
|
+
HTTP_SCHEME: "http.scheme",
|
16
|
+
HTTP_USER_AGENT: "http.user_agent",
|
17
|
+
HTTP_METHOD: "http.method",
|
18
|
+
HTTP_URL: "http.url",
|
19
|
+
HTTP_ROUTE: "http.route",
|
20
|
+
HTTP_TARGET: "http.target"
|
21
|
+
};
|
22
|
+
|
1
23
|
function notEmpty(value) {
|
2
24
|
return value !== null && value !== void 0;
|
3
25
|
}
|
@@ -13,6 +35,9 @@ function isDefined(value) {
|
|
13
35
|
function isString(value) {
|
14
36
|
return isDefined(value) && typeof value === "string";
|
15
37
|
}
|
38
|
+
function isStringArray(value) {
|
39
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
40
|
+
}
|
16
41
|
function toBase64(value) {
|
17
42
|
try {
|
18
43
|
return btoa(value);
|
@@ -85,18 +110,20 @@ function getGlobalFallbackBranch() {
|
|
85
110
|
}
|
86
111
|
async function getGitBranch() {
|
87
112
|
const cmd = ["git", "branch", "--show-current"];
|
113
|
+
const fullCmd = cmd.join(" ");
|
88
114
|
const nodeModule = ["child", "process"].join("_");
|
115
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
89
116
|
try {
|
90
117
|
if (typeof require === "function") {
|
91
|
-
return require(nodeModule).execSync(
|
118
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
92
119
|
}
|
93
120
|
const { execSync } = await import(nodeModule);
|
94
|
-
return execSync(
|
121
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
95
122
|
} catch (err) {
|
96
123
|
}
|
97
124
|
try {
|
98
125
|
if (isObject(Deno)) {
|
99
|
-
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "
|
126
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
100
127
|
return new TextDecoder().decode(await process2.output()).trim();
|
101
128
|
}
|
102
129
|
} catch (err) {
|
@@ -116,12 +143,14 @@ function getFetchImplementation(userFetch) {
|
|
116
143
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
117
144
|
const fetchImpl = userFetch ?? globalFetch;
|
118
145
|
if (!fetchImpl) {
|
119
|
-
throw new Error(
|
146
|
+
throw new Error(
|
147
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
148
|
+
);
|
120
149
|
}
|
121
150
|
return fetchImpl;
|
122
151
|
}
|
123
152
|
|
124
|
-
const VERSION = "0.0.0-alpha.
|
153
|
+
const VERSION = "0.0.0-alpha.vfc5c289";
|
125
154
|
|
126
155
|
class ErrorWithCause extends Error {
|
127
156
|
constructor(message, options) {
|
@@ -172,7 +201,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
172
201
|
}, {});
|
173
202
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
174
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
175
|
-
|
204
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
205
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
206
|
+
}, {});
|
207
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
176
208
|
};
|
177
209
|
function buildBaseUrl({
|
178
210
|
path,
|
@@ -180,10 +212,10 @@ function buildBaseUrl({
|
|
180
212
|
apiUrl,
|
181
213
|
pathParams
|
182
214
|
}) {
|
183
|
-
if (
|
215
|
+
if (pathParams?.workspace === void 0)
|
184
216
|
return `${apiUrl}${path}`;
|
185
217
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
186
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
218
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
187
219
|
}
|
188
220
|
function hostHeader(url) {
|
189
221
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -200,34 +232,61 @@ async function fetch$1({
|
|
200
232
|
fetchImpl,
|
201
233
|
apiKey,
|
202
234
|
apiUrl,
|
203
|
-
workspacesApiUrl
|
235
|
+
workspacesApiUrl,
|
236
|
+
trace
|
204
237
|
}) {
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
238
|
+
return trace(
|
239
|
+
`${method.toUpperCase()} ${path}`,
|
240
|
+
async ({ setAttributes }) => {
|
241
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
242
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
243
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
244
|
+
setAttributes({
|
245
|
+
[TraceAttributes.HTTP_URL]: url,
|
246
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
247
|
+
});
|
248
|
+
const response = await fetchImpl(url, {
|
249
|
+
method: method.toUpperCase(),
|
250
|
+
body: body ? JSON.stringify(body) : void 0,
|
251
|
+
headers: {
|
252
|
+
"Content-Type": "application/json",
|
253
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
254
|
+
...headers,
|
255
|
+
...hostHeader(fullUrl),
|
256
|
+
Authorization: `Bearer ${apiKey}`
|
257
|
+
}
|
258
|
+
});
|
259
|
+
if (response.status === 204) {
|
260
|
+
return {};
|
261
|
+
}
|
262
|
+
const { host, protocol } = parseUrl(response.url);
|
263
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
264
|
+
setAttributes({
|
265
|
+
[TraceAttributes.KIND]: "http",
|
266
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
267
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
268
|
+
[TraceAttributes.HTTP_HOST]: host,
|
269
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
270
|
+
});
|
271
|
+
try {
|
272
|
+
const jsonResponse = await response.json();
|
273
|
+
if (response.ok) {
|
274
|
+
return jsonResponse;
|
275
|
+
}
|
276
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
277
|
+
} catch (error) {
|
278
|
+
throw new FetcherError(response.status, error, requestId);
|
279
|
+
}
|
280
|
+
},
|
281
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
282
|
+
);
|
283
|
+
}
|
284
|
+
function parseUrl(url) {
|
223
285
|
try {
|
224
|
-
const
|
225
|
-
|
226
|
-
return jsonResponse;
|
227
|
-
}
|
228
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
286
|
+
const { host, protocol } = new URL(url);
|
287
|
+
return { host, protocol };
|
229
288
|
} catch (error) {
|
230
|
-
|
289
|
+
return {};
|
231
290
|
}
|
232
291
|
}
|
233
292
|
|
@@ -286,6 +345,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
286
345
|
...variables
|
287
346
|
});
|
288
347
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
348
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
289
349
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
290
350
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
291
351
|
method: "delete",
|
@@ -321,6 +381,12 @@ const deleteDatabase = (variables) => fetch$1({
|
|
321
381
|
method: "delete",
|
322
382
|
...variables
|
323
383
|
});
|
384
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
385
|
+
url: "/dbs/{dbName}/metadata",
|
386
|
+
method: "get",
|
387
|
+
...variables
|
388
|
+
});
|
389
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
324
390
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
325
391
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
326
392
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -329,16 +395,28 @@ const resolveBranch = (variables) => fetch$1({
|
|
329
395
|
method: "get",
|
330
396
|
...variables
|
331
397
|
});
|
332
|
-
const
|
333
|
-
|
398
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
399
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
400
|
+
const getMigrationRequest = (variables) => fetch$1({
|
401
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
334
402
|
method: "get",
|
335
403
|
...variables
|
336
404
|
});
|
337
|
-
const
|
405
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
406
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
407
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
408
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
409
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
410
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
411
|
+
method: "post",
|
412
|
+
...variables
|
413
|
+
});
|
414
|
+
const getBranchDetails = (variables) => fetch$1({
|
338
415
|
url: "/db/{dbBranchName}",
|
339
|
-
method: "
|
416
|
+
method: "get",
|
340
417
|
...variables
|
341
418
|
});
|
419
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
342
420
|
const deleteBranch = (variables) => fetch$1({
|
343
421
|
url: "/db/{dbBranchName}",
|
344
422
|
method: "delete",
|
@@ -357,6 +435,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
357
435
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
358
436
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
359
437
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
438
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
439
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
440
|
+
const updateBranchSchema = (variables) => fetch$1({
|
441
|
+
url: "/db/{dbBranchName}/schema/update",
|
442
|
+
method: "post",
|
443
|
+
...variables
|
444
|
+
});
|
445
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
446
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
447
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
360
448
|
const getBranchStats = (variables) => fetch$1({
|
361
449
|
url: "/db/{dbBranchName}/stats",
|
362
450
|
method: "get",
|
@@ -412,11 +500,7 @@ const updateColumn = (variables) => fetch$1({
|
|
412
500
|
method: "patch",
|
413
501
|
...variables
|
414
502
|
});
|
415
|
-
const insertRecord = (variables) => fetch$1({
|
416
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
417
|
-
method: "post",
|
418
|
-
...variables
|
419
|
-
});
|
503
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
420
504
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
421
505
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
422
506
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -458,6 +542,7 @@ const operationsByTag = {
|
|
458
542
|
updateWorkspaceMemberRole,
|
459
543
|
removeWorkspaceMember,
|
460
544
|
inviteWorkspaceMember,
|
545
|
+
updateWorkspaceMemberInvite,
|
461
546
|
cancelWorkspaceMemberInvite,
|
462
547
|
resendWorkspaceMemberInvite,
|
463
548
|
acceptWorkspaceMemberInvite
|
@@ -466,6 +551,8 @@ const operationsByTag = {
|
|
466
551
|
getDatabaseList,
|
467
552
|
createDatabase,
|
468
553
|
deleteDatabase,
|
554
|
+
getDatabaseMetadata,
|
555
|
+
updateDatabaseMetadata,
|
469
556
|
getGitBranchesMapping,
|
470
557
|
addGitBranchesEntry,
|
471
558
|
removeGitBranchesEntry,
|
@@ -478,10 +565,28 @@ const operationsByTag = {
|
|
478
565
|
deleteBranch,
|
479
566
|
updateBranchMetadata,
|
480
567
|
getBranchMetadata,
|
568
|
+
getBranchStats
|
569
|
+
},
|
570
|
+
migrationRequests: {
|
571
|
+
listMigrationRequests,
|
572
|
+
createMigrationRequest,
|
573
|
+
getMigrationRequest,
|
574
|
+
updateMigrationRequest,
|
575
|
+
listMigrationRequestsCommits,
|
576
|
+
compareMigrationRequest,
|
577
|
+
getMigrationRequestIsMerged,
|
578
|
+
mergeMigrationRequest
|
579
|
+
},
|
580
|
+
branchSchema: {
|
481
581
|
getBranchMigrationHistory,
|
482
582
|
executeBranchMigrationPlan,
|
483
583
|
getBranchMigrationPlan,
|
484
|
-
|
584
|
+
compareBranchWithUserSchema,
|
585
|
+
compareBranchSchemas,
|
586
|
+
updateBranchSchema,
|
587
|
+
previewBranchSchemaEdit,
|
588
|
+
applyBranchSchemaEdit,
|
589
|
+
getBranchSchemaHistory
|
485
590
|
},
|
486
591
|
table: {
|
487
592
|
createTable,
|
@@ -510,9 +615,9 @@ const operationsByTag = {
|
|
510
615
|
};
|
511
616
|
|
512
617
|
function getHostUrl(provider, type) {
|
513
|
-
if (
|
618
|
+
if (isHostProviderAlias(provider)) {
|
514
619
|
return providers[provider][type];
|
515
|
-
} else if (
|
620
|
+
} else if (isHostProviderBuilder(provider)) {
|
516
621
|
return provider[type];
|
517
622
|
}
|
518
623
|
throw new Error("Invalid API provider");
|
@@ -527,10 +632,10 @@ const providers = {
|
|
527
632
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
528
633
|
}
|
529
634
|
};
|
530
|
-
function
|
635
|
+
function isHostProviderAlias(alias) {
|
531
636
|
return isString(alias) && Object.keys(providers).includes(alias);
|
532
637
|
}
|
533
|
-
function
|
638
|
+
function isHostProviderBuilder(builder) {
|
534
639
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
535
640
|
}
|
536
641
|
|
@@ -558,7 +663,8 @@ class XataApiClient {
|
|
558
663
|
__privateAdd$7(this, _extraProps, void 0);
|
559
664
|
__privateAdd$7(this, _namespaces, {});
|
560
665
|
const provider = options.host ?? "production";
|
561
|
-
const apiKey = options
|
666
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
667
|
+
const trace = options.trace ?? defaultTrace;
|
562
668
|
if (!apiKey) {
|
563
669
|
throw new Error("Could not resolve a valid apiKey");
|
564
670
|
}
|
@@ -566,7 +672,8 @@ class XataApiClient {
|
|
566
672
|
apiUrl: getHostUrl(provider, "main"),
|
567
673
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
568
674
|
fetchImpl: getFetchImplementation(options.fetch),
|
569
|
-
apiKey
|
675
|
+
apiKey,
|
676
|
+
trace
|
570
677
|
});
|
571
678
|
}
|
572
679
|
get user() {
|
@@ -599,6 +706,16 @@ class XataApiClient {
|
|
599
706
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
600
707
|
return __privateGet$7(this, _namespaces).records;
|
601
708
|
}
|
709
|
+
get migrationRequests() {
|
710
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
711
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
712
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
713
|
+
}
|
714
|
+
get branchSchema() {
|
715
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
716
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
717
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
718
|
+
}
|
602
719
|
}
|
603
720
|
_extraProps = new WeakMap();
|
604
721
|
_namespaces = new WeakMap();
|
@@ -689,6 +806,13 @@ class WorkspaceApi {
|
|
689
806
|
...this.extraProps
|
690
807
|
});
|
691
808
|
}
|
809
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
810
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
811
|
+
pathParams: { workspaceId, inviteId },
|
812
|
+
body: { role },
|
813
|
+
...this.extraProps
|
814
|
+
});
|
815
|
+
}
|
692
816
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
693
817
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
694
818
|
pathParams: { workspaceId, inviteId },
|
@@ -731,6 +855,19 @@ class DatabaseApi {
|
|
731
855
|
...this.extraProps
|
732
856
|
});
|
733
857
|
}
|
858
|
+
getDatabaseMetadata(workspace, dbName) {
|
859
|
+
return operationsByTag.database.getDatabaseMetadata({
|
860
|
+
pathParams: { workspace, dbName },
|
861
|
+
...this.extraProps
|
862
|
+
});
|
863
|
+
}
|
864
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
865
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
866
|
+
pathParams: { workspace, dbName },
|
867
|
+
body: options,
|
868
|
+
...this.extraProps
|
869
|
+
});
|
870
|
+
}
|
734
871
|
getGitBranchesMapping(workspace, dbName) {
|
735
872
|
return operationsByTag.database.getGitBranchesMapping({
|
736
873
|
pathParams: { workspace, dbName },
|
@@ -802,27 +939,6 @@ class BranchApi {
|
|
802
939
|
...this.extraProps
|
803
940
|
});
|
804
941
|
}
|
805
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
806
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
807
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
808
|
-
body: options,
|
809
|
-
...this.extraProps
|
810
|
-
});
|
811
|
-
}
|
812
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
813
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
814
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
815
|
-
body: migrationPlan,
|
816
|
-
...this.extraProps
|
817
|
-
});
|
818
|
-
}
|
819
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
820
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
821
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
822
|
-
body: schema,
|
823
|
-
...this.extraProps
|
824
|
-
});
|
825
|
-
}
|
826
942
|
getBranchStats(workspace, database, branch) {
|
827
943
|
return operationsByTag.branch.getBranchStats({
|
828
944
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -903,9 +1019,10 @@ class RecordsApi {
|
|
903
1019
|
constructor(extraProps) {
|
904
1020
|
this.extraProps = extraProps;
|
905
1021
|
}
|
906
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1022
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
907
1023
|
return operationsByTag.records.insertRecord({
|
908
1024
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1025
|
+
queryParams: options,
|
909
1026
|
body: record,
|
910
1027
|
...this.extraProps
|
911
1028
|
});
|
@@ -934,21 +1051,24 @@ class RecordsApi {
|
|
934
1051
|
...this.extraProps
|
935
1052
|
});
|
936
1053
|
}
|
937
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1054
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
938
1055
|
return operationsByTag.records.deleteRecord({
|
939
1056
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1057
|
+
queryParams: options,
|
940
1058
|
...this.extraProps
|
941
1059
|
});
|
942
1060
|
}
|
943
1061
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
944
1062
|
return operationsByTag.records.getRecord({
|
945
1063
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1064
|
+
queryParams: options,
|
946
1065
|
...this.extraProps
|
947
1066
|
});
|
948
1067
|
}
|
949
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1068
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
950
1069
|
return operationsByTag.records.bulkInsertTableRecords({
|
951
1070
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1071
|
+
queryParams: options,
|
952
1072
|
body: { records },
|
953
1073
|
...this.extraProps
|
954
1074
|
});
|
@@ -975,6 +1095,131 @@ class RecordsApi {
|
|
975
1095
|
});
|
976
1096
|
}
|
977
1097
|
}
|
1098
|
+
class MigrationRequestsApi {
|
1099
|
+
constructor(extraProps) {
|
1100
|
+
this.extraProps = extraProps;
|
1101
|
+
}
|
1102
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1103
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1104
|
+
pathParams: { workspace, dbName: database },
|
1105
|
+
body: options,
|
1106
|
+
...this.extraProps
|
1107
|
+
});
|
1108
|
+
}
|
1109
|
+
createMigrationRequest(workspace, database, options) {
|
1110
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1111
|
+
pathParams: { workspace, dbName: database },
|
1112
|
+
body: options,
|
1113
|
+
...this.extraProps
|
1114
|
+
});
|
1115
|
+
}
|
1116
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1117
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1118
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1119
|
+
...this.extraProps
|
1120
|
+
});
|
1121
|
+
}
|
1122
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1123
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1124
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1125
|
+
body: options,
|
1126
|
+
...this.extraProps
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1130
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1131
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1132
|
+
body: options,
|
1133
|
+
...this.extraProps
|
1134
|
+
});
|
1135
|
+
}
|
1136
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1137
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1138
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1139
|
+
...this.extraProps
|
1140
|
+
});
|
1141
|
+
}
|
1142
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1143
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1144
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1145
|
+
...this.extraProps
|
1146
|
+
});
|
1147
|
+
}
|
1148
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1149
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1150
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1151
|
+
...this.extraProps
|
1152
|
+
});
|
1153
|
+
}
|
1154
|
+
}
|
1155
|
+
class BranchSchemaApi {
|
1156
|
+
constructor(extraProps) {
|
1157
|
+
this.extraProps = extraProps;
|
1158
|
+
}
|
1159
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1160
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1161
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1162
|
+
body: options,
|
1163
|
+
...this.extraProps
|
1164
|
+
});
|
1165
|
+
}
|
1166
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1167
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1168
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1169
|
+
body: migrationPlan,
|
1170
|
+
...this.extraProps
|
1171
|
+
});
|
1172
|
+
}
|
1173
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1174
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1175
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1176
|
+
body: schema,
|
1177
|
+
...this.extraProps
|
1178
|
+
});
|
1179
|
+
}
|
1180
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1181
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1182
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1183
|
+
body: { schema },
|
1184
|
+
...this.extraProps
|
1185
|
+
});
|
1186
|
+
}
|
1187
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1188
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1189
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1190
|
+
body: { schema },
|
1191
|
+
...this.extraProps
|
1192
|
+
});
|
1193
|
+
}
|
1194
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1195
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1196
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1197
|
+
body: migration,
|
1198
|
+
...this.extraProps
|
1199
|
+
});
|
1200
|
+
}
|
1201
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1202
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1203
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1204
|
+
body: migration,
|
1205
|
+
...this.extraProps
|
1206
|
+
});
|
1207
|
+
}
|
1208
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1209
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1210
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1211
|
+
body: { edits },
|
1212
|
+
...this.extraProps
|
1213
|
+
});
|
1214
|
+
}
|
1215
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1216
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1217
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1218
|
+
body: options,
|
1219
|
+
...this.extraProps
|
1220
|
+
});
|
1221
|
+
}
|
1222
|
+
}
|
978
1223
|
|
979
1224
|
class XataApiPlugin {
|
980
1225
|
async build(options) {
|
@@ -1158,21 +1403,34 @@ const _Query = class {
|
|
1158
1403
|
}
|
1159
1404
|
filter(a, b) {
|
1160
1405
|
if (arguments.length === 1) {
|
1161
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1406
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1162
1407
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1163
1408
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1164
1409
|
} else {
|
1165
|
-
const
|
1410
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1411
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1166
1412
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1167
1413
|
}
|
1168
1414
|
}
|
1169
|
-
|
1415
|
+
defaultFilter(column, value) {
|
1416
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1417
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1418
|
+
return { $includes: value };
|
1419
|
+
}
|
1420
|
+
return value;
|
1421
|
+
}
|
1422
|
+
sort(column, direction = "asc") {
|
1170
1423
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1171
1424
|
const sort = [...originalSort, { column, direction }];
|
1172
1425
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1173
1426
|
}
|
1174
1427
|
select(columns) {
|
1175
|
-
return new _Query(
|
1428
|
+
return new _Query(
|
1429
|
+
__privateGet$5(this, _repository),
|
1430
|
+
__privateGet$5(this, _table$1),
|
1431
|
+
{ columns },
|
1432
|
+
__privateGet$5(this, _data)
|
1433
|
+
);
|
1176
1434
|
}
|
1177
1435
|
getPaginated(options = {}) {
|
1178
1436
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1195,11 +1453,20 @@ const _Query = class {
|
|
1195
1453
|
}
|
1196
1454
|
}
|
1197
1455
|
async getMany(options = {}) {
|
1198
|
-
const
|
1199
|
-
|
1456
|
+
const { pagination = {}, ...rest } = options;
|
1457
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1458
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1459
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1460
|
+
const results = [...page.records];
|
1461
|
+
while (page.hasNextPage() && results.length < size) {
|
1462
|
+
page = await page.nextPage();
|
1463
|
+
results.push(...page.records);
|
1464
|
+
}
|
1465
|
+
if (page.hasNextPage()) {
|
1200
1466
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1201
1467
|
}
|
1202
|
-
|
1468
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1469
|
+
return array;
|
1203
1470
|
}
|
1204
1471
|
async getAll(options = {}) {
|
1205
1472
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1297,203 +1564,228 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1297
1564
|
__accessCheck$4(obj, member, "access private method");
|
1298
1565
|
return method;
|
1299
1566
|
};
|
1300
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1567
|
+
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;
|
1301
1568
|
class Repository extends Query {
|
1302
1569
|
}
|
1303
1570
|
class RestRepository extends Query {
|
1304
1571
|
constructor(options) {
|
1305
|
-
super(
|
1572
|
+
super(
|
1573
|
+
null,
|
1574
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1575
|
+
{}
|
1576
|
+
);
|
1306
1577
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1307
1578
|
__privateAdd$4(this, _insertRecordWithId);
|
1308
1579
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
1309
1580
|
__privateAdd$4(this, _updateRecordWithID);
|
1310
1581
|
__privateAdd$4(this, _upsertRecordWithID);
|
1311
1582
|
__privateAdd$4(this, _deleteRecord);
|
1312
|
-
__privateAdd$4(this, _invalidateCache);
|
1313
|
-
__privateAdd$4(this, _setCacheRecord);
|
1314
|
-
__privateAdd$4(this, _getCacheRecord);
|
1315
1583
|
__privateAdd$4(this, _setCacheQuery);
|
1316
1584
|
__privateAdd$4(this, _getCacheQuery);
|
1317
1585
|
__privateAdd$4(this, _getSchemaTables$1);
|
1318
1586
|
__privateAdd$4(this, _table, void 0);
|
1319
1587
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1588
|
+
__privateAdd$4(this, _db, void 0);
|
1320
1589
|
__privateAdd$4(this, _cache, void 0);
|
1321
1590
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1591
|
+
__privateAdd$4(this, _trace, void 0);
|
1322
1592
|
__privateSet$4(this, _table, options.table);
|
1323
1593
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1324
|
-
this
|
1594
|
+
__privateSet$4(this, _db, options.db);
|
1325
1595
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1326
1596
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1597
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1598
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1599
|
+
return trace(name, fn, {
|
1600
|
+
...options2,
|
1601
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1602
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1603
|
+
[TraceAttributes.VERSION]: VERSION
|
1604
|
+
});
|
1605
|
+
});
|
1327
1606
|
}
|
1328
|
-
async create(a, b) {
|
1329
|
-
|
1330
|
-
if (a
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
const
|
1370
|
-
|
1371
|
-
const
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1607
|
+
async create(a, b, c) {
|
1608
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1609
|
+
if (Array.isArray(a)) {
|
1610
|
+
if (a.length === 0)
|
1611
|
+
return [];
|
1612
|
+
const columns = isStringArray(b) ? b : void 0;
|
1613
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1614
|
+
}
|
1615
|
+
if (isString(a) && isObject(b)) {
|
1616
|
+
if (a === "")
|
1617
|
+
throw new Error("The id can't be empty");
|
1618
|
+
const columns = isStringArray(c) ? c : void 0;
|
1619
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1620
|
+
}
|
1621
|
+
if (isObject(a) && isString(a.id)) {
|
1622
|
+
if (a.id === "")
|
1623
|
+
throw new Error("The id can't be empty");
|
1624
|
+
const columns = isStringArray(b) ? b : void 0;
|
1625
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1626
|
+
}
|
1627
|
+
if (isObject(a)) {
|
1628
|
+
const columns = isStringArray(b) ? b : void 0;
|
1629
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1630
|
+
}
|
1631
|
+
throw new Error("Invalid arguments for create method");
|
1632
|
+
});
|
1633
|
+
}
|
1634
|
+
async read(a, b) {
|
1635
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1636
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1637
|
+
if (Array.isArray(a)) {
|
1638
|
+
if (a.length === 0)
|
1639
|
+
return [];
|
1640
|
+
const ids = a.map((item) => extractId(item));
|
1641
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1642
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1643
|
+
acc[object.id] = object;
|
1644
|
+
return acc;
|
1645
|
+
}, {});
|
1646
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1647
|
+
}
|
1648
|
+
const id = extractId(a);
|
1649
|
+
if (id) {
|
1650
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1651
|
+
try {
|
1652
|
+
const response = await getRecord({
|
1653
|
+
pathParams: {
|
1654
|
+
workspace: "{workspaceId}",
|
1655
|
+
dbBranchName: "{dbBranch}",
|
1656
|
+
tableName: __privateGet$4(this, _table),
|
1657
|
+
recordId: id
|
1658
|
+
},
|
1659
|
+
queryParams: { columns },
|
1660
|
+
...fetchProps
|
1661
|
+
});
|
1662
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1663
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1664
|
+
} catch (e) {
|
1665
|
+
if (isObject(e) && e.status === 404) {
|
1666
|
+
return null;
|
1667
|
+
}
|
1668
|
+
throw e;
|
1380
1669
|
}
|
1381
|
-
throw e;
|
1382
1670
|
}
|
1383
|
-
|
1671
|
+
return null;
|
1672
|
+
});
|
1384
1673
|
}
|
1385
|
-
async update(a, b) {
|
1386
|
-
|
1387
|
-
if (a
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1674
|
+
async update(a, b, c) {
|
1675
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1676
|
+
if (Array.isArray(a)) {
|
1677
|
+
if (a.length === 0)
|
1678
|
+
return [];
|
1679
|
+
if (a.length > 100) {
|
1680
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1681
|
+
}
|
1682
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1683
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1391
1684
|
}
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1396
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1397
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1398
|
-
return record;
|
1399
|
-
}
|
1400
|
-
if (isObject(a) && isString(a.id)) {
|
1401
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1402
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1403
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1404
|
-
return record;
|
1405
|
-
}
|
1406
|
-
throw new Error("Invalid arguments for update method");
|
1407
|
-
}
|
1408
|
-
async createOrUpdate(a, b) {
|
1409
|
-
if (Array.isArray(a)) {
|
1410
|
-
if (a.length === 0)
|
1411
|
-
return [];
|
1412
|
-
if (a.length > 100) {
|
1413
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1685
|
+
if (isString(a) && isObject(b)) {
|
1686
|
+
const columns = isStringArray(c) ? c : void 0;
|
1687
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1414
1688
|
}
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1419
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
|
1420
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1421
|
-
return record;
|
1422
|
-
}
|
1423
|
-
if (isObject(a) && isString(a.id)) {
|
1424
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1425
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1426
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1427
|
-
return record;
|
1428
|
-
}
|
1429
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1430
|
-
}
|
1431
|
-
async delete(a) {
|
1432
|
-
if (Array.isArray(a)) {
|
1433
|
-
if (a.length === 0)
|
1434
|
-
return;
|
1435
|
-
if (a.length > 100) {
|
1436
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1689
|
+
if (isObject(a) && isString(a.id)) {
|
1690
|
+
const columns = isStringArray(b) ? b : void 0;
|
1691
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1437
1692
|
}
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1693
|
+
throw new Error("Invalid arguments for update method");
|
1694
|
+
});
|
1695
|
+
}
|
1696
|
+
async createOrUpdate(a, b, c) {
|
1697
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1698
|
+
if (Array.isArray(a)) {
|
1699
|
+
if (a.length === 0)
|
1700
|
+
return [];
|
1701
|
+
if (a.length > 100) {
|
1702
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1703
|
+
}
|
1704
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1705
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1706
|
+
}
|
1707
|
+
if (isString(a) && isObject(b)) {
|
1708
|
+
const columns = isStringArray(c) ? c : void 0;
|
1709
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1710
|
+
}
|
1711
|
+
if (isObject(a) && isString(a.id)) {
|
1712
|
+
const columns = isStringArray(c) ? c : void 0;
|
1713
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1714
|
+
}
|
1715
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1716
|
+
});
|
1717
|
+
}
|
1718
|
+
async delete(a, b) {
|
1719
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1720
|
+
if (Array.isArray(a)) {
|
1721
|
+
if (a.length === 0)
|
1722
|
+
return [];
|
1723
|
+
if (a.length > 100) {
|
1724
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1725
|
+
}
|
1726
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1727
|
+
}
|
1728
|
+
if (isString(a)) {
|
1729
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1730
|
+
}
|
1731
|
+
if (isObject(a) && isString(a.id)) {
|
1732
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1733
|
+
}
|
1734
|
+
throw new Error("Invalid arguments for delete method");
|
1735
|
+
});
|
1452
1736
|
}
|
1453
1737
|
async search(query, options = {}) {
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1738
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1739
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1740
|
+
const { records } = await searchTable({
|
1741
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1742
|
+
body: {
|
1743
|
+
query,
|
1744
|
+
fuzziness: options.fuzziness,
|
1745
|
+
prefix: options.prefix,
|
1746
|
+
highlight: options.highlight,
|
1747
|
+
filter: options.filter,
|
1748
|
+
boosters: options.boosters
|
1749
|
+
},
|
1750
|
+
...fetchProps
|
1751
|
+
});
|
1752
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1753
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1464
1754
|
});
|
1465
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1466
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1467
1755
|
}
|
1468
1756
|
async query(query) {
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1757
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1758
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1759
|
+
if (cacheQuery)
|
1760
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1761
|
+
const data = query.getQueryOptions();
|
1762
|
+
const body = {
|
1763
|
+
filter: cleanFilter(data.filter),
|
1764
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1765
|
+
page: data.pagination,
|
1766
|
+
columns: data.columns
|
1767
|
+
};
|
1768
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1769
|
+
const { meta, records: objects } = await queryTable({
|
1770
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1771
|
+
body,
|
1772
|
+
...fetchProps
|
1773
|
+
});
|
1774
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1775
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1776
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1777
|
+
return new Page(query, meta, records);
|
1484
1778
|
});
|
1485
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1486
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1487
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1488
|
-
return new Page(query, meta, records);
|
1489
1779
|
}
|
1490
1780
|
}
|
1491
1781
|
_table = new WeakMap();
|
1492
1782
|
_getFetchProps = new WeakMap();
|
1783
|
+
_db = new WeakMap();
|
1493
1784
|
_cache = new WeakMap();
|
1494
1785
|
_schemaTables$2 = new WeakMap();
|
1786
|
+
_trace = new WeakMap();
|
1495
1787
|
_insertRecordWithoutId = new WeakSet();
|
1496
|
-
insertRecordWithoutId_fn = async function(object) {
|
1788
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1497
1789
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1498
1790
|
const record = transformObjectLinks(object);
|
1499
1791
|
const response = await insertRecord({
|
@@ -1502,17 +1794,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1502
1794
|
dbBranchName: "{dbBranch}",
|
1503
1795
|
tableName: __privateGet$4(this, _table)
|
1504
1796
|
},
|
1797
|
+
queryParams: { columns },
|
1505
1798
|
body: record,
|
1506
1799
|
...fetchProps
|
1507
1800
|
});
|
1508
|
-
const
|
1509
|
-
|
1510
|
-
throw new Error("The server failed to save the record");
|
1511
|
-
}
|
1512
|
-
return finalObject;
|
1801
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1802
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1513
1803
|
};
|
1514
1804
|
_insertRecordWithId = new WeakSet();
|
1515
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1805
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1516
1806
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1517
1807
|
const record = transformObjectLinks(object);
|
1518
1808
|
const response = await insertRecordWithID({
|
@@ -1523,92 +1813,78 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1523
1813
|
recordId
|
1524
1814
|
},
|
1525
1815
|
body: record,
|
1526
|
-
queryParams: { createOnly: true },
|
1816
|
+
queryParams: { createOnly: true, columns },
|
1527
1817
|
...fetchProps
|
1528
1818
|
});
|
1529
|
-
const
|
1530
|
-
|
1531
|
-
throw new Error("The server failed to save the record");
|
1532
|
-
}
|
1533
|
-
return finalObject;
|
1819
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1820
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1534
1821
|
};
|
1535
1822
|
_bulkInsertTableRecords = new WeakSet();
|
1536
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1823
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1537
1824
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1538
1825
|
const records = objects.map((object) => transformObjectLinks(object));
|
1539
|
-
const
|
1826
|
+
const response = await bulkInsertTableRecords({
|
1540
1827
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1828
|
+
queryParams: { columns },
|
1541
1829
|
body: { records },
|
1542
1830
|
...fetchProps
|
1543
1831
|
});
|
1544
|
-
|
1545
|
-
|
1546
|
-
throw new Error("The server failed to save some records");
|
1832
|
+
if (!isResponseWithRecords(response)) {
|
1833
|
+
throw new Error("Request included columns but server didn't include them");
|
1547
1834
|
}
|
1548
|
-
const
|
1549
|
-
|
1550
|
-
return acc;
|
1551
|
-
}, {});
|
1552
|
-
return recordIDs.map((id) => dictionary[id]);
|
1835
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1836
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1553
1837
|
};
|
1554
1838
|
_updateRecordWithID = new WeakSet();
|
1555
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1839
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1556
1840
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1557
1841
|
const record = transformObjectLinks(object);
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1842
|
+
try {
|
1843
|
+
const response = await updateRecordWithID({
|
1844
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1845
|
+
queryParams: { columns },
|
1846
|
+
body: record,
|
1847
|
+
...fetchProps
|
1848
|
+
});
|
1849
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1850
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1851
|
+
} catch (e) {
|
1852
|
+
if (isObject(e) && e.status === 404) {
|
1853
|
+
return null;
|
1854
|
+
}
|
1855
|
+
throw e;
|
1856
|
+
}
|
1567
1857
|
};
|
1568
1858
|
_upsertRecordWithID = new WeakSet();
|
1569
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1859
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1570
1860
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1571
1861
|
const response = await upsertRecordWithID({
|
1572
1862
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1863
|
+
queryParams: { columns },
|
1573
1864
|
body: object,
|
1574
1865
|
...fetchProps
|
1575
1866
|
});
|
1576
|
-
const
|
1577
|
-
|
1578
|
-
throw new Error("The server failed to save the record");
|
1579
|
-
return item;
|
1867
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1868
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1580
1869
|
};
|
1581
1870
|
_deleteRecord = new WeakSet();
|
1582
|
-
deleteRecord_fn = async function(recordId) {
|
1871
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1583
1872
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
await __privateGet$4(this, _cache).delete(key);
|
1873
|
+
try {
|
1874
|
+
const response = await deleteRecord({
|
1875
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1876
|
+
queryParams: { columns },
|
1877
|
+
...fetchProps
|
1878
|
+
});
|
1879
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1880
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1881
|
+
} catch (e) {
|
1882
|
+
if (isObject(e) && e.status === 404) {
|
1883
|
+
return null;
|
1884
|
+
}
|
1885
|
+
throw e;
|
1598
1886
|
}
|
1599
1887
|
};
|
1600
|
-
_setCacheRecord = new WeakSet();
|
1601
|
-
setCacheRecord_fn = async function(record) {
|
1602
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1603
|
-
return;
|
1604
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1605
|
-
};
|
1606
|
-
_getCacheRecord = new WeakSet();
|
1607
|
-
getCacheRecord_fn = async function(recordId) {
|
1608
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1609
|
-
return null;
|
1610
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1611
|
-
};
|
1612
1888
|
_setCacheQuery = new WeakSet();
|
1613
1889
|
setCacheQuery_fn = async function(query, meta, records) {
|
1614
1890
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1674,11 +1950,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1674
1950
|
}
|
1675
1951
|
}
|
1676
1952
|
}
|
1677
|
-
result.read = function() {
|
1678
|
-
return db[table].read(result["id"]);
|
1953
|
+
result.read = function(columns2) {
|
1954
|
+
return db[table].read(result["id"], columns2);
|
1679
1955
|
};
|
1680
|
-
result.update = function(data) {
|
1681
|
-
return db[table].update(result["id"], data);
|
1956
|
+
result.update = function(data, columns2) {
|
1957
|
+
return db[table].update(result["id"], data, columns2);
|
1682
1958
|
};
|
1683
1959
|
result.delete = function() {
|
1684
1960
|
return db[table].delete(result["id"]);
|
@@ -1692,14 +1968,21 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1692
1968
|
Object.freeze(result);
|
1693
1969
|
return result;
|
1694
1970
|
};
|
1695
|
-
function
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
if (
|
1700
|
-
return
|
1701
|
-
|
1702
|
-
|
1971
|
+
function isResponseWithRecords(value) {
|
1972
|
+
return isObject(value) && Array.isArray(value.records);
|
1973
|
+
}
|
1974
|
+
function extractId(value) {
|
1975
|
+
if (isString(value))
|
1976
|
+
return value;
|
1977
|
+
if (isObject(value) && isString(value.id))
|
1978
|
+
return value.id;
|
1979
|
+
return void 0;
|
1980
|
+
}
|
1981
|
+
function cleanFilter(filter) {
|
1982
|
+
if (!filter)
|
1983
|
+
return void 0;
|
1984
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1985
|
+
return values.length > 0 ? filter : void 0;
|
1703
1986
|
}
|
1704
1987
|
|
1705
1988
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1726,7 +2009,6 @@ class SimpleCache {
|
|
1726
2009
|
__privateAdd$3(this, _map, void 0);
|
1727
2010
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1728
2011
|
this.capacity = options.max ?? 500;
|
1729
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1730
2012
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1731
2013
|
}
|
1732
2014
|
async getAll() {
|
@@ -1752,18 +2034,25 @@ class SimpleCache {
|
|
1752
2034
|
}
|
1753
2035
|
_map = new WeakMap();
|
1754
2036
|
|
1755
|
-
const
|
1756
|
-
const
|
1757
|
-
const
|
1758
|
-
const
|
1759
|
-
const
|
1760
|
-
const
|
2037
|
+
const greaterThan = (value) => ({ $gt: value });
|
2038
|
+
const gt = greaterThan;
|
2039
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2040
|
+
const greaterEquals = greaterThanEquals;
|
2041
|
+
const gte = greaterThanEquals;
|
2042
|
+
const ge = greaterThanEquals;
|
2043
|
+
const lessThan = (value) => ({ $lt: value });
|
2044
|
+
const lt = lessThan;
|
2045
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2046
|
+
const lessEquals = lessThanEquals;
|
2047
|
+
const lte = lessThanEquals;
|
2048
|
+
const le = lessThanEquals;
|
1761
2049
|
const exists = (column) => ({ $exists: column });
|
1762
2050
|
const notExists = (column) => ({ $notExists: column });
|
1763
2051
|
const startsWith = (value) => ({ $startsWith: value });
|
1764
2052
|
const endsWith = (value) => ({ $endsWith: value });
|
1765
2053
|
const pattern = (value) => ({ $pattern: value });
|
1766
2054
|
const is = (value) => ({ $is: value });
|
2055
|
+
const equals = is;
|
1767
2056
|
const isNot = (value) => ({ $isNot: value });
|
1768
2057
|
const contains = (value) => ({ $contains: value });
|
1769
2058
|
const includes = (value) => ({ $includes: value });
|
@@ -1798,16 +2087,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1798
2087
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1799
2088
|
}
|
1800
2089
|
build(pluginOptions) {
|
1801
|
-
const db = new Proxy(
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
2090
|
+
const db = new Proxy(
|
2091
|
+
{},
|
2092
|
+
{
|
2093
|
+
get: (_target, table) => {
|
2094
|
+
if (!isString(table))
|
2095
|
+
throw new Error("Invalid table name");
|
2096
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2097
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2098
|
+
}
|
2099
|
+
return __privateGet$2(this, _tables)[table];
|
1807
2100
|
}
|
1808
|
-
return __privateGet$2(this, _tables)[table];
|
1809
2101
|
}
|
1810
|
-
|
2102
|
+
);
|
1811
2103
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1812
2104
|
for (const table of tableNames) {
|
1813
2105
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1877,10 +2169,10 @@ _schemaTables = new WeakMap();
|
|
1877
2169
|
_search = new WeakSet();
|
1878
2170
|
search_fn = async function(query, options, getFetchProps) {
|
1879
2171
|
const fetchProps = await getFetchProps();
|
1880
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
2172
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1881
2173
|
const { records } = await searchBranch({
|
1882
2174
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1883
|
-
body: { tables, query, fuzziness, highlight },
|
2175
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1884
2176
|
...fetchProps
|
1885
2177
|
});
|
1886
2178
|
return records;
|
@@ -1921,9 +2213,13 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1921
2213
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1922
2214
|
const apiKey = options?.apiKey || getAPIKey();
|
1923
2215
|
if (!databaseURL)
|
1924
|
-
throw new Error(
|
2216
|
+
throw new Error(
|
2217
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2218
|
+
);
|
1925
2219
|
if (!apiKey)
|
1926
|
-
throw new Error(
|
2220
|
+
throw new Error(
|
2221
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2222
|
+
);
|
1927
2223
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1928
2224
|
const [workspace] = host.split(".");
|
1929
2225
|
const { fallbackBranch } = getEnvironment();
|
@@ -1933,7 +2229,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1933
2229
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1934
2230
|
workspacesApiUrl: `${protocol}//${host}`,
|
1935
2231
|
pathParams: { dbName, workspace },
|
1936
|
-
queryParams: { gitBranch, fallbackBranch }
|
2232
|
+
queryParams: { gitBranch, fallbackBranch },
|
2233
|
+
trace: defaultTrace
|
1937
2234
|
});
|
1938
2235
|
return branch;
|
1939
2236
|
}
|
@@ -1941,9 +2238,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1941
2238
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1942
2239
|
const apiKey = options?.apiKey || getAPIKey();
|
1943
2240
|
if (!databaseURL)
|
1944
|
-
throw new Error(
|
2241
|
+
throw new Error(
|
2242
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2243
|
+
);
|
1945
2244
|
if (!apiKey)
|
1946
|
-
throw new Error(
|
2245
|
+
throw new Error(
|
2246
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2247
|
+
);
|
1947
2248
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1948
2249
|
const [workspace] = host.split(".");
|
1949
2250
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1953,7 +2254,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1953
2254
|
apiUrl: databaseURL,
|
1954
2255
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1955
2256
|
workspacesApiUrl: `${protocol}//${host}`,
|
1956
|
-
pathParams: { dbBranchName, workspace }
|
2257
|
+
pathParams: { dbBranchName, workspace },
|
2258
|
+
trace: defaultTrace
|
1957
2259
|
});
|
1958
2260
|
} catch (err) {
|
1959
2261
|
if (isObject(err) && err.status === 404)
|
@@ -1993,17 +2295,20 @@ var __privateMethod = (obj, member, method) => {
|
|
1993
2295
|
return method;
|
1994
2296
|
};
|
1995
2297
|
const buildClient = (plugins) => {
|
1996
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2298
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1997
2299
|
return _a = class {
|
1998
2300
|
constructor(options = {}, schemaTables) {
|
1999
2301
|
__privateAdd(this, _parseOptions);
|
2000
2302
|
__privateAdd(this, _getFetchProps);
|
2001
2303
|
__privateAdd(this, _evaluateBranch);
|
2002
2304
|
__privateAdd(this, _branch, void 0);
|
2305
|
+
__privateAdd(this, _options, void 0);
|
2003
2306
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2307
|
+
__privateSet(this, _options, safeOptions);
|
2004
2308
|
const pluginOptions = {
|
2005
2309
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2006
|
-
cache: safeOptions.cache
|
2310
|
+
cache: safeOptions.cache,
|
2311
|
+
trace: safeOptions.trace
|
2007
2312
|
};
|
2008
2313
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2009
2314
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2022,22 +2327,26 @@ const buildClient = (plugins) => {
|
|
2022
2327
|
}
|
2023
2328
|
}
|
2024
2329
|
}
|
2025
|
-
|
2330
|
+
async getConfig() {
|
2331
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2332
|
+
const branch = await __privateGet(this, _options).branch();
|
2333
|
+
return { databaseURL, branch };
|
2334
|
+
}
|
2335
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
2026
2336
|
const fetch = getFetchImplementation(options?.fetch);
|
2027
2337
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2028
2338
|
const apiKey = options?.apiKey || getAPIKey();
|
2029
|
-
const cache = options?.cache ?? new SimpleCache({
|
2339
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2340
|
+
const trace = options?.trace ?? defaultTrace;
|
2030
2341
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2031
|
-
if (!
|
2032
|
-
throw new Error("
|
2342
|
+
if (!apiKey) {
|
2343
|
+
throw new Error("Option apiKey is required");
|
2033
2344
|
}
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
apiKey,
|
2038
|
-
|
2039
|
-
branch
|
2040
|
-
}) {
|
2345
|
+
if (!databaseURL) {
|
2346
|
+
throw new Error("Option databaseURL is required");
|
2347
|
+
}
|
2348
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2349
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2041
2350
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2042
2351
|
if (!branchValue)
|
2043
2352
|
throw new Error("Unable to resolve branch value");
|
@@ -2047,9 +2356,10 @@ const buildClient = (plugins) => {
|
|
2047
2356
|
apiUrl: "",
|
2048
2357
|
workspacesApiUrl: (path, params) => {
|
2049
2358
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2050
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2359
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2051
2360
|
return databaseURL + newPath;
|
2052
|
-
}
|
2361
|
+
},
|
2362
|
+
trace
|
2053
2363
|
};
|
2054
2364
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2055
2365
|
if (__privateGet(this, _branch))
|
@@ -2072,6 +2382,88 @@ const buildClient = (plugins) => {
|
|
2072
2382
|
class BaseClient extends buildClient() {
|
2073
2383
|
}
|
2074
2384
|
|
2385
|
+
const META = "__";
|
2386
|
+
const VALUE = "___";
|
2387
|
+
class Serializer {
|
2388
|
+
constructor() {
|
2389
|
+
this.classes = {};
|
2390
|
+
}
|
2391
|
+
add(clazz) {
|
2392
|
+
this.classes[clazz.name] = clazz;
|
2393
|
+
}
|
2394
|
+
toJSON(data) {
|
2395
|
+
function visit(obj) {
|
2396
|
+
if (Array.isArray(obj))
|
2397
|
+
return obj.map(visit);
|
2398
|
+
const type = typeof obj;
|
2399
|
+
if (type === "undefined")
|
2400
|
+
return { [META]: "undefined" };
|
2401
|
+
if (type === "bigint")
|
2402
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2403
|
+
if (obj === null || type !== "object")
|
2404
|
+
return obj;
|
2405
|
+
const constructor = obj.constructor;
|
2406
|
+
const o = { [META]: constructor.name };
|
2407
|
+
for (const [key, value] of Object.entries(obj)) {
|
2408
|
+
o[key] = visit(value);
|
2409
|
+
}
|
2410
|
+
if (constructor === Date)
|
2411
|
+
o[VALUE] = obj.toISOString();
|
2412
|
+
if (constructor === Map)
|
2413
|
+
o[VALUE] = Object.fromEntries(obj);
|
2414
|
+
if (constructor === Set)
|
2415
|
+
o[VALUE] = [...obj];
|
2416
|
+
return o;
|
2417
|
+
}
|
2418
|
+
return JSON.stringify(visit(data));
|
2419
|
+
}
|
2420
|
+
fromJSON(json) {
|
2421
|
+
return JSON.parse(json, (key, value) => {
|
2422
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2423
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2424
|
+
const constructor = this.classes[clazz];
|
2425
|
+
if (constructor) {
|
2426
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2427
|
+
}
|
2428
|
+
if (clazz === "Date")
|
2429
|
+
return new Date(val);
|
2430
|
+
if (clazz === "Set")
|
2431
|
+
return new Set(val);
|
2432
|
+
if (clazz === "Map")
|
2433
|
+
return new Map(Object.entries(val));
|
2434
|
+
if (clazz === "bigint")
|
2435
|
+
return BigInt(val);
|
2436
|
+
if (clazz === "undefined")
|
2437
|
+
return void 0;
|
2438
|
+
return rest;
|
2439
|
+
}
|
2440
|
+
return value;
|
2441
|
+
});
|
2442
|
+
}
|
2443
|
+
}
|
2444
|
+
const defaultSerializer = new Serializer();
|
2445
|
+
const serialize = (data) => {
|
2446
|
+
return defaultSerializer.toJSON(data);
|
2447
|
+
};
|
2448
|
+
const deserialize = (json) => {
|
2449
|
+
return defaultSerializer.fromJSON(json);
|
2450
|
+
};
|
2451
|
+
|
2452
|
+
function buildWorkerRunner(config) {
|
2453
|
+
return function xataWorker(name, _worker) {
|
2454
|
+
return async (...args) => {
|
2455
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2456
|
+
const result = await fetch(url, {
|
2457
|
+
method: "POST",
|
2458
|
+
headers: { "Content-Type": "application/json" },
|
2459
|
+
body: serialize({ args })
|
2460
|
+
});
|
2461
|
+
const text = await result.text();
|
2462
|
+
return deserialize(text);
|
2463
|
+
};
|
2464
|
+
};
|
2465
|
+
}
|
2466
|
+
|
2075
2467
|
class XataError extends Error {
|
2076
2468
|
constructor(message, status) {
|
2077
2469
|
super(message);
|
@@ -2079,5 +2471,5 @@ class XataError extends Error {
|
|
2079
2471
|
}
|
2080
2472
|
}
|
2081
2473
|
|
2082
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, 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, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
2474
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2083
2475
|
//# sourceMappingURL=index.mjs.map
|