@xata.io/client 0.0.0-beta.bdce130 → 0.0.0-beta.c21e40a

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.
@@ -0,0 +1,288 @@
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
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_getFetchProps, _RestRepository_insertRecordWithoutId, _RestRepository_insertRecordWithId, _BaseClient_links, _BaseClient_branch;
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
32
+ const api_1 = require("../api");
33
+ const lang_1 = require("../util/lang");
34
+ const filters_1 = require("./filters");
35
+ const pagination_1 = require("./pagination");
36
+ const query_1 = require("./query");
37
+ const record_1 = require("./record");
38
+ /**
39
+ * Common interface for performing operations on a table.
40
+ */
41
+ class Repository extends query_1.Query {
42
+ }
43
+ exports.Repository = Repository;
44
+ class RestRepository extends query_1.Query {
45
+ constructor(client, table) {
46
+ var _a;
47
+ super(null, table, {});
48
+ _RestRepository_instances.add(this);
49
+ _RestRepository_client.set(this, void 0);
50
+ _RestRepository_fetch.set(this, void 0);
51
+ _RestRepository_table.set(this, void 0);
52
+ __classPrivateFieldSet(this, _RestRepository_client, client, "f");
53
+ __classPrivateFieldSet(this, _RestRepository_table, table, "f");
54
+ // TODO: Remove when integrating with API client
55
+ const globalFetch = typeof fetch !== 'undefined' ? fetch : undefined;
56
+ const fetchImpl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch) !== null && _a !== void 0 ? _a : globalFetch;
57
+ if (!fetchImpl) {
58
+ /** @todo add a link after docs exist */
59
+ throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
60
+ }
61
+ __classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
62
+ }
63
+ create(a, b) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ if ((0, lang_1.isString)(a) && (0, lang_1.isObject)(b)) {
66
+ if (a === '')
67
+ throw new Error("The id can't be empty");
68
+ return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a, b);
69
+ }
70
+ else if ((0, lang_1.isObject)(a) && (0, lang_1.isString)(a.id)) {
71
+ if (a.id === '')
72
+ throw new Error("The id can't be empty");
73
+ return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithId).call(this, a.id, Object.assign(Object.assign({}, a), { id: undefined }));
74
+ }
75
+ else if ((0, lang_1.isObject)(a)) {
76
+ return __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_insertRecordWithoutId).call(this, a);
77
+ }
78
+ else {
79
+ throw new Error('Invalid arguments for create method');
80
+ }
81
+ });
82
+ }
83
+ createMany(objects) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
86
+ const records = objects.map((object) => transformObjectLinks(object));
87
+ const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
88
+ const finalObjects = yield this.any(...response.recordIDs.map((id) => this.filter('id', id))).getAll();
89
+ if (finalObjects.length !== objects.length) {
90
+ throw new Error('The server failed to save some records');
91
+ }
92
+ return finalObjects;
93
+ });
94
+ }
95
+ // TODO: Add column support: https://github.com/xataio/openapi/issues/139
96
+ read(recordId) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
99
+ const response = yield (0, api_1.getRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
100
+ return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
101
+ });
102
+ }
103
+ update(recordId, object) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
106
+ const record = transformObjectLinks(object);
107
+ const response = yield (0, api_1.updateRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: record }, fetchProps));
108
+ const item = yield this.read(response.id);
109
+ if (!item)
110
+ throw new Error('The server failed to save the record');
111
+ return item;
112
+ });
113
+ }
114
+ createOrUpdate(recordId, object) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
117
+ const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
118
+ const item = yield this.read(response.id);
119
+ if (!item)
120
+ throw new Error('The server failed to save the record');
121
+ return item;
122
+ });
123
+ }
124
+ delete(recordId) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
127
+ yield (0, api_1.deleteRecord)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId } }, fetchProps));
128
+ });
129
+ }
130
+ query(query) {
131
+ var _a;
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ const data = query.getQueryOptions();
134
+ const body = {
135
+ filter: Object.values((_a = data.filter) !== null && _a !== void 0 ? _a : {}).some(Boolean) ? data.filter : undefined,
136
+ sort: (0, filters_1.buildSortFilter)(data.sort),
137
+ page: data.page,
138
+ columns: data.columns
139
+ };
140
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
141
+ const { meta, records: objects } = yield (0, api_1.queryTable)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body }, fetchProps));
142
+ const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), record));
143
+ return new pagination_1.Page(query, meta, records);
144
+ });
145
+ }
146
+ }
147
+ exports.RestRepository = RestRepository;
148
+ _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap(), _RestRepository_instances = new WeakSet(), _RestRepository_getFetchProps = function _RestRepository_getFetchProps() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const branch = yield __classPrivateFieldGet(this, _RestRepository_client, "f").getBranch();
151
+ return {
152
+ fetchImpl: __classPrivateFieldGet(this, _RestRepository_fetch, "f"),
153
+ apiKey: __classPrivateFieldGet(this, _RestRepository_client, "f").options.apiKey,
154
+ apiUrl: '',
155
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
156
+ workspacesApiUrl: (path, params) => {
157
+ var _a, _b;
158
+ const baseUrl = (_a = __classPrivateFieldGet(this, _RestRepository_client, "f").options.databaseURL) !== null && _a !== void 0 ? _a : '';
159
+ const hasBranch = (_b = params.dbBranchName) !== null && _b !== void 0 ? _b : params.branch;
160
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branch}` : '');
161
+ return baseUrl + newPath;
162
+ }
163
+ };
164
+ });
165
+ }, _RestRepository_insertRecordWithoutId = function _RestRepository_insertRecordWithoutId(object) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
168
+ const record = transformObjectLinks(object);
169
+ const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
170
+ workspace: '{workspaceId}',
171
+ dbBranchName: '{dbBranch}',
172
+ tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
173
+ }, body: record }, fetchProps));
174
+ const finalObject = yield this.read(response.id);
175
+ if (!finalObject) {
176
+ throw new Error('The server failed to save the record');
177
+ }
178
+ return finalObject;
179
+ });
180
+ }, _RestRepository_insertRecordWithId = function _RestRepository_insertRecordWithId(recordId, object) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
183
+ const record = transformObjectLinks(object);
184
+ const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
185
+ workspace: '{workspaceId}',
186
+ dbBranchName: '{dbBranch}',
187
+ tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
188
+ recordId
189
+ }, body: record, queryParams: { createOnly: true } }, fetchProps));
190
+ const finalObject = yield this.read(response.id);
191
+ if (!finalObject) {
192
+ throw new Error('The server failed to save the record');
193
+ }
194
+ return finalObject;
195
+ });
196
+ };
197
+ class RestRespositoryFactory {
198
+ createRepository(client, table) {
199
+ return new RestRepository(client, table);
200
+ }
201
+ }
202
+ exports.RestRespositoryFactory = RestRespositoryFactory;
203
+ class BaseClient {
204
+ constructor(options, links = {}) {
205
+ _BaseClient_links.set(this, void 0);
206
+ _BaseClient_branch.set(this, void 0);
207
+ if (!options.databaseURL || !options.apiKey || !options.branch) {
208
+ throw new Error('Options databaseURL, apiKey and branch are required');
209
+ }
210
+ this.options = options;
211
+ __classPrivateFieldSet(this, _BaseClient_links, links, "f");
212
+ const factory = options.repositoryFactory || new RestRespositoryFactory();
213
+ this.db = new Proxy({}, {
214
+ get: (_target, prop) => {
215
+ if (typeof prop !== 'string')
216
+ throw new Error('Invalid table name');
217
+ return factory.createRepository(this, prop);
218
+ }
219
+ });
220
+ }
221
+ initObject(table, object) {
222
+ const result = {};
223
+ Object.assign(result, object);
224
+ const tableLinks = __classPrivateFieldGet(this, _BaseClient_links, "f")[table] || [];
225
+ for (const link of tableLinks) {
226
+ const [field, linkTable] = link;
227
+ const value = result[field];
228
+ if (value && (0, lang_1.isObject)(value)) {
229
+ result[field] = this.initObject(linkTable, value);
230
+ }
231
+ }
232
+ const db = this.db;
233
+ result.read = function () {
234
+ return db[table].read(result['id']);
235
+ };
236
+ result.update = function (data) {
237
+ return db[table].update(result['id'], data);
238
+ };
239
+ result.delete = function () {
240
+ return db[table].delete(result['id']);
241
+ };
242
+ for (const prop of ['read', 'update', 'delete']) {
243
+ Object.defineProperty(result, prop, { enumerable: false });
244
+ }
245
+ Object.freeze(result);
246
+ return result;
247
+ }
248
+ getBranch() {
249
+ var e_1, _a;
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ if (__classPrivateFieldGet(this, _BaseClient_branch, "f"))
252
+ return __classPrivateFieldGet(this, _BaseClient_branch, "f");
253
+ const { branch: param } = this.options;
254
+ const strategies = Array.isArray(param) ? [...param] : [param];
255
+ const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
256
+ return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
257
+ });
258
+ try {
259
+ for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
260
+ const strategy = strategies_1_1.value;
261
+ const branch = yield evaluateBranch(strategy);
262
+ if (branch) {
263
+ __classPrivateFieldSet(this, _BaseClient_branch, branch, "f");
264
+ return branch;
265
+ }
266
+ }
267
+ }
268
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
269
+ finally {
270
+ try {
271
+ if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
272
+ }
273
+ finally { if (e_1) throw e_1.error; }
274
+ }
275
+ throw new Error('Unable to resolve branch value');
276
+ });
277
+ }
278
+ }
279
+ exports.BaseClient = BaseClient;
280
+ _BaseClient_links = new WeakMap(), _BaseClient_branch = new WeakMap();
281
+ const isBranchStrategyBuilder = (strategy) => {
282
+ return typeof strategy === 'function';
283
+ };
284
+ const transformObjectLinks = (object) => {
285
+ return Object.entries(object).reduce((acc, [key, value]) => {
286
+ return Object.assign(Object.assign({}, acc), { [key]: (0, record_1.isIdentifiable)(value) ? value.id : value });
287
+ }, {});
288
+ };
@@ -1,18 +1,25 @@
1
- import { XataRecord } from '..';
2
- import { StringKeys, UnionToIntersection, Values } from '../util/types';
3
- import { Query } from './query';
4
- declare type Queries<T> = {
5
- [key in keyof T as T[key] extends Query<any> ? key : never]: T[key];
6
- };
7
- declare type OmitQueries<T> = {
8
- [key in keyof T as T[key] extends Query<any> ? never : key]: T[key];
9
- };
10
- declare type OmitMethods<T> = {
11
- [key in keyof T as T[key] extends Function ? never : key]: T[key];
12
- };
13
- export declare type Selectable<T> = Omit<OmitQueries<OmitMethods<T>>, 'id' | 'xata'>;
14
- export declare type SelectableColumn<O> = '*' | (O extends Array<unknown> ? never : O extends Record<string, any> ? '*' | Values<{
15
- [K in StringKeys<O>]: O[K] extends Record<string, any> ? `${K}.${SelectableColumn<O[K]>}` : K;
16
- }> : '');
17
- export declare type Select<T, K extends SelectableColumn<T>> = UnionToIntersection<K extends keyof T ? Pick<T, K> : T> & Queries<T> & XataRecord;
1
+ import { If, IsArray, IsObject, StringKeys, UnionToIntersection, Values } from '../util/types';
2
+ import { Link, XataRecord } from './record';
3
+ export declare type SelectableColumn<O, RecursivePath extends any[] = []> = '*' | 'id' | DataProps<O> | NestedColumns<O, RecursivePath>;
4
+ export declare type SelectedPick<O extends XataRecord, Key extends SelectableColumn<O>[]> = XataRecord & UnionToIntersection<Values<{
5
+ [K in Key[number]]: NestedValueAtColumn<O, K> & XataRecord;
6
+ }>>;
7
+ export declare type ValueAtColumn<O extends XataRecord, P extends SelectableColumn<O>> = P extends '*' ? Values<O> : P extends 'id' ? string : P extends keyof O ? O[P] : P extends `${infer K}.${infer V}` ? K extends keyof O ? Values<O[K] extends XataRecord ? (V extends SelectableColumn<O[K]> ? {
8
+ V: ValueAtColumn<O[K], V>;
9
+ } : never) : O[K]> : never : never;
10
+ declare type MAX_RECURSION = 5;
11
+ declare type NestedColumns<O, RecursivePath extends any[]> = RecursivePath['length'] extends MAX_RECURSION ? never : If<IsObject<O>, Values<{
12
+ [K in DataProps<O>]: If<IsArray<NonNullable<O[K]>>, K, // If the property is an array, we stop recursion. We don't support object arrays yet
13
+ If<IsObject<NonNullable<O[K]>>, NonNullable<O[K]> extends XataRecord ? SelectableColumn<NonNullable<O[K]>, [...RecursivePath, O[K]]> extends string ? K | `${K}.${SelectableColumn<NonNullable<O[K]>, [...RecursivePath, O[K]]>}` : never : `${K}.${StringKeys<NonNullable<O[K]>> | '*'}`, // This allows usage of objects that are not links
14
+ K>>;
15
+ }>, never>;
16
+ declare type DataProps<O> = Exclude<StringKeys<O>, StringKeys<XataRecord>>;
17
+ declare type NestedValueAtColumn<O, Key extends SelectableColumn<O>> = Key extends `${infer N}.${infer M}` ? N extends DataProps<O> ? {
18
+ [K in N]: M extends SelectableColumn<NonNullable<O[K]>> ? NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M> & XataRecord> : ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M>> : unknown;
19
+ } : unknown : Key extends DataProps<O> ? {
20
+ [K in Key]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], SelectedPick<NonNullable<O[K]>, ['*']>> : O[K];
21
+ } : Key extends '*' ? {
22
+ [K in StringKeys<O>]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], Link<NonNullable<O[K]>>> : O[K];
23
+ } : unknown;
24
+ declare type ForwardNullable<T, R> = T extends NonNullable<T> ? R : R | null;
18
25
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-floating-promises */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // SelectableColumn<O> //
5
+ // --------------------------------------------------------------------------- //
6
+ const validTeamColumns = [
7
+ '*',
8
+ 'id',
9
+ 'name',
10
+ 'owner.*',
11
+ 'owner.address.*',
12
+ 'owner.address',
13
+ 'owner.address.street'
14
+ ];
15
+ // @ts-expect-error
16
+ const invalidFullNameTeamColumn = 'full_name';
17
+ // @ts-expect-error
18
+ const invalidPartialTeamColumn = 'owner.address.';
19
+ // @ts-expect-error
20
+ const invalidDeleteTeamColumn = 'owner.delete';
21
+ // @ts-expect-error
22
+ const invalidReadTeamColumn = 'owner.read.*';
23
+ // ValueAtColumn<O, P> //
24
+ // --------------------------------------------------------------------------- //
25
+ const labelsValue = ['foo'];
26
+ // @ts-expect-error
27
+ const invalidLabelsValue = [1];
28
+ // SelectedRecordPick<O, Key> //
29
+ // ---------------------------------------------------------------------------- //
30
+ function test1(user) {
31
+ var _a, _b, _c, _d;
32
+ user.id;
33
+ user.read();
34
+ user.full_name;
35
+ (_a = user.address) === null || _a === void 0 ? void 0 : _a.street;
36
+ // @ts-expect-error
37
+ user.team.id;
38
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.id;
39
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.read();
40
+ // @ts-expect-error
41
+ (_d = user.team) === null || _d === void 0 ? void 0 : _d.name;
42
+ user.partner.id;
43
+ user.partner.read();
44
+ // @ts-expect-error
45
+ user.partner.full_name;
46
+ user.team = null;
47
+ // @ts-expect-error
48
+ user.partner = null;
49
+ }
50
+ function test2(user) {
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
52
+ user.id;
53
+ user.read();
54
+ user.full_name;
55
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
56
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
57
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
58
+ (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner;
59
+ (_f = (_e = user.team) === null || _e === void 0 ? void 0 : _e.owner) === null || _f === void 0 ? void 0 : _f.id;
60
+ (_h = (_g = user.team) === null || _g === void 0 ? void 0 : _g.owner) === null || _h === void 0 ? void 0 : _h.read();
61
+ // @ts-expect-error
62
+ (_k = (_j = user.team) === null || _j === void 0 ? void 0 : _j.owner) === null || _k === void 0 ? void 0 : _k.full_name;
63
+ // @ts-expect-error
64
+ user.full_name = null;
65
+ user.email = null;
66
+ user.email = '';
67
+ // @ts-expect-error
68
+ user.email = 2;
69
+ if (user.team) {
70
+ // @ts-expect-error
71
+ user.team.name = null;
72
+ user.team.labels = null;
73
+ user.team.labels = ['foo'];
74
+ // @ts-expect-error
75
+ user.team.labels = [1];
76
+ }
77
+ }
78
+ function test3(user) {
79
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
80
+ user.id;
81
+ user.read();
82
+ // @ts-expect-error
83
+ user.full_name;
84
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
85
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
86
+ // @ts-expect-error
87
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
88
+ (_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
89
+ (_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
90
+ (_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
91
+ }
92
+ function test4(user) {
93
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
94
+ user.id;
95
+ user.read();
96
+ // @ts-expect-error
97
+ user.full_name;
98
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
99
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
100
+ // @ts-expect-error
101
+ (_c = user.team) === null || _c === void 0 ? void 0 : _c.name;
102
+ (_e = (_d = user.team) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.id;
103
+ (_g = (_f = user.team) === null || _f === void 0 ? void 0 : _f.owner) === null || _g === void 0 ? void 0 : _g.read();
104
+ // @ts-expect-error
105
+ (_j = (_h = user.team) === null || _h === void 0 ? void 0 : _h.owner) === null || _j === void 0 ? void 0 : _j.full_name;
106
+ (_l = (_k = user.team) === null || _k === void 0 ? void 0 : _k.owner) === null || _l === void 0 ? void 0 : _l.address;
107
+ (_p = (_o = (_m = user.team) === null || _m === void 0 ? void 0 : _m.owner) === null || _o === void 0 ? void 0 : _o.address) === null || _p === void 0 ? void 0 : _p.street;
108
+ (_s = (_r = (_q = user.team) === null || _q === void 0 ? void 0 : _q.owner) === null || _r === void 0 ? void 0 : _r.address) === null || _s === void 0 ? void 0 : _s.zipcode;
109
+ }
110
+ function test5(user) {
111
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
112
+ user.id;
113
+ user.read();
114
+ // @ts-expect-error
115
+ user.full_name;
116
+ user.settings;
117
+ (_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
118
+ (_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
119
+ (_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
120
+ (_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
121
+ (_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
122
+ // @ts-expect-error
123
+ (_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
124
+ // @ts-expect-error
125
+ (_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
126
+ // @ts-expect-error
127
+ (_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
128
+ user.settings = null;
129
+ user.nonNullable.nested.value = 2;
130
+ // @ts-expect-error
131
+ user.nonNullable = null;
132
+ // @ts-expect-error
133
+ user.nonNullable.nested.value = null;
134
+ }
135
+ function test6(user) {
136
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
137
+ user.id;
138
+ user.read();
139
+ // @ts-expect-error
140
+ user.full_name;
141
+ user.settings;
142
+ (_a = user.settings) === null || _a === void 0 ? void 0 : _a.theme;
143
+ (_b = user.settings) === null || _b === void 0 ? void 0 : _b.language;
144
+ (_c = user.settings) === null || _c === void 0 ? void 0 : _c.signin;
145
+ (_e = (_d = user.settings) === null || _d === void 0 ? void 0 : _d.signin) === null || _e === void 0 ? void 0 : _e.email;
146
+ (_g = (_f = user.settings) === null || _f === void 0 ? void 0 : _f.signin) === null || _g === void 0 ? void 0 : _g.github;
147
+ // @ts-expect-error
148
+ (_h = user.settings) === null || _h === void 0 ? void 0 : _h.id;
149
+ // @ts-expect-error
150
+ (_j = user.settings) === null || _j === void 0 ? void 0 : _j.read();
151
+ // @ts-expect-error
152
+ (_l = (_k = user.settings) === null || _k === void 0 ? void 0 : _k.signin) === null || _l === void 0 ? void 0 : _l.id;
153
+ user.nonNullable.nested.value = 2;
154
+ user.nonNullable.nested.deep.depths.of.numbers = [1, 2, 3];
155
+ // @ts-expect-error
156
+ user.nonNullable.nested.deep.depths.of.numbers = 'invalid-string';
157
+ user.settings = null;
158
+ // @ts-expect-error
159
+ user.nonNullable = null;
160
+ // @ts-expect-error
161
+ user.nonNullable.nested.value = null;
162
+ }
163
+ function test7(user) {
164
+ var _a, _b;
165
+ user.partner;
166
+ user.partner.id;
167
+ user.partner.read();
168
+ user.partner.full_name;
169
+ // @ts-expect-error
170
+ user.partner.full_name = null;
171
+ user.partner.address;
172
+ // @ts-expect-error
173
+ user.team.id;
174
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
175
+ // @ts-expect-error
176
+ user.team.read();
177
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
178
+ // @ts-expect-error
179
+ user.partner = null;
180
+ user.team = null;
181
+ }
182
+ function test8(user) {
183
+ var _a, _b;
184
+ user.partner;
185
+ user.partner.id;
186
+ user.partner.read();
187
+ user.partner.full_name;
188
+ // @ts-expect-error
189
+ user.partner.full_name = null;
190
+ user.partner.address;
191
+ // @ts-expect-error
192
+ user.team.id;
193
+ (_a = user.team) === null || _a === void 0 ? void 0 : _a.id;
194
+ // @ts-expect-error
195
+ user.team.read();
196
+ (_b = user.team) === null || _b === void 0 ? void 0 : _b.read();
197
+ // @ts-expect-error
198
+ user.partner = null;
199
+ user.team = null;
200
+ }
201
+ test('fake test', () => {
202
+ // This is a fake test to make sure that the type definitions in this file are working
203
+ });
@@ -1 +1,5 @@
1
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 object;
5
+ export declare function isString(value: any): value is string;
package/dist/util/lang.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compact = void 0;
3
+ exports.isString = exports.isObject = exports.compactObject = exports.compact = void 0;
4
4
  function notEmpty(value) {
5
5
  return value !== null && value !== undefined;
6
6
  }
@@ -8,3 +8,15 @@ function compact(arr) {
8
8
  return arr.filter(notEmpty);
9
9
  }
10
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 value !== undefined && value !== null && typeof value === 'object';
17
+ }
18
+ exports.isObject = isObject;
19
+ function isString(value) {
20
+ return value !== undefined && value !== null && typeof value === 'string';
21
+ }
22
+ exports.isString = isString;
@@ -1,3 +1,13 @@
1
1
  export declare type StringKeys<O> = Extract<keyof O, string>;
2
- export declare type Values<O> = O[keyof O];
2
+ export declare type NumberKeys<O> = Extract<keyof O, number>;
3
+ export declare type Values<O> = O[StringKeys<O>];
3
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-beta.bdce130",
3
+ "version": "0.0.0-beta.c21e40a",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -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": "bdce13039afb849ef27e24f3e79de7798204d75a"
23
+ "gitHead": "c21e40af09635fa25df211e8c4840a6da6117fe3"
24
24
  }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "lib": ["dom", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "esModuleInterop": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "strict": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "module": "CommonJS",
13
+ "moduleResolution": "node",
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "noEmit": false,
17
+ "outDir": "dist",
18
+ "declaration": true
19
+ },
20
+ "include": ["src"]
21
+ }