@xata.io/client 0.0.0-beta.123dd7a → 0.0.0-beta.14375f7

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.
Files changed (58) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +63 -0
  3. package/dist/api/client.d.ts +95 -0
  4. package/dist/api/client.js +238 -0
  5. package/dist/api/components.d.ts +1437 -0
  6. package/dist/api/components.js +998 -0
  7. package/dist/api/fetcher.d.ts +40 -0
  8. package/dist/api/fetcher.js +79 -0
  9. package/dist/api/index.d.ts +7 -0
  10. package/dist/api/index.js +21 -0
  11. package/dist/api/parameters.d.ts +16 -0
  12. package/dist/api/parameters.js +2 -0
  13. package/dist/api/providers.d.ts +8 -0
  14. package/dist/api/providers.js +30 -0
  15. package/dist/api/responses.d.ts +50 -0
  16. package/dist/api/responses.js +2 -0
  17. package/dist/api/schemas.d.ts +311 -0
  18. package/dist/api/schemas.js +2 -0
  19. package/dist/index.d.ts +2 -133
  20. package/dist/index.js +16 -368
  21. package/dist/schema/config.d.ts +4 -0
  22. package/dist/schema/config.js +83 -0
  23. package/dist/schema/filters.d.ts +96 -0
  24. package/dist/schema/filters.js +2 -0
  25. package/dist/{index.test.d.ts → schema/filters.spec.d.ts} +0 -0
  26. package/dist/schema/filters.spec.js +175 -0
  27. package/dist/schema/index.d.ts +7 -0
  28. package/dist/schema/index.js +29 -0
  29. package/dist/schema/operators.d.ts +74 -0
  30. package/dist/schema/operators.js +93 -0
  31. package/dist/schema/pagination.d.ts +83 -0
  32. package/dist/schema/pagination.js +93 -0
  33. package/dist/schema/query.d.ts +118 -0
  34. package/dist/schema/query.js +242 -0
  35. package/dist/schema/record.d.ts +66 -0
  36. package/dist/schema/record.js +13 -0
  37. package/dist/schema/repository.d.ts +148 -0
  38. package/dist/schema/repository.js +381 -0
  39. package/dist/schema/selection.d.ts +25 -0
  40. package/dist/schema/selection.js +2 -0
  41. package/dist/schema/selection.spec.d.ts +1 -0
  42. package/dist/schema/selection.spec.js +203 -0
  43. package/dist/schema/sorting.d.ts +17 -0
  44. package/dist/schema/sorting.js +28 -0
  45. package/dist/schema/sorting.spec.d.ts +1 -0
  46. package/dist/schema/sorting.spec.js +9 -0
  47. package/dist/util/environment.d.ts +5 -0
  48. package/dist/util/environment.js +68 -0
  49. package/dist/util/fetch.d.ts +2 -0
  50. package/dist/util/fetch.js +13 -0
  51. package/dist/util/lang.d.ts +5 -0
  52. package/dist/util/lang.js +22 -0
  53. package/dist/util/types.d.ts +24 -0
  54. package/dist/util/types.js +2 -0
  55. package/package.json +3 -3
  56. package/dist/index.test.js +0 -304
  57. package/src/index.test.ts +0 -392
  58. package/src/index.ts +0 -506
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Simple sorting
4
+ const simpleSorting = { name: 'asc' };
5
+ // Array of simple sorting
6
+ const arrayOfSimpleSorting = [{ name: 'asc' }, { age: 'desc' }];
7
+ test('fake test', () => {
8
+ // This is a fake test to make sure that the type definitions in this file are working
9
+ });
@@ -0,0 +1,5 @@
1
+ /// <reference path="../../src/types/global-node.d.ts" />
2
+ /// <reference path="../../src/types/global-variables.d.ts" />
3
+ /// <reference path="../../src/types/global-deno.d.ts" />
4
+ export declare function getEnvVariable(name: string): string | undefined;
5
+ export declare function getGitBranch(): Promise<string | undefined>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
3
+ ///<reference path="../types/global-node.d.ts"/>
4
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
5
+ ///<reference path="../types/global-variables.d.ts"/>
6
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
7
+ ///<reference path="../types/global-deno.d.ts"/>
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.getGitBranch = exports.getEnvVariable = void 0;
19
+ const lang_1 = require("./lang");
20
+ function getEnvVariable(name) {
21
+ var _a, _b;
22
+ // Node.js: process.env
23
+ try {
24
+ if ((0, lang_1.isObject)(process) && (0, lang_1.isString)((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[name])) {
25
+ return process.env[name];
26
+ }
27
+ }
28
+ catch (err) {
29
+ // Ignore: Should never happen
30
+ }
31
+ try {
32
+ // Deno: Deno.env.get
33
+ if ((0, lang_1.isObject)(Deno) && (0, lang_1.isString)((_b = Deno === null || Deno === void 0 ? void 0 : Deno.env) === null || _b === void 0 ? void 0 : _b.get(name))) {
34
+ return Deno.env.get(name);
35
+ }
36
+ }
37
+ catch (err) {
38
+ // Ignore: Will fail if not using --allow-env
39
+ }
40
+ }
41
+ exports.getEnvVariable = getEnvVariable;
42
+ function getGitBranch() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ // Node.js: child_process.execSync
45
+ try {
46
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
47
+ return require('child_process').execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
48
+ }
49
+ catch (err) {
50
+ // Ignore
51
+ }
52
+ // Deno: Deno.run
53
+ try {
54
+ if ((0, lang_1.isObject)(Deno)) {
55
+ const process = Deno.run({
56
+ cmd: ['git', 'branch', '--show-current'],
57
+ stdout: 'piped',
58
+ stderr: 'piped'
59
+ });
60
+ return new TextDecoder().decode(yield process.output()).trim();
61
+ }
62
+ }
63
+ catch (err) {
64
+ // Ignore: Will fail if not using --allow-run
65
+ }
66
+ });
67
+ }
68
+ exports.getGitBranch = getGitBranch;
@@ -0,0 +1,2 @@
1
+ import { FetchImpl } from '../api/fetcher';
2
+ export declare function getFetchImplementation(userFetch?: FetchImpl): FetchImpl | typeof fetch;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFetchImplementation = void 0;
4
+ function getFetchImplementation(userFetch) {
5
+ const globalFetch = typeof fetch !== 'undefined' ? fetch : undefined;
6
+ const fetchImpl = userFetch !== null && userFetch !== void 0 ? userFetch : globalFetch;
7
+ if (!fetchImpl) {
8
+ /** @todo add a link after docs exist */
9
+ throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
10
+ }
11
+ return fetchImpl;
12
+ }
13
+ exports.getFetchImplementation = getFetchImplementation;
@@ -0,0 +1,5 @@
1
+ export declare function compact<T>(arr: Array<T | null | undefined>): T[];
2
+ export declare function compactObject<T>(obj: Record<string, T | null | undefined>): Record<string, T>;
3
+ export declare type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4
+ export declare function isObject(value: any): value is Record<string, unknown>;
5
+ export declare function isString(value: any): value is string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isString = exports.isObject = exports.compactObject = exports.compact = void 0;
4
+ function notEmpty(value) {
5
+ return value !== null && value !== undefined;
6
+ }
7
+ function compact(arr) {
8
+ return arr.filter(notEmpty);
9
+ }
10
+ exports.compact = compact;
11
+ function compactObject(obj) {
12
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
13
+ }
14
+ exports.compactObject = compactObject;
15
+ function isObject(value) {
16
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
17
+ }
18
+ exports.isObject = isObject;
19
+ function isString(value) {
20
+ return value !== undefined && value !== null && typeof value === 'string';
21
+ }
22
+ exports.isString = isString;
@@ -0,0 +1,24 @@
1
+ export declare type StringKeys<O> = Extract<keyof O, string>;
2
+ export declare type NumberKeys<O> = Extract<keyof O, number>;
3
+ export declare type Values<O> = O[StringKeys<O>];
4
+ export declare type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
5
+ export declare type If<Condition, Then, Else> = Condition extends true ? Then : Else;
6
+ export declare type IsObject<T> = T extends Record<string, any> ? true : false;
7
+ export declare type IsArray<T> = T extends Array<any> ? true : false;
8
+ export declare type NonEmptyArray<T> = T[] & {
9
+ 0: T;
10
+ };
11
+ export declare type RequiredBy<T, K extends keyof T> = T & {
12
+ [P in K]-?: NonNullable<T[P]>;
13
+ };
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]>;
17
+ };
18
+ export declare type KeysOfUnion<T> = T extends T ? keyof T : never;
19
+ declare type Impossible<K extends keyof any> = {
20
+ [P in K]: never;
21
+ };
22
+ export declare type Exactly<T, U extends T = T> = U & Impossible<Exclude<keyof U, keyof T>>;
23
+ export declare type SingleOrArray<T> = T | T[];
24
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-beta.123dd7a",
3
+ "version": "0.0.0-beta.14375f7",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "tsc",
9
+ "build": "tsc -p tsconfig.build.json",
10
10
  "prepack": "npm run build"
11
11
  },
12
12
  "repository": {
@@ -20,5 +20,5 @@
20
20
  "url": "https://github.com/xataio/client-ts/issues"
21
21
  },
22
22
  "homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
23
- "gitHead": "123dd7a5eb1a79e75fd18921d67310c4bf277237"
23
+ "gitHead": "14375f77d57bc1bc99b477a30dcde1d9d84b054d"
24
24
  }
@@ -1,304 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const _1 = require("./");
13
- const buildClient = (options = {}) => {
14
- const { apiKey = '1234', databaseURL = 'https://my-workspace-5df34do.staging.xatabase.co/db/xata', branch = 'main' } = options;
15
- const fetch = jest.fn();
16
- const client = new _1.BaseClient({ fetch, apiKey, databaseURL, branch }, {});
17
- const users = new _1.RestRepository(client, 'users');
18
- return { fetch, client, users };
19
- };
20
- describe('client options', () => {
21
- test('option parameters are set', () => {
22
- const { client } = buildClient({ apiKey: 'apiKey', databaseURL: 'url' });
23
- expect(client.options.apiKey).toBe('apiKey');
24
- expect(client.options.databaseURL).toBe('url');
25
- });
26
- test('throws if mandatory options are missing', () => {
27
- // @ts-expect-error Options are mandatory in TypeScript
28
- expect(() => buildClient({ apiKey: null }, {})).toThrow('Options databaseURL, apiKey and branch are required');
29
- // @ts-expect-error Options are mandatory in TypeScript
30
- expect(() => buildClient({ databaseURL: null }, {})).toThrow('Options databaseURL, apiKey and branch are required');
31
- // @ts-expect-error Options are mandatory in TypeScript
32
- expect(() => buildClient({ branch: null }, {})).toThrow('Options databaseURL, apiKey and branch are required');
33
- });
34
- test('throws if branch cannot be resolved', () => {
35
- const { users } = buildClient({ branch: () => null });
36
- expect(users.request('GET', '/foo')).rejects.toThrow('Unable to resolve branch value');
37
- });
38
- test('provide branch as a string', () => __awaiter(void 0, void 0, void 0, function* () {
39
- const { fetch, users } = buildClient({ branch: 'branch' });
40
- fetch.mockReset().mockImplementation(() => {
41
- return {
42
- ok: true,
43
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); })
44
- };
45
- });
46
- yield users.request('GET', '/foo');
47
- expect(fetch).toHaveBeenCalledTimes(1);
48
- expect(fetch.mock.calls[0]).toMatchInlineSnapshot(`
49
- Array [
50
- "https://my-workspace-5df34do.staging.xatabase.co/db/xata:branch/foo",
51
- Object {
52
- "body": undefined,
53
- "headers": Object {
54
- "Accept": "*/*",
55
- "Authorization": "Bearer 1234",
56
- "Content-Type": "application/json",
57
- },
58
- "method": "GET",
59
- },
60
- ]
61
- `);
62
- }));
63
- test('provide branch as an array', () => __awaiter(void 0, void 0, void 0, function* () {
64
- const { fetch, users } = buildClient({
65
- branch: [process.env.NOT_DEFINED_VARIABLE, () => __awaiter(void 0, void 0, void 0, function* () { return null; }), 'branch', 'main']
66
- });
67
- fetch.mockReset().mockImplementation(() => {
68
- return {
69
- ok: true,
70
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); })
71
- };
72
- });
73
- yield users.request('GET', '/foo');
74
- expect(fetch).toHaveBeenCalledTimes(1);
75
- expect(fetch.mock.calls[0]).toMatchInlineSnapshot(`
76
- Array [
77
- "https://my-workspace-5df34do.staging.xatabase.co/db/xata:branch/foo",
78
- Object {
79
- "body": undefined,
80
- "headers": Object {
81
- "Accept": "*/*",
82
- "Authorization": "Bearer 1234",
83
- "Content-Type": "application/json",
84
- },
85
- "method": "GET",
86
- },
87
- ]
88
- `);
89
- }));
90
- test('provide branch as a function', () => __awaiter(void 0, void 0, void 0, function* () {
91
- const { fetch, users } = buildClient({ branch: () => 'branch' });
92
- fetch.mockReset().mockImplementation(() => {
93
- return {
94
- ok: true,
95
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); })
96
- };
97
- });
98
- yield users.request('GET', '/foo');
99
- expect(fetch).toHaveBeenCalledTimes(1);
100
- expect(fetch.mock.calls[0]).toMatchInlineSnapshot(`
101
- Array [
102
- "https://my-workspace-5df34do.staging.xatabase.co/db/xata:branch/foo",
103
- Object {
104
- "body": undefined,
105
- "headers": Object {
106
- "Accept": "*/*",
107
- "Authorization": "Bearer 1234",
108
- "Content-Type": "application/json",
109
- },
110
- "method": "GET",
111
- },
112
- ]
113
- `);
114
- }));
115
- test('ensure branch resolution is memoized', () => __awaiter(void 0, void 0, void 0, function* () {
116
- const branchGetter = jest.fn(() => 'branch');
117
- const { fetch, users } = buildClient({ branch: branchGetter });
118
- fetch.mockReset().mockImplementation(() => {
119
- return {
120
- ok: true,
121
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); })
122
- };
123
- });
124
- yield users.request('GET', '/foo');
125
- yield users.request('GET', '/foo');
126
- expect(branchGetter).toHaveBeenCalledTimes(1);
127
- }));
128
- });
129
- describe('request', () => {
130
- test('builds the right arguments for a GET request', () => __awaiter(void 0, void 0, void 0, function* () {
131
- const { fetch, users } = buildClient();
132
- fetch.mockReset().mockImplementation(() => {
133
- return {
134
- ok: true,
135
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); })
136
- };
137
- });
138
- yield users.request('GET', '/foo');
139
- expect(fetch).toHaveBeenCalledTimes(1);
140
- expect(fetch.mock.calls[0]).toMatchInlineSnapshot(`
141
- Array [
142
- "https://my-workspace-5df34do.staging.xatabase.co/db/xata:main/foo",
143
- Object {
144
- "body": undefined,
145
- "headers": Object {
146
- "Accept": "*/*",
147
- "Authorization": "Bearer 1234",
148
- "Content-Type": "application/json",
149
- },
150
- "method": "GET",
151
- },
152
- ]
153
- `);
154
- }));
155
- test('builds the right arguments for a POST request', () => __awaiter(void 0, void 0, void 0, function* () {
156
- const { fetch, users } = buildClient();
157
- fetch.mockReset().mockImplementation(() => {
158
- return {
159
- ok: true,
160
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({}); })
161
- };
162
- });
163
- yield users.request('POST', '/foo', { a: 1 });
164
- expect(fetch).toHaveBeenCalledTimes(1);
165
- expect(fetch.mock.calls[0]).toMatchInlineSnapshot(`
166
- Array [
167
- "https://my-workspace-5df34do.staging.xatabase.co/db/xata:main/foo",
168
- Object {
169
- "body": "{\\"a\\":1}",
170
- "headers": Object {
171
- "Accept": "*/*",
172
- "Authorization": "Bearer 1234",
173
- "Content-Type": "application/json",
174
- },
175
- "method": "POST",
176
- },
177
- ]
178
- `);
179
- }));
180
- test('throws if the response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
181
- const { fetch, users } = buildClient();
182
- fetch.mockImplementation(() => {
183
- return {
184
- ok: false,
185
- status: 404,
186
- statusText: 'Not Found'
187
- };
188
- });
189
- expect(users.request('GET', '/foo')).rejects.toThrow(new _1.XataError('Not Found', 404));
190
- }));
191
- test('throws with the error from the server if the response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
192
- const { fetch, users } = buildClient();
193
- fetch.mockImplementation(() => {
194
- return {
195
- ok: false,
196
- status: 404,
197
- statusText: 'Not Found',
198
- json: () => __awaiter(void 0, void 0, void 0, function* () { return ({ message: 'Resource not found' }); })
199
- };
200
- });
201
- expect(users.request('GET', '/foo')).rejects.toThrow(new _1.XataError('Resource not found', 404));
202
- }));
203
- test('returns the json body if the response is ok', () => __awaiter(void 0, void 0, void 0, function* () {
204
- const { fetch, users } = buildClient();
205
- const json = { a: 1 };
206
- fetch.mockImplementation(() => {
207
- return {
208
- ok: true,
209
- json: () => __awaiter(void 0, void 0, void 0, function* () { return json; })
210
- };
211
- });
212
- const result = yield users.request('GET', '/foo');
213
- expect(result).toEqual(json);
214
- }));
215
- });
216
- function expectRequest(users, expectedRequest, callback, response) {
217
- return __awaiter(this, void 0, void 0, function* () {
218
- const request = jest.fn(() => __awaiter(this, void 0, void 0, function* () { return response; }));
219
- users.request = request;
220
- yield callback();
221
- const { calls } = request.mock;
222
- expect(calls.length).toBe(1);
223
- const [method, path, body] = calls[0];
224
- expect(method).toBe(expectedRequest.method);
225
- expect(path).toBe(expectedRequest.path);
226
- expect(JSON.stringify(body)).toBe(JSON.stringify(expectedRequest.body));
227
- });
228
- }
229
- describe('query', () => {
230
- describe('getMany', () => {
231
- test('simple query', () => __awaiter(void 0, void 0, void 0, function* () {
232
- const { users } = buildClient();
233
- const expected = { method: 'POST', path: '/tables/users/query', body: {} };
234
- expectRequest(users, expected, () => users.getMany(), { records: [] });
235
- }));
236
- test('query with one filter', () => __awaiter(void 0, void 0, void 0, function* () {
237
- const { users } = buildClient();
238
- const expected = { method: 'POST', path: '/tables/users/query', body: { filter: { $all: [{ name: 'foo' }] } } };
239
- expectRequest(users, expected, () => users.filter('name', 'foo').getMany(), { records: [] });
240
- }));
241
- });
242
- describe('getOne', () => {
243
- test('returns a single object', () => __awaiter(void 0, void 0, void 0, function* () {
244
- const { users } = buildClient();
245
- const result = { records: [{ id: '1234' }] };
246
- const expected = { method: 'POST', path: '/tables/users/query', body: {} };
247
- expectRequest(users, expected, () => __awaiter(void 0, void 0, void 0, function* () {
248
- const first = yield users.select().getOne();
249
- expect(first === null || first === void 0 ? void 0 : first.id).toBe(result.records[0].id);
250
- }), result);
251
- }));
252
- test('returns null if no objects are returned', () => __awaiter(void 0, void 0, void 0, function* () {
253
- const { users } = buildClient();
254
- const result = { records: [] };
255
- const expected = { method: 'POST', path: '/tables/users/query', body: {} };
256
- expectRequest(users, expected, () => __awaiter(void 0, void 0, void 0, function* () {
257
- const first = yield users.getOne();
258
- expect(first).toBeNull();
259
- }), result);
260
- }));
261
- });
262
- });
263
- describe('read', () => {
264
- test('reads an object by id successfully', () => __awaiter(void 0, void 0, void 0, function* () {
265
- const { users } = buildClient();
266
- const id = 'rec_1234';
267
- const expected = { method: 'GET', path: `/tables/users/data/${id}`, body: undefined };
268
- expectRequest(users, expected, () => users.read(id));
269
- }));
270
- });
271
- describe('Repository.update', () => {
272
- test('updates and object successfully', () => __awaiter(void 0, void 0, void 0, function* () {
273
- const { users } = buildClient();
274
- const object = { id: 'rec_1234', xata: { version: 1 }, name: 'Ada' };
275
- const expected = { method: 'PUT', path: `/tables/users/data/${object.id}`, body: object };
276
- expectRequest(users, expected, () => __awaiter(void 0, void 0, void 0, function* () {
277
- const result = yield users.update(object.id, object);
278
- expect(result.id).toBe(object.id);
279
- }), { id: object.id });
280
- }));
281
- });
282
- describe('Repository.delete', () => {
283
- test('deletes a record by id successfully', () => __awaiter(void 0, void 0, void 0, function* () {
284
- const { users } = buildClient();
285
- const id = 'rec_1234';
286
- const expected = { method: 'DELETE', path: `/tables/users/data/${id}`, body: undefined };
287
- expectRequest(users, expected, () => __awaiter(void 0, void 0, void 0, function* () {
288
- const result = yield users.delete(id);
289
- expect(result).toBe(undefined);
290
- }));
291
- }));
292
- });
293
- describe('create', () => {
294
- test('successful', () => __awaiter(void 0, void 0, void 0, function* () {
295
- const { users } = buildClient();
296
- const created = { id: 'rec_1234', _version: 0 };
297
- const object = { name: 'Ada' };
298
- const expected = { method: 'POST', path: '/tables/users/data', body: object };
299
- expectRequest(users, expected, () => __awaiter(void 0, void 0, void 0, function* () {
300
- const result = yield users.create(object);
301
- expect(result.id).toBe(created.id);
302
- }), created);
303
- }));
304
- });