@xata.io/client 0.0.0-alpha.e3f7a92 → 0.0.0-beta.123dd7a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17,7 +17,6 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  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;
20
- const errors_1 = require("./util/errors");
21
20
  const gt = (value) => ({ $gt: value });
22
21
  exports.gt = gt;
23
22
  const ge = (value) => ({ $ge: value });
@@ -166,16 +165,25 @@ class RestRepository extends Repository {
166
165
  constructor(client, table) {
167
166
  super(null, table, {});
168
167
  this.client = client;
169
- const doWeHaveFetch = typeof fetch !== 'undefined';
170
- const isInjectedFetchProblematic = !this.client.options.fetch;
171
- if (doWeHaveFetch) {
168
+ const { fetch } = client.options;
169
+ if (fetch) {
172
170
  this.fetch = fetch;
173
171
  }
174
- else if (isInjectedFetchProblematic) {
175
- throw errors_1.errors.falsyFetchImplementation;
172
+ else if (typeof window === 'object') {
173
+ this.fetch = window.fetch;
176
174
  }
177
- else {
178
- this.fetch = this.client.options.fetch;
175
+ else if (typeof require === 'function') {
176
+ try {
177
+ this.fetch = require('node-fetch');
178
+ }
179
+ catch (err) {
180
+ try {
181
+ this.fetch = require('cross-fetch');
182
+ }
183
+ catch (err) {
184
+ throw new Error('No fetch implementation found. Please provide one in the constructor');
185
+ }
186
+ }
179
187
  }
180
188
  Object.defineProperty(this, 'client', { enumerable: false });
181
189
  Object.defineProperty(this, 'fetch', { enumerable: false });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-alpha.e3f7a92",
3
+ "version": "0.0.0-beta.123dd7a",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,5 +20,5 @@
20
20
  "url": "https://github.com/xataio/client-ts/issues"
21
21
  },
22
22
  "homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
23
- "gitHead": "e3f7a9253d72151233d02b397e0ab83a254ae8b4"
23
+ "gitHead": "123dd7a5eb1a79e75fd18921d67310c4bf277237"
24
24
  }
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { errors } from './util/errors';
2
-
3
1
  export interface XataRecord {
4
2
  id: string;
5
3
  xata: {
@@ -282,15 +280,22 @@ export class RestRepository<T> extends Repository<T> {
282
280
  super(null, table, {});
283
281
  this.client = client;
284
282
 
285
- const doWeHaveFetch = typeof fetch !== 'undefined';
286
- const isInjectedFetchProblematic = !this.client.options.fetch;
283
+ const { fetch } = client.options;
287
284
 
288
- if (doWeHaveFetch) {
285
+ if (fetch) {
289
286
  this.fetch = fetch;
290
- } else if (isInjectedFetchProblematic) {
291
- throw errors.falsyFetchImplementation;
292
- } else {
293
- this.fetch = this.client.options.fetch;
287
+ } else if (typeof window === 'object') {
288
+ this.fetch = window.fetch;
289
+ } else if (typeof require === 'function') {
290
+ try {
291
+ this.fetch = require('node-fetch');
292
+ } catch (err) {
293
+ try {
294
+ this.fetch = require('cross-fetch');
295
+ } catch (err) {
296
+ throw new Error('No fetch implementation found. Please provide one in the constructor');
297
+ }
298
+ }
294
299
  }
295
300
 
296
301
  Object.defineProperty(this, 'client', { enumerable: false });
@@ -1,4 +0,0 @@
1
- export declare const errors: {
2
- noFetchImplementation: Error;
3
- falsyFetchImplementation: Error;
4
- };
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errors = void 0;
4
- exports.errors = {
5
- noFetchImplementation: new Error(`The Xata client has no fetcher configured, and there is no global \`fetch\` function available for it to use. Please supply one in its constructor.
6
-
7
- More in the docs:
8
- ` /** @todo add a link after docs exist */),
9
- falsyFetchImplementation: new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.
10
-
11
- More in the docs:
12
- ` /** @todo add a link after docs exist */)
13
- };
@@ -1,12 +0,0 @@
1
- export const errors = {
2
- noFetchImplementation:
3
- new Error(`The Xata client has no fetcher configured, and there is no global \`fetch\` function available for it to use. Please supply one in its constructor.
4
-
5
- More in the docs:
6
- ` /** @todo add a link after docs exist */),
7
- falsyFetchImplementation:
8
- new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.
9
-
10
- More in the docs:
11
- ` /** @todo add a link after docs exist */)
12
- };