@xata.io/client 0.0.0-alpha.veb4417f → 0.0.0-alpha.vec88a57
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 +124 -0
- package/README.md +67 -52
- package/Usage.md +449 -0
- package/dist/index.cjs +714 -394
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +726 -180
- package/dist/index.mjs +683 -395
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,48 @@
|
|
|
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
|
+
onError: () => {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const TraceAttributes = {
|
|
34
|
+
VERSION: "xata.sdk.version",
|
|
35
|
+
TABLE: "xata.table",
|
|
36
|
+
HTTP_REQUEST_ID: "http.request_id",
|
|
37
|
+
HTTP_STATUS_CODE: "http.status_code",
|
|
38
|
+
HTTP_HOST: "http.host",
|
|
39
|
+
HTTP_SCHEME: "http.scheme",
|
|
40
|
+
HTTP_USER_AGENT: "http.user_agent",
|
|
41
|
+
HTTP_METHOD: "http.method",
|
|
42
|
+
HTTP_URL: "http.url",
|
|
43
|
+
HTTP_ROUTE: "http.route",
|
|
44
|
+
HTTP_TARGET: "http.target"
|
|
45
|
+
};
|
|
46
|
+
|
|
5
47
|
function notEmpty(value) {
|
|
6
48
|
return value !== null && value !== void 0;
|
|
7
49
|
}
|
|
@@ -17,43 +59,95 @@ function isDefined(value) {
|
|
|
17
59
|
function isString(value) {
|
|
18
60
|
return isDefined(value) && typeof value === "string";
|
|
19
61
|
}
|
|
62
|
+
function isStringArray(value) {
|
|
63
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
|
64
|
+
}
|
|
20
65
|
function toBase64(value) {
|
|
21
66
|
try {
|
|
22
67
|
return btoa(value);
|
|
23
68
|
} catch (err) {
|
|
24
|
-
|
|
69
|
+
const buf = Buffer;
|
|
70
|
+
return buf.from(value).toString("base64");
|
|
25
71
|
}
|
|
26
72
|
}
|
|
27
73
|
|
|
28
|
-
function
|
|
74
|
+
function getEnvironment() {
|
|
29
75
|
try {
|
|
30
|
-
if (isObject(process) &&
|
|
31
|
-
return
|
|
76
|
+
if (isObject(process) && isObject(process.env)) {
|
|
77
|
+
return {
|
|
78
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
|
79
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
|
80
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
|
81
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
|
82
|
+
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
|
83
|
+
};
|
|
32
84
|
}
|
|
33
85
|
} catch (err) {
|
|
34
86
|
}
|
|
35
87
|
try {
|
|
36
|
-
if (isObject(Deno) &&
|
|
37
|
-
return
|
|
88
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
|
89
|
+
return {
|
|
90
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
|
91
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
|
92
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
|
93
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
|
94
|
+
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
|
95
|
+
};
|
|
38
96
|
}
|
|
39
97
|
} catch (err) {
|
|
40
98
|
}
|
|
99
|
+
return {
|
|
100
|
+
apiKey: getGlobalApiKey(),
|
|
101
|
+
databaseURL: getGlobalDatabaseURL(),
|
|
102
|
+
branch: getGlobalBranch(),
|
|
103
|
+
envBranch: void 0,
|
|
104
|
+
fallbackBranch: getGlobalFallbackBranch()
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function getGlobalApiKey() {
|
|
108
|
+
try {
|
|
109
|
+
return XATA_API_KEY;
|
|
110
|
+
} catch (err) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function getGlobalDatabaseURL() {
|
|
115
|
+
try {
|
|
116
|
+
return XATA_DATABASE_URL;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
return void 0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function getGlobalBranch() {
|
|
122
|
+
try {
|
|
123
|
+
return XATA_BRANCH;
|
|
124
|
+
} catch (err) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function getGlobalFallbackBranch() {
|
|
129
|
+
try {
|
|
130
|
+
return XATA_FALLBACK_BRANCH;
|
|
131
|
+
} catch (err) {
|
|
132
|
+
return void 0;
|
|
133
|
+
}
|
|
41
134
|
}
|
|
42
135
|
async function getGitBranch() {
|
|
136
|
+
const cmd = ["git", "branch", "--show-current"];
|
|
137
|
+
const fullCmd = cmd.join(" ");
|
|
138
|
+
const nodeModule = ["child", "process"].join("_");
|
|
139
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
|
43
140
|
try {
|
|
44
141
|
if (typeof require === "function") {
|
|
45
|
-
|
|
46
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
|
142
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
|
47
143
|
}
|
|
144
|
+
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
|
145
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
|
48
146
|
} catch (err) {
|
|
49
147
|
}
|
|
50
148
|
try {
|
|
51
149
|
if (isObject(Deno)) {
|
|
52
|
-
const process2 = Deno.run({
|
|
53
|
-
cmd: ["git", "branch", "--show-current"],
|
|
54
|
-
stdout: "piped",
|
|
55
|
-
stderr: "piped"
|
|
56
|
-
});
|
|
150
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
|
57
151
|
return new TextDecoder().decode(await process2.output()).trim();
|
|
58
152
|
}
|
|
59
153
|
} catch (err) {
|
|
@@ -62,7 +156,8 @@ async function getGitBranch() {
|
|
|
62
156
|
|
|
63
157
|
function getAPIKey() {
|
|
64
158
|
try {
|
|
65
|
-
|
|
159
|
+
const { apiKey } = getEnvironment();
|
|
160
|
+
return apiKey;
|
|
66
161
|
} catch (err) {
|
|
67
162
|
return void 0;
|
|
68
163
|
}
|
|
@@ -72,26 +167,35 @@ function getFetchImplementation(userFetch) {
|
|
|
72
167
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
|
73
168
|
const fetchImpl = userFetch ?? globalFetch;
|
|
74
169
|
if (!fetchImpl) {
|
|
75
|
-
throw new Error(
|
|
170
|
+
throw new Error(
|
|
171
|
+
`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
|
|
172
|
+
);
|
|
76
173
|
}
|
|
77
174
|
return fetchImpl;
|
|
78
175
|
}
|
|
79
176
|
|
|
177
|
+
const VERSION = "0.0.0-alpha.vec88a57";
|
|
178
|
+
|
|
80
179
|
class ErrorWithCause extends Error {
|
|
81
180
|
constructor(message, options) {
|
|
82
181
|
super(message, options);
|
|
83
182
|
}
|
|
84
183
|
}
|
|
85
184
|
class FetcherError extends ErrorWithCause {
|
|
86
|
-
constructor(status, data) {
|
|
185
|
+
constructor(status, data, requestId) {
|
|
87
186
|
super(getMessage(data));
|
|
88
187
|
this.status = status;
|
|
89
188
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
|
189
|
+
this.requestId = requestId;
|
|
90
190
|
if (data instanceof Error) {
|
|
91
191
|
this.stack = data.stack;
|
|
92
192
|
this.cause = data.cause;
|
|
93
193
|
}
|
|
94
194
|
}
|
|
195
|
+
toString() {
|
|
196
|
+
const error = super.toString();
|
|
197
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
|
198
|
+
}
|
|
95
199
|
}
|
|
96
200
|
function isBulkError(error) {
|
|
97
201
|
return isObject(error) && Array.isArray(error.errors);
|
|
@@ -114,7 +218,12 @@ function getMessage(data) {
|
|
|
114
218
|
}
|
|
115
219
|
|
|
116
220
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
117
|
-
const
|
|
221
|
+
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
|
222
|
+
if (value === void 0 || value === null)
|
|
223
|
+
return acc;
|
|
224
|
+
return { ...acc, [key]: value };
|
|
225
|
+
}, {});
|
|
226
|
+
const query = new URLSearchParams(cleanQueryParams).toString();
|
|
118
227
|
const queryString = query.length > 0 ? `?${query}` : "";
|
|
119
228
|
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
|
|
120
229
|
};
|
|
@@ -144,32 +253,62 @@ async function fetch$1({
|
|
|
144
253
|
fetchImpl,
|
|
145
254
|
apiKey,
|
|
146
255
|
apiUrl,
|
|
147
|
-
workspacesApiUrl
|
|
256
|
+
workspacesApiUrl,
|
|
257
|
+
trace
|
|
148
258
|
}) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
259
|
+
return trace(
|
|
260
|
+
`${method.toUpperCase()} ${path}`,
|
|
261
|
+
async ({ setAttributes, onError }) => {
|
|
262
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
|
263
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
|
264
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
|
265
|
+
setAttributes({
|
|
266
|
+
[TraceAttributes.HTTP_URL]: url,
|
|
267
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
|
268
|
+
});
|
|
269
|
+
const response = await fetchImpl(url, {
|
|
270
|
+
method: method.toUpperCase(),
|
|
271
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
272
|
+
headers: {
|
|
273
|
+
"Content-Type": "application/json",
|
|
274
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
|
275
|
+
...headers,
|
|
276
|
+
...hostHeader(fullUrl),
|
|
277
|
+
Authorization: `Bearer ${apiKey}`
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
if (response.status === 204) {
|
|
281
|
+
return {};
|
|
282
|
+
}
|
|
283
|
+
const { host, protocol } = parseUrl(response.url);
|
|
284
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
|
285
|
+
setAttributes({
|
|
286
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
|
287
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
|
288
|
+
[TraceAttributes.HTTP_HOST]: host,
|
|
289
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
const jsonResponse = await response.json();
|
|
293
|
+
if (response.ok) {
|
|
294
|
+
return jsonResponse;
|
|
295
|
+
}
|
|
296
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
const fetcherError = new FetcherError(response.status, error, requestId);
|
|
299
|
+
onError(fetcherError.message);
|
|
300
|
+
throw fetcherError;
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
function parseUrl(url) {
|
|
165
307
|
try {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
return jsonResponse;
|
|
169
|
-
}
|
|
170
|
-
throw new FetcherError(response.status, jsonResponse);
|
|
308
|
+
const { host, protocol } = new URL(url);
|
|
309
|
+
return { host, protocol };
|
|
171
310
|
} catch (error) {
|
|
172
|
-
|
|
311
|
+
return {};
|
|
173
312
|
}
|
|
174
313
|
}
|
|
175
314
|
|
|
@@ -228,6 +367,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
|
228
367
|
...variables
|
|
229
368
|
});
|
|
230
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 });
|
|
231
371
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
|
232
372
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
|
233
373
|
method: "delete",
|
|
@@ -263,6 +403,11 @@ const deleteDatabase = (variables) => fetch$1({
|
|
|
263
403
|
method: "delete",
|
|
264
404
|
...variables
|
|
265
405
|
});
|
|
406
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
|
407
|
+
url: "/dbs/{dbName}/metadata",
|
|
408
|
+
method: "get",
|
|
409
|
+
...variables
|
|
410
|
+
});
|
|
266
411
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
|
267
412
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
|
268
413
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
|
@@ -276,11 +421,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
|
276
421
|
method: "get",
|
|
277
422
|
...variables
|
|
278
423
|
});
|
|
279
|
-
const createBranch = (variables) => fetch$1({
|
|
280
|
-
url: "/db/{dbBranchName}",
|
|
281
|
-
method: "put",
|
|
282
|
-
...variables
|
|
283
|
-
});
|
|
424
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
|
284
425
|
const deleteBranch = (variables) => fetch$1({
|
|
285
426
|
url: "/db/{dbBranchName}",
|
|
286
427
|
method: "delete",
|
|
@@ -354,11 +495,7 @@ const updateColumn = (variables) => fetch$1({
|
|
|
354
495
|
method: "patch",
|
|
355
496
|
...variables
|
|
356
497
|
});
|
|
357
|
-
const insertRecord = (variables) => fetch$1({
|
|
358
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
|
359
|
-
method: "post",
|
|
360
|
-
...variables
|
|
361
|
-
});
|
|
498
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
|
362
499
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
|
363
500
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
|
364
501
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
|
@@ -400,6 +537,7 @@ const operationsByTag = {
|
|
|
400
537
|
updateWorkspaceMemberRole,
|
|
401
538
|
removeWorkspaceMember,
|
|
402
539
|
inviteWorkspaceMember,
|
|
540
|
+
updateWorkspaceMemberInvite,
|
|
403
541
|
cancelWorkspaceMemberInvite,
|
|
404
542
|
resendWorkspaceMemberInvite,
|
|
405
543
|
acceptWorkspaceMemberInvite
|
|
@@ -408,6 +546,7 @@ const operationsByTag = {
|
|
|
408
546
|
getDatabaseList,
|
|
409
547
|
createDatabase,
|
|
410
548
|
deleteDatabase,
|
|
549
|
+
getDatabaseMetadata,
|
|
411
550
|
getGitBranchesMapping,
|
|
412
551
|
addGitBranchesEntry,
|
|
413
552
|
removeGitBranchesEntry,
|
|
@@ -489,7 +628,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
|
489
628
|
throw TypeError("Cannot add the same private member more than once");
|
|
490
629
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
491
630
|
};
|
|
492
|
-
var __privateSet$
|
|
631
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
|
493
632
|
__accessCheck$7(obj, member, "write to private field");
|
|
494
633
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
495
634
|
return value;
|
|
@@ -500,15 +639,17 @@ class XataApiClient {
|
|
|
500
639
|
__privateAdd$7(this, _extraProps, void 0);
|
|
501
640
|
__privateAdd$7(this, _namespaces, {});
|
|
502
641
|
const provider = options.host ?? "production";
|
|
503
|
-
const apiKey = options
|
|
642
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
|
643
|
+
const trace = options.trace ?? defaultTrace;
|
|
504
644
|
if (!apiKey) {
|
|
505
645
|
throw new Error("Could not resolve a valid apiKey");
|
|
506
646
|
}
|
|
507
|
-
__privateSet$
|
|
647
|
+
__privateSet$7(this, _extraProps, {
|
|
508
648
|
apiUrl: getHostUrl(provider, "main"),
|
|
509
649
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
|
510
650
|
fetchImpl: getFetchImplementation(options.fetch),
|
|
511
|
-
apiKey
|
|
651
|
+
apiKey,
|
|
652
|
+
trace
|
|
512
653
|
});
|
|
513
654
|
}
|
|
514
655
|
get user() {
|
|
@@ -631,6 +772,13 @@ class WorkspaceApi {
|
|
|
631
772
|
...this.extraProps
|
|
632
773
|
});
|
|
633
774
|
}
|
|
775
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
|
776
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
|
777
|
+
pathParams: { workspaceId, inviteId },
|
|
778
|
+
body: { role },
|
|
779
|
+
...this.extraProps
|
|
780
|
+
});
|
|
781
|
+
}
|
|
634
782
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
|
635
783
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
|
636
784
|
pathParams: { workspaceId, inviteId },
|
|
@@ -673,6 +821,12 @@ class DatabaseApi {
|
|
|
673
821
|
...this.extraProps
|
|
674
822
|
});
|
|
675
823
|
}
|
|
824
|
+
getDatabaseMetadata(workspace, dbName) {
|
|
825
|
+
return operationsByTag.database.getDatabaseMetadata({
|
|
826
|
+
pathParams: { workspace, dbName },
|
|
827
|
+
...this.extraProps
|
|
828
|
+
});
|
|
829
|
+
}
|
|
676
830
|
getGitBranchesMapping(workspace, dbName) {
|
|
677
831
|
return operationsByTag.database.getGitBranchesMapping({
|
|
678
832
|
pathParams: { workspace, dbName },
|
|
@@ -693,10 +847,10 @@ class DatabaseApi {
|
|
|
693
847
|
...this.extraProps
|
|
694
848
|
});
|
|
695
849
|
}
|
|
696
|
-
resolveBranch(workspace, dbName, gitBranch) {
|
|
850
|
+
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
|
697
851
|
return operationsByTag.database.resolveBranch({
|
|
698
852
|
pathParams: { workspace, dbName },
|
|
699
|
-
queryParams: { gitBranch },
|
|
853
|
+
queryParams: { gitBranch, fallbackBranch },
|
|
700
854
|
...this.extraProps
|
|
701
855
|
});
|
|
702
856
|
}
|
|
@@ -845,9 +999,10 @@ class RecordsApi {
|
|
|
845
999
|
constructor(extraProps) {
|
|
846
1000
|
this.extraProps = extraProps;
|
|
847
1001
|
}
|
|
848
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
|
1002
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
|
849
1003
|
return operationsByTag.records.insertRecord({
|
|
850
1004
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
|
1005
|
+
queryParams: options,
|
|
851
1006
|
body: record,
|
|
852
1007
|
...this.extraProps
|
|
853
1008
|
});
|
|
@@ -876,21 +1031,24 @@ class RecordsApi {
|
|
|
876
1031
|
...this.extraProps
|
|
877
1032
|
});
|
|
878
1033
|
}
|
|
879
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
|
1034
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
|
880
1035
|
return operationsByTag.records.deleteRecord({
|
|
881
1036
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
|
1037
|
+
queryParams: options,
|
|
882
1038
|
...this.extraProps
|
|
883
1039
|
});
|
|
884
1040
|
}
|
|
885
1041
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
|
886
1042
|
return operationsByTag.records.getRecord({
|
|
887
1043
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
|
1044
|
+
queryParams: options,
|
|
888
1045
|
...this.extraProps
|
|
889
1046
|
});
|
|
890
1047
|
}
|
|
891
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
|
1048
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
|
892
1049
|
return operationsByTag.records.bulkInsertTableRecords({
|
|
893
1050
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
|
1051
|
+
queryParams: options,
|
|
894
1052
|
body: { records },
|
|
895
1053
|
...this.extraProps
|
|
896
1054
|
});
|
|
@@ -941,18 +1099,18 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
|
941
1099
|
throw TypeError("Cannot add the same private member more than once");
|
|
942
1100
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
943
1101
|
};
|
|
944
|
-
var __privateSet$
|
|
1102
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
|
945
1103
|
__accessCheck$6(obj, member, "write to private field");
|
|
946
1104
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
947
1105
|
return value;
|
|
948
1106
|
};
|
|
949
|
-
var _query;
|
|
1107
|
+
var _query, _page;
|
|
950
1108
|
class Page {
|
|
951
1109
|
constructor(query, meta, records = []) {
|
|
952
1110
|
__privateAdd$6(this, _query, void 0);
|
|
953
|
-
__privateSet$
|
|
1111
|
+
__privateSet$6(this, _query, query);
|
|
954
1112
|
this.meta = meta;
|
|
955
|
-
this.records = records;
|
|
1113
|
+
this.records = new RecordArray(this, records);
|
|
956
1114
|
}
|
|
957
1115
|
async nextPage(size, offset) {
|
|
958
1116
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
|
@@ -972,12 +1130,56 @@ class Page {
|
|
|
972
1130
|
}
|
|
973
1131
|
_query = new WeakMap();
|
|
974
1132
|
const PAGINATION_MAX_SIZE = 200;
|
|
975
|
-
const PAGINATION_DEFAULT_SIZE =
|
|
1133
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
|
976
1134
|
const PAGINATION_MAX_OFFSET = 800;
|
|
977
1135
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
|
978
1136
|
function isCursorPaginationOptions(options) {
|
|
979
1137
|
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
|
980
1138
|
}
|
|
1139
|
+
const _RecordArray = class extends Array {
|
|
1140
|
+
constructor(...args) {
|
|
1141
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
|
1142
|
+
__privateAdd$6(this, _page, void 0);
|
|
1143
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
|
1144
|
+
}
|
|
1145
|
+
static parseConstructorParams(...args) {
|
|
1146
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
|
1147
|
+
return new Array(args[0]);
|
|
1148
|
+
}
|
|
1149
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
|
1150
|
+
const result = args[1] ?? args[0].records ?? [];
|
|
1151
|
+
return new Array(...result);
|
|
1152
|
+
}
|
|
1153
|
+
return new Array(...args);
|
|
1154
|
+
}
|
|
1155
|
+
toArray() {
|
|
1156
|
+
return new Array(...this);
|
|
1157
|
+
}
|
|
1158
|
+
map(callbackfn, thisArg) {
|
|
1159
|
+
return this.toArray().map(callbackfn, thisArg);
|
|
1160
|
+
}
|
|
1161
|
+
async nextPage(size, offset) {
|
|
1162
|
+
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
|
1163
|
+
return new _RecordArray(newPage);
|
|
1164
|
+
}
|
|
1165
|
+
async previousPage(size, offset) {
|
|
1166
|
+
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
|
1167
|
+
return new _RecordArray(newPage);
|
|
1168
|
+
}
|
|
1169
|
+
async firstPage(size, offset) {
|
|
1170
|
+
const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
|
|
1171
|
+
return new _RecordArray(newPage);
|
|
1172
|
+
}
|
|
1173
|
+
async lastPage(size, offset) {
|
|
1174
|
+
const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
|
|
1175
|
+
return new _RecordArray(newPage);
|
|
1176
|
+
}
|
|
1177
|
+
hasNextPage() {
|
|
1178
|
+
return __privateGet$6(this, _page).meta.page.more;
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
let RecordArray = _RecordArray;
|
|
1182
|
+
_page = new WeakMap();
|
|
981
1183
|
|
|
982
1184
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
983
1185
|
if (!member.has(obj))
|
|
@@ -992,7 +1194,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
|
992
1194
|
throw TypeError("Cannot add the same private member more than once");
|
|
993
1195
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
994
1196
|
};
|
|
995
|
-
var __privateSet$
|
|
1197
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
|
996
1198
|
__accessCheck$5(obj, member, "write to private field");
|
|
997
1199
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
998
1200
|
return value;
|
|
@@ -1004,12 +1206,12 @@ const _Query = class {
|
|
|
1004
1206
|
__privateAdd$5(this, _repository, void 0);
|
|
1005
1207
|
__privateAdd$5(this, _data, { filter: {} });
|
|
1006
1208
|
this.meta = { page: { cursor: "start", more: true } };
|
|
1007
|
-
this.records = [];
|
|
1008
|
-
__privateSet$
|
|
1209
|
+
this.records = new RecordArray(this, []);
|
|
1210
|
+
__privateSet$5(this, _table$1, table);
|
|
1009
1211
|
if (repository) {
|
|
1010
|
-
__privateSet$
|
|
1212
|
+
__privateSet$5(this, _repository, repository);
|
|
1011
1213
|
} else {
|
|
1012
|
-
__privateSet$
|
|
1214
|
+
__privateSet$5(this, _repository, this);
|
|
1013
1215
|
}
|
|
1014
1216
|
const parent = cleanParent(data, rawParent);
|
|
1015
1217
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
|
@@ -1064,13 +1266,18 @@ const _Query = class {
|
|
|
1064
1266
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1065
1267
|
}
|
|
1066
1268
|
}
|
|
1067
|
-
sort(column, direction) {
|
|
1269
|
+
sort(column, direction = "asc") {
|
|
1068
1270
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
|
1069
1271
|
const sort = [...originalSort, { column, direction }];
|
|
1070
1272
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
|
1071
1273
|
}
|
|
1072
1274
|
select(columns) {
|
|
1073
|
-
return new _Query(
|
|
1275
|
+
return new _Query(
|
|
1276
|
+
__privateGet$5(this, _repository),
|
|
1277
|
+
__privateGet$5(this, _table$1),
|
|
1278
|
+
{ columns },
|
|
1279
|
+
__privateGet$5(this, _data)
|
|
1280
|
+
);
|
|
1074
1281
|
}
|
|
1075
1282
|
getPaginated(options = {}) {
|
|
1076
1283
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
|
@@ -1093,8 +1300,11 @@ const _Query = class {
|
|
|
1093
1300
|
}
|
|
1094
1301
|
}
|
|
1095
1302
|
async getMany(options = {}) {
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1303
|
+
const page = await this.getPaginated(options);
|
|
1304
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
|
1305
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
|
1306
|
+
}
|
|
1307
|
+
return page.records;
|
|
1098
1308
|
}
|
|
1099
1309
|
async getAll(options = {}) {
|
|
1100
1310
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
|
@@ -1142,7 +1352,9 @@ function isIdentifiable(x) {
|
|
|
1142
1352
|
return isObject(x) && isString(x?.id);
|
|
1143
1353
|
}
|
|
1144
1354
|
function isXataRecord(x) {
|
|
1145
|
-
|
|
1355
|
+
const record = x;
|
|
1356
|
+
const metadata = record?.getMetadata();
|
|
1357
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
|
1146
1358
|
}
|
|
1147
1359
|
|
|
1148
1360
|
function isSortFilterString(value) {
|
|
@@ -1181,7 +1393,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
|
1181
1393
|
throw TypeError("Cannot add the same private member more than once");
|
|
1182
1394
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1183
1395
|
};
|
|
1184
|
-
var __privateSet$
|
|
1396
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
|
1185
1397
|
__accessCheck$4(obj, member, "write to private field");
|
|
1186
1398
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1187
1399
|
return value;
|
|
@@ -1190,7 +1402,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
|
1190
1402
|
__accessCheck$4(obj, member, "access private method");
|
|
1191
1403
|
return method;
|
|
1192
1404
|
};
|
|
1193
|
-
var _table, _getFetchProps, _cache,
|
|
1405
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
|
1194
1406
|
class Repository extends Query {
|
|
1195
1407
|
}
|
|
1196
1408
|
class RestRepository extends Query {
|
|
@@ -1202,188 +1414,214 @@ class RestRepository extends Query {
|
|
|
1202
1414
|
__privateAdd$4(this, _updateRecordWithID);
|
|
1203
1415
|
__privateAdd$4(this, _upsertRecordWithID);
|
|
1204
1416
|
__privateAdd$4(this, _deleteRecord);
|
|
1205
|
-
__privateAdd$4(this, _invalidateCache);
|
|
1206
|
-
__privateAdd$4(this, _setCacheRecord);
|
|
1207
|
-
__privateAdd$4(this, _getCacheRecord);
|
|
1208
1417
|
__privateAdd$4(this, _setCacheQuery);
|
|
1209
1418
|
__privateAdd$4(this, _getCacheQuery);
|
|
1210
|
-
__privateAdd$4(this,
|
|
1419
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
|
1211
1420
|
__privateAdd$4(this, _table, void 0);
|
|
1212
1421
|
__privateAdd$4(this, _getFetchProps, void 0);
|
|
1422
|
+
__privateAdd$4(this, _db, void 0);
|
|
1213
1423
|
__privateAdd$4(this, _cache, void 0);
|
|
1214
|
-
__privateAdd$4(this,
|
|
1215
|
-
|
|
1216
|
-
__privateSet$
|
|
1217
|
-
this
|
|
1218
|
-
__privateSet$
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
if (a === "")
|
|
1230
|
-
throw new Error("The id can't be empty");
|
|
1231
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
|
|
1232
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1233
|
-
return record;
|
|
1234
|
-
}
|
|
1235
|
-
if (isObject(a) && isString(a.id)) {
|
|
1236
|
-
if (a.id === "")
|
|
1237
|
-
throw new Error("The id can't be empty");
|
|
1238
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
|
|
1239
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1240
|
-
return record;
|
|
1241
|
-
}
|
|
1242
|
-
if (isObject(a)) {
|
|
1243
|
-
const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
|
|
1244
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1245
|
-
return record;
|
|
1246
|
-
}
|
|
1247
|
-
throw new Error("Invalid arguments for create method");
|
|
1424
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
|
1425
|
+
__privateAdd$4(this, _trace, void 0);
|
|
1426
|
+
__privateSet$4(this, _table, options.table);
|
|
1427
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
|
1428
|
+
__privateSet$4(this, _db, options.db);
|
|
1429
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
|
1430
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
|
1431
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
|
1432
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
|
1433
|
+
return trace(name, fn, {
|
|
1434
|
+
...options2,
|
|
1435
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
|
1436
|
+
[TraceAttributes.VERSION]: VERSION
|
|
1437
|
+
});
|
|
1438
|
+
});
|
|
1248
1439
|
}
|
|
1249
|
-
async
|
|
1250
|
-
|
|
1251
|
-
if (a
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1440
|
+
async create(a, b, c) {
|
|
1441
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
|
1442
|
+
if (Array.isArray(a)) {
|
|
1443
|
+
if (a.length === 0)
|
|
1444
|
+
return [];
|
|
1445
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1446
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
|
1447
|
+
}
|
|
1448
|
+
if (isString(a) && isObject(b)) {
|
|
1449
|
+
if (a === "")
|
|
1450
|
+
throw new Error("The id can't be empty");
|
|
1451
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1452
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
|
1453
|
+
}
|
|
1454
|
+
if (isObject(a) && isString(a.id)) {
|
|
1455
|
+
if (a.id === "")
|
|
1456
|
+
throw new Error("The id can't be empty");
|
|
1457
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1458
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1459
|
+
}
|
|
1460
|
+
if (isObject(a)) {
|
|
1461
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1462
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
|
1463
|
+
}
|
|
1464
|
+
throw new Error("Invalid arguments for create method");
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
async read(a, b) {
|
|
1468
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
|
1469
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1470
|
+
if (Array.isArray(a)) {
|
|
1471
|
+
if (a.length === 0)
|
|
1472
|
+
return [];
|
|
1473
|
+
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
|
1474
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
|
1475
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
|
1476
|
+
acc[object.id] = object;
|
|
1477
|
+
return acc;
|
|
1478
|
+
}, {});
|
|
1479
|
+
return ids.map((id2) => dictionary[id2] ?? null);
|
|
1480
|
+
}
|
|
1481
|
+
const id = isString(a) ? a : a.id;
|
|
1482
|
+
if (isString(id)) {
|
|
1483
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1484
|
+
try {
|
|
1485
|
+
const response = await getRecord({
|
|
1486
|
+
pathParams: {
|
|
1487
|
+
workspace: "{workspaceId}",
|
|
1488
|
+
dbBranchName: "{dbBranch}",
|
|
1489
|
+
tableName: __privateGet$4(this, _table),
|
|
1490
|
+
recordId: id
|
|
1491
|
+
},
|
|
1492
|
+
queryParams: { columns },
|
|
1493
|
+
...fetchProps
|
|
1494
|
+
});
|
|
1495
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1496
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1497
|
+
} catch (e) {
|
|
1498
|
+
if (isObject(e) && e.status === 404) {
|
|
1499
|
+
return null;
|
|
1500
|
+
}
|
|
1501
|
+
throw e;
|
|
1270
1502
|
}
|
|
1271
|
-
throw e;
|
|
1272
1503
|
}
|
|
1273
|
-
|
|
1504
|
+
return null;
|
|
1505
|
+
});
|
|
1274
1506
|
}
|
|
1275
|
-
async update(a, b) {
|
|
1276
|
-
|
|
1277
|
-
if (a
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1507
|
+
async update(a, b, c) {
|
|
1508
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
|
1509
|
+
if (Array.isArray(a)) {
|
|
1510
|
+
if (a.length === 0)
|
|
1511
|
+
return [];
|
|
1512
|
+
if (a.length > 100) {
|
|
1513
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1514
|
+
}
|
|
1515
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1516
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
|
1281
1517
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
|
1286
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
|
1287
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1288
|
-
return record;
|
|
1289
|
-
}
|
|
1290
|
-
if (isObject(a) && isString(a.id)) {
|
|
1291
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
|
1292
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
|
1293
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1294
|
-
return record;
|
|
1295
|
-
}
|
|
1296
|
-
throw new Error("Invalid arguments for update method");
|
|
1297
|
-
}
|
|
1298
|
-
async createOrUpdate(a, b) {
|
|
1299
|
-
if (Array.isArray(a)) {
|
|
1300
|
-
if (a.length === 0)
|
|
1301
|
-
return [];
|
|
1302
|
-
if (a.length > 100) {
|
|
1303
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1518
|
+
if (isString(a) && isObject(b)) {
|
|
1519
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1520
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
|
1304
1521
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1522
|
+
if (isObject(a) && isString(a.id)) {
|
|
1523
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1524
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1525
|
+
}
|
|
1526
|
+
throw new Error("Invalid arguments for update method");
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
async createOrUpdate(a, b, c) {
|
|
1530
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
|
1531
|
+
if (Array.isArray(a)) {
|
|
1532
|
+
if (a.length === 0)
|
|
1533
|
+
return [];
|
|
1534
|
+
if (a.length > 100) {
|
|
1535
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1536
|
+
}
|
|
1537
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1538
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
|
1539
|
+
}
|
|
1540
|
+
if (isString(a) && isObject(b)) {
|
|
1541
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1542
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
|
1543
|
+
}
|
|
1544
|
+
if (isObject(a) && isString(a.id)) {
|
|
1545
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1546
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1547
|
+
}
|
|
1548
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
|
1549
|
+
});
|
|
1320
1550
|
}
|
|
1321
1551
|
async delete(a) {
|
|
1322
|
-
|
|
1323
|
-
if (a
|
|
1552
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
|
1553
|
+
if (Array.isArray(a)) {
|
|
1554
|
+
if (a.length === 0)
|
|
1555
|
+
return;
|
|
1556
|
+
if (a.length > 100) {
|
|
1557
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
1558
|
+
}
|
|
1559
|
+
await Promise.all(a.map((id) => this.delete(id)));
|
|
1324
1560
|
return;
|
|
1325
|
-
if (a.length > 100) {
|
|
1326
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
1327
1561
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
|
1339
|
-
return;
|
|
1340
|
-
}
|
|
1341
|
-
throw new Error("Invalid arguments for delete method");
|
|
1562
|
+
if (isString(a)) {
|
|
1563
|
+
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
if (isObject(a) && isString(a.id)) {
|
|
1567
|
+
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
throw new Error("Invalid arguments for delete method");
|
|
1571
|
+
});
|
|
1342
1572
|
}
|
|
1343
1573
|
async search(query, options = {}) {
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1574
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
|
1575
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1576
|
+
const { records } = await searchTable({
|
|
1577
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1578
|
+
body: {
|
|
1579
|
+
query,
|
|
1580
|
+
fuzziness: options.fuzziness,
|
|
1581
|
+
prefix: options.prefix,
|
|
1582
|
+
highlight: options.highlight,
|
|
1583
|
+
filter: options.filter,
|
|
1584
|
+
boosters: options.boosters
|
|
1585
|
+
},
|
|
1586
|
+
...fetchProps
|
|
1587
|
+
});
|
|
1588
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1589
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
|
1354
1590
|
});
|
|
1355
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
|
1356
|
-
return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
|
|
1357
1591
|
}
|
|
1358
1592
|
async query(query) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1593
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
|
1594
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
|
1595
|
+
if (cacheQuery)
|
|
1596
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
|
1597
|
+
const data = query.getQueryOptions();
|
|
1598
|
+
const body = {
|
|
1599
|
+
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
|
1600
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
|
1601
|
+
page: data.pagination,
|
|
1602
|
+
columns: data.columns
|
|
1603
|
+
};
|
|
1604
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1605
|
+
const { meta, records: objects } = await queryTable({
|
|
1606
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1607
|
+
body,
|
|
1608
|
+
...fetchProps
|
|
1609
|
+
});
|
|
1610
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1611
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
|
1612
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
1613
|
+
return new Page(query, meta, records);
|
|
1374
1614
|
});
|
|
1375
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
|
1376
|
-
const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
|
|
1377
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
1378
|
-
return new Page(query, meta, records);
|
|
1379
1615
|
}
|
|
1380
1616
|
}
|
|
1381
1617
|
_table = new WeakMap();
|
|
1382
1618
|
_getFetchProps = new WeakMap();
|
|
1619
|
+
_db = new WeakMap();
|
|
1383
1620
|
_cache = new WeakMap();
|
|
1384
|
-
|
|
1621
|
+
_schemaTables$2 = new WeakMap();
|
|
1622
|
+
_trace = new WeakMap();
|
|
1385
1623
|
_insertRecordWithoutId = new WeakSet();
|
|
1386
|
-
insertRecordWithoutId_fn = async function(object) {
|
|
1624
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1387
1625
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1388
1626
|
const record = transformObjectLinks(object);
|
|
1389
1627
|
const response = await insertRecord({
|
|
@@ -1392,17 +1630,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
|
1392
1630
|
dbBranchName: "{dbBranch}",
|
|
1393
1631
|
tableName: __privateGet$4(this, _table)
|
|
1394
1632
|
},
|
|
1633
|
+
queryParams: { columns },
|
|
1395
1634
|
body: record,
|
|
1396
1635
|
...fetchProps
|
|
1397
1636
|
});
|
|
1398
|
-
const
|
|
1399
|
-
|
|
1400
|
-
throw new Error("The server failed to save the record");
|
|
1401
|
-
}
|
|
1402
|
-
return finalObject;
|
|
1637
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1638
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1403
1639
|
};
|
|
1404
1640
|
_insertRecordWithId = new WeakSet();
|
|
1405
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
|
1641
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1406
1642
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1407
1643
|
const record = transformObjectLinks(object);
|
|
1408
1644
|
const response = await insertRecordWithID({
|
|
@@ -1413,56 +1649,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
|
1413
1649
|
recordId
|
|
1414
1650
|
},
|
|
1415
1651
|
body: record,
|
|
1416
|
-
queryParams: { createOnly: true },
|
|
1652
|
+
queryParams: { createOnly: true, columns },
|
|
1417
1653
|
...fetchProps
|
|
1418
1654
|
});
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1421
|
-
throw new Error("The server failed to save the record");
|
|
1422
|
-
}
|
|
1423
|
-
return finalObject;
|
|
1655
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1656
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1424
1657
|
};
|
|
1425
1658
|
_bulkInsertTableRecords = new WeakSet();
|
|
1426
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
|
1659
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1427
1660
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1428
1661
|
const records = objects.map((object) => transformObjectLinks(object));
|
|
1429
1662
|
const response = await bulkInsertTableRecords({
|
|
1430
1663
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1664
|
+
queryParams: { columns },
|
|
1431
1665
|
body: { records },
|
|
1432
1666
|
...fetchProps
|
|
1433
1667
|
});
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
throw new Error("The server failed to save some records");
|
|
1668
|
+
if (!isResponseWithRecords(response)) {
|
|
1669
|
+
throw new Error("Request included columns but server didn't include them");
|
|
1437
1670
|
}
|
|
1438
|
-
|
|
1671
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1672
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
|
1439
1673
|
};
|
|
1440
1674
|
_updateRecordWithID = new WeakSet();
|
|
1441
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
|
1675
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1442
1676
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1443
1677
|
const record = transformObjectLinks(object);
|
|
1444
1678
|
const response = await updateRecordWithID({
|
|
1445
1679
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
1680
|
+
queryParams: { columns },
|
|
1446
1681
|
body: record,
|
|
1447
1682
|
...fetchProps
|
|
1448
1683
|
});
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
throw new Error("The server failed to save the record");
|
|
1452
|
-
return item;
|
|
1684
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1685
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1453
1686
|
};
|
|
1454
1687
|
_upsertRecordWithID = new WeakSet();
|
|
1455
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
|
1688
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1456
1689
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1457
1690
|
const response = await upsertRecordWithID({
|
|
1458
1691
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
1692
|
+
queryParams: { columns },
|
|
1459
1693
|
body: object,
|
|
1460
1694
|
...fetchProps
|
|
1461
1695
|
});
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
throw new Error("The server failed to save the record");
|
|
1465
|
-
return item;
|
|
1696
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1697
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
1466
1698
|
};
|
|
1467
1699
|
_deleteRecord = new WeakSet();
|
|
1468
1700
|
deleteRecord_fn = async function(recordId) {
|
|
@@ -1472,29 +1704,6 @@ deleteRecord_fn = async function(recordId) {
|
|
|
1472
1704
|
...fetchProps
|
|
1473
1705
|
});
|
|
1474
1706
|
};
|
|
1475
|
-
_invalidateCache = new WeakSet();
|
|
1476
|
-
invalidateCache_fn = async function(recordId) {
|
|
1477
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
|
1478
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
|
1479
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
|
1480
|
-
for (const [key, value] of queries) {
|
|
1481
|
-
const ids = getIds(value);
|
|
1482
|
-
if (ids.includes(recordId))
|
|
1483
|
-
await __privateGet$4(this, _cache).delete(key);
|
|
1484
|
-
}
|
|
1485
|
-
};
|
|
1486
|
-
_setCacheRecord = new WeakSet();
|
|
1487
|
-
setCacheRecord_fn = async function(record) {
|
|
1488
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
|
1489
|
-
return;
|
|
1490
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
|
1491
|
-
};
|
|
1492
|
-
_getCacheRecord = new WeakSet();
|
|
1493
|
-
getCacheRecord_fn = async function(recordId) {
|
|
1494
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
|
1495
|
-
return null;
|
|
1496
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
|
1497
|
-
};
|
|
1498
1707
|
_setCacheQuery = new WeakSet();
|
|
1499
1708
|
setCacheQuery_fn = async function(query, meta, records) {
|
|
1500
1709
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
|
@@ -1511,17 +1720,17 @@ getCacheQuery_fn = async function(query) {
|
|
|
1511
1720
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
|
1512
1721
|
return hasExpired ? null : result;
|
|
1513
1722
|
};
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
if (__privateGet$4(this,
|
|
1517
|
-
return __privateGet$4(this,
|
|
1723
|
+
_getSchemaTables$1 = new WeakSet();
|
|
1724
|
+
getSchemaTables_fn$1 = async function() {
|
|
1725
|
+
if (__privateGet$4(this, _schemaTables$2))
|
|
1726
|
+
return __privateGet$4(this, _schemaTables$2);
|
|
1518
1727
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1519
1728
|
const { schema } = await getBranchDetails({
|
|
1520
1729
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
1521
1730
|
...fetchProps
|
|
1522
1731
|
});
|
|
1523
|
-
__privateSet$
|
|
1524
|
-
return schema;
|
|
1732
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
|
1733
|
+
return schema.tables;
|
|
1525
1734
|
};
|
|
1526
1735
|
const transformObjectLinks = (object) => {
|
|
1527
1736
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
|
@@ -1530,10 +1739,11 @@ const transformObjectLinks = (object) => {
|
|
|
1530
1739
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
|
1531
1740
|
}, {});
|
|
1532
1741
|
};
|
|
1533
|
-
const initObject = (db,
|
|
1742
|
+
const initObject = (db, schemaTables, table, object) => {
|
|
1534
1743
|
const result = {};
|
|
1535
|
-
|
|
1536
|
-
|
|
1744
|
+
const { xata, ...rest } = object ?? {};
|
|
1745
|
+
Object.assign(result, rest);
|
|
1746
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
|
1537
1747
|
if (!columns)
|
|
1538
1748
|
console.error(`Table ${table} not found in schema`);
|
|
1539
1749
|
for (const column of columns ?? []) {
|
|
@@ -1553,35 +1763,32 @@ const initObject = (db, schema, table, object) => {
|
|
|
1553
1763
|
if (!linkTable) {
|
|
1554
1764
|
console.error(`Failed to parse link for field ${column.name}`);
|
|
1555
1765
|
} else if (isObject(value)) {
|
|
1556
|
-
result[column.name] = initObject(db,
|
|
1766
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
|
1557
1767
|
}
|
|
1558
1768
|
break;
|
|
1559
1769
|
}
|
|
1560
1770
|
}
|
|
1561
1771
|
}
|
|
1562
|
-
result.read = function() {
|
|
1563
|
-
return db[table].read(result["id"]);
|
|
1772
|
+
result.read = function(columns2) {
|
|
1773
|
+
return db[table].read(result["id"], columns2);
|
|
1564
1774
|
};
|
|
1565
|
-
result.update = function(data) {
|
|
1566
|
-
return db[table].update(result["id"], data);
|
|
1775
|
+
result.update = function(data, columns2) {
|
|
1776
|
+
return db[table].update(result["id"], data, columns2);
|
|
1567
1777
|
};
|
|
1568
1778
|
result.delete = function() {
|
|
1569
1779
|
return db[table].delete(result["id"]);
|
|
1570
1780
|
};
|
|
1571
|
-
|
|
1781
|
+
result.getMetadata = function() {
|
|
1782
|
+
return xata;
|
|
1783
|
+
};
|
|
1784
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
|
1572
1785
|
Object.defineProperty(result, prop, { enumerable: false });
|
|
1573
1786
|
}
|
|
1574
1787
|
Object.freeze(result);
|
|
1575
1788
|
return result;
|
|
1576
1789
|
};
|
|
1577
|
-
function
|
|
1578
|
-
|
|
1579
|
-
return value.map((item) => getIds(item)).flat();
|
|
1580
|
-
}
|
|
1581
|
-
if (!isObject(value))
|
|
1582
|
-
return [];
|
|
1583
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
|
1584
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
|
1790
|
+
function isResponseWithRecords(value) {
|
|
1791
|
+
return isObject(value) && Array.isArray(value.records);
|
|
1585
1792
|
}
|
|
1586
1793
|
|
|
1587
1794
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
@@ -1597,7 +1804,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
|
1597
1804
|
throw TypeError("Cannot add the same private member more than once");
|
|
1598
1805
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1599
1806
|
};
|
|
1600
|
-
var __privateSet$
|
|
1807
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
|
1601
1808
|
__accessCheck$3(obj, member, "write to private field");
|
|
1602
1809
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1603
1810
|
return value;
|
|
@@ -1606,9 +1813,8 @@ var _map;
|
|
|
1606
1813
|
class SimpleCache {
|
|
1607
1814
|
constructor(options = {}) {
|
|
1608
1815
|
__privateAdd$3(this, _map, void 0);
|
|
1609
|
-
__privateSet$
|
|
1816
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
|
1610
1817
|
this.capacity = options.max ?? 500;
|
|
1611
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
|
1612
1818
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
|
1613
1819
|
}
|
|
1614
1820
|
async getAll() {
|
|
@@ -1634,18 +1840,25 @@ class SimpleCache {
|
|
|
1634
1840
|
}
|
|
1635
1841
|
_map = new WeakMap();
|
|
1636
1842
|
|
|
1637
|
-
const
|
|
1638
|
-
const
|
|
1639
|
-
const
|
|
1640
|
-
const
|
|
1641
|
-
const
|
|
1642
|
-
const
|
|
1843
|
+
const greaterThan = (value) => ({ $gt: value });
|
|
1844
|
+
const gt = greaterThan;
|
|
1845
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
|
1846
|
+
const greaterEquals = greaterThanEquals;
|
|
1847
|
+
const gte = greaterThanEquals;
|
|
1848
|
+
const ge = greaterThanEquals;
|
|
1849
|
+
const lessThan = (value) => ({ $lt: value });
|
|
1850
|
+
const lt = lessThan;
|
|
1851
|
+
const lessThanEquals = (value) => ({ $le: value });
|
|
1852
|
+
const lessEquals = lessThanEquals;
|
|
1853
|
+
const lte = lessThanEquals;
|
|
1854
|
+
const le = lessThanEquals;
|
|
1643
1855
|
const exists = (column) => ({ $exists: column });
|
|
1644
1856
|
const notExists = (column) => ({ $notExists: column });
|
|
1645
1857
|
const startsWith = (value) => ({ $startsWith: value });
|
|
1646
1858
|
const endsWith = (value) => ({ $endsWith: value });
|
|
1647
1859
|
const pattern = (value) => ({ $pattern: value });
|
|
1648
1860
|
const is = (value) => ({ $is: value });
|
|
1861
|
+
const equals = is;
|
|
1649
1862
|
const isNot = (value) => ({ $isNot: value });
|
|
1650
1863
|
const contains = (value) => ({ $contains: value });
|
|
1651
1864
|
const includes = (value) => ({ $includes: value });
|
|
@@ -1666,31 +1879,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
|
1666
1879
|
throw TypeError("Cannot add the same private member more than once");
|
|
1667
1880
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1668
1881
|
};
|
|
1669
|
-
var
|
|
1882
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
|
1883
|
+
__accessCheck$2(obj, member, "write to private field");
|
|
1884
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1885
|
+
return value;
|
|
1886
|
+
};
|
|
1887
|
+
var _tables, _schemaTables$1;
|
|
1670
1888
|
class SchemaPlugin extends XataPlugin {
|
|
1671
|
-
constructor(
|
|
1889
|
+
constructor(schemaTables) {
|
|
1672
1890
|
super();
|
|
1673
|
-
this.tableNames = tableNames;
|
|
1674
1891
|
__privateAdd$2(this, _tables, {});
|
|
1892
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
|
1893
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
|
1675
1894
|
}
|
|
1676
1895
|
build(pluginOptions) {
|
|
1677
|
-
const db = new Proxy(
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1896
|
+
const db = new Proxy(
|
|
1897
|
+
{},
|
|
1898
|
+
{
|
|
1899
|
+
get: (_target, table) => {
|
|
1900
|
+
if (!isString(table))
|
|
1901
|
+
throw new Error("Invalid table name");
|
|
1902
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
|
1903
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
|
1904
|
+
}
|
|
1905
|
+
return __privateGet$2(this, _tables)[table];
|
|
1683
1906
|
}
|
|
1684
|
-
return __privateGet$2(this, _tables)[table];
|
|
1685
1907
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1908
|
+
);
|
|
1909
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
|
1910
|
+
for (const table of tableNames) {
|
|
1911
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
|
1689
1912
|
}
|
|
1690
1913
|
return db;
|
|
1691
1914
|
}
|
|
1692
1915
|
}
|
|
1693
1916
|
_tables = new WeakMap();
|
|
1917
|
+
_schemaTables$1 = new WeakMap();
|
|
1694
1918
|
|
|
1695
1919
|
var __accessCheck$1 = (obj, member, msg) => {
|
|
1696
1920
|
if (!member.has(obj))
|
|
@@ -1714,82 +1938,77 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
|
1714
1938
|
__accessCheck$1(obj, member, "access private method");
|
|
1715
1939
|
return method;
|
|
1716
1940
|
};
|
|
1717
|
-
var
|
|
1941
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
|
1718
1942
|
class SearchPlugin extends XataPlugin {
|
|
1719
|
-
constructor(db) {
|
|
1943
|
+
constructor(db, schemaTables) {
|
|
1720
1944
|
super();
|
|
1721
1945
|
this.db = db;
|
|
1722
1946
|
__privateAdd$1(this, _search);
|
|
1723
|
-
__privateAdd$1(this,
|
|
1724
|
-
__privateAdd$1(this,
|
|
1947
|
+
__privateAdd$1(this, _getSchemaTables);
|
|
1948
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
|
1949
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
|
1725
1950
|
}
|
|
1726
1951
|
build({ getFetchProps }) {
|
|
1727
1952
|
return {
|
|
1728
1953
|
all: async (query, options = {}) => {
|
|
1729
1954
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
|
1730
|
-
const
|
|
1955
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
|
1731
1956
|
return records.map((record) => {
|
|
1732
1957
|
const { table = "orphan" } = record.xata;
|
|
1733
|
-
return { table, record: initObject(this.db,
|
|
1958
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
|
1734
1959
|
});
|
|
1735
1960
|
},
|
|
1736
1961
|
byTable: async (query, options = {}) => {
|
|
1737
1962
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
|
1738
|
-
const
|
|
1963
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
|
1739
1964
|
return records.reduce((acc, record) => {
|
|
1740
1965
|
const { table = "orphan" } = record.xata;
|
|
1741
1966
|
const items = acc[table] ?? [];
|
|
1742
|
-
const item = initObject(this.db,
|
|
1967
|
+
const item = initObject(this.db, schemaTables, table, record);
|
|
1743
1968
|
return { ...acc, [table]: [...items, item] };
|
|
1744
1969
|
}, {});
|
|
1745
1970
|
}
|
|
1746
1971
|
};
|
|
1747
1972
|
}
|
|
1748
1973
|
}
|
|
1749
|
-
|
|
1974
|
+
_schemaTables = new WeakMap();
|
|
1750
1975
|
_search = new WeakSet();
|
|
1751
1976
|
search_fn = async function(query, options, getFetchProps) {
|
|
1752
1977
|
const fetchProps = await getFetchProps();
|
|
1753
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
|
1978
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
|
1754
1979
|
const { records } = await searchBranch({
|
|
1755
1980
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
1756
|
-
body: { tables, query, fuzziness, highlight },
|
|
1981
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
|
1757
1982
|
...fetchProps
|
|
1758
1983
|
});
|
|
1759
1984
|
return records;
|
|
1760
1985
|
};
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
if (__privateGet$1(this,
|
|
1764
|
-
return __privateGet$1(this,
|
|
1986
|
+
_getSchemaTables = new WeakSet();
|
|
1987
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
|
1988
|
+
if (__privateGet$1(this, _schemaTables))
|
|
1989
|
+
return __privateGet$1(this, _schemaTables);
|
|
1765
1990
|
const fetchProps = await getFetchProps();
|
|
1766
1991
|
const { schema } = await getBranchDetails({
|
|
1767
1992
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
1768
1993
|
...fetchProps
|
|
1769
1994
|
});
|
|
1770
|
-
__privateSet$1(this,
|
|
1771
|
-
return schema;
|
|
1995
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
|
1996
|
+
return schema.tables;
|
|
1772
1997
|
};
|
|
1773
1998
|
|
|
1774
1999
|
const isBranchStrategyBuilder = (strategy) => {
|
|
1775
2000
|
return typeof strategy === "function";
|
|
1776
2001
|
};
|
|
1777
2002
|
|
|
1778
|
-
const envBranchNames = [
|
|
1779
|
-
"XATA_BRANCH",
|
|
1780
|
-
"VERCEL_GIT_COMMIT_REF",
|
|
1781
|
-
"CF_PAGES_BRANCH",
|
|
1782
|
-
"BRANCH"
|
|
1783
|
-
];
|
|
1784
2003
|
async function getCurrentBranchName(options) {
|
|
1785
|
-
const
|
|
1786
|
-
if (
|
|
1787
|
-
const details = await getDatabaseBranch(
|
|
2004
|
+
const { branch, envBranch } = getEnvironment();
|
|
2005
|
+
if (branch) {
|
|
2006
|
+
const details = await getDatabaseBranch(branch, options);
|
|
1788
2007
|
if (details)
|
|
1789
|
-
return
|
|
1790
|
-
console.warn(`Branch ${
|
|
2008
|
+
return branch;
|
|
2009
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
|
1791
2010
|
}
|
|
1792
|
-
const gitBranch = await getGitBranch();
|
|
2011
|
+
const gitBranch = envBranch || await getGitBranch();
|
|
1793
2012
|
return resolveXataBranch(gitBranch, options);
|
|
1794
2013
|
}
|
|
1795
2014
|
async function getCurrentBranchDetails(options) {
|
|
@@ -1800,18 +2019,24 @@ async function resolveXataBranch(gitBranch, options) {
|
|
|
1800
2019
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1801
2020
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1802
2021
|
if (!databaseURL)
|
|
1803
|
-
throw new Error(
|
|
2022
|
+
throw new Error(
|
|
2023
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
2024
|
+
);
|
|
1804
2025
|
if (!apiKey)
|
|
1805
|
-
throw new Error(
|
|
2026
|
+
throw new Error(
|
|
2027
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
2028
|
+
);
|
|
1806
2029
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
|
1807
2030
|
const [workspace] = host.split(".");
|
|
2031
|
+
const { fallbackBranch } = getEnvironment();
|
|
1808
2032
|
const { branch } = await resolveBranch({
|
|
1809
2033
|
apiKey,
|
|
1810
2034
|
apiUrl: databaseURL,
|
|
1811
2035
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1812
2036
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1813
2037
|
pathParams: { dbName, workspace },
|
|
1814
|
-
queryParams: { gitBranch, fallbackBranch
|
|
2038
|
+
queryParams: { gitBranch, fallbackBranch },
|
|
2039
|
+
trace: defaultTrace
|
|
1815
2040
|
});
|
|
1816
2041
|
return branch;
|
|
1817
2042
|
}
|
|
@@ -1819,9 +2044,13 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1819
2044
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1820
2045
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1821
2046
|
if (!databaseURL)
|
|
1822
|
-
throw new Error(
|
|
2047
|
+
throw new Error(
|
|
2048
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
2049
|
+
);
|
|
1823
2050
|
if (!apiKey)
|
|
1824
|
-
throw new Error(
|
|
2051
|
+
throw new Error(
|
|
2052
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
2053
|
+
);
|
|
1825
2054
|
const [protocol, , host, , database] = databaseURL.split("/");
|
|
1826
2055
|
const [workspace] = host.split(".");
|
|
1827
2056
|
const dbBranchName = `${database}:${branch}`;
|
|
@@ -1831,10 +2060,8 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1831
2060
|
apiUrl: databaseURL,
|
|
1832
2061
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1833
2062
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1834
|
-
pathParams: {
|
|
1835
|
-
|
|
1836
|
-
workspace
|
|
1837
|
-
}
|
|
2063
|
+
pathParams: { dbBranchName, workspace },
|
|
2064
|
+
trace: defaultTrace
|
|
1838
2065
|
});
|
|
1839
2066
|
} catch (err) {
|
|
1840
2067
|
if (isObject(err) && err.status === 404)
|
|
@@ -1842,21 +2069,10 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1842
2069
|
throw err;
|
|
1843
2070
|
}
|
|
1844
2071
|
}
|
|
1845
|
-
function getBranchByEnvVariable() {
|
|
1846
|
-
for (const name of envBranchNames) {
|
|
1847
|
-
const value = getEnvVariable(name);
|
|
1848
|
-
if (value) {
|
|
1849
|
-
return value;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
try {
|
|
1853
|
-
return XATA_BRANCH;
|
|
1854
|
-
} catch (err) {
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
2072
|
function getDatabaseURL() {
|
|
1858
2073
|
try {
|
|
1859
|
-
|
|
2074
|
+
const { databaseURL } = getEnvironment();
|
|
2075
|
+
return databaseURL;
|
|
1860
2076
|
} catch (err) {
|
|
1861
2077
|
return void 0;
|
|
1862
2078
|
}
|
|
@@ -1885,20 +2101,23 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1885
2101
|
return method;
|
|
1886
2102
|
};
|
|
1887
2103
|
const buildClient = (plugins) => {
|
|
1888
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
|
2104
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
|
1889
2105
|
return _a = class {
|
|
1890
|
-
constructor(options = {},
|
|
2106
|
+
constructor(options = {}, schemaTables) {
|
|
1891
2107
|
__privateAdd(this, _parseOptions);
|
|
1892
2108
|
__privateAdd(this, _getFetchProps);
|
|
1893
2109
|
__privateAdd(this, _evaluateBranch);
|
|
1894
2110
|
__privateAdd(this, _branch, void 0);
|
|
2111
|
+
__privateAdd(this, _options, void 0);
|
|
1895
2112
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
|
2113
|
+
__privateSet(this, _options, safeOptions);
|
|
1896
2114
|
const pluginOptions = {
|
|
1897
2115
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
|
1898
|
-
cache: safeOptions.cache
|
|
2116
|
+
cache: safeOptions.cache,
|
|
2117
|
+
trace: safeOptions.trace
|
|
1899
2118
|
};
|
|
1900
|
-
const db = new SchemaPlugin(
|
|
1901
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
|
2119
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
|
2120
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
|
1902
2121
|
this.db = db;
|
|
1903
2122
|
this.search = search;
|
|
1904
2123
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
|
@@ -1914,22 +2133,26 @@ const buildClient = (plugins) => {
|
|
|
1914
2133
|
}
|
|
1915
2134
|
}
|
|
1916
2135
|
}
|
|
1917
|
-
|
|
2136
|
+
async getConfig() {
|
|
2137
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
|
2138
|
+
const branch = await __privateGet(this, _options).branch();
|
|
2139
|
+
return { databaseURL, branch };
|
|
2140
|
+
}
|
|
2141
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
|
1918
2142
|
const fetch = getFetchImplementation(options?.fetch);
|
|
1919
2143
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1920
2144
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1921
|
-
const cache = options?.cache ?? new SimpleCache({
|
|
2145
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
|
2146
|
+
const trace = options?.trace ?? defaultTrace;
|
|
1922
2147
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
|
1923
|
-
if (!
|
|
1924
|
-
throw new Error("
|
|
2148
|
+
if (!apiKey) {
|
|
2149
|
+
throw new Error("Option apiKey is required");
|
|
1925
2150
|
}
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
apiKey,
|
|
1930
|
-
|
|
1931
|
-
branch
|
|
1932
|
-
}) {
|
|
2151
|
+
if (!databaseURL) {
|
|
2152
|
+
throw new Error("Option databaseURL is required");
|
|
2153
|
+
}
|
|
2154
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
|
2155
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
|
1933
2156
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
|
1934
2157
|
if (!branchValue)
|
|
1935
2158
|
throw new Error("Unable to resolve branch value");
|
|
@@ -1941,7 +2164,8 @@ const buildClient = (plugins) => {
|
|
|
1941
2164
|
const hasBranch = params.dbBranchName ?? params.branch;
|
|
1942
2165
|
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
|
1943
2166
|
return databaseURL + newPath;
|
|
1944
|
-
}
|
|
2167
|
+
},
|
|
2168
|
+
trace
|
|
1945
2169
|
};
|
|
1946
2170
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
|
1947
2171
|
if (__privateGet(this, _branch))
|
|
@@ -1964,6 +2188,88 @@ const buildClient = (plugins) => {
|
|
|
1964
2188
|
class BaseClient extends buildClient() {
|
|
1965
2189
|
}
|
|
1966
2190
|
|
|
2191
|
+
const META = "__";
|
|
2192
|
+
const VALUE = "___";
|
|
2193
|
+
class Serializer {
|
|
2194
|
+
constructor() {
|
|
2195
|
+
this.classes = {};
|
|
2196
|
+
}
|
|
2197
|
+
add(clazz) {
|
|
2198
|
+
this.classes[clazz.name] = clazz;
|
|
2199
|
+
}
|
|
2200
|
+
toJSON(data) {
|
|
2201
|
+
function visit(obj) {
|
|
2202
|
+
if (Array.isArray(obj))
|
|
2203
|
+
return obj.map(visit);
|
|
2204
|
+
const type = typeof obj;
|
|
2205
|
+
if (type === "undefined")
|
|
2206
|
+
return { [META]: "undefined" };
|
|
2207
|
+
if (type === "bigint")
|
|
2208
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
|
2209
|
+
if (obj === null || type !== "object")
|
|
2210
|
+
return obj;
|
|
2211
|
+
const constructor = obj.constructor;
|
|
2212
|
+
const o = { [META]: constructor.name };
|
|
2213
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2214
|
+
o[key] = visit(value);
|
|
2215
|
+
}
|
|
2216
|
+
if (constructor === Date)
|
|
2217
|
+
o[VALUE] = obj.toISOString();
|
|
2218
|
+
if (constructor === Map)
|
|
2219
|
+
o[VALUE] = Object.fromEntries(obj);
|
|
2220
|
+
if (constructor === Set)
|
|
2221
|
+
o[VALUE] = [...obj];
|
|
2222
|
+
return o;
|
|
2223
|
+
}
|
|
2224
|
+
return JSON.stringify(visit(data));
|
|
2225
|
+
}
|
|
2226
|
+
fromJSON(json) {
|
|
2227
|
+
return JSON.parse(json, (key, value) => {
|
|
2228
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
2229
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
|
2230
|
+
const constructor = this.classes[clazz];
|
|
2231
|
+
if (constructor) {
|
|
2232
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
|
2233
|
+
}
|
|
2234
|
+
if (clazz === "Date")
|
|
2235
|
+
return new Date(val);
|
|
2236
|
+
if (clazz === "Set")
|
|
2237
|
+
return new Set(val);
|
|
2238
|
+
if (clazz === "Map")
|
|
2239
|
+
return new Map(Object.entries(val));
|
|
2240
|
+
if (clazz === "bigint")
|
|
2241
|
+
return BigInt(val);
|
|
2242
|
+
if (clazz === "undefined")
|
|
2243
|
+
return void 0;
|
|
2244
|
+
return rest;
|
|
2245
|
+
}
|
|
2246
|
+
return value;
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
const defaultSerializer = new Serializer();
|
|
2251
|
+
const serialize = (data) => {
|
|
2252
|
+
return defaultSerializer.toJSON(data);
|
|
2253
|
+
};
|
|
2254
|
+
const deserialize = (json) => {
|
|
2255
|
+
return defaultSerializer.fromJSON(json);
|
|
2256
|
+
};
|
|
2257
|
+
|
|
2258
|
+
function buildWorkerRunner(config) {
|
|
2259
|
+
return function xataWorker(name, _worker) {
|
|
2260
|
+
return async (...args) => {
|
|
2261
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
|
2262
|
+
const result = await fetch(url, {
|
|
2263
|
+
method: "POST",
|
|
2264
|
+
headers: { "Content-Type": "application/json" },
|
|
2265
|
+
body: serialize({ args })
|
|
2266
|
+
});
|
|
2267
|
+
const text = await result.text();
|
|
2268
|
+
return deserialize(text);
|
|
2269
|
+
};
|
|
2270
|
+
};
|
|
2271
|
+
}
|
|
2272
|
+
|
|
1967
2273
|
class XataError extends Error {
|
|
1968
2274
|
constructor(message, status) {
|
|
1969
2275
|
super(message);
|
|
@@ -1979,10 +2285,12 @@ exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
|
|
|
1979
2285
|
exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
|
1980
2286
|
exports.Page = Page;
|
|
1981
2287
|
exports.Query = Query;
|
|
2288
|
+
exports.RecordArray = RecordArray;
|
|
1982
2289
|
exports.Repository = Repository;
|
|
1983
2290
|
exports.RestRepository = RestRepository;
|
|
1984
2291
|
exports.SchemaPlugin = SchemaPlugin;
|
|
1985
2292
|
exports.SearchPlugin = SearchPlugin;
|
|
2293
|
+
exports.Serializer = Serializer;
|
|
1986
2294
|
exports.SimpleCache = SimpleCache;
|
|
1987
2295
|
exports.XataApiClient = XataApiClient;
|
|
1988
2296
|
exports.XataApiPlugin = XataApiPlugin;
|
|
@@ -1992,6 +2300,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
|
|
1992
2300
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
1993
2301
|
exports.addTableColumn = addTableColumn;
|
|
1994
2302
|
exports.buildClient = buildClient;
|
|
2303
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
|
1995
2304
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
1996
2305
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
|
1997
2306
|
exports.contains = contains;
|
|
@@ -2008,7 +2317,9 @@ exports.deleteTable = deleteTable;
|
|
|
2008
2317
|
exports.deleteUser = deleteUser;
|
|
2009
2318
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
|
2010
2319
|
exports.deleteWorkspace = deleteWorkspace;
|
|
2320
|
+
exports.deserialize = deserialize;
|
|
2011
2321
|
exports.endsWith = endsWith;
|
|
2322
|
+
exports.equals = equals;
|
|
2012
2323
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
|
2013
2324
|
exports.exists = exists;
|
|
2014
2325
|
exports.ge = ge;
|
|
@@ -2023,6 +2334,7 @@ exports.getColumn = getColumn;
|
|
|
2023
2334
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
|
2024
2335
|
exports.getCurrentBranchName = getCurrentBranchName;
|
|
2025
2336
|
exports.getDatabaseList = getDatabaseList;
|
|
2337
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
|
2026
2338
|
exports.getDatabaseURL = getDatabaseURL;
|
|
2027
2339
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
|
2028
2340
|
exports.getRecord = getRecord;
|
|
@@ -2033,6 +2345,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
|
2033
2345
|
exports.getWorkspace = getWorkspace;
|
|
2034
2346
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
|
2035
2347
|
exports.getWorkspacesList = getWorkspacesList;
|
|
2348
|
+
exports.greaterEquals = greaterEquals;
|
|
2349
|
+
exports.greaterThan = greaterThan;
|
|
2350
|
+
exports.greaterThanEquals = greaterThanEquals;
|
|
2036
2351
|
exports.gt = gt;
|
|
2037
2352
|
exports.gte = gte;
|
|
2038
2353
|
exports.includes = includes;
|
|
@@ -2048,6 +2363,9 @@ exports.isIdentifiable = isIdentifiable;
|
|
|
2048
2363
|
exports.isNot = isNot;
|
|
2049
2364
|
exports.isXataRecord = isXataRecord;
|
|
2050
2365
|
exports.le = le;
|
|
2366
|
+
exports.lessEquals = lessEquals;
|
|
2367
|
+
exports.lessThan = lessThan;
|
|
2368
|
+
exports.lessThanEquals = lessThanEquals;
|
|
2051
2369
|
exports.lt = lt;
|
|
2052
2370
|
exports.lte = lte;
|
|
2053
2371
|
exports.notExists = notExists;
|
|
@@ -2060,6 +2378,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
|
2060
2378
|
exports.resolveBranch = resolveBranch;
|
|
2061
2379
|
exports.searchBranch = searchBranch;
|
|
2062
2380
|
exports.searchTable = searchTable;
|
|
2381
|
+
exports.serialize = serialize;
|
|
2063
2382
|
exports.setTableSchema = setTableSchema;
|
|
2064
2383
|
exports.startsWith = startsWith;
|
|
2065
2384
|
exports.updateBranchMetadata = updateBranchMetadata;
|
|
@@ -2068,6 +2387,7 @@ exports.updateRecordWithID = updateRecordWithID;
|
|
|
2068
2387
|
exports.updateTable = updateTable;
|
|
2069
2388
|
exports.updateUser = updateUser;
|
|
2070
2389
|
exports.updateWorkspace = updateWorkspace;
|
|
2390
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
|
2071
2391
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
|
2072
2392
|
exports.upsertRecordWithID = upsertRecordWithID;
|
|
2073
2393
|
//# sourceMappingURL=index.cjs.map
|