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