@xata.io/client 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/index.cjs +154 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +133 -11
- package/dist/index.mjs +150 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -122,16 +122,20 @@ declare type WorkspaceMembers = {
|
|
122
122
|
* @pattern ^ik_[a-zA-Z0-9]+
|
123
123
|
*/
|
124
124
|
declare type InviteKey = string;
|
125
|
+
/**
|
126
|
+
* Metadata of databases
|
127
|
+
*/
|
128
|
+
declare type DatabaseMetadata = {
|
129
|
+
name: string;
|
130
|
+
displayName: string;
|
131
|
+
createdAt: DateTime;
|
132
|
+
numberOfBranches: number;
|
133
|
+
ui?: {
|
134
|
+
color?: string;
|
135
|
+
};
|
136
|
+
};
|
125
137
|
declare type ListDatabasesResponse = {
|
126
|
-
databases?:
|
127
|
-
name: string;
|
128
|
-
displayName: string;
|
129
|
-
createdAt: DateTime;
|
130
|
-
numberOfBranches: number;
|
131
|
-
ui?: {
|
132
|
-
color?: string;
|
133
|
-
};
|
134
|
-
}[];
|
138
|
+
databases?: DatabaseMetadata[];
|
135
139
|
};
|
136
140
|
declare type ListBranchesResponse = {
|
137
141
|
databaseName: string;
|
@@ -453,6 +457,7 @@ type schemas_InviteID = InviteID;
|
|
453
457
|
type schemas_WorkspaceInvite = WorkspaceInvite;
|
454
458
|
type schemas_WorkspaceMembers = WorkspaceMembers;
|
455
459
|
type schemas_InviteKey = InviteKey;
|
460
|
+
type schemas_DatabaseMetadata = DatabaseMetadata;
|
456
461
|
type schemas_ListDatabasesResponse = ListDatabasesResponse;
|
457
462
|
type schemas_ListBranchesResponse = ListBranchesResponse;
|
458
463
|
type schemas_ListGitBranchesResponse = ListGitBranchesResponse;
|
@@ -511,6 +516,7 @@ declare namespace schemas {
|
|
511
516
|
schemas_WorkspaceInvite as WorkspaceInvite,
|
512
517
|
schemas_WorkspaceMembers as WorkspaceMembers,
|
513
518
|
schemas_InviteKey as InviteKey,
|
519
|
+
schemas_DatabaseMetadata as DatabaseMetadata,
|
514
520
|
schemas_ListDatabasesResponse as ListDatabasesResponse,
|
515
521
|
schemas_ListBranchesResponse as ListBranchesResponse,
|
516
522
|
schemas_ListGitBranchesResponse as ListGitBranchesResponse,
|
@@ -1139,6 +1145,27 @@ declare type DeleteDatabaseVariables = {
|
|
1139
1145
|
* Delete a database and all of its branches and tables permanently.
|
1140
1146
|
*/
|
1141
1147
|
declare const deleteDatabase: (variables: DeleteDatabaseVariables) => Promise<undefined>;
|
1148
|
+
declare type GetDatabaseMetadataPathParams = {
|
1149
|
+
dbName: DBName;
|
1150
|
+
workspace: string;
|
1151
|
+
};
|
1152
|
+
declare type GetDatabaseMetadataError = ErrorWrapper<{
|
1153
|
+
status: 400;
|
1154
|
+
payload: BadRequestError;
|
1155
|
+
} | {
|
1156
|
+
status: 401;
|
1157
|
+
payload: AuthError;
|
1158
|
+
} | {
|
1159
|
+
status: 404;
|
1160
|
+
payload: SimpleError;
|
1161
|
+
}>;
|
1162
|
+
declare type GetDatabaseMetadataVariables = {
|
1163
|
+
pathParams: GetDatabaseMetadataPathParams;
|
1164
|
+
} & FetcherExtraProps;
|
1165
|
+
/**
|
1166
|
+
* Retrieve metadata of the given database
|
1167
|
+
*/
|
1168
|
+
declare const getDatabaseMetadata: (variables: GetDatabaseMetadataVariables) => Promise<DatabaseMetadata>;
|
1142
1169
|
declare type GetGitBranchesMappingPathParams = {
|
1143
1170
|
dbName: DBName;
|
1144
1171
|
workspace: string;
|
@@ -2813,6 +2840,7 @@ declare const operationsByTag: {
|
|
2813
2840
|
getDatabaseList: (variables: GetDatabaseListVariables) => Promise<ListDatabasesResponse>;
|
2814
2841
|
createDatabase: (variables: CreateDatabaseVariables) => Promise<CreateDatabaseResponse>;
|
2815
2842
|
deleteDatabase: (variables: DeleteDatabaseVariables) => Promise<undefined>;
|
2843
|
+
getDatabaseMetadata: (variables: GetDatabaseMetadataVariables) => Promise<DatabaseMetadata>;
|
2816
2844
|
getGitBranchesMapping: (variables: GetGitBranchesMappingVariables) => Promise<ListGitBranchesResponse>;
|
2817
2845
|
addGitBranchesEntry: (variables: AddGitBranchesEntryVariables) => Promise<AddGitBranchesEntryResponse>;
|
2818
2846
|
removeGitBranchesEntry: (variables: RemoveGitBranchesEntryVariables) => Promise<undefined>;
|
@@ -2914,6 +2942,7 @@ declare class DatabaseApi {
|
|
2914
2942
|
getDatabaseList(workspace: WorkspaceID): Promise<ListDatabasesResponse>;
|
2915
2943
|
createDatabase(workspace: WorkspaceID, dbName: DBName, options?: CreateDatabaseRequestBody): Promise<CreateDatabaseResponse>;
|
2916
2944
|
deleteDatabase(workspace: WorkspaceID, dbName: DBName): Promise<void>;
|
2945
|
+
getDatabaseMetadata(workspace: WorkspaceID, dbName: DBName): Promise<DatabaseMetadata>;
|
2917
2946
|
getGitBranchesMapping(workspace: WorkspaceID, dbName: DBName): Promise<ListGitBranchesResponse>;
|
2918
2947
|
addGitBranchesEntry(workspace: WorkspaceID, dbName: DBName, body: AddGitBranchesEntryRequestBody): Promise<AddGitBranchesEntryResponse>;
|
2919
2948
|
removeGitBranchesEntry(workspace: WorkspaceID, dbName: DBName, gitBranch: string): Promise<void>;
|
@@ -3846,7 +3875,6 @@ declare abstract class Repository<Data extends BaseData, Record extends XataReco
|
|
3846
3875
|
}
|
3847
3876
|
declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> implements Repository<Data, Record> {
|
3848
3877
|
#private;
|
3849
|
-
db: SchemaPluginResult<any>;
|
3850
3878
|
constructor(options: {
|
3851
3879
|
table: string;
|
3852
3880
|
db: SchemaPluginResult<any>;
|
@@ -4049,12 +4077,26 @@ interface ClientConstructor<Plugins extends Record<string, XataPlugin>> {
|
|
4049
4077
|
search: Awaited<ReturnType<SearchPlugin<SchemaInference<NonNullable<typeof schemaTables>>>['build']>>;
|
4050
4078
|
}, keyof Plugins> & {
|
4051
4079
|
[Key in StringKeys<NonNullable<Plugins>>]: Awaited<ReturnType<NonNullable<Plugins>[Key]['build']>>;
|
4080
|
+
} & {
|
4081
|
+
getConfig(): Promise<{
|
4082
|
+
databaseURL: string;
|
4083
|
+
branch: string;
|
4084
|
+
}>;
|
4052
4085
|
};
|
4053
4086
|
}
|
4054
4087
|
declare const BaseClient_base: ClientConstructor<{}>;
|
4055
4088
|
declare class BaseClient extends BaseClient_base<[]> {
|
4056
4089
|
}
|
4057
4090
|
|
4091
|
+
declare class Serializer {
|
4092
|
+
classes: Record<string, any>;
|
4093
|
+
add(clazz: any): void;
|
4094
|
+
toJSON<T>(data: T): string;
|
4095
|
+
fromJSON<T>(json: string): T;
|
4096
|
+
}
|
4097
|
+
declare const serialize: <T>(data: T) => string;
|
4098
|
+
declare const deserialize: <T>(json: string) => T;
|
4099
|
+
|
4058
4100
|
declare type BranchResolutionOptions = {
|
4059
4101
|
databaseURL?: string;
|
4060
4102
|
apiKey?: string;
|
@@ -4066,9 +4108,89 @@ declare function getDatabaseURL(): string | undefined;
|
|
4066
4108
|
|
4067
4109
|
declare function getAPIKey(): string | undefined;
|
4068
4110
|
|
4111
|
+
interface Body {
|
4112
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
4113
|
+
blob(): Promise<Blob>;
|
4114
|
+
formData(): Promise<FormData>;
|
4115
|
+
json(): Promise<any>;
|
4116
|
+
text(): Promise<string>;
|
4117
|
+
}
|
4118
|
+
interface Blob {
|
4119
|
+
readonly size: number;
|
4120
|
+
readonly type: string;
|
4121
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
4122
|
+
slice(start?: number, end?: number, contentType?: string): Blob;
|
4123
|
+
text(): Promise<string>;
|
4124
|
+
}
|
4125
|
+
/** Provides information about files and allows JavaScript in a web page to access their content. */
|
4126
|
+
interface File extends Blob {
|
4127
|
+
readonly lastModified: number;
|
4128
|
+
readonly name: string;
|
4129
|
+
readonly webkitRelativePath: string;
|
4130
|
+
}
|
4131
|
+
declare type FormDataEntryValue = File | string;
|
4132
|
+
/** Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data". */
|
4133
|
+
interface FormData {
|
4134
|
+
append(name: string, value: string | Blob, fileName?: string): void;
|
4135
|
+
delete(name: string): void;
|
4136
|
+
get(name: string): FormDataEntryValue | null;
|
4137
|
+
getAll(name: string): FormDataEntryValue[];
|
4138
|
+
has(name: string): boolean;
|
4139
|
+
set(name: string, value: string | Blob, fileName?: string): void;
|
4140
|
+
forEach(callbackfn: (value: FormDataEntryValue, key: string, parent: FormData) => void, thisArg?: any): void;
|
4141
|
+
}
|
4142
|
+
/** This Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs. You can add to this using methods like append() (see Examples.) In all methods of this interface, header names are matched by case-insensitive byte sequence. */
|
4143
|
+
interface Headers {
|
4144
|
+
append(name: string, value: string): void;
|
4145
|
+
delete(name: string): void;
|
4146
|
+
get(name: string): string | null;
|
4147
|
+
has(name: string): boolean;
|
4148
|
+
set(name: string, value: string): void;
|
4149
|
+
forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void;
|
4150
|
+
}
|
4151
|
+
interface Request extends Body {
|
4152
|
+
/** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
|
4153
|
+
readonly cache: 'default' | 'force-cache' | 'no-cache' | 'no-store' | 'only-if-cached' | 'reload';
|
4154
|
+
/** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
|
4155
|
+
readonly credentials: 'include' | 'omit' | 'same-origin';
|
4156
|
+
/** Returns the kind of resource requested by request, e.g., "document" or "script". */
|
4157
|
+
readonly destination: '' | 'audio' | 'audioworklet' | 'document' | 'embed' | 'font' | 'frame' | 'iframe' | 'image' | 'manifest' | 'object' | 'paintworklet' | 'report' | 'script' | 'sharedworker' | 'style' | 'track' | 'video' | 'worker' | 'xslt';
|
4158
|
+
/** Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. */
|
4159
|
+
readonly headers: Headers;
|
4160
|
+
/** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
|
4161
|
+
readonly integrity: string;
|
4162
|
+
/** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
|
4163
|
+
readonly keepalive: boolean;
|
4164
|
+
/** Returns request's HTTP method, which is "GET" by default. */
|
4165
|
+
readonly method: string;
|
4166
|
+
/** Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. */
|
4167
|
+
readonly mode: 'cors' | 'navigate' | 'no-cors' | 'same-origin';
|
4168
|
+
/** Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. */
|
4169
|
+
readonly redirect: 'error' | 'follow' | 'manual';
|
4170
|
+
/** Returns the referrer of request. Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default. This is used during fetching to determine the value of the `Referer` header of the request being made. */
|
4171
|
+
readonly referrer: string;
|
4172
|
+
/** Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. */
|
4173
|
+
readonly referrerPolicy: '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
|
4174
|
+
/** Returns the URL of request as a string. */
|
4175
|
+
readonly url: string;
|
4176
|
+
clone(): Request;
|
4177
|
+
}
|
4178
|
+
|
4179
|
+
declare type XataWorkerContext<XataClient> = {
|
4180
|
+
xata: XataClient;
|
4181
|
+
request: Request;
|
4182
|
+
env: Record<string, string | undefined>;
|
4183
|
+
};
|
4184
|
+
declare type RemoveFirst<T> = T extends [any, ...infer U] ? U : never;
|
4185
|
+
declare type WorkerRunnerConfig = {
|
4186
|
+
workspace: string;
|
4187
|
+
worker: string;
|
4188
|
+
};
|
4189
|
+
declare function buildWorkerRunner<XataClient>(config: WorkerRunnerConfig): <WorkerFunction extends (ctx: XataWorkerContext<XataClient>, ...args: any[]) => any>(name: string, _worker: WorkerFunction) => (...args: RemoveFirst<Parameters<WorkerFunction>>) => Promise<Awaited<ReturnType<WorkerFunction>>>;
|
4190
|
+
|
4069
4191
|
declare class XataError extends Error {
|
4070
4192
|
readonly status: number;
|
4071
4193
|
constructor(message: string, status: number);
|
4072
4194
|
}
|
4073
4195
|
|
4074
|
-
export { AcceptWorkspaceMemberInviteError, AcceptWorkspaceMemberInvitePathParams, AcceptWorkspaceMemberInviteVariables, AddGitBranchesEntryError, AddGitBranchesEntryPathParams, AddGitBranchesEntryRequestBody, AddGitBranchesEntryResponse, AddGitBranchesEntryVariables, AddTableColumnError, AddTableColumnPathParams, AddTableColumnVariables, BaseClient, BaseClientOptions, BaseData, BaseSchema, BulkInsertTableRecordsError, BulkInsertTableRecordsPathParams, BulkInsertTableRecordsQueryParams, BulkInsertTableRecordsRequestBody, BulkInsertTableRecordsVariables, CacheImpl, CancelWorkspaceMemberInviteError, CancelWorkspaceMemberInvitePathParams, CancelWorkspaceMemberInviteVariables, ClientConstructor, CreateBranchError, CreateBranchPathParams, CreateBranchQueryParams, CreateBranchRequestBody, CreateBranchResponse, CreateBranchVariables, CreateDatabaseError, CreateDatabasePathParams, CreateDatabaseRequestBody, CreateDatabaseResponse, CreateDatabaseVariables, CreateTableError, CreateTablePathParams, CreateTableResponse, CreateTableVariables, CreateUserAPIKeyError, CreateUserAPIKeyPathParams, CreateUserAPIKeyResponse, CreateUserAPIKeyVariables, CreateWorkspaceError, CreateWorkspaceVariables, CursorNavigationOptions, DeleteBranchError, DeleteBranchPathParams, DeleteBranchVariables, DeleteColumnError, DeleteColumnPathParams, DeleteColumnVariables, DeleteDatabaseError, DeleteDatabasePathParams, DeleteDatabaseVariables, DeleteRecordError, DeleteRecordPathParams, DeleteRecordQueryParams, 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, GetRecordQueryParams, 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, InsertRecordQueryParams, InsertRecordVariables, InsertRecordWithIDError, InsertRecordWithIDPathParams, InsertRecordWithIDQueryParams, InsertRecordWithIDVariables, InviteWorkspaceMemberError, InviteWorkspaceMemberPathParams, InviteWorkspaceMemberRequestBody, InviteWorkspaceMemberVariables, Link, OffsetNavigationOptions, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Paginable, PaginationQueryMeta, Query, QueryTableError, QueryTablePathParams, QueryTableRequestBody, QueryTableVariables, RecordArray, RemoveGitBranchesEntryError, RemoveGitBranchesEntryPathParams, RemoveGitBranchesEntryQueryParams, RemoveGitBranchesEntryVariables, RemoveWorkspaceMemberError, RemoveWorkspaceMemberPathParams, RemoveWorkspaceMemberVariables, Repository, ResendWorkspaceMemberInviteError, ResendWorkspaceMemberInvitePathParams, ResendWorkspaceMemberInviteVariables, ResolveBranchError, ResolveBranchPathParams, ResolveBranchQueryParams, ResolveBranchResponse, ResolveBranchVariables, responses as Responses, RestRepository, SchemaDefinition, SchemaInference, SchemaPlugin, SchemaPluginResult, schemas as Schemas, SearchBranchError, SearchBranchPathParams, SearchBranchRequestBody, SearchBranchVariables, SearchOptions, SearchPlugin, SearchPluginResult, SearchTableError, SearchTablePathParams, SearchTableRequestBody, SearchTableVariables, SearchXataRecord, 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, UpdateWorkspaceMemberInviteError, UpdateWorkspaceMemberInvitePathParams, UpdateWorkspaceMemberInviteRequestBody, UpdateWorkspaceMemberInviteVariables, 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, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
4196
|
+
export { AcceptWorkspaceMemberInviteError, AcceptWorkspaceMemberInvitePathParams, AcceptWorkspaceMemberInviteVariables, AddGitBranchesEntryError, AddGitBranchesEntryPathParams, AddGitBranchesEntryRequestBody, AddGitBranchesEntryResponse, AddGitBranchesEntryVariables, AddTableColumnError, AddTableColumnPathParams, AddTableColumnVariables, BaseClient, BaseClientOptions, BaseData, BaseSchema, BulkInsertTableRecordsError, BulkInsertTableRecordsPathParams, BulkInsertTableRecordsQueryParams, BulkInsertTableRecordsRequestBody, BulkInsertTableRecordsVariables, CacheImpl, CancelWorkspaceMemberInviteError, CancelWorkspaceMemberInvitePathParams, CancelWorkspaceMemberInviteVariables, ClientConstructor, CreateBranchError, CreateBranchPathParams, CreateBranchQueryParams, CreateBranchRequestBody, CreateBranchResponse, CreateBranchVariables, CreateDatabaseError, CreateDatabasePathParams, CreateDatabaseRequestBody, CreateDatabaseResponse, CreateDatabaseVariables, CreateTableError, CreateTablePathParams, CreateTableResponse, CreateTableVariables, CreateUserAPIKeyError, CreateUserAPIKeyPathParams, CreateUserAPIKeyResponse, CreateUserAPIKeyVariables, CreateWorkspaceError, CreateWorkspaceVariables, CursorNavigationOptions, DeleteBranchError, DeleteBranchPathParams, DeleteBranchVariables, DeleteColumnError, DeleteColumnPathParams, DeleteColumnVariables, DeleteDatabaseError, DeleteDatabasePathParams, DeleteDatabaseVariables, DeleteRecordError, DeleteRecordPathParams, DeleteRecordQueryParams, 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, GetDatabaseMetadataError, GetDatabaseMetadataPathParams, GetDatabaseMetadataVariables, GetGitBranchesMappingError, GetGitBranchesMappingPathParams, GetGitBranchesMappingVariables, GetRecordError, GetRecordPathParams, GetRecordQueryParams, 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, InsertRecordQueryParams, InsertRecordVariables, InsertRecordWithIDError, InsertRecordWithIDPathParams, InsertRecordWithIDQueryParams, InsertRecordWithIDVariables, InviteWorkspaceMemberError, InviteWorkspaceMemberPathParams, InviteWorkspaceMemberRequestBody, InviteWorkspaceMemberVariables, Link, OffsetNavigationOptions, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Paginable, PaginationQueryMeta, Query, QueryTableError, QueryTablePathParams, QueryTableRequestBody, QueryTableVariables, RecordArray, RemoveGitBranchesEntryError, RemoveGitBranchesEntryPathParams, RemoveGitBranchesEntryQueryParams, RemoveGitBranchesEntryVariables, RemoveWorkspaceMemberError, RemoveWorkspaceMemberPathParams, RemoveWorkspaceMemberVariables, Repository, ResendWorkspaceMemberInviteError, ResendWorkspaceMemberInvitePathParams, ResendWorkspaceMemberInviteVariables, ResolveBranchError, ResolveBranchPathParams, ResolveBranchQueryParams, ResolveBranchResponse, ResolveBranchVariables, responses as Responses, RestRepository, SchemaDefinition, SchemaInference, SchemaPlugin, SchemaPluginResult, schemas as Schemas, SearchBranchError, SearchBranchPathParams, SearchBranchRequestBody, SearchBranchVariables, SearchOptions, SearchPlugin, SearchPluginResult, SearchTableError, SearchTablePathParams, SearchTableRequestBody, SearchTableVariables, SearchXataRecord, SelectableColumn, SelectedPick, Serializer, SetTableSchemaError, SetTableSchemaPathParams, SetTableSchemaRequestBody, SetTableSchemaVariables, SimpleCache, SimpleCacheOptions, UpdateBranchMetadataError, UpdateBranchMetadataPathParams, UpdateBranchMetadataVariables, UpdateColumnError, UpdateColumnPathParams, UpdateColumnRequestBody, UpdateColumnVariables, UpdateRecordWithIDError, UpdateRecordWithIDPathParams, UpdateRecordWithIDQueryParams, UpdateRecordWithIDVariables, UpdateTableError, UpdateTablePathParams, UpdateTableRequestBody, UpdateTableVariables, UpdateUserError, UpdateUserVariables, UpdateWorkspaceError, UpdateWorkspaceMemberInviteError, UpdateWorkspaceMemberInvitePathParams, UpdateWorkspaceMemberInviteRequestBody, UpdateWorkspaceMemberInviteVariables, UpdateWorkspaceMemberRoleError, UpdateWorkspaceMemberRolePathParams, UpdateWorkspaceMemberRoleRequestBody, UpdateWorkspaceMemberRoleVariables, UpdateWorkspacePathParams, UpdateWorkspaceVariables, UpsertRecordWithIDError, UpsertRecordWithIDPathParams, UpsertRecordWithIDQueryParams, UpsertRecordWithIDVariables, ValueAtColumn, XataApiClient, XataApiClientOptions, XataApiPlugin, XataError, XataPlugin, XataPluginOptions, XataRecord, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
package/dist/index.mjs
CHANGED
@@ -121,12 +121,14 @@ function getFetchImplementation(userFetch) {
|
|
121
121
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
122
122
|
const fetchImpl = userFetch ?? globalFetch;
|
123
123
|
if (!fetchImpl) {
|
124
|
-
throw new Error(
|
124
|
+
throw new Error(
|
125
|
+
`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
|
126
|
+
);
|
125
127
|
}
|
126
128
|
return fetchImpl;
|
127
129
|
}
|
128
130
|
|
129
|
-
const VERSION = "0.16.
|
131
|
+
const VERSION = "0.16.1";
|
130
132
|
|
131
133
|
class ErrorWithCause extends Error {
|
132
134
|
constructor(message, options) {
|
@@ -327,6 +329,11 @@ const deleteDatabase = (variables) => fetch$1({
|
|
327
329
|
method: "delete",
|
328
330
|
...variables
|
329
331
|
});
|
332
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
333
|
+
url: "/dbs/{dbName}/metadata",
|
334
|
+
method: "get",
|
335
|
+
...variables
|
336
|
+
});
|
330
337
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
331
338
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
332
339
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -465,6 +472,7 @@ const operationsByTag = {
|
|
465
472
|
getDatabaseList,
|
466
473
|
createDatabase,
|
467
474
|
deleteDatabase,
|
475
|
+
getDatabaseMetadata,
|
468
476
|
getGitBranchesMapping,
|
469
477
|
addGitBranchesEntry,
|
470
478
|
removeGitBranchesEntry,
|
@@ -737,6 +745,12 @@ class DatabaseApi {
|
|
737
745
|
...this.extraProps
|
738
746
|
});
|
739
747
|
}
|
748
|
+
getDatabaseMetadata(workspace, dbName) {
|
749
|
+
return operationsByTag.database.getDatabaseMetadata({
|
750
|
+
pathParams: { workspace, dbName },
|
751
|
+
...this.extraProps
|
752
|
+
});
|
753
|
+
}
|
740
754
|
getGitBranchesMapping(workspace, dbName) {
|
741
755
|
return operationsByTag.database.getGitBranchesMapping({
|
742
756
|
pathParams: { workspace, dbName },
|
@@ -1182,7 +1196,12 @@ const _Query = class {
|
|
1182
1196
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1183
1197
|
}
|
1184
1198
|
select(columns) {
|
1185
|
-
return new _Query(
|
1199
|
+
return new _Query(
|
1200
|
+
__privateGet$5(this, _repository),
|
1201
|
+
__privateGet$5(this, _table$1),
|
1202
|
+
{ columns },
|
1203
|
+
__privateGet$5(this, _data)
|
1204
|
+
);
|
1186
1205
|
}
|
1187
1206
|
getPaginated(options = {}) {
|
1188
1207
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1307,7 +1326,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1307
1326
|
__accessCheck$4(obj, member, "access private method");
|
1308
1327
|
return method;
|
1309
1328
|
};
|
1310
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1329
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1311
1330
|
class Repository extends Query {
|
1312
1331
|
}
|
1313
1332
|
class RestRepository extends Query {
|
@@ -1324,11 +1343,12 @@ class RestRepository extends Query {
|
|
1324
1343
|
__privateAdd$4(this, _getSchemaTables$1);
|
1325
1344
|
__privateAdd$4(this, _table, void 0);
|
1326
1345
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1346
|
+
__privateAdd$4(this, _db, void 0);
|
1327
1347
|
__privateAdd$4(this, _cache, void 0);
|
1328
1348
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1329
1349
|
__privateSet$4(this, _table, options.table);
|
1330
1350
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1331
|
-
this
|
1351
|
+
__privateSet$4(this, _db, options.db);
|
1332
1352
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1333
1353
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1334
1354
|
}
|
@@ -1380,7 +1400,7 @@ class RestRepository extends Query {
|
|
1380
1400
|
...fetchProps
|
1381
1401
|
});
|
1382
1402
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1383
|
-
return initObject(this
|
1403
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1384
1404
|
} catch (e) {
|
1385
1405
|
if (isObject(e) && e.status === 404) {
|
1386
1406
|
return null;
|
@@ -1465,7 +1485,7 @@ class RestRepository extends Query {
|
|
1465
1485
|
...fetchProps
|
1466
1486
|
});
|
1467
1487
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1468
|
-
return records.map((item) => initObject(this
|
1488
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1469
1489
|
}
|
1470
1490
|
async query(query) {
|
1471
1491
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
@@ -1485,13 +1505,14 @@ class RestRepository extends Query {
|
|
1485
1505
|
...fetchProps
|
1486
1506
|
});
|
1487
1507
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1488
|
-
const records = objects.map((record) => initObject(this
|
1508
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1489
1509
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1490
1510
|
return new Page(query, meta, records);
|
1491
1511
|
}
|
1492
1512
|
}
|
1493
1513
|
_table = new WeakMap();
|
1494
1514
|
_getFetchProps = new WeakMap();
|
1515
|
+
_db = new WeakMap();
|
1495
1516
|
_cache = new WeakMap();
|
1496
1517
|
_schemaTables$2 = new WeakMap();
|
1497
1518
|
_insertRecordWithoutId = new WeakSet();
|
@@ -1509,7 +1530,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1509
1530
|
...fetchProps
|
1510
1531
|
});
|
1511
1532
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1512
|
-
return initObject(this
|
1533
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1513
1534
|
};
|
1514
1535
|
_insertRecordWithId = new WeakSet();
|
1515
1536
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1527,7 +1548,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1527
1548
|
...fetchProps
|
1528
1549
|
});
|
1529
1550
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1530
|
-
return initObject(this
|
1551
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1531
1552
|
};
|
1532
1553
|
_bulkInsertTableRecords = new WeakSet();
|
1533
1554
|
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
@@ -1543,7 +1564,7 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1543
1564
|
throw new Error("Request included columns but server didn't include them");
|
1544
1565
|
}
|
1545
1566
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1546
|
-
return response.records?.map((item) => initObject(this
|
1567
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1547
1568
|
};
|
1548
1569
|
_updateRecordWithID = new WeakSet();
|
1549
1570
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1556,7 +1577,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1556
1577
|
...fetchProps
|
1557
1578
|
});
|
1558
1579
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1559
|
-
return initObject(this
|
1580
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1560
1581
|
};
|
1561
1582
|
_upsertRecordWithID = new WeakSet();
|
1562
1583
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1568,7 +1589,7 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1568
1589
|
...fetchProps
|
1569
1590
|
});
|
1570
1591
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1571
|
-
return initObject(this
|
1592
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1572
1593
|
};
|
1573
1594
|
_deleteRecord = new WeakSet();
|
1574
1595
|
deleteRecord_fn = async function(recordId) {
|
@@ -1760,16 +1781,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1760
1781
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1761
1782
|
}
|
1762
1783
|
build(pluginOptions) {
|
1763
|
-
const db = new Proxy(
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1784
|
+
const db = new Proxy(
|
1785
|
+
{},
|
1786
|
+
{
|
1787
|
+
get: (_target, table) => {
|
1788
|
+
if (!isString(table))
|
1789
|
+
throw new Error("Invalid table name");
|
1790
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1791
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1792
|
+
}
|
1793
|
+
return __privateGet$2(this, _tables)[table];
|
1769
1794
|
}
|
1770
|
-
return __privateGet$2(this, _tables)[table];
|
1771
1795
|
}
|
1772
|
-
|
1796
|
+
);
|
1773
1797
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1774
1798
|
for (const table of tableNames) {
|
1775
1799
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1883,9 +1907,13 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1883
1907
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1884
1908
|
const apiKey = options?.apiKey || getAPIKey();
|
1885
1909
|
if (!databaseURL)
|
1886
|
-
throw new Error(
|
1910
|
+
throw new Error(
|
1911
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1912
|
+
);
|
1887
1913
|
if (!apiKey)
|
1888
|
-
throw new Error(
|
1914
|
+
throw new Error(
|
1915
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1916
|
+
);
|
1889
1917
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1890
1918
|
const [workspace] = host.split(".");
|
1891
1919
|
const { fallbackBranch } = getEnvironment();
|
@@ -1903,9 +1931,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1903
1931
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1904
1932
|
const apiKey = options?.apiKey || getAPIKey();
|
1905
1933
|
if (!databaseURL)
|
1906
|
-
throw new Error(
|
1934
|
+
throw new Error(
|
1935
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1936
|
+
);
|
1907
1937
|
if (!apiKey)
|
1908
|
-
throw new Error(
|
1938
|
+
throw new Error(
|
1939
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1940
|
+
);
|
1909
1941
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1910
1942
|
const [workspace] = host.split(".");
|
1911
1943
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1955,14 +1987,16 @@ var __privateMethod = (obj, member, method) => {
|
|
1955
1987
|
return method;
|
1956
1988
|
};
|
1957
1989
|
const buildClient = (plugins) => {
|
1958
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1990
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1959
1991
|
return _a = class {
|
1960
1992
|
constructor(options = {}, schemaTables) {
|
1961
1993
|
__privateAdd(this, _parseOptions);
|
1962
1994
|
__privateAdd(this, _getFetchProps);
|
1963
1995
|
__privateAdd(this, _evaluateBranch);
|
1964
1996
|
__privateAdd(this, _branch, void 0);
|
1997
|
+
__privateAdd(this, _options, void 0);
|
1965
1998
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
1999
|
+
__privateSet(this, _options, safeOptions);
|
1966
2000
|
const pluginOptions = {
|
1967
2001
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1968
2002
|
cache: safeOptions.cache
|
@@ -1984,7 +2018,12 @@ const buildClient = (plugins) => {
|
|
1984
2018
|
}
|
1985
2019
|
}
|
1986
2020
|
}
|
1987
|
-
|
2021
|
+
async getConfig() {
|
2022
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2023
|
+
const branch = await __privateGet(this, _options).branch();
|
2024
|
+
return { databaseURL, branch };
|
2025
|
+
}
|
2026
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1988
2027
|
const fetch = getFetchImplementation(options?.fetch);
|
1989
2028
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1990
2029
|
const apiKey = options?.apiKey || getAPIKey();
|
@@ -1994,12 +2033,7 @@ const buildClient = (plugins) => {
|
|
1994
2033
|
throw new Error("Options databaseURL and apiKey are required");
|
1995
2034
|
}
|
1996
2035
|
return { fetch, databaseURL, apiKey, branch, cache };
|
1997
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
1998
|
-
fetch,
|
1999
|
-
apiKey,
|
2000
|
-
databaseURL,
|
2001
|
-
branch
|
2002
|
-
}) {
|
2036
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
|
2003
2037
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2004
2038
|
if (!branchValue)
|
2005
2039
|
throw new Error("Unable to resolve branch value");
|
@@ -2034,6 +2068,88 @@ const buildClient = (plugins) => {
|
|
2034
2068
|
class BaseClient extends buildClient() {
|
2035
2069
|
}
|
2036
2070
|
|
2071
|
+
const META = "__";
|
2072
|
+
const VALUE = "___";
|
2073
|
+
class Serializer {
|
2074
|
+
constructor() {
|
2075
|
+
this.classes = {};
|
2076
|
+
}
|
2077
|
+
add(clazz) {
|
2078
|
+
this.classes[clazz.name] = clazz;
|
2079
|
+
}
|
2080
|
+
toJSON(data) {
|
2081
|
+
function visit(obj) {
|
2082
|
+
if (Array.isArray(obj))
|
2083
|
+
return obj.map(visit);
|
2084
|
+
const type = typeof obj;
|
2085
|
+
if (type === "undefined")
|
2086
|
+
return { [META]: "undefined" };
|
2087
|
+
if (type === "bigint")
|
2088
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2089
|
+
if (obj === null || type !== "object")
|
2090
|
+
return obj;
|
2091
|
+
const constructor = obj.constructor;
|
2092
|
+
const o = { [META]: constructor.name };
|
2093
|
+
for (const [key, value] of Object.entries(obj)) {
|
2094
|
+
o[key] = visit(value);
|
2095
|
+
}
|
2096
|
+
if (constructor === Date)
|
2097
|
+
o[VALUE] = obj.toISOString();
|
2098
|
+
if (constructor === Map)
|
2099
|
+
o[VALUE] = Object.fromEntries(obj);
|
2100
|
+
if (constructor === Set)
|
2101
|
+
o[VALUE] = [...obj];
|
2102
|
+
return o;
|
2103
|
+
}
|
2104
|
+
return JSON.stringify(visit(data));
|
2105
|
+
}
|
2106
|
+
fromJSON(json) {
|
2107
|
+
return JSON.parse(json, (key, value) => {
|
2108
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2109
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2110
|
+
const constructor = this.classes[clazz];
|
2111
|
+
if (constructor) {
|
2112
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2113
|
+
}
|
2114
|
+
if (clazz === "Date")
|
2115
|
+
return new Date(val);
|
2116
|
+
if (clazz === "Set")
|
2117
|
+
return new Set(val);
|
2118
|
+
if (clazz === "Map")
|
2119
|
+
return new Map(Object.entries(val));
|
2120
|
+
if (clazz === "bigint")
|
2121
|
+
return BigInt(val);
|
2122
|
+
if (clazz === "undefined")
|
2123
|
+
return void 0;
|
2124
|
+
return rest;
|
2125
|
+
}
|
2126
|
+
return value;
|
2127
|
+
});
|
2128
|
+
}
|
2129
|
+
}
|
2130
|
+
const defaultSerializer = new Serializer();
|
2131
|
+
const serialize = (data) => {
|
2132
|
+
return defaultSerializer.toJSON(data);
|
2133
|
+
};
|
2134
|
+
const deserialize = (json) => {
|
2135
|
+
return defaultSerializer.fromJSON(json);
|
2136
|
+
};
|
2137
|
+
|
2138
|
+
function buildWorkerRunner(config) {
|
2139
|
+
return function xataWorker(name, _worker) {
|
2140
|
+
return async (...args) => {
|
2141
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2142
|
+
const result = await fetch(url, {
|
2143
|
+
method: "POST",
|
2144
|
+
headers: { "Content-Type": "application/json" },
|
2145
|
+
body: serialize({ args })
|
2146
|
+
});
|
2147
|
+
const text = await result.text();
|
2148
|
+
return deserialize(text);
|
2149
|
+
};
|
2150
|
+
};
|
2151
|
+
}
|
2152
|
+
|
2037
2153
|
class XataError extends Error {
|
2038
2154
|
constructor(message, status) {
|
2039
2155
|
super(message);
|
@@ -2041,5 +2157,5 @@ class XataError extends Error {
|
|
2041
2157
|
}
|
2042
2158
|
}
|
2043
2159
|
|
2044
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, 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, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2160
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2045
2161
|
//# sourceMappingURL=index.mjs.map
|