@xata.io/client 0.0.0-alpha.vf45a2df → 0.0.0-alpha.vf4752f8
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/CHANGELOG.md +88 -0
- package/README.md +27 -25
- package/Usage.md +60 -6
- package/dist/index.cjs +904 -435
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1365 -261
- package/dist/index.mjs +859 -436
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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
|
}
|
@@ -17,6 +57,9 @@ function isDefined(value) {
|
|
17
57
|
function isString(value) {
|
18
58
|
return isDefined(value) && typeof value === "string";
|
19
59
|
}
|
60
|
+
function isStringArray(value) {
|
61
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
62
|
+
}
|
20
63
|
function toBase64(value) {
|
21
64
|
try {
|
22
65
|
return btoa(value);
|
@@ -26,35 +69,83 @@ function toBase64(value) {
|
|
26
69
|
}
|
27
70
|
}
|
28
71
|
|
29
|
-
function
|
72
|
+
function getEnvironment() {
|
30
73
|
try {
|
31
|
-
if (isObject(process) &&
|
32
|
-
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
|
+
};
|
33
82
|
}
|
34
83
|
} catch (err) {
|
35
84
|
}
|
36
85
|
try {
|
37
|
-
if (isObject(Deno) &&
|
38
|
-
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
|
+
};
|
39
94
|
}
|
40
95
|
} catch (err) {
|
41
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
|
+
}
|
42
132
|
}
|
43
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"] };
|
44
138
|
try {
|
45
139
|
if (typeof require === "function") {
|
46
|
-
|
47
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
140
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
48
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();
|
49
144
|
} catch (err) {
|
50
145
|
}
|
51
146
|
try {
|
52
147
|
if (isObject(Deno)) {
|
53
|
-
const process2 = Deno.run({
|
54
|
-
cmd: ["git", "branch", "--show-current"],
|
55
|
-
stdout: "piped",
|
56
|
-
stderr: "piped"
|
57
|
-
});
|
148
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
58
149
|
return new TextDecoder().decode(await process2.output()).trim();
|
59
150
|
}
|
60
151
|
} catch (err) {
|
@@ -63,7 +154,8 @@ async function getGitBranch() {
|
|
63
154
|
|
64
155
|
function getAPIKey() {
|
65
156
|
try {
|
66
|
-
|
157
|
+
const { apiKey } = getEnvironment();
|
158
|
+
return apiKey;
|
67
159
|
} catch (err) {
|
68
160
|
return void 0;
|
69
161
|
}
|
@@ -73,12 +165,14 @@ function getFetchImplementation(userFetch) {
|
|
73
165
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
74
166
|
const fetchImpl = userFetch ?? globalFetch;
|
75
167
|
if (!fetchImpl) {
|
76
|
-
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
|
+
);
|
77
171
|
}
|
78
172
|
return fetchImpl;
|
79
173
|
}
|
80
174
|
|
81
|
-
const VERSION = "0.0.0-alpha.
|
175
|
+
const VERSION = "0.0.0-alpha.vf4752f8";
|
82
176
|
|
83
177
|
class ErrorWithCause extends Error {
|
84
178
|
constructor(message, options) {
|
@@ -129,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
129
223
|
}, {});
|
130
224
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
131
225
|
const queryString = query.length > 0 ? `?${query}` : "";
|
132
|
-
|
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;
|
133
230
|
};
|
134
231
|
function buildBaseUrl({
|
135
232
|
path,
|
@@ -137,10 +234,10 @@ function buildBaseUrl({
|
|
137
234
|
apiUrl,
|
138
235
|
pathParams
|
139
236
|
}) {
|
140
|
-
if (
|
237
|
+
if (pathParams?.workspace === void 0)
|
141
238
|
return `${apiUrl}${path}`;
|
142
239
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
143
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
240
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
144
241
|
}
|
145
242
|
function hostHeader(url) {
|
146
243
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -157,34 +254,61 @@ async function fetch$1({
|
|
157
254
|
fetchImpl,
|
158
255
|
apiKey,
|
159
256
|
apiUrl,
|
160
|
-
workspacesApiUrl
|
257
|
+
workspacesApiUrl,
|
258
|
+
trace
|
161
259
|
}) {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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) {
|
180
307
|
try {
|
181
|
-
const
|
182
|
-
|
183
|
-
return jsonResponse;
|
184
|
-
}
|
185
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
308
|
+
const { host, protocol } = new URL(url);
|
309
|
+
return { host, protocol };
|
186
310
|
} catch (error) {
|
187
|
-
|
311
|
+
return {};
|
188
312
|
}
|
189
313
|
}
|
190
314
|
|
@@ -243,6 +367,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
243
367
|
...variables
|
244
368
|
});
|
245
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 });
|
246
371
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
247
372
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
248
373
|
method: "delete",
|
@@ -278,6 +403,12 @@ const deleteDatabase = (variables) => fetch$1({
|
|
278
403
|
method: "delete",
|
279
404
|
...variables
|
280
405
|
});
|
406
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
407
|
+
url: "/dbs/{dbName}/metadata",
|
408
|
+
method: "get",
|
409
|
+
...variables
|
410
|
+
});
|
411
|
+
const patchDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
281
412
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
282
413
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
283
414
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -286,16 +417,28 @@ const resolveBranch = (variables) => fetch$1({
|
|
286
417
|
method: "get",
|
287
418
|
...variables
|
288
419
|
});
|
289
|
-
const
|
290
|
-
|
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}",
|
291
424
|
method: "get",
|
292
425
|
...variables
|
293
426
|
});
|
294
|
-
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({
|
295
437
|
url: "/db/{dbBranchName}",
|
296
|
-
method: "
|
438
|
+
method: "get",
|
297
439
|
...variables
|
298
440
|
});
|
441
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
299
442
|
const deleteBranch = (variables) => fetch$1({
|
300
443
|
url: "/db/{dbBranchName}",
|
301
444
|
method: "delete",
|
@@ -314,6 +457,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
314
457
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
315
458
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
316
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 });
|
317
470
|
const getBranchStats = (variables) => fetch$1({
|
318
471
|
url: "/db/{dbBranchName}/stats",
|
319
472
|
method: "get",
|
@@ -369,11 +522,7 @@ const updateColumn = (variables) => fetch$1({
|
|
369
522
|
method: "patch",
|
370
523
|
...variables
|
371
524
|
});
|
372
|
-
const insertRecord = (variables) => fetch$1({
|
373
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
374
|
-
method: "post",
|
375
|
-
...variables
|
376
|
-
});
|
525
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
377
526
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
378
527
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
379
528
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -415,6 +564,7 @@ const operationsByTag = {
|
|
415
564
|
updateWorkspaceMemberRole,
|
416
565
|
removeWorkspaceMember,
|
417
566
|
inviteWorkspaceMember,
|
567
|
+
updateWorkspaceMemberInvite,
|
418
568
|
cancelWorkspaceMemberInvite,
|
419
569
|
resendWorkspaceMemberInvite,
|
420
570
|
acceptWorkspaceMemberInvite
|
@@ -423,6 +573,8 @@ const operationsByTag = {
|
|
423
573
|
getDatabaseList,
|
424
574
|
createDatabase,
|
425
575
|
deleteDatabase,
|
576
|
+
getDatabaseMetadata,
|
577
|
+
patchDatabaseMetadata,
|
426
578
|
getGitBranchesMapping,
|
427
579
|
addGitBranchesEntry,
|
428
580
|
removeGitBranchesEntry,
|
@@ -435,10 +587,28 @@ const operationsByTag = {
|
|
435
587
|
deleteBranch,
|
436
588
|
updateBranchMetadata,
|
437
589
|
getBranchMetadata,
|
590
|
+
getBranchStats
|
591
|
+
},
|
592
|
+
migrationRequests: {
|
593
|
+
listMigrationRequests,
|
594
|
+
createMigrationRequest,
|
595
|
+
getMigrationRequest,
|
596
|
+
updateMigrationRequest,
|
597
|
+
listMigrationRequestsCommits,
|
598
|
+
compareMigrationRequest,
|
599
|
+
getMigrationRequestIsMerged,
|
600
|
+
mergeMigrationRequest
|
601
|
+
},
|
602
|
+
branchSchema: {
|
438
603
|
getBranchMigrationHistory,
|
439
604
|
executeBranchMigrationPlan,
|
440
605
|
getBranchMigrationPlan,
|
441
|
-
|
606
|
+
compareBranchWithUserSchema,
|
607
|
+
compareBranchSchemas,
|
608
|
+
updateBranchSchema,
|
609
|
+
previewBranchSchemaEdit,
|
610
|
+
applyBranchSchemaEdit,
|
611
|
+
getBranchSchemaHistory
|
442
612
|
},
|
443
613
|
table: {
|
444
614
|
createTable,
|
@@ -467,9 +637,9 @@ const operationsByTag = {
|
|
467
637
|
};
|
468
638
|
|
469
639
|
function getHostUrl(provider, type) {
|
470
|
-
if (
|
640
|
+
if (isHostProviderAlias(provider)) {
|
471
641
|
return providers[provider][type];
|
472
|
-
} else if (
|
642
|
+
} else if (isHostProviderBuilder(provider)) {
|
473
643
|
return provider[type];
|
474
644
|
}
|
475
645
|
throw new Error("Invalid API provider");
|
@@ -484,10 +654,10 @@ const providers = {
|
|
484
654
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
485
655
|
}
|
486
656
|
};
|
487
|
-
function
|
657
|
+
function isHostProviderAlias(alias) {
|
488
658
|
return isString(alias) && Object.keys(providers).includes(alias);
|
489
659
|
}
|
490
|
-
function
|
660
|
+
function isHostProviderBuilder(builder) {
|
491
661
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
492
662
|
}
|
493
663
|
|
@@ -504,7 +674,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
504
674
|
throw TypeError("Cannot add the same private member more than once");
|
505
675
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
506
676
|
};
|
507
|
-
var __privateSet$
|
677
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
508
678
|
__accessCheck$7(obj, member, "write to private field");
|
509
679
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
510
680
|
return value;
|
@@ -515,15 +685,17 @@ class XataApiClient {
|
|
515
685
|
__privateAdd$7(this, _extraProps, void 0);
|
516
686
|
__privateAdd$7(this, _namespaces, {});
|
517
687
|
const provider = options.host ?? "production";
|
518
|
-
const apiKey = options
|
688
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
689
|
+
const trace = options.trace ?? defaultTrace;
|
519
690
|
if (!apiKey) {
|
520
691
|
throw new Error("Could not resolve a valid apiKey");
|
521
692
|
}
|
522
|
-
__privateSet$
|
693
|
+
__privateSet$7(this, _extraProps, {
|
523
694
|
apiUrl: getHostUrl(provider, "main"),
|
524
695
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
525
696
|
fetchImpl: getFetchImplementation(options.fetch),
|
526
|
-
apiKey
|
697
|
+
apiKey,
|
698
|
+
trace
|
527
699
|
});
|
528
700
|
}
|
529
701
|
get user() {
|
@@ -556,6 +728,16 @@ class XataApiClient {
|
|
556
728
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
557
729
|
return __privateGet$7(this, _namespaces).records;
|
558
730
|
}
|
731
|
+
get migrationRequests() {
|
732
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
733
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
734
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
735
|
+
}
|
736
|
+
get branchSchema() {
|
737
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
738
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
739
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
740
|
+
}
|
559
741
|
}
|
560
742
|
_extraProps = new WeakMap();
|
561
743
|
_namespaces = new WeakMap();
|
@@ -646,6 +828,13 @@ class WorkspaceApi {
|
|
646
828
|
...this.extraProps
|
647
829
|
});
|
648
830
|
}
|
831
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
832
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
833
|
+
pathParams: { workspaceId, inviteId },
|
834
|
+
body: { role },
|
835
|
+
...this.extraProps
|
836
|
+
});
|
837
|
+
}
|
649
838
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
650
839
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
651
840
|
pathParams: { workspaceId, inviteId },
|
@@ -688,6 +877,12 @@ class DatabaseApi {
|
|
688
877
|
...this.extraProps
|
689
878
|
});
|
690
879
|
}
|
880
|
+
getDatabaseMetadata(workspace, dbName) {
|
881
|
+
return operationsByTag.database.getDatabaseMetadata({
|
882
|
+
pathParams: { workspace, dbName },
|
883
|
+
...this.extraProps
|
884
|
+
});
|
885
|
+
}
|
691
886
|
getGitBranchesMapping(workspace, dbName) {
|
692
887
|
return operationsByTag.database.getGitBranchesMapping({
|
693
888
|
pathParams: { workspace, dbName },
|
@@ -759,27 +954,6 @@ class BranchApi {
|
|
759
954
|
...this.extraProps
|
760
955
|
});
|
761
956
|
}
|
762
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
763
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
764
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
765
|
-
body: options,
|
766
|
-
...this.extraProps
|
767
|
-
});
|
768
|
-
}
|
769
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
770
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
771
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
772
|
-
body: migrationPlan,
|
773
|
-
...this.extraProps
|
774
|
-
});
|
775
|
-
}
|
776
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
777
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
778
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
779
|
-
body: schema,
|
780
|
-
...this.extraProps
|
781
|
-
});
|
782
|
-
}
|
783
957
|
getBranchStats(workspace, database, branch) {
|
784
958
|
return operationsByTag.branch.getBranchStats({
|
785
959
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -860,9 +1034,10 @@ class RecordsApi {
|
|
860
1034
|
constructor(extraProps) {
|
861
1035
|
this.extraProps = extraProps;
|
862
1036
|
}
|
863
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1037
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
864
1038
|
return operationsByTag.records.insertRecord({
|
865
1039
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1040
|
+
queryParams: options,
|
866
1041
|
body: record,
|
867
1042
|
...this.extraProps
|
868
1043
|
});
|
@@ -891,21 +1066,24 @@ class RecordsApi {
|
|
891
1066
|
...this.extraProps
|
892
1067
|
});
|
893
1068
|
}
|
894
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1069
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
895
1070
|
return operationsByTag.records.deleteRecord({
|
896
1071
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1072
|
+
queryParams: options,
|
897
1073
|
...this.extraProps
|
898
1074
|
});
|
899
1075
|
}
|
900
1076
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
901
1077
|
return operationsByTag.records.getRecord({
|
902
1078
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1079
|
+
queryParams: options,
|
903
1080
|
...this.extraProps
|
904
1081
|
});
|
905
1082
|
}
|
906
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1083
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
907
1084
|
return operationsByTag.records.bulkInsertTableRecords({
|
908
1085
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1086
|
+
queryParams: options,
|
909
1087
|
body: { records },
|
910
1088
|
...this.extraProps
|
911
1089
|
});
|
@@ -932,6 +1110,131 @@ class RecordsApi {
|
|
932
1110
|
});
|
933
1111
|
}
|
934
1112
|
}
|
1113
|
+
class MigrationRequestsApi {
|
1114
|
+
constructor(extraProps) {
|
1115
|
+
this.extraProps = extraProps;
|
1116
|
+
}
|
1117
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1118
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1119
|
+
pathParams: { workspace, dbName: database },
|
1120
|
+
body: options,
|
1121
|
+
...this.extraProps
|
1122
|
+
});
|
1123
|
+
}
|
1124
|
+
createMigrationRequest(workspace, database, options) {
|
1125
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1126
|
+
pathParams: { workspace, dbName: database },
|
1127
|
+
body: options,
|
1128
|
+
...this.extraProps
|
1129
|
+
});
|
1130
|
+
}
|
1131
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1132
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1133
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1134
|
+
...this.extraProps
|
1135
|
+
});
|
1136
|
+
}
|
1137
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1138
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1139
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1140
|
+
body: options,
|
1141
|
+
...this.extraProps
|
1142
|
+
});
|
1143
|
+
}
|
1144
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1145
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1146
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1147
|
+
body: options,
|
1148
|
+
...this.extraProps
|
1149
|
+
});
|
1150
|
+
}
|
1151
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1152
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1153
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1154
|
+
...this.extraProps
|
1155
|
+
});
|
1156
|
+
}
|
1157
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1158
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1159
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1160
|
+
...this.extraProps
|
1161
|
+
});
|
1162
|
+
}
|
1163
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1164
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1165
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1166
|
+
...this.extraProps
|
1167
|
+
});
|
1168
|
+
}
|
1169
|
+
}
|
1170
|
+
class BranchSchemaApi {
|
1171
|
+
constructor(extraProps) {
|
1172
|
+
this.extraProps = extraProps;
|
1173
|
+
}
|
1174
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1175
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1176
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1177
|
+
body: options,
|
1178
|
+
...this.extraProps
|
1179
|
+
});
|
1180
|
+
}
|
1181
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1182
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1183
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1184
|
+
body: migrationPlan,
|
1185
|
+
...this.extraProps
|
1186
|
+
});
|
1187
|
+
}
|
1188
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1189
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1190
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1191
|
+
body: schema,
|
1192
|
+
...this.extraProps
|
1193
|
+
});
|
1194
|
+
}
|
1195
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1196
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1197
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1198
|
+
body: { schema },
|
1199
|
+
...this.extraProps
|
1200
|
+
});
|
1201
|
+
}
|
1202
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1203
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1204
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1205
|
+
body: { schema },
|
1206
|
+
...this.extraProps
|
1207
|
+
});
|
1208
|
+
}
|
1209
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1210
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1211
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1212
|
+
body: migration,
|
1213
|
+
...this.extraProps
|
1214
|
+
});
|
1215
|
+
}
|
1216
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1217
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1218
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1219
|
+
body: migration,
|
1220
|
+
...this.extraProps
|
1221
|
+
});
|
1222
|
+
}
|
1223
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1224
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1225
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1226
|
+
body: { edits },
|
1227
|
+
...this.extraProps
|
1228
|
+
});
|
1229
|
+
}
|
1230
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1231
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1232
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1233
|
+
body: options,
|
1234
|
+
...this.extraProps
|
1235
|
+
});
|
1236
|
+
}
|
1237
|
+
}
|
935
1238
|
|
936
1239
|
class XataApiPlugin {
|
937
1240
|
async build(options) {
|
@@ -956,7 +1259,7 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
956
1259
|
throw TypeError("Cannot add the same private member more than once");
|
957
1260
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
958
1261
|
};
|
959
|
-
var __privateSet$
|
1262
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
960
1263
|
__accessCheck$6(obj, member, "write to private field");
|
961
1264
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
962
1265
|
return value;
|
@@ -965,7 +1268,7 @@ var _query, _page;
|
|
965
1268
|
class Page {
|
966
1269
|
constructor(query, meta, records = []) {
|
967
1270
|
__privateAdd$6(this, _query, void 0);
|
968
|
-
__privateSet$
|
1271
|
+
__privateSet$6(this, _query, query);
|
969
1272
|
this.meta = meta;
|
970
1273
|
this.records = new RecordArray(this, records);
|
971
1274
|
}
|
@@ -994,10 +1297,10 @@ function isCursorPaginationOptions(options) {
|
|
994
1297
|
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
995
1298
|
}
|
996
1299
|
const _RecordArray = class extends Array {
|
997
|
-
constructor(
|
998
|
-
super(..._RecordArray.parseConstructorParams(
|
1300
|
+
constructor(...args) {
|
1301
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
999
1302
|
__privateAdd$6(this, _page, void 0);
|
1000
|
-
__privateSet$
|
1303
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1001
1304
|
}
|
1002
1305
|
static parseConstructorParams(...args) {
|
1003
1306
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -1009,6 +1312,12 @@ const _RecordArray = class extends Array {
|
|
1009
1312
|
}
|
1010
1313
|
return new Array(...args);
|
1011
1314
|
}
|
1315
|
+
toArray() {
|
1316
|
+
return new Array(...this);
|
1317
|
+
}
|
1318
|
+
map(callbackfn, thisArg) {
|
1319
|
+
return this.toArray().map(callbackfn, thisArg);
|
1320
|
+
}
|
1012
1321
|
async nextPage(size, offset) {
|
1013
1322
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1014
1323
|
return new _RecordArray(newPage);
|
@@ -1045,7 +1354,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
1045
1354
|
throw TypeError("Cannot add the same private member more than once");
|
1046
1355
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1047
1356
|
};
|
1048
|
-
var __privateSet$
|
1357
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
1049
1358
|
__accessCheck$5(obj, member, "write to private field");
|
1050
1359
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1051
1360
|
return value;
|
@@ -1058,11 +1367,11 @@ const _Query = class {
|
|
1058
1367
|
__privateAdd$5(this, _data, { filter: {} });
|
1059
1368
|
this.meta = { page: { cursor: "start", more: true } };
|
1060
1369
|
this.records = new RecordArray(this, []);
|
1061
|
-
__privateSet$
|
1370
|
+
__privateSet$5(this, _table$1, table);
|
1062
1371
|
if (repository) {
|
1063
|
-
__privateSet$
|
1372
|
+
__privateSet$5(this, _repository, repository);
|
1064
1373
|
} else {
|
1065
|
-
__privateSet$
|
1374
|
+
__privateSet$5(this, _repository, this);
|
1066
1375
|
}
|
1067
1376
|
const parent = cleanParent(data, rawParent);
|
1068
1377
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
@@ -1109,21 +1418,34 @@ const _Query = class {
|
|
1109
1418
|
}
|
1110
1419
|
filter(a, b) {
|
1111
1420
|
if (arguments.length === 1) {
|
1112
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1421
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1113
1422
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1114
1423
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1115
1424
|
} else {
|
1116
|
-
const
|
1425
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1426
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1117
1427
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1118
1428
|
}
|
1119
1429
|
}
|
1120
|
-
|
1430
|
+
defaultFilter(column, value) {
|
1431
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1432
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1433
|
+
return { $includes: value };
|
1434
|
+
}
|
1435
|
+
return value;
|
1436
|
+
}
|
1437
|
+
sort(column, direction = "asc") {
|
1121
1438
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1122
1439
|
const sort = [...originalSort, { column, direction }];
|
1123
1440
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1124
1441
|
}
|
1125
1442
|
select(columns) {
|
1126
|
-
return new _Query(
|
1443
|
+
return new _Query(
|
1444
|
+
__privateGet$5(this, _repository),
|
1445
|
+
__privateGet$5(this, _table$1),
|
1446
|
+
{ columns },
|
1447
|
+
__privateGet$5(this, _data)
|
1448
|
+
);
|
1127
1449
|
}
|
1128
1450
|
getPaginated(options = {}) {
|
1129
1451
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1239,7 +1561,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1239
1561
|
throw TypeError("Cannot add the same private member more than once");
|
1240
1562
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1241
1563
|
};
|
1242
|
-
var __privateSet$
|
1564
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1243
1565
|
__accessCheck$4(obj, member, "write to private field");
|
1244
1566
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1245
1567
|
return value;
|
@@ -1248,202 +1570,228 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1248
1570
|
__accessCheck$4(obj, member, "access private method");
|
1249
1571
|
return method;
|
1250
1572
|
};
|
1251
|
-
var _table, _getFetchProps, _cache,
|
1573
|
+
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;
|
1252
1574
|
class Repository extends Query {
|
1253
1575
|
}
|
1254
1576
|
class RestRepository extends Query {
|
1255
1577
|
constructor(options) {
|
1256
|
-
super(
|
1578
|
+
super(
|
1579
|
+
null,
|
1580
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1581
|
+
{}
|
1582
|
+
);
|
1257
1583
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1258
1584
|
__privateAdd$4(this, _insertRecordWithId);
|
1259
1585
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
1260
1586
|
__privateAdd$4(this, _updateRecordWithID);
|
1261
1587
|
__privateAdd$4(this, _upsertRecordWithID);
|
1262
1588
|
__privateAdd$4(this, _deleteRecord);
|
1263
|
-
__privateAdd$4(this, _invalidateCache);
|
1264
|
-
__privateAdd$4(this, _setCacheRecord);
|
1265
|
-
__privateAdd$4(this, _getCacheRecord);
|
1266
1589
|
__privateAdd$4(this, _setCacheQuery);
|
1267
1590
|
__privateAdd$4(this, _getCacheQuery);
|
1268
|
-
__privateAdd$4(this,
|
1591
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1269
1592
|
__privateAdd$4(this, _table, void 0);
|
1270
1593
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1594
|
+
__privateAdd$4(this, _db, void 0);
|
1271
1595
|
__privateAdd$4(this, _cache, void 0);
|
1272
|
-
__privateAdd$4(this,
|
1273
|
-
|
1274
|
-
__privateSet$
|
1275
|
-
this
|
1276
|
-
__privateSet$
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
if (a
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1596
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1597
|
+
__privateAdd$4(this, _trace, void 0);
|
1598
|
+
__privateSet$4(this, _table, options.table);
|
1599
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1600
|
+
__privateSet$4(this, _db, options.db);
|
1601
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1602
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1603
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1604
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1605
|
+
return trace(name, fn, {
|
1606
|
+
...options2,
|
1607
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1608
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1609
|
+
[TraceAttributes.VERSION]: VERSION
|
1610
|
+
});
|
1611
|
+
});
|
1612
|
+
}
|
1613
|
+
async create(a, b, c) {
|
1614
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1615
|
+
if (Array.isArray(a)) {
|
1616
|
+
if (a.length === 0)
|
1617
|
+
return [];
|
1618
|
+
const columns = isStringArray(b) ? b : void 0;
|
1619
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1620
|
+
}
|
1621
|
+
if (isString(a) && isObject(b)) {
|
1622
|
+
if (a === "")
|
1623
|
+
throw new Error("The id can't be empty");
|
1624
|
+
const columns = isStringArray(c) ? c : void 0;
|
1625
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1626
|
+
}
|
1627
|
+
if (isObject(a) && isString(a.id)) {
|
1628
|
+
if (a.id === "")
|
1629
|
+
throw new Error("The id can't be empty");
|
1630
|
+
const columns = isStringArray(b) ? b : void 0;
|
1631
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1632
|
+
}
|
1633
|
+
if (isObject(a)) {
|
1634
|
+
const columns = isStringArray(b) ? b : void 0;
|
1635
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1636
|
+
}
|
1637
|
+
throw new Error("Invalid arguments for create method");
|
1638
|
+
});
|
1639
|
+
}
|
1640
|
+
async read(a, b) {
|
1641
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1642
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1643
|
+
if (Array.isArray(a)) {
|
1644
|
+
if (a.length === 0)
|
1645
|
+
return [];
|
1646
|
+
const ids = a.map((item) => extractId(item));
|
1647
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1648
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1649
|
+
acc[object.id] = object;
|
1650
|
+
return acc;
|
1651
|
+
}, {});
|
1652
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1653
|
+
}
|
1654
|
+
const id = extractId(a);
|
1655
|
+
if (id) {
|
1656
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1657
|
+
try {
|
1658
|
+
const response = await getRecord({
|
1659
|
+
pathParams: {
|
1660
|
+
workspace: "{workspaceId}",
|
1661
|
+
dbBranchName: "{dbBranch}",
|
1662
|
+
tableName: __privateGet$4(this, _table),
|
1663
|
+
recordId: id
|
1664
|
+
},
|
1665
|
+
queryParams: { columns },
|
1666
|
+
...fetchProps
|
1667
|
+
});
|
1668
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1669
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1670
|
+
} catch (e) {
|
1671
|
+
if (isObject(e) && e.status === 404) {
|
1672
|
+
return null;
|
1673
|
+
}
|
1674
|
+
throw e;
|
1330
1675
|
}
|
1331
|
-
throw e;
|
1332
1676
|
}
|
1333
|
-
|
1677
|
+
return null;
|
1678
|
+
});
|
1334
1679
|
}
|
1335
|
-
async update(a, b) {
|
1336
|
-
|
1337
|
-
if (a
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1680
|
+
async update(a, b, c) {
|
1681
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1682
|
+
if (Array.isArray(a)) {
|
1683
|
+
if (a.length === 0)
|
1684
|
+
return [];
|
1685
|
+
if (a.length > 100) {
|
1686
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1687
|
+
}
|
1688
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1689
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1341
1690
|
}
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1346
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1347
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1348
|
-
return record;
|
1349
|
-
}
|
1350
|
-
if (isObject(a) && isString(a.id)) {
|
1351
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1352
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1353
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1354
|
-
return record;
|
1355
|
-
}
|
1356
|
-
throw new Error("Invalid arguments for update method");
|
1357
|
-
}
|
1358
|
-
async createOrUpdate(a, b) {
|
1359
|
-
if (Array.isArray(a)) {
|
1360
|
-
if (a.length === 0)
|
1361
|
-
return [];
|
1362
|
-
if (a.length > 100) {
|
1363
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1691
|
+
if (isString(a) && isObject(b)) {
|
1692
|
+
const columns = isStringArray(c) ? c : void 0;
|
1693
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1364
1694
|
}
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1369
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
|
1370
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1371
|
-
return record;
|
1372
|
-
}
|
1373
|
-
if (isObject(a) && isString(a.id)) {
|
1374
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1375
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1376
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1377
|
-
return record;
|
1378
|
-
}
|
1379
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1380
|
-
}
|
1381
|
-
async delete(a) {
|
1382
|
-
if (Array.isArray(a)) {
|
1383
|
-
if (a.length === 0)
|
1384
|
-
return;
|
1385
|
-
if (a.length > 100) {
|
1386
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1695
|
+
if (isObject(a) && isString(a.id)) {
|
1696
|
+
const columns = isStringArray(b) ? b : void 0;
|
1697
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1387
1698
|
}
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1699
|
+
throw new Error("Invalid arguments for update method");
|
1700
|
+
});
|
1701
|
+
}
|
1702
|
+
async createOrUpdate(a, b, c) {
|
1703
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1704
|
+
if (Array.isArray(a)) {
|
1705
|
+
if (a.length === 0)
|
1706
|
+
return [];
|
1707
|
+
if (a.length > 100) {
|
1708
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1709
|
+
}
|
1710
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1711
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1712
|
+
}
|
1713
|
+
if (isString(a) && isObject(b)) {
|
1714
|
+
const columns = isStringArray(c) ? c : void 0;
|
1715
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1716
|
+
}
|
1717
|
+
if (isObject(a) && isString(a.id)) {
|
1718
|
+
const columns = isStringArray(c) ? c : void 0;
|
1719
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1720
|
+
}
|
1721
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1722
|
+
});
|
1723
|
+
}
|
1724
|
+
async delete(a, b) {
|
1725
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1726
|
+
if (Array.isArray(a)) {
|
1727
|
+
if (a.length === 0)
|
1728
|
+
return [];
|
1729
|
+
if (a.length > 100) {
|
1730
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1731
|
+
}
|
1732
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1733
|
+
}
|
1734
|
+
if (isString(a)) {
|
1735
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1736
|
+
}
|
1737
|
+
if (isObject(a) && isString(a.id)) {
|
1738
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1739
|
+
}
|
1740
|
+
throw new Error("Invalid arguments for delete method");
|
1741
|
+
});
|
1402
1742
|
}
|
1403
1743
|
async search(query, options = {}) {
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1744
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1745
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1746
|
+
const { records } = await searchTable({
|
1747
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1748
|
+
body: {
|
1749
|
+
query,
|
1750
|
+
fuzziness: options.fuzziness,
|
1751
|
+
prefix: options.prefix,
|
1752
|
+
highlight: options.highlight,
|
1753
|
+
filter: options.filter,
|
1754
|
+
boosters: options.boosters
|
1755
|
+
},
|
1756
|
+
...fetchProps
|
1757
|
+
});
|
1758
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1759
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1414
1760
|
});
|
1415
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
1416
|
-
return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
|
1417
1761
|
}
|
1418
1762
|
async query(query) {
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1763
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1764
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1765
|
+
if (cacheQuery)
|
1766
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1767
|
+
const data = query.getQueryOptions();
|
1768
|
+
const body = {
|
1769
|
+
filter: cleanFilter(data.filter),
|
1770
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1771
|
+
page: data.pagination,
|
1772
|
+
columns: data.columns
|
1773
|
+
};
|
1774
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1775
|
+
const { meta, records: objects } = await queryTable({
|
1776
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1777
|
+
body,
|
1778
|
+
...fetchProps
|
1779
|
+
});
|
1780
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1781
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1782
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1783
|
+
return new Page(query, meta, records);
|
1434
1784
|
});
|
1435
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
1436
|
-
const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
|
1437
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1438
|
-
return new Page(query, meta, records);
|
1439
1785
|
}
|
1440
1786
|
}
|
1441
1787
|
_table = new WeakMap();
|
1442
1788
|
_getFetchProps = new WeakMap();
|
1789
|
+
_db = new WeakMap();
|
1443
1790
|
_cache = new WeakMap();
|
1444
|
-
|
1791
|
+
_schemaTables$2 = new WeakMap();
|
1792
|
+
_trace = new WeakMap();
|
1445
1793
|
_insertRecordWithoutId = new WeakSet();
|
1446
|
-
insertRecordWithoutId_fn = async function(object) {
|
1794
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1447
1795
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1448
1796
|
const record = transformObjectLinks(object);
|
1449
1797
|
const response = await insertRecord({
|
@@ -1452,17 +1800,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1452
1800
|
dbBranchName: "{dbBranch}",
|
1453
1801
|
tableName: __privateGet$4(this, _table)
|
1454
1802
|
},
|
1803
|
+
queryParams: { columns },
|
1455
1804
|
body: record,
|
1456
1805
|
...fetchProps
|
1457
1806
|
});
|
1458
|
-
const
|
1459
|
-
|
1460
|
-
throw new Error("The server failed to save the record");
|
1461
|
-
}
|
1462
|
-
return finalObject;
|
1807
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1808
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1463
1809
|
};
|
1464
1810
|
_insertRecordWithId = new WeakSet();
|
1465
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1811
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1466
1812
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1467
1813
|
const record = transformObjectLinks(object);
|
1468
1814
|
const response = await insertRecordWithID({
|
@@ -1473,92 +1819,78 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1473
1819
|
recordId
|
1474
1820
|
},
|
1475
1821
|
body: record,
|
1476
|
-
queryParams: { createOnly: true },
|
1822
|
+
queryParams: { createOnly: true, columns },
|
1477
1823
|
...fetchProps
|
1478
1824
|
});
|
1479
|
-
const
|
1480
|
-
|
1481
|
-
throw new Error("The server failed to save the record");
|
1482
|
-
}
|
1483
|
-
return finalObject;
|
1825
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1826
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1484
1827
|
};
|
1485
1828
|
_bulkInsertTableRecords = new WeakSet();
|
1486
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1829
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1487
1830
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1488
1831
|
const records = objects.map((object) => transformObjectLinks(object));
|
1489
|
-
const
|
1832
|
+
const response = await bulkInsertTableRecords({
|
1490
1833
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1834
|
+
queryParams: { columns },
|
1491
1835
|
body: { records },
|
1492
1836
|
...fetchProps
|
1493
1837
|
});
|
1494
|
-
|
1495
|
-
|
1496
|
-
throw new Error("The server failed to save some records");
|
1838
|
+
if (!isResponseWithRecords(response)) {
|
1839
|
+
throw new Error("Request included columns but server didn't include them");
|
1497
1840
|
}
|
1498
|
-
const
|
1499
|
-
|
1500
|
-
return acc;
|
1501
|
-
}, {});
|
1502
|
-
return recordIDs.map((id) => dictionary[id]);
|
1841
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1842
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1503
1843
|
};
|
1504
1844
|
_updateRecordWithID = new WeakSet();
|
1505
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1845
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1506
1846
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1507
1847
|
const record = transformObjectLinks(object);
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1848
|
+
try {
|
1849
|
+
const response = await updateRecordWithID({
|
1850
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1851
|
+
queryParams: { columns },
|
1852
|
+
body: record,
|
1853
|
+
...fetchProps
|
1854
|
+
});
|
1855
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1856
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1857
|
+
} catch (e) {
|
1858
|
+
if (isObject(e) && e.status === 404) {
|
1859
|
+
return null;
|
1860
|
+
}
|
1861
|
+
throw e;
|
1862
|
+
}
|
1517
1863
|
};
|
1518
1864
|
_upsertRecordWithID = new WeakSet();
|
1519
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1865
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1520
1866
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1521
1867
|
const response = await upsertRecordWithID({
|
1522
1868
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1869
|
+
queryParams: { columns },
|
1523
1870
|
body: object,
|
1524
1871
|
...fetchProps
|
1525
1872
|
});
|
1526
|
-
const
|
1527
|
-
|
1528
|
-
throw new Error("The server failed to save the record");
|
1529
|
-
return item;
|
1873
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1874
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1530
1875
|
};
|
1531
1876
|
_deleteRecord = new WeakSet();
|
1532
|
-
deleteRecord_fn = async function(recordId) {
|
1877
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1533
1878
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
await __privateGet$4(this, _cache).delete(key);
|
1879
|
+
try {
|
1880
|
+
const response = await deleteRecord({
|
1881
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1882
|
+
queryParams: { columns },
|
1883
|
+
...fetchProps
|
1884
|
+
});
|
1885
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1886
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1887
|
+
} catch (e) {
|
1888
|
+
if (isObject(e) && e.status === 404) {
|
1889
|
+
return null;
|
1890
|
+
}
|
1891
|
+
throw e;
|
1548
1892
|
}
|
1549
1893
|
};
|
1550
|
-
_setCacheRecord = new WeakSet();
|
1551
|
-
setCacheRecord_fn = async function(record) {
|
1552
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1553
|
-
return;
|
1554
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1555
|
-
};
|
1556
|
-
_getCacheRecord = new WeakSet();
|
1557
|
-
getCacheRecord_fn = async function(recordId) {
|
1558
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1559
|
-
return null;
|
1560
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1561
|
-
};
|
1562
1894
|
_setCacheQuery = new WeakSet();
|
1563
1895
|
setCacheQuery_fn = async function(query, meta, records) {
|
1564
1896
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1575,17 +1907,17 @@ getCacheQuery_fn = async function(query) {
|
|
1575
1907
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1576
1908
|
return hasExpired ? null : result;
|
1577
1909
|
};
|
1578
|
-
|
1579
|
-
|
1580
|
-
if (__privateGet$4(this,
|
1581
|
-
return __privateGet$4(this,
|
1910
|
+
_getSchemaTables$1 = new WeakSet();
|
1911
|
+
getSchemaTables_fn$1 = async function() {
|
1912
|
+
if (__privateGet$4(this, _schemaTables$2))
|
1913
|
+
return __privateGet$4(this, _schemaTables$2);
|
1582
1914
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1583
1915
|
const { schema } = await getBranchDetails({
|
1584
1916
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1585
1917
|
...fetchProps
|
1586
1918
|
});
|
1587
|
-
__privateSet$
|
1588
|
-
return schema;
|
1919
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1920
|
+
return schema.tables;
|
1589
1921
|
};
|
1590
1922
|
const transformObjectLinks = (object) => {
|
1591
1923
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
@@ -1594,11 +1926,11 @@ const transformObjectLinks = (object) => {
|
|
1594
1926
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1595
1927
|
}, {});
|
1596
1928
|
};
|
1597
|
-
const initObject = (db,
|
1929
|
+
const initObject = (db, schemaTables, table, object) => {
|
1598
1930
|
const result = {};
|
1599
1931
|
const { xata, ...rest } = object ?? {};
|
1600
1932
|
Object.assign(result, rest);
|
1601
|
-
const { columns } =
|
1933
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1602
1934
|
if (!columns)
|
1603
1935
|
console.error(`Table ${table} not found in schema`);
|
1604
1936
|
for (const column of columns ?? []) {
|
@@ -1618,17 +1950,17 @@ const initObject = (db, schema, table, object) => {
|
|
1618
1950
|
if (!linkTable) {
|
1619
1951
|
console.error(`Failed to parse link for field ${column.name}`);
|
1620
1952
|
} else if (isObject(value)) {
|
1621
|
-
result[column.name] = initObject(db,
|
1953
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
1622
1954
|
}
|
1623
1955
|
break;
|
1624
1956
|
}
|
1625
1957
|
}
|
1626
1958
|
}
|
1627
|
-
result.read = function() {
|
1628
|
-
return db[table].read(result["id"]);
|
1959
|
+
result.read = function(columns2) {
|
1960
|
+
return db[table].read(result["id"], columns2);
|
1629
1961
|
};
|
1630
|
-
result.update = function(data) {
|
1631
|
-
return db[table].update(result["id"], data);
|
1962
|
+
result.update = function(data, columns2) {
|
1963
|
+
return db[table].update(result["id"], data, columns2);
|
1632
1964
|
};
|
1633
1965
|
result.delete = function() {
|
1634
1966
|
return db[table].delete(result["id"]);
|
@@ -1642,14 +1974,21 @@ const initObject = (db, schema, table, object) => {
|
|
1642
1974
|
Object.freeze(result);
|
1643
1975
|
return result;
|
1644
1976
|
};
|
1645
|
-
function
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
if (
|
1650
|
-
return
|
1651
|
-
|
1652
|
-
|
1977
|
+
function isResponseWithRecords(value) {
|
1978
|
+
return isObject(value) && Array.isArray(value.records);
|
1979
|
+
}
|
1980
|
+
function extractId(value) {
|
1981
|
+
if (isString(value))
|
1982
|
+
return value;
|
1983
|
+
if (isObject(value) && isString(value.id))
|
1984
|
+
return value.id;
|
1985
|
+
return void 0;
|
1986
|
+
}
|
1987
|
+
function cleanFilter(filter) {
|
1988
|
+
if (!filter)
|
1989
|
+
return void 0;
|
1990
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1991
|
+
return values.length > 0 ? filter : void 0;
|
1653
1992
|
}
|
1654
1993
|
|
1655
1994
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1665,7 +2004,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1665
2004
|
throw TypeError("Cannot add the same private member more than once");
|
1666
2005
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1667
2006
|
};
|
1668
|
-
var __privateSet$
|
2007
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1669
2008
|
__accessCheck$3(obj, member, "write to private field");
|
1670
2009
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1671
2010
|
return value;
|
@@ -1674,9 +2013,8 @@ var _map;
|
|
1674
2013
|
class SimpleCache {
|
1675
2014
|
constructor(options = {}) {
|
1676
2015
|
__privateAdd$3(this, _map, void 0);
|
1677
|
-
__privateSet$
|
2016
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1678
2017
|
this.capacity = options.max ?? 500;
|
1679
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1680
2018
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1681
2019
|
}
|
1682
2020
|
async getAll() {
|
@@ -1702,18 +2040,25 @@ class SimpleCache {
|
|
1702
2040
|
}
|
1703
2041
|
_map = new WeakMap();
|
1704
2042
|
|
1705
|
-
const
|
1706
|
-
const
|
1707
|
-
const
|
1708
|
-
const
|
1709
|
-
const
|
1710
|
-
const
|
2043
|
+
const greaterThan = (value) => ({ $gt: value });
|
2044
|
+
const gt = greaterThan;
|
2045
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2046
|
+
const greaterEquals = greaterThanEquals;
|
2047
|
+
const gte = greaterThanEquals;
|
2048
|
+
const ge = greaterThanEquals;
|
2049
|
+
const lessThan = (value) => ({ $lt: value });
|
2050
|
+
const lt = lessThan;
|
2051
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2052
|
+
const lessEquals = lessThanEquals;
|
2053
|
+
const lte = lessThanEquals;
|
2054
|
+
const le = lessThanEquals;
|
1711
2055
|
const exists = (column) => ({ $exists: column });
|
1712
2056
|
const notExists = (column) => ({ $notExists: column });
|
1713
2057
|
const startsWith = (value) => ({ $startsWith: value });
|
1714
2058
|
const endsWith = (value) => ({ $endsWith: value });
|
1715
2059
|
const pattern = (value) => ({ $pattern: value });
|
1716
2060
|
const is = (value) => ({ $is: value });
|
2061
|
+
const equals = is;
|
1717
2062
|
const isNot = (value) => ({ $isNot: value });
|
1718
2063
|
const contains = (value) => ({ $contains: value });
|
1719
2064
|
const includes = (value) => ({ $includes: value });
|
@@ -1734,31 +2079,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1734
2079
|
throw TypeError("Cannot add the same private member more than once");
|
1735
2080
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1736
2081
|
};
|
1737
|
-
var
|
2082
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
2083
|
+
__accessCheck$2(obj, member, "write to private field");
|
2084
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
2085
|
+
return value;
|
2086
|
+
};
|
2087
|
+
var _tables, _schemaTables$1;
|
1738
2088
|
class SchemaPlugin extends XataPlugin {
|
1739
|
-
constructor(
|
2089
|
+
constructor(schemaTables) {
|
1740
2090
|
super();
|
1741
|
-
this.tableNames = tableNames;
|
1742
2091
|
__privateAdd$2(this, _tables, {});
|
2092
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
2093
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1743
2094
|
}
|
1744
2095
|
build(pluginOptions) {
|
1745
|
-
const db = new Proxy(
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
2096
|
+
const db = new Proxy(
|
2097
|
+
{},
|
2098
|
+
{
|
2099
|
+
get: (_target, table) => {
|
2100
|
+
if (!isString(table))
|
2101
|
+
throw new Error("Invalid table name");
|
2102
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2103
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2104
|
+
}
|
2105
|
+
return __privateGet$2(this, _tables)[table];
|
1751
2106
|
}
|
1752
|
-
return __privateGet$2(this, _tables)[table];
|
1753
2107
|
}
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
2108
|
+
);
|
2109
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
2110
|
+
for (const table of tableNames) {
|
2111
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1757
2112
|
}
|
1758
2113
|
return db;
|
1759
2114
|
}
|
1760
2115
|
}
|
1761
2116
|
_tables = new WeakMap();
|
2117
|
+
_schemaTables$1 = new WeakMap();
|
1762
2118
|
|
1763
2119
|
var __accessCheck$1 = (obj, member, msg) => {
|
1764
2120
|
if (!member.has(obj))
|
@@ -1782,82 +2138,77 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1782
2138
|
__accessCheck$1(obj, member, "access private method");
|
1783
2139
|
return method;
|
1784
2140
|
};
|
1785
|
-
var
|
2141
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1786
2142
|
class SearchPlugin extends XataPlugin {
|
1787
|
-
constructor(db) {
|
2143
|
+
constructor(db, schemaTables) {
|
1788
2144
|
super();
|
1789
2145
|
this.db = db;
|
1790
2146
|
__privateAdd$1(this, _search);
|
1791
|
-
__privateAdd$1(this,
|
1792
|
-
__privateAdd$1(this,
|
2147
|
+
__privateAdd$1(this, _getSchemaTables);
|
2148
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
2149
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1793
2150
|
}
|
1794
2151
|
build({ getFetchProps }) {
|
1795
2152
|
return {
|
1796
2153
|
all: async (query, options = {}) => {
|
1797
2154
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1798
|
-
const
|
2155
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1799
2156
|
return records.map((record) => {
|
1800
2157
|
const { table = "orphan" } = record.xata;
|
1801
|
-
return { table, record: initObject(this.db,
|
2158
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
1802
2159
|
});
|
1803
2160
|
},
|
1804
2161
|
byTable: async (query, options = {}) => {
|
1805
2162
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1806
|
-
const
|
2163
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1807
2164
|
return records.reduce((acc, record) => {
|
1808
2165
|
const { table = "orphan" } = record.xata;
|
1809
2166
|
const items = acc[table] ?? [];
|
1810
|
-
const item = initObject(this.db,
|
2167
|
+
const item = initObject(this.db, schemaTables, table, record);
|
1811
2168
|
return { ...acc, [table]: [...items, item] };
|
1812
2169
|
}, {});
|
1813
2170
|
}
|
1814
2171
|
};
|
1815
2172
|
}
|
1816
2173
|
}
|
1817
|
-
|
2174
|
+
_schemaTables = new WeakMap();
|
1818
2175
|
_search = new WeakSet();
|
1819
2176
|
search_fn = async function(query, options, getFetchProps) {
|
1820
2177
|
const fetchProps = await getFetchProps();
|
1821
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
2178
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1822
2179
|
const { records } = await searchBranch({
|
1823
2180
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1824
|
-
body: { tables, query, fuzziness, highlight },
|
2181
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1825
2182
|
...fetchProps
|
1826
2183
|
});
|
1827
2184
|
return records;
|
1828
2185
|
};
|
1829
|
-
|
1830
|
-
|
1831
|
-
if (__privateGet$1(this,
|
1832
|
-
return __privateGet$1(this,
|
2186
|
+
_getSchemaTables = new WeakSet();
|
2187
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
2188
|
+
if (__privateGet$1(this, _schemaTables))
|
2189
|
+
return __privateGet$1(this, _schemaTables);
|
1833
2190
|
const fetchProps = await getFetchProps();
|
1834
2191
|
const { schema } = await getBranchDetails({
|
1835
2192
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1836
2193
|
...fetchProps
|
1837
2194
|
});
|
1838
|
-
__privateSet$1(this,
|
1839
|
-
return schema;
|
2195
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
2196
|
+
return schema.tables;
|
1840
2197
|
};
|
1841
2198
|
|
1842
2199
|
const isBranchStrategyBuilder = (strategy) => {
|
1843
2200
|
return typeof strategy === "function";
|
1844
2201
|
};
|
1845
2202
|
|
1846
|
-
const envBranchNames = [
|
1847
|
-
"XATA_BRANCH",
|
1848
|
-
"VERCEL_GIT_COMMIT_REF",
|
1849
|
-
"CF_PAGES_BRANCH",
|
1850
|
-
"BRANCH"
|
1851
|
-
];
|
1852
2203
|
async function getCurrentBranchName(options) {
|
1853
|
-
const
|
1854
|
-
if (
|
1855
|
-
const details = await getDatabaseBranch(
|
2204
|
+
const { branch, envBranch } = getEnvironment();
|
2205
|
+
if (branch) {
|
2206
|
+
const details = await getDatabaseBranch(branch, options);
|
1856
2207
|
if (details)
|
1857
|
-
return
|
1858
|
-
console.warn(`Branch ${
|
2208
|
+
return branch;
|
2209
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1859
2210
|
}
|
1860
|
-
const gitBranch = await getGitBranch();
|
2211
|
+
const gitBranch = envBranch || await getGitBranch();
|
1861
2212
|
return resolveXataBranch(gitBranch, options);
|
1862
2213
|
}
|
1863
2214
|
async function getCurrentBranchDetails(options) {
|
@@ -1868,18 +2219,24 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1868
2219
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1869
2220
|
const apiKey = options?.apiKey || getAPIKey();
|
1870
2221
|
if (!databaseURL)
|
1871
|
-
throw new Error(
|
2222
|
+
throw new Error(
|
2223
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2224
|
+
);
|
1872
2225
|
if (!apiKey)
|
1873
|
-
throw new Error(
|
2226
|
+
throw new Error(
|
2227
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2228
|
+
);
|
1874
2229
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1875
2230
|
const [workspace] = host.split(".");
|
2231
|
+
const { fallbackBranch } = getEnvironment();
|
1876
2232
|
const { branch } = await resolveBranch({
|
1877
2233
|
apiKey,
|
1878
2234
|
apiUrl: databaseURL,
|
1879
2235
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1880
2236
|
workspacesApiUrl: `${protocol}//${host}`,
|
1881
2237
|
pathParams: { dbName, workspace },
|
1882
|
-
queryParams: { gitBranch, fallbackBranch
|
2238
|
+
queryParams: { gitBranch, fallbackBranch },
|
2239
|
+
trace: defaultTrace
|
1883
2240
|
});
|
1884
2241
|
return branch;
|
1885
2242
|
}
|
@@ -1887,9 +2244,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1887
2244
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1888
2245
|
const apiKey = options?.apiKey || getAPIKey();
|
1889
2246
|
if (!databaseURL)
|
1890
|
-
throw new Error(
|
2247
|
+
throw new Error(
|
2248
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2249
|
+
);
|
1891
2250
|
if (!apiKey)
|
1892
|
-
throw new Error(
|
2251
|
+
throw new Error(
|
2252
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2253
|
+
);
|
1893
2254
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1894
2255
|
const [workspace] = host.split(".");
|
1895
2256
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1899,7 +2260,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1899
2260
|
apiUrl: databaseURL,
|
1900
2261
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1901
2262
|
workspacesApiUrl: `${protocol}//${host}`,
|
1902
|
-
pathParams: { dbBranchName, workspace }
|
2263
|
+
pathParams: { dbBranchName, workspace },
|
2264
|
+
trace: defaultTrace
|
1903
2265
|
});
|
1904
2266
|
} catch (err) {
|
1905
2267
|
if (isObject(err) && err.status === 404)
|
@@ -1907,21 +2269,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1907
2269
|
throw err;
|
1908
2270
|
}
|
1909
2271
|
}
|
1910
|
-
function getBranchByEnvVariable() {
|
1911
|
-
for (const name of envBranchNames) {
|
1912
|
-
const value = getEnvVariable(name);
|
1913
|
-
if (value) {
|
1914
|
-
return value;
|
1915
|
-
}
|
1916
|
-
}
|
1917
|
-
try {
|
1918
|
-
return XATA_BRANCH;
|
1919
|
-
} catch (err) {
|
1920
|
-
}
|
1921
|
-
}
|
1922
2272
|
function getDatabaseURL() {
|
1923
2273
|
try {
|
1924
|
-
|
2274
|
+
const { databaseURL } = getEnvironment();
|
2275
|
+
return databaseURL;
|
1925
2276
|
} catch (err) {
|
1926
2277
|
return void 0;
|
1927
2278
|
}
|
@@ -1950,20 +2301,23 @@ var __privateMethod = (obj, member, method) => {
|
|
1950
2301
|
return method;
|
1951
2302
|
};
|
1952
2303
|
const buildClient = (plugins) => {
|
1953
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2304
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1954
2305
|
return _a = class {
|
1955
|
-
constructor(options = {},
|
2306
|
+
constructor(options = {}, schemaTables) {
|
1956
2307
|
__privateAdd(this, _parseOptions);
|
1957
2308
|
__privateAdd(this, _getFetchProps);
|
1958
2309
|
__privateAdd(this, _evaluateBranch);
|
1959
2310
|
__privateAdd(this, _branch, void 0);
|
2311
|
+
__privateAdd(this, _options, void 0);
|
1960
2312
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2313
|
+
__privateSet(this, _options, safeOptions);
|
1961
2314
|
const pluginOptions = {
|
1962
2315
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1963
|
-
cache: safeOptions.cache
|
2316
|
+
cache: safeOptions.cache,
|
2317
|
+
trace: safeOptions.trace
|
1964
2318
|
};
|
1965
|
-
const db = new SchemaPlugin(
|
1966
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
2319
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2320
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1967
2321
|
this.db = db;
|
1968
2322
|
this.search = search;
|
1969
2323
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
@@ -1979,22 +2333,26 @@ const buildClient = (plugins) => {
|
|
1979
2333
|
}
|
1980
2334
|
}
|
1981
2335
|
}
|
1982
|
-
|
2336
|
+
async getConfig() {
|
2337
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2338
|
+
const branch = await __privateGet(this, _options).branch();
|
2339
|
+
return { databaseURL, branch };
|
2340
|
+
}
|
2341
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1983
2342
|
const fetch = getFetchImplementation(options?.fetch);
|
1984
2343
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1985
2344
|
const apiKey = options?.apiKey || getAPIKey();
|
1986
|
-
const cache = options?.cache ?? new SimpleCache({
|
2345
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2346
|
+
const trace = options?.trace ?? defaultTrace;
|
1987
2347
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1988
|
-
if (!
|
1989
|
-
throw new Error("
|
2348
|
+
if (!apiKey) {
|
2349
|
+
throw new Error("Option apiKey is required");
|
1990
2350
|
}
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
apiKey,
|
1995
|
-
|
1996
|
-
branch
|
1997
|
-
}) {
|
2351
|
+
if (!databaseURL) {
|
2352
|
+
throw new Error("Option databaseURL is required");
|
2353
|
+
}
|
2354
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2355
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
1998
2356
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1999
2357
|
if (!branchValue)
|
2000
2358
|
throw new Error("Unable to resolve branch value");
|
@@ -2004,9 +2362,10 @@ const buildClient = (plugins) => {
|
|
2004
2362
|
apiUrl: "",
|
2005
2363
|
workspacesApiUrl: (path, params) => {
|
2006
2364
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2007
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2365
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2008
2366
|
return databaseURL + newPath;
|
2009
|
-
}
|
2367
|
+
},
|
2368
|
+
trace
|
2010
2369
|
};
|
2011
2370
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2012
2371
|
if (__privateGet(this, _branch))
|
@@ -2029,6 +2388,88 @@ const buildClient = (plugins) => {
|
|
2029
2388
|
class BaseClient extends buildClient() {
|
2030
2389
|
}
|
2031
2390
|
|
2391
|
+
const META = "__";
|
2392
|
+
const VALUE = "___";
|
2393
|
+
class Serializer {
|
2394
|
+
constructor() {
|
2395
|
+
this.classes = {};
|
2396
|
+
}
|
2397
|
+
add(clazz) {
|
2398
|
+
this.classes[clazz.name] = clazz;
|
2399
|
+
}
|
2400
|
+
toJSON(data) {
|
2401
|
+
function visit(obj) {
|
2402
|
+
if (Array.isArray(obj))
|
2403
|
+
return obj.map(visit);
|
2404
|
+
const type = typeof obj;
|
2405
|
+
if (type === "undefined")
|
2406
|
+
return { [META]: "undefined" };
|
2407
|
+
if (type === "bigint")
|
2408
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2409
|
+
if (obj === null || type !== "object")
|
2410
|
+
return obj;
|
2411
|
+
const constructor = obj.constructor;
|
2412
|
+
const o = { [META]: constructor.name };
|
2413
|
+
for (const [key, value] of Object.entries(obj)) {
|
2414
|
+
o[key] = visit(value);
|
2415
|
+
}
|
2416
|
+
if (constructor === Date)
|
2417
|
+
o[VALUE] = obj.toISOString();
|
2418
|
+
if (constructor === Map)
|
2419
|
+
o[VALUE] = Object.fromEntries(obj);
|
2420
|
+
if (constructor === Set)
|
2421
|
+
o[VALUE] = [...obj];
|
2422
|
+
return o;
|
2423
|
+
}
|
2424
|
+
return JSON.stringify(visit(data));
|
2425
|
+
}
|
2426
|
+
fromJSON(json) {
|
2427
|
+
return JSON.parse(json, (key, value) => {
|
2428
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2429
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2430
|
+
const constructor = this.classes[clazz];
|
2431
|
+
if (constructor) {
|
2432
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2433
|
+
}
|
2434
|
+
if (clazz === "Date")
|
2435
|
+
return new Date(val);
|
2436
|
+
if (clazz === "Set")
|
2437
|
+
return new Set(val);
|
2438
|
+
if (clazz === "Map")
|
2439
|
+
return new Map(Object.entries(val));
|
2440
|
+
if (clazz === "bigint")
|
2441
|
+
return BigInt(val);
|
2442
|
+
if (clazz === "undefined")
|
2443
|
+
return void 0;
|
2444
|
+
return rest;
|
2445
|
+
}
|
2446
|
+
return value;
|
2447
|
+
});
|
2448
|
+
}
|
2449
|
+
}
|
2450
|
+
const defaultSerializer = new Serializer();
|
2451
|
+
const serialize = (data) => {
|
2452
|
+
return defaultSerializer.toJSON(data);
|
2453
|
+
};
|
2454
|
+
const deserialize = (json) => {
|
2455
|
+
return defaultSerializer.fromJSON(json);
|
2456
|
+
};
|
2457
|
+
|
2458
|
+
function buildWorkerRunner(config) {
|
2459
|
+
return function xataWorker(name, _worker) {
|
2460
|
+
return async (...args) => {
|
2461
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2462
|
+
const result = await fetch(url, {
|
2463
|
+
method: "POST",
|
2464
|
+
headers: { "Content-Type": "application/json" },
|
2465
|
+
body: serialize({ args })
|
2466
|
+
});
|
2467
|
+
const text = await result.text();
|
2468
|
+
return deserialize(text);
|
2469
|
+
};
|
2470
|
+
};
|
2471
|
+
}
|
2472
|
+
|
2032
2473
|
class XataError extends Error {
|
2033
2474
|
constructor(message, status) {
|
2034
2475
|
super(message);
|
@@ -2049,6 +2490,7 @@ exports.Repository = Repository;
|
|
2049
2490
|
exports.RestRepository = RestRepository;
|
2050
2491
|
exports.SchemaPlugin = SchemaPlugin;
|
2051
2492
|
exports.SearchPlugin = SearchPlugin;
|
2493
|
+
exports.Serializer = Serializer;
|
2052
2494
|
exports.SimpleCache = SimpleCache;
|
2053
2495
|
exports.XataApiClient = XataApiClient;
|
2054
2496
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2057,12 +2499,18 @@ exports.XataPlugin = XataPlugin;
|
|
2057
2499
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2058
2500
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2059
2501
|
exports.addTableColumn = addTableColumn;
|
2502
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
2060
2503
|
exports.buildClient = buildClient;
|
2504
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2061
2505
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2062
2506
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2507
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
2508
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
2509
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2063
2510
|
exports.contains = contains;
|
2064
2511
|
exports.createBranch = createBranch;
|
2065
2512
|
exports.createDatabase = createDatabase;
|
2513
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2066
2514
|
exports.createTable = createTable;
|
2067
2515
|
exports.createUserAPIKey = createUserAPIKey;
|
2068
2516
|
exports.createWorkspace = createWorkspace;
|
@@ -2074,7 +2522,9 @@ exports.deleteTable = deleteTable;
|
|
2074
2522
|
exports.deleteUser = deleteUser;
|
2075
2523
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2076
2524
|
exports.deleteWorkspace = deleteWorkspace;
|
2525
|
+
exports.deserialize = deserialize;
|
2077
2526
|
exports.endsWith = endsWith;
|
2527
|
+
exports.equals = equals;
|
2078
2528
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2079
2529
|
exports.exists = exists;
|
2080
2530
|
exports.ge = ge;
|
@@ -2084,13 +2534,17 @@ exports.getBranchList = getBranchList;
|
|
2084
2534
|
exports.getBranchMetadata = getBranchMetadata;
|
2085
2535
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2086
2536
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
2537
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2087
2538
|
exports.getBranchStats = getBranchStats;
|
2088
2539
|
exports.getColumn = getColumn;
|
2089
2540
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
2090
2541
|
exports.getCurrentBranchName = getCurrentBranchName;
|
2091
2542
|
exports.getDatabaseList = getDatabaseList;
|
2543
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2092
2544
|
exports.getDatabaseURL = getDatabaseURL;
|
2093
2545
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
2546
|
+
exports.getMigrationRequest = getMigrationRequest;
|
2547
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
2094
2548
|
exports.getRecord = getRecord;
|
2095
2549
|
exports.getTableColumns = getTableColumns;
|
2096
2550
|
exports.getTableSchema = getTableSchema;
|
@@ -2099,6 +2553,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2099
2553
|
exports.getWorkspace = getWorkspace;
|
2100
2554
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2101
2555
|
exports.getWorkspacesList = getWorkspacesList;
|
2556
|
+
exports.greaterEquals = greaterEquals;
|
2557
|
+
exports.greaterThan = greaterThan;
|
2558
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2102
2559
|
exports.gt = gt;
|
2103
2560
|
exports.gte = gte;
|
2104
2561
|
exports.includes = includes;
|
@@ -2114,11 +2571,19 @@ exports.isIdentifiable = isIdentifiable;
|
|
2114
2571
|
exports.isNot = isNot;
|
2115
2572
|
exports.isXataRecord = isXataRecord;
|
2116
2573
|
exports.le = le;
|
2574
|
+
exports.lessEquals = lessEquals;
|
2575
|
+
exports.lessThan = lessThan;
|
2576
|
+
exports.lessThanEquals = lessThanEquals;
|
2577
|
+
exports.listMigrationRequests = listMigrationRequests;
|
2578
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
2117
2579
|
exports.lt = lt;
|
2118
2580
|
exports.lte = lte;
|
2581
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2119
2582
|
exports.notExists = notExists;
|
2120
2583
|
exports.operationsByTag = operationsByTag;
|
2584
|
+
exports.patchDatabaseMetadata = patchDatabaseMetadata;
|
2121
2585
|
exports.pattern = pattern;
|
2586
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
2122
2587
|
exports.queryTable = queryTable;
|
2123
2588
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2124
2589
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
@@ -2126,14 +2591,18 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2126
2591
|
exports.resolveBranch = resolveBranch;
|
2127
2592
|
exports.searchBranch = searchBranch;
|
2128
2593
|
exports.searchTable = searchTable;
|
2594
|
+
exports.serialize = serialize;
|
2129
2595
|
exports.setTableSchema = setTableSchema;
|
2130
2596
|
exports.startsWith = startsWith;
|
2131
2597
|
exports.updateBranchMetadata = updateBranchMetadata;
|
2598
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2132
2599
|
exports.updateColumn = updateColumn;
|
2600
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2133
2601
|
exports.updateRecordWithID = updateRecordWithID;
|
2134
2602
|
exports.updateTable = updateTable;
|
2135
2603
|
exports.updateUser = updateUser;
|
2136
2604
|
exports.updateWorkspace = updateWorkspace;
|
2605
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2137
2606
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2138
2607
|
exports.upsertRecordWithID = upsertRecordWithID;
|
2139
2608
|
//# sourceMappingURL=index.cjs.map
|