@xata.io/client 0.0.0-beta.9ac2bdc → 0.0.0-beta.a500a21

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.
@@ -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.
@@ -58,7 +65,8 @@ export declare class RestRepository<T extends XataRecord> extends Repository<T>
58
65
  createMany(objects: T[]): Promise<T[]>;
59
66
  read(recordId: string): Promise<T | null>;
60
67
  update(recordId: string, object: Partial<Selectable<T>>): Promise<T>;
61
- upsert(recordId: string, object: Selectable<T>): Promise<T>;
68
+ insert(recordId: string, object: Selectable<T>): Promise<T>;
69
+ updateOrInsert(recordId: string, object: Selectable<T>): Promise<T>;
62
70
  delete(recordId: string): Promise<void>;
63
71
  query<R extends XataRecord, Options extends QueryOptions<T>>(query: Query<T, R>, options?: Options): Promise<Page<T, typeof options extends {
64
72
  columns: SelectableColumn<T>[];
@@ -59,18 +59,11 @@ class RestRepository extends Repository {
59
59
  return __awaiter(this, void 0, void 0, function* () {
60
60
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
61
61
  const record = transformObjectLinks(object);
62
- const response = object.id
63
- ? yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
64
- workspace: '{workspaceId}',
65
- dbBranchName: '{dbBranch}',
66
- tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
67
- recordId: object.id
68
- }, body: record }, fetchProps))
69
- : yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
70
- workspace: '{workspaceId}',
71
- dbBranchName: '{dbBranch}',
72
- tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
73
- }, body: record }, fetchProps));
62
+ const response = yield (0, api_1.insertRecord)(Object.assign({ pathParams: {
63
+ workspace: '{workspaceId}',
64
+ dbBranchName: '{dbBranch}',
65
+ tableName: __classPrivateFieldGet(this, _RestRepository_table, "f")
66
+ }, body: record }, fetchProps));
74
67
  const finalObject = yield this.read(response.id);
75
68
  if (!finalObject) {
76
69
  throw new Error('The server failed to save the record');
@@ -108,7 +101,24 @@ class RestRepository extends Repository {
108
101
  return item;
109
102
  });
110
103
  }
111
- upsert(recordId, object) {
104
+ insert(recordId, object) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
107
+ const record = transformObjectLinks(object);
108
+ const response = yield (0, api_1.insertRecordWithID)(Object.assign({ pathParams: {
109
+ workspace: '{workspaceId}',
110
+ dbBranchName: '{dbBranch}',
111
+ tableName: __classPrivateFieldGet(this, _RestRepository_table, "f"),
112
+ recordId
113
+ }, body: record }, fetchProps));
114
+ const finalObject = yield this.read(response.id);
115
+ if (!finalObject) {
116
+ throw new Error('The server failed to save the record');
117
+ }
118
+ return finalObject;
119
+ });
120
+ }
121
+ updateOrInsert(recordId, object) {
112
122
  return __awaiter(this, void 0, void 0, function* () {
113
123
  const fetchProps = yield __classPrivateFieldGet(this, _RestRepository_instances, "m", _RestRepository_getFetchProps).call(this);
114
124
  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,12 +1,11 @@
1
1
  import { XataRecord } from '..';
2
- import { PartialBy } from '../util/lang';
3
2
  import { StringKeys, UnionToIntersection, Values } from '../util/types';
4
3
  import { Query } from './query';
5
4
  declare type Queries<T> = {
6
5
  [key in keyof T as T[key] extends Query<any> ? key : never]: T[key];
7
6
  };
8
- declare type InternalProperties = keyof Omit<XataRecord, 'id'>;
9
- export declare type Selectable<T extends XataRecord> = Omit<PartialBy<T, 'id'>, InternalProperties>;
7
+ declare type InternalProperties = keyof XataRecord;
8
+ export declare type Selectable<T extends XataRecord> = Omit<T, InternalProperties>;
10
9
  export declare type SelectableColumn<O> = '*' | (O extends Array<unknown> ? never : O extends Record<string, any> ? '*' | Values<{
11
10
  [K in StringKeys<O>]: O[K] extends Record<string, any> ? `${K}.${SelectableColumn<O[K]>}` : K;
12
11
  }> : '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-beta.9ac2bdc",
3
+ "version": "0.0.0-beta.a500a21",
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": "9ac2bdc7b36ee57583bdc4edefc0ba0f75f6f4f8"
23
+ "gitHead": "a500a21dec7ef52551d47ab75ab5ba6a287e57c6"
24
24
  }