@rushdb/javascript-sdk 0.9.4 → 0.9.5

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 (100) hide show
  1. package/dist/index.cjs +1 -0
  2. package/dist/index.mjs +1 -0
  3. package/dist/index.node.d.ts +137 -0
  4. package/dist/index.worker.d.ts +137 -0
  5. package/{types → dist}/sdk/model.d.ts +4 -4
  6. package/{types → dist}/sdk/record.d.ts +3 -3
  7. package/{types → dist}/sdk/sdk.d.ts +24 -24
  8. package/{types → dist}/sdk/transaction.d.ts +2 -2
  9. package/{types → dist}/types/query.d.ts +1 -2
  10. package/package.json +10 -34
  11. package/CHANGELOG.md +0 -180
  12. package/cjs/api/api.js +0 -328
  13. package/cjs/api/constants.js +0 -7
  14. package/cjs/api/create-api.js +0 -323
  15. package/cjs/api/index.js +0 -8
  16. package/cjs/api/rest-api-proxy.js +0 -22
  17. package/cjs/api/types.js +0 -2
  18. package/cjs/api/utils.js +0 -155
  19. package/cjs/common/constants.js +0 -10
  20. package/cjs/common/utils.js +0 -46
  21. package/cjs/index.cjs.node.js +0 -24
  22. package/cjs/index.cjs.worker.js +0 -24
  23. package/cjs/network/FetchHttpClient.js +0 -138
  24. package/cjs/network/HttpClient.js +0 -59
  25. package/cjs/network/NodeHttpClient.js +0 -103
  26. package/cjs/network/index.js +0 -28
  27. package/cjs/network/types.js +0 -2
  28. package/cjs/package.json +0 -4
  29. package/cjs/sdk/constants.js +0 -13
  30. package/cjs/sdk/errors.js +0 -27
  31. package/cjs/sdk/index.js +0 -23
  32. package/cjs/sdk/model.js +0 -147
  33. package/cjs/sdk/record.js +0 -122
  34. package/cjs/sdk/sdk.js +0 -46
  35. package/cjs/sdk/transaction.js +0 -17
  36. package/cjs/sdk/types.js +0 -2
  37. package/cjs/sdk/utils.js +0 -103
  38. package/cjs/types/expressions.js +0 -2
  39. package/cjs/types/index.js +0 -21
  40. package/cjs/types/query.js +0 -2
  41. package/cjs/types/schema.js +0 -2
  42. package/cjs/types/utils.js +0 -2
  43. package/cjs/types/value.js +0 -2
  44. package/esm/api/api.js +0 -324
  45. package/esm/api/constants.js +0 -4
  46. package/esm/api/create-api.js +0 -319
  47. package/esm/api/index.js +0 -2
  48. package/esm/api/rest-api-proxy.js +0 -18
  49. package/esm/api/types.js +0 -1
  50. package/esm/api/utils.js +0 -139
  51. package/esm/common/constants.js +0 -7
  52. package/esm/common/utils.js +0 -37
  53. package/esm/index.esm.node.js +0 -6
  54. package/esm/index.esm.worker.js +0 -6
  55. package/esm/network/FetchHttpClient.js +0 -133
  56. package/esm/network/HttpClient.js +0 -53
  57. package/esm/network/NodeHttpClient.js +0 -98
  58. package/esm/network/index.js +0 -24
  59. package/esm/network/types.js +0 -1
  60. package/esm/package.json +0 -4
  61. package/esm/sdk/constants.js +0 -10
  62. package/esm/sdk/errors.js +0 -21
  63. package/esm/sdk/index.js +0 -7
  64. package/esm/sdk/model.js +0 -143
  65. package/esm/sdk/record.js +0 -115
  66. package/esm/sdk/sdk.js +0 -42
  67. package/esm/sdk/transaction.js +0 -13
  68. package/esm/sdk/types.js +0 -1
  69. package/esm/sdk/utils.js +0 -93
  70. package/esm/types/expressions.js +0 -1
  71. package/esm/types/index.js +0 -5
  72. package/esm/types/query.js +0 -1
  73. package/esm/types/schema.js +0 -1
  74. package/esm/types/utils.js +0 -1
  75. package/esm/types/value.js +0 -1
  76. package/types/index.d.ts +0 -60
  77. /package/{types → dist}/api/api.d.ts +0 -0
  78. /package/{types → dist}/api/constants.d.ts +0 -0
  79. /package/{types → dist}/api/create-api.d.ts +0 -0
  80. /package/{types → dist}/api/index.d.ts +0 -0
  81. /package/{types → dist}/api/rest-api-proxy.d.ts +0 -0
  82. /package/{types → dist}/api/types.d.ts +0 -0
  83. /package/{types → dist}/api/utils.d.ts +0 -0
  84. /package/{types → dist}/common/constants.d.ts +0 -0
  85. /package/{types → dist}/common/utils.d.ts +0 -0
  86. /package/{types → dist}/network/FetchHttpClient.d.ts +0 -0
  87. /package/{types → dist}/network/HttpClient.d.ts +0 -0
  88. /package/{types → dist}/network/NodeHttpClient.d.ts +0 -0
  89. /package/{types → dist}/network/index.d.ts +0 -0
  90. /package/{types → dist}/network/types.d.ts +0 -0
  91. /package/{types → dist}/sdk/constants.d.ts +0 -0
  92. /package/{types → dist}/sdk/errors.d.ts +0 -0
  93. /package/{types → dist}/sdk/index.d.ts +0 -0
  94. /package/{types → dist}/sdk/types.d.ts +0 -0
  95. /package/{types → dist}/sdk/utils.d.ts +0 -0
  96. /package/{types → dist}/types/expressions.d.ts +0 -0
  97. /package/{types → dist}/types/index.d.ts +0 -0
  98. /package/{types → dist}/types/schema.d.ts +0 -0
  99. /package/{types → dist}/types/utils.d.ts +0 -0
  100. /package/{types → dist}/types/value.d.ts +0 -0
package/package.json CHANGED
@@ -12,10 +12,14 @@
12
12
  "rushdb"
13
13
  ],
14
14
  "license": "Apache-2.0",
15
- "version": "0.9.4",
15
+ "version": "0.9.5",
16
16
  "type": "module",
17
- "main": "cjs/index.cjs.node.js",
18
- "types": "types/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.worker.d.ts",
19
23
  "devDependencies": {},
20
24
  "peerDependencies": {},
21
25
  "sideEffects": false,
@@ -27,38 +31,10 @@
27
31
  "type": "https",
28
32
  "url": "https://github.com/rush-db/rushdb"
29
33
  },
30
- "exports": {
31
- "types": "./types/index.d.ts",
32
- "browser": {
33
- "import": "./esm/index.esm.worker.js",
34
- "require": "./cjs/index.cjs.worker.js"
35
- },
36
- "bun": {
37
- "import": "./esm/index.esm.worker.js",
38
- "require": "./cjs/index.cjs.worker.js"
39
- },
40
- "deno": {
41
- "import": "./esm/index.esm.worker.js",
42
- "require": "./cjs/index.cjs.worker.js"
43
- },
44
- "worker": {
45
- "import": "./esm/index.esm.worker.js",
46
- "require": "./cjs/index.cjs.worker.js"
47
- },
48
- "workerd": {
49
- "import": "./esm/index.esm.worker.js",
50
- "require": "./cjs/index.cjs.worker.js"
51
- },
52
- "default": {
53
- "import": "./esm/index.esm.node.js",
54
- "require": "./cjs/index.cjs.node.js"
55
- }
56
- },
57
34
  "scripts": {
58
- "build": "pnpm clean && pnpm build-esm && pnpm build-cjs && pnpm postbuild",
59
- "build-esm": "mkdir -p esm && tsc -p tsconfig.esm.json",
60
- "build-cjs": "mkdir -p cjs && tsc -p tsconfig.cjs.json",
61
- "postbuild": "node scripts/post-build.js",
35
+ "build": "pnpm clean && pnpm build:package && pnpm build:types",
36
+ "build:package": "node esbuild.config.cjs",
37
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
62
38
  "types:check": "tsc --noEmit",
63
39
  "clean": "rm -rf ./dist ./node_modules/.cache ./coverage ./esm ./cjs ./types",
64
40
  "flush": "rm -rf node_modules",
package/CHANGELOG.md DELETED
@@ -1,180 +0,0 @@
1
- # @rushdb/javascript-sdk
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
-
15
- ## 0.9.2
16
-
17
- ### Patch Changes
18
-
19
- - eafe1b5: updated secret credentials
20
-
21
- ## 0.9.1
22
-
23
- ### Patch Changes
24
-
25
- - b055539: Dashboard/website: Introduced start plan, updated dashboard && website layouts
26
-
27
- ## 0.9.0
28
-
29
- ### Minor Changes
30
-
31
- - 6cc7392: Release 0.9.0 version with updated billing
32
-
33
- ## 0.8.2
34
-
35
- ### Patch Changes
36
-
37
- - 6e900d7: bump other packages to 0.8.1
38
-
39
- ## 0.8.1
40
-
41
- ### Patch Changes
42
-
43
- - 3d65528: Core/Dashboard/Website now accept billing data from internal billing service instead of hardcoded values
44
-
45
- ## 0.8.0
46
-
47
- ### Minor Changes
48
-
49
- - 49e3153: Dependencies update & landing page rework
50
-
51
- ## 0.7.2
52
-
53
- ### Patch Changes
54
-
55
- - c32b9bf: Aggregations minor fixes
56
-
57
- ## 0.7.1
58
-
59
- ### Patch Changes
60
-
61
- - 0551051: Restore original skip & limit behaviour for nested search
62
-
63
- ## 0.7.0
64
-
65
- ### Minor Changes
66
-
67
- - 5470782: Fix result cut-off for nested queries and url parsing in node.js env at sdk's networking
68
-
69
- ## 0.6.0
70
-
71
- ### Minor Changes
72
-
73
- - 6ec52f2: Add simple backup module, cli command and minor fixes
74
-
75
- ## 0.5.0
76
-
77
- ### Minor Changes
78
-
79
- - 3112626: Implemented logger feature for sdk
80
-
81
- ## 0.4.1
82
-
83
- ### Patch Changes
84
-
85
- - 070d094: Minor cloud update
86
-
87
- ## 0.4.0
88
-
89
- ### Minor Changes
90
-
91
- - 0e04a46: Version bump
92
-
93
- ### Patch Changes
94
-
95
- - 4f83de0: Minor fixes and updates
96
- - defeaf0: Minor fixes and updates
97
-
98
- ## 0.3.1
99
-
100
- ### Patch Changes
101
-
102
- - d3b73ac: Minor fixes
103
-
104
- ## 0.3.0
105
-
106
- ### Minor Changes
107
-
108
- - 70d108d: CLI commands & datetime helpers in the Javascript SDK
109
-
110
- ## 0.2.10
111
-
112
- ### Patch Changes
113
-
114
- - 89f2783: Update readme and license
115
-
116
- ## 0.2.9
117
-
118
- ### Patch Changes
119
-
120
- - 9580ede: Update infrastructure and minor fixes
121
-
122
- ## 0.2.8
123
-
124
- ### Patch Changes
125
-
126
- - 1cf62ae: Minor fixes and cleanups
127
-
128
- ## 0.2.7
129
-
130
- ### Patch Changes
131
-
132
- - 147cc2b: Build docker image only on version bump
133
-
134
- ## 0.2.6
135
-
136
- ### Patch Changes
137
-
138
- - 89852a4: Update docker image release
139
-
140
- ## 0.2.5
141
-
142
- ### Patch Changes
143
-
144
- - cd0be33: Release flow improvements
145
-
146
- ## 0.2.4
147
-
148
- ### Patch Changes
149
-
150
- - 3741a7e: Release workflow change
151
-
152
- ## 0.2.3
153
-
154
- ### Patch Changes
155
-
156
- - c7f1eb9: Update workflow
157
-
158
- ## 0.2.2
159
-
160
- ### Patch Changes
161
-
162
- - de0fb17: Update release workflow
163
-
164
- ## 0.2.1
165
-
166
- ### Patch Changes
167
-
168
- - f934b0f: Bump version
169
-
170
- ## 0.2.0
171
-
172
- ### Minor Changes
173
-
174
- - cb1e4be: Update readme, cleanups, build public image
175
-
176
- ## 0.1.0
177
-
178
- ### Minor Changes
179
-
180
- - 0fc7f66: Initial release before migrating to RushDB domain
package/cjs/api/api.js DELETED
@@ -1,328 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RestAPI = void 0;
4
- const utils_js_1 = require("../common/utils.js");
5
- const index_js_1 = require("../network/index.js");
6
- const errors_js_1 = require("../sdk/errors.js");
7
- const record_js_1 = require("../sdk/record.js");
8
- const transaction_js_1 = require("../sdk/transaction.js");
9
- const create_api_js_1 = require("./create-api.js");
10
- const utils_js_2 = require("./utils.js");
11
- class RestAPI {
12
- constructor(token, config) {
13
- this.relations = {
14
- find: async ({ pagination, search, transaction }) => {
15
- const { searchParams } = (0, utils_js_2.createSearchParams)(search);
16
- const tx = (0, utils_js_2.pickTransaction)(transaction);
17
- return await this.api.relations.find(searchParams, pagination, tx);
18
- }
19
- };
20
- this.properties = {
21
- delete: async (id, transaction) => {
22
- var _a;
23
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.delete(id, transaction);
24
- },
25
- find: async (searchParams, transaction) => {
26
- var _a;
27
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.find(searchParams, transaction);
28
- },
29
- findById: async (id, transaction) => {
30
- var _a;
31
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.findById(id, transaction);
32
- },
33
- values: async (id, transaction) => {
34
- var _a;
35
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.values(id, {}, transaction);
36
- }
37
- };
38
- this.labels = {
39
- find: async (searchParams, transaction) => {
40
- return this.api.labels.find(searchParams, transaction);
41
- }
42
- };
43
- this.tx = {
44
- begin: async (config) => {
45
- var _a;
46
- const transaction = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.begin(config));
47
- const result = new transaction_js_1.Transaction(transaction.data.id);
48
- result.init(this);
49
- return result;
50
- },
51
- commit: async (id) => { var _a; return (_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.commit(id); },
52
- get: async (id) => {
53
- var _a;
54
- const transaction = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.get(id));
55
- const result = new transaction_js_1.Transaction(transaction.data.id);
56
- result.init(this);
57
- return result;
58
- },
59
- rollback: async (id) => { var _a; return (_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.commit(id); }
60
- };
61
- this.fetcher = null;
62
- if (config === null || config === void 0 ? void 0 : config.httpClient) {
63
- const url = (0, utils_js_2.buildUrl)(config);
64
- this.fetcher = (0, index_js_1.createFetcher)({
65
- httpClient: config.httpClient,
66
- token,
67
- url
68
- });
69
- }
70
- this.api = (0, create_api_js_1.createApi)(this.fetcher, config === null || config === void 0 ? void 0 : config.logger);
71
- this.records = {
72
- attach: async (sourceId, target, options, transaction) => {
73
- var _a, _b;
74
- // target is MaybeArray<DBRecordInstance>
75
- if (target instanceof record_js_1.DBRecordInstance) {
76
- const id = (_a = target.data) === null || _a === void 0 ? void 0 : _a.__id;
77
- if (id) {
78
- return await this.api.records.attach(sourceId, id, options, transaction);
79
- }
80
- else {
81
- throw new errors_js_1.EmptyTargetError('Attach error: Target id is empty');
82
- }
83
- }
84
- else if ((0, utils_js_1.isArray)(target) && target.every((r) => r instanceof record_js_1.DBRecordInstance)) {
85
- const ids = target.map((r) => { var _a; return (_a = r.data) === null || _a === void 0 ? void 0 : _a.__id; }).filter(utils_js_1.toBoolean);
86
- if (ids.length) {
87
- return await this.api.records.attach(sourceId, ids, options, transaction);
88
- }
89
- else {
90
- throw new errors_js_1.EmptyTargetError('Attach error: Target ids are empty');
91
- }
92
- }
93
- // target is DBRecordsArrayInstance
94
- else if (target instanceof record_js_1.DBRecordsArrayInstance) {
95
- const ids = (_b = target.data) === null || _b === void 0 ? void 0 : _b.map((r) => r.__id).filter(Boolean);
96
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
97
- return await this.api.records.attach(sourceId, ids, options, transaction);
98
- }
99
- else {
100
- throw new errors_js_1.EmptyTargetError('Attach error: Target ids are empty');
101
- }
102
- }
103
- // target is MaybeArray<DBRecord>
104
- else if ((0, utils_js_1.isObject)(target) && '__id' in target) {
105
- return await this.api.records.attach(sourceId, target.__id, options, transaction);
106
- }
107
- else if ((0, utils_js_1.isArray)(target) && target.every((r) => (0, utils_js_1.isObject)(r) && '__id' in r)) {
108
- const ids = target === null || target === void 0 ? void 0 : target.map((r) => r.__id).filter(Boolean);
109
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
110
- return await this.api.records.attach(sourceId, ids, options, transaction);
111
- }
112
- else {
113
- throw new errors_js_1.EmptyTargetError('Attach error: Target ids are empty');
114
- }
115
- }
116
- // target is MaybeArray<string>
117
- else {
118
- return await this.api.records.attach(sourceId, target, options, transaction);
119
- }
120
- },
121
- create: async (labelOrData, maybeDataOrTransaction, transaction) => {
122
- var _a, _b;
123
- let response;
124
- if (labelOrData instanceof record_js_1.DBRecordDraft) {
125
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.create(labelOrData, (0, utils_js_2.pickTransaction)(maybeDataOrTransaction)));
126
- }
127
- if (!response && (0, utils_js_1.isString)(labelOrData)) {
128
- if ((0, utils_js_1.isObjectFlat)(maybeDataOrTransaction)) {
129
- const normalizedRecord = (0, utils_js_2.normalizeRecord)({
130
- label: labelOrData,
131
- payload: maybeDataOrTransaction
132
- });
133
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.create(new record_js_1.DBRecordDraft(normalizedRecord), transaction));
134
- }
135
- else if ((0, utils_js_1.isObject)(maybeDataOrTransaction)) {
136
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
137
- }
138
- }
139
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
140
- const result = new record_js_1.DBRecordInstance(response.data);
141
- result.init(this);
142
- return result;
143
- }
144
- return new record_js_1.DBRecordInstance();
145
- },
146
- createMany: async (labelOrData, maybeDataOrTransaction, transaction) => {
147
- var _a, _b;
148
- let response;
149
- if (labelOrData instanceof record_js_1.DBRecordsBatchDraft) {
150
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.createMany(labelOrData, (0, utils_js_2.pickTransaction)(maybeDataOrTransaction)));
151
- }
152
- if (!response &&
153
- (0, utils_js_1.isString)(labelOrData) &&
154
- ((0, utils_js_1.isArray)(maybeDataOrTransaction) || (0, utils_js_1.isObject)(maybeDataOrTransaction))) {
155
- const data = new record_js_1.DBRecordsBatchDraft({
156
- label: labelOrData,
157
- payload: maybeDataOrTransaction
158
- });
159
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.createMany(data, transaction));
160
- }
161
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
162
- const result = new record_js_1.DBRecordsArrayInstance(response.data, response.total);
163
- result.init(this);
164
- return result;
165
- }
166
- return new record_js_1.DBRecordsArrayInstance([]);
167
- },
168
- delete: async (searchParams, transaction) => {
169
- var _a;
170
- if ((0, utils_js_1.isEmptyObject)(searchParams.where)) {
171
- throw new errors_js_1.EmptyTargetError(`You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.`);
172
- }
173
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.delete(searchParams, transaction);
174
- },
175
- deleteById: async (idOrIds, transaction) => {
176
- var _a;
177
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.deleteById(idOrIds, transaction);
178
- },
179
- detach: async (sourceId, target, options, transaction) => {
180
- var _a, _b;
181
- // target is MaybeArray<DBRecordInstance>
182
- if (target instanceof record_js_1.DBRecordInstance) {
183
- const id = (_a = target.data) === null || _a === void 0 ? void 0 : _a.__id;
184
- if (id) {
185
- return await this.api.records.detach(sourceId, id, options, transaction);
186
- }
187
- else {
188
- throw new errors_js_1.EmptyTargetError('Detach error: Target id is empty');
189
- }
190
- }
191
- else if ((0, utils_js_1.isArray)(target) && target.every((r) => r instanceof record_js_1.DBRecordInstance)) {
192
- const ids = target.map((r) => { var _a; return (_a = r.data) === null || _a === void 0 ? void 0 : _a.__id; }).filter(Boolean);
193
- if (ids.length) {
194
- return await this.api.records.detach(sourceId, ids, options, transaction);
195
- }
196
- else {
197
- throw new errors_js_1.EmptyTargetError('Detach error: Target ids are empty');
198
- }
199
- }
200
- // target is DBRecordsArrayInstance
201
- else if (target instanceof record_js_1.DBRecordsArrayInstance) {
202
- const ids = (_b = target.data) === null || _b === void 0 ? void 0 : _b.map((r) => r.__id).filter(Boolean);
203
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
204
- return await this.api.records.detach(sourceId, ids, options, transaction);
205
- }
206
- else {
207
- throw new errors_js_1.EmptyTargetError('Detach error: Target ids are empty');
208
- }
209
- }
210
- // target is MaybeArray<DBRecord>
211
- else if ((0, utils_js_1.isObject)(target) && '__id' in target) {
212
- return await this.api.records.detach(sourceId, target.__id, options, transaction);
213
- }
214
- else if ((0, utils_js_1.isArray)(target) && target.every((r) => (0, utils_js_1.isObject)(r) && '__id' in r)) {
215
- const ids = target === null || target === void 0 ? void 0 : target.map((r) => r.__id).filter(Boolean);
216
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
217
- return await this.api.records.detach(sourceId, ids, options, transaction);
218
- }
219
- else {
220
- throw new errors_js_1.EmptyTargetError('Detach error: Target ids are empty');
221
- }
222
- }
223
- // target is MaybeArray<string>
224
- else {
225
- return await this.api.records.detach(sourceId, target, options, transaction);
226
- }
227
- },
228
- export: async (searchParams, transaction) => {
229
- var _a;
230
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.export(searchParams, transaction);
231
- },
232
- find: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
233
- var _a;
234
- const isTransactionParam = (0, utils_js_2.isTransaction)(searchParamsOrTransaction);
235
- const { id, searchParams } = (0, utils_js_2.createSearchParams)(labelOrSearchParams, searchParamsOrTransaction);
236
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
237
- const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.find({ id, searchParams }, tx));
238
- const result = new record_js_1.DBRecordsArrayInstance(response.data, response.total, searchParamsOrTransaction);
239
- result.init(this);
240
- return result;
241
- },
242
- findById: async (idOrIds, transaction) => {
243
- var _a, _b;
244
- if ((0, utils_js_1.isArray)(idOrIds)) {
245
- const response = (await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findById(idOrIds, transaction)));
246
- const result = new record_js_1.DBRecordsArrayInstance(response.data, response.total);
247
- result.init(this);
248
- return result;
249
- }
250
- else {
251
- const response = (await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.findById(idOrIds, transaction)));
252
- const result = new record_js_1.DBRecordInstance(response.data);
253
- result.init(this);
254
- return result;
255
- }
256
- },
257
- findOne: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
258
- var _a;
259
- const isTransactionParam = (0, utils_js_2.isTransaction)(searchParamsOrTransaction);
260
- const { searchParams } = (0, utils_js_2.createSearchParams)(labelOrSearchParams, searchParamsOrTransaction);
261
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
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);
264
- result.init(this);
265
- return result;
266
- },
267
- findUniq: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
268
- var _a;
269
- const isTransactionParam = (0, utils_js_2.isTransaction)(searchParamsOrTransaction);
270
- const { searchParams } = (0, utils_js_2.createSearchParams)(labelOrSearchParams, searchParamsOrTransaction);
271
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
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);
274
- result.init(this);
275
- return result;
276
- },
277
- properties: async (id, transaction) => {
278
- var _a;
279
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.properties(id, transaction);
280
- },
281
- relations: async (id, transaction) => {
282
- return await this.api.records.relations(id, transaction);
283
- },
284
- set: async (id, data, transaction) => {
285
- var _a, _b;
286
- let response;
287
- if (data instanceof record_js_1.DBRecordDraft) {
288
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.set(id, data, transaction));
289
- }
290
- else if ((0, utils_js_1.isObjectFlat)(data)) {
291
- const properties = (0, utils_js_2.prepareProperties)(data);
292
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.set(id, new record_js_1.DBRecordDraft({ properties }), transaction));
293
- }
294
- else if ((0, utils_js_1.isObject)(data)) {
295
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
296
- }
297
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
298
- const result = new record_js_1.DBRecordInstance(response.data);
299
- result.init(this);
300
- return result;
301
- }
302
- return new record_js_1.DBRecordInstance();
303
- },
304
- update: async (id, data, transaction) => {
305
- var _a, _b;
306
- let response;
307
- if (data instanceof record_js_1.DBRecordDraft) {
308
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.update(id, data, transaction));
309
- }
310
- else if ((0, utils_js_1.isObjectFlat)(data)) {
311
- const properties = (0, utils_js_2.prepareProperties)(data);
312
- const recordDraft = new record_js_1.DBRecordDraft({ properties });
313
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.update(id, recordDraft, transaction));
314
- }
315
- else if ((0, utils_js_1.isObject)(data)) {
316
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
317
- }
318
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
319
- const result = new record_js_1.DBRecordInstance(response.data);
320
- result.init(this);
321
- return result;
322
- }
323
- return new record_js_1.DBRecordInstance();
324
- }
325
- };
326
- }
327
- }
328
- exports.RestAPI = RestAPI;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_BASE_PATH = exports.DEFAULT_PROTOCOL = exports.DEFAULT_PORT = exports.DEFAULT_HOST = void 0;
4
- exports.DEFAULT_HOST = 'api.rushdb.com';
5
- exports.DEFAULT_PORT = 443;
6
- exports.DEFAULT_PROTOCOL = 'https';
7
- exports.DEFAULT_BASE_PATH = '/api/v1';