@xata.io/client 0.0.0-beta.d2072d7 → 0.0.0-beta.f2b2fa6
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/api/client.d.ts +93 -0
- package/dist/api/client.js +229 -0
- package/dist/api/components.d.ts +1416 -0
- package/dist/api/components.js +988 -0
- package/dist/api/fetcher.d.ts +25 -0
- package/dist/api/fetcher.js +78 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +21 -0
- package/dist/api/parameters.d.ts +15 -0
- package/dist/api/parameters.js +2 -0
- package/dist/api/providers.d.ts +8 -0
- package/dist/api/providers.js +29 -0
- package/dist/api/responses.d.ts +44 -0
- package/dist/api/responses.js +2 -0
- package/dist/api/schemas.d.ts +311 -0
- package/dist/api/schemas.js +2 -0
- package/dist/index.d.ts +24 -145
- package/dist/index.js +125 -351
- package/dist/schema/filters.d.ts +20 -0
- package/dist/schema/filters.js +24 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +17 -0
- package/dist/schema/operators.d.ts +21 -0
- package/dist/schema/operators.js +40 -0
- package/dist/schema/pagination.d.ts +41 -0
- package/dist/schema/pagination.js +58 -0
- package/dist/schema/query.d.ts +45 -0
- package/dist/schema/query.js +190 -0
- package/dist/schema/selection.d.ts +14 -0
- package/dist/schema/selection.js +2 -0
- package/dist/util/lang.d.ts +2 -0
- package/dist/util/lang.js +10 -0
- package/dist/util/types.d.ts +3 -0
- package/dist/util/types.js +2 -0
- package/package.json +3 -3
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -320
- package/dist/util/errors.d.ts +0 -3
- package/dist/util/errors.js +0 -9
- package/src/index.test.ts +0 -412
- package/src/index.ts +0 -667
- package/src/util/errors.ts +0 -6
- package/tsconfig.json +0 -21
package/dist/index.d.ts
CHANGED
@@ -1,178 +1,56 @@
|
|
1
|
+
import { FetchImpl } from './api/fetcher';
|
2
|
+
import { Page } from './schema/pagination';
|
3
|
+
import { Query, QueryOptions } from './schema/query';
|
4
|
+
import { Selectable, SelectableColumn, Select } from './schema/selection';
|
1
5
|
export interface XataRecord {
|
2
6
|
id: string;
|
3
7
|
xata: {
|
4
8
|
version: number;
|
5
9
|
};
|
6
10
|
read(): Promise<this>;
|
7
|
-
update(data: Selectable<this
|
11
|
+
update(data: Partial<Selectable<this>>): Promise<this>;
|
8
12
|
delete(): Promise<void>;
|
9
13
|
}
|
10
|
-
export declare
|
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 CursorNavigationOptions = {
|
58
|
-
first?: string;
|
59
|
-
} | {
|
60
|
-
last?: string;
|
61
|
-
} | {
|
62
|
-
after?: string;
|
63
|
-
before?: string;
|
64
|
-
};
|
65
|
-
declare type OffsetNavigationOptions = {
|
66
|
-
size?: number;
|
67
|
-
offset?: number;
|
68
|
-
};
|
69
|
-
declare type PaginationOptions = CursorNavigationOptions & OffsetNavigationOptions;
|
70
|
-
declare type BulkQueryOptions<T> = {
|
71
|
-
page?: PaginationOptions;
|
72
|
-
};
|
73
|
-
declare type QueryOrConstraint<T, R> = Query<T, R> | Constraint<T>;
|
74
|
-
declare type QueryMeta = {
|
75
|
-
page: {
|
76
|
-
cursor: string;
|
77
|
-
more: boolean;
|
78
|
-
};
|
79
|
-
};
|
80
|
-
interface BasePage<T, R> {
|
81
|
-
query: Query<T, R>;
|
82
|
-
meta: QueryMeta;
|
83
|
-
records: R[];
|
84
|
-
nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
85
|
-
previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
86
|
-
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
87
|
-
lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
88
|
-
hasNextPage(): boolean;
|
89
|
-
}
|
90
|
-
declare class Page<T, R> implements BasePage<T, R> {
|
91
|
-
readonly query: Query<T, R>;
|
92
|
-
readonly meta: QueryMeta;
|
93
|
-
readonly records: R[];
|
94
|
-
constructor(query: Query<T, R>, meta: QueryMeta, records?: R[]);
|
95
|
-
nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
96
|
-
previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
97
|
-
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
98
|
-
lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
99
|
-
hasNextPage(): boolean;
|
100
|
-
}
|
101
|
-
export declare class Query<T, R = T> implements BasePage<T, R> {
|
102
|
-
table: string;
|
103
|
-
repository: Repository<T>;
|
104
|
-
readonly $any?: QueryOrConstraint<T, R>[];
|
105
|
-
readonly $all?: QueryOrConstraint<T, R>[];
|
106
|
-
readonly $not?: QueryOrConstraint<T, R>[];
|
107
|
-
readonly $none?: QueryOrConstraint<T, R>[];
|
108
|
-
readonly $sort?: Record<string, SortDirection>;
|
109
|
-
readonly query: Query<T, R>;
|
110
|
-
readonly meta: QueryMeta;
|
111
|
-
readonly records: R[];
|
112
|
-
constructor(repository: Repository<T> | null, table: string, data: Partial<Query<T, R>>, parent?: Query<T, R>);
|
113
|
-
any(...queries: Query<T, R>[]): Query<T, R>;
|
114
|
-
all(...queries: Query<T, R>[]): Query<T, R>;
|
115
|
-
not(...queries: Query<T, R>[]): Query<T, R>;
|
116
|
-
none(...queries: Query<T, R>[]): Query<T, R>;
|
117
|
-
filter(constraints: FilterConstraints<T>): Query<T, R>;
|
118
|
-
filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
|
119
|
-
sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
|
120
|
-
getPaginated(options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
|
121
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<R>;
|
122
|
-
getIterator(chunk: number, options?: Omit<BulkQueryOptions<T>, 'page'>): AsyncGenerator<R[]>;
|
123
|
-
getMany(options?: BulkQueryOptions<T>): Promise<R[]>;
|
124
|
-
getOne(options?: Omit<BulkQueryOptions<T>, 'page'>): Promise<R | null>;
|
125
|
-
deleteAll(): Promise<number>;
|
126
|
-
include(columns: Include<T>): this;
|
127
|
-
nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
128
|
-
previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
129
|
-
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
130
|
-
lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
131
|
-
hasNextPage(): boolean;
|
132
|
-
}
|
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>>;
|
14
|
+
export declare abstract class Repository<T extends XataRecord> extends Query<T> {
|
135
15
|
abstract create(object: Selectable<T>): Promise<T>;
|
136
16
|
abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
|
137
17
|
abstract read(id: string): Promise<T | null>;
|
138
|
-
abstract update(id: string, object: Partial<T
|
18
|
+
abstract update(id: string, object: Partial<Selectable<T>>): Promise<T>;
|
19
|
+
abstract upsert(id: string, object: Selectable<T>): Promise<T>;
|
139
20
|
abstract delete(id: string): void;
|
140
|
-
abstract
|
21
|
+
abstract query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
|
141
22
|
}
|
142
|
-
export declare class RestRepository<T> extends Repository<T> {
|
143
|
-
|
144
|
-
fetch: any;
|
23
|
+
export declare class RestRepository<T extends XataRecord> extends Repository<T> {
|
24
|
+
#private;
|
145
25
|
constructor(client: BaseClient<any>, table: string);
|
146
|
-
|
147
|
-
select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>;
|
148
|
-
create(object: T): Promise<T>;
|
26
|
+
create(object: Selectable<T>): Promise<T>;
|
149
27
|
createMany(objects: T[]): Promise<T[]>;
|
150
|
-
read(
|
151
|
-
update(
|
152
|
-
|
153
|
-
|
28
|
+
read(recordId: string): Promise<T | null>;
|
29
|
+
update(recordId: string, object: Partial<Selectable<T>>): Promise<T>;
|
30
|
+
upsert(recordId: string, object: Selectable<T>): Promise<T>;
|
31
|
+
delete(recordId: string): Promise<void>;
|
32
|
+
query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
|
154
33
|
}
|
155
34
|
interface RepositoryFactory {
|
156
|
-
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
|
35
|
+
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
157
36
|
}
|
158
37
|
export declare class RestRespositoryFactory implements RepositoryFactory {
|
159
|
-
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
|
38
|
+
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
160
39
|
}
|
161
40
|
declare type BranchStrategyValue = string | undefined | null;
|
162
41
|
declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
|
163
42
|
declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
|
164
43
|
declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
|
165
44
|
export declare type XataClientOptions = {
|
166
|
-
fetch?:
|
167
|
-
databaseURL
|
45
|
+
fetch?: FetchImpl;
|
46
|
+
databaseURL?: string;
|
168
47
|
branch: BranchStrategyOption;
|
169
48
|
apiKey: string;
|
170
49
|
repositoryFactory?: RepositoryFactory;
|
171
50
|
};
|
172
51
|
export declare class BaseClient<D extends Record<string, Repository<any>>> {
|
52
|
+
#private;
|
173
53
|
options: XataClientOptions;
|
174
|
-
private links;
|
175
|
-
private branch;
|
176
54
|
db: D;
|
177
55
|
constructor(options: XataClientOptions, links: Links);
|
178
56
|
initObject<T>(table: string, object: object): T;
|
@@ -183,4 +61,5 @@ export declare class XataError extends Error {
|
|
183
61
|
constructor(message: string, status: number);
|
184
62
|
}
|
185
63
|
export declare type Links = Record<string, Array<string[]>>;
|
186
|
-
export
|
64
|
+
export * from './api';
|
65
|
+
export * from './schema';
|