@xata.io/client 0.2.2 → 0.3.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 (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/api/client.d.ts +95 -0
  3. package/dist/api/client.js +235 -0
  4. package/dist/api/components.d.ts +1440 -0
  5. package/dist/api/components.js +1001 -0
  6. package/dist/api/fetcher.d.ts +25 -0
  7. package/dist/api/fetcher.js +78 -0
  8. package/dist/api/index.d.ts +7 -0
  9. package/dist/api/index.js +21 -0
  10. package/dist/api/parameters.d.ts +16 -0
  11. package/dist/api/parameters.js +2 -0
  12. package/dist/api/providers.d.ts +8 -0
  13. package/dist/api/providers.js +29 -0
  14. package/dist/api/responses.d.ts +44 -0
  15. package/dist/api/responses.js +2 -0
  16. package/dist/api/schemas.d.ts +311 -0
  17. package/dist/api/schemas.js +2 -0
  18. package/dist/index.d.ts +2 -133
  19. package/dist/index.js +16 -368
  20. package/dist/schema/filters.d.ts +20 -0
  21. package/dist/schema/filters.js +24 -0
  22. package/dist/schema/index.d.ts +5 -0
  23. package/dist/schema/index.js +25 -0
  24. package/dist/schema/operators.d.ts +72 -0
  25. package/dist/schema/operators.js +91 -0
  26. package/dist/schema/pagination.d.ts +79 -0
  27. package/dist/schema/pagination.js +90 -0
  28. package/dist/schema/query.d.ts +114 -0
  29. package/dist/schema/query.js +227 -0
  30. package/dist/schema/record.d.ts +36 -0
  31. package/dist/schema/record.js +2 -0
  32. package/dist/schema/repository.d.ts +109 -0
  33. package/dist/schema/repository.js +273 -0
  34. package/dist/schema/selection.d.ts +13 -0
  35. package/dist/schema/selection.js +2 -0
  36. package/dist/util/lang.d.ts +2 -0
  37. package/dist/util/lang.js +10 -0
  38. package/dist/util/types.d.ts +3 -0
  39. package/dist/util/types.js +2 -0
  40. package/package.json +3 -3
  41. package/dist/index.test.d.ts +0 -1
  42. package/dist/index.test.js +0 -304
  43. package/src/index.test.ts +0 -392
  44. package/src/index.ts +0 -506
@@ -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' | '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 });