@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/cjs/sdk/sdk.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initSDK = void 0;
4
- const api_js_1 = require("../api/api.js");
5
- const constants_js_1 = require("../common/constants.js");
6
- const record_js_1 = require("./record.js");
7
- const utils_js_1 = require("./utils.js");
8
- const initSDK = (httpClient) => {
9
- class RushDB extends api_js_1.RestAPI {
10
- constructor(token, config) {
11
- var _a;
12
- const props = (0, utils_js_1.parseConfig)(config);
13
- super(token, Object.assign(Object.assign({}, props), { httpClient: (_a = props.httpClient) !== null && _a !== void 0 ? _a : httpClient }));
14
- this.state = {
15
- debug: false,
16
- timeout: (0, utils_js_1.validateInteger)('timeout', props.timeout, constants_js_1.DEFAULT_TIMEOUT),
17
- token
18
- };
19
- this.models = new Map();
20
- RushDB.instance = this;
21
- }
22
- static getInstance() {
23
- return RushDB.instance;
24
- }
25
- registerModel(model) {
26
- const label = model.getLabel();
27
- // Inject the API into the model
28
- model.init(this);
29
- this.models.set(label, model);
30
- return model; //as unknown as Model<T['schema']> & Omit<RestAPI, 'find'>
31
- }
32
- getModels() {
33
- return this.models;
34
- }
35
- getModel(label) {
36
- return this.models.get(label);
37
- }
38
- toInstance(record) {
39
- const result = new record_js_1.DBRecordInstance(record);
40
- result.init(this);
41
- return result;
42
- }
43
- }
44
- return RushDB;
45
- };
46
- exports.initSDK = initSDK;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Transaction = void 0;
4
- const rest_api_proxy_js_1 = require("../api/rest-api-proxy.js");
5
- class Transaction extends rest_api_proxy_js_1.RestApiProxy {
6
- constructor(id) {
7
- super();
8
- this.id = id;
9
- }
10
- async rollback() {
11
- return await this.apiProxy.tx.rollback(this.id);
12
- }
13
- async commit() {
14
- return await this.apiProxy.tx.commit(this.id);
15
- }
16
- }
17
- exports.Transaction = Transaction;
package/cjs/sdk/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/sdk/utils.js DELETED
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseConfig = exports.pickUniqFieldsFromRecords = exports.pickUniqFieldsFromRecord = exports.mergeDefaultsWithPayload = void 0;
4
- exports.validateInteger = validateInteger;
5
- exports.idToTimestamp = idToTimestamp;
6
- exports.idToDate = idToDate;
7
- const utils_js_1 = require("../common/utils.js");
8
- const constants_js_1 = require("./constants.js");
9
- const errors_js_1 = require("./errors.js");
10
- const mergeDefaultsWithPayload = async (schema, payload) => {
11
- const defaultPromises = Object.entries(schema).map(async ([key, prop]) => {
12
- if (prop.default &&
13
- typeof prop.default !== 'undefined' &&
14
- typeof payload[key] === 'undefined') {
15
- return {
16
- key,
17
- value: typeof prop.default === 'function' ? await prop.default() : prop.default
18
- };
19
- }
20
- else {
21
- return { key, value: undefined };
22
- }
23
- });
24
- const resolvedDefaults = await Promise.all(defaultPromises);
25
- const defaults = resolvedDefaults.reduce((acc, { key, value }) => {
26
- if (value !== undefined) {
27
- acc[key] = value;
28
- }
29
- return acc;
30
- }, {});
31
- return Object.assign(Object.assign({}, defaults), payload);
32
- };
33
- exports.mergeDefaultsWithPayload = mergeDefaultsWithPayload;
34
- const pickUniqFieldsFromRecord = (schema, data) => {
35
- return Object.entries(data)
36
- .filter(([key]) => { var _a; return (_a = schema[key]) === null || _a === void 0 ? void 0 : _a.uniq; })
37
- .reduce((acc, [key, value]) => {
38
- if (key in schema) {
39
- acc[key] = value;
40
- }
41
- return acc;
42
- }, {});
43
- };
44
- exports.pickUniqFieldsFromRecord = pickUniqFieldsFromRecord;
45
- const pickUniqFieldsFromRecords = (data, schema, label) => {
46
- const properties = {};
47
- const uniqFields = Object.entries(schema)
48
- .filter(([_, config]) => config.uniq)
49
- .reduce((acc, [key]) => {
50
- acc[key] = true;
51
- return acc;
52
- }, {});
53
- data.forEach((record) => {
54
- Object.entries(record).forEach(([key, value]) => {
55
- if (key in uniqFields) {
56
- if (properties[key]) {
57
- if (properties[key].includes(value)) {
58
- throw new errors_js_1.UniquenessError(label, { [key]: value });
59
- }
60
- properties[key] = [...properties[key], value];
61
- }
62
- else {
63
- properties[key] = [value];
64
- }
65
- }
66
- });
67
- });
68
- return properties;
69
- };
70
- exports.pickUniqFieldsFromRecords = pickUniqFieldsFromRecords;
71
- const parseConfig = (config) => {
72
- if (!config) {
73
- return {};
74
- }
75
- if (!(0, utils_js_1.isObject)(config)) {
76
- throw new Error('Config must be an object');
77
- }
78
- const values = Object.keys(config).filter((value) => !constants_js_1.ALLOWED_CONFIG_PROPERTIES.includes(value));
79
- if (values.length > 0) {
80
- throw new Error(`Config object may only contain the following: ${constants_js_1.ALLOWED_CONFIG_PROPERTIES.join(', ')}`);
81
- }
82
- return config;
83
- };
84
- exports.parseConfig = parseConfig;
85
- function validateInteger(name, n, defaultVal) {
86
- if (!Number.isInteger(n)) {
87
- if (defaultVal !== undefined) {
88
- return defaultVal;
89
- }
90
- else {
91
- throw new Error(`${name} must be an integer`);
92
- }
93
- }
94
- return n;
95
- }
96
- function idToTimestamp(id) {
97
- const parts = id.split('-');
98
- const highBitsHex = parts[0] + parts[1].slice(0, 4);
99
- return parseInt(highBitsHex, 16);
100
- }
101
- function idToDate(id) {
102
- return new Date(idToTimestamp(id));
103
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./value.js"), exports);
18
- __exportStar(require("./query.js"), exports);
19
- __exportStar(require("./utils.js"), exports);
20
- __exportStar(require("./schema.js"), exports);
21
- __exportStar(require("./expressions.js"), exports);
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/esm/api/api.js DELETED
@@ -1,324 +0,0 @@
1
- import { isArray, isEmptyObject, isObject, isObjectFlat, isString, toBoolean } from '../common/utils.js';
2
- import { createFetcher } from '../network/index.js';
3
- import { EmptyTargetError } from '../sdk/errors.js';
4
- import { DBRecordsBatchDraft, DBRecordDraft, DBRecordInstance, DBRecordsArrayInstance } from '../sdk/record.js';
5
- import { Transaction } from '../sdk/transaction.js';
6
- import { createApi } from './create-api.js';
7
- import { buildUrl, createSearchParams, isTransaction, normalizeRecord, pickTransaction, prepareProperties } from './utils.js';
8
- export class RestAPI {
9
- constructor(token, config) {
10
- this.relations = {
11
- find: async ({ pagination, search, transaction }) => {
12
- const { searchParams } = createSearchParams(search);
13
- const tx = pickTransaction(transaction);
14
- return await this.api.relations.find(searchParams, pagination, tx);
15
- }
16
- };
17
- this.properties = {
18
- delete: async (id, transaction) => {
19
- var _a;
20
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.delete(id, transaction);
21
- },
22
- find: async (searchParams, transaction) => {
23
- var _a;
24
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.find(searchParams, transaction);
25
- },
26
- findById: async (id, transaction) => {
27
- var _a;
28
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.findById(id, transaction);
29
- },
30
- values: async (id, transaction) => {
31
- var _a;
32
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.values(id, {}, transaction);
33
- }
34
- };
35
- this.labels = {
36
- find: async (searchParams, transaction) => {
37
- return this.api.labels.find(searchParams, transaction);
38
- }
39
- };
40
- this.tx = {
41
- begin: async (config) => {
42
- var _a;
43
- const transaction = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.begin(config));
44
- const result = new Transaction(transaction.data.id);
45
- result.init(this);
46
- return result;
47
- },
48
- commit: async (id) => { var _a; return (_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.commit(id); },
49
- get: async (id) => {
50
- var _a;
51
- const transaction = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.get(id));
52
- const result = new Transaction(transaction.data.id);
53
- result.init(this);
54
- return result;
55
- },
56
- rollback: async (id) => { var _a; return (_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.commit(id); }
57
- };
58
- this.fetcher = null;
59
- if (config === null || config === void 0 ? void 0 : config.httpClient) {
60
- const url = buildUrl(config);
61
- this.fetcher = createFetcher({
62
- httpClient: config.httpClient,
63
- token,
64
- url
65
- });
66
- }
67
- this.api = createApi(this.fetcher, config === null || config === void 0 ? void 0 : config.logger);
68
- this.records = {
69
- attach: async (sourceId, target, options, transaction) => {
70
- var _a, _b;
71
- // target is MaybeArray<DBRecordInstance>
72
- if (target instanceof DBRecordInstance) {
73
- const id = (_a = target.data) === null || _a === void 0 ? void 0 : _a.__id;
74
- if (id) {
75
- return await this.api.records.attach(sourceId, id, options, transaction);
76
- }
77
- else {
78
- throw new EmptyTargetError('Attach error: Target id is empty');
79
- }
80
- }
81
- else if (isArray(target) && target.every((r) => r instanceof DBRecordInstance)) {
82
- const ids = target.map((r) => { var _a; return (_a = r.data) === null || _a === void 0 ? void 0 : _a.__id; }).filter(toBoolean);
83
- if (ids.length) {
84
- return await this.api.records.attach(sourceId, ids, options, transaction);
85
- }
86
- else {
87
- throw new EmptyTargetError('Attach error: Target ids are empty');
88
- }
89
- }
90
- // target is DBRecordsArrayInstance
91
- else if (target instanceof DBRecordsArrayInstance) {
92
- const ids = (_b = target.data) === null || _b === void 0 ? void 0 : _b.map((r) => r.__id).filter(Boolean);
93
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
94
- return await this.api.records.attach(sourceId, ids, options, transaction);
95
- }
96
- else {
97
- throw new EmptyTargetError('Attach error: Target ids are empty');
98
- }
99
- }
100
- // target is MaybeArray<DBRecord>
101
- else if (isObject(target) && '__id' in target) {
102
- return await this.api.records.attach(sourceId, target.__id, options, transaction);
103
- }
104
- else if (isArray(target) && target.every((r) => isObject(r) && '__id' in r)) {
105
- const ids = target === null || target === void 0 ? void 0 : target.map((r) => r.__id).filter(Boolean);
106
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
107
- return await this.api.records.attach(sourceId, ids, options, transaction);
108
- }
109
- else {
110
- throw new EmptyTargetError('Attach error: Target ids are empty');
111
- }
112
- }
113
- // target is MaybeArray<string>
114
- else {
115
- return await this.api.records.attach(sourceId, target, options, transaction);
116
- }
117
- },
118
- create: async (labelOrData, maybeDataOrTransaction, transaction) => {
119
- var _a, _b;
120
- let response;
121
- if (labelOrData instanceof DBRecordDraft) {
122
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.create(labelOrData, pickTransaction(maybeDataOrTransaction)));
123
- }
124
- if (!response && isString(labelOrData)) {
125
- if (isObjectFlat(maybeDataOrTransaction)) {
126
- const normalizedRecord = normalizeRecord({
127
- label: labelOrData,
128
- payload: maybeDataOrTransaction
129
- });
130
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.create(new DBRecordDraft(normalizedRecord), transaction));
131
- }
132
- else if (isObject(maybeDataOrTransaction)) {
133
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
134
- }
135
- }
136
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
137
- const result = new DBRecordInstance(response.data);
138
- result.init(this);
139
- return result;
140
- }
141
- return new DBRecordInstance();
142
- },
143
- createMany: async (labelOrData, maybeDataOrTransaction, transaction) => {
144
- var _a, _b;
145
- let response;
146
- if (labelOrData instanceof DBRecordsBatchDraft) {
147
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.createMany(labelOrData, pickTransaction(maybeDataOrTransaction)));
148
- }
149
- if (!response &&
150
- isString(labelOrData) &&
151
- (isArray(maybeDataOrTransaction) || isObject(maybeDataOrTransaction))) {
152
- const data = new DBRecordsBatchDraft({
153
- label: labelOrData,
154
- payload: maybeDataOrTransaction
155
- });
156
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.createMany(data, transaction));
157
- }
158
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
159
- const result = new DBRecordsArrayInstance(response.data, response.total);
160
- result.init(this);
161
- return result;
162
- }
163
- return new DBRecordsArrayInstance([]);
164
- },
165
- delete: async (searchParams, transaction) => {
166
- var _a;
167
- if (isEmptyObject(searchParams.where)) {
168
- throw new EmptyTargetError(`You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.`);
169
- }
170
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.delete(searchParams, transaction);
171
- },
172
- deleteById: async (idOrIds, transaction) => {
173
- var _a;
174
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.deleteById(idOrIds, transaction);
175
- },
176
- detach: async (sourceId, target, options, transaction) => {
177
- var _a, _b;
178
- // target is MaybeArray<DBRecordInstance>
179
- if (target instanceof DBRecordInstance) {
180
- const id = (_a = target.data) === null || _a === void 0 ? void 0 : _a.__id;
181
- if (id) {
182
- return await this.api.records.detach(sourceId, id, options, transaction);
183
- }
184
- else {
185
- throw new EmptyTargetError('Detach error: Target id is empty');
186
- }
187
- }
188
- else if (isArray(target) && target.every((r) => r instanceof DBRecordInstance)) {
189
- const ids = target.map((r) => { var _a; return (_a = r.data) === null || _a === void 0 ? void 0 : _a.__id; }).filter(Boolean);
190
- if (ids.length) {
191
- return await this.api.records.detach(sourceId, ids, options, transaction);
192
- }
193
- else {
194
- throw new EmptyTargetError('Detach error: Target ids are empty');
195
- }
196
- }
197
- // target is DBRecordsArrayInstance
198
- else if (target instanceof DBRecordsArrayInstance) {
199
- const ids = (_b = target.data) === null || _b === void 0 ? void 0 : _b.map((r) => r.__id).filter(Boolean);
200
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
201
- return await this.api.records.detach(sourceId, ids, options, transaction);
202
- }
203
- else {
204
- throw new EmptyTargetError('Detach error: Target ids are empty');
205
- }
206
- }
207
- // target is MaybeArray<DBRecord>
208
- else if (isObject(target) && '__id' in target) {
209
- return await this.api.records.detach(sourceId, target.__id, options, transaction);
210
- }
211
- else if (isArray(target) && target.every((r) => isObject(r) && '__id' in r)) {
212
- const ids = target === null || target === void 0 ? void 0 : target.map((r) => r.__id).filter(Boolean);
213
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
214
- return await this.api.records.detach(sourceId, ids, options, transaction);
215
- }
216
- else {
217
- throw new EmptyTargetError('Detach error: Target ids are empty');
218
- }
219
- }
220
- // target is MaybeArray<string>
221
- else {
222
- return await this.api.records.detach(sourceId, target, options, transaction);
223
- }
224
- },
225
- export: async (searchParams, transaction) => {
226
- var _a;
227
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.export(searchParams, transaction);
228
- },
229
- find: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
230
- var _a;
231
- const isTransactionParam = isTransaction(searchParamsOrTransaction);
232
- const { id, searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
233
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
234
- const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.find({ id, searchParams }, tx));
235
- const result = new DBRecordsArrayInstance(response.data, response.total, searchParamsOrTransaction);
236
- result.init(this);
237
- return result;
238
- },
239
- findById: async (idOrIds, transaction) => {
240
- var _a, _b;
241
- if (isArray(idOrIds)) {
242
- const response = (await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findById(idOrIds, transaction)));
243
- const result = new DBRecordsArrayInstance(response.data, response.total);
244
- result.init(this);
245
- return result;
246
- }
247
- else {
248
- const response = (await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.findById(idOrIds, transaction)));
249
- const result = new DBRecordInstance(response.data);
250
- result.init(this);
251
- return result;
252
- }
253
- },
254
- findOne: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
255
- var _a;
256
- const isTransactionParam = isTransaction(searchParamsOrTransaction);
257
- const { searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
258
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
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);
261
- result.init(this);
262
- return result;
263
- },
264
- findUniq: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
265
- var _a;
266
- const isTransactionParam = isTransaction(searchParamsOrTransaction);
267
- const { searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
268
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
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);
271
- result.init(this);
272
- return result;
273
- },
274
- properties: async (id, transaction) => {
275
- var _a;
276
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.properties(id, transaction);
277
- },
278
- relations: async (id, transaction) => {
279
- return await this.api.records.relations(id, transaction);
280
- },
281
- set: async (id, data, transaction) => {
282
- var _a, _b;
283
- let response;
284
- if (data instanceof DBRecordDraft) {
285
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.set(id, data, transaction));
286
- }
287
- else if (isObjectFlat(data)) {
288
- const properties = prepareProperties(data);
289
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.set(id, new DBRecordDraft({ properties }), transaction));
290
- }
291
- else if (isObject(data)) {
292
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
293
- }
294
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
295
- const result = new DBRecordInstance(response.data);
296
- result.init(this);
297
- return result;
298
- }
299
- return new DBRecordInstance();
300
- },
301
- update: async (id, data, transaction) => {
302
- var _a, _b;
303
- let response;
304
- if (data instanceof DBRecordDraft) {
305
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.update(id, data, transaction));
306
- }
307
- else if (isObjectFlat(data)) {
308
- const properties = prepareProperties(data);
309
- const recordDraft = new DBRecordDraft({ properties });
310
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.update(id, recordDraft, transaction));
311
- }
312
- else if (isObject(data)) {
313
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
314
- }
315
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
316
- const result = new DBRecordInstance(response.data);
317
- result.init(this);
318
- return result;
319
- }
320
- return new DBRecordInstance();
321
- }
322
- };
323
- }
324
- }
@@ -1,4 +0,0 @@
1
- export const DEFAULT_HOST = 'api.rushdb.com';
2
- export const DEFAULT_PORT = 443;
3
- export const DEFAULT_PROTOCOL = 'https';
4
- export const DEFAULT_BASE_PATH = '/api/v1';