@xata.io/client 0.6.0 → 0.7.2

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.
@@ -27,82 +27,176 @@ const labelsValue = ['foo'];
27
27
  const invalidLabelsValue = [1];
28
28
  // SelectedRecordPick<O, Key> //
29
29
  // ---------------------------------------------------------------------------- //
30
- function selectedRecordPickTest1(selectedUserBaseRecord) {
30
+ function test1(user) {
31
31
  var _a, _b, _c, _d;
32
- selectedUserBaseRecord.id;
33
- selectedUserBaseRecord.read();
34
- selectedUserBaseRecord.full_name;
35
- (_a = selectedUserBaseRecord.address) === null || _a === void 0 ? void 0 : _a.street;
32
+ user.id;
33
+ user.read();
34
+ user.full_name;
35
+ (_a = user.address) === null || _a === void 0 ? void 0 : _a.street;
36
36
  // @ts-expect-error
37
- selectedUserBaseRecord.team.id;
38
- (_b = selectedUserBaseRecord.team) === null || _b === void 0 ? void 0 : _b.id;
39
- (_c = selectedUserBaseRecord.team) === null || _c === void 0 ? void 0 : _c.read();
37
+ user.team.id;
38
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.id;
39
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.read();
40
40
  // @ts-expect-error
41
- (_d = selectedUserBaseRecord.team) === null || _d === void 0 ? void 0 : _d.name;
42
- selectedUserBaseRecord.owner.id;
43
- selectedUserBaseRecord.owner.read();
41
+ (_d = user.team) === null || _d === void 0 ? void 0 : _d.name;
42
+ user.partner.id;
43
+ user.partner.read();
44
44
  // @ts-expect-error
45
- selectedUserBaseRecord.owner.full_name;
45
+ user.partner.full_name;
46
+ user.team = null;
47
+ // @ts-expect-error
48
+ user.partner = null;
46
49
  }
47
- function selectedRecordPickTest2(selectedUserFullRecord) {
50
+ function test2(user) {
48
51
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
49
- selectedUserFullRecord.id;
50
- selectedUserFullRecord.read();
51
- selectedUserFullRecord.full_name;
52
- (_a = selectedUserFullRecord.team) === null || _a === void 0 ? void 0 : _a.id;
53
- (_b = selectedUserFullRecord.team) === null || _b === void 0 ? void 0 : _b.read();
54
- (_c = selectedUserFullRecord.team) === null || _c === void 0 ? void 0 : _c.name;
55
- (_d = selectedUserFullRecord.team) === null || _d === void 0 ? void 0 : _d.owner;
56
- (_f = (_e = selectedUserFullRecord.team) === null || _e === void 0 ? void 0 : _e.owner) === null || _f === void 0 ? void 0 : _f.id;
57
- (_h = (_g = selectedUserFullRecord.team) === null || _g === void 0 ? void 0 : _g.owner) === null || _h === void 0 ? void 0 : _h.read();
58
- // @ts-expect-error
59
- (_k = (_j = selectedUserFullRecord.team) === null || _j === void 0 ? void 0 : _j.owner) === null || _k === void 0 ? void 0 : _k.full_name;
60
- // @ts-expect-error
61
- selectedUserFullRecord.full_name = null;
62
- selectedUserFullRecord.email = null;
63
- selectedUserFullRecord.email = '';
64
- // @ts-expect-error
65
- selectedUserFullRecord.email = 2;
66
- if (selectedUserFullRecord.team) {
52
+ user.id;
53
+ user.read();
54
+ user.full_name;
55
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
56
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
57
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
58
+ (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner;
59
+ (_f = (_e = user.team) === null || _e === void 0 ? void 0 : _e.owner) === null || _f === void 0 ? void 0 : _f.id;
60
+ (_h = (_g = user.team) === null || _g === void 0 ? void 0 : _g.owner) === null || _h === void 0 ? void 0 : _h.read();
61
+ // @ts-expect-error
62
+ (_k = (_j = user.team) === null || _j === void 0 ? void 0 : _j.owner) === null || _k === void 0 ? void 0 : _k.full_name;
63
+ // @ts-expect-error
64
+ user.full_name = null;
65
+ user.email = null;
66
+ user.email = '';
67
+ // @ts-expect-error
68
+ user.email = 2;
69
+ if (user.team) {
67
70
  // @ts-expect-error
68
- selectedUserFullRecord.team.name = null;
69
- selectedUserFullRecord.team.labels = null;
70
- selectedUserFullRecord.team.labels = ['foo'];
71
+ user.team.name = null;
72
+ user.team.labels = null;
73
+ user.team.labels = ['foo'];
71
74
  // @ts-expect-error
72
- selectedUserFullRecord.team.labels = [1];
75
+ user.team.labels = [1];
73
76
  }
74
77
  }
75
- function selectedRecordPickTest3(selectedUserNestedRecord) {
78
+ function test3(user) {
76
79
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
77
- selectedUserNestedRecord.id;
78
- selectedUserNestedRecord.read();
80
+ user.id;
81
+ user.read();
79
82
  // @ts-expect-error
80
- selectedUserNestedRecord.full_name;
81
- (_a = selectedUserNestedRecord.team) === null || _a === void 0 ? void 0 : _a.id;
82
- (_b = selectedUserNestedRecord.team) === null || _b === void 0 ? void 0 : _b.read();
83
+ user.full_name;
84
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
85
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
83
86
  // @ts-expect-error
84
- (_c = selectedUserNestedRecord.team) === null || _c === void 0 ? void 0 : _c.name;
85
- (_e = (_d = selectedUserNestedRecord.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
86
- (_g = (_f = selectedUserNestedRecord.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
87
- (_j = (_h = selectedUserNestedRecord.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
87
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
88
+ (_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
89
+ (_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
90
+ (_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
88
91
  }
89
- function selectedRecordPickTest4(selectedUserNestedRecord) {
92
+ function test4(user) {
90
93
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
91
- selectedUserNestedRecord.id;
92
- selectedUserNestedRecord.read();
94
+ user.id;
95
+ user.read();
96
+ // @ts-expect-error
97
+ user.full_name;
98
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
99
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
100
+ // @ts-expect-error
101
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
102
+ (_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
103
+ (_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
104
+ // @ts-expect-error
105
+ (_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
106
+ (_l = (_k = user.team) === null || _k === void 0 ? void 0 : _k.owner) === null || _l === void 0 ? void 0 : _l.address;
107
+ (_p = (_o = (_m = user.team) === null || _m === void 0 ? void 0 : _m.owner) === null || _o === void 0 ? void 0 : _o.address) === null || _p === void 0 ? void 0 : _p.street;
108
+ (_s = (_r = (_q = user.team) === null || _q === void 0 ? void 0 : _q.owner) === null || _r === void 0 ? void 0 : _r.address) === null || _s === void 0 ? void 0 : _s.zipcode;
109
+ }
110
+ function test5(user) {
111
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
112
+ user.id;
113
+ user.read();
114
+ // @ts-expect-error
115
+ user.full_name;
116
+ user.settings;
117
+ (_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
118
+ (_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
119
+ (_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
120
+ (_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
121
+ (_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
122
+ // @ts-expect-error
123
+ (_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
124
+ // @ts-expect-error
125
+ (_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
126
+ // @ts-expect-error
127
+ (_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
128
+ user.settings = null;
129
+ user.nonNullable.nested.value = 2;
130
+ // @ts-expect-error
131
+ user.nonNullable = null;
132
+ // @ts-expect-error
133
+ user.nonNullable.nested.value = null;
134
+ }
135
+ function test6(user) {
136
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
137
+ user.id;
138
+ user.read();
139
+ // @ts-expect-error
140
+ user.full_name;
141
+ user.settings;
142
+ (_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
143
+ (_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
144
+ (_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
145
+ (_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
146
+ (_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
147
+ // @ts-expect-error
148
+ (_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
149
+ // @ts-expect-error
150
+ (_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
151
+ // @ts-expect-error
152
+ (_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
153
+ user.nonNullable.nested.value = 2;
154
+ user.nonNullable.nested.deep.depths.of.numbers = [1, 2, 3];
155
+ // @ts-expect-error
156
+ user.nonNullable.nested.deep.depths.of.numbers = 'invalid-string';
157
+ user.settings = null;
158
+ // @ts-expect-error
159
+ user.nonNullable = null;
160
+ // @ts-expect-error
161
+ user.nonNullable.nested.value = null;
162
+ }
163
+ function test7(user) {
164
+ var _a, _b;
165
+ user.partner;
166
+ user.partner.id;
167
+ user.partner.read();
168
+ user.partner.full_name;
169
+ // @ts-expect-error
170
+ user.partner.full_name = null;
171
+ user.partner.address;
172
+ // @ts-expect-error
173
+ user.team.id;
174
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
175
+ // @ts-expect-error
176
+ user.team.read();
177
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
178
+ // @ts-expect-error
179
+ user.partner = null;
180
+ user.team = null;
181
+ }
182
+ function test8(user) {
183
+ var _a, _b;
184
+ user.partner;
185
+ user.partner.id;
186
+ user.partner.read();
187
+ user.partner.full_name;
188
+ // @ts-expect-error
189
+ user.partner.full_name = null;
190
+ user.partner.address;
93
191
  // @ts-expect-error
94
- selectedUserNestedRecord.full_name;
95
- (_a = selectedUserNestedRecord.team) === null || _a === void 0 ? void 0 : _a.id;
96
- (_b = selectedUserNestedRecord.team) === null || _b === void 0 ? void 0 : _b.read();
192
+ user.team.id;
193
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
97
194
  // @ts-expect-error
98
- (_c = selectedUserNestedRecord.team) === null || _c === void 0 ? void 0 : _c.name;
99
- (_e = (_d = selectedUserNestedRecord.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
100
- (_g = (_f = selectedUserNestedRecord.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
195
+ user.team.read();
196
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
101
197
  // @ts-expect-error
102
- (_j = (_h = selectedUserNestedRecord.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
103
- (_l = (_k = selectedUserNestedRecord.team) === null || _k === void 0 ? void 0 : _k.owner) === null || _l === void 0 ? void 0 : _l.address;
104
- (_p = (_o = (_m = selectedUserNestedRecord.team) === null || _m === void 0 ? void 0 : _m.owner) === null || _o === void 0 ? void 0 : _o.address) === null || _p === void 0 ? void 0 : _p.street;
105
- (_s = (_r = (_q = selectedUserNestedRecord.team) === null || _q === void 0 ? void 0 : _q.owner) === null || _r === void 0 ? void 0 : _r.address) === null || _s === void 0 ? void 0 : _s.zipcode;
198
+ user.partner = null;
199
+ user.team = null;
106
200
  }
107
201
  test('fake test', () => {
108
202
  // This is a fake test to make sure that the type definitions in this file are working
@@ -0,0 +1,17 @@
1
+ import { SingleOrArray, Values } from '../util/types';
2
+ import { XataRecord } from './record';
3
+ import { SelectableColumn } from './selection';
4
+ export declare type SortDirection = 'asc' | 'desc';
5
+ export declare type SortFilterExtended<T extends XataRecord> = {
6
+ column: SelectableColumn<T>;
7
+ direction?: SortDirection;
8
+ };
9
+ export declare type SortFilter<T extends XataRecord> = SelectableColumn<T> | SortFilterExtended<T>;
10
+ export declare type ApiSortFilter<T extends XataRecord> = SingleOrArray<Values<{
11
+ [key in SelectableColumn<T>]: {
12
+ [K in key]: SortDirection;
13
+ };
14
+ }>>;
15
+ export declare function isSortFilterString<T extends XataRecord>(value: any): value is SelectableColumn<T>;
16
+ export declare function isSortFilterObject<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
17
+ export declare function buildSortFilter<T extends XataRecord>(filter: SingleOrArray<SortFilter<T>>): ApiSortFilter<T>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSortFilter = exports.isSortFilterObject = exports.isSortFilterString = void 0;
4
+ const lang_1 = require("../util/lang");
5
+ function isSortFilterString(value) {
6
+ return (0, lang_1.isString)(value);
7
+ }
8
+ exports.isSortFilterString = isSortFilterString;
9
+ function isSortFilterObject(filter) {
10
+ return (0, lang_1.isObject)(filter) && filter.column !== undefined;
11
+ }
12
+ exports.isSortFilterObject = isSortFilterObject;
13
+ function buildSortFilter(filter) {
14
+ var _a;
15
+ if (isSortFilterString(filter)) {
16
+ return { [filter]: 'asc' };
17
+ }
18
+ else if (Array.isArray(filter)) {
19
+ return filter.map((item) => buildSortFilter(item));
20
+ }
21
+ else if (isSortFilterObject(filter)) {
22
+ return { [filter.column]: (_a = filter.direction) !== null && _a !== void 0 ? _a : 'asc' };
23
+ }
24
+ else {
25
+ throw new Error(`Invalid sort filter: ${filter}`);
26
+ }
27
+ }
28
+ exports.buildSortFilter = buildSortFilter;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Simple sorting
4
+ const simpleSorting = { name: 'asc' };
5
+ // Array of simple sorting
6
+ const arrayOfSimpleSorting = [{ name: 'asc' }, { age: 'desc' }];
7
+ test('fake test', () => {
8
+ // This is a fake test to make sure that the type definitions in this file are working
9
+ });
@@ -0,0 +1,11 @@
1
+ import { FetchImpl } from '../api/fetcher';
2
+ declare type BranchResolutionOptions = {
3
+ databaseURL?: string;
4
+ apiKey?: string;
5
+ fetchImpl?: FetchImpl;
6
+ };
7
+ export declare function getCurrentBranchName(options?: BranchResolutionOptions): Promise<string | undefined>;
8
+ export declare function getCurrentBranchDetails(options?: BranchResolutionOptions): Promise<import("../api/schemas").DBBranch | null>;
9
+ export declare function getDatabaseURL(): string | undefined;
10
+ export declare function getAPIKey(): string | undefined;
11
+ export {};
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAPIKey = exports.getDatabaseURL = exports.getCurrentBranchDetails = exports.getCurrentBranchName = void 0;
13
+ const api_1 = require("../api");
14
+ const environment_1 = require("./environment");
15
+ const fetch_1 = require("./fetch");
16
+ const lang_1 = require("./lang");
17
+ const envBranchNames = [
18
+ 'XATA_BRANCH',
19
+ 'VERCEL_GIT_COMMIT_REF',
20
+ 'CF_PAGES_BRANCH',
21
+ 'BRANCH' // Netlify. Putting it the last one because it is more ambiguous
22
+ ];
23
+ const defaultBranch = 'main';
24
+ function getCurrentBranchName(options) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const env = yield getBranchByEnvVariable();
27
+ if (env)
28
+ return env;
29
+ const branch = yield (0, environment_1.getGitBranch)();
30
+ if (!branch)
31
+ return defaultBranch;
32
+ // TODO: in the future, call /resolve endpoint
33
+ // For now, call API to see if the branch exists. If not, use a default value.
34
+ const details = yield getDatabaseBranch(branch, options);
35
+ if (details)
36
+ return branch;
37
+ return defaultBranch;
38
+ });
39
+ }
40
+ exports.getCurrentBranchName = getCurrentBranchName;
41
+ function getCurrentBranchDetails(options) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const env = yield getBranchByEnvVariable();
44
+ if (env)
45
+ return getDatabaseBranch(env, options);
46
+ const branch = yield (0, environment_1.getGitBranch)();
47
+ if (!branch)
48
+ return getDatabaseBranch(defaultBranch, options);
49
+ // TODO: in the future, call /resolve endpoint
50
+ // For now, call API to see if the branch exists. If not, use a default value.
51
+ const details = yield getDatabaseBranch(branch, options);
52
+ if (details)
53
+ return details;
54
+ return getDatabaseBranch(defaultBranch, options);
55
+ });
56
+ }
57
+ exports.getCurrentBranchDetails = getCurrentBranchDetails;
58
+ function getDatabaseBranch(branch, options) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const databaseURL = (options === null || options === void 0 ? void 0 : options.databaseURL) || getDatabaseURL();
61
+ const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || getAPIKey();
62
+ if (!databaseURL)
63
+ throw new Error('A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely');
64
+ if (!apiKey)
65
+ throw new Error('An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely');
66
+ const [protocol, , host, , database] = databaseURL.split('/');
67
+ const [workspace] = host.split('.');
68
+ const dbBranchName = `${database}:${branch}`;
69
+ try {
70
+ return yield (0, api_1.getBranchDetails)({
71
+ apiKey,
72
+ apiUrl: databaseURL,
73
+ fetchImpl: (0, fetch_1.getFetchImplementation)(options === null || options === void 0 ? void 0 : options.fetchImpl),
74
+ workspacesApiUrl: `${protocol}//${host}`,
75
+ pathParams: {
76
+ dbBranchName,
77
+ workspace
78
+ }
79
+ });
80
+ }
81
+ catch (err) {
82
+ if ((0, lang_1.isObject)(err) && err.status === 404)
83
+ return null;
84
+ throw err;
85
+ }
86
+ });
87
+ }
88
+ function getBranchByEnvVariable() {
89
+ for (const name of envBranchNames) {
90
+ const value = (0, environment_1.getEnvVariable)(name);
91
+ if (value) {
92
+ return value;
93
+ }
94
+ }
95
+ try {
96
+ return XATA_BRANCH;
97
+ }
98
+ catch (err) {
99
+ // Ignore ReferenceError. Only CloudFlare workers set env variables as global variables
100
+ }
101
+ }
102
+ function getDatabaseURL() {
103
+ var _a;
104
+ try {
105
+ return (_a = (0, environment_1.getEnvVariable)('XATA_DATABASE_URL')) !== null && _a !== void 0 ? _a : XATA_DATABASE_URL;
106
+ }
107
+ catch (err) {
108
+ return undefined;
109
+ }
110
+ }
111
+ exports.getDatabaseURL = getDatabaseURL;
112
+ function getAPIKey() {
113
+ var _a;
114
+ try {
115
+ return (_a = (0, environment_1.getEnvVariable)('XATA_API_KEY')) !== null && _a !== void 0 ? _a : XATA_API_KEY;
116
+ }
117
+ catch (err) {
118
+ return undefined;
119
+ }
120
+ }
121
+ exports.getAPIKey = getAPIKey;
@@ -0,0 +1,5 @@
1
+ /// <reference path="../../src/types/global-node.d.ts" />
2
+ /// <reference path="../../src/types/global-variables.d.ts" />
3
+ /// <reference path="../../src/types/global-deno.d.ts" />
4
+ export declare function getEnvVariable(name: string): string | undefined;
5
+ export declare function getGitBranch(): Promise<string | undefined>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
3
+ ///<reference path="../types/global-node.d.ts"/>
4
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
5
+ ///<reference path="../types/global-variables.d.ts"/>
6
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
7
+ ///<reference path="../types/global-deno.d.ts"/>
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.getGitBranch = exports.getEnvVariable = void 0;
19
+ const lang_1 = require("./lang");
20
+ function getEnvVariable(name) {
21
+ var _a, _b;
22
+ // Node.js: process.env
23
+ try {
24
+ if ((0, lang_1.isObject)(process) && (0, lang_1.isString)((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[name])) {
25
+ return process.env[name];
26
+ }
27
+ }
28
+ catch (err) {
29
+ // Ignore: Should never happen
30
+ }
31
+ try {
32
+ // Deno: Deno.env.get
33
+ if ((0, lang_1.isObject)(Deno) && (0, lang_1.isString)((_b = Deno === null || Deno === void 0 ? void 0 : Deno.env) === null || _b === void 0 ? void 0 : _b.get(name))) {
34
+ return Deno.env.get(name);
35
+ }
36
+ }
37
+ catch (err) {
38
+ // Ignore: Will fail if not using --allow-env
39
+ }
40
+ }
41
+ exports.getEnvVariable = getEnvVariable;
42
+ function getGitBranch() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ // Node.js: child_process.execSync
45
+ try {
46
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
47
+ return require('child_process').execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
48
+ }
49
+ catch (err) {
50
+ // Ignore
51
+ }
52
+ // Deno: Deno.run
53
+ try {
54
+ if ((0, lang_1.isObject)(Deno)) {
55
+ const process = Deno.run({
56
+ cmd: ['git', 'branch', '--show-current'],
57
+ stdout: 'piped',
58
+ stderr: 'piped'
59
+ });
60
+ return new TextDecoder().decode(yield process.output()).trim();
61
+ }
62
+ }
63
+ catch (err) {
64
+ // Ignore: Will fail if not using --allow-run
65
+ }
66
+ });
67
+ }
68
+ exports.getGitBranch = getGitBranch;
@@ -0,0 +1,2 @@
1
+ import { FetchImpl } from '../api/fetcher';
2
+ export declare function getFetchImplementation(userFetch?: FetchImpl): FetchImpl | typeof fetch;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFetchImplementation = void 0;
4
+ function getFetchImplementation(userFetch) {
5
+ const globalFetch = typeof fetch !== 'undefined' ? fetch : undefined;
6
+ const fetchImpl = userFetch !== null && userFetch !== void 0 ? userFetch : globalFetch;
7
+ if (!fetchImpl) {
8
+ /** @todo add a link after docs exist */
9
+ throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
10
+ }
11
+ return fetchImpl;
12
+ }
13
+ exports.getFetchImplementation = getFetchImplementation;
@@ -1,5 +1,5 @@
1
1
  export declare function compact<T>(arr: Array<T | null | undefined>): T[];
2
2
  export declare function compactObject<T>(obj: Record<string, T | null | undefined>): Record<string, T>;
3
3
  export declare type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4
- export declare function isObject(value: any): value is object;
4
+ export declare function isObject(value: any): value is Record<string, unknown>;
5
5
  export declare function isString(value: any): value is string;
package/dist/util/lang.js CHANGED
@@ -13,7 +13,7 @@ function compactObject(obj) {
13
13
  }
14
14
  exports.compactObject = compactObject;
15
15
  function isObject(value) {
16
- return value !== undefined && value !== null && typeof value === 'object';
16
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
17
17
  }
18
18
  exports.isObject = isObject;
19
19
  function isString(value) {
@@ -11,3 +11,15 @@ export declare type NonEmptyArray<T> = T[] & {
11
11
  export declare type RequiredBy<T, K extends keyof T> = T & {
12
12
  [P in K]-?: NonNullable<T[P]>;
13
13
  };
14
+ export declare type GetArrayInnerType<T extends readonly any[]> = T[number];
15
+ export declare type NonNullableValues<Obj> = {
16
+ [K in keyof Obj]: NonNullable<Obj[K]>;
17
+ };
18
+ export declare type KeysOfUnion<T> = T extends T ? keyof T : never;
19
+ declare type Impossible<K extends keyof any> = {
20
+ [P in K]: never;
21
+ };
22
+ export declare type Exactly<T, U extends T = T> = U & Impossible<Exclude<keyof U, keyof T>>;
23
+ export declare type SingleOrArray<T> = T | T[];
24
+ export declare type Dictionary<T> = Record<string, T>;
25
+ export {};
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.6.0",
3
+ "version": "0.7.2",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
+ "browser": {
8
+ "child_process": false
9
+ },
7
10
  "scripts": {
8
11
  "test": "echo \"Error: no test specified\" && exit 1",
9
12
  "build": "tsc -p tsconfig.build.json",
@@ -20,5 +23,5 @@
20
23
  "url": "https://github.com/xataio/client-ts/issues"
21
24
  },
22
25
  "homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
23
- "gitHead": "f46df88912b2bac2ddae598d9d08efc1f44b00be"
26
+ "gitHead": "036d273ce2e938ef4bae72c3727881eefaf30574"
24
27
  }