@xata.io/client 0.0.0-beta.b0aab6b → 0.0.0-beta.bbcb88d

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,6 +17,7 @@ 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");
20
21
  const gt = (value) => ({ $gt: value });
21
22
  exports.gt = gt;
22
23
  const ge = (value) => ({ $ge: value });
@@ -165,25 +166,16 @@ class RestRepository extends Repository {
165
166
  constructor(client, table) {
166
167
  super(null, table, {});
167
168
  this.client = client;
168
- const { fetch } = client.options;
169
- if (fetch) {
169
+ const doWeHaveFetch = typeof fetch !== 'undefined';
170
+ const isInjectedFetchProblematic = !this.client.options.fetch;
171
+ if (doWeHaveFetch) {
170
172
  this.fetch = fetch;
171
173
  }
172
- else if (typeof window === 'object') {
173
- this.fetch = window.fetch;
174
+ else if (isInjectedFetchProblematic) {
175
+ throw new Error(errors_1.errors.falsyFetchImplementation);
174
176
  }
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
- }
177
+ else {
178
+ this.fetch = this.client.options.fetch;
187
179
  }
188
180
  Object.defineProperty(this, 'client', { enumerable: false });
189
181
  Object.defineProperty(this, 'fetch', { enumerable: false });
@@ -0,0 +1,3 @@
1
+ export declare const errors: {
2
+ falsyFetchImplementation: string; /** @todo add a link after docs exist */
3
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errors = void 0;
4
+ exports.errors = {
5
+ falsyFetchImplementation: `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.
6
+
7
+ More in the docs:
8
+ ` /** @todo add a link after docs exist */
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-beta.b0aab6b",
3
+ "version": "0.0.0-beta.bbcb88d",
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": "b0aab6be134341bf67fc0572278b488b027535ad"
23
+ "gitHead": "bbcb88d6cb878b39c43ee6c564496f362796baa9"
24
24
  }
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { errors } from './util/errors';
2
+
1
3
  export interface XataRecord {
2
4
  id: string;
3
5
  xata: {
@@ -280,22 +282,15 @@ export class RestRepository<T> extends Repository<T> {
280
282
  super(null, table, {});
281
283
  this.client = client;
282
284
 
283
- const { fetch } = client.options;
285
+ const doWeHaveFetch = typeof fetch !== 'undefined';
286
+ const isInjectedFetchProblematic = !this.client.options.fetch;
284
287
 
285
- if (fetch) {
288
+ if (doWeHaveFetch) {
286
289
  this.fetch = 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
- }
290
+ } else if (isInjectedFetchProblematic) {
291
+ throw new Error(errors.falsyFetchImplementation);
292
+ } else {
293
+ this.fetch = this.client.options.fetch;
299
294
  }
300
295
 
301
296
  Object.defineProperty(this, 'client', { enumerable: false });
@@ -0,0 +1,6 @@
1
+ export const errors = {
2
+ falsyFetchImplementation: `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.
3
+
4
+ More in the docs:
5
+ ` /** @todo add a link after docs exist */
6
+ };