@rushdb/javascript-sdk 0.9.2 → 0.9.4

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @rushdb/javascript-sdk
2
2
 
3
+ ## 0.9.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 09e2d57: Update docs, minor fixes and cleanups
8
+
9
+ ## 0.9.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 22ce867: billing setup update for dev/prod envs
14
+
3
15
  ## 0.9.2
4
16
 
5
17
  ### Patch Changes
package/cjs/api/api.js CHANGED
@@ -32,7 +32,7 @@ class RestAPI {
32
32
  },
33
33
  values: async (id, transaction) => {
34
34
  var _a;
35
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.values(id, transaction);
35
+ return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.values(id, {}, transaction);
36
36
  }
37
37
  };
38
38
  this.labels = {
@@ -260,7 +260,7 @@ class RestAPI {
260
260
  const { searchParams } = (0, utils_js_2.createSearchParams)(labelOrSearchParams, searchParamsOrTransaction);
261
261
  const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
262
262
  const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findOne(searchParams, tx));
263
- const result = new record_js_1.DBRecordInstance(response.data, searchParamsOrTransaction);
263
+ const result = new record_js_1.DBRecordInstance(response.data);
264
264
  result.init(this);
265
265
  return result;
266
266
  },
@@ -270,7 +270,7 @@ class RestAPI {
270
270
  const { searchParams } = (0, utils_js_2.createSearchParams)(labelOrSearchParams, searchParamsOrTransaction);
271
271
  const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
272
272
  const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findUniq(searchParams, tx));
273
- const result = new record_js_1.DBRecordInstance(response.data, searchParamsOrTransaction);
273
+ const result = new record_js_1.DBRecordInstance(response.data);
274
274
  result.init(this);
275
275
  return result;
276
276
  },
@@ -58,15 +58,25 @@ const createApi = (fetcher, logger) => ({
58
58
  // updateValues: (id: string, transaction?: Transaction | string) => {
59
59
  // // @TODO
60
60
  // },
61
- values: (id, transaction) => {
61
+ values: (id, options, transaction) => {
62
62
  const txId = (0, utils_js_2.pickTransactionId)(transaction);
63
63
  const path = `/properties/${id}/values`;
64
+ const { sort, skip, limit } = options !== null && options !== void 0 ? options : {};
65
+ const queryParams = new URLSearchParams();
66
+ if (sort)
67
+ queryParams.append('sort', sort);
68
+ if (skip !== undefined)
69
+ queryParams.append('skip', skip.toString());
70
+ if (limit !== undefined)
71
+ queryParams.append('limit', limit.toString());
72
+ const queryString = queryParams.toString();
73
+ const fullPath = queryString ? `${path}?${queryString}` : path;
64
74
  const payload = {
65
75
  headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
66
76
  method: 'GET'
67
77
  };
68
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
69
- return fetcher(path, payload);
78
+ logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path: fullPath }, payload));
79
+ return fetcher(fullPath, payload);
70
80
  }
71
81
  },
72
82
  records: {
package/cjs/sdk/record.js CHANGED
@@ -35,41 +35,79 @@ class DBRecordDraft {
35
35
  }
36
36
  exports.DBRecordDraft = DBRecordDraft;
37
37
  class DBRecordInstance extends rest_api_proxy_js_1.RestApiProxy {
38
- constructor(data, searchParams) {
38
+ constructor(data) {
39
39
  super();
40
40
  this.data = data;
41
- this.searchParams = searchParams;
42
41
  }
43
- __date() {
44
- return (0, utils_js_1.idToDate)(this.data.__id);
42
+ get id() {
43
+ try {
44
+ return this.data.__id;
45
+ }
46
+ catch (_a) {
47
+ throw new Error(`DBRecordInstance: Unable to access 'id'. The Record data is undefined.`);
48
+ }
49
+ }
50
+ get label() {
51
+ try {
52
+ return this.data.__label;
53
+ }
54
+ catch (_a) {
55
+ throw new Error(`DBRecordInstance: Unable to access 'label'. The Record data is undefined.`);
56
+ }
57
+ }
58
+ get proptypes() {
59
+ try {
60
+ return this.data.__proptypes;
61
+ }
62
+ catch (_a) {
63
+ throw new Error(`DBRecordInstance: Unable to access 'proptypes'. The Record data' is undefined.`);
64
+ }
45
65
  }
46
- __timestamp() {
47
- return (0, utils_js_1.idToTimestamp)(this.data.__id);
66
+ get date() {
67
+ try {
68
+ return (0, utils_js_1.idToDate)(this.data.__id);
69
+ }
70
+ catch (_a) {
71
+ throw new Error(`DBRecordInstance: Unable to access 'date'. The Record data is undefined.`);
72
+ }
73
+ }
74
+ get timestamp() {
75
+ try {
76
+ return (0, utils_js_1.idToTimestamp)(this.data.__id);
77
+ }
78
+ catch (_a) {
79
+ throw new Error(`DBRecordInstance: Unable to access 'timestamp'. The Record data is undefined.`);
80
+ }
48
81
  }
49
82
  async delete(transaction) {
50
- if (this.data) {
51
- return await this.apiProxy.records.deleteById(this.data.__id, transaction);
83
+ if (!this.data) {
84
+ throw new Error('DBRecordInstance: Unable to delete Record. The Record data is undefined.');
52
85
  }
86
+ return await this.apiProxy.records.deleteById(this.data.__id, transaction);
53
87
  }
54
88
  async update(partialData, transaction) {
55
- if (this.data) {
56
- return this.apiProxy.records.update(this.data.__id, partialData, transaction);
89
+ if (!this.data) {
90
+ throw new Error('DBRecordInstance: Unable to update Record. The Record data is undefined.');
57
91
  }
92
+ return this.apiProxy.records.update(this.data.__id, partialData, transaction);
58
93
  }
59
94
  async set(data, transaction) {
60
- if (this.data) {
61
- return this.apiProxy.records.set(this.data.__id, data, transaction);
95
+ if (!this.data) {
96
+ throw new Error('DBRecordInstance: Unable to set. The Record data is undefined.');
62
97
  }
98
+ return this.apiProxy.records.set(this.data.__id, data, transaction);
63
99
  }
64
100
  async attach(target, options, transaction) {
65
- if (this.data) {
66
- return this.apiProxy.records.attach(this.data.__id, target, options, transaction);
101
+ if (!this.data) {
102
+ throw new Error('DBRecordInstance: Unable to attach Record. The Record data is undefined.');
67
103
  }
104
+ return this.apiProxy.records.attach(this.data.__id, target, options, transaction);
68
105
  }
69
106
  async detach(target, options, transaction) {
70
- if (this.data) {
71
- return this.apiProxy.records.detach(this.data.__id, target, options, transaction);
107
+ if (!this.data) {
108
+ throw new Error('DBRecordInstance: Unable to detach Record. The Record data is undefined.');
72
109
  }
110
+ return this.apiProxy.records.detach(this.data.__id, target, options, transaction);
73
111
  }
74
112
  }
75
113
  exports.DBRecordInstance = DBRecordInstance;
package/esm/api/api.js CHANGED
@@ -29,7 +29,7 @@ export class RestAPI {
29
29
  },
30
30
  values: async (id, transaction) => {
31
31
  var _a;
32
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.values(id, transaction);
32
+ return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.values(id, {}, transaction);
33
33
  }
34
34
  };
35
35
  this.labels = {
@@ -257,7 +257,7 @@ export class RestAPI {
257
257
  const { searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
258
258
  const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
259
259
  const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findOne(searchParams, tx));
260
- const result = new DBRecordInstance(response.data, searchParamsOrTransaction);
260
+ const result = new DBRecordInstance(response.data);
261
261
  result.init(this);
262
262
  return result;
263
263
  },
@@ -267,7 +267,7 @@ export class RestAPI {
267
267
  const { searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
268
268
  const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
269
269
  const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findUniq(searchParams, tx));
270
- const result = new DBRecordInstance(response.data, searchParamsOrTransaction);
270
+ const result = new DBRecordInstance(response.data);
271
271
  result.init(this);
272
272
  return result;
273
273
  },
@@ -55,15 +55,25 @@ export const createApi = (fetcher, logger) => ({
55
55
  // updateValues: (id: string, transaction?: Transaction | string) => {
56
56
  // // @TODO
57
57
  // },
58
- values: (id, transaction) => {
58
+ values: (id, options, transaction) => {
59
59
  const txId = pickTransactionId(transaction);
60
60
  const path = `/properties/${id}/values`;
61
+ const { sort, skip, limit } = options !== null && options !== void 0 ? options : {};
62
+ const queryParams = new URLSearchParams();
63
+ if (sort)
64
+ queryParams.append('sort', sort);
65
+ if (skip !== undefined)
66
+ queryParams.append('skip', skip.toString());
67
+ if (limit !== undefined)
68
+ queryParams.append('limit', limit.toString());
69
+ const queryString = queryParams.toString();
70
+ const fullPath = queryString ? `${path}?${queryString}` : path;
61
71
  const payload = {
62
72
  headers: Object.assign({}, buildTransactionHeader(txId)),
63
73
  method: 'GET'
64
74
  };
65
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
66
- return fetcher(path, payload);
75
+ logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path: fullPath }, payload));
76
+ return fetcher(fullPath, payload);
67
77
  }
68
78
  },
69
79
  records: {
package/esm/sdk/record.js CHANGED
@@ -30,41 +30,79 @@ export class DBRecordDraft {
30
30
  }
31
31
  }
32
32
  export class DBRecordInstance extends RestApiProxy {
33
- constructor(data, searchParams) {
33
+ constructor(data) {
34
34
  super();
35
35
  this.data = data;
36
- this.searchParams = searchParams;
37
36
  }
38
- __date() {
39
- return idToDate(this.data.__id);
37
+ get id() {
38
+ try {
39
+ return this.data.__id;
40
+ }
41
+ catch (_a) {
42
+ throw new Error(`DBRecordInstance: Unable to access 'id'. The Record data is undefined.`);
43
+ }
44
+ }
45
+ get label() {
46
+ try {
47
+ return this.data.__label;
48
+ }
49
+ catch (_a) {
50
+ throw new Error(`DBRecordInstance: Unable to access 'label'. The Record data is undefined.`);
51
+ }
52
+ }
53
+ get proptypes() {
54
+ try {
55
+ return this.data.__proptypes;
56
+ }
57
+ catch (_a) {
58
+ throw new Error(`DBRecordInstance: Unable to access 'proptypes'. The Record data' is undefined.`);
59
+ }
40
60
  }
41
- __timestamp() {
42
- return idToTimestamp(this.data.__id);
61
+ get date() {
62
+ try {
63
+ return idToDate(this.data.__id);
64
+ }
65
+ catch (_a) {
66
+ throw new Error(`DBRecordInstance: Unable to access 'date'. The Record data is undefined.`);
67
+ }
68
+ }
69
+ get timestamp() {
70
+ try {
71
+ return idToTimestamp(this.data.__id);
72
+ }
73
+ catch (_a) {
74
+ throw new Error(`DBRecordInstance: Unable to access 'timestamp'. The Record data is undefined.`);
75
+ }
43
76
  }
44
77
  async delete(transaction) {
45
- if (this.data) {
46
- return await this.apiProxy.records.deleteById(this.data.__id, transaction);
78
+ if (!this.data) {
79
+ throw new Error('DBRecordInstance: Unable to delete Record. The Record data is undefined.');
47
80
  }
81
+ return await this.apiProxy.records.deleteById(this.data.__id, transaction);
48
82
  }
49
83
  async update(partialData, transaction) {
50
- if (this.data) {
51
- return this.apiProxy.records.update(this.data.__id, partialData, transaction);
84
+ if (!this.data) {
85
+ throw new Error('DBRecordInstance: Unable to update Record. The Record data is undefined.');
52
86
  }
87
+ return this.apiProxy.records.update(this.data.__id, partialData, transaction);
53
88
  }
54
89
  async set(data, transaction) {
55
- if (this.data) {
56
- return this.apiProxy.records.set(this.data.__id, data, transaction);
90
+ if (!this.data) {
91
+ throw new Error('DBRecordInstance: Unable to set. The Record data is undefined.');
57
92
  }
93
+ return this.apiProxy.records.set(this.data.__id, data, transaction);
58
94
  }
59
95
  async attach(target, options, transaction) {
60
- if (this.data) {
61
- return this.apiProxy.records.attach(this.data.__id, target, options, transaction);
96
+ if (!this.data) {
97
+ throw new Error('DBRecordInstance: Unable to attach Record. The Record data is undefined.');
62
98
  }
99
+ return this.apiProxy.records.attach(this.data.__id, target, options, transaction);
63
100
  }
64
101
  async detach(target, options, transaction) {
65
- if (this.data) {
66
- return this.apiProxy.records.detach(this.data.__id, target, options, transaction);
102
+ if (!this.data) {
103
+ throw new Error('DBRecordInstance: Unable to detach Record. The Record data is undefined.');
67
104
  }
105
+ return this.apiProxy.records.detach(this.data.__id, target, options, transaction);
68
106
  }
69
107
  }
70
108
  export class DBRecordsArrayInstance extends RestApiProxy {
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "rushdb"
13
13
  ],
14
14
  "license": "Apache-2.0",
15
- "version": "0.9.2",
15
+ "version": "0.9.4",
16
16
  "type": "module",
17
17
  "main": "cjs/index.cjs.node.js",
18
18
  "types": "types/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  import type { createFetcher } from '../network/index.js';
2
2
  import type { DBRecord, DBRecordTarget, Relation, RelationDetachOptions, RelationOptions } from '../sdk/record.js';
3
3
  import type { Transaction } from '../sdk/transaction.js';
4
- import type { Property, PropertyValuesData, SearchQuery, Schema, MaybeArray } from '../types/index.js';
4
+ import type { Property, PropertyValuesData, SearchQuery, Schema, MaybeArray, OrderDirection } from '../types/index.js';
5
5
  import type { ApiResponse } from './types.js';
6
6
  import { DBRecordsBatchDraft, DBRecordDraft } from '../sdk/record.js';
7
7
  import type { Logger } from '../sdk/types.js';
@@ -13,7 +13,11 @@ export declare const createApi: (fetcher: ReturnType<typeof createFetcher>, logg
13
13
  delete: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
14
14
  find: <S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<Property[]>>;
15
15
  findById: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
16
- values: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property & PropertyValuesData>>;
16
+ values: (id: string, options?: {
17
+ sort?: OrderDirection;
18
+ skip?: number;
19
+ limit?: number;
20
+ }, transaction?: Transaction | string) => Promise<ApiResponse<Property & PropertyValuesData>>;
17
21
  };
18
22
  records: {
19
23
  attach(source: DBRecordTarget, idOrIds: MaybeArray<string>, options?: RelationOptions, transaction?: Transaction | string): Promise<ApiResponse<{
@@ -86,21 +86,23 @@ export declare class DBRecordDraft {
86
86
  }
87
87
  export declare class DBRecordInstance<S extends Schema = Schema> extends RestApiProxy {
88
88
  data?: DBRecord<S>;
89
- searchParams?: SearchQuery<S>;
90
- constructor(data?: DBRecord<S>, searchParams?: SearchQuery<S>);
91
- __date(): Date;
92
- __timestamp(): number;
89
+ constructor(data?: DBRecord<S>);
90
+ get id(): string;
91
+ get label(): string;
92
+ get proptypes(): FlattenTypes<FlattenTypes<{ [Key in RequiredKeysRead<S>]: S[Key]["type"]; } & { [Key_1 in OptionalKeysRead<S>]?: S[Key_1]["type"] | undefined; }>> | undefined;
93
+ get date(): Date;
94
+ get timestamp(): number;
93
95
  delete(transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
94
96
  message: string;
95
- }, Record<string, any>> | undefined>;
96
- update<S extends Schema = Schema>(partialData: DBRecordDraft | Partial<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordInstance<S> | undefined>;
97
- set<S extends Schema = Schema>(data: DBRecordDraft | InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S> | undefined>;
97
+ }, Record<string, any>>>;
98
+ update<S extends Schema = Schema>(partialData: DBRecordDraft | Partial<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
99
+ set<S extends Schema = Schema>(data: DBRecordDraft | InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
98
100
  attach(target: RelationTarget, options?: RelationOptions, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
99
101
  message: string;
100
- }, Record<string, any>> | undefined>;
102
+ }, Record<string, any>>>;
101
103
  detach(target: RelationTarget, options?: RelationDetachOptions, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
102
104
  message: string;
103
- }, Record<string, any>> | undefined>;
105
+ }, Record<string, any>>>;
104
106
  }
105
107
  export declare class DBRecordsArrayInstance<S extends Schema = Schema> extends RestApiProxy {
106
108
  data?: DBRecord<S>[];
@@ -36,7 +36,8 @@ export type Expression<S extends Schema = Schema> = IdExpression | (S extends Sc
36
36
  [Key in keyof S]?: S[Key] extends MaybeArray<number> ? MaybeLogicalExpression<NumberExpression> : S[Key] extends MaybeArray<boolean> ? MaybeLogicalExpression<BooleanExpression> : S[Key] extends MaybeArray<string> ? MaybeLogicalExpression<DatetimeExpression> | MaybeLogicalExpression<StringExpression> : S[Key] extends MaybeArray<null> ? MaybeLogicalExpression<NullExpression> : LogicalExpression | Partial<PropertyExpression>;
37
37
  });
38
38
  export type Where<S extends Schema = Schema> = ((Expression<S> & Related) & LogicalGrouping<Expression<S> & Related>) | LogicalGrouping<Expression<S> & Related>;
39
- export type Order<S extends Schema = Schema> = 'asc' | 'desc' | Partial<Record<keyof S, 'asc' | 'desc'>>;
39
+ export type OrderDirection = 'asc' | 'desc';
40
+ export type Order<S extends Schema = Schema> = OrderDirection | Partial<Record<keyof S, OrderDirection>>;
40
41
  export type AggregateCollectFn = {
41
42
  alias: string;
42
43
  field?: string;