@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.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,6 +59,9 @@ 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);
|
@@ -26,35 +71,83 @@ function toBase64(value) {
|
|
26
71
|
}
|
27
72
|
}
|
28
73
|
|
29
|
-
function
|
74
|
+
function getEnvironment() {
|
30
75
|
try {
|
31
|
-
if (isObject(process) &&
|
32
|
-
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
|
+
};
|
33
84
|
}
|
34
85
|
} catch (err) {
|
35
86
|
}
|
36
87
|
try {
|
37
|
-
if (isObject(Deno) &&
|
38
|
-
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
|
+
};
|
39
96
|
}
|
40
97
|
} catch (err) {
|
41
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
|
+
}
|
42
134
|
}
|
43
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"] };
|
44
140
|
try {
|
45
141
|
if (typeof require === "function") {
|
46
|
-
|
47
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
142
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
48
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();
|
49
146
|
} catch (err) {
|
50
147
|
}
|
51
148
|
try {
|
52
149
|
if (isObject(Deno)) {
|
53
|
-
const process2 = Deno.run({
|
54
|
-
cmd: ["git", "branch", "--show-current"],
|
55
|
-
stdout: "piped",
|
56
|
-
stderr: "piped"
|
57
|
-
});
|
150
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
58
151
|
return new TextDecoder().decode(await process2.output()).trim();
|
59
152
|
}
|
60
153
|
} catch (err) {
|
@@ -63,7 +156,8 @@ async function getGitBranch() {
|
|
63
156
|
|
64
157
|
function getAPIKey() {
|
65
158
|
try {
|
66
|
-
|
159
|
+
const { apiKey } = getEnvironment();
|
160
|
+
return apiKey;
|
67
161
|
} catch (err) {
|
68
162
|
return void 0;
|
69
163
|
}
|
@@ -73,12 +167,14 @@ function getFetchImplementation(userFetch) {
|
|
73
167
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
74
168
|
const fetchImpl = userFetch ?? globalFetch;
|
75
169
|
if (!fetchImpl) {
|
76
|
-
throw new Error(
|
170
|
+
throw new Error(
|
171
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
172
|
+
);
|
77
173
|
}
|
78
174
|
return fetchImpl;
|
79
175
|
}
|
80
176
|
|
81
|
-
const VERSION = "0.0.0-alpha.
|
177
|
+
const VERSION = "0.0.0-alpha.vfeb24b1";
|
82
178
|
|
83
179
|
class ErrorWithCause extends Error {
|
84
180
|
constructor(message, options) {
|
@@ -157,34 +253,62 @@ async function fetch$1({
|
|
157
253
|
fetchImpl,
|
158
254
|
apiKey,
|
159
255
|
apiUrl,
|
160
|
-
workspacesApiUrl
|
256
|
+
workspacesApiUrl,
|
257
|
+
trace
|
161
258
|
}) {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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) {
|
180
307
|
try {
|
181
|
-
const
|
182
|
-
|
183
|
-
return jsonResponse;
|
184
|
-
}
|
185
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
308
|
+
const { host, protocol } = new URL(url);
|
309
|
+
return { host, protocol };
|
186
310
|
} catch (error) {
|
187
|
-
|
311
|
+
return {};
|
188
312
|
}
|
189
313
|
}
|
190
314
|
|
@@ -243,6 +367,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
243
367
|
...variables
|
244
368
|
});
|
245
369
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
370
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
246
371
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
247
372
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
248
373
|
method: "delete",
|
@@ -278,6 +403,11 @@ const deleteDatabase = (variables) => fetch$1({
|
|
278
403
|
method: "delete",
|
279
404
|
...variables
|
280
405
|
});
|
406
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
407
|
+
url: "/dbs/{dbName}/metadata",
|
408
|
+
method: "get",
|
409
|
+
...variables
|
410
|
+
});
|
281
411
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
282
412
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
283
413
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -291,11 +421,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
291
421
|
method: "get",
|
292
422
|
...variables
|
293
423
|
});
|
294
|
-
const createBranch = (variables) => fetch$1({
|
295
|
-
url: "/db/{dbBranchName}",
|
296
|
-
method: "put",
|
297
|
-
...variables
|
298
|
-
});
|
424
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
299
425
|
const deleteBranch = (variables) => fetch$1({
|
300
426
|
url: "/db/{dbBranchName}",
|
301
427
|
method: "delete",
|
@@ -369,11 +495,7 @@ const updateColumn = (variables) => fetch$1({
|
|
369
495
|
method: "patch",
|
370
496
|
...variables
|
371
497
|
});
|
372
|
-
const insertRecord = (variables) => fetch$1({
|
373
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
374
|
-
method: "post",
|
375
|
-
...variables
|
376
|
-
});
|
498
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
377
499
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
378
500
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
379
501
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -415,6 +537,7 @@ const operationsByTag = {
|
|
415
537
|
updateWorkspaceMemberRole,
|
416
538
|
removeWorkspaceMember,
|
417
539
|
inviteWorkspaceMember,
|
540
|
+
updateWorkspaceMemberInvite,
|
418
541
|
cancelWorkspaceMemberInvite,
|
419
542
|
resendWorkspaceMemberInvite,
|
420
543
|
acceptWorkspaceMemberInvite
|
@@ -423,6 +546,7 @@ const operationsByTag = {
|
|
423
546
|
getDatabaseList,
|
424
547
|
createDatabase,
|
425
548
|
deleteDatabase,
|
549
|
+
getDatabaseMetadata,
|
426
550
|
getGitBranchesMapping,
|
427
551
|
addGitBranchesEntry,
|
428
552
|
removeGitBranchesEntry,
|
@@ -515,7 +639,8 @@ class XataApiClient {
|
|
515
639
|
__privateAdd$7(this, _extraProps, void 0);
|
516
640
|
__privateAdd$7(this, _namespaces, {});
|
517
641
|
const provider = options.host ?? "production";
|
518
|
-
const apiKey = options
|
642
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
643
|
+
const trace = options.trace ?? defaultTrace;
|
519
644
|
if (!apiKey) {
|
520
645
|
throw new Error("Could not resolve a valid apiKey");
|
521
646
|
}
|
@@ -523,7 +648,8 @@ class XataApiClient {
|
|
523
648
|
apiUrl: getHostUrl(provider, "main"),
|
524
649
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
525
650
|
fetchImpl: getFetchImplementation(options.fetch),
|
526
|
-
apiKey
|
651
|
+
apiKey,
|
652
|
+
trace
|
527
653
|
});
|
528
654
|
}
|
529
655
|
get user() {
|
@@ -646,6 +772,13 @@ class WorkspaceApi {
|
|
646
772
|
...this.extraProps
|
647
773
|
});
|
648
774
|
}
|
775
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
776
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
777
|
+
pathParams: { workspaceId, inviteId },
|
778
|
+
body: { role },
|
779
|
+
...this.extraProps
|
780
|
+
});
|
781
|
+
}
|
649
782
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
650
783
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
651
784
|
pathParams: { workspaceId, inviteId },
|
@@ -688,6 +821,12 @@ class DatabaseApi {
|
|
688
821
|
...this.extraProps
|
689
822
|
});
|
690
823
|
}
|
824
|
+
getDatabaseMetadata(workspace, dbName) {
|
825
|
+
return operationsByTag.database.getDatabaseMetadata({
|
826
|
+
pathParams: { workspace, dbName },
|
827
|
+
...this.extraProps
|
828
|
+
});
|
829
|
+
}
|
691
830
|
getGitBranchesMapping(workspace, dbName) {
|
692
831
|
return operationsByTag.database.getGitBranchesMapping({
|
693
832
|
pathParams: { workspace, dbName },
|
@@ -860,9 +999,10 @@ class RecordsApi {
|
|
860
999
|
constructor(extraProps) {
|
861
1000
|
this.extraProps = extraProps;
|
862
1001
|
}
|
863
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1002
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
864
1003
|
return operationsByTag.records.insertRecord({
|
865
1004
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1005
|
+
queryParams: options,
|
866
1006
|
body: record,
|
867
1007
|
...this.extraProps
|
868
1008
|
});
|
@@ -891,21 +1031,24 @@ class RecordsApi {
|
|
891
1031
|
...this.extraProps
|
892
1032
|
});
|
893
1033
|
}
|
894
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1034
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
895
1035
|
return operationsByTag.records.deleteRecord({
|
896
1036
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1037
|
+
queryParams: options,
|
897
1038
|
...this.extraProps
|
898
1039
|
});
|
899
1040
|
}
|
900
1041
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
901
1042
|
return operationsByTag.records.getRecord({
|
902
1043
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1044
|
+
queryParams: options,
|
903
1045
|
...this.extraProps
|
904
1046
|
});
|
905
1047
|
}
|
906
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1048
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
907
1049
|
return operationsByTag.records.bulkInsertTableRecords({
|
908
1050
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1051
|
+
queryParams: options,
|
909
1052
|
body: { records },
|
910
1053
|
...this.extraProps
|
911
1054
|
});
|
@@ -997,7 +1140,7 @@ const _RecordArray = class extends Array {
|
|
997
1140
|
constructor(...args) {
|
998
1141
|
super(..._RecordArray.parseConstructorParams(...args));
|
999
1142
|
__privateAdd$6(this, _page, void 0);
|
1000
|
-
__privateSet$6(this, _page, args[0]);
|
1143
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1001
1144
|
}
|
1002
1145
|
static parseConstructorParams(...args) {
|
1003
1146
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -1009,6 +1152,12 @@ const _RecordArray = class extends Array {
|
|
1009
1152
|
}
|
1010
1153
|
return new Array(...args);
|
1011
1154
|
}
|
1155
|
+
toArray() {
|
1156
|
+
return new Array(...this);
|
1157
|
+
}
|
1158
|
+
map(callbackfn, thisArg) {
|
1159
|
+
return this.toArray().map(callbackfn, thisArg);
|
1160
|
+
}
|
1012
1161
|
async nextPage(size, offset) {
|
1013
1162
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1014
1163
|
return new _RecordArray(newPage);
|
@@ -1117,13 +1266,18 @@ const _Query = class {
|
|
1117
1266
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1118
1267
|
}
|
1119
1268
|
}
|
1120
|
-
sort(column, direction) {
|
1269
|
+
sort(column, direction = "asc") {
|
1121
1270
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1122
1271
|
const sort = [...originalSort, { column, direction }];
|
1123
1272
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1124
1273
|
}
|
1125
1274
|
select(columns) {
|
1126
|
-
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
|
+
);
|
1127
1281
|
}
|
1128
1282
|
getPaginated(options = {}) {
|
1129
1283
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1164,6 +1318,12 @@ const _Query = class {
|
|
1164
1318
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1165
1319
|
return records[0] ?? null;
|
1166
1320
|
}
|
1321
|
+
async getFirstOrThrow(options = {}) {
|
1322
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1323
|
+
if (records[0] === void 0)
|
1324
|
+
throw new Error("No results found.");
|
1325
|
+
return records[0];
|
1326
|
+
}
|
1167
1327
|
cache(ttl) {
|
1168
1328
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1169
1329
|
}
|
@@ -1248,7 +1408,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1248
1408
|
__accessCheck$4(obj, member, "access private method");
|
1249
1409
|
return method;
|
1250
1410
|
};
|
1251
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1411
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1252
1412
|
class Repository extends Query {
|
1253
1413
|
}
|
1254
1414
|
class RestRepository extends Query {
|
@@ -1260,191 +1420,254 @@ class RestRepository extends Query {
|
|
1260
1420
|
__privateAdd$4(this, _updateRecordWithID);
|
1261
1421
|
__privateAdd$4(this, _upsertRecordWithID);
|
1262
1422
|
__privateAdd$4(this, _deleteRecord);
|
1263
|
-
__privateAdd$4(this, _invalidateCache);
|
1264
|
-
__privateAdd$4(this, _setCacheRecord);
|
1265
|
-
__privateAdd$4(this, _getCacheRecord);
|
1266
1423
|
__privateAdd$4(this, _setCacheQuery);
|
1267
1424
|
__privateAdd$4(this, _getCacheQuery);
|
1268
1425
|
__privateAdd$4(this, _getSchemaTables$1);
|
1269
1426
|
__privateAdd$4(this, _table, void 0);
|
1270
1427
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1428
|
+
__privateAdd$4(this, _db, void 0);
|
1271
1429
|
__privateAdd$4(this, _cache, void 0);
|
1272
1430
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1431
|
+
__privateAdd$4(this, _trace, void 0);
|
1273
1432
|
__privateSet$4(this, _table, options.table);
|
1274
1433
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1275
|
-
this
|
1434
|
+
__privateSet$4(this, _db, options.db);
|
1276
1435
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1277
1436
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1437
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1438
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1439
|
+
return trace(name, fn, {
|
1440
|
+
...options2,
|
1441
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1442
|
+
[TraceAttributes.VERSION]: VERSION
|
1443
|
+
});
|
1444
|
+
});
|
1278
1445
|
}
|
1279
|
-
async create(a, b) {
|
1280
|
-
|
1281
|
-
if (a
|
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
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
const
|
1321
|
-
|
1322
|
-
const
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1446
|
+
async create(a, b, c) {
|
1447
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1448
|
+
if (Array.isArray(a)) {
|
1449
|
+
if (a.length === 0)
|
1450
|
+
return [];
|
1451
|
+
const columns = isStringArray(b) ? b : void 0;
|
1452
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1453
|
+
}
|
1454
|
+
if (isString(a) && isObject(b)) {
|
1455
|
+
if (a === "")
|
1456
|
+
throw new Error("The id can't be empty");
|
1457
|
+
const columns = isStringArray(c) ? c : void 0;
|
1458
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1459
|
+
}
|
1460
|
+
if (isObject(a) && isString(a.id)) {
|
1461
|
+
if (a.id === "")
|
1462
|
+
throw new Error("The id can't be empty");
|
1463
|
+
const columns = isStringArray(b) ? b : void 0;
|
1464
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1465
|
+
}
|
1466
|
+
if (isObject(a)) {
|
1467
|
+
const columns = isStringArray(b) ? b : void 0;
|
1468
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1469
|
+
}
|
1470
|
+
throw new Error("Invalid arguments for create method");
|
1471
|
+
});
|
1472
|
+
}
|
1473
|
+
async read(a, b) {
|
1474
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1475
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1476
|
+
if (Array.isArray(a)) {
|
1477
|
+
if (a.length === 0)
|
1478
|
+
return [];
|
1479
|
+
const ids = a.map((item) => extractId(item));
|
1480
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1481
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1482
|
+
acc[object.id] = object;
|
1483
|
+
return acc;
|
1484
|
+
}, {});
|
1485
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1486
|
+
}
|
1487
|
+
const id = extractId(a);
|
1488
|
+
if (id) {
|
1489
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1490
|
+
try {
|
1491
|
+
const response = await getRecord({
|
1492
|
+
pathParams: {
|
1493
|
+
workspace: "{workspaceId}",
|
1494
|
+
dbBranchName: "{dbBranch}",
|
1495
|
+
tableName: __privateGet$4(this, _table),
|
1496
|
+
recordId: id
|
1497
|
+
},
|
1498
|
+
queryParams: { columns },
|
1499
|
+
...fetchProps
|
1500
|
+
});
|
1501
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1502
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1503
|
+
} catch (e) {
|
1504
|
+
if (isObject(e) && e.status === 404) {
|
1505
|
+
return null;
|
1506
|
+
}
|
1507
|
+
throw e;
|
1331
1508
|
}
|
1332
|
-
throw e;
|
1333
1509
|
}
|
1334
|
-
|
1510
|
+
return null;
|
1511
|
+
});
|
1335
1512
|
}
|
1336
|
-
async
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1513
|
+
async readOrThrow(a, b) {
|
1514
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1515
|
+
const result = await this.read(a, b);
|
1516
|
+
if (Array.isArray(result)) {
|
1517
|
+
const missingIds = compact(
|
1518
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1519
|
+
);
|
1520
|
+
if (missingIds.length > 0) {
|
1521
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1522
|
+
}
|
1523
|
+
return result;
|
1342
1524
|
}
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1347
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1348
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1349
|
-
return record;
|
1350
|
-
}
|
1351
|
-
if (isObject(a) && isString(a.id)) {
|
1352
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1353
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1354
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1355
|
-
return record;
|
1356
|
-
}
|
1357
|
-
throw new Error("Invalid arguments for update method");
|
1358
|
-
}
|
1359
|
-
async createOrUpdate(a, b) {
|
1360
|
-
if (Array.isArray(a)) {
|
1361
|
-
if (a.length === 0)
|
1362
|
-
return [];
|
1363
|
-
if (a.length > 100) {
|
1364
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1525
|
+
if (result === null) {
|
1526
|
+
const id = extractId(a) ?? "unknown";
|
1527
|
+
throw new Error(`Record with id ${id} not found`);
|
1365
1528
|
}
|
1366
|
-
return
|
1367
|
-
}
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
}
|
1380
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1381
|
-
}
|
1382
|
-
async delete(a) {
|
1383
|
-
if (Array.isArray(a)) {
|
1384
|
-
if (a.length === 0)
|
1385
|
-
return;
|
1386
|
-
if (a.length > 100) {
|
1387
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1529
|
+
return result;
|
1530
|
+
});
|
1531
|
+
}
|
1532
|
+
async update(a, b, c) {
|
1533
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1534
|
+
if (Array.isArray(a)) {
|
1535
|
+
if (a.length === 0)
|
1536
|
+
return [];
|
1537
|
+
if (a.length > 100) {
|
1538
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1539
|
+
}
|
1540
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1541
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1388
1542
|
}
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1543
|
+
if (isString(a) && isObject(b)) {
|
1544
|
+
const columns = isStringArray(c) ? c : void 0;
|
1545
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1546
|
+
}
|
1547
|
+
if (isObject(a) && isString(a.id)) {
|
1548
|
+
const columns = isStringArray(b) ? b : void 0;
|
1549
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1550
|
+
}
|
1551
|
+
throw new Error("Invalid arguments for update method");
|
1552
|
+
});
|
1553
|
+
}
|
1554
|
+
async updateOrThrow(a, b, c) {
|
1555
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1556
|
+
const result = await this.update(a, b, c);
|
1557
|
+
if (Array.isArray(result)) {
|
1558
|
+
const missingIds = compact(
|
1559
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1560
|
+
);
|
1561
|
+
if (missingIds.length > 0) {
|
1562
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1563
|
+
}
|
1564
|
+
return result;
|
1565
|
+
}
|
1566
|
+
if (result === null) {
|
1567
|
+
const id = extractId(a) ?? "unknown";
|
1568
|
+
throw new Error(`Record with id ${id} not found`);
|
1569
|
+
}
|
1570
|
+
return result;
|
1571
|
+
});
|
1572
|
+
}
|
1573
|
+
async createOrUpdate(a, b, c) {
|
1574
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1575
|
+
if (Array.isArray(a)) {
|
1576
|
+
if (a.length === 0)
|
1577
|
+
return [];
|
1578
|
+
if (a.length > 100) {
|
1579
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1580
|
+
}
|
1581
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1582
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1583
|
+
}
|
1584
|
+
if (isString(a) && isObject(b)) {
|
1585
|
+
const columns = isStringArray(c) ? c : void 0;
|
1586
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1587
|
+
}
|
1588
|
+
if (isObject(a) && isString(a.id)) {
|
1589
|
+
const columns = isStringArray(c) ? c : void 0;
|
1590
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1591
|
+
}
|
1592
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1593
|
+
});
|
1594
|
+
}
|
1595
|
+
async delete(a, b) {
|
1596
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1597
|
+
if (Array.isArray(a)) {
|
1598
|
+
if (a.length === 0)
|
1599
|
+
return [];
|
1600
|
+
if (a.length > 100) {
|
1601
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1602
|
+
}
|
1603
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1604
|
+
}
|
1605
|
+
if (isString(a)) {
|
1606
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1607
|
+
}
|
1608
|
+
if (isObject(a) && isString(a.id)) {
|
1609
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1610
|
+
}
|
1611
|
+
throw new Error("Invalid arguments for delete method");
|
1612
|
+
});
|
1613
|
+
}
|
1614
|
+
async deleteOrThrow(a, b) {
|
1615
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1616
|
+
throw new Error("Not implemented");
|
1617
|
+
});
|
1403
1618
|
}
|
1404
1619
|
async search(query, options = {}) {
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1620
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1621
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1622
|
+
const { records } = await searchTable({
|
1623
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1624
|
+
body: {
|
1625
|
+
query,
|
1626
|
+
fuzziness: options.fuzziness,
|
1627
|
+
prefix: options.prefix,
|
1628
|
+
highlight: options.highlight,
|
1629
|
+
filter: options.filter,
|
1630
|
+
boosters: options.boosters
|
1631
|
+
},
|
1632
|
+
...fetchProps
|
1633
|
+
});
|
1634
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1635
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1415
1636
|
});
|
1416
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1417
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1418
1637
|
}
|
1419
1638
|
async query(query) {
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1639
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1640
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1641
|
+
if (cacheQuery)
|
1642
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1643
|
+
const data = query.getQueryOptions();
|
1644
|
+
const body = {
|
1645
|
+
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1646
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1647
|
+
page: data.pagination,
|
1648
|
+
columns: data.columns
|
1649
|
+
};
|
1650
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1651
|
+
const { meta, records: objects } = await queryTable({
|
1652
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1653
|
+
body,
|
1654
|
+
...fetchProps
|
1655
|
+
});
|
1656
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1657
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1658
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1659
|
+
return new Page(query, meta, records);
|
1435
1660
|
});
|
1436
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1437
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1438
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1439
|
-
return new Page(query, meta, records);
|
1440
1661
|
}
|
1441
1662
|
}
|
1442
1663
|
_table = new WeakMap();
|
1443
1664
|
_getFetchProps = new WeakMap();
|
1665
|
+
_db = new WeakMap();
|
1444
1666
|
_cache = new WeakMap();
|
1445
1667
|
_schemaTables$2 = new WeakMap();
|
1668
|
+
_trace = new WeakMap();
|
1446
1669
|
_insertRecordWithoutId = new WeakSet();
|
1447
|
-
insertRecordWithoutId_fn = async function(object) {
|
1670
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1448
1671
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1449
1672
|
const record = transformObjectLinks(object);
|
1450
1673
|
const response = await insertRecord({
|
@@ -1453,17 +1676,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1453
1676
|
dbBranchName: "{dbBranch}",
|
1454
1677
|
tableName: __privateGet$4(this, _table)
|
1455
1678
|
},
|
1679
|
+
queryParams: { columns },
|
1456
1680
|
body: record,
|
1457
1681
|
...fetchProps
|
1458
1682
|
});
|
1459
|
-
const
|
1460
|
-
|
1461
|
-
throw new Error("The server failed to save the record");
|
1462
|
-
}
|
1463
|
-
return finalObject;
|
1683
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1684
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1464
1685
|
};
|
1465
1686
|
_insertRecordWithId = new WeakSet();
|
1466
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1687
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1467
1688
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1468
1689
|
const record = transformObjectLinks(object);
|
1469
1690
|
const response = await insertRecordWithID({
|
@@ -1474,91 +1695,63 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1474
1695
|
recordId
|
1475
1696
|
},
|
1476
1697
|
body: record,
|
1477
|
-
queryParams: { createOnly: true },
|
1698
|
+
queryParams: { createOnly: true, columns },
|
1478
1699
|
...fetchProps
|
1479
1700
|
});
|
1480
|
-
const
|
1481
|
-
|
1482
|
-
throw new Error("The server failed to save the record");
|
1483
|
-
}
|
1484
|
-
return finalObject;
|
1701
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1702
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1485
1703
|
};
|
1486
1704
|
_bulkInsertTableRecords = new WeakSet();
|
1487
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1705
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1488
1706
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1489
1707
|
const records = objects.map((object) => transformObjectLinks(object));
|
1490
|
-
const
|
1708
|
+
const response = await bulkInsertTableRecords({
|
1491
1709
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1710
|
+
queryParams: { columns },
|
1492
1711
|
body: { records },
|
1493
1712
|
...fetchProps
|
1494
1713
|
});
|
1495
|
-
|
1496
|
-
|
1497
|
-
throw new Error("The server failed to save some records");
|
1714
|
+
if (!isResponseWithRecords(response)) {
|
1715
|
+
throw new Error("Request included columns but server didn't include them");
|
1498
1716
|
}
|
1499
|
-
const
|
1500
|
-
|
1501
|
-
return acc;
|
1502
|
-
}, {});
|
1503
|
-
return recordIDs.map((id) => dictionary[id]);
|
1717
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1718
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1504
1719
|
};
|
1505
1720
|
_updateRecordWithID = new WeakSet();
|
1506
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1721
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1507
1722
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1508
1723
|
const record = transformObjectLinks(object);
|
1509
1724
|
const response = await updateRecordWithID({
|
1510
1725
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1726
|
+
queryParams: { columns },
|
1511
1727
|
body: record,
|
1512
1728
|
...fetchProps
|
1513
1729
|
});
|
1514
|
-
const
|
1515
|
-
|
1516
|
-
throw new Error("The server failed to save the record");
|
1517
|
-
return item;
|
1730
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1731
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1518
1732
|
};
|
1519
1733
|
_upsertRecordWithID = new WeakSet();
|
1520
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1734
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1521
1735
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1522
1736
|
const response = await upsertRecordWithID({
|
1523
1737
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1738
|
+
queryParams: { columns },
|
1524
1739
|
body: object,
|
1525
1740
|
...fetchProps
|
1526
1741
|
});
|
1527
|
-
const
|
1528
|
-
|
1529
|
-
throw new Error("The server failed to save the record");
|
1530
|
-
return item;
|
1742
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1743
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1531
1744
|
};
|
1532
1745
|
_deleteRecord = new WeakSet();
|
1533
|
-
deleteRecord_fn = async function(recordId) {
|
1746
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1534
1747
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1535
|
-
await deleteRecord({
|
1748
|
+
const response = await deleteRecord({
|
1536
1749
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1750
|
+
queryParams: { columns },
|
1537
1751
|
...fetchProps
|
1538
1752
|
});
|
1539
|
-
|
1540
|
-
|
1541
|
-
invalidateCache_fn = async function(recordId) {
|
1542
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1543
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1544
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1545
|
-
for (const [key, value] of queries) {
|
1546
|
-
const ids = getIds(value);
|
1547
|
-
if (ids.includes(recordId))
|
1548
|
-
await __privateGet$4(this, _cache).delete(key);
|
1549
|
-
}
|
1550
|
-
};
|
1551
|
-
_setCacheRecord = new WeakSet();
|
1552
|
-
setCacheRecord_fn = async function(record) {
|
1553
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1554
|
-
return;
|
1555
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1556
|
-
};
|
1557
|
-
_getCacheRecord = new WeakSet();
|
1558
|
-
getCacheRecord_fn = async function(recordId) {
|
1559
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1560
|
-
return null;
|
1561
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1753
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1754
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1562
1755
|
};
|
1563
1756
|
_setCacheQuery = new WeakSet();
|
1564
1757
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1625,11 +1818,11 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1625
1818
|
}
|
1626
1819
|
}
|
1627
1820
|
}
|
1628
|
-
result.read = function() {
|
1629
|
-
return db[table].read(result["id"]);
|
1821
|
+
result.read = function(columns2) {
|
1822
|
+
return db[table].read(result["id"], columns2);
|
1630
1823
|
};
|
1631
|
-
result.update = function(data) {
|
1632
|
-
return db[table].update(result["id"], data);
|
1824
|
+
result.update = function(data, columns2) {
|
1825
|
+
return db[table].update(result["id"], data, columns2);
|
1633
1826
|
};
|
1634
1827
|
result.delete = function() {
|
1635
1828
|
return db[table].delete(result["id"]);
|
@@ -1643,14 +1836,15 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1643
1836
|
Object.freeze(result);
|
1644
1837
|
return result;
|
1645
1838
|
};
|
1646
|
-
function
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
if (
|
1651
|
-
return
|
1652
|
-
|
1653
|
-
|
1839
|
+
function isResponseWithRecords(value) {
|
1840
|
+
return isObject(value) && Array.isArray(value.records);
|
1841
|
+
}
|
1842
|
+
function extractId(value) {
|
1843
|
+
if (isString(value))
|
1844
|
+
return value;
|
1845
|
+
if (isObject(value) && isString(value.id))
|
1846
|
+
return value.id;
|
1847
|
+
return void 0;
|
1654
1848
|
}
|
1655
1849
|
|
1656
1850
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1677,7 +1871,6 @@ class SimpleCache {
|
|
1677
1871
|
__privateAdd$3(this, _map, void 0);
|
1678
1872
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1679
1873
|
this.capacity = options.max ?? 500;
|
1680
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1681
1874
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1682
1875
|
}
|
1683
1876
|
async getAll() {
|
@@ -1703,18 +1896,25 @@ class SimpleCache {
|
|
1703
1896
|
}
|
1704
1897
|
_map = new WeakMap();
|
1705
1898
|
|
1706
|
-
const
|
1707
|
-
const
|
1708
|
-
const
|
1709
|
-
const
|
1710
|
-
const
|
1711
|
-
const
|
1899
|
+
const greaterThan = (value) => ({ $gt: value });
|
1900
|
+
const gt = greaterThan;
|
1901
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
1902
|
+
const greaterEquals = greaterThanEquals;
|
1903
|
+
const gte = greaterThanEquals;
|
1904
|
+
const ge = greaterThanEquals;
|
1905
|
+
const lessThan = (value) => ({ $lt: value });
|
1906
|
+
const lt = lessThan;
|
1907
|
+
const lessThanEquals = (value) => ({ $le: value });
|
1908
|
+
const lessEquals = lessThanEquals;
|
1909
|
+
const lte = lessThanEquals;
|
1910
|
+
const le = lessThanEquals;
|
1712
1911
|
const exists = (column) => ({ $exists: column });
|
1713
1912
|
const notExists = (column) => ({ $notExists: column });
|
1714
1913
|
const startsWith = (value) => ({ $startsWith: value });
|
1715
1914
|
const endsWith = (value) => ({ $endsWith: value });
|
1716
1915
|
const pattern = (value) => ({ $pattern: value });
|
1717
1916
|
const is = (value) => ({ $is: value });
|
1917
|
+
const equals = is;
|
1718
1918
|
const isNot = (value) => ({ $isNot: value });
|
1719
1919
|
const contains = (value) => ({ $contains: value });
|
1720
1920
|
const includes = (value) => ({ $includes: value });
|
@@ -1749,16 +1949,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1749
1949
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1750
1950
|
}
|
1751
1951
|
build(pluginOptions) {
|
1752
|
-
const db = new Proxy(
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1952
|
+
const db = new Proxy(
|
1953
|
+
{},
|
1954
|
+
{
|
1955
|
+
get: (_target, table) => {
|
1956
|
+
if (!isString(table))
|
1957
|
+
throw new Error("Invalid table name");
|
1958
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1959
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1960
|
+
}
|
1961
|
+
return __privateGet$2(this, _tables)[table];
|
1758
1962
|
}
|
1759
|
-
return __privateGet$2(this, _tables)[table];
|
1760
1963
|
}
|
1761
|
-
|
1964
|
+
);
|
1762
1965
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1763
1966
|
for (const table of tableNames) {
|
1764
1967
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1828,10 +2031,10 @@ _schemaTables = new WeakMap();
|
|
1828
2031
|
_search = new WeakSet();
|
1829
2032
|
search_fn = async function(query, options, getFetchProps) {
|
1830
2033
|
const fetchProps = await getFetchProps();
|
1831
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
2034
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1832
2035
|
const { records } = await searchBranch({
|
1833
2036
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1834
|
-
body: { tables, query, fuzziness, highlight },
|
2037
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1835
2038
|
...fetchProps
|
1836
2039
|
});
|
1837
2040
|
return records;
|
@@ -1853,21 +2056,15 @@ const isBranchStrategyBuilder = (strategy) => {
|
|
1853
2056
|
return typeof strategy === "function";
|
1854
2057
|
};
|
1855
2058
|
|
1856
|
-
const envBranchNames = [
|
1857
|
-
"XATA_BRANCH",
|
1858
|
-
"VERCEL_GIT_COMMIT_REF",
|
1859
|
-
"CF_PAGES_BRANCH",
|
1860
|
-
"BRANCH"
|
1861
|
-
];
|
1862
2059
|
async function getCurrentBranchName(options) {
|
1863
|
-
const
|
1864
|
-
if (
|
1865
|
-
const details = await getDatabaseBranch(
|
2060
|
+
const { branch, envBranch } = getEnvironment();
|
2061
|
+
if (branch) {
|
2062
|
+
const details = await getDatabaseBranch(branch, options);
|
1866
2063
|
if (details)
|
1867
|
-
return
|
1868
|
-
console.warn(`Branch ${
|
2064
|
+
return branch;
|
2065
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1869
2066
|
}
|
1870
|
-
const gitBranch = await getGitBranch();
|
2067
|
+
const gitBranch = envBranch || await getGitBranch();
|
1871
2068
|
return resolveXataBranch(gitBranch, options);
|
1872
2069
|
}
|
1873
2070
|
async function getCurrentBranchDetails(options) {
|
@@ -1878,18 +2075,24 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1878
2075
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1879
2076
|
const apiKey = options?.apiKey || getAPIKey();
|
1880
2077
|
if (!databaseURL)
|
1881
|
-
throw new Error(
|
2078
|
+
throw new Error(
|
2079
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2080
|
+
);
|
1882
2081
|
if (!apiKey)
|
1883
|
-
throw new Error(
|
2082
|
+
throw new Error(
|
2083
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2084
|
+
);
|
1884
2085
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1885
2086
|
const [workspace] = host.split(".");
|
2087
|
+
const { fallbackBranch } = getEnvironment();
|
1886
2088
|
const { branch } = await resolveBranch({
|
1887
2089
|
apiKey,
|
1888
2090
|
apiUrl: databaseURL,
|
1889
2091
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1890
2092
|
workspacesApiUrl: `${protocol}//${host}`,
|
1891
2093
|
pathParams: { dbName, workspace },
|
1892
|
-
queryParams: { gitBranch, fallbackBranch
|
2094
|
+
queryParams: { gitBranch, fallbackBranch },
|
2095
|
+
trace: defaultTrace
|
1893
2096
|
});
|
1894
2097
|
return branch;
|
1895
2098
|
}
|
@@ -1897,9 +2100,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1897
2100
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1898
2101
|
const apiKey = options?.apiKey || getAPIKey();
|
1899
2102
|
if (!databaseURL)
|
1900
|
-
throw new Error(
|
2103
|
+
throw new Error(
|
2104
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2105
|
+
);
|
1901
2106
|
if (!apiKey)
|
1902
|
-
throw new Error(
|
2107
|
+
throw new Error(
|
2108
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2109
|
+
);
|
1903
2110
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1904
2111
|
const [workspace] = host.split(".");
|
1905
2112
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1909,7 +2116,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1909
2116
|
apiUrl: databaseURL,
|
1910
2117
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1911
2118
|
workspacesApiUrl: `${protocol}//${host}`,
|
1912
|
-
pathParams: { dbBranchName, workspace }
|
2119
|
+
pathParams: { dbBranchName, workspace },
|
2120
|
+
trace: defaultTrace
|
1913
2121
|
});
|
1914
2122
|
} catch (err) {
|
1915
2123
|
if (isObject(err) && err.status === 404)
|
@@ -1917,21 +2125,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1917
2125
|
throw err;
|
1918
2126
|
}
|
1919
2127
|
}
|
1920
|
-
function getBranchByEnvVariable() {
|
1921
|
-
for (const name of envBranchNames) {
|
1922
|
-
const value = getEnvVariable(name);
|
1923
|
-
if (value) {
|
1924
|
-
return value;
|
1925
|
-
}
|
1926
|
-
}
|
1927
|
-
try {
|
1928
|
-
return XATA_BRANCH;
|
1929
|
-
} catch (err) {
|
1930
|
-
}
|
1931
|
-
}
|
1932
2128
|
function getDatabaseURL() {
|
1933
2129
|
try {
|
1934
|
-
|
2130
|
+
const { databaseURL } = getEnvironment();
|
2131
|
+
return databaseURL;
|
1935
2132
|
} catch (err) {
|
1936
2133
|
return void 0;
|
1937
2134
|
}
|
@@ -1960,17 +2157,20 @@ var __privateMethod = (obj, member, method) => {
|
|
1960
2157
|
return method;
|
1961
2158
|
};
|
1962
2159
|
const buildClient = (plugins) => {
|
1963
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2160
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1964
2161
|
return _a = class {
|
1965
2162
|
constructor(options = {}, schemaTables) {
|
1966
2163
|
__privateAdd(this, _parseOptions);
|
1967
2164
|
__privateAdd(this, _getFetchProps);
|
1968
2165
|
__privateAdd(this, _evaluateBranch);
|
1969
2166
|
__privateAdd(this, _branch, void 0);
|
2167
|
+
__privateAdd(this, _options, void 0);
|
1970
2168
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2169
|
+
__privateSet(this, _options, safeOptions);
|
1971
2170
|
const pluginOptions = {
|
1972
2171
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1973
|
-
cache: safeOptions.cache
|
2172
|
+
cache: safeOptions.cache,
|
2173
|
+
trace: safeOptions.trace
|
1974
2174
|
};
|
1975
2175
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1976
2176
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -1989,22 +2189,26 @@ const buildClient = (plugins) => {
|
|
1989
2189
|
}
|
1990
2190
|
}
|
1991
2191
|
}
|
1992
|
-
|
2192
|
+
async getConfig() {
|
2193
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2194
|
+
const branch = await __privateGet(this, _options).branch();
|
2195
|
+
return { databaseURL, branch };
|
2196
|
+
}
|
2197
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1993
2198
|
const fetch = getFetchImplementation(options?.fetch);
|
1994
2199
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1995
2200
|
const apiKey = options?.apiKey || getAPIKey();
|
1996
|
-
const cache = options?.cache ?? new SimpleCache({
|
2201
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2202
|
+
const trace = options?.trace ?? defaultTrace;
|
1997
2203
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1998
|
-
if (!
|
1999
|
-
throw new Error("
|
2204
|
+
if (!apiKey) {
|
2205
|
+
throw new Error("Option apiKey is required");
|
2000
2206
|
}
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
apiKey,
|
2005
|
-
|
2006
|
-
branch
|
2007
|
-
}) {
|
2207
|
+
if (!databaseURL) {
|
2208
|
+
throw new Error("Option databaseURL is required");
|
2209
|
+
}
|
2210
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2211
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2008
2212
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2009
2213
|
if (!branchValue)
|
2010
2214
|
throw new Error("Unable to resolve branch value");
|
@@ -2016,7 +2220,8 @@ const buildClient = (plugins) => {
|
|
2016
2220
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2017
2221
|
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2018
2222
|
return databaseURL + newPath;
|
2019
|
-
}
|
2223
|
+
},
|
2224
|
+
trace
|
2020
2225
|
};
|
2021
2226
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2022
2227
|
if (__privateGet(this, _branch))
|
@@ -2039,6 +2244,88 @@ const buildClient = (plugins) => {
|
|
2039
2244
|
class BaseClient extends buildClient() {
|
2040
2245
|
}
|
2041
2246
|
|
2247
|
+
const META = "__";
|
2248
|
+
const VALUE = "___";
|
2249
|
+
class Serializer {
|
2250
|
+
constructor() {
|
2251
|
+
this.classes = {};
|
2252
|
+
}
|
2253
|
+
add(clazz) {
|
2254
|
+
this.classes[clazz.name] = clazz;
|
2255
|
+
}
|
2256
|
+
toJSON(data) {
|
2257
|
+
function visit(obj) {
|
2258
|
+
if (Array.isArray(obj))
|
2259
|
+
return obj.map(visit);
|
2260
|
+
const type = typeof obj;
|
2261
|
+
if (type === "undefined")
|
2262
|
+
return { [META]: "undefined" };
|
2263
|
+
if (type === "bigint")
|
2264
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2265
|
+
if (obj === null || type !== "object")
|
2266
|
+
return obj;
|
2267
|
+
const constructor = obj.constructor;
|
2268
|
+
const o = { [META]: constructor.name };
|
2269
|
+
for (const [key, value] of Object.entries(obj)) {
|
2270
|
+
o[key] = visit(value);
|
2271
|
+
}
|
2272
|
+
if (constructor === Date)
|
2273
|
+
o[VALUE] = obj.toISOString();
|
2274
|
+
if (constructor === Map)
|
2275
|
+
o[VALUE] = Object.fromEntries(obj);
|
2276
|
+
if (constructor === Set)
|
2277
|
+
o[VALUE] = [...obj];
|
2278
|
+
return o;
|
2279
|
+
}
|
2280
|
+
return JSON.stringify(visit(data));
|
2281
|
+
}
|
2282
|
+
fromJSON(json) {
|
2283
|
+
return JSON.parse(json, (key, value) => {
|
2284
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2285
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2286
|
+
const constructor = this.classes[clazz];
|
2287
|
+
if (constructor) {
|
2288
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2289
|
+
}
|
2290
|
+
if (clazz === "Date")
|
2291
|
+
return new Date(val);
|
2292
|
+
if (clazz === "Set")
|
2293
|
+
return new Set(val);
|
2294
|
+
if (clazz === "Map")
|
2295
|
+
return new Map(Object.entries(val));
|
2296
|
+
if (clazz === "bigint")
|
2297
|
+
return BigInt(val);
|
2298
|
+
if (clazz === "undefined")
|
2299
|
+
return void 0;
|
2300
|
+
return rest;
|
2301
|
+
}
|
2302
|
+
return value;
|
2303
|
+
});
|
2304
|
+
}
|
2305
|
+
}
|
2306
|
+
const defaultSerializer = new Serializer();
|
2307
|
+
const serialize = (data) => {
|
2308
|
+
return defaultSerializer.toJSON(data);
|
2309
|
+
};
|
2310
|
+
const deserialize = (json) => {
|
2311
|
+
return defaultSerializer.fromJSON(json);
|
2312
|
+
};
|
2313
|
+
|
2314
|
+
function buildWorkerRunner(config) {
|
2315
|
+
return function xataWorker(name, _worker) {
|
2316
|
+
return async (...args) => {
|
2317
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2318
|
+
const result = await fetch(url, {
|
2319
|
+
method: "POST",
|
2320
|
+
headers: { "Content-Type": "application/json" },
|
2321
|
+
body: serialize({ args })
|
2322
|
+
});
|
2323
|
+
const text = await result.text();
|
2324
|
+
return deserialize(text);
|
2325
|
+
};
|
2326
|
+
};
|
2327
|
+
}
|
2328
|
+
|
2042
2329
|
class XataError extends Error {
|
2043
2330
|
constructor(message, status) {
|
2044
2331
|
super(message);
|
@@ -2059,6 +2346,7 @@ exports.Repository = Repository;
|
|
2059
2346
|
exports.RestRepository = RestRepository;
|
2060
2347
|
exports.SchemaPlugin = SchemaPlugin;
|
2061
2348
|
exports.SearchPlugin = SearchPlugin;
|
2349
|
+
exports.Serializer = Serializer;
|
2062
2350
|
exports.SimpleCache = SimpleCache;
|
2063
2351
|
exports.XataApiClient = XataApiClient;
|
2064
2352
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2068,6 +2356,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
|
2068
2356
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2069
2357
|
exports.addTableColumn = addTableColumn;
|
2070
2358
|
exports.buildClient = buildClient;
|
2359
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2071
2360
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2072
2361
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2073
2362
|
exports.contains = contains;
|
@@ -2084,7 +2373,9 @@ exports.deleteTable = deleteTable;
|
|
2084
2373
|
exports.deleteUser = deleteUser;
|
2085
2374
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2086
2375
|
exports.deleteWorkspace = deleteWorkspace;
|
2376
|
+
exports.deserialize = deserialize;
|
2087
2377
|
exports.endsWith = endsWith;
|
2378
|
+
exports.equals = equals;
|
2088
2379
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2089
2380
|
exports.exists = exists;
|
2090
2381
|
exports.ge = ge;
|
@@ -2099,6 +2390,7 @@ exports.getColumn = getColumn;
|
|
2099
2390
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
2100
2391
|
exports.getCurrentBranchName = getCurrentBranchName;
|
2101
2392
|
exports.getDatabaseList = getDatabaseList;
|
2393
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2102
2394
|
exports.getDatabaseURL = getDatabaseURL;
|
2103
2395
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
2104
2396
|
exports.getRecord = getRecord;
|
@@ -2109,6 +2401,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2109
2401
|
exports.getWorkspace = getWorkspace;
|
2110
2402
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2111
2403
|
exports.getWorkspacesList = getWorkspacesList;
|
2404
|
+
exports.greaterEquals = greaterEquals;
|
2405
|
+
exports.greaterThan = greaterThan;
|
2406
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2112
2407
|
exports.gt = gt;
|
2113
2408
|
exports.gte = gte;
|
2114
2409
|
exports.includes = includes;
|
@@ -2124,6 +2419,9 @@ exports.isIdentifiable = isIdentifiable;
|
|
2124
2419
|
exports.isNot = isNot;
|
2125
2420
|
exports.isXataRecord = isXataRecord;
|
2126
2421
|
exports.le = le;
|
2422
|
+
exports.lessEquals = lessEquals;
|
2423
|
+
exports.lessThan = lessThan;
|
2424
|
+
exports.lessThanEquals = lessThanEquals;
|
2127
2425
|
exports.lt = lt;
|
2128
2426
|
exports.lte = lte;
|
2129
2427
|
exports.notExists = notExists;
|
@@ -2136,6 +2434,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2136
2434
|
exports.resolveBranch = resolveBranch;
|
2137
2435
|
exports.searchBranch = searchBranch;
|
2138
2436
|
exports.searchTable = searchTable;
|
2437
|
+
exports.serialize = serialize;
|
2139
2438
|
exports.setTableSchema = setTableSchema;
|
2140
2439
|
exports.startsWith = startsWith;
|
2141
2440
|
exports.updateBranchMetadata = updateBranchMetadata;
|
@@ -2144,6 +2443,7 @@ exports.updateRecordWithID = updateRecordWithID;
|
|
2144
2443
|
exports.updateTable = updateTable;
|
2145
2444
|
exports.updateUser = updateUser;
|
2146
2445
|
exports.updateWorkspace = updateWorkspace;
|
2446
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2147
2447
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2148
2448
|
exports.upsertRecordWithID = upsertRecordWithID;
|
2149
2449
|
//# sourceMappingURL=index.cjs.map
|