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