@xata.io/client 0.0.0-beta.4e4e7fc → 0.0.0-beta.50e1cc9

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.
@@ -40,6 +40,8 @@ declare class WorkspaceApi {
40
40
  updateWorkspaceMemberRole(workspaceId: Schemas.WorkspaceID, userId: Schemas.UserID, role: Schemas.Role): Promise<void>;
41
41
  removeWorkspaceMember(workspaceId: Schemas.WorkspaceID, userId: Schemas.UserID): Promise<void>;
42
42
  inviteWorkspaceMember(workspaceId: Schemas.WorkspaceID, email: string, role: Schemas.Role): Promise<Schemas.WorkspaceInvite>;
43
+ cancelWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteId: Schemas.InviteID): Promise<void>;
44
+ resendWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteId: Schemas.InviteID): Promise<void>;
43
45
  acceptWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteKey: Schemas.InviteKey): Promise<void>;
44
46
  }
45
47
  declare class DatabaseApi {
@@ -107,6 +107,12 @@ class WorkspaceApi {
107
107
  inviteWorkspaceMember(workspaceId, email, role) {
108
108
  return components_1.operationsByTag.workspaces.inviteWorkspaceMember(Object.assign({ pathParams: { workspaceId }, body: { email, role } }, this.extraProps));
109
109
  }
110
+ cancelWorkspaceMemberInvite(workspaceId, inviteId) {
111
+ return components_1.operationsByTag.workspaces.cancelWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteId } }, this.extraProps));
112
+ }
113
+ resendWorkspaceMemberInvite(workspaceId, inviteId) {
114
+ return components_1.operationsByTag.workspaces.resendWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteId } }, this.extraProps));
115
+ }
110
116
  acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
111
117
  return components_1.operationsByTag.workspaces.acceptWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteKey } }, this.extraProps));
112
118
  }
@@ -161,6 +161,28 @@ export declare type InviteWorkspaceMemberVariables = {
161
161
  * Invite some user to join the workspace with the given role
162
162
  */
163
163
  export declare const inviteWorkspaceMember: (variables: InviteWorkspaceMemberVariables) => Promise<Schemas.WorkspaceInvite>;
164
+ export declare type CancelWorkspaceMemberInvitePathParams = {
165
+ workspaceId: Schemas.WorkspaceID;
166
+ inviteId: Schemas.InviteID;
167
+ };
168
+ export declare type CancelWorkspaceMemberInviteVariables = {
169
+ pathParams: CancelWorkspaceMemberInvitePathParams;
170
+ } & FetcherExtraProps;
171
+ /**
172
+ * This operation provides a way to cancel invites by deleting them. Already accepted invites cannot be deleted.
173
+ */
174
+ export declare const cancelWorkspaceMemberInvite: (variables: CancelWorkspaceMemberInviteVariables) => Promise<undefined>;
175
+ export declare type ResendWorkspaceMemberInvitePathParams = {
176
+ workspaceId: Schemas.WorkspaceID;
177
+ inviteId: Schemas.InviteID;
178
+ };
179
+ export declare type ResendWorkspaceMemberInviteVariables = {
180
+ pathParams: ResendWorkspaceMemberInvitePathParams;
181
+ } & FetcherExtraProps;
182
+ /**
183
+ * This operation provides a way to resend an Invite notification. Invite notifications can only be sent for Invites not yet accepted.
184
+ */
185
+ export declare const resendWorkspaceMemberInvite: (variables: ResendWorkspaceMemberInviteVariables) => Promise<undefined>;
164
186
  export declare type AcceptWorkspaceMemberInvitePathParams = {
165
187
  workspaceId: Schemas.WorkspaceID;
166
188
  inviteKey: Schemas.InviteKey;
@@ -1371,6 +1393,8 @@ export declare const operationsByTag: {
1371
1393
  updateWorkspaceMemberRole: (variables: UpdateWorkspaceMemberRoleVariables) => Promise<undefined>;
1372
1394
  removeWorkspaceMember: (variables: RemoveWorkspaceMemberVariables) => Promise<undefined>;
1373
1395
  inviteWorkspaceMember: (variables: InviteWorkspaceMemberVariables) => Promise<Schemas.WorkspaceInvite>;
1396
+ cancelWorkspaceMemberInvite: (variables: CancelWorkspaceMemberInviteVariables) => Promise<undefined>;
1397
+ resendWorkspaceMemberInvite: (variables: ResendWorkspaceMemberInviteVariables) => Promise<undefined>;
1374
1398
  acceptWorkspaceMemberInvite: (variables: AcceptWorkspaceMemberInviteVariables) => Promise<undefined>;
1375
1399
  };
1376
1400
  database: {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.operationsByTag = exports.searchBranch = exports.queryTable = exports.bulkInsertTableRecords = exports.getRecord = exports.deleteRecord = exports.upsertRecordWithID = exports.updateRecordWithID = exports.insertRecordWithID = exports.insertRecord = exports.updateColumn = exports.deleteColumn = exports.getColumn = exports.addTableColumn = exports.getTableColumns = exports.setTableSchema = exports.getTableSchema = exports.updateTable = exports.deleteTable = exports.createTable = exports.getBranchStats = exports.getBranchMigrationPlan = exports.executeBranchMigrationPlan = exports.getBranchMigrationHistory = exports.getBranchMetadata = exports.updateBranchMetadata = exports.deleteBranch = exports.createBranch = exports.getBranchDetails = exports.deleteDatabase = exports.createDatabase = exports.getBranchList = exports.getDatabaseList = exports.acceptWorkspaceMemberInvite = exports.inviteWorkspaceMember = exports.removeWorkspaceMember = exports.updateWorkspaceMemberRole = exports.getWorkspaceMembersList = exports.deleteWorkspace = exports.updateWorkspace = exports.getWorkspace = exports.getWorkspacesList = exports.createWorkspace = exports.deleteUserAPIKey = exports.createUserAPIKey = exports.getUserAPIKeys = exports.deleteUser = exports.updateUser = exports.getUser = void 0;
3
+ exports.searchBranch = exports.queryTable = exports.bulkInsertTableRecords = exports.getRecord = exports.deleteRecord = exports.upsertRecordWithID = exports.updateRecordWithID = exports.insertRecordWithID = exports.insertRecord = exports.updateColumn = exports.deleteColumn = exports.getColumn = exports.addTableColumn = exports.getTableColumns = exports.setTableSchema = exports.getTableSchema = exports.updateTable = exports.deleteTable = exports.createTable = exports.getBranchStats = exports.getBranchMigrationPlan = exports.executeBranchMigrationPlan = exports.getBranchMigrationHistory = exports.getBranchMetadata = exports.updateBranchMetadata = exports.deleteBranch = exports.createBranch = exports.getBranchDetails = exports.deleteDatabase = exports.createDatabase = exports.getBranchList = exports.getDatabaseList = exports.acceptWorkspaceMemberInvite = exports.resendWorkspaceMemberInvite = exports.cancelWorkspaceMemberInvite = exports.inviteWorkspaceMember = exports.removeWorkspaceMember = exports.updateWorkspaceMemberRole = exports.getWorkspaceMembersList = exports.deleteWorkspace = exports.updateWorkspace = exports.getWorkspace = exports.getWorkspacesList = exports.createWorkspace = exports.deleteUserAPIKey = exports.createUserAPIKey = exports.getUserAPIKeys = exports.deleteUser = exports.updateUser = exports.getUser = void 0;
4
+ exports.operationsByTag = void 0;
4
5
  /**
5
6
  * Generated by @openapi-codegen
6
7
  *
@@ -82,6 +83,16 @@ exports.removeWorkspaceMember = removeWorkspaceMember;
82
83
  */
83
84
  const inviteWorkspaceMember = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites', method: 'post' }, variables));
84
85
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
86
+ /**
87
+ * This operation provides a way to cancel invites by deleting them. Already accepted invites cannot be deleted.
88
+ */
89
+ const cancelWorkspaceMemberInvite = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites/{inviteId}', method: 'delete' }, variables));
90
+ exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
91
+ /**
92
+ * This operation provides a way to resend an Invite notification. Invite notifications can only be sent for Invites not yet accepted.
93
+ */
94
+ const resendWorkspaceMemberInvite = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites/{inviteId}/resend', method: 'post' }, variables));
95
+ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
85
96
  /**
86
97
  * Accept the invitation to join a workspace. If the operation succeeds the user will be a member of the workspace
87
98
  */
@@ -947,6 +958,8 @@ exports.operationsByTag = {
947
958
  updateWorkspaceMemberRole: exports.updateWorkspaceMemberRole,
948
959
  removeWorkspaceMember: exports.removeWorkspaceMember,
949
960
  inviteWorkspaceMember: exports.inviteWorkspaceMember,
961
+ cancelWorkspaceMemberInvite: exports.cancelWorkspaceMemberInvite,
962
+ resendWorkspaceMemberInvite: exports.resendWorkspaceMemberInvite,
950
963
  acceptWorkspaceMemberInvite: exports.acceptWorkspaceMemberInvite
951
964
  },
952
965
  database: { getDatabaseList: exports.getDatabaseList, createDatabase: exports.createDatabase, deleteDatabase: exports.deleteDatabase },
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type * as Schemas from './schemas';
7
7
  export declare type APIKeyNameParam = Schemas.APIKeyName;
8
+ export declare type InviteIDParam = Schemas.InviteID;
8
9
  export declare type InviteKeyParam = Schemas.InviteKey;
9
10
  export declare type UserIDParam = Schemas.UserID;
10
11
  export declare type WorkspaceIDParam = Schemas.WorkspaceID;
@@ -1,21 +1,72 @@
1
1
  import { Constraint } from './filters';
2
2
  declare type ComparableType = number | Date;
3
+ /**
4
+ * Operator to restrict results to only values that are greater than the given value.
5
+ */
3
6
  export declare const gt: <T extends ComparableType>(value: T) => Constraint<T>;
7
+ /**
8
+ * Operator to restrict results to only values that are greater than or equal to the given value.
9
+ */
4
10
  export declare const ge: <T extends ComparableType>(value: T) => Constraint<T>;
11
+ /**
12
+ * Operator to restrict results to only values that are greater than or equal to the given value.
13
+ */
5
14
  export declare const gte: <T extends ComparableType>(value: T) => Constraint<T>;
15
+ /**
16
+ * Operator to restrict results to only values that are lower than the given value.
17
+ */
6
18
  export declare const lt: <T extends ComparableType>(value: T) => Constraint<T>;
19
+ /**
20
+ * Operator to restrict results to only values that are lower than or equal to the given value.
21
+ */
7
22
  export declare const lte: <T extends ComparableType>(value: T) => Constraint<T>;
23
+ /**
24
+ * Operator to restrict results to only values that are lower than or equal to the given value.
25
+ */
8
26
  export declare const le: <T extends ComparableType>(value: T) => Constraint<T>;
27
+ /**
28
+ * Operator to restrict results to only values that are not null.
29
+ */
9
30
  export declare const exists: (column: string) => Constraint<string>;
31
+ /**
32
+ * Operator to restrict results to only values that are null.
33
+ */
10
34
  export declare const notExists: (column: string) => Constraint<string>;
35
+ /**
36
+ * Operator to restrict results to only values that start with the given prefix.
37
+ */
11
38
  export declare const startsWith: (value: string) => Constraint<string>;
39
+ /**
40
+ * Operator to restrict results to only values that end with the given suffix.
41
+ */
12
42
  export declare const endsWith: (value: string) => Constraint<string>;
43
+ /**
44
+ * Operator to restrict results to only values that match the given pattern.
45
+ */
13
46
  export declare const pattern: (value: string) => Constraint<string>;
47
+ /**
48
+ * Operator to restrict results to only values that are equal to the given value.
49
+ */
14
50
  export declare const is: <T>(value: T) => Constraint<T>;
51
+ /**
52
+ * Operator to restrict results to only values that are not equal to the given value.
53
+ */
15
54
  export declare const isNot: <T>(value: T) => Constraint<T>;
55
+ /**
56
+ * Operator to restrict results to only values that contain the given value.
57
+ */
16
58
  export declare const contains: <T>(value: T) => Constraint<T>;
59
+ /**
60
+ * Operator to restrict results to only arrays that include the given value.
61
+ */
17
62
  export declare const includes: (value: string) => Constraint<string>;
63
+ /**
64
+ * Operator to restrict results to only arrays that include a value matching the given substring.
65
+ */
18
66
  export declare const includesSubstring: (value: string) => Constraint<string>;
67
+ /**
68
+ * Operator to restrict results to only arrays that include a value matching the given pattern.
69
+ */
19
70
  export declare const includesPattern: (value: string) => Constraint<string>;
20
71
  export declare const includesAll: (value: string) => Constraint<string>;
21
72
  export {};
@@ -1,39 +1,90 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.includesAll = exports.includesPattern = exports.includesSubstring = exports.includes = exports.contains = exports.isNot = exports.is = exports.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.le = exports.lte = exports.lt = exports.gte = exports.ge = exports.gt = void 0;
4
+ /**
5
+ * Operator to restrict results to only values that are greater than the given value.
6
+ */
4
7
  const gt = (value) => ({ $gt: value });
5
8
  exports.gt = gt;
9
+ /**
10
+ * Operator to restrict results to only values that are greater than or equal to the given value.
11
+ */
6
12
  const ge = (value) => ({ $ge: value });
7
13
  exports.ge = ge;
14
+ /**
15
+ * Operator to restrict results to only values that are greater than or equal to the given value.
16
+ */
8
17
  const gte = (value) => ({ $ge: value });
9
18
  exports.gte = gte;
19
+ /**
20
+ * Operator to restrict results to only values that are lower than the given value.
21
+ */
10
22
  const lt = (value) => ({ $lt: value });
11
23
  exports.lt = lt;
24
+ /**
25
+ * Operator to restrict results to only values that are lower than or equal to the given value.
26
+ */
12
27
  const lte = (value) => ({ $le: value });
13
28
  exports.lte = lte;
29
+ /**
30
+ * Operator to restrict results to only values that are lower than or equal to the given value.
31
+ */
14
32
  const le = (value) => ({ $le: value });
15
33
  exports.le = le;
34
+ /**
35
+ * Operator to restrict results to only values that are not null.
36
+ */
16
37
  const exists = (column) => ({ $exists: column });
17
38
  exports.exists = exists;
39
+ /**
40
+ * Operator to restrict results to only values that are null.
41
+ */
18
42
  const notExists = (column) => ({ $notExists: column });
19
43
  exports.notExists = notExists;
44
+ /**
45
+ * Operator to restrict results to only values that start with the given prefix.
46
+ */
20
47
  const startsWith = (value) => ({ $startsWith: value });
21
48
  exports.startsWith = startsWith;
49
+ /**
50
+ * Operator to restrict results to only values that end with the given suffix.
51
+ */
22
52
  const endsWith = (value) => ({ $endsWith: value });
23
53
  exports.endsWith = endsWith;
54
+ /**
55
+ * Operator to restrict results to only values that match the given pattern.
56
+ */
24
57
  const pattern = (value) => ({ $pattern: value });
25
58
  exports.pattern = pattern;
59
+ /**
60
+ * Operator to restrict results to only values that are equal to the given value.
61
+ */
26
62
  const is = (value) => ({ $is: value });
27
63
  exports.is = is;
64
+ /**
65
+ * Operator to restrict results to only values that are not equal to the given value.
66
+ */
28
67
  const isNot = (value) => ({ $isNot: value });
29
68
  exports.isNot = isNot;
69
+ /**
70
+ * Operator to restrict results to only values that contain the given value.
71
+ */
30
72
  const contains = (value) => ({ $contains: value });
31
73
  exports.contains = contains;
32
74
  // TODO: these can only be applied to columns of type "multiple"
75
+ /**
76
+ * Operator to restrict results to only arrays that include the given value.
77
+ */
33
78
  const includes = (value) => ({ $includes: value });
34
79
  exports.includes = includes;
80
+ /**
81
+ * Operator to restrict results to only arrays that include a value matching the given substring.
82
+ */
35
83
  const includesSubstring = (value) => ({ $includesSubstring: value });
36
84
  exports.includesSubstring = includesSubstring;
85
+ /**
86
+ * Operator to restrict results to only arrays that include a value matching the given pattern.
87
+ */
37
88
  const includesPattern = (value) => ({ $includesPattern: value });
38
89
  exports.includesPattern = includesPattern;
39
90
  const includesAll = (value) => ({ $includesAll: value });
@@ -15,15 +15,53 @@ export interface Paginable<T extends XataRecord, R extends XataRecord = T> {
15
15
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
16
16
  hasNextPage(): boolean;
17
17
  }
18
+ /**
19
+ * A Page contains a set of results from a query plus metadata about the retrieved
20
+ * set of values such as the cursor, required to retrieve additional records.
21
+ */
18
22
  export declare class Page<T extends XataRecord, R extends XataRecord> implements Paginable<T, R> {
19
23
  #private;
24
+ /**
25
+ * Page metadata, required to retrieve additional records.
26
+ */
20
27
  readonly meta: PaginationQueryMeta;
28
+ /**
29
+ * The set of results for this page.
30
+ */
21
31
  readonly records: R[];
22
32
  constructor(query: Query<T, R>, meta: PaginationQueryMeta, records?: R[]);
33
+ /**
34
+ * Retrieves the next page of results.
35
+ * @param size Maximum number of results to be retrieved.
36
+ * @param offset Number of results to skip when retrieving the results.
37
+ * @returns The next page or results.
38
+ */
23
39
  nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
40
+ /**
41
+ * Retrieves the previous page of results.
42
+ * @param size Maximum number of results to be retrieved.
43
+ * @param offset Number of results to skip when retrieving the results.
44
+ * @returns The previous page or results.
45
+ */
24
46
  previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
47
+ /**
48
+ * Retrieves the first page of results.
49
+ * @param size Maximum number of results to be retrieved.
50
+ * @param offset Number of results to skip when retrieving the results.
51
+ * @returns The first page or results.
52
+ */
25
53
  firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
54
+ /**
55
+ * Retrieves the last page of results.
56
+ * @param size Maximum number of results to be retrieved.
57
+ * @param offset Number of results to skip when retrieving the results.
58
+ * @returns The last page or results.
59
+ */
26
60
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
61
+ /**
62
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
63
+ * @returns Whether or not there will be additional results in the next page of results.
64
+ */
27
65
  hasNextPage(): boolean;
28
66
  }
29
67
  export declare type CursorNavigationOptions = {
@@ -22,6 +22,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
22
22
  var _Page_query;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.Page = void 0;
25
+ /**
26
+ * A Page contains a set of results from a query plus metadata about the retrieved
27
+ * set of values such as the cursor, required to retrieve additional records.
28
+ */
25
29
  class Page {
26
30
  constructor(query, meta, records = []) {
27
31
  _Page_query.set(this, void 0);
@@ -29,27 +33,55 @@ class Page {
29
33
  this.meta = meta;
30
34
  this.records = records;
31
35
  }
36
+ /**
37
+ * Retrieves the next page of results.
38
+ * @param size Maximum number of results to be retrieved.
39
+ * @param offset Number of results to skip when retrieving the results.
40
+ * @returns The next page or results.
41
+ */
32
42
  nextPage(size, offset) {
33
43
  return __awaiter(this, void 0, void 0, function* () {
34
44
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
35
45
  });
36
46
  }
47
+ /**
48
+ * Retrieves the previous page of results.
49
+ * @param size Maximum number of results to be retrieved.
50
+ * @param offset Number of results to skip when retrieving the results.
51
+ * @returns The previous page or results.
52
+ */
37
53
  previousPage(size, offset) {
38
54
  return __awaiter(this, void 0, void 0, function* () {
39
55
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
40
56
  });
41
57
  }
58
+ /**
59
+ * Retrieves the first page of results.
60
+ * @param size Maximum number of results to be retrieved.
61
+ * @param offset Number of results to skip when retrieving the results.
62
+ * @returns The first page or results.
63
+ */
42
64
  firstPage(size, offset) {
43
65
  return __awaiter(this, void 0, void 0, function* () {
44
66
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
45
67
  });
46
68
  }
69
+ /**
70
+ * Retrieves the last page of results.
71
+ * @param size Maximum number of results to be retrieved.
72
+ * @param offset Number of results to skip when retrieving the results.
73
+ * @returns The last page or results.
74
+ */
47
75
  lastPage(size, offset) {
48
76
  return __awaiter(this, void 0, void 0, function* () {
49
77
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
50
78
  });
51
79
  }
52
80
  // TODO: We need to add something on the backend if we want a hasPreviousPage
81
+ /**
82
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
83
+ * @returns Whether or not there will be additional results in the next page of results.
84
+ */
53
85
  hasNextPage() {
54
86
  return this.meta.page.more;
55
87
  }
@@ -14,25 +14,94 @@ export declare type QueryTableOptions = {
14
14
  page?: PageConfig;
15
15
  columns?: ColumnsFilter;
16
16
  };
17
+ /**
18
+ * Query objects contain the information of all filters, sorting, etc. to be included in the database query.
19
+ *
20
+ * Query objects are immutable. Any method that adds more constraints or options to the query will return
21
+ * a new Query object containing the both the previous and the new constraints and options.
22
+ */
17
23
  export declare class Query<T extends XataRecord, R extends XataRecord = T> implements Paginable<T, R> {
18
24
  #private;
19
25
  readonly meta: PaginationQueryMeta;
20
26
  readonly records: R[];
21
27
  constructor(repository: Repository<T> | null, table: string, data: Partial<QueryTableOptions>, parent?: Partial<QueryTableOptions>);
22
28
  getQueryOptions(): QueryTableOptions;
29
+ /**
30
+ * Builds a new query object representing a logical OR between the given subqueries.
31
+ * @param queries An array of subqueries.
32
+ * @returns A new Query object.
33
+ */
23
34
  any(...queries: Query<T, R>[]): Query<T, R>;
35
+ /**
36
+ * Builds a new query object representing a logical AND between the given subqueries.
37
+ * @param queries An array of subqueries.
38
+ * @returns A new Query object.
39
+ */
24
40
  all(...queries: Query<T, R>[]): Query<T, R>;
41
+ /**
42
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
43
+ * @param queries An array of subqueries.
44
+ * @returns A new Query object.
45
+ */
25
46
  not(...queries: Query<T, R>[]): Query<T, R>;
47
+ /**
48
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
49
+ * @param queries An array of subqueries.
50
+ * @returns A new Query object.
51
+ */
26
52
  none(...queries: Query<T, R>[]): Query<T, R>;
53
+ /**
54
+ * Builds a new query object adding one or more constraints. Examples:
55
+ *
56
+ * ```
57
+ * query.filter("columnName", columnValue)
58
+ * query.filter({
59
+ * "columnName": columnValue
60
+ * })
61
+ * query.filter({
62
+ * "columnName": operator(columnValue) // Use gt, gte, lt, lte, startsWith,...
63
+ * })
64
+ * ```
65
+ *
66
+ * @param constraints
67
+ * @returns A new Query object.
68
+ */
27
69
  filter(constraints: FilterConstraints<T>): Query<T, R>;
28
- filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
70
+ filter<F extends keyof Selectable<T>>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
71
+ /**
72
+ * Builds a new query with a new sort option.
73
+ * @param column The column name.
74
+ * @param direction The direction. Either ascending or descending.
75
+ * @returns A new Query object.
76
+ */
29
77
  sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
78
+ /**
79
+ * Builds a new query specifying the set of columns to be returned in the query response.
80
+ * @param columns Array of column names to be returned by the query.
81
+ * @returns A new Query object.
82
+ */
30
83
  select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
31
- getPaginated<Options extends QueryOptions<T>>(options?: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
84
+ getPaginated<Options extends QueryOptions<T>>(options?: Options): Promise<Page<T, typeof options extends {
85
+ columns: SelectableColumn<T>[];
86
+ } ? Select<T, typeof options['columns'][number]> : R>>;
32
87
  [Symbol.asyncIterator](): AsyncIterableIterator<R>;
33
88
  getIterator(chunk: number, options?: Omit<QueryOptions<T>, 'page'>): AsyncGenerator<R[]>;
34
- getMany<Options extends QueryOptions<T>>(options?: Options): Promise<(typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R)[]>;
35
- getOne<Options extends Omit<QueryOptions<T>, 'page'>>(options?: Options): Promise<(typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R) | null>;
89
+ /**
90
+ * Performs the query in the database and returns a set of results.
91
+ * @param options Additional options to be used when performing the query.
92
+ * @returns An array of records from the database.
93
+ */
94
+ getMany<Options extends QueryOptions<T>>(options?: Options): Promise<(typeof options extends {
95
+ columns: SelectableColumn<T>[];
96
+ } ? Select<T, typeof options['columns'][number]> : R)[]>;
97
+ /**
98
+ * Performs the query in the database and returns the first result.
99
+ * @param options Additional options to be used when performing the query.
100
+ * @returns The first record that matches the query, or null if no record matched the query.
101
+ */
102
+ getOne<Options extends Omit<QueryOptions<T>, 'page'>>(options?: Options): Promise<(typeof options extends {
103
+ columns: SelectableColumn<T>[];
104
+ } ? Select<T, typeof options['columns'][number]> : R) | null>;
36
105
  /**async deleteAll(): Promise<number> {
37
106
  // TODO: Return number of affected rows
38
107
  return 0;
@@ -42,6 +42,12 @@ var _Query_table, _Query_repository, _Query_data;
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.Query = void 0;
44
44
  const lang_1 = require("../util/lang");
45
+ /**
46
+ * Query objects contain the information of all filters, sorting, etc. to be included in the database query.
47
+ *
48
+ * Query objects are immutable. Any method that adds more constraints or options to the query will return
49
+ * a new Query object containing the both the previous and the new constraints and options.
50
+ */
45
51
  class Query {
46
52
  constructor(repository, table, data, parent) {
47
53
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
@@ -76,18 +82,38 @@ class Query {
76
82
  getQueryOptions() {
77
83
  return __classPrivateFieldGet(this, _Query_data, "f");
78
84
  }
85
+ /**
86
+ * Builds a new query object representing a logical OR between the given subqueries.
87
+ * @param queries An array of subqueries.
88
+ * @returns A new Query object.
89
+ */
79
90
  any(...queries) {
80
91
  const $any = queries.map((query) => query.getQueryOptions().filter);
81
92
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
82
93
  }
94
+ /**
95
+ * Builds a new query object representing a logical AND between the given subqueries.
96
+ * @param queries An array of subqueries.
97
+ * @returns A new Query object.
98
+ */
83
99
  all(...queries) {
84
100
  const $all = queries.map((query) => query.getQueryOptions().filter);
85
101
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
86
102
  }
103
+ /**
104
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
105
+ * @param queries An array of subqueries.
106
+ * @returns A new Query object.
107
+ */
87
108
  not(...queries) {
88
109
  const $not = queries.map((query) => query.getQueryOptions().filter);
89
110
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
90
111
  }
112
+ /**
113
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
114
+ * @param queries An array of subqueries.
115
+ * @returns A new Query object.
116
+ */
91
117
  none(...queries) {
92
118
  const $none = queries.map((query) => query.getQueryOptions().filter);
93
119
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
@@ -105,17 +131,26 @@ class Query {
105
131
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
106
132
  }
107
133
  }
134
+ /**
135
+ * Builds a new query with a new sort option.
136
+ * @param column The column name.
137
+ * @param direction The direction. Either ascending or descending.
138
+ * @returns A new Query object.
139
+ */
108
140
  sort(column, direction) {
109
141
  const sort = Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Query_data, "f").sort), { [column]: direction });
110
142
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
111
143
  }
144
+ /**
145
+ * Builds a new query specifying the set of columns to be returned in the query response.
146
+ * @param columns Array of column names to be returned by the query.
147
+ * @returns A new Query object.
148
+ */
112
149
  select(columns) {
113
150
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { columns }, __classPrivateFieldGet(this, _Query_data, "f"));
114
151
  }
115
152
  getPaginated(options = {}) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- return __classPrivateFieldGet(this, _Query_repository, "f").query(this, options);
118
- });
153
+ return __classPrivateFieldGet(this, _Query_repository, "f").query(this, options);
119
154
  }
120
155
  [(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
121
156
  return __asyncGenerator(this, arguments, function* _a() {
@@ -147,12 +182,22 @@ class Query {
147
182
  }
148
183
  });
149
184
  }
185
+ /**
186
+ * Performs the query in the database and returns a set of results.
187
+ * @param options Additional options to be used when performing the query.
188
+ * @returns An array of records from the database.
189
+ */
150
190
  getMany(options = {}) {
151
191
  return __awaiter(this, void 0, void 0, function* () {
152
192
  const { records } = yield this.getPaginated(options);
153
193
  return records;
154
194
  });
155
195
  }
196
+ /**
197
+ * Performs the query in the database and returns the first result.
198
+ * @param options Additional options to be used when performing the query.
199
+ * @returns The first record that matches the query, or null if no record matched the query.
200
+ */
156
201
  getOne(options = {}) {
157
202
  return __awaiter(this, void 0, void 0, function* () {
158
203
  const records = yield this.getMany(Object.assign(Object.assign({}, options), { page: { size: 1 } }));
@@ -164,24 +209,16 @@ class Query {
164
209
  return 0;
165
210
  }**/
166
211
  nextPage(size, offset) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- return this.firstPage(size, offset);
169
- });
212
+ return this.firstPage(size, offset);
170
213
  }
171
214
  previousPage(size, offset) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- return this.firstPage(size, offset);
174
- });
215
+ return this.firstPage(size, offset);
175
216
  }
176
217
  firstPage(size, offset) {
177
- return __awaiter(this, void 0, void 0, function* () {
178
- return this.getPaginated({ page: { size, offset } });
179
- });
218
+ return this.getPaginated({ page: { size, offset } });
180
219
  }
181
220
  lastPage(size, offset) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- return this.getPaginated({ page: { size, offset, before: 'end' } });
184
- });
221
+ return this.getPaginated({ page: { size, offset, before: 'end' } });
185
222
  }
186
223
  hasNextPage() {
187
224
  return this.meta.page.more;
@@ -1,10 +1,36 @@
1
1
  import { Selectable } from './selection';
2
+ /**
3
+ * Represents a persisted record from the database.
4
+ */
2
5
  export interface XataRecord {
6
+ /**
7
+ * Unique id of this record.
8
+ */
3
9
  id: string;
10
+ /**
11
+ * Metadata of this record.
12
+ */
4
13
  xata: {
14
+ /**
15
+ * Number that is increased every time the record is updated.
16
+ */
5
17
  version: number;
6
18
  };
19
+ /**
20
+ * Retrieves a refreshed copy of the current record from the database.
21
+ */
7
22
  read(): Promise<this>;
23
+ /**
24
+ * Performs a partial update of the current record. On success a new object is
25
+ * returned and the current object is not mutated.
26
+ * @param data The columns and their values that have to be updated.
27
+ * @returns A new record containing the latest values for all the columns of the current record.
28
+ */
8
29
  update(data: Partial<Selectable<this>>): Promise<this>;
30
+ /**
31
+ * Performs a deletion of the current record in the database.
32
+ *
33
+ * @throws If the record was already deleted or if an error happened while performing the deletion.
34
+ */
9
35
  delete(): Promise<void>;
10
36
  }
@@ -4,14 +4,52 @@ import { Query, QueryOptions } from './query';
4
4
  import { XataRecord } from './record';
5
5
  import { Selectable, SelectableColumn, Select } from './selection';
6
6
  export declare type Links = Record<string, Array<string[]>>;
7
+ /**
8
+ * Common interface for performing operations on a table.
9
+ */
7
10
  export declare abstract class Repository<T extends XataRecord> extends Query<T> {
11
+ /**
12
+ * Creates a record in the table.
13
+ * @param object Object containing the column names with their values to be stored in the table.
14
+ * @returns The full persisted record.
15
+ */
8
16
  abstract create(object: Selectable<T>): Promise<T>;
17
+ /**
18
+ * Creates multiple records in the table.
19
+ * @param objects Array of objects with the column names and the values to be stored in the table.
20
+ * @returns Array of the persisted records.
21
+ */
9
22
  abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
23
+ /**
24
+ * Queries a single record from the table given its unique id.
25
+ * @param id The unique id.
26
+ * @returns The persisted record for the given id or null if the record could not be found.
27
+ */
10
28
  abstract read(id: string): Promise<T | null>;
29
+ /**
30
+ * Partially update a single record given its unique id.
31
+ * @param id The unique id.
32
+ * @param object The column names and their values that have to be updatd.
33
+ * @returns The full persisted record.
34
+ */
11
35
  abstract update(id: string, object: Partial<Selectable<T>>): Promise<T>;
36
+ /**
37
+ * Updates or creates a single record. If a record exists with the given id,
38
+ * it will be update, otherwise a new record will be created.
39
+ * @param id A unique id.
40
+ * @param object The column names and the values to be persisted.
41
+ * @returns The full persisted record.
42
+ */
12
43
  abstract upsert(id: string, object: Selectable<T>): Promise<T>;
44
+ /**
45
+ * Deletes a record given its unique id.
46
+ * @param id The unique id.
47
+ * @throws If the record could not be found or there was an error while performing the deletion.
48
+ */
13
49
  abstract delete(id: string): void;
14
- 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>>;
50
+ abstract query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options extends {
51
+ columns: SelectableColumn<T>[];
52
+ } ? Select<T, typeof options['columns'][number]> : R>>;
15
53
  }
16
54
  export declare class RestRepository<T extends XataRecord> extends Repository<T> {
17
55
  #private;
@@ -22,7 +60,9 @@ export declare class RestRepository<T extends XataRecord> extends Repository<T>
22
60
  update(recordId: string, object: Partial<Selectable<T>>): Promise<T>;
23
61
  upsert(recordId: string, object: Selectable<T>): Promise<T>;
24
62
  delete(recordId: string): Promise<void>;
25
- 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>>;
63
+ query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options?: Options): Promise<Page<T, typeof options extends {
64
+ columns: SelectableColumn<T>[];
65
+ } ? Select<T, typeof options['columns'][number]> : R>>;
26
66
  }
27
67
  interface RepositoryFactory {
28
68
  createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
@@ -35,9 +75,18 @@ declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchS
35
75
  declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
36
76
  declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
37
77
  export declare type XataClientOptions = {
78
+ /**
79
+ * Fetch implementation. This option is only required if the runtime does not include a fetch implementation
80
+ * available in the global scope. If you are running your code on Deno or Cloudflare workers for example,
81
+ * you won't need to provide a specific fetch implementation. But for most versions of Node.js you'll need
82
+ * to provide one. Such as cross-fetch, node-fetch or isomorphic-fetch.
83
+ */
38
84
  fetch?: FetchImpl;
39
85
  databaseURL?: string;
40
86
  branch: BranchStrategyOption;
87
+ /**
88
+ * API key to be used. You can create one in your account settings at https://app.xata.io/settings.
89
+ */
41
90
  apiKey: string;
42
91
  repositoryFactory?: RepositoryFactory;
43
92
  };
@@ -45,7 +94,7 @@ export declare class BaseClient<D extends Record<string, Repository<any>>> {
45
94
  #private;
46
95
  options: XataClientOptions;
47
96
  db: D;
48
- constructor(options: XataClientOptions, links: Links);
97
+ constructor(options: XataClientOptions, links?: Links);
49
98
  initObject<T>(table: string, object: object): T;
50
99
  getBranch(): Promise<string>;
51
100
  }
@@ -33,6 +33,9 @@ const api_1 = require("../api");
33
33
  const filters_1 = require("./filters");
34
34
  const pagination_1 = require("./pagination");
35
35
  const query_1 = require("./query");
36
+ /**
37
+ * Common interface for performing operations on a table.
38
+ */
36
39
  class Repository extends query_1.Query {
37
40
  }
38
41
  exports.Repository = Repository;
@@ -121,7 +124,7 @@ class RestRepository extends Repository {
121
124
  yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
122
125
  });
123
126
  }
124
- query(query, options) {
127
+ query(query, options = {}) {
125
128
  var _a, _b, _c;
126
129
  return __awaiter(this, void 0, void 0, function* () {
127
130
  const data = query.getQueryOptions();
@@ -165,7 +168,7 @@ class RestRespositoryFactory {
165
168
  }
166
169
  exports.RestRespositoryFactory = RestRespositoryFactory;
167
170
  class BaseClient {
168
- constructor(options, links) {
171
+ constructor(options, links = {}) {
169
172
  _BaseClient_links.set(this, void 0);
170
173
  _BaseClient_branch.set(this, void 0);
171
174
  if (!options.databaseURL || !options.apiKey || !options.branch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-beta.4e4e7fc",
3
+ "version": "0.0.0-beta.50e1cc9",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,5 +20,5 @@
20
20
  "url": "https://github.com/xataio/client-ts/issues"
21
21
  },
22
22
  "homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
23
- "gitHead": "4e4e7fc8f16c42c25a78e1094ab8bc2202f4b0fe"
23
+ "gitHead": "50e1cc94906232f6a384f222d482b0f871cfecb6"
24
24
  }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "lib": ["dom", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "esModuleInterop": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "strict": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "module": "CommonJS",
13
+ "moduleResolution": "node",
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "noEmit": false,
17
+ "outDir": "dist",
18
+ "declaration": true
19
+ },
20
+ "include": ["src"]
21
+ }