@xata.io/client 0.0.0-beta.f2b2fa6 → 0.0.0-beta.f4457bf
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 +71 -0
- package/dist/api/client.d.ts +4 -2
- package/dist/api/client.js +19 -10
- package/dist/api/components.d.ts +58 -37
- package/dist/api/components.js +48 -38
- package/dist/api/fetcher.d.ts +15 -0
- package/dist/api/fetcher.js +23 -22
- package/dist/api/parameters.d.ts +1 -0
- package/dist/api/providers.js +3 -2
- package/dist/api/responses.d.ts +6 -0
- package/dist/api/schemas.d.ts +1 -1
- package/dist/index.d.ts +1 -59
- package/dist/index.js +2 -258
- package/dist/schema/filters.d.ts +93 -17
- package/dist/schema/filters.js +0 -22
- package/dist/schema/filters.spec.d.ts +1 -0
- package/dist/schema/filters.spec.js +175 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.js +12 -0
- package/dist/schema/operators.d.ts +74 -21
- package/dist/schema/operators.js +59 -6
- package/dist/schema/pagination.d.ts +56 -14
- package/dist/schema/pagination.js +37 -2
- package/dist/schema/query.d.ts +110 -37
- package/dist/schema/query.js +87 -35
- package/dist/schema/record.d.ts +66 -0
- package/dist/schema/record.js +13 -0
- package/dist/schema/repository.d.ts +148 -0
- package/dist/schema/repository.js +376 -0
- package/dist/schema/selection.d.ts +24 -13
- package/dist/schema/selection.spec.d.ts +1 -0
- package/dist/schema/selection.spec.js +203 -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 +9 -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 +3 -0
- package/dist/util/lang.js +13 -1
- package/dist/util/types.d.ts +22 -1
- package/package.json +5 -2
- package/tsconfig.json +21 -0
package/dist/api/providers.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getHostUrl = void 0;
|
4
|
+
const lang_1 = require("../util/lang");
|
4
5
|
function getHostUrl(provider, type) {
|
5
6
|
if (isValidAlias(provider)) {
|
6
7
|
return providers[provider][type];
|
@@ -22,8 +23,8 @@ const providers = {
|
|
22
23
|
}
|
23
24
|
};
|
24
25
|
function isValidAlias(alias) {
|
25
|
-
return
|
26
|
+
return (0, lang_1.isString)(alias) && Object.keys(providers).includes(alias);
|
26
27
|
}
|
27
28
|
function isValidBuilder(builder) {
|
28
|
-
return
|
29
|
+
return (0, lang_1.isObject)(builder) && (0, lang_1.isString)(builder.main) && (0, lang_1.isString)(builder.workspaces);
|
29
30
|
}
|
package/dist/api/responses.d.ts
CHANGED
@@ -19,6 +19,12 @@ export declare type AuthError = {
|
|
19
19
|
id?: string;
|
20
20
|
message: string;
|
21
21
|
};
|
22
|
+
export declare type BulkError = {
|
23
|
+
errors: {
|
24
|
+
message?: string;
|
25
|
+
status?: number;
|
26
|
+
}[];
|
27
|
+
};
|
22
28
|
export declare type BranchMigrationPlan = {
|
23
29
|
version: number;
|
24
30
|
migration: Schemas.BranchMigration;
|
package/dist/api/schemas.d.ts
CHANGED
@@ -130,7 +130,7 @@ export declare type Table = {
|
|
130
130
|
*/
|
131
131
|
export declare type Column = {
|
132
132
|
name: string;
|
133
|
-
type: 'bool' | 'int' | 'string' | 'text' | 'email' | 'multiple' | 'link' | 'object';
|
133
|
+
type: 'bool' | 'int' | 'float' | 'string' | 'text' | 'email' | 'multiple' | 'link' | 'object';
|
134
134
|
link?: {
|
135
135
|
table: string;
|
136
136
|
};
|
package/dist/index.d.ts
CHANGED
@@ -1,65 +1,7 @@
|
|
1
|
-
import { FetchImpl } from './api/fetcher';
|
2
|
-
import { Page } from './schema/pagination';
|
3
|
-
import { Query, QueryOptions } from './schema/query';
|
4
|
-
import { Selectable, SelectableColumn, Select } from './schema/selection';
|
5
|
-
export interface XataRecord {
|
6
|
-
id: string;
|
7
|
-
xata: {
|
8
|
-
version: number;
|
9
|
-
};
|
10
|
-
read(): Promise<this>;
|
11
|
-
update(data: Partial<Selectable<this>>): Promise<this>;
|
12
|
-
delete(): Promise<void>;
|
13
|
-
}
|
14
|
-
export declare abstract class Repository<T extends XataRecord> extends Query<T> {
|
15
|
-
abstract create(object: Selectable<T>): Promise<T>;
|
16
|
-
abstract createMany(objects: Selectable<T>[]): Promise<T[]>;
|
17
|
-
abstract read(id: string): Promise<T | null>;
|
18
|
-
abstract update(id: string, object: Partial<Selectable<T>>): Promise<T>;
|
19
|
-
abstract upsert(id: string, object: Selectable<T>): Promise<T>;
|
20
|
-
abstract delete(id: string): void;
|
21
|
-
abstract query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
|
22
|
-
}
|
23
|
-
export declare class RestRepository<T extends XataRecord> extends Repository<T> {
|
24
|
-
#private;
|
25
|
-
constructor(client: BaseClient<any>, table: string);
|
26
|
-
create(object: Selectable<T>): Promise<T>;
|
27
|
-
createMany(objects: T[]): Promise<T[]>;
|
28
|
-
read(recordId: string): Promise<T | null>;
|
29
|
-
update(recordId: string, object: Partial<Selectable<T>>): Promise<T>;
|
30
|
-
upsert(recordId: string, object: Selectable<T>): Promise<T>;
|
31
|
-
delete(recordId: string): Promise<void>;
|
32
|
-
query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options: Options): Promise<Page<T, typeof options['columns'] extends SelectableColumn<T>[] ? Select<T, typeof options['columns'][number]> : R>>;
|
33
|
-
}
|
34
|
-
interface RepositoryFactory {
|
35
|
-
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
36
|
-
}
|
37
|
-
export declare class RestRespositoryFactory implements RepositoryFactory {
|
38
|
-
createRepository<T extends XataRecord>(client: BaseClient<any>, table: string): Repository<T>;
|
39
|
-
}
|
40
|
-
declare type BranchStrategyValue = string | undefined | null;
|
41
|
-
declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
|
42
|
-
declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
|
43
|
-
declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
|
44
|
-
export declare type XataClientOptions = {
|
45
|
-
fetch?: FetchImpl;
|
46
|
-
databaseURL?: string;
|
47
|
-
branch: BranchStrategyOption;
|
48
|
-
apiKey: string;
|
49
|
-
repositoryFactory?: RepositoryFactory;
|
50
|
-
};
|
51
|
-
export declare class BaseClient<D extends Record<string, Repository<any>>> {
|
52
|
-
#private;
|
53
|
-
options: XataClientOptions;
|
54
|
-
db: D;
|
55
|
-
constructor(options: XataClientOptions, links: Links);
|
56
|
-
initObject<T>(table: string, object: object): T;
|
57
|
-
getBranch(): Promise<string>;
|
58
|
-
}
|
59
1
|
export declare class XataError extends Error {
|
60
2
|
readonly status: number;
|
61
3
|
constructor(message: string, status: number);
|
62
4
|
}
|
63
|
-
export declare type Links = Record<string, Array<string[]>>;
|
64
5
|
export * from './api';
|
65
6
|
export * from './schema';
|
7
|
+
export * from './util/config';
|
package/dist/index.js
CHANGED
@@ -13,253 +13,8 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
23
|
-
});
|
24
|
-
};
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
28
|
-
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");
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
30
|
-
};
|
31
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
32
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
33
|
-
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");
|
34
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
35
|
-
};
|
36
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
37
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
38
|
-
var m = o[Symbol.asyncIterator], i;
|
39
|
-
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);
|
40
|
-
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); }); }; }
|
41
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
42
|
-
};
|
43
|
-
var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_getFetchProps, _BaseClient_links, _BaseClient_branch;
|
44
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
45
|
-
exports.XataError =
|
46
|
-
const api_1 = require("./api");
|
47
|
-
const filters_1 = require("./schema/filters");
|
48
|
-
const pagination_1 = require("./schema/pagination");
|
49
|
-
const query_1 = require("./schema/query");
|
50
|
-
class Repository extends query_1.Query {
|
51
|
-
}
|
52
|
-
exports.Repository = Repository;
|
53
|
-
class RestRepository extends Repository {
|
54
|
-
constructor(client, table) {
|
55
|
-
super(null, table, {});
|
56
|
-
_RestRepository_instances.add(this);
|
57
|
-
_RestRepository_client.set(this, void 0);
|
58
|
-
_RestRepository_fetch.set(this, void 0);
|
59
|
-
_RestRepository_table.set(this, void 0);
|
60
|
-
__classPrivateFieldSet(this, _RestRepository_client, client, "f");
|
61
|
-
__classPrivateFieldSet(this, _RestRepository_table, table, "f");
|
62
|
-
// TODO: Remove when integrating with API client
|
63
|
-
const fetchImpl = typeof fetch !== 'undefined' ? fetch : __classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch;
|
64
|
-
if (!fetchImpl) {
|
65
|
-
throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
|
66
|
-
}
|
67
|
-
__classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
|
68
|
-
}
|
69
|
-
create(object) {
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
71
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
72
|
-
const record = transformObjectLinks(object);
|
73
|
-
const response = object.id
|
74
|
-
? yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
|
75
|
-
workspace: '{workspaceId}',
|
76
|
-
dbBranchName: '{dbBranch}',
|
77
|
-
tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
|
78
|
-
recordId: object.id
|
79
|
-
}, body: record }, fetchProps))
|
80
|
-
: yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
|
81
|
-
workspace: '{workspaceId}',
|
82
|
-
dbBranchName: '{dbBranch}',
|
83
|
-
tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
|
84
|
-
}, body: record }, fetchProps));
|
85
|
-
const finalObject = yield this.read(response.id);
|
86
|
-
if (!finalObject) {
|
87
|
-
throw new Error('The server failed to save the record');
|
88
|
-
}
|
89
|
-
return finalObject;
|
90
|
-
});
|
91
|
-
}
|
92
|
-
createMany(objects) {
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
94
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
95
|
-
const records = objects.map((object) => transformObjectLinks(object));
|
96
|
-
const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
|
97
|
-
// TODO: Use filer.$any() to get all the records
|
98
|
-
const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
|
99
|
-
if (finalObjects.some((object) => !object)) {
|
100
|
-
throw new Error('The server failed to save the record');
|
101
|
-
}
|
102
|
-
return finalObjects;
|
103
|
-
});
|
104
|
-
}
|
105
|
-
read(recordId) {
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
107
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
108
|
-
const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
109
|
-
return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
|
110
|
-
});
|
111
|
-
}
|
112
|
-
update(recordId, object) {
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
114
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
115
|
-
const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
|
116
|
-
const item = yield this.read(response.id);
|
117
|
-
if (!item)
|
118
|
-
throw new Error('The server failed to save the record');
|
119
|
-
return item;
|
120
|
-
});
|
121
|
-
}
|
122
|
-
upsert(recordId, object) {
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
124
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
125
|
-
const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
|
126
|
-
const item = yield this.read(response.id);
|
127
|
-
if (!item)
|
128
|
-
throw new Error('The server failed to save the record');
|
129
|
-
return item;
|
130
|
-
});
|
131
|
-
}
|
132
|
-
delete(recordId) {
|
133
|
-
return __awaiter(this, void 0, void 0, function* () {
|
134
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
135
|
-
yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
|
136
|
-
});
|
137
|
-
}
|
138
|
-
query(query, options) {
|
139
|
-
var _a, _b, _c;
|
140
|
-
return __awaiter(this, void 0, void 0, function* () {
|
141
|
-
const data = query.getQueryOptions();
|
142
|
-
const body = {
|
143
|
-
filter: Object.values(data.filter).some(Boolean) ? data.filter : undefined,
|
144
|
-
sort: (_a = (0, filters_1.buildSortFilter)(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : data.sort,
|
145
|
-
page: (_b = options === null || options === void 0 ? void 0 : options.page) !== null && _b !== void 0 ? _b : data.page,
|
146
|
-
columns: (_c = options === null || options === void 0 ? void 0 : options.columns) !== null && _c !== void 0 ? _c : data.columns
|
147
|
-
};
|
148
|
-
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
|
149
|
-
const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
|
150
|
-
const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), record));
|
151
|
-
// TODO: We should properly type this any
|
152
|
-
return new pagination_1.Page(query, meta, records);
|
153
|
-
});
|
154
|
-
}
|
155
|
-
}
|
156
|
-
exports.RestRepository = RestRepository;
|
157
|
-
_RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_getFetchProps = function _RestRepository_getFetchProps() {
|
158
|
-
return __awaiter(this, void 0, void 0, function* () {
|
159
|
-
const branch = yield __classPrivateFieldGet(this, _RestRepository_client, "f").getBranch();
|
160
|
-
return {
|
161
|
-
fetchImpl: __classPrivateFieldGet(this, _RestRepository_fetch, "f"),
|
162
|
-
apiKey: __classPrivateFieldGet(this, _RestRepository_client, "f").options.apiKey,
|
163
|
-
apiUrl: '',
|
164
|
-
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
165
|
-
workspacesApiUrl: (path, params) => {
|
166
|
-
var _a, _b;
|
167
|
-
const baseUrl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.databaseURL) !== null && _a !== void 0 ? _a : '';
|
168
|
-
const hasBranch = (_b = params.dbBranchName) !== null && _b !== void 0 ? _b : params.branch;
|
169
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branch}` : '');
|
170
|
-
return baseUrl + newPath;
|
171
|
-
}
|
172
|
-
};
|
173
|
-
});
|
174
|
-
};
|
175
|
-
class RestRespositoryFactory {
|
176
|
-
createRepository(client, table) {
|
177
|
-
return new RestRepository(client, table);
|
178
|
-
}
|
179
|
-
}
|
180
|
-
exports.RestRespositoryFactory = RestRespositoryFactory;
|
181
|
-
class BaseClient {
|
182
|
-
constructor(options, links) {
|
183
|
-
_BaseClient_links.set(this, void 0);
|
184
|
-
_BaseClient_branch.set(this, void 0);
|
185
|
-
if (!options.databaseURL || !options.apiKey || !options.branch) {
|
186
|
-
throw new Error('Options databaseURL, apiKey and branch are required');
|
187
|
-
}
|
188
|
-
this.options = options;
|
189
|
-
__classPrivateFieldSet(this, _BaseClient_links, links, "f");
|
190
|
-
}
|
191
|
-
initObject(table, object) {
|
192
|
-
const o = {};
|
193
|
-
Object.assign(o, object);
|
194
|
-
const tableLinks = __classPrivateFieldGet(this, _BaseClient_links, "f")[table] || [];
|
195
|
-
for (const link of tableLinks) {
|
196
|
-
const [field, linkTable] = link;
|
197
|
-
const value = o[field];
|
198
|
-
if (value && typeof value === 'object') {
|
199
|
-
const { id } = value;
|
200
|
-
if (Object.keys(value).find((col) => col === 'id')) {
|
201
|
-
o[field] = this.initObject(linkTable, value);
|
202
|
-
}
|
203
|
-
else if (id) {
|
204
|
-
o[field] = {
|
205
|
-
id,
|
206
|
-
get: () => {
|
207
|
-
this.db[linkTable].read(id);
|
208
|
-
}
|
209
|
-
};
|
210
|
-
}
|
211
|
-
}
|
212
|
-
}
|
213
|
-
const db = this.db;
|
214
|
-
o.read = function () {
|
215
|
-
return db[table].read(o['id']);
|
216
|
-
};
|
217
|
-
o.update = function (data) {
|
218
|
-
return db[table].update(o['id'], data);
|
219
|
-
};
|
220
|
-
o.delete = function () {
|
221
|
-
return db[table].delete(o['id']);
|
222
|
-
};
|
223
|
-
for (const prop of ['read', 'update', 'delete']) {
|
224
|
-
Object.defineProperty(o, prop, { enumerable: false });
|
225
|
-
}
|
226
|
-
// TODO: links and rev links
|
227
|
-
Object.freeze(o);
|
228
|
-
return o;
|
229
|
-
}
|
230
|
-
getBranch() {
|
231
|
-
var e_1, _a;
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
233
|
-
if (__classPrivateFieldGet(this, _BaseClient_branch, "f"))
|
234
|
-
return __classPrivateFieldGet(this, _BaseClient_branch, "f");
|
235
|
-
const { branch: param } = this.options;
|
236
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
237
|
-
const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
|
238
|
-
return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
|
239
|
-
});
|
240
|
-
try {
|
241
|
-
for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
|
242
|
-
const strategy = strategies_1_1.value;
|
243
|
-
const branch = yield evaluateBranch(strategy);
|
244
|
-
if (branch) {
|
245
|
-
__classPrivateFieldSet(this, _BaseClient_branch, branch, "f");
|
246
|
-
return branch;
|
247
|
-
}
|
248
|
-
}
|
249
|
-
}
|
250
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
251
|
-
finally {
|
252
|
-
try {
|
253
|
-
if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
|
254
|
-
}
|
255
|
-
finally { if (e_1) throw e_1.error; }
|
256
|
-
}
|
257
|
-
throw new Error('Unable to resolve branch value');
|
258
|
-
});
|
259
|
-
}
|
260
|
-
}
|
261
|
-
exports.BaseClient = BaseClient;
|
262
|
-
_BaseClient_links = new WeakMap(), _BaseClient_branch = new WeakMap();
|
17
|
+
exports.XataError = void 0;
|
263
18
|
class XataError extends Error {
|
264
19
|
constructor(message, status) {
|
265
20
|
super(message);
|
@@ -267,17 +22,6 @@ class XataError extends Error {
|
|
267
22
|
}
|
268
23
|
}
|
269
24
|
exports.XataError = XataError;
|
270
|
-
const isBranchStrategyBuilder = (strategy) => {
|
271
|
-
return typeof strategy === 'function';
|
272
|
-
};
|
273
|
-
// TODO: We can find a better implementation for links
|
274
|
-
const transformObjectLinks = (object) => {
|
275
|
-
return Object.entries(object).reduce((acc, [key, value]) => {
|
276
|
-
if (value && typeof value === 'object' && typeof value.id === 'string') {
|
277
|
-
return Object.assign(Object.assign({}, acc), { [key]: value.id });
|
278
|
-
}
|
279
|
-
return Object.assign(Object.assign({}, acc), { [key]: value });
|
280
|
-
}, {});
|
281
|
-
};
|
282
25
|
__exportStar(require("./api"), exports);
|
283
26
|
__exportStar(require("./schema"), exports);
|
27
|
+
__exportStar(require("./util/config"), exports);
|
package/dist/schema/filters.d.ts
CHANGED
@@ -1,20 +1,96 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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>>;
|
5
23
|
};
|
6
|
-
export declare type
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
[
|
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
|
+
}>;
|
14
37
|
};
|
15
|
-
export declare type
|
16
|
-
[key in
|
17
|
-
} : Constraint<T>;
|
18
|
-
export declare type FilterConstraints<T> = {
|
19
|
-
[key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
|
38
|
+
export declare type StringTypeFilter = {
|
39
|
+
[key in '$contains' | '$pattern' | '$startsWith' | '$endsWith']?: string;
|
20
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
CHANGED
@@ -1,24 +1,2 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.buildSortFilter = exports.isSortFilterObject = void 0;
|
4
|
-
function isSortFilterObject(filter) {
|
5
|
-
return typeof filter === 'object' && filter.column !== undefined;
|
6
|
-
}
|
7
|
-
exports.isSortFilterObject = isSortFilterObject;
|
8
|
-
function buildSortFilter(filter) {
|
9
|
-
if (!filter)
|
10
|
-
return undefined;
|
11
|
-
const filters = Array.isArray(filter) ? filter : [filter];
|
12
|
-
return filters.reduce((acc, item) => {
|
13
|
-
if (typeof item === 'string') {
|
14
|
-
return Object.assign(Object.assign({}, acc), { [item]: 'asc' });
|
15
|
-
}
|
16
|
-
else if (isSortFilterObject(item)) {
|
17
|
-
return Object.assign(Object.assign({}, acc), { [item.column]: item.direction });
|
18
|
-
}
|
19
|
-
else {
|
20
|
-
return acc;
|
21
|
-
}
|
22
|
-
}, {});
|
23
|
-
}
|
24
|
-
exports.buildSortFilter = buildSortFilter;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|