@rushdb/javascript-sdk 0.9.4 → 0.10.0
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/{types → dist}/api/create-api.d.ts +6 -6
- package/{types → dist}/api/types.d.ts +17 -17
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.node.d.ts +137 -0
- package/dist/index.worker.d.ts +137 -0
- package/{types → dist}/sdk/model.d.ts +19 -15
- package/{types → dist}/sdk/record.d.ts +15 -12
- package/{types → dist}/sdk/sdk.d.ts +27 -27
- package/{types → dist}/sdk/transaction.d.ts +2 -2
- package/{types → dist}/types/query.d.ts +15 -8
- package/package.json +36 -39
- package/CHANGELOG.md +0 -180
- package/cjs/api/api.js +0 -328
- package/cjs/api/constants.js +0 -7
- package/cjs/api/create-api.js +0 -323
- package/cjs/api/index.js +0 -8
- package/cjs/api/rest-api-proxy.js +0 -22
- package/cjs/api/types.js +0 -2
- package/cjs/api/utils.js +0 -155
- package/cjs/common/constants.js +0 -10
- package/cjs/common/utils.js +0 -46
- package/cjs/index.cjs.node.js +0 -24
- package/cjs/index.cjs.worker.js +0 -24
- package/cjs/network/FetchHttpClient.js +0 -138
- package/cjs/network/HttpClient.js +0 -59
- package/cjs/network/NodeHttpClient.js +0 -103
- package/cjs/network/index.js +0 -28
- package/cjs/network/types.js +0 -2
- package/cjs/package.json +0 -4
- package/cjs/sdk/constants.js +0 -13
- package/cjs/sdk/errors.js +0 -27
- package/cjs/sdk/index.js +0 -23
- package/cjs/sdk/model.js +0 -147
- package/cjs/sdk/record.js +0 -122
- package/cjs/sdk/sdk.js +0 -46
- package/cjs/sdk/transaction.js +0 -17
- package/cjs/sdk/types.js +0 -2
- package/cjs/sdk/utils.js +0 -103
- package/cjs/types/expressions.js +0 -2
- package/cjs/types/index.js +0 -21
- package/cjs/types/query.js +0 -2
- package/cjs/types/schema.js +0 -2
- package/cjs/types/utils.js +0 -2
- package/cjs/types/value.js +0 -2
- package/esm/api/api.js +0 -324
- package/esm/api/constants.js +0 -4
- package/esm/api/create-api.js +0 -319
- package/esm/api/index.js +0 -2
- package/esm/api/rest-api-proxy.js +0 -18
- package/esm/api/types.js +0 -1
- package/esm/api/utils.js +0 -139
- package/esm/common/constants.js +0 -7
- package/esm/common/utils.js +0 -37
- package/esm/index.esm.node.js +0 -6
- package/esm/index.esm.worker.js +0 -6
- package/esm/network/FetchHttpClient.js +0 -133
- package/esm/network/HttpClient.js +0 -53
- package/esm/network/NodeHttpClient.js +0 -98
- package/esm/network/index.js +0 -24
- package/esm/network/types.js +0 -1
- package/esm/package.json +0 -4
- package/esm/sdk/constants.js +0 -10
- package/esm/sdk/errors.js +0 -21
- package/esm/sdk/index.js +0 -7
- package/esm/sdk/model.js +0 -143
- package/esm/sdk/record.js +0 -115
- package/esm/sdk/sdk.js +0 -42
- package/esm/sdk/transaction.js +0 -13
- package/esm/sdk/types.js +0 -1
- package/esm/sdk/utils.js +0 -93
- package/esm/types/expressions.js +0 -1
- package/esm/types/index.js +0 -5
- package/esm/types/query.js +0 -1
- package/esm/types/schema.js +0 -1
- package/esm/types/utils.js +0 -1
- package/esm/types/value.js +0 -1
- package/types/index.d.ts +0 -60
- /package/{types → dist}/api/api.d.ts +0 -0
- /package/{types → dist}/api/constants.d.ts +0 -0
- /package/{types → dist}/api/index.d.ts +0 -0
- /package/{types → dist}/api/rest-api-proxy.d.ts +0 -0
- /package/{types → dist}/api/utils.d.ts +0 -0
- /package/{types → dist}/common/constants.d.ts +0 -0
- /package/{types → dist}/common/utils.d.ts +0 -0
- /package/{types → dist}/network/FetchHttpClient.d.ts +0 -0
- /package/{types → dist}/network/HttpClient.d.ts +0 -0
- /package/{types → dist}/network/NodeHttpClient.d.ts +0 -0
- /package/{types → dist}/network/index.d.ts +0 -0
- /package/{types → dist}/network/types.d.ts +0 -0
- /package/{types → dist}/sdk/constants.d.ts +0 -0
- /package/{types → dist}/sdk/errors.d.ts +0 -0
- /package/{types → dist}/sdk/index.d.ts +0 -0
- /package/{types → dist}/sdk/types.d.ts +0 -0
- /package/{types → dist}/sdk/utils.d.ts +0 -0
- /package/{types → dist}/types/expressions.d.ts +0 -0
- /package/{types → dist}/types/index.d.ts +0 -0
- /package/{types → dist}/types/schema.d.ts +0 -0
- /package/{types → dist}/types/utils.d.ts +0 -0
- /package/{types → dist}/types/value.d.ts +0 -0
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RestApiProxy = void 0;
|
|
4
|
-
class RestApiProxy {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.apiProxy = {};
|
|
7
|
-
return new Proxy(this, {
|
|
8
|
-
get: (target, prop, receiver) => {
|
|
9
|
-
if (prop in target) {
|
|
10
|
-
return Reflect.get(target, prop, receiver);
|
|
11
|
-
}
|
|
12
|
-
if (this.apiProxy && prop in this.apiProxy) {
|
|
13
|
-
return Reflect.get(this.apiProxy, prop, receiver);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
init(api, methodsWhiteList) {
|
|
19
|
-
this.apiProxy = api;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.RestApiProxy = RestApiProxy;
|
package/cjs/api/types.js
DELETED
package/cjs/api/utils.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildUrl = exports.normalizeRecord = exports.prepareProperties = exports.suggestPropertyType = exports.getValueParameters = exports.arrayIsConsistent = exports.isUUID = exports.createSearchParams = exports.pickRecordId = exports.pickTransactionId = exports.pickTransaction = exports.isTransaction = exports.buildTransactionHeader = void 0;
|
|
4
|
-
const constants_js_1 = require("../common/constants.js");
|
|
5
|
-
const utils_js_1 = require("../common/utils.js");
|
|
6
|
-
const sdk_1 = require("../sdk");
|
|
7
|
-
const transaction_js_1 = require("../sdk/transaction.js");
|
|
8
|
-
const constants_js_2 = require("./constants.js");
|
|
9
|
-
const buildTransactionHeader = (txId) => txId ?
|
|
10
|
-
{
|
|
11
|
-
['x-transaction-id']: txId
|
|
12
|
-
}
|
|
13
|
-
: undefined;
|
|
14
|
-
exports.buildTransactionHeader = buildTransactionHeader;
|
|
15
|
-
const isTransaction = (input) => (0, utils_js_1.isString)(input) || input instanceof transaction_js_1.Transaction;
|
|
16
|
-
exports.isTransaction = isTransaction;
|
|
17
|
-
const pickTransaction = (input) => ((0, exports.isTransaction)(input) ? input : undefined);
|
|
18
|
-
exports.pickTransaction = pickTransaction;
|
|
19
|
-
const pickTransactionId = (input) => (0, exports.isTransaction)(input) ?
|
|
20
|
-
input instanceof transaction_js_1.Transaction ?
|
|
21
|
-
input.id
|
|
22
|
-
: input
|
|
23
|
-
: undefined;
|
|
24
|
-
exports.pickTransactionId = pickTransactionId;
|
|
25
|
-
const pickRecordId = (input) => {
|
|
26
|
-
if ((0, utils_js_1.isString)(input)) {
|
|
27
|
-
return input;
|
|
28
|
-
}
|
|
29
|
-
else if (input instanceof sdk_1.DBRecordInstance && input.data) {
|
|
30
|
-
return input.data.__id;
|
|
31
|
-
}
|
|
32
|
-
else if ('__id' in input) {
|
|
33
|
-
return input.__id;
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
};
|
|
37
|
-
exports.pickRecordId = pickRecordId;
|
|
38
|
-
const createSearchParams = (labelOrSearchParams, searchParamsOrTransaction) => {
|
|
39
|
-
var _a, _b, _c;
|
|
40
|
-
const isFirstArgString = (0, utils_js_1.isString)(labelOrSearchParams);
|
|
41
|
-
const isFirstArgUUID = (0, exports.isUUID)(labelOrSearchParams);
|
|
42
|
-
const isSecondArgTransaction = (0, exports.isTransaction)(searchParamsOrTransaction);
|
|
43
|
-
const isEmptySearchParams = isSecondArgTransaction || !(0, utils_js_1.isObject)(searchParamsOrTransaction);
|
|
44
|
-
if (isFirstArgString) {
|
|
45
|
-
const baseParams = isFirstArgUUID ?
|
|
46
|
-
{ id: labelOrSearchParams }
|
|
47
|
-
: { searchParams: { labels: [labelOrSearchParams] } };
|
|
48
|
-
return isEmptySearchParams ? Object.assign(Object.assign({}, baseParams), { searchParams: Object.assign({}, baseParams.searchParams) }) : Object.assign(Object.assign({}, baseParams), { searchParams: Object.assign(Object.assign({}, searchParamsOrTransaction), { labels: [
|
|
49
|
-
...((_b = (_a = baseParams.searchParams) === null || _a === void 0 ? void 0 : _a.labels) !== null && _b !== void 0 ? _b : []),
|
|
50
|
-
...((_c = searchParamsOrTransaction.labels) !== null && _c !== void 0 ? _c : [])
|
|
51
|
-
] }) });
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return { searchParams: labelOrSearchParams !== null && labelOrSearchParams !== void 0 ? labelOrSearchParams : {} };
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.createSearchParams = createSearchParams;
|
|
58
|
-
const isUUID = (value) => {
|
|
59
|
-
const regex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
|
60
|
-
return regex.test(value);
|
|
61
|
-
};
|
|
62
|
-
exports.isUUID = isUUID;
|
|
63
|
-
const arrayIsConsistent = (arr) => arr.every((item) => typeof item === typeof arr[0]);
|
|
64
|
-
exports.arrayIsConsistent = arrayIsConsistent;
|
|
65
|
-
const getValueParameters = (value) => {
|
|
66
|
-
if (Array.isArray(value)) {
|
|
67
|
-
return {
|
|
68
|
-
isEmptyArray: value.length === 0,
|
|
69
|
-
isEmptyStringsArray: value.every((v) => v === ''),
|
|
70
|
-
isInconsistentArray: !(0, exports.arrayIsConsistent)(value)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
return { isEmptyString: value === '' };
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
exports.getValueParameters = getValueParameters;
|
|
78
|
-
const suggestPropertyType = (value) => {
|
|
79
|
-
if (typeof value === constants_js_1.PROPERTY_TYPE_STRING) {
|
|
80
|
-
return constants_js_1.ISO_8601_FULL.test(value) ? constants_js_1.PROPERTY_TYPE_DATETIME : constants_js_1.PROPERTY_TYPE_STRING;
|
|
81
|
-
}
|
|
82
|
-
else if (typeof value === constants_js_1.PROPERTY_TYPE_NUMBER) {
|
|
83
|
-
return constants_js_1.PROPERTY_TYPE_NUMBER;
|
|
84
|
-
}
|
|
85
|
-
else if (typeof value === constants_js_1.PROPERTY_TYPE_BOOLEAN) {
|
|
86
|
-
return constants_js_1.PROPERTY_TYPE_BOOLEAN;
|
|
87
|
-
}
|
|
88
|
-
else if (value === null) {
|
|
89
|
-
return constants_js_1.PROPERTY_TYPE_NULL;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return constants_js_1.PROPERTY_TYPE_STRING;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
exports.suggestPropertyType = suggestPropertyType;
|
|
96
|
-
const processArrayValue = (value, suggestTypes) => {
|
|
97
|
-
const { isEmptyArray, isInconsistentArray } = (0, exports.getValueParameters)(value);
|
|
98
|
-
if (isEmptyArray) {
|
|
99
|
-
return { type: constants_js_1.PROPERTY_TYPE_STRING, value: [] };
|
|
100
|
-
}
|
|
101
|
-
if (isInconsistentArray || !suggestTypes) {
|
|
102
|
-
return { type: constants_js_1.PROPERTY_TYPE_STRING, value: value.map(String) };
|
|
103
|
-
}
|
|
104
|
-
return { type: (0, exports.suggestPropertyType)(value[0]), value };
|
|
105
|
-
};
|
|
106
|
-
const processNonArrayValue = (value, suggestTypes) => {
|
|
107
|
-
if (!suggestTypes) {
|
|
108
|
-
return { type: constants_js_1.PROPERTY_TYPE_STRING, value: String(value) };
|
|
109
|
-
}
|
|
110
|
-
const type = (0, exports.suggestPropertyType)(value);
|
|
111
|
-
return { type, value: type === constants_js_1.PROPERTY_TYPE_NULL ? null : value };
|
|
112
|
-
};
|
|
113
|
-
const prepareProperties = (data, options = { suggestTypes: true }) => Object.entries(data).map(([name, value]) => {
|
|
114
|
-
const { type, value: processedValue } = (0, utils_js_1.isArray)(value) ?
|
|
115
|
-
processArrayValue(value, options.suggestTypes)
|
|
116
|
-
: processNonArrayValue(value, options.suggestTypes);
|
|
117
|
-
return { name, type, value: processedValue };
|
|
118
|
-
});
|
|
119
|
-
exports.prepareProperties = prepareProperties;
|
|
120
|
-
const normalizeRecord = ({ label, options = { suggestTypes: true }, payload }) => ({
|
|
121
|
-
label,
|
|
122
|
-
properties: (0, exports.prepareProperties)(payload, options)
|
|
123
|
-
});
|
|
124
|
-
exports.normalizeRecord = normalizeRecord;
|
|
125
|
-
const buildUrl = (props) => {
|
|
126
|
-
let protocol = constants_js_2.DEFAULT_PROTOCOL;
|
|
127
|
-
let host = constants_js_2.DEFAULT_HOST;
|
|
128
|
-
let port = constants_js_2.DEFAULT_PORT;
|
|
129
|
-
let basePath = constants_js_2.DEFAULT_BASE_PATH;
|
|
130
|
-
if ('url' in props) {
|
|
131
|
-
const url = new URL(props.url);
|
|
132
|
-
protocol = url.protocol.replace(':', '');
|
|
133
|
-
host = url.hostname;
|
|
134
|
-
port = parseInt(url.port ||
|
|
135
|
-
(protocol === 'http' ? '80'
|
|
136
|
-
: protocol === 'https' ? '443'
|
|
137
|
-
: ''));
|
|
138
|
-
}
|
|
139
|
-
if ('host' in props && 'port' in props && 'protocol' in props) {
|
|
140
|
-
protocol = props.protocol.replace(':', '');
|
|
141
|
-
host = props.host;
|
|
142
|
-
port = props.port;
|
|
143
|
-
}
|
|
144
|
-
// Ensure the basePath starts with a '/'
|
|
145
|
-
if (basePath && !basePath.startsWith('/')) {
|
|
146
|
-
basePath = '/' + basePath;
|
|
147
|
-
}
|
|
148
|
-
// If the port is the default for the protocol (80 for http, 443 for https), it can be omitted
|
|
149
|
-
let portString = '';
|
|
150
|
-
if (!((protocol === 'http' && port === 80) || (protocol === 'https' && port === 443))) {
|
|
151
|
-
portString = ':' + port;
|
|
152
|
-
}
|
|
153
|
-
return `${protocol}://${host}${portString}${basePath}`;
|
|
154
|
-
};
|
|
155
|
-
exports.buildUrl = buildUrl;
|
package/cjs/common/constants.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PROPERTY_TYPE_NULL = exports.PROPERTY_TYPE_NUMBER = exports.PROPERTY_TYPE_BOOLEAN = exports.PROPERTY_TYPE_DATETIME = exports.PROPERTY_TYPE_STRING = exports.DEFAULT_TIMEOUT = exports.ISO_8601_FULL = void 0;
|
|
4
|
-
exports.ISO_8601_FULL = /^(?:\d{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:\d{2}(?:[02468][048]|[13579][26])-02-29))Schema(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])?(?:\.([0-9]{1,9}))?([zZ]?|([\+-])(((([0][0-9])|([1][0-3])):?(([03][0])|([14][5])))|14:00)?)$/;
|
|
5
|
-
exports.DEFAULT_TIMEOUT = 80000;
|
|
6
|
-
exports.PROPERTY_TYPE_STRING = 'string';
|
|
7
|
-
exports.PROPERTY_TYPE_DATETIME = 'datetime';
|
|
8
|
-
exports.PROPERTY_TYPE_BOOLEAN = 'boolean';
|
|
9
|
-
exports.PROPERTY_TYPE_NUMBER = 'number';
|
|
10
|
-
exports.PROPERTY_TYPE_NULL = 'null';
|
package/cjs/common/utils.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toBoolean = exports.isString = exports.isObjectFlat = exports.isEmptyObject = exports.isObject = exports.isArray = void 0;
|
|
4
|
-
const isArray = (item) => typeof item === 'object' && Array.isArray(item) && item !== null;
|
|
5
|
-
exports.isArray = isArray;
|
|
6
|
-
const isObject = (input) => input !== null && Object.prototype.toString.call(input) === '[object Object]';
|
|
7
|
-
exports.isObject = isObject;
|
|
8
|
-
const isEmptyObject = (input) => (0, exports.isObject)(input) && Object.keys(input).length === 0;
|
|
9
|
-
exports.isEmptyObject = isEmptyObject;
|
|
10
|
-
const isObjectFlat = (input) => {
|
|
11
|
-
return ((0, exports.isObject)(input) &&
|
|
12
|
-
Object.keys(input).every((key) => {
|
|
13
|
-
const value = input[key];
|
|
14
|
-
// Check if the value is an array
|
|
15
|
-
if ((0, exports.isArray)(value)) {
|
|
16
|
-
// Check if every element in the array is of an allowed type (string, number, boolean, or null)
|
|
17
|
-
return value.every((element) => typeof element === 'string' ||
|
|
18
|
-
typeof element === 'number' ||
|
|
19
|
-
typeof element === 'boolean' ||
|
|
20
|
-
element === null);
|
|
21
|
-
}
|
|
22
|
-
// Check if the value is a non-null object (excluding arrays, which are also typeof 'object')
|
|
23
|
-
return !(value && typeof value === 'object');
|
|
24
|
-
}));
|
|
25
|
-
};
|
|
26
|
-
exports.isObjectFlat = isObjectFlat;
|
|
27
|
-
const isString = (input) => typeof input === 'string';
|
|
28
|
-
exports.isString = isString;
|
|
29
|
-
const toBoolean = (value) => {
|
|
30
|
-
if (typeof value === 'string') {
|
|
31
|
-
if (value.toLowerCase() === 'true') {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
else if (value.toLowerCase() === 'false') {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if ((0, exports.isArray)(value) && value.length === 0) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
if ((0, exports.isObject)(value) && Object.keys(value).length === 0) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
return Boolean(value);
|
|
45
|
-
};
|
|
46
|
-
exports.toBoolean = toBoolean;
|
package/cjs/index.cjs.node.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const HttpClient_js_1 = require("./network/HttpClient.js");
|
|
4
|
-
const NodeHttpClient_js_1 = require("./network/NodeHttpClient.js");
|
|
5
|
-
const index_js_1 = require("./sdk/index.js");
|
|
6
|
-
const RushDB = (0, index_js_1.initSDK)(new NodeHttpClient_js_1.NodeHttpClient());
|
|
7
|
-
module.exports = {
|
|
8
|
-
RushDB,
|
|
9
|
-
DBRecordsBatchDraft: index_js_1.DBRecordsBatchDraft,
|
|
10
|
-
Model: index_js_1.Model,
|
|
11
|
-
DBRecordInstance: index_js_1.DBRecordInstance,
|
|
12
|
-
DBRecordsArrayInstance: index_js_1.DBRecordsArrayInstance,
|
|
13
|
-
Transaction: index_js_1.Transaction,
|
|
14
|
-
EmptyTargetError: index_js_1.EmptyTargetError,
|
|
15
|
-
HttpClient: HttpClient_js_1.HttpClient,
|
|
16
|
-
HttpClientResponse: HttpClient_js_1.HttpClientResponse,
|
|
17
|
-
NonUniqueResultError: index_js_1.NonUniqueResultError,
|
|
18
|
-
UniquenessError: index_js_1.UniquenessError,
|
|
19
|
-
default: RushDB,
|
|
20
|
-
idToDate: index_js_1.idToDate,
|
|
21
|
-
idToTimestamp: index_js_1.idToTimestamp
|
|
22
|
-
};
|
|
23
|
-
module.exports.RushDB = RushDB;
|
|
24
|
-
module.exports.default = RushDB;
|
package/cjs/index.cjs.worker.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const FetchHttpClient_js_1 = require("./network/FetchHttpClient.js");
|
|
4
|
-
const HttpClient_js_1 = require("./network/HttpClient.js");
|
|
5
|
-
const index_js_1 = require("./sdk/index.js");
|
|
6
|
-
const RushDB = (0, index_js_1.initSDK)(new FetchHttpClient_js_1.FetchHttpClient());
|
|
7
|
-
module.exports = {
|
|
8
|
-
RushDB,
|
|
9
|
-
DBRecordsBatchDraft: index_js_1.DBRecordsBatchDraft,
|
|
10
|
-
Model: index_js_1.Model,
|
|
11
|
-
DBRecordInstance: index_js_1.DBRecordInstance,
|
|
12
|
-
DBRecordsArrayInstance: index_js_1.DBRecordsArrayInstance,
|
|
13
|
-
Transaction: index_js_1.Transaction,
|
|
14
|
-
EmptyTargetError: index_js_1.EmptyTargetError,
|
|
15
|
-
HttpClient: HttpClient_js_1.HttpClient,
|
|
16
|
-
HttpClientResponse: HttpClient_js_1.HttpClientResponse,
|
|
17
|
-
NonUniqueResultError: index_js_1.NonUniqueResultError,
|
|
18
|
-
UniquenessError: index_js_1.UniquenessError,
|
|
19
|
-
default: RushDB,
|
|
20
|
-
idToDate: index_js_1.idToDate,
|
|
21
|
-
idToTimestamp: index_js_1.idToTimestamp
|
|
22
|
-
};
|
|
23
|
-
module.exports.RushDB = RushDB;
|
|
24
|
-
module.exports.default = RushDB;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FetchHttpClientResponse = exports.FetchHttpClient = void 0;
|
|
4
|
-
const constants_js_1 = require("../common/constants.js");
|
|
5
|
-
const HttpClient_js_1 = require("./HttpClient.js");
|
|
6
|
-
/**
|
|
7
|
-
* HTTP client which uses a `fetch` function to issue requests.
|
|
8
|
-
*
|
|
9
|
-
* By default, relies on the global `fetch` function, but an optional function
|
|
10
|
-
* can be passed in. If passing in a function, it is expected to match the Web
|
|
11
|
-
* Fetch API. As an example, this could be the function provided by the
|
|
12
|
-
* node-fetch package (https://github.com/node-fetch/node-fetch).
|
|
13
|
-
*/
|
|
14
|
-
class FetchHttpClient extends HttpClient_js_1.HttpClient {
|
|
15
|
-
constructor(fetchFn) {
|
|
16
|
-
super();
|
|
17
|
-
// Default to global fetch if available
|
|
18
|
-
if (!fetchFn) {
|
|
19
|
-
if (!globalThis.fetch) {
|
|
20
|
-
throw new Error('fetch() function not provided and is not defined in the global scope. ' +
|
|
21
|
-
'You must provide a fetch implementation.');
|
|
22
|
-
}
|
|
23
|
-
fetchFn = globalThis.fetch;
|
|
24
|
-
}
|
|
25
|
-
// Both timeout behaviors differs from Node:
|
|
26
|
-
// - Fetch uses a single timeout for the entire length of the request.
|
|
27
|
-
// - Node is more fine-grained and resets the timeout after each stage of the request.
|
|
28
|
-
if (globalThis.AbortController) {
|
|
29
|
-
// Utilise native AbortController if available
|
|
30
|
-
// AbortController was added in Node v15.0.0, v14.17.0
|
|
31
|
-
this._fetchFn = FetchHttpClient.makeFetchWithAbortTimeout(fetchFn);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// Fall back to racing against a timeout promise if not available in the runtime
|
|
35
|
-
// This does not actually cancel the underlying fetch operation or resources
|
|
36
|
-
this._fetchFn = FetchHttpClient.makeFetchWithRaceTimeout(fetchFn);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
static makeFetchWithRaceTimeout(fetchFn) {
|
|
40
|
-
return (url, init, timeout) => {
|
|
41
|
-
let pendingTimeoutId;
|
|
42
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
43
|
-
pendingTimeoutId = setTimeout(() => {
|
|
44
|
-
pendingTimeoutId = null;
|
|
45
|
-
reject(HttpClient_js_1.HttpClient.makeTimeoutError());
|
|
46
|
-
}, timeout);
|
|
47
|
-
});
|
|
48
|
-
const fetchPromise = fetchFn(url, init);
|
|
49
|
-
return Promise.race([fetchPromise, timeoutPromise]).finally(() => {
|
|
50
|
-
if (pendingTimeoutId) {
|
|
51
|
-
clearTimeout(pendingTimeoutId);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
static makeFetchWithAbortTimeout(fetchFn) {
|
|
57
|
-
return async (url, init, timeout) => {
|
|
58
|
-
// Use AbortController because AbortSignal.timeout() was added later in Node v17.3.0, v16.14.0
|
|
59
|
-
const abort = new AbortController();
|
|
60
|
-
let timeoutId = setTimeout(() => {
|
|
61
|
-
timeoutId = null;
|
|
62
|
-
abort.abort(HttpClient_js_1.HttpClient.makeTimeoutError());
|
|
63
|
-
}, timeout);
|
|
64
|
-
try {
|
|
65
|
-
return await fetchFn(url, Object.assign(Object.assign({}, init), { signal: abort.signal }));
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
// Some implementations, like node-fetch, do not respect the reason passed to AbortController.abort()
|
|
69
|
-
// and instead it always throws an AbortError
|
|
70
|
-
// We catch this case to normalise all timeout errors
|
|
71
|
-
if (err.name === 'AbortError') {
|
|
72
|
-
throw HttpClient_js_1.HttpClient.makeTimeoutError();
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
throw err;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
if (timeoutId) {
|
|
80
|
-
clearTimeout(timeoutId);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
async makeRequest(url, { headers, method, protocol, requestData, timeout }) {
|
|
86
|
-
// For methods which expect payloads, we should always pass a body value
|
|
87
|
-
// even when it is empty. Without this, some JS runtimes (eg. Deno) will
|
|
88
|
-
// inject a second Content-Length header.
|
|
89
|
-
const methodHasPayload = method == 'POST' || method == 'PUT' || method == 'PATCH';
|
|
90
|
-
const body = JSON.stringify(requestData) || (methodHasPayload ? '' : undefined);
|
|
91
|
-
const res = await this._fetchFn(url, {
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
body,
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
headers,
|
|
98
|
-
method
|
|
99
|
-
}, timeout !== null && timeout !== void 0 ? timeout : constants_js_1.DEFAULT_TIMEOUT);
|
|
100
|
-
return new FetchHttpClientResponse(res);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.FetchHttpClient = FetchHttpClient;
|
|
104
|
-
class FetchHttpClientResponse extends HttpClient_js_1.HttpClientGenericResponse {
|
|
105
|
-
constructor(res) {
|
|
106
|
-
super(res.status, FetchHttpClientResponse._transformHeadersToObject(res.headers));
|
|
107
|
-
this._res = res;
|
|
108
|
-
}
|
|
109
|
-
getRawResponse() {
|
|
110
|
-
return this._res;
|
|
111
|
-
}
|
|
112
|
-
toStream(streamCompleteCallback) {
|
|
113
|
-
// Unfortunately `fetch` does not have event handlers for when the stream is
|
|
114
|
-
// completely read. We therefore invoke the streamCompleteCallback right
|
|
115
|
-
// away. This callback emits a response event with metadata and completes
|
|
116
|
-
// metrics, so it's ok to do this without waiting for the stream to be
|
|
117
|
-
// completely read.
|
|
118
|
-
streamCompleteCallback();
|
|
119
|
-
// Fetch's `body` property is expected to be a readable stream of the body.
|
|
120
|
-
return this._res.body;
|
|
121
|
-
}
|
|
122
|
-
toJSON() {
|
|
123
|
-
return this._res.json();
|
|
124
|
-
}
|
|
125
|
-
static _transformHeadersToObject(headers) {
|
|
126
|
-
// Fetch uses a Headers instance so this must be converted to a barebones
|
|
127
|
-
// JS object to meet the HttpClient interface.
|
|
128
|
-
const headersObj = {};
|
|
129
|
-
for (const entry of headers) {
|
|
130
|
-
if (!Array.isArray(entry) || entry.length != 2) {
|
|
131
|
-
throw new Error('Response objects produced by the fetch function given to FetchHttpClient do not have an iterable headers map. Response#headers should be an iterable object.');
|
|
132
|
-
}
|
|
133
|
-
headersObj[entry[0]] = entry[1];
|
|
134
|
-
}
|
|
135
|
-
return headersObj;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.FetchHttpClientResponse = FetchHttpClientResponse;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpClientResponse = exports.HttpClientGenericResponse = exports.HttpClient = void 0;
|
|
4
|
-
class HttpClient {
|
|
5
|
-
makeRequest(url, { headers, method, protocol, requestData, timeout }) {
|
|
6
|
-
throw new Error('makeRequest not implemented.');
|
|
7
|
-
}
|
|
8
|
-
static makeTimeoutError() {
|
|
9
|
-
const timeoutErr = new TypeError(HttpClient.TIMEOUT_ERROR_CODE);
|
|
10
|
-
timeoutErr.code = HttpClient.TIMEOUT_ERROR_CODE;
|
|
11
|
-
return timeoutErr;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.HttpClient = HttpClient;
|
|
15
|
-
HttpClient.CONNECTION_CLOSED_ERROR_CODES = ['ECONNRESET', 'EPIPE'];
|
|
16
|
-
HttpClient.TIMEOUT_ERROR_CODE = 'ETIMEDOUT';
|
|
17
|
-
class HttpClientGenericResponse {
|
|
18
|
-
constructor(statusCode, headers) {
|
|
19
|
-
this._statusCode = statusCode;
|
|
20
|
-
this._headers = headers;
|
|
21
|
-
}
|
|
22
|
-
getStatusCode() {
|
|
23
|
-
return this._statusCode;
|
|
24
|
-
}
|
|
25
|
-
getHeaders() {
|
|
26
|
-
return this._headers;
|
|
27
|
-
}
|
|
28
|
-
getRawResponse() {
|
|
29
|
-
throw new Error('getRawResponse not implemented.');
|
|
30
|
-
}
|
|
31
|
-
toStream(streamCompleteCallback) {
|
|
32
|
-
throw new Error('toStream not implemented.');
|
|
33
|
-
}
|
|
34
|
-
toJSON() {
|
|
35
|
-
throw new Error('toJSON not implemented.');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.HttpClientGenericResponse = HttpClientGenericResponse;
|
|
39
|
-
class HttpClientResponse {
|
|
40
|
-
constructor(response) {
|
|
41
|
-
this._res = response;
|
|
42
|
-
}
|
|
43
|
-
getStatusCode() {
|
|
44
|
-
throw new Error('getStatusCode not implemented.');
|
|
45
|
-
}
|
|
46
|
-
getHeaders() {
|
|
47
|
-
throw new Error('getHeaders not implemented.');
|
|
48
|
-
}
|
|
49
|
-
getRawResponse() {
|
|
50
|
-
throw new Error('getRawResponse not implemented.');
|
|
51
|
-
}
|
|
52
|
-
toStream(streamCompleteCallback) {
|
|
53
|
-
throw new Error('toStream not implemented.');
|
|
54
|
-
}
|
|
55
|
-
toJSON() {
|
|
56
|
-
throw new Error('toJSON not implemented.');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.HttpClientResponse = HttpClientResponse;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeHttpClientResponse = exports.NodeHttpClient = void 0;
|
|
4
|
-
const http_ = require("http");
|
|
5
|
-
const https_ = require("https");
|
|
6
|
-
const constants_js_1 = require("../common/constants.js");
|
|
7
|
-
const HttpClient_js_1 = require("./HttpClient.js");
|
|
8
|
-
// `import * as http_ from 'http'` creates a "Module Namespace Exotic Object"
|
|
9
|
-
// which is immune to monkey-patching, whereas http_.default (in an ES Module context)
|
|
10
|
-
// will resolve to the same thing as require('http'), which is
|
|
11
|
-
// monkey-patchable. We care about this because users in their test
|
|
12
|
-
// suites might be using a library like "nock" which relies on the ability
|
|
13
|
-
// to monkey-patch and intercept calls to http.request.
|
|
14
|
-
const http = http_.default || http_;
|
|
15
|
-
const https = https_.default || https_;
|
|
16
|
-
const defaultHttpAgent = new http.Agent({ keepAlive: true });
|
|
17
|
-
const defaultHttpsAgent = new https.Agent({ keepAlive: true });
|
|
18
|
-
class NodeHttpClient extends HttpClient_js_1.HttpClient {
|
|
19
|
-
constructor(agent) {
|
|
20
|
-
super();
|
|
21
|
-
this._agent = agent;
|
|
22
|
-
}
|
|
23
|
-
makeRequest(urlString, { headers, method, protocol, requestData, timeout }) {
|
|
24
|
-
const url = new URL(urlString);
|
|
25
|
-
const isInsecureConnection = protocol === 'http' || url.protocol === 'http:';
|
|
26
|
-
let agent = this._agent;
|
|
27
|
-
if (!agent) {
|
|
28
|
-
agent = isInsecureConnection ? defaultHttpAgent : defaultHttpsAgent;
|
|
29
|
-
}
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
const req = (isInsecureConnection ? http : https).request({
|
|
32
|
-
agent,
|
|
33
|
-
ciphers: 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5',
|
|
34
|
-
headers,
|
|
35
|
-
host: url.hostname,
|
|
36
|
-
method,
|
|
37
|
-
path: url.pathname + url.search,
|
|
38
|
-
port: url.port
|
|
39
|
-
});
|
|
40
|
-
req.setTimeout(timeout !== null && timeout !== void 0 ? timeout : constants_js_1.DEFAULT_TIMEOUT, () => {
|
|
41
|
-
req.destroy(HttpClient_js_1.HttpClient.makeTimeoutError());
|
|
42
|
-
});
|
|
43
|
-
req.on('response', (res) => {
|
|
44
|
-
resolve(new NodeHttpClientResponse(res));
|
|
45
|
-
});
|
|
46
|
-
req.on('error', (error) => {
|
|
47
|
-
reject(error);
|
|
48
|
-
});
|
|
49
|
-
req.once('socket', (socket) => {
|
|
50
|
-
const payload = requestData ? JSON.stringify(requestData) : '';
|
|
51
|
-
if (socket.connecting) {
|
|
52
|
-
socket.once(isInsecureConnection ? 'connect' : 'secureConnect', () => {
|
|
53
|
-
// Send payload; we're safe:
|
|
54
|
-
req.write(payload);
|
|
55
|
-
req.end();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// we're already connected
|
|
60
|
-
req.write(payload);
|
|
61
|
-
req.end();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.NodeHttpClient = NodeHttpClient;
|
|
68
|
-
class NodeHttpClientResponse extends HttpClient_js_1.HttpClientGenericResponse {
|
|
69
|
-
constructor(res) {
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
super(res.statusCode, res.headers || {});
|
|
73
|
-
this._res = res;
|
|
74
|
-
}
|
|
75
|
-
getRawResponse() {
|
|
76
|
-
return this._res;
|
|
77
|
-
}
|
|
78
|
-
toStream(streamCompleteCallback) {
|
|
79
|
-
// The raw response is itself the stream, so we just return that. To be
|
|
80
|
-
// backwards compatible, we should invoke the streamCompleteCallback only
|
|
81
|
-
// once the stream has been fully consumed.
|
|
82
|
-
this._res.once('end', () => streamCompleteCallback());
|
|
83
|
-
return this._res;
|
|
84
|
-
}
|
|
85
|
-
toJSON() {
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
let response = '';
|
|
88
|
-
this._res.setEncoding('utf8');
|
|
89
|
-
this._res.on('data', (chunk) => {
|
|
90
|
-
response += chunk;
|
|
91
|
-
});
|
|
92
|
-
this._res.once('end', () => {
|
|
93
|
-
try {
|
|
94
|
-
resolve(JSON.parse(response));
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
reject(e);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.NodeHttpClientResponse = NodeHttpClientResponse;
|
package/cjs/network/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.createFetcher = void 0;
|
|
15
|
-
const defaultHeaders = {
|
|
16
|
-
'Content-Type': 'application/json'
|
|
17
|
-
};
|
|
18
|
-
const createFetcher = ({ httpClient, token, url }) => async (input, _a) => {
|
|
19
|
-
var { headers: initHeaders } = _a, init = __rest(_a, ["headers"]);
|
|
20
|
-
const response = await httpClient.makeRequest(`${url}${input}`, Object.assign({ credentials: 'omit', headers: Object.assign(Object.assign(Object.assign({}, defaultHeaders), initHeaders), typeof token !== 'undefined' ? { token } : {}) }, init));
|
|
21
|
-
if (response.getStatusCode() >= 200 && response.getStatusCode() < 300) {
|
|
22
|
-
const data = await response.toJSON();
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
|
-
// @TODO: Make it more useful
|
|
26
|
-
throw new Error(`${response.getStatusCode()}`);
|
|
27
|
-
};
|
|
28
|
-
exports.createFetcher = createFetcher;
|
package/cjs/network/types.js
DELETED
package/cjs/package.json
DELETED
package/cjs/sdk/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALLOWED_CONFIG_PROPERTIES = void 0;
|
|
4
|
-
exports.ALLOWED_CONFIG_PROPERTIES = [
|
|
5
|
-
'httpClient',
|
|
6
|
-
'timeout',
|
|
7
|
-
'host',
|
|
8
|
-
'port',
|
|
9
|
-
'protocol',
|
|
10
|
-
'url',
|
|
11
|
-
'validator',
|
|
12
|
-
'logger'
|
|
13
|
-
];
|
package/cjs/sdk/errors.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NonUniqueResultError = exports.EmptyTargetError = exports.UniquenessError = void 0;
|
|
4
|
-
class UniquenessError extends Error {
|
|
5
|
-
constructor(label, properties) {
|
|
6
|
-
super(`Record with label "${label}" and properties ${JSON.stringify(properties)} already exists`);
|
|
7
|
-
this.name = 'UniquenessError';
|
|
8
|
-
Object.setPrototypeOf(this, UniquenessError.prototype);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.UniquenessError = UniquenessError;
|
|
12
|
-
class EmptyTargetError extends Error {
|
|
13
|
-
constructor(message) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = 'EmptyTarget';
|
|
16
|
-
Object.setPrototypeOf(this, EmptyTargetError.prototype);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.EmptyTargetError = EmptyTargetError;
|
|
20
|
-
class NonUniqueResultError extends Error {
|
|
21
|
-
constructor(duplicateCount, searchParams) {
|
|
22
|
-
super(`Expected a unique result but found ${duplicateCount} matches for the provided search parameters: ${JSON.stringify(searchParams)}. Ensure your search parameters uniquely identify a single result.`);
|
|
23
|
-
this.name = 'NonUniqueResultError';
|
|
24
|
-
Object.setPrototypeOf(this, NonUniqueResultError.prototype);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.NonUniqueResultError = NonUniqueResultError;
|