@xata.io/client 0.8.2 → 0.8.3

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.cjs +1762 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +2731 -7
  5. package/dist/index.mjs +1667 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +9 -5
  8. package/rollup.config.js +33 -0
  9. package/tsconfig.json +2 -2
  10. package/dist/api/client.d.ts +0 -95
  11. package/dist/api/client.js +0 -251
  12. package/dist/api/components.d.ts +0 -1437
  13. package/dist/api/components.js +0 -998
  14. package/dist/api/fetcher.d.ts +0 -40
  15. package/dist/api/fetcher.js +0 -79
  16. package/dist/api/index.d.ts +0 -13
  17. package/dist/api/index.js +0 -40
  18. package/dist/api/parameters.d.ts +0 -16
  19. package/dist/api/parameters.js +0 -2
  20. package/dist/api/providers.d.ts +0 -8
  21. package/dist/api/providers.js +0 -30
  22. package/dist/api/responses.d.ts +0 -50
  23. package/dist/api/responses.js +0 -2
  24. package/dist/api/schemas.d.ts +0 -311
  25. package/dist/api/schemas.js +0 -2
  26. package/dist/client.d.ts +0 -27
  27. package/dist/client.js +0 -131
  28. package/dist/index.js +0 -30
  29. package/dist/plugins.d.ts +0 -7
  30. package/dist/plugins.js +0 -6
  31. package/dist/schema/filters.d.ts +0 -96
  32. package/dist/schema/filters.js +0 -2
  33. package/dist/schema/filters.spec.d.ts +0 -1
  34. package/dist/schema/filters.spec.js +0 -177
  35. package/dist/schema/index.d.ts +0 -24
  36. package/dist/schema/index.js +0 -60
  37. package/dist/schema/operators.d.ts +0 -74
  38. package/dist/schema/operators.js +0 -93
  39. package/dist/schema/pagination.d.ts +0 -83
  40. package/dist/schema/pagination.js +0 -93
  41. package/dist/schema/query.d.ts +0 -118
  42. package/dist/schema/query.js +0 -242
  43. package/dist/schema/record.d.ts +0 -66
  44. package/dist/schema/record.js +0 -13
  45. package/dist/schema/repository.d.ts +0 -135
  46. package/dist/schema/repository.js +0 -283
  47. package/dist/schema/selection.d.ts +0 -25
  48. package/dist/schema/selection.js +0 -2
  49. package/dist/schema/selection.spec.d.ts +0 -1
  50. package/dist/schema/selection.spec.js +0 -204
  51. package/dist/schema/sorting.d.ts +0 -22
  52. package/dist/schema/sorting.js +0 -35
  53. package/dist/schema/sorting.spec.d.ts +0 -1
  54. package/dist/schema/sorting.spec.js +0 -11
  55. package/dist/search/index.d.ts +0 -34
  56. package/dist/search/index.js +0 -55
  57. package/dist/util/branches.d.ts +0 -5
  58. package/dist/util/branches.js +0 -7
  59. package/dist/util/config.d.ts +0 -11
  60. package/dist/util/config.js +0 -121
  61. package/dist/util/environment.d.ts +0 -5
  62. package/dist/util/environment.js +0 -68
  63. package/dist/util/fetch.d.ts +0 -2
  64. package/dist/util/fetch.js +0 -13
  65. package/dist/util/lang.d.ts +0 -5
  66. package/dist/util/lang.js +0 -22
  67. package/dist/util/types.d.ts +0 -25
  68. package/dist/util/types.js +0 -2
@@ -1,204 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-floating-promises */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const vitest_1 = require("vitest");
5
- // SelectableColumn<O> //
6
- // --------------------------------------------------------------------------- //
7
- const validTeamColumns = [
8
- '*',
9
- 'id',
10
- 'name',
11
- 'owner.*',
12
- 'owner.address.*',
13
- 'owner.address',
14
- 'owner.address.street'
15
- ];
16
- // @ts-expect-error
17
- const invalidFullNameTeamColumn = 'full_name';
18
- // @ts-expect-error
19
- const invalidPartialTeamColumn = 'owner.address.';
20
- // @ts-expect-error
21
- const invalidDeleteTeamColumn = 'owner.delete';
22
- // @ts-expect-error
23
- const invalidReadTeamColumn = 'owner.read.*';
24
- // ValueAtColumn<O, P> //
25
- // --------------------------------------------------------------------------- //
26
- const labelsValue = ['foo'];
27
- // @ts-expect-error
28
- const invalidLabelsValue = [1];
29
- // SelectedRecordPick<O, Key> //
30
- // ---------------------------------------------------------------------------- //
31
- function test1(user) {
32
- var _a, _b, _c, _d;
33
- user.id;
34
- user.read();
35
- user.full_name;
36
- (_a = user.address) === null || _a === void 0 ? void 0 : _a.street;
37
- // @ts-expect-error
38
- user.team.id;
39
- (_b = user.team) === null || _b === void 0 ? void 0 : _b.id;
40
- (_c = user.team) === null || _c === void 0 ? void 0 : _c.read();
41
- // @ts-expect-error
42
- (_d = user.team) === null || _d === void 0 ? void 0 : _d.name;
43
- user.partner.id;
44
- user.partner.read();
45
- // @ts-expect-error
46
- user.partner.full_name;
47
- user.team = null;
48
- // @ts-expect-error
49
- user.partner = null;
50
- }
51
- function test2(user) {
52
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
53
- user.id;
54
- user.read();
55
- user.full_name;
56
- (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
57
- (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
58
- (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
59
- (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner;
60
- (_f = (_e = user.team) === null || _e === void 0 ? void 0 : _e.owner) === null || _f === void 0 ? void 0 : _f.id;
61
- (_h = (_g = user.team) === null || _g === void 0 ? void 0 : _g.owner) === null || _h === void 0 ? void 0 : _h.read();
62
- // @ts-expect-error
63
- (_k = (_j = user.team) === null || _j === void 0 ? void 0 : _j.owner) === null || _k === void 0 ? void 0 : _k.full_name;
64
- // @ts-expect-error
65
- user.full_name = null;
66
- user.email = null;
67
- user.email = '';
68
- // @ts-expect-error
69
- user.email = 2;
70
- if (user.team) {
71
- // @ts-expect-error
72
- user.team.name = null;
73
- user.team.labels = null;
74
- user.team.labels = ['foo'];
75
- // @ts-expect-error
76
- user.team.labels = [1];
77
- }
78
- }
79
- function test3(user) {
80
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
81
- user.id;
82
- user.read();
83
- // @ts-expect-error
84
- user.full_name;
85
- (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
86
- (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
87
- // @ts-expect-error
88
- (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
89
- (_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
90
- (_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
91
- (_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
92
- }
93
- function test4(user) {
94
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
95
- user.id;
96
- user.read();
97
- // @ts-expect-error
98
- user.full_name;
99
- (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
100
- (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
101
- // @ts-expect-error
102
- (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
103
- (_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
104
- (_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
105
- // @ts-expect-error
106
- (_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
107
- (_l = (_k = user.team) === null || _k === void 0 ? void 0 : _k.owner) === null || _l === void 0 ? void 0 : _l.address;
108
- (_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;
109
- (_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;
110
- }
111
- function test5(user) {
112
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
113
- user.id;
114
- user.read();
115
- // @ts-expect-error
116
- user.full_name;
117
- user.settings;
118
- (_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
119
- (_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
120
- (_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
121
- (_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
122
- (_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
123
- // @ts-expect-error
124
- (_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
125
- // @ts-expect-error
126
- (_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
127
- // @ts-expect-error
128
- (_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
129
- user.settings = null;
130
- user.nonNullable.nested.value = 2;
131
- // @ts-expect-error
132
- user.nonNullable = null;
133
- // @ts-expect-error
134
- user.nonNullable.nested.value = null;
135
- }
136
- function test6(user) {
137
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
138
- user.id;
139
- user.read();
140
- // @ts-expect-error
141
- user.full_name;
142
- user.settings;
143
- (_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
144
- (_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
145
- (_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
146
- (_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
147
- (_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
148
- // @ts-expect-error
149
- (_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
150
- // @ts-expect-error
151
- (_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
152
- // @ts-expect-error
153
- (_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
154
- user.nonNullable.nested.value = 2;
155
- user.nonNullable.nested.deep.depths.of.numbers = [1, 2, 3];
156
- // @ts-expect-error
157
- user.nonNullable.nested.deep.depths.of.numbers = 'invalid-string';
158
- user.settings = null;
159
- // @ts-expect-error
160
- user.nonNullable = null;
161
- // @ts-expect-error
162
- user.nonNullable.nested.value = null;
163
- }
164
- function test7(user) {
165
- var _a, _b;
166
- user.partner;
167
- user.partner.id;
168
- user.partner.read();
169
- user.partner.full_name;
170
- // @ts-expect-error
171
- user.partner.full_name = null;
172
- user.partner.address;
173
- // @ts-expect-error
174
- user.team.id;
175
- (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
176
- // @ts-expect-error
177
- user.team.read();
178
- (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
179
- // @ts-expect-error
180
- user.partner = null;
181
- user.team = null;
182
- }
183
- function test8(user) {
184
- var _a, _b;
185
- user.partner;
186
- user.partner.id;
187
- user.partner.read();
188
- user.partner.full_name;
189
- // @ts-expect-error
190
- user.partner.full_name = null;
191
- user.partner.address;
192
- // @ts-expect-error
193
- user.team.id;
194
- (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
195
- // @ts-expect-error
196
- user.team.read();
197
- (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
198
- // @ts-expect-error
199
- user.partner = null;
200
- user.team = null;
201
- }
202
- (0, vitest_1.test)('fake test', () => {
203
- // This is a fake test to make sure that the type definitions in this file are working
204
- });
@@ -1,22 +0,0 @@
1
- import { SingleOrArray, StringKeys, 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> | SortFilterBase<T>;
10
- declare type SortFilterBase<T extends XataRecord> = {
11
- [Key in StringKeys<T>]: SortDirection;
12
- };
13
- export declare type ApiSortFilter<T extends XataRecord> = SingleOrArray<Values<{
14
- [Key in SelectableColumn<T>]: {
15
- [K in Key]: SortDirection;
16
- };
17
- }>>;
18
- export declare function isSortFilterString<T extends XataRecord>(value: any): value is SelectableColumn<T>;
19
- export declare function isSortFilterBase<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterBase<T>;
20
- export declare function isSortFilterObject<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
21
- export declare function buildSortFilter<T extends XataRecord>(filter: SingleOrArray<SortFilter<T>>): ApiSortFilter<T>;
22
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildSortFilter = exports.isSortFilterObject = exports.isSortFilterBase = 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 isSortFilterBase(filter) {
10
- return (0, lang_1.isObject)(filter) && Object.values(filter).every((value) => value === 'asc' || value === 'desc');
11
- }
12
- exports.isSortFilterBase = isSortFilterBase;
13
- function isSortFilterObject(filter) {
14
- return (0, lang_1.isObject)(filter) && !isSortFilterBase(filter) && filter.column !== undefined;
15
- }
16
- exports.isSortFilterObject = isSortFilterObject;
17
- function buildSortFilter(filter) {
18
- var _a;
19
- if (isSortFilterString(filter)) {
20
- return { [filter]: 'asc' };
21
- }
22
- else if (Array.isArray(filter)) {
23
- return filter.map((item) => buildSortFilter(item));
24
- }
25
- else if (isSortFilterBase(filter)) {
26
- return filter;
27
- }
28
- else if (isSortFilterObject(filter)) {
29
- return { [filter.column]: (_a = filter.direction) !== null && _a !== void 0 ? _a : 'asc' };
30
- }
31
- else {
32
- throw new Error(`Invalid sort filter: ${filter}`);
33
- }
34
- }
35
- exports.buildSortFilter = buildSortFilter;
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable @typescript-eslint/no-unused-vars */
4
- const vitest_1 = require("vitest");
5
- // Simple sorting
6
- const simpleSorting = { name: 'asc' };
7
- // Array of simple sorting
8
- const arrayOfSimpleSorting = [{ name: 'asc' }, { age: 'desc' }];
9
- (0, vitest_1.test)('fake test', () => {
10
- // This is a fake test to make sure that the type definitions in this file are working
11
- });
@@ -1,34 +0,0 @@
1
- import { XataPlugin, XataPluginOptions } from '../plugins';
2
- import { BaseData, XataRecord } from '../schema/record';
3
- import { SelectedPick } from '../schema/selection';
4
- import { GetArrayInnerType, Values } from '../util/types';
5
- export declare class SearchPlugin<Schemas extends Record<string, BaseData>> extends XataPlugin {
6
- #private;
7
- build({ getFetchProps }: XataPluginOptions): {
8
- all: <Tables extends Extract<keyof Schemas, string>>(query: string, options?: {
9
- fuzziness?: number | undefined;
10
- tables?: Tables[] | undefined;
11
- }) => Promise<Values<{ [Model in Tables]: {
12
- table: Model;
13
- record: Awaited<SelectedPick<Schemas[Model] & XataRecord & {
14
- xata: {
15
- table: string;
16
- };
17
- }, ["*"]>>;
18
- }; }>[]>;
19
- byTable: <Tables_1 extends Extract<keyof Schemas, string>>(query: string, options?: {
20
- fuzziness?: number | undefined;
21
- tables?: Tables_1[] | undefined;
22
- }) => Promise<{ [Model_1 in Tables_1]: SelectedPick<Schemas[Model_1] & XataRecord & {
23
- xata: {
24
- table: string;
25
- };
26
- }, ["*"]>[]; }>;
27
- };
28
- }
29
- declare type SearchXataRecord = XataRecord & {
30
- xata: {
31
- table: string;
32
- };
33
- };
34
- export {};
@@ -1,55 +0,0 @@
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
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
- };
16
- var _SearchPlugin_instances, _SearchPlugin_search;
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.SearchPlugin = void 0;
19
- const api_1 = require("../api");
20
- const plugins_1 = require("../plugins");
21
- class SearchPlugin extends plugins_1.XataPlugin {
22
- constructor() {
23
- super(...arguments);
24
- _SearchPlugin_instances.add(this);
25
- }
26
- build({ getFetchProps }) {
27
- return {
28
- all: (query, options = {}) => __awaiter(this, void 0, void 0, function* () {
29
- const records = yield __classPrivateFieldGet(this, _SearchPlugin_instances, "m", _SearchPlugin_search).call(this, query, options, getFetchProps);
30
- return records.map((record) => {
31
- const { table = 'orphan' } = record.xata;
32
- return { table, record };
33
- });
34
- }),
35
- byTable: (query, options = {}) => __awaiter(this, void 0, void 0, function* () {
36
- const records = yield __classPrivateFieldGet(this, _SearchPlugin_instances, "m", _SearchPlugin_search).call(this, query, options, getFetchProps);
37
- return records.reduce((acc, record) => {
38
- var _a;
39
- const { table = 'orphan' } = record.xata;
40
- const items = (_a = acc[table]) !== null && _a !== void 0 ? _a : [];
41
- return Object.assign(Object.assign({}, acc), { [table]: [...items, record] });
42
- }, {});
43
- })
44
- };
45
- }
46
- }
47
- exports.SearchPlugin = SearchPlugin;
48
- _SearchPlugin_instances = new WeakSet(), _SearchPlugin_search = function _SearchPlugin_search(query, options, getFetchProps) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const fetchProps = yield getFetchProps();
51
- const { tables, fuzziness } = options !== null && options !== void 0 ? options : {};
52
- const { records } = yield (0, api_1.searchBranch)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}' }, body: { tables, query, fuzziness } }, fetchProps));
53
- return records;
54
- });
55
- };
@@ -1,5 +0,0 @@
1
- export declare type BranchStrategyValue = string | undefined | null;
2
- export declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
3
- export declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
4
- export declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
5
- export declare const isBranchStrategyBuilder: (strategy: BranchStrategy) => strategy is BranchStrategyBuilder;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBranchStrategyBuilder = void 0;
4
- const isBranchStrategyBuilder = (strategy) => {
5
- return typeof strategy === 'function';
6
- };
7
- exports.isBranchStrategyBuilder = isBranchStrategyBuilder;
@@ -1,11 +0,0 @@
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 {};
@@ -1,121 +0,0 @@
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;
@@ -1,5 +0,0 @@
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>;
@@ -1,68 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import { FetchImpl } from '../api/fetcher';
2
- export declare function getFetchImplementation(userFetch?: FetchImpl): FetchImpl | typeof fetch;
@@ -1,13 +0,0 @@
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 +0,0 @@
1
- export declare function compact<T>(arr: Array<T | null | undefined>): T[];
2
- export declare function compactObject<T>(obj: Record<string, T | null | undefined>): Record<string, T>;
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 Record<string, unknown>;
5
- export declare function isString(value: any): value is string;
package/dist/util/lang.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isString = exports.isObject = exports.compactObject = exports.compact = void 0;
4
- function notEmpty(value) {
5
- return value !== null && value !== undefined;
6
- }
7
- function compact(arr) {
8
- return arr.filter(notEmpty);
9
- }
10
- exports.compact = compact;
11
- function compactObject(obj) {
12
- return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
13
- }
14
- exports.compactObject = compactObject;
15
- function isObject(value) {
16
- return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
17
- }
18
- exports.isObject = isObject;
19
- function isString(value) {
20
- return value !== undefined && value !== null && typeof value === 'string';
21
- }
22
- exports.isString = isString;