@xata.io/client 0.0.0-alpha.d63e473 → 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 +19 -2
- package/package.json +2 -2
- package/src/index.ts +16 -3
- package/dist/util/getFetch.d.ts +0 -8
- package/dist/util/getFetch.js +0 -26
- package/dist/util/getFetch.test.d.ts +0 -1
- package/dist/util/getFetch.test.js +0 -21
- package/src/util/getFetch.test.ts +0 -21
- package/src/util/getFetch.ts +0 -31
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 getFetch_1 = require("./util/getFetch");
|
21
20
|
const gt = (value) => ({ $gt: value });
|
22
21
|
exports.gt = gt;
|
23
22
|
const ge = (value) => ({ $ge: value });
|
@@ -167,7 +166,25 @@ class RestRepository extends Repository {
|
|
167
166
|
super(null, table, {});
|
168
167
|
this.client = client;
|
169
168
|
const { fetch } = client.options;
|
170
|
-
|
169
|
+
if (fetch) {
|
170
|
+
this.fetch = fetch;
|
171
|
+
}
|
172
|
+
else if (typeof window === 'object') {
|
173
|
+
this.fetch = window.fetch;
|
174
|
+
}
|
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
|
+
}
|
187
|
+
}
|
171
188
|
Object.defineProperty(this, 'client', { enumerable: false });
|
172
189
|
Object.defineProperty(this, 'fetch', { enumerable: false });
|
173
190
|
Object.defineProperty(this, 'hostname', { enumerable: false });
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@xata.io/client",
|
3
|
-
"version": "0.0.0-
|
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": "
|
23
|
+
"gitHead": "123dd7a5eb1a79e75fd18921d67310c4bf277237"
|
24
24
|
}
|
package/src/index.ts
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import { getFetch } from './util/getFetch';
|
2
|
-
|
3
1
|
export interface XataRecord {
|
4
2
|
id: string;
|
5
3
|
xata: {
|
@@ -283,7 +281,22 @@ export class RestRepository<T> extends Repository<T> {
|
|
283
281
|
this.client = client;
|
284
282
|
|
285
283
|
const { fetch } = client.options;
|
286
|
-
|
284
|
+
|
285
|
+
if (fetch) {
|
286
|
+
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
|
+
}
|
299
|
+
}
|
287
300
|
|
288
301
|
Object.defineProperty(this, 'client', { enumerable: false });
|
289
302
|
Object.defineProperty(this, 'fetch', { enumerable: false });
|
package/dist/util/getFetch.d.ts
DELETED
package/dist/util/getFetch.js
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getFetchErrors = exports.getFetch = void 0;
|
4
|
-
const getFetch = ({ fetchesToTryToRequire } = { fetchesToTryToRequire: ['isomorphic-fetch', 'node-fetch', 'cross-fetch'] }) => {
|
5
|
-
if (typeof window === 'object' && 'fetch' in window) {
|
6
|
-
return window.fetch;
|
7
|
-
}
|
8
|
-
if (typeof require !== 'function') {
|
9
|
-
// If there's no `require`, bail out here. There is no hope.
|
10
|
-
throw exports.getFetchErrors.noImplementation;
|
11
|
-
}
|
12
|
-
for (const fetchImplementation of fetchesToTryToRequire) {
|
13
|
-
try {
|
14
|
-
return require(fetchImplementation);
|
15
|
-
}
|
16
|
-
catch (_a) {
|
17
|
-
// Fail silently, throw later.
|
18
|
-
}
|
19
|
-
}
|
20
|
-
throw exports.getFetchErrors.noImplementation;
|
21
|
-
};
|
22
|
-
exports.getFetch = getFetch;
|
23
|
-
exports.getFetchErrors = {
|
24
|
-
noImplementation: new Error(`The Xata client has no fetcher configured. Please add one in its constructor.
|
25
|
-
More in the docs: ` /** @todo add a link after docs exist */)
|
26
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,21 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const getFetch_1 = require("./getFetch");
|
4
|
-
describe('getFetch', () => {
|
5
|
-
it('should yield window.fetch when it exists', () => {
|
6
|
-
// `any` party here because this is a test.
|
7
|
-
const fakeFetch = () => new Promise((resolve) => resolve('hello'));
|
8
|
-
global.window = { fetch: fakeFetch };
|
9
|
-
expect((0, getFetch_1.getFetch)()).toBe(fakeFetch);
|
10
|
-
// @ts-ignore because lib.dom.d.ts does not apply here
|
11
|
-
delete global.window;
|
12
|
-
});
|
13
|
-
it('should yield one fetch implementation when it exists (this project has cross-fetch)', () => {
|
14
|
-
// We explicitly want to `require` here as an assertion, so disabling this rule:
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
16
|
-
expect((0, getFetch_1.getFetch)({ fetchesToTryToRequire: ['cross-fetch'] })).toEqual(require('cross-fetch'));
|
17
|
-
});
|
18
|
-
it("should throw when it can't find a suitable fetch", () => {
|
19
|
-
expect(() => (0, getFetch_1.getFetch)({ fetchesToTryToRequire: [] })).toThrow(getFetch_1.getFetchErrors.noImplementation);
|
20
|
-
});
|
21
|
-
});
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import { getFetch, getFetchErrors } from './getFetch';
|
2
|
-
|
3
|
-
describe('getFetch', () => {
|
4
|
-
it('should yield window.fetch when it exists', () => {
|
5
|
-
// `any` party here because this is a test.
|
6
|
-
const fakeFetch: any = () => new Promise((resolve) => resolve('hello'));
|
7
|
-
global.window = { fetch: fakeFetch } as any;
|
8
|
-
expect(getFetch()).toBe(fakeFetch);
|
9
|
-
|
10
|
-
// @ts-ignore because lib.dom.d.ts does not apply here
|
11
|
-
delete global.window;
|
12
|
-
});
|
13
|
-
it('should yield one fetch implementation when it exists (this project has cross-fetch)', () => {
|
14
|
-
// We explicitly want to `require` here as an assertion, so disabling this rule:
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
16
|
-
expect(getFetch({ fetchesToTryToRequire: ['cross-fetch'] })).toEqual(require('cross-fetch'));
|
17
|
-
});
|
18
|
-
it("should throw when it can't find a suitable fetch", () => {
|
19
|
-
expect(() => getFetch({ fetchesToTryToRequire: [] })).toThrow(getFetchErrors.noImplementation);
|
20
|
-
});
|
21
|
-
});
|
package/src/util/getFetch.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
type Options = {
|
2
|
-
fetchesToTryToRequire: string[];
|
3
|
-
};
|
4
|
-
|
5
|
-
export const getFetch = (
|
6
|
-
{ fetchesToTryToRequire }: Options = { fetchesToTryToRequire: ['isomorphic-fetch', 'node-fetch', 'cross-fetch'] }
|
7
|
-
) => {
|
8
|
-
if (typeof window === 'object' && 'fetch' in window) {
|
9
|
-
return window.fetch;
|
10
|
-
}
|
11
|
-
|
12
|
-
if (typeof require !== 'function') {
|
13
|
-
// If there's no `require`, bail out here. There is no hope.
|
14
|
-
throw getFetchErrors.noImplementation;
|
15
|
-
}
|
16
|
-
|
17
|
-
for (const fetchImplementation of fetchesToTryToRequire) {
|
18
|
-
try {
|
19
|
-
return require(fetchImplementation);
|
20
|
-
} catch {
|
21
|
-
// Fail silently, throw later.
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
throw getFetchErrors.noImplementation;
|
26
|
-
};
|
27
|
-
|
28
|
-
export const getFetchErrors = {
|
29
|
-
noImplementation: new Error(`The Xata client has no fetcher configured. Please add one in its constructor.
|
30
|
-
More in the docs: ` /** @todo add a link after docs exist */)
|
31
|
-
};
|