@xata.io/client 0.0.0-beta.62e04e1 → 0.0.0-beta.645c53a
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 +49 -0
- package/dist/api/client.d.ts +95 -0
- package/dist/api/client.js +236 -0
- package/dist/api/components.d.ts +1436 -0
- package/dist/api/components.js +997 -0
- package/dist/api/fetcher.d.ts +25 -0
- package/dist/api/fetcher.js +73 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +21 -0
- package/dist/api/parameters.d.ts +16 -0
- package/dist/api/parameters.js +2 -0
- package/dist/api/providers.d.ts +8 -0
- package/dist/api/providers.js +30 -0
- package/dist/api/responses.d.ts +50 -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 +2 -182
- package/dist/index.js +16 -499
- package/dist/schema/filters.d.ts +22 -0
- package/dist/schema/filters.js +25 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.js +29 -0
- package/dist/schema/operators.d.ts +72 -0
- package/dist/schema/operators.js +91 -0
- package/dist/schema/pagination.d.ts +83 -0
- package/dist/schema/pagination.js +93 -0
- package/dist/schema/query.d.ts +118 -0
- package/dist/schema/query.js +242 -0
- package/dist/schema/record.d.ts +66 -0
- package/dist/schema/record.js +13 -0
- package/dist/schema/repository.d.ts +100 -0
- package/dist/schema/repository.js +288 -0
- package/dist/schema/selection.d.ts +25 -0
- package/dist/schema/selection.js +2 -0
- package/dist/{index.test.d.ts → schema/selection.spec.d.ts} +0 -0
- package/dist/schema/selection.spec.js +203 -0
- package/dist/util/lang.d.ts +5 -0
- package/dist/util/lang.js +22 -0
- package/dist/util/types.d.ts +13 -0
- package/dist/util/types.js +2 -0
- package/package.json +3 -3
- 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/dist/index.d.ts
CHANGED
@@ -1,186 +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 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>>;
|
135
|
-
abstract create(object: Selectable<T>): Promise<T>;
|
136
|
-
abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
|
137
|
-
abstract read(id: string): Promise<T | null>;
|
138
|
-
abstract update(id: string, object: Partial<T>): Promise<T>;
|
139
|
-
abstract delete(id: string): void;
|
140
|
-
abstract _runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
|
141
|
-
}
|
142
|
-
export declare class RestRepository<T> extends Repository<T> {
|
143
|
-
client: BaseClient<any>;
|
144
|
-
fetch: any;
|
145
|
-
constructor(client: BaseClient<any>, table: string);
|
146
|
-
request<T>(method: string, path: string, body?: unknown): Promise<T | undefined>;
|
147
|
-
select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>;
|
148
|
-
create(object: T): Promise<T>;
|
149
|
-
createMany(objects: T[]): Promise<T[]>;
|
150
|
-
read(id: string): Promise<T | null>;
|
151
|
-
update(id: string, object: Partial<T>): Promise<T>;
|
152
|
-
delete(id: string): Promise<void>;
|
153
|
-
_runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
|
154
|
-
}
|
155
|
-
interface RepositoryFactory {
|
156
|
-
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
|
157
|
-
}
|
158
|
-
export declare class RestRespositoryFactory implements RepositoryFactory {
|
159
|
-
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
|
160
|
-
}
|
161
|
-
declare type BranchStrategyValue = string | undefined | null;
|
162
|
-
declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
|
163
|
-
declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
|
164
|
-
declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
|
165
|
-
export declare type XataClientOptions = {
|
166
|
-
fetch?: unknown;
|
167
|
-
databaseURL: string;
|
168
|
-
branch: BranchStrategyOption;
|
169
|
-
apiKey: string;
|
170
|
-
repositoryFactory?: RepositoryFactory;
|
171
|
-
};
|
172
|
-
export declare class BaseClient<D extends Record<string, Repository<any>>> {
|
173
|
-
options: XataClientOptions;
|
174
|
-
private links;
|
175
|
-
private branch;
|
176
|
-
db: D;
|
177
|
-
constructor(options: XataClientOptions, links: Links);
|
178
|
-
initObject<T>(table: string, object: object): T;
|
179
|
-
getBranch(): Promise<string>;
|
180
|
-
}
|
181
1
|
export declare class XataError extends Error {
|
182
2
|
readonly status: number;
|
183
3
|
constructor(message: string, status: number);
|
184
4
|
}
|
185
|
-
export
|
186
|
-
export
|
5
|
+
export * from './api';
|
6
|
+
export * from './schema';
|