@xata.io/client 0.0.0-alpha.vf4b92f1 → 0.0.0-alpha.vf54f8ba
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 +282 -0
- package/README.md +273 -1
- package/Usage.md +451 -0
- package/dist/index.cjs +1537 -598
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3595 -587
- package/dist/index.mjs +1474 -599
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
- 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,43 +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") {
|
118
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
119
|
+
}
|
120
|
+
const { execSync } = await import(nodeModule);
|
121
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
38
122
|
} catch (err) {
|
39
123
|
}
|
40
124
|
try {
|
41
125
|
if (isObject(Deno)) {
|
42
|
-
const process2 = Deno.run({
|
43
|
-
cmd: ["git", "branch", "--show-current"],
|
44
|
-
stdout: "piped",
|
45
|
-
stderr: "piped"
|
46
|
-
});
|
126
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
47
127
|
return new TextDecoder().decode(await process2.output()).trim();
|
48
128
|
}
|
49
129
|
} catch (err) {
|
@@ -52,7 +132,8 @@ async function getGitBranch() {
|
|
52
132
|
|
53
133
|
function getAPIKey() {
|
54
134
|
try {
|
55
|
-
|
135
|
+
const { apiKey } = getEnvironment();
|
136
|
+
return apiKey;
|
56
137
|
} catch (err) {
|
57
138
|
return void 0;
|
58
139
|
}
|
@@ -62,21 +143,35 @@ function getFetchImplementation(userFetch) {
|
|
62
143
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
63
144
|
const fetchImpl = userFetch ?? globalFetch;
|
64
145
|
if (!fetchImpl) {
|
65
|
-
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
|
+
);
|
66
149
|
}
|
67
150
|
return fetchImpl;
|
68
151
|
}
|
69
152
|
|
70
|
-
|
71
|
-
|
153
|
+
const VERSION = "0.0.0-alpha.vf54f8ba";
|
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) {
|
72
162
|
super(getMessage(data));
|
73
163
|
this.status = status;
|
74
164
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
165
|
+
this.requestId = requestId;
|
75
166
|
if (data instanceof Error) {
|
76
167
|
this.stack = data.stack;
|
77
168
|
this.cause = data.cause;
|
78
169
|
}
|
79
170
|
}
|
171
|
+
toString() {
|
172
|
+
const error = super.toString();
|
173
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
174
|
+
}
|
80
175
|
}
|
81
176
|
function isBulkError(error) {
|
82
177
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -99,9 +194,17 @@ function getMessage(data) {
|
|
99
194
|
}
|
100
195
|
|
101
196
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
102
|
-
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();
|
103
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
104
|
-
|
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;
|
105
208
|
};
|
106
209
|
function buildBaseUrl({
|
107
210
|
path,
|
@@ -109,10 +212,10 @@ function buildBaseUrl({
|
|
109
212
|
apiUrl,
|
110
213
|
pathParams
|
111
214
|
}) {
|
112
|
-
if (
|
215
|
+
if (pathParams?.workspace === void 0 || !path.startsWith("/db"))
|
113
216
|
return `${apiUrl}${path}`;
|
114
217
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
115
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
218
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
116
219
|
}
|
117
220
|
function hostHeader(url) {
|
118
221
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -129,237 +232,382 @@ async function fetch$1({
|
|
129
232
|
fetchImpl,
|
130
233
|
apiKey,
|
131
234
|
apiUrl,
|
132
|
-
workspacesApiUrl
|
235
|
+
workspacesApiUrl,
|
236
|
+
trace,
|
237
|
+
signal
|
133
238
|
}) {
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
239
|
+
return trace(
|
240
|
+
`${method.toUpperCase()} ${path}`,
|
241
|
+
async ({ setAttributes }) => {
|
242
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
243
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
244
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
245
|
+
setAttributes({
|
246
|
+
[TraceAttributes.HTTP_URL]: url,
|
247
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
248
|
+
});
|
249
|
+
const response = await fetchImpl(url, {
|
250
|
+
method: method.toUpperCase(),
|
251
|
+
body: body ? JSON.stringify(body) : void 0,
|
252
|
+
headers: {
|
253
|
+
"Content-Type": "application/json",
|
254
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
255
|
+
...headers,
|
256
|
+
...hostHeader(fullUrl),
|
257
|
+
Authorization: `Bearer ${apiKey}`
|
258
|
+
},
|
259
|
+
signal
|
260
|
+
});
|
261
|
+
if (response.status === 204) {
|
262
|
+
return {};
|
263
|
+
}
|
264
|
+
const { host, protocol } = parseUrl(response.url);
|
265
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
266
|
+
setAttributes({
|
267
|
+
[TraceAttributes.KIND]: "http",
|
268
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
269
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
270
|
+
[TraceAttributes.HTTP_HOST]: host,
|
271
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
272
|
+
});
|
273
|
+
try {
|
274
|
+
const jsonResponse = await response.json();
|
275
|
+
if (response.ok) {
|
276
|
+
return jsonResponse;
|
277
|
+
}
|
278
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
279
|
+
} catch (error) {
|
280
|
+
throw new FetcherError(response.status, error, requestId);
|
281
|
+
}
|
282
|
+
},
|
283
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
284
|
+
);
|
285
|
+
}
|
286
|
+
function parseUrl(url) {
|
150
287
|
try {
|
151
|
-
const
|
152
|
-
|
153
|
-
return jsonResponse;
|
154
|
-
}
|
155
|
-
throw new FetcherError(response.status, jsonResponse);
|
288
|
+
const { host, protocol } = new URL(url);
|
289
|
+
return { host, protocol };
|
156
290
|
} catch (error) {
|
157
|
-
|
291
|
+
return {};
|
158
292
|
}
|
159
293
|
}
|
160
294
|
|
161
|
-
const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
|
162
|
-
const updateUser = (variables) => fetch$1({
|
163
|
-
|
164
|
-
|
295
|
+
const getUser = (variables, signal) => fetch$1({ url: "/user", method: "get", ...variables, signal });
|
296
|
+
const updateUser = (variables, signal) => fetch$1({
|
297
|
+
url: "/user",
|
298
|
+
method: "put",
|
299
|
+
...variables,
|
300
|
+
signal
|
301
|
+
});
|
302
|
+
const deleteUser = (variables, signal) => fetch$1({ url: "/user", method: "delete", ...variables, signal });
|
303
|
+
const getUserAPIKeys = (variables, signal) => fetch$1({
|
165
304
|
url: "/user/keys",
|
166
305
|
method: "get",
|
167
|
-
...variables
|
306
|
+
...variables,
|
307
|
+
signal
|
168
308
|
});
|
169
|
-
const createUserAPIKey = (variables) => fetch$1({
|
309
|
+
const createUserAPIKey = (variables, signal) => fetch$1({
|
170
310
|
url: "/user/keys/{keyName}",
|
171
311
|
method: "post",
|
172
|
-
...variables
|
312
|
+
...variables,
|
313
|
+
signal
|
173
314
|
});
|
174
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
315
|
+
const deleteUserAPIKey = (variables, signal) => fetch$1({
|
175
316
|
url: "/user/keys/{keyName}",
|
176
317
|
method: "delete",
|
177
|
-
...variables
|
318
|
+
...variables,
|
319
|
+
signal
|
178
320
|
});
|
179
|
-
const createWorkspace = (variables) => fetch$1({
|
321
|
+
const createWorkspace = (variables, signal) => fetch$1({
|
180
322
|
url: "/workspaces",
|
181
323
|
method: "post",
|
182
|
-
...variables
|
324
|
+
...variables,
|
325
|
+
signal
|
183
326
|
});
|
184
|
-
const getWorkspacesList = (variables) => fetch$1({
|
327
|
+
const getWorkspacesList = (variables, signal) => fetch$1({
|
185
328
|
url: "/workspaces",
|
186
329
|
method: "get",
|
187
|
-
...variables
|
330
|
+
...variables,
|
331
|
+
signal
|
188
332
|
});
|
189
|
-
const getWorkspace = (variables) => fetch$1({
|
333
|
+
const getWorkspace = (variables, signal) => fetch$1({
|
190
334
|
url: "/workspaces/{workspaceId}",
|
191
335
|
method: "get",
|
192
|
-
...variables
|
336
|
+
...variables,
|
337
|
+
signal
|
193
338
|
});
|
194
|
-
const updateWorkspace = (variables) => fetch$1({
|
339
|
+
const updateWorkspace = (variables, signal) => fetch$1({
|
195
340
|
url: "/workspaces/{workspaceId}",
|
196
341
|
method: "put",
|
197
|
-
...variables
|
342
|
+
...variables,
|
343
|
+
signal
|
198
344
|
});
|
199
|
-
const deleteWorkspace = (variables) => fetch$1({
|
345
|
+
const deleteWorkspace = (variables, signal) => fetch$1({
|
200
346
|
url: "/workspaces/{workspaceId}",
|
201
347
|
method: "delete",
|
202
|
-
...variables
|
348
|
+
...variables,
|
349
|
+
signal
|
203
350
|
});
|
204
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
351
|
+
const getWorkspaceMembersList = (variables, signal) => fetch$1({
|
205
352
|
url: "/workspaces/{workspaceId}/members",
|
206
353
|
method: "get",
|
207
|
-
...variables
|
354
|
+
...variables,
|
355
|
+
signal
|
208
356
|
});
|
209
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
210
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
357
|
+
const updateWorkspaceMemberRole = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
358
|
+
const removeWorkspaceMember = (variables, signal) => fetch$1({
|
211
359
|
url: "/workspaces/{workspaceId}/members/{userId}",
|
212
360
|
method: "delete",
|
213
|
-
...variables
|
361
|
+
...variables,
|
362
|
+
signal
|
214
363
|
});
|
215
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
216
|
-
const
|
364
|
+
const inviteWorkspaceMember = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
365
|
+
const updateWorkspaceMemberInvite = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
366
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
217
367
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
218
368
|
method: "delete",
|
219
|
-
...variables
|
369
|
+
...variables,
|
370
|
+
signal
|
220
371
|
});
|
221
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
372
|
+
const resendWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
222
373
|
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
223
374
|
method: "post",
|
224
|
-
...variables
|
375
|
+
...variables,
|
376
|
+
signal
|
225
377
|
});
|
226
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
378
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
227
379
|
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
228
380
|
method: "post",
|
229
|
-
...variables
|
381
|
+
...variables,
|
382
|
+
signal
|
230
383
|
});
|
231
|
-
const getDatabaseList = (variables) => fetch$1({
|
384
|
+
const getDatabaseList = (variables, signal) => fetch$1({
|
232
385
|
url: "/dbs",
|
233
386
|
method: "get",
|
234
|
-
...variables
|
387
|
+
...variables,
|
388
|
+
signal
|
235
389
|
});
|
236
|
-
const getBranchList = (variables) => fetch$1({
|
390
|
+
const getBranchList = (variables, signal) => fetch$1({
|
237
391
|
url: "/dbs/{dbName}",
|
238
392
|
method: "get",
|
239
|
-
...variables
|
393
|
+
...variables,
|
394
|
+
signal
|
240
395
|
});
|
241
|
-
const createDatabase = (variables) => fetch$1({
|
396
|
+
const createDatabase = (variables, signal) => fetch$1({
|
242
397
|
url: "/dbs/{dbName}",
|
243
398
|
method: "put",
|
244
|
-
...variables
|
399
|
+
...variables,
|
400
|
+
signal
|
245
401
|
});
|
246
|
-
const deleteDatabase = (variables) => fetch$1({
|
402
|
+
const deleteDatabase = (variables, signal) => fetch$1({
|
247
403
|
url: "/dbs/{dbName}",
|
248
404
|
method: "delete",
|
249
|
-
...variables
|
405
|
+
...variables,
|
406
|
+
signal
|
250
407
|
});
|
251
|
-
const
|
252
|
-
url: "/
|
408
|
+
const getDatabaseMetadata = (variables, signal) => fetch$1({
|
409
|
+
url: "/dbs/{dbName}/metadata",
|
410
|
+
method: "get",
|
411
|
+
...variables,
|
412
|
+
signal
|
413
|
+
});
|
414
|
+
const updateDatabaseMetadata = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
415
|
+
const getGitBranchesMapping = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
416
|
+
const addGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
417
|
+
const removeGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
418
|
+
const resolveBranch = (variables, signal) => fetch$1({
|
419
|
+
url: "/dbs/{dbName}/resolveBranch",
|
420
|
+
method: "get",
|
421
|
+
...variables,
|
422
|
+
signal
|
423
|
+
});
|
424
|
+
const queryMigrationRequests = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
425
|
+
const createMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
426
|
+
const getMigrationRequest = (variables, signal) => fetch$1({
|
427
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
253
428
|
method: "get",
|
254
|
-
...variables
|
429
|
+
...variables,
|
430
|
+
signal
|
431
|
+
});
|
432
|
+
const updateMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
433
|
+
const listMigrationRequestsCommits = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
434
|
+
const compareMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
435
|
+
const getMigrationRequestIsMerged = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
436
|
+
const mergeMigrationRequest = (variables, signal) => fetch$1({
|
437
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
438
|
+
method: "post",
|
439
|
+
...variables,
|
440
|
+
signal
|
255
441
|
});
|
256
|
-
const
|
442
|
+
const getBranchDetails = (variables, signal) => fetch$1({
|
257
443
|
url: "/db/{dbBranchName}",
|
258
|
-
method: "
|
259
|
-
...variables
|
444
|
+
method: "get",
|
445
|
+
...variables,
|
446
|
+
signal
|
260
447
|
});
|
261
|
-
const
|
448
|
+
const createBranch = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
449
|
+
const deleteBranch = (variables, signal) => fetch$1({
|
262
450
|
url: "/db/{dbBranchName}",
|
263
451
|
method: "delete",
|
264
|
-
...variables
|
452
|
+
...variables,
|
453
|
+
signal
|
265
454
|
});
|
266
|
-
const updateBranchMetadata = (variables) => fetch$1({
|
455
|
+
const updateBranchMetadata = (variables, signal) => fetch$1({
|
267
456
|
url: "/db/{dbBranchName}/metadata",
|
268
457
|
method: "put",
|
269
|
-
...variables
|
458
|
+
...variables,
|
459
|
+
signal
|
270
460
|
});
|
271
|
-
const getBranchMetadata = (variables) => fetch$1({
|
461
|
+
const getBranchMetadata = (variables, signal) => fetch$1({
|
272
462
|
url: "/db/{dbBranchName}/metadata",
|
273
463
|
method: "get",
|
274
|
-
...variables
|
464
|
+
...variables,
|
465
|
+
signal
|
466
|
+
});
|
467
|
+
const getBranchMigrationHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
468
|
+
const executeBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
469
|
+
const getBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
470
|
+
const compareBranchWithUserSchema = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
471
|
+
const compareBranchSchemas = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
472
|
+
const updateBranchSchema = (variables, signal) => fetch$1({
|
473
|
+
url: "/db/{dbBranchName}/schema/update",
|
474
|
+
method: "post",
|
475
|
+
...variables,
|
476
|
+
signal
|
275
477
|
});
|
276
|
-
const
|
277
|
-
const
|
278
|
-
const
|
279
|
-
const getBranchStats = (variables) => fetch$1({
|
478
|
+
const previewBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
479
|
+
const applyBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
480
|
+
const getBranchSchemaHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
481
|
+
const getBranchStats = (variables, signal) => fetch$1({
|
280
482
|
url: "/db/{dbBranchName}/stats",
|
281
483
|
method: "get",
|
282
|
-
...variables
|
484
|
+
...variables,
|
485
|
+
signal
|
283
486
|
});
|
284
|
-
const createTable = (variables) => fetch$1({
|
487
|
+
const createTable = (variables, signal) => fetch$1({
|
285
488
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
286
489
|
method: "put",
|
287
|
-
...variables
|
490
|
+
...variables,
|
491
|
+
signal
|
288
492
|
});
|
289
|
-
const deleteTable = (variables) => fetch$1({
|
493
|
+
const deleteTable = (variables, signal) => fetch$1({
|
290
494
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
291
495
|
method: "delete",
|
292
|
-
...variables
|
496
|
+
...variables,
|
497
|
+
signal
|
293
498
|
});
|
294
|
-
const updateTable = (variables) => fetch$1({
|
499
|
+
const updateTable = (variables, signal) => fetch$1({
|
295
500
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
296
501
|
method: "patch",
|
297
|
-
...variables
|
502
|
+
...variables,
|
503
|
+
signal
|
298
504
|
});
|
299
|
-
const getTableSchema = (variables) => fetch$1({
|
505
|
+
const getTableSchema = (variables, signal) => fetch$1({
|
300
506
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
301
507
|
method: "get",
|
302
|
-
...variables
|
508
|
+
...variables,
|
509
|
+
signal
|
303
510
|
});
|
304
|
-
const setTableSchema = (variables) => fetch$1({
|
511
|
+
const setTableSchema = (variables, signal) => fetch$1({
|
305
512
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
306
513
|
method: "put",
|
307
|
-
...variables
|
514
|
+
...variables,
|
515
|
+
signal
|
308
516
|
});
|
309
|
-
const getTableColumns = (variables) => fetch$1({
|
517
|
+
const getTableColumns = (variables, signal) => fetch$1({
|
310
518
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
311
519
|
method: "get",
|
312
|
-
...variables
|
520
|
+
...variables,
|
521
|
+
signal
|
313
522
|
});
|
314
|
-
const addTableColumn = (variables) => fetch$1({
|
523
|
+
const addTableColumn = (variables, signal) => fetch$1({
|
315
524
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
316
525
|
method: "post",
|
317
|
-
...variables
|
526
|
+
...variables,
|
527
|
+
signal
|
318
528
|
});
|
319
|
-
const getColumn = (variables) => fetch$1({
|
529
|
+
const getColumn = (variables, signal) => fetch$1({
|
320
530
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
321
531
|
method: "get",
|
322
|
-
...variables
|
532
|
+
...variables,
|
533
|
+
signal
|
323
534
|
});
|
324
|
-
const deleteColumn = (variables) => fetch$1({
|
535
|
+
const deleteColumn = (variables, signal) => fetch$1({
|
325
536
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
326
537
|
method: "delete",
|
327
|
-
...variables
|
538
|
+
...variables,
|
539
|
+
signal
|
328
540
|
});
|
329
|
-
const updateColumn = (variables) => fetch$1({
|
541
|
+
const updateColumn = (variables, signal) => fetch$1({
|
330
542
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
331
543
|
method: "patch",
|
332
|
-
...variables
|
544
|
+
...variables,
|
545
|
+
signal
|
333
546
|
});
|
334
|
-
const insertRecord = (variables) => fetch$1({
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
340
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
341
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
342
|
-
const deleteRecord = (variables) => fetch$1({
|
547
|
+
const insertRecord = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
548
|
+
const insertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
549
|
+
const updateRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
550
|
+
const upsertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
551
|
+
const deleteRecord = (variables, signal) => fetch$1({
|
343
552
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
344
553
|
method: "delete",
|
345
|
-
...variables
|
554
|
+
...variables,
|
555
|
+
signal
|
346
556
|
});
|
347
|
-
const getRecord = (variables) => fetch$1({
|
557
|
+
const getRecord = (variables, signal) => fetch$1({
|
348
558
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
349
559
|
method: "get",
|
350
|
-
...variables
|
560
|
+
...variables,
|
561
|
+
signal
|
351
562
|
});
|
352
|
-
const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
|
353
|
-
const queryTable = (variables) => fetch$1({
|
563
|
+
const bulkInsertTableRecords = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
564
|
+
const queryTable = (variables, signal) => fetch$1({
|
354
565
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
355
566
|
method: "post",
|
356
|
-
...variables
|
567
|
+
...variables,
|
568
|
+
signal
|
569
|
+
});
|
570
|
+
const searchTable = (variables, signal) => fetch$1({
|
571
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
572
|
+
method: "post",
|
573
|
+
...variables,
|
574
|
+
signal
|
357
575
|
});
|
358
|
-
const searchBranch = (variables) => fetch$1({
|
576
|
+
const searchBranch = (variables, signal) => fetch$1({
|
359
577
|
url: "/db/{dbBranchName}/search",
|
360
578
|
method: "post",
|
361
|
-
...variables
|
579
|
+
...variables,
|
580
|
+
signal
|
581
|
+
});
|
582
|
+
const summarizeTable = (variables, signal) => fetch$1({
|
583
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
584
|
+
method: "post",
|
585
|
+
...variables,
|
586
|
+
signal
|
587
|
+
});
|
588
|
+
const aggregateTable = (variables, signal) => fetch$1({
|
589
|
+
url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
|
590
|
+
method: "post",
|
591
|
+
...variables,
|
592
|
+
signal
|
593
|
+
});
|
594
|
+
const cPGetDatabaseList = (variables, signal) => fetch$1({
|
595
|
+
url: "/workspaces/{workspaceId}/dbs",
|
596
|
+
method: "get",
|
597
|
+
...variables,
|
598
|
+
signal
|
362
599
|
});
|
600
|
+
const cPCreateDatabase = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
601
|
+
const cPDeleteDatabase = (variables, signal) => fetch$1({
|
602
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
603
|
+
method: "delete",
|
604
|
+
...variables,
|
605
|
+
signal
|
606
|
+
});
|
607
|
+
const cPGetCPDatabaseMetadata = (variables, signal) => fetch$1(
|
608
|
+
{ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "get", ...variables, signal }
|
609
|
+
);
|
610
|
+
const cPUpdateCPDatabaseMetadata = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
363
611
|
const operationsByTag = {
|
364
612
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
365
613
|
workspaces: {
|
@@ -372,11 +620,22 @@ const operationsByTag = {
|
|
372
620
|
updateWorkspaceMemberRole,
|
373
621
|
removeWorkspaceMember,
|
374
622
|
inviteWorkspaceMember,
|
623
|
+
updateWorkspaceMemberInvite,
|
375
624
|
cancelWorkspaceMemberInvite,
|
376
625
|
resendWorkspaceMemberInvite,
|
377
626
|
acceptWorkspaceMemberInvite
|
378
627
|
},
|
379
|
-
database: {
|
628
|
+
database: {
|
629
|
+
getDatabaseList,
|
630
|
+
createDatabase,
|
631
|
+
deleteDatabase,
|
632
|
+
getDatabaseMetadata,
|
633
|
+
updateDatabaseMetadata,
|
634
|
+
getGitBranchesMapping,
|
635
|
+
addGitBranchesEntry,
|
636
|
+
removeGitBranchesEntry,
|
637
|
+
resolveBranch
|
638
|
+
},
|
380
639
|
branch: {
|
381
640
|
getBranchList,
|
382
641
|
getBranchDetails,
|
@@ -384,10 +643,28 @@ const operationsByTag = {
|
|
384
643
|
deleteBranch,
|
385
644
|
updateBranchMetadata,
|
386
645
|
getBranchMetadata,
|
646
|
+
getBranchStats
|
647
|
+
},
|
648
|
+
migrationRequests: {
|
649
|
+
queryMigrationRequests,
|
650
|
+
createMigrationRequest,
|
651
|
+
getMigrationRequest,
|
652
|
+
updateMigrationRequest,
|
653
|
+
listMigrationRequestsCommits,
|
654
|
+
compareMigrationRequest,
|
655
|
+
getMigrationRequestIsMerged,
|
656
|
+
mergeMigrationRequest
|
657
|
+
},
|
658
|
+
branchSchema: {
|
387
659
|
getBranchMigrationHistory,
|
388
660
|
executeBranchMigrationPlan,
|
389
661
|
getBranchMigrationPlan,
|
390
|
-
|
662
|
+
compareBranchWithUserSchema,
|
663
|
+
compareBranchSchemas,
|
664
|
+
updateBranchSchema,
|
665
|
+
previewBranchSchemaEdit,
|
666
|
+
applyBranchSchemaEdit,
|
667
|
+
getBranchSchemaHistory
|
391
668
|
},
|
392
669
|
table: {
|
393
670
|
createTable,
|
@@ -410,14 +687,24 @@ const operationsByTag = {
|
|
410
687
|
getRecord,
|
411
688
|
bulkInsertTableRecords,
|
412
689
|
queryTable,
|
413
|
-
|
690
|
+
searchTable,
|
691
|
+
searchBranch,
|
692
|
+
summarizeTable,
|
693
|
+
aggregateTable
|
694
|
+
},
|
695
|
+
databases: {
|
696
|
+
cPGetDatabaseList,
|
697
|
+
cPCreateDatabase,
|
698
|
+
cPDeleteDatabase,
|
699
|
+
cPGetCPDatabaseMetadata,
|
700
|
+
cPUpdateCPDatabaseMetadata
|
414
701
|
}
|
415
702
|
};
|
416
703
|
|
417
704
|
function getHostUrl(provider, type) {
|
418
|
-
if (
|
705
|
+
if (isHostProviderAlias(provider)) {
|
419
706
|
return providers[provider][type];
|
420
|
-
} else if (
|
707
|
+
} else if (isHostProviderBuilder(provider)) {
|
421
708
|
return provider[type];
|
422
709
|
}
|
423
710
|
throw new Error("Invalid API provider");
|
@@ -432,18 +719,27 @@ const providers = {
|
|
432
719
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
433
720
|
}
|
434
721
|
};
|
435
|
-
function
|
722
|
+
function isHostProviderAlias(alias) {
|
436
723
|
return isString(alias) && Object.keys(providers).includes(alias);
|
437
724
|
}
|
438
|
-
function
|
725
|
+
function isHostProviderBuilder(builder) {
|
439
726
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
440
727
|
}
|
728
|
+
function parseProviderString(provider = "production") {
|
729
|
+
if (isHostProviderAlias(provider)) {
|
730
|
+
return provider;
|
731
|
+
}
|
732
|
+
const [main, workspaces] = provider.split(",");
|
733
|
+
if (!main || !workspaces)
|
734
|
+
return null;
|
735
|
+
return { main, workspaces };
|
736
|
+
}
|
441
737
|
|
442
738
|
var __accessCheck$7 = (obj, member, msg) => {
|
443
739
|
if (!member.has(obj))
|
444
740
|
throw TypeError("Cannot " + msg);
|
445
741
|
};
|
446
|
-
var __privateGet$
|
742
|
+
var __privateGet$7 = (obj, member, getter) => {
|
447
743
|
__accessCheck$7(obj, member, "read from private field");
|
448
744
|
return getter ? getter.call(obj) : member.get(obj);
|
449
745
|
};
|
@@ -452,7 +748,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
452
748
|
throw TypeError("Cannot add the same private member more than once");
|
453
749
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
454
750
|
};
|
455
|
-
var __privateSet$
|
751
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
456
752
|
__accessCheck$7(obj, member, "write to private field");
|
457
753
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
458
754
|
return value;
|
@@ -463,46 +759,58 @@ class XataApiClient {
|
|
463
759
|
__privateAdd$7(this, _extraProps, void 0);
|
464
760
|
__privateAdd$7(this, _namespaces, {});
|
465
761
|
const provider = options.host ?? "production";
|
466
|
-
const apiKey = options
|
762
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
763
|
+
const trace = options.trace ?? defaultTrace;
|
467
764
|
if (!apiKey) {
|
468
765
|
throw new Error("Could not resolve a valid apiKey");
|
469
766
|
}
|
470
|
-
__privateSet$
|
767
|
+
__privateSet$7(this, _extraProps, {
|
471
768
|
apiUrl: getHostUrl(provider, "main"),
|
472
769
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
473
770
|
fetchImpl: getFetchImplementation(options.fetch),
|
474
|
-
apiKey
|
771
|
+
apiKey,
|
772
|
+
trace
|
475
773
|
});
|
476
774
|
}
|
477
775
|
get user() {
|
478
|
-
if (!__privateGet$
|
479
|
-
__privateGet$
|
480
|
-
return __privateGet$
|
776
|
+
if (!__privateGet$7(this, _namespaces).user)
|
777
|
+
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
778
|
+
return __privateGet$7(this, _namespaces).user;
|
481
779
|
}
|
482
780
|
get workspaces() {
|
483
|
-
if (!__privateGet$
|
484
|
-
__privateGet$
|
485
|
-
return __privateGet$
|
781
|
+
if (!__privateGet$7(this, _namespaces).workspaces)
|
782
|
+
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
783
|
+
return __privateGet$7(this, _namespaces).workspaces;
|
486
784
|
}
|
487
785
|
get databases() {
|
488
|
-
if (!__privateGet$
|
489
|
-
__privateGet$
|
490
|
-
return __privateGet$
|
786
|
+
if (!__privateGet$7(this, _namespaces).databases)
|
787
|
+
__privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
|
788
|
+
return __privateGet$7(this, _namespaces).databases;
|
491
789
|
}
|
492
790
|
get branches() {
|
493
|
-
if (!__privateGet$
|
494
|
-
__privateGet$
|
495
|
-
return __privateGet$
|
791
|
+
if (!__privateGet$7(this, _namespaces).branches)
|
792
|
+
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
793
|
+
return __privateGet$7(this, _namespaces).branches;
|
496
794
|
}
|
497
795
|
get tables() {
|
498
|
-
if (!__privateGet$
|
499
|
-
__privateGet$
|
500
|
-
return __privateGet$
|
796
|
+
if (!__privateGet$7(this, _namespaces).tables)
|
797
|
+
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
798
|
+
return __privateGet$7(this, _namespaces).tables;
|
501
799
|
}
|
502
800
|
get records() {
|
503
|
-
if (!__privateGet$
|
504
|
-
__privateGet$
|
505
|
-
return __privateGet$
|
801
|
+
if (!__privateGet$7(this, _namespaces).records)
|
802
|
+
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
803
|
+
return __privateGet$7(this, _namespaces).records;
|
804
|
+
}
|
805
|
+
get migrationRequests() {
|
806
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
807
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
808
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
809
|
+
}
|
810
|
+
get branchSchema() {
|
811
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
812
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
813
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
506
814
|
}
|
507
815
|
}
|
508
816
|
_extraProps = new WeakMap();
|
@@ -594,6 +902,13 @@ class WorkspaceApi {
|
|
594
902
|
...this.extraProps
|
595
903
|
});
|
596
904
|
}
|
905
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
906
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
907
|
+
pathParams: { workspaceId, inviteId },
|
908
|
+
body: { role },
|
909
|
+
...this.extraProps
|
910
|
+
});
|
911
|
+
}
|
597
912
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
598
913
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
599
914
|
pathParams: { workspaceId, inviteId },
|
@@ -636,6 +951,46 @@ class DatabaseApi {
|
|
636
951
|
...this.extraProps
|
637
952
|
});
|
638
953
|
}
|
954
|
+
getDatabaseMetadata(workspace, dbName) {
|
955
|
+
return operationsByTag.database.getDatabaseMetadata({
|
956
|
+
pathParams: { workspace, dbName },
|
957
|
+
...this.extraProps
|
958
|
+
});
|
959
|
+
}
|
960
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
961
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
962
|
+
pathParams: { workspace, dbName },
|
963
|
+
body: options,
|
964
|
+
...this.extraProps
|
965
|
+
});
|
966
|
+
}
|
967
|
+
getGitBranchesMapping(workspace, dbName) {
|
968
|
+
return operationsByTag.database.getGitBranchesMapping({
|
969
|
+
pathParams: { workspace, dbName },
|
970
|
+
...this.extraProps
|
971
|
+
});
|
972
|
+
}
|
973
|
+
addGitBranchesEntry(workspace, dbName, body) {
|
974
|
+
return operationsByTag.database.addGitBranchesEntry({
|
975
|
+
pathParams: { workspace, dbName },
|
976
|
+
body,
|
977
|
+
...this.extraProps
|
978
|
+
});
|
979
|
+
}
|
980
|
+
removeGitBranchesEntry(workspace, dbName, gitBranch) {
|
981
|
+
return operationsByTag.database.removeGitBranchesEntry({
|
982
|
+
pathParams: { workspace, dbName },
|
983
|
+
queryParams: { gitBranch },
|
984
|
+
...this.extraProps
|
985
|
+
});
|
986
|
+
}
|
987
|
+
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
988
|
+
return operationsByTag.database.resolveBranch({
|
989
|
+
pathParams: { workspace, dbName },
|
990
|
+
queryParams: { gitBranch, fallbackBranch },
|
991
|
+
...this.extraProps
|
992
|
+
});
|
993
|
+
}
|
639
994
|
}
|
640
995
|
class BranchApi {
|
641
996
|
constructor(extraProps) {
|
@@ -653,10 +1008,10 @@ class BranchApi {
|
|
653
1008
|
...this.extraProps
|
654
1009
|
});
|
655
1010
|
}
|
656
|
-
createBranch(workspace, database, branch, from
|
1011
|
+
createBranch(workspace, database, branch, from, options = {}) {
|
657
1012
|
return operationsByTag.branch.createBranch({
|
658
1013
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
659
|
-
queryParams: { from },
|
1014
|
+
queryParams: isString(from) ? { from } : void 0,
|
660
1015
|
body: options,
|
661
1016
|
...this.extraProps
|
662
1017
|
});
|
@@ -680,27 +1035,6 @@ class BranchApi {
|
|
680
1035
|
...this.extraProps
|
681
1036
|
});
|
682
1037
|
}
|
683
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
684
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
685
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
686
|
-
body: options,
|
687
|
-
...this.extraProps
|
688
|
-
});
|
689
|
-
}
|
690
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
691
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
692
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
693
|
-
body: migrationPlan,
|
694
|
-
...this.extraProps
|
695
|
-
});
|
696
|
-
}
|
697
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
698
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
699
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
700
|
-
body: schema,
|
701
|
-
...this.extraProps
|
702
|
-
});
|
703
|
-
}
|
704
1038
|
getBranchStats(workspace, database, branch) {
|
705
1039
|
return operationsByTag.branch.getBranchStats({
|
706
1040
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -781,9 +1115,10 @@ class RecordsApi {
|
|
781
1115
|
constructor(extraProps) {
|
782
1116
|
this.extraProps = extraProps;
|
783
1117
|
}
|
784
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1118
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
785
1119
|
return operationsByTag.records.insertRecord({
|
786
1120
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1121
|
+
queryParams: options,
|
787
1122
|
body: record,
|
788
1123
|
...this.extraProps
|
789
1124
|
});
|
@@ -812,21 +1147,24 @@ class RecordsApi {
|
|
812
1147
|
...this.extraProps
|
813
1148
|
});
|
814
1149
|
}
|
815
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1150
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
816
1151
|
return operationsByTag.records.deleteRecord({
|
817
1152
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1153
|
+
queryParams: options,
|
818
1154
|
...this.extraProps
|
819
1155
|
});
|
820
1156
|
}
|
821
1157
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
822
1158
|
return operationsByTag.records.getRecord({
|
823
1159
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1160
|
+
queryParams: options,
|
824
1161
|
...this.extraProps
|
825
1162
|
});
|
826
1163
|
}
|
827
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1164
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
828
1165
|
return operationsByTag.records.bulkInsertTableRecords({
|
829
1166
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1167
|
+
queryParams: options,
|
830
1168
|
body: { records },
|
831
1169
|
...this.extraProps
|
832
1170
|
});
|
@@ -838,6 +1176,13 @@ class RecordsApi {
|
|
838
1176
|
...this.extraProps
|
839
1177
|
});
|
840
1178
|
}
|
1179
|
+
searchTable(workspace, database, branch, tableName, query) {
|
1180
|
+
return operationsByTag.records.searchTable({
|
1181
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1182
|
+
body: query,
|
1183
|
+
...this.extraProps
|
1184
|
+
});
|
1185
|
+
}
|
841
1186
|
searchBranch(workspace, database, branch, query) {
|
842
1187
|
return operationsByTag.records.searchBranch({
|
843
1188
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -845,6 +1190,138 @@ class RecordsApi {
|
|
845
1190
|
...this.extraProps
|
846
1191
|
});
|
847
1192
|
}
|
1193
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1194
|
+
return operationsByTag.records.summarizeTable({
|
1195
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1196
|
+
body: query,
|
1197
|
+
...this.extraProps
|
1198
|
+
});
|
1199
|
+
}
|
1200
|
+
}
|
1201
|
+
class MigrationRequestsApi {
|
1202
|
+
constructor(extraProps) {
|
1203
|
+
this.extraProps = extraProps;
|
1204
|
+
}
|
1205
|
+
queryMigrationRequests(workspace, database, options = {}) {
|
1206
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1207
|
+
pathParams: { workspace, dbName: database },
|
1208
|
+
body: options,
|
1209
|
+
...this.extraProps
|
1210
|
+
});
|
1211
|
+
}
|
1212
|
+
createMigrationRequest(workspace, database, options) {
|
1213
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1214
|
+
pathParams: { workspace, dbName: database },
|
1215
|
+
body: options,
|
1216
|
+
...this.extraProps
|
1217
|
+
});
|
1218
|
+
}
|
1219
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1220
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1221
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1222
|
+
...this.extraProps
|
1223
|
+
});
|
1224
|
+
}
|
1225
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1226
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1227
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1228
|
+
body: options,
|
1229
|
+
...this.extraProps
|
1230
|
+
});
|
1231
|
+
}
|
1232
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1233
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1234
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1235
|
+
body: options,
|
1236
|
+
...this.extraProps
|
1237
|
+
});
|
1238
|
+
}
|
1239
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1240
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1241
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1242
|
+
...this.extraProps
|
1243
|
+
});
|
1244
|
+
}
|
1245
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1246
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1247
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1248
|
+
...this.extraProps
|
1249
|
+
});
|
1250
|
+
}
|
1251
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1252
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1253
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1254
|
+
...this.extraProps
|
1255
|
+
});
|
1256
|
+
}
|
1257
|
+
}
|
1258
|
+
class BranchSchemaApi {
|
1259
|
+
constructor(extraProps) {
|
1260
|
+
this.extraProps = extraProps;
|
1261
|
+
}
|
1262
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1263
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1264
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1265
|
+
body: options,
|
1266
|
+
...this.extraProps
|
1267
|
+
});
|
1268
|
+
}
|
1269
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1270
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1271
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1272
|
+
body: migrationPlan,
|
1273
|
+
...this.extraProps
|
1274
|
+
});
|
1275
|
+
}
|
1276
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1277
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1278
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1279
|
+
body: schema,
|
1280
|
+
...this.extraProps
|
1281
|
+
});
|
1282
|
+
}
|
1283
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1284
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1285
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1286
|
+
body: { schema },
|
1287
|
+
...this.extraProps
|
1288
|
+
});
|
1289
|
+
}
|
1290
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1291
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1292
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1293
|
+
body: { schema },
|
1294
|
+
...this.extraProps
|
1295
|
+
});
|
1296
|
+
}
|
1297
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1298
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1299
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1300
|
+
body: migration,
|
1301
|
+
...this.extraProps
|
1302
|
+
});
|
1303
|
+
}
|
1304
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1305
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1306
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1307
|
+
body: migration,
|
1308
|
+
...this.extraProps
|
1309
|
+
});
|
1310
|
+
}
|
1311
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1312
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1313
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1314
|
+
body: { edits },
|
1315
|
+
...this.extraProps
|
1316
|
+
});
|
1317
|
+
}
|
1318
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1319
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1320
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1321
|
+
body: options,
|
1322
|
+
...this.extraProps
|
1323
|
+
});
|
1324
|
+
}
|
848
1325
|
}
|
849
1326
|
|
850
1327
|
class XataApiPlugin {
|
@@ -861,7 +1338,7 @@ var __accessCheck$6 = (obj, member, msg) => {
|
|
861
1338
|
if (!member.has(obj))
|
862
1339
|
throw TypeError("Cannot " + msg);
|
863
1340
|
};
|
864
|
-
var __privateGet$
|
1341
|
+
var __privateGet$6 = (obj, member, getter) => {
|
865
1342
|
__accessCheck$6(obj, member, "read from private field");
|
866
1343
|
return getter ? getter.call(obj) : member.get(obj);
|
867
1344
|
};
|
@@ -870,30 +1347,30 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
870
1347
|
throw TypeError("Cannot add the same private member more than once");
|
871
1348
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
872
1349
|
};
|
873
|
-
var __privateSet$
|
1350
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
874
1351
|
__accessCheck$6(obj, member, "write to private field");
|
875
1352
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
876
1353
|
return value;
|
877
1354
|
};
|
878
|
-
var _query;
|
1355
|
+
var _query, _page;
|
879
1356
|
class Page {
|
880
1357
|
constructor(query, meta, records = []) {
|
881
1358
|
__privateAdd$6(this, _query, void 0);
|
882
|
-
__privateSet$
|
1359
|
+
__privateSet$6(this, _query, query);
|
883
1360
|
this.meta = meta;
|
884
|
-
this.records = records;
|
1361
|
+
this.records = new RecordArray(this, records);
|
885
1362
|
}
|
886
1363
|
async nextPage(size, offset) {
|
887
|
-
return __privateGet$
|
1364
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
888
1365
|
}
|
889
1366
|
async previousPage(size, offset) {
|
890
|
-
return __privateGet$
|
1367
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
891
1368
|
}
|
892
1369
|
async firstPage(size, offset) {
|
893
|
-
return __privateGet$
|
1370
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
|
894
1371
|
}
|
895
1372
|
async lastPage(size, offset) {
|
896
|
-
return __privateGet$
|
1373
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
|
897
1374
|
}
|
898
1375
|
hasNextPage() {
|
899
1376
|
return this.meta.page.more;
|
@@ -901,15 +1378,62 @@ class Page {
|
|
901
1378
|
}
|
902
1379
|
_query = new WeakMap();
|
903
1380
|
const PAGINATION_MAX_SIZE = 200;
|
904
|
-
const PAGINATION_DEFAULT_SIZE =
|
1381
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
905
1382
|
const PAGINATION_MAX_OFFSET = 800;
|
906
1383
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1384
|
+
function isCursorPaginationOptions(options) {
|
1385
|
+
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
1386
|
+
}
|
1387
|
+
const _RecordArray = class extends Array {
|
1388
|
+
constructor(...args) {
|
1389
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
1390
|
+
__privateAdd$6(this, _page, void 0);
|
1391
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1392
|
+
}
|
1393
|
+
static parseConstructorParams(...args) {
|
1394
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1395
|
+
return new Array(args[0]);
|
1396
|
+
}
|
1397
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
1398
|
+
const result = args[1] ?? args[0].records ?? [];
|
1399
|
+
return new Array(...result);
|
1400
|
+
}
|
1401
|
+
return new Array(...args);
|
1402
|
+
}
|
1403
|
+
toArray() {
|
1404
|
+
return new Array(...this);
|
1405
|
+
}
|
1406
|
+
map(callbackfn, thisArg) {
|
1407
|
+
return this.toArray().map(callbackfn, thisArg);
|
1408
|
+
}
|
1409
|
+
async nextPage(size, offset) {
|
1410
|
+
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1411
|
+
return new _RecordArray(newPage);
|
1412
|
+
}
|
1413
|
+
async previousPage(size, offset) {
|
1414
|
+
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1415
|
+
return new _RecordArray(newPage);
|
1416
|
+
}
|
1417
|
+
async firstPage(size, offset) {
|
1418
|
+
const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
|
1419
|
+
return new _RecordArray(newPage);
|
1420
|
+
}
|
1421
|
+
async lastPage(size, offset) {
|
1422
|
+
const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
|
1423
|
+
return new _RecordArray(newPage);
|
1424
|
+
}
|
1425
|
+
hasNextPage() {
|
1426
|
+
return __privateGet$6(this, _page).meta.page.more;
|
1427
|
+
}
|
1428
|
+
};
|
1429
|
+
let RecordArray = _RecordArray;
|
1430
|
+
_page = new WeakMap();
|
907
1431
|
|
908
1432
|
var __accessCheck$5 = (obj, member, msg) => {
|
909
1433
|
if (!member.has(obj))
|
910
1434
|
throw TypeError("Cannot " + msg);
|
911
1435
|
};
|
912
|
-
var __privateGet$
|
1436
|
+
var __privateGet$5 = (obj, member, getter) => {
|
913
1437
|
__accessCheck$5(obj, member, "read from private field");
|
914
1438
|
return getter ? getter.call(obj) : member.get(obj);
|
915
1439
|
};
|
@@ -918,34 +1442,40 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
918
1442
|
throw TypeError("Cannot add the same private member more than once");
|
919
1443
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
920
1444
|
};
|
921
|
-
var __privateSet$
|
1445
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
922
1446
|
__accessCheck$5(obj, member, "write to private field");
|
923
1447
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
924
1448
|
return value;
|
925
1449
|
};
|
926
|
-
var
|
1450
|
+
var __privateMethod$3 = (obj, member, method) => {
|
1451
|
+
__accessCheck$5(obj, member, "access private method");
|
1452
|
+
return method;
|
1453
|
+
};
|
1454
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
927
1455
|
const _Query = class {
|
928
|
-
constructor(repository, table, data,
|
1456
|
+
constructor(repository, table, data, rawParent) {
|
1457
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
929
1458
|
__privateAdd$5(this, _table$1, void 0);
|
930
1459
|
__privateAdd$5(this, _repository, void 0);
|
931
1460
|
__privateAdd$5(this, _data, { filter: {} });
|
932
1461
|
this.meta = { page: { cursor: "start", more: true } };
|
933
|
-
this.records = [];
|
934
|
-
__privateSet$
|
1462
|
+
this.records = new RecordArray(this, []);
|
1463
|
+
__privateSet$5(this, _table$1, table);
|
935
1464
|
if (repository) {
|
936
|
-
__privateSet$
|
1465
|
+
__privateSet$5(this, _repository, repository);
|
937
1466
|
} else {
|
938
|
-
__privateSet$
|
1467
|
+
__privateSet$5(this, _repository, this);
|
939
1468
|
}
|
940
|
-
|
941
|
-
__privateGet$
|
942
|
-
__privateGet$
|
943
|
-
__privateGet$
|
944
|
-
__privateGet$
|
945
|
-
__privateGet$
|
946
|
-
__privateGet$
|
947
|
-
__privateGet$
|
948
|
-
__privateGet$
|
1469
|
+
const parent = cleanParent(data, rawParent);
|
1470
|
+
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
1471
|
+
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
1472
|
+
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
1473
|
+
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1474
|
+
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1475
|
+
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1476
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
|
1477
|
+
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1478
|
+
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
949
1479
|
this.any = this.any.bind(this);
|
950
1480
|
this.all = this.all.bind(this);
|
951
1481
|
this.not = this.not.bind(this);
|
@@ -956,83 +1486,111 @@ const _Query = class {
|
|
956
1486
|
Object.defineProperty(this, "repository", { enumerable: false });
|
957
1487
|
}
|
958
1488
|
getQueryOptions() {
|
959
|
-
return __privateGet$
|
1489
|
+
return __privateGet$5(this, _data);
|
960
1490
|
}
|
961
1491
|
key() {
|
962
|
-
const { columns = [], filter = {}, sort = [],
|
963
|
-
const key = JSON.stringify({ columns, filter, sort,
|
1492
|
+
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
|
1493
|
+
const key = JSON.stringify({ columns, filter, sort, pagination });
|
964
1494
|
return toBase64(key);
|
965
1495
|
}
|
966
1496
|
any(...queries) {
|
967
1497
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
968
|
-
return new _Query(__privateGet$
|
1498
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
969
1499
|
}
|
970
1500
|
all(...queries) {
|
971
1501
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
972
|
-
return new _Query(__privateGet$
|
1502
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
973
1503
|
}
|
974
1504
|
not(...queries) {
|
975
1505
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
976
|
-
return new _Query(__privateGet$
|
1506
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
977
1507
|
}
|
978
1508
|
none(...queries) {
|
979
1509
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
980
|
-
return new _Query(__privateGet$
|
1510
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
981
1511
|
}
|
982
1512
|
filter(a, b) {
|
983
1513
|
if (arguments.length === 1) {
|
984
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
985
|
-
|
986
|
-
|
1514
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1515
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1516
|
+
}));
|
1517
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1518
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
987
1519
|
} else {
|
988
|
-
const
|
989
|
-
|
1520
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1521
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1522
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
990
1523
|
}
|
991
1524
|
}
|
992
|
-
sort(column, direction) {
|
993
|
-
const originalSort = [__privateGet$
|
1525
|
+
sort(column, direction = "asc") {
|
1526
|
+
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
994
1527
|
const sort = [...originalSort, { column, direction }];
|
995
|
-
return new _Query(__privateGet$
|
1528
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
996
1529
|
}
|
997
1530
|
select(columns) {
|
998
|
-
return new _Query(
|
1531
|
+
return new _Query(
|
1532
|
+
__privateGet$5(this, _repository),
|
1533
|
+
__privateGet$5(this, _table$1),
|
1534
|
+
{ columns },
|
1535
|
+
__privateGet$5(this, _data)
|
1536
|
+
);
|
999
1537
|
}
|
1000
1538
|
getPaginated(options = {}) {
|
1001
|
-
const query = new _Query(__privateGet$
|
1002
|
-
return __privateGet$
|
1539
|
+
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1540
|
+
return __privateGet$5(this, _repository).query(query);
|
1003
1541
|
}
|
1004
1542
|
async *[Symbol.asyncIterator]() {
|
1005
|
-
for await (const [record] of this.getIterator(1)) {
|
1543
|
+
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1006
1544
|
yield record;
|
1007
1545
|
}
|
1008
1546
|
}
|
1009
|
-
async *getIterator(
|
1010
|
-
|
1011
|
-
let
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1547
|
+
async *getIterator(options = {}) {
|
1548
|
+
const { batchSize = 1 } = options;
|
1549
|
+
let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
|
1550
|
+
let more = page.hasNextPage();
|
1551
|
+
yield page.records;
|
1552
|
+
while (more) {
|
1553
|
+
page = await page.nextPage();
|
1554
|
+
more = page.hasNextPage();
|
1555
|
+
yield page.records;
|
1017
1556
|
}
|
1018
1557
|
}
|
1019
1558
|
async getMany(options = {}) {
|
1020
|
-
const {
|
1021
|
-
|
1559
|
+
const { pagination = {}, ...rest } = options;
|
1560
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1561
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1562
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1563
|
+
const results = [...page.records];
|
1564
|
+
while (page.hasNextPage() && results.length < size) {
|
1565
|
+
page = await page.nextPage();
|
1566
|
+
results.push(...page.records);
|
1567
|
+
}
|
1568
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1569
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1570
|
+
}
|
1571
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1572
|
+
return array;
|
1022
1573
|
}
|
1023
|
-
async getAll(
|
1574
|
+
async getAll(options = {}) {
|
1575
|
+
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
1024
1576
|
const results = [];
|
1025
|
-
for await (const page of this.getIterator(
|
1577
|
+
for await (const page of this.getIterator({ ...rest, batchSize })) {
|
1026
1578
|
results.push(...page);
|
1027
1579
|
}
|
1028
1580
|
return results;
|
1029
1581
|
}
|
1030
1582
|
async getFirst(options = {}) {
|
1031
|
-
const records = await this.getMany({ ...options,
|
1032
|
-
return records[0]
|
1583
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1584
|
+
return records[0] ?? null;
|
1585
|
+
}
|
1586
|
+
async getFirstOrThrow(options = {}) {
|
1587
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1588
|
+
if (records[0] === void 0)
|
1589
|
+
throw new Error("No results found.");
|
1590
|
+
return records[0];
|
1033
1591
|
}
|
1034
1592
|
cache(ttl) {
|
1035
|
-
return new _Query(__privateGet$
|
1593
|
+
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1036
1594
|
}
|
1037
1595
|
nextPage(size, offset) {
|
1038
1596
|
return this.firstPage(size, offset);
|
@@ -1041,10 +1599,10 @@ const _Query = class {
|
|
1041
1599
|
return this.firstPage(size, offset);
|
1042
1600
|
}
|
1043
1601
|
firstPage(size, offset) {
|
1044
|
-
return this.getPaginated({
|
1602
|
+
return this.getPaginated({ pagination: { size, offset } });
|
1045
1603
|
}
|
1046
1604
|
lastPage(size, offset) {
|
1047
|
-
return this.getPaginated({
|
1605
|
+
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1048
1606
|
}
|
1049
1607
|
hasNextPage() {
|
1050
1608
|
return this.meta.page.more;
|
@@ -1054,12 +1612,31 @@ let Query = _Query;
|
|
1054
1612
|
_table$1 = new WeakMap();
|
1055
1613
|
_repository = new WeakMap();
|
1056
1614
|
_data = new WeakMap();
|
1615
|
+
_cleanFilterConstraint = new WeakSet();
|
1616
|
+
cleanFilterConstraint_fn = function(column, value) {
|
1617
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1618
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1619
|
+
return { $includes: value };
|
1620
|
+
}
|
1621
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
1622
|
+
return value.id;
|
1623
|
+
}
|
1624
|
+
return value;
|
1625
|
+
};
|
1626
|
+
function cleanParent(data, parent) {
|
1627
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
1628
|
+
return { ...parent, sorting: void 0, filter: void 0 };
|
1629
|
+
}
|
1630
|
+
return parent;
|
1631
|
+
}
|
1057
1632
|
|
1058
1633
|
function isIdentifiable(x) {
|
1059
1634
|
return isObject(x) && isString(x?.id);
|
1060
1635
|
}
|
1061
1636
|
function isXataRecord(x) {
|
1062
|
-
|
1637
|
+
const record = x;
|
1638
|
+
const metadata = record?.getMetadata();
|
1639
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
1063
1640
|
}
|
1064
1641
|
|
1065
1642
|
function isSortFilterString(value) {
|
@@ -1089,7 +1666,7 @@ var __accessCheck$4 = (obj, member, msg) => {
|
|
1089
1666
|
if (!member.has(obj))
|
1090
1667
|
throw TypeError("Cannot " + msg);
|
1091
1668
|
};
|
1092
|
-
var __privateGet$
|
1669
|
+
var __privateGet$4 = (obj, member, getter) => {
|
1093
1670
|
__accessCheck$4(obj, member, "read from private field");
|
1094
1671
|
return getter ? getter.call(obj) : member.get(obj);
|
1095
1672
|
};
|
@@ -1098,7 +1675,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1098
1675
|
throw TypeError("Cannot add the same private member more than once");
|
1099
1676
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1100
1677
|
};
|
1101
|
-
var __privateSet$
|
1678
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1102
1679
|
__accessCheck$4(obj, member, "write to private field");
|
1103
1680
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1104
1681
|
return value;
|
@@ -1107,304 +1684,413 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1107
1684
|
__accessCheck$4(obj, member, "access private method");
|
1108
1685
|
return method;
|
1109
1686
|
};
|
1110
|
-
var _table,
|
1687
|
+
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;
|
1111
1688
|
class Repository extends Query {
|
1112
1689
|
}
|
1113
1690
|
class RestRepository extends Query {
|
1114
1691
|
constructor(options) {
|
1115
|
-
super(
|
1692
|
+
super(
|
1693
|
+
null,
|
1694
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1695
|
+
{}
|
1696
|
+
);
|
1116
1697
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1117
1698
|
__privateAdd$4(this, _insertRecordWithId);
|
1118
1699
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
1119
1700
|
__privateAdd$4(this, _updateRecordWithID);
|
1120
1701
|
__privateAdd$4(this, _upsertRecordWithID);
|
1121
1702
|
__privateAdd$4(this, _deleteRecord);
|
1122
|
-
__privateAdd$4(this, _invalidateCache);
|
1123
|
-
__privateAdd$4(this, _setCacheRecord);
|
1124
|
-
__privateAdd$4(this, _getCacheRecord);
|
1125
1703
|
__privateAdd$4(this, _setCacheQuery);
|
1126
1704
|
__privateAdd$4(this, _getCacheQuery);
|
1705
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1127
1706
|
__privateAdd$4(this, _table, void 0);
|
1128
|
-
__privateAdd$4(this, _links, void 0);
|
1129
1707
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1708
|
+
__privateAdd$4(this, _db, void 0);
|
1130
1709
|
__privateAdd$4(this, _cache, void 0);
|
1131
|
-
|
1132
|
-
|
1133
|
-
__privateSet$
|
1134
|
-
this
|
1135
|
-
__privateSet$
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
throw new Error("The id can't be empty");
|
1146
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
|
1147
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1148
|
-
return record;
|
1149
|
-
}
|
1150
|
-
if (isObject(a) && isString(a.id)) {
|
1151
|
-
if (a.id === "")
|
1152
|
-
throw new Error("The id can't be empty");
|
1153
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
|
1154
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1155
|
-
return record;
|
1156
|
-
}
|
1157
|
-
if (isObject(a)) {
|
1158
|
-
const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
|
1159
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1160
|
-
return record;
|
1161
|
-
}
|
1162
|
-
throw new Error("Invalid arguments for create method");
|
1163
|
-
}
|
1164
|
-
async read(recordId) {
|
1165
|
-
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
|
1166
|
-
if (cacheRecord)
|
1167
|
-
return cacheRecord;
|
1168
|
-
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
1169
|
-
try {
|
1170
|
-
const response = await getRecord({
|
1171
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
|
1172
|
-
...fetchProps
|
1710
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1711
|
+
__privateAdd$4(this, _trace, void 0);
|
1712
|
+
__privateSet$4(this, _table, options.table);
|
1713
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1714
|
+
__privateSet$4(this, _db, options.db);
|
1715
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1716
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1717
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1718
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1719
|
+
return trace(name, fn, {
|
1720
|
+
...options2,
|
1721
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1722
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1723
|
+
[TraceAttributes.VERSION]: VERSION
|
1173
1724
|
});
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1725
|
+
});
|
1726
|
+
}
|
1727
|
+
async create(a, b, c) {
|
1728
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1729
|
+
if (Array.isArray(a)) {
|
1730
|
+
if (a.length === 0)
|
1731
|
+
return [];
|
1732
|
+
const columns = isStringArray(b) ? b : void 0;
|
1733
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1178
1734
|
}
|
1179
|
-
|
1180
|
-
|
1735
|
+
if (isString(a) && isObject(b)) {
|
1736
|
+
if (a === "")
|
1737
|
+
throw new Error("The id can't be empty");
|
1738
|
+
const columns = isStringArray(c) ? c : void 0;
|
1739
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1740
|
+
}
|
1741
|
+
if (isObject(a) && isString(a.id)) {
|
1742
|
+
if (a.id === "")
|
1743
|
+
throw new Error("The id can't be empty");
|
1744
|
+
const columns = isStringArray(b) ? b : void 0;
|
1745
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1746
|
+
}
|
1747
|
+
if (isObject(a)) {
|
1748
|
+
const columns = isStringArray(b) ? b : void 0;
|
1749
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1750
|
+
}
|
1751
|
+
throw new Error("Invalid arguments for create method");
|
1752
|
+
});
|
1181
1753
|
}
|
1182
|
-
async
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1754
|
+
async read(a, b) {
|
1755
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1756
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1757
|
+
if (Array.isArray(a)) {
|
1758
|
+
if (a.length === 0)
|
1759
|
+
return [];
|
1760
|
+
const ids = a.map((item) => extractId(item));
|
1761
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1762
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1763
|
+
acc[object.id] = object;
|
1764
|
+
return acc;
|
1765
|
+
}, {});
|
1766
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1186
1767
|
}
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1768
|
+
const id = extractId(a);
|
1769
|
+
if (id) {
|
1770
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1771
|
+
try {
|
1772
|
+
const response = await getRecord({
|
1773
|
+
pathParams: {
|
1774
|
+
workspace: "{workspaceId}",
|
1775
|
+
dbBranchName: "{dbBranch}",
|
1776
|
+
tableName: __privateGet$4(this, _table),
|
1777
|
+
recordId: id
|
1778
|
+
},
|
1779
|
+
queryParams: { columns },
|
1780
|
+
...fetchProps
|
1781
|
+
});
|
1782
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1783
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1784
|
+
} catch (e) {
|
1785
|
+
if (isObject(e) && e.status === 404) {
|
1786
|
+
return null;
|
1787
|
+
}
|
1788
|
+
throw e;
|
1789
|
+
}
|
1790
|
+
}
|
1791
|
+
return null;
|
1792
|
+
});
|
1202
1793
|
}
|
1203
|
-
async
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1794
|
+
async readOrThrow(a, b) {
|
1795
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1796
|
+
const result = await this.read(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;
|
1207
1805
|
}
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
return record;
|
1215
|
-
}
|
1216
|
-
if (isObject(a) && isString(a.id)) {
|
1217
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1218
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1219
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1220
|
-
return record;
|
1221
|
-
}
|
1222
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1806
|
+
if (result === null) {
|
1807
|
+
const id = extractId(a) ?? "unknown";
|
1808
|
+
throw new Error(`Record with id ${id} not found`);
|
1809
|
+
}
|
1810
|
+
return result;
|
1811
|
+
});
|
1223
1812
|
}
|
1224
|
-
async
|
1225
|
-
|
1226
|
-
if (a
|
1227
|
-
|
1813
|
+
async update(a, b, c) {
|
1814
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1815
|
+
if (Array.isArray(a)) {
|
1816
|
+
if (a.length === 0)
|
1817
|
+
return [];
|
1818
|
+
if (a.length > 100) {
|
1819
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1820
|
+
}
|
1821
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1822
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1228
1823
|
}
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1824
|
+
if (isString(a) && isObject(b)) {
|
1825
|
+
const columns = isStringArray(c) ? c : void 0;
|
1826
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1827
|
+
}
|
1828
|
+
if (isObject(a) && isString(a.id)) {
|
1829
|
+
const columns = isStringArray(b) ? b : void 0;
|
1830
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1831
|
+
}
|
1832
|
+
throw new Error("Invalid arguments for update method");
|
1833
|
+
});
|
1834
|
+
}
|
1835
|
+
async updateOrThrow(a, b, c) {
|
1836
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1837
|
+
const result = await this.update(a, b, c);
|
1838
|
+
if (Array.isArray(result)) {
|
1839
|
+
const missingIds = compact(
|
1840
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1841
|
+
);
|
1842
|
+
if (missingIds.length > 0) {
|
1843
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1844
|
+
}
|
1845
|
+
return result;
|
1846
|
+
}
|
1847
|
+
if (result === null) {
|
1848
|
+
const id = extractId(a) ?? "unknown";
|
1849
|
+
throw new Error(`Record with id ${id} not found`);
|
1850
|
+
}
|
1851
|
+
return result;
|
1852
|
+
});
|
1853
|
+
}
|
1854
|
+
async createOrUpdate(a, b, c) {
|
1855
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1856
|
+
if (Array.isArray(a)) {
|
1857
|
+
if (a.length === 0)
|
1858
|
+
return [];
|
1859
|
+
if (a.length > 100) {
|
1860
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1861
|
+
}
|
1862
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1863
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1864
|
+
}
|
1865
|
+
if (isString(a) && isObject(b)) {
|
1866
|
+
const columns = isStringArray(c) ? c : void 0;
|
1867
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1868
|
+
}
|
1869
|
+
if (isObject(a) && isString(a.id)) {
|
1870
|
+
const columns = isStringArray(c) ? c : void 0;
|
1871
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1872
|
+
}
|
1873
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1874
|
+
});
|
1875
|
+
}
|
1876
|
+
async delete(a, b) {
|
1877
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1878
|
+
if (Array.isArray(a)) {
|
1879
|
+
if (a.length === 0)
|
1880
|
+
return [];
|
1881
|
+
if (a.length > 100) {
|
1882
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1883
|
+
}
|
1884
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1885
|
+
}
|
1886
|
+
if (isString(a)) {
|
1887
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1888
|
+
}
|
1889
|
+
if (isObject(a) && isString(a.id)) {
|
1890
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1891
|
+
}
|
1892
|
+
throw new Error("Invalid arguments for delete method");
|
1893
|
+
});
|
1894
|
+
}
|
1895
|
+
async deleteOrThrow(a, b) {
|
1896
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1897
|
+
const result = await this.delete(a, b);
|
1898
|
+
if (Array.isArray(result)) {
|
1899
|
+
const missingIds = compact(
|
1900
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1901
|
+
);
|
1902
|
+
if (missingIds.length > 0) {
|
1903
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1904
|
+
}
|
1905
|
+
return result;
|
1906
|
+
} else if (result === null) {
|
1907
|
+
const id = extractId(a) ?? "unknown";
|
1908
|
+
throw new Error(`Record with id ${id} not found`);
|
1909
|
+
}
|
1910
|
+
return result;
|
1911
|
+
});
|
1243
1912
|
}
|
1244
1913
|
async search(query, options = {}) {
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1914
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1915
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1916
|
+
const { records } = await searchTable({
|
1917
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1918
|
+
body: {
|
1919
|
+
query,
|
1920
|
+
fuzziness: options.fuzziness,
|
1921
|
+
prefix: options.prefix,
|
1922
|
+
highlight: options.highlight,
|
1923
|
+
filter: options.filter,
|
1924
|
+
boosters: options.boosters
|
1925
|
+
},
|
1926
|
+
...fetchProps
|
1927
|
+
});
|
1928
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1929
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
1250
1930
|
});
|
1251
|
-
return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
|
1252
1931
|
}
|
1253
1932
|
async query(query) {
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1933
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1934
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1935
|
+
if (cacheQuery)
|
1936
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1937
|
+
const data = query.getQueryOptions();
|
1938
|
+
const body = {
|
1939
|
+
filter: cleanFilter(data.filter),
|
1940
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1941
|
+
page: data.pagination,
|
1942
|
+
columns: data.columns
|
1943
|
+
};
|
1944
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1945
|
+
const { meta, records: objects } = await queryTable({
|
1946
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1947
|
+
body,
|
1948
|
+
...fetchProps
|
1949
|
+
});
|
1950
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1951
|
+
const records = objects.map(
|
1952
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
1953
|
+
);
|
1954
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1955
|
+
return new Page(query, meta, records);
|
1269
1956
|
});
|
1270
|
-
const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
|
1271
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1272
|
-
return new Page(query, meta, records);
|
1273
1957
|
}
|
1274
1958
|
}
|
1275
1959
|
_table = new WeakMap();
|
1276
|
-
_links = new WeakMap();
|
1277
1960
|
_getFetchProps = new WeakMap();
|
1961
|
+
_db = new WeakMap();
|
1278
1962
|
_cache = new WeakMap();
|
1963
|
+
_schemaTables$2 = new WeakMap();
|
1964
|
+
_trace = new WeakMap();
|
1279
1965
|
_insertRecordWithoutId = new WeakSet();
|
1280
|
-
insertRecordWithoutId_fn = async function(object) {
|
1281
|
-
const fetchProps = await __privateGet$
|
1966
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1967
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1282
1968
|
const record = transformObjectLinks(object);
|
1283
1969
|
const response = await insertRecord({
|
1284
1970
|
pathParams: {
|
1285
1971
|
workspace: "{workspaceId}",
|
1286
1972
|
dbBranchName: "{dbBranch}",
|
1287
|
-
tableName: __privateGet$
|
1973
|
+
tableName: __privateGet$4(this, _table)
|
1288
1974
|
},
|
1975
|
+
queryParams: { columns },
|
1289
1976
|
body: record,
|
1290
1977
|
...fetchProps
|
1291
1978
|
});
|
1292
|
-
const
|
1293
|
-
|
1294
|
-
throw new Error("The server failed to save the record");
|
1295
|
-
}
|
1296
|
-
return finalObject;
|
1979
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1980
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1297
1981
|
};
|
1298
1982
|
_insertRecordWithId = new WeakSet();
|
1299
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1300
|
-
const fetchProps = await __privateGet$
|
1983
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1984
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1301
1985
|
const record = transformObjectLinks(object);
|
1302
1986
|
const response = await insertRecordWithID({
|
1303
1987
|
pathParams: {
|
1304
1988
|
workspace: "{workspaceId}",
|
1305
1989
|
dbBranchName: "{dbBranch}",
|
1306
|
-
tableName: __privateGet$
|
1990
|
+
tableName: __privateGet$4(this, _table),
|
1307
1991
|
recordId
|
1308
1992
|
},
|
1309
1993
|
body: record,
|
1310
|
-
queryParams: { createOnly: true },
|
1994
|
+
queryParams: { createOnly: true, columns },
|
1311
1995
|
...fetchProps
|
1312
1996
|
});
|
1313
|
-
const
|
1314
|
-
|
1315
|
-
throw new Error("The server failed to save the record");
|
1316
|
-
}
|
1317
|
-
return finalObject;
|
1997
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1998
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1318
1999
|
};
|
1319
2000
|
_bulkInsertTableRecords = new WeakSet();
|
1320
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1321
|
-
const fetchProps = await __privateGet$
|
2001
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
2002
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1322
2003
|
const records = objects.map((object) => transformObjectLinks(object));
|
1323
2004
|
const response = await bulkInsertTableRecords({
|
1324
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
2005
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
2006
|
+
queryParams: { columns },
|
1325
2007
|
body: { records },
|
1326
2008
|
...fetchProps
|
1327
2009
|
});
|
1328
|
-
|
1329
|
-
|
1330
|
-
throw new Error("The server failed to save some records");
|
2010
|
+
if (!isResponseWithRecords(response)) {
|
2011
|
+
throw new Error("Request included columns but server didn't include them");
|
1331
2012
|
}
|
1332
|
-
|
2013
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2014
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
1333
2015
|
};
|
1334
2016
|
_updateRecordWithID = new WeakSet();
|
1335
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1336
|
-
const fetchProps = await __privateGet$
|
2017
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
2018
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1337
2019
|
const record = transformObjectLinks(object);
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
2020
|
+
try {
|
2021
|
+
const response = await updateRecordWithID({
|
2022
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
2023
|
+
queryParams: { columns },
|
2024
|
+
body: record,
|
2025
|
+
...fetchProps
|
2026
|
+
});
|
2027
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2028
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2029
|
+
} catch (e) {
|
2030
|
+
if (isObject(e) && e.status === 404) {
|
2031
|
+
return null;
|
2032
|
+
}
|
2033
|
+
throw e;
|
2034
|
+
}
|
1347
2035
|
};
|
1348
2036
|
_upsertRecordWithID = new WeakSet();
|
1349
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1350
|
-
const fetchProps = await __privateGet$
|
2037
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
2038
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1351
2039
|
const response = await upsertRecordWithID({
|
1352
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$
|
2040
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
2041
|
+
queryParams: { columns },
|
1353
2042
|
body: object,
|
1354
2043
|
...fetchProps
|
1355
2044
|
});
|
1356
|
-
const
|
1357
|
-
|
1358
|
-
throw new Error("The server failed to save the record");
|
1359
|
-
return item;
|
2045
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2046
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1360
2047
|
};
|
1361
2048
|
_deleteRecord = new WeakSet();
|
1362
|
-
deleteRecord_fn = async function(recordId) {
|
1363
|
-
const fetchProps = await __privateGet$
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
await __privateGet$3(this, _cache).delete(key);
|
2049
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2050
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2051
|
+
try {
|
2052
|
+
const response = await deleteRecord({
|
2053
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
2054
|
+
queryParams: { columns },
|
2055
|
+
...fetchProps
|
2056
|
+
});
|
2057
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2058
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2059
|
+
} catch (e) {
|
2060
|
+
if (isObject(e) && e.status === 404) {
|
2061
|
+
return null;
|
2062
|
+
}
|
2063
|
+
throw e;
|
1378
2064
|
}
|
1379
2065
|
};
|
1380
|
-
_setCacheRecord = new WeakSet();
|
1381
|
-
setCacheRecord_fn = async function(record) {
|
1382
|
-
if (!__privateGet$3(this, _cache).cacheRecords)
|
1383
|
-
return;
|
1384
|
-
await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
|
1385
|
-
};
|
1386
|
-
_getCacheRecord = new WeakSet();
|
1387
|
-
getCacheRecord_fn = async function(recordId) {
|
1388
|
-
if (!__privateGet$3(this, _cache).cacheRecords)
|
1389
|
-
return null;
|
1390
|
-
return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
|
1391
|
-
};
|
1392
2066
|
_setCacheQuery = new WeakSet();
|
1393
2067
|
setCacheQuery_fn = async function(query, meta, records) {
|
1394
|
-
await __privateGet$
|
2068
|
+
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
1395
2069
|
};
|
1396
2070
|
_getCacheQuery = new WeakSet();
|
1397
2071
|
getCacheQuery_fn = async function(query) {
|
1398
|
-
const key = `query_${__privateGet$
|
1399
|
-
const result = await __privateGet$
|
2072
|
+
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2073
|
+
const result = await __privateGet$4(this, _cache).get(key);
|
1400
2074
|
if (!result)
|
1401
2075
|
return null;
|
1402
|
-
const { cache: ttl = __privateGet$
|
1403
|
-
if (
|
1404
|
-
return
|
2076
|
+
const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
|
2077
|
+
if (ttl < 0)
|
2078
|
+
return null;
|
1405
2079
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1406
2080
|
return hasExpired ? null : result;
|
1407
2081
|
};
|
2082
|
+
_getSchemaTables$1 = new WeakSet();
|
2083
|
+
getSchemaTables_fn$1 = async function() {
|
2084
|
+
if (__privateGet$4(this, _schemaTables$2))
|
2085
|
+
return __privateGet$4(this, _schemaTables$2);
|
2086
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2087
|
+
const { schema } = await getBranchDetails({
|
2088
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
2089
|
+
...fetchProps
|
2090
|
+
});
|
2091
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2092
|
+
return schema.tables;
|
2093
|
+
};
|
1408
2094
|
const transformObjectLinks = (object) => {
|
1409
2095
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
1410
2096
|
if (key === "xata")
|
@@ -1412,47 +2098,105 @@ const transformObjectLinks = (object) => {
|
|
1412
2098
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1413
2099
|
}, {});
|
1414
2100
|
};
|
1415
|
-
const initObject = (db,
|
2101
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
1416
2102
|
const result = {};
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
2103
|
+
const { xata, ...rest } = object ?? {};
|
2104
|
+
Object.assign(result, rest);
|
2105
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2106
|
+
if (!columns)
|
2107
|
+
console.error(`Table ${table} not found in schema`);
|
2108
|
+
for (const column of columns ?? []) {
|
2109
|
+
if (!isValidColumn(selectedColumns, column))
|
2110
|
+
continue;
|
2111
|
+
const value = result[column.name];
|
2112
|
+
switch (column.type) {
|
2113
|
+
case "datetime": {
|
2114
|
+
const date = value !== void 0 ? new Date(value) : void 0;
|
2115
|
+
if (date && isNaN(date.getTime())) {
|
2116
|
+
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2117
|
+
} else if (date) {
|
2118
|
+
result[column.name] = date;
|
2119
|
+
}
|
2120
|
+
break;
|
2121
|
+
}
|
2122
|
+
case "link": {
|
2123
|
+
const linkTable = column.link?.table;
|
2124
|
+
if (!linkTable) {
|
2125
|
+
console.error(`Failed to parse link for field ${column.name}`);
|
2126
|
+
} else if (isObject(value)) {
|
2127
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2128
|
+
if (item === column.name) {
|
2129
|
+
return [...acc, "*"];
|
2130
|
+
}
|
2131
|
+
if (item.startsWith(`${column.name}.`)) {
|
2132
|
+
const [, ...path] = item.split(".");
|
2133
|
+
return [...acc, path.join(".")];
|
2134
|
+
}
|
2135
|
+
return acc;
|
2136
|
+
}, []);
|
2137
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2138
|
+
} else {
|
2139
|
+
result[column.name] = null;
|
2140
|
+
}
|
2141
|
+
break;
|
2142
|
+
}
|
2143
|
+
default:
|
2144
|
+
result[column.name] = value ?? null;
|
2145
|
+
if (column.notNull === true && value === null) {
|
2146
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2147
|
+
}
|
2148
|
+
break;
|
1424
2149
|
}
|
1425
2150
|
}
|
1426
|
-
result.read = function() {
|
1427
|
-
return db[table].read(result["id"]);
|
2151
|
+
result.read = function(columns2) {
|
2152
|
+
return db[table].read(result["id"], columns2);
|
1428
2153
|
};
|
1429
|
-
result.update = function(data) {
|
1430
|
-
return db[table].update(result["id"], data);
|
2154
|
+
result.update = function(data, columns2) {
|
2155
|
+
return db[table].update(result["id"], data, columns2);
|
1431
2156
|
};
|
1432
2157
|
result.delete = function() {
|
1433
2158
|
return db[table].delete(result["id"]);
|
1434
2159
|
};
|
1435
|
-
|
2160
|
+
result.getMetadata = function() {
|
2161
|
+
return xata;
|
2162
|
+
};
|
2163
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
1436
2164
|
Object.defineProperty(result, prop, { enumerable: false });
|
1437
2165
|
}
|
1438
2166
|
Object.freeze(result);
|
1439
2167
|
return result;
|
1440
2168
|
};
|
1441
|
-
function
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
if (
|
1446
|
-
return
|
1447
|
-
|
1448
|
-
|
2169
|
+
function isResponseWithRecords(value) {
|
2170
|
+
return isObject(value) && Array.isArray(value.records);
|
2171
|
+
}
|
2172
|
+
function extractId(value) {
|
2173
|
+
if (isString(value))
|
2174
|
+
return value;
|
2175
|
+
if (isObject(value) && isString(value.id))
|
2176
|
+
return value.id;
|
2177
|
+
return void 0;
|
2178
|
+
}
|
2179
|
+
function cleanFilter(filter) {
|
2180
|
+
if (!filter)
|
2181
|
+
return void 0;
|
2182
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2183
|
+
return values.length > 0 ? filter : void 0;
|
2184
|
+
}
|
2185
|
+
function isValidColumn(columns, column) {
|
2186
|
+
if (columns.includes("*"))
|
2187
|
+
return true;
|
2188
|
+
if (column.type === "link") {
|
2189
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2190
|
+
return linkColumns.length > 0;
|
2191
|
+
}
|
2192
|
+
return columns.includes(column.name);
|
1449
2193
|
}
|
1450
2194
|
|
1451
2195
|
var __accessCheck$3 = (obj, member, msg) => {
|
1452
2196
|
if (!member.has(obj))
|
1453
2197
|
throw TypeError("Cannot " + msg);
|
1454
2198
|
};
|
1455
|
-
var __privateGet$
|
2199
|
+
var __privateGet$3 = (obj, member, getter) => {
|
1456
2200
|
__accessCheck$3(obj, member, "read from private field");
|
1457
2201
|
return getter ? getter.call(obj) : member.get(obj);
|
1458
2202
|
};
|
@@ -1461,7 +2205,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1461
2205
|
throw TypeError("Cannot add the same private member more than once");
|
1462
2206
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1463
2207
|
};
|
1464
|
-
var __privateSet$
|
2208
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1465
2209
|
__accessCheck$3(obj, member, "write to private field");
|
1466
2210
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1467
2211
|
return value;
|
@@ -1470,46 +2214,52 @@ var _map;
|
|
1470
2214
|
class SimpleCache {
|
1471
2215
|
constructor(options = {}) {
|
1472
2216
|
__privateAdd$3(this, _map, void 0);
|
1473
|
-
__privateSet$
|
2217
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1474
2218
|
this.capacity = options.max ?? 500;
|
1475
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1476
2219
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1477
2220
|
}
|
1478
2221
|
async getAll() {
|
1479
|
-
return Object.fromEntries(__privateGet$
|
2222
|
+
return Object.fromEntries(__privateGet$3(this, _map));
|
1480
2223
|
}
|
1481
2224
|
async get(key) {
|
1482
|
-
return __privateGet$
|
2225
|
+
return __privateGet$3(this, _map).get(key) ?? null;
|
1483
2226
|
}
|
1484
2227
|
async set(key, value) {
|
1485
2228
|
await this.delete(key);
|
1486
|
-
__privateGet$
|
1487
|
-
if (__privateGet$
|
1488
|
-
const leastRecentlyUsed = __privateGet$
|
2229
|
+
__privateGet$3(this, _map).set(key, value);
|
2230
|
+
if (__privateGet$3(this, _map).size > this.capacity) {
|
2231
|
+
const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
|
1489
2232
|
await this.delete(leastRecentlyUsed);
|
1490
2233
|
}
|
1491
2234
|
}
|
1492
2235
|
async delete(key) {
|
1493
|
-
__privateGet$
|
2236
|
+
__privateGet$3(this, _map).delete(key);
|
1494
2237
|
}
|
1495
2238
|
async clear() {
|
1496
|
-
return __privateGet$
|
2239
|
+
return __privateGet$3(this, _map).clear();
|
1497
2240
|
}
|
1498
2241
|
}
|
1499
2242
|
_map = new WeakMap();
|
1500
2243
|
|
1501
|
-
const
|
1502
|
-
const
|
1503
|
-
const
|
1504
|
-
const
|
1505
|
-
const
|
1506
|
-
const
|
2244
|
+
const greaterThan = (value) => ({ $gt: value });
|
2245
|
+
const gt = greaterThan;
|
2246
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2247
|
+
const greaterEquals = greaterThanEquals;
|
2248
|
+
const gte = greaterThanEquals;
|
2249
|
+
const ge = greaterThanEquals;
|
2250
|
+
const lessThan = (value) => ({ $lt: value });
|
2251
|
+
const lt = lessThan;
|
2252
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2253
|
+
const lessEquals = lessThanEquals;
|
2254
|
+
const lte = lessThanEquals;
|
2255
|
+
const le = lessThanEquals;
|
1507
2256
|
const exists = (column) => ({ $exists: column });
|
1508
2257
|
const notExists = (column) => ({ $notExists: column });
|
1509
2258
|
const startsWith = (value) => ({ $startsWith: value });
|
1510
2259
|
const endsWith = (value) => ({ $endsWith: value });
|
1511
2260
|
const pattern = (value) => ({ $pattern: value });
|
1512
2261
|
const is = (value) => ({ $is: value });
|
2262
|
+
const equals = is;
|
1513
2263
|
const isNot = (value) => ({ $isNot: value });
|
1514
2264
|
const contains = (value) => ({ $contains: value });
|
1515
2265
|
const includes = (value) => ({ $includes: value });
|
@@ -1521,7 +2271,7 @@ var __accessCheck$2 = (obj, member, msg) => {
|
|
1521
2271
|
if (!member.has(obj))
|
1522
2272
|
throw TypeError("Cannot " + msg);
|
1523
2273
|
};
|
1524
|
-
var __privateGet$
|
2274
|
+
var __privateGet$2 = (obj, member, getter) => {
|
1525
2275
|
__accessCheck$2(obj, member, "read from private field");
|
1526
2276
|
return getter ? getter.call(obj) : member.get(obj);
|
1527
2277
|
};
|
@@ -1530,130 +2280,178 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1530
2280
|
throw TypeError("Cannot add the same private member more than once");
|
1531
2281
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1532
2282
|
};
|
1533
|
-
var
|
2283
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
2284
|
+
__accessCheck$2(obj, member, "write to private field");
|
2285
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
2286
|
+
return value;
|
2287
|
+
};
|
2288
|
+
var _tables, _schemaTables$1;
|
1534
2289
|
class SchemaPlugin extends XataPlugin {
|
1535
|
-
constructor(
|
2290
|
+
constructor(schemaTables) {
|
1536
2291
|
super();
|
1537
|
-
this.links = links;
|
1538
|
-
this.tableNames = tableNames;
|
1539
2292
|
__privateAdd$2(this, _tables, {});
|
2293
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
2294
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1540
2295
|
}
|
1541
2296
|
build(pluginOptions) {
|
1542
|
-
const
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
__privateGet$
|
2297
|
+
const db = new Proxy(
|
2298
|
+
{},
|
2299
|
+
{
|
2300
|
+
get: (_target, table) => {
|
2301
|
+
if (!isString(table))
|
2302
|
+
throw new Error("Invalid table name");
|
2303
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2304
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2305
|
+
}
|
2306
|
+
return __privateGet$2(this, _tables)[table];
|
1549
2307
|
}
|
1550
|
-
return __privateGet$1(this, _tables)[table];
|
1551
2308
|
}
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
2309
|
+
);
|
2310
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
2311
|
+
for (const table of tableNames) {
|
2312
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1555
2313
|
}
|
1556
2314
|
return db;
|
1557
2315
|
}
|
1558
2316
|
}
|
1559
2317
|
_tables = new WeakMap();
|
2318
|
+
_schemaTables$1 = new WeakMap();
|
1560
2319
|
|
1561
2320
|
var __accessCheck$1 = (obj, member, msg) => {
|
1562
2321
|
if (!member.has(obj))
|
1563
2322
|
throw TypeError("Cannot " + msg);
|
1564
2323
|
};
|
2324
|
+
var __privateGet$1 = (obj, member, getter) => {
|
2325
|
+
__accessCheck$1(obj, member, "read from private field");
|
2326
|
+
return getter ? getter.call(obj) : member.get(obj);
|
2327
|
+
};
|
1565
2328
|
var __privateAdd$1 = (obj, member, value) => {
|
1566
2329
|
if (member.has(obj))
|
1567
2330
|
throw TypeError("Cannot add the same private member more than once");
|
1568
2331
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1569
2332
|
};
|
2333
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
2334
|
+
__accessCheck$1(obj, member, "write to private field");
|
2335
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
2336
|
+
return value;
|
2337
|
+
};
|
1570
2338
|
var __privateMethod$1 = (obj, member, method) => {
|
1571
2339
|
__accessCheck$1(obj, member, "access private method");
|
1572
2340
|
return method;
|
1573
2341
|
};
|
1574
|
-
var _search, search_fn;
|
2342
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1575
2343
|
class SearchPlugin extends XataPlugin {
|
1576
|
-
constructor(db,
|
2344
|
+
constructor(db, schemaTables) {
|
1577
2345
|
super();
|
1578
2346
|
this.db = db;
|
1579
|
-
this.links = links;
|
1580
2347
|
__privateAdd$1(this, _search);
|
2348
|
+
__privateAdd$1(this, _getSchemaTables);
|
2349
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
2350
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1581
2351
|
}
|
1582
2352
|
build({ getFetchProps }) {
|
1583
2353
|
return {
|
1584
2354
|
all: async (query, options = {}) => {
|
1585
2355
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
2356
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1586
2357
|
return records.map((record) => {
|
1587
2358
|
const { table = "orphan" } = record.xata;
|
1588
|
-
return { table, record: initObject(this.db,
|
2359
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1589
2360
|
});
|
1590
2361
|
},
|
1591
2362
|
byTable: async (query, options = {}) => {
|
1592
2363
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
2364
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1593
2365
|
return records.reduce((acc, record) => {
|
1594
2366
|
const { table = "orphan" } = record.xata;
|
1595
2367
|
const items = acc[table] ?? [];
|
1596
|
-
const item = initObject(this.db,
|
2368
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1597
2369
|
return { ...acc, [table]: [...items, item] };
|
1598
2370
|
}, {});
|
1599
2371
|
}
|
1600
2372
|
};
|
1601
2373
|
}
|
1602
2374
|
}
|
2375
|
+
_schemaTables = new WeakMap();
|
1603
2376
|
_search = new WeakSet();
|
1604
2377
|
search_fn = async function(query, options, getFetchProps) {
|
1605
2378
|
const fetchProps = await getFetchProps();
|
1606
|
-
const { tables, fuzziness } = options ?? {};
|
2379
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1607
2380
|
const { records } = await searchBranch({
|
1608
2381
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1609
|
-
body: { tables, query, fuzziness },
|
2382
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1610
2383
|
...fetchProps
|
1611
2384
|
});
|
1612
2385
|
return records;
|
1613
2386
|
};
|
2387
|
+
_getSchemaTables = new WeakSet();
|
2388
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
2389
|
+
if (__privateGet$1(this, _schemaTables))
|
2390
|
+
return __privateGet$1(this, _schemaTables);
|
2391
|
+
const fetchProps = await getFetchProps();
|
2392
|
+
const { schema } = await getBranchDetails({
|
2393
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
2394
|
+
...fetchProps
|
2395
|
+
});
|
2396
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
2397
|
+
return schema.tables;
|
2398
|
+
};
|
1614
2399
|
|
1615
2400
|
const isBranchStrategyBuilder = (strategy) => {
|
1616
2401
|
return typeof strategy === "function";
|
1617
2402
|
};
|
1618
2403
|
|
1619
|
-
const envBranchNames = [
|
1620
|
-
"XATA_BRANCH",
|
1621
|
-
"VERCEL_GIT_COMMIT_REF",
|
1622
|
-
"CF_PAGES_BRANCH",
|
1623
|
-
"BRANCH"
|
1624
|
-
];
|
1625
|
-
const defaultBranch = "main";
|
1626
2404
|
async function getCurrentBranchName(options) {
|
1627
|
-
const
|
1628
|
-
if (
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
return defaultBranch;
|
2405
|
+
const { branch, envBranch } = getEnvironment();
|
2406
|
+
if (branch) {
|
2407
|
+
const details = await getDatabaseBranch(branch, options);
|
2408
|
+
if (details)
|
2409
|
+
return branch;
|
2410
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
2411
|
+
}
|
2412
|
+
const gitBranch = envBranch || await getGitBranch();
|
2413
|
+
return resolveXataBranch(gitBranch, options);
|
1637
2414
|
}
|
1638
2415
|
async function getCurrentBranchDetails(options) {
|
1639
|
-
const
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
2416
|
+
const branch = await getCurrentBranchName(options);
|
2417
|
+
return getDatabaseBranch(branch, options);
|
2418
|
+
}
|
2419
|
+
async function resolveXataBranch(gitBranch, options) {
|
2420
|
+
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2421
|
+
const apiKey = options?.apiKey || getAPIKey();
|
2422
|
+
if (!databaseURL)
|
2423
|
+
throw new Error(
|
2424
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2425
|
+
);
|
2426
|
+
if (!apiKey)
|
2427
|
+
throw new Error(
|
2428
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2429
|
+
);
|
2430
|
+
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2431
|
+
const [workspace] = host.split(".");
|
2432
|
+
const { fallbackBranch } = getEnvironment();
|
2433
|
+
const { branch } = await resolveBranch({
|
2434
|
+
apiKey,
|
2435
|
+
apiUrl: databaseURL,
|
2436
|
+
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2437
|
+
workspacesApiUrl: `${protocol}//${host}`,
|
2438
|
+
pathParams: { dbName, workspace },
|
2439
|
+
queryParams: { gitBranch, fallbackBranch },
|
2440
|
+
trace: defaultTrace
|
2441
|
+
});
|
2442
|
+
return branch;
|
1649
2443
|
}
|
1650
2444
|
async function getDatabaseBranch(branch, options) {
|
1651
2445
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1652
2446
|
const apiKey = options?.apiKey || getAPIKey();
|
1653
2447
|
if (!databaseURL)
|
1654
|
-
throw new Error(
|
2448
|
+
throw new Error(
|
2449
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2450
|
+
);
|
1655
2451
|
if (!apiKey)
|
1656
|
-
throw new Error(
|
2452
|
+
throw new Error(
|
2453
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2454
|
+
);
|
1657
2455
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1658
2456
|
const [workspace] = host.split(".");
|
1659
2457
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1663,10 +2461,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1663
2461
|
apiUrl: databaseURL,
|
1664
2462
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1665
2463
|
workspacesApiUrl: `${protocol}//${host}`,
|
1666
|
-
pathParams: {
|
1667
|
-
|
1668
|
-
workspace
|
1669
|
-
}
|
2464
|
+
pathParams: { dbBranchName, workspace },
|
2465
|
+
trace: defaultTrace
|
1670
2466
|
});
|
1671
2467
|
} catch (err) {
|
1672
2468
|
if (isObject(err) && err.status === 404)
|
@@ -1674,21 +2470,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1674
2470
|
throw err;
|
1675
2471
|
}
|
1676
2472
|
}
|
1677
|
-
function getBranchByEnvVariable() {
|
1678
|
-
for (const name of envBranchNames) {
|
1679
|
-
const value = getEnvVariable(name);
|
1680
|
-
if (value) {
|
1681
|
-
return value;
|
1682
|
-
}
|
1683
|
-
}
|
1684
|
-
try {
|
1685
|
-
return XATA_BRANCH;
|
1686
|
-
} catch (err) {
|
1687
|
-
}
|
1688
|
-
}
|
1689
2473
|
function getDatabaseURL() {
|
1690
2474
|
try {
|
1691
|
-
|
2475
|
+
const { databaseURL } = getEnvironment();
|
2476
|
+
return databaseURL;
|
1692
2477
|
} catch (err) {
|
1693
2478
|
return void 0;
|
1694
2479
|
}
|
@@ -1717,24 +2502,27 @@ var __privateMethod = (obj, member, method) => {
|
|
1717
2502
|
return method;
|
1718
2503
|
};
|
1719
2504
|
const buildClient = (plugins) => {
|
1720
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2505
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1721
2506
|
return _a = class {
|
1722
|
-
constructor(options = {},
|
2507
|
+
constructor(options = {}, schemaTables) {
|
1723
2508
|
__privateAdd(this, _parseOptions);
|
1724
2509
|
__privateAdd(this, _getFetchProps);
|
1725
2510
|
__privateAdd(this, _evaluateBranch);
|
1726
2511
|
__privateAdd(this, _branch, void 0);
|
2512
|
+
__privateAdd(this, _options, void 0);
|
1727
2513
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2514
|
+
__privateSet(this, _options, safeOptions);
|
1728
2515
|
const pluginOptions = {
|
1729
2516
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1730
|
-
cache: safeOptions.cache
|
2517
|
+
cache: safeOptions.cache,
|
2518
|
+
trace: safeOptions.trace
|
1731
2519
|
};
|
1732
|
-
const db = new SchemaPlugin(
|
1733
|
-
const search = new SearchPlugin(db,
|
2520
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2521
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1734
2522
|
this.db = db;
|
1735
2523
|
this.search = search;
|
1736
2524
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
1737
|
-
if (
|
2525
|
+
if (namespace === void 0)
|
1738
2526
|
continue;
|
1739
2527
|
const result = namespace.build(pluginOptions);
|
1740
2528
|
if (result instanceof Promise) {
|
@@ -1746,22 +2534,26 @@ const buildClient = (plugins) => {
|
|
1746
2534
|
}
|
1747
2535
|
}
|
1748
2536
|
}
|
1749
|
-
|
2537
|
+
async getConfig() {
|
2538
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2539
|
+
const branch = await __privateGet(this, _options).branch();
|
2540
|
+
return { databaseURL, branch };
|
2541
|
+
}
|
2542
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1750
2543
|
const fetch = getFetchImplementation(options?.fetch);
|
1751
2544
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1752
2545
|
const apiKey = options?.apiKey || getAPIKey();
|
1753
|
-
const cache = options?.cache ?? new SimpleCache({
|
1754
|
-
const
|
1755
|
-
|
1756
|
-
|
2546
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2547
|
+
const trace = options?.trace ?? defaultTrace;
|
2548
|
+
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2549
|
+
if (!apiKey) {
|
2550
|
+
throw new Error("Option apiKey is required");
|
1757
2551
|
}
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
apiKey,
|
1762
|
-
|
1763
|
-
branch
|
1764
|
-
}) {
|
2552
|
+
if (!databaseURL) {
|
2553
|
+
throw new Error("Option databaseURL is required");
|
2554
|
+
}
|
2555
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2556
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
1765
2557
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1766
2558
|
if (!branchValue)
|
1767
2559
|
throw new Error("Unable to resolve branch value");
|
@@ -1771,14 +2563,15 @@ const buildClient = (plugins) => {
|
|
1771
2563
|
apiUrl: "",
|
1772
2564
|
workspacesApiUrl: (path, params) => {
|
1773
2565
|
const hasBranch = params.dbBranchName ?? params.branch;
|
1774
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2566
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
1775
2567
|
return databaseURL + newPath;
|
1776
|
-
}
|
2568
|
+
},
|
2569
|
+
trace
|
1777
2570
|
};
|
1778
2571
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
1779
2572
|
if (__privateGet(this, _branch))
|
1780
2573
|
return __privateGet(this, _branch);
|
1781
|
-
if (
|
2574
|
+
if (param === void 0)
|
1782
2575
|
return void 0;
|
1783
2576
|
const strategies = Array.isArray(param) ? [...param] : [param];
|
1784
2577
|
const evaluateBranch = async (strategy) => {
|
@@ -1796,6 +2589,88 @@ const buildClient = (plugins) => {
|
|
1796
2589
|
class BaseClient extends buildClient() {
|
1797
2590
|
}
|
1798
2591
|
|
2592
|
+
const META = "__";
|
2593
|
+
const VALUE = "___";
|
2594
|
+
class Serializer {
|
2595
|
+
constructor() {
|
2596
|
+
this.classes = {};
|
2597
|
+
}
|
2598
|
+
add(clazz) {
|
2599
|
+
this.classes[clazz.name] = clazz;
|
2600
|
+
}
|
2601
|
+
toJSON(data) {
|
2602
|
+
function visit(obj) {
|
2603
|
+
if (Array.isArray(obj))
|
2604
|
+
return obj.map(visit);
|
2605
|
+
const type = typeof obj;
|
2606
|
+
if (type === "undefined")
|
2607
|
+
return { [META]: "undefined" };
|
2608
|
+
if (type === "bigint")
|
2609
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2610
|
+
if (obj === null || type !== "object")
|
2611
|
+
return obj;
|
2612
|
+
const constructor = obj.constructor;
|
2613
|
+
const o = { [META]: constructor.name };
|
2614
|
+
for (const [key, value] of Object.entries(obj)) {
|
2615
|
+
o[key] = visit(value);
|
2616
|
+
}
|
2617
|
+
if (constructor === Date)
|
2618
|
+
o[VALUE] = obj.toISOString();
|
2619
|
+
if (constructor === Map)
|
2620
|
+
o[VALUE] = Object.fromEntries(obj);
|
2621
|
+
if (constructor === Set)
|
2622
|
+
o[VALUE] = [...obj];
|
2623
|
+
return o;
|
2624
|
+
}
|
2625
|
+
return JSON.stringify(visit(data));
|
2626
|
+
}
|
2627
|
+
fromJSON(json) {
|
2628
|
+
return JSON.parse(json, (key, value) => {
|
2629
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2630
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2631
|
+
const constructor = this.classes[clazz];
|
2632
|
+
if (constructor) {
|
2633
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2634
|
+
}
|
2635
|
+
if (clazz === "Date")
|
2636
|
+
return new Date(val);
|
2637
|
+
if (clazz === "Set")
|
2638
|
+
return new Set(val);
|
2639
|
+
if (clazz === "Map")
|
2640
|
+
return new Map(Object.entries(val));
|
2641
|
+
if (clazz === "bigint")
|
2642
|
+
return BigInt(val);
|
2643
|
+
if (clazz === "undefined")
|
2644
|
+
return void 0;
|
2645
|
+
return rest;
|
2646
|
+
}
|
2647
|
+
return value;
|
2648
|
+
});
|
2649
|
+
}
|
2650
|
+
}
|
2651
|
+
const defaultSerializer = new Serializer();
|
2652
|
+
const serialize = (data) => {
|
2653
|
+
return defaultSerializer.toJSON(data);
|
2654
|
+
};
|
2655
|
+
const deserialize = (json) => {
|
2656
|
+
return defaultSerializer.fromJSON(json);
|
2657
|
+
};
|
2658
|
+
|
2659
|
+
function buildWorkerRunner(config) {
|
2660
|
+
return function xataWorker(name, _worker) {
|
2661
|
+
return async (...args) => {
|
2662
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2663
|
+
const result = await fetch(url, {
|
2664
|
+
method: "POST",
|
2665
|
+
headers: { "Content-Type": "application/json" },
|
2666
|
+
body: serialize({ args })
|
2667
|
+
});
|
2668
|
+
const text = await result.text();
|
2669
|
+
return deserialize(text);
|
2670
|
+
};
|
2671
|
+
};
|
2672
|
+
}
|
2673
|
+
|
1799
2674
|
class XataError extends Error {
|
1800
2675
|
constructor(message, status) {
|
1801
2676
|
super(message);
|
@@ -1803,5 +2678,5 @@ class XataError extends Error {
|
|
1803
2678
|
}
|
1804
2679
|
}
|
1805
2680
|
|
1806
|
-
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, 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, 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, removeWorkspaceMember, resendWorkspaceMemberInvite, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
2681
|
+
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, aggregateTable, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cPCreateDatabase, cPDeleteDatabase, cPGetCPDatabaseMetadata, cPGetDatabaseList, cPUpdateCPDatabaseMetadata, 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, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
1807
2682
|
//# sourceMappingURL=index.mjs.map
|