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
4349
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.c8f2e88 to 0.0.0-alpha.c91a6a2

dist/util/errors.d.ts

6

dist/index.d.ts

@@ -140,3 +140,3 @@ export interface XataRecord {

abstract delete(id: string): void;
abstract executeQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
abstract _runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
}

@@ -150,7 +150,7 @@ export declare class RestRepository<T> extends Repository<T> {

create(object: T): Promise<T>;
createMany(records: 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>;
executeQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
_runQuery<R>(query: Query<T, R>, options?: BulkQueryOptions<T>): Promise<Page<T, R>>;
}

@@ -157,0 +157,0 @@ interface RepositoryFactory {

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

exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.Query = exports.includesAll = exports.includesPattern = exports.includesSubstring = exports.includes = exports.contains = exports.isNot = exports.is = exports.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.le = exports.lte = exports.lt = exports.gte = exports.ge = exports.gt = void 0;
const errors_1 = require("./util/errors");
const gt = (value) => ({ $gt: value });

@@ -181,3 +182,3 @@ exports.gt = gt;

return __awaiter(this, void 0, void 0, function* () {
return this.repository.executeQuery(this, options);
return this.repository._runQuery(this, options);
});

@@ -272,21 +273,12 @@ }

this.client = client;
const { fetch } = client.options;
if (fetch) {
const doWeHaveFetch = typeof fetch !== 'undefined';
const isInjectedFetchProblematic = !this.client.options.fetch;
if (doWeHaveFetch) {
this.fetch = fetch;
}
else if (typeof window === 'object') {
this.fetch = window.fetch;
else if (isInjectedFetchProblematic) {
throw new Error(errors_1.errors.falsyFetchImplementation);
}
else if (typeof require === 'function') {
try {
this.fetch = require('node-fetch');
}
catch (err) {
try {
this.fetch = require('cross-fetch');
}
catch (err) {
throw new Error('No fetch implementation found. Please provide one in the constructor');
}
}
else {
this.fetch = this.client.options.fetch;
}

@@ -336,20 +328,17 @@ Object.defineProperty(this, 'client', { enumerable: false });

return __awaiter(this, void 0, void 0, function* () {
const body = Object.assign({}, object);
for (const key of Object.keys(body)) {
const value = body[key];
if (value && typeof value === 'object' && typeof value.id === 'string') {
body[key] = value.id;
}
}
const response = yield this.request('POST', `/tables/${this.table}/data`, body);
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");
}
// TODO: Review this, not sure we are properly initializing the object
return this.client.initObject(this.table, response);
const finalObject = yield this.read(response.id);
if (!finalObject) {
throw new Error('The server failed to save the record');
}
return finalObject;
});
}
createMany(records) {
createMany(objects) {
return __awaiter(this, void 0, void 0, function* () {
// TODO: Review the id of the records
const records = objects.map((object) => transformObjectLinks(object));
const response = yield this.request('POST', `/tables/${this.table}/bulk`, { records });

@@ -359,4 +348,8 @@ if (!response) {

}
// TODO: Review this, not sure we are properly initializing the object
return response.recordIDs.map((record) => this.client.initObject(this.table, { id: record }));
// TODO: Use filer.$any() to get all the records
const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
if (finalObjects.some((object) => !object)) {
throw new Error('The server failed to save the record');
}
return finalObjects;
});

@@ -391,7 +384,6 @@ }

return __awaiter(this, void 0, void 0, function* () {
// TODO: Return boolean?
yield this.request('DELETE', `/tables/${this.table}/data/${id}`);
});
}
executeQuery(query, options) {
_runQuery(query, options) {
return __awaiter(this, void 0, void 0, function* () {

@@ -515,1 +507,10 @@ const filter = {

};
// TODO: We can find a better implementation for links
const transformObjectLinks = (object) => {
return Object.entries(object).reduce((acc, [key, value]) => {
if (value && typeof value === 'object' && typeof value.id === 'string') {
return Object.assign(Object.assign({}, acc), { [key]: value.id });
}
return Object.assign(Object.assign({}, acc), { [key]: value });
}, {});
};
{
"name": "@xata.io/client",
"version": "0.0.0-alpha.c8f2e88",
"version": "0.0.0-alpha.c91a6a2",
"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": "c8f2e8877faf74729601a36ec10b25938fee4a38"
"gitHead": "c91a6a2e7d624a6d0c3fc71b6fce36628651a72d"
}
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