@xata.io/client 0.5.1 → 0.6.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.
package/.eslintrc.cjs ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ ignorePatterns: ["dist"],
3
+ parserOptions: {
4
+ ecmaVersion: 2020,
5
+ sourceType: 'module',
6
+ project: 'client/tsconfig.json'
7
+ },
8
+ rules: {
9
+ '@typescript-eslint/no-explicit-any': 'off',
10
+ '@typescript-eslint/ban-types': 'off',
11
+ '@typescript-eslint/no-floating-promises': 'error',
12
+ }
13
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 084f5df: Add type inference for columns
8
+ - bb73c89: Unify create and insert in a single method overload
9
+
10
+ ### Patch Changes
11
+
12
+ - 716c487: Forward nullable types on links
13
+ - bb66bb2: Fix error handling with createMany
14
+ - 084f5df: Fix circular dependencies on selectable column
15
+
3
16
  ## 0.5.1
4
17
 
5
18
  ### Patch Changes
@@ -10,12 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.fetch = void 0;
13
+ /* eslint-disable @typescript-eslint/no-throw-literal */
14
+ /* eslint-disable @typescript-eslint/ban-types */
15
+ const lang_1 = require("../util/lang");
13
16
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
14
17
  const query = new URLSearchParams(queryParams).toString();
15
18
  const queryString = query.length > 0 ? `?${query}` : '';
16
19
  return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
17
20
  };
18
- const fallbackError = { message: 'Network response was not ok' };
19
21
  function buildBaseUrl({ path, workspacesApiUrl, apiUrl, pathParams }) {
20
22
  if (!(pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace))
21
23
  return `${apiUrl}${path}`;
@@ -51,28 +53,21 @@ function fetch({ url: path, method, body, headers, pathParams, queryParams, fetc
51
53
  if (response.ok) {
52
54
  return jsonResponse;
53
55
  }
54
- if (jsonResponse.message) {
55
- throw withStatus({ message: jsonResponse.message }, response.status);
56
- }
57
- else {
58
- throw withStatus(fallbackError, response.status);
59
- }
56
+ const { message = 'Unknown error', errors } = jsonResponse;
57
+ throw withStatus({ message, errors }, response.status);
60
58
  }
61
59
  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') {
60
+ if (isError(e)) {
69
61
  throw withStatus(e, response.status);
70
62
  }
71
63
  else {
72
- throw withStatus(fallbackError, response.status);
64
+ throw withStatus({ message: 'Network response was not ok' }, response.status);
73
65
  }
74
66
  }
75
67
  });
76
68
  }
77
69
  exports.fetch = fetch;
78
- const withStatus = (error, status) => (Object.assign(Object.assign({}, error), { status }));
70
+ const isError = (error) => {
71
+ return (0, lang_1.isObject)(error) && (0, lang_1.isString)(error.message);
72
+ };
73
+ const withStatus = (error, status) => (0, lang_1.compactObject)(Object.assign(Object.assign({}, error), { status }));
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHostUrl = void 0;
4
+ const lang_1 = require("../util/lang");
4
5
  function getHostUrl(provider, type) {
5
6
  if (isValidAlias(provider)) {
6
7
  return providers[provider][type];
@@ -22,8 +23,8 @@ const providers = {
22
23
  }
23
24
  };
24
25
  function isValidAlias(alias) {
25
- return typeof alias === 'string' && Object.keys(providers).includes(alias);
26
+ return (0, lang_1.isString)(alias) && Object.keys(providers).includes(alias);
26
27
  }
27
28
  function isValidBuilder(builder) {
28
- return typeof builder === 'object' && typeof builder.main === 'string' && typeof builder.workspaces === 'string';
29
+ return (0, lang_1.isObject)(builder) && (0, lang_1.isString)(builder.main) && (0, lang_1.isString)(builder.workspaces);
29
30
  }
@@ -19,6 +19,12 @@ export declare type AuthError = {
19
19
  id?: string;
20
20
  message: string;
21
21
  };
22
+ export declare type BulkError = {
23
+ errors: {
24
+ message?: string;
25
+ status?: number;
26
+ }[];
27
+ };
22
28
  export declare type BranchMigrationPlan = {
23
29
  version: number;
24
30
  migration: Schemas.BranchMigration;
@@ -1,12 +1,14 @@
1
+ import { XataRecord } from './record';
2
+ import { SelectableColumn } from './selection';
1
3
  export declare type SortDirection = 'asc' | 'desc';
2
- export declare type SortFilterExtended<T> = {
3
- column: keyof T;
4
+ export declare type SortFilterExtended<T extends XataRecord> = {
5
+ column: SelectableColumn<T>;
4
6
  direction?: SortDirection;
5
7
  };
6
- export declare type SortFilter<T> = SortFilterExtended<T> | keyof T;
7
- export declare function isSortFilterObject<T>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
8
+ export declare type SortFilter<T extends XataRecord> = SelectableColumn<T> | SortFilterExtended<T>;
9
+ export declare function isSortFilterObject<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
8
10
  export declare type FilterOperator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
9
- export declare function buildSortFilter<T>(filter?: SortFilter<T> | SortFilter<T>[]): {
11
+ export declare function buildSortFilter<T extends XataRecord>(filter?: SortFilter<T> | SortFilter<T>[]): {
10
12
  [key: string]: SortDirection;
11
13
  } | undefined;
12
14
  export declare type Constraint<T> = {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildSortFilter = exports.isSortFilterObject = void 0;
4
+ const lang_1 = require("../util/lang");
4
5
  function isSortFilterObject(filter) {
5
- return typeof filter === 'object' && filter.column !== undefined;
6
+ return (0, lang_1.isObject)(filter) && filter.column !== undefined;
6
7
  }
7
8
  exports.isSortFilterObject = isSortFilterObject;
8
9
  function buildSortFilter(filter) {
@@ -1,6 +1,7 @@
1
1
  export * from './operators';
2
2
  export * from './pagination';
3
3
  export { Query } from './query';
4
+ export { isIdentifiable, isXataRecord } from './record';
4
5
  export type { Identifiable, XataRecord } from './record';
5
6
  export { BaseClient, Repository, RestRepository, RestRespositoryFactory } from './repository';
6
7
  export type { XataClientOptions } from './repository';
@@ -14,11 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.BaseClient = exports.Query = void 0;
17
+ exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.BaseClient = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
18
18
  __exportStar(require("./operators"), exports);
19
19
  __exportStar(require("./pagination"), exports);
20
20
  var query_1 = require("./query");
21
21
  Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
22
+ var record_1 = require("./record");
23
+ Object.defineProperty(exports, "isIdentifiable", { enumerable: true, get: function () { return record_1.isIdentifiable; } });
24
+ Object.defineProperty(exports, "isXataRecord", { enumerable: true, get: function () { return record_1.isXataRecord; } });
22
25
  var repository_1 = require("./repository");
23
26
  Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
24
27
  Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
@@ -6,20 +6,20 @@ export declare type PaginationQueryMeta = {
6
6
  more: boolean;
7
7
  };
8
8
  };
9
- export interface Paginable<T extends XataRecord, R extends XataRecord = T> {
9
+ export interface Paginable<Record extends XataRecord, Result extends XataRecord = Record> {
10
10
  meta: PaginationQueryMeta;
11
- records: R[];
12
- nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
13
- previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
14
- firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
15
- lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
11
+ records: Result[];
12
+ nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
13
+ previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
14
+ firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
15
+ lastPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
16
16
  hasNextPage(): boolean;
17
17
  }
18
18
  /**
19
19
  * A Page contains a set of results from a query plus metadata about the retrieved
20
20
  * set of values such as the cursor, required to retrieve additional records.
21
21
  */
22
- export declare class Page<T extends XataRecord, R extends XataRecord = T> implements Paginable<T, R> {
22
+ export declare class Page<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
23
23
  #private;
24
24
  /**
25
25
  * Page metadata, required to retrieve additional records.
@@ -28,36 +28,36 @@ export declare class Page<T extends XataRecord, R extends XataRecord = T> implem
28
28
  /**
29
29
  * The set of results for this page.
30
30
  */
31
- readonly records: R[];
32
- constructor(query: Query<T, R>, meta: PaginationQueryMeta, records?: R[]);
31
+ readonly records: Result[];
32
+ constructor(query: Query<Record, Result>, meta: PaginationQueryMeta, records?: Result[]);
33
33
  /**
34
34
  * Retrieves the next page of results.
35
35
  * @param size Maximum number of results to be retrieved.
36
36
  * @param offset Number of results to skip when retrieving the results.
37
37
  * @returns The next page or results.
38
38
  */
39
- nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
39
+ nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
40
40
  /**
41
41
  * Retrieves the previous page of results.
42
42
  * @param size Maximum number of results to be retrieved.
43
43
  * @param offset Number of results to skip when retrieving the results.
44
44
  * @returns The previous page or results.
45
45
  */
46
- previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
46
+ previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
47
47
  /**
48
48
  * Retrieves the first page of results.
49
49
  * @param size Maximum number of results to be retrieved.
50
50
  * @param offset Number of results to skip when retrieving the results.
51
51
  * @returns The first page or results.
52
52
  */
53
- firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
53
+ firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
54
54
  /**
55
55
  * Retrieves the last page of results.
56
56
  * @param size Maximum number of results to be retrieved.
57
57
  * @param offset Number of results to skip when retrieving the results.
58
58
  * @returns The last page or results.
59
59
  */
60
- lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
60
+ lastPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
61
61
  /**
62
62
  * Shortcut method to check if there will be additional results if the next page of results is retrieved.
63
63
  * @returns Whether or not there will be additional results in the next page of results.
@@ -77,7 +77,6 @@ class Page {
77
77
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
78
78
  });
79
79
  }
80
- // TODO: We need to add something on the backend if we want a hasPreviousPage
81
80
  /**
82
81
  * Shortcut method to check if there will be additional results if the next page of results is retrieved.
83
82
  * @returns Whether or not there will be additional results in the next page of results.
@@ -1,56 +1,52 @@
1
- import { ColumnsFilter, FilterExpression, PageConfig, SortExpression } from '../api/schemas';
1
+ import { FilterExpression } from '../api/schemas';
2
+ import { NonEmptyArray, RequiredBy } from '../util/types';
2
3
  import { DeepConstraint, FilterConstraints, SortDirection, SortFilter } from './filters';
3
4
  import { Page, Paginable, PaginationOptions, PaginationQueryMeta } from './pagination';
4
5
  import { XataRecord } from './record';
5
6
  import { Repository } from './repository';
6
- import { Select, Selectable, SelectableColumn } from './selection';
7
+ import { SelectableColumn, SelectedPick, ValueAtColumn } from './selection';
7
8
  export declare type QueryOptions<T extends XataRecord> = {
8
9
  page?: PaginationOptions;
9
- columns?: Extract<keyof Selectable<T>, string>[];
10
+ columns?: NonEmptyArray<SelectableColumn<T>>;
11
+ filter?: FilterExpression;
10
12
  sort?: SortFilter<T> | SortFilter<T>[];
11
13
  };
12
- export declare type QueryTableOptions = {
13
- filter: FilterExpression;
14
- sort?: SortExpression;
15
- page?: PageConfig;
16
- columns?: ColumnsFilter;
17
- };
18
14
  /**
19
15
  * Query objects contain the information of all filters, sorting, etc. to be included in the database query.
20
16
  *
21
17
  * Query objects are immutable. Any method that adds more constraints or options to the query will return
22
18
  * a new Query object containing the both the previous and the new constraints and options.
23
19
  */
24
- export declare class Query<T extends XataRecord, R extends XataRecord = T> implements Paginable<T, R> {
20
+ export declare class Query<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
25
21
  #private;
26
22
  readonly meta: PaginationQueryMeta;
27
- readonly records: R[];
28
- constructor(repository: Repository<T> | null, table: string, data: Partial<QueryTableOptions>, parent?: Partial<QueryTableOptions>);
29
- getQueryOptions(): QueryTableOptions;
23
+ readonly records: Result[];
24
+ constructor(repository: Repository<Record> | null, table: string, data: Partial<QueryOptions<Record>>, parent?: Partial<QueryOptions<Record>>);
25
+ getQueryOptions(): QueryOptions<Record>;
30
26
  /**
31
27
  * Builds a new query object representing a logical OR between the given subqueries.
32
28
  * @param queries An array of subqueries.
33
29
  * @returns A new Query object.
34
30
  */
35
- any(...queries: Query<T, R>[]): Query<T, R>;
31
+ any(...queries: Query<Record, Result>[]): Query<Record, Result>;
36
32
  /**
37
33
  * Builds a new query object representing a logical AND between the given subqueries.
38
34
  * @param queries An array of subqueries.
39
35
  * @returns A new Query object.
40
36
  */
41
- all(...queries: Query<T, R>[]): Query<T, R>;
37
+ all(...queries: Query<Record, Result>[]): Query<Record, Result>;
42
38
  /**
43
39
  * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
44
40
  * @param queries An array of subqueries.
45
41
  * @returns A new Query object.
46
42
  */
47
- not(...queries: Query<T, R>[]): Query<T, R>;
43
+ not(...queries: Query<Record, Result>[]): Query<Record, Result>;
48
44
  /**
49
45
  * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
50
46
  * @param queries An array of subqueries.
51
47
  * @returns A new Query object.
52
48
  */
53
- none(...queries: Query<T, R>[]): Query<T, R>;
49
+ none(...queries: Query<Record, Result>[]): Query<Record, Result>;
54
50
  /**
55
51
  * Builds a new query object adding one or more constraints. Examples:
56
52
  *
@@ -67,63 +63,56 @@ export declare class Query<T extends XataRecord, R extends XataRecord = T> imple
67
63
  * @param constraints
68
64
  * @returns A new Query object.
69
65
  */
70
- filter(constraints: FilterConstraints<T>): Query<T, R>;
71
- filter<F extends keyof Selectable<T>>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
66
+ filter(constraints: FilterConstraints<Record>): Query<Record, Result>;
67
+ filter<F extends SelectableColumn<Record>>(column: F, value: FilterConstraints<ValueAtColumn<Record, F>> | DeepConstraint<ValueAtColumn<Record, F>>): Query<Record, Result>;
72
68
  /**
73
69
  * Builds a new query with a new sort option.
74
70
  * @param column The column name.
75
71
  * @param direction The direction. Either ascending or descending.
76
72
  * @returns A new Query object.
77
73
  */
78
- sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
74
+ sort<F extends SelectableColumn<Record>>(column: F, direction: SortDirection): Query<Record, Result>;
79
75
  /**
80
76
  * Builds a new query specifying the set of columns to be returned in the query response.
81
77
  * @param columns Array of column names to be returned by the query.
82
78
  * @returns A new Query object.
83
79
  */
84
- select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
85
- getPaginated<Options extends QueryOptions<T>>(options?: Options): Promise<Page<T, GetWithColumnOptions<T, R, typeof options>>>;
86
- [Symbol.asyncIterator](): AsyncIterableIterator<R>;
87
- getIterator<Options extends QueryOptions<T>>(chunk: number, options?: Omit<Options, 'page'>): AsyncGenerator<GetWithColumnOptions<T, R, typeof options>[]>;
80
+ select<K extends SelectableColumn<Record>>(columns: NonEmptyArray<K>): Query<Record, SelectedPick<Record, NonEmptyArray<K>>>;
81
+ getPaginated(): Promise<Page<Record, Result>>;
82
+ getPaginated(options: Omit<QueryOptions<Record>, 'columns'>): Promise<Page<Record, Result>>;
83
+ getPaginated<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<Page<Record, SelectedPick<Record, typeof options['columns']>>>;
84
+ [Symbol.asyncIterator](): AsyncIterableIterator<Result>;
85
+ getIterator(chunk: number): AsyncGenerator<Result[]>;
86
+ getIterator(chunk: number, options: Omit<QueryOptions<Record>, 'columns' | 'page'>): AsyncGenerator<Result[]>;
87
+ getIterator<Options extends RequiredBy<Omit<QueryOptions<Record>, 'page'>, 'columns'>>(chunk: number, options: Options): AsyncGenerator<SelectedPick<Record, typeof options['columns']>[]>;
88
88
  /**
89
89
  * Performs the query in the database and returns a set of results.
90
90
  * @param options Additional options to be used when performing the query.
91
91
  * @returns An array of records from the database.
92
92
  */
93
- getMany<Options extends QueryOptions<T>>(options?: Options): Promise<GetWithColumnOptions<T, R, typeof options>[]>;
93
+ getMany(): Promise<Result[]>;
94
+ getMany(options: Omit<QueryOptions<Record>, 'columns'>): Promise<Result[]>;
95
+ getMany<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<SelectedPick<Record, typeof options['columns']>[]>;
94
96
  /**
95
97
  * Performs the query in the database and returns all the results.
96
98
  * Warning: If there are a large number of results, this method can have performance implications.
97
99
  * @param options Additional options to be used when performing the query.
98
100
  * @returns An array of records from the database.
99
101
  */
100
- getAll<Options extends QueryOptions<T>>(chunk?: number, options?: Omit<Options, 'page'>): Promise<GetWithColumnOptions<T, R, typeof options>[]>;
102
+ getAll(chunk?: number): Promise<Result[]>;
103
+ getAll(chunk: number | undefined, options: Omit<QueryOptions<Record>, 'columns' | 'page'>): Promise<Result[]>;
104
+ getAll<Options extends RequiredBy<Omit<QueryOptions<Record>, 'page'>, 'columns'>>(chunk: number | undefined, options: Options): Promise<SelectedPick<Record, typeof options['columns']>[]>;
101
105
  /**
102
106
  * Performs the query in the database and returns the first result.
103
107
  * @param options Additional options to be used when performing the query.
104
108
  * @returns The first record that matches the query, or null if no record matched the query.
105
109
  */
106
- getOne<Options extends Omit<QueryOptions<T>, 'page'>>(options?: Options): Promise<GetWithColumnOptions<T, R, typeof options> | null>;
107
- /**async deleteAll(): Promise<number> {
108
- // TODO: Return number of affected rows
109
- return 0;
110
- }**/
111
- nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
112
- previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
113
- firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
114
- lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
110
+ getOne(): Promise<Result | null>;
111
+ getOne(options: Omit<QueryOptions<Record>, 'columns' | 'page'>): Promise<Result | null>;
112
+ getOne<Options extends RequiredBy<Omit<QueryOptions<Record>, 'page'>, 'columns'>>(options: Options): Promise<SelectedPick<Record, typeof options['columns']> | null>;
113
+ nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
114
+ previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
115
+ firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
116
+ lastPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
115
117
  hasNextPage(): boolean;
116
118
  }
117
- /**
118
- * Helper type to read options and compute the correct type for the result values
119
- * T: Original type
120
- * R: Default destination type
121
- * Options: QueryOptions
122
- *
123
- * If the columns are overriden in the options, the result type is the pick of the original type and the columns
124
- * If the columns are not overriden, the result type is the default destination type
125
- */
126
- declare type GetWithColumnOptions<T, R, Options> = Options extends {
127
- columns: SelectableColumn<T>[];
128
- } ? Select<T, Options['columns'][number]> : R;
129
- export {};
@@ -51,7 +51,7 @@ const pagination_1 = require("./pagination");
51
51
  */
52
52
  class Query {
53
53
  constructor(repository, table, data, parent) {
54
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
54
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
55
55
  _Query_table.set(this, void 0);
56
56
  _Query_repository.set(this, void 0);
57
57
  _Query_data.set(this, { filter: {} });
@@ -65,12 +65,14 @@ class Query {
65
65
  else {
66
66
  __classPrivateFieldSet(this, _Query_repository, this, "f");
67
67
  }
68
- __classPrivateFieldGet(this, _Query_data, "f").filter.$any = (_b = (_a = data.filter) === null || _a === void 0 ? void 0 : _a.$any) !== null && _b !== void 0 ? _b : (_c = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _c === void 0 ? void 0 : _c.$any;
69
- __classPrivateFieldGet(this, _Query_data, "f").filter.$all = (_e = (_d = data.filter) === null || _d === void 0 ? void 0 : _d.$all) !== null && _e !== void 0 ? _e : (_f = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _f === void 0 ? void 0 : _f.$all;
70
- __classPrivateFieldGet(this, _Query_data, "f").filter.$not = (_h = (_g = data.filter) === null || _g === void 0 ? void 0 : _g.$not) !== null && _h !== void 0 ? _h : (_j = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _j === void 0 ? void 0 : _j.$not;
71
- __classPrivateFieldGet(this, _Query_data, "f").filter.$none = (_l = (_k = data.filter) === null || _k === void 0 ? void 0 : _k.$none) !== null && _l !== void 0 ? _l : (_m = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _m === void 0 ? void 0 : _m.$none;
72
- __classPrivateFieldGet(this, _Query_data, "f").sort = (_o = data.sort) !== null && _o !== void 0 ? _o : parent === null || parent === void 0 ? void 0 : parent.sort;
73
- __classPrivateFieldGet(this, _Query_data, "f").columns = (_q = (_p = data.columns) !== null && _p !== void 0 ? _p : parent === null || parent === void 0 ? void 0 : parent.columns) !== null && _q !== void 0 ? _q : ['*'];
68
+ __classPrivateFieldGet(this, _Query_data, "f").filter = (_b = (_a = data.filter) !== null && _a !== void 0 ? _a : parent === null || parent === void 0 ? void 0 : parent.filter) !== null && _b !== void 0 ? _b : {};
69
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$any = (_d = (_c = data.filter) === null || _c === void 0 ? void 0 : _c.$any) !== null && _d !== void 0 ? _d : (_e = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _e === void 0 ? void 0 : _e.$any;
70
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$all = (_g = (_f = data.filter) === null || _f === void 0 ? void 0 : _f.$all) !== null && _g !== void 0 ? _g : (_h = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _h === void 0 ? void 0 : _h.$all;
71
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$not = (_k = (_j = data.filter) === null || _j === void 0 ? void 0 : _j.$not) !== null && _k !== void 0 ? _k : (_l = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _l === void 0 ? void 0 : _l.$not;
72
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$none = (_o = (_m = data.filter) === null || _m === void 0 ? void 0 : _m.$none) !== null && _o !== void 0 ? _o : (_p = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _p === void 0 ? void 0 : _p.$none;
73
+ __classPrivateFieldGet(this, _Query_data, "f").sort = (_q = data.sort) !== null && _q !== void 0 ? _q : parent === null || parent === void 0 ? void 0 : parent.sort;
74
+ __classPrivateFieldGet(this, _Query_data, "f").columns = (_s = (_r = data.columns) !== null && _r !== void 0 ? _r : parent === null || parent === void 0 ? void 0 : parent.columns) !== null && _s !== void 0 ? _s : ['*'];
75
+ __classPrivateFieldGet(this, _Query_data, "f").page = (_t = data.page) !== null && _t !== void 0 ? _t : parent === null || parent === void 0 ? void 0 : parent.page;
74
76
  this.any = this.any.bind(this);
75
77
  this.all = this.all.bind(this);
76
78
  this.not = this.not.bind(this);
@@ -89,7 +91,7 @@ class Query {
89
91
  * @returns A new Query object.
90
92
  */
91
93
  any(...queries) {
92
- const $any = queries.map((query) => query.getQueryOptions().filter);
94
+ const $any = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
93
95
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
94
96
  }
95
97
  /**
@@ -98,7 +100,7 @@ class Query {
98
100
  * @returns A new Query object.
99
101
  */
100
102
  all(...queries) {
101
- const $all = queries.map((query) => query.getQueryOptions().filter);
103
+ const $all = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
102
104
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
103
105
  }
104
106
  /**
@@ -107,7 +109,7 @@ class Query {
107
109
  * @returns A new Query object.
108
110
  */
109
111
  not(...queries) {
110
- const $not = queries.map((query) => query.getQueryOptions().filter);
112
+ const $not = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
111
113
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
112
114
  }
113
115
  /**
@@ -116,19 +118,18 @@ class Query {
116
118
  * @returns A new Query object.
117
119
  */
118
120
  none(...queries) {
119
- const $none = queries.map((query) => query.getQueryOptions().filter);
121
+ const $none = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
120
122
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
121
123
  }
122
124
  filter(a, b) {
125
+ var _a, _b;
123
126
  if (arguments.length === 1) {
124
127
  const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
125
- const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat(constraints));
128
+ const $all = (0, lang_1.compact)([(_a = __classPrivateFieldGet(this, _Query_data, "f").filter) === null || _a === void 0 ? void 0 : _a.$all].flat().concat(constraints));
126
129
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
127
130
  }
128
131
  else {
129
- const column = a;
130
- const value = b;
131
- const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat({ [column]: value }));
132
+ const $all = (0, lang_1.compact)([(_b = __classPrivateFieldGet(this, _Query_data, "f").filter) === null || _b === void 0 ? void 0 : _b.$all].flat().concat([{ [a]: b }]));
132
133
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
133
134
  }
134
135
  }
@@ -139,7 +140,9 @@ class Query {
139
140
  * @returns A new Query object.
140
141
  */
141
142
  sort(column, direction) {
142
- const sort = Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Query_data, "f").sort), { [column]: direction });
143
+ var _a;
144
+ const originalSort = [(_a = __classPrivateFieldGet(this, _Query_data, "f").sort) !== null && _a !== void 0 ? _a : []].flat();
145
+ const sort = [...originalSort, { column, direction }];
143
146
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
144
147
  }
145
148
  /**
@@ -151,7 +154,8 @@ class Query {
151
154
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { columns }, __classPrivateFieldGet(this, _Query_data, "f"));
152
155
  }
153
156
  getPaginated(options = {}) {
154
- return __classPrivateFieldGet(this, _Query_repository, "f").query(this, options);
157
+ const query = new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), options, __classPrivateFieldGet(this, _Query_data, "f"));
158
+ return __classPrivateFieldGet(this, _Query_repository, "f").query(query);
155
159
  }
156
160
  [(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
157
161
  return __asyncGenerator(this, arguments, function* _a() {
@@ -177,29 +181,20 @@ class Query {
177
181
  let end = false;
178
182
  while (!end) {
179
183
  const { records, meta } = yield __await(this.getPaginated(Object.assign(Object.assign({}, options), { page: { size: chunk, offset } })));
184
+ // Method overloading does not provide type inference for the return type.
180
185
  yield yield __await(records);
181
186
  offset += chunk;
182
187
  end = !meta.page.more;
183
188
  }
184
189
  });
185
190
  }
186
- /**
187
- * Performs the query in the database and returns a set of results.
188
- * @param options Additional options to be used when performing the query.
189
- * @returns An array of records from the database.
190
- */
191
191
  getMany(options = {}) {
192
192
  return __awaiter(this, void 0, void 0, function* () {
193
193
  const { records } = yield this.getPaginated(options);
194
+ // Method overloading does not provide type inference for the return type.
194
195
  return records;
195
196
  });
196
197
  }
197
- /**
198
- * Performs the query in the database and returns all the results.
199
- * Warning: If there are a large number of results, this method can have performance implications.
200
- * @param options Additional options to be used when performing the query.
201
- * @returns An array of records from the database.
202
- */
203
198
  getAll(chunk = pagination_1.PAGINATION_MAX_SIZE, options = {}) {
204
199
  var e_2, _a;
205
200
  return __awaiter(this, void 0, void 0, function* () {
@@ -217,24 +212,17 @@ class Query {
217
212
  }
218
213
  finally { if (e_2) throw e_2.error; }
219
214
  }
215
+ // Method overloading does not provide type inference for the return type.
220
216
  return results;
221
217
  });
222
218
  }
223
- /**
224
- * Performs the query in the database and returns the first result.
225
- * @param options Additional options to be used when performing the query.
226
- * @returns The first record that matches the query, or null if no record matched the query.
227
- */
228
219
  getOne(options = {}) {
229
220
  return __awaiter(this, void 0, void 0, function* () {
230
221
  const records = yield this.getMany(Object.assign(Object.assign({}, options), { page: { size: 1 } }));
222
+ // Method overloading does not provide type inference for the return type.
231
223
  return records[0] || null;
232
224
  });
233
225
  }
234
- /**async deleteAll(): Promise<number> {
235
- // TODO: Return number of affected rows
236
- return 0;
237
- }**/
238
226
  nextPage(size, offset) {
239
227
  return this.firstPage(size, offset);
240
228
  }
@@ -1,4 +1,4 @@
1
- import { Selectable } from './selection';
1
+ import { SelectedPick } from './selection';
2
2
  /**
3
3
  * Represents an identifiable record from the database.
4
4
  */
@@ -27,14 +27,14 @@ export interface XataRecord extends Identifiable {
27
27
  /**
28
28
  * Retrieves a refreshed copy of the current record from the database.
29
29
  */
30
- read(): Promise<this>;
30
+ read(): Promise<SelectedPick<this, ['*']> | null>;
31
31
  /**
32
32
  * Performs a partial update of the current record. On success a new object is
33
33
  * returned and the current object is not mutated.
34
34
  * @param data The columns and their values that have to be updated.
35
35
  * @returns A new record containing the latest values for all the columns of the current record.
36
36
  */
37
- update(data: Partial<Selectable<this>>): Promise<this>;
37
+ update(data: Partial<EditableData<Omit<this, keyof XataRecord>>>): Promise<SelectedPick<this, ['*']>>;
38
38
  /**
39
39
  * Performs a deletion of the current record in the database.
40
40
  *
@@ -42,3 +42,25 @@ export interface XataRecord extends Identifiable {
42
42
  */
43
43
  delete(): Promise<void>;
44
44
  }
45
+ export declare type Link<Record extends XataRecord> = Omit<XataRecord, 'read' | 'update'> & {
46
+ /**
47
+ * Retrieves a refreshed copy of the current record from the database.
48
+ */
49
+ read(): Promise<SelectedPick<Record, ['*']> | null>;
50
+ /**
51
+ * Performs a partial update of the current record. On success a new object is
52
+ * returned and the current object is not mutated.
53
+ * @param data The columns and their values that have to be updated.
54
+ * @returns A new record containing the latest values for all the columns of the current record.
55
+ */
56
+ update(data: Partial<EditableData<Omit<Record, keyof XataRecord>>>): Promise<SelectedPick<Record, ['*']>>;
57
+ };
58
+ export declare function isIdentifiable(x: any): x is Identifiable & Record<string, unknown>;
59
+ export declare function isXataRecord(x: any): x is XataRecord & Record<string, unknown>;
60
+ export declare type EditableData<O extends BaseData> = {
61
+ [K in keyof O]: O[K] extends XataRecord ? {
62
+ id: string;
63
+ } : NonNullable<O[K]> extends XataRecord ? {
64
+ id: string;
65
+ } | undefined : O[K];
66
+ };
@@ -1,2 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isXataRecord = exports.isIdentifiable = void 0;
4
+ const lang_1 = require("../util/lang");
5
+ function isIdentifiable(x) {
6
+ return (0, lang_1.isObject)(x) && (0, lang_1.isString)(x === null || x === void 0 ? void 0 : x.id);
7
+ }
8
+ exports.isIdentifiable = isIdentifiable;
9
+ function isXataRecord(x) {
10
+ var _a;
11
+ return (isIdentifiable(x) && typeof (x === null || x === void 0 ? void 0 : x.xata) === 'object' && typeof ((_a = x === null || x === void 0 ? void 0 : x.xata) === null || _a === void 0 ? void 0 : _a.version) === 'number');
12
+ }
13
+ exports.isXataRecord = isXataRecord;
@@ -1,77 +1,73 @@
1
1
  import { FetchImpl } from '../api/fetcher';
2
2
  import { Page } from './pagination';
3
- import { Query, QueryOptions } from './query';
4
- import { BaseData, XataRecord } from './record';
5
- import { Select, SelectableColumn } from './selection';
3
+ import { Query } from './query';
4
+ import { BaseData, EditableData, Identifiable, XataRecord } from './record';
5
+ import { SelectedPick } from './selection';
6
6
  export declare type Links = Record<string, Array<string[]>>;
7
7
  /**
8
8
  * Common interface for performing operations on a table.
9
9
  */
10
- export declare abstract class Repository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record> {
11
- abstract create(object: Data): Promise<Record>;
10
+ export declare abstract class Repository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
11
+ abstract create(object: EditableData<Data> & Partial<Identifiable>): Promise<SelectedPick<Record, ['*']>>;
12
+ /**
13
+ * Creates a single record in the table with a unique id.
14
+ * @param id The unique id.
15
+ * @param object Object containing the column names with their values to be stored in the table.
16
+ * @returns The full persisted record.
17
+ */
18
+ abstract create(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
12
19
  /**
13
20
  * Creates multiple records in the table.
14
21
  * @param objects Array of objects with the column names and the values to be stored in the table.
15
22
  * @returns Array of the persisted records.
16
23
  */
17
- abstract createMany(objects: Data[]): Promise<Record[]>;
24
+ abstract createMany(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
18
25
  /**
19
26
  * Queries a single record from the table given its unique id.
20
27
  * @param id The unique id.
21
28
  * @returns The persisted record for the given id or null if the record could not be found.
22
29
  */
23
- abstract read(id: string): Promise<Record | null>;
24
- /**
25
- * Insert a single record with a unique id.
26
- * @param id The unique id.
27
- * @param object Object containing the column names with their values to be stored in the table.
28
- * @returns The full persisted record.
29
- */
30
- abstract insert(id: string, object: Data): Promise<Record>;
30
+ abstract read(id: string): Promise<SelectedPick<Record, ['*']> | null>;
31
31
  /**
32
32
  * Partially update a single record given its unique id.
33
33
  * @param id The unique id.
34
34
  * @param object The column names and their values that have to be updatd.
35
35
  * @returns The full persisted record.
36
36
  */
37
- abstract update(id: string, object: Partial<Data>): Promise<Record>;
37
+ abstract update(id: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
38
38
  /**
39
- * Updates or inserts a single record. If a record exists with the given id,
39
+ * Creates or updates a single record. If a record exists with the given id,
40
40
  * it will be update, otherwise a new record will be created.
41
41
  * @param id A unique id.
42
42
  * @param object The column names and the values to be persisted.
43
43
  * @returns The full persisted record.
44
44
  */
45
- abstract updateOrInsert(id: string, object: Data): Promise<Record>;
45
+ abstract createOrUpdate(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
46
46
  /**
47
47
  * Deletes a record given its unique id.
48
48
  * @param id The unique id.
49
49
  * @throws If the record could not be found or there was an error while performing the deletion.
50
50
  */
51
51
  abstract delete(id: string): void;
52
- abstract query<Result extends XataRecord, Options extends QueryOptions<Record>>(query: Query<Record, Result>, options: Options): Promise<Page<Record, typeof options extends {
53
- columns: SelectableColumn<Data>[];
54
- } ? Select<Data, typeof options['columns'][number]> : Result>>;
52
+ abstract query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
55
53
  }
56
- export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Repository<Data, Record> {
54
+ export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
57
55
  #private;
58
56
  constructor(client: BaseClient<any>, table: string);
59
- create(object: Data): Promise<Record>;
60
- createMany(objects: Data[]): Promise<Record[]>;
61
- read(recordId: string): Promise<Record | null>;
62
- update(recordId: string, object: Partial<Data>): Promise<Record>;
63
- insert(recordId: string, object: Data): Promise<Record>;
64
- updateOrInsert(recordId: string, object: Data): Promise<Record>;
57
+ create(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
58
+ create(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
59
+ createMany(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
60
+ read(recordId: string): Promise<SelectedPick<Record, ['*']> | null>;
61
+ update(recordId: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
62
+ createOrUpdate(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
65
63
  delete(recordId: string): Promise<void>;
66
- query<Result extends XataRecord, Options extends QueryOptions<Record>>(query: Query<Record, Result>, options?: Options): Promise<Page<Record, typeof options extends {
67
- columns: SelectableColumn<Data>[];
68
- } ? Select<Data, typeof options['columns'][number]> : Result>>;
64
+ query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
69
65
  }
70
66
  interface RepositoryFactory {
71
- createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data>;
67
+ createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data & XataRecord>;
72
68
  }
73
69
  export declare class RestRespositoryFactory implements RepositoryFactory {
74
- createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data>;
70
+ createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data & XataRecord>;
75
71
  }
76
72
  declare type BranchStrategyValue = string | undefined | null;
77
73
  declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
@@ -26,20 +26,22 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
26
26
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
27
27
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
28
28
  };
29
- var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _BaseClient_links, _BaseClient_branch;
29
+ var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _BaseClient_links, _BaseClient_branch;
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
32
32
  const api_1 = require("../api");
33
+ const lang_1 = require("../util/lang");
33
34
  const filters_1 = require("./filters");
34
35
  const pagination_1 = require("./pagination");
35
36
  const query_1 = require("./query");
37
+ const record_1 = require("./record");
36
38
  /**
37
39
  * Common interface for performing operations on a table.
38
40
  */
39
41
  class Repository extends query_1.Query {
40
42
  }
41
43
  exports.Repository = Repository;
42
- class RestRepository extends Repository {
44
+ class RestRepository extends query_1.Query {
43
45
  constructor(client, table) {
44
46
  var _a;
45
47
  super(null, table, {});
@@ -58,20 +60,24 @@ class RestRepository extends Repository {
58
60
  }
59
61
  __classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
60
62
  }
61
- create(object) {
63
+ create(a, b) {
62
64
  return __awaiter(this, void 0, void 0, function* () {
63
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
64
- const record = transformObjectLinks(object);
65
- const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
66
- workspace: '{workspaceId}',
67
- dbBranchName: '{dbBranch}',
68
- tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
69
- }, body: record }, fetchProps));
70
- const finalObject = yield this.read(response.id);
71
- if (!finalObject) {
72
- throw new Error('The server failed to save the record');
65
+ if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
66
+ if (a === '')
67
+ throw new Error("The id can't be empty");
68
+ return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a, b);
69
+ }
70
+ else if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
71
+ if (a.id === '')
72
+ throw new Error("The id can't be empty");
73
+ return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
74
+ }
75
+ else if ((0, lang_1.isObject)(a)) {
76
+ return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithoutId).call(this, a);
77
+ }
78
+ else {
79
+ throw new Error('Invalid arguments for create method');
73
80
  }
74
- return finalObject;
75
81
  });
76
82
  }
77
83
  createMany(objects) {
@@ -86,6 +92,7 @@ class RestRepository extends Repository {
86
92
  return finalObjects;
87
93
  });
88
94
  }
95
+ // TODO: Add column support: https://github.com/xataio/openapi/issues/139
89
96
  read(recordId) {
90
97
  return __awaiter(this, void 0, void 0, function* () {
91
98
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
@@ -96,31 +103,15 @@ class RestRepository extends Repository {
96
103
  update(recordId, object) {
97
104
  return __awaiter(this, void 0, void 0, function* () {
98
105
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
99
- const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
106
+ const record = transformObjectLinks(object);
107
+ const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: record }, fetchProps));
100
108
  const item = yield this.read(response.id);
101
109
  if (!item)
102
110
  throw new Error('The server failed to save the record');
103
111
  return item;
104
112
  });
105
113
  }
106
- insert(recordId, object) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
109
- const record = transformObjectLinks(object);
110
- const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
111
- workspace: '{workspaceId}',
112
- dbBranchName: '{dbBranch}',
113
- tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
114
- recordId
115
- }, body: record }, fetchProps));
116
- const finalObject = yield this.read(response.id);
117
- if (!finalObject) {
118
- throw new Error('The server failed to save the record');
119
- }
120
- return finalObject;
121
- });
122
- }
123
- updateOrInsert(recordId, object) {
114
+ createOrUpdate(recordId, object) {
124
115
  return __awaiter(this, void 0, void 0, function* () {
125
116
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
126
117
  const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
@@ -136,20 +127,19 @@ class RestRepository extends Repository {
136
127
  yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
137
128
  });
138
129
  }
139
- query(query, options = {}) {
140
- var _a, _b, _c;
130
+ query(query) {
131
+ var _a;
141
132
  return __awaiter(this, void 0, void 0, function* () {
142
133
  const data = query.getQueryOptions();
143
134
  const body = {
144
- filter: Object.values(data.filter).some(Boolean) ? data.filter : undefined,
145
- sort: (_a = (0, filters_1.buildSortFilter)(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : data.sort,
146
- page: (_b = options === null || options === void 0 ? void 0 : options.page) !== null && _b !== void 0 ? _b : data.page,
147
- columns: (_c = options === null || options === void 0 ? void 0 : options.columns) !== null && _c !== void 0 ? _c : data.columns
135
+ filter: Object.values((_a = data.filter) !== null && _a !== void 0 ? _a : {}).some(Boolean) ? data.filter : undefined,
136
+ sort: (0, filters_1.buildSortFilter)(data.sort),
137
+ page: data.page,
138
+ columns: data.columns
148
139
  };
149
140
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
150
141
  const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
151
142
  const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), record));
152
- // TODO: We should properly type this any
153
143
  return new pagination_1.Page(query, meta, records);
154
144
  });
155
145
  }
@@ -172,6 +162,37 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
172
162
  }
173
163
  };
174
164
  });
165
+ }, _RestRepository_insertRecordWithoutId = function _RestRepository_insertRecordWithoutId(object) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
168
+ const record = transformObjectLinks(object);
169
+ const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
170
+ workspace: '{workspaceId}',
171
+ dbBranchName: '{dbBranch}',
172
+ tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
173
+ }, body: record }, fetchProps));
174
+ const finalObject = yield this.read(response.id);
175
+ if (!finalObject) {
176
+ throw new Error('The server failed to save the record');
177
+ }
178
+ return finalObject;
179
+ });
180
+ }, _RestRepository_insertRecordWithId = function _RestRepository_insertRecordWithId(recordId, object) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
183
+ const record = transformObjectLinks(object);
184
+ const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
185
+ workspace: '{workspaceId}',
186
+ dbBranchName: '{dbBranch}',
187
+ tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
188
+ recordId
189
+ }, body: record, queryParams: { createOnly: true } }, fetchProps));
190
+ const finalObject = yield this.read(response.id);
191
+ if (!finalObject) {
192
+ throw new Error('The server failed to save the record');
193
+ }
194
+ return finalObject;
195
+ });
175
196
  };
176
197
  class RestRespositoryFactory {
177
198
  createRepository(client, table) {
@@ -198,43 +219,31 @@ class BaseClient {
198
219
  });
199
220
  }
200
221
  initObject(table, object) {
201
- const o = {};
202
- Object.assign(o, object);
222
+ const result = {};
223
+ Object.assign(result, object);
203
224
  const tableLinks = __classPrivateFieldGet(this, _BaseClient_links, "f")[table] || [];
204
225
  for (const link of tableLinks) {
205
226
  const [field, linkTable] = link;
206
- const value = o[field];
207
- if (value && typeof value === 'object') {
208
- const { id } = value;
209
- if (Object.keys(value).find((col) => col === 'id')) {
210
- o[field] = this.initObject(linkTable, value);
211
- }
212
- else if (id) {
213
- o[field] = {
214
- id,
215
- get: () => {
216
- this.db[linkTable].read(id);
217
- }
218
- };
219
- }
227
+ const value = result[field];
228
+ if (value && (0, lang_1.isObject)(value)) {
229
+ result[field] = this.initObject(linkTable, value);
220
230
  }
221
231
  }
222
232
  const db = this.db;
223
- o.read = function () {
224
- return db[table].read(o['id']);
233
+ result.read = function () {
234
+ return db[table].read(result['id']);
225
235
  };
226
- o.update = function (data) {
227
- return db[table].update(o['id'], data);
236
+ result.update = function (data) {
237
+ return db[table].update(result['id'], data);
228
238
  };
229
- o.delete = function () {
230
- return db[table].delete(o['id']);
239
+ result.delete = function () {
240
+ return db[table].delete(result['id']);
231
241
  };
232
242
  for (const prop of ['read', 'update', 'delete']) {
233
- Object.defineProperty(o, prop, { enumerable: false });
243
+ Object.defineProperty(result, prop, { enumerable: false });
234
244
  }
235
- // TODO: links and rev links
236
- Object.freeze(o);
237
- return o;
245
+ Object.freeze(result);
246
+ return result;
238
247
  }
239
248
  getBranch() {
240
249
  var e_1, _a;
@@ -272,12 +281,8 @@ _BaseClient_links = new WeakMap(), _BaseClient_branch = new WeakMap();
272
281
  const isBranchStrategyBuilder = (strategy) => {
273
282
  return typeof strategy === 'function';
274
283
  };
275
- // TODO: We can find a better implementation for links
276
284
  const transformObjectLinks = (object) => {
277
285
  return Object.entries(object).reduce((acc, [key, value]) => {
278
- if (value && typeof value === 'object' && typeof value.id === 'string') {
279
- return Object.assign(Object.assign({}, acc), { [key]: value.id });
280
- }
281
- return Object.assign(Object.assign({}, acc), { [key]: value });
286
+ return Object.assign(Object.assign({}, acc), { [key]: (0, record_1.isIdentifiable)(value) ? value.id : value });
282
287
  }, {});
283
288
  };
@@ -1,12 +1,24 @@
1
- import { StringKeys, UnionToIntersection, Values } from '../util/types';
2
- import { Query } from './query';
3
- import { BaseData, Identifiable, XataRecord } from './record';
4
- declare type Queries<T> = {
5
- [key in keyof T as T[key] extends Query<any, any> ? key : never]: T[key];
6
- };
7
- export declare type Selectable<T extends BaseData> = T & Partial<Identifiable>;
8
- export declare type SelectableColumn<O> = '*' | (O extends Array<unknown> ? never : O extends Record<string, any> ? '*' | Values<{
9
- [K in StringKeys<O>]: O[K] extends Record<string, any> ? `${K}.${SelectableColumn<O[K]>}` : K;
10
- }> : '');
11
- export declare type Select<T, K extends SelectableColumn<T>> = UnionToIntersection<K extends keyof T ? Pick<T, K> : T> & Queries<T> & XataRecord;
1
+ import { If, IsArray, IsObject, StringKeys, UnionToIntersection, Values } from '../util/types';
2
+ import { Link, XataRecord } from './record';
3
+ export declare type SelectableColumn<O, RecursivePath extends any[] = []> = '*' | 'id' | DataProps<O> | NestedColumns<O, RecursivePath>;
4
+ export declare type SelectedPick<O extends XataRecord, Key extends SelectableColumn<O>[]> = XataRecord & UnionToIntersection<Values<{
5
+ [K in Key[number]]: NestedValueAtColumn<O, K> & XataRecord;
6
+ }>>;
7
+ export declare type ValueAtColumn<O extends XataRecord, P extends SelectableColumn<O>> = P extends '*' ? Values<O> : P extends 'id' ? string : P extends keyof O ? O[P] : P extends `${infer K}.${infer V}` ? K extends keyof O ? Values<O[K] extends XataRecord ? (V extends SelectableColumn<O[K]> ? {
8
+ V: ValueAtColumn<O[K], V>;
9
+ } : never) : O[K]> : never : never;
10
+ declare type MAX_RECURSION = 5;
11
+ declare type NestedColumns<O, RecursivePath extends any[]> = RecursivePath['length'] extends MAX_RECURSION ? never : If<IsObject<O>, Values<{
12
+ [K in DataProps<O>]: If<IsArray<NonNullable<O[K]>>, K, // If the property is an array, we stop recursion. We don't support object arrays yet
13
+ If<IsObject<NonNullable<O[K]>>, NonNullable<O[K]> extends XataRecord ? SelectableColumn<NonNullable<O[K]>, [...RecursivePath, O[K]]> extends string ? K | `${K}.${SelectableColumn<NonNullable<O[K]>, [...RecursivePath, O[K]]>}` : never : `${K}.${StringKeys<NonNullable<O[K]>> | '*'}`, // This allows usage of objects that are not links
14
+ K>>;
15
+ }>, never>;
16
+ declare type DataProps<O> = Exclude<StringKeys<O>, StringKeys<XataRecord>>;
17
+ declare type NestedValueAtColumn<O, Key extends SelectableColumn<O>> = Key extends `${infer N}.${infer M}` ? N extends DataProps<O> ? {
18
+ [K in N]: M extends SelectableColumn<NonNullable<O[K]>> ? NestedValueAtColumn<NonNullable<O[K]>, M> & XataRecord : unknown;
19
+ } : unknown : Key extends DataProps<O> ? {
20
+ [K in Key]: NonNullable<O[K]> extends XataRecord ? SelectedPick<NonNullable<O[K]>, ['*']> : O[K];
21
+ } : Key extends '*' ? {
22
+ [K in keyof NonNullable<O>]: NonNullable<NonNullable<O>[K]> extends XataRecord ? NonNullable<O>[K] extends XataRecord ? Link<NonNullable<O>[K]> : Link<NonNullable<NonNullable<O>[K]>> | null : NonNullable<O>[K];
23
+ } : unknown;
12
24
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-floating-promises */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // SelectableColumn<O> //
5
+ // --------------------------------------------------------------------------- //
6
+ const validTeamColumns = [
7
+ '*',
8
+ 'id',
9
+ 'name',
10
+ 'owner.*',
11
+ 'owner.address.*',
12
+ 'owner.address',
13
+ 'owner.address.street'
14
+ ];
15
+ // @ts-expect-error
16
+ const invalidFullNameTeamColumn = 'full_name';
17
+ // @ts-expect-error
18
+ const invalidPartialTeamColumn = 'owner.address.';
19
+ // @ts-expect-error
20
+ const invalidDeleteTeamColumn = 'owner.delete';
21
+ // @ts-expect-error
22
+ const invalidReadTeamColumn = 'owner.read.*';
23
+ // ValueAtColumn<O, P> //
24
+ // --------------------------------------------------------------------------- //
25
+ const labelsValue = ['foo'];
26
+ // @ts-expect-error
27
+ const invalidLabelsValue = [1];
28
+ // SelectedRecordPick<O, Key> //
29
+ // ---------------------------------------------------------------------------- //
30
+ function selectedRecordPickTest1(selectedUserBaseRecord) {
31
+ var _a, _b, _c, _d;
32
+ selectedUserBaseRecord.id;
33
+ selectedUserBaseRecord.read();
34
+ selectedUserBaseRecord.full_name;
35
+ (_a = selectedUserBaseRecord.address) === null || _a === void 0 ? void 0 : _a.street;
36
+ // @ts-expect-error
37
+ selectedUserBaseRecord.team.id;
38
+ (_b = selectedUserBaseRecord.team) === null || _b === void 0 ? void 0 : _b.id;
39
+ (_c = selectedUserBaseRecord.team) === null || _c === void 0 ? void 0 : _c.read();
40
+ // @ts-expect-error
41
+ (_d = selectedUserBaseRecord.team) === null || _d === void 0 ? void 0 : _d.name;
42
+ selectedUserBaseRecord.owner.id;
43
+ selectedUserBaseRecord.owner.read();
44
+ // @ts-expect-error
45
+ selectedUserBaseRecord.owner.full_name;
46
+ }
47
+ function selectedRecordPickTest2(selectedUserFullRecord) {
48
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
49
+ selectedUserFullRecord.id;
50
+ selectedUserFullRecord.read();
51
+ selectedUserFullRecord.full_name;
52
+ (_a = selectedUserFullRecord.team) === null || _a === void 0 ? void 0 : _a.id;
53
+ (_b = selectedUserFullRecord.team) === null || _b === void 0 ? void 0 : _b.read();
54
+ (_c = selectedUserFullRecord.team) === null || _c === void 0 ? void 0 : _c.name;
55
+ (_d = selectedUserFullRecord.team) === null || _d === void 0 ? void 0 : _d.owner;
56
+ (_f = (_e = selectedUserFullRecord.team) === null || _e === void 0 ? void 0 : _e.owner) === null || _f === void 0 ? void 0 : _f.id;
57
+ (_h = (_g = selectedUserFullRecord.team) === null || _g === void 0 ? void 0 : _g.owner) === null || _h === void 0 ? void 0 : _h.read();
58
+ // @ts-expect-error
59
+ (_k = (_j = selectedUserFullRecord.team) === null || _j === void 0 ? void 0 : _j.owner) === null || _k === void 0 ? void 0 : _k.full_name;
60
+ // @ts-expect-error
61
+ selectedUserFullRecord.full_name = null;
62
+ selectedUserFullRecord.email = null;
63
+ selectedUserFullRecord.email = '';
64
+ // @ts-expect-error
65
+ selectedUserFullRecord.email = 2;
66
+ if (selectedUserFullRecord.team) {
67
+ // @ts-expect-error
68
+ selectedUserFullRecord.team.name = null;
69
+ selectedUserFullRecord.team.labels = null;
70
+ selectedUserFullRecord.team.labels = ['foo'];
71
+ // @ts-expect-error
72
+ selectedUserFullRecord.team.labels = [1];
73
+ }
74
+ }
75
+ function selectedRecordPickTest3(selectedUserNestedRecord) {
76
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
77
+ selectedUserNestedRecord.id;
78
+ selectedUserNestedRecord.read();
79
+ // @ts-expect-error
80
+ selectedUserNestedRecord.full_name;
81
+ (_a = selectedUserNestedRecord.team) === null || _a === void 0 ? void 0 : _a.id;
82
+ (_b = selectedUserNestedRecord.team) === null || _b === void 0 ? void 0 : _b.read();
83
+ // @ts-expect-error
84
+ (_c = selectedUserNestedRecord.team) === null || _c === void 0 ? void 0 : _c.name;
85
+ (_e = (_d = selectedUserNestedRecord.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
86
+ (_g = (_f = selectedUserNestedRecord.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
87
+ (_j = (_h = selectedUserNestedRecord.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
88
+ }
89
+ function selectedRecordPickTest4(selectedUserNestedRecord) {
90
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
91
+ selectedUserNestedRecord.id;
92
+ selectedUserNestedRecord.read();
93
+ // @ts-expect-error
94
+ selectedUserNestedRecord.full_name;
95
+ (_a = selectedUserNestedRecord.team) === null || _a === void 0 ? void 0 : _a.id;
96
+ (_b = selectedUserNestedRecord.team) === null || _b === void 0 ? void 0 : _b.read();
97
+ // @ts-expect-error
98
+ (_c = selectedUserNestedRecord.team) === null || _c === void 0 ? void 0 : _c.name;
99
+ (_e = (_d = selectedUserNestedRecord.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
100
+ (_g = (_f = selectedUserNestedRecord.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
101
+ // @ts-expect-error
102
+ (_j = (_h = selectedUserNestedRecord.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
103
+ (_l = (_k = selectedUserNestedRecord.team) === null || _k === void 0 ? void 0 : _k.owner) === null || _l === void 0 ? void 0 : _l.address;
104
+ (_p = (_o = (_m = selectedUserNestedRecord.team) === null || _m === void 0 ? void 0 : _m.owner) === null || _o === void 0 ? void 0 : _o.address) === null || _p === void 0 ? void 0 : _p.street;
105
+ (_s = (_r = (_q = selectedUserNestedRecord.team) === null || _q === void 0 ? void 0 : _q.owner) === null || _r === void 0 ? void 0 : _r.address) === null || _s === void 0 ? void 0 : _s.zipcode;
106
+ }
107
+ test('fake test', () => {
108
+ // This is a fake test to make sure that the type definitions in this file are working
109
+ });
@@ -1,2 +1,5 @@
1
1
  export declare function compact<T>(arr: Array<T | null | undefined>): T[];
2
+ export declare function compactObject<T>(obj: Record<string, T | null | undefined>): Record<string, T>;
2
3
  export declare type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4
+ export declare function isObject(value: any): value is object;
5
+ export declare function isString(value: any): value is string;
package/dist/util/lang.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compact = void 0;
3
+ exports.isString = exports.isObject = exports.compactObject = exports.compact = void 0;
4
4
  function notEmpty(value) {
5
5
  return value !== null && value !== undefined;
6
6
  }
@@ -8,3 +8,15 @@ function compact(arr) {
8
8
  return arr.filter(notEmpty);
9
9
  }
10
10
  exports.compact = compact;
11
+ function compactObject(obj) {
12
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
13
+ }
14
+ exports.compactObject = compactObject;
15
+ function isObject(value) {
16
+ return value !== undefined && value !== null && typeof value === 'object';
17
+ }
18
+ exports.isObject = isObject;
19
+ function isString(value) {
20
+ return value !== undefined && value !== null && typeof value === 'string';
21
+ }
22
+ exports.isString = isString;
@@ -1,3 +1,13 @@
1
1
  export declare type StringKeys<O> = Extract<keyof O, string>;
2
- export declare type Values<O> = O[keyof O];
2
+ export declare type NumberKeys<O> = Extract<keyof O, number>;
3
+ export declare type Values<O> = O[StringKeys<O>];
3
4
  export declare type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
5
+ export declare type If<Condition, Then, Else> = Condition extends true ? Then : Else;
6
+ export declare type IsObject<T> = T extends Record<string, any> ? true : false;
7
+ export declare type IsArray<T> = T extends Array<any> ? true : false;
8
+ export declare type NonEmptyArray<T> = T[] & {
9
+ 0: T;
10
+ };
11
+ export declare type RequiredBy<T, K extends keyof T> = T & {
12
+ [P in K]-?: NonNullable<T[P]>;
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
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": "09892c40a01ece59c802844310aac17aba7a281c"
23
+ "gitHead": "f46df88912b2bac2ddae598d9d08efc1f44b00be"
24
24
  }