@xata.io/client 0.1.1 → 0.1.2
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/README.md +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +24 -18
- package/dist/index.test.js +2 -2
- package/package.json +2 -2
- package/src/index.test.ts +2 -2
- package/src/index.ts +37 -33
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Visit https://github.com/xataio/client-ts for more information.
|
package/dist/index.d.ts
CHANGED
@@ -23,19 +23,22 @@ export declare type Include<T> = {
|
|
23
23
|
[key in keyof T as T[key] extends XataRecord ? key : never]?: boolean | Array<keyof Selectable<T[key]>>;
|
24
24
|
};
|
25
25
|
declare type SortDirection = 'asc' | 'desc';
|
26
|
-
declare type Operator = '
|
26
|
+
declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
|
27
27
|
declare type Constraint<T> = Partial<Record<Operator, T>>;
|
28
28
|
declare type ComparableType = number | Date;
|
29
29
|
export declare const gt: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
|
30
|
+
export declare const ge: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
|
30
31
|
export declare const gte: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
|
31
32
|
export declare const lt: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
|
32
33
|
export declare const lte: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
|
34
|
+
export declare const le: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
|
33
35
|
export declare const exists: (column: string) => Constraint<string>;
|
34
36
|
export declare const notExists: (column: string) => Constraint<string>;
|
35
37
|
export declare const startsWith: (value: string) => Constraint<string>;
|
36
38
|
export declare const endsWith: (value: string) => Constraint<string>;
|
37
39
|
export declare const pattern: (value: string) => Constraint<string>;
|
38
40
|
export declare const isNot: <T>(value: T) => Partial<Record<Operator, T>>;
|
41
|
+
export declare const contains: <T>(value: T) => Partial<Record<Operator, T>>;
|
39
42
|
export declare const includes: (value: string) => Constraint<string>;
|
40
43
|
export declare const includesSubstring: (value: string) => Constraint<string>;
|
41
44
|
export declare const includesPattern: (value: string) => Constraint<string>;
|
@@ -109,8 +112,8 @@ export declare class RestRespositoryFactory implements RepositoryFactory {
|
|
109
112
|
}
|
110
113
|
export declare type XataClientOptions = {
|
111
114
|
fetch?: unknown;
|
112
|
-
|
113
|
-
|
115
|
+
databaseURL: string;
|
116
|
+
apiKey: string;
|
114
117
|
repositoryFactory?: RepositoryFactory;
|
115
118
|
};
|
116
119
|
export declare class BaseClient<D extends Record<string, Repository<any>>> {
|
package/dist/index.js
CHANGED
@@ -9,35 +9,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.Query = exports.includesAll = exports.includesPattern = exports.includesSubstring = exports.includes = exports.isNot = exports.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.lte = exports.lt = exports.gte = exports.gt = void 0;
|
13
|
-
const gt = (value) => ({
|
12
|
+
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.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.le = exports.lte = exports.lt = exports.gte = exports.ge = exports.gt = void 0;
|
13
|
+
const gt = (value) => ({ $gt: value });
|
14
14
|
exports.gt = gt;
|
15
|
-
const
|
15
|
+
const ge = (value) => ({ $ge: value });
|
16
|
+
exports.ge = ge;
|
17
|
+
const gte = (value) => ({ $ge: value });
|
16
18
|
exports.gte = gte;
|
17
|
-
const lt = (value) => ({
|
19
|
+
const lt = (value) => ({ $lt: value });
|
18
20
|
exports.lt = lt;
|
19
|
-
const lte = (value) => ({
|
21
|
+
const lte = (value) => ({ $le: value });
|
20
22
|
exports.lte = lte;
|
21
|
-
const
|
23
|
+
const le = (value) => ({ $le: value });
|
24
|
+
exports.le = le;
|
25
|
+
const exists = (column) => ({ $exists: column });
|
22
26
|
exports.exists = exists;
|
23
|
-
const notExists = (column) => ({
|
27
|
+
const notExists = (column) => ({ $notExists: column });
|
24
28
|
exports.notExists = notExists;
|
25
|
-
const startsWith = (value) => ({
|
29
|
+
const startsWith = (value) => ({ $startsWith: value });
|
26
30
|
exports.startsWith = startsWith;
|
27
|
-
const endsWith = (value) => ({
|
31
|
+
const endsWith = (value) => ({ $endsWith: value });
|
28
32
|
exports.endsWith = endsWith;
|
29
|
-
const pattern = (value) => ({
|
33
|
+
const pattern = (value) => ({ $pattern: value });
|
30
34
|
exports.pattern = pattern;
|
31
|
-
const isNot = (value) => ({
|
35
|
+
const isNot = (value) => ({ $isNot: value });
|
32
36
|
exports.isNot = isNot;
|
37
|
+
const contains = (value) => ({ $contains: value });
|
38
|
+
exports.contains = contains;
|
33
39
|
// TODO: these can only be applied to columns of type "multiple"
|
34
|
-
const includes = (value) => ({
|
40
|
+
const includes = (value) => ({ $includes: value });
|
35
41
|
exports.includes = includes;
|
36
|
-
const includesSubstring = (value) => ({
|
42
|
+
const includesSubstring = (value) => ({ $includesSubstring: value });
|
37
43
|
exports.includesSubstring = includesSubstring;
|
38
|
-
const includesPattern = (value) => ({
|
44
|
+
const includesPattern = (value) => ({ $includesPattern: value });
|
39
45
|
exports.includesPattern = includesPattern;
|
40
|
-
const includesAll = (value) => ({
|
46
|
+
const includesAll = (value) => ({ $includesAll: value });
|
41
47
|
exports.includesAll = includesAll;
|
42
48
|
class Query {
|
43
49
|
constructor(repository, table, data, parent) {
|
@@ -186,13 +192,13 @@ class RestRepository extends Repository {
|
|
186
192
|
}
|
187
193
|
request(method, path, body) {
|
188
194
|
return __awaiter(this, void 0, void 0, function* () {
|
189
|
-
const {
|
190
|
-
const resp = yield this.fetch(`${
|
195
|
+
const { databaseURL } = this.client.options;
|
196
|
+
const resp = yield this.fetch(`${databaseURL}${path}`, {
|
191
197
|
method,
|
192
198
|
headers: {
|
193
199
|
Accept: '*/*',
|
194
200
|
'Content-Type': 'application/json',
|
195
|
-
Authorization: `Bearer ${this.client.options.
|
201
|
+
Authorization: `Bearer ${this.client.options.apiKey}`
|
196
202
|
},
|
197
203
|
body: JSON.stringify(body)
|
198
204
|
});
|
package/dist/index.test.js
CHANGED
@@ -13,8 +13,8 @@ const _1 = require("./");
|
|
13
13
|
const fetch = jest.fn();
|
14
14
|
const client = new _1.BaseClient({
|
15
15
|
fetch,
|
16
|
-
|
17
|
-
|
16
|
+
apiKey: '1234',
|
17
|
+
databaseURL: 'https://my-workspace-5df34do.staging.xatabase.co/db/xata:main'
|
18
18
|
}, {});
|
19
19
|
const users = new _1.RestRepository(client, 'users');
|
20
20
|
describe('request', () => {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@xata.io/client",
|
3
|
-
"version": "0.1.
|
4
|
-
"description": "Xata.io SDK for
|
3
|
+
"version": "0.1.2",
|
4
|
+
"description": "Xata.io SDK for TypeScript and JavaScript",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.ts",
|
7
7
|
"scripts": {
|
package/src/index.test.ts
CHANGED
@@ -4,8 +4,8 @@ const fetch = jest.fn();
|
|
4
4
|
const client = new BaseClient(
|
5
5
|
{
|
6
6
|
fetch,
|
7
|
-
|
8
|
-
|
7
|
+
apiKey: '1234',
|
8
|
+
databaseURL: 'https://my-workspace-5df34do.staging.xatabase.co/db/xata:main'
|
9
9
|
},
|
10
10
|
{}
|
11
11
|
);
|
package/src/index.ts
CHANGED
@@ -34,20 +34,21 @@ export type Include<T> = {
|
|
34
34
|
type SortDirection = 'asc' | 'desc';
|
35
35
|
|
36
36
|
type Operator =
|
37
|
-
| '
|
38
|
-
| '
|
39
|
-
| '
|
40
|
-
| '
|
41
|
-
| '
|
42
|
-
| '
|
43
|
-
| '
|
44
|
-
| '
|
45
|
-
| '
|
46
|
-
| '
|
47
|
-
| '
|
48
|
-
| '
|
49
|
-
| '
|
50
|
-
| '
|
37
|
+
| '$gt'
|
38
|
+
| '$lt'
|
39
|
+
| '$ge'
|
40
|
+
| '$le'
|
41
|
+
| '$exists'
|
42
|
+
| '$notExists'
|
43
|
+
| '$endsWith'
|
44
|
+
| '$startsWith'
|
45
|
+
| '$pattern'
|
46
|
+
| '$isNot'
|
47
|
+
| '$contains'
|
48
|
+
| '$includes'
|
49
|
+
| '$includesSubstring'
|
50
|
+
| '$includesPattern'
|
51
|
+
| '$includesAll';
|
51
52
|
|
52
53
|
// TODO: restrict constraints depending on type?
|
53
54
|
// E.g. startsWith cannot be used with numbers
|
@@ -55,22 +56,25 @@ type Constraint<T> = Partial<Record<Operator, T>>;
|
|
55
56
|
|
56
57
|
type ComparableType = number | Date;
|
57
58
|
|
58
|
-
export const gt = <T extends ComparableType>(value: T): Constraint<T> => ({
|
59
|
-
export const
|
60
|
-
export const
|
61
|
-
export const
|
62
|
-
export const
|
63
|
-
export const
|
64
|
-
export const
|
65
|
-
export const
|
66
|
-
export const
|
67
|
-
export const
|
59
|
+
export const gt = <T extends ComparableType>(value: T): Constraint<T> => ({ $gt: value });
|
60
|
+
export const ge = <T extends ComparableType>(value: T): Constraint<T> => ({ $ge: value });
|
61
|
+
export const gte = <T extends ComparableType>(value: T): Constraint<T> => ({ $ge: value });
|
62
|
+
export const lt = <T extends ComparableType>(value: T): Constraint<T> => ({ $lt: value });
|
63
|
+
export const lte = <T extends ComparableType>(value: T): Constraint<T> => ({ $le: value });
|
64
|
+
export const le = <T extends ComparableType>(value: T): Constraint<T> => ({ $le: value });
|
65
|
+
export const exists = (column: string): Constraint<string> => ({ $exists: column });
|
66
|
+
export const notExists = (column: string): Constraint<string> => ({ $notExists: column });
|
67
|
+
export const startsWith = (value: string): Constraint<string> => ({ $startsWith: value });
|
68
|
+
export const endsWith = (value: string): Constraint<string> => ({ $endsWith: value });
|
69
|
+
export const pattern = (value: string): Constraint<string> => ({ $pattern: value });
|
70
|
+
export const isNot = <T>(value: T): Constraint<T> => ({ $isNot: value });
|
71
|
+
export const contains = <T>(value: T): Constraint<T> => ({ $contains: value });
|
68
72
|
|
69
73
|
// TODO: these can only be applied to columns of type "multiple"
|
70
|
-
export const includes = (value: string): Constraint<string> => ({
|
71
|
-
export const includesSubstring = (value: string): Constraint<string> => ({
|
72
|
-
export const includesPattern = (value: string): Constraint<string> => ({
|
73
|
-
export const includesAll = (value: string): Constraint<string> => ({
|
74
|
+
export const includes = (value: string): Constraint<string> => ({ $includes: value });
|
75
|
+
export const includesSubstring = (value: string): Constraint<string> => ({ $includesSubstring: value });
|
76
|
+
export const includesPattern = (value: string): Constraint<string> => ({ $includesPattern: value });
|
77
|
+
export const includesAll = (value: string): Constraint<string> => ({ $includesAll: value });
|
74
78
|
|
75
79
|
type FilterConstraints<T> = {
|
76
80
|
[key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | Constraint<T[key]>;
|
@@ -300,13 +304,13 @@ export class RestRepository<T> extends Repository<T> {
|
|
300
304
|
}
|
301
305
|
|
302
306
|
async request(method: string, path: string, body?: unknown) {
|
303
|
-
const {
|
304
|
-
const resp: Response = await this.fetch(`${
|
307
|
+
const { databaseURL } = this.client.options;
|
308
|
+
const resp: Response = await this.fetch(`${databaseURL}${path}`, {
|
305
309
|
method,
|
306
310
|
headers: {
|
307
311
|
Accept: '*/*',
|
308
312
|
'Content-Type': 'application/json',
|
309
|
-
Authorization: `Bearer ${this.client.options.
|
313
|
+
Authorization: `Bearer ${this.client.options.apiKey}`
|
310
314
|
},
|
311
315
|
body: JSON.stringify(body)
|
312
316
|
});
|
@@ -374,8 +378,8 @@ export class RestRespositoryFactory implements RepositoryFactory {
|
|
374
378
|
|
375
379
|
export type XataClientOptions = {
|
376
380
|
fetch?: unknown;
|
377
|
-
|
378
|
-
|
381
|
+
databaseURL: string;
|
382
|
+
apiKey: string;
|
379
383
|
repositoryFactory?: RepositoryFactory;
|
380
384
|
};
|
381
385
|
|