Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xata.io/client

Package Overview
Dependencies
Maintainers
4
Versions
4350
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xata.io/client - npm Package Compare versions

Comparing version 0.0.0-alpha.0b29cce to 0.0.0-alpha.0ec3f79

53

dist/index.d.ts

@@ -11,6 +11,6 @@ export interface XataRecord {

export declare type Queries<T> = {
[key in keyof T as T[key] extends Query<infer A, infer B> ? key : never]: T[key];
[key in keyof T as T[key] extends Query<any> ? key : never]: T[key];
};
export declare type OmitQueries<T> = {
[key in keyof T as T[key] extends Query<infer A, infer B> ? never : key]: T[key];
[key in keyof T as T[key] extends Query<any> ? never : key]: T[key];
};

@@ -24,3 +24,9 @@ export declare type OmitLinks<T> = {

export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>;
export declare type Select<T, K extends keyof T> = Pick<T, K> & Queries<T> & XataRecord;
declare type StringKeys<O> = Extract<keyof O, string>;
declare type Values<O> = O[keyof O];
export declare type SelectableColumn<O> = '*' | (O extends Array<unknown> ? never : O extends Record<string, any> ? '*' | Values<{
[K in StringKeys<O>]: O[K] extends Record<string, any> ? `${K}.${SelectableColumn<O[K]>}` : K;
}> : '');
declare type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
export declare type Select<T, K extends SelectableColumn<T>> = UnionToIntersection<K extends keyof T ? Pick<T, K> : T> & Queries<T> & XataRecord;
export declare type Include<T> = {

@@ -30,2 +36,7 @@ [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';

@@ -75,4 +86,6 @@ declare type Constraint<T> = {

page?: PaginationOptions;
columns?: Array<keyof Selectable<T>>;
sort?: SortFilter<T> | SortFilter<T>[];
};
declare type QueryOrConstraint<T, R> = Query<T, R> | Constraint<T>;
declare type QueryOrConstraint<T extends XataRecord, R extends XataRecord> = Query<T, R> | Constraint<T>;
declare type QueryMeta = {

@@ -84,3 +97,3 @@ page: {

};
interface BasePage<T, R> {
interface BasePage<T extends XataRecord, R extends XataRecord> {
query: Query<T, R>;

@@ -95,3 +108,3 @@ meta: QueryMeta;

}
declare class Page<T, R> implements BasePage<T, R> {
declare class Page<T extends XataRecord, R extends XataRecord> implements BasePage<T, R> {
readonly query: Query<T, R>;

@@ -107,3 +120,3 @@ readonly meta: QueryMeta;

}
export declare class Query<T, R = T> implements BasePage<T, R> {
export declare class Query<T extends XataRecord, R extends XataRecord = T> implements BasePage<T, R> {
table: string;

@@ -116,2 +129,3 @@ repository: Repository<T>;

readonly $sort?: Record<string, SortDirection>;
readonly columns: SelectableColumn<T>[];
readonly query: Query<T, R>;

@@ -128,9 +142,8 @@ readonly meta: QueryMeta;

sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
getPaginated(options?: BulkQueryOptions<T>): Promise<Page<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>>;
[Symbol.asyncIterator](): AsyncIterableIterator<R>;
getIterator(chunk: number, options?: Omit<BulkQueryOptions<T>, 'page'>): AsyncGenerator<R[]>;
getMany(options?: BulkQueryOptions<T>): Promise<R[]>;
getOne(options?: Omit<BulkQueryOptions<T>, 'page'>): Promise<R | null>;
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>;
deleteAll(): Promise<number>;
include(columns: Include<T>): this;
nextPage(size?: number, offset?: number): Promise<Page<T, R>>;

@@ -142,4 +155,4 @@ previousPage(size?: number, offset?: number): Promise<Page<T, R>>;

}
export declare abstract class Repository<T> extends Query<T, Selectable<T>> {
select<K extends keyof Selectable<T>>(...columns: K[]): Query<T, Select<T, K>>;
export declare abstract class Repository<T extends XataRecord> extends Query<T> {
select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
abstract create(object: Selectable<T>): Promise<T>;

@@ -150,5 +163,5 @@ abstract createMany(objects: Selectable<T>[]): Promise<T[]>;

abstract delete(id: string): void;
abstract _runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
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>>;
}
export declare class RestRepository<T> extends Repository<T> {
export declare class RestRepository<T extends XataRecord> extends Repository<T> {
client: BaseClient<any>;

@@ -158,3 +171,3 @@ fetch: any;

request<T>(method: string, path: string, body?: unknown): Promise<T | undefined>;
select<K extends keyof T>(...columns: K[]): Query<T, Select<T, K>>;
select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
create(object: T): Promise<T>;

@@ -165,9 +178,9 @@ createMany(objects: T[]): Promise<T[]>;

delete(id: string): Promise<void>;
_runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
_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>>;
}
interface RepositoryFactory {
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
}
export declare class RestRespositoryFactory implements RepositoryFactory {
createRepository<T>(client: BaseClient<any>, table: string): Repository<T>;
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
}

@@ -180,3 +193,3 @@ declare type BranchStrategyValue = string | undefined | null;

fetch?: unknown;
databaseURL: string;
databaseURL?: string;
branch: BranchStrategyOption;

@@ -183,0 +196,0 @@ apiKey: string;

@@ -103,2 +103,3 @@ "use strict";

constructor(repository, table, data, parent) {
this.columns = ['*'];
// Cursor pagination

@@ -180,3 +181,3 @@ this.query = this;

}
getPaginated(options) {
getPaginated(options = {}) {
return __awaiter(this, void 0, void 0, function* () {

@@ -216,3 +217,3 @@ return this.repository._runQuery(this, options);

}
getMany(options) {
getMany(options = {}) {
return __awaiter(this, void 0, void 0, function* () {

@@ -235,6 +236,2 @@ const { records } = yield this.getPaginated(options);

}
include(columns) {
// TODO
return this;
}
nextPage(size, offset) {

@@ -266,4 +263,4 @@ return __awaiter(this, void 0, void 0, function* () {

class Repository extends Query {
select(...columns) {
return new Query(this.repository, this.table, {});
select(columns) {
return new Query(this.repository, this.table, { columns });
}

@@ -325,4 +322,4 @@ }

}
select(...columns) {
return new Query(this.repository, this.table, {});
select(columns) {
return new Query(this.repository, this.table, { columns });
}

@@ -389,2 +386,3 @@ create(object) {

_runQuery(query, options) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {

@@ -399,4 +397,5 @@ const filter = {

filter: Object.values(filter).some(Boolean) ? filter : undefined,
sort: query.$sort,
page: options === null || options === void 0 ? void 0 : options.page
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
};

@@ -409,2 +408,3 @@ 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,1 +519,20 @@ });

};
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.0b29cce",
"version": "0.0.0-alpha.0ec3f79",
"description": "Xata.io SDK for TypeScript and JavaScript",

@@ -9,3 +9,3 @@ "main": "./dist/index.js",

"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"build": "tsc -p tsconfig.build.json",
"prepack": "npm run build"

@@ -24,3 +24,3 @@ },

"homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
"gitHead": "0b29ccefbae3ed4a2324d3b6dbeeb5a3aa1b3246"
"gitHead": "0ec3f79b07b56e1d2e8058bafcc09560bc205fb4"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc