@xata.io/client 0.0.0-alpha.vf95371f → 0.0.0-alpha.vf957886
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/.eslintrc.cjs +1 -2
- package/CHANGELOG.md +14 -0
- package/dist/index.cjs +86 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +64 -5
- package/dist/index.mjs +85 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/tsconfig.json +1 -0
package/dist/index.d.ts
CHANGED
@@ -268,6 +268,17 @@ declare type SortExpression = string[] | {
|
|
268
268
|
[key: string]: SortOrder;
|
269
269
|
}[];
|
270
270
|
declare type SortOrder = 'asc' | 'desc';
|
271
|
+
/**
|
272
|
+
* Maximum [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) for the search terms. The Levenshtein
|
273
|
+
* distance is the number of one charcter changes needed to make two strings equal. The default is 1, meaning that single
|
274
|
+
* character typos per word are tollerated by search. You can set it to 0 to remove the typo tollerance or set it to 2
|
275
|
+
* to allow two typos in a word.
|
276
|
+
*
|
277
|
+
* @default 1
|
278
|
+
* @maximum 2
|
279
|
+
* @minimum 0
|
280
|
+
*/
|
281
|
+
declare type FuzzinessExpression = number;
|
271
282
|
/**
|
272
283
|
* @minProperties 1
|
273
284
|
*/
|
@@ -409,6 +420,7 @@ type schemas_TableMigration = TableMigration;
|
|
409
420
|
type schemas_ColumnMigration = ColumnMigration;
|
410
421
|
type schemas_SortExpression = SortExpression;
|
411
422
|
type schemas_SortOrder = SortOrder;
|
423
|
+
type schemas_FuzzinessExpression = FuzzinessExpression;
|
412
424
|
type schemas_FilterExpression = FilterExpression;
|
413
425
|
type schemas_FilterList = FilterList;
|
414
426
|
type schemas_FilterColumn = FilterColumn;
|
@@ -462,6 +474,7 @@ declare namespace schemas {
|
|
462
474
|
schemas_ColumnMigration as ColumnMigration,
|
463
475
|
schemas_SortExpression as SortExpression,
|
464
476
|
schemas_SortOrder as SortOrder,
|
477
|
+
schemas_FuzzinessExpression as FuzzinessExpression,
|
465
478
|
schemas_FilterExpression as FilterExpression,
|
466
479
|
schemas_FilterList as FilterList,
|
467
480
|
schemas_FilterColumn as FilterColumn,
|
@@ -2262,12 +2275,18 @@ declare type QueryTableVariables = {
|
|
2262
2275
|
* {
|
2263
2276
|
* "filter": {
|
2264
2277
|
* "<column_name>": {
|
2265
|
-
* "$pattern": "v*
|
2278
|
+
* "$pattern": "v*alu?"
|
2266
2279
|
* }
|
2267
2280
|
* }
|
2268
2281
|
* }
|
2269
2282
|
* ```
|
2270
2283
|
*
|
2284
|
+
* The `$pattern` operator accepts two wildcard characters:
|
2285
|
+
* * `*` matches zero or more characters
|
2286
|
+
* * `?` matches exactly one character
|
2287
|
+
*
|
2288
|
+
* If you want to match a string that contains a wildcard character, you can escape them using a backslash (`\`). You can escape a backslash by usign another backslash.
|
2289
|
+
*
|
2271
2290
|
* We could also have `$endsWith` and `$startsWith` operators:
|
2272
2291
|
*
|
2273
2292
|
* ```json
|
@@ -2574,6 +2593,38 @@ declare type QueryTableVariables = {
|
|
2574
2593
|
* ```
|
2575
2594
|
*/
|
2576
2595
|
declare const queryTable: (variables: QueryTableVariables) => Promise<QueryResponse>;
|
2596
|
+
declare type SearchTablePathParams = {
|
2597
|
+
dbBranchName: DBBranchName;
|
2598
|
+
tableName: TableName;
|
2599
|
+
workspace: string;
|
2600
|
+
};
|
2601
|
+
declare type SearchTableError = ErrorWrapper<{
|
2602
|
+
status: 400;
|
2603
|
+
payload: BadRequestError;
|
2604
|
+
} | {
|
2605
|
+
status: 401;
|
2606
|
+
payload: AuthError;
|
2607
|
+
} | {
|
2608
|
+
status: 404;
|
2609
|
+
payload: SimpleError;
|
2610
|
+
}>;
|
2611
|
+
declare type SearchTableRequestBody = {
|
2612
|
+
query: string;
|
2613
|
+
fuzziness?: FuzzinessExpression;
|
2614
|
+
filter?: FilterExpression;
|
2615
|
+
};
|
2616
|
+
declare type SearchTableVariables = {
|
2617
|
+
body: SearchTableRequestBody;
|
2618
|
+
pathParams: SearchTablePathParams;
|
2619
|
+
} & FetcherExtraProps;
|
2620
|
+
/**
|
2621
|
+
* Run a free text search operation in a particular table.
|
2622
|
+
*
|
2623
|
+
* The endpoint accepts a `query` parameter that is used for the free text search and a set of structured filters (via the `filter` parameter) that are applied before the search. The `filter` parameter uses the same syntax as the [query endpoint](/api-reference/db/db_branch_name/tables/table_name/) with the following exceptions:
|
2624
|
+
* * filters `$contains`, `$startsWith`, `$endsWith` don't work on columns of type `text`
|
2625
|
+
* * filtering on columns of type `multiple` is currently unsupported
|
2626
|
+
*/
|
2627
|
+
declare const searchTable: (variables: SearchTableVariables) => Promise<SearchResponse>;
|
2577
2628
|
declare type SearchBranchPathParams = {
|
2578
2629
|
dbBranchName: DBBranchName;
|
2579
2630
|
workspace: string;
|
@@ -2589,9 +2640,12 @@ declare type SearchBranchError = ErrorWrapper<{
|
|
2589
2640
|
payload: SimpleError;
|
2590
2641
|
}>;
|
2591
2642
|
declare type SearchBranchRequestBody = {
|
2592
|
-
tables?: string
|
2643
|
+
tables?: (string | {
|
2644
|
+
table: string;
|
2645
|
+
filter?: FilterExpression;
|
2646
|
+
})[];
|
2593
2647
|
query: string;
|
2594
|
-
fuzziness?:
|
2648
|
+
fuzziness?: FuzzinessExpression;
|
2595
2649
|
};
|
2596
2650
|
declare type SearchBranchVariables = {
|
2597
2651
|
body: SearchBranchRequestBody;
|
@@ -2666,6 +2720,7 @@ declare const operationsByTag: {
|
|
2666
2720
|
getRecord: (variables: GetRecordVariables) => Promise<XataRecord$1>;
|
2667
2721
|
bulkInsertTableRecords: (variables: BulkInsertTableRecordsVariables) => Promise<BulkInsertTableRecordsResponse>;
|
2668
2722
|
queryTable: (variables: QueryTableVariables) => Promise<QueryResponse>;
|
2723
|
+
searchTable: (variables: SearchTableVariables) => Promise<SearchResponse>;
|
2669
2724
|
searchBranch: (variables: SearchBranchVariables) => Promise<SearchResponse>;
|
2670
2725
|
};
|
2671
2726
|
};
|
@@ -2771,6 +2826,7 @@ declare class RecordsApi {
|
|
2771
2826
|
getRecord(workspace: WorkspaceID, database: DBName, branch: BranchName, tableName: TableName, recordId: RecordID, options?: GetRecordRequestBody): Promise<XataRecord$1>;
|
2772
2827
|
bulkInsertTableRecords(workspace: WorkspaceID, database: DBName, branch: BranchName, tableName: TableName, records: Record<string, any>[]): Promise<BulkInsertTableRecordsResponse>;
|
2773
2828
|
queryTable(workspace: WorkspaceID, database: DBName, branch: BranchName, tableName: TableName, query: QueryTableRequestBody): Promise<QueryResponse>;
|
2829
|
+
searchTable(workspace: WorkspaceID, database: DBName, branch: BranchName, tableName: TableName, query: SearchTableRequestBody): Promise<SearchResponse>;
|
2774
2830
|
searchBranch(workspace: WorkspaceID, database: DBName, branch: BranchName, query: SearchBranchRequestBody): Promise<SearchResponse>;
|
2775
2831
|
}
|
2776
2832
|
|
@@ -3012,7 +3068,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
3012
3068
|
#private;
|
3013
3069
|
readonly meta: PaginationQueryMeta;
|
3014
3070
|
readonly records: Result[];
|
3015
|
-
constructor(repository: Repository<Record> | null, table: string, data: Partial<QueryOptions<Record>>,
|
3071
|
+
constructor(repository: Repository<Record> | null, table: string, data: Partial<QueryOptions<Record>>, rawParent?: Partial<QueryOptions<Record>>);
|
3016
3072
|
getQueryOptions(): QueryOptions<Record>;
|
3017
3073
|
key(): string;
|
3018
3074
|
/**
|
@@ -3202,6 +3258,7 @@ declare const PAGINATION_MAX_SIZE = 200;
|
|
3202
3258
|
declare const PAGINATION_DEFAULT_SIZE = 200;
|
3203
3259
|
declare const PAGINATION_MAX_OFFSET = 800;
|
3204
3260
|
declare const PAGINATION_DEFAULT_OFFSET = 0;
|
3261
|
+
declare function isCursorPaginationOptions(options: Record<string, unknown> | undefined | null): options is CursorNavigationOptions;
|
3205
3262
|
|
3206
3263
|
/**
|
3207
3264
|
* Common interface for performing operations on a table.
|
@@ -3300,6 +3357,7 @@ declare abstract class Repository<Data extends BaseData, Record extends XataReco
|
|
3300
3357
|
*/
|
3301
3358
|
abstract search(query: string, options?: {
|
3302
3359
|
fuzziness?: number;
|
3360
|
+
filter?: Filter<Record>;
|
3303
3361
|
}): Promise<SelectedPick<Record, ['*']>[]>;
|
3304
3362
|
abstract query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
|
3305
3363
|
}
|
@@ -3324,6 +3382,7 @@ declare class RestRepository<Data extends BaseData, Record extends XataRecord =
|
|
3324
3382
|
delete(a: string | Identifiable | Array<string | Identifiable>): Promise<void>;
|
3325
3383
|
search(query: string, options?: {
|
3326
3384
|
fuzziness?: number;
|
3385
|
+
filter?: Filter<Record>;
|
3327
3386
|
}): Promise<SelectedPick<Record, ['*']>[]>;
|
3328
3387
|
query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
|
3329
3388
|
}
|
@@ -3484,4 +3543,4 @@ declare class XataError extends Error {
|
|
3484
3543
|
constructor(message: string, status: number);
|
3485
3544
|
}
|
3486
3545
|
|
3487
|
-
export { AcceptWorkspaceMemberInviteError, AcceptWorkspaceMemberInvitePathParams, AcceptWorkspaceMemberInviteVariables, AddGitBranchesEntryError, AddGitBranchesEntryPathParams, AddGitBranchesEntryRequestBody, AddGitBranchesEntryResponse, AddGitBranchesEntryVariables, AddTableColumnError, AddTableColumnPathParams, AddTableColumnVariables, BaseClient, BaseClientOptions, BaseData, BulkInsertTableRecordsError, BulkInsertTableRecordsPathParams, BulkInsertTableRecordsRequestBody, BulkInsertTableRecordsResponse, BulkInsertTableRecordsVariables, CacheImpl, CancelWorkspaceMemberInviteError, CancelWorkspaceMemberInvitePathParams, CancelWorkspaceMemberInviteVariables, ClientConstructor, CreateBranchError, CreateBranchPathParams, CreateBranchQueryParams, CreateBranchRequestBody, CreateBranchVariables, CreateDatabaseError, CreateDatabasePathParams, CreateDatabaseRequestBody, CreateDatabaseResponse, CreateDatabaseVariables, CreateTableError, CreateTablePathParams, CreateTableVariables, CreateUserAPIKeyError, CreateUserAPIKeyPathParams, CreateUserAPIKeyResponse, CreateUserAPIKeyVariables, CreateWorkspaceError, CreateWorkspaceVariables, CursorNavigationOptions, DeleteBranchError, DeleteBranchPathParams, DeleteBranchVariables, DeleteColumnError, DeleteColumnPathParams, DeleteColumnVariables, DeleteDatabaseError, DeleteDatabasePathParams, DeleteDatabaseVariables, DeleteRecordError, DeleteRecordPathParams, DeleteRecordVariables, DeleteTableError, DeleteTablePathParams, DeleteTableVariables, DeleteUserAPIKeyError, DeleteUserAPIKeyPathParams, DeleteUserAPIKeyVariables, DeleteUserError, DeleteUserVariables, DeleteWorkspaceError, DeleteWorkspacePathParams, DeleteWorkspaceVariables, EditableData, ExecuteBranchMigrationPlanError, ExecuteBranchMigrationPlanPathParams, ExecuteBranchMigrationPlanRequestBody, ExecuteBranchMigrationPlanVariables, FetchImpl, FetcherExtraProps, GetBranchDetailsError, GetBranchDetailsPathParams, GetBranchDetailsVariables, GetBranchListError, GetBranchListPathParams, GetBranchListVariables, GetBranchMetadataError, GetBranchMetadataPathParams, GetBranchMetadataVariables, GetBranchMigrationHistoryError, GetBranchMigrationHistoryPathParams, GetBranchMigrationHistoryRequestBody, GetBranchMigrationHistoryResponse, GetBranchMigrationHistoryVariables, GetBranchMigrationPlanError, GetBranchMigrationPlanPathParams, GetBranchMigrationPlanVariables, GetBranchStatsError, GetBranchStatsPathParams, GetBranchStatsResponse, GetBranchStatsVariables, GetColumnError, GetColumnPathParams, GetColumnVariables, GetDatabaseListError, GetDatabaseListPathParams, GetDatabaseListVariables, GetGitBranchesMappingError, GetGitBranchesMappingPathParams, GetGitBranchesMappingVariables, GetRecordError, GetRecordPathParams, GetRecordRequestBody, GetRecordVariables, GetTableColumnsError, GetTableColumnsPathParams, GetTableColumnsResponse, GetTableColumnsVariables, GetTableSchemaError, GetTableSchemaPathParams, GetTableSchemaResponse, GetTableSchemaVariables, GetUserAPIKeysError, GetUserAPIKeysResponse, GetUserAPIKeysVariables, GetUserError, GetUserVariables, GetWorkspaceError, GetWorkspaceMembersListError, GetWorkspaceMembersListPathParams, GetWorkspaceMembersListVariables, GetWorkspacePathParams, GetWorkspaceVariables, GetWorkspacesListError, GetWorkspacesListResponse, GetWorkspacesListVariables, Identifiable, InsertRecordError, InsertRecordPathParams, InsertRecordResponse, InsertRecordVariables, InsertRecordWithIDError, InsertRecordWithIDPathParams, InsertRecordWithIDQueryParams, InsertRecordWithIDVariables, InviteWorkspaceMemberError, InviteWorkspaceMemberPathParams, InviteWorkspaceMemberRequestBody, InviteWorkspaceMemberVariables, OffsetNavigationOptions, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Paginable, PaginationQueryMeta, Query, QueryTableError, QueryTablePathParams, QueryTableRequestBody, QueryTableVariables, RemoveGitBranchesEntryError, RemoveGitBranchesEntryPathParams, RemoveGitBranchesEntryQueryParams, RemoveGitBranchesEntryVariables, RemoveWorkspaceMemberError, RemoveWorkspaceMemberPathParams, RemoveWorkspaceMemberVariables, Repository, ResendWorkspaceMemberInviteError, ResendWorkspaceMemberInvitePathParams, ResendWorkspaceMemberInviteVariables, ResolveBranchError, ResolveBranchPathParams, ResolveBranchQueryParams, ResolveBranchResponse, ResolveBranchVariables, responses as Responses, RestRepository, SchemaDefinition, SchemaPlugin, SchemaPluginResult, schemas as Schemas, SearchBranchError, SearchBranchPathParams, SearchBranchRequestBody, SearchBranchVariables, SearchOptions, SearchPlugin, SearchPluginResult, SelectableColumn, SelectedPick, SetTableSchemaError, SetTableSchemaPathParams, SetTableSchemaRequestBody, SetTableSchemaVariables, SimpleCache, SimpleCacheOptions, UpdateBranchMetadataError, UpdateBranchMetadataPathParams, UpdateBranchMetadataVariables, UpdateColumnError, UpdateColumnPathParams, UpdateColumnRequestBody, UpdateColumnVariables, UpdateRecordWithIDError, UpdateRecordWithIDPathParams, UpdateRecordWithIDQueryParams, UpdateRecordWithIDVariables, UpdateTableError, UpdateTablePathParams, UpdateTableRequestBody, UpdateTableVariables, UpdateUserError, UpdateUserVariables, UpdateWorkspaceError, UpdateWorkspaceMemberRoleError, UpdateWorkspaceMemberRolePathParams, UpdateWorkspaceMemberRoleRequestBody, UpdateWorkspaceMemberRoleVariables, UpdateWorkspacePathParams, UpdateWorkspaceVariables, UpsertRecordWithIDError, UpsertRecordWithIDPathParams, UpsertRecordWithIDQueryParams, UpsertRecordWithIDVariables, ValueAtColumn, XataApiClient, XataApiClientOptions, XataApiPlugin, XataError, XataPlugin, XataPluginOptions, XataRecord, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
3546
|
+
export { AcceptWorkspaceMemberInviteError, AcceptWorkspaceMemberInvitePathParams, AcceptWorkspaceMemberInviteVariables, AddGitBranchesEntryError, AddGitBranchesEntryPathParams, AddGitBranchesEntryRequestBody, AddGitBranchesEntryResponse, AddGitBranchesEntryVariables, AddTableColumnError, AddTableColumnPathParams, AddTableColumnVariables, BaseClient, BaseClientOptions, BaseData, BulkInsertTableRecordsError, BulkInsertTableRecordsPathParams, BulkInsertTableRecordsRequestBody, BulkInsertTableRecordsResponse, BulkInsertTableRecordsVariables, CacheImpl, CancelWorkspaceMemberInviteError, CancelWorkspaceMemberInvitePathParams, CancelWorkspaceMemberInviteVariables, ClientConstructor, CreateBranchError, CreateBranchPathParams, CreateBranchQueryParams, CreateBranchRequestBody, CreateBranchVariables, CreateDatabaseError, CreateDatabasePathParams, CreateDatabaseRequestBody, CreateDatabaseResponse, CreateDatabaseVariables, CreateTableError, CreateTablePathParams, CreateTableVariables, CreateUserAPIKeyError, CreateUserAPIKeyPathParams, CreateUserAPIKeyResponse, CreateUserAPIKeyVariables, CreateWorkspaceError, CreateWorkspaceVariables, CursorNavigationOptions, DeleteBranchError, DeleteBranchPathParams, DeleteBranchVariables, DeleteColumnError, DeleteColumnPathParams, DeleteColumnVariables, DeleteDatabaseError, DeleteDatabasePathParams, DeleteDatabaseVariables, DeleteRecordError, DeleteRecordPathParams, DeleteRecordVariables, DeleteTableError, DeleteTablePathParams, DeleteTableVariables, DeleteUserAPIKeyError, DeleteUserAPIKeyPathParams, DeleteUserAPIKeyVariables, DeleteUserError, DeleteUserVariables, DeleteWorkspaceError, DeleteWorkspacePathParams, DeleteWorkspaceVariables, EditableData, ExecuteBranchMigrationPlanError, ExecuteBranchMigrationPlanPathParams, ExecuteBranchMigrationPlanRequestBody, ExecuteBranchMigrationPlanVariables, FetchImpl, FetcherExtraProps, GetBranchDetailsError, GetBranchDetailsPathParams, GetBranchDetailsVariables, GetBranchListError, GetBranchListPathParams, GetBranchListVariables, GetBranchMetadataError, GetBranchMetadataPathParams, GetBranchMetadataVariables, GetBranchMigrationHistoryError, GetBranchMigrationHistoryPathParams, GetBranchMigrationHistoryRequestBody, GetBranchMigrationHistoryResponse, GetBranchMigrationHistoryVariables, GetBranchMigrationPlanError, GetBranchMigrationPlanPathParams, GetBranchMigrationPlanVariables, GetBranchStatsError, GetBranchStatsPathParams, GetBranchStatsResponse, GetBranchStatsVariables, GetColumnError, GetColumnPathParams, GetColumnVariables, GetDatabaseListError, GetDatabaseListPathParams, GetDatabaseListVariables, GetGitBranchesMappingError, GetGitBranchesMappingPathParams, GetGitBranchesMappingVariables, GetRecordError, GetRecordPathParams, GetRecordRequestBody, GetRecordVariables, GetTableColumnsError, GetTableColumnsPathParams, GetTableColumnsResponse, GetTableColumnsVariables, GetTableSchemaError, GetTableSchemaPathParams, GetTableSchemaResponse, GetTableSchemaVariables, GetUserAPIKeysError, GetUserAPIKeysResponse, GetUserAPIKeysVariables, GetUserError, GetUserVariables, GetWorkspaceError, GetWorkspaceMembersListError, GetWorkspaceMembersListPathParams, GetWorkspaceMembersListVariables, GetWorkspacePathParams, GetWorkspaceVariables, GetWorkspacesListError, GetWorkspacesListResponse, GetWorkspacesListVariables, Identifiable, InsertRecordError, InsertRecordPathParams, InsertRecordResponse, InsertRecordVariables, InsertRecordWithIDError, InsertRecordWithIDPathParams, InsertRecordWithIDQueryParams, InsertRecordWithIDVariables, InviteWorkspaceMemberError, InviteWorkspaceMemberPathParams, InviteWorkspaceMemberRequestBody, InviteWorkspaceMemberVariables, OffsetNavigationOptions, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Paginable, PaginationQueryMeta, Query, QueryTableError, QueryTablePathParams, QueryTableRequestBody, QueryTableVariables, RemoveGitBranchesEntryError, RemoveGitBranchesEntryPathParams, RemoveGitBranchesEntryQueryParams, RemoveGitBranchesEntryVariables, RemoveWorkspaceMemberError, RemoveWorkspaceMemberPathParams, RemoveWorkspaceMemberVariables, Repository, ResendWorkspaceMemberInviteError, ResendWorkspaceMemberInvitePathParams, ResendWorkspaceMemberInviteVariables, ResolveBranchError, ResolveBranchPathParams, ResolveBranchQueryParams, ResolveBranchResponse, ResolveBranchVariables, responses as Responses, RestRepository, SchemaDefinition, SchemaPlugin, SchemaPluginResult, schemas as Schemas, SearchBranchError, SearchBranchPathParams, SearchBranchRequestBody, SearchBranchVariables, SearchOptions, SearchPlugin, SearchPluginResult, SearchTableError, SearchTablePathParams, SearchTableRequestBody, SearchTableVariables, SelectableColumn, SelectedPick, SetTableSchemaError, SetTableSchemaPathParams, SetTableSchemaRequestBody, SetTableSchemaVariables, SimpleCache, SimpleCacheOptions, UpdateBranchMetadataError, UpdateBranchMetadataPathParams, UpdateBranchMetadataVariables, UpdateColumnError, UpdateColumnPathParams, UpdateColumnRequestBody, UpdateColumnVariables, UpdateRecordWithIDError, UpdateRecordWithIDPathParams, UpdateRecordWithIDQueryParams, UpdateRecordWithIDVariables, UpdateTableError, UpdateTablePathParams, UpdateTableRequestBody, UpdateTableVariables, UpdateUserError, UpdateUserVariables, UpdateWorkspaceError, UpdateWorkspaceMemberRoleError, UpdateWorkspaceMemberRolePathParams, UpdateWorkspaceMemberRoleRequestBody, UpdateWorkspaceMemberRoleVariables, UpdateWorkspacePathParams, UpdateWorkspaceVariables, UpsertRecordWithIDError, UpsertRecordWithIDPathParams, UpsertRecordWithIDQueryParams, UpsertRecordWithIDVariables, ValueAtColumn, XataApiClient, XataApiClientOptions, XataApiPlugin, XataError, XataPlugin, XataPluginOptions, XataRecord, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
package/dist/index.mjs
CHANGED
@@ -7,8 +7,11 @@ function compact(arr) {
|
|
7
7
|
function isObject(value) {
|
8
8
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
9
9
|
}
|
10
|
+
function isDefined(value) {
|
11
|
+
return value !== null && value !== void 0;
|
12
|
+
}
|
10
13
|
function isString(value) {
|
11
|
-
return value
|
14
|
+
return isDefined(value) && typeof value === "string";
|
12
15
|
}
|
13
16
|
function toBase64(value) {
|
14
17
|
try {
|
@@ -70,7 +73,12 @@ function getFetchImplementation(userFetch) {
|
|
70
73
|
return fetchImpl;
|
71
74
|
}
|
72
75
|
|
73
|
-
class
|
76
|
+
class ErrorWithCause extends Error {
|
77
|
+
constructor(message, options) {
|
78
|
+
super(message, options);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
class FetcherError extends ErrorWithCause {
|
74
82
|
constructor(status, data) {
|
75
83
|
super(getMessage(data));
|
76
84
|
this.status = status;
|
@@ -366,6 +374,11 @@ const queryTable = (variables) => fetch$1({
|
|
366
374
|
method: "post",
|
367
375
|
...variables
|
368
376
|
});
|
377
|
+
const searchTable = (variables) => fetch$1({
|
378
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
379
|
+
method: "post",
|
380
|
+
...variables
|
381
|
+
});
|
369
382
|
const searchBranch = (variables) => fetch$1({
|
370
383
|
url: "/db/{dbBranchName}/search",
|
371
384
|
method: "post",
|
@@ -429,6 +442,7 @@ const operationsByTag = {
|
|
429
442
|
getRecord,
|
430
443
|
bulkInsertTableRecords,
|
431
444
|
queryTable,
|
445
|
+
searchTable,
|
432
446
|
searchBranch
|
433
447
|
}
|
434
448
|
};
|
@@ -884,6 +898,13 @@ class RecordsApi {
|
|
884
898
|
...this.extraProps
|
885
899
|
});
|
886
900
|
}
|
901
|
+
searchTable(workspace, database, branch, tableName, query) {
|
902
|
+
return operationsByTag.records.searchTable({
|
903
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
904
|
+
body: query,
|
905
|
+
...this.extraProps
|
906
|
+
});
|
907
|
+
}
|
887
908
|
searchBranch(workspace, database, branch, query) {
|
888
909
|
return operationsByTag.records.searchBranch({
|
889
910
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -950,6 +971,9 @@ const PAGINATION_MAX_SIZE = 200;
|
|
950
971
|
const PAGINATION_DEFAULT_SIZE = 200;
|
951
972
|
const PAGINATION_MAX_OFFSET = 800;
|
952
973
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
974
|
+
function isCursorPaginationOptions(options) {
|
975
|
+
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
976
|
+
}
|
953
977
|
|
954
978
|
var __accessCheck$5 = (obj, member, msg) => {
|
955
979
|
if (!member.has(obj))
|
@@ -971,7 +995,7 @@ var __privateSet$4 = (obj, member, value, setter) => {
|
|
971
995
|
};
|
972
996
|
var _table$1, _repository, _data;
|
973
997
|
const _Query = class {
|
974
|
-
constructor(repository, table, data,
|
998
|
+
constructor(repository, table, data, rawParent) {
|
975
999
|
__privateAdd$5(this, _table$1, void 0);
|
976
1000
|
__privateAdd$5(this, _repository, void 0);
|
977
1001
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -983,6 +1007,7 @@ const _Query = class {
|
|
983
1007
|
} else {
|
984
1008
|
__privateSet$4(this, _repository, this);
|
985
1009
|
}
|
1010
|
+
const parent = cleanParent(data, rawParent);
|
986
1011
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
987
1012
|
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
988
1013
|
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
@@ -1054,13 +1079,13 @@ const _Query = class {
|
|
1054
1079
|
}
|
1055
1080
|
async *getIterator(options = {}) {
|
1056
1081
|
const { batchSize = 1 } = options;
|
1057
|
-
let
|
1058
|
-
let
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1082
|
+
let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
|
1083
|
+
let more = page.hasNextPage();
|
1084
|
+
yield page.records;
|
1085
|
+
while (more) {
|
1086
|
+
page = await page.nextPage();
|
1087
|
+
more = page.hasNextPage();
|
1088
|
+
yield page.records;
|
1064
1089
|
}
|
1065
1090
|
}
|
1066
1091
|
async getMany(options = {}) {
|
@@ -1077,7 +1102,7 @@ const _Query = class {
|
|
1077
1102
|
}
|
1078
1103
|
async getFirst(options = {}) {
|
1079
1104
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1080
|
-
return records[0]
|
1105
|
+
return records[0] ?? null;
|
1081
1106
|
}
|
1082
1107
|
cache(ttl) {
|
1083
1108
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
@@ -1102,6 +1127,12 @@ let Query = _Query;
|
|
1102
1127
|
_table$1 = new WeakMap();
|
1103
1128
|
_repository = new WeakMap();
|
1104
1129
|
_data = new WeakMap();
|
1130
|
+
function cleanParent(data, parent) {
|
1131
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
1132
|
+
return { ...parent, sorting: void 0, filter: void 0 };
|
1133
|
+
}
|
1134
|
+
return parent;
|
1135
|
+
}
|
1105
1136
|
|
1106
1137
|
function isIdentifiable(x) {
|
1107
1138
|
return isObject(x) && isString(x?.id);
|
@@ -1292,9 +1323,13 @@ class RestRepository extends Query {
|
|
1292
1323
|
}
|
1293
1324
|
async search(query, options = {}) {
|
1294
1325
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1295
|
-
const { records } = await
|
1296
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1297
|
-
body: {
|
1326
|
+
const { records } = await searchTable({
|
1327
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1328
|
+
body: {
|
1329
|
+
query,
|
1330
|
+
fuzziness: options.fuzziness,
|
1331
|
+
filter: options.filter
|
1332
|
+
},
|
1298
1333
|
...fetchProps
|
1299
1334
|
});
|
1300
1335
|
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
@@ -1307,7 +1342,7 @@ class RestRepository extends Query {
|
|
1307
1342
|
const data = query.getQueryOptions();
|
1308
1343
|
const body = {
|
1309
1344
|
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1310
|
-
sort: data.sort ? buildSortFilter(data.sort) : void 0,
|
1345
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1311
1346
|
page: data.pagination,
|
1312
1347
|
columns: data.columns
|
1313
1348
|
};
|
@@ -1497,7 +1532,7 @@ const initObject = (db, schema, table, object) => {
|
|
1497
1532
|
const linkTable = column.link?.table;
|
1498
1533
|
if (!linkTable) {
|
1499
1534
|
console.error(`Failed to parse link for field ${column.name}`);
|
1500
|
-
} else if (
|
1535
|
+
} else if (isObject(value)) {
|
1501
1536
|
result[column.name] = initObject(db, schema, linkTable, value);
|
1502
1537
|
}
|
1503
1538
|
break;
|
@@ -1623,7 +1658,7 @@ class SchemaPlugin extends XataPlugin {
|
|
1623
1658
|
get: (_target, table) => {
|
1624
1659
|
if (!isString(table))
|
1625
1660
|
throw new Error("Invalid table name");
|
1626
|
-
if (
|
1661
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1627
1662
|
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
|
1628
1663
|
}
|
1629
1664
|
return __privateGet$2(this, _tables)[table];
|
@@ -1726,30 +1761,39 @@ const envBranchNames = [
|
|
1726
1761
|
"CF_PAGES_BRANCH",
|
1727
1762
|
"BRANCH"
|
1728
1763
|
];
|
1729
|
-
const defaultBranch = "main";
|
1730
1764
|
async function getCurrentBranchName(options) {
|
1731
1765
|
const env = getBranchByEnvVariable();
|
1732
|
-
if (env)
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
return defaultBranch;
|
1766
|
+
if (env) {
|
1767
|
+
const details = await getDatabaseBranch(env, options);
|
1768
|
+
if (details)
|
1769
|
+
return env;
|
1770
|
+
console.warn(`Branch ${env} not found in Xata. Ignoring...`);
|
1771
|
+
}
|
1772
|
+
const gitBranch = await getGitBranch();
|
1773
|
+
return resolveXataBranch(gitBranch, options);
|
1741
1774
|
}
|
1742
1775
|
async function getCurrentBranchDetails(options) {
|
1743
|
-
const
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1776
|
+
const branch = await getCurrentBranchName(options);
|
1777
|
+
return getDatabaseBranch(branch, options);
|
1778
|
+
}
|
1779
|
+
async function resolveXataBranch(gitBranch, options) {
|
1780
|
+
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1781
|
+
const apiKey = options?.apiKey || getAPIKey();
|
1782
|
+
if (!databaseURL)
|
1783
|
+
throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
|
1784
|
+
if (!apiKey)
|
1785
|
+
throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
|
1786
|
+
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1787
|
+
const [workspace] = host.split(".");
|
1788
|
+
const { branch } = await resolveBranch({
|
1789
|
+
apiKey,
|
1790
|
+
apiUrl: databaseURL,
|
1791
|
+
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1792
|
+
workspacesApiUrl: `${protocol}//${host}`,
|
1793
|
+
pathParams: { dbName, workspace },
|
1794
|
+
queryParams: { gitBranch, fallbackBranch: getEnvVariable("XATA_FALLBACK_BRANCH") }
|
1795
|
+
});
|
1796
|
+
return branch;
|
1753
1797
|
}
|
1754
1798
|
async function getDatabaseBranch(branch, options) {
|
1755
1799
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
@@ -1838,7 +1882,7 @@ const buildClient = (plugins) => {
|
|
1838
1882
|
this.db = db;
|
1839
1883
|
this.search = search;
|
1840
1884
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
1841
|
-
if (
|
1885
|
+
if (namespace === void 0)
|
1842
1886
|
continue;
|
1843
1887
|
const result = namespace.build(pluginOptions);
|
1844
1888
|
if (result instanceof Promise) {
|
@@ -1855,7 +1899,7 @@ const buildClient = (plugins) => {
|
|
1855
1899
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1856
1900
|
const apiKey = options?.apiKey || getAPIKey();
|
1857
1901
|
const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
|
1858
|
-
const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1902
|
+
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1859
1903
|
if (!databaseURL || !apiKey) {
|
1860
1904
|
throw new Error("Options databaseURL and apiKey are required");
|
1861
1905
|
}
|
@@ -1882,7 +1926,7 @@ const buildClient = (plugins) => {
|
|
1882
1926
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
1883
1927
|
if (__privateGet(this, _branch))
|
1884
1928
|
return __privateGet(this, _branch);
|
1885
|
-
if (
|
1929
|
+
if (param === void 0)
|
1886
1930
|
return void 0;
|
1887
1931
|
const strategies = Array.isArray(param) ? [...param] : [param];
|
1888
1932
|
const evaluateBranch = async (strategy) => {
|
@@ -1907,5 +1951,5 @@ class XataError extends Error {
|
|
1907
1951
|
}
|
1908
1952
|
}
|
1909
1953
|
|
1910
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
1954
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
1911
1955
|
//# sourceMappingURL=index.mjs.map
|