@xata.io/client 0.7.0 → 0.8.0
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/CHANGELOG.md +24 -0
- package/dist/api/client.js +22 -9
- package/dist/api/components.d.ts +7 -6
- package/dist/api/components.js +7 -6
- package/dist/client.d.ts +39 -0
- package/dist/client.js +124 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/namespace.d.ts +7 -0
- package/dist/namespace.js +6 -0
- package/dist/schema/filters.spec.js +3 -1
- package/dist/schema/index.d.ts +16 -2
- package/dist/schema/index.js +26 -6
- package/dist/schema/operators.d.ts +13 -1
- package/dist/schema/operators.js +17 -2
- package/dist/schema/record.d.ts +5 -5
- package/dist/schema/repository.d.ts +34 -48
- package/dist/schema/repository.js +57 -150
- package/dist/schema/selection.spec.js +2 -1
- package/dist/schema/sorting.spec.js +3 -1
- package/dist/search/index.d.ts +20 -0
- package/dist/search/index.js +30 -0
- package/dist/util/branches.d.ts +5 -0
- package/dist/util/branches.js +7 -0
- package/dist/util/config.d.ts +11 -0
- package/dist/util/config.js +121 -0
- package/dist/util/types.d.ts +3 -2
- package/package.json +5 -2
- package/dist/schema/config.d.ts +0 -4
- package/dist/schema/config.js +0 -83
@@ -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;
|
package/dist/util/types.d.ts
CHANGED
@@ -12,8 +12,8 @@ export declare type RequiredBy<T, K extends keyof T> = T & {
|
|
12
12
|
[P in K]-?: NonNullable<T[P]>;
|
13
13
|
};
|
14
14
|
export declare type GetArrayInnerType<T extends readonly any[]> = T[number];
|
15
|
-
export declare type
|
16
|
-
[
|
15
|
+
export declare type AllRequired<T> = {
|
16
|
+
[P in keyof T]-?: T[P];
|
17
17
|
};
|
18
18
|
export declare type KeysOfUnion<T> = T extends T ? keyof T : never;
|
19
19
|
declare type Impossible<K extends keyof any> = {
|
@@ -21,4 +21,5 @@ declare type Impossible<K extends keyof any> = {
|
|
21
21
|
};
|
22
22
|
export declare type Exactly<T, U extends T = T> = U & Impossible<Exclude<keyof U, keyof T>>;
|
23
23
|
export declare type SingleOrArray<T> = T | T[];
|
24
|
+
export declare type Dictionary<T> = Record<string, T>;
|
24
25
|
export {};
|
package/package.json
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@xata.io/client",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.8.0",
|
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": "
|
26
|
+
"gitHead": "ca9389ac662985428e3714be546cbf9d3bc5c4b6"
|
24
27
|
}
|
package/dist/schema/config.d.ts
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
import { FetcherExtraProps } from '../api/fetcher';
|
2
|
-
export declare function getBranch(fetchProps: Omit<FetcherExtraProps, 'workspacesApiUrl'>): Promise<string | undefined>;
|
3
|
-
export declare function getDatabaseUrl(): string | undefined;
|
4
|
-
export declare function getAPIKey(): string | undefined;
|
package/dist/schema/config.js
DELETED
@@ -1,83 +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.getBranch = void 0;
|
13
|
-
const api_1 = require("../api");
|
14
|
-
const environment_1 = require("../util/environment");
|
15
|
-
const lang_1 = require("../util/lang");
|
16
|
-
const envBranchNames = [
|
17
|
-
'XATA_BRANCH',
|
18
|
-
'VERCEL_GIT_COMMIT_REF',
|
19
|
-
'CF_PAGES_BRANCH',
|
20
|
-
'BRANCH' // Netlify. Putting it the last one because it is more ambiguous
|
21
|
-
];
|
22
|
-
function getBranch(fetchProps) {
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
const env = getBranchByEnvVariable();
|
25
|
-
if (env)
|
26
|
-
return env;
|
27
|
-
const branch = yield (0, environment_1.getGitBranch)();
|
28
|
-
if (!branch)
|
29
|
-
return undefined;
|
30
|
-
// TODO: in the future, call /resolve endpoint
|
31
|
-
// For now, call API to see if the branch exists. If not, use a default value.
|
32
|
-
const [protocol, , host, , database] = fetchProps.apiUrl.split('/');
|
33
|
-
const [workspace] = host.split('.');
|
34
|
-
const dbBranchName = `${database}:${branch}`;
|
35
|
-
try {
|
36
|
-
yield (0, api_1.getBranchDetails)(Object.assign(Object.assign({}, fetchProps), { workspacesApiUrl: `${protocol}//${host}`, pathParams: {
|
37
|
-
dbBranchName,
|
38
|
-
workspace
|
39
|
-
} }));
|
40
|
-
}
|
41
|
-
catch (err) {
|
42
|
-
if ((0, lang_1.isObject)(err) && err.status === 404)
|
43
|
-
return 'main';
|
44
|
-
throw err;
|
45
|
-
}
|
46
|
-
return branch;
|
47
|
-
});
|
48
|
-
}
|
49
|
-
exports.getBranch = getBranch;
|
50
|
-
function getBranchByEnvVariable() {
|
51
|
-
for (const name of envBranchNames) {
|
52
|
-
const value = (0, environment_1.getEnvVariable)(name);
|
53
|
-
if (value) {
|
54
|
-
return value;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
try {
|
58
|
-
return XATA_BRANCH;
|
59
|
-
}
|
60
|
-
catch (err) {
|
61
|
-
// Ignore ReferenceError. Only CloudFlare workers set env variables as global variables
|
62
|
-
}
|
63
|
-
}
|
64
|
-
function getDatabaseUrl() {
|
65
|
-
var _a;
|
66
|
-
try {
|
67
|
-
return (_a = (0, environment_1.getEnvVariable)('XATA_DATABASE_URL')) !== null && _a !== void 0 ? _a : XATA_DATABASE_URL;
|
68
|
-
}
|
69
|
-
catch (err) {
|
70
|
-
return undefined;
|
71
|
-
}
|
72
|
-
}
|
73
|
-
exports.getDatabaseUrl = getDatabaseUrl;
|
74
|
-
function getAPIKey() {
|
75
|
-
var _a;
|
76
|
-
try {
|
77
|
-
return (_a = (0, environment_1.getEnvVariable)('XATA_API_KEY')) !== null && _a !== void 0 ? _a : XATA_API_KEY;
|
78
|
-
}
|
79
|
-
catch (err) {
|
80
|
-
return undefined;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
exports.getAPIKey = getAPIKey;
|