@xata.io/client 0.1.5 → 0.4.0

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +201 -0
  3. package/dist/api/client.d.ts +95 -0
  4. package/dist/api/client.js +235 -0
  5. package/dist/api/components.d.ts +1440 -0
  6. package/dist/api/components.js +1001 -0
  7. package/dist/api/fetcher.d.ts +25 -0
  8. package/dist/api/fetcher.js +78 -0
  9. package/dist/api/index.d.ts +7 -0
  10. package/dist/api/index.js +21 -0
  11. package/dist/api/parameters.d.ts +16 -0
  12. package/dist/api/parameters.js +2 -0
  13. package/dist/api/providers.d.ts +8 -0
  14. package/dist/api/providers.js +29 -0
  15. package/dist/api/responses.d.ts +44 -0
  16. package/dist/api/responses.js +2 -0
  17. package/dist/api/schemas.d.ts +311 -0
  18. package/dist/api/schemas.js +2 -0
  19. package/dist/index.d.ts +2 -126
  20. package/dist/index.js +16 -324
  21. package/dist/schema/filters.d.ts +20 -0
  22. package/dist/schema/filters.js +24 -0
  23. package/dist/schema/index.d.ts +6 -0
  24. package/dist/schema/index.js +26 -0
  25. package/dist/schema/operators.d.ts +72 -0
  26. package/dist/schema/operators.js +91 -0
  27. package/dist/schema/pagination.d.ts +83 -0
  28. package/dist/schema/pagination.js +94 -0
  29. package/dist/schema/query.d.ts +128 -0
  30. package/dist/schema/query.js +254 -0
  31. package/dist/schema/record.d.ts +41 -0
  32. package/dist/schema/record.js +2 -0
  33. package/dist/schema/repository.d.ts +109 -0
  34. package/dist/schema/repository.js +280 -0
  35. package/dist/schema/selection.d.ts +14 -0
  36. package/dist/schema/selection.js +2 -0
  37. package/dist/util/lang.d.ts +2 -0
  38. package/dist/util/lang.js +10 -0
  39. package/dist/util/types.d.ts +3 -0
  40. package/dist/util/types.js +2 -0
  41. package/package.json +4 -3
  42. package/dist/index.test.d.ts +0 -1
  43. package/dist/index.test.js +0 -182
  44. package/src/index.test.ts +0 -222
  45. package/src/index.ts +0 -468
@@ -0,0 +1,25 @@
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 WorkspaceApiUrlBuilder = (path: string, pathParams: Record<string, string>) => string;
11
+ export declare type FetcherExtraProps = {
12
+ apiUrl: string;
13
+ workspacesApiUrl: string | WorkspaceApiUrlBuilder;
14
+ fetchImpl: FetchImpl;
15
+ apiKey: string;
16
+ };
17
+ export declare type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> = {
18
+ url: string;
19
+ method: string;
20
+ body?: TBody;
21
+ headers?: THeaders;
22
+ queryParams?: TQueryParams;
23
+ pathParams?: TPathParams;
24
+ };
25
+ 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: path, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> & FetcherExtraProps): Promise<TData>;
@@ -0,0 +1,78 @@
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 buildBaseUrl({ path, workspacesApiUrl, apiUrl, pathParams }) {
20
+ if (!(pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace))
21
+ return `${apiUrl}${path}`;
22
+ const url = typeof workspacesApiUrl === 'string' ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
23
+ return url.replace('{workspaceId}', pathParams.workspace);
24
+ }
25
+ // The host header is needed by Node.js on localhost.
26
+ // It is ignored by fetch() in the frontend
27
+ function hostHeader(url) {
28
+ var _a;
29
+ const pattern = /.*:\/\/(?<host>[^/]+).*/;
30
+ const { groups } = (_a = pattern.exec(url)) !== null && _a !== void 0 ? _a : {};
31
+ return (groups === null || groups === void 0 ? void 0 : groups.host) ? { Host: groups.host } : {};
32
+ }
33
+ function fetch({ url: path, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
36
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
37
+ // Node.js on localhost won't resolve localhost subdomains unless mapped in /etc/hosts
38
+ // So, instead, we use localhost without subdomains, but will add a Host header
39
+ const url = fullUrl.includes('localhost') ? fullUrl.replace(/^[^.]+\./, 'http://') : fullUrl;
40
+ const response = yield fetchImpl(url, {
41
+ method: method.toUpperCase(),
42
+ body: body ? JSON.stringify(body) : undefined,
43
+ headers: Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, headers), hostHeader(fullUrl)), { Authorization: `Bearer ${apiKey}` })
44
+ });
45
+ // No content
46
+ if (response.status === 204) {
47
+ return {};
48
+ }
49
+ try {
50
+ const jsonResponse = yield response.json();
51
+ if (response.ok) {
52
+ return jsonResponse;
53
+ }
54
+ if (jsonResponse.message) {
55
+ throw withStatus({ message: jsonResponse.message }, response.status);
56
+ }
57
+ else {
58
+ throw withStatus(fallbackError, response.status);
59
+ }
60
+ }
61
+ catch (e) {
62
+ if (e instanceof Error) {
63
+ const error = {
64
+ message: e.message
65
+ };
66
+ throw withStatus(error, response.status);
67
+ }
68
+ else if (typeof e === 'object' && typeof e.message === 'string') {
69
+ throw withStatus(e, response.status);
70
+ }
71
+ else {
72
+ throw withStatus(fallbackError, response.status);
73
+ }
74
+ }
75
+ });
76
+ }
77
+ exports.fetch = fetch;
78
+ 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,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Operations = void 0;
18
+ const components_1 = require("./components");
19
+ Object.defineProperty(exports, "Operations", { enumerable: true, get: function () { return components_1.operationsByTag; } });
20
+ __exportStar(require("./client"), exports);
21
+ __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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,44 @@
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 RecordUpdateResponse = {
27
+ id: string;
28
+ xata: {
29
+ version: number;
30
+ };
31
+ };
32
+ export declare type QueryResponse = {
33
+ records: Schemas.XataRecord[];
34
+ meta: Schemas.RecordsMetadata;
35
+ };
36
+ export declare type SearchResponse = {
37
+ records: Schemas.XataRecord[];
38
+ };
39
+ /**
40
+ * @example {"migrationID":"mig_c7m19ilcefoebpqj12p0"}
41
+ */
42
+ export declare type MigrationIdResponse = {
43
+ migrationID: string;
44
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,130 +1,6 @@
1
- export interface XataRecord {
2
- id: string;
3
- xata: {
4
- version: number;
5
- };
6
- read(): Promise<this>;
7
- update(data: Selectable<this>): Promise<this>;
8
- delete(): Promise<void>;
9
- }
10
- export declare type Queries<T> = {
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>>;
88
- abstract create(object: Selectable<T>): Promise<T>;
89
- abstract read(id: string): Promise<T | null>;
90
- abstract update(id: string, object: Partial<T>): Promise<T>;
91
- abstract delete(id: string): void;
92
- abstract query<R>(query: Query<T, R>): Promise<R[]>;
93
- }
94
- export declare class RestRepository<T> extends Repository<T> {
95
- client: BaseClient<any>;
96
- fetch: any;
97
- constructor(client: BaseClient<any>, table: string);
98
- request(method: string, path: string, body?: unknown): Promise<any>;
99
- select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>;
100
- create(object: T): Promise<T>;
101
- read(id: string): Promise<T | null>;
102
- update(id: string, object: Partial<T>): Promise<T>;
103
- delete(id: string): Promise<void>;
104
- query<R>(query: Query<T, R>): Promise<R[]>;
105
- }
106
- interface RepositoryFactory {
107
- createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
108
- }
109
- export declare class RestRespositoryFactory implements RepositoryFactory {
110
- createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
111
- }
112
- export declare type XataClientOptions = {
113
- fetch?: unknown;
114
- databaseURL: string;
115
- apiKey: string;
116
- repositoryFactory?: RepositoryFactory;
117
- };
118
- export declare class BaseClient<D extends Record<string, Repository<any>>> {
119
- options: XataClientOptions;
120
- private links;
121
- db: D;
122
- constructor(options: XataClientOptions, links: Links);
123
- initObject<T>(table: string, object: object): T;
124
- }
125
1
  export declare class XataError extends Error {
126
2
  readonly status: number;
127
3
  constructor(message: string, status: number);
128
4
  }
129
- export declare type Links = Record<string, Array<string[]>>;
130
- export {};
5
+ export * from './api';
6
+ export * from './schema';