@xata.io/client 0.8.0 → 0.8.1
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 +1 -1
- package/CHANGELOG.md +9 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.js +20 -1
- package/dist/client.d.ts +12 -24
- package/dist/client.js +14 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugins.d.ts +7 -0
- package/dist/plugins.js +6 -0
- package/dist/schema/index.d.ts +7 -5
- package/dist/schema/index.js +8 -7
- package/dist/schema/repository.d.ts +4 -3
- package/dist/schema/repository.js +4 -5
- package/dist/schema/sorting.d.ts +9 -4
- package/dist/schema/sorting.js +9 -2
- package/dist/search/index.d.ts +25 -11
- package/dist/search/index.js +40 -15
- package/package.json +2 -2
- package/dist/namespace.d.ts +0 -7
- package/dist/namespace.js +0 -6
package/.eslintrc.cjs
CHANGED
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.8.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 5110261: Fix execution from the browser
|
8
|
+
- aa3d7e7: Allow sending sort as in the API
|
9
|
+
- 0047193: Add new plugin system for the SDK
|
10
|
+
- 43856a5: Add discriminated union search
|
11
|
+
|
3
12
|
## 0.8.0
|
4
13
|
|
5
14
|
### Patch Changes
|
package/dist/api/index.d.ts
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
import { XataPlugin, XataPluginOptions } from '../plugins';
|
2
|
+
import { XataApiClient } from './client';
|
1
3
|
import { operationsByTag } from './components';
|
2
4
|
import type * as Responses from './responses';
|
3
5
|
import type * as Schemas from './schemas';
|
4
6
|
export * from './client';
|
5
7
|
export * from './components';
|
8
|
+
export type { FetcherExtraProps, FetchImpl } from './fetcher';
|
6
9
|
export { operationsByTag as Operations };
|
7
10
|
export type { Responses, Schemas };
|
11
|
+
export declare class XataApiPlugin implements XataPlugin {
|
12
|
+
build(options: XataPluginOptions): Promise<XataApiClient>;
|
13
|
+
}
|
package/dist/api/index.js
CHANGED
@@ -13,9 +13,28 @@ 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
|
+
};
|
16
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.Operations = void 0;
|
26
|
+
exports.XataApiPlugin = exports.Operations = void 0;
|
27
|
+
const client_1 = require("./client");
|
18
28
|
const components_1 = require("./components");
|
19
29
|
Object.defineProperty(exports, "Operations", { enumerable: true, get: function () { return components_1.operationsByTag; } });
|
20
30
|
__exportStar(require("./client"), exports);
|
21
31
|
__exportStar(require("./components"), exports);
|
32
|
+
class XataApiPlugin {
|
33
|
+
build(options) {
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
35
|
+
const { fetchImpl, apiKey } = yield options.getFetchProps();
|
36
|
+
return new client_1.XataApiClient({ fetch: fetchImpl, apiKey });
|
37
|
+
});
|
38
|
+
}
|
39
|
+
}
|
40
|
+
exports.XataApiPlugin = XataApiPlugin;
|
package/dist/client.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { FetchImpl } from './api/fetcher';
|
2
|
-
import {
|
3
|
-
import {
|
2
|
+
import { XataPlugin } from './plugins';
|
3
|
+
import { SchemaPlugin } from './schema';
|
4
4
|
import { BaseData } from './schema/record';
|
5
5
|
import { LinkDictionary } from './schema/repository';
|
6
|
-
import {
|
6
|
+
import { SearchPlugin } from './search';
|
7
7
|
import { BranchStrategyOption } from './util/branches';
|
8
8
|
import { StringKeys } from './util/types';
|
9
9
|
export declare type BaseClientOptions = {
|
@@ -12,28 +12,16 @@ export declare type BaseClientOptions = {
|
|
12
12
|
databaseURL?: string;
|
13
13
|
branch?: BranchStrategyOption;
|
14
14
|
};
|
15
|
-
export declare const
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}>(external?: ExternalNamespaces | undefined) => WrapperConstructor<Schemas, Namespaces, ExternalNamespaces>;
|
23
|
-
export interface WrapperConstructor<Schemas extends Record<string, BaseData> = Record<string, any>, Namespaces extends Record<string, Namespace> = {
|
24
|
-
db: SchemaNamespace<Schemas>;
|
25
|
-
search: SearchNamespace<Schemas>;
|
26
|
-
}, ExternalNamespaces extends Record<string, Namespace> = Record<string, Namespace>> {
|
27
|
-
new (options?: Partial<BaseClientOptions>, links?: LinkDictionary): {
|
28
|
-
[Key in StringKeys<Namespaces>]: ReturnType<Namespaces[Key]['build']>;
|
29
|
-
} & {
|
30
|
-
[Key in StringKeys<NonNullable<ExternalNamespaces>>]: ReturnType<NonNullable<ExternalNamespaces>[Key]['build']>;
|
15
|
+
export declare const buildClient: <Plugins extends Record<string, XataPlugin> = {}>(plugins?: Plugins | undefined) => ClientConstructor<Plugins>;
|
16
|
+
export interface ClientConstructor<Plugins extends Record<string, XataPlugin>> {
|
17
|
+
new <Schemas extends Record<string, BaseData>>(options?: Partial<BaseClientOptions>, links?: LinkDictionary): Omit<{
|
18
|
+
db: Awaited<ReturnType<SchemaPlugin<Schemas>['build']>>;
|
19
|
+
search: Awaited<ReturnType<SearchPlugin<Schemas>['build']>>;
|
20
|
+
}, keyof Plugins> & {
|
21
|
+
[Key in StringKeys<NonNullable<Plugins>>]: Awaited<ReturnType<NonNullable<Plugins>[Key]['build']>>;
|
31
22
|
};
|
32
23
|
}
|
33
|
-
declare const BaseClient_base:
|
34
|
-
|
35
|
-
search: SearchNamespace<Record<string, any>>;
|
36
|
-
}, {}>;
|
37
|
-
export declare class BaseClient extends BaseClient_base {
|
24
|
+
declare const BaseClient_base: ClientConstructor<{}>;
|
25
|
+
export declare class BaseClient extends BaseClient_base<Record<string, any>> {
|
38
26
|
}
|
39
27
|
export {};
|
package/dist/client.js
CHANGED
@@ -27,27 +27,34 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
27
27
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
28
28
|
};
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
30
|
-
exports.BaseClient = exports.buildClient =
|
30
|
+
exports.BaseClient = exports.buildClient = void 0;
|
31
31
|
const schema_1 = require("./schema");
|
32
32
|
const search_1 = require("./search");
|
33
33
|
const branches_1 = require("./util/branches");
|
34
34
|
const config_1 = require("./util/config");
|
35
35
|
const fetch_1 = require("./util/fetch");
|
36
|
-
const
|
37
|
-
exports.buildClientWithNamespaces = buildClientWithNamespaces;
|
38
|
-
const buildClient = (external) => {
|
36
|
+
const buildClient = (plugins) => {
|
39
37
|
var _instances, _branch, _parseOptions, _getFetchProps, _evaluateBranch, _a;
|
40
38
|
return _a = class {
|
41
39
|
constructor(options = {}, links) {
|
42
40
|
_instances.add(this);
|
43
41
|
_branch.set(this, void 0);
|
44
42
|
const safeOptions = __classPrivateFieldGet(this, _instances, "m", _parseOptions).call(this, options);
|
45
|
-
const namespaces = Object.assign({ db: new schema_1.
|
43
|
+
const namespaces = Object.assign({ db: new schema_1.SchemaPlugin(links), search: new search_1.SearchPlugin() }, plugins);
|
46
44
|
for (const [key, namespace] of Object.entries(namespaces)) {
|
47
45
|
if (!namespace)
|
48
46
|
continue;
|
49
|
-
|
50
|
-
|
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
|
+
}
|
51
58
|
}
|
52
59
|
}
|
53
60
|
},
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -23,6 +23,7 @@ class XataError extends Error {
|
|
23
23
|
}
|
24
24
|
exports.XataError = XataError;
|
25
25
|
__exportStar(require("./api"), exports);
|
26
|
+
__exportStar(require("./plugins"), exports);
|
26
27
|
__exportStar(require("./client"), exports);
|
27
28
|
__exportStar(require("./schema"), exports);
|
28
29
|
__exportStar(require("./search"), exports);
|
@@ -0,0 +1,7 @@
|
|
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
ADDED
package/dist/schema/index.d.ts
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
import {
|
1
|
+
import { XataPlugin, XataPluginOptions } from '../plugins';
|
2
2
|
import { BaseData } from './record';
|
3
3
|
import { LinkDictionary, Repository } from './repository';
|
4
4
|
export * from './operators';
|
5
5
|
export * from './pagination';
|
6
6
|
export { Query } from './query';
|
7
7
|
export { isIdentifiable, isXataRecord } from './record';
|
8
|
-
export type { Identifiable, XataRecord } from './record';
|
8
|
+
export type { BaseData, EditableData, Identifiable, XataRecord } from './record';
|
9
9
|
export { Repository, RestRepository } from './repository';
|
10
|
+
export type { LinkDictionary } from './repository';
|
11
|
+
export * from './selection';
|
10
12
|
export declare type SchemaDefinition = {
|
11
13
|
table: string;
|
12
14
|
links?: LinkDictionary;
|
13
15
|
};
|
14
|
-
export declare type
|
16
|
+
export declare type SchemaPluginResult<Schemas extends Record<string, BaseData>> = {
|
15
17
|
[Key in keyof Schemas]: Repository<Schemas[Key]>;
|
16
18
|
};
|
17
|
-
export declare class
|
19
|
+
export declare class SchemaPlugin<Schemas extends Record<string, BaseData>> extends XataPlugin {
|
18
20
|
private links?;
|
19
21
|
constructor(links?: LinkDictionary | undefined);
|
20
|
-
build(options:
|
22
|
+
build(options: XataPluginOptions): SchemaPluginResult<Schemas>;
|
21
23
|
}
|
package/dist/schema/index.js
CHANGED
@@ -14,8 +14,8 @@ 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
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.
|
18
|
-
const
|
17
|
+
exports.SchemaPlugin = exports.RestRepository = exports.Repository = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
|
18
|
+
const plugins_1 = require("../plugins");
|
19
19
|
const lang_1 = require("../util/lang");
|
20
20
|
const repository_1 = require("./repository");
|
21
21
|
__exportStar(require("./operators"), exports);
|
@@ -28,7 +28,8 @@ Object.defineProperty(exports, "isXataRecord", { enumerable: true, get: function
|
|
28
28
|
var repository_2 = require("./repository");
|
29
29
|
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_2.Repository; } });
|
30
30
|
Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_2.RestRepository; } });
|
31
|
-
|
31
|
+
__exportStar(require("./selection"), exports);
|
32
|
+
class SchemaPlugin extends plugins_1.XataPlugin {
|
32
33
|
constructor(links) {
|
33
34
|
super();
|
34
35
|
this.links = links;
|
@@ -36,14 +37,14 @@ class SchemaNamespace extends namespace_1.Namespace {
|
|
36
37
|
build(options) {
|
37
38
|
const { getFetchProps } = options;
|
38
39
|
const links = this.links;
|
39
|
-
const
|
40
|
+
const db = new Proxy({}, {
|
40
41
|
get: (_target, table) => {
|
41
42
|
if (!(0, lang_1.isString)(table))
|
42
43
|
throw new Error('Invalid table name');
|
43
|
-
return new repository_1.RestRepository({
|
44
|
+
return new repository_1.RestRepository({ db, getFetchProps, table, links });
|
44
45
|
}
|
45
46
|
});
|
46
|
-
return
|
47
|
+
return db;
|
47
48
|
}
|
48
49
|
}
|
49
|
-
exports.
|
50
|
+
exports.SchemaPlugin = SchemaPlugin;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { SchemaPluginResult } from '.';
|
2
2
|
import { FetcherExtraProps } from '../api/fetcher';
|
3
3
|
import { Dictionary } from '../util/types';
|
4
4
|
import { Page } from './pagination';
|
@@ -107,13 +107,14 @@ export declare abstract class Repository<Data extends BaseData, Record extends X
|
|
107
107
|
}): Promise<SelectedPick<Record, ['*']>[]>;
|
108
108
|
abstract query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
|
109
109
|
}
|
110
|
-
export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
|
110
|
+
export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> implements Repository<Data, Record> {
|
111
111
|
#private;
|
112
|
+
db: SchemaPluginResult<any>;
|
112
113
|
constructor(options: {
|
113
114
|
table: string;
|
114
115
|
links?: LinkDictionary;
|
115
116
|
getFetchProps: () => Promise<FetcherExtraProps>;
|
116
|
-
|
117
|
+
db: SchemaPluginResult<any>;
|
117
118
|
});
|
118
119
|
create(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
119
120
|
create(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
|
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
19
19
|
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");
|
20
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
21
21
|
};
|
22
|
-
var _RestRepository_instances, _RestRepository_table, _RestRepository_links, _RestRepository_getFetchProps,
|
22
|
+
var _RestRepository_instances, _RestRepository_table, _RestRepository_links, _RestRepository_getFetchProps, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _RestRepository_bulkInsertTableRecords, _RestRepository_updateRecordWithID, _RestRepository_upsertRecordWithID, _RestRepository_deleteRecord, _RestRepository_initObject;
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
24
24
|
exports.RestRepository = exports.Repository = void 0;
|
25
25
|
const api_1 = require("../api");
|
@@ -42,11 +42,10 @@ class RestRepository extends query_1.Query {
|
|
42
42
|
_RestRepository_table.set(this, void 0);
|
43
43
|
_RestRepository_links.set(this, void 0);
|
44
44
|
_RestRepository_getFetchProps.set(this, void 0);
|
45
|
-
_RestRepository_schemaNamespace.set(this, void 0);
|
46
45
|
__classPrivateFieldSet(this, _RestRepository_table, options.table, "f");
|
47
46
|
__classPrivateFieldSet(this, _RestRepository_links, (_a = options.links) !== null && _a !== void 0 ? _a : {}, "f");
|
48
47
|
__classPrivateFieldSet(this, _RestRepository_getFetchProps, options.getFetchProps, "f");
|
49
|
-
|
48
|
+
this.db = options.db;
|
50
49
|
}
|
51
50
|
create(a, b) {
|
52
51
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -180,7 +179,7 @@ class RestRepository extends query_1.Query {
|
|
180
179
|
}
|
181
180
|
}
|
182
181
|
exports.RestRepository = RestRepository;
|
183
|
-
_RestRepository_table = new WeakMap(), _RestRepository_links = new WeakMap(), _RestRepository_getFetchProps = new WeakMap(),
|
182
|
+
_RestRepository_table = new WeakMap(), _RestRepository_links = new WeakMap(), _RestRepository_getFetchProps = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_insertRecordWithoutId = function _RestRepository_insertRecordWithoutId(object) {
|
184
183
|
return __awaiter(this, void 0, void 0, function* () {
|
185
184
|
const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
|
186
185
|
const record = transformObjectLinks(object);
|
@@ -257,7 +256,7 @@ _RestRepository_table = new WeakMap(), _RestRepository_links = new WeakMap(), _R
|
|
257
256
|
result[field] = __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, linkTable, value);
|
258
257
|
}
|
259
258
|
}
|
260
|
-
const db =
|
259
|
+
const db = this.db;
|
261
260
|
result.read = function () {
|
262
261
|
return db[table].read(result['id']);
|
263
262
|
};
|
package/dist/schema/sorting.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SingleOrArray, Values } from '../util/types';
|
1
|
+
import { SingleOrArray, StringKeys, Values } from '../util/types';
|
2
2
|
import { XataRecord } from './record';
|
3
3
|
import { SelectableColumn } from './selection';
|
4
4
|
export declare type SortDirection = 'asc' | 'desc';
|
@@ -6,12 +6,17 @@ export declare type SortFilterExtended<T extends XataRecord> = {
|
|
6
6
|
column: SelectableColumn<T>;
|
7
7
|
direction?: SortDirection;
|
8
8
|
};
|
9
|
-
export declare type SortFilter<T extends XataRecord> = SelectableColumn<T> | SortFilterExtended<T>;
|
9
|
+
export declare type SortFilter<T extends XataRecord> = SelectableColumn<T> | SortFilterExtended<T> | SortFilterBase<T>;
|
10
|
+
declare type SortFilterBase<T extends XataRecord> = {
|
11
|
+
[Key in StringKeys<T>]: SortDirection;
|
12
|
+
};
|
10
13
|
export declare type ApiSortFilter<T extends XataRecord> = SingleOrArray<Values<{
|
11
|
-
[
|
12
|
-
[K in
|
14
|
+
[Key in SelectableColumn<T>]: {
|
15
|
+
[K in Key]: SortDirection;
|
13
16
|
};
|
14
17
|
}>>;
|
15
18
|
export declare function isSortFilterString<T extends XataRecord>(value: any): value is SelectableColumn<T>;
|
19
|
+
export declare function isSortFilterBase<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterBase<T>;
|
16
20
|
export declare function isSortFilterObject<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
|
17
21
|
export declare function buildSortFilter<T extends XataRecord>(filter: SingleOrArray<SortFilter<T>>): ApiSortFilter<T>;
|
22
|
+
export {};
|
package/dist/schema/sorting.js
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.buildSortFilter = exports.isSortFilterObject = exports.isSortFilterString = void 0;
|
3
|
+
exports.buildSortFilter = exports.isSortFilterObject = exports.isSortFilterBase = exports.isSortFilterString = void 0;
|
4
4
|
const lang_1 = require("../util/lang");
|
5
5
|
function isSortFilterString(value) {
|
6
6
|
return (0, lang_1.isString)(value);
|
7
7
|
}
|
8
8
|
exports.isSortFilterString = isSortFilterString;
|
9
|
+
function isSortFilterBase(filter) {
|
10
|
+
return (0, lang_1.isObject)(filter) && Object.values(filter).every((value) => value === 'asc' || value === 'desc');
|
11
|
+
}
|
12
|
+
exports.isSortFilterBase = isSortFilterBase;
|
9
13
|
function isSortFilterObject(filter) {
|
10
|
-
return (0, lang_1.isObject)(filter) && filter.column !== undefined;
|
14
|
+
return (0, lang_1.isObject)(filter) && !isSortFilterBase(filter) && filter.column !== undefined;
|
11
15
|
}
|
12
16
|
exports.isSortFilterObject = isSortFilterObject;
|
13
17
|
function buildSortFilter(filter) {
|
@@ -18,6 +22,9 @@ function buildSortFilter(filter) {
|
|
18
22
|
else if (Array.isArray(filter)) {
|
19
23
|
return filter.map((item) => buildSortFilter(item));
|
20
24
|
}
|
25
|
+
else if (isSortFilterBase(filter)) {
|
26
|
+
return filter;
|
27
|
+
}
|
21
28
|
else if (isSortFilterObject(filter)) {
|
22
29
|
return { [filter.column]: (_a = filter.direction) !== null && _a !== void 0 ? _a : 'asc' };
|
23
30
|
}
|
package/dist/search/index.d.ts
CHANGED
@@ -1,16 +1,30 @@
|
|
1
|
-
import {
|
1
|
+
import { XataPlugin, XataPluginOptions } from '../plugins';
|
2
2
|
import { BaseData, XataRecord } from '../schema/record';
|
3
3
|
import { SelectedPick } from '../schema/selection';
|
4
|
-
import { GetArrayInnerType } from '../util/types';
|
5
|
-
export declare class
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
import { GetArrayInnerType, Values } from '../util/types';
|
5
|
+
export declare class SearchPlugin<Schemas extends Record<string, BaseData>> extends XataPlugin {
|
6
|
+
#private;
|
7
|
+
build({ getFetchProps }: XataPluginOptions): {
|
8
|
+
all: <Tables extends Extract<keyof Schemas, string>>(query: string, options?: {
|
9
|
+
fuzziness?: number | undefined;
|
10
|
+
tables?: Tables[] | undefined;
|
11
|
+
}) => Promise<Values<{ [Model in Tables]: {
|
12
|
+
table: Model;
|
13
|
+
record: Awaited<SelectedPick<Schemas[Model] & XataRecord & {
|
14
|
+
xata: {
|
15
|
+
table: string;
|
16
|
+
};
|
17
|
+
}, ["*"]>>;
|
18
|
+
}; }>[]>;
|
19
|
+
byTable: <Tables_1 extends Extract<keyof Schemas, string>>(query: string, options?: {
|
20
|
+
fuzziness?: number | undefined;
|
21
|
+
tables?: Tables_1[] | undefined;
|
22
|
+
}) => Promise<{ [Model_1 in Tables_1]: SelectedPick<Schemas[Model_1] & XataRecord & {
|
23
|
+
xata: {
|
24
|
+
table: string;
|
25
|
+
};
|
26
|
+
}, ["*"]>[]; }>;
|
27
|
+
};
|
14
28
|
}
|
15
29
|
declare type SearchXataRecord = XataRecord & {
|
16
30
|
xata: {
|
package/dist/search/index.js
CHANGED
@@ -8,23 +8,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
15
|
+
};
|
16
|
+
var _SearchPlugin_instances, _SearchPlugin_search;
|
11
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.
|
18
|
+
exports.SearchPlugin = void 0;
|
13
19
|
const api_1 = require("../api");
|
14
|
-
const
|
15
|
-
class
|
20
|
+
const plugins_1 = require("../plugins");
|
21
|
+
class SearchPlugin extends plugins_1.XataPlugin {
|
22
|
+
constructor() {
|
23
|
+
super(...arguments);
|
24
|
+
_SearchPlugin_instances.add(this);
|
25
|
+
}
|
16
26
|
build({ getFetchProps }) {
|
17
|
-
return
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
return {
|
28
|
+
all: (query, options = {}) => __awaiter(this, void 0, void 0, function* () {
|
29
|
+
const records = yield __classPrivateFieldGet(this, _SearchPlugin_instances, "m", _SearchPlugin_search).call(this, query, options, getFetchProps);
|
30
|
+
return records.map((record) => {
|
31
|
+
const { table = 'orphan' } = record.xata;
|
32
|
+
return { table, record };
|
33
|
+
});
|
34
|
+
}),
|
35
|
+
byTable: (query, options = {}) => __awaiter(this, void 0, void 0, function* () {
|
36
|
+
const records = yield __classPrivateFieldGet(this, _SearchPlugin_instances, "m", _SearchPlugin_search).call(this, query, options, getFetchProps);
|
37
|
+
return records.reduce((acc, record) => {
|
38
|
+
var _a;
|
39
|
+
const { table = 'orphan' } = record.xata;
|
40
|
+
const items = (_a = acc[table]) !== null && _a !== void 0 ? _a : [];
|
41
|
+
return Object.assign(Object.assign({}, acc), { [table]: [...items, record] });
|
42
|
+
}, {});
|
43
|
+
})
|
44
|
+
};
|
28
45
|
}
|
29
46
|
}
|
30
|
-
exports.
|
47
|
+
exports.SearchPlugin = SearchPlugin;
|
48
|
+
_SearchPlugin_instances = new WeakSet(), _SearchPlugin_search = function _SearchPlugin_search(query, options, getFetchProps) {
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
50
|
+
const fetchProps = yield getFetchProps();
|
51
|
+
const { tables, fuzziness } = options !== null && options !== void 0 ? options : {};
|
52
|
+
const { records } = yield (0, api_1.searchBranch)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}' }, body: { tables, query, fuzziness } }, fetchProps));
|
53
|
+
return records;
|
54
|
+
});
|
55
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@xata.io/client",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.1",
|
4
4
|
"description": "Xata.io SDK for TypeScript and JavaScript",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.ts",
|
@@ -23,5 +23,5 @@
|
|
23
23
|
"url": "https://github.com/xataio/client-ts/issues"
|
24
24
|
},
|
25
25
|
"homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
|
26
|
-
"gitHead": "
|
26
|
+
"gitHead": "e0277aa65a86bd878e236c28677bab8aeff9a051"
|
27
27
|
}
|
package/dist/namespace.d.ts
DELETED