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