@xata.io/client 0.0.0-beta.641039e → 0.0.0-beta.642c07f
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 +13 -0
- package/dist/api/client.d.ts +2 -0
- package/dist/api/client.js +6 -0
- package/dist/api/components.d.ts +24 -0
- package/dist/api/components.js +14 -1
- package/dist/api/parameters.d.ts +1 -0
- package/dist/api/schemas.d.ts +1 -1
- package/dist/index.d.ts +0 -59
- package/dist/index.js +1 -258
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +8 -0
- package/dist/schema/operators.d.ts +51 -0
- package/dist/schema/operators.js +51 -0
- package/dist/schema/pagination.d.ts +38 -0
- package/dist/schema/pagination.js +32 -0
- package/dist/schema/query.d.ts +73 -4
- package/dist/schema/query.js +56 -19
- package/dist/schema/record.d.ts +36 -0
- package/dist/schema/record.js +2 -0
- package/dist/schema/repository.d.ts +109 -0
- package/dist/schema/repository.js +273 -0
- package/dist/schema/selection.d.ts +2 -3
- package/package.json +2 -2
- package/tsconfig.json +21 -0
package/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# @xata.io/client
|
2
|
+
|
3
|
+
## 0.3.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 1c0a454: Add API Client and internally use it
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- 122321c: Fix client in CF workers and Deno
|
12
|
+
- a2671b5: Allow cancel or resend workspace invites
|
13
|
+
- e73d470: Split insert and create
|
package/dist/api/client.d.ts
CHANGED
@@ -40,6 +40,8 @@ declare class WorkspaceApi {
|
|
40
40
|
updateWorkspaceMemberRole(workspaceId: Schemas.WorkspaceID, userId: Schemas.UserID, role: Schemas.Role): Promise<void>;
|
41
41
|
removeWorkspaceMember(workspaceId: Schemas.WorkspaceID, userId: Schemas.UserID): Promise<void>;
|
42
42
|
inviteWorkspaceMember(workspaceId: Schemas.WorkspaceID, email: string, role: Schemas.Role): Promise<Schemas.WorkspaceInvite>;
|
43
|
+
cancelWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteId: Schemas.InviteID): Promise<void>;
|
44
|
+
resendWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteId: Schemas.InviteID): Promise<void>;
|
43
45
|
acceptWorkspaceMemberInvite(workspaceId: Schemas.WorkspaceID, inviteKey: Schemas.InviteKey): Promise<void>;
|
44
46
|
}
|
45
47
|
declare class DatabaseApi {
|
package/dist/api/client.js
CHANGED
@@ -107,6 +107,12 @@ class WorkspaceApi {
|
|
107
107
|
inviteWorkspaceMember(workspaceId, email, role) {
|
108
108
|
return components_1.operationsByTag.workspaces.inviteWorkspaceMember(Object.assign({ pathParams: { workspaceId }, body: { email, role } }, this.extraProps));
|
109
109
|
}
|
110
|
+
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
111
|
+
return components_1.operationsByTag.workspaces.cancelWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteId } }, this.extraProps));
|
112
|
+
}
|
113
|
+
resendWorkspaceMemberInvite(workspaceId, inviteId) {
|
114
|
+
return components_1.operationsByTag.workspaces.resendWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteId } }, this.extraProps));
|
115
|
+
}
|
110
116
|
acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
|
111
117
|
return components_1.operationsByTag.workspaces.acceptWorkspaceMemberInvite(Object.assign({ pathParams: { workspaceId, inviteKey } }, this.extraProps));
|
112
118
|
}
|
package/dist/api/components.d.ts
CHANGED
@@ -161,6 +161,28 @@ export declare type InviteWorkspaceMemberVariables = {
|
|
161
161
|
* Invite some user to join the workspace with the given role
|
162
162
|
*/
|
163
163
|
export declare const inviteWorkspaceMember: (variables: InviteWorkspaceMemberVariables) => Promise<Schemas.WorkspaceInvite>;
|
164
|
+
export declare type CancelWorkspaceMemberInvitePathParams = {
|
165
|
+
workspaceId: Schemas.WorkspaceID;
|
166
|
+
inviteId: Schemas.InviteID;
|
167
|
+
};
|
168
|
+
export declare type CancelWorkspaceMemberInviteVariables = {
|
169
|
+
pathParams: CancelWorkspaceMemberInvitePathParams;
|
170
|
+
} & FetcherExtraProps;
|
171
|
+
/**
|
172
|
+
* This operation provides a way to cancel invites by deleting them. Already accepted invites cannot be deleted.
|
173
|
+
*/
|
174
|
+
export declare const cancelWorkspaceMemberInvite: (variables: CancelWorkspaceMemberInviteVariables) => Promise<undefined>;
|
175
|
+
export declare type ResendWorkspaceMemberInvitePathParams = {
|
176
|
+
workspaceId: Schemas.WorkspaceID;
|
177
|
+
inviteId: Schemas.InviteID;
|
178
|
+
};
|
179
|
+
export declare type ResendWorkspaceMemberInviteVariables = {
|
180
|
+
pathParams: ResendWorkspaceMemberInvitePathParams;
|
181
|
+
} & FetcherExtraProps;
|
182
|
+
/**
|
183
|
+
* This operation provides a way to resend an Invite notification. Invite notifications can only be sent for Invites not yet accepted.
|
184
|
+
*/
|
185
|
+
export declare const resendWorkspaceMemberInvite: (variables: ResendWorkspaceMemberInviteVariables) => Promise<undefined>;
|
164
186
|
export declare type AcceptWorkspaceMemberInvitePathParams = {
|
165
187
|
workspaceId: Schemas.WorkspaceID;
|
166
188
|
inviteKey: Schemas.InviteKey;
|
@@ -1371,6 +1393,8 @@ export declare const operationsByTag: {
|
|
1371
1393
|
updateWorkspaceMemberRole: (variables: UpdateWorkspaceMemberRoleVariables) => Promise<undefined>;
|
1372
1394
|
removeWorkspaceMember: (variables: RemoveWorkspaceMemberVariables) => Promise<undefined>;
|
1373
1395
|
inviteWorkspaceMember: (variables: InviteWorkspaceMemberVariables) => Promise<Schemas.WorkspaceInvite>;
|
1396
|
+
cancelWorkspaceMemberInvite: (variables: CancelWorkspaceMemberInviteVariables) => Promise<undefined>;
|
1397
|
+
resendWorkspaceMemberInvite: (variables: ResendWorkspaceMemberInviteVariables) => Promise<undefined>;
|
1374
1398
|
acceptWorkspaceMemberInvite: (variables: AcceptWorkspaceMemberInviteVariables) => Promise<undefined>;
|
1375
1399
|
};
|
1376
1400
|
database: {
|
package/dist/api/components.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.searchBranch = exports.queryTable = exports.bulkInsertTableRecords = exports.getRecord = exports.deleteRecord = exports.upsertRecordWithID = exports.updateRecordWithID = exports.insertRecordWithID = exports.insertRecord = exports.updateColumn = exports.deleteColumn = exports.getColumn = exports.addTableColumn = exports.getTableColumns = exports.setTableSchema = exports.getTableSchema = exports.updateTable = exports.deleteTable = exports.createTable = exports.getBranchStats = exports.getBranchMigrationPlan = exports.executeBranchMigrationPlan = exports.getBranchMigrationHistory = exports.getBranchMetadata = exports.updateBranchMetadata = exports.deleteBranch = exports.createBranch = exports.getBranchDetails = exports.deleteDatabase = exports.createDatabase = exports.getBranchList = exports.getDatabaseList = exports.acceptWorkspaceMemberInvite = exports.resendWorkspaceMemberInvite = exports.cancelWorkspaceMemberInvite = exports.inviteWorkspaceMember = exports.removeWorkspaceMember = exports.updateWorkspaceMemberRole = exports.getWorkspaceMembersList = exports.deleteWorkspace = exports.updateWorkspace = exports.getWorkspace = exports.getWorkspacesList = exports.createWorkspace = exports.deleteUserAPIKey = exports.createUserAPIKey = exports.getUserAPIKeys = exports.deleteUser = exports.updateUser = exports.getUser = void 0;
|
4
|
+
exports.operationsByTag = void 0;
|
4
5
|
/**
|
5
6
|
* Generated by @openapi-codegen
|
6
7
|
*
|
@@ -82,6 +83,16 @@ exports.removeWorkspaceMember = removeWorkspaceMember;
|
|
82
83
|
*/
|
83
84
|
const inviteWorkspaceMember = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites', method: 'post' }, variables));
|
84
85
|
exports.inviteWorkspaceMember = inviteWorkspaceMember;
|
86
|
+
/**
|
87
|
+
* This operation provides a way to cancel invites by deleting them. Already accepted invites cannot be deleted.
|
88
|
+
*/
|
89
|
+
const cancelWorkspaceMemberInvite = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites/{inviteId}', method: 'delete' }, variables));
|
90
|
+
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
91
|
+
/**
|
92
|
+
* This operation provides a way to resend an Invite notification. Invite notifications can only be sent for Invites not yet accepted.
|
93
|
+
*/
|
94
|
+
const resendWorkspaceMemberInvite = (variables) => (0, fetcher_1.fetch)(Object.assign({ url: '/workspaces/{workspaceId}/invites/{inviteId}/resend', method: 'post' }, variables));
|
95
|
+
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
85
96
|
/**
|
86
97
|
* Accept the invitation to join a workspace. If the operation succeeds the user will be a member of the workspace
|
87
98
|
*/
|
@@ -947,6 +958,8 @@ exports.operationsByTag = {
|
|
947
958
|
updateWorkspaceMemberRole: exports.updateWorkspaceMemberRole,
|
948
959
|
removeWorkspaceMember: exports.removeWorkspaceMember,
|
949
960
|
inviteWorkspaceMember: exports.inviteWorkspaceMember,
|
961
|
+
cancelWorkspaceMemberInvite: exports.cancelWorkspaceMemberInvite,
|
962
|
+
resendWorkspaceMemberInvite: exports.resendWorkspaceMemberInvite,
|
950
963
|
acceptWorkspaceMemberInvite: exports.acceptWorkspaceMemberInvite
|
951
964
|
},
|
952
965
|
database: { getDatabaseList: exports.getDatabaseList, createDatabase: exports.createDatabase, deleteDatabase: exports.deleteDatabase },
|
package/dist/api/parameters.d.ts
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
*/
|
6
6
|
import type * as Schemas from './schemas';
|
7
7
|
export declare type APIKeyNameParam = Schemas.APIKeyName;
|
8
|
+
export declare type InviteIDParam = Schemas.InviteID;
|
8
9
|
export declare type InviteKeyParam = Schemas.InviteKey;
|
9
10
|
export declare type UserIDParam = Schemas.UserID;
|
10
11
|
export declare type WorkspaceIDParam = Schemas.WorkspaceID;
|
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,6 @@
|
|
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';
|
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,5 @@ 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);
|
package/dist/schema/index.d.ts
CHANGED
package/dist/schema/index.js
CHANGED
@@ -14,4 +14,12 @@ 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.Query = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
|
17
18
|
__exportStar(require("./operators"), exports);
|
19
|
+
var repository_1 = require("./repository");
|
20
|
+
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
|
21
|
+
Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_1.RestRepository; } });
|
22
|
+
Object.defineProperty(exports, "RestRespositoryFactory", { enumerable: true, get: function () { return repository_1.RestRespositoryFactory; } });
|
23
|
+
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
|
24
|
+
var query_1 = require("./query");
|
25
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
|
@@ -1,21 +1,72 @@
|
|
1
1
|
import { Constraint } from './filters';
|
2
2
|
declare type ComparableType = number | Date;
|
3
|
+
/**
|
4
|
+
* Operator to restrict results to only values that are greater than the given value.
|
5
|
+
*/
|
3
6
|
export declare const gt: <T extends ComparableType>(value: T) => Constraint<T>;
|
7
|
+
/**
|
8
|
+
* Operator to restrict results to only values that are greater than or equal to the given value.
|
9
|
+
*/
|
4
10
|
export declare const ge: <T extends ComparableType>(value: T) => Constraint<T>;
|
11
|
+
/**
|
12
|
+
* Operator to restrict results to only values that are greater than or equal to the given value.
|
13
|
+
*/
|
5
14
|
export declare const gte: <T extends ComparableType>(value: T) => Constraint<T>;
|
15
|
+
/**
|
16
|
+
* Operator to restrict results to only values that are lower than the given value.
|
17
|
+
*/
|
6
18
|
export declare const lt: <T extends ComparableType>(value: T) => Constraint<T>;
|
19
|
+
/**
|
20
|
+
* Operator to restrict results to only values that are lower than or equal to the given value.
|
21
|
+
*/
|
7
22
|
export declare const lte: <T extends ComparableType>(value: T) => Constraint<T>;
|
23
|
+
/**
|
24
|
+
* Operator to restrict results to only values that are lower than or equal to the given value.
|
25
|
+
*/
|
8
26
|
export declare const le: <T extends ComparableType>(value: T) => Constraint<T>;
|
27
|
+
/**
|
28
|
+
* Operator to restrict results to only values that are not null.
|
29
|
+
*/
|
9
30
|
export declare const exists: (column: string) => Constraint<string>;
|
31
|
+
/**
|
32
|
+
* Operator to restrict results to only values that are null.
|
33
|
+
*/
|
10
34
|
export declare const notExists: (column: string) => Constraint<string>;
|
35
|
+
/**
|
36
|
+
* Operator to restrict results to only values that start with the given prefix.
|
37
|
+
*/
|
11
38
|
export declare const startsWith: (value: string) => Constraint<string>;
|
39
|
+
/**
|
40
|
+
* Operator to restrict results to only values that end with the given suffix.
|
41
|
+
*/
|
12
42
|
export declare const endsWith: (value: string) => Constraint<string>;
|
43
|
+
/**
|
44
|
+
* Operator to restrict results to only values that match the given pattern.
|
45
|
+
*/
|
13
46
|
export declare const pattern: (value: string) => Constraint<string>;
|
47
|
+
/**
|
48
|
+
* Operator to restrict results to only values that are equal to the given value.
|
49
|
+
*/
|
14
50
|
export declare const is: <T>(value: T) => Constraint<T>;
|
51
|
+
/**
|
52
|
+
* Operator to restrict results to only values that are not equal to the given value.
|
53
|
+
*/
|
15
54
|
export declare const isNot: <T>(value: T) => Constraint<T>;
|
55
|
+
/**
|
56
|
+
* Operator to restrict results to only values that contain the given value.
|
57
|
+
*/
|
16
58
|
export declare const contains: <T>(value: T) => Constraint<T>;
|
59
|
+
/**
|
60
|
+
* Operator to restrict results to only arrays that include the given value.
|
61
|
+
*/
|
17
62
|
export declare const includes: (value: string) => Constraint<string>;
|
63
|
+
/**
|
64
|
+
* Operator to restrict results to only arrays that include a value matching the given substring.
|
65
|
+
*/
|
18
66
|
export declare const includesSubstring: (value: string) => Constraint<string>;
|
67
|
+
/**
|
68
|
+
* Operator to restrict results to only arrays that include a value matching the given pattern.
|
69
|
+
*/
|
19
70
|
export declare const includesPattern: (value: string) => Constraint<string>;
|
20
71
|
export declare const includesAll: (value: string) => Constraint<string>;
|
21
72
|
export {};
|