New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@xata.io/client

Package Overview
Dependencies
Maintainers
4
Versions
4360
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.b66fd1c to 0.0.0-alpha.b8b17fa

dist/api/client.d.ts

23

dist/index.d.ts

@@ -0,1 +1,2 @@

import { FetchImpl } from './api/fetcher';
import { Page } from './schema/pagination';

@@ -14,3 +15,2 @@ import { Query, QueryOptions } from './schema/query';

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

@@ -21,16 +21,13 @@ abstract createMany(objects: Selectable<T>[]): Promise<T[]>;

abstract delete(id: string): void;
abstract _runQuery<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>>;
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>>;
}
export declare class RestRepository<T extends XataRecord> extends Repository<T> {
client: BaseClient<any>;
fetch: any;
#private;
constructor(client: BaseClient<any>, table: string);
request<T>(method: string, path: string, body?: unknown): Promise<T | undefined>;
select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
create(object: T): Promise<T>;
createMany(objects: T[]): Promise<T[]>;
read(id: string): Promise<T | null>;
update(id: string, object: Partial<T>): Promise<T>;
delete(id: string): Promise<void>;
_runQuery<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>>;
read(recordId: string): Promise<T | null>;
update(recordId: string, object: Partial<T>): Promise<T>;
delete(recordId: string): Promise<void>;
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>>;
}

@@ -48,3 +45,3 @@ interface RepositoryFactory {

export declare type XataClientOptions = {
fetch?: unknown;
fetch?: FetchImpl;
databaseURL?: string;

@@ -56,5 +53,4 @@ branch: BranchStrategyOption;

export declare class BaseClient<D extends Record<string, Repository<any>>> {
#private;
options: XataClientOptions;
private links;
private branch;
db: D;

@@ -70,2 +66,3 @@ constructor(options: XataClientOptions, links: Links);

export declare type Links = Record<string, Array<string[]>>;
export * from './api';
export * from './schema';

@@ -21,2 +21,13 @@ "use strict";

};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __asyncValues = (this && this.__asyncValues) || function (o) {

@@ -29,12 +40,10 @@ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");

};
var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _BaseClient_links, _BaseClient_branch;
Object.defineProperty(exports, "__esModule", { value: true });
exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
const api_1 = require("./api");
const filters_1 = require("./schema/filters");
const pagination_1 = require("./schema/pagination");
const query_1 = require("./schema/query");
const errors_1 = require("./util/errors");
class Repository extends query_1.Query {
select(columns) {
return new query_1.Query(this.repository, this.table, { columns });
}
}

@@ -45,63 +54,20 @@ exports.Repository = Repository;

super(null, table, {});
this.client = client;
const doWeHaveFetch = typeof fetch !== 'undefined';
const isInjectedFetchProblematic = !this.client.options.fetch;
if (doWeHaveFetch) {
this.fetch = fetch;
_RestRepository_instances.add(this);
_RestRepository_client.set(this, void 0);
_RestRepository_fetch.set(this, void 0);
_RestRepository_table.set(this, void 0);
__classPrivateFieldSet(this, _RestRepository_client, client, "f");
__classPrivateFieldSet(this, _RestRepository_table, table, "f");
// TODO: Remove when integrating with API client
const fetchImpl = typeof fetch !== 'undefined' ? fetch : __classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch;
if (!fetchImpl) {
throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
}
else if (isInjectedFetchProblematic) {
throw new Error(errors_1.errors.falsyFetchImplementation);
}
else {
this.fetch = this.client.options.fetch;
}
Object.defineProperty(this, 'client', { enumerable: false });
Object.defineProperty(this, 'fetch', { enumerable: false });
Object.defineProperty(this, 'hostname', { enumerable: false });
__classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
}
request(method, path, body) {
return __awaiter(this, void 0, void 0, function* () {
const { databaseURL, apiKey } = this.client.options;
const branch = yield this.client.getBranch();
const fetchImpl = this.fetch;
const resp = yield fetchImpl(`${databaseURL}:${branch}${path}`, {
method,
headers: {
Accept: '*/*',
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`
},
body: JSON.stringify(body)
});
if (!resp.ok) {
try {
const json = yield resp.json();
const message = json.message;
if (typeof message === 'string') {
throw new XataError(message, resp.status);
}
}
catch (err) {
if (err instanceof XataError)
throw err;
// Ignore errors for other reasons.
// For example if the response's body cannot be parsed as JSON
}
throw new XataError(resp.statusText, resp.status);
}
if (resp.status === 204)
return undefined;
return resp.json();
});
}
select(columns) {
return new query_1.Query(this.repository, this.table, { columns });
}
create(object) {
return __awaiter(this, void 0, void 0, function* () {
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
const record = transformObjectLinks(object);
const response = yield this.request('POST', `/tables/${this.table}/data`, record);
if (!response) {
throw new Error("The server didn't return any data for the query");
}
const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: record }, fetchProps));
const finalObject = yield this.read(response.id);

@@ -116,7 +82,5 @@ if (!finalObject) {

return __awaiter(this, void 0, void 0, function* () {
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
const records = objects.map((object) => transformObjectLinks(object));
const response = yield this.request('POST', `/tables/${this.table}/bulk`, { records });
if (!response) {
throw new Error("The server didn't return any data for the query");
}
const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
// TODO: Use filer.$any() to get all the records

@@ -130,53 +94,36 @@ const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));

}
read(id) {
read(recordId) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.request('GET', `/tables/${this.table}/data/${id}`);
if (!response)
return null;
return this.client.initObject(this.table, response);
}
catch (err) {
if (err.status === 404)
return null;
throw err;
}
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
});
}
update(id, object) {
update(recordId, object) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.request('PUT', `/tables/${this.table}/data/${id}`, object);
if (!response) {
throw new Error("The server didn't return any data for the query");
}
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
// TODO: Review this, not sure we are properly initializing the object
return this.client.initObject(this.table, response);
return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
});
}
delete(id) {
delete(recordId) {
return __awaiter(this, void 0, void 0, function* () {
yield this.request('DELETE', `/tables/${this.table}/data/${id}`);
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
});
}
_runQuery(query, options) {
var _a, _b;
query(query, options) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () {
const filter = {
$any: query.$any,
$all: query.$all,
$not: query.$not,
$none: query.$none
};
const data = query.getData();
const body = {
filter: Object.values(filter).some(Boolean) ? filter : undefined,
sort: (_a = (0, filters_1.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
filter: Object.values(data.filter).some(Boolean) ? data.filter : undefined,
sort: (_a = (0, filters_1.buildSortFilter)(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : data.sort,
page: (_b = options === null || options === void 0 ? void 0 : options.page) !== null && _b !== void 0 ? _b : data.page,
columns: (_c = options === null || options === void 0 ? void 0 : options.columns) !== null && _c !== void 0 ? _c : data.columns
};
const response = yield this.request('POST', `/tables/${this.table}/query`, body);
if (!response) {
throw new Error("The server didn't return any data for the query");
}
const { meta, records: objects } = response;
const records = objects.map((record) => this.client.initObject(this.table, record));
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), record));
// TODO: We should properly type this any

@@ -188,2 +135,20 @@ return new pagination_1.Page(query, meta, records);

exports.RestRepository = RestRepository;
_RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_getFetchProps = function _RestRepository_getFetchProps() {
return __awaiter(this, void 0, void 0, function* () {
const branch = yield __classPrivateFieldGet(this, _RestRepository_client, "f").getBranch();
return {
fetchImpl: __classPrivateFieldGet(this, _RestRepository_fetch, "f"),
apiKey: __classPrivateFieldGet(this, _RestRepository_client, "f").options.apiKey,
apiUrl: '',
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
workspacesApiUrl: (path, params) => {
var _a, _b;
const baseUrl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.databaseURL) !== null && _a !== void 0 ? _a : '';
const hasBranch = (_b = params.dbBranchName) !== null && _b !== void 0 ? _b : params.branch;
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branch}` : '');
return baseUrl + newPath;
}
};
});
};
class RestRespositoryFactory {

@@ -197,2 +162,4 @@ createRepository(client, table) {

constructor(options, links) {
_BaseClient_links.set(this, void 0);
_BaseClient_branch.set(this, void 0);
if (!options.databaseURL || !options.apiKey || !options.branch) {

@@ -202,3 +169,3 @@ throw new Error('Options databaseURL, apiKey and branch are required');

this.options = options;
this.links = links;
__classPrivateFieldSet(this, _BaseClient_links, links, "f");
}

@@ -208,3 +175,3 @@ initObject(table, object) {

Object.assign(o, object);
const tableLinks = this.links[table] || [];
const tableLinks = __classPrivateFieldGet(this, _BaseClient_links, "f")[table] || [];
for (const link of tableLinks) {

@@ -248,4 +215,4 @@ const [field, linkTable] = link;

return __awaiter(this, void 0, void 0, function* () {
if (this.branch)
return this.branch;
if (__classPrivateFieldGet(this, _BaseClient_branch, "f"))
return __classPrivateFieldGet(this, _BaseClient_branch, "f");
const { branch: param } = this.options;

@@ -261,3 +228,3 @@ const strategies = Array.isArray(param) ? [...param] : [param];

if (branch) {
this.branch = branch;
__classPrivateFieldSet(this, _BaseClient_branch, branch, "f");
return branch;

@@ -279,2 +246,3 @@ }

exports.BaseClient = BaseClient;
_BaseClient_links = new WeakMap(), _BaseClient_branch = new WeakMap();
class XataError extends Error {

@@ -299,2 +267,3 @@ constructor(message, status) {

};
__exportStar(require("./api"), exports);
__exportStar(require("./schema"), exports);

@@ -9,14 +9,4 @@ import { XataRecord } from '..';

};
export interface BasePage<T extends XataRecord, R extends XataRecord> {
query: Query<T, R>;
meta: PaginationQueryMeta;
records: R[];
nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
hasNextPage(): boolean;
}
export declare class Page<T extends XataRecord, R extends XataRecord> implements BasePage<T, R> {
readonly query: Query<T, R>;
export declare class Page<T extends XataRecord, R extends XataRecord> {
#private;
readonly meta: PaginationQueryMeta;

@@ -23,0 +13,0 @@ readonly records: R[];

@@ -11,2 +11,14 @@ "use strict";

};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Page_query;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,3 +28,4 @@ exports.Page = void 0;

constructor(query, meta, records = []) {
this.query = query;
_Page_query.set(this, void 0);
__classPrivateFieldSet(this, _Page_query, query, "f");
this.meta = meta;

@@ -23,3 +36,3 @@ this.records = records;

return __awaiter(this, void 0, void 0, function* () {
return this.query.getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
});

@@ -29,3 +42,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.query.getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
});

@@ -35,3 +48,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.query.getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
});

@@ -41,3 +54,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.query.getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
});

@@ -51,1 +64,2 @@ }

exports.Page = Page;
_Page_query = new WeakMap();
import { XataRecord, Repository } from '..';
import { Constraint, DeepConstraint, FilterConstraints, SortDirection, SortFilter } from './filters';
import { PaginationOptions, BasePage, PaginationQueryMeta, Page } from './pagination';
import { FilterExpression, SortExpression, PageConfig, ColumnsFilter } from '../api/schemas';
import { DeepConstraint, FilterConstraints, SortDirection, SortFilter } from './filters';
import { PaginationOptions, Page } from './pagination';
import { Selectable, SelectableColumn, Select } from './selection';
export declare type QueryOptions<T> = {
page?: PaginationOptions;
columns?: Array<keyof Selectable<T>>;
columns?: Extract<keyof Selectable<T>, string>[];
sort?: SortFilter<T> | SortFilter<T>[];
};
declare type QueryOrConstraint<T extends XataRecord, R extends XataRecord> = Query<T, R> | Constraint<T>;
export declare class Query<T extends XataRecord, R extends XataRecord = T> implements BasePage<T, R> {
table: string;
repository: Repository<T>;
readonly $any?: QueryOrConstraint<T, R>[];
readonly $all?: QueryOrConstraint<T, R>[];
readonly $not?: QueryOrConstraint<T, R>[];
readonly $none?: QueryOrConstraint<T, R>[];
readonly $sort?: Record<string, SortDirection>;
readonly columns: SelectableColumn<T>[];
readonly query: Query<T, R>;
readonly meta: PaginationQueryMeta;
readonly records: R[];
constructor(repository: Repository<T> | null, table: string, data: Partial<Query<T, R>>, parent?: Query<T, R>);
export declare type QueryTableData = {
filter: FilterExpression;
sort?: SortExpression;
page?: PageConfig;
columns?: ColumnsFilter;
};
export declare class Query<T extends XataRecord, R extends XataRecord = T> {
#private;
constructor(repository: Repository<T> | null, table: string, data: Partial<QueryTableData>, parent?: Partial<QueryTableData>);
getData(): QueryTableData;
any(...queries: Query<T, R>[]): Query<T, R>;

@@ -31,2 +28,3 @@ all(...queries: Query<T, R>[]): Query<T, R>;

sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
getPaginated<Options extends QueryOptions<T>>(options?: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;

@@ -37,9 +35,9 @@ [Symbol.asyncIterator](): AsyncIterableIterator<R>;

getOne<Options extends Omit<QueryOptions<T>, 'page'>>(options?: Options): Promise<(typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R) | null>;
deleteAll(): Promise<number>;
/**async deleteAll(): Promise<number> {
// TODO: Return number of affected rows
return 0;
}**/
nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
hasNextPage(): boolean;
}
export {};

@@ -11,2 +11,13 @@ "use strict";

};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __asyncValues = (this && this.__asyncValues) || function (o) {

@@ -31,28 +42,25 @@ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");

};
var _Query_table, _Query_repository, _Query_data;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Query = void 0;
const lang_1 = require("../util/lang");
class Query {
constructor(repository, table, data, parent) {
this.columns = ['*'];
// Cursor pagination
this.query = this;
this.meta = { page: { cursor: 'start', more: true } };
this.records = [];
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
_Query_table.set(this, void 0);
_Query_repository.set(this, void 0);
_Query_data.set(this, { filter: {} });
__classPrivateFieldSet(this, _Query_table, table, "f");
if (repository) {
this.repository = repository;
__classPrivateFieldSet(this, _Query_repository, repository, "f");
}
else {
this.repository = this;
__classPrivateFieldSet(this, _Query_repository, this, "f");
}
this.table = table;
// For some reason Object.assign(this, parent) didn't work in this case
// so doing all this manually:
this.$any = parent === null || parent === void 0 ? void 0 : parent.$any;
this.$all = parent === null || parent === void 0 ? void 0 : parent.$all;
this.$not = parent === null || parent === void 0 ? void 0 : parent.$not;
this.$none = parent === null || parent === void 0 ? void 0 : parent.$none;
this.$sort = parent === null || parent === void 0 ? void 0 : parent.$sort;
Object.assign(this, data);
// These bindings are used to support deconstructing
// const { any, not, filter, sort } = xata.users.query()
__classPrivateFieldGet(this, _Query_data, "f").filter.$any = (_b = (_a = data.filter) === null || _a === void 0 ? void 0 : _a.$any) !== null && _b !== void 0 ? _b : (_c = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _c === void 0 ? void 0 : _c.$any;
__classPrivateFieldGet(this, _Query_data, "f").filter.$all = (_e = (_d = data.filter) === null || _d === void 0 ? void 0 : _d.$all) !== null && _e !== void 0 ? _e : (_f = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _f === void 0 ? void 0 : _f.$all;
__classPrivateFieldGet(this, _Query_data, "f").filter.$not = (_h = (_g = data.filter) === null || _g === void 0 ? void 0 : _g.$not) !== null && _h !== void 0 ? _h : (_j = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _j === void 0 ? void 0 : _j.$not;
__classPrivateFieldGet(this, _Query_data, "f").filter.$none = (_l = (_k = data.filter) === null || _k === void 0 ? void 0 : _k.$none) !== null && _l !== void 0 ? _l : (_m = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _m === void 0 ? void 0 : _m.$none;
__classPrivateFieldGet(this, _Query_data, "f").sort = (_o = data.sort) !== null && _o !== void 0 ? _o : parent === null || parent === void 0 ? void 0 : parent.sort;
__classPrivateFieldGet(this, _Query_data, "f").columns = (_q = (_p = data.columns) !== null && _p !== void 0 ? _p : parent === null || parent === void 0 ? void 0 : parent.columns) !== null && _q !== void 0 ? _q : ['*'];
this.any = this.any.bind(this);

@@ -67,32 +75,26 @@ this.all = this.all.bind(this);

}
getData() {
return __classPrivateFieldGet(this, _Query_data, "f");
}
any(...queries) {
return new Query(this.repository, this.table, {
$any: (this.$any || []).concat(queries)
}, this);
const $any = (0, lang_1.compact)(queries.map((query) => query.getData().filter.$any)).flat();
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
}
all(...queries) {
return new Query(this.repository, this.table, {
$all: (this.$all || []).concat(queries)
}, this);
const $all = (0, lang_1.compact)(queries.map((query) => query.getData().filter.$all)).flat();
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
}
not(...queries) {
return new Query(this.repository, this.table, {
$not: (this.$not || []).concat(queries)
}, this);
const $not = (0, lang_1.compact)(queries.map((query) => query.getData().filter.$not)).flat();
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
}
none(...queries) {
return new Query(this.repository, this.table, {
$none: (this.$none || []).concat(queries)
}, this);
const $none = (0, lang_1.compact)(queries.map((query) => query.getData().filter.$none)).flat();
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
}
filter(a, b) {
if (arguments.length === 1) {
const constraints = a;
const queries = [];
for (const [column, constraint] of Object.entries(constraints)) {
queries.push({ [column]: constraint });
}
return new Query(this.repository, this.table, {
$all: (this.$all || []).concat(queries)
}, this);
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat(constraints));
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
}

@@ -102,20 +104,19 @@ else {

const value = b;
return new Query(this.repository, this.table, {
$all: (this.$all || []).concat({ [column]: value })
}, this);
const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat({ [column]: value }));
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
}
}
sort(column, direction) {
const sort = Object.assign(Object.assign({}, this.$sort), { [column]: direction });
const q = new Query(this.repository, this.table, {
$sort: sort
}, this);
return q;
const sort = Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Query_data, "f").sort), { [column]: direction });
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
}
select(columns) {
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { columns }, __classPrivateFieldGet(this, _Query_data, "f"));
}
getPaginated(options = {}) {
return __awaiter(this, void 0, void 0, function* () {
return this.repository._runQuery(this, options);
return __classPrivateFieldGet(this, _Query_repository, "f").query(this, options);
});
}
[Symbol.asyncIterator]() {
[(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
return __asyncGenerator(this, arguments, function* _a() {

@@ -162,8 +163,6 @@ var e_1, _b;

}
deleteAll() {
return __awaiter(this, void 0, void 0, function* () {
// TODO: Return number of affected rows
return 0;
});
}
/**async deleteAll(): Promise<number> {
// TODO: Return number of affected rows
return 0;
}**/
nextPage(size, offset) {

@@ -174,7 +173,2 @@ return __awaiter(this, void 0, void 0, function* () {

}
previousPage(size, offset) {
return __awaiter(this, void 0, void 0, function* () {
return this.firstPage(size, offset);
});
}
firstPage(size, offset) {

@@ -190,6 +184,3 @@ return __awaiter(this, void 0, void 0, function* () {

}
hasNextPage() {
return this.meta.page.more;
}
}
exports.Query = Query;
{
"name": "@xata.io/client",
"version": "0.0.0-alpha.b66fd1c",
"version": "0.0.0-alpha.b8b17fa",
"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": "b66fd1cf5622e8229f25730735b0b8592dcfcff2"
"gitHead": "b8b17fa338fdbdc560de1ef3cc5810581e493437"
}
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