@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.
- 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 +4 -4
- package/{types → dist}/sdk/record.d.ts +3 -3
- package/{types → dist}/sdk/sdk.d.ts +24 -24
- package/{types → dist}/sdk/transaction.d.ts +2 -2
- package/{types → dist}/types/query.d.ts +1 -2
- package/package.json +10 -34
- 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/create-api.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/types.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
package/esm/sdk/utils.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { isObject } from '../common/utils.js';
|
|
2
|
-
import { ALLOWED_CONFIG_PROPERTIES } from './constants.js';
|
|
3
|
-
import { UniquenessError } from './errors.js';
|
|
4
|
-
export const mergeDefaultsWithPayload = async (schema, payload) => {
|
|
5
|
-
const defaultPromises = Object.entries(schema).map(async ([key, prop]) => {
|
|
6
|
-
if (prop.default &&
|
|
7
|
-
typeof prop.default !== 'undefined' &&
|
|
8
|
-
typeof payload[key] === 'undefined') {
|
|
9
|
-
return {
|
|
10
|
-
key,
|
|
11
|
-
value: typeof prop.default === 'function' ? await prop.default() : prop.default
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return { key, value: undefined };
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
const resolvedDefaults = await Promise.all(defaultPromises);
|
|
19
|
-
const defaults = resolvedDefaults.reduce((acc, { key, value }) => {
|
|
20
|
-
if (value !== undefined) {
|
|
21
|
-
acc[key] = value;
|
|
22
|
-
}
|
|
23
|
-
return acc;
|
|
24
|
-
}, {});
|
|
25
|
-
return Object.assign(Object.assign({}, defaults), payload);
|
|
26
|
-
};
|
|
27
|
-
export const pickUniqFieldsFromRecord = (schema, data) => {
|
|
28
|
-
return Object.entries(data)
|
|
29
|
-
.filter(([key]) => { var _a; return (_a = schema[key]) === null || _a === void 0 ? void 0 : _a.uniq; })
|
|
30
|
-
.reduce((acc, [key, value]) => {
|
|
31
|
-
if (key in schema) {
|
|
32
|
-
acc[key] = value;
|
|
33
|
-
}
|
|
34
|
-
return acc;
|
|
35
|
-
}, {});
|
|
36
|
-
};
|
|
37
|
-
export const pickUniqFieldsFromRecords = (data, schema, label) => {
|
|
38
|
-
const properties = {};
|
|
39
|
-
const uniqFields = Object.entries(schema)
|
|
40
|
-
.filter(([_, config]) => config.uniq)
|
|
41
|
-
.reduce((acc, [key]) => {
|
|
42
|
-
acc[key] = true;
|
|
43
|
-
return acc;
|
|
44
|
-
}, {});
|
|
45
|
-
data.forEach((record) => {
|
|
46
|
-
Object.entries(record).forEach(([key, value]) => {
|
|
47
|
-
if (key in uniqFields) {
|
|
48
|
-
if (properties[key]) {
|
|
49
|
-
if (properties[key].includes(value)) {
|
|
50
|
-
throw new UniquenessError(label, { [key]: value });
|
|
51
|
-
}
|
|
52
|
-
properties[key] = [...properties[key], value];
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
properties[key] = [value];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
return properties;
|
|
61
|
-
};
|
|
62
|
-
export const parseConfig = (config) => {
|
|
63
|
-
if (!config) {
|
|
64
|
-
return {};
|
|
65
|
-
}
|
|
66
|
-
if (!isObject(config)) {
|
|
67
|
-
throw new Error('Config must be an object');
|
|
68
|
-
}
|
|
69
|
-
const values = Object.keys(config).filter((value) => !ALLOWED_CONFIG_PROPERTIES.includes(value));
|
|
70
|
-
if (values.length > 0) {
|
|
71
|
-
throw new Error(`Config object may only contain the following: ${ALLOWED_CONFIG_PROPERTIES.join(', ')}`);
|
|
72
|
-
}
|
|
73
|
-
return config;
|
|
74
|
-
};
|
|
75
|
-
export function validateInteger(name, n, defaultVal) {
|
|
76
|
-
if (!Number.isInteger(n)) {
|
|
77
|
-
if (defaultVal !== undefined) {
|
|
78
|
-
return defaultVal;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
throw new Error(`${name} must be an integer`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return n;
|
|
85
|
-
}
|
|
86
|
-
export function idToTimestamp(id) {
|
|
87
|
-
const parts = id.split('-');
|
|
88
|
-
const highBitsHex = parts[0] + parts[1].slice(0, 4);
|
|
89
|
-
return parseInt(highBitsHex, 16);
|
|
90
|
-
}
|
|
91
|
-
export function idToDate(id) {
|
|
92
|
-
return new Date(idToTimestamp(id));
|
|
93
|
-
}
|
package/esm/types/expressions.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/types/index.js
DELETED
package/esm/types/query.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/types/schema.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/types/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/types/value.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/types/index.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { InferType, DBRecord, UserProvidedConfig, Relation } from './sdk'
|
|
2
|
-
|
|
3
|
-
import { DBRecordsBatchDraft, DBRecordDraft, RestAPI, ApiResponse } from './api'
|
|
4
|
-
import { HttpClient, HttpClientResponse } from './network/HttpClient'
|
|
5
|
-
import {
|
|
6
|
-
Model,
|
|
7
|
-
DBRecordInstance,
|
|
8
|
-
DBRecordsArrayInstance,
|
|
9
|
-
Transaction,
|
|
10
|
-
idToDate,
|
|
11
|
-
idToTimestamp,
|
|
12
|
-
EmptyTargetError,
|
|
13
|
-
UniquenessError,
|
|
14
|
-
NonUniqueResultError
|
|
15
|
-
} from './sdk'
|
|
16
|
-
import { Models, Schema } from './types'
|
|
17
|
-
|
|
18
|
-
declare module '@rushdb/javascript-sdk' {
|
|
19
|
-
export namespace RushDB {}
|
|
20
|
-
|
|
21
|
-
export class RushDB extends RestAPI {
|
|
22
|
-
static RushDB: typeof RushDB
|
|
23
|
-
|
|
24
|
-
constructor(token?: string, config?: UserProvidedConfig)
|
|
25
|
-
public api: RestAPI
|
|
26
|
-
|
|
27
|
-
public registerModel<Model extends Model = Model>(model: Model): Model //Model<T['schema']>
|
|
28
|
-
public getModel(label: string): Model
|
|
29
|
-
public getModels(): Map<string, Model>
|
|
30
|
-
public getInstance(token: string, config?: UserProvidedConfig): RushDB
|
|
31
|
-
public toInstance<Schema extends Schema = Schema>(record: DBRecord<Schema>): DBRecordInstance
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export {
|
|
35
|
-
DBRecordsBatchDraft,
|
|
36
|
-
Relation,
|
|
37
|
-
ApiResponse,
|
|
38
|
-
InferType,
|
|
39
|
-
Model,
|
|
40
|
-
Models,
|
|
41
|
-
DBRecord,
|
|
42
|
-
DBRecordDraft,
|
|
43
|
-
DBRecordInstance,
|
|
44
|
-
DBRecordsArrayInstance,
|
|
45
|
-
RestAPI,
|
|
46
|
-
Schema,
|
|
47
|
-
Transaction,
|
|
48
|
-
HttpClient,
|
|
49
|
-
HttpClientResponse,
|
|
50
|
-
EmptyTargetError,
|
|
51
|
-
NonUniqueResultError,
|
|
52
|
-
UniquenessError,
|
|
53
|
-
idToDate,
|
|
54
|
-
idToTimestamp
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export * from './types'
|
|
58
|
-
|
|
59
|
-
export default RushDB
|
|
60
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|