@xata.io/client 0.7.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Patch Changes
6
+
7
+ - bde908e: Refactor client builder
8
+ - ea3eef8: Make records returned by the API readonly
9
+
3
10
  ## 0.7.2
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,39 @@
1
+ import { FetchImpl } from './api/fetcher';
2
+ import { Namespace } from './namespace';
3
+ import { SchemaNamespace } from './schema';
4
+ import { BaseData } from './schema/record';
5
+ import { LinkDictionary } from './schema/repository';
6
+ import { SearchNamespace } from './search';
7
+ import { BranchStrategyOption } from './util/branches';
8
+ import { StringKeys } from './util/types';
9
+ export declare type BaseClientOptions = {
10
+ fetch?: FetchImpl;
11
+ apiKey?: string;
12
+ databaseURL?: string;
13
+ branch?: BranchStrategyOption;
14
+ };
15
+ export declare const buildClientWithNamespaces: <ExternalNamespaces extends Record<string, Namespace>>(namespaces: ExternalNamespaces) => <Schemas extends Record<string, BaseData>>() => WrapperConstructor<Schemas, {
16
+ db: SchemaNamespace<Schemas>;
17
+ search: SearchNamespace<Schemas>;
18
+ }, ExternalNamespaces>;
19
+ export declare const buildClient: <Schemas extends Record<string, BaseData>, ExternalNamespaces extends Record<string, Namespace> = {}, Namespaces extends Record<string, Namespace> = {
20
+ db: SchemaNamespace<Schemas>;
21
+ search: SearchNamespace<Schemas>;
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']>;
31
+ };
32
+ }
33
+ declare const BaseClient_base: WrapperConstructor<Record<string, any>, {
34
+ db: SchemaNamespace<Record<string, any>>;
35
+ search: SearchNamespace<Record<string, any>>;
36
+ }, {}>;
37
+ export declare class BaseClient extends BaseClient_base {
38
+ }
39
+ export {};
package/dist/client.js ADDED
@@ -0,0 +1,124 @@
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 = exports.buildClientWithNamespaces = 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 buildClientWithNamespaces = (namespaces) => () => (0, exports.buildClient)(namespaces);
37
+ exports.buildClientWithNamespaces = buildClientWithNamespaces;
38
+ const buildClient = (external) => {
39
+ var _instances, _branch, _parseOptions, _getFetchProps, _evaluateBranch, _a;
40
+ return _a = class {
41
+ constructor(options = {}, links) {
42
+ _instances.add(this);
43
+ _branch.set(this, void 0);
44
+ const safeOptions = __classPrivateFieldGet(this, _instances, "m", _parseOptions).call(this, options);
45
+ const namespaces = Object.assign({ db: new schema_1.SchemaNamespace(links), search: new search_1.SearchNamespace() }, external);
46
+ for (const [key, namespace] of Object.entries(namespaces)) {
47
+ if (!namespace)
48
+ continue;
49
+ // @ts-ignore
50
+ this[key] = namespace.build({ getFetchProps: () => __classPrivateFieldGet(this, _instances, "m", _getFetchProps).call(this, safeOptions) });
51
+ }
52
+ }
53
+ },
54
+ _branch = new WeakMap(),
55
+ _instances = new WeakSet(),
56
+ _parseOptions = function _parseOptions(options) {
57
+ const fetch = (0, fetch_1.getFetchImplementation)(options === null || options === void 0 ? void 0 : options.fetch);
58
+ const databaseURL = (options === null || options === void 0 ? void 0 : options.databaseURL) || (0, config_1.getDatabaseURL)();
59
+ const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (0, config_1.getAPIKey)();
60
+ const branch = () => __awaiter(this, void 0, void 0, function* () {
61
+ return (options === null || options === void 0 ? void 0 : options.branch)
62
+ ? yield __classPrivateFieldGet(this, _instances, "m", _evaluateBranch).call(this, options.branch)
63
+ : yield (0, config_1.getCurrentBranchName)({ apiKey, databaseURL, fetchImpl: options === null || options === void 0 ? void 0 : options.fetch });
64
+ });
65
+ if (!databaseURL || !apiKey) {
66
+ throw new Error('Options databaseURL and apiKey are required');
67
+ }
68
+ return { fetch, databaseURL, apiKey, branch };
69
+ },
70
+ _getFetchProps = function _getFetchProps({ fetch, apiKey, databaseURL, branch }) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const branchValue = yield __classPrivateFieldGet(this, _instances, "m", _evaluateBranch).call(this, branch);
73
+ if (!branchValue)
74
+ throw new Error('Unable to resolve branch value');
75
+ return {
76
+ fetchImpl: fetch,
77
+ apiKey,
78
+ apiUrl: '',
79
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
80
+ workspacesApiUrl: (path, params) => {
81
+ var _a;
82
+ const hasBranch = (_a = params.dbBranchName) !== null && _a !== void 0 ? _a : params.branch;
83
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : '');
84
+ return databaseURL + newPath;
85
+ }
86
+ };
87
+ });
88
+ },
89
+ _evaluateBranch = function _evaluateBranch(param) {
90
+ var e_1, _a;
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ if (__classPrivateFieldGet(this, _branch, "f"))
93
+ return __classPrivateFieldGet(this, _branch, "f");
94
+ if (!param)
95
+ return undefined;
96
+ const strategies = Array.isArray(param) ? [...param] : [param];
97
+ const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
98
+ return (0, branches_1.isBranchStrategyBuilder)(strategy) ? yield strategy() : strategy;
99
+ });
100
+ try {
101
+ for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
102
+ const strategy = strategies_1_1.value;
103
+ const branch = yield evaluateBranch(strategy);
104
+ if (branch) {
105
+ __classPrivateFieldSet(this, _branch, branch, "f");
106
+ return branch;
107
+ }
108
+ }
109
+ }
110
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
111
+ finally {
112
+ try {
113
+ if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
114
+ }
115
+ finally { if (e_1) throw e_1.error; }
116
+ }
117
+ });
118
+ },
119
+ _a;
120
+ };
121
+ exports.buildClient = buildClient;
122
+ class BaseClient extends (0, exports.buildClient)() {
123
+ }
124
+ exports.BaseClient = BaseClient;
package/dist/index.d.ts CHANGED
@@ -3,5 +3,7 @@ export declare class XataError extends Error {
3
3
  constructor(message: string, status: number);
4
4
  }
5
5
  export * from './api';
6
+ export * from './client';
6
7
  export * from './schema';
8
+ export * from './search';
7
9
  export * from './util/config';
package/dist/index.js CHANGED
@@ -23,5 +23,7 @@ class XataError extends Error {
23
23
  }
24
24
  exports.XataError = XataError;
25
25
  __exportStar(require("./api"), exports);
26
+ __exportStar(require("./client"), exports);
26
27
  __exportStar(require("./schema"), exports);
28
+ __exportStar(require("./search"), exports);
27
29
  __exportStar(require("./util/config"), exports);
@@ -0,0 +1,7 @@
1
+ import { FetcherExtraProps } from './api/fetcher';
2
+ export declare abstract class Namespace {
3
+ abstract build(options: NamespaceBuildOptions): unknown;
4
+ }
5
+ export declare type NamespaceBuildOptions = {
6
+ getFetchProps: () => Promise<FetcherExtraProps>;
7
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Namespace = void 0;
4
+ class Namespace {
5
+ }
6
+ exports.Namespace = Namespace;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-unused-vars */
4
+ const vitest_1 = require("vitest");
3
5
  // Single column with implicit is
4
6
  const singleColumnWithImplicitIs = { name: 'r2' };
5
7
  // Single column with explicit is
@@ -170,6 +172,6 @@ const filterWithInvalidNestedObjectPropertyType = { settings: { plan: 42 } };
170
172
  // Filter with invalid property $is type
171
173
  // @ts-expect-error
172
174
  const filterWithInvalidOperator = { name: { $is: 42 } };
173
- test('fake test', () => {
175
+ (0, vitest_1.test)('fake test', () => {
174
176
  // This is a fake test to make sure that the type definitions in this file are working
175
177
  });
@@ -1,7 +1,21 @@
1
+ import { Namespace, NamespaceBuildOptions } from '../namespace';
2
+ import { BaseData } from './record';
3
+ import { LinkDictionary, Repository } from './repository';
1
4
  export * from './operators';
2
5
  export * from './pagination';
3
6
  export { Query } from './query';
4
7
  export { isIdentifiable, isXataRecord } from './record';
5
8
  export type { Identifiable, XataRecord } from './record';
6
- export { BaseClient, Repository, RestRepository, RestRespositoryFactory } from './repository';
7
- export type { XataClientOptions } from './repository';
9
+ export { Repository, RestRepository } from './repository';
10
+ export declare type SchemaDefinition = {
11
+ table: string;
12
+ links?: LinkDictionary;
13
+ };
14
+ export declare type SchemaNamespaceResult<Schemas extends Record<string, BaseData>> = {
15
+ [Key in keyof Schemas]: Repository<Schemas[Key]>;
16
+ };
17
+ export declare class SchemaNamespace<Schemas extends Record<string, BaseData>> extends Namespace {
18
+ private links?;
19
+ constructor(links?: LinkDictionary | undefined);
20
+ build(options: NamespaceBuildOptions): SchemaNamespaceResult<Schemas>;
21
+ }
@@ -14,7 +14,10 @@ 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.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.BaseClient = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
17
+ exports.SchemaNamespace = exports.RestRepository = exports.Repository = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
18
+ const namespace_1 = require("../namespace");
19
+ const lang_1 = require("../util/lang");
20
+ const repository_1 = require("./repository");
18
21
  __exportStar(require("./operators"), exports);
19
22
  __exportStar(require("./pagination"), exports);
20
23
  var query_1 = require("./query");
@@ -22,8 +25,25 @@ Object.defineProperty(exports, "Query", { enumerable: true, get: function () { r
22
25
  var record_1 = require("./record");
23
26
  Object.defineProperty(exports, "isIdentifiable", { enumerable: true, get: function () { return record_1.isIdentifiable; } });
24
27
  Object.defineProperty(exports, "isXataRecord", { enumerable: true, get: function () { return record_1.isXataRecord; } });
25
- var repository_1 = require("./repository");
26
- Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
27
- Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
28
- Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_1.RestRepository; } });
29
- Object.defineProperty(exports, "RestRespositoryFactory", { enumerable: true, get: function () { return repository_1.RestRespositoryFactory; } });
28
+ var repository_2 = require("./repository");
29
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_2.Repository; } });
30
+ Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_2.RestRepository; } });
31
+ class SchemaNamespace extends namespace_1.Namespace {
32
+ constructor(links) {
33
+ super();
34
+ this.links = links;
35
+ }
36
+ build(options) {
37
+ const { getFetchProps } = options;
38
+ const links = this.links;
39
+ const schemaNamespace = new Proxy({}, {
40
+ get: (_target, table) => {
41
+ if (!(0, lang_1.isString)(table))
42
+ throw new Error('Invalid table name');
43
+ return new repository_1.RestRepository({ schemaNamespace, getFetchProps, table, links });
44
+ }
45
+ });
46
+ return schemaNamespace;
47
+ }
48
+ }
49
+ exports.SchemaNamespace = SchemaNamespace;
@@ -27,14 +27,14 @@ export interface XataRecord extends Identifiable {
27
27
  /**
28
28
  * Retrieves a refreshed copy of the current record from the database.
29
29
  */
30
- read(): Promise<SelectedPick<this, ['*']> | null>;
30
+ read(): Promise<Readonly<SelectedPick<this, ['*']>> | null>;
31
31
  /**
32
32
  * Performs a partial update of the current record. On success a new object is
33
33
  * returned and the current object is not mutated.
34
34
  * @param data The columns and their values that have to be updated.
35
35
  * @returns A new record containing the latest values for all the columns of the current record.
36
36
  */
37
- update(data: Partial<EditableData<Omit<this, keyof XataRecord>>>): Promise<SelectedPick<this, ['*']>>;
37
+ update(partialUpdate: Partial<EditableData<Omit<this, keyof XataRecord>>>): Promise<Readonly<SelectedPick<this, ['*']>>>;
38
38
  /**
39
39
  * Performs a deletion of the current record in the database.
40
40
  *
@@ -46,14 +46,14 @@ export declare type Link<Record extends XataRecord> = Omit<XataRecord, 'read' |
46
46
  /**
47
47
  * Retrieves a refreshed copy of the current record from the database.
48
48
  */
49
- read(): Promise<SelectedPick<Record, ['*']> | null>;
49
+ read(): Promise<Readonly<SelectedPick<Record, ['*']>> | null>;
50
50
  /**
51
51
  * Performs a partial update of the current record. On success a new object is
52
52
  * returned and the current object is not mutated.
53
53
  * @param data The columns and their values that have to be updated.
54
54
  * @returns A new record containing the latest values for all the columns of the current record.
55
55
  */
56
- update(data: Partial<EditableData<Omit<Record, keyof XataRecord>>>): Promise<SelectedPick<Record, ['*']>>;
56
+ update(partialUpdate: Partial<EditableData<Omit<Record, keyof XataRecord>>>): Promise<Readonly<SelectedPick<Record, ['*']>>>;
57
57
  };
58
58
  export declare function isIdentifiable(x: any): x is Identifiable & Record<string, unknown>;
59
59
  export declare function isXataRecord(x: any): x is XataRecord & Record<string, unknown>;
@@ -1,5 +1,6 @@
1
- import { FetchImpl } from '../api/fetcher';
2
- import { Dictionary, GetArrayInnerType, StringKeys } from '../util/types';
1
+ import { SchemaNamespaceResult } from '.';
2
+ import { FetcherExtraProps } from '../api/fetcher';
3
+ import { Dictionary } from '../util/types';
3
4
  import { Page } from './pagination';
4
5
  import { Query } from './query';
5
6
  import { BaseData, EditableData, Identifiable, XataRecord } from './record';
@@ -9,53 +10,53 @@ export declare type LinkDictionary = Dictionary<TableLink[]>;
9
10
  /**
10
11
  * Common interface for performing operations on a table.
11
12
  */
12
- export declare abstract class Repository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
13
- abstract create(object: EditableData<Data> & Partial<Identifiable>): Promise<SelectedPick<Record, ['*']>>;
13
+ export declare abstract class Repository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, Readonly<SelectedPick<Record, ['*']>>> {
14
+ abstract create(object: EditableData<Data> & Partial<Identifiable>): Promise<Readonly<SelectedPick<Record, ['*']>>>;
14
15
  /**
15
16
  * Creates a single record in the table with a unique id.
16
17
  * @param id The unique id.
17
18
  * @param object Object containing the column names with their values to be stored in the table.
18
19
  * @returns The full persisted record.
19
20
  */
20
- abstract create(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
21
+ abstract create(id: string, object: EditableData<Data>): Promise<Readonly<SelectedPick<Record, ['*']>>>;
21
22
  /**
22
23
  * Creates multiple records in the table.
23
24
  * @param objects Array of objects with the column names and the values to be stored in the table.
24
25
  * @returns Array of the persisted records.
25
26
  */
26
- abstract create(objects: Array<EditableData<Data> & Partial<Identifiable>>): Promise<SelectedPick<Record, ['*']>[]>;
27
+ abstract create(objects: Array<EditableData<Data> & Partial<Identifiable>>): Promise<Readonly<SelectedPick<Record, ['*']>>[]>;
27
28
  /**
28
29
  * Queries a single record from the table given its unique id.
29
30
  * @param id The unique id.
30
31
  * @returns The persisted record for the given id or null if the record could not be found.
31
32
  */
32
- abstract read(id: string): Promise<SelectedPick<Record, ['*']> | null>;
33
+ abstract read(id: string): Promise<Readonly<SelectedPick<Record, ['*']> | null>>;
33
34
  /**
34
35
  * Partially update a single record.
35
36
  * @param object An object with its id and the columns to be updated.
36
37
  * @returns The full persisted record.
37
38
  */
38
- abstract update(object: Partial<EditableData<Data>> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
39
+ abstract update(object: Partial<EditableData<Data>> & Identifiable): Promise<Readonly<SelectedPick<Record, ['*']>>>;
39
40
  /**
40
41
  * Partially update a single record given its unique id.
41
42
  * @param id The unique id.
42
43
  * @param object The column names and their values that have to be updated.
43
44
  * @returns The full persisted record.
44
45
  */
45
- abstract update(id: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
46
+ abstract update(id: string, object: Partial<EditableData<Data>>): Promise<Readonly<SelectedPick<Record, ['*']>>>;
46
47
  /**
47
48
  * Partially updates multiple records.
48
49
  * @param objects An array of objects with their ids and columns to be updated.
49
50
  * @returns Array of the persisted records.
50
51
  */
51
- abstract update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
52
+ abstract update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<Readonly<SelectedPick<Record, ['*']>>[]>;
52
53
  /**
53
54
  * Creates or updates a single record. If a record exists with the given id,
54
55
  * it will be update, otherwise a new record will be created.
55
56
  * @param object Object containing the column names with their values to be persisted in the table.
56
57
  * @returns The full persisted record.
57
58
  */
58
- abstract createOrUpdate(object: EditableData<Data> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
59
+ abstract createOrUpdate(object: EditableData<Data> & Identifiable): Promise<Readonly<SelectedPick<Record, ['*']>>>;
59
60
  /**
60
61
  * Creates or updates a single record. If a record exists with the given id,
61
62
  * it will be update, otherwise a new record will be created.
@@ -63,14 +64,14 @@ export declare abstract class Repository<Data extends BaseData, Record extends X
63
64
  * @param object The column names and the values to be persisted.
64
65
  * @returns The full persisted record.
65
66
  */
66
- abstract createOrUpdate(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
67
+ abstract createOrUpdate(id: string, object: EditableData<Data>): Promise<Readonly<SelectedPick<Record, ['*']>>>;
67
68
  /**
68
69
  * Creates or updates a single record. If a record exists with the given id,
69
70
  * it will be update, otherwise a new record will be created.
70
71
  * @param objects Array of objects with the column names and the values to be stored in the table.
71
72
  * @returns Array of the persisted records.
72
73
  */
73
- abstract createOrUpdate(objects: Array<EditableData<Data> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
74
+ abstract createOrUpdate(objects: Array<EditableData<Data> & Identifiable>): Promise<Readonly<SelectedPick<Record, ['*']>>[]>;
74
75
  /**
75
76
  * Deletes a record given its unique id.
76
77
  * @param id The unique id.
@@ -108,7 +109,12 @@ export declare abstract class Repository<Data extends BaseData, Record extends X
108
109
  }
109
110
  export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
110
111
  #private;
111
- constructor(client: BaseClient<any>, table: string, links?: LinkDictionary);
112
+ constructor(options: {
113
+ table: string;
114
+ links?: LinkDictionary;
115
+ getFetchProps: () => Promise<FetcherExtraProps>;
116
+ schemaNamespace: SchemaNamespaceResult<any>;
117
+ });
112
118
  create(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
113
119
  create(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
114
120
  create(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
@@ -125,41 +131,4 @@ export declare class RestRepository<Data extends BaseData, Record extends XataRe
125
131
  }): Promise<SelectedPick<Record, ['*']>[]>;
126
132
  query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
127
133
  }
128
- interface RepositoryFactory {
129
- createRepository<Data extends BaseData>(client: BaseClient<any>, table: string, links?: LinkDictionary): Repository<Data & XataRecord>;
130
- }
131
- export declare class RestRespositoryFactory implements RepositoryFactory {
132
- createRepository<Data extends BaseData>(client: BaseClient<any>, table: string, links?: LinkDictionary): Repository<Data & XataRecord>;
133
- }
134
- declare type BranchStrategyValue = string | undefined | null;
135
- declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
136
- declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
137
- declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
138
- export declare type XataClientOptions = {
139
- /**
140
- * Fetch implementation. This option is only required if the runtime does not include a fetch implementation
141
- * available in the global scope. If you are running your code on Deno or Cloudflare workers for example,
142
- * you won't need to provide a specific fetch implementation. But for most versions of Node.js you'll need
143
- * to provide one. Such as cross-fetch, node-fetch or isomorphic-fetch.
144
- */
145
- fetch?: FetchImpl;
146
- databaseURL?: string;
147
- branch?: BranchStrategyOption;
148
- /**
149
- * API key to be used. You can create one in your account settings at https://app.xata.io/settings.
150
- */
151
- apiKey?: string;
152
- repositoryFactory?: RepositoryFactory;
153
- };
154
- export declare class BaseClient<D extends Record<string, Repository<any>> = Record<string, Repository<any>>> {
155
- options: XataClientOptions;
156
- db: D;
157
- constructor(options?: XataClientOptions, links?: LinkDictionary);
158
- search<Tables extends StringKeys<D>>(query: string, options?: {
159
- fuzziness?: number;
160
- tables?: Tables[];
161
- }): Promise<{
162
- [Model in GetArrayInnerType<NonNullable<NonNullable<typeof options>['tables']>>]: Awaited<ReturnType<D[Model]['search']>>;
163
- }>;
164
- }
165
134
  export {};
@@ -19,20 +19,11 @@ 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 __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
- var _RestRepository_instances, _RestRepository_client, _RestRepository_fetch, _RestRepository_table, _RestRepository_links, _RestRepository_branch, _RestRepository_getFetchProps, _RestRepository_getBranch, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _RestRepository_bulkInsertTableRecords, _RestRepository_updateRecordWithID, _RestRepository_upsertRecordWithID, _RestRepository_deleteRecord, _RestRepository_initObject;
22
+ var _RestRepository_instances, _RestRepository_table, _RestRepository_links, _RestRepository_getFetchProps, _RestRepository_schemaNamespace, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _RestRepository_bulkInsertTableRecords, _RestRepository_updateRecordWithID, _RestRepository_upsertRecordWithID, _RestRepository_deleteRecord, _RestRepository_initObject;
30
23
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
24
+ exports.RestRepository = exports.Repository = void 0;
32
25
  const api_1 = require("../api");
33
- const fetch_1 = require("../util/fetch");
34
26
  const lang_1 = require("../util/lang");
35
- const config_1 = require("../util/config");
36
27
  const pagination_1 = require("./pagination");
37
28
  const query_1 = require("./query");
38
29
  const record_1 = require("./record");
@@ -44,18 +35,18 @@ class Repository extends query_1.Query {
44
35
  }
45
36
  exports.Repository = Repository;
46
37
  class RestRepository extends query_1.Query {
47
- constructor(client, table, links) {
48
- super(null, table, {});
38
+ constructor(options) {
39
+ var _a;
40
+ super(null, options.table, {});
49
41
  _RestRepository_instances.add(this);
50
- _RestRepository_client.set(this, void 0);
51
- _RestRepository_fetch.set(this, void 0);
52
42
  _RestRepository_table.set(this, void 0);
53
43
  _RestRepository_links.set(this, void 0);
54
- _RestRepository_branch.set(this, void 0);
55
- __classPrivateFieldSet(this, _RestRepository_client, client, "f");
56
- __classPrivateFieldSet(this, _RestRepository_table, table, "f");
57
- __classPrivateFieldSet(this, _RestRepository_fetch, (0, fetch_1.getFetchImplementation)(__classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch), "f");
58
- __classPrivateFieldSet(this, _RestRepository_links, links !== null && links !== void 0 ? links : {}, "f");
44
+ _RestRepository_getFetchProps.set(this, void 0);
45
+ _RestRepository_schemaNamespace.set(this, void 0);
46
+ __classPrivateFieldSet(this, _RestRepository_table, options.table, "f");
47
+ __classPrivateFieldSet(this, _RestRepository_links, (_a = options.links) !== null && _a !== void 0 ? _a : {}, "f");
48
+ __classPrivateFieldSet(this, _RestRepository_getFetchProps, options.getFetchProps, "f");
49
+ __classPrivateFieldSet(this, _RestRepository_schemaNamespace, options.schemaNamespace, "f");
59
50
  }
60
51
  create(a, b) {
61
52
  return __awaiter(this, void 0, void 0, function* () {
@@ -85,7 +76,7 @@ class RestRepository extends query_1.Query {
85
76
  // TODO: Add column support: https://github.com/xataio/openapi/issues/139
86
77
  read(recordId) {
87
78
  return __awaiter(this, void 0, void 0, function* () {
88
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
79
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
89
80
  try {
90
81
  const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
91
82
  return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, __classPrivateFieldGet(this, _RestRepository_table, "f"), response);
@@ -166,7 +157,7 @@ class RestRepository extends query_1.Query {
166
157
  }
167
158
  search(query, options = {}) {
168
159
  return __awaiter(this, void 0, void 0, function* () {
169
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
160
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
170
161
  const { records } = yield (0, api_1.searchBranch)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}' }, body: { tables: [__classPrivateFieldGet(this, _RestRepository_table, "f")], query, fuzziness: options.fuzziness } }, fetchProps));
171
162
  return records.map((item) => __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, __classPrivateFieldGet(this, _RestRepository_table, "f"), item));
172
163
  });
@@ -181,7 +172,7 @@ class RestRepository extends query_1.Query {
181
172
  page: data.page,
182
173
  columns: data.columns
183
174
  };
184
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
175
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
185
176
  const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
186
177
  const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, __classPrivateFieldGet(this, _RestRepository_table, "f"), record));
187
178
  return new pagination_1.Page(query, meta, records);
@@ -189,60 +180,9 @@ class RestRepository extends query_1.Query {
189
180
  }
190
181
  }
191
182
  exports.RestRepository = RestRepository;
192
- _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap(), _RestRepository_links = new WeakMap(), _RestRepository_branch = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_getFetchProps = function _RestRepository_getFetchProps() {
193
- var _a;
194
- return __awaiter(this, void 0, void 0, function* () {
195
- const branch = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getBranch).call(this);
196
- const apiKey = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.apiKey) !== null && _a !== void 0 ? _a : (0, config_1.getAPIKey)();
197
- if (!apiKey) {
198
- throw new Error('Could not resolve a valid apiKey');
199
- }
200
- return {
201
- fetchImpl: __classPrivateFieldGet(this, _RestRepository_fetch, "f"),
202
- apiKey,
203
- apiUrl: '',
204
- // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
205
- workspacesApiUrl: (path, params) => {
206
- var _a, _b;
207
- const baseUrl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.databaseURL) !== null && _a !== void 0 ? _a : '';
208
- const hasBranch = (_b = params.dbBranchName) !== null && _b !== void 0 ? _b : params.branch;
209
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branch}` : '');
210
- return baseUrl + newPath;
211
- }
212
- };
213
- });
214
- }, _RestRepository_getBranch = function _RestRepository_getBranch() {
215
- var e_1, _a;
216
- return __awaiter(this, void 0, void 0, function* () {
217
- if (__classPrivateFieldGet(this, _RestRepository_branch, "f"))
218
- return __classPrivateFieldGet(this, _RestRepository_branch, "f");
219
- const { branch: param } = __classPrivateFieldGet(this, _RestRepository_client, "f").options;
220
- const strategies = Array.isArray(param) ? [...param] : [param];
221
- const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
222
- return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
223
- });
224
- try {
225
- for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
226
- const strategy = strategies_1_1.value;
227
- const branch = yield evaluateBranch(strategy);
228
- if (branch) {
229
- __classPrivateFieldSet(this, _RestRepository_branch, branch, "f");
230
- return branch;
231
- }
232
- }
233
- }
234
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
235
- finally {
236
- try {
237
- if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
238
- }
239
- finally { if (e_1) throw e_1.error; }
240
- }
241
- throw new Error('Unable to resolve branch value');
242
- });
243
- }, _RestRepository_insertRecordWithoutId = function _RestRepository_insertRecordWithoutId(object) {
183
+ _RestRepository_table = new WeakMap(), _RestRepository_links = new WeakMap(), _RestRepository_getFetchProps = new WeakMap(), _RestRepository_schemaNamespace = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_insertRecordWithoutId = function _RestRepository_insertRecordWithoutId(object) {
244
184
  return __awaiter(this, void 0, void 0, function* () {
245
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
185
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
246
186
  const record = transformObjectLinks(object);
247
187
  const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
248
188
  workspace: '{workspaceId}',
@@ -257,7 +197,7 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
257
197
  });
258
198
  }, _RestRepository_insertRecordWithId = function _RestRepository_insertRecordWithId(recordId, object) {
259
199
  return __awaiter(this, void 0, void 0, function* () {
260
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
200
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
261
201
  const record = transformObjectLinks(object);
262
202
  const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
263
203
  workspace: '{workspaceId}',
@@ -273,7 +213,7 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
273
213
  });
274
214
  }, _RestRepository_bulkInsertTableRecords = function _RestRepository_bulkInsertTableRecords(objects) {
275
215
  return __awaiter(this, void 0, void 0, function* () {
276
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
216
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
277
217
  const records = objects.map((object) => transformObjectLinks(object));
278
218
  const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
279
219
  const finalObjects = yield this.any(...response.recordIDs.map((id) => this.filter('id', id))).getAll();
@@ -284,7 +224,7 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
284
224
  });
285
225
  }, _RestRepository_updateRecordWithID = function _RestRepository_updateRecordWithID(recordId, object) {
286
226
  return __awaiter(this, void 0, void 0, function* () {
287
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
227
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
288
228
  const record = transformObjectLinks(object);
289
229
  const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: record }, fetchProps));
290
230
  const item = yield this.read(response.id);
@@ -294,7 +234,7 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
294
234
  });
295
235
  }, _RestRepository_upsertRecordWithID = function _RestRepository_upsertRecordWithID(recordId, object) {
296
236
  return __awaiter(this, void 0, void 0, function* () {
297
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
237
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
298
238
  const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
299
239
  const item = yield this.read(response.id);
300
240
  if (!item)
@@ -303,7 +243,7 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
303
243
  });
304
244
  }, _RestRepository_deleteRecord = function _RestRepository_deleteRecord(recordId) {
305
245
  return __awaiter(this, void 0, void 0, function* () {
306
- const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
246
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_getFetchProps, "f").call(this);
307
247
  yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
308
248
  });
309
249
  }, _RestRepository_initObject = function _RestRepository_initObject(table, object) {
@@ -317,7 +257,7 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
317
257
  result[field] = __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_initObject).call(this, linkTable, value);
318
258
  }
319
259
  }
320
- const db = __classPrivateFieldGet(this, _RestRepository_client, "f").db;
260
+ const db = __classPrivateFieldGet(this, _RestRepository_schemaNamespace, "f");
321
261
  result.read = function () {
322
262
  return db[table].read(result['id']);
323
263
  };
@@ -333,51 +273,6 @@ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _
333
273
  Object.freeze(result);
334
274
  return result;
335
275
  };
336
- class RestRespositoryFactory {
337
- createRepository(client, table, links) {
338
- return new RestRepository(client, table, links);
339
- }
340
- }
341
- exports.RestRespositoryFactory = RestRespositoryFactory;
342
- function resolveXataClientOptions(options) {
343
- const databaseURL = (options === null || options === void 0 ? void 0 : options.databaseURL) || (0, config_1.getDatabaseURL)() || '';
344
- const apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) || (0, config_1.getAPIKey)() || '';
345
- const branch = (options === null || options === void 0 ? void 0 : options.branch) || (() => (0, config_1.getCurrentBranchName)({ apiKey, databaseURL, fetchImpl: options === null || options === void 0 ? void 0 : options.fetch }));
346
- if (!databaseURL || !apiKey) {
347
- throw new Error('Options databaseURL and apiKey are required');
348
- }
349
- return Object.assign(Object.assign({}, options), { databaseURL,
350
- apiKey,
351
- branch });
352
- }
353
- class BaseClient {
354
- constructor(options = {}, links) {
355
- this.options = resolveXataClientOptions(options);
356
- // Make this property not enumerable so it doesn't show up in console.dir, etc.
357
- Object.defineProperty(this.options, 'apiKey', { enumerable: false });
358
- const factory = this.options.repositoryFactory || new RestRespositoryFactory();
359
- this.db = new Proxy({}, {
360
- get: (_target, prop) => {
361
- if (!(0, lang_1.isString)(prop))
362
- throw new Error('Invalid table name');
363
- return factory.createRepository(this, prop, links);
364
- }
365
- });
366
- }
367
- search(query, options) {
368
- var _a;
369
- return __awaiter(this, void 0, void 0, function* () {
370
- const tables = (_a = options === null || options === void 0 ? void 0 : options.tables) !== null && _a !== void 0 ? _a : Object.keys(this.db);
371
- // TODO: Implement global search with a single call, REST repository abstraction needed
372
- const results = yield Promise.all(tables.map((table) => this.db[table].search(query, options).then((results) => [table, results])));
373
- return Object.fromEntries(results);
374
- });
375
- }
376
- }
377
- exports.BaseClient = BaseClient;
378
- const isBranchStrategyBuilder = (strategy) => {
379
- return typeof strategy === 'function';
380
- };
381
276
  const transformObjectLinks = (object) => {
382
277
  return Object.entries(object).reduce((acc, [key, value]) => {
383
278
  // Ignore internal properties
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-floating-promises */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ const vitest_1 = require("vitest");
4
5
  // SelectableColumn<O> //
5
6
  // --------------------------------------------------------------------------- //
6
7
  const validTeamColumns = [
@@ -198,6 +199,6 @@ function test8(user) {
198
199
  user.partner = null;
199
200
  user.team = null;
200
201
  }
201
- test('fake test', () => {
202
+ (0, vitest_1.test)('fake test', () => {
202
203
  // This is a fake test to make sure that the type definitions in this file are working
203
204
  });
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-unused-vars */
4
+ const vitest_1 = require("vitest");
3
5
  // Simple sorting
4
6
  const simpleSorting = { name: 'asc' };
5
7
  // Array of simple sorting
6
8
  const arrayOfSimpleSorting = [{ name: 'asc' }, { age: 'desc' }];
7
- test('fake test', () => {
9
+ (0, vitest_1.test)('fake test', () => {
8
10
  // This is a fake test to make sure that the type definitions in this file are working
9
11
  });
@@ -0,0 +1,20 @@
1
+ import { Namespace, NamespaceBuildOptions } from '../namespace';
2
+ import { BaseData, XataRecord } from '../schema/record';
3
+ import { SelectedPick } from '../schema/selection';
4
+ import { GetArrayInnerType } from '../util/types';
5
+ export declare class SearchNamespace<Schemas extends Record<string, BaseData>> extends Namespace {
6
+ build({ getFetchProps }: NamespaceBuildOptions): <Tables extends Extract<keyof Schemas, string>>(query: string, options?: {
7
+ fuzziness?: number | undefined;
8
+ tables?: Tables[] | undefined;
9
+ } | undefined) => Promise<{ [Model in Tables]: SelectedPick<Schemas[Model] & XataRecord & {
10
+ xata: {
11
+ table: string;
12
+ };
13
+ }, ["*"]>[]; }>;
14
+ }
15
+ declare type SearchXataRecord = XataRecord & {
16
+ xata: {
17
+ table: string;
18
+ };
19
+ };
20
+ export {};
@@ -0,0 +1,30 @@
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.SearchNamespace = void 0;
13
+ const api_1 = require("../api");
14
+ const namespace_1 = require("../namespace");
15
+ class SearchNamespace extends namespace_1.Namespace {
16
+ build({ getFetchProps }) {
17
+ return (query, options) => __awaiter(this, void 0, void 0, function* () {
18
+ const fetchProps = yield getFetchProps();
19
+ const { tables, fuzziness } = options !== null && options !== void 0 ? options : {};
20
+ const { records } = yield (0, api_1.searchBranch)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}' }, body: { tables, query, fuzziness } }, fetchProps));
21
+ return records.reduce((acc, record) => {
22
+ var _a;
23
+ const { table = 'orphan' } = record.xata;
24
+ const items = (_a = acc[table]) !== null && _a !== void 0 ? _a : [];
25
+ return Object.assign(Object.assign({}, acc), { [table]: [...items, record] });
26
+ }, {});
27
+ });
28
+ }
29
+ }
30
+ exports.SearchNamespace = SearchNamespace;
@@ -0,0 +1,5 @@
1
+ export declare type BranchStrategyValue = string | undefined | null;
2
+ export declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
3
+ export declare type BranchStrategy = BranchStrategyValue | BranchStrategyBuilder;
4
+ export declare type BranchStrategyOption = NonNullable<BranchStrategy | BranchStrategy[]>;
5
+ export declare const isBranchStrategyBuilder: (strategy: BranchStrategy) => strategy is BranchStrategyBuilder;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBranchStrategyBuilder = void 0;
4
+ const isBranchStrategyBuilder = (strategy) => {
5
+ return typeof strategy === 'function';
6
+ };
7
+ exports.isBranchStrategyBuilder = isBranchStrategyBuilder;
@@ -12,8 +12,8 @@ export declare type RequiredBy<T, K extends keyof T> = T & {
12
12
  [P in K]-?: NonNullable<T[P]>;
13
13
  };
14
14
  export declare type GetArrayInnerType<T extends readonly any[]> = T[number];
15
- export declare type NonNullableValues<Obj> = {
16
- [K in keyof Obj]: NonNullable<Obj[K]>;
15
+ export declare type AllRequired<T> = {
16
+ [P in keyof T]-?: T[P];
17
17
  };
18
18
  export declare type KeysOfUnion<T> = T extends T ? keyof T : never;
19
19
  declare type Impossible<K extends keyof any> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -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": "036d273ce2e938ef4bae72c3727881eefaf30574"
26
+ "gitHead": "ca9389ac662985428e3714be546cbf9d3bc5c4b6"
27
27
  }