@xata.io/client 0.0.0-alpha.fd777ef → 0.0.0-beta.09bfef8
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/CHANGELOG.md +14 -0
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.js +8 -8
- package/dist/api/fetcher.d.ts +15 -0
- package/dist/api/fetcher.js +19 -13
- package/dist/schema/config.d.ts +4 -0
- package/dist/schema/config.js +83 -0
- package/dist/schema/filters.d.ts +16 -12
- package/dist/schema/operators.d.ts +17 -27
- package/dist/schema/operators.js +1 -14
- package/dist/schema/query.d.ts +3 -3
- package/dist/schema/repository.d.ts +56 -8
- package/dist/schema/repository.js +143 -54
- package/dist/schema/selection.d.ts +4 -3
- package/dist/schema/selection.spec.js +152 -58
- package/dist/schema/sorting.d.ts +8 -3
- package/dist/schema/sorting.js +18 -15
- package/dist/schema/sorting.spec.d.ts +1 -0
- package/dist/schema/sorting.spec.js +9 -0
- package/dist/util/environment.d.ts +5 -0
- package/dist/util/environment.js +68 -0
- package/dist/util/fetch.d.ts +2 -0
- package/dist/util/fetch.js +13 -0
- package/dist/util/lang.d.ts +1 -1
- package/dist/util/lang.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.7.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 6ce5512: Add bulk operations for all methods
|
8
|
+
- 2a1fa4f: Introduced automatic branch resolution mechanism
|
9
|
+
|
10
|
+
### Patch Changes
|
11
|
+
|
12
|
+
- d033f3a: Improve column selection output type with non-nullable columns
|
13
|
+
- b1e92db: Include stack trace with errors
|
14
|
+
- deed570: Improve sorting with multiple properties
|
15
|
+
- 80b5417: Improve filtering types
|
16
|
+
|
3
17
|
## 0.6.0
|
4
18
|
|
5
19
|
### Minor Changes
|
package/dist/api/client.d.ts
CHANGED
package/dist/api/client.js
CHANGED
@@ -13,24 +13,24 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
13
13
|
var _XataApiClient_extraProps;
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
exports.XataApiClient = void 0;
|
16
|
+
const config_1 = require("../schema/config");
|
17
|
+
const fetch_1 = require("../util/fetch");
|
16
18
|
const components_1 = require("./components");
|
17
19
|
const providers_1 = require("./providers");
|
18
20
|
class XataApiClient {
|
19
21
|
constructor(options) {
|
20
22
|
var _a, _b;
|
21
23
|
_XataApiClient_extraProps.set(this, void 0);
|
22
|
-
const
|
23
|
-
const
|
24
|
-
if (!
|
25
|
-
|
26
|
-
throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
|
24
|
+
const provider = (_a = options.host) !== null && _a !== void 0 ? _a : 'production';
|
25
|
+
const apiKey = (_b = options === null || options === void 0 ? void 0 : options.apiKey) !== null && _b !== void 0 ? _b : (0, config_1.getAPIKey)();
|
26
|
+
if (!apiKey) {
|
27
|
+
throw new Error('Could not resolve a valid apiKey');
|
27
28
|
}
|
28
|
-
const provider = (_b = options.host) !== null && _b !== void 0 ? _b : 'production';
|
29
29
|
__classPrivateFieldSet(this, _XataApiClient_extraProps, {
|
30
30
|
apiUrl: (0, providers_1.getHostUrl)(provider, 'main'),
|
31
31
|
workspacesApiUrl: (0, providers_1.getHostUrl)(provider, 'workspaces'),
|
32
|
-
fetchImpl,
|
33
|
-
apiKey
|
32
|
+
fetchImpl: (0, fetch_1.getFetchImplementation)(options.fetch),
|
33
|
+
apiKey
|
34
34
|
}, "f");
|
35
35
|
}
|
36
36
|
get user() {
|
package/dist/api/fetcher.d.ts
CHANGED
@@ -23,3 +23,18 @@ export declare type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> =
|
|
23
23
|
pathParams?: TPathParams;
|
24
24
|
};
|
25
25
|
export declare function fetch<TData, TBody extends Record<string, unknown> | undefined, THeaders extends Record<string, unknown>, TQueryParams extends Record<string, unknown>, TPathParams extends Record<string, string>>({ url: path, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> & FetcherExtraProps): Promise<TData>;
|
26
|
+
export declare class FetcherError extends Error {
|
27
|
+
status: number;
|
28
|
+
errors: Array<{
|
29
|
+
status: number;
|
30
|
+
message?: string;
|
31
|
+
}> | undefined;
|
32
|
+
constructor(data: {
|
33
|
+
message: string;
|
34
|
+
status: number;
|
35
|
+
errors?: Array<{
|
36
|
+
status: number;
|
37
|
+
message?: string;
|
38
|
+
}>;
|
39
|
+
}, parent?: Error);
|
40
|
+
}
|
package/dist/api/fetcher.js
CHANGED
@@ -9,9 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.fetch = void 0;
|
13
|
-
/* eslint-disable @typescript-eslint/no-throw-literal */
|
14
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
12
|
+
exports.FetcherError = exports.fetch = void 0;
|
15
13
|
const lang_1 = require("../util/lang");
|
16
14
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
17
15
|
const query = new URLSearchParams(queryParams).toString();
|
@@ -54,20 +52,28 @@ function fetch({ url: path, method, body, headers, pathParams, queryParams, fetc
|
|
54
52
|
return jsonResponse;
|
55
53
|
}
|
56
54
|
const { message = 'Unknown error', errors } = jsonResponse;
|
57
|
-
throw
|
55
|
+
throw new FetcherError({ message, status: response.status, errors });
|
58
56
|
}
|
59
|
-
catch (
|
60
|
-
|
61
|
-
|
62
|
-
}
|
63
|
-
else {
|
64
|
-
throw withStatus({ message: 'Network response was not ok' }, response.status);
|
65
|
-
}
|
57
|
+
catch (error) {
|
58
|
+
const message = hasMessage(error) ? error.message : 'Unknown network error';
|
59
|
+
const parent = error instanceof Error ? error : undefined;
|
60
|
+
throw new FetcherError({ message, status: response.status }, parent);
|
66
61
|
}
|
67
62
|
});
|
68
63
|
}
|
69
64
|
exports.fetch = fetch;
|
70
|
-
const
|
65
|
+
const hasMessage = (error) => {
|
71
66
|
return (0, lang_1.isObject)(error) && (0, lang_1.isString)(error.message);
|
72
67
|
};
|
73
|
-
|
68
|
+
class FetcherError extends Error {
|
69
|
+
constructor(data, parent) {
|
70
|
+
super(data.message);
|
71
|
+
this.status = data.status;
|
72
|
+
this.errors = data.errors;
|
73
|
+
if (parent) {
|
74
|
+
this.stack = parent.stack;
|
75
|
+
this.cause = parent.cause;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
exports.FetcherError = FetcherError;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { FetcherExtraProps } from '../api/fetcher';
|
2
|
+
export declare function getBranch(fetchProps: Omit<FetcherExtraProps, 'workspacesApiUrl'>): Promise<string | undefined>;
|
3
|
+
export declare function getDatabaseUrl(): string | undefined;
|
4
|
+
export declare function getAPIKey(): string | undefined;
|
@@ -0,0 +1,83 @@
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.getAPIKey = exports.getDatabaseUrl = exports.getBranch = void 0;
|
13
|
+
const api_1 = require("../api");
|
14
|
+
const environment_1 = require("../util/environment");
|
15
|
+
const lang_1 = require("../util/lang");
|
16
|
+
const envBranchNames = [
|
17
|
+
'XATA_BRANCH',
|
18
|
+
'VERCEL_GIT_COMMIT_REF',
|
19
|
+
'CF_PAGES_BRANCH',
|
20
|
+
'BRANCH' // Netlify. Putting it the last one because it is more ambiguous
|
21
|
+
];
|
22
|
+
function getBranch(fetchProps) {
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
24
|
+
const env = getBranchByEnvVariable();
|
25
|
+
if (env)
|
26
|
+
return env;
|
27
|
+
const branch = yield (0, environment_1.getGitBranch)();
|
28
|
+
if (!branch)
|
29
|
+
return undefined;
|
30
|
+
// TODO: in the future, call /resolve endpoint
|
31
|
+
// For now, call API to see if the branch exists. If not, use a default value.
|
32
|
+
const [protocol, , host, , database] = fetchProps.apiUrl.split('/');
|
33
|
+
const [workspace] = host.split('.');
|
34
|
+
const dbBranchName = `${database}:${branch}`;
|
35
|
+
try {
|
36
|
+
yield (0, api_1.getBranchDetails)(Object.assign(Object.assign({}, fetchProps), { workspacesApiUrl: `${protocol}//${host}`, pathParams: {
|
37
|
+
dbBranchName,
|
38
|
+
workspace
|
39
|
+
} }));
|
40
|
+
}
|
41
|
+
catch (err) {
|
42
|
+
if ((0, lang_1.isObject)(err) && err.status === 404)
|
43
|
+
return 'main';
|
44
|
+
throw err;
|
45
|
+
}
|
46
|
+
return branch;
|
47
|
+
});
|
48
|
+
}
|
49
|
+
exports.getBranch = getBranch;
|
50
|
+
function getBranchByEnvVariable() {
|
51
|
+
for (const name of envBranchNames) {
|
52
|
+
const value = (0, environment_1.getEnvVariable)(name);
|
53
|
+
if (value) {
|
54
|
+
return value;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
try {
|
58
|
+
return XATA_BRANCH;
|
59
|
+
}
|
60
|
+
catch (err) {
|
61
|
+
// Ignore ReferenceError. Only CloudFlare workers set env variables as global variables
|
62
|
+
}
|
63
|
+
}
|
64
|
+
function getDatabaseUrl() {
|
65
|
+
var _a;
|
66
|
+
try {
|
67
|
+
return (_a = (0, environment_1.getEnvVariable)('XATA_DATABASE_URL')) !== null && _a !== void 0 ? _a : XATA_DATABASE_URL;
|
68
|
+
}
|
69
|
+
catch (err) {
|
70
|
+
return undefined;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.getDatabaseUrl = getDatabaseUrl;
|
74
|
+
function getAPIKey() {
|
75
|
+
var _a;
|
76
|
+
try {
|
77
|
+
return (_a = (0, environment_1.getEnvVariable)('XATA_API_KEY')) !== null && _a !== void 0 ? _a : XATA_API_KEY;
|
78
|
+
}
|
79
|
+
catch (err) {
|
80
|
+
return undefined;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
exports.getAPIKey = getAPIKey;
|
package/dist/schema/filters.d.ts
CHANGED
@@ -19,9 +19,9 @@ import { SelectableColumn, ValueAtColumn } from './selection';
|
|
19
19
|
}
|
20
20
|
*/
|
21
21
|
declare type PropertyAccessFilter<Record> = {
|
22
|
-
[key in SelectableColumn<Record>]?:
|
22
|
+
[key in SelectableColumn<Record>]?: NestedApiFilter<ValueAtColumn<Record, key>> | PropertyFilter<ValueAtColumn<Record, key>>;
|
23
23
|
};
|
24
|
-
declare type PropertyFilter<T> = T | {
|
24
|
+
export declare type PropertyFilter<T> = T | {
|
25
25
|
$is: T;
|
26
26
|
} | {
|
27
27
|
$isNot: T;
|
@@ -35,17 +35,21 @@ declare type IncludesFilter<T> = PropertyFilter<T> | {
|
|
35
35
|
$not: IncludesFilter<T>;
|
36
36
|
}>;
|
37
37
|
};
|
38
|
-
declare type
|
38
|
+
export declare type StringTypeFilter = {
|
39
39
|
[key in '$contains' | '$pattern' | '$startsWith' | '$endsWith']?: string;
|
40
|
-
}
|
41
|
-
|
42
|
-
|
40
|
+
};
|
41
|
+
export declare type ComparableType = number | Date;
|
42
|
+
export declare type ComparableTypeFilter<T extends ComparableType> = {
|
43
|
+
[key in '$gt' | '$lt' | '$ge' | '$le']?: T;
|
44
|
+
};
|
45
|
+
export declare type ArrayFilter<T> = {
|
43
46
|
[key in '$includes']?: SingleOrArray<PropertyFilter<T> | ValueTypeFilters<T>> | IncludesFilter<T>;
|
44
47
|
} | {
|
45
48
|
[key in '$includesAll' | '$includesNone' | '$includesAny']?: T | Array<PropertyFilter<T> | {
|
46
49
|
$not: PropertyFilter<T>;
|
47
50
|
}>;
|
48
|
-
}
|
51
|
+
};
|
52
|
+
declare type ValueTypeFilters<T> = T | T extends string ? StringTypeFilter : T extends number ? ComparableTypeFilter<number> : T extends Date ? ComparableTypeFilter<Date> : T extends Array<infer T> ? ArrayFilter<T> : never;
|
49
53
|
/**
|
50
54
|
* AggregatorFilter
|
51
55
|
* Example:
|
@@ -70,13 +74,13 @@ declare type ValueTypeFilters<T> = T | T extends string ? {
|
|
70
74
|
}
|
71
75
|
*/
|
72
76
|
declare type AggregatorFilter<Record> = {
|
73
|
-
[key in '$all' | '$any' | '$not' | '$none']?: SingleOrArray<
|
77
|
+
[key in '$all' | '$any' | '$not' | '$none']?: SingleOrArray<Filter<Record>>;
|
74
78
|
};
|
75
79
|
/**
|
76
80
|
* Existance filter
|
77
81
|
* Example: { filter: { $exists: "settings" } }
|
78
82
|
*/
|
79
|
-
declare type ExistanceFilter<Record> = {
|
83
|
+
export declare type ExistanceFilter<Record> = {
|
80
84
|
[key in '$exists' | '$notExists']?: SelectableColumn<Record>;
|
81
85
|
};
|
82
86
|
declare type BaseApiFilter<Record> = PropertyAccessFilter<Record> | AggregatorFilter<Record> | ExistanceFilter<Record>;
|
@@ -86,7 +90,7 @@ declare type BaseApiFilter<Record> = PropertyAccessFilter<Record> | AggregatorFi
|
|
86
90
|
* Example: { filter: { settings: { plan: { $any: ['free', 'trial'] } } } }
|
87
91
|
*/
|
88
92
|
declare type NestedApiFilter<T> = T extends Record<string, any> ? {
|
89
|
-
[key in keyof T]?: T[key] extends Record<string, any> ? SingleOrArray<
|
90
|
-
} : T
|
91
|
-
export declare type
|
93
|
+
[key in keyof T]?: T[key] extends Record<string, any> ? SingleOrArray<Filter<T[key]>> : PropertyFilter<T[key]>;
|
94
|
+
} : PropertyFilter<T>;
|
95
|
+
export declare type Filter<Record> = BaseApiFilter<Record> | NestedApiFilter<Record>;
|
92
96
|
export {};
|
@@ -1,72 +1,62 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { ArrayFilter, ComparableType, ComparableTypeFilter, ExistanceFilter, PropertyFilter, StringTypeFilter } from './filters';
|
2
|
+
import { SelectableColumn } from './selection';
|
3
3
|
/**
|
4
4
|
* Operator to restrict results to only values that are greater than the given value.
|
5
5
|
*/
|
6
|
-
export declare const gt: <T extends ComparableType>(value: T) =>
|
6
|
+
export declare const gt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
7
7
|
/**
|
8
8
|
* Operator to restrict results to only values that are greater than or equal to the given value.
|
9
9
|
*/
|
10
|
-
export declare const ge: <T extends ComparableType>(value: T) =>
|
10
|
+
export declare const ge: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
11
11
|
/**
|
12
12
|
* Operator to restrict results to only values that are greater than or equal to the given value.
|
13
13
|
*/
|
14
|
-
export declare const gte: <T extends ComparableType>(value: T) =>
|
14
|
+
export declare const gte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
15
15
|
/**
|
16
16
|
* Operator to restrict results to only values that are lower than the given value.
|
17
17
|
*/
|
18
|
-
export declare const lt: <T extends ComparableType>(value: T) =>
|
18
|
+
export declare const lt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
19
19
|
/**
|
20
20
|
* Operator to restrict results to only values that are lower than or equal to the given value.
|
21
21
|
*/
|
22
|
-
export declare const lte: <T extends ComparableType>(value: T) =>
|
22
|
+
export declare const lte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
23
23
|
/**
|
24
24
|
* Operator to restrict results to only values that are lower than or equal to the given value.
|
25
25
|
*/
|
26
|
-
export declare const le: <T extends ComparableType>(value: T) =>
|
26
|
+
export declare const le: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
27
27
|
/**
|
28
28
|
* Operator to restrict results to only values that are not null.
|
29
29
|
*/
|
30
|
-
export declare const exists: (column:
|
30
|
+
export declare const exists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
|
31
31
|
/**
|
32
32
|
* Operator to restrict results to only values that are null.
|
33
33
|
*/
|
34
|
-
export declare const notExists: (column:
|
34
|
+
export declare const notExists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
|
35
35
|
/**
|
36
36
|
* Operator to restrict results to only values that start with the given prefix.
|
37
37
|
*/
|
38
|
-
export declare const startsWith: (value: string) =>
|
38
|
+
export declare const startsWith: (value: string) => StringTypeFilter;
|
39
39
|
/**
|
40
40
|
* Operator to restrict results to only values that end with the given suffix.
|
41
41
|
*/
|
42
|
-
export declare const endsWith: (value: string) =>
|
42
|
+
export declare const endsWith: (value: string) => StringTypeFilter;
|
43
43
|
/**
|
44
44
|
* Operator to restrict results to only values that match the given pattern.
|
45
45
|
*/
|
46
|
-
export declare const pattern: (value: string) =>
|
46
|
+
export declare const pattern: (value: string) => StringTypeFilter;
|
47
47
|
/**
|
48
48
|
* Operator to restrict results to only values that are equal to the given value.
|
49
49
|
*/
|
50
|
-
export declare const is: <T>(value: T) =>
|
50
|
+
export declare const is: <T>(value: T) => PropertyFilter<T>;
|
51
51
|
/**
|
52
52
|
* Operator to restrict results to only values that are not equal to the given value.
|
53
53
|
*/
|
54
|
-
export declare const isNot: <T>(value: T) =>
|
54
|
+
export declare const isNot: <T>(value: T) => PropertyFilter<T>;
|
55
55
|
/**
|
56
56
|
* Operator to restrict results to only values that contain the given value.
|
57
57
|
*/
|
58
|
-
export declare const contains:
|
58
|
+
export declare const contains: (value: string) => StringTypeFilter;
|
59
59
|
/**
|
60
60
|
* Operator to restrict results to only arrays that include the given value.
|
61
61
|
*/
|
62
|
-
export declare const includes: (value:
|
63
|
-
/**
|
64
|
-
* Operator to restrict results to only arrays that include a value matching the given substring.
|
65
|
-
*/
|
66
|
-
export declare const includesSubstring: (value: string) => Constraint<string>;
|
67
|
-
/**
|
68
|
-
* Operator to restrict results to only arrays that include a value matching the given pattern.
|
69
|
-
*/
|
70
|
-
export declare const includesPattern: (value: string) => Constraint<string>;
|
71
|
-
export declare const includesAll: (value: string) => Constraint<string>;
|
72
|
-
export {};
|
62
|
+
export declare const includes: <T>(value: T) => ArrayFilter<T>;
|
package/dist/schema/operators.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.includes = exports.contains = exports.isNot = exports.is = exports.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.le = exports.lte = exports.lt = exports.gte = exports.ge = exports.gt = void 0;
|
4
4
|
/**
|
5
5
|
* Operator to restrict results to only values that are greater than the given value.
|
6
6
|
*/
|
@@ -71,21 +71,8 @@ exports.isNot = isNot;
|
|
71
71
|
*/
|
72
72
|
const contains = (value) => ({ $contains: value });
|
73
73
|
exports.contains = contains;
|
74
|
-
// TODO: these can only be applied to columns of type "multiple"
|
75
74
|
/**
|
76
75
|
* Operator to restrict results to only arrays that include the given value.
|
77
76
|
*/
|
78
77
|
const includes = (value) => ({ $includes: value });
|
79
78
|
exports.includes = includes;
|
80
|
-
/**
|
81
|
-
* Operator to restrict results to only arrays that include a value matching the given substring.
|
82
|
-
*/
|
83
|
-
const includesSubstring = (value) => ({ $includesSubstring: value });
|
84
|
-
exports.includesSubstring = includesSubstring;
|
85
|
-
/**
|
86
|
-
* Operator to restrict results to only arrays that include a value matching the given pattern.
|
87
|
-
*/
|
88
|
-
const includesPattern = (value) => ({ $includesPattern: value });
|
89
|
-
exports.includesPattern = includesPattern;
|
90
|
-
const includesAll = (value) => ({ $includesAll: value });
|
91
|
-
exports.includesAll = includesAll;
|
package/dist/schema/query.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { FilterExpression } from '../api/schemas';
|
2
2
|
import { NonEmptyArray, RequiredBy } from '../util/types';
|
3
|
-
import {
|
3
|
+
import { Filter } from './filters';
|
4
4
|
import { Page, Paginable, PaginationOptions, PaginationQueryMeta } from './pagination';
|
5
5
|
import { XataRecord } from './record';
|
6
6
|
import { Repository } from './repository';
|
@@ -63,8 +63,8 @@ export declare class Query<Record extends XataRecord, Result extends XataRecord
|
|
63
63
|
*
|
64
64
|
* @returns A new Query object.
|
65
65
|
*/
|
66
|
-
filter(filters:
|
67
|
-
filter<F extends SelectableColumn<Record>>(column: F, value:
|
66
|
+
filter(filters: Filter<Record>): Query<Record, Result>;
|
67
|
+
filter<F extends SelectableColumn<Record>>(column: F, value: Filter<ValueAtColumn<Record, F>>): Query<Record, Result>;
|
68
68
|
/**
|
69
69
|
* Builds a new query with a new sort option.
|
70
70
|
* @param column The column name.
|
@@ -21,20 +21,39 @@ export declare abstract class Repository<Data extends BaseData, Record extends X
|
|
21
21
|
* @param objects Array of objects with the column names and the values to be stored in the table.
|
22
22
|
* @returns Array of the persisted records.
|
23
23
|
*/
|
24
|
-
abstract
|
24
|
+
abstract create(objects: Array<EditableData<Data> & Partial<Identifiable>>): Promise<SelectedPick<Record, ['*']>[]>;
|
25
25
|
/**
|
26
26
|
* Queries a single record from the table given its unique id.
|
27
27
|
* @param id The unique id.
|
28
28
|
* @returns The persisted record for the given id or null if the record could not be found.
|
29
29
|
*/
|
30
30
|
abstract read(id: string): Promise<SelectedPick<Record, ['*']> | null>;
|
31
|
+
/**
|
32
|
+
* Partially update a single record.
|
33
|
+
* @param object An object with its id and the columns to be updated.
|
34
|
+
* @returns The full persisted record.
|
35
|
+
*/
|
36
|
+
abstract update(object: Partial<EditableData<Data>> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
|
31
37
|
/**
|
32
38
|
* Partially update a single record given its unique id.
|
33
39
|
* @param id The unique id.
|
34
|
-
* @param object The column names and their values that have to be
|
40
|
+
* @param object The column names and their values that have to be updated.
|
35
41
|
* @returns The full persisted record.
|
36
42
|
*/
|
37
43
|
abstract update(id: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
|
44
|
+
/**
|
45
|
+
* Partially updates multiple records.
|
46
|
+
* @param objects An array of objects with their ids and columns to be updated.
|
47
|
+
* @returns Array of the persisted records.
|
48
|
+
*/
|
49
|
+
abstract update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
|
50
|
+
/**
|
51
|
+
* Creates or updates a single record. If a record exists with the given id,
|
52
|
+
* it will be update, otherwise a new record will be created.
|
53
|
+
* @param object Object containing the column names with their values to be persisted in the table.
|
54
|
+
* @returns The full persisted record.
|
55
|
+
*/
|
56
|
+
abstract createOrUpdate(object: EditableData<Data> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
|
38
57
|
/**
|
39
58
|
* Creates or updates a single record. If a record exists with the given id,
|
40
59
|
* it will be update, otherwise a new record will be created.
|
@@ -43,12 +62,37 @@ export declare abstract class Repository<Data extends BaseData, Record extends X
|
|
43
62
|
* @returns The full persisted record.
|
44
63
|
*/
|
45
64
|
abstract createOrUpdate(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
65
|
+
/**
|
66
|
+
* Creates or updates a single record. If a record exists with the given id,
|
67
|
+
* it will be update, otherwise a new record will be created.
|
68
|
+
* @param objects Array of objects with the column names and the values to be stored in the table.
|
69
|
+
* @returns Array of the persisted records.
|
70
|
+
*/
|
71
|
+
abstract createOrUpdate(objects: Array<EditableData<Data> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
|
46
72
|
/**
|
47
73
|
* Deletes a record given its unique id.
|
48
74
|
* @param id The unique id.
|
49
75
|
* @throws If the record could not be found or there was an error while performing the deletion.
|
50
76
|
*/
|
51
|
-
abstract delete(id: string): void
|
77
|
+
abstract delete(id: string): Promise<void>;
|
78
|
+
/**
|
79
|
+
* Deletes a record given its unique id.
|
80
|
+
* @param id An object with a unique id.
|
81
|
+
* @throws If the record could not be found or there was an error while performing the deletion.
|
82
|
+
*/
|
83
|
+
abstract delete(id: Identifiable): Promise<void>;
|
84
|
+
/**
|
85
|
+
* Deletes a record given a list of unique ids.
|
86
|
+
* @param ids The array of unique ids.
|
87
|
+
* @throws If the record could not be found or there was an error while performing the deletion.
|
88
|
+
*/
|
89
|
+
abstract delete(ids: string[]): Promise<void>;
|
90
|
+
/**
|
91
|
+
* Deletes a record given a list of unique ids.
|
92
|
+
* @param ids An array of objects with unique ids.
|
93
|
+
* @throws If the record could not be found or there was an error while performing the deletion.
|
94
|
+
*/
|
95
|
+
abstract delete(ids: Identifiable[]): Promise<void>;
|
52
96
|
abstract query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
|
53
97
|
}
|
54
98
|
export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
|
@@ -56,11 +100,15 @@ export declare class RestRepository<Data extends BaseData, Record extends XataRe
|
|
56
100
|
constructor(client: BaseClient<any>, table: string);
|
57
101
|
create(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
58
102
|
create(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
59
|
-
|
103
|
+
create(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
|
60
104
|
read(recordId: string): Promise<SelectedPick<Record, ['*']> | null>;
|
105
|
+
update(object: Partial<EditableData<Data>> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
|
61
106
|
update(recordId: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
|
107
|
+
update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
|
108
|
+
createOrUpdate(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
62
109
|
createOrUpdate(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
63
|
-
|
110
|
+
createOrUpdate(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
|
111
|
+
delete(recordId: string | Identifiable | Array<string | Identifiable>): Promise<void>;
|
64
112
|
query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
|
65
113
|
}
|
66
114
|
interface RepositoryFactory {
|
@@ -82,18 +130,18 @@ export declare type XataClientOptions = {
|
|
82
130
|
*/
|
83
131
|
fetch?: FetchImpl;
|
84
132
|
databaseURL?: string;
|
85
|
-
branch
|
133
|
+
branch?: BranchStrategyOption;
|
86
134
|
/**
|
87
135
|
* API key to be used. You can create one in your account settings at https://app.xata.io/settings.
|
88
136
|
*/
|
89
|
-
apiKey
|
137
|
+
apiKey?: string;
|
90
138
|
repositoryFactory?: RepositoryFactory;
|
91
139
|
};
|
92
140
|
export declare class BaseClient<D extends Record<string, Repository<any>> = Record<string, Repository<any>>> {
|
93
141
|
#private;
|
94
142
|
options: XataClientOptions;
|
95
143
|
db: D;
|
96
|
-
constructor(options
|
144
|
+
constructor(options?: XataClientOptions, links?: Links);
|
97
145
|
initObject<T>(table: string, object: object): T;
|
98
146
|
getBranch(): Promise<string>;
|
99
147
|
}
|