@xata.io/client 0.0.0-beta.9d62fb3 → 0.0.0-beta.bdce130
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/dist/api/client.d.ts +90 -0
- package/dist/api/client.js +206 -0
- package/dist/api/components.d.ts +1430 -0
- package/dist/api/components.js +1001 -0
- package/dist/api/fetcher.d.ts +24 -0
- package/dist/api/fetcher.js +75 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +17 -0
- package/dist/api/parameters.d.ts +16 -0
- package/dist/api/parameters.js +2 -0
- package/dist/api/providers.d.ts +8 -0
- package/dist/api/providers.js +29 -0
- package/dist/api/responses.d.ts +38 -0
- package/dist/api/responses.js +2 -0
- package/dist/api/schemas.d.ts +311 -0
- package/dist/api/schemas.js +2 -0
- package/dist/index.d.ts +16 -89
- package/dist/index.js +104 -197
- package/dist/schema/filters.d.ts +20 -0
- package/dist/schema/filters.js +24 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +13 -0
- package/dist/schema/operators.d.ts +21 -0
- package/dist/schema/operators.js +40 -0
- package/dist/schema/pagination.d.ts +41 -0
- package/dist/schema/pagination.js +58 -0
- package/dist/schema/query.d.ts +110 -0
- package/dist/schema/query.js +190 -0
- package/dist/schema/selection.d.ts +18 -0
- package/dist/schema/selection.js +2 -0
- package/dist/util/lang.d.ts +1 -0
- package/dist/util/lang.js +10 -0
- package/dist/util/types.d.ts +3 -0
- package/dist/util/types.js +2 -0
- package/package.json +3 -3
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -304
- package/src/index.test.ts +0 -392
- package/src/index.ts +0 -506
- package/tsconfig.json +0 -21
@@ -0,0 +1,24 @@
|
|
1
|
+
export declare type FetchImpl = (url: string, init?: {
|
2
|
+
body?: string;
|
3
|
+
headers?: Record<string, string>;
|
4
|
+
method?: string;
|
5
|
+
}) => Promise<{
|
6
|
+
ok: boolean;
|
7
|
+
status: number;
|
8
|
+
json(): Promise<any>;
|
9
|
+
}>;
|
10
|
+
export declare type FetcherExtraProps = {
|
11
|
+
apiUrl: string;
|
12
|
+
workspacesApiUrl: string;
|
13
|
+
fetchImpl: FetchImpl;
|
14
|
+
apiKey: string;
|
15
|
+
};
|
16
|
+
export declare type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> = {
|
17
|
+
url: string;
|
18
|
+
method: string;
|
19
|
+
body?: TBody;
|
20
|
+
headers?: THeaders;
|
21
|
+
queryParams?: TQueryParams;
|
22
|
+
pathParams?: TPathParams;
|
23
|
+
};
|
24
|
+
export declare function fetch<TData, TBody extends Record<string, unknown> | undefined, THeaders extends Record<string, unknown>, TQueryParams extends Record<string, unknown>, TPathParams extends Record<string, string>>({ url, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> & FetcherExtraProps): Promise<TData>;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.fetch = void 0;
|
13
|
+
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
14
|
+
const query = new URLSearchParams(queryParams).toString();
|
15
|
+
const queryString = query.length > 0 ? `?${query}` : '';
|
16
|
+
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
|
17
|
+
};
|
18
|
+
const fallbackError = { message: 'Network response was not ok' };
|
19
|
+
function baseURLForWorkspace(workspacesApiUrl, workspace) {
|
20
|
+
// Node.js on localhost won't resolve localhost subdomains unless mapped in /etc/hosts
|
21
|
+
// So, instead, we use localhost without subdomains, but will add a Host header
|
22
|
+
if (typeof window === 'undefined' && workspacesApiUrl.includes('localhost:')) {
|
23
|
+
return workspacesApiUrl.replace('{workspaceId}.', '');
|
24
|
+
}
|
25
|
+
return workspacesApiUrl.replace('{workspaceId}', workspace);
|
26
|
+
}
|
27
|
+
function hostHeaderForWorkspace(workspacesApiUrl, workspace) {
|
28
|
+
const url = baseURLForWorkspace(workspacesApiUrl, workspace);
|
29
|
+
if (!url)
|
30
|
+
return;
|
31
|
+
const [, hostname] = url.split('://');
|
32
|
+
return hostname;
|
33
|
+
}
|
34
|
+
function fetch({ url, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }) {
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
36
|
+
const baseURL = (pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace) ? baseURLForWorkspace(workspacesApiUrl, pathParams.workspace) : apiUrl;
|
37
|
+
const response = yield fetchImpl(`${baseURL}${resolveUrl(url, queryParams, pathParams)}`, {
|
38
|
+
method: method.toUpperCase(),
|
39
|
+
body: body ? JSON.stringify(body) : undefined,
|
40
|
+
headers: Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, headers), { Authorization: `Bearer ${apiKey}` }), ((pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace) ? { Host: hostHeaderForWorkspace(workspacesApiUrl, pathParams.workspace) } : {}))
|
41
|
+
});
|
42
|
+
// No content
|
43
|
+
if (response.status === 204) {
|
44
|
+
return {};
|
45
|
+
}
|
46
|
+
try {
|
47
|
+
const jsonResponse = yield response.json();
|
48
|
+
if (response.ok) {
|
49
|
+
return jsonResponse;
|
50
|
+
}
|
51
|
+
if (jsonResponse.message) {
|
52
|
+
throw withStatus({ message: jsonResponse.message }, response.status);
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
throw withStatus(fallbackError, response.status);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
catch (e) {
|
59
|
+
if (e instanceof Error) {
|
60
|
+
const error = {
|
61
|
+
message: e.message
|
62
|
+
};
|
63
|
+
throw withStatus(error, response.status);
|
64
|
+
}
|
65
|
+
else if (typeof e === 'object' && typeof e.message === 'string') {
|
66
|
+
throw withStatus(e, response.status);
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
throw withStatus(fallbackError, response.status);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
});
|
73
|
+
}
|
74
|
+
exports.fetch = fetch;
|
75
|
+
const withStatus = (error, status) => (Object.assign(Object.assign({}, error), { status }));
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { operationsByTag } from './components';
|
2
|
+
import type * as Responses from './responses';
|
3
|
+
import type * as Schemas from './schemas';
|
4
|
+
export * from './client';
|
5
|
+
export * from './components';
|
6
|
+
export { operationsByTag as Operations };
|
7
|
+
export type { Responses, Schemas };
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
|
+
};
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
+
exports.Operations = void 0;
|
14
|
+
const components_1 = require("./components");
|
15
|
+
Object.defineProperty(exports, "Operations", { enumerable: true, get: function () { return components_1.operationsByTag; } });
|
16
|
+
__exportStar(require("./client"), exports);
|
17
|
+
__exportStar(require("./components"), exports);
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* Generated by @openapi-codegen
|
3
|
+
*
|
4
|
+
* @version 1.0
|
5
|
+
*/
|
6
|
+
import type * as Schemas from './schemas';
|
7
|
+
export declare type APIKeyNameParam = Schemas.APIKeyName;
|
8
|
+
export declare type InviteIDParam = Schemas.InviteID;
|
9
|
+
export declare type InviteKeyParam = Schemas.InviteKey;
|
10
|
+
export declare type UserIDParam = Schemas.UserID;
|
11
|
+
export declare type WorkspaceIDParam = Schemas.WorkspaceID;
|
12
|
+
export declare type ColumnNameParam = Schemas.ColumnName;
|
13
|
+
export declare type DBBranchNameParam = Schemas.DBBranchName;
|
14
|
+
export declare type DBNameParam = Schemas.DBName;
|
15
|
+
export declare type RecordIDParam = Schemas.RecordID;
|
16
|
+
export declare type TableNameParam = Schemas.TableName;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
declare type HostAliases = 'production' | 'staging';
|
2
|
+
declare type ProviderBuilder = {
|
3
|
+
main: string;
|
4
|
+
workspaces: string;
|
5
|
+
};
|
6
|
+
export declare type HostProvider = HostAliases | ProviderBuilder;
|
7
|
+
export declare function getHostUrl(provider: HostProvider, type: keyof ProviderBuilder): string;
|
8
|
+
export {};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getHostUrl = void 0;
|
4
|
+
function getHostUrl(provider, type) {
|
5
|
+
if (isValidAlias(provider)) {
|
6
|
+
return providers[provider][type];
|
7
|
+
}
|
8
|
+
else if (isValidBuilder(provider)) {
|
9
|
+
return provider[type];
|
10
|
+
}
|
11
|
+
throw new Error('Invalid API provider');
|
12
|
+
}
|
13
|
+
exports.getHostUrl = getHostUrl;
|
14
|
+
const providers = {
|
15
|
+
production: {
|
16
|
+
main: 'https://api.xata.io',
|
17
|
+
workspaces: 'https://{workspaceId}.xata.sh'
|
18
|
+
},
|
19
|
+
staging: {
|
20
|
+
main: 'https://staging.xatabase.co',
|
21
|
+
workspaces: 'https://{workspaceId}.staging.xatabase.co'
|
22
|
+
}
|
23
|
+
};
|
24
|
+
function isValidAlias(alias) {
|
25
|
+
return typeof alias === 'string' && Object.keys(providers).includes(alias);
|
26
|
+
}
|
27
|
+
function isValidBuilder(builder) {
|
28
|
+
return typeof builder === 'object' && typeof builder.main === 'string' && typeof builder.workspaces === 'string';
|
29
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/**
|
2
|
+
* Generated by @openapi-codegen
|
3
|
+
*
|
4
|
+
* @version 1.0
|
5
|
+
*/
|
6
|
+
import type * as Schemas from './schemas';
|
7
|
+
export declare type SimpleError = {
|
8
|
+
id?: string;
|
9
|
+
message: string;
|
10
|
+
};
|
11
|
+
export declare type BadRequestError = {
|
12
|
+
id?: string;
|
13
|
+
message: string;
|
14
|
+
};
|
15
|
+
/**
|
16
|
+
* @example {"message":"invalid API key"}
|
17
|
+
*/
|
18
|
+
export declare type AuthError = {
|
19
|
+
id?: string;
|
20
|
+
message: string;
|
21
|
+
};
|
22
|
+
export declare type BranchMigrationPlan = {
|
23
|
+
version: number;
|
24
|
+
migration: Schemas.BranchMigration;
|
25
|
+
};
|
26
|
+
export declare type QueryResponse = {
|
27
|
+
records: Schemas.XataRecord[];
|
28
|
+
meta: Schemas.RecordsMetadata;
|
29
|
+
};
|
30
|
+
export declare type SearchResponse = {
|
31
|
+
records: Schemas.XataRecord[];
|
32
|
+
};
|
33
|
+
/**
|
34
|
+
* @example {"migrationID":"mig_c7m19ilcefoebpqj12p0"}
|
35
|
+
*/
|
36
|
+
export declare type MigrationIdResponse = {
|
37
|
+
migrationID: string;
|
38
|
+
};
|
@@ -0,0 +1,311 @@
|
|
1
|
+
/**
|
2
|
+
* Generated by @openapi-codegen
|
3
|
+
*
|
4
|
+
* @version 1.0
|
5
|
+
*/
|
6
|
+
export declare type User = {
|
7
|
+
email: string;
|
8
|
+
fullname: string;
|
9
|
+
image: string;
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* @pattern [a-zA-Z0-9_-~:]+
|
13
|
+
*/
|
14
|
+
export declare type UserID = string;
|
15
|
+
export declare type UserWithID = User & {
|
16
|
+
id: UserID;
|
17
|
+
};
|
18
|
+
/**
|
19
|
+
* @format date-time
|
20
|
+
* @x-go-type string
|
21
|
+
*/
|
22
|
+
export declare type DateTime = string;
|
23
|
+
/**
|
24
|
+
* @pattern [a-zA-Z0-9_\-~]*
|
25
|
+
*/
|
26
|
+
export declare type APIKeyName = string;
|
27
|
+
/**
|
28
|
+
* @pattern ^([a-zA-Z0-9][a-zA-Z0-9_\-~]+-)?[a-zA-Z0-9]{6}
|
29
|
+
* @x-go-type auth.WorkspaceID
|
30
|
+
*/
|
31
|
+
export declare type WorkspaceID = string;
|
32
|
+
/**
|
33
|
+
* @x-go-type auth.Role
|
34
|
+
*/
|
35
|
+
export declare type Role = 'owner' | 'maintainer';
|
36
|
+
export declare type WorkspaceMeta = {
|
37
|
+
name: string;
|
38
|
+
slug: string;
|
39
|
+
};
|
40
|
+
export declare type Workspace = WorkspaceMeta & {
|
41
|
+
id: WorkspaceID;
|
42
|
+
memberCount: number;
|
43
|
+
plan: 'free';
|
44
|
+
};
|
45
|
+
export declare type WorkspaceMember = {
|
46
|
+
userId: UserID;
|
47
|
+
fullname: string;
|
48
|
+
email: string;
|
49
|
+
role: Role;
|
50
|
+
};
|
51
|
+
/**
|
52
|
+
* @pattern [a-zA-Z0-9]+
|
53
|
+
*/
|
54
|
+
export declare type InviteID = string;
|
55
|
+
export declare type WorkspaceInvite = {
|
56
|
+
inviteId: InviteID;
|
57
|
+
email: string;
|
58
|
+
expires: string;
|
59
|
+
role: Role;
|
60
|
+
};
|
61
|
+
export declare type WorkspaceMembers = {
|
62
|
+
members: WorkspaceMember[];
|
63
|
+
invites: WorkspaceInvite[];
|
64
|
+
};
|
65
|
+
/**
|
66
|
+
* @pattern ^ik_[a-zA-Z0-9]+
|
67
|
+
*/
|
68
|
+
export declare type InviteKey = string;
|
69
|
+
export declare type ListDatabasesResponse = {
|
70
|
+
databases?: {
|
71
|
+
name: string;
|
72
|
+
displayName: string;
|
73
|
+
createdAt: DateTime;
|
74
|
+
numberOfBranches: number;
|
75
|
+
ui?: {
|
76
|
+
color?: string;
|
77
|
+
};
|
78
|
+
}[];
|
79
|
+
};
|
80
|
+
export declare type ListBranchesResponse = {
|
81
|
+
databaseName: string;
|
82
|
+
displayName: string;
|
83
|
+
branches: Branch[];
|
84
|
+
};
|
85
|
+
export declare type Branch = {
|
86
|
+
name: string;
|
87
|
+
createdAt: DateTime;
|
88
|
+
};
|
89
|
+
/**
|
90
|
+
* @example {"repository":"github.com/my/repository","branch":"feature-login","stage":"testing","labels":["epic-100"]}
|
91
|
+
* @x-go-type xata.BranchMetadata
|
92
|
+
*/
|
93
|
+
export declare type BranchMetadata = {
|
94
|
+
repository?: string;
|
95
|
+
branch?: BranchName;
|
96
|
+
stage?: string;
|
97
|
+
labels?: string[];
|
98
|
+
};
|
99
|
+
export declare type DBBranch = {
|
100
|
+
databaseName: DBName;
|
101
|
+
branchName: BranchName;
|
102
|
+
createdAt: DateTime;
|
103
|
+
id: string;
|
104
|
+
version: number;
|
105
|
+
lastMigrationID: string;
|
106
|
+
metadata?: BranchMetadata;
|
107
|
+
startedFrom?: StartedFromMetadata;
|
108
|
+
schema: Schema;
|
109
|
+
};
|
110
|
+
export declare type StartedFromMetadata = {
|
111
|
+
branchName: BranchName;
|
112
|
+
dbBranchID: string;
|
113
|
+
migrationID: string;
|
114
|
+
};
|
115
|
+
/**
|
116
|
+
* @x-go-type xata.Schema
|
117
|
+
*/
|
118
|
+
export declare type Schema = {
|
119
|
+
tables: Table[];
|
120
|
+
tablesOrder?: string[];
|
121
|
+
};
|
122
|
+
export declare type Table = {
|
123
|
+
id?: string;
|
124
|
+
name: TableName;
|
125
|
+
columns: Column[];
|
126
|
+
revLinks?: RevLink[];
|
127
|
+
};
|
128
|
+
/**
|
129
|
+
* @x-go-type xata.Column
|
130
|
+
*/
|
131
|
+
export declare type Column = {
|
132
|
+
name: string;
|
133
|
+
type: 'bool' | 'int' | 'float' | 'string' | 'text' | 'email' | 'multiple' | 'link' | 'object';
|
134
|
+
link?: {
|
135
|
+
table: string;
|
136
|
+
};
|
137
|
+
columns?: Column[];
|
138
|
+
};
|
139
|
+
export declare type RevLink = {
|
140
|
+
linkID: string;
|
141
|
+
table: string;
|
142
|
+
};
|
143
|
+
/**
|
144
|
+
* @pattern [a-zA-Z0-9_\-~]+
|
145
|
+
*/
|
146
|
+
export declare type BranchName = string;
|
147
|
+
/**
|
148
|
+
* @pattern [a-zA-Z0-9_\-~]+
|
149
|
+
*/
|
150
|
+
export declare type DBName = string;
|
151
|
+
/**
|
152
|
+
* The DBBranchName matches the pattern `{db_name}:{branch_name}`.
|
153
|
+
*
|
154
|
+
* @pattern [a-zA-Z0-9_\-~]+:[a-zA-Z0-9_\-~]+
|
155
|
+
*/
|
156
|
+
export declare type DBBranchName = string;
|
157
|
+
/**
|
158
|
+
* @pattern [a-zA-Z0-9_\-~]+
|
159
|
+
*/
|
160
|
+
export declare type TableName = string;
|
161
|
+
/**
|
162
|
+
* @pattern [a-zA-Z0-9_\-~\.]+
|
163
|
+
*/
|
164
|
+
export declare type ColumnName = string;
|
165
|
+
export declare type MetricsDatapoint = {
|
166
|
+
timestamp: string;
|
167
|
+
value: number;
|
168
|
+
};
|
169
|
+
export declare type MetricsLatency = {
|
170
|
+
p50?: MetricsDatapoint[];
|
171
|
+
p90?: MetricsDatapoint[];
|
172
|
+
};
|
173
|
+
export declare type BranchMigration = {
|
174
|
+
id?: string;
|
175
|
+
parentID?: string;
|
176
|
+
status: string;
|
177
|
+
title?: string;
|
178
|
+
lastGitRevision?: string;
|
179
|
+
localChanges: boolean;
|
180
|
+
createdAt?: DateTime;
|
181
|
+
newTables?: {
|
182
|
+
[key: string]: Table;
|
183
|
+
};
|
184
|
+
removedTables?: string[];
|
185
|
+
tableMigrations?: {
|
186
|
+
[key: string]: TableMigration;
|
187
|
+
};
|
188
|
+
newTableOrder: string[];
|
189
|
+
renamedTables?: TableRename[];
|
190
|
+
};
|
191
|
+
export declare type TableMigration = {
|
192
|
+
newColumns?: {
|
193
|
+
[key: string]: Column;
|
194
|
+
};
|
195
|
+
removedColumns?: string[];
|
196
|
+
modifiedColumns?: ColumnMigration[];
|
197
|
+
newColumnOrder: string[];
|
198
|
+
};
|
199
|
+
export declare type ColumnMigration = {
|
200
|
+
old: Column;
|
201
|
+
['new']: Column;
|
202
|
+
};
|
203
|
+
export declare type SortExpression = string[] | {
|
204
|
+
[key: string]: SortOrder;
|
205
|
+
} | {
|
206
|
+
[key: string]: SortOrder;
|
207
|
+
}[];
|
208
|
+
export declare type SortOrder = 'asc' | 'desc';
|
209
|
+
/**
|
210
|
+
* @minProperties 1
|
211
|
+
*/
|
212
|
+
export declare type FilterExpression = {
|
213
|
+
$exists?: string;
|
214
|
+
$existsNot?: string;
|
215
|
+
$any?: FilterList;
|
216
|
+
$all?: FilterList;
|
217
|
+
$none?: FilterList;
|
218
|
+
$not?: FilterList;
|
219
|
+
} & {
|
220
|
+
[key: string]: FilterColumn;
|
221
|
+
};
|
222
|
+
export declare type FilterList = FilterExpression | FilterExpression[];
|
223
|
+
export declare type FilterColumn = FilterColumnIncludes | FilterPredicate | FilterList;
|
224
|
+
/**
|
225
|
+
* @maxProperties 1
|
226
|
+
* @minProperties 1
|
227
|
+
*/
|
228
|
+
export declare type FilterColumnIncludes = {
|
229
|
+
$includes?: FilterPredicate;
|
230
|
+
$includesAny?: FilterPredicate;
|
231
|
+
$includesAll?: FilterPredicate;
|
232
|
+
$includesNone?: FilterPredicate;
|
233
|
+
};
|
234
|
+
export declare type FilterPredicate = FilterValue | FilterPredicate[] | FilterPredicateOp | FilterPredicateRangeOp;
|
235
|
+
/**
|
236
|
+
* @maxProperties 1
|
237
|
+
* @minProperties 1
|
238
|
+
*/
|
239
|
+
export declare type FilterPredicateOp = {
|
240
|
+
$any?: FilterPredicate[];
|
241
|
+
$all?: FilterPredicate[];
|
242
|
+
$none?: FilterPredicate | FilterPredicate[];
|
243
|
+
$not?: FilterPredicate | FilterPredicate[];
|
244
|
+
$is?: FilterValue | FilterValue[];
|
245
|
+
$isNot?: FilterValue | FilterValue[];
|
246
|
+
$lt?: FilterRangeValue;
|
247
|
+
$le?: FilterRangeValue;
|
248
|
+
$gt?: FilterRangeValue;
|
249
|
+
$ge?: FilterRangeValue;
|
250
|
+
$contains?: string;
|
251
|
+
$startsWith?: string;
|
252
|
+
$endsWith?: string;
|
253
|
+
$pattern?: string;
|
254
|
+
};
|
255
|
+
/**
|
256
|
+
* @maxProperties 2
|
257
|
+
* @minProperties 2
|
258
|
+
*/
|
259
|
+
export declare type FilterPredicateRangeOp = {
|
260
|
+
$lt?: FilterRangeValue;
|
261
|
+
$le?: FilterRangeValue;
|
262
|
+
$gt?: FilterRangeValue;
|
263
|
+
$ge?: FilterRangeValue;
|
264
|
+
};
|
265
|
+
export declare type FilterRangeValue = number | string;
|
266
|
+
export declare type FilterValue = number | string | boolean;
|
267
|
+
/**
|
268
|
+
* Pagination settings.
|
269
|
+
*/
|
270
|
+
export declare type PageConfig = {
|
271
|
+
after?: string;
|
272
|
+
before?: string;
|
273
|
+
first?: string;
|
274
|
+
last?: string;
|
275
|
+
size?: number;
|
276
|
+
offset?: number;
|
277
|
+
};
|
278
|
+
export declare type ColumnsFilter = string[];
|
279
|
+
/**
|
280
|
+
* @pattern [a-zA-Z0-9_-~:]+
|
281
|
+
*/
|
282
|
+
export declare type RecordID = string;
|
283
|
+
/**
|
284
|
+
* @example {"newName":"newName","oldName":"oldName"}
|
285
|
+
*/
|
286
|
+
export declare type TableRename = {
|
287
|
+
newName: string;
|
288
|
+
oldName: string;
|
289
|
+
};
|
290
|
+
/**
|
291
|
+
* Records metadata
|
292
|
+
*/
|
293
|
+
export declare type RecordsMetadata = {
|
294
|
+
page: {
|
295
|
+
cursor: string;
|
296
|
+
more: boolean;
|
297
|
+
};
|
298
|
+
};
|
299
|
+
/**
|
300
|
+
* Xata Table Record
|
301
|
+
*/
|
302
|
+
export declare type XataRecord = {
|
303
|
+
id: RecordID;
|
304
|
+
xata: {
|
305
|
+
version: number;
|
306
|
+
table?: string;
|
307
|
+
warnings?: string[];
|
308
|
+
};
|
309
|
+
} & {
|
310
|
+
[key: string]: any;
|
311
|
+
};
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
import { Page } from './schema/pagination';
|
2
|
+
import { Query, QueryOptions } from './schema/query';
|
3
|
+
import { Selectable, SelectableColumn, Select } from './schema/selection';
|
1
4
|
export interface XataRecord {
|
2
5
|
id: string;
|
3
6
|
xata: {
|
@@ -7,107 +10,30 @@ export interface XataRecord {
|
|
7
10
|
update(data: Selectable<this>): Promise<this>;
|
8
11
|
delete(): Promise<void>;
|
9
12
|
}
|
10
|
-
export declare
|
11
|
-
[key in keyof T as T[key] extends Query<infer A, infer B> ? key : never]: T[key];
|
12
|
-
};
|
13
|
-
export declare type OmitQueries<T> = {
|
14
|
-
[key in keyof T as T[key] extends Query<infer A, infer B> ? never : key]: T[key];
|
15
|
-
};
|
16
|
-
export declare type OmitLinks<T> = {
|
17
|
-
[key in keyof T as T[key] extends XataRecord ? never : key]: T[key];
|
18
|
-
};
|
19
|
-
export declare type OmitMethods<T> = {
|
20
|
-
[key in keyof T as T[key] extends Function ? never : key]: T[key];
|
21
|
-
};
|
22
|
-
export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>;
|
23
|
-
export declare type Select<T, K extends keyof T> = Pick<T, K> & Queries<T> & XataRecord;
|
24
|
-
export declare type Include<T> = {
|
25
|
-
[key in keyof T as T[key] extends XataRecord ? key : never]?: boolean | Array<keyof Selectable<T[key]>>;
|
26
|
-
};
|
27
|
-
declare type SortDirection = 'asc' | 'desc';
|
28
|
-
declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
|
29
|
-
declare type Constraint<T> = {
|
30
|
-
[key in Operator]?: T;
|
31
|
-
};
|
32
|
-
declare type DeepConstraint<T> = T extends Record<string, any> ? {
|
33
|
-
[key in keyof T]?: T[key] | DeepConstraint<T[key]>;
|
34
|
-
} : Constraint<T>;
|
35
|
-
declare type ComparableType = number | Date;
|
36
|
-
export declare const gt: <T extends ComparableType>(value: T) => Constraint<T>;
|
37
|
-
export declare const ge: <T extends ComparableType>(value: T) => Constraint<T>;
|
38
|
-
export declare const gte: <T extends ComparableType>(value: T) => Constraint<T>;
|
39
|
-
export declare const lt: <T extends ComparableType>(value: T) => Constraint<T>;
|
40
|
-
export declare const lte: <T extends ComparableType>(value: T) => Constraint<T>;
|
41
|
-
export declare const le: <T extends ComparableType>(value: T) => Constraint<T>;
|
42
|
-
export declare const exists: (column: string) => Constraint<string>;
|
43
|
-
export declare const notExists: (column: string) => Constraint<string>;
|
44
|
-
export declare const startsWith: (value: string) => Constraint<string>;
|
45
|
-
export declare const endsWith: (value: string) => Constraint<string>;
|
46
|
-
export declare const pattern: (value: string) => Constraint<string>;
|
47
|
-
export declare const is: <T>(value: T) => Constraint<T>;
|
48
|
-
export declare const isNot: <T>(value: T) => Constraint<T>;
|
49
|
-
export declare const contains: <T>(value: T) => Constraint<T>;
|
50
|
-
export declare const includes: (value: string) => Constraint<string>;
|
51
|
-
export declare const includesSubstring: (value: string) => Constraint<string>;
|
52
|
-
export declare const includesPattern: (value: string) => Constraint<string>;
|
53
|
-
export declare const includesAll: (value: string) => Constraint<string>;
|
54
|
-
declare type FilterConstraints<T> = {
|
55
|
-
[key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
|
56
|
-
};
|
57
|
-
declare type BulkQueryOptions<T> = {
|
58
|
-
filter?: FilterConstraints<T>;
|
59
|
-
sort?: {
|
60
|
-
column: keyof T;
|
61
|
-
direction?: SortDirection;
|
62
|
-
} | keyof T;
|
63
|
-
};
|
64
|
-
declare type QueryOrConstraint<T, R> = Query<T, R> | Constraint<T>;
|
65
|
-
export declare class Query<T, R = T> {
|
66
|
-
table: string;
|
67
|
-
repository: Repository<T>;
|
68
|
-
readonly $any?: QueryOrConstraint<T, R>[];
|
69
|
-
readonly $all?: QueryOrConstraint<T, R>[];
|
70
|
-
readonly $not?: QueryOrConstraint<T, R>[];
|
71
|
-
readonly $none?: QueryOrConstraint<T, R>[];
|
72
|
-
readonly $sort?: Record<string, SortDirection>;
|
73
|
-
constructor(repository: Repository<T> | null, table: string, data: Partial<Query<T, R>>, parent?: Query<T, R>);
|
74
|
-
any(...queries: Query<T, R>[]): Query<T, R>;
|
75
|
-
all(...queries: Query<T, R>[]): Query<T, R>;
|
76
|
-
not(...queries: Query<T, R>[]): Query<T, R>;
|
77
|
-
none(...queries: Query<T, R>[]): Query<T, R>;
|
78
|
-
filter(constraints: FilterConstraints<T>): Query<T, R>;
|
79
|
-
filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
|
80
|
-
sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
|
81
|
-
getMany(options?: BulkQueryOptions<T>): Promise<R[]>;
|
82
|
-
getOne(options?: BulkQueryOptions<T>): Promise<R | null>;
|
83
|
-
deleteAll(): Promise<number>;
|
84
|
-
include(columns: Include<T>): this;
|
85
|
-
}
|
86
|
-
export declare abstract class Repository<T> extends Query<T, Selectable<T>> {
|
87
|
-
select<K extends keyof Selectable<T>>(...columns: K[]): Query<T, Select<T, K>>;
|
13
|
+
export declare abstract class Repository<T extends XataRecord> extends Query<T> {
|
88
14
|
abstract create(object: Selectable<T>): Promise<T>;
|
15
|
+
abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
|
89
16
|
abstract read(id: string): Promise<T | null>;
|
90
17
|
abstract update(id: string, object: Partial<T>): Promise<T>;
|
91
18
|
abstract delete(id: string): void;
|
92
|
-
abstract query<R
|
19
|
+
abstract query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
|
93
20
|
}
|
94
|
-
export declare class RestRepository<T> extends Repository<T> {
|
95
|
-
|
96
|
-
fetch: any;
|
21
|
+
export declare class RestRepository<T extends XataRecord> extends Repository<T> {
|
22
|
+
#private;
|
97
23
|
constructor(client: BaseClient<any>, table: string);
|
98
|
-
request(method: string, path: string, body?: unknown): Promise<
|
99
|
-
select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>;
|
24
|
+
request<T>(method: string, path: string, body?: unknown): Promise<T | undefined>;
|
100
25
|
create(object: T): Promise<T>;
|
26
|
+
createMany(objects: T[]): Promise<T[]>;
|
101
27
|
read(id: string): Promise<T | null>;
|
102
28
|
update(id: string, object: Partial<T>): Promise<T>;
|
103
29
|
delete(id: string): Promise<void>;
|
104
|
-
query<R
|
30
|
+
query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
|
105
31
|
}
|
106
32
|
interface RepositoryFactory {
|
107
|
-
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
|
33
|
+
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
108
34
|
}
|
109
35
|
export declare class RestRespositoryFactory implements RepositoryFactory {
|
110
|
-
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
|
36
|
+
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
111
37
|
}
|
112
38
|
declare type BranchStrategyValue = string | undefined | null;
|
113
39
|
declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
|
@@ -115,7 +41,7 @@ declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
|
|
115
41
|
declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
|
116
42
|
export declare type XataClientOptions = {
|
117
43
|
fetch?: unknown;
|
118
|
-
databaseURL
|
44
|
+
databaseURL?: string;
|
119
45
|
branch: BranchStrategyOption;
|
120
46
|
apiKey: string;
|
121
47
|
repositoryFactory?: RepositoryFactory;
|
@@ -134,4 +60,5 @@ export declare class XataError extends Error {
|
|
134
60
|
constructor(message: string, status: number);
|
135
61
|
}
|
136
62
|
export declare type Links = Record<string, Array<string[]>>;
|
137
|
-
export
|
63
|
+
export * from './api';
|
64
|
+
export * from './schema';
|