@xata.io/client
Advanced tools
Comparing version 0.0.0-alpha.ed1ba7e to 0.0.0-alpha.f1d45fd
@@ -11,6 +11,6 @@ export interface XataRecord { | ||
export declare type Queries<T> = { | ||
[key in keyof T as T[key] extends Query<any> ? key : never]: T[key]; | ||
[key in keyof T as T[key] extends Query<infer A, infer B> ? key : never]: T[key]; | ||
}; | ||
export declare type OmitQueries<T> = { | ||
[key in keyof T as T[key] extends Query<any> ? never : key]: T[key]; | ||
[key in keyof T as T[key] extends Query<infer A, infer B> ? never : key]: T[key]; | ||
}; | ||
@@ -24,4 +24,3 @@ export declare type OmitLinks<T> = { | ||
export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>; | ||
export declare type SelectableColumn<T> = keyof Selectable<T> | '*'; | ||
export declare type Select<T, K extends SelectableColumn<T>> = (K extends keyof T ? Pick<T, K> : T) & Queries<T> & XataRecord; | ||
export declare type Select<T, K extends keyof T> = Pick<T, K> & Queries<T> & XataRecord; | ||
export declare type Include<T> = { | ||
@@ -31,7 +30,2 @@ [key in keyof T as T[key] extends XataRecord ? key : never]?: boolean | Array<keyof Selectable<T[key]>>; | ||
declare type SortDirection = 'asc' | 'desc'; | ||
declare type SortFilterExtended<T> = { | ||
column: keyof T; | ||
direction?: SortDirection; | ||
}; | ||
declare type SortFilter<T> = SortFilterExtended<T> | keyof T; | ||
declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll'; | ||
@@ -81,6 +75,4 @@ declare type Constraint<T> = { | ||
page?: PaginationOptions; | ||
columns?: Array<keyof Selectable<T>>; | ||
sort?: SortFilter<T> | SortFilter<T>[]; | ||
}; | ||
declare type QueryOrConstraint<T extends XataRecord, R extends XataRecord> = Query<T, R> | Constraint<T>; | ||
declare type QueryOrConstraint<T, R> = Query<T, R> | Constraint<T>; | ||
declare type QueryMeta = { | ||
@@ -92,3 +84,3 @@ page: { | ||
}; | ||
interface BasePage<T extends XataRecord, R extends XataRecord> { | ||
interface BasePage<T, R> { | ||
query: Query<T, R>; | ||
@@ -103,3 +95,3 @@ meta: QueryMeta; | ||
} | ||
declare class Page<T extends XataRecord, R extends XataRecord> implements BasePage<T, R> { | ||
declare class Page<T, R> implements BasePage<T, R> { | ||
readonly query: Query<T, R>; | ||
@@ -115,3 +107,3 @@ readonly meta: QueryMeta; | ||
} | ||
export declare class Query<T extends XataRecord, R extends XataRecord = T> implements BasePage<T, R> { | ||
export declare class Query<T, R = T> implements BasePage<T, R> { | ||
table: string; | ||
@@ -124,3 +116,2 @@ repository: Repository<T>; | ||
readonly $sort?: Record<string, SortDirection>; | ||
readonly columns: SelectableColumn<T>[]; | ||
readonly query: Query<T, R>; | ||
@@ -137,8 +128,9 @@ readonly meta: QueryMeta; | ||
sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>; | ||
getPaginated<Options extends BulkQueryOptions<T>>(options?: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>; | ||
getPaginated(options?: BulkQueryOptions<T>): Promise<Page<T, R>>; | ||
[Symbol.asyncIterator](): AsyncIterableIterator<R>; | ||
getIterator(chunk: number, options?: Omit<BulkQueryOptions<T>, 'page'>): AsyncGenerator<R[]>; | ||
getMany<Options extends BulkQueryOptions<T>>(options?: Options): Promise<(typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R)[]>; | ||
getOne<Options extends Omit<BulkQueryOptions<T>, 'page'>>(options?: Options): Promise<(typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R) | null>; | ||
getMany(options?: BulkQueryOptions<T>): Promise<R[]>; | ||
getOne(options?: Omit<BulkQueryOptions<T>, 'page'>): Promise<R | null>; | ||
deleteAll(): Promise<number>; | ||
include(columns: Include<T>): this; | ||
nextPage(size?: number, offset?: number): Promise<Page<T, R>>; | ||
@@ -150,4 +142,4 @@ previousPage(size?: number, offset?: number): Promise<Page<T, R>>; | ||
} | ||
export declare abstract class Repository<T extends XataRecord> extends Query<T> { | ||
select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>; | ||
export declare abstract class Repository<T> extends Query<T, Selectable<T>> { | ||
select<K extends keyof Selectable<T>>(...columns: K[]): Query<T, Select<T, K>>; | ||
abstract create(object: Selectable<T>): Promise<T>; | ||
@@ -158,5 +150,5 @@ abstract createMany(objects: Selectable<T>[]): Promise<T[]>; | ||
abstract delete(id: string): void; | ||
abstract _runQuery<R extends XataRecord, Options extends BulkQueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>; | ||
abstract _runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>; | ||
} | ||
export declare class RestRepository<T extends XataRecord> extends Repository<T> { | ||
export declare class RestRepository<T> extends Repository<T> { | ||
client: BaseClient<any>; | ||
@@ -166,3 +158,3 @@ fetch: any; | ||
request<T>(method: string, path: string, body?: unknown): Promise<T | undefined>; | ||
select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>; | ||
select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>; | ||
create(object: T): Promise<T>; | ||
@@ -173,9 +165,9 @@ createMany(objects: T[]): Promise<T[]>; | ||
delete(id: string): Promise<void>; | ||
_runQuery<R extends XataRecord, Options extends BulkQueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>; | ||
_runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>; | ||
} | ||
interface RepositoryFactory { | ||
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>; | ||
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>; | ||
} | ||
export declare class RestRespositoryFactory implements RepositoryFactory { | ||
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>; | ||
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>; | ||
} | ||
@@ -182,0 +174,0 @@ declare type BranchStrategyValue = string | undefined | null; |
@@ -103,3 +103,2 @@ "use strict"; | ||
constructor(repository, table, data, parent) { | ||
this.columns = ['*']; | ||
// Cursor pagination | ||
@@ -181,3 +180,3 @@ this.query = this; | ||
} | ||
getPaginated(options = {}) { | ||
getPaginated(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -217,3 +216,3 @@ return this.repository._runQuery(this, options); | ||
} | ||
getMany(options = {}) { | ||
getMany(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -236,2 +235,6 @@ const { records } = yield this.getPaginated(options); | ||
} | ||
include(columns) { | ||
// TODO | ||
return this; | ||
} | ||
nextPage(size, offset) { | ||
@@ -263,4 +266,4 @@ return __awaiter(this, void 0, void 0, function* () { | ||
class Repository extends Query { | ||
select(columns) { | ||
return new Query(this.repository, this.table, { columns }); | ||
select(...columns) { | ||
return new Query(this.repository, this.table, {}); | ||
} | ||
@@ -322,4 +325,4 @@ } | ||
} | ||
select(columns) { | ||
return new Query(this.repository, this.table, { columns }); | ||
select(...columns) { | ||
return new Query(this.repository, this.table, {}); | ||
} | ||
@@ -386,3 +389,2 @@ create(object) { | ||
_runQuery(query, options) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -397,5 +399,4 @@ const filter = { | ||
filter: Object.values(filter).some(Boolean) ? filter : undefined, | ||
sort: (_a = buildSortFilter(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : query.$sort, | ||
page: options === null || options === void 0 ? void 0 : options.page, | ||
columns: (_b = options === null || options === void 0 ? void 0 : options.columns) !== null && _b !== void 0 ? _b : query.columns | ||
sort: query.$sort, | ||
page: options === null || options === void 0 ? void 0 : options.page | ||
}; | ||
@@ -408,3 +409,2 @@ const response = yield this.request('POST', `/tables/${this.table}/query`, body); | ||
const records = objects.map((record) => this.client.initObject(this.table, record)); | ||
// TODO: We should properly type this any | ||
return new Page(query, meta, records); | ||
@@ -519,20 +519,1 @@ }); | ||
}; | ||
function buildSortFilter(filter) { | ||
if (!filter) | ||
return undefined; | ||
const filters = Array.isArray(filter) ? filter : [filter]; | ||
return filters.reduce((acc, item) => { | ||
if (typeof item === 'string') { | ||
return Object.assign(Object.assign({}, acc), { [item]: 'asc' }); | ||
} | ||
else if (isObjectSortFilter(item)) { | ||
return Object.assign(Object.assign({}, acc), { [item.column]: item.direction }); | ||
} | ||
else { | ||
return acc; | ||
} | ||
}, {}); | ||
} | ||
function isObjectSortFilter(filter) { | ||
return typeof filter === 'object' && filter.column !== undefined; | ||
} |
{ | ||
"name": "@xata.io/client", | ||
"version": "0.0.0-alpha.ed1ba7e", | ||
"version": "0.0.0-alpha.f1d45fd", | ||
"description": "Xata.io SDK for TypeScript and JavaScript", | ||
@@ -23,3 +23,3 @@ "main": "./dist/index.js", | ||
"homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md", | ||
"gitHead": "ed1ba7edce38949e3e2cd9823523d6598126fe04" | ||
"gitHead": "f1d45fdba414a2cc32d0551405941c0a88861001" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
42347
707