@xata.io/client 0.0.0-alpha.ved669cc → 0.0.0-alpha.vede38ca
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 +800 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1256 -200
- package/dist/index.mjs +755 -359
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
const defaultTrace = async (_name, fn, _options) => {
|
|
2
|
+
return await fn({
|
|
3
|
+
setAttributes: () => {
|
|
4
|
+
return;
|
|
5
|
+
},
|
|
6
|
+
propagateTrace: () => {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const TraceAttributes = {
|
|
12
|
+
KIND: "xata.trace.kind",
|
|
13
|
+
VERSION: "xata.sdk.version",
|
|
14
|
+
TABLE: "xata.table",
|
|
15
|
+
HTTP_REQUEST_ID: "http.request_id",
|
|
16
|
+
HTTP_STATUS_CODE: "http.status_code",
|
|
17
|
+
HTTP_HOST: "http.host",
|
|
18
|
+
HTTP_SCHEME: "http.scheme",
|
|
19
|
+
HTTP_USER_AGENT: "http.user_agent",
|
|
20
|
+
HTTP_METHOD: "http.method",
|
|
21
|
+
HTTP_URL: "http.url",
|
|
22
|
+
HTTP_ROUTE: "http.route",
|
|
23
|
+
HTTP_TARGET: "http.target"
|
|
24
|
+
};
|
|
25
|
+
|
|
1
26
|
function notEmpty(value) {
|
|
2
27
|
return value !== null && value !== void 0;
|
|
3
28
|
}
|
|
@@ -13,6 +38,9 @@ function isDefined(value) {
|
|
|
13
38
|
function isString(value) {
|
|
14
39
|
return isDefined(value) && typeof value === "string";
|
|
15
40
|
}
|
|
41
|
+
function isStringArray(value) {
|
|
42
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
|
43
|
+
}
|
|
16
44
|
function toBase64(value) {
|
|
17
45
|
try {
|
|
18
46
|
return btoa(value);
|
|
@@ -28,7 +56,8 @@ function getEnvironment() {
|
|
|
28
56
|
return {
|
|
29
57
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
|
30
58
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
|
31
|
-
branch: process.env.XATA_BRANCH ??
|
|
59
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
|
60
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
|
32
61
|
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
|
33
62
|
};
|
|
34
63
|
}
|
|
@@ -39,7 +68,8 @@ function getEnvironment() {
|
|
|
39
68
|
return {
|
|
40
69
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
|
41
70
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
|
42
|
-
branch: Deno.env.get("XATA_BRANCH") ??
|
|
71
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
|
72
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
|
43
73
|
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
|
44
74
|
};
|
|
45
75
|
}
|
|
@@ -49,6 +79,7 @@ function getEnvironment() {
|
|
|
49
79
|
apiKey: getGlobalApiKey(),
|
|
50
80
|
databaseURL: getGlobalDatabaseURL(),
|
|
51
81
|
branch: getGlobalBranch(),
|
|
82
|
+
envBranch: void 0,
|
|
52
83
|
fallbackBranch: getGlobalFallbackBranch()
|
|
53
84
|
};
|
|
54
85
|
}
|
|
@@ -81,20 +112,21 @@ function getGlobalFallbackBranch() {
|
|
|
81
112
|
}
|
|
82
113
|
}
|
|
83
114
|
async function getGitBranch() {
|
|
115
|
+
const cmd = ["git", "branch", "--show-current"];
|
|
116
|
+
const fullCmd = cmd.join(" ");
|
|
117
|
+
const nodeModule = ["child", "process"].join("_");
|
|
118
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
|
84
119
|
try {
|
|
85
120
|
if (typeof require === "function") {
|
|
86
|
-
|
|
87
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
|
121
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
|
88
122
|
}
|
|
123
|
+
const { execSync } = await import(nodeModule);
|
|
124
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
|
89
125
|
} catch (err) {
|
|
90
126
|
}
|
|
91
127
|
try {
|
|
92
128
|
if (isObject(Deno)) {
|
|
93
|
-
const process2 = Deno.run({
|
|
94
|
-
cmd: ["git", "branch", "--show-current"],
|
|
95
|
-
stdout: "piped",
|
|
96
|
-
stderr: "piped"
|
|
97
|
-
});
|
|
129
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
|
98
130
|
return new TextDecoder().decode(await process2.output()).trim();
|
|
99
131
|
}
|
|
100
132
|
} catch (err) {
|
|
@@ -114,12 +146,14 @@ function getFetchImplementation(userFetch) {
|
|
|
114
146
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
|
115
147
|
const fetchImpl = userFetch ?? globalFetch;
|
|
116
148
|
if (!fetchImpl) {
|
|
117
|
-
throw new Error(
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
|
151
|
+
);
|
|
118
152
|
}
|
|
119
153
|
return fetchImpl;
|
|
120
154
|
}
|
|
121
155
|
|
|
122
|
-
const VERSION = "0.0.0-alpha.
|
|
156
|
+
const VERSION = "0.0.0-alpha.vede38ca";
|
|
123
157
|
|
|
124
158
|
class ErrorWithCause extends Error {
|
|
125
159
|
constructor(message, options) {
|
|
@@ -170,7 +204,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
|
170
204
|
}, {});
|
|
171
205
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
|
172
206
|
const queryString = query.length > 0 ? `?${query}` : "";
|
|
173
|
-
|
|
207
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
|
208
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
|
209
|
+
}, {});
|
|
210
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
|
174
211
|
};
|
|
175
212
|
function buildBaseUrl({
|
|
176
213
|
path,
|
|
@@ -178,10 +215,10 @@ function buildBaseUrl({
|
|
|
178
215
|
apiUrl,
|
|
179
216
|
pathParams
|
|
180
217
|
}) {
|
|
181
|
-
if (
|
|
218
|
+
if (pathParams?.workspace === void 0)
|
|
182
219
|
return `${apiUrl}${path}`;
|
|
183
220
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
|
184
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
|
221
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
|
185
222
|
}
|
|
186
223
|
function hostHeader(url) {
|
|
187
224
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
|
@@ -198,34 +235,63 @@ async function fetch$1({
|
|
|
198
235
|
fetchImpl,
|
|
199
236
|
apiKey,
|
|
200
237
|
apiUrl,
|
|
201
|
-
workspacesApiUrl
|
|
238
|
+
workspacesApiUrl,
|
|
239
|
+
trace
|
|
202
240
|
}) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
241
|
+
return trace(
|
|
242
|
+
`${method.toUpperCase()} ${path}`,
|
|
243
|
+
async ({ setAttributes, propagateTrace }) => {
|
|
244
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
|
245
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
|
246
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
|
247
|
+
setAttributes({
|
|
248
|
+
[TraceAttributes.HTTP_URL]: url,
|
|
249
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
|
250
|
+
});
|
|
251
|
+
const reqHeaders = {
|
|
252
|
+
"Content-Type": "application/json",
|
|
253
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
|
254
|
+
...headers,
|
|
255
|
+
...hostHeader(fullUrl),
|
|
256
|
+
Authorization: `Bearer ${apiKey}`
|
|
257
|
+
};
|
|
258
|
+
propagateTrace(reqHeaders);
|
|
259
|
+
const response = await fetchImpl(url, {
|
|
260
|
+
method: method.toUpperCase(),
|
|
261
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
262
|
+
headers: reqHeaders
|
|
263
|
+
});
|
|
264
|
+
if (response.status === 204) {
|
|
265
|
+
return {};
|
|
266
|
+
}
|
|
267
|
+
const { host, protocol } = parseUrl(response.url);
|
|
268
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
|
269
|
+
setAttributes({
|
|
270
|
+
[TraceAttributes.KIND]: "http",
|
|
271
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
|
272
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
|
273
|
+
[TraceAttributes.HTTP_HOST]: host,
|
|
274
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
|
275
|
+
});
|
|
276
|
+
try {
|
|
277
|
+
const jsonResponse = await response.json();
|
|
278
|
+
if (response.ok) {
|
|
279
|
+
return jsonResponse;
|
|
280
|
+
}
|
|
281
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
throw new FetcherError(response.status, error, requestId);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
function parseUrl(url) {
|
|
221
290
|
try {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
return jsonResponse;
|
|
225
|
-
}
|
|
226
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
|
291
|
+
const { host, protocol } = new URL(url);
|
|
292
|
+
return { host, protocol };
|
|
227
293
|
} catch (error) {
|
|
228
|
-
|
|
294
|
+
return {};
|
|
229
295
|
}
|
|
230
296
|
}
|
|
231
297
|
|
|
@@ -284,6 +350,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
|
284
350
|
...variables
|
|
285
351
|
});
|
|
286
352
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
|
353
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
|
287
354
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
|
288
355
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
|
289
356
|
method: "delete",
|
|
@@ -319,6 +386,12 @@ const deleteDatabase = (variables) => fetch$1({
|
|
|
319
386
|
method: "delete",
|
|
320
387
|
...variables
|
|
321
388
|
});
|
|
389
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
|
390
|
+
url: "/dbs/{dbName}/metadata",
|
|
391
|
+
method: "get",
|
|
392
|
+
...variables
|
|
393
|
+
});
|
|
394
|
+
const patchDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
|
322
395
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
|
323
396
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
|
324
397
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
|
@@ -327,16 +400,28 @@ const resolveBranch = (variables) => fetch$1({
|
|
|
327
400
|
method: "get",
|
|
328
401
|
...variables
|
|
329
402
|
});
|
|
330
|
-
const
|
|
331
|
-
|
|
403
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
|
404
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
|
405
|
+
const getMigrationRequest = (variables) => fetch$1({
|
|
406
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
|
332
407
|
method: "get",
|
|
333
408
|
...variables
|
|
334
409
|
});
|
|
335
|
-
const
|
|
410
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
|
411
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
|
412
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
|
413
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
|
414
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
|
415
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
|
416
|
+
method: "post",
|
|
417
|
+
...variables
|
|
418
|
+
});
|
|
419
|
+
const getBranchDetails = (variables) => fetch$1({
|
|
336
420
|
url: "/db/{dbBranchName}",
|
|
337
|
-
method: "
|
|
421
|
+
method: "get",
|
|
338
422
|
...variables
|
|
339
423
|
});
|
|
424
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
|
340
425
|
const deleteBranch = (variables) => fetch$1({
|
|
341
426
|
url: "/db/{dbBranchName}",
|
|
342
427
|
method: "delete",
|
|
@@ -355,6 +440,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
|
355
440
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
|
356
441
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
|
357
442
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
|
443
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
|
444
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
|
445
|
+
const updateBranchSchema = (variables) => fetch$1({
|
|
446
|
+
url: "/db/{dbBranchName}/schema/update",
|
|
447
|
+
method: "post",
|
|
448
|
+
...variables
|
|
449
|
+
});
|
|
450
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
|
451
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
|
452
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
|
358
453
|
const getBranchStats = (variables) => fetch$1({
|
|
359
454
|
url: "/db/{dbBranchName}/stats",
|
|
360
455
|
method: "get",
|
|
@@ -410,11 +505,7 @@ const updateColumn = (variables) => fetch$1({
|
|
|
410
505
|
method: "patch",
|
|
411
506
|
...variables
|
|
412
507
|
});
|
|
413
|
-
const insertRecord = (variables) => fetch$1({
|
|
414
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
|
415
|
-
method: "post",
|
|
416
|
-
...variables
|
|
417
|
-
});
|
|
508
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
|
418
509
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
|
419
510
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
|
420
511
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
|
@@ -456,6 +547,7 @@ const operationsByTag = {
|
|
|
456
547
|
updateWorkspaceMemberRole,
|
|
457
548
|
removeWorkspaceMember,
|
|
458
549
|
inviteWorkspaceMember,
|
|
550
|
+
updateWorkspaceMemberInvite,
|
|
459
551
|
cancelWorkspaceMemberInvite,
|
|
460
552
|
resendWorkspaceMemberInvite,
|
|
461
553
|
acceptWorkspaceMemberInvite
|
|
@@ -464,6 +556,8 @@ const operationsByTag = {
|
|
|
464
556
|
getDatabaseList,
|
|
465
557
|
createDatabase,
|
|
466
558
|
deleteDatabase,
|
|
559
|
+
getDatabaseMetadata,
|
|
560
|
+
patchDatabaseMetadata,
|
|
467
561
|
getGitBranchesMapping,
|
|
468
562
|
addGitBranchesEntry,
|
|
469
563
|
removeGitBranchesEntry,
|
|
@@ -476,10 +570,28 @@ const operationsByTag = {
|
|
|
476
570
|
deleteBranch,
|
|
477
571
|
updateBranchMetadata,
|
|
478
572
|
getBranchMetadata,
|
|
573
|
+
getBranchStats
|
|
574
|
+
},
|
|
575
|
+
migrationRequests: {
|
|
576
|
+
listMigrationRequests,
|
|
577
|
+
createMigrationRequest,
|
|
578
|
+
getMigrationRequest,
|
|
579
|
+
updateMigrationRequest,
|
|
580
|
+
listMigrationRequestsCommits,
|
|
581
|
+
compareMigrationRequest,
|
|
582
|
+
getMigrationRequestIsMerged,
|
|
583
|
+
mergeMigrationRequest
|
|
584
|
+
},
|
|
585
|
+
branchSchema: {
|
|
479
586
|
getBranchMigrationHistory,
|
|
480
587
|
executeBranchMigrationPlan,
|
|
481
588
|
getBranchMigrationPlan,
|
|
482
|
-
|
|
589
|
+
compareBranchWithUserSchema,
|
|
590
|
+
compareBranchSchemas,
|
|
591
|
+
updateBranchSchema,
|
|
592
|
+
previewBranchSchemaEdit,
|
|
593
|
+
applyBranchSchemaEdit,
|
|
594
|
+
getBranchSchemaHistory
|
|
483
595
|
},
|
|
484
596
|
table: {
|
|
485
597
|
createTable,
|
|
@@ -508,9 +620,9 @@ const operationsByTag = {
|
|
|
508
620
|
};
|
|
509
621
|
|
|
510
622
|
function getHostUrl(provider, type) {
|
|
511
|
-
if (
|
|
623
|
+
if (isHostProviderAlias(provider)) {
|
|
512
624
|
return providers[provider][type];
|
|
513
|
-
} else if (
|
|
625
|
+
} else if (isHostProviderBuilder(provider)) {
|
|
514
626
|
return provider[type];
|
|
515
627
|
}
|
|
516
628
|
throw new Error("Invalid API provider");
|
|
@@ -525,10 +637,10 @@ const providers = {
|
|
|
525
637
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
|
526
638
|
}
|
|
527
639
|
};
|
|
528
|
-
function
|
|
640
|
+
function isHostProviderAlias(alias) {
|
|
529
641
|
return isString(alias) && Object.keys(providers).includes(alias);
|
|
530
642
|
}
|
|
531
|
-
function
|
|
643
|
+
function isHostProviderBuilder(builder) {
|
|
532
644
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
|
533
645
|
}
|
|
534
646
|
|
|
@@ -556,7 +668,8 @@ class XataApiClient {
|
|
|
556
668
|
__privateAdd$7(this, _extraProps, void 0);
|
|
557
669
|
__privateAdd$7(this, _namespaces, {});
|
|
558
670
|
const provider = options.host ?? "production";
|
|
559
|
-
const apiKey = options
|
|
671
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
|
672
|
+
const trace = options.trace ?? defaultTrace;
|
|
560
673
|
if (!apiKey) {
|
|
561
674
|
throw new Error("Could not resolve a valid apiKey");
|
|
562
675
|
}
|
|
@@ -564,7 +677,8 @@ class XataApiClient {
|
|
|
564
677
|
apiUrl: getHostUrl(provider, "main"),
|
|
565
678
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
|
566
679
|
fetchImpl: getFetchImplementation(options.fetch),
|
|
567
|
-
apiKey
|
|
680
|
+
apiKey,
|
|
681
|
+
trace
|
|
568
682
|
});
|
|
569
683
|
}
|
|
570
684
|
get user() {
|
|
@@ -597,6 +711,16 @@ class XataApiClient {
|
|
|
597
711
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
|
598
712
|
return __privateGet$7(this, _namespaces).records;
|
|
599
713
|
}
|
|
714
|
+
get migrationRequests() {
|
|
715
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
|
716
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
|
717
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
|
718
|
+
}
|
|
719
|
+
get branchSchema() {
|
|
720
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
|
721
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
|
722
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
|
723
|
+
}
|
|
600
724
|
}
|
|
601
725
|
_extraProps = new WeakMap();
|
|
602
726
|
_namespaces = new WeakMap();
|
|
@@ -687,6 +811,13 @@ class WorkspaceApi {
|
|
|
687
811
|
...this.extraProps
|
|
688
812
|
});
|
|
689
813
|
}
|
|
814
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
|
815
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
|
816
|
+
pathParams: { workspaceId, inviteId },
|
|
817
|
+
body: { role },
|
|
818
|
+
...this.extraProps
|
|
819
|
+
});
|
|
820
|
+
}
|
|
690
821
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
|
691
822
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
|
692
823
|
pathParams: { workspaceId, inviteId },
|
|
@@ -729,6 +860,19 @@ class DatabaseApi {
|
|
|
729
860
|
...this.extraProps
|
|
730
861
|
});
|
|
731
862
|
}
|
|
863
|
+
getDatabaseMetadata(workspace, dbName) {
|
|
864
|
+
return operationsByTag.database.getDatabaseMetadata({
|
|
865
|
+
pathParams: { workspace, dbName },
|
|
866
|
+
...this.extraProps
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
patchDatabaseMetadata(workspace, dbName, options = {}) {
|
|
870
|
+
return operationsByTag.database.patchDatabaseMetadata({
|
|
871
|
+
pathParams: { workspace, dbName },
|
|
872
|
+
body: options,
|
|
873
|
+
...this.extraProps
|
|
874
|
+
});
|
|
875
|
+
}
|
|
732
876
|
getGitBranchesMapping(workspace, dbName) {
|
|
733
877
|
return operationsByTag.database.getGitBranchesMapping({
|
|
734
878
|
pathParams: { workspace, dbName },
|
|
@@ -800,27 +944,6 @@ class BranchApi {
|
|
|
800
944
|
...this.extraProps
|
|
801
945
|
});
|
|
802
946
|
}
|
|
803
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
|
804
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
|
805
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
806
|
-
body: options,
|
|
807
|
-
...this.extraProps
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
|
811
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
|
812
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
813
|
-
body: migrationPlan,
|
|
814
|
-
...this.extraProps
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
|
818
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
|
819
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
820
|
-
body: schema,
|
|
821
|
-
...this.extraProps
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
947
|
getBranchStats(workspace, database, branch) {
|
|
825
948
|
return operationsByTag.branch.getBranchStats({
|
|
826
949
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
@@ -901,9 +1024,10 @@ class RecordsApi {
|
|
|
901
1024
|
constructor(extraProps) {
|
|
902
1025
|
this.extraProps = extraProps;
|
|
903
1026
|
}
|
|
904
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
|
1027
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
|
905
1028
|
return operationsByTag.records.insertRecord({
|
|
906
1029
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
|
1030
|
+
queryParams: options,
|
|
907
1031
|
body: record,
|
|
908
1032
|
...this.extraProps
|
|
909
1033
|
});
|
|
@@ -932,21 +1056,24 @@ class RecordsApi {
|
|
|
932
1056
|
...this.extraProps
|
|
933
1057
|
});
|
|
934
1058
|
}
|
|
935
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
|
1059
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
|
936
1060
|
return operationsByTag.records.deleteRecord({
|
|
937
1061
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
|
1062
|
+
queryParams: options,
|
|
938
1063
|
...this.extraProps
|
|
939
1064
|
});
|
|
940
1065
|
}
|
|
941
1066
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
|
942
1067
|
return operationsByTag.records.getRecord({
|
|
943
1068
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
|
1069
|
+
queryParams: options,
|
|
944
1070
|
...this.extraProps
|
|
945
1071
|
});
|
|
946
1072
|
}
|
|
947
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
|
1073
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
|
948
1074
|
return operationsByTag.records.bulkInsertTableRecords({
|
|
949
1075
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
|
1076
|
+
queryParams: options,
|
|
950
1077
|
body: { records },
|
|
951
1078
|
...this.extraProps
|
|
952
1079
|
});
|
|
@@ -973,6 +1100,131 @@ class RecordsApi {
|
|
|
973
1100
|
});
|
|
974
1101
|
}
|
|
975
1102
|
}
|
|
1103
|
+
class MigrationRequestsApi {
|
|
1104
|
+
constructor(extraProps) {
|
|
1105
|
+
this.extraProps = extraProps;
|
|
1106
|
+
}
|
|
1107
|
+
listMigrationRequests(workspace, database, options = {}) {
|
|
1108
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
|
1109
|
+
pathParams: { workspace, dbName: database },
|
|
1110
|
+
body: options,
|
|
1111
|
+
...this.extraProps
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
createMigrationRequest(workspace, database, options) {
|
|
1115
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
|
1116
|
+
pathParams: { workspace, dbName: database },
|
|
1117
|
+
body: options,
|
|
1118
|
+
...this.extraProps
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
|
1122
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
|
1123
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1124
|
+
...this.extraProps
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
|
1128
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
|
1129
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1130
|
+
body: options,
|
|
1131
|
+
...this.extraProps
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
|
1135
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
|
1136
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1137
|
+
body: options,
|
|
1138
|
+
...this.extraProps
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
|
1142
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
|
1143
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1144
|
+
...this.extraProps
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
|
1148
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
|
1149
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1150
|
+
...this.extraProps
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
|
1154
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
|
1155
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1156
|
+
...this.extraProps
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
class BranchSchemaApi {
|
|
1161
|
+
constructor(extraProps) {
|
|
1162
|
+
this.extraProps = extraProps;
|
|
1163
|
+
}
|
|
1164
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
|
1165
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
|
1166
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1167
|
+
body: options,
|
|
1168
|
+
...this.extraProps
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
|
1172
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
|
1173
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1174
|
+
body: migrationPlan,
|
|
1175
|
+
...this.extraProps
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
|
1179
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
|
1180
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1181
|
+
body: schema,
|
|
1182
|
+
...this.extraProps
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
|
1186
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
|
1187
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1188
|
+
body: { schema },
|
|
1189
|
+
...this.extraProps
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
|
1193
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
|
1194
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
|
1195
|
+
body: { schema },
|
|
1196
|
+
...this.extraProps
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
|
1200
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
|
1201
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1202
|
+
body: migration,
|
|
1203
|
+
...this.extraProps
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
|
1207
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
|
1208
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1209
|
+
body: migration,
|
|
1210
|
+
...this.extraProps
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
|
1214
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
|
1215
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1216
|
+
body: { edits },
|
|
1217
|
+
...this.extraProps
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
|
1221
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
|
1222
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1223
|
+
body: options,
|
|
1224
|
+
...this.extraProps
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
976
1228
|
|
|
977
1229
|
class XataApiPlugin {
|
|
978
1230
|
async build(options) {
|
|
@@ -1035,10 +1287,10 @@ function isCursorPaginationOptions(options) {
|
|
|
1035
1287
|
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
|
1036
1288
|
}
|
|
1037
1289
|
const _RecordArray = class extends Array {
|
|
1038
|
-
constructor(
|
|
1039
|
-
super(..._RecordArray.parseConstructorParams(
|
|
1290
|
+
constructor(...args) {
|
|
1291
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
|
1040
1292
|
__privateAdd$6(this, _page, void 0);
|
|
1041
|
-
__privateSet$6(this, _page, page);
|
|
1293
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
|
1042
1294
|
}
|
|
1043
1295
|
static parseConstructorParams(...args) {
|
|
1044
1296
|
if (args.length === 1 && typeof args[0] === "number") {
|
|
@@ -1050,6 +1302,12 @@ const _RecordArray = class extends Array {
|
|
|
1050
1302
|
}
|
|
1051
1303
|
return new Array(...args);
|
|
1052
1304
|
}
|
|
1305
|
+
toArray() {
|
|
1306
|
+
return new Array(...this);
|
|
1307
|
+
}
|
|
1308
|
+
map(callbackfn, thisArg) {
|
|
1309
|
+
return this.toArray().map(callbackfn, thisArg);
|
|
1310
|
+
}
|
|
1053
1311
|
async nextPage(size, offset) {
|
|
1054
1312
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
|
1055
1313
|
return new _RecordArray(newPage);
|
|
@@ -1150,21 +1408,34 @@ const _Query = class {
|
|
|
1150
1408
|
}
|
|
1151
1409
|
filter(a, b) {
|
|
1152
1410
|
if (arguments.length === 1) {
|
|
1153
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
|
1411
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
|
1154
1412
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1155
1413
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1156
1414
|
} else {
|
|
1157
|
-
const
|
|
1415
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
|
1416
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1158
1417
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1159
1418
|
}
|
|
1160
1419
|
}
|
|
1161
|
-
|
|
1420
|
+
defaultFilter(column, value) {
|
|
1421
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
|
1422
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
|
1423
|
+
return { $includes: value };
|
|
1424
|
+
}
|
|
1425
|
+
return value;
|
|
1426
|
+
}
|
|
1427
|
+
sort(column, direction = "asc") {
|
|
1162
1428
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
|
1163
1429
|
const sort = [...originalSort, { column, direction }];
|
|
1164
1430
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
|
1165
1431
|
}
|
|
1166
1432
|
select(columns) {
|
|
1167
|
-
return new _Query(
|
|
1433
|
+
return new _Query(
|
|
1434
|
+
__privateGet$5(this, _repository),
|
|
1435
|
+
__privateGet$5(this, _table$1),
|
|
1436
|
+
{ columns },
|
|
1437
|
+
__privateGet$5(this, _data)
|
|
1438
|
+
);
|
|
1168
1439
|
}
|
|
1169
1440
|
getPaginated(options = {}) {
|
|
1170
1441
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
|
@@ -1289,203 +1560,228 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
|
1289
1560
|
__accessCheck$4(obj, member, "access private method");
|
|
1290
1561
|
return method;
|
|
1291
1562
|
};
|
|
1292
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
|
1563
|
+
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;
|
|
1293
1564
|
class Repository extends Query {
|
|
1294
1565
|
}
|
|
1295
1566
|
class RestRepository extends Query {
|
|
1296
1567
|
constructor(options) {
|
|
1297
|
-
super(
|
|
1568
|
+
super(
|
|
1569
|
+
null,
|
|
1570
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
|
1571
|
+
{}
|
|
1572
|
+
);
|
|
1298
1573
|
__privateAdd$4(this, _insertRecordWithoutId);
|
|
1299
1574
|
__privateAdd$4(this, _insertRecordWithId);
|
|
1300
1575
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
|
1301
1576
|
__privateAdd$4(this, _updateRecordWithID);
|
|
1302
1577
|
__privateAdd$4(this, _upsertRecordWithID);
|
|
1303
1578
|
__privateAdd$4(this, _deleteRecord);
|
|
1304
|
-
__privateAdd$4(this, _invalidateCache);
|
|
1305
|
-
__privateAdd$4(this, _setCacheRecord);
|
|
1306
|
-
__privateAdd$4(this, _getCacheRecord);
|
|
1307
1579
|
__privateAdd$4(this, _setCacheQuery);
|
|
1308
1580
|
__privateAdd$4(this, _getCacheQuery);
|
|
1309
1581
|
__privateAdd$4(this, _getSchemaTables$1);
|
|
1310
1582
|
__privateAdd$4(this, _table, void 0);
|
|
1311
1583
|
__privateAdd$4(this, _getFetchProps, void 0);
|
|
1584
|
+
__privateAdd$4(this, _db, void 0);
|
|
1312
1585
|
__privateAdd$4(this, _cache, void 0);
|
|
1313
1586
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
|
1587
|
+
__privateAdd$4(this, _trace, void 0);
|
|
1314
1588
|
__privateSet$4(this, _table, options.table);
|
|
1315
1589
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
|
1316
|
-
this
|
|
1590
|
+
__privateSet$4(this, _db, options.db);
|
|
1317
1591
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
|
1318
1592
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
|
1593
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
|
1594
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
|
1595
|
+
return trace("sdk op: " + name, fn, {
|
|
1596
|
+
...options2,
|
|
1597
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
|
1598
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
|
1599
|
+
[TraceAttributes.VERSION]: VERSION
|
|
1600
|
+
});
|
|
1601
|
+
});
|
|
1319
1602
|
}
|
|
1320
|
-
async create(a, b) {
|
|
1321
|
-
|
|
1322
|
-
if (a
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
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
|
-
const
|
|
1362
|
-
|
|
1363
|
-
const
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1603
|
+
async create(a, b, c) {
|
|
1604
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
|
1605
|
+
if (Array.isArray(a)) {
|
|
1606
|
+
if (a.length === 0)
|
|
1607
|
+
return [];
|
|
1608
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1609
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
|
1610
|
+
}
|
|
1611
|
+
if (isString(a) && isObject(b)) {
|
|
1612
|
+
if (a === "")
|
|
1613
|
+
throw new Error("The id can't be empty");
|
|
1614
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1615
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
|
1616
|
+
}
|
|
1617
|
+
if (isObject(a) && isString(a.id)) {
|
|
1618
|
+
if (a.id === "")
|
|
1619
|
+
throw new Error("The id can't be empty");
|
|
1620
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1621
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1622
|
+
}
|
|
1623
|
+
if (isObject(a)) {
|
|
1624
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1625
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
|
1626
|
+
}
|
|
1627
|
+
throw new Error("Invalid arguments for create method");
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
async read(a, b) {
|
|
1631
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
|
1632
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1633
|
+
if (Array.isArray(a)) {
|
|
1634
|
+
if (a.length === 0)
|
|
1635
|
+
return [];
|
|
1636
|
+
const ids = a.map((item) => extractId(item));
|
|
1637
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
|
1638
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
|
1639
|
+
acc[object.id] = object;
|
|
1640
|
+
return acc;
|
|
1641
|
+
}, {});
|
|
1642
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
|
1643
|
+
}
|
|
1644
|
+
const id = extractId(a);
|
|
1645
|
+
if (id) {
|
|
1646
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1647
|
+
try {
|
|
1648
|
+
const response = await getRecord({
|
|
1649
|
+
pathParams: {
|
|
1650
|
+
workspace: "{workspaceId}",
|
|
1651
|
+
dbBranchName: "{dbBranch}",
|
|
1652
|
+
tableName: __privateGet$4(this, _table),
|
|
1653
|
+
recordId: id
|
|
1654
|
+
},
|
|
1655
|
+
queryParams: { columns },
|
|
1656
|
+
...fetchProps
|
|
1657
|
+
});
|
|
1658
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1659
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1660
|
+
} catch (e) {
|
|
1661
|
+
if (isObject(e) && e.status === 404) {
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
throw e;
|
|
1372
1665
|
}
|
|
1373
|
-
throw e;
|
|
1374
1666
|
}
|
|
1375
|
-
|
|
1667
|
+
return null;
|
|
1668
|
+
});
|
|
1376
1669
|
}
|
|
1377
|
-
async update(a, b) {
|
|
1378
|
-
|
|
1379
|
-
if (a
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1670
|
+
async update(a, b, c) {
|
|
1671
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
|
1672
|
+
if (Array.isArray(a)) {
|
|
1673
|
+
if (a.length === 0)
|
|
1674
|
+
return [];
|
|
1675
|
+
if (a.length > 100) {
|
|
1676
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1677
|
+
}
|
|
1678
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1679
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
|
1383
1680
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
|
1388
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
|
1389
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1390
|
-
return record;
|
|
1391
|
-
}
|
|
1392
|
-
if (isObject(a) && isString(a.id)) {
|
|
1393
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
|
1394
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
|
1395
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1396
|
-
return record;
|
|
1397
|
-
}
|
|
1398
|
-
throw new Error("Invalid arguments for update method");
|
|
1399
|
-
}
|
|
1400
|
-
async createOrUpdate(a, b) {
|
|
1401
|
-
if (Array.isArray(a)) {
|
|
1402
|
-
if (a.length === 0)
|
|
1403
|
-
return [];
|
|
1404
|
-
if (a.length > 100) {
|
|
1405
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1681
|
+
if (isString(a) && isObject(b)) {
|
|
1682
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1683
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
|
1406
1684
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
|
1411
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
|
|
1412
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1413
|
-
return record;
|
|
1414
|
-
}
|
|
1415
|
-
if (isObject(a) && isString(a.id)) {
|
|
1416
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
|
1417
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
|
1418
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1419
|
-
return record;
|
|
1420
|
-
}
|
|
1421
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
|
1422
|
-
}
|
|
1423
|
-
async delete(a) {
|
|
1424
|
-
if (Array.isArray(a)) {
|
|
1425
|
-
if (a.length === 0)
|
|
1426
|
-
return;
|
|
1427
|
-
if (a.length > 100) {
|
|
1428
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
1685
|
+
if (isObject(a) && isString(a.id)) {
|
|
1686
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1687
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1429
1688
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1689
|
+
throw new Error("Invalid arguments for update method");
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
async createOrUpdate(a, b, c) {
|
|
1693
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
|
1694
|
+
if (Array.isArray(a)) {
|
|
1695
|
+
if (a.length === 0)
|
|
1696
|
+
return [];
|
|
1697
|
+
if (a.length > 100) {
|
|
1698
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1699
|
+
}
|
|
1700
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1701
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
|
1702
|
+
}
|
|
1703
|
+
if (isString(a) && isObject(b)) {
|
|
1704
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1705
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
|
1706
|
+
}
|
|
1707
|
+
if (isObject(a) && isString(a.id)) {
|
|
1708
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1709
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1710
|
+
}
|
|
1711
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
async delete(a, b) {
|
|
1715
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
|
1716
|
+
if (Array.isArray(a)) {
|
|
1717
|
+
if (a.length === 0)
|
|
1718
|
+
return [];
|
|
1719
|
+
if (a.length > 100) {
|
|
1720
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
1721
|
+
}
|
|
1722
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
|
1723
|
+
}
|
|
1724
|
+
if (isString(a)) {
|
|
1725
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
|
1726
|
+
}
|
|
1727
|
+
if (isObject(a) && isString(a.id)) {
|
|
1728
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
|
1729
|
+
}
|
|
1730
|
+
throw new Error("Invalid arguments for delete method");
|
|
1731
|
+
});
|
|
1444
1732
|
}
|
|
1445
1733
|
async search(query, options = {}) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1734
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
|
1735
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1736
|
+
const { records } = await searchTable({
|
|
1737
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1738
|
+
body: {
|
|
1739
|
+
query,
|
|
1740
|
+
fuzziness: options.fuzziness,
|
|
1741
|
+
prefix: options.prefix,
|
|
1742
|
+
highlight: options.highlight,
|
|
1743
|
+
filter: options.filter,
|
|
1744
|
+
boosters: options.boosters
|
|
1745
|
+
},
|
|
1746
|
+
...fetchProps
|
|
1747
|
+
});
|
|
1748
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1749
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
|
1456
1750
|
});
|
|
1457
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1458
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
|
1459
1751
|
}
|
|
1460
1752
|
async query(query) {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1753
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
|
1754
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
|
1755
|
+
if (cacheQuery)
|
|
1756
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
|
1757
|
+
const data = query.getQueryOptions();
|
|
1758
|
+
const body = {
|
|
1759
|
+
filter: cleanFilter(data.filter),
|
|
1760
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
|
1761
|
+
page: data.pagination,
|
|
1762
|
+
columns: data.columns
|
|
1763
|
+
};
|
|
1764
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1765
|
+
const { meta, records: objects } = await queryTable({
|
|
1766
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1767
|
+
body,
|
|
1768
|
+
...fetchProps
|
|
1769
|
+
});
|
|
1770
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1771
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
|
1772
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
1773
|
+
return new Page(query, meta, records);
|
|
1476
1774
|
});
|
|
1477
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1478
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
|
1479
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
1480
|
-
return new Page(query, meta, records);
|
|
1481
1775
|
}
|
|
1482
1776
|
}
|
|
1483
1777
|
_table = new WeakMap();
|
|
1484
1778
|
_getFetchProps = new WeakMap();
|
|
1779
|
+
_db = new WeakMap();
|
|
1485
1780
|
_cache = new WeakMap();
|
|
1486
1781
|
_schemaTables$2 = new WeakMap();
|
|
1782
|
+
_trace = new WeakMap();
|
|
1487
1783
|
_insertRecordWithoutId = new WeakSet();
|
|
1488
|
-
insertRecordWithoutId_fn = async function(object) {
|
|
1784
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1489
1785
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1490
1786
|
const record = transformObjectLinks(object);
|
|
1491
1787
|
const response = await insertRecord({
|
|
@@ -1494,17 +1790,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
|
1494
1790
|
dbBranchName: "{dbBranch}",
|
|
1495
1791
|
tableName: __privateGet$4(this, _table)
|
|
1496
1792
|
},
|
|
1793
|
+
queryParams: { columns },
|
|
1497
1794
|
body: record,
|
|
1498
1795
|
...fetchProps
|
|
1499
1796
|
});
|
|
1500
|
-
const
|
|
1501
|
-
|
|
1502
|
-
throw new Error("The server failed to save the record");
|
|
1503
|
-
}
|
|
1504
|
-
return finalObject;
|
|
1797
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1798
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1505
1799
|
};
|
|
1506
1800
|
_insertRecordWithId = new WeakSet();
|
|
1507
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
|
1801
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1508
1802
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1509
1803
|
const record = transformObjectLinks(object);
|
|
1510
1804
|
const response = await insertRecordWithID({
|
|
@@ -1515,92 +1809,78 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
|
1515
1809
|
recordId
|
|
1516
1810
|
},
|
|
1517
1811
|
body: record,
|
|
1518
|
-
queryParams: { createOnly: true },
|
|
1812
|
+
queryParams: { createOnly: true, columns },
|
|
1519
1813
|
...fetchProps
|
|
1520
1814
|
});
|
|
1521
|
-
const
|
|
1522
|
-
|
|
1523
|
-
throw new Error("The server failed to save the record");
|
|
1524
|
-
}
|
|
1525
|
-
return finalObject;
|
|
1815
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1816
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1526
1817
|
};
|
|
1527
1818
|
_bulkInsertTableRecords = new WeakSet();
|
|
1528
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
|
1819
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1529
1820
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1530
1821
|
const records = objects.map((object) => transformObjectLinks(object));
|
|
1531
|
-
const
|
|
1822
|
+
const response = await bulkInsertTableRecords({
|
|
1532
1823
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1824
|
+
queryParams: { columns },
|
|
1533
1825
|
body: { records },
|
|
1534
1826
|
...fetchProps
|
|
1535
1827
|
});
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
throw new Error("The server failed to save some records");
|
|
1828
|
+
if (!isResponseWithRecords(response)) {
|
|
1829
|
+
throw new Error("Request included columns but server didn't include them");
|
|
1539
1830
|
}
|
|
1540
|
-
const
|
|
1541
|
-
|
|
1542
|
-
return acc;
|
|
1543
|
-
}, {});
|
|
1544
|
-
return recordIDs.map((id) => dictionary[id]);
|
|
1831
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1832
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
|
1545
1833
|
};
|
|
1546
1834
|
_updateRecordWithID = new WeakSet();
|
|
1547
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
|
1835
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1548
1836
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1549
1837
|
const record = transformObjectLinks(object);
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1838
|
+
try {
|
|
1839
|
+
const response = await updateRecordWithID({
|
|
1840
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
1841
|
+
queryParams: { columns },
|
|
1842
|
+
body: record,
|
|
1843
|
+
...fetchProps
|
|
1844
|
+
});
|
|
1845
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1846
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1847
|
+
} catch (e) {
|
|
1848
|
+
if (isObject(e) && e.status === 404) {
|
|
1849
|
+
return null;
|
|
1850
|
+
}
|
|
1851
|
+
throw e;
|
|
1852
|
+
}
|
|
1559
1853
|
};
|
|
1560
1854
|
_upsertRecordWithID = new WeakSet();
|
|
1561
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
|
1855
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1562
1856
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1563
1857
|
const response = await upsertRecordWithID({
|
|
1564
1858
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
1859
|
+
queryParams: { columns },
|
|
1565
1860
|
body: object,
|
|
1566
1861
|
...fetchProps
|
|
1567
1862
|
});
|
|
1568
|
-
const
|
|
1569
|
-
|
|
1570
|
-
throw new Error("The server failed to save the record");
|
|
1571
|
-
return item;
|
|
1863
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1864
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1572
1865
|
};
|
|
1573
1866
|
_deleteRecord = new WeakSet();
|
|
1574
|
-
deleteRecord_fn = async function(recordId) {
|
|
1867
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
1575
1868
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
await __privateGet$4(this, _cache).delete(key);
|
|
1869
|
+
try {
|
|
1870
|
+
const response = await deleteRecord({
|
|
1871
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
1872
|
+
queryParams: { columns },
|
|
1873
|
+
...fetchProps
|
|
1874
|
+
});
|
|
1875
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1876
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1877
|
+
} catch (e) {
|
|
1878
|
+
if (isObject(e) && e.status === 404) {
|
|
1879
|
+
return null;
|
|
1880
|
+
}
|
|
1881
|
+
throw e;
|
|
1590
1882
|
}
|
|
1591
1883
|
};
|
|
1592
|
-
_setCacheRecord = new WeakSet();
|
|
1593
|
-
setCacheRecord_fn = async function(record) {
|
|
1594
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
|
1595
|
-
return;
|
|
1596
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
|
1597
|
-
};
|
|
1598
|
-
_getCacheRecord = new WeakSet();
|
|
1599
|
-
getCacheRecord_fn = async function(recordId) {
|
|
1600
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
|
1601
|
-
return null;
|
|
1602
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
|
1603
|
-
};
|
|
1604
1884
|
_setCacheQuery = new WeakSet();
|
|
1605
1885
|
setCacheQuery_fn = async function(query, meta, records) {
|
|
1606
1886
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
|
@@ -1666,11 +1946,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
|
1666
1946
|
}
|
|
1667
1947
|
}
|
|
1668
1948
|
}
|
|
1669
|
-
result.read = function() {
|
|
1670
|
-
return db[table].read(result["id"]);
|
|
1949
|
+
result.read = function(columns2) {
|
|
1950
|
+
return db[table].read(result["id"], columns2);
|
|
1671
1951
|
};
|
|
1672
|
-
result.update = function(data) {
|
|
1673
|
-
return db[table].update(result["id"], data);
|
|
1952
|
+
result.update = function(data, columns2) {
|
|
1953
|
+
return db[table].update(result["id"], data, columns2);
|
|
1674
1954
|
};
|
|
1675
1955
|
result.delete = function() {
|
|
1676
1956
|
return db[table].delete(result["id"]);
|
|
@@ -1684,14 +1964,21 @@ const initObject = (db, schemaTables, table, object) => {
|
|
|
1684
1964
|
Object.freeze(result);
|
|
1685
1965
|
return result;
|
|
1686
1966
|
};
|
|
1687
|
-
function
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
if (
|
|
1692
|
-
return
|
|
1693
|
-
|
|
1694
|
-
|
|
1967
|
+
function isResponseWithRecords(value) {
|
|
1968
|
+
return isObject(value) && Array.isArray(value.records);
|
|
1969
|
+
}
|
|
1970
|
+
function extractId(value) {
|
|
1971
|
+
if (isString(value))
|
|
1972
|
+
return value;
|
|
1973
|
+
if (isObject(value) && isString(value.id))
|
|
1974
|
+
return value.id;
|
|
1975
|
+
return void 0;
|
|
1976
|
+
}
|
|
1977
|
+
function cleanFilter(filter) {
|
|
1978
|
+
if (!filter)
|
|
1979
|
+
return void 0;
|
|
1980
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
|
1981
|
+
return values.length > 0 ? filter : void 0;
|
|
1695
1982
|
}
|
|
1696
1983
|
|
|
1697
1984
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
@@ -1718,7 +2005,6 @@ class SimpleCache {
|
|
|
1718
2005
|
__privateAdd$3(this, _map, void 0);
|
|
1719
2006
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
|
1720
2007
|
this.capacity = options.max ?? 500;
|
|
1721
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
|
1722
2008
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
|
1723
2009
|
}
|
|
1724
2010
|
async getAll() {
|
|
@@ -1744,18 +2030,25 @@ class SimpleCache {
|
|
|
1744
2030
|
}
|
|
1745
2031
|
_map = new WeakMap();
|
|
1746
2032
|
|
|
1747
|
-
const
|
|
1748
|
-
const
|
|
1749
|
-
const
|
|
1750
|
-
const
|
|
1751
|
-
const
|
|
1752
|
-
const
|
|
2033
|
+
const greaterThan = (value) => ({ $gt: value });
|
|
2034
|
+
const gt = greaterThan;
|
|
2035
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
|
2036
|
+
const greaterEquals = greaterThanEquals;
|
|
2037
|
+
const gte = greaterThanEquals;
|
|
2038
|
+
const ge = greaterThanEquals;
|
|
2039
|
+
const lessThan = (value) => ({ $lt: value });
|
|
2040
|
+
const lt = lessThan;
|
|
2041
|
+
const lessThanEquals = (value) => ({ $le: value });
|
|
2042
|
+
const lessEquals = lessThanEquals;
|
|
2043
|
+
const lte = lessThanEquals;
|
|
2044
|
+
const le = lessThanEquals;
|
|
1753
2045
|
const exists = (column) => ({ $exists: column });
|
|
1754
2046
|
const notExists = (column) => ({ $notExists: column });
|
|
1755
2047
|
const startsWith = (value) => ({ $startsWith: value });
|
|
1756
2048
|
const endsWith = (value) => ({ $endsWith: value });
|
|
1757
2049
|
const pattern = (value) => ({ $pattern: value });
|
|
1758
2050
|
const is = (value) => ({ $is: value });
|
|
2051
|
+
const equals = is;
|
|
1759
2052
|
const isNot = (value) => ({ $isNot: value });
|
|
1760
2053
|
const contains = (value) => ({ $contains: value });
|
|
1761
2054
|
const includes = (value) => ({ $includes: value });
|
|
@@ -1790,16 +2083,19 @@ class SchemaPlugin extends XataPlugin {
|
|
|
1790
2083
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
|
1791
2084
|
}
|
|
1792
2085
|
build(pluginOptions) {
|
|
1793
|
-
const db = new Proxy(
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
2086
|
+
const db = new Proxy(
|
|
2087
|
+
{},
|
|
2088
|
+
{
|
|
2089
|
+
get: (_target, table) => {
|
|
2090
|
+
if (!isString(table))
|
|
2091
|
+
throw new Error("Invalid table name");
|
|
2092
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
|
2093
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
|
2094
|
+
}
|
|
2095
|
+
return __privateGet$2(this, _tables)[table];
|
|
1799
2096
|
}
|
|
1800
|
-
return __privateGet$2(this, _tables)[table];
|
|
1801
2097
|
}
|
|
1802
|
-
|
|
2098
|
+
);
|
|
1803
2099
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
|
1804
2100
|
for (const table of tableNames) {
|
|
1805
2101
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
|
@@ -1869,10 +2165,10 @@ _schemaTables = new WeakMap();
|
|
|
1869
2165
|
_search = new WeakSet();
|
|
1870
2166
|
search_fn = async function(query, options, getFetchProps) {
|
|
1871
2167
|
const fetchProps = await getFetchProps();
|
|
1872
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
|
2168
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
|
1873
2169
|
const { records } = await searchBranch({
|
|
1874
2170
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
1875
|
-
body: { tables, query, fuzziness, highlight },
|
|
2171
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
|
1876
2172
|
...fetchProps
|
|
1877
2173
|
});
|
|
1878
2174
|
return records;
|
|
@@ -1895,14 +2191,14 @@ const isBranchStrategyBuilder = (strategy) => {
|
|
|
1895
2191
|
};
|
|
1896
2192
|
|
|
1897
2193
|
async function getCurrentBranchName(options) {
|
|
1898
|
-
const { branch } = getEnvironment();
|
|
2194
|
+
const { branch, envBranch } = getEnvironment();
|
|
1899
2195
|
if (branch) {
|
|
1900
2196
|
const details = await getDatabaseBranch(branch, options);
|
|
1901
2197
|
if (details)
|
|
1902
2198
|
return branch;
|
|
1903
2199
|
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
|
1904
2200
|
}
|
|
1905
|
-
const gitBranch = await getGitBranch();
|
|
2201
|
+
const gitBranch = envBranch || await getGitBranch();
|
|
1906
2202
|
return resolveXataBranch(gitBranch, options);
|
|
1907
2203
|
}
|
|
1908
2204
|
async function getCurrentBranchDetails(options) {
|
|
@@ -1913,9 +2209,13 @@ async function resolveXataBranch(gitBranch, options) {
|
|
|
1913
2209
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1914
2210
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1915
2211
|
if (!databaseURL)
|
|
1916
|
-
throw new Error(
|
|
2212
|
+
throw new Error(
|
|
2213
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
2214
|
+
);
|
|
1917
2215
|
if (!apiKey)
|
|
1918
|
-
throw new Error(
|
|
2216
|
+
throw new Error(
|
|
2217
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
2218
|
+
);
|
|
1919
2219
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
|
1920
2220
|
const [workspace] = host.split(".");
|
|
1921
2221
|
const { fallbackBranch } = getEnvironment();
|
|
@@ -1925,7 +2225,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
|
1925
2225
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1926
2226
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1927
2227
|
pathParams: { dbName, workspace },
|
|
1928
|
-
queryParams: { gitBranch, fallbackBranch }
|
|
2228
|
+
queryParams: { gitBranch, fallbackBranch },
|
|
2229
|
+
trace: defaultTrace
|
|
1929
2230
|
});
|
|
1930
2231
|
return branch;
|
|
1931
2232
|
}
|
|
@@ -1933,9 +2234,13 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1933
2234
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1934
2235
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1935
2236
|
if (!databaseURL)
|
|
1936
|
-
throw new Error(
|
|
2237
|
+
throw new Error(
|
|
2238
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
2239
|
+
);
|
|
1937
2240
|
if (!apiKey)
|
|
1938
|
-
throw new Error(
|
|
2241
|
+
throw new Error(
|
|
2242
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
2243
|
+
);
|
|
1939
2244
|
const [protocol, , host, , database] = databaseURL.split("/");
|
|
1940
2245
|
const [workspace] = host.split(".");
|
|
1941
2246
|
const dbBranchName = `${database}:${branch}`;
|
|
@@ -1945,7 +2250,8 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1945
2250
|
apiUrl: databaseURL,
|
|
1946
2251
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1947
2252
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1948
|
-
pathParams: { dbBranchName, workspace }
|
|
2253
|
+
pathParams: { dbBranchName, workspace },
|
|
2254
|
+
trace: defaultTrace
|
|
1949
2255
|
});
|
|
1950
2256
|
} catch (err) {
|
|
1951
2257
|
if (isObject(err) && err.status === 404)
|
|
@@ -1985,17 +2291,20 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1985
2291
|
return method;
|
|
1986
2292
|
};
|
|
1987
2293
|
const buildClient = (plugins) => {
|
|
1988
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
|
2294
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
|
1989
2295
|
return _a = class {
|
|
1990
2296
|
constructor(options = {}, schemaTables) {
|
|
1991
2297
|
__privateAdd(this, _parseOptions);
|
|
1992
2298
|
__privateAdd(this, _getFetchProps);
|
|
1993
2299
|
__privateAdd(this, _evaluateBranch);
|
|
1994
2300
|
__privateAdd(this, _branch, void 0);
|
|
2301
|
+
__privateAdd(this, _options, void 0);
|
|
1995
2302
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
|
2303
|
+
__privateSet(this, _options, safeOptions);
|
|
1996
2304
|
const pluginOptions = {
|
|
1997
2305
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
|
1998
|
-
cache: safeOptions.cache
|
|
2306
|
+
cache: safeOptions.cache,
|
|
2307
|
+
trace: safeOptions.trace
|
|
1999
2308
|
};
|
|
2000
2309
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
|
2001
2310
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
|
@@ -2014,22 +2323,26 @@ const buildClient = (plugins) => {
|
|
|
2014
2323
|
}
|
|
2015
2324
|
}
|
|
2016
2325
|
}
|
|
2017
|
-
|
|
2326
|
+
async getConfig() {
|
|
2327
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
|
2328
|
+
const branch = await __privateGet(this, _options).branch();
|
|
2329
|
+
return { databaseURL, branch };
|
|
2330
|
+
}
|
|
2331
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
|
2018
2332
|
const fetch = getFetchImplementation(options?.fetch);
|
|
2019
2333
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
2020
2334
|
const apiKey = options?.apiKey || getAPIKey();
|
|
2021
|
-
const cache = options?.cache ?? new SimpleCache({
|
|
2335
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
|
2336
|
+
const trace = options?.trace ?? defaultTrace;
|
|
2022
2337
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
|
2023
|
-
if (!
|
|
2024
|
-
throw new Error("
|
|
2338
|
+
if (!apiKey) {
|
|
2339
|
+
throw new Error("Option apiKey is required");
|
|
2025
2340
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
apiKey,
|
|
2030
|
-
|
|
2031
|
-
branch
|
|
2032
|
-
}) {
|
|
2341
|
+
if (!databaseURL) {
|
|
2342
|
+
throw new Error("Option databaseURL is required");
|
|
2343
|
+
}
|
|
2344
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
|
2345
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
|
2033
2346
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
|
2034
2347
|
if (!branchValue)
|
|
2035
2348
|
throw new Error("Unable to resolve branch value");
|
|
@@ -2039,9 +2352,10 @@ const buildClient = (plugins) => {
|
|
|
2039
2352
|
apiUrl: "",
|
|
2040
2353
|
workspacesApiUrl: (path, params) => {
|
|
2041
2354
|
const hasBranch = params.dbBranchName ?? params.branch;
|
|
2042
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
|
2355
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
|
2043
2356
|
return databaseURL + newPath;
|
|
2044
|
-
}
|
|
2357
|
+
},
|
|
2358
|
+
trace
|
|
2045
2359
|
};
|
|
2046
2360
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
|
2047
2361
|
if (__privateGet(this, _branch))
|
|
@@ -2064,6 +2378,88 @@ const buildClient = (plugins) => {
|
|
|
2064
2378
|
class BaseClient extends buildClient() {
|
|
2065
2379
|
}
|
|
2066
2380
|
|
|
2381
|
+
const META = "__";
|
|
2382
|
+
const VALUE = "___";
|
|
2383
|
+
class Serializer {
|
|
2384
|
+
constructor() {
|
|
2385
|
+
this.classes = {};
|
|
2386
|
+
}
|
|
2387
|
+
add(clazz) {
|
|
2388
|
+
this.classes[clazz.name] = clazz;
|
|
2389
|
+
}
|
|
2390
|
+
toJSON(data) {
|
|
2391
|
+
function visit(obj) {
|
|
2392
|
+
if (Array.isArray(obj))
|
|
2393
|
+
return obj.map(visit);
|
|
2394
|
+
const type = typeof obj;
|
|
2395
|
+
if (type === "undefined")
|
|
2396
|
+
return { [META]: "undefined" };
|
|
2397
|
+
if (type === "bigint")
|
|
2398
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
|
2399
|
+
if (obj === null || type !== "object")
|
|
2400
|
+
return obj;
|
|
2401
|
+
const constructor = obj.constructor;
|
|
2402
|
+
const o = { [META]: constructor.name };
|
|
2403
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2404
|
+
o[key] = visit(value);
|
|
2405
|
+
}
|
|
2406
|
+
if (constructor === Date)
|
|
2407
|
+
o[VALUE] = obj.toISOString();
|
|
2408
|
+
if (constructor === Map)
|
|
2409
|
+
o[VALUE] = Object.fromEntries(obj);
|
|
2410
|
+
if (constructor === Set)
|
|
2411
|
+
o[VALUE] = [...obj];
|
|
2412
|
+
return o;
|
|
2413
|
+
}
|
|
2414
|
+
return JSON.stringify(visit(data));
|
|
2415
|
+
}
|
|
2416
|
+
fromJSON(json) {
|
|
2417
|
+
return JSON.parse(json, (key, value) => {
|
|
2418
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
2419
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
|
2420
|
+
const constructor = this.classes[clazz];
|
|
2421
|
+
if (constructor) {
|
|
2422
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
|
2423
|
+
}
|
|
2424
|
+
if (clazz === "Date")
|
|
2425
|
+
return new Date(val);
|
|
2426
|
+
if (clazz === "Set")
|
|
2427
|
+
return new Set(val);
|
|
2428
|
+
if (clazz === "Map")
|
|
2429
|
+
return new Map(Object.entries(val));
|
|
2430
|
+
if (clazz === "bigint")
|
|
2431
|
+
return BigInt(val);
|
|
2432
|
+
if (clazz === "undefined")
|
|
2433
|
+
return void 0;
|
|
2434
|
+
return rest;
|
|
2435
|
+
}
|
|
2436
|
+
return value;
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
const defaultSerializer = new Serializer();
|
|
2441
|
+
const serialize = (data) => {
|
|
2442
|
+
return defaultSerializer.toJSON(data);
|
|
2443
|
+
};
|
|
2444
|
+
const deserialize = (json) => {
|
|
2445
|
+
return defaultSerializer.fromJSON(json);
|
|
2446
|
+
};
|
|
2447
|
+
|
|
2448
|
+
function buildWorkerRunner(config) {
|
|
2449
|
+
return function xataWorker(name, _worker) {
|
|
2450
|
+
return async (...args) => {
|
|
2451
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
|
2452
|
+
const result = await fetch(url, {
|
|
2453
|
+
method: "POST",
|
|
2454
|
+
headers: { "Content-Type": "application/json" },
|
|
2455
|
+
body: serialize({ args })
|
|
2456
|
+
});
|
|
2457
|
+
const text = await result.text();
|
|
2458
|
+
return deserialize(text);
|
|
2459
|
+
};
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2067
2463
|
class XataError extends Error {
|
|
2068
2464
|
constructor(message, status) {
|
|
2069
2465
|
super(message);
|
|
@@ -2071,5 +2467,5 @@ class XataError extends Error {
|
|
|
2071
2467
|
}
|
|
2072
2468
|
}
|
|
2073
2469
|
|
|
2074
|
-
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 };
|
|
2470
|
+
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, patchDatabaseMetadata, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateBranchSchema, updateColumn, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
|
2075
2471
|
//# sourceMappingURL=index.mjs.map
|