@xata.io/client 0.0.0-alpha.vfe4ae98 → 0.0.0-alpha.vfeb24b1
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 +64 -0
- package/README.md +2 -0
- package/Usage.md +60 -6
- package/dist/index.cjs +644 -344
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +858 -172
- package/dist/index.mjs +614 -345
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
const defaultTrace = async (_name, fn, _options) => {
|
2
|
+
return await fn({
|
3
|
+
setAttributes: () => {
|
4
|
+
return;
|
5
|
+
},
|
6
|
+
onError: () => {
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
});
|
10
|
+
};
|
11
|
+
const TraceAttributes = {
|
12
|
+
VERSION: "xata.sdk.version",
|
13
|
+
TABLE: "xata.table",
|
14
|
+
HTTP_REQUEST_ID: "http.request_id",
|
15
|
+
HTTP_STATUS_CODE: "http.status_code",
|
16
|
+
HTTP_HOST: "http.host",
|
17
|
+
HTTP_SCHEME: "http.scheme",
|
18
|
+
HTTP_USER_AGENT: "http.user_agent",
|
19
|
+
HTTP_METHOD: "http.method",
|
20
|
+
HTTP_URL: "http.url",
|
21
|
+
HTTP_ROUTE: "http.route",
|
22
|
+
HTTP_TARGET: "http.target"
|
23
|
+
};
|
24
|
+
|
1
25
|
function notEmpty(value) {
|
2
26
|
return value !== null && value !== void 0;
|
3
27
|
}
|
@@ -13,6 +37,9 @@ function isDefined(value) {
|
|
13
37
|
function isString(value) {
|
14
38
|
return isDefined(value) && typeof value === "string";
|
15
39
|
}
|
40
|
+
function isStringArray(value) {
|
41
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
42
|
+
}
|
16
43
|
function toBase64(value) {
|
17
44
|
try {
|
18
45
|
return btoa(value);
|
@@ -22,35 +49,83 @@ function toBase64(value) {
|
|
22
49
|
}
|
23
50
|
}
|
24
51
|
|
25
|
-
function
|
52
|
+
function getEnvironment() {
|
26
53
|
try {
|
27
|
-
if (isObject(process) &&
|
28
|
-
return
|
54
|
+
if (isObject(process) && isObject(process.env)) {
|
55
|
+
return {
|
56
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
57
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
58
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
59
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
60
|
+
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
61
|
+
};
|
29
62
|
}
|
30
63
|
} catch (err) {
|
31
64
|
}
|
32
65
|
try {
|
33
|
-
if (isObject(Deno) &&
|
34
|
-
return
|
66
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
67
|
+
return {
|
68
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
69
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
70
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
71
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
72
|
+
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
73
|
+
};
|
35
74
|
}
|
36
75
|
} catch (err) {
|
37
76
|
}
|
77
|
+
return {
|
78
|
+
apiKey: getGlobalApiKey(),
|
79
|
+
databaseURL: getGlobalDatabaseURL(),
|
80
|
+
branch: getGlobalBranch(),
|
81
|
+
envBranch: void 0,
|
82
|
+
fallbackBranch: getGlobalFallbackBranch()
|
83
|
+
};
|
84
|
+
}
|
85
|
+
function getGlobalApiKey() {
|
86
|
+
try {
|
87
|
+
return XATA_API_KEY;
|
88
|
+
} catch (err) {
|
89
|
+
return void 0;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
function getGlobalDatabaseURL() {
|
93
|
+
try {
|
94
|
+
return XATA_DATABASE_URL;
|
95
|
+
} catch (err) {
|
96
|
+
return void 0;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
function getGlobalBranch() {
|
100
|
+
try {
|
101
|
+
return XATA_BRANCH;
|
102
|
+
} catch (err) {
|
103
|
+
return void 0;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
function getGlobalFallbackBranch() {
|
107
|
+
try {
|
108
|
+
return XATA_FALLBACK_BRANCH;
|
109
|
+
} catch (err) {
|
110
|
+
return void 0;
|
111
|
+
}
|
38
112
|
}
|
39
113
|
async function getGitBranch() {
|
114
|
+
const cmd = ["git", "branch", "--show-current"];
|
115
|
+
const fullCmd = cmd.join(" ");
|
116
|
+
const nodeModule = ["child", "process"].join("_");
|
117
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
40
118
|
try {
|
41
119
|
if (typeof require === "function") {
|
42
|
-
|
43
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
120
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
44
121
|
}
|
122
|
+
const { execSync } = await import(nodeModule);
|
123
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
45
124
|
} catch (err) {
|
46
125
|
}
|
47
126
|
try {
|
48
127
|
if (isObject(Deno)) {
|
49
|
-
const process2 = Deno.run({
|
50
|
-
cmd: ["git", "branch", "--show-current"],
|
51
|
-
stdout: "piped",
|
52
|
-
stderr: "piped"
|
53
|
-
});
|
128
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
54
129
|
return new TextDecoder().decode(await process2.output()).trim();
|
55
130
|
}
|
56
131
|
} catch (err) {
|
@@ -59,7 +134,8 @@ async function getGitBranch() {
|
|
59
134
|
|
60
135
|
function getAPIKey() {
|
61
136
|
try {
|
62
|
-
|
137
|
+
const { apiKey } = getEnvironment();
|
138
|
+
return apiKey;
|
63
139
|
} catch (err) {
|
64
140
|
return void 0;
|
65
141
|
}
|
@@ -69,12 +145,14 @@ function getFetchImplementation(userFetch) {
|
|
69
145
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
70
146
|
const fetchImpl = userFetch ?? globalFetch;
|
71
147
|
if (!fetchImpl) {
|
72
|
-
throw new Error(
|
148
|
+
throw new Error(
|
149
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
150
|
+
);
|
73
151
|
}
|
74
152
|
return fetchImpl;
|
75
153
|
}
|
76
154
|
|
77
|
-
const VERSION = "0.0.0-alpha.
|
155
|
+
const VERSION = "0.0.0-alpha.vfeb24b1";
|
78
156
|
|
79
157
|
class ErrorWithCause extends Error {
|
80
158
|
constructor(message, options) {
|
@@ -153,34 +231,62 @@ async function fetch$1({
|
|
153
231
|
fetchImpl,
|
154
232
|
apiKey,
|
155
233
|
apiUrl,
|
156
|
-
workspacesApiUrl
|
234
|
+
workspacesApiUrl,
|
235
|
+
trace
|
157
236
|
}) {
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
237
|
+
return trace(
|
238
|
+
`${method.toUpperCase()} ${path}`,
|
239
|
+
async ({ setAttributes, onError }) => {
|
240
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
241
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
242
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
243
|
+
setAttributes({
|
244
|
+
[TraceAttributes.HTTP_URL]: url,
|
245
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
246
|
+
});
|
247
|
+
const response = await fetchImpl(url, {
|
248
|
+
method: method.toUpperCase(),
|
249
|
+
body: body ? JSON.stringify(body) : void 0,
|
250
|
+
headers: {
|
251
|
+
"Content-Type": "application/json",
|
252
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
253
|
+
...headers,
|
254
|
+
...hostHeader(fullUrl),
|
255
|
+
Authorization: `Bearer ${apiKey}`
|
256
|
+
}
|
257
|
+
});
|
258
|
+
if (response.status === 204) {
|
259
|
+
return {};
|
260
|
+
}
|
261
|
+
const { host, protocol } = parseUrl(response.url);
|
262
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
263
|
+
setAttributes({
|
264
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
265
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
266
|
+
[TraceAttributes.HTTP_HOST]: host,
|
267
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
268
|
+
});
|
269
|
+
try {
|
270
|
+
const jsonResponse = await response.json();
|
271
|
+
if (response.ok) {
|
272
|
+
return jsonResponse;
|
273
|
+
}
|
274
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
275
|
+
} catch (error) {
|
276
|
+
const fetcherError = new FetcherError(response.status, error, requestId);
|
277
|
+
onError(fetcherError.message);
|
278
|
+
throw fetcherError;
|
279
|
+
}
|
280
|
+
},
|
281
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
282
|
+
);
|
283
|
+
}
|
284
|
+
function parseUrl(url) {
|
176
285
|
try {
|
177
|
-
const
|
178
|
-
|
179
|
-
return jsonResponse;
|
180
|
-
}
|
181
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
286
|
+
const { host, protocol } = new URL(url);
|
287
|
+
return { host, protocol };
|
182
288
|
} catch (error) {
|
183
|
-
|
289
|
+
return {};
|
184
290
|
}
|
185
291
|
}
|
186
292
|
|
@@ -239,6 +345,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
239
345
|
...variables
|
240
346
|
});
|
241
347
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
348
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
242
349
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
243
350
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
244
351
|
method: "delete",
|
@@ -274,6 +381,11 @@ const deleteDatabase = (variables) => fetch$1({
|
|
274
381
|
method: "delete",
|
275
382
|
...variables
|
276
383
|
});
|
384
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
385
|
+
url: "/dbs/{dbName}/metadata",
|
386
|
+
method: "get",
|
387
|
+
...variables
|
388
|
+
});
|
277
389
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
278
390
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
279
391
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -287,11 +399,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
287
399
|
method: "get",
|
288
400
|
...variables
|
289
401
|
});
|
290
|
-
const createBranch = (variables) => fetch$1({
|
291
|
-
url: "/db/{dbBranchName}",
|
292
|
-
method: "put",
|
293
|
-
...variables
|
294
|
-
});
|
402
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
295
403
|
const deleteBranch = (variables) => fetch$1({
|
296
404
|
url: "/db/{dbBranchName}",
|
297
405
|
method: "delete",
|
@@ -365,11 +473,7 @@ const updateColumn = (variables) => fetch$1({
|
|
365
473
|
method: "patch",
|
366
474
|
...variables
|
367
475
|
});
|
368
|
-
const insertRecord = (variables) => fetch$1({
|
369
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
370
|
-
method: "post",
|
371
|
-
...variables
|
372
|
-
});
|
476
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
373
477
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
374
478
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
375
479
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -411,6 +515,7 @@ const operationsByTag = {
|
|
411
515
|
updateWorkspaceMemberRole,
|
412
516
|
removeWorkspaceMember,
|
413
517
|
inviteWorkspaceMember,
|
518
|
+
updateWorkspaceMemberInvite,
|
414
519
|
cancelWorkspaceMemberInvite,
|
415
520
|
resendWorkspaceMemberInvite,
|
416
521
|
acceptWorkspaceMemberInvite
|
@@ -419,6 +524,7 @@ const operationsByTag = {
|
|
419
524
|
getDatabaseList,
|
420
525
|
createDatabase,
|
421
526
|
deleteDatabase,
|
527
|
+
getDatabaseMetadata,
|
422
528
|
getGitBranchesMapping,
|
423
529
|
addGitBranchesEntry,
|
424
530
|
removeGitBranchesEntry,
|
@@ -511,7 +617,8 @@ class XataApiClient {
|
|
511
617
|
__privateAdd$7(this, _extraProps, void 0);
|
512
618
|
__privateAdd$7(this, _namespaces, {});
|
513
619
|
const provider = options.host ?? "production";
|
514
|
-
const apiKey = options
|
620
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
621
|
+
const trace = options.trace ?? defaultTrace;
|
515
622
|
if (!apiKey) {
|
516
623
|
throw new Error("Could not resolve a valid apiKey");
|
517
624
|
}
|
@@ -519,7 +626,8 @@ class XataApiClient {
|
|
519
626
|
apiUrl: getHostUrl(provider, "main"),
|
520
627
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
521
628
|
fetchImpl: getFetchImplementation(options.fetch),
|
522
|
-
apiKey
|
629
|
+
apiKey,
|
630
|
+
trace
|
523
631
|
});
|
524
632
|
}
|
525
633
|
get user() {
|
@@ -642,6 +750,13 @@ class WorkspaceApi {
|
|
642
750
|
...this.extraProps
|
643
751
|
});
|
644
752
|
}
|
753
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
754
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
755
|
+
pathParams: { workspaceId, inviteId },
|
756
|
+
body: { role },
|
757
|
+
...this.extraProps
|
758
|
+
});
|
759
|
+
}
|
645
760
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
646
761
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
647
762
|
pathParams: { workspaceId, inviteId },
|
@@ -684,6 +799,12 @@ class DatabaseApi {
|
|
684
799
|
...this.extraProps
|
685
800
|
});
|
686
801
|
}
|
802
|
+
getDatabaseMetadata(workspace, dbName) {
|
803
|
+
return operationsByTag.database.getDatabaseMetadata({
|
804
|
+
pathParams: { workspace, dbName },
|
805
|
+
...this.extraProps
|
806
|
+
});
|
807
|
+
}
|
687
808
|
getGitBranchesMapping(workspace, dbName) {
|
688
809
|
return operationsByTag.database.getGitBranchesMapping({
|
689
810
|
pathParams: { workspace, dbName },
|
@@ -856,9 +977,10 @@ class RecordsApi {
|
|
856
977
|
constructor(extraProps) {
|
857
978
|
this.extraProps = extraProps;
|
858
979
|
}
|
859
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
980
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
860
981
|
return operationsByTag.records.insertRecord({
|
861
982
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
983
|
+
queryParams: options,
|
862
984
|
body: record,
|
863
985
|
...this.extraProps
|
864
986
|
});
|
@@ -887,21 +1009,24 @@ class RecordsApi {
|
|
887
1009
|
...this.extraProps
|
888
1010
|
});
|
889
1011
|
}
|
890
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1012
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
891
1013
|
return operationsByTag.records.deleteRecord({
|
892
1014
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1015
|
+
queryParams: options,
|
893
1016
|
...this.extraProps
|
894
1017
|
});
|
895
1018
|
}
|
896
1019
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
897
1020
|
return operationsByTag.records.getRecord({
|
898
1021
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1022
|
+
queryParams: options,
|
899
1023
|
...this.extraProps
|
900
1024
|
});
|
901
1025
|
}
|
902
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1026
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
903
1027
|
return operationsByTag.records.bulkInsertTableRecords({
|
904
1028
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1029
|
+
queryParams: options,
|
905
1030
|
body: { records },
|
906
1031
|
...this.extraProps
|
907
1032
|
});
|
@@ -993,7 +1118,7 @@ const _RecordArray = class extends Array {
|
|
993
1118
|
constructor(...args) {
|
994
1119
|
super(..._RecordArray.parseConstructorParams(...args));
|
995
1120
|
__privateAdd$6(this, _page, void 0);
|
996
|
-
__privateSet$6(this, _page, args[0]);
|
1121
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
997
1122
|
}
|
998
1123
|
static parseConstructorParams(...args) {
|
999
1124
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -1005,6 +1130,12 @@ const _RecordArray = class extends Array {
|
|
1005
1130
|
}
|
1006
1131
|
return new Array(...args);
|
1007
1132
|
}
|
1133
|
+
toArray() {
|
1134
|
+
return new Array(...this);
|
1135
|
+
}
|
1136
|
+
map(callbackfn, thisArg) {
|
1137
|
+
return this.toArray().map(callbackfn, thisArg);
|
1138
|
+
}
|
1008
1139
|
async nextPage(size, offset) {
|
1009
1140
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1010
1141
|
return new _RecordArray(newPage);
|
@@ -1113,13 +1244,18 @@ const _Query = class {
|
|
1113
1244
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1114
1245
|
}
|
1115
1246
|
}
|
1116
|
-
sort(column, direction) {
|
1247
|
+
sort(column, direction = "asc") {
|
1117
1248
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1118
1249
|
const sort = [...originalSort, { column, direction }];
|
1119
1250
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1120
1251
|
}
|
1121
1252
|
select(columns) {
|
1122
|
-
return new _Query(
|
1253
|
+
return new _Query(
|
1254
|
+
__privateGet$5(this, _repository),
|
1255
|
+
__privateGet$5(this, _table$1),
|
1256
|
+
{ columns },
|
1257
|
+
__privateGet$5(this, _data)
|
1258
|
+
);
|
1123
1259
|
}
|
1124
1260
|
getPaginated(options = {}) {
|
1125
1261
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1160,6 +1296,12 @@ const _Query = class {
|
|
1160
1296
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1161
1297
|
return records[0] ?? null;
|
1162
1298
|
}
|
1299
|
+
async getFirstOrThrow(options = {}) {
|
1300
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1301
|
+
if (records[0] === void 0)
|
1302
|
+
throw new Error("No results found.");
|
1303
|
+
return records[0];
|
1304
|
+
}
|
1163
1305
|
cache(ttl) {
|
1164
1306
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1165
1307
|
}
|
@@ -1244,7 +1386,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1244
1386
|
__accessCheck$4(obj, member, "access private method");
|
1245
1387
|
return method;
|
1246
1388
|
};
|
1247
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1389
|
+
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;
|
1248
1390
|
class Repository extends Query {
|
1249
1391
|
}
|
1250
1392
|
class RestRepository extends Query {
|
@@ -1256,191 +1398,254 @@ class RestRepository extends Query {
|
|
1256
1398
|
__privateAdd$4(this, _updateRecordWithID);
|
1257
1399
|
__privateAdd$4(this, _upsertRecordWithID);
|
1258
1400
|
__privateAdd$4(this, _deleteRecord);
|
1259
|
-
__privateAdd$4(this, _invalidateCache);
|
1260
|
-
__privateAdd$4(this, _setCacheRecord);
|
1261
|
-
__privateAdd$4(this, _getCacheRecord);
|
1262
1401
|
__privateAdd$4(this, _setCacheQuery);
|
1263
1402
|
__privateAdd$4(this, _getCacheQuery);
|
1264
1403
|
__privateAdd$4(this, _getSchemaTables$1);
|
1265
1404
|
__privateAdd$4(this, _table, void 0);
|
1266
1405
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1406
|
+
__privateAdd$4(this, _db, void 0);
|
1267
1407
|
__privateAdd$4(this, _cache, void 0);
|
1268
1408
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1409
|
+
__privateAdd$4(this, _trace, void 0);
|
1269
1410
|
__privateSet$4(this, _table, options.table);
|
1270
1411
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1271
|
-
this
|
1412
|
+
__privateSet$4(this, _db, options.db);
|
1272
1413
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1273
1414
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1415
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1416
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1417
|
+
return trace(name, fn, {
|
1418
|
+
...options2,
|
1419
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1420
|
+
[TraceAttributes.VERSION]: VERSION
|
1421
|
+
});
|
1422
|
+
});
|
1274
1423
|
}
|
1275
|
-
async create(a, b) {
|
1276
|
-
|
1277
|
-
if (a
|
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
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
const
|
1317
|
-
|
1318
|
-
const
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1424
|
+
async create(a, b, c) {
|
1425
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1426
|
+
if (Array.isArray(a)) {
|
1427
|
+
if (a.length === 0)
|
1428
|
+
return [];
|
1429
|
+
const columns = isStringArray(b) ? b : void 0;
|
1430
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1431
|
+
}
|
1432
|
+
if (isString(a) && isObject(b)) {
|
1433
|
+
if (a === "")
|
1434
|
+
throw new Error("The id can't be empty");
|
1435
|
+
const columns = isStringArray(c) ? c : void 0;
|
1436
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1437
|
+
}
|
1438
|
+
if (isObject(a) && isString(a.id)) {
|
1439
|
+
if (a.id === "")
|
1440
|
+
throw new Error("The id can't be empty");
|
1441
|
+
const columns = isStringArray(b) ? b : void 0;
|
1442
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1443
|
+
}
|
1444
|
+
if (isObject(a)) {
|
1445
|
+
const columns = isStringArray(b) ? b : void 0;
|
1446
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1447
|
+
}
|
1448
|
+
throw new Error("Invalid arguments for create method");
|
1449
|
+
});
|
1450
|
+
}
|
1451
|
+
async read(a, b) {
|
1452
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1453
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1454
|
+
if (Array.isArray(a)) {
|
1455
|
+
if (a.length === 0)
|
1456
|
+
return [];
|
1457
|
+
const ids = a.map((item) => extractId(item));
|
1458
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1459
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1460
|
+
acc[object.id] = object;
|
1461
|
+
return acc;
|
1462
|
+
}, {});
|
1463
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1464
|
+
}
|
1465
|
+
const id = extractId(a);
|
1466
|
+
if (id) {
|
1467
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1468
|
+
try {
|
1469
|
+
const response = await getRecord({
|
1470
|
+
pathParams: {
|
1471
|
+
workspace: "{workspaceId}",
|
1472
|
+
dbBranchName: "{dbBranch}",
|
1473
|
+
tableName: __privateGet$4(this, _table),
|
1474
|
+
recordId: id
|
1475
|
+
},
|
1476
|
+
queryParams: { columns },
|
1477
|
+
...fetchProps
|
1478
|
+
});
|
1479
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1480
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1481
|
+
} catch (e) {
|
1482
|
+
if (isObject(e) && e.status === 404) {
|
1483
|
+
return null;
|
1484
|
+
}
|
1485
|
+
throw e;
|
1327
1486
|
}
|
1328
|
-
throw e;
|
1329
1487
|
}
|
1330
|
-
|
1488
|
+
return null;
|
1489
|
+
});
|
1331
1490
|
}
|
1332
|
-
async
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1491
|
+
async readOrThrow(a, b) {
|
1492
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1493
|
+
const result = await this.read(a, b);
|
1494
|
+
if (Array.isArray(result)) {
|
1495
|
+
const missingIds = compact(
|
1496
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1497
|
+
);
|
1498
|
+
if (missingIds.length > 0) {
|
1499
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1500
|
+
}
|
1501
|
+
return result;
|
1338
1502
|
}
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1343
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1344
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1345
|
-
return record;
|
1346
|
-
}
|
1347
|
-
if (isObject(a) && isString(a.id)) {
|
1348
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1349
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1350
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1351
|
-
return record;
|
1352
|
-
}
|
1353
|
-
throw new Error("Invalid arguments for update method");
|
1354
|
-
}
|
1355
|
-
async createOrUpdate(a, b) {
|
1356
|
-
if (Array.isArray(a)) {
|
1357
|
-
if (a.length === 0)
|
1358
|
-
return [];
|
1359
|
-
if (a.length > 100) {
|
1360
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1503
|
+
if (result === null) {
|
1504
|
+
const id = extractId(a) ?? "unknown";
|
1505
|
+
throw new Error(`Record with id ${id} not found`);
|
1361
1506
|
}
|
1362
|
-
return
|
1363
|
-
}
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
}
|
1376
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1377
|
-
}
|
1378
|
-
async delete(a) {
|
1379
|
-
if (Array.isArray(a)) {
|
1380
|
-
if (a.length === 0)
|
1381
|
-
return;
|
1382
|
-
if (a.length > 100) {
|
1383
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1507
|
+
return result;
|
1508
|
+
});
|
1509
|
+
}
|
1510
|
+
async update(a, b, c) {
|
1511
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1512
|
+
if (Array.isArray(a)) {
|
1513
|
+
if (a.length === 0)
|
1514
|
+
return [];
|
1515
|
+
if (a.length > 100) {
|
1516
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1517
|
+
}
|
1518
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1519
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1384
1520
|
}
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1521
|
+
if (isString(a) && isObject(b)) {
|
1522
|
+
const columns = isStringArray(c) ? c : void 0;
|
1523
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1524
|
+
}
|
1525
|
+
if (isObject(a) && isString(a.id)) {
|
1526
|
+
const columns = isStringArray(b) ? b : void 0;
|
1527
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1528
|
+
}
|
1529
|
+
throw new Error("Invalid arguments for update method");
|
1530
|
+
});
|
1531
|
+
}
|
1532
|
+
async updateOrThrow(a, b, c) {
|
1533
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1534
|
+
const result = await this.update(a, b, c);
|
1535
|
+
if (Array.isArray(result)) {
|
1536
|
+
const missingIds = compact(
|
1537
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1538
|
+
);
|
1539
|
+
if (missingIds.length > 0) {
|
1540
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1541
|
+
}
|
1542
|
+
return result;
|
1543
|
+
}
|
1544
|
+
if (result === null) {
|
1545
|
+
const id = extractId(a) ?? "unknown";
|
1546
|
+
throw new Error(`Record with id ${id} not found`);
|
1547
|
+
}
|
1548
|
+
return result;
|
1549
|
+
});
|
1550
|
+
}
|
1551
|
+
async createOrUpdate(a, b, c) {
|
1552
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1553
|
+
if (Array.isArray(a)) {
|
1554
|
+
if (a.length === 0)
|
1555
|
+
return [];
|
1556
|
+
if (a.length > 100) {
|
1557
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1558
|
+
}
|
1559
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1560
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1561
|
+
}
|
1562
|
+
if (isString(a) && isObject(b)) {
|
1563
|
+
const columns = isStringArray(c) ? c : void 0;
|
1564
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1565
|
+
}
|
1566
|
+
if (isObject(a) && isString(a.id)) {
|
1567
|
+
const columns = isStringArray(c) ? c : void 0;
|
1568
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1569
|
+
}
|
1570
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1571
|
+
});
|
1572
|
+
}
|
1573
|
+
async delete(a, b) {
|
1574
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1575
|
+
if (Array.isArray(a)) {
|
1576
|
+
if (a.length === 0)
|
1577
|
+
return [];
|
1578
|
+
if (a.length > 100) {
|
1579
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1580
|
+
}
|
1581
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1582
|
+
}
|
1583
|
+
if (isString(a)) {
|
1584
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1585
|
+
}
|
1586
|
+
if (isObject(a) && isString(a.id)) {
|
1587
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1588
|
+
}
|
1589
|
+
throw new Error("Invalid arguments for delete method");
|
1590
|
+
});
|
1591
|
+
}
|
1592
|
+
async deleteOrThrow(a, b) {
|
1593
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1594
|
+
throw new Error("Not implemented");
|
1595
|
+
});
|
1399
1596
|
}
|
1400
1597
|
async search(query, options = {}) {
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1598
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1599
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1600
|
+
const { records } = await searchTable({
|
1601
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1602
|
+
body: {
|
1603
|
+
query,
|
1604
|
+
fuzziness: options.fuzziness,
|
1605
|
+
prefix: options.prefix,
|
1606
|
+
highlight: options.highlight,
|
1607
|
+
filter: options.filter,
|
1608
|
+
boosters: options.boosters
|
1609
|
+
},
|
1610
|
+
...fetchProps
|
1611
|
+
});
|
1612
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1613
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1411
1614
|
});
|
1412
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1413
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1414
1615
|
}
|
1415
1616
|
async query(query) {
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1617
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1618
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1619
|
+
if (cacheQuery)
|
1620
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1621
|
+
const data = query.getQueryOptions();
|
1622
|
+
const body = {
|
1623
|
+
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1624
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1625
|
+
page: data.pagination,
|
1626
|
+
columns: data.columns
|
1627
|
+
};
|
1628
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1629
|
+
const { meta, records: objects } = await queryTable({
|
1630
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1631
|
+
body,
|
1632
|
+
...fetchProps
|
1633
|
+
});
|
1634
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1635
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1636
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1637
|
+
return new Page(query, meta, records);
|
1431
1638
|
});
|
1432
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1433
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1434
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1435
|
-
return new Page(query, meta, records);
|
1436
1639
|
}
|
1437
1640
|
}
|
1438
1641
|
_table = new WeakMap();
|
1439
1642
|
_getFetchProps = new WeakMap();
|
1643
|
+
_db = new WeakMap();
|
1440
1644
|
_cache = new WeakMap();
|
1441
1645
|
_schemaTables$2 = new WeakMap();
|
1646
|
+
_trace = new WeakMap();
|
1442
1647
|
_insertRecordWithoutId = new WeakSet();
|
1443
|
-
insertRecordWithoutId_fn = async function(object) {
|
1648
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1444
1649
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1445
1650
|
const record = transformObjectLinks(object);
|
1446
1651
|
const response = await insertRecord({
|
@@ -1449,17 +1654,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1449
1654
|
dbBranchName: "{dbBranch}",
|
1450
1655
|
tableName: __privateGet$4(this, _table)
|
1451
1656
|
},
|
1657
|
+
queryParams: { columns },
|
1452
1658
|
body: record,
|
1453
1659
|
...fetchProps
|
1454
1660
|
});
|
1455
|
-
const
|
1456
|
-
|
1457
|
-
throw new Error("The server failed to save the record");
|
1458
|
-
}
|
1459
|
-
return finalObject;
|
1661
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1662
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1460
1663
|
};
|
1461
1664
|
_insertRecordWithId = new WeakSet();
|
1462
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1665
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1463
1666
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1464
1667
|
const record = transformObjectLinks(object);
|
1465
1668
|
const response = await insertRecordWithID({
|
@@ -1470,91 +1673,63 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1470
1673
|
recordId
|
1471
1674
|
},
|
1472
1675
|
body: record,
|
1473
|
-
queryParams: { createOnly: true },
|
1676
|
+
queryParams: { createOnly: true, columns },
|
1474
1677
|
...fetchProps
|
1475
1678
|
});
|
1476
|
-
const
|
1477
|
-
|
1478
|
-
throw new Error("The server failed to save the record");
|
1479
|
-
}
|
1480
|
-
return finalObject;
|
1679
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1680
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1481
1681
|
};
|
1482
1682
|
_bulkInsertTableRecords = new WeakSet();
|
1483
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1683
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1484
1684
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1485
1685
|
const records = objects.map((object) => transformObjectLinks(object));
|
1486
|
-
const
|
1686
|
+
const response = await bulkInsertTableRecords({
|
1487
1687
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1688
|
+
queryParams: { columns },
|
1488
1689
|
body: { records },
|
1489
1690
|
...fetchProps
|
1490
1691
|
});
|
1491
|
-
|
1492
|
-
|
1493
|
-
throw new Error("The server failed to save some records");
|
1692
|
+
if (!isResponseWithRecords(response)) {
|
1693
|
+
throw new Error("Request included columns but server didn't include them");
|
1494
1694
|
}
|
1495
|
-
const
|
1496
|
-
|
1497
|
-
return acc;
|
1498
|
-
}, {});
|
1499
|
-
return recordIDs.map((id) => dictionary[id]);
|
1695
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1696
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1500
1697
|
};
|
1501
1698
|
_updateRecordWithID = new WeakSet();
|
1502
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1699
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1503
1700
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1504
1701
|
const record = transformObjectLinks(object);
|
1505
1702
|
const response = await updateRecordWithID({
|
1506
1703
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1704
|
+
queryParams: { columns },
|
1507
1705
|
body: record,
|
1508
1706
|
...fetchProps
|
1509
1707
|
});
|
1510
|
-
const
|
1511
|
-
|
1512
|
-
throw new Error("The server failed to save the record");
|
1513
|
-
return item;
|
1708
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1709
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1514
1710
|
};
|
1515
1711
|
_upsertRecordWithID = new WeakSet();
|
1516
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1712
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1517
1713
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1518
1714
|
const response = await upsertRecordWithID({
|
1519
1715
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1716
|
+
queryParams: { columns },
|
1520
1717
|
body: object,
|
1521
1718
|
...fetchProps
|
1522
1719
|
});
|
1523
|
-
const
|
1524
|
-
|
1525
|
-
throw new Error("The server failed to save the record");
|
1526
|
-
return item;
|
1720
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1721
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1527
1722
|
};
|
1528
1723
|
_deleteRecord = new WeakSet();
|
1529
|
-
deleteRecord_fn = async function(recordId) {
|
1724
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1530
1725
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1531
|
-
await deleteRecord({
|
1726
|
+
const response = await deleteRecord({
|
1532
1727
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1728
|
+
queryParams: { columns },
|
1533
1729
|
...fetchProps
|
1534
1730
|
});
|
1535
|
-
|
1536
|
-
|
1537
|
-
invalidateCache_fn = async function(recordId) {
|
1538
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1539
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1540
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1541
|
-
for (const [key, value] of queries) {
|
1542
|
-
const ids = getIds(value);
|
1543
|
-
if (ids.includes(recordId))
|
1544
|
-
await __privateGet$4(this, _cache).delete(key);
|
1545
|
-
}
|
1546
|
-
};
|
1547
|
-
_setCacheRecord = new WeakSet();
|
1548
|
-
setCacheRecord_fn = async function(record) {
|
1549
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1550
|
-
return;
|
1551
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1552
|
-
};
|
1553
|
-
_getCacheRecord = new WeakSet();
|
1554
|
-
getCacheRecord_fn = async function(recordId) {
|
1555
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1556
|
-
return null;
|
1557
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1731
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1732
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1558
1733
|
};
|
1559
1734
|
_setCacheQuery = new WeakSet();
|
1560
1735
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1621,11 +1796,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1621
1796
|
}
|
1622
1797
|
}
|
1623
1798
|
}
|
1624
|
-
result.read = function() {
|
1625
|
-
return db[table].read(result["id"]);
|
1799
|
+
result.read = function(columns2) {
|
1800
|
+
return db[table].read(result["id"], columns2);
|
1626
1801
|
};
|
1627
|
-
result.update = function(data) {
|
1628
|
-
return db[table].update(result["id"], data);
|
1802
|
+
result.update = function(data, columns2) {
|
1803
|
+
return db[table].update(result["id"], data, columns2);
|
1629
1804
|
};
|
1630
1805
|
result.delete = function() {
|
1631
1806
|
return db[table].delete(result["id"]);
|
@@ -1639,14 +1814,15 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1639
1814
|
Object.freeze(result);
|
1640
1815
|
return result;
|
1641
1816
|
};
|
1642
|
-
function
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
if (
|
1647
|
-
return
|
1648
|
-
|
1649
|
-
|
1817
|
+
function isResponseWithRecords(value) {
|
1818
|
+
return isObject(value) && Array.isArray(value.records);
|
1819
|
+
}
|
1820
|
+
function extractId(value) {
|
1821
|
+
if (isString(value))
|
1822
|
+
return value;
|
1823
|
+
if (isObject(value) && isString(value.id))
|
1824
|
+
return value.id;
|
1825
|
+
return void 0;
|
1650
1826
|
}
|
1651
1827
|
|
1652
1828
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1673,7 +1849,6 @@ class SimpleCache {
|
|
1673
1849
|
__privateAdd$3(this, _map, void 0);
|
1674
1850
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1675
1851
|
this.capacity = options.max ?? 500;
|
1676
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1677
1852
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1678
1853
|
}
|
1679
1854
|
async getAll() {
|
@@ -1699,18 +1874,25 @@ class SimpleCache {
|
|
1699
1874
|
}
|
1700
1875
|
_map = new WeakMap();
|
1701
1876
|
|
1702
|
-
const
|
1703
|
-
const
|
1704
|
-
const
|
1705
|
-
const
|
1706
|
-
const
|
1707
|
-
const
|
1877
|
+
const greaterThan = (value) => ({ $gt: value });
|
1878
|
+
const gt = greaterThan;
|
1879
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
1880
|
+
const greaterEquals = greaterThanEquals;
|
1881
|
+
const gte = greaterThanEquals;
|
1882
|
+
const ge = greaterThanEquals;
|
1883
|
+
const lessThan = (value) => ({ $lt: value });
|
1884
|
+
const lt = lessThan;
|
1885
|
+
const lessThanEquals = (value) => ({ $le: value });
|
1886
|
+
const lessEquals = lessThanEquals;
|
1887
|
+
const lte = lessThanEquals;
|
1888
|
+
const le = lessThanEquals;
|
1708
1889
|
const exists = (column) => ({ $exists: column });
|
1709
1890
|
const notExists = (column) => ({ $notExists: column });
|
1710
1891
|
const startsWith = (value) => ({ $startsWith: value });
|
1711
1892
|
const endsWith = (value) => ({ $endsWith: value });
|
1712
1893
|
const pattern = (value) => ({ $pattern: value });
|
1713
1894
|
const is = (value) => ({ $is: value });
|
1895
|
+
const equals = is;
|
1714
1896
|
const isNot = (value) => ({ $isNot: value });
|
1715
1897
|
const contains = (value) => ({ $contains: value });
|
1716
1898
|
const includes = (value) => ({ $includes: value });
|
@@ -1745,16 +1927,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1745
1927
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1746
1928
|
}
|
1747
1929
|
build(pluginOptions) {
|
1748
|
-
const db = new Proxy(
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1930
|
+
const db = new Proxy(
|
1931
|
+
{},
|
1932
|
+
{
|
1933
|
+
get: (_target, table) => {
|
1934
|
+
if (!isString(table))
|
1935
|
+
throw new Error("Invalid table name");
|
1936
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1937
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1938
|
+
}
|
1939
|
+
return __privateGet$2(this, _tables)[table];
|
1754
1940
|
}
|
1755
|
-
return __privateGet$2(this, _tables)[table];
|
1756
1941
|
}
|
1757
|
-
|
1942
|
+
);
|
1758
1943
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1759
1944
|
for (const table of tableNames) {
|
1760
1945
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1824,10 +2009,10 @@ _schemaTables = new WeakMap();
|
|
1824
2009
|
_search = new WeakSet();
|
1825
2010
|
search_fn = async function(query, options, getFetchProps) {
|
1826
2011
|
const fetchProps = await getFetchProps();
|
1827
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
2012
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1828
2013
|
const { records } = await searchBranch({
|
1829
2014
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1830
|
-
body: { tables, query, fuzziness, highlight },
|
2015
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1831
2016
|
...fetchProps
|
1832
2017
|
});
|
1833
2018
|
return records;
|
@@ -1849,21 +2034,15 @@ const isBranchStrategyBuilder = (strategy) => {
|
|
1849
2034
|
return typeof strategy === "function";
|
1850
2035
|
};
|
1851
2036
|
|
1852
|
-
const envBranchNames = [
|
1853
|
-
"XATA_BRANCH",
|
1854
|
-
"VERCEL_GIT_COMMIT_REF",
|
1855
|
-
"CF_PAGES_BRANCH",
|
1856
|
-
"BRANCH"
|
1857
|
-
];
|
1858
2037
|
async function getCurrentBranchName(options) {
|
1859
|
-
const
|
1860
|
-
if (
|
1861
|
-
const details = await getDatabaseBranch(
|
2038
|
+
const { branch, envBranch } = getEnvironment();
|
2039
|
+
if (branch) {
|
2040
|
+
const details = await getDatabaseBranch(branch, options);
|
1862
2041
|
if (details)
|
1863
|
-
return
|
1864
|
-
console.warn(`Branch ${
|
2042
|
+
return branch;
|
2043
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1865
2044
|
}
|
1866
|
-
const gitBranch = await getGitBranch();
|
2045
|
+
const gitBranch = envBranch || await getGitBranch();
|
1867
2046
|
return resolveXataBranch(gitBranch, options);
|
1868
2047
|
}
|
1869
2048
|
async function getCurrentBranchDetails(options) {
|
@@ -1874,18 +2053,24 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1874
2053
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1875
2054
|
const apiKey = options?.apiKey || getAPIKey();
|
1876
2055
|
if (!databaseURL)
|
1877
|
-
throw new Error(
|
2056
|
+
throw new Error(
|
2057
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2058
|
+
);
|
1878
2059
|
if (!apiKey)
|
1879
|
-
throw new Error(
|
2060
|
+
throw new Error(
|
2061
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2062
|
+
);
|
1880
2063
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1881
2064
|
const [workspace] = host.split(".");
|
2065
|
+
const { fallbackBranch } = getEnvironment();
|
1882
2066
|
const { branch } = await resolveBranch({
|
1883
2067
|
apiKey,
|
1884
2068
|
apiUrl: databaseURL,
|
1885
2069
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1886
2070
|
workspacesApiUrl: `${protocol}//${host}`,
|
1887
2071
|
pathParams: { dbName, workspace },
|
1888
|
-
queryParams: { gitBranch, fallbackBranch
|
2072
|
+
queryParams: { gitBranch, fallbackBranch },
|
2073
|
+
trace: defaultTrace
|
1889
2074
|
});
|
1890
2075
|
return branch;
|
1891
2076
|
}
|
@@ -1893,9 +2078,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1893
2078
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1894
2079
|
const apiKey = options?.apiKey || getAPIKey();
|
1895
2080
|
if (!databaseURL)
|
1896
|
-
throw new Error(
|
2081
|
+
throw new Error(
|
2082
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2083
|
+
);
|
1897
2084
|
if (!apiKey)
|
1898
|
-
throw new Error(
|
2085
|
+
throw new Error(
|
2086
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2087
|
+
);
|
1899
2088
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1900
2089
|
const [workspace] = host.split(".");
|
1901
2090
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1905,7 +2094,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1905
2094
|
apiUrl: databaseURL,
|
1906
2095
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1907
2096
|
workspacesApiUrl: `${protocol}//${host}`,
|
1908
|
-
pathParams: { dbBranchName, workspace }
|
2097
|
+
pathParams: { dbBranchName, workspace },
|
2098
|
+
trace: defaultTrace
|
1909
2099
|
});
|
1910
2100
|
} catch (err) {
|
1911
2101
|
if (isObject(err) && err.status === 404)
|
@@ -1913,21 +2103,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1913
2103
|
throw err;
|
1914
2104
|
}
|
1915
2105
|
}
|
1916
|
-
function getBranchByEnvVariable() {
|
1917
|
-
for (const name of envBranchNames) {
|
1918
|
-
const value = getEnvVariable(name);
|
1919
|
-
if (value) {
|
1920
|
-
return value;
|
1921
|
-
}
|
1922
|
-
}
|
1923
|
-
try {
|
1924
|
-
return XATA_BRANCH;
|
1925
|
-
} catch (err) {
|
1926
|
-
}
|
1927
|
-
}
|
1928
2106
|
function getDatabaseURL() {
|
1929
2107
|
try {
|
1930
|
-
|
2108
|
+
const { databaseURL } = getEnvironment();
|
2109
|
+
return databaseURL;
|
1931
2110
|
} catch (err) {
|
1932
2111
|
return void 0;
|
1933
2112
|
}
|
@@ -1956,17 +2135,20 @@ var __privateMethod = (obj, member, method) => {
|
|
1956
2135
|
return method;
|
1957
2136
|
};
|
1958
2137
|
const buildClient = (plugins) => {
|
1959
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2138
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1960
2139
|
return _a = class {
|
1961
2140
|
constructor(options = {}, schemaTables) {
|
1962
2141
|
__privateAdd(this, _parseOptions);
|
1963
2142
|
__privateAdd(this, _getFetchProps);
|
1964
2143
|
__privateAdd(this, _evaluateBranch);
|
1965
2144
|
__privateAdd(this, _branch, void 0);
|
2145
|
+
__privateAdd(this, _options, void 0);
|
1966
2146
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2147
|
+
__privateSet(this, _options, safeOptions);
|
1967
2148
|
const pluginOptions = {
|
1968
2149
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1969
|
-
cache: safeOptions.cache
|
2150
|
+
cache: safeOptions.cache,
|
2151
|
+
trace: safeOptions.trace
|
1970
2152
|
};
|
1971
2153
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1972
2154
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -1985,22 +2167,26 @@ const buildClient = (plugins) => {
|
|
1985
2167
|
}
|
1986
2168
|
}
|
1987
2169
|
}
|
1988
|
-
|
2170
|
+
async getConfig() {
|
2171
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2172
|
+
const branch = await __privateGet(this, _options).branch();
|
2173
|
+
return { databaseURL, branch };
|
2174
|
+
}
|
2175
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1989
2176
|
const fetch = getFetchImplementation(options?.fetch);
|
1990
2177
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1991
2178
|
const apiKey = options?.apiKey || getAPIKey();
|
1992
|
-
const cache = options?.cache ?? new SimpleCache({
|
2179
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2180
|
+
const trace = options?.trace ?? defaultTrace;
|
1993
2181
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1994
|
-
if (!
|
1995
|
-
throw new Error("
|
2182
|
+
if (!apiKey) {
|
2183
|
+
throw new Error("Option apiKey is required");
|
1996
2184
|
}
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
apiKey,
|
2001
|
-
|
2002
|
-
branch
|
2003
|
-
}) {
|
2185
|
+
if (!databaseURL) {
|
2186
|
+
throw new Error("Option databaseURL is required");
|
2187
|
+
}
|
2188
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2189
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2004
2190
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2005
2191
|
if (!branchValue)
|
2006
2192
|
throw new Error("Unable to resolve branch value");
|
@@ -2012,7 +2198,8 @@ const buildClient = (plugins) => {
|
|
2012
2198
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2013
2199
|
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2014
2200
|
return databaseURL + newPath;
|
2015
|
-
}
|
2201
|
+
},
|
2202
|
+
trace
|
2016
2203
|
};
|
2017
2204
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2018
2205
|
if (__privateGet(this, _branch))
|
@@ -2035,6 +2222,88 @@ const buildClient = (plugins) => {
|
|
2035
2222
|
class BaseClient extends buildClient() {
|
2036
2223
|
}
|
2037
2224
|
|
2225
|
+
const META = "__";
|
2226
|
+
const VALUE = "___";
|
2227
|
+
class Serializer {
|
2228
|
+
constructor() {
|
2229
|
+
this.classes = {};
|
2230
|
+
}
|
2231
|
+
add(clazz) {
|
2232
|
+
this.classes[clazz.name] = clazz;
|
2233
|
+
}
|
2234
|
+
toJSON(data) {
|
2235
|
+
function visit(obj) {
|
2236
|
+
if (Array.isArray(obj))
|
2237
|
+
return obj.map(visit);
|
2238
|
+
const type = typeof obj;
|
2239
|
+
if (type === "undefined")
|
2240
|
+
return { [META]: "undefined" };
|
2241
|
+
if (type === "bigint")
|
2242
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2243
|
+
if (obj === null || type !== "object")
|
2244
|
+
return obj;
|
2245
|
+
const constructor = obj.constructor;
|
2246
|
+
const o = { [META]: constructor.name };
|
2247
|
+
for (const [key, value] of Object.entries(obj)) {
|
2248
|
+
o[key] = visit(value);
|
2249
|
+
}
|
2250
|
+
if (constructor === Date)
|
2251
|
+
o[VALUE] = obj.toISOString();
|
2252
|
+
if (constructor === Map)
|
2253
|
+
o[VALUE] = Object.fromEntries(obj);
|
2254
|
+
if (constructor === Set)
|
2255
|
+
o[VALUE] = [...obj];
|
2256
|
+
return o;
|
2257
|
+
}
|
2258
|
+
return JSON.stringify(visit(data));
|
2259
|
+
}
|
2260
|
+
fromJSON(json) {
|
2261
|
+
return JSON.parse(json, (key, value) => {
|
2262
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2263
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2264
|
+
const constructor = this.classes[clazz];
|
2265
|
+
if (constructor) {
|
2266
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2267
|
+
}
|
2268
|
+
if (clazz === "Date")
|
2269
|
+
return new Date(val);
|
2270
|
+
if (clazz === "Set")
|
2271
|
+
return new Set(val);
|
2272
|
+
if (clazz === "Map")
|
2273
|
+
return new Map(Object.entries(val));
|
2274
|
+
if (clazz === "bigint")
|
2275
|
+
return BigInt(val);
|
2276
|
+
if (clazz === "undefined")
|
2277
|
+
return void 0;
|
2278
|
+
return rest;
|
2279
|
+
}
|
2280
|
+
return value;
|
2281
|
+
});
|
2282
|
+
}
|
2283
|
+
}
|
2284
|
+
const defaultSerializer = new Serializer();
|
2285
|
+
const serialize = (data) => {
|
2286
|
+
return defaultSerializer.toJSON(data);
|
2287
|
+
};
|
2288
|
+
const deserialize = (json) => {
|
2289
|
+
return defaultSerializer.fromJSON(json);
|
2290
|
+
};
|
2291
|
+
|
2292
|
+
function buildWorkerRunner(config) {
|
2293
|
+
return function xataWorker(name, _worker) {
|
2294
|
+
return async (...args) => {
|
2295
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2296
|
+
const result = await fetch(url, {
|
2297
|
+
method: "POST",
|
2298
|
+
headers: { "Content-Type": "application/json" },
|
2299
|
+
body: serialize({ args })
|
2300
|
+
});
|
2301
|
+
const text = await result.text();
|
2302
|
+
return deserialize(text);
|
2303
|
+
};
|
2304
|
+
};
|
2305
|
+
}
|
2306
|
+
|
2038
2307
|
class XataError extends Error {
|
2039
2308
|
constructor(message, status) {
|
2040
2309
|
super(message);
|
@@ -2042,5 +2311,5 @@ class XataError extends Error {
|
|
2042
2311
|
}
|
2043
2312
|
}
|
2044
2313
|
|
2045
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
2314
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2046
2315
|
//# sourceMappingURL=index.mjs.map
|