@xata.io/client 0.8.2 → 0.9.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 +29 -0
- package/dist/index.cjs +1903 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3286 -7
- package/dist/index.mjs +1807 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -5
- package/rollup.config.js +29 -0
- package/tsconfig.json +5 -4
- package/dist/api/client.d.ts +0 -95
- package/dist/api/client.js +0 -251
- package/dist/api/components.d.ts +0 -1437
- package/dist/api/components.js +0 -998
- package/dist/api/fetcher.d.ts +0 -40
- package/dist/api/fetcher.js +0 -79
- package/dist/api/index.d.ts +0 -13
- package/dist/api/index.js +0 -40
- package/dist/api/parameters.d.ts +0 -16
- package/dist/api/parameters.js +0 -2
- package/dist/api/providers.d.ts +0 -8
- package/dist/api/providers.js +0 -30
- package/dist/api/responses.d.ts +0 -50
- package/dist/api/responses.js +0 -2
- package/dist/api/schemas.d.ts +0 -311
- package/dist/api/schemas.js +0 -2
- package/dist/client.d.ts +0 -27
- package/dist/client.js +0 -131
- package/dist/index.js +0 -30
- package/dist/plugins.d.ts +0 -7
- package/dist/plugins.js +0 -6
- package/dist/schema/filters.d.ts +0 -96
- package/dist/schema/filters.js +0 -2
- package/dist/schema/filters.spec.d.ts +0 -1
- package/dist/schema/filters.spec.js +0 -177
- package/dist/schema/index.d.ts +0 -24
- package/dist/schema/index.js +0 -60
- package/dist/schema/operators.d.ts +0 -74
- package/dist/schema/operators.js +0 -93
- package/dist/schema/pagination.d.ts +0 -83
- package/dist/schema/pagination.js +0 -93
- package/dist/schema/query.d.ts +0 -118
- package/dist/schema/query.js +0 -242
- package/dist/schema/record.d.ts +0 -66
- package/dist/schema/record.js +0 -13
- package/dist/schema/repository.d.ts +0 -135
- package/dist/schema/repository.js +0 -283
- package/dist/schema/selection.d.ts +0 -25
- package/dist/schema/selection.js +0 -2
- package/dist/schema/selection.spec.d.ts +0 -1
- package/dist/schema/selection.spec.js +0 -204
- package/dist/schema/sorting.d.ts +0 -22
- package/dist/schema/sorting.js +0 -35
- package/dist/schema/sorting.spec.d.ts +0 -1
- package/dist/schema/sorting.spec.js +0 -11
- package/dist/search/index.d.ts +0 -34
- package/dist/search/index.js +0 -55
- package/dist/util/branches.d.ts +0 -5
- package/dist/util/branches.js +0 -7
- package/dist/util/config.d.ts +0 -11
- package/dist/util/config.js +0 -121
- package/dist/util/environment.d.ts +0 -5
- package/dist/util/environment.js +0 -68
- package/dist/util/fetch.d.ts +0 -2
- package/dist/util/fetch.js +0 -13
- package/dist/util/lang.d.ts +0 -5
- package/dist/util/lang.js +0 -22
- package/dist/util/types.d.ts +0 -25
- package/dist/util/types.js +0 -2
package/dist/client.js
DELETED
@@ -1,131 +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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
17
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
20
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
21
|
-
};
|
22
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
23
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
24
|
-
var m = o[Symbol.asyncIterator], i;
|
25
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
26
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
27
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
28
|
-
};
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
30
|
-
exports.BaseClient = exports.buildClient = void 0;
|
31
|
-
const schema_1 = require("./schema");
|
32
|
-
const search_1 = require("./search");
|
33
|
-
const branches_1 = require("./util/branches");
|
34
|
-
const config_1 = require("./util/config");
|
35
|
-
const fetch_1 = require("./util/fetch");
|
36
|
-
const buildClient = (plugins) => {
|
37
|
-
var _instances, _branch, _parseOptions, _getFetchProps, _evaluateBranch, _a;
|
38
|
-
return _a = class {
|
39
|
-
constructor(options = {}, links) {
|
40
|
-
_instances.add(this);
|
41
|
-
_branch.set(this, void 0);
|
42
|
-
const safeOptions = __classPrivateFieldGet(this, _instances, "m", _parseOptions).call(this, options);
|
43
|
-
const namespaces = Object.assign({ db: new schema_1.SchemaPlugin(links), search: new search_1.SearchPlugin() }, plugins);
|
44
|
-
for (const [key, namespace] of Object.entries(namespaces)) {
|
45
|
-
if (!namespace)
|
46
|
-
continue;
|
47
|
-
const result = namespace.build({ getFetchProps: () => __classPrivateFieldGet(this, _instances, "m", _getFetchProps).call(this, safeOptions) });
|
48
|
-
if (result instanceof Promise) {
|
49
|
-
void result.then((namespace) => {
|
50
|
-
// @ts-ignore
|
51
|
-
this[key] = namespace;
|
52
|
-
});
|
53
|
-
}
|
54
|
-
else {
|
55
|
-
// @ts-ignore
|
56
|
-
this[key] = result;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
},
|
61
|
-
_branch = new WeakMap(),
|
62
|
-
_instances = new WeakSet(),
|
63
|
-
_parseOptions = function _parseOptions(options) {
|
64
|
-
const fetch = (0, fetch_1.getFetchImplementation)(options === null || options === void 0 ? void 0 : options.fetch);
|
65
|
-
const databaseURL = (options === null || options === void 0 ? void 0 : options.databaseURL) || (0, config_1.getDatabaseURL)();
|
66
|
-
const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (0, config_1.getAPIKey)();
|
67
|
-
const branch = () => __awaiter(this, void 0, void 0, function* () {
|
68
|
-
return (options === null || options === void 0 ? void 0 : options.branch)
|
69
|
-
? yield __classPrivateFieldGet(this, _instances, "m", _evaluateBranch).call(this, options.branch)
|
70
|
-
: yield (0, config_1.getCurrentBranchName)({ apiKey, databaseURL, fetchImpl: options === null || options === void 0 ? void 0 : options.fetch });
|
71
|
-
});
|
72
|
-
if (!databaseURL || !apiKey) {
|
73
|
-
throw new Error('Options databaseURL and apiKey are required');
|
74
|
-
}
|
75
|
-
return { fetch, databaseURL, apiKey, branch };
|
76
|
-
},
|
77
|
-
_getFetchProps = function _getFetchProps({ fetch, apiKey, databaseURL, branch }) {
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
79
|
-
const branchValue = yield __classPrivateFieldGet(this, _instances, "m", _evaluateBranch).call(this, branch);
|
80
|
-
if (!branchValue)
|
81
|
-
throw new Error('Unable to resolve branch value');
|
82
|
-
return {
|
83
|
-
fetchImpl: fetch,
|
84
|
-
apiKey,
|
85
|
-
apiUrl: '',
|
86
|
-
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
87
|
-
workspacesApiUrl: (path, params) => {
|
88
|
-
var _a;
|
89
|
-
const hasBranch = (_a = params.dbBranchName) !== null && _a !== void 0 ? _a : params.branch;
|
90
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : '');
|
91
|
-
return databaseURL + newPath;
|
92
|
-
}
|
93
|
-
};
|
94
|
-
});
|
95
|
-
},
|
96
|
-
_evaluateBranch = function _evaluateBranch(param) {
|
97
|
-
var e_1, _a;
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
99
|
-
if (__classPrivateFieldGet(this, _branch, "f"))
|
100
|
-
return __classPrivateFieldGet(this, _branch, "f");
|
101
|
-
if (!param)
|
102
|
-
return undefined;
|
103
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
104
|
-
const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
|
105
|
-
return (0, branches_1.isBranchStrategyBuilder)(strategy) ? yield strategy() : strategy;
|
106
|
-
});
|
107
|
-
try {
|
108
|
-
for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
|
109
|
-
const strategy = strategies_1_1.value;
|
110
|
-
const branch = yield evaluateBranch(strategy);
|
111
|
-
if (branch) {
|
112
|
-
__classPrivateFieldSet(this, _branch, branch, "f");
|
113
|
-
return branch;
|
114
|
-
}
|
115
|
-
}
|
116
|
-
}
|
117
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
118
|
-
finally {
|
119
|
-
try {
|
120
|
-
if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
|
121
|
-
}
|
122
|
-
finally { if (e_1) throw e_1.error; }
|
123
|
-
}
|
124
|
-
});
|
125
|
-
},
|
126
|
-
_a;
|
127
|
-
};
|
128
|
-
exports.buildClient = buildClient;
|
129
|
-
class BaseClient extends (0, exports.buildClient)() {
|
130
|
-
}
|
131
|
-
exports.BaseClient = BaseClient;
|
package/dist/index.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.XataError = void 0;
|
18
|
-
class XataError extends Error {
|
19
|
-
constructor(message, status) {
|
20
|
-
super(message);
|
21
|
-
this.status = status;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
exports.XataError = XataError;
|
25
|
-
__exportStar(require("./api"), exports);
|
26
|
-
__exportStar(require("./plugins"), exports);
|
27
|
-
__exportStar(require("./client"), exports);
|
28
|
-
__exportStar(require("./schema"), exports);
|
29
|
-
__exportStar(require("./search"), exports);
|
30
|
-
__exportStar(require("./util/config"), exports);
|
package/dist/plugins.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { FetcherExtraProps } from './api/fetcher';
|
2
|
-
export declare abstract class XataPlugin {
|
3
|
-
abstract build(options: XataPluginOptions): unknown | Promise<unknown>;
|
4
|
-
}
|
5
|
-
export declare type XataPluginOptions = {
|
6
|
-
getFetchProps: () => Promise<FetcherExtraProps>;
|
7
|
-
};
|
package/dist/plugins.js
DELETED
package/dist/schema/filters.d.ts
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
import { SingleOrArray } from '../util/types';
|
2
|
-
import { SelectableColumn, ValueAtColumn } from './selection';
|
3
|
-
/**
|
4
|
-
* PropertyMatchFilter
|
5
|
-
* Example:
|
6
|
-
{
|
7
|
-
"filter": {
|
8
|
-
"name": "value",
|
9
|
-
"name": {
|
10
|
-
"$is": "value",
|
11
|
-
"$any": [ "value1", "value2" ],
|
12
|
-
},
|
13
|
-
"settings.plan": {"$any": ["free", "paid"]},
|
14
|
-
"settings.plan": "free",
|
15
|
-
"settings": {
|
16
|
-
"plan": "free"
|
17
|
-
},
|
18
|
-
}
|
19
|
-
}
|
20
|
-
*/
|
21
|
-
declare type PropertyAccessFilter<Record> = {
|
22
|
-
[key in SelectableColumn<Record>]?: NestedApiFilter<ValueAtColumn<Record, key>> | PropertyFilter<ValueAtColumn<Record, key>>;
|
23
|
-
};
|
24
|
-
export declare type PropertyFilter<T> = T | {
|
25
|
-
$is: T;
|
26
|
-
} | {
|
27
|
-
$isNot: T;
|
28
|
-
} | {
|
29
|
-
$any: T[];
|
30
|
-
} | {
|
31
|
-
$none: T[];
|
32
|
-
} | ValueTypeFilters<T>;
|
33
|
-
declare type IncludesFilter<T> = PropertyFilter<T> | {
|
34
|
-
[key in '$all' | '$none' | '$any']?: IncludesFilter<T> | Array<IncludesFilter<T> | {
|
35
|
-
$not: IncludesFilter<T>;
|
36
|
-
}>;
|
37
|
-
};
|
38
|
-
export declare type StringTypeFilter = {
|
39
|
-
[key in '$contains' | '$pattern' | '$startsWith' | '$endsWith']?: string;
|
40
|
-
};
|
41
|
-
export declare type ComparableType = number | Date;
|
42
|
-
export declare type ComparableTypeFilter<T extends ComparableType> = {
|
43
|
-
[key in '$gt' | '$lt' | '$ge' | '$le']?: T;
|
44
|
-
};
|
45
|
-
export declare type ArrayFilter<T> = {
|
46
|
-
[key in '$includes']?: SingleOrArray<PropertyFilter<T> | ValueTypeFilters<T>> | IncludesFilter<T>;
|
47
|
-
} | {
|
48
|
-
[key in '$includesAll' | '$includesNone' | '$includesAny']?: T | Array<PropertyFilter<T> | {
|
49
|
-
$not: PropertyFilter<T>;
|
50
|
-
}>;
|
51
|
-
};
|
52
|
-
declare type ValueTypeFilters<T> = T | T extends string ? StringTypeFilter : T extends number ? ComparableTypeFilter<number> : T extends Date ? ComparableTypeFilter<Date> : T extends Array<infer T> ? ArrayFilter<T> : never;
|
53
|
-
/**
|
54
|
-
* AggregatorFilter
|
55
|
-
* Example:
|
56
|
-
{
|
57
|
-
"filter": {
|
58
|
-
"$any": {
|
59
|
-
"settings.dark": true,
|
60
|
-
"settings.plan": "free"
|
61
|
-
}
|
62
|
-
},
|
63
|
-
}
|
64
|
-
{
|
65
|
-
"filter": {
|
66
|
-
"$any": [
|
67
|
-
{
|
68
|
-
"name": "r1",
|
69
|
-
},
|
70
|
-
{
|
71
|
-
"name": "r2",
|
72
|
-
},
|
73
|
-
],
|
74
|
-
}
|
75
|
-
*/
|
76
|
-
declare type AggregatorFilter<Record> = {
|
77
|
-
[key in '$all' | '$any' | '$not' | '$none']?: SingleOrArray<Filter<Record>>;
|
78
|
-
};
|
79
|
-
/**
|
80
|
-
* Existance filter
|
81
|
-
* Example: { filter: { $exists: "settings" } }
|
82
|
-
*/
|
83
|
-
export declare type ExistanceFilter<Record> = {
|
84
|
-
[key in '$exists' | '$notExists']?: SelectableColumn<Record>;
|
85
|
-
};
|
86
|
-
declare type BaseApiFilter<Record> = PropertyAccessFilter<Record> | AggregatorFilter<Record> | ExistanceFilter<Record>;
|
87
|
-
/**
|
88
|
-
* Nested filter
|
89
|
-
* Injects the Api filters on nested properties
|
90
|
-
* Example: { filter: { settings: { plan: { $any: ['free', 'trial'] } } } }
|
91
|
-
*/
|
92
|
-
declare type NestedApiFilter<T> = T extends Record<string, any> ? {
|
93
|
-
[key in keyof T]?: T[key] extends Record<string, any> ? SingleOrArray<Filter<T[key]>> : PropertyFilter<T[key]>;
|
94
|
-
} : PropertyFilter<T>;
|
95
|
-
export declare type Filter<Record> = BaseApiFilter<Record> | NestedApiFilter<Record>;
|
96
|
-
export {};
|
package/dist/schema/filters.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,177 +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
|
-
// Single column with implicit is
|
6
|
-
const singleColumnWithImplicitIs = { name: 'r2' };
|
7
|
-
// Single column with explicit is
|
8
|
-
const singleColumnWithExplicitIs = { name: { $is: 'r2' } };
|
9
|
-
// Is string
|
10
|
-
const isString = { string: 'string' };
|
11
|
-
// Is true
|
12
|
-
const isTrue = { boolean: true };
|
13
|
-
// Is false
|
14
|
-
const isFalse = { boolean: false };
|
15
|
-
// Is pos int
|
16
|
-
const isPosInt = { number: 1234567 };
|
17
|
-
// Is neg int
|
18
|
-
const isNegInt = { number: -42 };
|
19
|
-
// Is float
|
20
|
-
const isFloat = { number: 3.14 };
|
21
|
-
// with dots
|
22
|
-
const withDots = { 'settings.plan': 'free' };
|
23
|
-
// Nested columns
|
24
|
-
const nestedColumns = { settings: { plan: 'free' } };
|
25
|
-
// Nested columns array
|
26
|
-
const nestedColumnsArray = { settings: [{ dark: false }, { plan: 'free' }] };
|
27
|
-
// Nested columns any
|
28
|
-
const nestedColumnsAny = { settings: { $any: [{ plan: 'free' }, { plan: 'trial' }] } };
|
29
|
-
// Nested columns any value
|
30
|
-
const nestedColumnsAnyValue = { settings: { plan: { $any: ['free', 'trial'] } } };
|
31
|
-
// Or with $any
|
32
|
-
const orWithAny = { 'settings.plan': { $any: ['free', 'paid'] } };
|
33
|
-
// Multiple columns implicit and
|
34
|
-
const multipleColumnsImplicitAnd = { 'settings.dark': true, 'settings.plan': 'free' };
|
35
|
-
// Explicit $all with multi-key filter list
|
36
|
-
const explicitAllWithMultiKeyFilterList = {
|
37
|
-
$all: { 'settings.dark': true, 'settings.plan': 'free' }
|
38
|
-
};
|
39
|
-
// Explicit $all with filter list
|
40
|
-
const explicitAllWithFilterList = {
|
41
|
-
$all: [{ 'settings.dark': true }, { 'settings.plan': 'free' }]
|
42
|
-
};
|
43
|
-
// Explicit $any with multi-key filter list
|
44
|
-
const explicitAnyWithMultiKeyFilterList = {
|
45
|
-
$all: { 'settings.dark': true, 'settings.plan': 'free' }
|
46
|
-
};
|
47
|
-
// Explicit $any with filter list
|
48
|
-
const explicitAnyWithFilterList = {
|
49
|
-
$any: [{ 'settings.dark': true }, { 'settings.plan': 'free' }]
|
50
|
-
};
|
51
|
-
// $any with multiple values
|
52
|
-
const anyWithMultipleValues = { number: { $any: [1, 2, 3] } };
|
53
|
-
// $none with multiple values
|
54
|
-
const noneWithMultipleValues = { number: { $none: [1, 2, 3] } };
|
55
|
-
// Exists filter
|
56
|
-
const existsFilter = { $exists: 'test' };
|
57
|
-
// Not exists filter
|
58
|
-
const notExistsFilter = { $notExists: 'test' };
|
59
|
-
// Exists with all
|
60
|
-
const existsWithAll = { $all: [{ $exists: 'settings' }, { $exists: 'name' }] };
|
61
|
-
// Nest any with not
|
62
|
-
const nestAnyWithNot = { $not: { $any: { 'settings.dark': true, 'settings.plan': 'free' } } };
|
63
|
-
// Mix $all and $any with extra keys
|
64
|
-
const mixAllAndAnyWithExtraKeys = {
|
65
|
-
$all: { $any: { 'settings.dark': false, 'settings.plan': 'free' }, name: 'r1' }
|
66
|
-
};
|
67
|
-
// Range query with less first
|
68
|
-
const rangeQueryWithLessFirst = { age: { $lt: 30, $ge: 20 } };
|
69
|
-
// Range query with greater first
|
70
|
-
const rangeQueryWithGreaterFirst = { age: { $ge: 20, $lt: 30 } };
|
71
|
-
// Ordered op
|
72
|
-
const orderedOp = { age: { $lt: 30 } };
|
73
|
-
// Simple includes
|
74
|
-
const simpleIncludes = { labels: { $includes: 'test' } };
|
75
|
-
// Simple includes with op
|
76
|
-
const simpleIncludesWithOp = { labels: { $includes: { $contains: 'test' } } };
|
77
|
-
// Simple includes multiple
|
78
|
-
const simpleIncludesMultiple = { labels: { $includes: ['a', 'b', 'c'] } };
|
79
|
-
// Simple includes multiple with op
|
80
|
-
const simpleIncludesMultipleWithOp = {
|
81
|
-
labels: { $includes: [{ $is: 'a' }, { $is: 'b' }, { $is: 'c' }] }
|
82
|
-
};
|
83
|
-
// Includes with many comparisons
|
84
|
-
const includesWithManyComparisons = {
|
85
|
-
labels: { $includes: { $all: [{ $contains: 'a' }, { $contains: 'b' }] } }
|
86
|
-
};
|
87
|
-
// Simple includes multiple op and value
|
88
|
-
const simpleIncludesMultipleOpAndValue = { labels: { $includes: [{ $contains: 'a' }, 'b'] } };
|
89
|
-
// Includes with mode and array of filters
|
90
|
-
const includesWithModeAndArrayOfFilters = {
|
91
|
-
labels: { $includesNone: [{ $contains: 'test' }, 'abc', { $endsWith: 'bad' }] }
|
92
|
-
};
|
93
|
-
// Includes with mix of any and all in predicate position
|
94
|
-
const includesWithMixOfAnyAndAllInPredicatePosition = {
|
95
|
-
labels: { $includes: { $any: { $all: [{ $startsWith: 'test' }, { $contains: 'x' }], $any: ['a', 'b'] } } }
|
96
|
-
};
|
97
|
-
// Simple $includesany
|
98
|
-
const simpleIncludesAny = { labels: { $includesAny: 'test' } };
|
99
|
-
// Simple $includesall
|
100
|
-
const simpleIncludesAll = { labels: { $includesAll: 'test' } };
|
101
|
-
// Simple $includesnone
|
102
|
-
const simpleIncludesNone = { labels: { $includesNone: 'test' } };
|
103
|
-
// Exists value must be string not int
|
104
|
-
// @ts-expect-error
|
105
|
-
const existsValueMustBeStringNotInt = { $exists: 42 };
|
106
|
-
// Exists value must be string not objct
|
107
|
-
// @ts-expect-error
|
108
|
-
const existsValueMustBeStringNotObject = { $exists: { field: 'settings.unknown' } };
|
109
|
-
// Filter by one column
|
110
|
-
const filterByOneColumn = { name: 'r1' };
|
111
|
-
// Filter with the $is operator
|
112
|
-
const filterWithTheIsOperator = { name: { $is: 'r1' } };
|
113
|
-
// Filter with dot notation
|
114
|
-
const filterWithDotNotation = { 'settings.plan': 'free' };
|
115
|
-
// Filter with nested object
|
116
|
-
const filterWithNestedObject = { 'settings.plan': { $is: 'free' } };
|
117
|
-
// Filter with $any operation
|
118
|
-
const filterWithAnyOperation = { 'settings.plan': { $any: ['free', 'paid'] } };
|
119
|
-
// Filter with and operations
|
120
|
-
const filterWithAndOperations = { 'settings.dark': true, 'settings.plan': 'free' };
|
121
|
-
// Filter with both and and any operations
|
122
|
-
const filterWithBothAndAndAnyOperations = {
|
123
|
-
$any: { 'settings.dark': true, 'settings.plan': 'free' }
|
124
|
-
};
|
125
|
-
// Filter with both and and any operations in array
|
126
|
-
const filterWithBothAndAndAnyOperationsInArray = { $any: [{ name: 'r1' }, { name: 'r2' }] };
|
127
|
-
// Filter with exists operation
|
128
|
-
const filterWithExistsOperation = { $exists: 'settings' };
|
129
|
-
// Filter with exists, and and any operations
|
130
|
-
const filterWithExistsAndAndAnyOperations = {
|
131
|
-
$all: [{ $exists: 'settings' }, { $exists: 'name' }]
|
132
|
-
};
|
133
|
-
// Filter with not exists operation
|
134
|
-
const filterWithNotExistsOperation = { $notExists: 'settings' };
|
135
|
-
// Filter with partial match
|
136
|
-
const filterWithPartialMatch = { name: { $contains: 'value' } };
|
137
|
-
// Filter with pattern operator
|
138
|
-
const filterWithPatternOperator = { name: { $pattern: 'value' } };
|
139
|
-
// Filter with $startsWith and $endsWith operators
|
140
|
-
const filterWithStartsWithAndEndsWithOperators = {
|
141
|
-
name: { $startsWith: 'value', $endsWith: 'value' }
|
142
|
-
};
|
143
|
-
// Filter with numeric ranges
|
144
|
-
const filterWithNumericRanges = { age: { $lt: 30, $ge: 20 } };
|
145
|
-
// Filter with negations
|
146
|
-
const filterWithNegations = { $not: { name: 'r1' } };
|
147
|
-
// Filter with complex negations
|
148
|
-
const filterWithComplexNegations = { $not: { $any: [{ name: 'r1' }, { name: 'r2' }] } };
|
149
|
-
// Filter with arrays complex negations
|
150
|
-
const filterWithArraysComplexNegations = {
|
151
|
-
labels: {
|
152
|
-
$includes: {
|
153
|
-
$all: [{ $contains: 'label' }, { $not: { $endsWith: '-debug' } }]
|
154
|
-
}
|
155
|
-
}
|
156
|
-
};
|
157
|
-
// Filters with $includesAll
|
158
|
-
const filtersWithIncludesAll = {
|
159
|
-
'settings.labels': {
|
160
|
-
$includesAll: [{ $contains: 'label' }]
|
161
|
-
}
|
162
|
-
};
|
163
|
-
// Filter with invalid property type
|
164
|
-
// @ts-expect-error
|
165
|
-
const filterWithInvalidPropertyType = { name: 42 };
|
166
|
-
// Filter with invalid dot notation property type
|
167
|
-
// @ts-expect-error
|
168
|
-
const filterWithInvalidNestedPropertyType = { 'settings.plan': 42 };
|
169
|
-
// Filter with invalid nested object property type
|
170
|
-
// @ts-expect-error
|
171
|
-
const filterWithInvalidNestedObjectPropertyType = { settings: { plan: 42 } };
|
172
|
-
// Filter with invalid property $is type
|
173
|
-
// @ts-expect-error
|
174
|
-
const filterWithInvalidOperator = { name: { $is: 42 } };
|
175
|
-
(0, vitest_1.test)('fake test', () => {
|
176
|
-
// This is a fake test to make sure that the type definitions in this file are working
|
177
|
-
});
|
package/dist/schema/index.d.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import { XataPlugin, XataPluginOptions } from '../plugins';
|
2
|
-
import { BaseData } from './record';
|
3
|
-
import { LinkDictionary, Repository } from './repository';
|
4
|
-
export * from './operators';
|
5
|
-
export * from './pagination';
|
6
|
-
export { Query } from './query';
|
7
|
-
export { isIdentifiable, isXataRecord } from './record';
|
8
|
-
export type { BaseData, EditableData, Identifiable, XataRecord } from './record';
|
9
|
-
export { Repository, RestRepository } from './repository';
|
10
|
-
export type { LinkDictionary } from './repository';
|
11
|
-
export * from './selection';
|
12
|
-
export declare type SchemaDefinition = {
|
13
|
-
table: string;
|
14
|
-
links?: LinkDictionary;
|
15
|
-
};
|
16
|
-
export declare type SchemaPluginResult<Schemas extends Record<string, BaseData>> = {
|
17
|
-
[Key in keyof Schemas]: Repository<Schemas[Key]>;
|
18
|
-
};
|
19
|
-
export declare class SchemaPlugin<Schemas extends Record<string, BaseData>> extends XataPlugin {
|
20
|
-
#private;
|
21
|
-
private links?;
|
22
|
-
constructor(links?: LinkDictionary | undefined);
|
23
|
-
build(options: XataPluginOptions): SchemaPluginResult<Schemas>;
|
24
|
-
}
|
package/dist/schema/index.js
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
17
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
18
|
-
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");
|
19
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
20
|
-
};
|
21
|
-
var _SchemaPlugin_tables;
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
23
|
-
exports.SchemaPlugin = exports.RestRepository = exports.Repository = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
|
24
|
-
const plugins_1 = require("../plugins");
|
25
|
-
const lang_1 = require("../util/lang");
|
26
|
-
const repository_1 = require("./repository");
|
27
|
-
__exportStar(require("./operators"), exports);
|
28
|
-
__exportStar(require("./pagination"), exports);
|
29
|
-
var query_1 = require("./query");
|
30
|
-
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
|
31
|
-
var record_1 = require("./record");
|
32
|
-
Object.defineProperty(exports, "isIdentifiable", { enumerable: true, get: function () { return record_1.isIdentifiable; } });
|
33
|
-
Object.defineProperty(exports, "isXataRecord", { enumerable: true, get: function () { return record_1.isXataRecord; } });
|
34
|
-
var repository_2 = require("./repository");
|
35
|
-
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_2.Repository; } });
|
36
|
-
Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_2.RestRepository; } });
|
37
|
-
__exportStar(require("./selection"), exports);
|
38
|
-
class SchemaPlugin extends plugins_1.XataPlugin {
|
39
|
-
constructor(links) {
|
40
|
-
super();
|
41
|
-
this.links = links;
|
42
|
-
_SchemaPlugin_tables.set(this, {});
|
43
|
-
}
|
44
|
-
build(options) {
|
45
|
-
const { getFetchProps } = options;
|
46
|
-
const links = this.links;
|
47
|
-
const db = new Proxy({}, {
|
48
|
-
get: (_target, table) => {
|
49
|
-
if (!(0, lang_1.isString)(table))
|
50
|
-
throw new Error('Invalid table name');
|
51
|
-
if (!__classPrivateFieldGet(this, _SchemaPlugin_tables, "f")[table])
|
52
|
-
__classPrivateFieldGet(this, _SchemaPlugin_tables, "f")[table] = new repository_1.RestRepository({ db, getFetchProps, table, links });
|
53
|
-
return __classPrivateFieldGet(this, _SchemaPlugin_tables, "f")[table];
|
54
|
-
}
|
55
|
-
});
|
56
|
-
return db;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
exports.SchemaPlugin = SchemaPlugin;
|
60
|
-
_SchemaPlugin_tables = new WeakMap();
|
@@ -1,74 +0,0 @@
|
|
1
|
-
import { ArrayFilter, ComparableType, ComparableTypeFilter, ExistanceFilter, PropertyFilter, StringTypeFilter } from './filters';
|
2
|
-
import { SelectableColumn } from './selection';
|
3
|
-
/**
|
4
|
-
* Operator to restrict results to only values that are greater than the given value.
|
5
|
-
*/
|
6
|
-
export declare const gt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
7
|
-
/**
|
8
|
-
* Operator to restrict results to only values that are greater than or equal to the given value.
|
9
|
-
*/
|
10
|
-
export declare const ge: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
11
|
-
/**
|
12
|
-
* Operator to restrict results to only values that are greater than or equal to the given value.
|
13
|
-
*/
|
14
|
-
export declare const gte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
15
|
-
/**
|
16
|
-
* Operator to restrict results to only values that are lower than the given value.
|
17
|
-
*/
|
18
|
-
export declare const lt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
19
|
-
/**
|
20
|
-
* Operator to restrict results to only values that are lower than or equal to the given value.
|
21
|
-
*/
|
22
|
-
export declare const lte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
23
|
-
/**
|
24
|
-
* Operator to restrict results to only values that are lower than or equal to the given value.
|
25
|
-
*/
|
26
|
-
export declare const le: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
27
|
-
/**
|
28
|
-
* Operator to restrict results to only values that are not null.
|
29
|
-
*/
|
30
|
-
export declare const exists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
|
31
|
-
/**
|
32
|
-
* Operator to restrict results to only values that are null.
|
33
|
-
*/
|
34
|
-
export declare const notExists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
|
35
|
-
/**
|
36
|
-
* Operator to restrict results to only values that start with the given prefix.
|
37
|
-
*/
|
38
|
-
export declare const startsWith: (value: string) => StringTypeFilter;
|
39
|
-
/**
|
40
|
-
* Operator to restrict results to only values that end with the given suffix.
|
41
|
-
*/
|
42
|
-
export declare const endsWith: (value: string) => StringTypeFilter;
|
43
|
-
/**
|
44
|
-
* Operator to restrict results to only values that match the given pattern.
|
45
|
-
*/
|
46
|
-
export declare const pattern: (value: string) => StringTypeFilter;
|
47
|
-
/**
|
48
|
-
* Operator to restrict results to only values that are equal to the given value.
|
49
|
-
*/
|
50
|
-
export declare const is: <T>(value: T) => PropertyFilter<T>;
|
51
|
-
/**
|
52
|
-
* Operator to restrict results to only values that are not equal to the given value.
|
53
|
-
*/
|
54
|
-
export declare const isNot: <T>(value: T) => PropertyFilter<T>;
|
55
|
-
/**
|
56
|
-
* Operator to restrict results to only values that contain the given value.
|
57
|
-
*/
|
58
|
-
export declare const contains: (value: string) => StringTypeFilter;
|
59
|
-
/**
|
60
|
-
* Operator to restrict results if some array items match the predicate.
|
61
|
-
*/
|
62
|
-
export declare const includes: <T>(value: T) => ArrayFilter<T>;
|
63
|
-
/**
|
64
|
-
* Operator to restrict results if all array items match the predicate.
|
65
|
-
*/
|
66
|
-
export declare const includesAll: <T>(value: T) => ArrayFilter<T>;
|
67
|
-
/**
|
68
|
-
* Operator to restrict results if none array items match the predicate.
|
69
|
-
*/
|
70
|
-
export declare const includesNone: <T>(value: T) => ArrayFilter<T>;
|
71
|
-
/**
|
72
|
-
* Operator to restrict results if some array items match the predicate.
|
73
|
-
*/
|
74
|
-
export declare const includesAny: <T>(value: T) => ArrayFilter<T>;
|