@xata.io/client 0.0.0-beta.c9e08d0 → 0.0.0-beta.ca9389a
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/.eslintrc.cjs +13 -0
- package/CHANGELOG.md +87 -0
- package/dist/api/client.d.ts +95 -0
- package/dist/api/client.js +251 -0
- package/dist/api/components.d.ts +1437 -0
- package/dist/api/components.js +998 -0
- package/dist/api/fetcher.d.ts +40 -0
- package/dist/api/fetcher.js +79 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +21 -0
- package/dist/api/parameters.d.ts +16 -0
- package/dist/api/parameters.js +2 -0
- package/dist/api/providers.d.ts +8 -0
- package/dist/api/providers.js +30 -0
- package/dist/api/responses.d.ts +50 -0
- package/dist/api/responses.js +2 -0
- package/dist/api/schemas.d.ts +311 -0
- package/dist/api/schemas.js +2 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.js +124 -0
- package/dist/index.d.ts +5 -182
- package/dist/index.js +19 -499
- package/dist/namespace.d.ts +7 -0
- package/dist/namespace.js +6 -0
- package/dist/schema/filters.d.ts +96 -0
- package/dist/schema/filters.js +2 -0
- package/dist/schema/filters.spec.d.ts +1 -0
- package/dist/schema/filters.spec.js +177 -0
- package/dist/schema/index.d.ts +21 -0
- package/dist/schema/index.js +49 -0
- package/dist/schema/operators.d.ts +74 -0
- package/dist/schema/operators.js +93 -0
- package/dist/schema/pagination.d.ts +83 -0
- package/dist/schema/pagination.js +93 -0
- package/dist/schema/query.d.ts +118 -0
- package/dist/schema/query.js +242 -0
- package/dist/schema/record.d.ts +66 -0
- package/dist/schema/record.js +13 -0
- package/dist/schema/repository.d.ts +134 -0
- package/dist/schema/repository.js +284 -0
- package/dist/schema/selection.d.ts +25 -0
- package/dist/schema/selection.js +2 -0
- package/dist/schema/selection.spec.d.ts +1 -0
- package/dist/schema/selection.spec.js +204 -0
- package/dist/schema/sorting.d.ts +17 -0
- package/dist/schema/sorting.js +28 -0
- package/dist/schema/sorting.spec.d.ts +1 -0
- package/dist/schema/sorting.spec.js +11 -0
- 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/environment.d.ts +5 -0
- package/dist/util/environment.js +68 -0
- package/dist/util/fetch.d.ts +2 -0
- package/dist/util/fetch.js +13 -0
- package/dist/util/lang.d.ts +5 -0
- package/dist/util/lang.js +22 -0
- package/dist/util/types.d.ts +25 -0
- package/dist/util/types.js +2 -0
- package/package.json +5 -2
- package/tsconfig.json +21 -0
- package/dist/util/errors.d.ts +0 -3
- package/dist/util/errors.js +0 -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,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;
|
@@ -0,0 +1,5 @@
|
|
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;
|
@@ -0,0 +1,22 @@
|
|
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;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
export declare type StringKeys<O> = Extract<keyof O, string>;
|
2
|
+
export declare type NumberKeys<O> = Extract<keyof O, number>;
|
3
|
+
export declare type Values<O> = O[StringKeys<O>];
|
4
|
+
export declare type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
|
5
|
+
export declare type If<Condition, Then, Else> = Condition extends true ? Then : Else;
|
6
|
+
export declare type IsObject<T> = T extends Record<string, any> ? true : false;
|
7
|
+
export declare type IsArray<T> = T extends Array<any> ? true : false;
|
8
|
+
export declare type NonEmptyArray<T> = T[] & {
|
9
|
+
0: T;
|
10
|
+
};
|
11
|
+
export declare type RequiredBy<T, K extends keyof T> = T & {
|
12
|
+
[P in K]-?: NonNullable<T[P]>;
|
13
|
+
};
|
14
|
+
export declare type GetArrayInnerType<T extends readonly any[]> = T[number];
|
15
|
+
export declare type AllRequired<T> = {
|
16
|
+
[P in keyof T]-?: T[P];
|
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.0.0-beta.
|
3
|
+
"version": "0.0.0-beta.ca9389a",
|
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/tsconfig.json
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "ES6",
|
4
|
+
"lib": ["dom", "esnext"],
|
5
|
+
"allowJs": true,
|
6
|
+
"skipLibCheck": true,
|
7
|
+
"esModuleInterop": true,
|
8
|
+
"allowSyntheticDefaultImports": true,
|
9
|
+
"strict": true,
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
11
|
+
"noFallthroughCasesInSwitch": true,
|
12
|
+
"module": "CommonJS",
|
13
|
+
"moduleResolution": "node",
|
14
|
+
"resolveJsonModule": true,
|
15
|
+
"isolatedModules": true,
|
16
|
+
"noEmit": false,
|
17
|
+
"outDir": "dist",
|
18
|
+
"declaration": true
|
19
|
+
},
|
20
|
+
"include": ["src"]
|
21
|
+
}
|
package/dist/util/errors.d.ts
DELETED
package/dist/util/errors.js
DELETED
@@ -1,9 +0,0 @@
|
|
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
|
-
};
|