@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.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
|
}
|
@@ -35,6 +57,9 @@ function isDefined(value) {
|
|
35
57
|
function isString(value) {
|
36
58
|
return isDefined(value) && typeof value === "string";
|
37
59
|
}
|
60
|
+
function isStringArray(value) {
|
61
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
62
|
+
}
|
38
63
|
function toBase64(value) {
|
39
64
|
try {
|
40
65
|
return btoa(value);
|
@@ -107,18 +132,20 @@ function getGlobalFallbackBranch() {
|
|
107
132
|
}
|
108
133
|
async function getGitBranch() {
|
109
134
|
const cmd = ["git", "branch", "--show-current"];
|
135
|
+
const fullCmd = cmd.join(" ");
|
110
136
|
const nodeModule = ["child", "process"].join("_");
|
137
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
111
138
|
try {
|
112
139
|
if (typeof require === "function") {
|
113
|
-
return require(nodeModule).execSync(
|
140
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
114
141
|
}
|
115
142
|
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
116
|
-
return execSync(
|
143
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
117
144
|
} catch (err) {
|
118
145
|
}
|
119
146
|
try {
|
120
147
|
if (isObject(Deno)) {
|
121
|
-
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "
|
148
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
122
149
|
return new TextDecoder().decode(await process2.output()).trim();
|
123
150
|
}
|
124
151
|
} catch (err) {
|
@@ -138,12 +165,14 @@ function getFetchImplementation(userFetch) {
|
|
138
165
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
139
166
|
const fetchImpl = userFetch ?? globalFetch;
|
140
167
|
if (!fetchImpl) {
|
141
|
-
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
|
+
);
|
142
171
|
}
|
143
172
|
return fetchImpl;
|
144
173
|
}
|
145
174
|
|
146
|
-
const VERSION = "0.0.0-alpha.
|
175
|
+
const VERSION = "0.0.0-alpha.vfc5c289";
|
147
176
|
|
148
177
|
class ErrorWithCause extends Error {
|
149
178
|
constructor(message, options) {
|
@@ -194,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
194
223
|
}, {});
|
195
224
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
196
225
|
const queryString = query.length > 0 ? `?${query}` : "";
|
197
|
-
|
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;
|
198
230
|
};
|
199
231
|
function buildBaseUrl({
|
200
232
|
path,
|
@@ -202,10 +234,10 @@ function buildBaseUrl({
|
|
202
234
|
apiUrl,
|
203
235
|
pathParams
|
204
236
|
}) {
|
205
|
-
if (
|
237
|
+
if (pathParams?.workspace === void 0)
|
206
238
|
return `${apiUrl}${path}`;
|
207
239
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
208
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
240
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
209
241
|
}
|
210
242
|
function hostHeader(url) {
|
211
243
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -222,34 +254,61 @@ async function fetch$1({
|
|
222
254
|
fetchImpl,
|
223
255
|
apiKey,
|
224
256
|
apiUrl,
|
225
|
-
workspacesApiUrl
|
257
|
+
workspacesApiUrl,
|
258
|
+
trace
|
226
259
|
}) {
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
260
|
+
return trace(
|
261
|
+
`${method.toUpperCase()} ${path}`,
|
262
|
+
async ({ setAttributes }) => {
|
263
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
264
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
265
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
266
|
+
setAttributes({
|
267
|
+
[TraceAttributes.HTTP_URL]: url,
|
268
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
269
|
+
});
|
270
|
+
const response = await fetchImpl(url, {
|
271
|
+
method: method.toUpperCase(),
|
272
|
+
body: body ? JSON.stringify(body) : void 0,
|
273
|
+
headers: {
|
274
|
+
"Content-Type": "application/json",
|
275
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
276
|
+
...headers,
|
277
|
+
...hostHeader(fullUrl),
|
278
|
+
Authorization: `Bearer ${apiKey}`
|
279
|
+
}
|
280
|
+
});
|
281
|
+
if (response.status === 204) {
|
282
|
+
return {};
|
283
|
+
}
|
284
|
+
const { host, protocol } = parseUrl(response.url);
|
285
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
286
|
+
setAttributes({
|
287
|
+
[TraceAttributes.KIND]: "http",
|
288
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
289
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
290
|
+
[TraceAttributes.HTTP_HOST]: host,
|
291
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
292
|
+
});
|
293
|
+
try {
|
294
|
+
const jsonResponse = await response.json();
|
295
|
+
if (response.ok) {
|
296
|
+
return jsonResponse;
|
297
|
+
}
|
298
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
299
|
+
} catch (error) {
|
300
|
+
throw new FetcherError(response.status, error, requestId);
|
301
|
+
}
|
302
|
+
},
|
303
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
304
|
+
);
|
305
|
+
}
|
306
|
+
function parseUrl(url) {
|
245
307
|
try {
|
246
|
-
const
|
247
|
-
|
248
|
-
return jsonResponse;
|
249
|
-
}
|
250
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
308
|
+
const { host, protocol } = new URL(url);
|
309
|
+
return { host, protocol };
|
251
310
|
} catch (error) {
|
252
|
-
|
311
|
+
return {};
|
253
312
|
}
|
254
313
|
}
|
255
314
|
|
@@ -308,6 +367,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
308
367
|
...variables
|
309
368
|
});
|
310
369
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
370
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
311
371
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
312
372
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
313
373
|
method: "delete",
|
@@ -343,6 +403,12 @@ const deleteDatabase = (variables) => fetch$1({
|
|
343
403
|
method: "delete",
|
344
404
|
...variables
|
345
405
|
});
|
406
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
407
|
+
url: "/dbs/{dbName}/metadata",
|
408
|
+
method: "get",
|
409
|
+
...variables
|
410
|
+
});
|
411
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
346
412
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
347
413
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
348
414
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -351,16 +417,28 @@ const resolveBranch = (variables) => fetch$1({
|
|
351
417
|
method: "get",
|
352
418
|
...variables
|
353
419
|
});
|
354
|
-
const
|
355
|
-
|
420
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
421
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
422
|
+
const getMigrationRequest = (variables) => fetch$1({
|
423
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
356
424
|
method: "get",
|
357
425
|
...variables
|
358
426
|
});
|
359
|
-
const
|
427
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
428
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
429
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
430
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
431
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
432
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
433
|
+
method: "post",
|
434
|
+
...variables
|
435
|
+
});
|
436
|
+
const getBranchDetails = (variables) => fetch$1({
|
360
437
|
url: "/db/{dbBranchName}",
|
361
|
-
method: "
|
438
|
+
method: "get",
|
362
439
|
...variables
|
363
440
|
});
|
441
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
364
442
|
const deleteBranch = (variables) => fetch$1({
|
365
443
|
url: "/db/{dbBranchName}",
|
366
444
|
method: "delete",
|
@@ -379,6 +457,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
379
457
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
380
458
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
381
459
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
460
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
461
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
462
|
+
const updateBranchSchema = (variables) => fetch$1({
|
463
|
+
url: "/db/{dbBranchName}/schema/update",
|
464
|
+
method: "post",
|
465
|
+
...variables
|
466
|
+
});
|
467
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
468
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
469
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
382
470
|
const getBranchStats = (variables) => fetch$1({
|
383
471
|
url: "/db/{dbBranchName}/stats",
|
384
472
|
method: "get",
|
@@ -434,11 +522,7 @@ const updateColumn = (variables) => fetch$1({
|
|
434
522
|
method: "patch",
|
435
523
|
...variables
|
436
524
|
});
|
437
|
-
const insertRecord = (variables) => fetch$1({
|
438
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
439
|
-
method: "post",
|
440
|
-
...variables
|
441
|
-
});
|
525
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
442
526
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
443
527
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
444
528
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -480,6 +564,7 @@ const operationsByTag = {
|
|
480
564
|
updateWorkspaceMemberRole,
|
481
565
|
removeWorkspaceMember,
|
482
566
|
inviteWorkspaceMember,
|
567
|
+
updateWorkspaceMemberInvite,
|
483
568
|
cancelWorkspaceMemberInvite,
|
484
569
|
resendWorkspaceMemberInvite,
|
485
570
|
acceptWorkspaceMemberInvite
|
@@ -488,6 +573,8 @@ const operationsByTag = {
|
|
488
573
|
getDatabaseList,
|
489
574
|
createDatabase,
|
490
575
|
deleteDatabase,
|
576
|
+
getDatabaseMetadata,
|
577
|
+
updateDatabaseMetadata,
|
491
578
|
getGitBranchesMapping,
|
492
579
|
addGitBranchesEntry,
|
493
580
|
removeGitBranchesEntry,
|
@@ -500,10 +587,28 @@ const operationsByTag = {
|
|
500
587
|
deleteBranch,
|
501
588
|
updateBranchMetadata,
|
502
589
|
getBranchMetadata,
|
590
|
+
getBranchStats
|
591
|
+
},
|
592
|
+
migrationRequests: {
|
593
|
+
listMigrationRequests,
|
594
|
+
createMigrationRequest,
|
595
|
+
getMigrationRequest,
|
596
|
+
updateMigrationRequest,
|
597
|
+
listMigrationRequestsCommits,
|
598
|
+
compareMigrationRequest,
|
599
|
+
getMigrationRequestIsMerged,
|
600
|
+
mergeMigrationRequest
|
601
|
+
},
|
602
|
+
branchSchema: {
|
503
603
|
getBranchMigrationHistory,
|
504
604
|
executeBranchMigrationPlan,
|
505
605
|
getBranchMigrationPlan,
|
506
|
-
|
606
|
+
compareBranchWithUserSchema,
|
607
|
+
compareBranchSchemas,
|
608
|
+
updateBranchSchema,
|
609
|
+
previewBranchSchemaEdit,
|
610
|
+
applyBranchSchemaEdit,
|
611
|
+
getBranchSchemaHistory
|
507
612
|
},
|
508
613
|
table: {
|
509
614
|
createTable,
|
@@ -532,9 +637,9 @@ const operationsByTag = {
|
|
532
637
|
};
|
533
638
|
|
534
639
|
function getHostUrl(provider, type) {
|
535
|
-
if (
|
640
|
+
if (isHostProviderAlias(provider)) {
|
536
641
|
return providers[provider][type];
|
537
|
-
} else if (
|
642
|
+
} else if (isHostProviderBuilder(provider)) {
|
538
643
|
return provider[type];
|
539
644
|
}
|
540
645
|
throw new Error("Invalid API provider");
|
@@ -549,10 +654,10 @@ const providers = {
|
|
549
654
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
550
655
|
}
|
551
656
|
};
|
552
|
-
function
|
657
|
+
function isHostProviderAlias(alias) {
|
553
658
|
return isString(alias) && Object.keys(providers).includes(alias);
|
554
659
|
}
|
555
|
-
function
|
660
|
+
function isHostProviderBuilder(builder) {
|
556
661
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
557
662
|
}
|
558
663
|
|
@@ -580,7 +685,8 @@ class XataApiClient {
|
|
580
685
|
__privateAdd$7(this, _extraProps, void 0);
|
581
686
|
__privateAdd$7(this, _namespaces, {});
|
582
687
|
const provider = options.host ?? "production";
|
583
|
-
const apiKey = options
|
688
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
689
|
+
const trace = options.trace ?? defaultTrace;
|
584
690
|
if (!apiKey) {
|
585
691
|
throw new Error("Could not resolve a valid apiKey");
|
586
692
|
}
|
@@ -588,7 +694,8 @@ class XataApiClient {
|
|
588
694
|
apiUrl: getHostUrl(provider, "main"),
|
589
695
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
590
696
|
fetchImpl: getFetchImplementation(options.fetch),
|
591
|
-
apiKey
|
697
|
+
apiKey,
|
698
|
+
trace
|
592
699
|
});
|
593
700
|
}
|
594
701
|
get user() {
|
@@ -621,6 +728,16 @@ class XataApiClient {
|
|
621
728
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
622
729
|
return __privateGet$7(this, _namespaces).records;
|
623
730
|
}
|
731
|
+
get migrationRequests() {
|
732
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
733
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
734
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
735
|
+
}
|
736
|
+
get branchSchema() {
|
737
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
738
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
739
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
740
|
+
}
|
624
741
|
}
|
625
742
|
_extraProps = new WeakMap();
|
626
743
|
_namespaces = new WeakMap();
|
@@ -711,6 +828,13 @@ class WorkspaceApi {
|
|
711
828
|
...this.extraProps
|
712
829
|
});
|
713
830
|
}
|
831
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
832
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
833
|
+
pathParams: { workspaceId, inviteId },
|
834
|
+
body: { role },
|
835
|
+
...this.extraProps
|
836
|
+
});
|
837
|
+
}
|
714
838
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
715
839
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
716
840
|
pathParams: { workspaceId, inviteId },
|
@@ -753,6 +877,19 @@ class DatabaseApi {
|
|
753
877
|
...this.extraProps
|
754
878
|
});
|
755
879
|
}
|
880
|
+
getDatabaseMetadata(workspace, dbName) {
|
881
|
+
return operationsByTag.database.getDatabaseMetadata({
|
882
|
+
pathParams: { workspace, dbName },
|
883
|
+
...this.extraProps
|
884
|
+
});
|
885
|
+
}
|
886
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
887
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
888
|
+
pathParams: { workspace, dbName },
|
889
|
+
body: options,
|
890
|
+
...this.extraProps
|
891
|
+
});
|
892
|
+
}
|
756
893
|
getGitBranchesMapping(workspace, dbName) {
|
757
894
|
return operationsByTag.database.getGitBranchesMapping({
|
758
895
|
pathParams: { workspace, dbName },
|
@@ -824,27 +961,6 @@ class BranchApi {
|
|
824
961
|
...this.extraProps
|
825
962
|
});
|
826
963
|
}
|
827
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
828
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
829
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
830
|
-
body: options,
|
831
|
-
...this.extraProps
|
832
|
-
});
|
833
|
-
}
|
834
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
835
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
836
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
837
|
-
body: migrationPlan,
|
838
|
-
...this.extraProps
|
839
|
-
});
|
840
|
-
}
|
841
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
842
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
843
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
844
|
-
body: schema,
|
845
|
-
...this.extraProps
|
846
|
-
});
|
847
|
-
}
|
848
964
|
getBranchStats(workspace, database, branch) {
|
849
965
|
return operationsByTag.branch.getBranchStats({
|
850
966
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -925,9 +1041,10 @@ class RecordsApi {
|
|
925
1041
|
constructor(extraProps) {
|
926
1042
|
this.extraProps = extraProps;
|
927
1043
|
}
|
928
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1044
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
929
1045
|
return operationsByTag.records.insertRecord({
|
930
1046
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1047
|
+
queryParams: options,
|
931
1048
|
body: record,
|
932
1049
|
...this.extraProps
|
933
1050
|
});
|
@@ -956,21 +1073,24 @@ class RecordsApi {
|
|
956
1073
|
...this.extraProps
|
957
1074
|
});
|
958
1075
|
}
|
959
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1076
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
960
1077
|
return operationsByTag.records.deleteRecord({
|
961
1078
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1079
|
+
queryParams: options,
|
962
1080
|
...this.extraProps
|
963
1081
|
});
|
964
1082
|
}
|
965
1083
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
966
1084
|
return operationsByTag.records.getRecord({
|
967
1085
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1086
|
+
queryParams: options,
|
968
1087
|
...this.extraProps
|
969
1088
|
});
|
970
1089
|
}
|
971
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1090
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
972
1091
|
return operationsByTag.records.bulkInsertTableRecords({
|
973
1092
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1093
|
+
queryParams: options,
|
974
1094
|
body: { records },
|
975
1095
|
...this.extraProps
|
976
1096
|
});
|
@@ -997,6 +1117,131 @@ class RecordsApi {
|
|
997
1117
|
});
|
998
1118
|
}
|
999
1119
|
}
|
1120
|
+
class MigrationRequestsApi {
|
1121
|
+
constructor(extraProps) {
|
1122
|
+
this.extraProps = extraProps;
|
1123
|
+
}
|
1124
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1125
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1126
|
+
pathParams: { workspace, dbName: database },
|
1127
|
+
body: options,
|
1128
|
+
...this.extraProps
|
1129
|
+
});
|
1130
|
+
}
|
1131
|
+
createMigrationRequest(workspace, database, options) {
|
1132
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1133
|
+
pathParams: { workspace, dbName: database },
|
1134
|
+
body: options,
|
1135
|
+
...this.extraProps
|
1136
|
+
});
|
1137
|
+
}
|
1138
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1139
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1140
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1141
|
+
...this.extraProps
|
1142
|
+
});
|
1143
|
+
}
|
1144
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1145
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1146
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1147
|
+
body: options,
|
1148
|
+
...this.extraProps
|
1149
|
+
});
|
1150
|
+
}
|
1151
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1152
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1153
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1154
|
+
body: options,
|
1155
|
+
...this.extraProps
|
1156
|
+
});
|
1157
|
+
}
|
1158
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1159
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1160
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1161
|
+
...this.extraProps
|
1162
|
+
});
|
1163
|
+
}
|
1164
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1165
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1166
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1167
|
+
...this.extraProps
|
1168
|
+
});
|
1169
|
+
}
|
1170
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1171
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1172
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1173
|
+
...this.extraProps
|
1174
|
+
});
|
1175
|
+
}
|
1176
|
+
}
|
1177
|
+
class BranchSchemaApi {
|
1178
|
+
constructor(extraProps) {
|
1179
|
+
this.extraProps = extraProps;
|
1180
|
+
}
|
1181
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1182
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1183
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1184
|
+
body: options,
|
1185
|
+
...this.extraProps
|
1186
|
+
});
|
1187
|
+
}
|
1188
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1189
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1190
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1191
|
+
body: migrationPlan,
|
1192
|
+
...this.extraProps
|
1193
|
+
});
|
1194
|
+
}
|
1195
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1196
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1197
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1198
|
+
body: schema,
|
1199
|
+
...this.extraProps
|
1200
|
+
});
|
1201
|
+
}
|
1202
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1203
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1204
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1205
|
+
body: { schema },
|
1206
|
+
...this.extraProps
|
1207
|
+
});
|
1208
|
+
}
|
1209
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1210
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1211
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1212
|
+
body: { schema },
|
1213
|
+
...this.extraProps
|
1214
|
+
});
|
1215
|
+
}
|
1216
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1217
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1218
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1219
|
+
body: migration,
|
1220
|
+
...this.extraProps
|
1221
|
+
});
|
1222
|
+
}
|
1223
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1224
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1225
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1226
|
+
body: migration,
|
1227
|
+
...this.extraProps
|
1228
|
+
});
|
1229
|
+
}
|
1230
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1231
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1232
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1233
|
+
body: { edits },
|
1234
|
+
...this.extraProps
|
1235
|
+
});
|
1236
|
+
}
|
1237
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1238
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1239
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1240
|
+
body: options,
|
1241
|
+
...this.extraProps
|
1242
|
+
});
|
1243
|
+
}
|
1244
|
+
}
|
1000
1245
|
|
1001
1246
|
class XataApiPlugin {
|
1002
1247
|
async build(options) {
|
@@ -1180,21 +1425,34 @@ const _Query = class {
|
|
1180
1425
|
}
|
1181
1426
|
filter(a, b) {
|
1182
1427
|
if (arguments.length === 1) {
|
1183
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1428
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1184
1429
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1185
1430
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1186
1431
|
} else {
|
1187
|
-
const
|
1432
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1433
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1188
1434
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1189
1435
|
}
|
1190
1436
|
}
|
1191
|
-
|
1437
|
+
defaultFilter(column, value) {
|
1438
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1439
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1440
|
+
return { $includes: value };
|
1441
|
+
}
|
1442
|
+
return value;
|
1443
|
+
}
|
1444
|
+
sort(column, direction = "asc") {
|
1192
1445
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1193
1446
|
const sort = [...originalSort, { column, direction }];
|
1194
1447
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1195
1448
|
}
|
1196
1449
|
select(columns) {
|
1197
|
-
return new _Query(
|
1450
|
+
return new _Query(
|
1451
|
+
__privateGet$5(this, _repository),
|
1452
|
+
__privateGet$5(this, _table$1),
|
1453
|
+
{ columns },
|
1454
|
+
__privateGet$5(this, _data)
|
1455
|
+
);
|
1198
1456
|
}
|
1199
1457
|
getPaginated(options = {}) {
|
1200
1458
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1217,11 +1475,20 @@ const _Query = class {
|
|
1217
1475
|
}
|
1218
1476
|
}
|
1219
1477
|
async getMany(options = {}) {
|
1220
|
-
const
|
1221
|
-
|
1478
|
+
const { pagination = {}, ...rest } = options;
|
1479
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1480
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1481
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1482
|
+
const results = [...page.records];
|
1483
|
+
while (page.hasNextPage() && results.length < size) {
|
1484
|
+
page = await page.nextPage();
|
1485
|
+
results.push(...page.records);
|
1486
|
+
}
|
1487
|
+
if (page.hasNextPage()) {
|
1222
1488
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1223
1489
|
}
|
1224
|
-
|
1490
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1491
|
+
return array;
|
1225
1492
|
}
|
1226
1493
|
async getAll(options = {}) {
|
1227
1494
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1319,203 +1586,228 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1319
1586
|
__accessCheck$4(obj, member, "access private method");
|
1320
1587
|
return method;
|
1321
1588
|
};
|
1322
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1589
|
+
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;
|
1323
1590
|
class Repository extends Query {
|
1324
1591
|
}
|
1325
1592
|
class RestRepository extends Query {
|
1326
1593
|
constructor(options) {
|
1327
|
-
super(
|
1594
|
+
super(
|
1595
|
+
null,
|
1596
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1597
|
+
{}
|
1598
|
+
);
|
1328
1599
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1329
1600
|
__privateAdd$4(this, _insertRecordWithId);
|
1330
1601
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
1331
1602
|
__privateAdd$4(this, _updateRecordWithID);
|
1332
1603
|
__privateAdd$4(this, _upsertRecordWithID);
|
1333
1604
|
__privateAdd$4(this, _deleteRecord);
|
1334
|
-
__privateAdd$4(this, _invalidateCache);
|
1335
|
-
__privateAdd$4(this, _setCacheRecord);
|
1336
|
-
__privateAdd$4(this, _getCacheRecord);
|
1337
1605
|
__privateAdd$4(this, _setCacheQuery);
|
1338
1606
|
__privateAdd$4(this, _getCacheQuery);
|
1339
1607
|
__privateAdd$4(this, _getSchemaTables$1);
|
1340
1608
|
__privateAdd$4(this, _table, void 0);
|
1341
1609
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1610
|
+
__privateAdd$4(this, _db, void 0);
|
1342
1611
|
__privateAdd$4(this, _cache, void 0);
|
1343
1612
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1613
|
+
__privateAdd$4(this, _trace, void 0);
|
1344
1614
|
__privateSet$4(this, _table, options.table);
|
1345
1615
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1346
|
-
this
|
1616
|
+
__privateSet$4(this, _db, options.db);
|
1347
1617
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1348
1618
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1619
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1620
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1621
|
+
return trace(name, fn, {
|
1622
|
+
...options2,
|
1623
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1624
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1625
|
+
[TraceAttributes.VERSION]: VERSION
|
1626
|
+
});
|
1627
|
+
});
|
1349
1628
|
}
|
1350
|
-
async create(a, b) {
|
1351
|
-
|
1352
|
-
if (a
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
const
|
1392
|
-
|
1393
|
-
const
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1629
|
+
async create(a, b, c) {
|
1630
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1631
|
+
if (Array.isArray(a)) {
|
1632
|
+
if (a.length === 0)
|
1633
|
+
return [];
|
1634
|
+
const columns = isStringArray(b) ? b : void 0;
|
1635
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1636
|
+
}
|
1637
|
+
if (isString(a) && isObject(b)) {
|
1638
|
+
if (a === "")
|
1639
|
+
throw new Error("The id can't be empty");
|
1640
|
+
const columns = isStringArray(c) ? c : void 0;
|
1641
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1642
|
+
}
|
1643
|
+
if (isObject(a) && isString(a.id)) {
|
1644
|
+
if (a.id === "")
|
1645
|
+
throw new Error("The id can't be empty");
|
1646
|
+
const columns = isStringArray(b) ? b : void 0;
|
1647
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1648
|
+
}
|
1649
|
+
if (isObject(a)) {
|
1650
|
+
const columns = isStringArray(b) ? b : void 0;
|
1651
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1652
|
+
}
|
1653
|
+
throw new Error("Invalid arguments for create method");
|
1654
|
+
});
|
1655
|
+
}
|
1656
|
+
async read(a, b) {
|
1657
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1658
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1659
|
+
if (Array.isArray(a)) {
|
1660
|
+
if (a.length === 0)
|
1661
|
+
return [];
|
1662
|
+
const ids = a.map((item) => extractId(item));
|
1663
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1664
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1665
|
+
acc[object.id] = object;
|
1666
|
+
return acc;
|
1667
|
+
}, {});
|
1668
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1669
|
+
}
|
1670
|
+
const id = extractId(a);
|
1671
|
+
if (id) {
|
1672
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1673
|
+
try {
|
1674
|
+
const response = await getRecord({
|
1675
|
+
pathParams: {
|
1676
|
+
workspace: "{workspaceId}",
|
1677
|
+
dbBranchName: "{dbBranch}",
|
1678
|
+
tableName: __privateGet$4(this, _table),
|
1679
|
+
recordId: id
|
1680
|
+
},
|
1681
|
+
queryParams: { columns },
|
1682
|
+
...fetchProps
|
1683
|
+
});
|
1684
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1685
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1686
|
+
} catch (e) {
|
1687
|
+
if (isObject(e) && e.status === 404) {
|
1688
|
+
return null;
|
1689
|
+
}
|
1690
|
+
throw e;
|
1402
1691
|
}
|
1403
|
-
throw e;
|
1404
1692
|
}
|
1405
|
-
|
1693
|
+
return null;
|
1694
|
+
});
|
1406
1695
|
}
|
1407
|
-
async update(a, b) {
|
1408
|
-
|
1409
|
-
if (a
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1696
|
+
async update(a, b, c) {
|
1697
|
+
return __privateGet$4(this, _trace).call(this, "update", 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.update(object, columns)));
|
1413
1706
|
}
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1418
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1419
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1420
|
-
return record;
|
1421
|
-
}
|
1422
|
-
if (isObject(a) && isString(a.id)) {
|
1423
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1424
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1425
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1426
|
-
return record;
|
1427
|
-
}
|
1428
|
-
throw new Error("Invalid arguments for update method");
|
1429
|
-
}
|
1430
|
-
async createOrUpdate(a, b) {
|
1431
|
-
if (Array.isArray(a)) {
|
1432
|
-
if (a.length === 0)
|
1433
|
-
return [];
|
1434
|
-
if (a.length > 100) {
|
1435
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1707
|
+
if (isString(a) && isObject(b)) {
|
1708
|
+
const columns = isStringArray(c) ? c : void 0;
|
1709
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1436
1710
|
}
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1441
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
|
1442
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1443
|
-
return record;
|
1444
|
-
}
|
1445
|
-
if (isObject(a) && isString(a.id)) {
|
1446
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1447
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1448
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1449
|
-
return record;
|
1450
|
-
}
|
1451
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1452
|
-
}
|
1453
|
-
async delete(a) {
|
1454
|
-
if (Array.isArray(a)) {
|
1455
|
-
if (a.length === 0)
|
1456
|
-
return;
|
1457
|
-
if (a.length > 100) {
|
1458
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1711
|
+
if (isObject(a) && isString(a.id)) {
|
1712
|
+
const columns = isStringArray(b) ? b : void 0;
|
1713
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1459
1714
|
}
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1715
|
+
throw new Error("Invalid arguments for update method");
|
1716
|
+
});
|
1717
|
+
}
|
1718
|
+
async createOrUpdate(a, b, c) {
|
1719
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1720
|
+
if (Array.isArray(a)) {
|
1721
|
+
if (a.length === 0)
|
1722
|
+
return [];
|
1723
|
+
if (a.length > 100) {
|
1724
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1725
|
+
}
|
1726
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1727
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1728
|
+
}
|
1729
|
+
if (isString(a) && isObject(b)) {
|
1730
|
+
const columns = isStringArray(c) ? c : void 0;
|
1731
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1732
|
+
}
|
1733
|
+
if (isObject(a) && isString(a.id)) {
|
1734
|
+
const columns = isStringArray(c) ? c : void 0;
|
1735
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1736
|
+
}
|
1737
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1738
|
+
});
|
1739
|
+
}
|
1740
|
+
async delete(a, b) {
|
1741
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1742
|
+
if (Array.isArray(a)) {
|
1743
|
+
if (a.length === 0)
|
1744
|
+
return [];
|
1745
|
+
if (a.length > 100) {
|
1746
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1747
|
+
}
|
1748
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1749
|
+
}
|
1750
|
+
if (isString(a)) {
|
1751
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1752
|
+
}
|
1753
|
+
if (isObject(a) && isString(a.id)) {
|
1754
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1755
|
+
}
|
1756
|
+
throw new Error("Invalid arguments for delete method");
|
1757
|
+
});
|
1474
1758
|
}
|
1475
1759
|
async search(query, options = {}) {
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1760
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1761
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1762
|
+
const { records } = await searchTable({
|
1763
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1764
|
+
body: {
|
1765
|
+
query,
|
1766
|
+
fuzziness: options.fuzziness,
|
1767
|
+
prefix: options.prefix,
|
1768
|
+
highlight: options.highlight,
|
1769
|
+
filter: options.filter,
|
1770
|
+
boosters: options.boosters
|
1771
|
+
},
|
1772
|
+
...fetchProps
|
1773
|
+
});
|
1774
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1775
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1486
1776
|
});
|
1487
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1488
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1489
1777
|
}
|
1490
1778
|
async query(query) {
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1779
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1780
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1781
|
+
if (cacheQuery)
|
1782
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1783
|
+
const data = query.getQueryOptions();
|
1784
|
+
const body = {
|
1785
|
+
filter: cleanFilter(data.filter),
|
1786
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1787
|
+
page: data.pagination,
|
1788
|
+
columns: data.columns
|
1789
|
+
};
|
1790
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1791
|
+
const { meta, records: objects } = await queryTable({
|
1792
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1793
|
+
body,
|
1794
|
+
...fetchProps
|
1795
|
+
});
|
1796
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1797
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1798
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1799
|
+
return new Page(query, meta, records);
|
1506
1800
|
});
|
1507
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1508
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1509
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1510
|
-
return new Page(query, meta, records);
|
1511
1801
|
}
|
1512
1802
|
}
|
1513
1803
|
_table = new WeakMap();
|
1514
1804
|
_getFetchProps = new WeakMap();
|
1805
|
+
_db = new WeakMap();
|
1515
1806
|
_cache = new WeakMap();
|
1516
1807
|
_schemaTables$2 = new WeakMap();
|
1808
|
+
_trace = new WeakMap();
|
1517
1809
|
_insertRecordWithoutId = new WeakSet();
|
1518
|
-
insertRecordWithoutId_fn = async function(object) {
|
1810
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1519
1811
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1520
1812
|
const record = transformObjectLinks(object);
|
1521
1813
|
const response = await insertRecord({
|
@@ -1524,17 +1816,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1524
1816
|
dbBranchName: "{dbBranch}",
|
1525
1817
|
tableName: __privateGet$4(this, _table)
|
1526
1818
|
},
|
1819
|
+
queryParams: { columns },
|
1527
1820
|
body: record,
|
1528
1821
|
...fetchProps
|
1529
1822
|
});
|
1530
|
-
const
|
1531
|
-
|
1532
|
-
throw new Error("The server failed to save the record");
|
1533
|
-
}
|
1534
|
-
return finalObject;
|
1823
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1824
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1535
1825
|
};
|
1536
1826
|
_insertRecordWithId = new WeakSet();
|
1537
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1827
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1538
1828
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1539
1829
|
const record = transformObjectLinks(object);
|
1540
1830
|
const response = await insertRecordWithID({
|
@@ -1545,92 +1835,78 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1545
1835
|
recordId
|
1546
1836
|
},
|
1547
1837
|
body: record,
|
1548
|
-
queryParams: { createOnly: true },
|
1838
|
+
queryParams: { createOnly: true, columns },
|
1549
1839
|
...fetchProps
|
1550
1840
|
});
|
1551
|
-
const
|
1552
|
-
|
1553
|
-
throw new Error("The server failed to save the record");
|
1554
|
-
}
|
1555
|
-
return finalObject;
|
1841
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1842
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1556
1843
|
};
|
1557
1844
|
_bulkInsertTableRecords = new WeakSet();
|
1558
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1845
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1559
1846
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1560
1847
|
const records = objects.map((object) => transformObjectLinks(object));
|
1561
|
-
const
|
1848
|
+
const response = await bulkInsertTableRecords({
|
1562
1849
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1850
|
+
queryParams: { columns },
|
1563
1851
|
body: { records },
|
1564
1852
|
...fetchProps
|
1565
1853
|
});
|
1566
|
-
|
1567
|
-
|
1568
|
-
throw new Error("The server failed to save some records");
|
1854
|
+
if (!isResponseWithRecords(response)) {
|
1855
|
+
throw new Error("Request included columns but server didn't include them");
|
1569
1856
|
}
|
1570
|
-
const
|
1571
|
-
|
1572
|
-
return acc;
|
1573
|
-
}, {});
|
1574
|
-
return recordIDs.map((id) => dictionary[id]);
|
1857
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1858
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1575
1859
|
};
|
1576
1860
|
_updateRecordWithID = new WeakSet();
|
1577
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1861
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1578
1862
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1579
1863
|
const record = transformObjectLinks(object);
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1864
|
+
try {
|
1865
|
+
const response = await updateRecordWithID({
|
1866
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1867
|
+
queryParams: { columns },
|
1868
|
+
body: record,
|
1869
|
+
...fetchProps
|
1870
|
+
});
|
1871
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1872
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1873
|
+
} catch (e) {
|
1874
|
+
if (isObject(e) && e.status === 404) {
|
1875
|
+
return null;
|
1876
|
+
}
|
1877
|
+
throw e;
|
1878
|
+
}
|
1589
1879
|
};
|
1590
1880
|
_upsertRecordWithID = new WeakSet();
|
1591
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1881
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1592
1882
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1593
1883
|
const response = await upsertRecordWithID({
|
1594
1884
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1885
|
+
queryParams: { columns },
|
1595
1886
|
body: object,
|
1596
1887
|
...fetchProps
|
1597
1888
|
});
|
1598
|
-
const
|
1599
|
-
|
1600
|
-
throw new Error("The server failed to save the record");
|
1601
|
-
return item;
|
1889
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1890
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1602
1891
|
};
|
1603
1892
|
_deleteRecord = new WeakSet();
|
1604
|
-
deleteRecord_fn = async function(recordId) {
|
1893
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1605
1894
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
await __privateGet$4(this, _cache).delete(key);
|
1895
|
+
try {
|
1896
|
+
const response = await deleteRecord({
|
1897
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1898
|
+
queryParams: { columns },
|
1899
|
+
...fetchProps
|
1900
|
+
});
|
1901
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1902
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1903
|
+
} catch (e) {
|
1904
|
+
if (isObject(e) && e.status === 404) {
|
1905
|
+
return null;
|
1906
|
+
}
|
1907
|
+
throw e;
|
1620
1908
|
}
|
1621
1909
|
};
|
1622
|
-
_setCacheRecord = new WeakSet();
|
1623
|
-
setCacheRecord_fn = async function(record) {
|
1624
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1625
|
-
return;
|
1626
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1627
|
-
};
|
1628
|
-
_getCacheRecord = new WeakSet();
|
1629
|
-
getCacheRecord_fn = async function(recordId) {
|
1630
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1631
|
-
return null;
|
1632
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1633
|
-
};
|
1634
1910
|
_setCacheQuery = new WeakSet();
|
1635
1911
|
setCacheQuery_fn = async function(query, meta, records) {
|
1636
1912
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1696,11 +1972,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1696
1972
|
}
|
1697
1973
|
}
|
1698
1974
|
}
|
1699
|
-
result.read = function() {
|
1700
|
-
return db[table].read(result["id"]);
|
1975
|
+
result.read = function(columns2) {
|
1976
|
+
return db[table].read(result["id"], columns2);
|
1701
1977
|
};
|
1702
|
-
result.update = function(data) {
|
1703
|
-
return db[table].update(result["id"], data);
|
1978
|
+
result.update = function(data, columns2) {
|
1979
|
+
return db[table].update(result["id"], data, columns2);
|
1704
1980
|
};
|
1705
1981
|
result.delete = function() {
|
1706
1982
|
return db[table].delete(result["id"]);
|
@@ -1714,14 +1990,21 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1714
1990
|
Object.freeze(result);
|
1715
1991
|
return result;
|
1716
1992
|
};
|
1717
|
-
function
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
if (
|
1722
|
-
return
|
1723
|
-
|
1724
|
-
|
1993
|
+
function isResponseWithRecords(value) {
|
1994
|
+
return isObject(value) && Array.isArray(value.records);
|
1995
|
+
}
|
1996
|
+
function extractId(value) {
|
1997
|
+
if (isString(value))
|
1998
|
+
return value;
|
1999
|
+
if (isObject(value) && isString(value.id))
|
2000
|
+
return value.id;
|
2001
|
+
return void 0;
|
2002
|
+
}
|
2003
|
+
function cleanFilter(filter) {
|
2004
|
+
if (!filter)
|
2005
|
+
return void 0;
|
2006
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2007
|
+
return values.length > 0 ? filter : void 0;
|
1725
2008
|
}
|
1726
2009
|
|
1727
2010
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1748,7 +2031,6 @@ class SimpleCache {
|
|
1748
2031
|
__privateAdd$3(this, _map, void 0);
|
1749
2032
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1750
2033
|
this.capacity = options.max ?? 500;
|
1751
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1752
2034
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1753
2035
|
}
|
1754
2036
|
async getAll() {
|
@@ -1774,18 +2056,25 @@ class SimpleCache {
|
|
1774
2056
|
}
|
1775
2057
|
_map = new WeakMap();
|
1776
2058
|
|
1777
|
-
const
|
1778
|
-
const
|
1779
|
-
const
|
1780
|
-
const
|
1781
|
-
const
|
1782
|
-
const
|
2059
|
+
const greaterThan = (value) => ({ $gt: value });
|
2060
|
+
const gt = greaterThan;
|
2061
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2062
|
+
const greaterEquals = greaterThanEquals;
|
2063
|
+
const gte = greaterThanEquals;
|
2064
|
+
const ge = greaterThanEquals;
|
2065
|
+
const lessThan = (value) => ({ $lt: value });
|
2066
|
+
const lt = lessThan;
|
2067
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2068
|
+
const lessEquals = lessThanEquals;
|
2069
|
+
const lte = lessThanEquals;
|
2070
|
+
const le = lessThanEquals;
|
1783
2071
|
const exists = (column) => ({ $exists: column });
|
1784
2072
|
const notExists = (column) => ({ $notExists: column });
|
1785
2073
|
const startsWith = (value) => ({ $startsWith: value });
|
1786
2074
|
const endsWith = (value) => ({ $endsWith: value });
|
1787
2075
|
const pattern = (value) => ({ $pattern: value });
|
1788
2076
|
const is = (value) => ({ $is: value });
|
2077
|
+
const equals = is;
|
1789
2078
|
const isNot = (value) => ({ $isNot: value });
|
1790
2079
|
const contains = (value) => ({ $contains: value });
|
1791
2080
|
const includes = (value) => ({ $includes: value });
|
@@ -1820,16 +2109,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1820
2109
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1821
2110
|
}
|
1822
2111
|
build(pluginOptions) {
|
1823
|
-
const db = new Proxy(
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
2112
|
+
const db = new Proxy(
|
2113
|
+
{},
|
2114
|
+
{
|
2115
|
+
get: (_target, table) => {
|
2116
|
+
if (!isString(table))
|
2117
|
+
throw new Error("Invalid table name");
|
2118
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2119
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2120
|
+
}
|
2121
|
+
return __privateGet$2(this, _tables)[table];
|
1829
2122
|
}
|
1830
|
-
return __privateGet$2(this, _tables)[table];
|
1831
2123
|
}
|
1832
|
-
|
2124
|
+
);
|
1833
2125
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1834
2126
|
for (const table of tableNames) {
|
1835
2127
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1899,10 +2191,10 @@ _schemaTables = new WeakMap();
|
|
1899
2191
|
_search = new WeakSet();
|
1900
2192
|
search_fn = async function(query, options, getFetchProps) {
|
1901
2193
|
const fetchProps = await getFetchProps();
|
1902
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
2194
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1903
2195
|
const { records } = await searchBranch({
|
1904
2196
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1905
|
-
body: { tables, query, fuzziness, highlight },
|
2197
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1906
2198
|
...fetchProps
|
1907
2199
|
});
|
1908
2200
|
return records;
|
@@ -1943,9 +2235,13 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1943
2235
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1944
2236
|
const apiKey = options?.apiKey || getAPIKey();
|
1945
2237
|
if (!databaseURL)
|
1946
|
-
throw new Error(
|
2238
|
+
throw new Error(
|
2239
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2240
|
+
);
|
1947
2241
|
if (!apiKey)
|
1948
|
-
throw new Error(
|
2242
|
+
throw new Error(
|
2243
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2244
|
+
);
|
1949
2245
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1950
2246
|
const [workspace] = host.split(".");
|
1951
2247
|
const { fallbackBranch } = getEnvironment();
|
@@ -1955,7 +2251,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1955
2251
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1956
2252
|
workspacesApiUrl: `${protocol}//${host}`,
|
1957
2253
|
pathParams: { dbName, workspace },
|
1958
|
-
queryParams: { gitBranch, fallbackBranch }
|
2254
|
+
queryParams: { gitBranch, fallbackBranch },
|
2255
|
+
trace: defaultTrace
|
1959
2256
|
});
|
1960
2257
|
return branch;
|
1961
2258
|
}
|
@@ -1963,9 +2260,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1963
2260
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1964
2261
|
const apiKey = options?.apiKey || getAPIKey();
|
1965
2262
|
if (!databaseURL)
|
1966
|
-
throw new Error(
|
2263
|
+
throw new Error(
|
2264
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2265
|
+
);
|
1967
2266
|
if (!apiKey)
|
1968
|
-
throw new Error(
|
2267
|
+
throw new Error(
|
2268
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2269
|
+
);
|
1969
2270
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1970
2271
|
const [workspace] = host.split(".");
|
1971
2272
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1975,7 +2276,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1975
2276
|
apiUrl: databaseURL,
|
1976
2277
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1977
2278
|
workspacesApiUrl: `${protocol}//${host}`,
|
1978
|
-
pathParams: { dbBranchName, workspace }
|
2279
|
+
pathParams: { dbBranchName, workspace },
|
2280
|
+
trace: defaultTrace
|
1979
2281
|
});
|
1980
2282
|
} catch (err) {
|
1981
2283
|
if (isObject(err) && err.status === 404)
|
@@ -2015,17 +2317,20 @@ var __privateMethod = (obj, member, method) => {
|
|
2015
2317
|
return method;
|
2016
2318
|
};
|
2017
2319
|
const buildClient = (plugins) => {
|
2018
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2320
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2019
2321
|
return _a = class {
|
2020
2322
|
constructor(options = {}, schemaTables) {
|
2021
2323
|
__privateAdd(this, _parseOptions);
|
2022
2324
|
__privateAdd(this, _getFetchProps);
|
2023
2325
|
__privateAdd(this, _evaluateBranch);
|
2024
2326
|
__privateAdd(this, _branch, void 0);
|
2327
|
+
__privateAdd(this, _options, void 0);
|
2025
2328
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2329
|
+
__privateSet(this, _options, safeOptions);
|
2026
2330
|
const pluginOptions = {
|
2027
2331
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2028
|
-
cache: safeOptions.cache
|
2332
|
+
cache: safeOptions.cache,
|
2333
|
+
trace: safeOptions.trace
|
2029
2334
|
};
|
2030
2335
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2031
2336
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2044,22 +2349,26 @@ const buildClient = (plugins) => {
|
|
2044
2349
|
}
|
2045
2350
|
}
|
2046
2351
|
}
|
2047
|
-
|
2352
|
+
async getConfig() {
|
2353
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2354
|
+
const branch = await __privateGet(this, _options).branch();
|
2355
|
+
return { databaseURL, branch };
|
2356
|
+
}
|
2357
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
2048
2358
|
const fetch = getFetchImplementation(options?.fetch);
|
2049
2359
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2050
2360
|
const apiKey = options?.apiKey || getAPIKey();
|
2051
|
-
const cache = options?.cache ?? new SimpleCache({
|
2361
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2362
|
+
const trace = options?.trace ?? defaultTrace;
|
2052
2363
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2053
|
-
if (!
|
2054
|
-
throw new Error("
|
2364
|
+
if (!apiKey) {
|
2365
|
+
throw new Error("Option apiKey is required");
|
2055
2366
|
}
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
apiKey,
|
2060
|
-
|
2061
|
-
branch
|
2062
|
-
}) {
|
2367
|
+
if (!databaseURL) {
|
2368
|
+
throw new Error("Option databaseURL is required");
|
2369
|
+
}
|
2370
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2371
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2063
2372
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2064
2373
|
if (!branchValue)
|
2065
2374
|
throw new Error("Unable to resolve branch value");
|
@@ -2069,9 +2378,10 @@ const buildClient = (plugins) => {
|
|
2069
2378
|
apiUrl: "",
|
2070
2379
|
workspacesApiUrl: (path, params) => {
|
2071
2380
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2072
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2381
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2073
2382
|
return databaseURL + newPath;
|
2074
|
-
}
|
2383
|
+
},
|
2384
|
+
trace
|
2075
2385
|
};
|
2076
2386
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2077
2387
|
if (__privateGet(this, _branch))
|
@@ -2094,6 +2404,88 @@ const buildClient = (plugins) => {
|
|
2094
2404
|
class BaseClient extends buildClient() {
|
2095
2405
|
}
|
2096
2406
|
|
2407
|
+
const META = "__";
|
2408
|
+
const VALUE = "___";
|
2409
|
+
class Serializer {
|
2410
|
+
constructor() {
|
2411
|
+
this.classes = {};
|
2412
|
+
}
|
2413
|
+
add(clazz) {
|
2414
|
+
this.classes[clazz.name] = clazz;
|
2415
|
+
}
|
2416
|
+
toJSON(data) {
|
2417
|
+
function visit(obj) {
|
2418
|
+
if (Array.isArray(obj))
|
2419
|
+
return obj.map(visit);
|
2420
|
+
const type = typeof obj;
|
2421
|
+
if (type === "undefined")
|
2422
|
+
return { [META]: "undefined" };
|
2423
|
+
if (type === "bigint")
|
2424
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2425
|
+
if (obj === null || type !== "object")
|
2426
|
+
return obj;
|
2427
|
+
const constructor = obj.constructor;
|
2428
|
+
const o = { [META]: constructor.name };
|
2429
|
+
for (const [key, value] of Object.entries(obj)) {
|
2430
|
+
o[key] = visit(value);
|
2431
|
+
}
|
2432
|
+
if (constructor === Date)
|
2433
|
+
o[VALUE] = obj.toISOString();
|
2434
|
+
if (constructor === Map)
|
2435
|
+
o[VALUE] = Object.fromEntries(obj);
|
2436
|
+
if (constructor === Set)
|
2437
|
+
o[VALUE] = [...obj];
|
2438
|
+
return o;
|
2439
|
+
}
|
2440
|
+
return JSON.stringify(visit(data));
|
2441
|
+
}
|
2442
|
+
fromJSON(json) {
|
2443
|
+
return JSON.parse(json, (key, value) => {
|
2444
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2445
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2446
|
+
const constructor = this.classes[clazz];
|
2447
|
+
if (constructor) {
|
2448
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2449
|
+
}
|
2450
|
+
if (clazz === "Date")
|
2451
|
+
return new Date(val);
|
2452
|
+
if (clazz === "Set")
|
2453
|
+
return new Set(val);
|
2454
|
+
if (clazz === "Map")
|
2455
|
+
return new Map(Object.entries(val));
|
2456
|
+
if (clazz === "bigint")
|
2457
|
+
return BigInt(val);
|
2458
|
+
if (clazz === "undefined")
|
2459
|
+
return void 0;
|
2460
|
+
return rest;
|
2461
|
+
}
|
2462
|
+
return value;
|
2463
|
+
});
|
2464
|
+
}
|
2465
|
+
}
|
2466
|
+
const defaultSerializer = new Serializer();
|
2467
|
+
const serialize = (data) => {
|
2468
|
+
return defaultSerializer.toJSON(data);
|
2469
|
+
};
|
2470
|
+
const deserialize = (json) => {
|
2471
|
+
return defaultSerializer.fromJSON(json);
|
2472
|
+
};
|
2473
|
+
|
2474
|
+
function buildWorkerRunner(config) {
|
2475
|
+
return function xataWorker(name, _worker) {
|
2476
|
+
return async (...args) => {
|
2477
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2478
|
+
const result = await fetch(url, {
|
2479
|
+
method: "POST",
|
2480
|
+
headers: { "Content-Type": "application/json" },
|
2481
|
+
body: serialize({ args })
|
2482
|
+
});
|
2483
|
+
const text = await result.text();
|
2484
|
+
return deserialize(text);
|
2485
|
+
};
|
2486
|
+
};
|
2487
|
+
}
|
2488
|
+
|
2097
2489
|
class XataError extends Error {
|
2098
2490
|
constructor(message, status) {
|
2099
2491
|
super(message);
|
@@ -2114,6 +2506,7 @@ exports.Repository = Repository;
|
|
2114
2506
|
exports.RestRepository = RestRepository;
|
2115
2507
|
exports.SchemaPlugin = SchemaPlugin;
|
2116
2508
|
exports.SearchPlugin = SearchPlugin;
|
2509
|
+
exports.Serializer = Serializer;
|
2117
2510
|
exports.SimpleCache = SimpleCache;
|
2118
2511
|
exports.XataApiClient = XataApiClient;
|
2119
2512
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2122,12 +2515,18 @@ exports.XataPlugin = XataPlugin;
|
|
2122
2515
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2123
2516
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2124
2517
|
exports.addTableColumn = addTableColumn;
|
2518
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
2125
2519
|
exports.buildClient = buildClient;
|
2520
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2126
2521
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2127
2522
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2523
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
2524
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
2525
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2128
2526
|
exports.contains = contains;
|
2129
2527
|
exports.createBranch = createBranch;
|
2130
2528
|
exports.createDatabase = createDatabase;
|
2529
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2131
2530
|
exports.createTable = createTable;
|
2132
2531
|
exports.createUserAPIKey = createUserAPIKey;
|
2133
2532
|
exports.createWorkspace = createWorkspace;
|
@@ -2139,7 +2538,9 @@ exports.deleteTable = deleteTable;
|
|
2139
2538
|
exports.deleteUser = deleteUser;
|
2140
2539
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2141
2540
|
exports.deleteWorkspace = deleteWorkspace;
|
2541
|
+
exports.deserialize = deserialize;
|
2142
2542
|
exports.endsWith = endsWith;
|
2543
|
+
exports.equals = equals;
|
2143
2544
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2144
2545
|
exports.exists = exists;
|
2145
2546
|
exports.ge = ge;
|
@@ -2149,13 +2550,17 @@ exports.getBranchList = getBranchList;
|
|
2149
2550
|
exports.getBranchMetadata = getBranchMetadata;
|
2150
2551
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2151
2552
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
2553
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2152
2554
|
exports.getBranchStats = getBranchStats;
|
2153
2555
|
exports.getColumn = getColumn;
|
2154
2556
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
2155
2557
|
exports.getCurrentBranchName = getCurrentBranchName;
|
2156
2558
|
exports.getDatabaseList = getDatabaseList;
|
2559
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2157
2560
|
exports.getDatabaseURL = getDatabaseURL;
|
2158
2561
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
2562
|
+
exports.getMigrationRequest = getMigrationRequest;
|
2563
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
2159
2564
|
exports.getRecord = getRecord;
|
2160
2565
|
exports.getTableColumns = getTableColumns;
|
2161
2566
|
exports.getTableSchema = getTableSchema;
|
@@ -2164,6 +2569,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2164
2569
|
exports.getWorkspace = getWorkspace;
|
2165
2570
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2166
2571
|
exports.getWorkspacesList = getWorkspacesList;
|
2572
|
+
exports.greaterEquals = greaterEquals;
|
2573
|
+
exports.greaterThan = greaterThan;
|
2574
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2167
2575
|
exports.gt = gt;
|
2168
2576
|
exports.gte = gte;
|
2169
2577
|
exports.includes = includes;
|
@@ -2179,11 +2587,18 @@ exports.isIdentifiable = isIdentifiable;
|
|
2179
2587
|
exports.isNot = isNot;
|
2180
2588
|
exports.isXataRecord = isXataRecord;
|
2181
2589
|
exports.le = le;
|
2590
|
+
exports.lessEquals = lessEquals;
|
2591
|
+
exports.lessThan = lessThan;
|
2592
|
+
exports.lessThanEquals = lessThanEquals;
|
2593
|
+
exports.listMigrationRequests = listMigrationRequests;
|
2594
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
2182
2595
|
exports.lt = lt;
|
2183
2596
|
exports.lte = lte;
|
2597
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2184
2598
|
exports.notExists = notExists;
|
2185
2599
|
exports.operationsByTag = operationsByTag;
|
2186
2600
|
exports.pattern = pattern;
|
2601
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
2187
2602
|
exports.queryTable = queryTable;
|
2188
2603
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2189
2604
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
@@ -2191,14 +2606,19 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2191
2606
|
exports.resolveBranch = resolveBranch;
|
2192
2607
|
exports.searchBranch = searchBranch;
|
2193
2608
|
exports.searchTable = searchTable;
|
2609
|
+
exports.serialize = serialize;
|
2194
2610
|
exports.setTableSchema = setTableSchema;
|
2195
2611
|
exports.startsWith = startsWith;
|
2196
2612
|
exports.updateBranchMetadata = updateBranchMetadata;
|
2613
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2197
2614
|
exports.updateColumn = updateColumn;
|
2615
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
2616
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2198
2617
|
exports.updateRecordWithID = updateRecordWithID;
|
2199
2618
|
exports.updateTable = updateTable;
|
2200
2619
|
exports.updateUser = updateUser;
|
2201
2620
|
exports.updateWorkspace = updateWorkspace;
|
2621
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2202
2622
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2203
2623
|
exports.upsertRecordWithID = upsertRecordWithID;
|
2204
2624
|
//# sourceMappingURL=index.cjs.map
|