@xata.io/client 0.0.0-alpha.vf603f80 → 0.0.0-alpha.vf683143
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 +70 -0
- package/README.md +27 -25
- package/Usage.md +62 -6
- package/dist/index.cjs +763 -357
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1482 -298
- package/dist/index.mjs +740 -358
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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
|
}
|
@@ -13,6 +35,9 @@ function isDefined(value) {
|
|
13
35
|
function isString(value) {
|
14
36
|
return isDefined(value) && typeof value === "string";
|
15
37
|
}
|
38
|
+
function isStringArray(value) {
|
39
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
40
|
+
}
|
16
41
|
function toBase64(value) {
|
17
42
|
try {
|
18
43
|
return btoa(value);
|
@@ -118,12 +143,14 @@ function getFetchImplementation(userFetch) {
|
|
118
143
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
119
144
|
const fetchImpl = userFetch ?? globalFetch;
|
120
145
|
if (!fetchImpl) {
|
121
|
-
throw new Error(
|
146
|
+
throw new Error(
|
147
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
148
|
+
);
|
122
149
|
}
|
123
150
|
return fetchImpl;
|
124
151
|
}
|
125
152
|
|
126
|
-
const VERSION = "0.0.0-alpha.
|
153
|
+
const VERSION = "0.0.0-alpha.vf683143";
|
127
154
|
|
128
155
|
class ErrorWithCause extends Error {
|
129
156
|
constructor(message, options) {
|
@@ -174,7 +201,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
174
201
|
}, {});
|
175
202
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
176
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
177
|
-
|
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;
|
178
208
|
};
|
179
209
|
function buildBaseUrl({
|
180
210
|
path,
|
@@ -182,10 +212,10 @@ function buildBaseUrl({
|
|
182
212
|
apiUrl,
|
183
213
|
pathParams
|
184
214
|
}) {
|
185
|
-
if (
|
215
|
+
if (pathParams?.workspace === void 0)
|
186
216
|
return `${apiUrl}${path}`;
|
187
217
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
188
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
218
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
189
219
|
}
|
190
220
|
function hostHeader(url) {
|
191
221
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -202,34 +232,61 @@ async function fetch$1({
|
|
202
232
|
fetchImpl,
|
203
233
|
apiKey,
|
204
234
|
apiUrl,
|
205
|
-
workspacesApiUrl
|
235
|
+
workspacesApiUrl,
|
236
|
+
trace
|
206
237
|
}) {
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
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) {
|
225
285
|
try {
|
226
|
-
const
|
227
|
-
|
228
|
-
return jsonResponse;
|
229
|
-
}
|
230
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
286
|
+
const { host, protocol } = new URL(url);
|
287
|
+
return { host, protocol };
|
231
288
|
} catch (error) {
|
232
|
-
|
289
|
+
return {};
|
233
290
|
}
|
234
291
|
}
|
235
292
|
|
@@ -324,6 +381,12 @@ const deleteDatabase = (variables) => fetch$1({
|
|
324
381
|
method: "delete",
|
325
382
|
...variables
|
326
383
|
});
|
384
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
385
|
+
url: "/dbs/{dbName}/metadata",
|
386
|
+
method: "get",
|
387
|
+
...variables
|
388
|
+
});
|
389
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
327
390
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
328
391
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
329
392
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -332,16 +395,28 @@ const resolveBranch = (variables) => fetch$1({
|
|
332
395
|
method: "get",
|
333
396
|
...variables
|
334
397
|
});
|
335
|
-
const
|
336
|
-
|
398
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
399
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
400
|
+
const getMigrationRequest = (variables) => fetch$1({
|
401
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
337
402
|
method: "get",
|
338
403
|
...variables
|
339
404
|
});
|
340
|
-
const
|
405
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
406
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
407
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
408
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
409
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
410
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
411
|
+
method: "post",
|
412
|
+
...variables
|
413
|
+
});
|
414
|
+
const getBranchDetails = (variables) => fetch$1({
|
341
415
|
url: "/db/{dbBranchName}",
|
342
|
-
method: "
|
416
|
+
method: "get",
|
343
417
|
...variables
|
344
418
|
});
|
419
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
345
420
|
const deleteBranch = (variables) => fetch$1({
|
346
421
|
url: "/db/{dbBranchName}",
|
347
422
|
method: "delete",
|
@@ -360,6 +435,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
360
435
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
361
436
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
362
437
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
438
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
439
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
440
|
+
const updateBranchSchema = (variables) => fetch$1({
|
441
|
+
url: "/db/{dbBranchName}/schema/update",
|
442
|
+
method: "post",
|
443
|
+
...variables
|
444
|
+
});
|
445
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
446
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
447
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
363
448
|
const getBranchStats = (variables) => fetch$1({
|
364
449
|
url: "/db/{dbBranchName}/stats",
|
365
450
|
method: "get",
|
@@ -415,11 +500,7 @@ const updateColumn = (variables) => fetch$1({
|
|
415
500
|
method: "patch",
|
416
501
|
...variables
|
417
502
|
});
|
418
|
-
const insertRecord = (variables) => fetch$1({
|
419
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
420
|
-
method: "post",
|
421
|
-
...variables
|
422
|
-
});
|
503
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
423
504
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
424
505
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
425
506
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -449,6 +530,11 @@ const searchBranch = (variables) => fetch$1({
|
|
449
530
|
method: "post",
|
450
531
|
...variables
|
451
532
|
});
|
533
|
+
const summarizeTable = (variables) => fetch$1({
|
534
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
535
|
+
method: "post",
|
536
|
+
...variables
|
537
|
+
});
|
452
538
|
const operationsByTag = {
|
453
539
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
454
540
|
workspaces: {
|
@@ -470,6 +556,8 @@ const operationsByTag = {
|
|
470
556
|
getDatabaseList,
|
471
557
|
createDatabase,
|
472
558
|
deleteDatabase,
|
559
|
+
getDatabaseMetadata,
|
560
|
+
updateDatabaseMetadata,
|
473
561
|
getGitBranchesMapping,
|
474
562
|
addGitBranchesEntry,
|
475
563
|
removeGitBranchesEntry,
|
@@ -482,10 +570,28 @@ const operationsByTag = {
|
|
482
570
|
deleteBranch,
|
483
571
|
updateBranchMetadata,
|
484
572
|
getBranchMetadata,
|
573
|
+
getBranchStats
|
574
|
+
},
|
575
|
+
migrationRequests: {
|
576
|
+
listMigrationRequests,
|
577
|
+
createMigrationRequest,
|
578
|
+
getMigrationRequest,
|
579
|
+
updateMigrationRequest,
|
580
|
+
listMigrationRequestsCommits,
|
581
|
+
compareMigrationRequest,
|
582
|
+
getMigrationRequestIsMerged,
|
583
|
+
mergeMigrationRequest
|
584
|
+
},
|
585
|
+
branchSchema: {
|
485
586
|
getBranchMigrationHistory,
|
486
587
|
executeBranchMigrationPlan,
|
487
588
|
getBranchMigrationPlan,
|
488
|
-
|
589
|
+
compareBranchWithUserSchema,
|
590
|
+
compareBranchSchemas,
|
591
|
+
updateBranchSchema,
|
592
|
+
previewBranchSchemaEdit,
|
593
|
+
applyBranchSchemaEdit,
|
594
|
+
getBranchSchemaHistory
|
489
595
|
},
|
490
596
|
table: {
|
491
597
|
createTable,
|
@@ -509,14 +615,15 @@ const operationsByTag = {
|
|
509
615
|
bulkInsertTableRecords,
|
510
616
|
queryTable,
|
511
617
|
searchTable,
|
512
|
-
searchBranch
|
618
|
+
searchBranch,
|
619
|
+
summarizeTable
|
513
620
|
}
|
514
621
|
};
|
515
622
|
|
516
623
|
function getHostUrl(provider, type) {
|
517
|
-
if (
|
624
|
+
if (isHostProviderAlias(provider)) {
|
518
625
|
return providers[provider][type];
|
519
|
-
} else if (
|
626
|
+
} else if (isHostProviderBuilder(provider)) {
|
520
627
|
return provider[type];
|
521
628
|
}
|
522
629
|
throw new Error("Invalid API provider");
|
@@ -531,10 +638,10 @@ const providers = {
|
|
531
638
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
532
639
|
}
|
533
640
|
};
|
534
|
-
function
|
641
|
+
function isHostProviderAlias(alias) {
|
535
642
|
return isString(alias) && Object.keys(providers).includes(alias);
|
536
643
|
}
|
537
|
-
function
|
644
|
+
function isHostProviderBuilder(builder) {
|
538
645
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
539
646
|
}
|
540
647
|
|
@@ -562,7 +669,8 @@ class XataApiClient {
|
|
562
669
|
__privateAdd$7(this, _extraProps, void 0);
|
563
670
|
__privateAdd$7(this, _namespaces, {});
|
564
671
|
const provider = options.host ?? "production";
|
565
|
-
const apiKey = options
|
672
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
673
|
+
const trace = options.trace ?? defaultTrace;
|
566
674
|
if (!apiKey) {
|
567
675
|
throw new Error("Could not resolve a valid apiKey");
|
568
676
|
}
|
@@ -570,7 +678,8 @@ class XataApiClient {
|
|
570
678
|
apiUrl: getHostUrl(provider, "main"),
|
571
679
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
572
680
|
fetchImpl: getFetchImplementation(options.fetch),
|
573
|
-
apiKey
|
681
|
+
apiKey,
|
682
|
+
trace
|
574
683
|
});
|
575
684
|
}
|
576
685
|
get user() {
|
@@ -603,6 +712,16 @@ class XataApiClient {
|
|
603
712
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
604
713
|
return __privateGet$7(this, _namespaces).records;
|
605
714
|
}
|
715
|
+
get migrationRequests() {
|
716
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
717
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
718
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
719
|
+
}
|
720
|
+
get branchSchema() {
|
721
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
722
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
723
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
724
|
+
}
|
606
725
|
}
|
607
726
|
_extraProps = new WeakMap();
|
608
727
|
_namespaces = new WeakMap();
|
@@ -742,6 +861,19 @@ class DatabaseApi {
|
|
742
861
|
...this.extraProps
|
743
862
|
});
|
744
863
|
}
|
864
|
+
getDatabaseMetadata(workspace, dbName) {
|
865
|
+
return operationsByTag.database.getDatabaseMetadata({
|
866
|
+
pathParams: { workspace, dbName },
|
867
|
+
...this.extraProps
|
868
|
+
});
|
869
|
+
}
|
870
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
871
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
872
|
+
pathParams: { workspace, dbName },
|
873
|
+
body: options,
|
874
|
+
...this.extraProps
|
875
|
+
});
|
876
|
+
}
|
745
877
|
getGitBranchesMapping(workspace, dbName) {
|
746
878
|
return operationsByTag.database.getGitBranchesMapping({
|
747
879
|
pathParams: { workspace, dbName },
|
@@ -813,27 +945,6 @@ class BranchApi {
|
|
813
945
|
...this.extraProps
|
814
946
|
});
|
815
947
|
}
|
816
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
817
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
818
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
819
|
-
body: options,
|
820
|
-
...this.extraProps
|
821
|
-
});
|
822
|
-
}
|
823
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
824
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
825
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
826
|
-
body: migrationPlan,
|
827
|
-
...this.extraProps
|
828
|
-
});
|
829
|
-
}
|
830
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
831
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
832
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
833
|
-
body: schema,
|
834
|
-
...this.extraProps
|
835
|
-
});
|
836
|
-
}
|
837
948
|
getBranchStats(workspace, database, branch) {
|
838
949
|
return operationsByTag.branch.getBranchStats({
|
839
950
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -914,9 +1025,10 @@ class RecordsApi {
|
|
914
1025
|
constructor(extraProps) {
|
915
1026
|
this.extraProps = extraProps;
|
916
1027
|
}
|
917
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
1028
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
918
1029
|
return operationsByTag.records.insertRecord({
|
919
1030
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1031
|
+
queryParams: options,
|
920
1032
|
body: record,
|
921
1033
|
...this.extraProps
|
922
1034
|
});
|
@@ -945,21 +1057,24 @@ class RecordsApi {
|
|
945
1057
|
...this.extraProps
|
946
1058
|
});
|
947
1059
|
}
|
948
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
1060
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
949
1061
|
return operationsByTag.records.deleteRecord({
|
950
1062
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1063
|
+
queryParams: options,
|
951
1064
|
...this.extraProps
|
952
1065
|
});
|
953
1066
|
}
|
954
1067
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
955
1068
|
return operationsByTag.records.getRecord({
|
956
1069
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1070
|
+
queryParams: options,
|
957
1071
|
...this.extraProps
|
958
1072
|
});
|
959
1073
|
}
|
960
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
1074
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
961
1075
|
return operationsByTag.records.bulkInsertTableRecords({
|
962
1076
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1077
|
+
queryParams: options,
|
963
1078
|
body: { records },
|
964
1079
|
...this.extraProps
|
965
1080
|
});
|
@@ -985,6 +1100,138 @@ class RecordsApi {
|
|
985
1100
|
...this.extraProps
|
986
1101
|
});
|
987
1102
|
}
|
1103
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1104
|
+
return operationsByTag.records.summarizeTable({
|
1105
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1106
|
+
body: query,
|
1107
|
+
...this.extraProps
|
1108
|
+
});
|
1109
|
+
}
|
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
|
+
}
|
988
1235
|
}
|
989
1236
|
|
990
1237
|
class XataApiPlugin {
|
@@ -1169,21 +1416,34 @@ const _Query = class {
|
|
1169
1416
|
}
|
1170
1417
|
filter(a, b) {
|
1171
1418
|
if (arguments.length === 1) {
|
1172
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1419
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1173
1420
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1174
1421
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1175
1422
|
} else {
|
1176
|
-
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));
|
1177
1425
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1178
1426
|
}
|
1179
1427
|
}
|
1180
|
-
|
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") {
|
1181
1436
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1182
1437
|
const sort = [...originalSort, { column, direction }];
|
1183
1438
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1184
1439
|
}
|
1185
1440
|
select(columns) {
|
1186
|
-
return new _Query(
|
1441
|
+
return new _Query(
|
1442
|
+
__privateGet$5(this, _repository),
|
1443
|
+
__privateGet$5(this, _table$1),
|
1444
|
+
{ columns },
|
1445
|
+
__privateGet$5(this, _data)
|
1446
|
+
);
|
1187
1447
|
}
|
1188
1448
|
getPaginated(options = {}) {
|
1189
1449
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1206,11 +1466,20 @@ const _Query = class {
|
|
1206
1466
|
}
|
1207
1467
|
}
|
1208
1468
|
async getMany(options = {}) {
|
1209
|
-
const
|
1469
|
+
const { pagination = {}, ...rest } = options;
|
1470
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1471
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1472
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1473
|
+
const results = [...page.records];
|
1474
|
+
while (page.hasNextPage() && results.length < size) {
|
1475
|
+
page = await page.nextPage();
|
1476
|
+
results.push(...page.records);
|
1477
|
+
}
|
1210
1478
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1211
1479
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1212
1480
|
}
|
1213
|
-
|
1481
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1482
|
+
return array;
|
1214
1483
|
}
|
1215
1484
|
async getAll(options = {}) {
|
1216
1485
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1224,6 +1493,12 @@ const _Query = class {
|
|
1224
1493
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1225
1494
|
return records[0] ?? null;
|
1226
1495
|
}
|
1496
|
+
async getFirstOrThrow(options = {}) {
|
1497
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1498
|
+
if (records[0] === void 0)
|
1499
|
+
throw new Error("No results found.");
|
1500
|
+
return records[0];
|
1501
|
+
}
|
1227
1502
|
cache(ttl) {
|
1228
1503
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1229
1504
|
}
|
@@ -1308,203 +1583,284 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1308
1583
|
__accessCheck$4(obj, member, "access private method");
|
1309
1584
|
return method;
|
1310
1585
|
};
|
1311
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn,
|
1586
|
+
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;
|
1312
1587
|
class Repository extends Query {
|
1313
1588
|
}
|
1314
1589
|
class RestRepository extends Query {
|
1315
1590
|
constructor(options) {
|
1316
|
-
super(
|
1591
|
+
super(
|
1592
|
+
null,
|
1593
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1594
|
+
{}
|
1595
|
+
);
|
1317
1596
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1318
1597
|
__privateAdd$4(this, _insertRecordWithId);
|
1319
1598
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
1320
1599
|
__privateAdd$4(this, _updateRecordWithID);
|
1321
1600
|
__privateAdd$4(this, _upsertRecordWithID);
|
1322
1601
|
__privateAdd$4(this, _deleteRecord);
|
1323
|
-
__privateAdd$4(this, _invalidateCache);
|
1324
|
-
__privateAdd$4(this, _setCacheRecord);
|
1325
|
-
__privateAdd$4(this, _getCacheRecord);
|
1326
1602
|
__privateAdd$4(this, _setCacheQuery);
|
1327
1603
|
__privateAdd$4(this, _getCacheQuery);
|
1328
1604
|
__privateAdd$4(this, _getSchemaTables$1);
|
1329
1605
|
__privateAdd$4(this, _table, void 0);
|
1330
1606
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1607
|
+
__privateAdd$4(this, _db, void 0);
|
1331
1608
|
__privateAdd$4(this, _cache, void 0);
|
1332
1609
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1610
|
+
__privateAdd$4(this, _trace, void 0);
|
1333
1611
|
__privateSet$4(this, _table, options.table);
|
1334
1612
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1335
|
-
this
|
1613
|
+
__privateSet$4(this, _db, options.db);
|
1336
1614
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1337
1615
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1616
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1617
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1618
|
+
return trace(name, fn, {
|
1619
|
+
...options2,
|
1620
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1621
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1622
|
+
[TraceAttributes.VERSION]: VERSION
|
1623
|
+
});
|
1624
|
+
});
|
1338
1625
|
}
|
1339
|
-
async create(a, b) {
|
1340
|
-
|
1341
|
-
if (a
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
const
|
1381
|
-
|
1382
|
-
const
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1626
|
+
async create(a, b, c) {
|
1627
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1628
|
+
if (Array.isArray(a)) {
|
1629
|
+
if (a.length === 0)
|
1630
|
+
return [];
|
1631
|
+
const columns = isStringArray(b) ? b : void 0;
|
1632
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1633
|
+
}
|
1634
|
+
if (isString(a) && isObject(b)) {
|
1635
|
+
if (a === "")
|
1636
|
+
throw new Error("The id can't be empty");
|
1637
|
+
const columns = isStringArray(c) ? c : void 0;
|
1638
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1639
|
+
}
|
1640
|
+
if (isObject(a) && isString(a.id)) {
|
1641
|
+
if (a.id === "")
|
1642
|
+
throw new Error("The id can't be empty");
|
1643
|
+
const columns = isStringArray(b) ? b : void 0;
|
1644
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1645
|
+
}
|
1646
|
+
if (isObject(a)) {
|
1647
|
+
const columns = isStringArray(b) ? b : void 0;
|
1648
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1649
|
+
}
|
1650
|
+
throw new Error("Invalid arguments for create method");
|
1651
|
+
});
|
1652
|
+
}
|
1653
|
+
async read(a, b) {
|
1654
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1655
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1656
|
+
if (Array.isArray(a)) {
|
1657
|
+
if (a.length === 0)
|
1658
|
+
return [];
|
1659
|
+
const ids = a.map((item) => extractId(item));
|
1660
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1661
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1662
|
+
acc[object.id] = object;
|
1663
|
+
return acc;
|
1664
|
+
}, {});
|
1665
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1666
|
+
}
|
1667
|
+
const id = extractId(a);
|
1668
|
+
if (id) {
|
1669
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1670
|
+
try {
|
1671
|
+
const response = await getRecord({
|
1672
|
+
pathParams: {
|
1673
|
+
workspace: "{workspaceId}",
|
1674
|
+
dbBranchName: "{dbBranch}",
|
1675
|
+
tableName: __privateGet$4(this, _table),
|
1676
|
+
recordId: id
|
1677
|
+
},
|
1678
|
+
queryParams: { columns },
|
1679
|
+
...fetchProps
|
1680
|
+
});
|
1681
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1682
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1683
|
+
} catch (e) {
|
1684
|
+
if (isObject(e) && e.status === 404) {
|
1685
|
+
return null;
|
1686
|
+
}
|
1687
|
+
throw e;
|
1391
1688
|
}
|
1392
|
-
throw e;
|
1393
1689
|
}
|
1394
|
-
|
1690
|
+
return null;
|
1691
|
+
});
|
1395
1692
|
}
|
1396
|
-
async
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1693
|
+
async readOrThrow(a, b) {
|
1694
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1695
|
+
const result = await this.read(a, b);
|
1696
|
+
if (Array.isArray(result)) {
|
1697
|
+
const missingIds = compact(
|
1698
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1699
|
+
);
|
1700
|
+
if (missingIds.length > 0) {
|
1701
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1702
|
+
}
|
1703
|
+
return result;
|
1402
1704
|
}
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1407
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1408
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1409
|
-
return record;
|
1410
|
-
}
|
1411
|
-
if (isObject(a) && isString(a.id)) {
|
1412
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1413
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1414
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1415
|
-
return record;
|
1416
|
-
}
|
1417
|
-
throw new Error("Invalid arguments for update method");
|
1418
|
-
}
|
1419
|
-
async createOrUpdate(a, b) {
|
1420
|
-
if (Array.isArray(a)) {
|
1421
|
-
if (a.length === 0)
|
1422
|
-
return [];
|
1423
|
-
if (a.length > 100) {
|
1424
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1705
|
+
if (result === null) {
|
1706
|
+
const id = extractId(a) ?? "unknown";
|
1707
|
+
throw new Error(`Record with id ${id} not found`);
|
1425
1708
|
}
|
1426
|
-
return
|
1427
|
-
}
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
}
|
1440
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1441
|
-
}
|
1442
|
-
async delete(a) {
|
1443
|
-
if (Array.isArray(a)) {
|
1444
|
-
if (a.length === 0)
|
1445
|
-
return;
|
1446
|
-
if (a.length > 100) {
|
1447
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1709
|
+
return result;
|
1710
|
+
});
|
1711
|
+
}
|
1712
|
+
async update(a, b, c) {
|
1713
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1714
|
+
if (Array.isArray(a)) {
|
1715
|
+
if (a.length === 0)
|
1716
|
+
return [];
|
1717
|
+
if (a.length > 100) {
|
1718
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1719
|
+
}
|
1720
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1721
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1448
1722
|
}
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1723
|
+
if (isString(a) && isObject(b)) {
|
1724
|
+
const columns = isStringArray(c) ? c : void 0;
|
1725
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1726
|
+
}
|
1727
|
+
if (isObject(a) && isString(a.id)) {
|
1728
|
+
const columns = isStringArray(b) ? b : void 0;
|
1729
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1730
|
+
}
|
1731
|
+
throw new Error("Invalid arguments for update method");
|
1732
|
+
});
|
1733
|
+
}
|
1734
|
+
async updateOrThrow(a, b, c) {
|
1735
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1736
|
+
const result = await this.update(a, b, c);
|
1737
|
+
if (Array.isArray(result)) {
|
1738
|
+
const missingIds = compact(
|
1739
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1740
|
+
);
|
1741
|
+
if (missingIds.length > 0) {
|
1742
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1743
|
+
}
|
1744
|
+
return result;
|
1745
|
+
}
|
1746
|
+
if (result === null) {
|
1747
|
+
const id = extractId(a) ?? "unknown";
|
1748
|
+
throw new Error(`Record with id ${id} not found`);
|
1749
|
+
}
|
1750
|
+
return result;
|
1751
|
+
});
|
1752
|
+
}
|
1753
|
+
async createOrUpdate(a, b, c) {
|
1754
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1755
|
+
if (Array.isArray(a)) {
|
1756
|
+
if (a.length === 0)
|
1757
|
+
return [];
|
1758
|
+
if (a.length > 100) {
|
1759
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1760
|
+
}
|
1761
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1762
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1763
|
+
}
|
1764
|
+
if (isString(a) && isObject(b)) {
|
1765
|
+
const columns = isStringArray(c) ? c : void 0;
|
1766
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1767
|
+
}
|
1768
|
+
if (isObject(a) && isString(a.id)) {
|
1769
|
+
const columns = isStringArray(c) ? c : void 0;
|
1770
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1771
|
+
}
|
1772
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1773
|
+
});
|
1774
|
+
}
|
1775
|
+
async delete(a, b) {
|
1776
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1777
|
+
if (Array.isArray(a)) {
|
1778
|
+
if (a.length === 0)
|
1779
|
+
return [];
|
1780
|
+
if (a.length > 100) {
|
1781
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1782
|
+
}
|
1783
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1784
|
+
}
|
1785
|
+
if (isString(a)) {
|
1786
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1787
|
+
}
|
1788
|
+
if (isObject(a) && isString(a.id)) {
|
1789
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1790
|
+
}
|
1791
|
+
throw new Error("Invalid arguments for delete method");
|
1792
|
+
});
|
1793
|
+
}
|
1794
|
+
async deleteOrThrow(a, b) {
|
1795
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1796
|
+
const result = await this.delete(a, b);
|
1797
|
+
if (Array.isArray(result)) {
|
1798
|
+
const missingIds = compact(
|
1799
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1800
|
+
);
|
1801
|
+
if (missingIds.length > 0) {
|
1802
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1803
|
+
}
|
1804
|
+
return result;
|
1805
|
+
} else if (result === null) {
|
1806
|
+
const id = extractId(a) ?? "unknown";
|
1807
|
+
throw new Error(`Record with id ${id} not found`);
|
1808
|
+
}
|
1809
|
+
return result;
|
1810
|
+
});
|
1463
1811
|
}
|
1464
1812
|
async search(query, options = {}) {
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1813
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1814
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1815
|
+
const { records } = await searchTable({
|
1816
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1817
|
+
body: {
|
1818
|
+
query,
|
1819
|
+
fuzziness: options.fuzziness,
|
1820
|
+
prefix: options.prefix,
|
1821
|
+
highlight: options.highlight,
|
1822
|
+
filter: options.filter,
|
1823
|
+
boosters: options.boosters
|
1824
|
+
},
|
1825
|
+
...fetchProps
|
1826
|
+
});
|
1827
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1828
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1475
1829
|
});
|
1476
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1477
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1478
1830
|
}
|
1479
1831
|
async query(query) {
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1832
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1833
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1834
|
+
if (cacheQuery)
|
1835
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1836
|
+
const data = query.getQueryOptions();
|
1837
|
+
const body = {
|
1838
|
+
filter: cleanFilter(data.filter),
|
1839
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1840
|
+
page: data.pagination,
|
1841
|
+
columns: data.columns
|
1842
|
+
};
|
1843
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1844
|
+
const { meta, records: objects } = await queryTable({
|
1845
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1846
|
+
body,
|
1847
|
+
...fetchProps
|
1848
|
+
});
|
1849
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1850
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1851
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1852
|
+
return new Page(query, meta, records);
|
1495
1853
|
});
|
1496
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1497
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1498
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1499
|
-
return new Page(query, meta, records);
|
1500
1854
|
}
|
1501
1855
|
}
|
1502
1856
|
_table = new WeakMap();
|
1503
1857
|
_getFetchProps = new WeakMap();
|
1858
|
+
_db = new WeakMap();
|
1504
1859
|
_cache = new WeakMap();
|
1505
1860
|
_schemaTables$2 = new WeakMap();
|
1861
|
+
_trace = new WeakMap();
|
1506
1862
|
_insertRecordWithoutId = new WeakSet();
|
1507
|
-
insertRecordWithoutId_fn = async function(object) {
|
1863
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1508
1864
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1509
1865
|
const record = transformObjectLinks(object);
|
1510
1866
|
const response = await insertRecord({
|
@@ -1513,17 +1869,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1513
1869
|
dbBranchName: "{dbBranch}",
|
1514
1870
|
tableName: __privateGet$4(this, _table)
|
1515
1871
|
},
|
1872
|
+
queryParams: { columns },
|
1516
1873
|
body: record,
|
1517
1874
|
...fetchProps
|
1518
1875
|
});
|
1519
|
-
const
|
1520
|
-
|
1521
|
-
throw new Error("The server failed to save the record");
|
1522
|
-
}
|
1523
|
-
return finalObject;
|
1876
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1877
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1524
1878
|
};
|
1525
1879
|
_insertRecordWithId = new WeakSet();
|
1526
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1880
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1527
1881
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1528
1882
|
const record = transformObjectLinks(object);
|
1529
1883
|
const response = await insertRecordWithID({
|
@@ -1534,92 +1888,78 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1534
1888
|
recordId
|
1535
1889
|
},
|
1536
1890
|
body: record,
|
1537
|
-
queryParams: { createOnly: true },
|
1891
|
+
queryParams: { createOnly: true, columns },
|
1538
1892
|
...fetchProps
|
1539
1893
|
});
|
1540
|
-
const
|
1541
|
-
|
1542
|
-
throw new Error("The server failed to save the record");
|
1543
|
-
}
|
1544
|
-
return finalObject;
|
1894
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1895
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1545
1896
|
};
|
1546
1897
|
_bulkInsertTableRecords = new WeakSet();
|
1547
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1898
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1548
1899
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1549
1900
|
const records = objects.map((object) => transformObjectLinks(object));
|
1550
|
-
const
|
1901
|
+
const response = await bulkInsertTableRecords({
|
1551
1902
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1903
|
+
queryParams: { columns },
|
1552
1904
|
body: { records },
|
1553
1905
|
...fetchProps
|
1554
1906
|
});
|
1555
|
-
|
1556
|
-
|
1557
|
-
throw new Error("The server failed to save some records");
|
1907
|
+
if (!isResponseWithRecords(response)) {
|
1908
|
+
throw new Error("Request included columns but server didn't include them");
|
1558
1909
|
}
|
1559
|
-
const
|
1560
|
-
|
1561
|
-
return acc;
|
1562
|
-
}, {});
|
1563
|
-
return recordIDs.map((id) => dictionary[id]);
|
1910
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1911
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1564
1912
|
};
|
1565
1913
|
_updateRecordWithID = new WeakSet();
|
1566
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1914
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1567
1915
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1568
1916
|
const record = transformObjectLinks(object);
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1917
|
+
try {
|
1918
|
+
const response = await updateRecordWithID({
|
1919
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1920
|
+
queryParams: { columns },
|
1921
|
+
body: record,
|
1922
|
+
...fetchProps
|
1923
|
+
});
|
1924
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1925
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1926
|
+
} catch (e) {
|
1927
|
+
if (isObject(e) && e.status === 404) {
|
1928
|
+
return null;
|
1929
|
+
}
|
1930
|
+
throw e;
|
1931
|
+
}
|
1578
1932
|
};
|
1579
1933
|
_upsertRecordWithID = new WeakSet();
|
1580
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1934
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1581
1935
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1582
1936
|
const response = await upsertRecordWithID({
|
1583
1937
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1938
|
+
queryParams: { columns },
|
1584
1939
|
body: object,
|
1585
1940
|
...fetchProps
|
1586
1941
|
});
|
1587
|
-
const
|
1588
|
-
|
1589
|
-
throw new Error("The server failed to save the record");
|
1590
|
-
return item;
|
1942
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1943
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1591
1944
|
};
|
1592
1945
|
_deleteRecord = new WeakSet();
|
1593
|
-
deleteRecord_fn = async function(recordId) {
|
1946
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1594
1947
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
await __privateGet$4(this, _cache).delete(key);
|
1948
|
+
try {
|
1949
|
+
const response = await deleteRecord({
|
1950
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1951
|
+
queryParams: { columns },
|
1952
|
+
...fetchProps
|
1953
|
+
});
|
1954
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1955
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1956
|
+
} catch (e) {
|
1957
|
+
if (isObject(e) && e.status === 404) {
|
1958
|
+
return null;
|
1959
|
+
}
|
1960
|
+
throw e;
|
1609
1961
|
}
|
1610
1962
|
};
|
1611
|
-
_setCacheRecord = new WeakSet();
|
1612
|
-
setCacheRecord_fn = async function(record) {
|
1613
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1614
|
-
return;
|
1615
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1616
|
-
};
|
1617
|
-
_getCacheRecord = new WeakSet();
|
1618
|
-
getCacheRecord_fn = async function(recordId) {
|
1619
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1620
|
-
return null;
|
1621
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1622
|
-
};
|
1623
1963
|
_setCacheQuery = new WeakSet();
|
1624
1964
|
setCacheQuery_fn = async function(query, meta, records) {
|
1625
1965
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1680,16 +2020,24 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1680
2020
|
console.error(`Failed to parse link for field ${column.name}`);
|
1681
2021
|
} else if (isObject(value)) {
|
1682
2022
|
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
2023
|
+
} else {
|
2024
|
+
result[column.name] = null;
|
1683
2025
|
}
|
1684
2026
|
break;
|
1685
2027
|
}
|
2028
|
+
default:
|
2029
|
+
result[column.name] = value ?? null;
|
2030
|
+
if (column.notNull === true && value === null) {
|
2031
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2032
|
+
}
|
2033
|
+
break;
|
1686
2034
|
}
|
1687
2035
|
}
|
1688
|
-
result.read = function() {
|
1689
|
-
return db[table].read(result["id"]);
|
2036
|
+
result.read = function(columns2) {
|
2037
|
+
return db[table].read(result["id"], columns2);
|
1690
2038
|
};
|
1691
|
-
result.update = function(data) {
|
1692
|
-
return db[table].update(result["id"], data);
|
2039
|
+
result.update = function(data, columns2) {
|
2040
|
+
return db[table].update(result["id"], data, columns2);
|
1693
2041
|
};
|
1694
2042
|
result.delete = function() {
|
1695
2043
|
return db[table].delete(result["id"]);
|
@@ -1703,14 +2051,21 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1703
2051
|
Object.freeze(result);
|
1704
2052
|
return result;
|
1705
2053
|
};
|
1706
|
-
function
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
if (
|
1711
|
-
return
|
1712
|
-
|
1713
|
-
|
2054
|
+
function isResponseWithRecords(value) {
|
2055
|
+
return isObject(value) && Array.isArray(value.records);
|
2056
|
+
}
|
2057
|
+
function extractId(value) {
|
2058
|
+
if (isString(value))
|
2059
|
+
return value;
|
2060
|
+
if (isObject(value) && isString(value.id))
|
2061
|
+
return value.id;
|
2062
|
+
return void 0;
|
2063
|
+
}
|
2064
|
+
function cleanFilter(filter) {
|
2065
|
+
if (!filter)
|
2066
|
+
return void 0;
|
2067
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2068
|
+
return values.length > 0 ? filter : void 0;
|
1714
2069
|
}
|
1715
2070
|
|
1716
2071
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1737,7 +2092,6 @@ class SimpleCache {
|
|
1737
2092
|
__privateAdd$3(this, _map, void 0);
|
1738
2093
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1739
2094
|
this.capacity = options.max ?? 500;
|
1740
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1741
2095
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1742
2096
|
}
|
1743
2097
|
async getAll() {
|
@@ -1763,18 +2117,25 @@ class SimpleCache {
|
|
1763
2117
|
}
|
1764
2118
|
_map = new WeakMap();
|
1765
2119
|
|
1766
|
-
const
|
1767
|
-
const
|
1768
|
-
const
|
1769
|
-
const
|
1770
|
-
const
|
1771
|
-
const
|
2120
|
+
const greaterThan = (value) => ({ $gt: value });
|
2121
|
+
const gt = greaterThan;
|
2122
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2123
|
+
const greaterEquals = greaterThanEquals;
|
2124
|
+
const gte = greaterThanEquals;
|
2125
|
+
const ge = greaterThanEquals;
|
2126
|
+
const lessThan = (value) => ({ $lt: value });
|
2127
|
+
const lt = lessThan;
|
2128
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2129
|
+
const lessEquals = lessThanEquals;
|
2130
|
+
const lte = lessThanEquals;
|
2131
|
+
const le = lessThanEquals;
|
1772
2132
|
const exists = (column) => ({ $exists: column });
|
1773
2133
|
const notExists = (column) => ({ $notExists: column });
|
1774
2134
|
const startsWith = (value) => ({ $startsWith: value });
|
1775
2135
|
const endsWith = (value) => ({ $endsWith: value });
|
1776
2136
|
const pattern = (value) => ({ $pattern: value });
|
1777
2137
|
const is = (value) => ({ $is: value });
|
2138
|
+
const equals = is;
|
1778
2139
|
const isNot = (value) => ({ $isNot: value });
|
1779
2140
|
const contains = (value) => ({ $contains: value });
|
1780
2141
|
const includes = (value) => ({ $includes: value });
|
@@ -1809,16 +2170,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1809
2170
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1810
2171
|
}
|
1811
2172
|
build(pluginOptions) {
|
1812
|
-
const db = new Proxy(
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
2173
|
+
const db = new Proxy(
|
2174
|
+
{},
|
2175
|
+
{
|
2176
|
+
get: (_target, table) => {
|
2177
|
+
if (!isString(table))
|
2178
|
+
throw new Error("Invalid table name");
|
2179
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
2180
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
2181
|
+
}
|
2182
|
+
return __privateGet$2(this, _tables)[table];
|
1818
2183
|
}
|
1819
|
-
return __privateGet$2(this, _tables)[table];
|
1820
2184
|
}
|
1821
|
-
|
2185
|
+
);
|
1822
2186
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1823
2187
|
for (const table of tableNames) {
|
1824
2188
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1888,10 +2252,10 @@ _schemaTables = new WeakMap();
|
|
1888
2252
|
_search = new WeakSet();
|
1889
2253
|
search_fn = async function(query, options, getFetchProps) {
|
1890
2254
|
const fetchProps = await getFetchProps();
|
1891
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
2255
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1892
2256
|
const { records } = await searchBranch({
|
1893
2257
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1894
|
-
body: { tables, query, fuzziness, highlight },
|
2258
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1895
2259
|
...fetchProps
|
1896
2260
|
});
|
1897
2261
|
return records;
|
@@ -1932,9 +2296,13 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1932
2296
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1933
2297
|
const apiKey = options?.apiKey || getAPIKey();
|
1934
2298
|
if (!databaseURL)
|
1935
|
-
throw new Error(
|
2299
|
+
throw new Error(
|
2300
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2301
|
+
);
|
1936
2302
|
if (!apiKey)
|
1937
|
-
throw new Error(
|
2303
|
+
throw new Error(
|
2304
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2305
|
+
);
|
1938
2306
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1939
2307
|
const [workspace] = host.split(".");
|
1940
2308
|
const { fallbackBranch } = getEnvironment();
|
@@ -1944,7 +2312,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1944
2312
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1945
2313
|
workspacesApiUrl: `${protocol}//${host}`,
|
1946
2314
|
pathParams: { dbName, workspace },
|
1947
|
-
queryParams: { gitBranch, fallbackBranch }
|
2315
|
+
queryParams: { gitBranch, fallbackBranch },
|
2316
|
+
trace: defaultTrace
|
1948
2317
|
});
|
1949
2318
|
return branch;
|
1950
2319
|
}
|
@@ -1952,9 +2321,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1952
2321
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1953
2322
|
const apiKey = options?.apiKey || getAPIKey();
|
1954
2323
|
if (!databaseURL)
|
1955
|
-
throw new Error(
|
2324
|
+
throw new Error(
|
2325
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2326
|
+
);
|
1956
2327
|
if (!apiKey)
|
1957
|
-
throw new Error(
|
2328
|
+
throw new Error(
|
2329
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2330
|
+
);
|
1958
2331
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1959
2332
|
const [workspace] = host.split(".");
|
1960
2333
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1964,7 +2337,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1964
2337
|
apiUrl: databaseURL,
|
1965
2338
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1966
2339
|
workspacesApiUrl: `${protocol}//${host}`,
|
1967
|
-
pathParams: { dbBranchName, workspace }
|
2340
|
+
pathParams: { dbBranchName, workspace },
|
2341
|
+
trace: defaultTrace
|
1968
2342
|
});
|
1969
2343
|
} catch (err) {
|
1970
2344
|
if (isObject(err) && err.status === 404)
|
@@ -2004,17 +2378,20 @@ var __privateMethod = (obj, member, method) => {
|
|
2004
2378
|
return method;
|
2005
2379
|
};
|
2006
2380
|
const buildClient = (plugins) => {
|
2007
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2381
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2008
2382
|
return _a = class {
|
2009
2383
|
constructor(options = {}, schemaTables) {
|
2010
2384
|
__privateAdd(this, _parseOptions);
|
2011
2385
|
__privateAdd(this, _getFetchProps);
|
2012
2386
|
__privateAdd(this, _evaluateBranch);
|
2013
2387
|
__privateAdd(this, _branch, void 0);
|
2388
|
+
__privateAdd(this, _options, void 0);
|
2014
2389
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2390
|
+
__privateSet(this, _options, safeOptions);
|
2015
2391
|
const pluginOptions = {
|
2016
2392
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2017
|
-
cache: safeOptions.cache
|
2393
|
+
cache: safeOptions.cache,
|
2394
|
+
trace: safeOptions.trace
|
2018
2395
|
};
|
2019
2396
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2020
2397
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2033,22 +2410,26 @@ const buildClient = (plugins) => {
|
|
2033
2410
|
}
|
2034
2411
|
}
|
2035
2412
|
}
|
2036
|
-
|
2413
|
+
async getConfig() {
|
2414
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2415
|
+
const branch = await __privateGet(this, _options).branch();
|
2416
|
+
return { databaseURL, branch };
|
2417
|
+
}
|
2418
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
2037
2419
|
const fetch = getFetchImplementation(options?.fetch);
|
2038
2420
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2039
2421
|
const apiKey = options?.apiKey || getAPIKey();
|
2040
|
-
const cache = options?.cache ?? new SimpleCache({
|
2422
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2423
|
+
const trace = options?.trace ?? defaultTrace;
|
2041
2424
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2042
|
-
if (!
|
2043
|
-
throw new Error("
|
2425
|
+
if (!apiKey) {
|
2426
|
+
throw new Error("Option apiKey is required");
|
2044
2427
|
}
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
apiKey,
|
2049
|
-
|
2050
|
-
branch
|
2051
|
-
}) {
|
2428
|
+
if (!databaseURL) {
|
2429
|
+
throw new Error("Option databaseURL is required");
|
2430
|
+
}
|
2431
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2432
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2052
2433
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2053
2434
|
if (!branchValue)
|
2054
2435
|
throw new Error("Unable to resolve branch value");
|
@@ -2058,9 +2439,10 @@ const buildClient = (plugins) => {
|
|
2058
2439
|
apiUrl: "",
|
2059
2440
|
workspacesApiUrl: (path, params) => {
|
2060
2441
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2061
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2442
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2062
2443
|
return databaseURL + newPath;
|
2063
|
-
}
|
2444
|
+
},
|
2445
|
+
trace
|
2064
2446
|
};
|
2065
2447
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2066
2448
|
if (__privateGet(this, _branch))
|
@@ -2142,25 +2524,25 @@ class Serializer {
|
|
2142
2524
|
});
|
2143
2525
|
}
|
2144
2526
|
}
|
2145
|
-
const
|
2146
|
-
|
2527
|
+
const defaultSerializer = new Serializer();
|
2528
|
+
const serialize = (data) => {
|
2529
|
+
return defaultSerializer.toJSON(data);
|
2147
2530
|
};
|
2148
|
-
const deserialize = () => {
|
2149
|
-
|
2531
|
+
const deserialize = (json) => {
|
2532
|
+
return defaultSerializer.fromJSON(json);
|
2150
2533
|
};
|
2151
2534
|
|
2152
2535
|
function buildWorkerRunner(config) {
|
2153
2536
|
return function xataWorker(name, _worker) {
|
2154
2537
|
return async (...args) => {
|
2155
|
-
const
|
2538
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2539
|
+
const result = await fetch(url, {
|
2156
2540
|
method: "POST",
|
2157
2541
|
headers: { "Content-Type": "application/json" },
|
2158
|
-
body:
|
2159
|
-
name,
|
2160
|
-
payload: args
|
2161
|
-
})
|
2542
|
+
body: serialize({ args })
|
2162
2543
|
});
|
2163
|
-
|
2544
|
+
const text = await result.text();
|
2545
|
+
return deserialize(text);
|
2164
2546
|
};
|
2165
2547
|
};
|
2166
2548
|
}
|
@@ -2172,5 +2554,5 @@ class XataError extends Error {
|
|
2172
2554
|
}
|
2173
2555
|
}
|
2174
2556
|
|
2175
|
-
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, 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 };
|
2557
|
+
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, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2176
2558
|
//# sourceMappingURL=index.mjs.map
|