@xata.io/client 0.0.0-beta.bbcb88d → 0.0.0-beta.c21e40a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +49 -0
  3. package/dist/api/client.d.ts +95 -0
  4. package/dist/api/client.js +236 -0
  5. package/dist/api/components.d.ts +1436 -0
  6. package/dist/api/components.js +997 -0
  7. package/dist/api/fetcher.d.ts +25 -0
  8. package/dist/api/fetcher.js +73 -0
  9. package/dist/api/index.d.ts +7 -0
  10. package/dist/api/index.js +21 -0
  11. package/dist/api/parameters.d.ts +16 -0
  12. package/dist/api/parameters.js +2 -0
  13. package/dist/api/providers.d.ts +8 -0
  14. package/dist/api/providers.js +30 -0
  15. package/dist/api/responses.d.ts +50 -0
  16. package/dist/api/responses.js +2 -0
  17. package/dist/api/schemas.d.ts +311 -0
  18. package/dist/api/schemas.js +2 -0
  19. package/dist/index.d.ts +2 -133
  20. package/dist/index.js +16 -360
  21. package/dist/schema/filters.d.ts +22 -0
  22. package/dist/schema/filters.js +25 -0
  23. package/dist/schema/index.d.ts +7 -0
  24. package/dist/schema/index.js +29 -0
  25. package/dist/schema/operators.d.ts +72 -0
  26. package/dist/schema/operators.js +91 -0
  27. package/dist/schema/pagination.d.ts +83 -0
  28. package/dist/schema/pagination.js +93 -0
  29. package/dist/schema/query.d.ts +118 -0
  30. package/dist/schema/query.js +242 -0
  31. package/dist/schema/record.d.ts +66 -0
  32. package/dist/schema/record.js +13 -0
  33. package/dist/schema/repository.d.ts +100 -0
  34. package/dist/schema/repository.js +288 -0
  35. package/dist/schema/selection.d.ts +25 -0
  36. package/dist/schema/selection.js +2 -0
  37. package/dist/{index.test.d.ts → schema/selection.spec.d.ts} +0 -0
  38. package/dist/schema/selection.spec.js +203 -0
  39. package/dist/util/lang.d.ts +5 -0
  40. package/dist/util/lang.js +22 -0
  41. package/dist/util/types.d.ts +13 -0
  42. package/dist/util/types.js +2 -0
  43. package/package.json +3 -3
  44. package/dist/index.test.js +0 -304
  45. package/dist/util/errors.d.ts +0 -3
  46. package/dist/util/errors.js +0 -9
  47. package/src/index.test.ts +0 -392
  48. package/src/index.ts +0 -501
  49. package/src/util/errors.ts +0 -6
package/dist/index.d.ts CHANGED
@@ -1,137 +1,6 @@
1
- export interface XataRecord {
2
- id: string;
3
- xata: {
4
- version: number;
5
- };
6
- read(): Promise<this>;
7
- update(data: Selectable<this>): Promise<this>;
8
- delete(): Promise<void>;
9
- }
10
- export declare type Queries<T> = {
11
- [key in keyof T as T[key] extends Query<infer A, infer B> ? key : never]: T[key];
12
- };
13
- export declare type OmitQueries<T> = {
14
- [key in keyof T as T[key] extends Query<infer A, infer B> ? never : key]: T[key];
15
- };
16
- export declare type OmitLinks<T> = {
17
- [key in keyof T as T[key] extends XataRecord ? never : key]: T[key];
18
- };
19
- export declare type OmitMethods<T> = {
20
- [key in keyof T as T[key] extends Function ? never : key]: T[key];
21
- };
22
- export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>;
23
- export declare type Select<T, K extends keyof T> = Pick<T, K> & Queries<T> & XataRecord;
24
- export declare type Include<T> = {
25
- [key in keyof T as T[key] extends XataRecord ? key : never]?: boolean | Array<keyof Selectable<T[key]>>;
26
- };
27
- declare type SortDirection = 'asc' | 'desc';
28
- declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
29
- declare type Constraint<T> = {
30
- [key in Operator]?: T;
31
- };
32
- declare type DeepConstraint<T> = T extends Record<string, any> ? {
33
- [key in keyof T]?: T[key] | DeepConstraint<T[key]>;
34
- } : Constraint<T>;
35
- declare type ComparableType = number | Date;
36
- export declare const gt: <T extends ComparableType>(value: T) => Constraint<T>;
37
- export declare const ge: <T extends ComparableType>(value: T) => Constraint<T>;
38
- export declare const gte: <T extends ComparableType>(value: T) => Constraint<T>;
39
- export declare const lt: <T extends ComparableType>(value: T) => Constraint<T>;
40
- export declare const lte: <T extends ComparableType>(value: T) => Constraint<T>;
41
- export declare const le: <T extends ComparableType>(value: T) => Constraint<T>;
42
- export declare const exists: (column: string) => Constraint<string>;
43
- export declare const notExists: (column: string) => Constraint<string>;
44
- export declare const startsWith: (value: string) => Constraint<string>;
45
- export declare const endsWith: (value: string) => Constraint<string>;
46
- export declare const pattern: (value: string) => Constraint<string>;
47
- export declare const is: <T>(value: T) => Constraint<T>;
48
- export declare const isNot: <T>(value: T) => Constraint<T>;
49
- export declare const contains: <T>(value: T) => Constraint<T>;
50
- export declare const includes: (value: string) => Constraint<string>;
51
- export declare const includesSubstring: (value: string) => Constraint<string>;
52
- export declare const includesPattern: (value: string) => Constraint<string>;
53
- export declare const includesAll: (value: string) => Constraint<string>;
54
- declare type FilterConstraints<T> = {
55
- [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
56
- };
57
- declare type BulkQueryOptions<T> = {
58
- filter?: FilterConstraints<T>;
59
- sort?: {
60
- column: keyof T;
61
- direction?: SortDirection;
62
- } | keyof T;
63
- };
64
- declare type QueryOrConstraint<T, R> = Query<T, R> | Constraint<T>;
65
- export declare class Query<T, R = T> {
66
- table: string;
67
- repository: Repository<T>;
68
- readonly $any?: QueryOrConstraint<T, R>[];
69
- readonly $all?: QueryOrConstraint<T, R>[];
70
- readonly $not?: QueryOrConstraint<T, R>[];
71
- readonly $none?: QueryOrConstraint<T, R>[];
72
- readonly $sort?: Record<string, SortDirection>;
73
- constructor(repository: Repository<T> | null, table: string, data: Partial<Query<T, R>>, parent?: Query<T, R>);
74
- any(...queries: Query<T, R>[]): Query<T, R>;
75
- all(...queries: Query<T, R>[]): Query<T, R>;
76
- not(...queries: Query<T, R>[]): Query<T, R>;
77
- none(...queries: Query<T, R>[]): Query<T, R>;
78
- filter(constraints: FilterConstraints<T>): Query<T, R>;
79
- filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
80
- sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
81
- getMany(options?: BulkQueryOptions<T>): Promise<R[]>;
82
- getOne(options?: BulkQueryOptions<T>): Promise<R | null>;
83
- deleteAll(): Promise<number>;
84
- include(columns: Include<T>): this;
85
- }
86
- export declare abstract class Repository<T> extends Query<T, Selectable<T>> {
87
- select<K extends keyof Selectable<T>>(...columns: K[]): Query<T, Select<T, K>>;
88
- abstract create(object: Selectable<T>): Promise<T>;
89
- abstract read(id: string): Promise<T | null>;
90
- abstract update(id: string, object: Partial<T>): Promise<T>;
91
- abstract delete(id: string): void;
92
- abstract query<R>(query: Query<T, R>): Promise<R[]>;
93
- }
94
- export declare class RestRepository<T> extends Repository<T> {
95
- client: BaseClient<any>;
96
- fetch: any;
97
- constructor(client: BaseClient<any>, table: string);
98
- request(method: string, path: string, body?: unknown): Promise<any>;
99
- select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>;
100
- create(object: T): Promise<T>;
101
- read(id: string): Promise<T | null>;
102
- update(id: string, object: Partial<T>): Promise<T>;
103
- delete(id: string): Promise<void>;
104
- query<R>(query: Query<T, R>): Promise<R[]>;
105
- }
106
- interface RepositoryFactory {
107
- createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
108
- }
109
- export declare class RestRespositoryFactory implements RepositoryFactory {
110
- createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
111
- }
112
- declare type BranchStrategyValue = string | undefined | null;
113
- declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
114
- declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
115
- declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
116
- export declare type XataClientOptions = {
117
- fetch?: unknown;
118
- databaseURL: string;
119
- branch: BranchStrategyOption;
120
- apiKey: string;
121
- repositoryFactory?: RepositoryFactory;
122
- };
123
- export declare class BaseClient<D extends Record<string, Repository<any>>> {
124
- options: XataClientOptions;
125
- private links;
126
- private branch;
127
- db: D;
128
- constructor(options: XataClientOptions, links: Links);
129
- initObject<T>(table: string, object: object): T;
130
- getBranch(): Promise<string>;
131
- }
132
1
  export declare class XataError extends Error {
133
2
  readonly status: number;
134
3
  constructor(message: string, status: number);
135
4
  }
136
- export declare type Links = Record<string, Array<string[]>>;
137
- export {};
5
+ export * from './api';
6
+ export * from './schema';
package/dist/index.js CHANGED
@@ -1,363 +1,20 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- 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); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
15
  };
18
16
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.Query = 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;
20
- const errors_1 = require("./util/errors");
21
- const gt = (value) => ({ $gt: value });
22
- exports.gt = gt;
23
- const ge = (value) => ({ $ge: value });
24
- exports.ge = ge;
25
- const gte = (value) => ({ $ge: value });
26
- exports.gte = gte;
27
- const lt = (value) => ({ $lt: value });
28
- exports.lt = lt;
29
- const lte = (value) => ({ $le: value });
30
- exports.lte = lte;
31
- const le = (value) => ({ $le: value });
32
- exports.le = le;
33
- const exists = (column) => ({ $exists: column });
34
- exports.exists = exists;
35
- const notExists = (column) => ({ $notExists: column });
36
- exports.notExists = notExists;
37
- const startsWith = (value) => ({ $startsWith: value });
38
- exports.startsWith = startsWith;
39
- const endsWith = (value) => ({ $endsWith: value });
40
- exports.endsWith = endsWith;
41
- const pattern = (value) => ({ $pattern: value });
42
- exports.pattern = pattern;
43
- const is = (value) => ({ $is: value });
44
- exports.is = is;
45
- const isNot = (value) => ({ $isNot: value });
46
- exports.isNot = isNot;
47
- const contains = (value) => ({ $contains: value });
48
- exports.contains = contains;
49
- // TODO: these can only be applied to columns of type "multiple"
50
- const includes = (value) => ({ $includes: value });
51
- exports.includes = includes;
52
- const includesSubstring = (value) => ({ $includesSubstring: value });
53
- exports.includesSubstring = includesSubstring;
54
- const includesPattern = (value) => ({ $includesPattern: value });
55
- exports.includesPattern = includesPattern;
56
- const includesAll = (value) => ({ $includesAll: value });
57
- exports.includesAll = includesAll;
58
- class Query {
59
- constructor(repository, table, data, parent) {
60
- if (repository) {
61
- this.repository = repository;
62
- }
63
- else {
64
- this.repository = this;
65
- }
66
- this.table = table;
67
- // For some reason Object.assign(this, parent) didn't work in this case
68
- // so doing all this manually:
69
- this.$any = parent === null || parent === void 0 ? void 0 : parent.$any;
70
- this.$all = parent === null || parent === void 0 ? void 0 : parent.$all;
71
- this.$not = parent === null || parent === void 0 ? void 0 : parent.$not;
72
- this.$none = parent === null || parent === void 0 ? void 0 : parent.$none;
73
- this.$sort = parent === null || parent === void 0 ? void 0 : parent.$sort;
74
- Object.assign(this, data);
75
- // These bindings are used to support deconstructing
76
- // const { any, not, filter, sort } = xata.users.query()
77
- this.any = this.any.bind(this);
78
- this.all = this.all.bind(this);
79
- this.not = this.not.bind(this);
80
- this.filter = this.filter.bind(this);
81
- this.sort = this.sort.bind(this);
82
- this.none = this.none.bind(this);
83
- Object.defineProperty(this, 'table', { enumerable: false });
84
- Object.defineProperty(this, 'repository', { enumerable: false });
85
- }
86
- any(...queries) {
87
- return new Query(this.repository, this.table, {
88
- $any: (this.$any || []).concat(queries)
89
- }, this);
90
- }
91
- all(...queries) {
92
- return new Query(this.repository, this.table, {
93
- $all: (this.$all || []).concat(queries)
94
- }, this);
95
- }
96
- not(...queries) {
97
- return new Query(this.repository, this.table, {
98
- $not: (this.$not || []).concat(queries)
99
- }, this);
100
- }
101
- none(...queries) {
102
- return new Query(this.repository, this.table, {
103
- $none: (this.$none || []).concat(queries)
104
- }, this);
105
- }
106
- filter(a, b) {
107
- if (arguments.length === 1) {
108
- const constraints = a;
109
- const queries = [];
110
- for (const [column, constraint] of Object.entries(constraints)) {
111
- queries.push({ [column]: constraint });
112
- }
113
- return new Query(this.repository, this.table, {
114
- $all: (this.$all || []).concat(queries)
115
- }, this);
116
- }
117
- else {
118
- const column = a;
119
- const value = b;
120
- return new Query(this.repository, this.table, {
121
- $all: (this.$all || []).concat({ [column]: value })
122
- }, this);
123
- }
124
- }
125
- sort(column, direction) {
126
- const sort = Object.assign(Object.assign({}, this.$sort), { [column]: direction });
127
- const q = new Query(this.repository, this.table, {
128
- $sort: sort
129
- }, this);
130
- return q;
131
- }
132
- // TODO: pagination. Maybe implement different methods for different type of paginations
133
- // and one to simply get the first records returned by the query with no pagination.
134
- getMany(options) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- // TODO: use options
137
- return this.repository.query(this);
138
- });
139
- }
140
- getOne(options) {
141
- return __awaiter(this, void 0, void 0, function* () {
142
- // TODO: use options
143
- const arr = yield this.getMany(); // TODO, limit to 1
144
- return arr[0] || null;
145
- });
146
- }
147
- deleteAll() {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- // Return number of affected rows
150
- return 0;
151
- });
152
- }
153
- include(columns) {
154
- // TODO
155
- return this;
156
- }
157
- }
158
- exports.Query = Query;
159
- class Repository extends Query {
160
- select(...columns) {
161
- return new Query(this.repository, this.table, {});
162
- }
163
- }
164
- exports.Repository = Repository;
165
- class RestRepository extends Repository {
166
- constructor(client, table) {
167
- super(null, table, {});
168
- this.client = client;
169
- const doWeHaveFetch = typeof fetch !== 'undefined';
170
- const isInjectedFetchProblematic = !this.client.options.fetch;
171
- if (doWeHaveFetch) {
172
- this.fetch = fetch;
173
- }
174
- else if (isInjectedFetchProblematic) {
175
- throw new Error(errors_1.errors.falsyFetchImplementation);
176
- }
177
- else {
178
- this.fetch = this.client.options.fetch;
179
- }
180
- Object.defineProperty(this, 'client', { enumerable: false });
181
- Object.defineProperty(this, 'fetch', { enumerable: false });
182
- Object.defineProperty(this, 'hostname', { enumerable: false });
183
- }
184
- request(method, path, body) {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- const { databaseURL, apiKey } = this.client.options;
187
- const branch = yield this.client.getBranch();
188
- const resp = yield this.fetch(`${databaseURL}:${branch}${path}`, {
189
- method,
190
- headers: {
191
- Accept: '*/*',
192
- 'Content-Type': 'application/json',
193
- Authorization: `Bearer ${apiKey}`
194
- },
195
- body: JSON.stringify(body)
196
- });
197
- if (!resp.ok) {
198
- try {
199
- const json = yield resp.json();
200
- const message = json.message;
201
- if (typeof message === 'string') {
202
- throw new XataError(message, resp.status);
203
- }
204
- }
205
- catch (err) {
206
- if (err instanceof XataError)
207
- throw err;
208
- // Ignore errors for other reasons.
209
- // For example if the response's body cannot be parsed as JSON
210
- }
211
- throw new XataError(resp.statusText, resp.status);
212
- }
213
- if (resp.status === 204)
214
- return;
215
- return resp.json();
216
- });
217
- }
218
- select(...columns) {
219
- return new Query(this.repository, this.table, {});
220
- }
221
- create(object) {
222
- return __awaiter(this, void 0, void 0, function* () {
223
- const body = Object.assign({}, object);
224
- for (const key of Object.keys(body)) {
225
- const value = body[key];
226
- if (value && typeof value === 'object' && typeof value.id === 'string') {
227
- body[key] = value.id;
228
- }
229
- }
230
- const obj = yield this.request('POST', `/tables/${this.table}/data`, body);
231
- return this.client.initObject(this.table, obj);
232
- });
233
- }
234
- read(id) {
235
- return __awaiter(this, void 0, void 0, function* () {
236
- try {
237
- const obj = yield this.request('GET', `/tables/${this.table}/data/${id}`);
238
- return this.client.initObject(this.table, obj);
239
- }
240
- catch (err) {
241
- if (err.status === 404)
242
- return null;
243
- throw err;
244
- }
245
- });
246
- }
247
- update(id, object) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- const obj = yield this.request('PUT', `/tables/${this.table}/data/${id}`, object);
250
- return this.client.initObject(this.table, obj);
251
- });
252
- }
253
- delete(id) {
254
- return __awaiter(this, void 0, void 0, function* () {
255
- yield this.request('DELETE', `/tables/${this.table}/data/${id}`);
256
- });
257
- }
258
- query(query) {
259
- return __awaiter(this, void 0, void 0, function* () {
260
- const filter = {
261
- $any: query.$any,
262
- $all: query.$all,
263
- $not: query.$not,
264
- $none: query.$none
265
- };
266
- const body = {
267
- filter: Object.values(filter).some(Boolean) ? filter : undefined,
268
- sort: query.$sort
269
- };
270
- const result = yield this.request('POST', `/tables/${this.table}/query`, body);
271
- return result.records.map((record) => this.client.initObject(this.table, record));
272
- });
273
- }
274
- }
275
- exports.RestRepository = RestRepository;
276
- class RestRespositoryFactory {
277
- createRepository(client, table) {
278
- return new RestRepository(client, table);
279
- }
280
- }
281
- exports.RestRespositoryFactory = RestRespositoryFactory;
282
- class BaseClient {
283
- constructor(options, links) {
284
- if (!options.databaseURL || !options.apiKey || !options.branch) {
285
- throw new Error('Options databaseURL, apiKey and branch are required');
286
- }
287
- this.options = options;
288
- this.links = links;
289
- }
290
- initObject(table, object) {
291
- const o = {};
292
- Object.assign(o, object);
293
- const tableLinks = this.links[table] || [];
294
- for (const link of tableLinks) {
295
- const [field, linkTable] = link;
296
- const value = o[field];
297
- if (value && typeof value === 'object') {
298
- const { id } = value;
299
- if (Object.keys(value).find((col) => col === 'id')) {
300
- o[field] = this.initObject(linkTable, value);
301
- }
302
- else if (id) {
303
- o[field] = {
304
- id,
305
- get: () => {
306
- this.db[linkTable].read(id);
307
- }
308
- };
309
- }
310
- }
311
- }
312
- const db = this.db;
313
- o.read = function () {
314
- return db[table].read(o['id']);
315
- };
316
- o.update = function (data) {
317
- return db[table].update(o['id'], data);
318
- };
319
- o.delete = function () {
320
- return db[table].delete(o['id']);
321
- };
322
- for (const prop of ['read', 'update', 'delete']) {
323
- Object.defineProperty(o, prop, { enumerable: false });
324
- }
325
- // TODO: links and rev links
326
- Object.freeze(o);
327
- return o;
328
- }
329
- getBranch() {
330
- var e_1, _a;
331
- return __awaiter(this, void 0, void 0, function* () {
332
- if (this.branch)
333
- return this.branch;
334
- const { branch: param } = this.options;
335
- const strategies = Array.isArray(param) ? [...param] : [param];
336
- const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
337
- return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
338
- });
339
- try {
340
- for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
341
- const strategy = strategies_1_1.value;
342
- const branch = yield evaluateBranch(strategy);
343
- if (branch) {
344
- this.branch = branch;
345
- return branch;
346
- }
347
- }
348
- }
349
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
350
- finally {
351
- try {
352
- if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
353
- }
354
- finally { if (e_1) throw e_1.error; }
355
- }
356
- throw new Error('Unable to resolve branch value');
357
- });
358
- }
359
- }
360
- exports.BaseClient = BaseClient;
17
+ exports.XataError = void 0;
361
18
  class XataError extends Error {
362
19
  constructor(message, status) {
363
20
  super(message);
@@ -365,6 +22,5 @@ class XataError extends Error {
365
22
  }
366
23
  }
367
24
  exports.XataError = XataError;
368
- const isBranchStrategyBuilder = (strategy) => {
369
- return typeof strategy === 'function';
370
- };
25
+ __exportStar(require("./api"), exports);
26
+ __exportStar(require("./schema"), exports);
@@ -0,0 +1,22 @@
1
+ import { XataRecord } from './record';
2
+ import { SelectableColumn } from './selection';
3
+ export declare type SortDirection = 'asc' | 'desc';
4
+ export declare type SortFilterExtended<T extends XataRecord> = {
5
+ column: SelectableColumn<T>;
6
+ direction?: SortDirection;
7
+ };
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>;
10
+ export declare type FilterOperator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
11
+ export declare function buildSortFilter<T extends XataRecord>(filter?: SortFilter<T> | SortFilter<T>[]): {
12
+ [key: string]: SortDirection;
13
+ } | undefined;
14
+ export declare type Constraint<T> = {
15
+ [key in FilterOperator]?: T;
16
+ };
17
+ export declare type DeepConstraint<T> = T extends Record<string, any> ? {
18
+ [key in keyof T]?: T[key] | DeepConstraint<T[key]>;
19
+ } : Constraint<T>;
20
+ export declare type FilterConstraints<T> = {
21
+ [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
22
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSortFilter = exports.isSortFilterObject = void 0;
4
+ const lang_1 = require("../util/lang");
5
+ function isSortFilterObject(filter) {
6
+ return (0, lang_1.isObject)(filter) && filter.column !== undefined;
7
+ }
8
+ exports.isSortFilterObject = isSortFilterObject;
9
+ function buildSortFilter(filter) {
10
+ if (!filter)
11
+ return undefined;
12
+ const filters = Array.isArray(filter) ? filter : [filter];
13
+ return filters.reduce((acc, item) => {
14
+ if (typeof item === 'string') {
15
+ return Object.assign(Object.assign({}, acc), { [item]: 'asc' });
16
+ }
17
+ else if (isSortFilterObject(item)) {
18
+ return Object.assign(Object.assign({}, acc), { [item.column]: item.direction });
19
+ }
20
+ else {
21
+ return acc;
22
+ }
23
+ }, {});
24
+ }
25
+ exports.buildSortFilter = buildSortFilter;
@@ -0,0 +1,7 @@
1
+ export * from './operators';
2
+ export * from './pagination';
3
+ export { Query } from './query';
4
+ export { isIdentifiable, isXataRecord } from './record';
5
+ export type { Identifiable, XataRecord } from './record';
6
+ export { BaseClient, Repository, RestRepository, RestRespositoryFactory } from './repository';
7
+ export type { XataClientOptions } from './repository';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.BaseClient = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
18
+ __exportStar(require("./operators"), exports);
19
+ __exportStar(require("./pagination"), exports);
20
+ var query_1 = require("./query");
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; } });
25
+ var repository_1 = require("./repository");
26
+ Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
27
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
28
+ Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_1.RestRepository; } });
29
+ Object.defineProperty(exports, "RestRespositoryFactory", { enumerable: true, get: function () { return repository_1.RestRespositoryFactory; } });