@xata.io/client 0.0.0-beta.26144eb → 0.0.0-beta.2ab8b47
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 +13 -0
- package/CHANGELOG.md +67 -0
- package/dist/api/client.d.ts +2 -2
- package/dist/api/client.js +34 -18
- package/dist/api/components.d.ts +34 -37
- package/dist/api/components.js +34 -37
- package/dist/api/fetcher.d.ts +15 -0
- package/dist/api/fetcher.js +23 -22
- package/dist/api/providers.js +3 -2
- package/dist/api/responses.d.ts +6 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.js +124 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/namespace.d.ts +7 -0
- package/dist/namespace.js +6 -0
- package/dist/schema/filters.d.ts +93 -17
- package/dist/schema/filters.js +0 -22
- package/dist/schema/filters.spec.d.ts +1 -0
- package/dist/schema/filters.spec.js +177 -0
- package/dist/schema/index.d.ts +19 -3
- package/dist/schema/index.js +30 -6
- package/dist/schema/operators.d.ts +26 -24
- package/dist/schema/operators.js +13 -11
- package/dist/schema/pagination.d.ts +18 -14
- package/dist/schema/pagination.js +5 -2
- package/dist/schema/query.d.ts +48 -44
- package/dist/schema/query.js +46 -31
- package/dist/schema/record.d.ts +28 -3
- package/dist/schema/record.js +11 -0
- package/dist/schema/repository.d.ts +90 -65
- package/dist/schema/repository.js +206 -194
- package/dist/schema/selection.d.ts +24 -13
- package/dist/schema/selection.spec.d.ts +1 -0
- package/dist/schema/selection.spec.js +204 -0
- package/dist/schema/sorting.d.ts +17 -0
- package/dist/schema/sorting.js +28 -0
- package/dist/schema/sorting.spec.d.ts +1 -0
- package/dist/schema/sorting.spec.js +11 -0
- package/dist/search/index.d.ts +20 -0
- package/dist/search/index.js +30 -0
- package/dist/util/branches.d.ts +5 -0
- package/dist/util/branches.js +7 -0
- package/dist/util/config.d.ts +11 -0
- package/dist/util/config.js +121 -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 +3 -0
- package/dist/util/lang.js +13 -1
- package/dist/util/types.d.ts +23 -1
- package/package.json +5 -2
package/dist/schema/record.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { SelectedPick } from './selection';
|
2
2
|
/**
|
3
3
|
* Represents an identifiable record from the database.
|
4
4
|
*/
|
@@ -8,6 +8,9 @@ export interface Identifiable {
|
|
8
8
|
*/
|
9
9
|
id: string;
|
10
10
|
}
|
11
|
+
export interface BaseData {
|
12
|
+
[key: string]: any;
|
13
|
+
}
|
11
14
|
/**
|
12
15
|
* Represents a persisted record from the database.
|
13
16
|
*/
|
@@ -24,14 +27,14 @@ export interface XataRecord extends Identifiable {
|
|
24
27
|
/**
|
25
28
|
* Retrieves a refreshed copy of the current record from the database.
|
26
29
|
*/
|
27
|
-
read(): Promise<this>;
|
30
|
+
read(): Promise<SelectedPick<this, ['*']> | null>;
|
28
31
|
/**
|
29
32
|
* Performs a partial update of the current record. On success a new object is
|
30
33
|
* returned and the current object is not mutated.
|
31
34
|
* @param data The columns and their values that have to be updated.
|
32
35
|
* @returns A new record containing the latest values for all the columns of the current record.
|
33
36
|
*/
|
34
|
-
update(data: Partial<
|
37
|
+
update(data: Partial<EditableData<Omit<this, keyof XataRecord>>>): Promise<SelectedPick<this, ['*']>>;
|
35
38
|
/**
|
36
39
|
* Performs a deletion of the current record in the database.
|
37
40
|
*
|
@@ -39,3 +42,25 @@ export interface XataRecord extends Identifiable {
|
|
39
42
|
*/
|
40
43
|
delete(): Promise<void>;
|
41
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
|
+
} | null | undefined : O[K];
|
66
|
+
};
|
package/dist/schema/record.js
CHANGED
@@ -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,109 +1,134 @@
|
|
1
|
-
import {
|
1
|
+
import { SchemaNamespaceResult } from '.';
|
2
|
+
import { FetcherExtraProps } from '../api/fetcher';
|
3
|
+
import { Dictionary } from '../util/types';
|
2
4
|
import { Page } from './pagination';
|
3
|
-
import { Query
|
4
|
-
import { XataRecord } from './record';
|
5
|
-
import {
|
6
|
-
|
5
|
+
import { Query } from './query';
|
6
|
+
import { BaseData, EditableData, Identifiable, XataRecord } from './record';
|
7
|
+
import { SelectedPick } from './selection';
|
8
|
+
declare type TableLink = string[];
|
9
|
+
export declare type LinkDictionary = Dictionary<TableLink[]>;
|
7
10
|
/**
|
8
11
|
* Common interface for performing operations on a table.
|
9
12
|
*/
|
10
|
-
export declare abstract class Repository<
|
13
|
+
export declare abstract class Repository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
|
14
|
+
abstract create(object: EditableData<Data> & Partial<Identifiable>): Promise<SelectedPick<Record, ['*']>>;
|
11
15
|
/**
|
12
|
-
* Creates a record in the table.
|
16
|
+
* Creates a single record in the table with a unique id.
|
17
|
+
* @param id The unique id.
|
13
18
|
* @param object Object containing the column names with their values to be stored in the table.
|
14
19
|
* @returns The full persisted record.
|
15
20
|
*/
|
16
|
-
abstract create(object:
|
21
|
+
abstract create(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
17
22
|
/**
|
18
23
|
* Creates multiple records in the table.
|
19
24
|
* @param objects Array of objects with the column names and the values to be stored in the table.
|
20
25
|
* @returns Array of the persisted records.
|
21
26
|
*/
|
22
|
-
abstract
|
27
|
+
abstract create(objects: Array<EditableData<Data> & Partial<Identifiable>>): Promise<SelectedPick<Record, ['*']>[]>;
|
23
28
|
/**
|
24
29
|
* Queries a single record from the table given its unique id.
|
25
30
|
* @param id The unique id.
|
26
31
|
* @returns The persisted record for the given id or null if the record could not be found.
|
27
32
|
*/
|
28
|
-
abstract read(id: string): Promise<
|
33
|
+
abstract read(id: string): Promise<SelectedPick<Record, ['*']> | null>;
|
29
34
|
/**
|
30
|
-
*
|
31
|
-
* @param id
|
32
|
-
* @param object Object containing the column names with their values to be stored in the table.
|
35
|
+
* Partially update a single record.
|
36
|
+
* @param object An object with its id and the columns to be updated.
|
33
37
|
* @returns The full persisted record.
|
34
38
|
*/
|
35
|
-
abstract
|
39
|
+
abstract update(object: Partial<EditableData<Data>> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
|
36
40
|
/**
|
37
41
|
* Partially update a single record given its unique id.
|
38
42
|
* @param id The unique id.
|
39
|
-
* @param object The column names and their values that have to be
|
43
|
+
* @param object The column names and their values that have to be updated.
|
40
44
|
* @returns The full persisted record.
|
41
45
|
*/
|
42
|
-
abstract update(id: string, object: Partial<
|
46
|
+
abstract update(id: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
|
47
|
+
/**
|
48
|
+
* Partially updates multiple records.
|
49
|
+
* @param objects An array of objects with their ids and columns to be updated.
|
50
|
+
* @returns Array of the persisted records.
|
51
|
+
*/
|
52
|
+
abstract update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
|
43
53
|
/**
|
44
|
-
*
|
54
|
+
* Creates or updates a single record. If a record exists with the given id,
|
55
|
+
* it will be update, otherwise a new record will be created.
|
56
|
+
* @param object Object containing the column names with their values to be persisted in the table.
|
57
|
+
* @returns The full persisted record.
|
58
|
+
*/
|
59
|
+
abstract createOrUpdate(object: EditableData<Data> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
|
60
|
+
/**
|
61
|
+
* Creates or updates a single record. If a record exists with the given id,
|
45
62
|
* it will be update, otherwise a new record will be created.
|
46
63
|
* @param id A unique id.
|
47
64
|
* @param object The column names and the values to be persisted.
|
48
65
|
* @returns The full persisted record.
|
49
66
|
*/
|
50
|
-
abstract
|
67
|
+
abstract createOrUpdate(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
68
|
+
/**
|
69
|
+
* Creates or updates a single record. If a record exists with the given id,
|
70
|
+
* it will be update, otherwise a new record will be created.
|
71
|
+
* @param objects Array of objects with the column names and the values to be stored in the table.
|
72
|
+
* @returns Array of the persisted records.
|
73
|
+
*/
|
74
|
+
abstract createOrUpdate(objects: Array<EditableData<Data> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
|
51
75
|
/**
|
52
76
|
* Deletes a record given its unique id.
|
53
77
|
* @param id The unique id.
|
54
78
|
* @throws If the record could not be found or there was an error while performing the deletion.
|
55
79
|
*/
|
56
|
-
abstract delete(id: string): void
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
constructor(client: BaseClient<any>, table: string);
|
64
|
-
create(object: Selectable<T>): Promise<T>;
|
65
|
-
createMany(objects: T[]): Promise<T[]>;
|
66
|
-
read(recordId: string): Promise<T | null>;
|
67
|
-
update(recordId: string, object: Partial<Selectable<T>>): Promise<T>;
|
68
|
-
insert(recordId: string, object: Selectable<T>): Promise<T>;
|
69
|
-
updateOrInsert(recordId: string, object: Selectable<T>): Promise<T>;
|
70
|
-
delete(recordId: string): Promise<void>;
|
71
|
-
query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options?: Options): Promise<Page<T, typeof options extends {
|
72
|
-
columns: SelectableColumn<T>[];
|
73
|
-
} ? Select<T, typeof options['columns'][number]> : R>>;
|
74
|
-
}
|
75
|
-
interface RepositoryFactory {
|
76
|
-
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
77
|
-
}
|
78
|
-
export declare class RestRespositoryFactory implements RepositoryFactory {
|
79
|
-
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
80
|
-
}
|
81
|
-
declare type BranchStrategyValue = string | undefined | null;
|
82
|
-
declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
|
83
|
-
declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
|
84
|
-
declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
|
85
|
-
export declare type XataClientOptions = {
|
80
|
+
abstract delete(id: string): Promise<void>;
|
81
|
+
/**
|
82
|
+
* Deletes a record given its unique id.
|
83
|
+
* @param id An object with a unique id.
|
84
|
+
* @throws If the record could not be found or there was an error while performing the deletion.
|
85
|
+
*/
|
86
|
+
abstract delete(id: Identifiable): Promise<void>;
|
86
87
|
/**
|
87
|
-
*
|
88
|
-
*
|
89
|
-
*
|
90
|
-
* to provide one. Such as cross-fetch, node-fetch or isomorphic-fetch.
|
88
|
+
* Deletes a record given a list of unique ids.
|
89
|
+
* @param ids The array of unique ids.
|
90
|
+
* @throws If the record could not be found or there was an error while performing the deletion.
|
91
91
|
*/
|
92
|
-
|
93
|
-
databaseURL?: string;
|
94
|
-
branch: BranchStrategyOption;
|
92
|
+
abstract delete(ids: string[]): Promise<void>;
|
95
93
|
/**
|
96
|
-
*
|
94
|
+
* Deletes a record given a list of unique ids.
|
95
|
+
* @param ids An array of objects with unique ids.
|
96
|
+
* @throws If the record could not be found or there was an error while performing the deletion.
|
97
97
|
*/
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
abstract delete(ids: Identifiable[]): Promise<void>;
|
99
|
+
/**
|
100
|
+
* Search for records in the table.
|
101
|
+
* @param query The query to search for.
|
102
|
+
* @param options The options to search with (like: fuzziness)
|
103
|
+
* @returns The found records.
|
104
|
+
*/
|
105
|
+
abstract search(query: string, options?: {
|
106
|
+
fuzziness?: number;
|
107
|
+
}): Promise<SelectedPick<Record, ['*']>[]>;
|
108
|
+
abstract query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
|
109
|
+
}
|
110
|
+
export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
|
102
111
|
#private;
|
103
|
-
options:
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
112
|
+
constructor(options: {
|
113
|
+
table: string;
|
114
|
+
links?: LinkDictionary;
|
115
|
+
getFetchProps: () => Promise<FetcherExtraProps>;
|
116
|
+
schemaNamespace: SchemaNamespaceResult<any>;
|
117
|
+
});
|
118
|
+
create(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
119
|
+
create(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
120
|
+
create(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
|
121
|
+
read(recordId: string): Promise<SelectedPick<Record, ['*']> | null>;
|
122
|
+
update(object: Partial<EditableData<Data>> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
|
123
|
+
update(recordId: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
|
124
|
+
update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
|
125
|
+
createOrUpdate(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
126
|
+
createOrUpdate(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
127
|
+
createOrUpdate(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
|
128
|
+
delete(recordId: string | Identifiable | Array<string | Identifiable>): Promise<void>;
|
129
|
+
search(query: string, options?: {
|
130
|
+
fuzziness?: number;
|
131
|
+
}): Promise<SelectedPick<Record, ['*']>[]>;
|
132
|
+
query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
|
108
133
|
}
|
109
134
|
export {};
|