@xata.io/client 0.0.0-alpha.vfe4ae98 → 0.0.0-alpha.vfe9bed6
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 +116 -0
- package/README.md +27 -25
- package/Usage.md +62 -6
- package/dist/index.cjs +957 -387
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2225 -234
- package/dist/index.mjs +911 -388
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
const defaultTrace = async (_name, fn, _options) => {
|
2
|
+
return await fn({
|
3
|
+
setAttributes: () => {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
});
|
7
|
+
};
|
8
|
+
const TraceAttributes = {
|
9
|
+
KIND: "xata.trace.kind",
|
10
|
+
VERSION: "xata.sdk.version",
|
11
|
+
TABLE: "xata.table",
|
12
|
+
HTTP_REQUEST_ID: "http.request_id",
|
13
|
+
HTTP_STATUS_CODE: "http.status_code",
|
14
|
+
HTTP_HOST: "http.host",
|
15
|
+
HTTP_SCHEME: "http.scheme",
|
16
|
+
HTTP_USER_AGENT: "http.user_agent",
|
17
|
+
HTTP_METHOD: "http.method",
|
18
|
+
HTTP_URL: "http.url",
|
19
|
+
HTTP_ROUTE: "http.route",
|
20
|
+
HTTP_TARGET: "http.target"
|
21
|
+
};
|
22
|
+
|
1
23
|
function notEmpty(value) {
|
2
24
|
return value !== null && value !== void 0;
|
3
25
|
}
|
@@ -13,6 +35,9 @@ function isDefined(value) {
|
|
13
35
|
function isString(value) {
|
14
36
|
return isDefined(value) && typeof value === "string";
|
15
37
|
}
|
38
|
+
function isStringArray(value) {
|
39
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
40
|
+
}
|
16
41
|
function toBase64(value) {
|
17
42
|
try {
|
18
43
|
return btoa(value);
|
@@ -22,35 +47,83 @@ function toBase64(value) {
|
|
22
47
|
}
|
23
48
|
}
|
24
49
|
|
25
|
-
function
|
50
|
+
function getEnvironment() {
|
26
51
|
try {
|
27
|
-
if (isObject(process) &&
|
28
|
-
return
|
52
|
+
if (isObject(process) && isObject(process.env)) {
|
53
|
+
return {
|
54
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
55
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
56
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
57
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
58
|
+
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
59
|
+
};
|
29
60
|
}
|
30
61
|
} catch (err) {
|
31
62
|
}
|
32
63
|
try {
|
33
|
-
if (isObject(Deno) &&
|
34
|
-
return
|
64
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
65
|
+
return {
|
66
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
67
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
68
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
69
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
70
|
+
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
71
|
+
};
|
35
72
|
}
|
36
73
|
} catch (err) {
|
37
74
|
}
|
75
|
+
return {
|
76
|
+
apiKey: getGlobalApiKey(),
|
77
|
+
databaseURL: getGlobalDatabaseURL(),
|
78
|
+
branch: getGlobalBranch(),
|
79
|
+
envBranch: void 0,
|
80
|
+
fallbackBranch: getGlobalFallbackBranch()
|
81
|
+
};
|
82
|
+
}
|
83
|
+
function getGlobalApiKey() {
|
84
|
+
try {
|
85
|
+
return XATA_API_KEY;
|
86
|
+
} catch (err) {
|
87
|
+
return void 0;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
function getGlobalDatabaseURL() {
|
91
|
+
try {
|
92
|
+
return XATA_DATABASE_URL;
|
93
|
+
} catch (err) {
|
94
|
+
return void 0;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
function getGlobalBranch() {
|
98
|
+
try {
|
99
|
+
return XATA_BRANCH;
|
100
|
+
} catch (err) {
|
101
|
+
return void 0;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
function getGlobalFallbackBranch() {
|
105
|
+
try {
|
106
|
+
return XATA_FALLBACK_BRANCH;
|
107
|
+
} catch (err) {
|
108
|
+
return void 0;
|
109
|
+
}
|
38
110
|
}
|
39
111
|
async function getGitBranch() {
|
112
|
+
const cmd = ["git", "branch", "--show-current"];
|
113
|
+
const fullCmd = cmd.join(" ");
|
114
|
+
const nodeModule = ["child", "process"].join("_");
|
115
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
40
116
|
try {
|
41
117
|
if (typeof require === "function") {
|
42
|
-
|
43
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
118
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
44
119
|
}
|
120
|
+
const { execSync } = await import(nodeModule);
|
121
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
45
122
|
} catch (err) {
|
46
123
|
}
|
47
124
|
try {
|
48
125
|
if (isObject(Deno)) {
|
49
|
-
const process2 = Deno.run({
|
50
|
-
cmd: ["git", "branch", "--show-current"],
|
51
|
-
stdout: "piped",
|
52
|
-
stderr: "piped"
|
53
|
-
});
|
126
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
54
127
|
return new TextDecoder().decode(await process2.output()).trim();
|
55
128
|
}
|
56
129
|
} catch (err) {
|
@@ -59,7 +132,8 @@ async function getGitBranch() {
|
|
59
132
|
|
60
133
|
function getAPIKey() {
|
61
134
|
try {
|
62
|
-
|
135
|
+
const { apiKey } = getEnvironment();
|
136
|
+
return apiKey;
|
63
137
|
} catch (err) {
|
64
138
|
return void 0;
|
65
139
|
}
|
@@ -69,12 +143,14 @@ function getFetchImplementation(userFetch) {
|
|
69
143
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
70
144
|
const fetchImpl = userFetch ?? globalFetch;
|
71
145
|
if (!fetchImpl) {
|
72
|
-
throw new Error(
|
146
|
+
throw new Error(
|
147
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
148
|
+
);
|
73
149
|
}
|
74
150
|
return fetchImpl;
|
75
151
|
}
|
76
152
|
|
77
|
-
const VERSION = "0.0.0-alpha.
|
153
|
+
const VERSION = "0.0.0-alpha.vfe9bed6";
|
78
154
|
|
79
155
|
class ErrorWithCause extends Error {
|
80
156
|
constructor(message, options) {
|
@@ -125,7 +201,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
125
201
|
}, {});
|
126
202
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
127
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
128
|
-
|
204
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
205
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
206
|
+
}, {});
|
207
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
129
208
|
};
|
130
209
|
function buildBaseUrl({
|
131
210
|
path,
|
@@ -133,10 +212,10 @@ function buildBaseUrl({
|
|
133
212
|
apiUrl,
|
134
213
|
pathParams
|
135
214
|
}) {
|
136
|
-
if (
|
215
|
+
if (pathParams?.workspace === void 0)
|
137
216
|
return `${apiUrl}${path}`;
|
138
217
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
139
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
218
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
140
219
|
}
|
141
220
|
function hostHeader(url) {
|
142
221
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -153,34 +232,61 @@ async function fetch$1({
|
|
153
232
|
fetchImpl,
|
154
233
|
apiKey,
|
155
234
|
apiUrl,
|
156
|
-
workspacesApiUrl
|
235
|
+
workspacesApiUrl,
|
236
|
+
trace
|
157
237
|
}) {
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
238
|
+
return trace(
|
239
|
+
`${method.toUpperCase()} ${path}`,
|
240
|
+
async ({ setAttributes }) => {
|
241
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
242
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
243
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
244
|
+
setAttributes({
|
245
|
+
[TraceAttributes.HTTP_URL]: url,
|
246
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
247
|
+
});
|
248
|
+
const response = await fetchImpl(url, {
|
249
|
+
method: method.toUpperCase(),
|
250
|
+
body: body ? JSON.stringify(body) : void 0,
|
251
|
+
headers: {
|
252
|
+
"Content-Type": "application/json",
|
253
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
254
|
+
...headers,
|
255
|
+
...hostHeader(fullUrl),
|
256
|
+
Authorization: `Bearer ${apiKey}`
|
257
|
+
}
|
258
|
+
});
|
259
|
+
if (response.status === 204) {
|
260
|
+
return {};
|
261
|
+
}
|
262
|
+
const { host, protocol } = parseUrl(response.url);
|
263
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
264
|
+
setAttributes({
|
265
|
+
[TraceAttributes.KIND]: "http",
|
266
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
267
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
268
|
+
[TraceAttributes.HTTP_HOST]: host,
|
269
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
270
|
+
});
|
271
|
+
try {
|
272
|
+
const jsonResponse = await response.json();
|
273
|
+
if (response.ok) {
|
274
|
+
return jsonResponse;
|
275
|
+
}
|
276
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
277
|
+
} catch (error) {
|
278
|
+
throw new FetcherError(response.status, error, requestId);
|
279
|
+
}
|
280
|
+
},
|
281
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
282
|
+
);
|
283
|
+
}
|
284
|
+
function parseUrl(url) {
|
176
285
|
try {
|
177
|
-
const
|
178
|
-
|
179
|
-
return jsonResponse;
|
180
|
-
}
|
181
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
286
|
+
const { host, protocol } = new URL(url);
|
287
|
+
return { host, protocol };
|
182
288
|
} catch (error) {
|
183
|
-
|
289
|
+
return {};
|
184
290
|
}
|
185
291
|
}
|
186
292
|
|
@@ -239,6 +345,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
239
345
|
...variables
|
240
346
|
});
|
241
347
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
348
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
242
349
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
243
350
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
244
351
|
method: "delete",
|
@@ -274,6 +381,12 @@ const deleteDatabase = (variables) => fetch$1({
|
|
274
381
|
method: "delete",
|
275
382
|
...variables
|
276
383
|
});
|
384
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
385
|
+
url: "/dbs/{dbName}/metadata",
|
386
|
+
method: "get",
|
387
|
+
...variables
|
388
|
+
});
|
389
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
277
390
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
278
391
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
279
392
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -282,16 +395,28 @@ const resolveBranch = (variables) => fetch$1({
|
|
282
395
|
method: "get",
|
283
396
|
...variables
|
284
397
|
});
|
285
|
-
const
|
286
|
-
|
398
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
399
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
400
|
+
const getMigrationRequest = (variables) => fetch$1({
|
401
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
287
402
|
method: "get",
|
288
403
|
...variables
|
289
404
|
});
|
290
|
-
const
|
405
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
406
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
407
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
408
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
409
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
410
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
411
|
+
method: "post",
|
412
|
+
...variables
|
413
|
+
});
|
414
|
+
const getBranchDetails = (variables) => fetch$1({
|
291
415
|
url: "/db/{dbBranchName}",
|
292
|
-
method: "
|
416
|
+
method: "get",
|
293
417
|
...variables
|
294
418
|
});
|
419
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
295
420
|
const deleteBranch = (variables) => fetch$1({
|
296
421
|
url: "/db/{dbBranchName}",
|
297
422
|
method: "delete",
|
@@ -310,6 +435,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
310
435
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
311
436
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
312
437
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
438
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
439
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
440
|
+
const updateBranchSchema = (variables) => fetch$1({
|
441
|
+
url: "/db/{dbBranchName}/schema/update",
|
442
|
+
method: "post",
|
443
|
+
...variables
|
444
|
+
});
|
445
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
446
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
447
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
313
448
|
const getBranchStats = (variables) => fetch$1({
|
314
449
|
url: "/db/{dbBranchName}/stats",
|
315
450
|
method: "get",
|
@@ -365,11 +500,7 @@ const updateColumn = (variables) => fetch$1({
|
|
365
500
|
method: "patch",
|
366
501
|
...variables
|
367
502
|
});
|
368
|
-
const insertRecord = (variables) => fetch$1({
|
369
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
370
|
-
method: "post",
|
371
|
-
...variables
|
372
|
-
});
|
503
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
373
504
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
374
505
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
375
506
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -399,6 +530,11 @@ const searchBranch = (variables) => fetch$1({
|
|
399
530
|
method: "post",
|
400
531
|
...variables
|
401
532
|
});
|
533
|
+
const summarizeTable = (variables) => fetch$1({
|
534
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
535
|
+
method: "post",
|
536
|
+
...variables
|
537
|
+
});
|
402
538
|
const operationsByTag = {
|
403
539
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
404
540
|
workspaces: {
|
@@ -411,6 +547,7 @@ const operationsByTag = {
|
|
411
547
|
updateWorkspaceMemberRole,
|
412
548
|
removeWorkspaceMember,
|
413
549
|
inviteWorkspaceMember,
|
550
|
+
updateWorkspaceMemberInvite,
|
414
551
|
cancelWorkspaceMemberInvite,
|
415
552
|
resendWorkspaceMemberInvite,
|
416
553
|
acceptWorkspaceMemberInvite
|
@@ -419,6 +556,8 @@ const operationsByTag = {
|
|
419
556
|
getDatabaseList,
|
420
557
|
createDatabase,
|
421
558
|
deleteDatabase,
|
559
|
+
getDatabaseMetadata,
|
560
|
+
updateDatabaseMetadata,
|
422
561
|
getGitBranchesMapping,
|
423
562
|
addGitBranchesEntry,
|
424
563
|
removeGitBranchesEntry,
|
@@ -431,10 +570,28 @@ const operationsByTag = {
|
|
431
570
|
deleteBranch,
|
432
571
|
updateBranchMetadata,
|
433
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: {
|
434
586
|
getBranchMigrationHistory,
|
435
587
|
executeBranchMigrationPlan,
|
436
588
|
getBranchMigrationPlan,
|
437
|
-
|
589
|
+
compareBranchWithUserSchema,
|
590
|
+
compareBranchSchemas,
|
591
|
+
updateBranchSchema,
|
592
|
+
previewBranchSchemaEdit,
|
593
|
+
applyBranchSchemaEdit,
|
594
|
+
getBranchSchemaHistory
|
438
595
|
},
|
439
596
|
table: {
|
440
597
|
createTable,
|
@@ -458,14 +615,15 @@ const operationsByTag = {
|
|
458
615
|
bulkInsertTableRecords,
|
459
616
|
queryTable,
|
460
617
|
searchTable,
|
461
|
-
searchBranch
|
618
|
+
searchBranch,
|
619
|
+
summarizeTable
|
462
620
|
}
|
463
621
|
};
|
464
622
|
|
465
623
|
function getHostUrl(provider, type) {
|
466
|
-
if (
|
624
|
+
if (isHostProviderAlias(provider)) {
|
467
625
|
return providers[provider][type];
|
468
|
-
} else if (
|
626
|
+
} else if (isHostProviderBuilder(provider)) {
|
469
627
|
return provider[type];
|
470
628
|
}
|
471
629
|
throw new Error("Invalid API provider");
|
@@ -480,10 +638,10 @@ const providers = {
|
|
480
638
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
481
639
|
}
|
482
640
|
};
|
483
|
-
function
|
641
|
+
function isHostProviderAlias(alias) {
|
484
642
|
return isString(alias) && Object.keys(providers).includes(alias);
|
485
643
|
}
|
486
|
-
function
|
644
|
+
function isHostProviderBuilder(builder) {
|
487
645
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
488
646
|
}
|
489
647
|
|
@@ -511,7 +669,8 @@ class XataApiClient {
|
|
511
669
|
__privateAdd$7(this, _extraProps, void 0);
|
512
670
|
__privateAdd$7(this, _namespaces, {});
|
513
671
|
const provider = options.host ?? "production";
|
514
|
-
const apiKey = options
|
672
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
673
|
+
const trace = options.trace ?? defaultTrace;
|
515
674
|
if (!apiKey) {
|
516
675
|
throw new Error("Could not resolve a valid apiKey");
|
517
676
|
}
|
@@ -519,7 +678,8 @@ class XataApiClient {
|
|
519
678
|
apiUrl: getHostUrl(provider, "main"),
|
520
679
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
521
680
|
fetchImpl: getFetchImplementation(options.fetch),
|
522
|
-
apiKey
|
681
|
+
apiKey,
|
682
|
+
trace
|
523
683
|
});
|
524
684
|
}
|
525
685
|
get user() {
|
@@ -552,6 +712,16 @@ class XataApiClient {
|
|
552
712
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
553
713
|
return __privateGet$7(this, _namespaces).records;
|
554
714
|
}
|
715
|
+
get migrationRequests() {
|
716
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
717
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
718
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
719
|
+
}
|
720
|
+
get branchSchema() {
|
721
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
722
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
723
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
724
|
+
}
|
555
725
|
}
|
556
726
|
_extraProps = new WeakMap();
|
557
727
|
_namespaces = new WeakMap();
|
@@ -642,6 +812,13 @@ class WorkspaceApi {
|
|
642
812
|
...this.extraProps
|
643
813
|
});
|
644
814
|
}
|
815
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
816
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
817
|
+
pathParams: { workspaceId, inviteId },
|
818
|
+
body: { role },
|
819
|
+
...this.extraProps
|
820
|
+
});
|
821
|
+
}
|
645
822
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
646
823
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
647
824
|
pathParams: { workspaceId, inviteId },
|
@@ -684,6 +861,19 @@ class DatabaseApi {
|
|
684
861
|
...this.extraProps
|
685
862
|
});
|
686
863
|
}
|
864
|
+
getDatabaseMetadata(workspace, dbName) {
|
865
|
+
return operationsByTag.database.getDatabaseMetadata({
|
866
|
+
pathParams: { workspace, dbName },
|
867
|
+
...this.extraProps
|
868
|
+
});
|
869
|
+
}
|
870
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
871
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
872
|
+
pathParams: { workspace, dbName },
|
873
|
+
body: options,
|
874
|
+
...this.extraProps
|
875
|
+
});
|
876
|
+
}
|
687
877
|
getGitBranchesMapping(workspace, dbName) {
|
688
878
|
return operationsByTag.database.getGitBranchesMapping({
|
689
879
|
pathParams: { workspace, dbName },
|
@@ -755,27 +945,6 @@ class BranchApi {
|
|
755
945
|
...this.extraProps
|
756
946
|
});
|
757
947
|
}
|
758
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
759
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
760
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
761
|
-
body: options,
|
762
|
-
...this.extraProps
|
763
|
-
});
|
764
|
-
}
|
765
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
766
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
767
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
768
|
-
body: migrationPlan,
|
769
|
-
...this.extraProps
|
770
|
-
});
|
771
|
-
}
|
772
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
773
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
774
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
775
|
-
body: schema,
|
776
|
-
...this.extraProps
|
777
|
-
});
|
778
|
-
}
|
779
948
|
getBranchStats(workspace, database, branch) {
|
780
949
|
return operationsByTag.branch.getBranchStats({
|
781
950
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -856,9 +1025,10 @@ class RecordsApi {
|
|
856
1025
|
constructor(extraProps) {
|
857
1026
|
this.extraProps = extraProps;
|
858
1027
|
}
|
859
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1028
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
860
1029
|
return operationsByTag.records.insertRecord({
|
861
1030
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1031
|
+
queryParams: options,
|
862
1032
|
body: record,
|
863
1033
|
...this.extraProps
|
864
1034
|
});
|
@@ -887,21 +1057,24 @@ class RecordsApi {
|
|
887
1057
|
...this.extraProps
|
888
1058
|
});
|
889
1059
|
}
|
890
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1060
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
891
1061
|
return operationsByTag.records.deleteRecord({
|
892
1062
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1063
|
+
queryParams: options,
|
893
1064
|
...this.extraProps
|
894
1065
|
});
|
895
1066
|
}
|
896
1067
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
897
1068
|
return operationsByTag.records.getRecord({
|
898
1069
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1070
|
+
queryParams: options,
|
899
1071
|
...this.extraProps
|
900
1072
|
});
|
901
1073
|
}
|
902
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1074
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
903
1075
|
return operationsByTag.records.bulkInsertTableRecords({
|
904
1076
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1077
|
+
queryParams: options,
|
905
1078
|
body: { records },
|
906
1079
|
...this.extraProps
|
907
1080
|
});
|
@@ -927,6 +1100,138 @@ class RecordsApi {
|
|
927
1100
|
...this.extraProps
|
928
1101
|
});
|
929
1102
|
}
|
1103
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1104
|
+
return operationsByTag.records.summarizeTable({
|
1105
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1106
|
+
body: query,
|
1107
|
+
...this.extraProps
|
1108
|
+
});
|
1109
|
+
}
|
1110
|
+
}
|
1111
|
+
class MigrationRequestsApi {
|
1112
|
+
constructor(extraProps) {
|
1113
|
+
this.extraProps = extraProps;
|
1114
|
+
}
|
1115
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1116
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1117
|
+
pathParams: { workspace, dbName: database },
|
1118
|
+
body: options,
|
1119
|
+
...this.extraProps
|
1120
|
+
});
|
1121
|
+
}
|
1122
|
+
createMigrationRequest(workspace, database, options) {
|
1123
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1124
|
+
pathParams: { workspace, dbName: database },
|
1125
|
+
body: options,
|
1126
|
+
...this.extraProps
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1130
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1131
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1132
|
+
...this.extraProps
|
1133
|
+
});
|
1134
|
+
}
|
1135
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1136
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1137
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1138
|
+
body: options,
|
1139
|
+
...this.extraProps
|
1140
|
+
});
|
1141
|
+
}
|
1142
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1143
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1144
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1145
|
+
body: options,
|
1146
|
+
...this.extraProps
|
1147
|
+
});
|
1148
|
+
}
|
1149
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1150
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1151
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1152
|
+
...this.extraProps
|
1153
|
+
});
|
1154
|
+
}
|
1155
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1156
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1157
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1158
|
+
...this.extraProps
|
1159
|
+
});
|
1160
|
+
}
|
1161
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1162
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1163
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1164
|
+
...this.extraProps
|
1165
|
+
});
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
class BranchSchemaApi {
|
1169
|
+
constructor(extraProps) {
|
1170
|
+
this.extraProps = extraProps;
|
1171
|
+
}
|
1172
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1173
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1174
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1175
|
+
body: options,
|
1176
|
+
...this.extraProps
|
1177
|
+
});
|
1178
|
+
}
|
1179
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1180
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1181
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1182
|
+
body: migrationPlan,
|
1183
|
+
...this.extraProps
|
1184
|
+
});
|
1185
|
+
}
|
1186
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1187
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1188
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1189
|
+
body: schema,
|
1190
|
+
...this.extraProps
|
1191
|
+
});
|
1192
|
+
}
|
1193
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1194
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1195
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1196
|
+
body: { schema },
|
1197
|
+
...this.extraProps
|
1198
|
+
});
|
1199
|
+
}
|
1200
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1201
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1202
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1203
|
+
body: { schema },
|
1204
|
+
...this.extraProps
|
1205
|
+
});
|
1206
|
+
}
|
1207
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1208
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1209
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1210
|
+
body: migration,
|
1211
|
+
...this.extraProps
|
1212
|
+
});
|
1213
|
+
}
|
1214
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1215
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1216
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1217
|
+
body: migration,
|
1218
|
+
...this.extraProps
|
1219
|
+
});
|
1220
|
+
}
|
1221
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1222
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1223
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1224
|
+
body: { edits },
|
1225
|
+
...this.extraProps
|
1226
|
+
});
|
1227
|
+
}
|
1228
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1229
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1230
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1231
|
+
body: options,
|
1232
|
+
...this.extraProps
|
1233
|
+
});
|
1234
|
+
}
|
930
1235
|
}
|
931
1236
|
|
932
1237
|
class XataApiPlugin {
|
@@ -993,7 +1298,7 @@ const _RecordArray = class extends Array {
|
|
993
1298
|
constructor(...args) {
|
994
1299
|
super(..._RecordArray.parseConstructorParams(...args));
|
995
1300
|
__privateAdd$6(this, _page, void 0);
|
996
|
-
__privateSet$6(this, _page, args[0]);
|
1301
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
997
1302
|
}
|
998
1303
|
static parseConstructorParams(...args) {
|
999
1304
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -1005,6 +1310,12 @@ const _RecordArray = class extends Array {
|
|
1005
1310
|
}
|
1006
1311
|
return new Array(...args);
|
1007
1312
|
}
|
1313
|
+
toArray() {
|
1314
|
+
return new Array(...this);
|
1315
|
+
}
|
1316
|
+
map(callbackfn, thisArg) {
|
1317
|
+
return this.toArray().map(callbackfn, thisArg);
|
1318
|
+
}
|
1008
1319
|
async nextPage(size, offset) {
|
1009
1320
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1010
1321
|
return new _RecordArray(newPage);
|
@@ -1046,9 +1357,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1046
1357
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1047
1358
|
return value;
|
1048
1359
|
};
|
1049
|
-
var
|
1360
|
+
var __privateMethod$3 = (obj, member, method) => {
|
1361
|
+
__accessCheck$5(obj, member, "access private method");
|
1362
|
+
return method;
|
1363
|
+
};
|
1364
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1050
1365
|
const _Query = class {
|
1051
1366
|
constructor(repository, table, data, rawParent) {
|
1367
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1052
1368
|
__privateAdd$5(this, _table$1, void 0);
|
1053
1369
|
__privateAdd$5(this, _repository, void 0);
|
1054
1370
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -1105,21 +1421,29 @@ const _Query = class {
|
|
1105
1421
|
}
|
1106
1422
|
filter(a, b) {
|
1107
1423
|
if (arguments.length === 1) {
|
1108
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
1424
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1425
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1426
|
+
}));
|
1109
1427
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1110
1428
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1111
1429
|
} else {
|
1112
|
-
const
|
1430
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1431
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1113
1432
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1114
1433
|
}
|
1115
1434
|
}
|
1116
|
-
sort(column, direction) {
|
1435
|
+
sort(column, direction = "asc") {
|
1117
1436
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1118
1437
|
const sort = [...originalSort, { column, direction }];
|
1119
1438
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1120
1439
|
}
|
1121
1440
|
select(columns) {
|
1122
|
-
return new _Query(
|
1441
|
+
return new _Query(
|
1442
|
+
__privateGet$5(this, _repository),
|
1443
|
+
__privateGet$5(this, _table$1),
|
1444
|
+
{ columns },
|
1445
|
+
__privateGet$5(this, _data)
|
1446
|
+
);
|
1123
1447
|
}
|
1124
1448
|
getPaginated(options = {}) {
|
1125
1449
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1142,11 +1466,20 @@ const _Query = class {
|
|
1142
1466
|
}
|
1143
1467
|
}
|
1144
1468
|
async getMany(options = {}) {
|
1145
|
-
const
|
1469
|
+
const { pagination = {}, ...rest } = options;
|
1470
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1471
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1472
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1473
|
+
const results = [...page.records];
|
1474
|
+
while (page.hasNextPage() && results.length < size) {
|
1475
|
+
page = await page.nextPage();
|
1476
|
+
results.push(...page.records);
|
1477
|
+
}
|
1146
1478
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1147
1479
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1148
1480
|
}
|
1149
|
-
|
1481
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1482
|
+
return array;
|
1150
1483
|
}
|
1151
1484
|
async getAll(options = {}) {
|
1152
1485
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1160,6 +1493,12 @@ const _Query = class {
|
|
1160
1493
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1161
1494
|
return records[0] ?? null;
|
1162
1495
|
}
|
1496
|
+
async getFirstOrThrow(options = {}) {
|
1497
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1498
|
+
if (records[0] === void 0)
|
1499
|
+
throw new Error("No results found.");
|
1500
|
+
return records[0];
|
1501
|
+
}
|
1163
1502
|
cache(ttl) {
|
1164
1503
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1165
1504
|
}
|
@@ -1183,6 +1522,17 @@ let Query = _Query;
|
|
1183
1522
|
_table$1 = new WeakMap();
|
1184
1523
|
_repository = new WeakMap();
|
1185
1524
|
_data = new WeakMap();
|
1525
|
+
_cleanFilterConstraint = new WeakSet();
|
1526
|
+
cleanFilterConstraint_fn = function(column, value) {
|
1527
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1528
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1529
|
+
return { $includes: value };
|
1530
|
+
}
|
1531
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
1532
|
+
return value.id;
|
1533
|
+
}
|
1534
|
+
return value;
|
1535
|
+
};
|
1186
1536
|
function cleanParent(data, parent) {
|
1187
1537
|
if (isCursorPaginationOptions(data.pagination)) {
|
1188
1538
|
return { ...parent, sorting: void 0, filter: void 0 };
|
@@ -1244,203 +1594,284 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1244
1594
|
__accessCheck$4(obj, member, "access private method");
|
1245
1595
|
return method;
|
1246
1596
|
};
|
1247
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1597
|
+
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;
|
1248
1598
|
class Repository extends Query {
|
1249
1599
|
}
|
1250
1600
|
class RestRepository extends Query {
|
1251
1601
|
constructor(options) {
|
1252
|
-
super(
|
1602
|
+
super(
|
1603
|
+
null,
|
1604
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1605
|
+
{}
|
1606
|
+
);
|
1253
1607
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1254
1608
|
__privateAdd$4(this, _insertRecordWithId);
|
1255
1609
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
1256
1610
|
__privateAdd$4(this, _updateRecordWithID);
|
1257
1611
|
__privateAdd$4(this, _upsertRecordWithID);
|
1258
1612
|
__privateAdd$4(this, _deleteRecord);
|
1259
|
-
__privateAdd$4(this, _invalidateCache);
|
1260
|
-
__privateAdd$4(this, _setCacheRecord);
|
1261
|
-
__privateAdd$4(this, _getCacheRecord);
|
1262
1613
|
__privateAdd$4(this, _setCacheQuery);
|
1263
1614
|
__privateAdd$4(this, _getCacheQuery);
|
1264
1615
|
__privateAdd$4(this, _getSchemaTables$1);
|
1265
1616
|
__privateAdd$4(this, _table, void 0);
|
1266
1617
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1618
|
+
__privateAdd$4(this, _db, void 0);
|
1267
1619
|
__privateAdd$4(this, _cache, void 0);
|
1268
1620
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1621
|
+
__privateAdd$4(this, _trace, void 0);
|
1269
1622
|
__privateSet$4(this, _table, options.table);
|
1270
1623
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1271
|
-
this
|
1624
|
+
__privateSet$4(this, _db, options.db);
|
1272
1625
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1273
1626
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1627
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1628
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1629
|
+
return trace(name, fn, {
|
1630
|
+
...options2,
|
1631
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1632
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1633
|
+
[TraceAttributes.VERSION]: VERSION
|
1634
|
+
});
|
1635
|
+
});
|
1274
1636
|
}
|
1275
|
-
async create(a, b) {
|
1276
|
-
|
1277
|
-
if (a
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
const
|
1317
|
-
|
1318
|
-
const
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1637
|
+
async create(a, b, c) {
|
1638
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1639
|
+
if (Array.isArray(a)) {
|
1640
|
+
if (a.length === 0)
|
1641
|
+
return [];
|
1642
|
+
const columns = isStringArray(b) ? b : void 0;
|
1643
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1644
|
+
}
|
1645
|
+
if (isString(a) && isObject(b)) {
|
1646
|
+
if (a === "")
|
1647
|
+
throw new Error("The id can't be empty");
|
1648
|
+
const columns = isStringArray(c) ? c : void 0;
|
1649
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1650
|
+
}
|
1651
|
+
if (isObject(a) && isString(a.id)) {
|
1652
|
+
if (a.id === "")
|
1653
|
+
throw new Error("The id can't be empty");
|
1654
|
+
const columns = isStringArray(b) ? b : void 0;
|
1655
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1656
|
+
}
|
1657
|
+
if (isObject(a)) {
|
1658
|
+
const columns = isStringArray(b) ? b : void 0;
|
1659
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1660
|
+
}
|
1661
|
+
throw new Error("Invalid arguments for create method");
|
1662
|
+
});
|
1663
|
+
}
|
1664
|
+
async read(a, b) {
|
1665
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1666
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1667
|
+
if (Array.isArray(a)) {
|
1668
|
+
if (a.length === 0)
|
1669
|
+
return [];
|
1670
|
+
const ids = a.map((item) => extractId(item));
|
1671
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1672
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1673
|
+
acc[object.id] = object;
|
1674
|
+
return acc;
|
1675
|
+
}, {});
|
1676
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1677
|
+
}
|
1678
|
+
const id = extractId(a);
|
1679
|
+
if (id) {
|
1680
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1681
|
+
try {
|
1682
|
+
const response = await getRecord({
|
1683
|
+
pathParams: {
|
1684
|
+
workspace: "{workspaceId}",
|
1685
|
+
dbBranchName: "{dbBranch}",
|
1686
|
+
tableName: __privateGet$4(this, _table),
|
1687
|
+
recordId: id
|
1688
|
+
},
|
1689
|
+
queryParams: { columns },
|
1690
|
+
...fetchProps
|
1691
|
+
});
|
1692
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1693
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1694
|
+
} catch (e) {
|
1695
|
+
if (isObject(e) && e.status === 404) {
|
1696
|
+
return null;
|
1697
|
+
}
|
1698
|
+
throw e;
|
1327
1699
|
}
|
1328
|
-
throw e;
|
1329
1700
|
}
|
1330
|
-
|
1701
|
+
return null;
|
1702
|
+
});
|
1331
1703
|
}
|
1332
|
-
async
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1704
|
+
async readOrThrow(a, b) {
|
1705
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1706
|
+
const result = await this.read(a, b);
|
1707
|
+
if (Array.isArray(result)) {
|
1708
|
+
const missingIds = compact(
|
1709
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1710
|
+
);
|
1711
|
+
if (missingIds.length > 0) {
|
1712
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1713
|
+
}
|
1714
|
+
return result;
|
1338
1715
|
}
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1343
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1344
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1345
|
-
return record;
|
1346
|
-
}
|
1347
|
-
if (isObject(a) && isString(a.id)) {
|
1348
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1349
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1350
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1351
|
-
return record;
|
1352
|
-
}
|
1353
|
-
throw new Error("Invalid arguments for update method");
|
1354
|
-
}
|
1355
|
-
async createOrUpdate(a, b) {
|
1356
|
-
if (Array.isArray(a)) {
|
1357
|
-
if (a.length === 0)
|
1358
|
-
return [];
|
1359
|
-
if (a.length > 100) {
|
1360
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1716
|
+
if (result === null) {
|
1717
|
+
const id = extractId(a) ?? "unknown";
|
1718
|
+
throw new Error(`Record with id ${id} not found`);
|
1361
1719
|
}
|
1362
|
-
return
|
1363
|
-
}
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
}
|
1376
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1377
|
-
}
|
1378
|
-
async delete(a) {
|
1379
|
-
if (Array.isArray(a)) {
|
1380
|
-
if (a.length === 0)
|
1381
|
-
return;
|
1382
|
-
if (a.length > 100) {
|
1383
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1720
|
+
return result;
|
1721
|
+
});
|
1722
|
+
}
|
1723
|
+
async update(a, b, c) {
|
1724
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1725
|
+
if (Array.isArray(a)) {
|
1726
|
+
if (a.length === 0)
|
1727
|
+
return [];
|
1728
|
+
if (a.length > 100) {
|
1729
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1730
|
+
}
|
1731
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1732
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1384
1733
|
}
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1734
|
+
if (isString(a) && isObject(b)) {
|
1735
|
+
const columns = isStringArray(c) ? c : void 0;
|
1736
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1737
|
+
}
|
1738
|
+
if (isObject(a) && isString(a.id)) {
|
1739
|
+
const columns = isStringArray(b) ? b : void 0;
|
1740
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1741
|
+
}
|
1742
|
+
throw new Error("Invalid arguments for update method");
|
1743
|
+
});
|
1744
|
+
}
|
1745
|
+
async updateOrThrow(a, b, c) {
|
1746
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1747
|
+
const result = await this.update(a, b, c);
|
1748
|
+
if (Array.isArray(result)) {
|
1749
|
+
const missingIds = compact(
|
1750
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1751
|
+
);
|
1752
|
+
if (missingIds.length > 0) {
|
1753
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1754
|
+
}
|
1755
|
+
return result;
|
1756
|
+
}
|
1757
|
+
if (result === null) {
|
1758
|
+
const id = extractId(a) ?? "unknown";
|
1759
|
+
throw new Error(`Record with id ${id} not found`);
|
1760
|
+
}
|
1761
|
+
return result;
|
1762
|
+
});
|
1763
|
+
}
|
1764
|
+
async createOrUpdate(a, b, c) {
|
1765
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1766
|
+
if (Array.isArray(a)) {
|
1767
|
+
if (a.length === 0)
|
1768
|
+
return [];
|
1769
|
+
if (a.length > 100) {
|
1770
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1771
|
+
}
|
1772
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1773
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1774
|
+
}
|
1775
|
+
if (isString(a) && isObject(b)) {
|
1776
|
+
const columns = isStringArray(c) ? c : void 0;
|
1777
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1778
|
+
}
|
1779
|
+
if (isObject(a) && isString(a.id)) {
|
1780
|
+
const columns = isStringArray(c) ? c : void 0;
|
1781
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1782
|
+
}
|
1783
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1784
|
+
});
|
1785
|
+
}
|
1786
|
+
async delete(a, b) {
|
1787
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1788
|
+
if (Array.isArray(a)) {
|
1789
|
+
if (a.length === 0)
|
1790
|
+
return [];
|
1791
|
+
if (a.length > 100) {
|
1792
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1793
|
+
}
|
1794
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1795
|
+
}
|
1796
|
+
if (isString(a)) {
|
1797
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1798
|
+
}
|
1799
|
+
if (isObject(a) && isString(a.id)) {
|
1800
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1801
|
+
}
|
1802
|
+
throw new Error("Invalid arguments for delete method");
|
1803
|
+
});
|
1804
|
+
}
|
1805
|
+
async deleteOrThrow(a, b) {
|
1806
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1807
|
+
const result = await this.delete(a, b);
|
1808
|
+
if (Array.isArray(result)) {
|
1809
|
+
const missingIds = compact(
|
1810
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1811
|
+
);
|
1812
|
+
if (missingIds.length > 0) {
|
1813
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1814
|
+
}
|
1815
|
+
return result;
|
1816
|
+
} else if (result === null) {
|
1817
|
+
const id = extractId(a) ?? "unknown";
|
1818
|
+
throw new Error(`Record with id ${id} not found`);
|
1819
|
+
}
|
1820
|
+
return result;
|
1821
|
+
});
|
1399
1822
|
}
|
1400
1823
|
async search(query, options = {}) {
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1824
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1825
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1826
|
+
const { records } = await searchTable({
|
1827
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1828
|
+
body: {
|
1829
|
+
query,
|
1830
|
+
fuzziness: options.fuzziness,
|
1831
|
+
prefix: options.prefix,
|
1832
|
+
highlight: options.highlight,
|
1833
|
+
filter: options.filter,
|
1834
|
+
boosters: options.boosters
|
1835
|
+
},
|
1836
|
+
...fetchProps
|
1837
|
+
});
|
1838
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1839
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1411
1840
|
});
|
1412
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1413
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1414
1841
|
}
|
1415
1842
|
async query(query) {
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1843
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1844
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1845
|
+
if (cacheQuery)
|
1846
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1847
|
+
const data = query.getQueryOptions();
|
1848
|
+
const body = {
|
1849
|
+
filter: cleanFilter(data.filter),
|
1850
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1851
|
+
page: data.pagination,
|
1852
|
+
columns: data.columns
|
1853
|
+
};
|
1854
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1855
|
+
const { meta, records: objects } = await queryTable({
|
1856
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1857
|
+
body,
|
1858
|
+
...fetchProps
|
1859
|
+
});
|
1860
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1861
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1862
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1863
|
+
return new Page(query, meta, records);
|
1431
1864
|
});
|
1432
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1433
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1434
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1435
|
-
return new Page(query, meta, records);
|
1436
1865
|
}
|
1437
1866
|
}
|
1438
1867
|
_table = new WeakMap();
|
1439
1868
|
_getFetchProps = new WeakMap();
|
1869
|
+
_db = new WeakMap();
|
1440
1870
|
_cache = new WeakMap();
|
1441
1871
|
_schemaTables$2 = new WeakMap();
|
1872
|
+
_trace = new WeakMap();
|
1442
1873
|
_insertRecordWithoutId = new WeakSet();
|
1443
|
-
insertRecordWithoutId_fn = async function(object) {
|
1874
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1444
1875
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1445
1876
|
const record = transformObjectLinks(object);
|
1446
1877
|
const response = await insertRecord({
|
@@ -1449,17 +1880,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1449
1880
|
dbBranchName: "{dbBranch}",
|
1450
1881
|
tableName: __privateGet$4(this, _table)
|
1451
1882
|
},
|
1883
|
+
queryParams: { columns },
|
1452
1884
|
body: record,
|
1453
1885
|
...fetchProps
|
1454
1886
|
});
|
1455
|
-
const
|
1456
|
-
|
1457
|
-
throw new Error("The server failed to save the record");
|
1458
|
-
}
|
1459
|
-
return finalObject;
|
1887
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1888
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1460
1889
|
};
|
1461
1890
|
_insertRecordWithId = new WeakSet();
|
1462
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1891
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1463
1892
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1464
1893
|
const record = transformObjectLinks(object);
|
1465
1894
|
const response = await insertRecordWithID({
|
@@ -1470,92 +1899,78 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1470
1899
|
recordId
|
1471
1900
|
},
|
1472
1901
|
body: record,
|
1473
|
-
queryParams: { createOnly: true },
|
1902
|
+
queryParams: { createOnly: true, columns },
|
1474
1903
|
...fetchProps
|
1475
1904
|
});
|
1476
|
-
const
|
1477
|
-
|
1478
|
-
throw new Error("The server failed to save the record");
|
1479
|
-
}
|
1480
|
-
return finalObject;
|
1905
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1906
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1481
1907
|
};
|
1482
1908
|
_bulkInsertTableRecords = new WeakSet();
|
1483
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1909
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1484
1910
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1485
1911
|
const records = objects.map((object) => transformObjectLinks(object));
|
1486
|
-
const
|
1912
|
+
const response = await bulkInsertTableRecords({
|
1487
1913
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1914
|
+
queryParams: { columns },
|
1488
1915
|
body: { records },
|
1489
1916
|
...fetchProps
|
1490
1917
|
});
|
1491
|
-
|
1492
|
-
|
1493
|
-
throw new Error("The server failed to save some records");
|
1918
|
+
if (!isResponseWithRecords(response)) {
|
1919
|
+
throw new Error("Request included columns but server didn't include them");
|
1494
1920
|
}
|
1495
|
-
const
|
1496
|
-
|
1497
|
-
return acc;
|
1498
|
-
}, {});
|
1499
|
-
return recordIDs.map((id) => dictionary[id]);
|
1921
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1922
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1500
1923
|
};
|
1501
1924
|
_updateRecordWithID = new WeakSet();
|
1502
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1925
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1503
1926
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1504
1927
|
const record = transformObjectLinks(object);
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1928
|
+
try {
|
1929
|
+
const response = await updateRecordWithID({
|
1930
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1931
|
+
queryParams: { columns },
|
1932
|
+
body: record,
|
1933
|
+
...fetchProps
|
1934
|
+
});
|
1935
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1936
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1937
|
+
} catch (e) {
|
1938
|
+
if (isObject(e) && e.status === 404) {
|
1939
|
+
return null;
|
1940
|
+
}
|
1941
|
+
throw e;
|
1942
|
+
}
|
1514
1943
|
};
|
1515
1944
|
_upsertRecordWithID = new WeakSet();
|
1516
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1945
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1517
1946
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1518
1947
|
const response = await upsertRecordWithID({
|
1519
1948
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1949
|
+
queryParams: { columns },
|
1520
1950
|
body: object,
|
1521
1951
|
...fetchProps
|
1522
1952
|
});
|
1523
|
-
const
|
1524
|
-
|
1525
|
-
throw new Error("The server failed to save the record");
|
1526
|
-
return item;
|
1953
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1954
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1527
1955
|
};
|
1528
1956
|
_deleteRecord = new WeakSet();
|
1529
|
-
deleteRecord_fn = async function(recordId) {
|
1957
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1530
1958
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
await __privateGet$4(this, _cache).delete(key);
|
1959
|
+
try {
|
1960
|
+
const response = await deleteRecord({
|
1961
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1962
|
+
queryParams: { columns },
|
1963
|
+
...fetchProps
|
1964
|
+
});
|
1965
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1966
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1967
|
+
} catch (e) {
|
1968
|
+
if (isObject(e) && e.status === 404) {
|
1969
|
+
return null;
|
1970
|
+
}
|
1971
|
+
throw e;
|
1545
1972
|
}
|
1546
1973
|
};
|
1547
|
-
_setCacheRecord = new WeakSet();
|
1548
|
-
setCacheRecord_fn = async function(record) {
|
1549
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1550
|
-
return;
|
1551
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1552
|
-
};
|
1553
|
-
_getCacheRecord = new WeakSet();
|
1554
|
-
getCacheRecord_fn = async function(recordId) {
|
1555
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1556
|
-
return null;
|
1557
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1558
|
-
};
|
1559
1974
|
_setCacheQuery = new WeakSet();
|
1560
1975
|
setCacheQuery_fn = async function(query, meta, records) {
|
1561
1976
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1616,16 +2031,24 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1616
2031
|
console.error(`Failed to parse link for field ${column.name}`);
|
1617
2032
|
} else if (isObject(value)) {
|
1618
2033
|
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
2034
|
+
} else {
|
2035
|
+
result[column.name] = null;
|
1619
2036
|
}
|
1620
2037
|
break;
|
1621
2038
|
}
|
2039
|
+
default:
|
2040
|
+
result[column.name] = value ?? null;
|
2041
|
+
if (column.notNull === true && value === null) {
|
2042
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2043
|
+
}
|
2044
|
+
break;
|
1622
2045
|
}
|
1623
2046
|
}
|
1624
|
-
result.read = function() {
|
1625
|
-
return db[table].read(result["id"]);
|
2047
|
+
result.read = function(columns2) {
|
2048
|
+
return db[table].read(result["id"], columns2);
|
1626
2049
|
};
|
1627
|
-
result.update = function(data) {
|
1628
|
-
return db[table].update(result["id"], data);
|
2050
|
+
result.update = function(data, columns2) {
|
2051
|
+
return db[table].update(result["id"], data, columns2);
|
1629
2052
|
};
|
1630
2053
|
result.delete = function() {
|
1631
2054
|
return db[table].delete(result["id"]);
|
@@ -1639,14 +2062,21 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1639
2062
|
Object.freeze(result);
|
1640
2063
|
return result;
|
1641
2064
|
};
|
1642
|
-
function
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
if (
|
1647
|
-
return
|
1648
|
-
|
1649
|
-
|
2065
|
+
function isResponseWithRecords(value) {
|
2066
|
+
return isObject(value) && Array.isArray(value.records);
|
2067
|
+
}
|
2068
|
+
function extractId(value) {
|
2069
|
+
if (isString(value))
|
2070
|
+
return value;
|
2071
|
+
if (isObject(value) && isString(value.id))
|
2072
|
+
return value.id;
|
2073
|
+
return void 0;
|
2074
|
+
}
|
2075
|
+
function cleanFilter(filter) {
|
2076
|
+
if (!filter)
|
2077
|
+
return void 0;
|
2078
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2079
|
+
return values.length > 0 ? filter : void 0;
|
1650
2080
|
}
|
1651
2081
|
|
1652
2082
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1673,7 +2103,6 @@ class SimpleCache {
|
|
1673
2103
|
__privateAdd$3(this, _map, void 0);
|
1674
2104
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1675
2105
|
this.capacity = options.max ?? 500;
|
1676
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1677
2106
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1678
2107
|
}
|
1679
2108
|
async getAll() {
|
@@ -1699,18 +2128,25 @@ class SimpleCache {
|
|
1699
2128
|
}
|
1700
2129
|
_map = new WeakMap();
|
1701
2130
|
|
1702
|
-
const
|
1703
|
-
const
|
1704
|
-
const
|
1705
|
-
const
|
1706
|
-
const
|
1707
|
-
const
|
2131
|
+
const greaterThan = (value) => ({ $gt: value });
|
2132
|
+
const gt = greaterThan;
|
2133
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2134
|
+
const greaterEquals = greaterThanEquals;
|
2135
|
+
const gte = greaterThanEquals;
|
2136
|
+
const ge = greaterThanEquals;
|
2137
|
+
const lessThan = (value) => ({ $lt: value });
|
2138
|
+
const lt = lessThan;
|
2139
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2140
|
+
const lessEquals = lessThanEquals;
|
2141
|
+
const lte = lessThanEquals;
|
2142
|
+
const le = lessThanEquals;
|
1708
2143
|
const exists = (column) => ({ $exists: column });
|
1709
2144
|
const notExists = (column) => ({ $notExists: column });
|
1710
2145
|
const startsWith = (value) => ({ $startsWith: value });
|
1711
2146
|
const endsWith = (value) => ({ $endsWith: value });
|
1712
2147
|
const pattern = (value) => ({ $pattern: value });
|
1713
2148
|
const is = (value) => ({ $is: value });
|
2149
|
+
const equals = is;
|
1714
2150
|
const isNot = (value) => ({ $isNot: value });
|
1715
2151
|
const contains = (value) => ({ $contains: value });
|
1716
2152
|
const includes = (value) => ({ $includes: value });
|
@@ -1745,16 +2181,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1745
2181
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1746
2182
|
}
|
1747
2183
|
build(pluginOptions) {
|
1748
|
-
const db = new Proxy(
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
2184
|
+
const db = new Proxy(
|
2185
|
+
{},
|
2186
|
+
{
|
2187
|
+
get: (_target, table) => {
|
2188
|
+
if (!isString(table))
|
2189
|
+
throw new Error("Invalid table name");
|
2190
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2191
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2192
|
+
}
|
2193
|
+
return __privateGet$2(this, _tables)[table];
|
1754
2194
|
}
|
1755
|
-
return __privateGet$2(this, _tables)[table];
|
1756
2195
|
}
|
1757
|
-
|
2196
|
+
);
|
1758
2197
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1759
2198
|
for (const table of tableNames) {
|
1760
2199
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1824,10 +2263,10 @@ _schemaTables = new WeakMap();
|
|
1824
2263
|
_search = new WeakSet();
|
1825
2264
|
search_fn = async function(query, options, getFetchProps) {
|
1826
2265
|
const fetchProps = await getFetchProps();
|
1827
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
2266
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1828
2267
|
const { records } = await searchBranch({
|
1829
2268
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1830
|
-
body: { tables, query, fuzziness, highlight },
|
2269
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1831
2270
|
...fetchProps
|
1832
2271
|
});
|
1833
2272
|
return records;
|
@@ -1849,21 +2288,15 @@ const isBranchStrategyBuilder = (strategy) => {
|
|
1849
2288
|
return typeof strategy === "function";
|
1850
2289
|
};
|
1851
2290
|
|
1852
|
-
const envBranchNames = [
|
1853
|
-
"XATA_BRANCH",
|
1854
|
-
"VERCEL_GIT_COMMIT_REF",
|
1855
|
-
"CF_PAGES_BRANCH",
|
1856
|
-
"BRANCH"
|
1857
|
-
];
|
1858
2291
|
async function getCurrentBranchName(options) {
|
1859
|
-
const
|
1860
|
-
if (
|
1861
|
-
const details = await getDatabaseBranch(
|
2292
|
+
const { branch, envBranch } = getEnvironment();
|
2293
|
+
if (branch) {
|
2294
|
+
const details = await getDatabaseBranch(branch, options);
|
1862
2295
|
if (details)
|
1863
|
-
return
|
1864
|
-
console.warn(`Branch ${
|
2296
|
+
return branch;
|
2297
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1865
2298
|
}
|
1866
|
-
const gitBranch = await getGitBranch();
|
2299
|
+
const gitBranch = envBranch || await getGitBranch();
|
1867
2300
|
return resolveXataBranch(gitBranch, options);
|
1868
2301
|
}
|
1869
2302
|
async function getCurrentBranchDetails(options) {
|
@@ -1874,18 +2307,24 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1874
2307
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1875
2308
|
const apiKey = options?.apiKey || getAPIKey();
|
1876
2309
|
if (!databaseURL)
|
1877
|
-
throw new Error(
|
2310
|
+
throw new Error(
|
2311
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2312
|
+
);
|
1878
2313
|
if (!apiKey)
|
1879
|
-
throw new Error(
|
2314
|
+
throw new Error(
|
2315
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2316
|
+
);
|
1880
2317
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1881
2318
|
const [workspace] = host.split(".");
|
2319
|
+
const { fallbackBranch } = getEnvironment();
|
1882
2320
|
const { branch } = await resolveBranch({
|
1883
2321
|
apiKey,
|
1884
2322
|
apiUrl: databaseURL,
|
1885
2323
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1886
2324
|
workspacesApiUrl: `${protocol}//${host}`,
|
1887
2325
|
pathParams: { dbName, workspace },
|
1888
|
-
queryParams: { gitBranch, fallbackBranch
|
2326
|
+
queryParams: { gitBranch, fallbackBranch },
|
2327
|
+
trace: defaultTrace
|
1889
2328
|
});
|
1890
2329
|
return branch;
|
1891
2330
|
}
|
@@ -1893,9 +2332,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1893
2332
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1894
2333
|
const apiKey = options?.apiKey || getAPIKey();
|
1895
2334
|
if (!databaseURL)
|
1896
|
-
throw new Error(
|
2335
|
+
throw new Error(
|
2336
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2337
|
+
);
|
1897
2338
|
if (!apiKey)
|
1898
|
-
throw new Error(
|
2339
|
+
throw new Error(
|
2340
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2341
|
+
);
|
1899
2342
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1900
2343
|
const [workspace] = host.split(".");
|
1901
2344
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1905,7 +2348,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1905
2348
|
apiUrl: databaseURL,
|
1906
2349
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1907
2350
|
workspacesApiUrl: `${protocol}//${host}`,
|
1908
|
-
pathParams: { dbBranchName, workspace }
|
2351
|
+
pathParams: { dbBranchName, workspace },
|
2352
|
+
trace: defaultTrace
|
1909
2353
|
});
|
1910
2354
|
} catch (err) {
|
1911
2355
|
if (isObject(err) && err.status === 404)
|
@@ -1913,21 +2357,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1913
2357
|
throw err;
|
1914
2358
|
}
|
1915
2359
|
}
|
1916
|
-
function getBranchByEnvVariable() {
|
1917
|
-
for (const name of envBranchNames) {
|
1918
|
-
const value = getEnvVariable(name);
|
1919
|
-
if (value) {
|
1920
|
-
return value;
|
1921
|
-
}
|
1922
|
-
}
|
1923
|
-
try {
|
1924
|
-
return XATA_BRANCH;
|
1925
|
-
} catch (err) {
|
1926
|
-
}
|
1927
|
-
}
|
1928
2360
|
function getDatabaseURL() {
|
1929
2361
|
try {
|
1930
|
-
|
2362
|
+
const { databaseURL } = getEnvironment();
|
2363
|
+
return databaseURL;
|
1931
2364
|
} catch (err) {
|
1932
2365
|
return void 0;
|
1933
2366
|
}
|
@@ -1956,17 +2389,20 @@ var __privateMethod = (obj, member, method) => {
|
|
1956
2389
|
return method;
|
1957
2390
|
};
|
1958
2391
|
const buildClient = (plugins) => {
|
1959
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2392
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1960
2393
|
return _a = class {
|
1961
2394
|
constructor(options = {}, schemaTables) {
|
1962
2395
|
__privateAdd(this, _parseOptions);
|
1963
2396
|
__privateAdd(this, _getFetchProps);
|
1964
2397
|
__privateAdd(this, _evaluateBranch);
|
1965
2398
|
__privateAdd(this, _branch, void 0);
|
2399
|
+
__privateAdd(this, _options, void 0);
|
1966
2400
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2401
|
+
__privateSet(this, _options, safeOptions);
|
1967
2402
|
const pluginOptions = {
|
1968
2403
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1969
|
-
cache: safeOptions.cache
|
2404
|
+
cache: safeOptions.cache,
|
2405
|
+
trace: safeOptions.trace
|
1970
2406
|
};
|
1971
2407
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1972
2408
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -1985,22 +2421,26 @@ const buildClient = (plugins) => {
|
|
1985
2421
|
}
|
1986
2422
|
}
|
1987
2423
|
}
|
1988
|
-
|
2424
|
+
async getConfig() {
|
2425
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2426
|
+
const branch = await __privateGet(this, _options).branch();
|
2427
|
+
return { databaseURL, branch };
|
2428
|
+
}
|
2429
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1989
2430
|
const fetch = getFetchImplementation(options?.fetch);
|
1990
2431
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1991
2432
|
const apiKey = options?.apiKey || getAPIKey();
|
1992
|
-
const cache = options?.cache ?? new SimpleCache({
|
2433
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2434
|
+
const trace = options?.trace ?? defaultTrace;
|
1993
2435
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1994
|
-
if (!
|
1995
|
-
throw new Error("
|
2436
|
+
if (!apiKey) {
|
2437
|
+
throw new Error("Option apiKey is required");
|
1996
2438
|
}
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
apiKey,
|
2001
|
-
|
2002
|
-
branch
|
2003
|
-
}) {
|
2439
|
+
if (!databaseURL) {
|
2440
|
+
throw new Error("Option databaseURL is required");
|
2441
|
+
}
|
2442
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2443
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2004
2444
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2005
2445
|
if (!branchValue)
|
2006
2446
|
throw new Error("Unable to resolve branch value");
|
@@ -2010,9 +2450,10 @@ const buildClient = (plugins) => {
|
|
2010
2450
|
apiUrl: "",
|
2011
2451
|
workspacesApiUrl: (path, params) => {
|
2012
2452
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2013
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2453
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2014
2454
|
return databaseURL + newPath;
|
2015
|
-
}
|
2455
|
+
},
|
2456
|
+
trace
|
2016
2457
|
};
|
2017
2458
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2018
2459
|
if (__privateGet(this, _branch))
|
@@ -2035,6 +2476,88 @@ const buildClient = (plugins) => {
|
|
2035
2476
|
class BaseClient extends buildClient() {
|
2036
2477
|
}
|
2037
2478
|
|
2479
|
+
const META = "__";
|
2480
|
+
const VALUE = "___";
|
2481
|
+
class Serializer {
|
2482
|
+
constructor() {
|
2483
|
+
this.classes = {};
|
2484
|
+
}
|
2485
|
+
add(clazz) {
|
2486
|
+
this.classes[clazz.name] = clazz;
|
2487
|
+
}
|
2488
|
+
toJSON(data) {
|
2489
|
+
function visit(obj) {
|
2490
|
+
if (Array.isArray(obj))
|
2491
|
+
return obj.map(visit);
|
2492
|
+
const type = typeof obj;
|
2493
|
+
if (type === "undefined")
|
2494
|
+
return { [META]: "undefined" };
|
2495
|
+
if (type === "bigint")
|
2496
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2497
|
+
if (obj === null || type !== "object")
|
2498
|
+
return obj;
|
2499
|
+
const constructor = obj.constructor;
|
2500
|
+
const o = { [META]: constructor.name };
|
2501
|
+
for (const [key, value] of Object.entries(obj)) {
|
2502
|
+
o[key] = visit(value);
|
2503
|
+
}
|
2504
|
+
if (constructor === Date)
|
2505
|
+
o[VALUE] = obj.toISOString();
|
2506
|
+
if (constructor === Map)
|
2507
|
+
o[VALUE] = Object.fromEntries(obj);
|
2508
|
+
if (constructor === Set)
|
2509
|
+
o[VALUE] = [...obj];
|
2510
|
+
return o;
|
2511
|
+
}
|
2512
|
+
return JSON.stringify(visit(data));
|
2513
|
+
}
|
2514
|
+
fromJSON(json) {
|
2515
|
+
return JSON.parse(json, (key, value) => {
|
2516
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2517
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2518
|
+
const constructor = this.classes[clazz];
|
2519
|
+
if (constructor) {
|
2520
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2521
|
+
}
|
2522
|
+
if (clazz === "Date")
|
2523
|
+
return new Date(val);
|
2524
|
+
if (clazz === "Set")
|
2525
|
+
return new Set(val);
|
2526
|
+
if (clazz === "Map")
|
2527
|
+
return new Map(Object.entries(val));
|
2528
|
+
if (clazz === "bigint")
|
2529
|
+
return BigInt(val);
|
2530
|
+
if (clazz === "undefined")
|
2531
|
+
return void 0;
|
2532
|
+
return rest;
|
2533
|
+
}
|
2534
|
+
return value;
|
2535
|
+
});
|
2536
|
+
}
|
2537
|
+
}
|
2538
|
+
const defaultSerializer = new Serializer();
|
2539
|
+
const serialize = (data) => {
|
2540
|
+
return defaultSerializer.toJSON(data);
|
2541
|
+
};
|
2542
|
+
const deserialize = (json) => {
|
2543
|
+
return defaultSerializer.fromJSON(json);
|
2544
|
+
};
|
2545
|
+
|
2546
|
+
function buildWorkerRunner(config) {
|
2547
|
+
return function xataWorker(name, _worker) {
|
2548
|
+
return async (...args) => {
|
2549
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2550
|
+
const result = await fetch(url, {
|
2551
|
+
method: "POST",
|
2552
|
+
headers: { "Content-Type": "application/json" },
|
2553
|
+
body: serialize({ args })
|
2554
|
+
});
|
2555
|
+
const text = await result.text();
|
2556
|
+
return deserialize(text);
|
2557
|
+
};
|
2558
|
+
};
|
2559
|
+
}
|
2560
|
+
|
2038
2561
|
class XataError extends Error {
|
2039
2562
|
constructor(message, status) {
|
2040
2563
|
super(message);
|
@@ -2042,5 +2565,5 @@ class XataError extends Error {
|
|
2042
2565
|
}
|
2043
2566
|
}
|
2044
2567
|
|
2045
|
-
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 };
|
2568
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2046
2569
|
//# sourceMappingURL=index.mjs.map
|