@xata.io/client 0.0.0-alpha.ed1ba7e → 0.0.0-beta.18f8d57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -8,10 +8,10 @@ export interface XataRecord {
8
8
  delete(): Promise<void>;
9
9
  }
10
10
  export declare type Queries<T> = {
11
- [key in keyof T as T[key] extends Query<any> ? key : never]: T[key];
11
+ [key in keyof T as T[key] extends Query<infer A, infer B> ? key : never]: T[key];
12
12
  };
13
13
  export declare type OmitQueries<T> = {
14
- [key in keyof T as T[key] extends Query<any> ? never : key]: T[key];
14
+ [key in keyof T as T[key] extends Query<infer A, infer B> ? never : key]: T[key];
15
15
  };
16
16
  export declare type OmitLinks<T> = {
17
17
  [key in keyof T as T[key] extends XataRecord ? never : key]: T[key];
@@ -20,17 +20,11 @@ export declare type OmitMethods<T> = {
20
20
  [key in keyof T as T[key] extends Function ? never : key]: T[key];
21
21
  };
22
22
  export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>;
23
- export declare type SelectableColumn<T> = keyof Selectable<T> | '*';
24
- export declare type Select<T, K extends SelectableColumn<T>> = (K extends keyof T ? Pick<T, K> : T) & Queries<T> & XataRecord;
23
+ export declare type Select<T, K extends keyof T> = Pick<T, K> & Queries<T> & XataRecord;
25
24
  export declare type Include<T> = {
26
25
  [key in keyof T as T[key] extends XataRecord ? key : never]?: boolean | Array<keyof Selectable<T[key]>>;
27
26
  };
28
27
  declare type SortDirection = 'asc' | 'desc';
29
- declare type SortFilterExtended<T> = {
30
- column: keyof T;
31
- direction?: SortDirection;
32
- };
33
- declare type SortFilter<T> = SortFilterExtended<T> | keyof T;
34
28
  declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
35
29
  declare type Constraint<T> = {
36
30
  [key in Operator]?: T;
@@ -75,17 +69,15 @@ declare type OffsetNavigationOptions = {
75
69
  declare type PaginationOptions = CursorNavigationOptions & OffsetNavigationOptions;
76
70
  declare type BulkQueryOptions<T> = {
77
71
  page?: PaginationOptions;
78
- columns?: Array<keyof Selectable<T>>;
79
- sort?: SortFilter<T> | SortFilter<T>[];
80
72
  };
81
- declare type QueryOrConstraint<T extends XataRecord, R extends XataRecord> = Query<T, R> | Constraint<T>;
73
+ declare type QueryOrConstraint<T, R> = Query<T, R> | Constraint<T>;
82
74
  declare type QueryMeta = {
83
75
  page: {
84
76
  cursor: string;
85
77
  more: boolean;
86
78
  };
87
79
  };
88
- interface BasePage<T extends XataRecord, R extends XataRecord> {
80
+ interface BasePage<T, R> {
89
81
  query: Query<T, R>;
90
82
  meta: QueryMeta;
91
83
  records: R[];
@@ -95,7 +87,7 @@ interface BasePage<T extends XataRecord, R extends XataRecord> {
95
87
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
96
88
  hasNextPage(): boolean;
97
89
  }
98
- declare class Page<T extends XataRecord, R extends XataRecord> implements BasePage<T, R> {
90
+ declare class Page<T, R> implements BasePage<T, R> {
99
91
  readonly query: Query<T, R>;
100
92
  readonly meta: QueryMeta;
101
93
  readonly records: R[];
@@ -106,7 +98,7 @@ declare class Page<T extends XataRecord, R extends XataRecord> implements BasePa
106
98
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
107
99
  hasNextPage(): boolean;
108
100
  }
109
- export declare class Query<T extends XataRecord, R extends XataRecord = T> implements BasePage<T, R> {
101
+ export declare class Query<T, R = T> implements BasePage<T, R> {
110
102
  table: string;
111
103
  repository: Repository<T>;
112
104
  readonly $any?: QueryOrConstraint<T, R>[];
@@ -114,7 +106,6 @@ export declare class Query<T extends XataRecord, R extends XataRecord = T> imple
114
106
  readonly $not?: QueryOrConstraint<T, R>[];
115
107
  readonly $none?: QueryOrConstraint<T, R>[];
116
108
  readonly $sort?: Record<string, SortDirection>;
117
- readonly columns: SelectableColumn<T>[];
118
109
  readonly query: Query<T, R>;
119
110
  readonly meta: QueryMeta;
120
111
  readonly records: R[];
@@ -126,45 +117,46 @@ export declare class Query<T extends XataRecord, R extends XataRecord = T> imple
126
117
  filter(constraints: FilterConstraints<T>): Query<T, R>;
127
118
  filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
128
119
  sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
129
- getPaginated<Options extends BulkQueryOptions<T>>(options?: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
120
+ getPaginated(options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
130
121
  [Symbol.asyncIterator](): AsyncIterableIterator<R>;
131
122
  getIterator(chunk: number, options?: Omit<BulkQueryOptions<T>, 'page'>): AsyncGenerator<R[]>;
132
- getMany<Options extends BulkQueryOptions<T>>(options?: Options): Promise<(typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R)[]>;
133
- getOne<Options extends Omit<BulkQueryOptions<T>, 'page'>>(options?: Options): Promise<(typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R) | null>;
123
+ getMany(options?: BulkQueryOptions<T>): Promise<R[]>;
124
+ getOne(options?: Omit<BulkQueryOptions<T>, 'page'>): Promise<R | null>;
134
125
  deleteAll(): Promise<number>;
126
+ include(columns: Include<T>): this;
135
127
  nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
136
128
  previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
137
129
  firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
138
130
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
139
131
  hasNextPage(): boolean;
140
132
  }
141
- export declare abstract class Repository<T extends XataRecord> extends Query<T> {
142
- select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
133
+ export declare abstract class Repository<T> extends Query<T, Selectable<T>> {
134
+ select<K extends keyof Selectable<T>>(...columns: K[]): Query<T, Select<T, K>>;
143
135
  abstract create(object: Selectable<T>): Promise<T>;
144
136
  abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
145
137
  abstract read(id: string): Promise<T | null>;
146
138
  abstract update(id: string, object: Partial<T>): Promise<T>;
147
139
  abstract delete(id: string): void;
148
- abstract _runQuery<R extends XataRecord, Options extends BulkQueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
140
+ abstract _runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
149
141
  }
150
- export declare class RestRepository<T extends XataRecord> extends Repository<T> {
142
+ export declare class RestRepository<T> extends Repository<T> {
151
143
  client: BaseClient<any>;
152
144
  fetch: any;
153
145
  constructor(client: BaseClient<any>, table: string);
154
146
  request<T>(method: string, path: string, body?: unknown): Promise<T | undefined>;
155
- select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
147
+ select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>;
156
148
  create(object: T): Promise<T>;
157
149
  createMany(objects: T[]): Promise<T[]>;
158
150
  read(id: string): Promise<T | null>;
159
151
  update(id: string, object: Partial<T>): Promise<T>;
160
152
  delete(id: string): Promise<void>;
161
- _runQuery<R extends XataRecord, Options extends BulkQueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
153
+ _runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
162
154
  }
163
155
  interface RepositoryFactory {
164
- createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
156
+ createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
165
157
  }
166
158
  export declare class RestRespositoryFactory implements RepositoryFactory {
167
- createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
159
+ createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
168
160
  }
169
161
  declare type BranchStrategyValue = string | undefined | null;
170
162
  declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
package/dist/index.js CHANGED
@@ -100,7 +100,6 @@ class Page {
100
100
  }
101
101
  class Query {
102
102
  constructor(repository, table, data, parent) {
103
- this.columns = ['*'];
104
103
  // Cursor pagination
105
104
  this.query = this;
106
105
  this.meta = { page: { cursor: 'start', more: true } };
@@ -177,7 +176,7 @@ class Query {
177
176
  }, this);
178
177
  return q;
179
178
  }
180
- getPaginated(options = {}) {
179
+ getPaginated(options) {
181
180
  return __awaiter(this, void 0, void 0, function* () {
182
181
  return this.repository._runQuery(this, options);
183
182
  });
@@ -212,7 +211,7 @@ class Query {
212
211
  }
213
212
  });
214
213
  }
215
- getMany(options = {}) {
214
+ getMany(options) {
216
215
  return __awaiter(this, void 0, void 0, function* () {
217
216
  const { records } = yield this.getPaginated(options);
218
217
  return records;
@@ -230,6 +229,10 @@ class Query {
230
229
  return 0;
231
230
  });
232
231
  }
232
+ include(columns) {
233
+ // TODO
234
+ return this;
235
+ }
233
236
  nextPage(size, offset) {
234
237
  return __awaiter(this, void 0, void 0, function* () {
235
238
  return this.firstPage(size, offset);
@@ -256,8 +259,8 @@ class Query {
256
259
  }
257
260
  exports.Query = Query;
258
261
  class Repository extends Query {
259
- select(columns) {
260
- return new Query(this.repository, this.table, { columns });
262
+ select(...columns) {
263
+ return new Query(this.repository, this.table, {});
261
264
  }
262
265
  }
263
266
  exports.Repository = Repository;
@@ -314,8 +317,8 @@ class RestRepository extends Repository {
314
317
  return resp.json();
315
318
  });
316
319
  }
317
- select(columns) {
318
- return new Query(this.repository, this.table, { columns });
320
+ select(...columns) {
321
+ return new Query(this.repository, this.table, {});
319
322
  }
320
323
  create(object) {
321
324
  return __awaiter(this, void 0, void 0, function* () {
@@ -377,7 +380,6 @@ class RestRepository extends Repository {
377
380
  });
378
381
  }
379
382
  _runQuery(query, options) {
380
- var _a, _b;
381
383
  return __awaiter(this, void 0, void 0, function* () {
382
384
  const filter = {
383
385
  $any: query.$any,
@@ -387,9 +389,8 @@ class RestRepository extends Repository {
387
389
  };
388
390
  const body = {
389
391
  filter: Object.values(filter).some(Boolean) ? filter : undefined,
390
- sort: (_a = buildSortFilter(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : query.$sort,
391
- page: options === null || options === void 0 ? void 0 : options.page,
392
- columns: (_b = options === null || options === void 0 ? void 0 : options.columns) !== null && _b !== void 0 ? _b : query.columns
392
+ sort: query.$sort,
393
+ page: options === null || options === void 0 ? void 0 : options.page
393
394
  };
394
395
  const response = yield this.request('POST', `/tables/${this.table}/query`, body);
395
396
  if (!response) {
@@ -397,7 +398,6 @@ class RestRepository extends Repository {
397
398
  }
398
399
  const { meta, records: objects } = response;
399
400
  const records = objects.map((record) => this.client.initObject(this.table, record));
400
- // TODO: We should properly type this any
401
401
  return new Page(query, meta, records);
402
402
  });
403
403
  }
@@ -507,22 +507,3 @@ const transformObjectLinks = (object) => {
507
507
  return Object.assign(Object.assign({}, acc), { [key]: value });
508
508
  }, {});
509
509
  };
510
- function buildSortFilter(filter) {
511
- if (!filter)
512
- return undefined;
513
- const filters = Array.isArray(filter) ? filter : [filter];
514
- return filters.reduce((acc, item) => {
515
- if (typeof item === 'string') {
516
- return Object.assign(Object.assign({}, acc), { [item]: 'asc' });
517
- }
518
- else if (isObjectSortFilter(item)) {
519
- return Object.assign(Object.assign({}, acc), { [item.column]: item.direction });
520
- }
521
- else {
522
- return acc;
523
- }
524
- }, {});
525
- }
526
- function isObjectSortFilter(filter) {
527
- return typeof filter === 'object' && filter.column !== undefined;
528
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-alpha.ed1ba7e",
3
+ "version": "0.0.0-beta.18f8d57",
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": "ed1ba7edce38949e3e2cd9823523d6598126fe04"
23
+ "gitHead": "18f8d57ed1b43ef057251dae3fcf98a4d591f2cf"
24
24
  }