@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.cjs
CHANGED
@@ -20,6 +20,28 @@ function _interopNamespace(e) {
|
|
20
20
|
return Object.freeze(n);
|
21
21
|
}
|
22
22
|
|
23
|
+
const defaultTrace = async (_name, fn, _options) => {
|
24
|
+
return await fn({
|
25
|
+
setAttributes: () => {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
});
|
29
|
+
};
|
30
|
+
const TraceAttributes = {
|
31
|
+
KIND: "xata.trace.kind",
|
32
|
+
VERSION: "xata.sdk.version",
|
33
|
+
TABLE: "xata.table",
|
34
|
+
HTTP_REQUEST_ID: "http.request_id",
|
35
|
+
HTTP_STATUS_CODE: "http.status_code",
|
36
|
+
HTTP_HOST: "http.host",
|
37
|
+
HTTP_SCHEME: "http.scheme",
|
38
|
+
HTTP_USER_AGENT: "http.user_agent",
|
39
|
+
HTTP_METHOD: "http.method",
|
40
|
+
HTTP_URL: "http.url",
|
41
|
+
HTTP_ROUTE: "http.route",
|
42
|
+
HTTP_TARGET: "http.target"
|
43
|
+
};
|
44
|
+
|
23
45
|
function notEmpty(value) {
|
24
46
|
return value !== null && value !== void 0;
|
25
47
|
}
|
@@ -144,13 +166,13 @@ function getFetchImplementation(userFetch) {
|
|
144
166
|
const fetchImpl = userFetch ?? globalFetch;
|
145
167
|
if (!fetchImpl) {
|
146
168
|
throw new Error(
|
147
|
-
`
|
169
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
148
170
|
);
|
149
171
|
}
|
150
172
|
return fetchImpl;
|
151
173
|
}
|
152
174
|
|
153
|
-
const VERSION = "0.
|
175
|
+
const VERSION = "0.17.1";
|
154
176
|
|
155
177
|
class ErrorWithCause extends Error {
|
156
178
|
constructor(message, options) {
|
@@ -201,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
201
223
|
}, {});
|
202
224
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
203
225
|
const queryString = query.length > 0 ? `?${query}` : "";
|
204
|
-
|
226
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
227
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
228
|
+
}, {});
|
229
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
205
230
|
};
|
206
231
|
function buildBaseUrl({
|
207
232
|
path,
|
@@ -209,10 +234,10 @@ function buildBaseUrl({
|
|
209
234
|
apiUrl,
|
210
235
|
pathParams
|
211
236
|
}) {
|
212
|
-
if (
|
237
|
+
if (pathParams?.workspace === void 0)
|
213
238
|
return `${apiUrl}${path}`;
|
214
239
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
215
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
240
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
216
241
|
}
|
217
242
|
function hostHeader(url) {
|
218
243
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -229,34 +254,61 @@ async function fetch$1({
|
|
229
254
|
fetchImpl,
|
230
255
|
apiKey,
|
231
256
|
apiUrl,
|
232
|
-
workspacesApiUrl
|
257
|
+
workspacesApiUrl,
|
258
|
+
trace
|
233
259
|
}) {
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
260
|
+
return trace(
|
261
|
+
`${method.toUpperCase()} ${path}`,
|
262
|
+
async ({ setAttributes }) => {
|
263
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
264
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
265
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
266
|
+
setAttributes({
|
267
|
+
[TraceAttributes.HTTP_URL]: url,
|
268
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
269
|
+
});
|
270
|
+
const response = await fetchImpl(url, {
|
271
|
+
method: method.toUpperCase(),
|
272
|
+
body: body ? JSON.stringify(body) : void 0,
|
273
|
+
headers: {
|
274
|
+
"Content-Type": "application/json",
|
275
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
276
|
+
...headers,
|
277
|
+
...hostHeader(fullUrl),
|
278
|
+
Authorization: `Bearer ${apiKey}`
|
279
|
+
}
|
280
|
+
});
|
281
|
+
if (response.status === 204) {
|
282
|
+
return {};
|
283
|
+
}
|
284
|
+
const { host, protocol } = parseUrl(response.url);
|
285
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
286
|
+
setAttributes({
|
287
|
+
[TraceAttributes.KIND]: "http",
|
288
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
289
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
290
|
+
[TraceAttributes.HTTP_HOST]: host,
|
291
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
292
|
+
});
|
293
|
+
try {
|
294
|
+
const jsonResponse = await response.json();
|
295
|
+
if (response.ok) {
|
296
|
+
return jsonResponse;
|
297
|
+
}
|
298
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
299
|
+
} catch (error) {
|
300
|
+
throw new FetcherError(response.status, error, requestId);
|
301
|
+
}
|
302
|
+
},
|
303
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
304
|
+
);
|
305
|
+
}
|
306
|
+
function parseUrl(url) {
|
252
307
|
try {
|
253
|
-
const
|
254
|
-
|
255
|
-
return jsonResponse;
|
256
|
-
}
|
257
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
308
|
+
const { host, protocol } = new URL(url);
|
309
|
+
return { host, protocol };
|
258
310
|
} catch (error) {
|
259
|
-
|
311
|
+
return {};
|
260
312
|
}
|
261
313
|
}
|
262
314
|
|
@@ -364,6 +416,22 @@ const resolveBranch = (variables) => fetch$1({
|
|
364
416
|
method: "get",
|
365
417
|
...variables
|
366
418
|
});
|
419
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
420
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
421
|
+
const getMigrationRequest = (variables) => fetch$1({
|
422
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
423
|
+
method: "get",
|
424
|
+
...variables
|
425
|
+
});
|
426
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
427
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
428
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
429
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
430
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
431
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
432
|
+
method: "post",
|
433
|
+
...variables
|
434
|
+
});
|
367
435
|
const getBranchDetails = (variables) => fetch$1({
|
368
436
|
url: "/db/{dbBranchName}",
|
369
437
|
method: "get",
|
@@ -388,6 +456,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
388
456
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
389
457
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
390
458
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
459
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
460
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
461
|
+
const updateBranchSchema = (variables) => fetch$1({
|
462
|
+
url: "/db/{dbBranchName}/schema/update",
|
463
|
+
method: "post",
|
464
|
+
...variables
|
465
|
+
});
|
466
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
467
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
468
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
391
469
|
const getBranchStats = (variables) => fetch$1({
|
392
470
|
url: "/db/{dbBranchName}/stats",
|
393
471
|
method: "get",
|
@@ -507,10 +585,28 @@ const operationsByTag = {
|
|
507
585
|
deleteBranch,
|
508
586
|
updateBranchMetadata,
|
509
587
|
getBranchMetadata,
|
588
|
+
getBranchStats
|
589
|
+
},
|
590
|
+
migrationRequests: {
|
591
|
+
listMigrationRequests,
|
592
|
+
createMigrationRequest,
|
593
|
+
getMigrationRequest,
|
594
|
+
updateMigrationRequest,
|
595
|
+
listMigrationRequestsCommits,
|
596
|
+
compareMigrationRequest,
|
597
|
+
getMigrationRequestIsMerged,
|
598
|
+
mergeMigrationRequest
|
599
|
+
},
|
600
|
+
branchSchema: {
|
510
601
|
getBranchMigrationHistory,
|
511
602
|
executeBranchMigrationPlan,
|
512
603
|
getBranchMigrationPlan,
|
513
|
-
|
604
|
+
compareBranchWithUserSchema,
|
605
|
+
compareBranchSchemas,
|
606
|
+
updateBranchSchema,
|
607
|
+
previewBranchSchemaEdit,
|
608
|
+
applyBranchSchemaEdit,
|
609
|
+
getBranchSchemaHistory
|
514
610
|
},
|
515
611
|
table: {
|
516
612
|
createTable,
|
@@ -539,9 +635,9 @@ const operationsByTag = {
|
|
539
635
|
};
|
540
636
|
|
541
637
|
function getHostUrl(provider, type) {
|
542
|
-
if (
|
638
|
+
if (isHostProviderAlias(provider)) {
|
543
639
|
return providers[provider][type];
|
544
|
-
} else if (
|
640
|
+
} else if (isHostProviderBuilder(provider)) {
|
545
641
|
return provider[type];
|
546
642
|
}
|
547
643
|
throw new Error("Invalid API provider");
|
@@ -556,10 +652,10 @@ const providers = {
|
|
556
652
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
557
653
|
}
|
558
654
|
};
|
559
|
-
function
|
655
|
+
function isHostProviderAlias(alias) {
|
560
656
|
return isString(alias) && Object.keys(providers).includes(alias);
|
561
657
|
}
|
562
|
-
function
|
658
|
+
function isHostProviderBuilder(builder) {
|
563
659
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
564
660
|
}
|
565
661
|
|
@@ -587,7 +683,8 @@ class XataApiClient {
|
|
587
683
|
__privateAdd$7(this, _extraProps, void 0);
|
588
684
|
__privateAdd$7(this, _namespaces, {});
|
589
685
|
const provider = options.host ?? "production";
|
590
|
-
const apiKey = options
|
686
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
687
|
+
const trace = options.trace ?? defaultTrace;
|
591
688
|
if (!apiKey) {
|
592
689
|
throw new Error("Could not resolve a valid apiKey");
|
593
690
|
}
|
@@ -595,7 +692,8 @@ class XataApiClient {
|
|
595
692
|
apiUrl: getHostUrl(provider, "main"),
|
596
693
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
597
694
|
fetchImpl: getFetchImplementation(options.fetch),
|
598
|
-
apiKey
|
695
|
+
apiKey,
|
696
|
+
trace
|
599
697
|
});
|
600
698
|
}
|
601
699
|
get user() {
|
@@ -628,6 +726,16 @@ class XataApiClient {
|
|
628
726
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
629
727
|
return __privateGet$7(this, _namespaces).records;
|
630
728
|
}
|
729
|
+
get migrationRequests() {
|
730
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
731
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
732
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
733
|
+
}
|
734
|
+
get branchSchema() {
|
735
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
736
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
737
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
738
|
+
}
|
631
739
|
}
|
632
740
|
_extraProps = new WeakMap();
|
633
741
|
_namespaces = new WeakMap();
|
@@ -844,27 +952,6 @@ class BranchApi {
|
|
844
952
|
...this.extraProps
|
845
953
|
});
|
846
954
|
}
|
847
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
848
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
849
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
850
|
-
body: options,
|
851
|
-
...this.extraProps
|
852
|
-
});
|
853
|
-
}
|
854
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
855
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
856
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
857
|
-
body: migrationPlan,
|
858
|
-
...this.extraProps
|
859
|
-
});
|
860
|
-
}
|
861
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
862
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
863
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
864
|
-
body: schema,
|
865
|
-
...this.extraProps
|
866
|
-
});
|
867
|
-
}
|
868
955
|
getBranchStats(workspace, database, branch) {
|
869
956
|
return operationsByTag.branch.getBranchStats({
|
870
957
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -1021,6 +1108,131 @@ class RecordsApi {
|
|
1021
1108
|
});
|
1022
1109
|
}
|
1023
1110
|
}
|
1111
|
+
class MigrationRequestsApi {
|
1112
|
+
constructor(extraProps) {
|
1113
|
+
this.extraProps = extraProps;
|
1114
|
+
}
|
1115
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1116
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1117
|
+
pathParams: { workspace, dbName: database },
|
1118
|
+
body: options,
|
1119
|
+
...this.extraProps
|
1120
|
+
});
|
1121
|
+
}
|
1122
|
+
createMigrationRequest(workspace, database, options) {
|
1123
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1124
|
+
pathParams: { workspace, dbName: database },
|
1125
|
+
body: options,
|
1126
|
+
...this.extraProps
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1130
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1131
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1132
|
+
...this.extraProps
|
1133
|
+
});
|
1134
|
+
}
|
1135
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1136
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1137
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1138
|
+
body: options,
|
1139
|
+
...this.extraProps
|
1140
|
+
});
|
1141
|
+
}
|
1142
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1143
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1144
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1145
|
+
body: options,
|
1146
|
+
...this.extraProps
|
1147
|
+
});
|
1148
|
+
}
|
1149
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1150
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1151
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1152
|
+
...this.extraProps
|
1153
|
+
});
|
1154
|
+
}
|
1155
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1156
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1157
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1158
|
+
...this.extraProps
|
1159
|
+
});
|
1160
|
+
}
|
1161
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1162
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1163
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1164
|
+
...this.extraProps
|
1165
|
+
});
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
class BranchSchemaApi {
|
1169
|
+
constructor(extraProps) {
|
1170
|
+
this.extraProps = extraProps;
|
1171
|
+
}
|
1172
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1173
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1174
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1175
|
+
body: options,
|
1176
|
+
...this.extraProps
|
1177
|
+
});
|
1178
|
+
}
|
1179
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1180
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1181
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1182
|
+
body: migrationPlan,
|
1183
|
+
...this.extraProps
|
1184
|
+
});
|
1185
|
+
}
|
1186
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1187
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1188
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1189
|
+
body: schema,
|
1190
|
+
...this.extraProps
|
1191
|
+
});
|
1192
|
+
}
|
1193
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1194
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1195
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1196
|
+
body: { schema },
|
1197
|
+
...this.extraProps
|
1198
|
+
});
|
1199
|
+
}
|
1200
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1201
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1202
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1203
|
+
body: { schema },
|
1204
|
+
...this.extraProps
|
1205
|
+
});
|
1206
|
+
}
|
1207
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1208
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1209
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1210
|
+
body: migration,
|
1211
|
+
...this.extraProps
|
1212
|
+
});
|
1213
|
+
}
|
1214
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1215
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1216
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1217
|
+
body: migration,
|
1218
|
+
...this.extraProps
|
1219
|
+
});
|
1220
|
+
}
|
1221
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1222
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1223
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1224
|
+
body: { edits },
|
1225
|
+
...this.extraProps
|
1226
|
+
});
|
1227
|
+
}
|
1228
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1229
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1230
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1231
|
+
body: options,
|
1232
|
+
...this.extraProps
|
1233
|
+
});
|
1234
|
+
}
|
1235
|
+
}
|
1024
1236
|
|
1025
1237
|
class XataApiPlugin {
|
1026
1238
|
async build(options) {
|
@@ -1204,15 +1416,23 @@ const _Query = class {
|
|
1204
1416
|
}
|
1205
1417
|
filter(a, b) {
|
1206
1418
|
if (arguments.length === 1) {
|
1207
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1419
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1208
1420
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1209
1421
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1210
1422
|
} else {
|
1211
|
-
const
|
1423
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1424
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1212
1425
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1213
1426
|
}
|
1214
1427
|
}
|
1215
|
-
|
1428
|
+
defaultFilter(column, value) {
|
1429
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1430
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1431
|
+
return { $includes: value };
|
1432
|
+
}
|
1433
|
+
return value;
|
1434
|
+
}
|
1435
|
+
sort(column, direction = "asc") {
|
1216
1436
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1217
1437
|
const sort = [...originalSort, { column, direction }];
|
1218
1438
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
@@ -1348,12 +1568,16 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1348
1568
|
__accessCheck$4(obj, member, "access private method");
|
1349
1569
|
return method;
|
1350
1570
|
};
|
1351
|
-
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;
|
1571
|
+
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;
|
1352
1572
|
class Repository extends Query {
|
1353
1573
|
}
|
1354
1574
|
class RestRepository extends Query {
|
1355
1575
|
constructor(options) {
|
1356
|
-
super(
|
1576
|
+
super(
|
1577
|
+
null,
|
1578
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1579
|
+
{}
|
1580
|
+
);
|
1357
1581
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1358
1582
|
__privateAdd$4(this, _insertRecordWithId);
|
1359
1583
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
@@ -1368,168 +1592,194 @@ class RestRepository extends Query {
|
|
1368
1592
|
__privateAdd$4(this, _db, void 0);
|
1369
1593
|
__privateAdd$4(this, _cache, void 0);
|
1370
1594
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1595
|
+
__privateAdd$4(this, _trace, void 0);
|
1371
1596
|
__privateSet$4(this, _table, options.table);
|
1372
1597
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1373
1598
|
__privateSet$4(this, _db, options.db);
|
1374
1599
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1375
1600
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1601
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1602
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1603
|
+
return trace(name, fn, {
|
1604
|
+
...options2,
|
1605
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1606
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1607
|
+
[TraceAttributes.VERSION]: VERSION
|
1608
|
+
});
|
1609
|
+
});
|
1376
1610
|
}
|
1377
1611
|
async create(a, b, c) {
|
1378
|
-
|
1379
|
-
if (a
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
if (a
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
if (a.id
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1612
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1613
|
+
if (Array.isArray(a)) {
|
1614
|
+
if (a.length === 0)
|
1615
|
+
return [];
|
1616
|
+
const columns = isStringArray(b) ? b : void 0;
|
1617
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1618
|
+
}
|
1619
|
+
if (isString(a) && isObject(b)) {
|
1620
|
+
if (a === "")
|
1621
|
+
throw new Error("The id can't be empty");
|
1622
|
+
const columns = isStringArray(c) ? c : void 0;
|
1623
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1624
|
+
}
|
1625
|
+
if (isObject(a) && isString(a.id)) {
|
1626
|
+
if (a.id === "")
|
1627
|
+
throw new Error("The id can't be empty");
|
1628
|
+
const columns = isStringArray(b) ? b : void 0;
|
1629
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1630
|
+
}
|
1631
|
+
if (isObject(a)) {
|
1632
|
+
const columns = isStringArray(b) ? b : void 0;
|
1633
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1634
|
+
}
|
1635
|
+
throw new Error("Invalid arguments for create method");
|
1636
|
+
});
|
1401
1637
|
}
|
1402
1638
|
async read(a, b) {
|
1403
|
-
|
1404
|
-
|
1405
|
-
if (a
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
acc
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1639
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1640
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1641
|
+
if (Array.isArray(a)) {
|
1642
|
+
if (a.length === 0)
|
1643
|
+
return [];
|
1644
|
+
const ids = a.map((item) => extractId(item));
|
1645
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1646
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1647
|
+
acc[object.id] = object;
|
1648
|
+
return acc;
|
1649
|
+
}, {});
|
1650
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1651
|
+
}
|
1652
|
+
const id = extractId(a);
|
1653
|
+
if (id) {
|
1654
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1655
|
+
try {
|
1656
|
+
const response = await getRecord({
|
1657
|
+
pathParams: {
|
1658
|
+
workspace: "{workspaceId}",
|
1659
|
+
dbBranchName: "{dbBranch}",
|
1660
|
+
tableName: __privateGet$4(this, _table),
|
1661
|
+
recordId: id
|
1662
|
+
},
|
1663
|
+
queryParams: { columns },
|
1664
|
+
...fetchProps
|
1665
|
+
});
|
1666
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1667
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1668
|
+
} catch (e) {
|
1669
|
+
if (isObject(e) && e.status === 404) {
|
1670
|
+
return null;
|
1671
|
+
}
|
1672
|
+
throw e;
|
1429
1673
|
}
|
1430
|
-
throw e;
|
1431
1674
|
}
|
1432
|
-
|
1433
|
-
|
1675
|
+
return null;
|
1676
|
+
});
|
1434
1677
|
}
|
1435
1678
|
async update(a, b, c) {
|
1436
|
-
|
1437
|
-
if (a
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1679
|
+
return __privateGet$4(this, _trace).call(this, "update", 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.update(object, columns)));
|
1441
1688
|
}
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
}
|
1453
|
-
throw new Error("Invalid arguments for update method");
|
1689
|
+
if (isString(a) && isObject(b)) {
|
1690
|
+
const columns = isStringArray(c) ? c : void 0;
|
1691
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1692
|
+
}
|
1693
|
+
if (isObject(a) && isString(a.id)) {
|
1694
|
+
const columns = isStringArray(b) ? b : void 0;
|
1695
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1696
|
+
}
|
1697
|
+
throw new Error("Invalid arguments for update method");
|
1698
|
+
});
|
1454
1699
|
}
|
1455
1700
|
async createOrUpdate(a, b, c) {
|
1456
|
-
|
1457
|
-
if (a
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1701
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1702
|
+
if (Array.isArray(a)) {
|
1703
|
+
if (a.length === 0)
|
1704
|
+
return [];
|
1705
|
+
if (a.length > 100) {
|
1706
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1707
|
+
}
|
1708
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1709
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1461
1710
|
}
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
if (isString(a) && isObject(b)) {
|
1466
|
-
const columns = isStringArray(c) ? c : void 0;
|
1467
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1468
|
-
}
|
1469
|
-
if (isObject(a) && isString(a.id)) {
|
1470
|
-
const columns = isStringArray(c) ? c : void 0;
|
1471
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1472
|
-
}
|
1473
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1474
|
-
}
|
1475
|
-
async delete(a) {
|
1476
|
-
if (Array.isArray(a)) {
|
1477
|
-
if (a.length === 0)
|
1478
|
-
return;
|
1479
|
-
if (a.length > 100) {
|
1480
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1711
|
+
if (isString(a) && isObject(b)) {
|
1712
|
+
const columns = isStringArray(c) ? c : void 0;
|
1713
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1481
1714
|
}
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1715
|
+
if (isObject(a) && isString(a.id)) {
|
1716
|
+
const columns = isStringArray(c) ? c : void 0;
|
1717
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1718
|
+
}
|
1719
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1720
|
+
});
|
1721
|
+
}
|
1722
|
+
async delete(a, b) {
|
1723
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1724
|
+
if (Array.isArray(a)) {
|
1725
|
+
if (a.length === 0)
|
1726
|
+
return [];
|
1727
|
+
if (a.length > 100) {
|
1728
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1729
|
+
}
|
1730
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1731
|
+
}
|
1732
|
+
if (isString(a)) {
|
1733
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1734
|
+
}
|
1735
|
+
if (isObject(a) && isString(a.id)) {
|
1736
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1737
|
+
}
|
1738
|
+
throw new Error("Invalid arguments for delete method");
|
1739
|
+
});
|
1494
1740
|
}
|
1495
1741
|
async search(query, options = {}) {
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1742
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1743
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1744
|
+
const { records } = await searchTable({
|
1745
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1746
|
+
body: {
|
1747
|
+
query,
|
1748
|
+
fuzziness: options.fuzziness,
|
1749
|
+
prefix: options.prefix,
|
1750
|
+
highlight: options.highlight,
|
1751
|
+
filter: options.filter,
|
1752
|
+
boosters: options.boosters
|
1753
|
+
},
|
1754
|
+
...fetchProps
|
1755
|
+
});
|
1756
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1757
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1508
1758
|
});
|
1509
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1510
|
-
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1511
1759
|
}
|
1512
1760
|
async query(query) {
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1761
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1762
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1763
|
+
if (cacheQuery)
|
1764
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1765
|
+
const data = query.getQueryOptions();
|
1766
|
+
const body = {
|
1767
|
+
filter: cleanFilter(data.filter),
|
1768
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1769
|
+
page: data.pagination,
|
1770
|
+
columns: data.columns
|
1771
|
+
};
|
1772
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1773
|
+
const { meta, records: objects } = await queryTable({
|
1774
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1775
|
+
body,
|
1776
|
+
...fetchProps
|
1777
|
+
});
|
1778
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1779
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1780
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1781
|
+
return new Page(query, meta, records);
|
1528
1782
|
});
|
1529
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1530
|
-
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1531
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1532
|
-
return new Page(query, meta, records);
|
1533
1783
|
}
|
1534
1784
|
}
|
1535
1785
|
_table = new WeakMap();
|
@@ -1537,6 +1787,7 @@ _getFetchProps = new WeakMap();
|
|
1537
1787
|
_db = new WeakMap();
|
1538
1788
|
_cache = new WeakMap();
|
1539
1789
|
_schemaTables$2 = new WeakMap();
|
1790
|
+
_trace = new WeakMap();
|
1540
1791
|
_insertRecordWithoutId = new WeakSet();
|
1541
1792
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1542
1793
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1592,14 +1843,21 @@ _updateRecordWithID = new WeakSet();
|
|
1592
1843
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1593
1844
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1594
1845
|
const record = transformObjectLinks(object);
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1846
|
+
try {
|
1847
|
+
const response = await updateRecordWithID({
|
1848
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1849
|
+
queryParams: { columns },
|
1850
|
+
body: record,
|
1851
|
+
...fetchProps
|
1852
|
+
});
|
1853
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1854
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1855
|
+
} catch (e) {
|
1856
|
+
if (isObject(e) && e.status === 404) {
|
1857
|
+
return null;
|
1858
|
+
}
|
1859
|
+
throw e;
|
1860
|
+
}
|
1603
1861
|
};
|
1604
1862
|
_upsertRecordWithID = new WeakSet();
|
1605
1863
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1614,12 +1872,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1614
1872
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1615
1873
|
};
|
1616
1874
|
_deleteRecord = new WeakSet();
|
1617
|
-
deleteRecord_fn = async function(recordId) {
|
1875
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1618
1876
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1877
|
+
try {
|
1878
|
+
const response = await deleteRecord({
|
1879
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1880
|
+
queryParams: { columns },
|
1881
|
+
...fetchProps
|
1882
|
+
});
|
1883
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1884
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1885
|
+
} catch (e) {
|
1886
|
+
if (isObject(e) && e.status === 404) {
|
1887
|
+
return null;
|
1888
|
+
}
|
1889
|
+
throw e;
|
1890
|
+
}
|
1623
1891
|
};
|
1624
1892
|
_setCacheQuery = new WeakSet();
|
1625
1893
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1707,6 +1975,19 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1707
1975
|
function isResponseWithRecords(value) {
|
1708
1976
|
return isObject(value) && Array.isArray(value.records);
|
1709
1977
|
}
|
1978
|
+
function extractId(value) {
|
1979
|
+
if (isString(value))
|
1980
|
+
return value;
|
1981
|
+
if (isObject(value) && isString(value.id))
|
1982
|
+
return value.id;
|
1983
|
+
return void 0;
|
1984
|
+
}
|
1985
|
+
function cleanFilter(filter) {
|
1986
|
+
if (!filter)
|
1987
|
+
return void 0;
|
1988
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1989
|
+
return values.length > 0 ? filter : void 0;
|
1990
|
+
}
|
1710
1991
|
|
1711
1992
|
var __accessCheck$3 = (obj, member, msg) => {
|
1712
1993
|
if (!member.has(obj))
|
@@ -1757,18 +2038,25 @@ class SimpleCache {
|
|
1757
2038
|
}
|
1758
2039
|
_map = new WeakMap();
|
1759
2040
|
|
1760
|
-
const
|
1761
|
-
const
|
1762
|
-
const
|
1763
|
-
const
|
1764
|
-
const
|
1765
|
-
const
|
2041
|
+
const greaterThan = (value) => ({ $gt: value });
|
2042
|
+
const gt = greaterThan;
|
2043
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2044
|
+
const greaterEquals = greaterThanEquals;
|
2045
|
+
const gte = greaterThanEquals;
|
2046
|
+
const ge = greaterThanEquals;
|
2047
|
+
const lessThan = (value) => ({ $lt: value });
|
2048
|
+
const lt = lessThan;
|
2049
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2050
|
+
const lessEquals = lessThanEquals;
|
2051
|
+
const lte = lessThanEquals;
|
2052
|
+
const le = lessThanEquals;
|
1766
2053
|
const exists = (column) => ({ $exists: column });
|
1767
2054
|
const notExists = (column) => ({ $notExists: column });
|
1768
2055
|
const startsWith = (value) => ({ $startsWith: value });
|
1769
2056
|
const endsWith = (value) => ({ $endsWith: value });
|
1770
2057
|
const pattern = (value) => ({ $pattern: value });
|
1771
2058
|
const is = (value) => ({ $is: value });
|
2059
|
+
const equals = is;
|
1772
2060
|
const isNot = (value) => ({ $isNot: value });
|
1773
2061
|
const contains = (value) => ({ $contains: value });
|
1774
2062
|
const includes = (value) => ({ $includes: value });
|
@@ -1945,7 +2233,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1945
2233
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1946
2234
|
workspacesApiUrl: `${protocol}//${host}`,
|
1947
2235
|
pathParams: { dbName, workspace },
|
1948
|
-
queryParams: { gitBranch, fallbackBranch }
|
2236
|
+
queryParams: { gitBranch, fallbackBranch },
|
2237
|
+
trace: defaultTrace
|
1949
2238
|
});
|
1950
2239
|
return branch;
|
1951
2240
|
}
|
@@ -1969,7 +2258,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1969
2258
|
apiUrl: databaseURL,
|
1970
2259
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1971
2260
|
workspacesApiUrl: `${protocol}//${host}`,
|
1972
|
-
pathParams: { dbBranchName, workspace }
|
2261
|
+
pathParams: { dbBranchName, workspace },
|
2262
|
+
trace: defaultTrace
|
1973
2263
|
});
|
1974
2264
|
} catch (err) {
|
1975
2265
|
if (isObject(err) && err.status === 404)
|
@@ -2021,7 +2311,8 @@ const buildClient = (plugins) => {
|
|
2021
2311
|
__privateSet(this, _options, safeOptions);
|
2022
2312
|
const pluginOptions = {
|
2023
2313
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2024
|
-
cache: safeOptions.cache
|
2314
|
+
cache: safeOptions.cache,
|
2315
|
+
trace: safeOptions.trace
|
2025
2316
|
};
|
2026
2317
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2027
2318
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2050,12 +2341,16 @@ const buildClient = (plugins) => {
|
|
2050
2341
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2051
2342
|
const apiKey = options?.apiKey || getAPIKey();
|
2052
2343
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2344
|
+
const trace = options?.trace ?? defaultTrace;
|
2053
2345
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2054
|
-
if (!
|
2055
|
-
throw new Error("
|
2346
|
+
if (!apiKey) {
|
2347
|
+
throw new Error("Option apiKey is required");
|
2056
2348
|
}
|
2057
|
-
|
2058
|
-
|
2349
|
+
if (!databaseURL) {
|
2350
|
+
throw new Error("Option databaseURL is required");
|
2351
|
+
}
|
2352
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2353
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2059
2354
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2060
2355
|
if (!branchValue)
|
2061
2356
|
throw new Error("Unable to resolve branch value");
|
@@ -2065,9 +2360,10 @@ const buildClient = (plugins) => {
|
|
2065
2360
|
apiUrl: "",
|
2066
2361
|
workspacesApiUrl: (path, params) => {
|
2067
2362
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2068
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2363
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2069
2364
|
return databaseURL + newPath;
|
2070
|
-
}
|
2365
|
+
},
|
2366
|
+
trace
|
2071
2367
|
};
|
2072
2368
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2073
2369
|
if (__privateGet(this, _branch))
|
@@ -2201,13 +2497,18 @@ exports.XataPlugin = XataPlugin;
|
|
2201
2497
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2202
2498
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2203
2499
|
exports.addTableColumn = addTableColumn;
|
2500
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
2204
2501
|
exports.buildClient = buildClient;
|
2205
2502
|
exports.buildWorkerRunner = buildWorkerRunner;
|
2206
2503
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2207
2504
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2505
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
2506
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
2507
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2208
2508
|
exports.contains = contains;
|
2209
2509
|
exports.createBranch = createBranch;
|
2210
2510
|
exports.createDatabase = createDatabase;
|
2511
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2211
2512
|
exports.createTable = createTable;
|
2212
2513
|
exports.createUserAPIKey = createUserAPIKey;
|
2213
2514
|
exports.createWorkspace = createWorkspace;
|
@@ -2221,6 +2522,7 @@ exports.deleteUserAPIKey = deleteUserAPIKey;
|
|
2221
2522
|
exports.deleteWorkspace = deleteWorkspace;
|
2222
2523
|
exports.deserialize = deserialize;
|
2223
2524
|
exports.endsWith = endsWith;
|
2525
|
+
exports.equals = equals;
|
2224
2526
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2225
2527
|
exports.exists = exists;
|
2226
2528
|
exports.ge = ge;
|
@@ -2230,6 +2532,7 @@ exports.getBranchList = getBranchList;
|
|
2230
2532
|
exports.getBranchMetadata = getBranchMetadata;
|
2231
2533
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2232
2534
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
2535
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2233
2536
|
exports.getBranchStats = getBranchStats;
|
2234
2537
|
exports.getColumn = getColumn;
|
2235
2538
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
@@ -2238,6 +2541,8 @@ exports.getDatabaseList = getDatabaseList;
|
|
2238
2541
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2239
2542
|
exports.getDatabaseURL = getDatabaseURL;
|
2240
2543
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
2544
|
+
exports.getMigrationRequest = getMigrationRequest;
|
2545
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
2241
2546
|
exports.getRecord = getRecord;
|
2242
2547
|
exports.getTableColumns = getTableColumns;
|
2243
2548
|
exports.getTableSchema = getTableSchema;
|
@@ -2246,6 +2551,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2246
2551
|
exports.getWorkspace = getWorkspace;
|
2247
2552
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2248
2553
|
exports.getWorkspacesList = getWorkspacesList;
|
2554
|
+
exports.greaterEquals = greaterEquals;
|
2555
|
+
exports.greaterThan = greaterThan;
|
2556
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2249
2557
|
exports.gt = gt;
|
2250
2558
|
exports.gte = gte;
|
2251
2559
|
exports.includes = includes;
|
@@ -2261,11 +2569,18 @@ exports.isIdentifiable = isIdentifiable;
|
|
2261
2569
|
exports.isNot = isNot;
|
2262
2570
|
exports.isXataRecord = isXataRecord;
|
2263
2571
|
exports.le = le;
|
2572
|
+
exports.lessEquals = lessEquals;
|
2573
|
+
exports.lessThan = lessThan;
|
2574
|
+
exports.lessThanEquals = lessThanEquals;
|
2575
|
+
exports.listMigrationRequests = listMigrationRequests;
|
2576
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
2264
2577
|
exports.lt = lt;
|
2265
2578
|
exports.lte = lte;
|
2579
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2266
2580
|
exports.notExists = notExists;
|
2267
2581
|
exports.operationsByTag = operationsByTag;
|
2268
2582
|
exports.pattern = pattern;
|
2583
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
2269
2584
|
exports.queryTable = queryTable;
|
2270
2585
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2271
2586
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
@@ -2277,7 +2592,9 @@ exports.serialize = serialize;
|
|
2277
2592
|
exports.setTableSchema = setTableSchema;
|
2278
2593
|
exports.startsWith = startsWith;
|
2279
2594
|
exports.updateBranchMetadata = updateBranchMetadata;
|
2595
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2280
2596
|
exports.updateColumn = updateColumn;
|
2597
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2281
2598
|
exports.updateRecordWithID = updateRecordWithID;
|
2282
2599
|
exports.updateTable = updateTable;
|
2283
2600
|
exports.updateUser = updateUser;
|