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
4351
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.da202d4 to 0.0.0-alpha.dd899d8

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>;
}

@@ -199,2 +212,2 @@ declare type BranchStrategyValue = string | undefined | null;

export declare type Links = Record<string, Array<string[]>>;
export * from './api';
export {};
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -113,2 +103,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

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

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

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

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

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

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

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

@@ -276,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 });
}

@@ -305,3 +292,4 @@ }

const branch = yield this.client.getBranch();
const resp = yield this.fetch(`${databaseURL}:${branch}${path}`, {
const fetchImpl = this.fetch;
const resp = yield fetchImpl(`${databaseURL}:${branch}${path}`, {
method,

@@ -336,4 +324,4 @@ headers: {

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

@@ -400,2 +388,3 @@ create(object) {

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

@@ -410,4 +399,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
};

@@ -420,2 +410,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);

@@ -530,2 +521,20 @@ });

};
__exportStar(require("./api"), exports);
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;
}
export declare const errors: {
noFetchImplementation: string;
invalidApiProvider: string;
falsyFetchImplementation: string; /** @todo add a link after docs exist */
};

@@ -5,4 +5,2 @@ "use strict";

exports.errors = {
noFetchImplementation: 'No fetch implementation provided',
invalidApiProvider: 'Invalid API provider',
falsyFetchImplementation: `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.

@@ -9,0 +7,0 @@

{
"name": "@xata.io/client",
"version": "0.0.0-alpha.da202d4",
"version": "0.0.0-alpha.dd899d8",
"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": "da202d4ed02aed5290ddaa0cf03cd8e775128699"
"gitHead": "dd899d8c82e5fd46e4f70a0202b72f90b30f1309"
}
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