@xata.io/client 0.16.1 → 0.17.1
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 +38 -0
- package/README.md +27 -25
- package/Usage.md +27 -6
- package/dist/index.cjs +546 -229
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +726 -103
- package/dist/index.mjs +526 -230
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
const defaultTrace = async (_name, fn, _options) => {
|
2
|
+
return await fn({
|
3
|
+
setAttributes: () => {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
});
|
7
|
+
};
|
8
|
+
const TraceAttributes = {
|
9
|
+
KIND: "xata.trace.kind",
|
10
|
+
VERSION: "xata.sdk.version",
|
11
|
+
TABLE: "xata.table",
|
12
|
+
HTTP_REQUEST_ID: "http.request_id",
|
13
|
+
HTTP_STATUS_CODE: "http.status_code",
|
14
|
+
HTTP_HOST: "http.host",
|
15
|
+
HTTP_SCHEME: "http.scheme",
|
16
|
+
HTTP_USER_AGENT: "http.user_agent",
|
17
|
+
HTTP_METHOD: "http.method",
|
18
|
+
HTTP_URL: "http.url",
|
19
|
+
HTTP_ROUTE: "http.route",
|
20
|
+
HTTP_TARGET: "http.target"
|
21
|
+
};
|
22
|
+
|
1
23
|
function notEmpty(value) {
|
2
24
|
return value !== null && value !== void 0;
|
3
25
|
}
|
@@ -122,13 +144,13 @@ function getFetchImplementation(userFetch) {
|
|
122
144
|
const fetchImpl = userFetch ?? globalFetch;
|
123
145
|
if (!fetchImpl) {
|
124
146
|
throw new Error(
|
125
|
-
`
|
147
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
126
148
|
);
|
127
149
|
}
|
128
150
|
return fetchImpl;
|
129
151
|
}
|
130
152
|
|
131
|
-
const VERSION = "0.
|
153
|
+
const VERSION = "0.17.1";
|
132
154
|
|
133
155
|
class ErrorWithCause extends Error {
|
134
156
|
constructor(message, options) {
|
@@ -179,7 +201,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
179
201
|
}, {});
|
180
202
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
181
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
182
|
-
|
204
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
205
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
206
|
+
}, {});
|
207
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
183
208
|
};
|
184
209
|
function buildBaseUrl({
|
185
210
|
path,
|
@@ -187,10 +212,10 @@ function buildBaseUrl({
|
|
187
212
|
apiUrl,
|
188
213
|
pathParams
|
189
214
|
}) {
|
190
|
-
if (
|
215
|
+
if (pathParams?.workspace === void 0)
|
191
216
|
return `${apiUrl}${path}`;
|
192
217
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
193
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
218
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
194
219
|
}
|
195
220
|
function hostHeader(url) {
|
196
221
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -207,34 +232,61 @@ async function fetch$1({
|
|
207
232
|
fetchImpl,
|
208
233
|
apiKey,
|
209
234
|
apiUrl,
|
210
|
-
workspacesApiUrl
|
235
|
+
workspacesApiUrl,
|
236
|
+
trace
|
211
237
|
}) {
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
238
|
+
return trace(
|
239
|
+
`${method.toUpperCase()} ${path}`,
|
240
|
+
async ({ setAttributes }) => {
|
241
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
242
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
243
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
244
|
+
setAttributes({
|
245
|
+
[TraceAttributes.HTTP_URL]: url,
|
246
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
247
|
+
});
|
248
|
+
const response = await fetchImpl(url, {
|
249
|
+
method: method.toUpperCase(),
|
250
|
+
body: body ? JSON.stringify(body) : void 0,
|
251
|
+
headers: {
|
252
|
+
"Content-Type": "application/json",
|
253
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
254
|
+
...headers,
|
255
|
+
...hostHeader(fullUrl),
|
256
|
+
Authorization: `Bearer ${apiKey}`
|
257
|
+
}
|
258
|
+
});
|
259
|
+
if (response.status === 204) {
|
260
|
+
return {};
|
261
|
+
}
|
262
|
+
const { host, protocol } = parseUrl(response.url);
|
263
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
264
|
+
setAttributes({
|
265
|
+
[TraceAttributes.KIND]: "http",
|
266
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
267
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
268
|
+
[TraceAttributes.HTTP_HOST]: host,
|
269
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
270
|
+
});
|
271
|
+
try {
|
272
|
+
const jsonResponse = await response.json();
|
273
|
+
if (response.ok) {
|
274
|
+
return jsonResponse;
|
275
|
+
}
|
276
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
277
|
+
} catch (error) {
|
278
|
+
throw new FetcherError(response.status, error, requestId);
|
279
|
+
}
|
280
|
+
},
|
281
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
282
|
+
);
|
283
|
+
}
|
284
|
+
function parseUrl(url) {
|
230
285
|
try {
|
231
|
-
const
|
232
|
-
|
233
|
-
return jsonResponse;
|
234
|
-
}
|
235
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
286
|
+
const { host, protocol } = new URL(url);
|
287
|
+
return { host, protocol };
|
236
288
|
} catch (error) {
|
237
|
-
|
289
|
+
return {};
|
238
290
|
}
|
239
291
|
}
|
240
292
|
|
@@ -342,6 +394,22 @@ const resolveBranch = (variables) => fetch$1({
|
|
342
394
|
method: "get",
|
343
395
|
...variables
|
344
396
|
});
|
397
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
398
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
399
|
+
const getMigrationRequest = (variables) => fetch$1({
|
400
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
401
|
+
method: "get",
|
402
|
+
...variables
|
403
|
+
});
|
404
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
405
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
406
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
407
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
408
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
409
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
410
|
+
method: "post",
|
411
|
+
...variables
|
412
|
+
});
|
345
413
|
const getBranchDetails = (variables) => fetch$1({
|
346
414
|
url: "/db/{dbBranchName}",
|
347
415
|
method: "get",
|
@@ -366,6 +434,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
366
434
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
367
435
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
368
436
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
437
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
438
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
439
|
+
const updateBranchSchema = (variables) => fetch$1({
|
440
|
+
url: "/db/{dbBranchName}/schema/update",
|
441
|
+
method: "post",
|
442
|
+
...variables
|
443
|
+
});
|
444
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
445
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
446
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
369
447
|
const getBranchStats = (variables) => fetch$1({
|
370
448
|
url: "/db/{dbBranchName}/stats",
|
371
449
|
method: "get",
|
@@ -485,10 +563,28 @@ const operationsByTag = {
|
|
485
563
|
deleteBranch,
|
486
564
|
updateBranchMetadata,
|
487
565
|
getBranchMetadata,
|
566
|
+
getBranchStats
|
567
|
+
},
|
568
|
+
migrationRequests: {
|
569
|
+
listMigrationRequests,
|
570
|
+
createMigrationRequest,
|
571
|
+
getMigrationRequest,
|
572
|
+
updateMigrationRequest,
|
573
|
+
listMigrationRequestsCommits,
|
574
|
+
compareMigrationRequest,
|
575
|
+
getMigrationRequestIsMerged,
|
576
|
+
mergeMigrationRequest
|
577
|
+
},
|
578
|
+
branchSchema: {
|
488
579
|
getBranchMigrationHistory,
|
489
580
|
executeBranchMigrationPlan,
|
490
581
|
getBranchMigrationPlan,
|
491
|
-
|
582
|
+
compareBranchWithUserSchema,
|
583
|
+
compareBranchSchemas,
|
584
|
+
updateBranchSchema,
|
585
|
+
previewBranchSchemaEdit,
|
586
|
+
applyBranchSchemaEdit,
|
587
|
+
getBranchSchemaHistory
|
492
588
|
},
|
493
589
|
table: {
|
494
590
|
createTable,
|
@@ -517,9 +613,9 @@ const operationsByTag = {
|
|
517
613
|
};
|
518
614
|
|
519
615
|
function getHostUrl(provider, type) {
|
520
|
-
if (
|
616
|
+
if (isHostProviderAlias(provider)) {
|
521
617
|
return providers[provider][type];
|
522
|
-
} else if (
|
618
|
+
} else if (isHostProviderBuilder(provider)) {
|
523
619
|
return provider[type];
|
524
620
|
}
|
525
621
|
throw new Error("Invalid API provider");
|
@@ -534,10 +630,10 @@ const providers = {
|
|
534
630
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
535
631
|
}
|
536
632
|
};
|
537
|
-
function
|
633
|
+
function isHostProviderAlias(alias) {
|
538
634
|
return isString(alias) && Object.keys(providers).includes(alias);
|
539
635
|
}
|
540
|
-
function
|
636
|
+
function isHostProviderBuilder(builder) {
|
541
637
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
542
638
|
}
|
543
639
|
|
@@ -565,7 +661,8 @@ class XataApiClient {
|
|
565
661
|
__privateAdd$7(this, _extraProps, void 0);
|
566
662
|
__privateAdd$7(this, _namespaces, {});
|
567
663
|
const provider = options.host ?? "production";
|
568
|
-
const apiKey = options
|
664
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
665
|
+
const trace = options.trace ?? defaultTrace;
|
569
666
|
if (!apiKey) {
|
570
667
|
throw new Error("Could not resolve a valid apiKey");
|
571
668
|
}
|
@@ -573,7 +670,8 @@ class XataApiClient {
|
|
573
670
|
apiUrl: getHostUrl(provider, "main"),
|
574
671
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
575
672
|
fetchImpl: getFetchImplementation(options.fetch),
|
576
|
-
apiKey
|
673
|
+
apiKey,
|
674
|
+
trace
|
577
675
|
});
|
578
676
|
}
|
579
677
|
get user() {
|
@@ -606,6 +704,16 @@ class XataApiClient {
|
|
606
704
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
607
705
|
return __privateGet$7(this, _namespaces).records;
|
608
706
|
}
|
707
|
+
get migrationRequests() {
|
708
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
709
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
710
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
711
|
+
}
|
712
|
+
get branchSchema() {
|
713
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
714
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
715
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
716
|
+
}
|
609
717
|
}
|
610
718
|
_extraProps = new WeakMap();
|
611
719
|
_namespaces = new WeakMap();
|
@@ -822,27 +930,6 @@ class BranchApi {
|
|
822
930
|
...this.extraProps
|
823
931
|
});
|
824
932
|
}
|
825
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
826
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
827
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
828
|
-
body: options,
|
829
|
-
...this.extraProps
|
830
|
-
});
|
831
|
-
}
|
832
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
833
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
834
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
835
|
-
body: migrationPlan,
|
836
|
-
...this.extraProps
|
837
|
-
});
|
838
|
-
}
|
839
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
840
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
841
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
842
|
-
body: schema,
|
843
|
-
...this.extraProps
|
844
|
-
});
|
845
|
-
}
|
846
933
|
getBranchStats(workspace, database, branch) {
|
847
934
|
return operationsByTag.branch.getBranchStats({
|
848
935
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -999,6 +1086,131 @@ class RecordsApi {
|
|
999
1086
|
});
|
1000
1087
|
}
|
1001
1088
|
}
|
1089
|
+
class MigrationRequestsApi {
|
1090
|
+
constructor(extraProps) {
|
1091
|
+
this.extraProps = extraProps;
|
1092
|
+
}
|
1093
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1094
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1095
|
+
pathParams: { workspace, dbName: database },
|
1096
|
+
body: options,
|
1097
|
+
...this.extraProps
|
1098
|
+
});
|
1099
|
+
}
|
1100
|
+
createMigrationRequest(workspace, database, options) {
|
1101
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1102
|
+
pathParams: { workspace, dbName: database },
|
1103
|
+
body: options,
|
1104
|
+
...this.extraProps
|
1105
|
+
});
|
1106
|
+
}
|
1107
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1108
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1109
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1110
|
+
...this.extraProps
|
1111
|
+
});
|
1112
|
+
}
|
1113
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1114
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1115
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1116
|
+
body: options,
|
1117
|
+
...this.extraProps
|
1118
|
+
});
|
1119
|
+
}
|
1120
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1121
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1122
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1123
|
+
body: options,
|
1124
|
+
...this.extraProps
|
1125
|
+
});
|
1126
|
+
}
|
1127
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1128
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1129
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1130
|
+
...this.extraProps
|
1131
|
+
});
|
1132
|
+
}
|
1133
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1134
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1135
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1136
|
+
...this.extraProps
|
1137
|
+
});
|
1138
|
+
}
|
1139
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1140
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1141
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1142
|
+
...this.extraProps
|
1143
|
+
});
|
1144
|
+
}
|
1145
|
+
}
|
1146
|
+
class BranchSchemaApi {
|
1147
|
+
constructor(extraProps) {
|
1148
|
+
this.extraProps = extraProps;
|
1149
|
+
}
|
1150
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1151
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1152
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1153
|
+
body: options,
|
1154
|
+
...this.extraProps
|
1155
|
+
});
|
1156
|
+
}
|
1157
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1158
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1159
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1160
|
+
body: migrationPlan,
|
1161
|
+
...this.extraProps
|
1162
|
+
});
|
1163
|
+
}
|
1164
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1165
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1166
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1167
|
+
body: schema,
|
1168
|
+
...this.extraProps
|
1169
|
+
});
|
1170
|
+
}
|
1171
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1172
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1173
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1174
|
+
body: { schema },
|
1175
|
+
...this.extraProps
|
1176
|
+
});
|
1177
|
+
}
|
1178
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1179
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1180
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1181
|
+
body: { schema },
|
1182
|
+
...this.extraProps
|
1183
|
+
});
|
1184
|
+
}
|
1185
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1186
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1187
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1188
|
+
body: migration,
|
1189
|
+
...this.extraProps
|
1190
|
+
});
|
1191
|
+
}
|
1192
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1193
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1194
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1195
|
+
body: migration,
|
1196
|
+
...this.extraProps
|
1197
|
+
});
|
1198
|
+
}
|
1199
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1200
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1201
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1202
|
+
body: { edits },
|
1203
|
+
...this.extraProps
|
1204
|
+
});
|
1205
|
+
}
|
1206
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1207
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1208
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1209
|
+
body: options,
|
1210
|
+
...this.extraProps
|
1211
|
+
});
|
1212
|
+
}
|
1213
|
+
}
|
1002
1214
|
|
1003
1215
|
class XataApiPlugin {
|
1004
1216
|
async build(options) {
|
@@ -1182,15 +1394,23 @@ const _Query = class {
|
|
1182
1394
|
}
|
1183
1395
|
filter(a, b) {
|
1184
1396
|
if (arguments.length === 1) {
|
1185
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1397
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1186
1398
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1187
1399
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1188
1400
|
} else {
|
1189
|
-
const
|
1401
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1402
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1190
1403
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1191
1404
|
}
|
1192
1405
|
}
|
1193
|
-
|
1406
|
+
defaultFilter(column, value) {
|
1407
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1408
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1409
|
+
return { $includes: value };
|
1410
|
+
}
|
1411
|
+
return value;
|
1412
|
+
}
|
1413
|
+
sort(column, direction = "asc") {
|
1194
1414
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1195
1415
|
const sort = [...originalSort, { column, direction }];
|
1196
1416
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
@@ -1326,12 +1546,16 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1326
1546
|
__accessCheck$4(obj, member, "access private method");
|
1327
1547
|
return method;
|
1328
1548
|
};
|
1329
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _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;
|
1549
|
+
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;
|
1330
1550
|
class Repository extends Query {
|
1331
1551
|
}
|
1332
1552
|
class RestRepository extends Query {
|
1333
1553
|
constructor(options) {
|
1334
|
-
super(
|
1554
|
+
super(
|
1555
|
+
null,
|
1556
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1557
|
+
{}
|
1558
|
+
);
|
1335
1559
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1336
1560
|
__privateAdd$4(this, _insertRecordWithId);
|
1337
1561
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
@@ -1346,168 +1570,194 @@ class RestRepository extends Query {
|
|
1346
1570
|
__privateAdd$4(this, _db, void 0);
|
1347
1571
|
__privateAdd$4(this, _cache, void 0);
|
1348
1572
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1573
|
+
__privateAdd$4(this, _trace, void 0);
|
1349
1574
|
__privateSet$4(this, _table, options.table);
|
1350
1575
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1351
1576
|
__privateSet$4(this, _db, options.db);
|
1352
1577
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1353
1578
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1579
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1580
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1581
|
+
return trace(name, fn, {
|
1582
|
+
...options2,
|
1583
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1584
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1585
|
+
[TraceAttributes.VERSION]: VERSION
|
1586
|
+
});
|
1587
|
+
});
|
1354
1588
|
}
|
1355
1589
|
async create(a, b, c) {
|
1356
|
-
|
1357
|
-
if (a
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
if (a
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
if (a.id
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1590
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1591
|
+
if (Array.isArray(a)) {
|
1592
|
+
if (a.length === 0)
|
1593
|
+
return [];
|
1594
|
+
const columns = isStringArray(b) ? b : void 0;
|
1595
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1596
|
+
}
|
1597
|
+
if (isString(a) && isObject(b)) {
|
1598
|
+
if (a === "")
|
1599
|
+
throw new Error("The id can't be empty");
|
1600
|
+
const columns = isStringArray(c) ? c : void 0;
|
1601
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1602
|
+
}
|
1603
|
+
if (isObject(a) && isString(a.id)) {
|
1604
|
+
if (a.id === "")
|
1605
|
+
throw new Error("The id can't be empty");
|
1606
|
+
const columns = isStringArray(b) ? b : void 0;
|
1607
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1608
|
+
}
|
1609
|
+
if (isObject(a)) {
|
1610
|
+
const columns = isStringArray(b) ? b : void 0;
|
1611
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1612
|
+
}
|
1613
|
+
throw new Error("Invalid arguments for create method");
|
1614
|
+
});
|
1379
1615
|
}
|
1380
1616
|
async read(a, b) {
|
1381
|
-
|
1382
|
-
|
1383
|
-
if (a
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
acc
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1617
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1618
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1619
|
+
if (Array.isArray(a)) {
|
1620
|
+
if (a.length === 0)
|
1621
|
+
return [];
|
1622
|
+
const ids = a.map((item) => extractId(item));
|
1623
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1624
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1625
|
+
acc[object.id] = object;
|
1626
|
+
return acc;
|
1627
|
+
}, {});
|
1628
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1629
|
+
}
|
1630
|
+
const id = extractId(a);
|
1631
|
+
if (id) {
|
1632
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1633
|
+
try {
|
1634
|
+
const response = await getRecord({
|
1635
|
+
pathParams: {
|
1636
|
+
workspace: "{workspaceId}",
|
1637
|
+
dbBranchName: "{dbBranch}",
|
1638
|
+
tableName: __privateGet$4(this, _table),
|
1639
|
+
recordId: id
|
1640
|
+
},
|
1641
|
+
queryParams: { columns },
|
1642
|
+
...fetchProps
|
1643
|
+
});
|
1644
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1645
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1646
|
+
} catch (e) {
|
1647
|
+
if (isObject(e) && e.status === 404) {
|
1648
|
+
return null;
|
1649
|
+
}
|
1650
|
+
throw e;
|
1407
1651
|
}
|
1408
|
-
throw e;
|
1409
1652
|
}
|
1410
|
-
|
1411
|
-
|
1653
|
+
return null;
|
1654
|
+
});
|
1412
1655
|
}
|
1413
1656
|
async update(a, b, c) {
|
1414
|
-
|
1415
|
-
if (a
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1657
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1658
|
+
if (Array.isArray(a)) {
|
1659
|
+
if (a.length === 0)
|
1660
|
+
return [];
|
1661
|
+
if (a.length > 100) {
|
1662
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1663
|
+
}
|
1664
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1665
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1419
1666
|
}
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
}
|
1431
|
-
throw new Error("Invalid arguments for update method");
|
1667
|
+
if (isString(a) && isObject(b)) {
|
1668
|
+
const columns = isStringArray(c) ? c : void 0;
|
1669
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1670
|
+
}
|
1671
|
+
if (isObject(a) && isString(a.id)) {
|
1672
|
+
const columns = isStringArray(b) ? b : void 0;
|
1673
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1674
|
+
}
|
1675
|
+
throw new Error("Invalid arguments for update method");
|
1676
|
+
});
|
1432
1677
|
}
|
1433
1678
|
async createOrUpdate(a, b, c) {
|
1434
|
-
|
1435
|
-
if (a
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1679
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1680
|
+
if (Array.isArray(a)) {
|
1681
|
+
if (a.length === 0)
|
1682
|
+
return [];
|
1683
|
+
if (a.length > 100) {
|
1684
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1685
|
+
}
|
1686
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1687
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1439
1688
|
}
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
if (isString(a) && isObject(b)) {
|
1444
|
-
const columns = isStringArray(c) ? c : void 0;
|
1445
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1446
|
-
}
|
1447
|
-
if (isObject(a) && isString(a.id)) {
|
1448
|
-
const columns = isStringArray(c) ? c : void 0;
|
1449
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1450
|
-
}
|
1451
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1452
|
-
}
|
1453
|
-
async delete(a) {
|
1454
|
-
if (Array.isArray(a)) {
|
1455
|
-
if (a.length === 0)
|
1456
|
-
return;
|
1457
|
-
if (a.length > 100) {
|
1458
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1689
|
+
if (isString(a) && isObject(b)) {
|
1690
|
+
const columns = isStringArray(c) ? c : void 0;
|
1691
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1459
1692
|
}
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1693
|
+
if (isObject(a) && isString(a.id)) {
|
1694
|
+
const columns = isStringArray(c) ? c : void 0;
|
1695
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1696
|
+
}
|
1697
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1698
|
+
});
|
1699
|
+
}
|
1700
|
+
async delete(a, b) {
|
1701
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1702
|
+
if (Array.isArray(a)) {
|
1703
|
+
if (a.length === 0)
|
1704
|
+
return [];
|
1705
|
+
if (a.length > 100) {
|
1706
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1707
|
+
}
|
1708
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1709
|
+
}
|
1710
|
+
if (isString(a)) {
|
1711
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1712
|
+
}
|
1713
|
+
if (isObject(a) && isString(a.id)) {
|
1714
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1715
|
+
}
|
1716
|
+
throw new Error("Invalid arguments for delete method");
|
1717
|
+
});
|
1472
1718
|
}
|
1473
1719
|
async search(query, options = {}) {
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1720
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1721
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1722
|
+
const { records } = await searchTable({
|
1723
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1724
|
+
body: {
|
1725
|
+
query,
|
1726
|
+
fuzziness: options.fuzziness,
|
1727
|
+
prefix: options.prefix,
|
1728
|
+
highlight: options.highlight,
|
1729
|
+
filter: options.filter,
|
1730
|
+
boosters: options.boosters
|
1731
|
+
},
|
1732
|
+
...fetchProps
|
1733
|
+
});
|
1734
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1735
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1486
1736
|
});
|
1487
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1488
|
-
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1489
1737
|
}
|
1490
1738
|
async query(query) {
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1739
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1740
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1741
|
+
if (cacheQuery)
|
1742
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1743
|
+
const data = query.getQueryOptions();
|
1744
|
+
const body = {
|
1745
|
+
filter: cleanFilter(data.filter),
|
1746
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1747
|
+
page: data.pagination,
|
1748
|
+
columns: data.columns
|
1749
|
+
};
|
1750
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1751
|
+
const { meta, records: objects } = await queryTable({
|
1752
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1753
|
+
body,
|
1754
|
+
...fetchProps
|
1755
|
+
});
|
1756
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1757
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1758
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1759
|
+
return new Page(query, meta, records);
|
1506
1760
|
});
|
1507
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1508
|
-
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1509
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1510
|
-
return new Page(query, meta, records);
|
1511
1761
|
}
|
1512
1762
|
}
|
1513
1763
|
_table = new WeakMap();
|
@@ -1515,6 +1765,7 @@ _getFetchProps = new WeakMap();
|
|
1515
1765
|
_db = new WeakMap();
|
1516
1766
|
_cache = new WeakMap();
|
1517
1767
|
_schemaTables$2 = new WeakMap();
|
1768
|
+
_trace = new WeakMap();
|
1518
1769
|
_insertRecordWithoutId = new WeakSet();
|
1519
1770
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1520
1771
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1570,14 +1821,21 @@ _updateRecordWithID = new WeakSet();
|
|
1570
1821
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1571
1822
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1572
1823
|
const record = transformObjectLinks(object);
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1824
|
+
try {
|
1825
|
+
const response = await updateRecordWithID({
|
1826
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1827
|
+
queryParams: { columns },
|
1828
|
+
body: record,
|
1829
|
+
...fetchProps
|
1830
|
+
});
|
1831
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1832
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1833
|
+
} catch (e) {
|
1834
|
+
if (isObject(e) && e.status === 404) {
|
1835
|
+
return null;
|
1836
|
+
}
|
1837
|
+
throw e;
|
1838
|
+
}
|
1581
1839
|
};
|
1582
1840
|
_upsertRecordWithID = new WeakSet();
|
1583
1841
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1592,12 +1850,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1592
1850
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1593
1851
|
};
|
1594
1852
|
_deleteRecord = new WeakSet();
|
1595
|
-
deleteRecord_fn = async function(recordId) {
|
1853
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1596
1854
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1855
|
+
try {
|
1856
|
+
const response = await deleteRecord({
|
1857
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1858
|
+
queryParams: { columns },
|
1859
|
+
...fetchProps
|
1860
|
+
});
|
1861
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1862
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1863
|
+
} catch (e) {
|
1864
|
+
if (isObject(e) && e.status === 404) {
|
1865
|
+
return null;
|
1866
|
+
}
|
1867
|
+
throw e;
|
1868
|
+
}
|
1601
1869
|
};
|
1602
1870
|
_setCacheQuery = new WeakSet();
|
1603
1871
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1685,6 +1953,19 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1685
1953
|
function isResponseWithRecords(value) {
|
1686
1954
|
return isObject(value) && Array.isArray(value.records);
|
1687
1955
|
}
|
1956
|
+
function extractId(value) {
|
1957
|
+
if (isString(value))
|
1958
|
+
return value;
|
1959
|
+
if (isObject(value) && isString(value.id))
|
1960
|
+
return value.id;
|
1961
|
+
return void 0;
|
1962
|
+
}
|
1963
|
+
function cleanFilter(filter) {
|
1964
|
+
if (!filter)
|
1965
|
+
return void 0;
|
1966
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1967
|
+
return values.length > 0 ? filter : void 0;
|
1968
|
+
}
|
1688
1969
|
|
1689
1970
|
var __accessCheck$3 = (obj, member, msg) => {
|
1690
1971
|
if (!member.has(obj))
|
@@ -1735,18 +2016,25 @@ class SimpleCache {
|
|
1735
2016
|
}
|
1736
2017
|
_map = new WeakMap();
|
1737
2018
|
|
1738
|
-
const
|
1739
|
-
const
|
1740
|
-
const
|
1741
|
-
const
|
1742
|
-
const
|
1743
|
-
const
|
2019
|
+
const greaterThan = (value) => ({ $gt: value });
|
2020
|
+
const gt = greaterThan;
|
2021
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2022
|
+
const greaterEquals = greaterThanEquals;
|
2023
|
+
const gte = greaterThanEquals;
|
2024
|
+
const ge = greaterThanEquals;
|
2025
|
+
const lessThan = (value) => ({ $lt: value });
|
2026
|
+
const lt = lessThan;
|
2027
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2028
|
+
const lessEquals = lessThanEquals;
|
2029
|
+
const lte = lessThanEquals;
|
2030
|
+
const le = lessThanEquals;
|
1744
2031
|
const exists = (column) => ({ $exists: column });
|
1745
2032
|
const notExists = (column) => ({ $notExists: column });
|
1746
2033
|
const startsWith = (value) => ({ $startsWith: value });
|
1747
2034
|
const endsWith = (value) => ({ $endsWith: value });
|
1748
2035
|
const pattern = (value) => ({ $pattern: value });
|
1749
2036
|
const is = (value) => ({ $is: value });
|
2037
|
+
const equals = is;
|
1750
2038
|
const isNot = (value) => ({ $isNot: value });
|
1751
2039
|
const contains = (value) => ({ $contains: value });
|
1752
2040
|
const includes = (value) => ({ $includes: value });
|
@@ -1923,7 +2211,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1923
2211
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1924
2212
|
workspacesApiUrl: `${protocol}//${host}`,
|
1925
2213
|
pathParams: { dbName, workspace },
|
1926
|
-
queryParams: { gitBranch, fallbackBranch }
|
2214
|
+
queryParams: { gitBranch, fallbackBranch },
|
2215
|
+
trace: defaultTrace
|
1927
2216
|
});
|
1928
2217
|
return branch;
|
1929
2218
|
}
|
@@ -1947,7 +2236,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1947
2236
|
apiUrl: databaseURL,
|
1948
2237
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1949
2238
|
workspacesApiUrl: `${protocol}//${host}`,
|
1950
|
-
pathParams: { dbBranchName, workspace }
|
2239
|
+
pathParams: { dbBranchName, workspace },
|
2240
|
+
trace: defaultTrace
|
1951
2241
|
});
|
1952
2242
|
} catch (err) {
|
1953
2243
|
if (isObject(err) && err.status === 404)
|
@@ -1999,7 +2289,8 @@ const buildClient = (plugins) => {
|
|
1999
2289
|
__privateSet(this, _options, safeOptions);
|
2000
2290
|
const pluginOptions = {
|
2001
2291
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2002
|
-
cache: safeOptions.cache
|
2292
|
+
cache: safeOptions.cache,
|
2293
|
+
trace: safeOptions.trace
|
2003
2294
|
};
|
2004
2295
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2005
2296
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2028,12 +2319,16 @@ const buildClient = (plugins) => {
|
|
2028
2319
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2029
2320
|
const apiKey = options?.apiKey || getAPIKey();
|
2030
2321
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2322
|
+
const trace = options?.trace ?? defaultTrace;
|
2031
2323
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2032
|
-
if (!
|
2033
|
-
throw new Error("
|
2324
|
+
if (!apiKey) {
|
2325
|
+
throw new Error("Option apiKey is required");
|
2034
2326
|
}
|
2035
|
-
|
2036
|
-
|
2327
|
+
if (!databaseURL) {
|
2328
|
+
throw new Error("Option databaseURL is required");
|
2329
|
+
}
|
2330
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2331
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2037
2332
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2038
2333
|
if (!branchValue)
|
2039
2334
|
throw new Error("Unable to resolve branch value");
|
@@ -2043,9 +2338,10 @@ const buildClient = (plugins) => {
|
|
2043
2338
|
apiUrl: "",
|
2044
2339
|
workspacesApiUrl: (path, params) => {
|
2045
2340
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2046
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2341
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2047
2342
|
return databaseURL + newPath;
|
2048
|
-
}
|
2343
|
+
},
|
2344
|
+
trace
|
2049
2345
|
};
|
2050
2346
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2051
2347
|
if (__privateGet(this, _branch))
|
@@ -2157,5 +2453,5 @@ class XataError extends Error {
|
|
2157
2453
|
}
|
2158
2454
|
}
|
2159
2455
|
|
2160
|
-
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, 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, 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, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2456
|
+
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, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, 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, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateBranchSchema, updateColumn, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2161
2457
|
//# sourceMappingURL=index.mjs.map
|