@xata.io/client 0.0.0-alpha.f12226f → 0.0.0-beta.103e462

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 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
@@ -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
  };
@@ -1,12 +1,17 @@
1
1
  import { Selectable } from './selection';
2
2
  /**
3
- * Represents a persisted record from the database.
3
+ * Represents an identifiable record from the database.
4
4
  */
5
- export interface XataRecord {
5
+ export interface Identifiable {
6
6
  /**
7
7
  * Unique id of this record.
8
8
  */
9
9
  id: string;
10
+ }
11
+ /**
12
+ * Represents a persisted record from the database.
13
+ */
14
+ export interface XataRecord extends Identifiable {
10
15
  /**
11
16
  * Metadata of this record.
12
17
  */
@@ -26,6 +26,13 @@ export declare abstract class Repository<T extends XataRecord> extends Query<T>
26
26
  * @returns The persisted record for the given id or null if the record could not be found.
27
27
  */
28
28
  abstract read(id: string): Promise<T | null>;
29
+ /**
30
+ * Insert a single record with a unique id.
31
+ * @param id The unique id.
32
+ * @param object Object containing the column names with their values to be stored in the table.
33
+ * @returns The full persisted record.
34
+ */
35
+ abstract insert(id: string, object: Selectable<T>): Promise<T>;
29
36
  /**
30
37
  * Partially update a single record given its unique id.
31
38
  * @param id The unique id.
@@ -34,13 +41,13 @@ export declare abstract class Repository<T extends XataRecord> extends Query<T>
34
41
  */
35
42
  abstract update(id: string, object: Partial<Selectable<T>>): Promise<T>;
36
43
  /**
37
- * Updates or creates a single record. If a record exists with the given id,
44
+ * Updates or inserts a single record. If a record exists with the given id,
38
45
  * it will be update, otherwise a new record will be created.
39
46
  * @param id A unique id.
40
47
  * @param object The column names and the values to be persisted.
41
48
  * @returns The full persisted record.
42
49
  */
43
- abstract upsert(id: string, object: Selectable<T>): Promise<T>;
50
+ abstract updateOrInsert(id: string, object: Selectable<T>): Promise<T>;
44
51
  /**
45
52
  * Deletes a record given its unique id.
46
53
  * @param id The unique id.
@@ -59,7 +66,7 @@ export declare class RestRepository<T extends XataRecord> extends Repository<T>
59
66
  read(recordId: string): Promise<T | null>;
60
67
  update(recordId: string, object: Partial<Selectable<T>>): Promise<T>;
61
68
  insert(recordId: string, object: Selectable<T>): Promise<T>;
62
- upsert(recordId: string, object: Selectable<T>): Promise<T>;
69
+ updateOrInsert(recordId: string, object: Selectable<T>): Promise<T>;
63
70
  delete(recordId: string): Promise<void>;
64
71
  query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options?: Options): Promise<Page<T, typeof options extends {
65
72
  columns: SelectableColumn<T>[];
@@ -76,10 +76,9 @@ class RestRepository extends Repository {
76
76
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
77
77
  const records = objects.map((object) => transformObjectLinks(object));
78
78
  const response = yield (0, api_1.bulkInsertTableRecords)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f") }, body: { records } }, fetchProps));
79
- // TODO: Use filer.$any() to get all the records
80
- const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
81
- if (finalObjects.some((object) => !object)) {
82
- throw new Error('The server failed to save the record');
79
+ const finalObjects = yield this.any(...response.recordIDs.map((id) => this.filter('id', id))).getMany();
80
+ if (finalObjects.length !== objects.length) {
81
+ throw new Error('The server failed to save some records');
83
82
  }
84
83
  return finalObjects;
85
84
  });
@@ -118,7 +117,7 @@ class RestRepository extends Repository {
118
117
  return finalObject;
119
118
  });
120
119
  }
121
- upsert(recordId, object) {
120
+ updateOrInsert(recordId, object) {
122
121
  return __awaiter(this, void 0, void 0, function* () {
123
122
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
124
123
  const response = yield (0, api_1.upsertRecordWithID)(Object.assign({ pathParams: { workspace: '{workspaceId}', dbBranchName: '{dbBranch}', tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"), recordId }, body: object }, fetchProps));
@@ -1,11 +1,12 @@
1
1
  import { XataRecord } from '..';
2
2
  import { StringKeys, UnionToIntersection, Values } from '../util/types';
3
3
  import { Query } from './query';
4
+ import { Identifiable } from './record';
4
5
  declare type Queries<T> = {
5
6
  [key in keyof T as T[key] extends Query<any> ? key : never]: T[key];
6
7
  };
7
8
  declare type InternalProperties = keyof XataRecord;
8
- export declare type Selectable<T extends XataRecord> = Omit<T, InternalProperties>;
9
+ export declare type Selectable<T extends XataRecord> = Omit<T, InternalProperties> & Identifiable;
9
10
  export declare type SelectableColumn<O> = '*' | (O extends Array<unknown> ? never : O extends Record<string, any> ? '*' | Values<{
10
11
  [K in StringKeys<O>]: O[K] extends Record<string, any> ? `${K}.${SelectableColumn<O[K]>}` : K;
11
12
  }> : '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-alpha.f12226f",
3
+ "version": "0.0.0-beta.103e462",
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": "f12226f10cc4c648b3e1ffe6ca258e665570ee2c"
23
+ "gitHead": "103e46248cb25543e29be8405a122762109a4b0f"
24
24
  }