@xata.io/client 0.0.0-alpha.vf7b5320 → 0.0.0-alpha.vf7d30cc
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/.eslintrc.cjs +1 -2
- package/CHANGELOG.md +222 -0
- package/README.md +273 -1
- package/Usage.md +451 -0
- package/dist/index.cjs +1155 -456
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1961 -334
- package/dist/index.mjs +1106 -457
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -4
- package/tsconfig.json +1 -0
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
|
}
|
@@ -7,46 +29,101 @@ function compact(arr) {
|
|
7
29
|
function isObject(value) {
|
8
30
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
9
31
|
}
|
32
|
+
function isDefined(value) {
|
33
|
+
return value !== null && value !== void 0;
|
34
|
+
}
|
10
35
|
function isString(value) {
|
11
|
-
return value
|
36
|
+
return isDefined(value) && typeof value === "string";
|
37
|
+
}
|
38
|
+
function isStringArray(value) {
|
39
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
12
40
|
}
|
13
41
|
function toBase64(value) {
|
14
42
|
try {
|
15
43
|
return btoa(value);
|
16
44
|
} catch (err) {
|
17
|
-
|
45
|
+
const buf = Buffer;
|
46
|
+
return buf.from(value).toString("base64");
|
18
47
|
}
|
19
48
|
}
|
20
49
|
|
21
|
-
function
|
50
|
+
function getEnvironment() {
|
22
51
|
try {
|
23
|
-
if (isObject(process) &&
|
24
|
-
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
|
+
};
|
25
60
|
}
|
26
61
|
} catch (err) {
|
27
62
|
}
|
28
63
|
try {
|
29
|
-
if (isObject(Deno) &&
|
30
|
-
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
|
+
};
|
31
72
|
}
|
32
73
|
} catch (err) {
|
33
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
|
+
}
|
34
110
|
}
|
35
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"] };
|
36
116
|
try {
|
37
117
|
if (typeof require === "function") {
|
38
|
-
|
39
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
118
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
40
119
|
}
|
120
|
+
const { execSync } = await import(nodeModule);
|
121
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
41
122
|
} catch (err) {
|
42
123
|
}
|
43
124
|
try {
|
44
125
|
if (isObject(Deno)) {
|
45
|
-
const process2 = Deno.run({
|
46
|
-
cmd: ["git", "branch", "--show-current"],
|
47
|
-
stdout: "piped",
|
48
|
-
stderr: "piped"
|
49
|
-
});
|
126
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
50
127
|
return new TextDecoder().decode(await process2.output()).trim();
|
51
128
|
}
|
52
129
|
} catch (err) {
|
@@ -55,7 +132,8 @@ async function getGitBranch() {
|
|
55
132
|
|
56
133
|
function getAPIKey() {
|
57
134
|
try {
|
58
|
-
|
135
|
+
const { apiKey } = getEnvironment();
|
136
|
+
return apiKey;
|
59
137
|
} catch (err) {
|
60
138
|
return void 0;
|
61
139
|
}
|
@@ -65,21 +143,35 @@ function getFetchImplementation(userFetch) {
|
|
65
143
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
66
144
|
const fetchImpl = userFetch ?? globalFetch;
|
67
145
|
if (!fetchImpl) {
|
68
|
-
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
|
+
);
|
69
149
|
}
|
70
150
|
return fetchImpl;
|
71
151
|
}
|
72
152
|
|
73
|
-
|
74
|
-
|
153
|
+
const VERSION = "0.0.0-alpha.vf7d30cc";
|
154
|
+
|
155
|
+
class ErrorWithCause extends Error {
|
156
|
+
constructor(message, options) {
|
157
|
+
super(message, options);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
class FetcherError extends ErrorWithCause {
|
161
|
+
constructor(status, data, requestId) {
|
75
162
|
super(getMessage(data));
|
76
163
|
this.status = status;
|
77
164
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
165
|
+
this.requestId = requestId;
|
78
166
|
if (data instanceof Error) {
|
79
167
|
this.stack = data.stack;
|
80
168
|
this.cause = data.cause;
|
81
169
|
}
|
82
170
|
}
|
171
|
+
toString() {
|
172
|
+
const error = super.toString();
|
173
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
174
|
+
}
|
83
175
|
}
|
84
176
|
function isBulkError(error) {
|
85
177
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -102,9 +194,17 @@ function getMessage(data) {
|
|
102
194
|
}
|
103
195
|
|
104
196
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
105
|
-
const
|
197
|
+
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
198
|
+
if (value === void 0 || value === null)
|
199
|
+
return acc;
|
200
|
+
return { ...acc, [key]: value };
|
201
|
+
}, {});
|
202
|
+
const query = new URLSearchParams(cleanQueryParams).toString();
|
106
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
107
|
-
|
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;
|
108
208
|
};
|
109
209
|
function buildBaseUrl({
|
110
210
|
path,
|
@@ -112,10 +212,10 @@ function buildBaseUrl({
|
|
112
212
|
apiUrl,
|
113
213
|
pathParams
|
114
214
|
}) {
|
115
|
-
if (
|
215
|
+
if (pathParams?.workspace === void 0)
|
116
216
|
return `${apiUrl}${path}`;
|
117
217
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
118
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
218
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
119
219
|
}
|
120
220
|
function hostHeader(url) {
|
121
221
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -132,32 +232,61 @@ async function fetch$1({
|
|
132
232
|
fetchImpl,
|
133
233
|
apiKey,
|
134
234
|
apiUrl,
|
135
|
-
workspacesApiUrl
|
235
|
+
workspacesApiUrl,
|
236
|
+
trace
|
136
237
|
}) {
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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) {
|
153
285
|
try {
|
154
|
-
const
|
155
|
-
|
156
|
-
return jsonResponse;
|
157
|
-
}
|
158
|
-
throw new FetcherError(response.status, jsonResponse);
|
286
|
+
const { host, protocol } = new URL(url);
|
287
|
+
return { host, protocol };
|
159
288
|
} catch (error) {
|
160
|
-
|
289
|
+
return {};
|
161
290
|
}
|
162
291
|
}
|
163
292
|
|
@@ -216,6 +345,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
216
345
|
...variables
|
217
346
|
});
|
218
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 });
|
219
349
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
220
350
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
221
351
|
method: "delete",
|
@@ -251,6 +381,12 @@ const deleteDatabase = (variables) => fetch$1({
|
|
251
381
|
method: "delete",
|
252
382
|
...variables
|
253
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 });
|
254
390
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
255
391
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
256
392
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -259,16 +395,28 @@ const resolveBranch = (variables) => fetch$1({
|
|
259
395
|
method: "get",
|
260
396
|
...variables
|
261
397
|
});
|
262
|
-
const
|
263
|
-
|
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}",
|
264
402
|
method: "get",
|
265
403
|
...variables
|
266
404
|
});
|
267
|
-
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({
|
268
415
|
url: "/db/{dbBranchName}",
|
269
|
-
method: "
|
416
|
+
method: "get",
|
270
417
|
...variables
|
271
418
|
});
|
419
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
272
420
|
const deleteBranch = (variables) => fetch$1({
|
273
421
|
url: "/db/{dbBranchName}",
|
274
422
|
method: "delete",
|
@@ -287,6 +435,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
287
435
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
288
436
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
289
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 });
|
290
448
|
const getBranchStats = (variables) => fetch$1({
|
291
449
|
url: "/db/{dbBranchName}/stats",
|
292
450
|
method: "get",
|
@@ -342,11 +500,7 @@ const updateColumn = (variables) => fetch$1({
|
|
342
500
|
method: "patch",
|
343
501
|
...variables
|
344
502
|
});
|
345
|
-
const insertRecord = (variables) => fetch$1({
|
346
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
347
|
-
method: "post",
|
348
|
-
...variables
|
349
|
-
});
|
503
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
350
504
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
351
505
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
352
506
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -366,11 +520,21 @@ const queryTable = (variables) => fetch$1({
|
|
366
520
|
method: "post",
|
367
521
|
...variables
|
368
522
|
});
|
523
|
+
const searchTable = (variables) => fetch$1({
|
524
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
525
|
+
method: "post",
|
526
|
+
...variables
|
527
|
+
});
|
369
528
|
const searchBranch = (variables) => fetch$1({
|
370
529
|
url: "/db/{dbBranchName}/search",
|
371
530
|
method: "post",
|
372
531
|
...variables
|
373
532
|
});
|
533
|
+
const summarizeTable = (variables) => fetch$1({
|
534
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
535
|
+
method: "post",
|
536
|
+
...variables
|
537
|
+
});
|
374
538
|
const operationsByTag = {
|
375
539
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
376
540
|
workspaces: {
|
@@ -383,6 +547,7 @@ const operationsByTag = {
|
|
383
547
|
updateWorkspaceMemberRole,
|
384
548
|
removeWorkspaceMember,
|
385
549
|
inviteWorkspaceMember,
|
550
|
+
updateWorkspaceMemberInvite,
|
386
551
|
cancelWorkspaceMemberInvite,
|
387
552
|
resendWorkspaceMemberInvite,
|
388
553
|
acceptWorkspaceMemberInvite
|
@@ -391,6 +556,8 @@ const operationsByTag = {
|
|
391
556
|
getDatabaseList,
|
392
557
|
createDatabase,
|
393
558
|
deleteDatabase,
|
559
|
+
getDatabaseMetadata,
|
560
|
+
updateDatabaseMetadata,
|
394
561
|
getGitBranchesMapping,
|
395
562
|
addGitBranchesEntry,
|
396
563
|
removeGitBranchesEntry,
|
@@ -403,10 +570,28 @@ const operationsByTag = {
|
|
403
570
|
deleteBranch,
|
404
571
|
updateBranchMetadata,
|
405
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: {
|
406
586
|
getBranchMigrationHistory,
|
407
587
|
executeBranchMigrationPlan,
|
408
588
|
getBranchMigrationPlan,
|
409
|
-
|
589
|
+
compareBranchWithUserSchema,
|
590
|
+
compareBranchSchemas,
|
591
|
+
updateBranchSchema,
|
592
|
+
previewBranchSchemaEdit,
|
593
|
+
applyBranchSchemaEdit,
|
594
|
+
getBranchSchemaHistory
|
410
595
|
},
|
411
596
|
table: {
|
412
597
|
createTable,
|
@@ -429,14 +614,16 @@ const operationsByTag = {
|
|
429
614
|
getRecord,
|
430
615
|
bulkInsertTableRecords,
|
431
616
|
queryTable,
|
432
|
-
|
617
|
+
searchTable,
|
618
|
+
searchBranch,
|
619
|
+
summarizeTable
|
433
620
|
}
|
434
621
|
};
|
435
622
|
|
436
623
|
function getHostUrl(provider, type) {
|
437
|
-
if (
|
624
|
+
if (isHostProviderAlias(provider)) {
|
438
625
|
return providers[provider][type];
|
439
|
-
} else if (
|
626
|
+
} else if (isHostProviderBuilder(provider)) {
|
440
627
|
return provider[type];
|
441
628
|
}
|
442
629
|
throw new Error("Invalid API provider");
|
@@ -451,10 +638,10 @@ const providers = {
|
|
451
638
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
452
639
|
}
|
453
640
|
};
|
454
|
-
function
|
641
|
+
function isHostProviderAlias(alias) {
|
455
642
|
return isString(alias) && Object.keys(providers).includes(alias);
|
456
643
|
}
|
457
|
-
function
|
644
|
+
function isHostProviderBuilder(builder) {
|
458
645
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
459
646
|
}
|
460
647
|
|
@@ -471,7 +658,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
471
658
|
throw TypeError("Cannot add the same private member more than once");
|
472
659
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
473
660
|
};
|
474
|
-
var __privateSet$
|
661
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
475
662
|
__accessCheck$7(obj, member, "write to private field");
|
476
663
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
477
664
|
return value;
|
@@ -482,15 +669,17 @@ class XataApiClient {
|
|
482
669
|
__privateAdd$7(this, _extraProps, void 0);
|
483
670
|
__privateAdd$7(this, _namespaces, {});
|
484
671
|
const provider = options.host ?? "production";
|
485
|
-
const apiKey = options
|
672
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
673
|
+
const trace = options.trace ?? defaultTrace;
|
486
674
|
if (!apiKey) {
|
487
675
|
throw new Error("Could not resolve a valid apiKey");
|
488
676
|
}
|
489
|
-
__privateSet$
|
677
|
+
__privateSet$7(this, _extraProps, {
|
490
678
|
apiUrl: getHostUrl(provider, "main"),
|
491
679
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
492
680
|
fetchImpl: getFetchImplementation(options.fetch),
|
493
|
-
apiKey
|
681
|
+
apiKey,
|
682
|
+
trace
|
494
683
|
});
|
495
684
|
}
|
496
685
|
get user() {
|
@@ -523,6 +712,16 @@ class XataApiClient {
|
|
523
712
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
524
713
|
return __privateGet$7(this, _namespaces).records;
|
525
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
|
+
}
|
526
725
|
}
|
527
726
|
_extraProps = new WeakMap();
|
528
727
|
_namespaces = new WeakMap();
|
@@ -613,6 +812,13 @@ class WorkspaceApi {
|
|
613
812
|
...this.extraProps
|
614
813
|
});
|
615
814
|
}
|
815
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
816
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
817
|
+
pathParams: { workspaceId, inviteId },
|
818
|
+
body: { role },
|
819
|
+
...this.extraProps
|
820
|
+
});
|
821
|
+
}
|
616
822
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
617
823
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
618
824
|
pathParams: { workspaceId, inviteId },
|
@@ -655,6 +861,19 @@ class DatabaseApi {
|
|
655
861
|
...this.extraProps
|
656
862
|
});
|
657
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
|
+
}
|
658
877
|
getGitBranchesMapping(workspace, dbName) {
|
659
878
|
return operationsByTag.database.getGitBranchesMapping({
|
660
879
|
pathParams: { workspace, dbName },
|
@@ -675,10 +894,10 @@ class DatabaseApi {
|
|
675
894
|
...this.extraProps
|
676
895
|
});
|
677
896
|
}
|
678
|
-
resolveBranch(workspace, dbName, gitBranch) {
|
897
|
+
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
679
898
|
return operationsByTag.database.resolveBranch({
|
680
899
|
pathParams: { workspace, dbName },
|
681
|
-
queryParams: { gitBranch },
|
900
|
+
queryParams: { gitBranch, fallbackBranch },
|
682
901
|
...this.extraProps
|
683
902
|
});
|
684
903
|
}
|
@@ -699,10 +918,10 @@ class BranchApi {
|
|
699
918
|
...this.extraProps
|
700
919
|
});
|
701
920
|
}
|
702
|
-
createBranch(workspace, database, branch, from
|
921
|
+
createBranch(workspace, database, branch, from, options = {}) {
|
703
922
|
return operationsByTag.branch.createBranch({
|
704
923
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
705
|
-
queryParams: { from },
|
924
|
+
queryParams: isString(from) ? { from } : void 0,
|
706
925
|
body: options,
|
707
926
|
...this.extraProps
|
708
927
|
});
|
@@ -726,27 +945,6 @@ class BranchApi {
|
|
726
945
|
...this.extraProps
|
727
946
|
});
|
728
947
|
}
|
729
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
730
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
731
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
732
|
-
body: options,
|
733
|
-
...this.extraProps
|
734
|
-
});
|
735
|
-
}
|
736
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
737
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
738
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
739
|
-
body: migrationPlan,
|
740
|
-
...this.extraProps
|
741
|
-
});
|
742
|
-
}
|
743
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
744
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
745
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
746
|
-
body: schema,
|
747
|
-
...this.extraProps
|
748
|
-
});
|
749
|
-
}
|
750
948
|
getBranchStats(workspace, database, branch) {
|
751
949
|
return operationsByTag.branch.getBranchStats({
|
752
950
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -827,9 +1025,10 @@ class RecordsApi {
|
|
827
1025
|
constructor(extraProps) {
|
828
1026
|
this.extraProps = extraProps;
|
829
1027
|
}
|
830
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1028
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
831
1029
|
return operationsByTag.records.insertRecord({
|
832
1030
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1031
|
+
queryParams: options,
|
833
1032
|
body: record,
|
834
1033
|
...this.extraProps
|
835
1034
|
});
|
@@ -858,21 +1057,24 @@ class RecordsApi {
|
|
858
1057
|
...this.extraProps
|
859
1058
|
});
|
860
1059
|
}
|
861
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1060
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
862
1061
|
return operationsByTag.records.deleteRecord({
|
863
1062
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1063
|
+
queryParams: options,
|
864
1064
|
...this.extraProps
|
865
1065
|
});
|
866
1066
|
}
|
867
1067
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
868
1068
|
return operationsByTag.records.getRecord({
|
869
1069
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1070
|
+
queryParams: options,
|
870
1071
|
...this.extraProps
|
871
1072
|
});
|
872
1073
|
}
|
873
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1074
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
874
1075
|
return operationsByTag.records.bulkInsertTableRecords({
|
875
1076
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1077
|
+
queryParams: options,
|
876
1078
|
body: { records },
|
877
1079
|
...this.extraProps
|
878
1080
|
});
|
@@ -884,6 +1086,13 @@ class RecordsApi {
|
|
884
1086
|
...this.extraProps
|
885
1087
|
});
|
886
1088
|
}
|
1089
|
+
searchTable(workspace, database, branch, tableName, query) {
|
1090
|
+
return operationsByTag.records.searchTable({
|
1091
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1092
|
+
body: query,
|
1093
|
+
...this.extraProps
|
1094
|
+
});
|
1095
|
+
}
|
887
1096
|
searchBranch(workspace, database, branch, query) {
|
888
1097
|
return operationsByTag.records.searchBranch({
|
889
1098
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -891,6 +1100,138 @@ class RecordsApi {
|
|
891
1100
|
...this.extraProps
|
892
1101
|
});
|
893
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
|
+
}
|
894
1235
|
}
|
895
1236
|
|
896
1237
|
class XataApiPlugin {
|
@@ -916,18 +1257,18 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
916
1257
|
throw TypeError("Cannot add the same private member more than once");
|
917
1258
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
918
1259
|
};
|
919
|
-
var __privateSet$
|
1260
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
920
1261
|
__accessCheck$6(obj, member, "write to private field");
|
921
1262
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
922
1263
|
return value;
|
923
1264
|
};
|
924
|
-
var _query;
|
1265
|
+
var _query, _page;
|
925
1266
|
class Page {
|
926
1267
|
constructor(query, meta, records = []) {
|
927
1268
|
__privateAdd$6(this, _query, void 0);
|
928
|
-
__privateSet$
|
1269
|
+
__privateSet$6(this, _query, query);
|
929
1270
|
this.meta = meta;
|
930
|
-
this.records = records;
|
1271
|
+
this.records = new RecordArray(this, records);
|
931
1272
|
}
|
932
1273
|
async nextPage(size, offset) {
|
933
1274
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
@@ -947,9 +1288,56 @@ class Page {
|
|
947
1288
|
}
|
948
1289
|
_query = new WeakMap();
|
949
1290
|
const PAGINATION_MAX_SIZE = 200;
|
950
|
-
const PAGINATION_DEFAULT_SIZE =
|
1291
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
951
1292
|
const PAGINATION_MAX_OFFSET = 800;
|
952
1293
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1294
|
+
function isCursorPaginationOptions(options) {
|
1295
|
+
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
1296
|
+
}
|
1297
|
+
const _RecordArray = class extends Array {
|
1298
|
+
constructor(...args) {
|
1299
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
1300
|
+
__privateAdd$6(this, _page, void 0);
|
1301
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1302
|
+
}
|
1303
|
+
static parseConstructorParams(...args) {
|
1304
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1305
|
+
return new Array(args[0]);
|
1306
|
+
}
|
1307
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
1308
|
+
const result = args[1] ?? args[0].records ?? [];
|
1309
|
+
return new Array(...result);
|
1310
|
+
}
|
1311
|
+
return new Array(...args);
|
1312
|
+
}
|
1313
|
+
toArray() {
|
1314
|
+
return new Array(...this);
|
1315
|
+
}
|
1316
|
+
map(callbackfn, thisArg) {
|
1317
|
+
return this.toArray().map(callbackfn, thisArg);
|
1318
|
+
}
|
1319
|
+
async nextPage(size, offset) {
|
1320
|
+
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1321
|
+
return new _RecordArray(newPage);
|
1322
|
+
}
|
1323
|
+
async previousPage(size, offset) {
|
1324
|
+
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1325
|
+
return new _RecordArray(newPage);
|
1326
|
+
}
|
1327
|
+
async firstPage(size, offset) {
|
1328
|
+
const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
|
1329
|
+
return new _RecordArray(newPage);
|
1330
|
+
}
|
1331
|
+
async lastPage(size, offset) {
|
1332
|
+
const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
|
1333
|
+
return new _RecordArray(newPage);
|
1334
|
+
}
|
1335
|
+
hasNextPage() {
|
1336
|
+
return __privateGet$6(this, _page).meta.page.more;
|
1337
|
+
}
|
1338
|
+
};
|
1339
|
+
let RecordArray = _RecordArray;
|
1340
|
+
_page = new WeakMap();
|
953
1341
|
|
954
1342
|
var __accessCheck$5 = (obj, member, msg) => {
|
955
1343
|
if (!member.has(obj))
|
@@ -964,25 +1352,26 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
964
1352
|
throw TypeError("Cannot add the same private member more than once");
|
965
1353
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
966
1354
|
};
|
967
|
-
var __privateSet$
|
1355
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
968
1356
|
__accessCheck$5(obj, member, "write to private field");
|
969
1357
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
970
1358
|
return value;
|
971
1359
|
};
|
972
1360
|
var _table$1, _repository, _data;
|
973
1361
|
const _Query = class {
|
974
|
-
constructor(repository, table, data,
|
1362
|
+
constructor(repository, table, data, rawParent) {
|
975
1363
|
__privateAdd$5(this, _table$1, void 0);
|
976
1364
|
__privateAdd$5(this, _repository, void 0);
|
977
1365
|
__privateAdd$5(this, _data, { filter: {} });
|
978
1366
|
this.meta = { page: { cursor: "start", more: true } };
|
979
|
-
this.records = [];
|
980
|
-
__privateSet$
|
1367
|
+
this.records = new RecordArray(this, []);
|
1368
|
+
__privateSet$5(this, _table$1, table);
|
981
1369
|
if (repository) {
|
982
|
-
__privateSet$
|
1370
|
+
__privateSet$5(this, _repository, repository);
|
983
1371
|
} else {
|
984
|
-
__privateSet$
|
1372
|
+
__privateSet$5(this, _repository, this);
|
985
1373
|
}
|
1374
|
+
const parent = cleanParent(data, rawParent);
|
986
1375
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
987
1376
|
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
988
1377
|
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
@@ -1027,55 +1416,88 @@ const _Query = class {
|
|
1027
1416
|
}
|
1028
1417
|
filter(a, b) {
|
1029
1418
|
if (arguments.length === 1) {
|
1030
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1419
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1031
1420
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1032
1421
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1033
1422
|
} else {
|
1034
|
-
const
|
1423
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1424
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1035
1425
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1036
1426
|
}
|
1037
1427
|
}
|
1038
|
-
|
1428
|
+
defaultFilter(column, value) {
|
1429
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1430
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1431
|
+
return { $includes: value };
|
1432
|
+
}
|
1433
|
+
return value;
|
1434
|
+
}
|
1435
|
+
sort(column, direction = "asc") {
|
1039
1436
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1040
1437
|
const sort = [...originalSort, { column, direction }];
|
1041
1438
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1042
1439
|
}
|
1043
1440
|
select(columns) {
|
1044
|
-
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
|
+
);
|
1045
1447
|
}
|
1046
1448
|
getPaginated(options = {}) {
|
1047
1449
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1048
1450
|
return __privateGet$5(this, _repository).query(query);
|
1049
1451
|
}
|
1050
1452
|
async *[Symbol.asyncIterator]() {
|
1051
|
-
for await (const [record] of this.getIterator(1)) {
|
1453
|
+
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1052
1454
|
yield record;
|
1053
1455
|
}
|
1054
1456
|
}
|
1055
|
-
async *getIterator(
|
1056
|
-
|
1057
|
-
let
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1457
|
+
async *getIterator(options = {}) {
|
1458
|
+
const { batchSize = 1 } = options;
|
1459
|
+
let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
|
1460
|
+
let more = page.hasNextPage();
|
1461
|
+
yield page.records;
|
1462
|
+
while (more) {
|
1463
|
+
page = await page.nextPage();
|
1464
|
+
more = page.hasNextPage();
|
1465
|
+
yield page.records;
|
1063
1466
|
}
|
1064
1467
|
}
|
1065
1468
|
async getMany(options = {}) {
|
1066
|
-
const {
|
1067
|
-
|
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
|
+
}
|
1478
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1479
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1480
|
+
}
|
1481
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1482
|
+
return array;
|
1068
1483
|
}
|
1069
|
-
async getAll(
|
1484
|
+
async getAll(options = {}) {
|
1485
|
+
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
1070
1486
|
const results = [];
|
1071
|
-
for await (const page of this.getIterator(
|
1487
|
+
for await (const page of this.getIterator({ ...rest, batchSize })) {
|
1072
1488
|
results.push(...page);
|
1073
1489
|
}
|
1074
1490
|
return results;
|
1075
1491
|
}
|
1076
1492
|
async getFirst(options = {}) {
|
1077
1493
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1078
|
-
return records[0]
|
1494
|
+
return records[0] ?? null;
|
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];
|
1079
1501
|
}
|
1080
1502
|
cache(ttl) {
|
1081
1503
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
@@ -1100,12 +1522,20 @@ let Query = _Query;
|
|
1100
1522
|
_table$1 = new WeakMap();
|
1101
1523
|
_repository = new WeakMap();
|
1102
1524
|
_data = new WeakMap();
|
1525
|
+
function cleanParent(data, parent) {
|
1526
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
1527
|
+
return { ...parent, sorting: void 0, filter: void 0 };
|
1528
|
+
}
|
1529
|
+
return parent;
|
1530
|
+
}
|
1103
1531
|
|
1104
1532
|
function isIdentifiable(x) {
|
1105
1533
|
return isObject(x) && isString(x?.id);
|
1106
1534
|
}
|
1107
1535
|
function isXataRecord(x) {
|
1108
|
-
|
1536
|
+
const record = x;
|
1537
|
+
const metadata = record?.getMetadata();
|
1538
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
1109
1539
|
}
|
1110
1540
|
|
1111
1541
|
function isSortFilterString(value) {
|
@@ -1144,7 +1574,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1144
1574
|
throw TypeError("Cannot add the same private member more than once");
|
1145
1575
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1146
1576
|
};
|
1147
|
-
var __privateSet$
|
1577
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1148
1578
|
__accessCheck$4(obj, member, "write to private field");
|
1149
1579
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1150
1580
|
return value;
|
@@ -1153,180 +1583,284 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1153
1583
|
__accessCheck$4(obj, member, "access private method");
|
1154
1584
|
return method;
|
1155
1585
|
};
|
1156
|
-
var _table, _getFetchProps, _cache,
|
1586
|
+
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;
|
1157
1587
|
class Repository extends Query {
|
1158
1588
|
}
|
1159
1589
|
class RestRepository extends Query {
|
1160
1590
|
constructor(options) {
|
1161
|
-
super(
|
1591
|
+
super(
|
1592
|
+
null,
|
1593
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1594
|
+
{}
|
1595
|
+
);
|
1162
1596
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1163
1597
|
__privateAdd$4(this, _insertRecordWithId);
|
1164
1598
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
1165
1599
|
__privateAdd$4(this, _updateRecordWithID);
|
1166
1600
|
__privateAdd$4(this, _upsertRecordWithID);
|
1167
1601
|
__privateAdd$4(this, _deleteRecord);
|
1168
|
-
__privateAdd$4(this, _invalidateCache);
|
1169
|
-
__privateAdd$4(this, _setCacheRecord);
|
1170
|
-
__privateAdd$4(this, _getCacheRecord);
|
1171
1602
|
__privateAdd$4(this, _setCacheQuery);
|
1172
1603
|
__privateAdd$4(this, _getCacheQuery);
|
1173
|
-
__privateAdd$4(this,
|
1604
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1174
1605
|
__privateAdd$4(this, _table, void 0);
|
1175
1606
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1607
|
+
__privateAdd$4(this, _db, void 0);
|
1176
1608
|
__privateAdd$4(this, _cache, void 0);
|
1177
|
-
__privateAdd$4(this,
|
1178
|
-
|
1179
|
-
__privateSet$
|
1180
|
-
this
|
1181
|
-
__privateSet$
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
throw new Error("The id can't be empty");
|
1192
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
|
1193
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1194
|
-
return record;
|
1195
|
-
}
|
1196
|
-
if (isObject(a) && isString(a.id)) {
|
1197
|
-
if (a.id === "")
|
1198
|
-
throw new Error("The id can't be empty");
|
1199
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
|
1200
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1201
|
-
return record;
|
1202
|
-
}
|
1203
|
-
if (isObject(a)) {
|
1204
|
-
const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
|
1205
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1206
|
-
return record;
|
1207
|
-
}
|
1208
|
-
throw new Error("Invalid arguments for create method");
|
1209
|
-
}
|
1210
|
-
async read(recordId) {
|
1211
|
-
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
|
1212
|
-
if (cacheRecord)
|
1213
|
-
return cacheRecord;
|
1214
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1215
|
-
try {
|
1216
|
-
const response = await getRecord({
|
1217
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1218
|
-
...fetchProps
|
1609
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1610
|
+
__privateAdd$4(this, _trace, void 0);
|
1611
|
+
__privateSet$4(this, _table, options.table);
|
1612
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1613
|
+
__privateSet$4(this, _db, options.db);
|
1614
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1615
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1616
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1617
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1618
|
+
return trace(name, fn, {
|
1619
|
+
...options2,
|
1620
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1621
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1622
|
+
[TraceAttributes.VERSION]: VERSION
|
1219
1623
|
});
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1624
|
+
});
|
1625
|
+
}
|
1626
|
+
async create(a, b, c) {
|
1627
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1628
|
+
if (Array.isArray(a)) {
|
1629
|
+
if (a.length === 0)
|
1630
|
+
return [];
|
1631
|
+
const columns = isStringArray(b) ? b : void 0;
|
1632
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1225
1633
|
}
|
1226
|
-
|
1227
|
-
|
1634
|
+
if (isString(a) && isObject(b)) {
|
1635
|
+
if (a === "")
|
1636
|
+
throw new Error("The id can't be empty");
|
1637
|
+
const columns = isStringArray(c) ? c : void 0;
|
1638
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1639
|
+
}
|
1640
|
+
if (isObject(a) && isString(a.id)) {
|
1641
|
+
if (a.id === "")
|
1642
|
+
throw new Error("The id can't be empty");
|
1643
|
+
const columns = isStringArray(b) ? b : void 0;
|
1644
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1645
|
+
}
|
1646
|
+
if (isObject(a)) {
|
1647
|
+
const columns = isStringArray(b) ? b : void 0;
|
1648
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1649
|
+
}
|
1650
|
+
throw new Error("Invalid arguments for create method");
|
1651
|
+
});
|
1228
1652
|
}
|
1229
|
-
async
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1653
|
+
async read(a, b) {
|
1654
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1655
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1656
|
+
if (Array.isArray(a)) {
|
1657
|
+
if (a.length === 0)
|
1658
|
+
return [];
|
1659
|
+
const ids = a.map((item) => extractId(item));
|
1660
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1661
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1662
|
+
acc[object.id] = object;
|
1663
|
+
return acc;
|
1664
|
+
}, {});
|
1665
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1233
1666
|
}
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1667
|
+
const id = extractId(a);
|
1668
|
+
if (id) {
|
1669
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1670
|
+
try {
|
1671
|
+
const response = await getRecord({
|
1672
|
+
pathParams: {
|
1673
|
+
workspace: "{workspaceId}",
|
1674
|
+
dbBranchName: "{dbBranch}",
|
1675
|
+
tableName: __privateGet$4(this, _table),
|
1676
|
+
recordId: id
|
1677
|
+
},
|
1678
|
+
queryParams: { columns },
|
1679
|
+
...fetchProps
|
1680
|
+
});
|
1681
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1682
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1683
|
+
} catch (e) {
|
1684
|
+
if (isObject(e) && e.status === 404) {
|
1685
|
+
return null;
|
1686
|
+
}
|
1687
|
+
throw e;
|
1688
|
+
}
|
1689
|
+
}
|
1690
|
+
return null;
|
1691
|
+
});
|
1249
1692
|
}
|
1250
|
-
async
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1693
|
+
async readOrThrow(a, b) {
|
1694
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1695
|
+
const result = await this.read(a, b);
|
1696
|
+
if (Array.isArray(result)) {
|
1697
|
+
const missingIds = compact(
|
1698
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1699
|
+
);
|
1700
|
+
if (missingIds.length > 0) {
|
1701
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1702
|
+
}
|
1703
|
+
return result;
|
1254
1704
|
}
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
return record;
|
1262
|
-
}
|
1263
|
-
if (isObject(a) && isString(a.id)) {
|
1264
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1265
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1266
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1267
|
-
return record;
|
1268
|
-
}
|
1269
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1705
|
+
if (result === null) {
|
1706
|
+
const id = extractId(a) ?? "unknown";
|
1707
|
+
throw new Error(`Record with id ${id} not found`);
|
1708
|
+
}
|
1709
|
+
return result;
|
1710
|
+
});
|
1270
1711
|
}
|
1271
|
-
async
|
1272
|
-
|
1273
|
-
if (a
|
1274
|
-
|
1712
|
+
async update(a, b, c) {
|
1713
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1714
|
+
if (Array.isArray(a)) {
|
1715
|
+
if (a.length === 0)
|
1716
|
+
return [];
|
1717
|
+
if (a.length > 100) {
|
1718
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1719
|
+
}
|
1720
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1721
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1275
1722
|
}
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1723
|
+
if (isString(a) && isObject(b)) {
|
1724
|
+
const columns = isStringArray(c) ? c : void 0;
|
1725
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1726
|
+
}
|
1727
|
+
if (isObject(a) && isString(a.id)) {
|
1728
|
+
const columns = isStringArray(b) ? b : void 0;
|
1729
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1730
|
+
}
|
1731
|
+
throw new Error("Invalid arguments for update method");
|
1732
|
+
});
|
1733
|
+
}
|
1734
|
+
async updateOrThrow(a, b, c) {
|
1735
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1736
|
+
const result = await this.update(a, b, c);
|
1737
|
+
if (Array.isArray(result)) {
|
1738
|
+
const missingIds = compact(
|
1739
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1740
|
+
);
|
1741
|
+
if (missingIds.length > 0) {
|
1742
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1743
|
+
}
|
1744
|
+
return result;
|
1745
|
+
}
|
1746
|
+
if (result === null) {
|
1747
|
+
const id = extractId(a) ?? "unknown";
|
1748
|
+
throw new Error(`Record with id ${id} not found`);
|
1749
|
+
}
|
1750
|
+
return result;
|
1751
|
+
});
|
1752
|
+
}
|
1753
|
+
async createOrUpdate(a, b, c) {
|
1754
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1755
|
+
if (Array.isArray(a)) {
|
1756
|
+
if (a.length === 0)
|
1757
|
+
return [];
|
1758
|
+
if (a.length > 100) {
|
1759
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1760
|
+
}
|
1761
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1762
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1763
|
+
}
|
1764
|
+
if (isString(a) && isObject(b)) {
|
1765
|
+
const columns = isStringArray(c) ? c : void 0;
|
1766
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1767
|
+
}
|
1768
|
+
if (isObject(a) && isString(a.id)) {
|
1769
|
+
const columns = isStringArray(c) ? c : void 0;
|
1770
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1771
|
+
}
|
1772
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1773
|
+
});
|
1774
|
+
}
|
1775
|
+
async delete(a, b) {
|
1776
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1777
|
+
if (Array.isArray(a)) {
|
1778
|
+
if (a.length === 0)
|
1779
|
+
return [];
|
1780
|
+
if (a.length > 100) {
|
1781
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1782
|
+
}
|
1783
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1784
|
+
}
|
1785
|
+
if (isString(a)) {
|
1786
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1787
|
+
}
|
1788
|
+
if (isObject(a) && isString(a.id)) {
|
1789
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1790
|
+
}
|
1791
|
+
throw new Error("Invalid arguments for delete method");
|
1792
|
+
});
|
1793
|
+
}
|
1794
|
+
async deleteOrThrow(a, b) {
|
1795
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1796
|
+
const result = await this.delete(a, b);
|
1797
|
+
if (Array.isArray(result)) {
|
1798
|
+
const missingIds = compact(
|
1799
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1800
|
+
);
|
1801
|
+
if (missingIds.length > 0) {
|
1802
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1803
|
+
}
|
1804
|
+
return result;
|
1805
|
+
} else if (result === null) {
|
1806
|
+
const id = extractId(a) ?? "unknown";
|
1807
|
+
throw new Error(`Record with id ${id} not found`);
|
1808
|
+
}
|
1809
|
+
return result;
|
1810
|
+
});
|
1290
1811
|
}
|
1291
1812
|
async search(query, options = {}) {
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1813
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1814
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1815
|
+
const { records } = await searchTable({
|
1816
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1817
|
+
body: {
|
1818
|
+
query,
|
1819
|
+
fuzziness: options.fuzziness,
|
1820
|
+
prefix: options.prefix,
|
1821
|
+
highlight: options.highlight,
|
1822
|
+
filter: options.filter,
|
1823
|
+
boosters: options.boosters
|
1824
|
+
},
|
1825
|
+
...fetchProps
|
1826
|
+
});
|
1827
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1828
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1297
1829
|
});
|
1298
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
1299
|
-
return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
|
1300
1830
|
}
|
1301
1831
|
async query(query) {
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1832
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1833
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1834
|
+
if (cacheQuery)
|
1835
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1836
|
+
const data = query.getQueryOptions();
|
1837
|
+
const body = {
|
1838
|
+
filter: cleanFilter(data.filter),
|
1839
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1840
|
+
page: data.pagination,
|
1841
|
+
columns: data.columns
|
1842
|
+
};
|
1843
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1844
|
+
const { meta, records: objects } = await queryTable({
|
1845
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1846
|
+
body,
|
1847
|
+
...fetchProps
|
1848
|
+
});
|
1849
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1850
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1851
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1852
|
+
return new Page(query, meta, records);
|
1317
1853
|
});
|
1318
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
1319
|
-
const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
|
1320
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1321
|
-
return new Page(query, meta, records);
|
1322
1854
|
}
|
1323
1855
|
}
|
1324
1856
|
_table = new WeakMap();
|
1325
1857
|
_getFetchProps = new WeakMap();
|
1858
|
+
_db = new WeakMap();
|
1326
1859
|
_cache = new WeakMap();
|
1327
|
-
|
1860
|
+
_schemaTables$2 = new WeakMap();
|
1861
|
+
_trace = new WeakMap();
|
1328
1862
|
_insertRecordWithoutId = new WeakSet();
|
1329
|
-
insertRecordWithoutId_fn = async function(object) {
|
1863
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1330
1864
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1331
1865
|
const record = transformObjectLinks(object);
|
1332
1866
|
const response = await insertRecord({
|
@@ -1335,17 +1869,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1335
1869
|
dbBranchName: "{dbBranch}",
|
1336
1870
|
tableName: __privateGet$4(this, _table)
|
1337
1871
|
},
|
1872
|
+
queryParams: { columns },
|
1338
1873
|
body: record,
|
1339
1874
|
...fetchProps
|
1340
1875
|
});
|
1341
|
-
const
|
1342
|
-
|
1343
|
-
throw new Error("The server failed to save the record");
|
1344
|
-
}
|
1345
|
-
return finalObject;
|
1876
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1877
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1346
1878
|
};
|
1347
1879
|
_insertRecordWithId = new WeakSet();
|
1348
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1880
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1349
1881
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1350
1882
|
const record = transformObjectLinks(object);
|
1351
1883
|
const response = await insertRecordWithID({
|
@@ -1356,88 +1888,78 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1356
1888
|
recordId
|
1357
1889
|
},
|
1358
1890
|
body: record,
|
1359
|
-
queryParams: { createOnly: true },
|
1891
|
+
queryParams: { createOnly: true, columns },
|
1360
1892
|
...fetchProps
|
1361
1893
|
});
|
1362
|
-
const
|
1363
|
-
|
1364
|
-
throw new Error("The server failed to save the record");
|
1365
|
-
}
|
1366
|
-
return finalObject;
|
1894
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1895
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1367
1896
|
};
|
1368
1897
|
_bulkInsertTableRecords = new WeakSet();
|
1369
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1898
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1370
1899
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1371
1900
|
const records = objects.map((object) => transformObjectLinks(object));
|
1372
1901
|
const response = await bulkInsertTableRecords({
|
1373
1902
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1903
|
+
queryParams: { columns },
|
1374
1904
|
body: { records },
|
1375
1905
|
...fetchProps
|
1376
1906
|
});
|
1377
|
-
|
1378
|
-
|
1379
|
-
throw new Error("The server failed to save some records");
|
1907
|
+
if (!isResponseWithRecords(response)) {
|
1908
|
+
throw new Error("Request included columns but server didn't include them");
|
1380
1909
|
}
|
1381
|
-
|
1910
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1911
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1382
1912
|
};
|
1383
1913
|
_updateRecordWithID = new WeakSet();
|
1384
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1914
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1385
1915
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1386
1916
|
const record = transformObjectLinks(object);
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1917
|
+
try {
|
1918
|
+
const response = await updateRecordWithID({
|
1919
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1920
|
+
queryParams: { columns },
|
1921
|
+
body: record,
|
1922
|
+
...fetchProps
|
1923
|
+
});
|
1924
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1925
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1926
|
+
} catch (e) {
|
1927
|
+
if (isObject(e) && e.status === 404) {
|
1928
|
+
return null;
|
1929
|
+
}
|
1930
|
+
throw e;
|
1931
|
+
}
|
1396
1932
|
};
|
1397
1933
|
_upsertRecordWithID = new WeakSet();
|
1398
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1934
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1399
1935
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1400
1936
|
const response = await upsertRecordWithID({
|
1401
1937
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1938
|
+
queryParams: { columns },
|
1402
1939
|
body: object,
|
1403
1940
|
...fetchProps
|
1404
1941
|
});
|
1405
|
-
const
|
1406
|
-
|
1407
|
-
throw new Error("The server failed to save the record");
|
1408
|
-
return item;
|
1942
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1943
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1409
1944
|
};
|
1410
1945
|
_deleteRecord = new WeakSet();
|
1411
|
-
deleteRecord_fn = async function(recordId) {
|
1946
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1412
1947
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
await __privateGet$4(this, _cache).delete(key);
|
1948
|
+
try {
|
1949
|
+
const response = await deleteRecord({
|
1950
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1951
|
+
queryParams: { columns },
|
1952
|
+
...fetchProps
|
1953
|
+
});
|
1954
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1955
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1956
|
+
} catch (e) {
|
1957
|
+
if (isObject(e) && e.status === 404) {
|
1958
|
+
return null;
|
1959
|
+
}
|
1960
|
+
throw e;
|
1427
1961
|
}
|
1428
1962
|
};
|
1429
|
-
_setCacheRecord = new WeakSet();
|
1430
|
-
setCacheRecord_fn = async function(record) {
|
1431
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1432
|
-
return;
|
1433
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1434
|
-
};
|
1435
|
-
_getCacheRecord = new WeakSet();
|
1436
|
-
getCacheRecord_fn = async function(recordId) {
|
1437
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1438
|
-
return null;
|
1439
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1440
|
-
};
|
1441
1963
|
_setCacheQuery = new WeakSet();
|
1442
1964
|
setCacheQuery_fn = async function(query, meta, records) {
|
1443
1965
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1449,22 +1971,22 @@ getCacheQuery_fn = async function(query) {
|
|
1449
1971
|
if (!result)
|
1450
1972
|
return null;
|
1451
1973
|
const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
|
1452
|
-
if (
|
1453
|
-
return
|
1974
|
+
if (ttl < 0)
|
1975
|
+
return null;
|
1454
1976
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1455
1977
|
return hasExpired ? null : result;
|
1456
1978
|
};
|
1457
|
-
|
1458
|
-
|
1459
|
-
if (__privateGet$4(this,
|
1460
|
-
return __privateGet$4(this,
|
1979
|
+
_getSchemaTables$1 = new WeakSet();
|
1980
|
+
getSchemaTables_fn$1 = async function() {
|
1981
|
+
if (__privateGet$4(this, _schemaTables$2))
|
1982
|
+
return __privateGet$4(this, _schemaTables$2);
|
1461
1983
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1462
1984
|
const { schema } = await getBranchDetails({
|
1463
1985
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1464
1986
|
...fetchProps
|
1465
1987
|
});
|
1466
|
-
__privateSet$
|
1467
|
-
return schema;
|
1988
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1989
|
+
return schema.tables;
|
1468
1990
|
};
|
1469
1991
|
const transformObjectLinks = (object) => {
|
1470
1992
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
@@ -1473,20 +1995,21 @@ const transformObjectLinks = (object) => {
|
|
1473
1995
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1474
1996
|
}, {});
|
1475
1997
|
};
|
1476
|
-
const initObject = (db,
|
1998
|
+
const initObject = (db, schemaTables, table, object) => {
|
1477
1999
|
const result = {};
|
1478
|
-
|
1479
|
-
|
2000
|
+
const { xata, ...rest } = object ?? {};
|
2001
|
+
Object.assign(result, rest);
|
2002
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1480
2003
|
if (!columns)
|
1481
2004
|
console.error(`Table ${table} not found in schema`);
|
1482
2005
|
for (const column of columns ?? []) {
|
1483
2006
|
const value = result[column.name];
|
1484
2007
|
switch (column.type) {
|
1485
2008
|
case "datetime": {
|
1486
|
-
const date = new Date(value);
|
1487
|
-
if (isNaN(date.getTime())) {
|
2009
|
+
const date = value !== void 0 ? new Date(value) : void 0;
|
2010
|
+
if (date && isNaN(date.getTime())) {
|
1488
2011
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1489
|
-
} else {
|
2012
|
+
} else if (date) {
|
1490
2013
|
result[column.name] = date;
|
1491
2014
|
}
|
1492
2015
|
break;
|
@@ -1495,36 +2018,54 @@ const initObject = (db, schema, table, object) => {
|
|
1495
2018
|
const linkTable = column.link?.table;
|
1496
2019
|
if (!linkTable) {
|
1497
2020
|
console.error(`Failed to parse link for field ${column.name}`);
|
1498
|
-
} else if (
|
1499
|
-
result[column.name] = initObject(db,
|
2021
|
+
} else if (isObject(value)) {
|
2022
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
2023
|
+
} else {
|
2024
|
+
result[column.name] = null;
|
1500
2025
|
}
|
1501
2026
|
break;
|
1502
2027
|
}
|
2028
|
+
default:
|
2029
|
+
result[column.name] = value ?? null;
|
2030
|
+
if (column.notNull === true && value === null) {
|
2031
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2032
|
+
}
|
2033
|
+
break;
|
1503
2034
|
}
|
1504
2035
|
}
|
1505
|
-
result.read = function() {
|
1506
|
-
return db[table].read(result["id"]);
|
2036
|
+
result.read = function(columns2) {
|
2037
|
+
return db[table].read(result["id"], columns2);
|
1507
2038
|
};
|
1508
|
-
result.update = function(data) {
|
1509
|
-
return db[table].update(result["id"], data);
|
2039
|
+
result.update = function(data, columns2) {
|
2040
|
+
return db[table].update(result["id"], data, columns2);
|
1510
2041
|
};
|
1511
2042
|
result.delete = function() {
|
1512
2043
|
return db[table].delete(result["id"]);
|
1513
2044
|
};
|
1514
|
-
|
2045
|
+
result.getMetadata = function() {
|
2046
|
+
return xata;
|
2047
|
+
};
|
2048
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
1515
2049
|
Object.defineProperty(result, prop, { enumerable: false });
|
1516
2050
|
}
|
1517
2051
|
Object.freeze(result);
|
1518
2052
|
return result;
|
1519
2053
|
};
|
1520
|
-
function
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
if (
|
1525
|
-
return
|
1526
|
-
|
1527
|
-
|
2054
|
+
function isResponseWithRecords(value) {
|
2055
|
+
return isObject(value) && Array.isArray(value.records);
|
2056
|
+
}
|
2057
|
+
function extractId(value) {
|
2058
|
+
if (isString(value))
|
2059
|
+
return value;
|
2060
|
+
if (isObject(value) && isString(value.id))
|
2061
|
+
return value.id;
|
2062
|
+
return void 0;
|
2063
|
+
}
|
2064
|
+
function cleanFilter(filter) {
|
2065
|
+
if (!filter)
|
2066
|
+
return void 0;
|
2067
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2068
|
+
return values.length > 0 ? filter : void 0;
|
1528
2069
|
}
|
1529
2070
|
|
1530
2071
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1540,7 +2081,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1540
2081
|
throw TypeError("Cannot add the same private member more than once");
|
1541
2082
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1542
2083
|
};
|
1543
|
-
var __privateSet$
|
2084
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1544
2085
|
__accessCheck$3(obj, member, "write to private field");
|
1545
2086
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1546
2087
|
return value;
|
@@ -1549,9 +2090,8 @@ var _map;
|
|
1549
2090
|
class SimpleCache {
|
1550
2091
|
constructor(options = {}) {
|
1551
2092
|
__privateAdd$3(this, _map, void 0);
|
1552
|
-
__privateSet$
|
2093
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1553
2094
|
this.capacity = options.max ?? 500;
|
1554
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1555
2095
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1556
2096
|
}
|
1557
2097
|
async getAll() {
|
@@ -1577,18 +2117,25 @@ class SimpleCache {
|
|
1577
2117
|
}
|
1578
2118
|
_map = new WeakMap();
|
1579
2119
|
|
1580
|
-
const
|
1581
|
-
const
|
1582
|
-
const
|
1583
|
-
const
|
1584
|
-
const
|
1585
|
-
const
|
2120
|
+
const greaterThan = (value) => ({ $gt: value });
|
2121
|
+
const gt = greaterThan;
|
2122
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2123
|
+
const greaterEquals = greaterThanEquals;
|
2124
|
+
const gte = greaterThanEquals;
|
2125
|
+
const ge = greaterThanEquals;
|
2126
|
+
const lessThan = (value) => ({ $lt: value });
|
2127
|
+
const lt = lessThan;
|
2128
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2129
|
+
const lessEquals = lessThanEquals;
|
2130
|
+
const lte = lessThanEquals;
|
2131
|
+
const le = lessThanEquals;
|
1586
2132
|
const exists = (column) => ({ $exists: column });
|
1587
2133
|
const notExists = (column) => ({ $notExists: column });
|
1588
2134
|
const startsWith = (value) => ({ $startsWith: value });
|
1589
2135
|
const endsWith = (value) => ({ $endsWith: value });
|
1590
2136
|
const pattern = (value) => ({ $pattern: value });
|
1591
2137
|
const is = (value) => ({ $is: value });
|
2138
|
+
const equals = is;
|
1592
2139
|
const isNot = (value) => ({ $isNot: value });
|
1593
2140
|
const contains = (value) => ({ $contains: value });
|
1594
2141
|
const includes = (value) => ({ $includes: value });
|
@@ -1609,31 +2156,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1609
2156
|
throw TypeError("Cannot add the same private member more than once");
|
1610
2157
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1611
2158
|
};
|
1612
|
-
var
|
2159
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
2160
|
+
__accessCheck$2(obj, member, "write to private field");
|
2161
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
2162
|
+
return value;
|
2163
|
+
};
|
2164
|
+
var _tables, _schemaTables$1;
|
1613
2165
|
class SchemaPlugin extends XataPlugin {
|
1614
|
-
constructor(
|
2166
|
+
constructor(schemaTables) {
|
1615
2167
|
super();
|
1616
|
-
this.tableNames = tableNames;
|
1617
2168
|
__privateAdd$2(this, _tables, {});
|
2169
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
2170
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1618
2171
|
}
|
1619
2172
|
build(pluginOptions) {
|
1620
|
-
const db = new Proxy(
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
2173
|
+
const db = new Proxy(
|
2174
|
+
{},
|
2175
|
+
{
|
2176
|
+
get: (_target, table) => {
|
2177
|
+
if (!isString(table))
|
2178
|
+
throw new Error("Invalid table name");
|
2179
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2180
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2181
|
+
}
|
2182
|
+
return __privateGet$2(this, _tables)[table];
|
1626
2183
|
}
|
1627
|
-
return __privateGet$2(this, _tables)[table];
|
1628
2184
|
}
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
2185
|
+
);
|
2186
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
2187
|
+
for (const table of tableNames) {
|
2188
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1632
2189
|
}
|
1633
2190
|
return db;
|
1634
2191
|
}
|
1635
2192
|
}
|
1636
2193
|
_tables = new WeakMap();
|
2194
|
+
_schemaTables$1 = new WeakMap();
|
1637
2195
|
|
1638
2196
|
var __accessCheck$1 = (obj, member, msg) => {
|
1639
2197
|
if (!member.has(obj))
|
@@ -1657,105 +2215,119 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1657
2215
|
__accessCheck$1(obj, member, "access private method");
|
1658
2216
|
return method;
|
1659
2217
|
};
|
1660
|
-
var
|
2218
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1661
2219
|
class SearchPlugin extends XataPlugin {
|
1662
|
-
constructor(db) {
|
2220
|
+
constructor(db, schemaTables) {
|
1663
2221
|
super();
|
1664
2222
|
this.db = db;
|
1665
2223
|
__privateAdd$1(this, _search);
|
1666
|
-
__privateAdd$1(this,
|
1667
|
-
__privateAdd$1(this,
|
2224
|
+
__privateAdd$1(this, _getSchemaTables);
|
2225
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
2226
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1668
2227
|
}
|
1669
2228
|
build({ getFetchProps }) {
|
1670
2229
|
return {
|
1671
2230
|
all: async (query, options = {}) => {
|
1672
2231
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1673
|
-
const
|
2232
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1674
2233
|
return records.map((record) => {
|
1675
2234
|
const { table = "orphan" } = record.xata;
|
1676
|
-
return { table, record: initObject(this.db,
|
2235
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
1677
2236
|
});
|
1678
2237
|
},
|
1679
2238
|
byTable: async (query, options = {}) => {
|
1680
2239
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1681
|
-
const
|
2240
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1682
2241
|
return records.reduce((acc, record) => {
|
1683
2242
|
const { table = "orphan" } = record.xata;
|
1684
2243
|
const items = acc[table] ?? [];
|
1685
|
-
const item = initObject(this.db,
|
2244
|
+
const item = initObject(this.db, schemaTables, table, record);
|
1686
2245
|
return { ...acc, [table]: [...items, item] };
|
1687
2246
|
}, {});
|
1688
2247
|
}
|
1689
2248
|
};
|
1690
2249
|
}
|
1691
2250
|
}
|
1692
|
-
|
2251
|
+
_schemaTables = new WeakMap();
|
1693
2252
|
_search = new WeakSet();
|
1694
2253
|
search_fn = async function(query, options, getFetchProps) {
|
1695
2254
|
const fetchProps = await getFetchProps();
|
1696
|
-
const { tables, fuzziness } = options ?? {};
|
2255
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1697
2256
|
const { records } = await searchBranch({
|
1698
2257
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1699
|
-
body: { tables, query, fuzziness },
|
2258
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1700
2259
|
...fetchProps
|
1701
2260
|
});
|
1702
2261
|
return records;
|
1703
2262
|
};
|
1704
|
-
|
1705
|
-
|
1706
|
-
if (__privateGet$1(this,
|
1707
|
-
return __privateGet$1(this,
|
2263
|
+
_getSchemaTables = new WeakSet();
|
2264
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
2265
|
+
if (__privateGet$1(this, _schemaTables))
|
2266
|
+
return __privateGet$1(this, _schemaTables);
|
1708
2267
|
const fetchProps = await getFetchProps();
|
1709
2268
|
const { schema } = await getBranchDetails({
|
1710
2269
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1711
2270
|
...fetchProps
|
1712
2271
|
});
|
1713
|
-
__privateSet$1(this,
|
1714
|
-
return schema;
|
2272
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
2273
|
+
return schema.tables;
|
1715
2274
|
};
|
1716
2275
|
|
1717
2276
|
const isBranchStrategyBuilder = (strategy) => {
|
1718
2277
|
return typeof strategy === "function";
|
1719
2278
|
};
|
1720
2279
|
|
1721
|
-
const envBranchNames = [
|
1722
|
-
"XATA_BRANCH",
|
1723
|
-
"VERCEL_GIT_COMMIT_REF",
|
1724
|
-
"CF_PAGES_BRANCH",
|
1725
|
-
"BRANCH"
|
1726
|
-
];
|
1727
|
-
const defaultBranch = "main";
|
1728
2280
|
async function getCurrentBranchName(options) {
|
1729
|
-
const
|
1730
|
-
if (
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
return defaultBranch;
|
2281
|
+
const { branch, envBranch } = getEnvironment();
|
2282
|
+
if (branch) {
|
2283
|
+
const details = await getDatabaseBranch(branch, options);
|
2284
|
+
if (details)
|
2285
|
+
return branch;
|
2286
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
2287
|
+
}
|
2288
|
+
const gitBranch = envBranch || await getGitBranch();
|
2289
|
+
return resolveXataBranch(gitBranch, options);
|
1739
2290
|
}
|
1740
2291
|
async function getCurrentBranchDetails(options) {
|
1741
|
-
const
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
2292
|
+
const branch = await getCurrentBranchName(options);
|
2293
|
+
return getDatabaseBranch(branch, options);
|
2294
|
+
}
|
2295
|
+
async function resolveXataBranch(gitBranch, options) {
|
2296
|
+
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2297
|
+
const apiKey = options?.apiKey || getAPIKey();
|
2298
|
+
if (!databaseURL)
|
2299
|
+
throw new Error(
|
2300
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2301
|
+
);
|
2302
|
+
if (!apiKey)
|
2303
|
+
throw new Error(
|
2304
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2305
|
+
);
|
2306
|
+
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2307
|
+
const [workspace] = host.split(".");
|
2308
|
+
const { fallbackBranch } = getEnvironment();
|
2309
|
+
const { branch } = await resolveBranch({
|
2310
|
+
apiKey,
|
2311
|
+
apiUrl: databaseURL,
|
2312
|
+
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2313
|
+
workspacesApiUrl: `${protocol}//${host}`,
|
2314
|
+
pathParams: { dbName, workspace },
|
2315
|
+
queryParams: { gitBranch, fallbackBranch },
|
2316
|
+
trace: defaultTrace
|
2317
|
+
});
|
2318
|
+
return branch;
|
1751
2319
|
}
|
1752
2320
|
async function getDatabaseBranch(branch, options) {
|
1753
2321
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1754
2322
|
const apiKey = options?.apiKey || getAPIKey();
|
1755
2323
|
if (!databaseURL)
|
1756
|
-
throw new Error(
|
2324
|
+
throw new Error(
|
2325
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2326
|
+
);
|
1757
2327
|
if (!apiKey)
|
1758
|
-
throw new Error(
|
2328
|
+
throw new Error(
|
2329
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2330
|
+
);
|
1759
2331
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1760
2332
|
const [workspace] = host.split(".");
|
1761
2333
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1765,10 +2337,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1765
2337
|
apiUrl: databaseURL,
|
1766
2338
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1767
2339
|
workspacesApiUrl: `${protocol}//${host}`,
|
1768
|
-
pathParams: {
|
1769
|
-
|
1770
|
-
workspace
|
1771
|
-
}
|
2340
|
+
pathParams: { dbBranchName, workspace },
|
2341
|
+
trace: defaultTrace
|
1772
2342
|
});
|
1773
2343
|
} catch (err) {
|
1774
2344
|
if (isObject(err) && err.status === 404)
|
@@ -1776,21 +2346,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1776
2346
|
throw err;
|
1777
2347
|
}
|
1778
2348
|
}
|
1779
|
-
function getBranchByEnvVariable() {
|
1780
|
-
for (const name of envBranchNames) {
|
1781
|
-
const value = getEnvVariable(name);
|
1782
|
-
if (value) {
|
1783
|
-
return value;
|
1784
|
-
}
|
1785
|
-
}
|
1786
|
-
try {
|
1787
|
-
return XATA_BRANCH;
|
1788
|
-
} catch (err) {
|
1789
|
-
}
|
1790
|
-
}
|
1791
2349
|
function getDatabaseURL() {
|
1792
2350
|
try {
|
1793
|
-
|
2351
|
+
const { databaseURL } = getEnvironment();
|
2352
|
+
return databaseURL;
|
1794
2353
|
} catch (err) {
|
1795
2354
|
return void 0;
|
1796
2355
|
}
|
@@ -1819,24 +2378,27 @@ var __privateMethod = (obj, member, method) => {
|
|
1819
2378
|
return method;
|
1820
2379
|
};
|
1821
2380
|
const buildClient = (plugins) => {
|
1822
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2381
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1823
2382
|
return _a = class {
|
1824
|
-
constructor(options = {},
|
2383
|
+
constructor(options = {}, schemaTables) {
|
1825
2384
|
__privateAdd(this, _parseOptions);
|
1826
2385
|
__privateAdd(this, _getFetchProps);
|
1827
2386
|
__privateAdd(this, _evaluateBranch);
|
1828
2387
|
__privateAdd(this, _branch, void 0);
|
2388
|
+
__privateAdd(this, _options, void 0);
|
1829
2389
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2390
|
+
__privateSet(this, _options, safeOptions);
|
1830
2391
|
const pluginOptions = {
|
1831
2392
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1832
|
-
cache: safeOptions.cache
|
2393
|
+
cache: safeOptions.cache,
|
2394
|
+
trace: safeOptions.trace
|
1833
2395
|
};
|
1834
|
-
const db = new SchemaPlugin(
|
1835
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
2396
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2397
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1836
2398
|
this.db = db;
|
1837
2399
|
this.search = search;
|
1838
2400
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
1839
|
-
if (
|
2401
|
+
if (namespace === void 0)
|
1840
2402
|
continue;
|
1841
2403
|
const result = namespace.build(pluginOptions);
|
1842
2404
|
if (result instanceof Promise) {
|
@@ -1848,22 +2410,26 @@ const buildClient = (plugins) => {
|
|
1848
2410
|
}
|
1849
2411
|
}
|
1850
2412
|
}
|
1851
|
-
|
2413
|
+
async getConfig() {
|
2414
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2415
|
+
const branch = await __privateGet(this, _options).branch();
|
2416
|
+
return { databaseURL, branch };
|
2417
|
+
}
|
2418
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1852
2419
|
const fetch = getFetchImplementation(options?.fetch);
|
1853
2420
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1854
2421
|
const apiKey = options?.apiKey || getAPIKey();
|
1855
|
-
const cache = options?.cache ?? new SimpleCache({
|
1856
|
-
const
|
1857
|
-
|
1858
|
-
|
2422
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2423
|
+
const trace = options?.trace ?? defaultTrace;
|
2424
|
+
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2425
|
+
if (!apiKey) {
|
2426
|
+
throw new Error("Option apiKey is required");
|
1859
2427
|
}
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
apiKey,
|
1864
|
-
|
1865
|
-
branch
|
1866
|
-
}) {
|
2428
|
+
if (!databaseURL) {
|
2429
|
+
throw new Error("Option databaseURL is required");
|
2430
|
+
}
|
2431
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2432
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
1867
2433
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1868
2434
|
if (!branchValue)
|
1869
2435
|
throw new Error("Unable to resolve branch value");
|
@@ -1873,14 +2439,15 @@ const buildClient = (plugins) => {
|
|
1873
2439
|
apiUrl: "",
|
1874
2440
|
workspacesApiUrl: (path, params) => {
|
1875
2441
|
const hasBranch = params.dbBranchName ?? params.branch;
|
1876
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2442
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
1877
2443
|
return databaseURL + newPath;
|
1878
|
-
}
|
2444
|
+
},
|
2445
|
+
trace
|
1879
2446
|
};
|
1880
2447
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
1881
2448
|
if (__privateGet(this, _branch))
|
1882
2449
|
return __privateGet(this, _branch);
|
1883
|
-
if (
|
2450
|
+
if (param === void 0)
|
1884
2451
|
return void 0;
|
1885
2452
|
const strategies = Array.isArray(param) ? [...param] : [param];
|
1886
2453
|
const evaluateBranch = async (strategy) => {
|
@@ -1898,6 +2465,88 @@ const buildClient = (plugins) => {
|
|
1898
2465
|
class BaseClient extends buildClient() {
|
1899
2466
|
}
|
1900
2467
|
|
2468
|
+
const META = "__";
|
2469
|
+
const VALUE = "___";
|
2470
|
+
class Serializer {
|
2471
|
+
constructor() {
|
2472
|
+
this.classes = {};
|
2473
|
+
}
|
2474
|
+
add(clazz) {
|
2475
|
+
this.classes[clazz.name] = clazz;
|
2476
|
+
}
|
2477
|
+
toJSON(data) {
|
2478
|
+
function visit(obj) {
|
2479
|
+
if (Array.isArray(obj))
|
2480
|
+
return obj.map(visit);
|
2481
|
+
const type = typeof obj;
|
2482
|
+
if (type === "undefined")
|
2483
|
+
return { [META]: "undefined" };
|
2484
|
+
if (type === "bigint")
|
2485
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2486
|
+
if (obj === null || type !== "object")
|
2487
|
+
return obj;
|
2488
|
+
const constructor = obj.constructor;
|
2489
|
+
const o = { [META]: constructor.name };
|
2490
|
+
for (const [key, value] of Object.entries(obj)) {
|
2491
|
+
o[key] = visit(value);
|
2492
|
+
}
|
2493
|
+
if (constructor === Date)
|
2494
|
+
o[VALUE] = obj.toISOString();
|
2495
|
+
if (constructor === Map)
|
2496
|
+
o[VALUE] = Object.fromEntries(obj);
|
2497
|
+
if (constructor === Set)
|
2498
|
+
o[VALUE] = [...obj];
|
2499
|
+
return o;
|
2500
|
+
}
|
2501
|
+
return JSON.stringify(visit(data));
|
2502
|
+
}
|
2503
|
+
fromJSON(json) {
|
2504
|
+
return JSON.parse(json, (key, value) => {
|
2505
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2506
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2507
|
+
const constructor = this.classes[clazz];
|
2508
|
+
if (constructor) {
|
2509
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2510
|
+
}
|
2511
|
+
if (clazz === "Date")
|
2512
|
+
return new Date(val);
|
2513
|
+
if (clazz === "Set")
|
2514
|
+
return new Set(val);
|
2515
|
+
if (clazz === "Map")
|
2516
|
+
return new Map(Object.entries(val));
|
2517
|
+
if (clazz === "bigint")
|
2518
|
+
return BigInt(val);
|
2519
|
+
if (clazz === "undefined")
|
2520
|
+
return void 0;
|
2521
|
+
return rest;
|
2522
|
+
}
|
2523
|
+
return value;
|
2524
|
+
});
|
2525
|
+
}
|
2526
|
+
}
|
2527
|
+
const defaultSerializer = new Serializer();
|
2528
|
+
const serialize = (data) => {
|
2529
|
+
return defaultSerializer.toJSON(data);
|
2530
|
+
};
|
2531
|
+
const deserialize = (json) => {
|
2532
|
+
return defaultSerializer.fromJSON(json);
|
2533
|
+
};
|
2534
|
+
|
2535
|
+
function buildWorkerRunner(config) {
|
2536
|
+
return function xataWorker(name, _worker) {
|
2537
|
+
return async (...args) => {
|
2538
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2539
|
+
const result = await fetch(url, {
|
2540
|
+
method: "POST",
|
2541
|
+
headers: { "Content-Type": "application/json" },
|
2542
|
+
body: serialize({ args })
|
2543
|
+
});
|
2544
|
+
const text = await result.text();
|
2545
|
+
return deserialize(text);
|
2546
|
+
};
|
2547
|
+
};
|
2548
|
+
}
|
2549
|
+
|
1901
2550
|
class XataError extends Error {
|
1902
2551
|
constructor(message, status) {
|
1903
2552
|
super(message);
|
@@ -1905,5 +2554,5 @@ class XataError extends Error {
|
|
1905
2554
|
}
|
1906
2555
|
}
|
1907
2556
|
|
1908
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, 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, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
2557
|
+
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 };
|
1909
2558
|
//# sourceMappingURL=index.mjs.map
|