@rushdb/javascript-sdk 0.17.0 → 1.0.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/README.md +75 -59
- package/dist/api/api.d.ts +260 -19
- package/dist/api/index.d.ts +0 -1
- package/dist/api/rest-api-proxy.d.ts +1 -1
- package/dist/api/types.d.ts +0 -60
- package/dist/api/utils.d.ts +3 -33
- package/dist/common/constants.d.ts +2 -0
- package/dist/common/utils.d.ts +4 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.node.d.ts +492 -69
- package/dist/index.worker.d.ts +492 -69
- package/dist/network/HttpClient.d.ts +1 -1
- package/dist/network/types.d.ts +3 -2
- package/dist/sdk/errors.d.ts +2 -1
- package/dist/sdk/model.d.ts +160 -20
- package/dist/sdk/record.d.ts +23 -67
- package/dist/sdk/sdk.d.ts +465 -42
- package/dist/sdk/utils.d.ts +2 -2
- package/dist/types/expressions.d.ts +11 -2
- package/dist/types/query.d.ts +8 -3
- package/dist/types/schema.d.ts +6 -4
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/value.d.ts +18 -11
- package/package.json +1 -1
- package/dist/api/create-api.d.ts +0 -66
|
@@ -21,7 +21,7 @@ export interface HttpClientResponseInterface {
|
|
|
21
21
|
toStream: (streamCompleteCallback: () => void) => unknown;
|
|
22
22
|
}
|
|
23
23
|
export declare class HttpClient implements HttpClientInterface {
|
|
24
|
-
static CONNECTION_CLOSED_ERROR_CODES: string
|
|
24
|
+
static CONNECTION_CLOSED_ERROR_CODES: Array<string>;
|
|
25
25
|
static TIMEOUT_ERROR_CODE: string;
|
|
26
26
|
makeRequest(url: string, { headers, method, protocol, requestData, timeout }: MakeRequestConfig): Promise<HttpClientResponseInterface>;
|
|
27
27
|
static makeTimeoutError(): TimeoutError;
|
package/dist/network/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { MaybeArray } from '../types';
|
|
1
2
|
export type RequestData<T extends Record<string, any> = Record<string, any>> = T;
|
|
2
|
-
export type RequestHeaders = Record<string, number | string
|
|
3
|
-
export type ResponseHeaderValue = string
|
|
3
|
+
export type RequestHeaders = Record<string, number | MaybeArray<string>>;
|
|
4
|
+
export type ResponseHeaderValue = MaybeArray<string>;
|
|
4
5
|
export type ResponseHeaders = Record<string, ResponseHeaderValue>;
|
package/dist/sdk/errors.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SearchQuery } from '../types';
|
|
1
2
|
export declare class UniquenessError extends Error {
|
|
2
3
|
constructor(label: string, properties: any);
|
|
3
4
|
}
|
|
@@ -5,5 +6,5 @@ export declare class EmptyTargetError extends Error {
|
|
|
5
6
|
constructor(message: string);
|
|
6
7
|
}
|
|
7
8
|
export declare class NonUniqueResultError extends Error {
|
|
8
|
-
constructor(duplicateCount: number,
|
|
9
|
+
constructor(duplicateCount: number, searchQuery: SearchQuery);
|
|
9
10
|
}
|
package/dist/sdk/model.d.ts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import type { SearchQuery, Schema, FlattenTypes, InferSchemaTypesRead, InferSchemaTypesWrite, MaybeArray } from '../types/index.js';
|
|
2
|
-
import type { DBRecord, DBRecordInstance, DBRecordsArrayInstance, RelationDetachOptions, RelationOptions, RelationTarget } from './record.js';
|
|
2
|
+
import type { DBRecord, DBRecordInstance, DBRecordsArrayInstance, DBRecordTarget, RelationDetachOptions, RelationOptions, RelationTarget } from './record.js';
|
|
3
3
|
import type { Transaction } from './transaction.js';
|
|
4
4
|
import { RestApiProxy } from '../api/rest-api-proxy.js';
|
|
5
5
|
type RushDBInstance = {
|
|
6
6
|
registerModel(model: Model): void;
|
|
7
|
+
toInstance<S extends Schema = Schema>(record: DBRecord<S>): DBRecordInstance<S, SearchQuery<S>>;
|
|
7
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Represents a model in the RushDB database.
|
|
11
|
+
* A model defines the structure and behavior of a specific type of record in the database.
|
|
12
|
+
* It provides methods for CRUD operations and relationship management.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam S - The schema type that defines the structure of the model's records
|
|
15
|
+
*/
|
|
8
16
|
export declare class Model<S extends Schema = any> extends RestApiProxy {
|
|
9
17
|
readonly label: string;
|
|
10
18
|
readonly schema: S;
|
|
19
|
+
private readonly rushDBInstance?;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new Model instance.
|
|
22
|
+
*
|
|
23
|
+
* @param modelName - The name/label of the model in the database
|
|
24
|
+
* @param schema - The schema definition that describes the model's structure
|
|
25
|
+
* @param RushDBInstance - Optional RushDB instance for model registration.
|
|
26
|
+
* This is the recommended way to register models as it automatically
|
|
27
|
+
* registers the model with the RushDB instance during creation.
|
|
28
|
+
*/
|
|
11
29
|
constructor(modelName: string, schema: S, RushDBInstance?: RushDBInstance);
|
|
12
30
|
/** @description
|
|
13
31
|
* Type helper for a draft version of the schema.
|
|
@@ -35,42 +53,164 @@ export declare class Model<S extends Schema = any> extends RestApiProxy {
|
|
|
35
53
|
* allowing efficient management of multiple records simultaneously.
|
|
36
54
|
*/
|
|
37
55
|
readonly recordsArrayInstance: DBRecordsArrayInstance<S>;
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves the model's label.
|
|
58
|
+
*
|
|
59
|
+
* @returns The label/name of the model
|
|
60
|
+
*/
|
|
38
61
|
getLabel(): string;
|
|
39
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Converts a database record to a record instance with additional methods.
|
|
64
|
+
*
|
|
65
|
+
* @param record - The database record to convert
|
|
66
|
+
* @returns A record instance with additional methods
|
|
67
|
+
* @throws Error if no RushDB instance was provided during initialization
|
|
68
|
+
*/
|
|
69
|
+
toInstance(record: DBRecord<S>): DBRecordInstance<S, SearchQuery<S>>;
|
|
70
|
+
/**
|
|
71
|
+
* Finds records that match the given search criteria.
|
|
72
|
+
*
|
|
73
|
+
* @param searchQuery - Optional search criteria
|
|
74
|
+
* @param transaction - Optional transaction or transaction ID
|
|
75
|
+
* @returns Promise resolving to matching records
|
|
76
|
+
*/
|
|
77
|
+
find<Q extends SearchQuery<S> = SearchQuery<S>>(searchQuery?: Q & {
|
|
40
78
|
labels?: never;
|
|
41
79
|
}, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S, Q>>;
|
|
42
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Finds a single record that matches the given search criteria.
|
|
82
|
+
*
|
|
83
|
+
* @param searchQuery - Optional search criteria
|
|
84
|
+
* @param transaction - Optional transaction or transaction ID
|
|
85
|
+
* @returns Promise resolving to the matching record or null if not found
|
|
86
|
+
*/
|
|
87
|
+
findOne<Q extends SearchQuery<S> = SearchQuery<S>>(searchQuery?: Q & {
|
|
43
88
|
labels?: never;
|
|
44
89
|
limit?: never;
|
|
45
90
|
skip?: never;
|
|
46
|
-
}, transaction?: Transaction | string): Promise<DBRecordInstance<S,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
91
|
+
}, transaction?: Transaction | string): Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
92
|
+
/**
|
|
93
|
+
* Finds a record by its ID.
|
|
94
|
+
*
|
|
95
|
+
* @param id - The ID of the record to find
|
|
96
|
+
* @param transaction - Optional transaction or transaction ID
|
|
97
|
+
* @returns Promise resolving to the matching record or null if not found
|
|
98
|
+
*/
|
|
99
|
+
findById(id: string, transaction?: Transaction | string): Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
100
|
+
/**
|
|
101
|
+
* Finds a unique record that matches the given search criteria.
|
|
102
|
+
*
|
|
103
|
+
* @param searchQuery - Optional search criteria
|
|
104
|
+
* @param transaction - Optional transaction or transaction ID
|
|
105
|
+
* @returns Promise resolving to the unique matching record or null if not found
|
|
106
|
+
*/
|
|
107
|
+
findUniq<Q extends SearchQuery<S> = SearchQuery<S>>(searchQuery?: Q & {
|
|
53
108
|
labels?: never;
|
|
54
109
|
limit?: never;
|
|
55
110
|
skip?: never;
|
|
56
111
|
}, transaction?: Transaction | string): Promise<DBRecordInstance<S, Q>>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a new record in the database.
|
|
114
|
+
*
|
|
115
|
+
* @param record - The record data to create
|
|
116
|
+
* @param transaction - Optional transaction or transaction ID
|
|
117
|
+
* @returns Promise resolving to the created record
|
|
118
|
+
* @throws UniquenessError if the record violates uniqueness constraints
|
|
119
|
+
*/
|
|
57
120
|
create(record: InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
58
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Attaches a relationship between records.
|
|
123
|
+
*
|
|
124
|
+
* @param params - Object containing source, target, and relationship options
|
|
125
|
+
* @param transaction - Optional transaction or transaction ID
|
|
126
|
+
* @returns Promise resolving to the result of the attach operation
|
|
127
|
+
*/
|
|
128
|
+
attach({ source, target, options }: {
|
|
129
|
+
source: DBRecordTarget;
|
|
130
|
+
target: RelationTarget;
|
|
131
|
+
options?: RelationOptions;
|
|
132
|
+
}, transaction?: Transaction | string): Promise<import("../index.node.js").ApiResponse<{
|
|
59
133
|
message: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
134
|
+
}>>;
|
|
135
|
+
/**
|
|
136
|
+
* Detaches a relationship between records.
|
|
137
|
+
*
|
|
138
|
+
* @param params - Object containing source, target, and detach options
|
|
139
|
+
* @param transaction - Optional transaction or transaction ID
|
|
140
|
+
* @returns Promise resolving to the result of the detach operation
|
|
141
|
+
*/
|
|
142
|
+
detach({ source, target, options }: {
|
|
143
|
+
source: DBRecordTarget;
|
|
144
|
+
target: RelationTarget;
|
|
145
|
+
options?: RelationDetachOptions;
|
|
146
|
+
}, transaction?: Transaction | string): Promise<import("../index.node.js").ApiResponse<{
|
|
62
147
|
message: string;
|
|
63
|
-
}
|
|
148
|
+
}>>;
|
|
149
|
+
/**
|
|
150
|
+
* Internal method to handle both set and update operations.
|
|
151
|
+
*
|
|
152
|
+
* @param target - The target record to modify
|
|
153
|
+
* @param record - The data to set or update
|
|
154
|
+
* @param method - The operation type ('set' or 'update')
|
|
155
|
+
* @param transaction - Optional transaction or transaction ID
|
|
156
|
+
* @returns Promise resolving to the modified record
|
|
157
|
+
* @throws UniquenessError if the modification violates uniqueness constraints
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
64
160
|
private handleSetOrUpdate;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Sets all fields of a record to the provided values.
|
|
163
|
+
*
|
|
164
|
+
* @param target - The target record to modify
|
|
165
|
+
* @param record - The new values to set
|
|
166
|
+
* @param transaction - Optional transaction or transaction ID
|
|
167
|
+
* @returns Promise resolving to the modified record
|
|
168
|
+
*/
|
|
169
|
+
set(target: DBRecordTarget, record: InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
170
|
+
/**
|
|
171
|
+
* Updates specified fields of a record.
|
|
172
|
+
*
|
|
173
|
+
* @param target - The target record to modify
|
|
174
|
+
* @param record - The fields to update and their new values
|
|
175
|
+
* @param transaction - Optional transaction or transaction ID
|
|
176
|
+
* @returns Promise resolving to the modified record
|
|
177
|
+
*/
|
|
178
|
+
update(target: DBRecordTarget, record: Partial<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
179
|
+
/**
|
|
180
|
+
* Creates multiple records in a single operation.
|
|
181
|
+
*
|
|
182
|
+
* @param records - Array of records to create
|
|
183
|
+
* @param transaction - Optional transaction or transaction ID
|
|
184
|
+
* @returns Promise resolving to the created records
|
|
185
|
+
* @throws UniquenessError if any record violates uniqueness constraints
|
|
186
|
+
*/
|
|
187
|
+
createMany(records: Array<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S, SearchQuery<S>>>;
|
|
188
|
+
/**
|
|
189
|
+
* Deletes records that match the given search criteria.
|
|
190
|
+
*
|
|
191
|
+
* @param searchQuery - Search criteria for records to delete
|
|
192
|
+
* @param transaction - Optional transaction or transaction ID
|
|
193
|
+
* @returns Promise resolving to the result of the delete operation
|
|
194
|
+
* @throws EmptyTargetError if no search criteria are provided
|
|
195
|
+
*/
|
|
196
|
+
delete(searchQuery: Omit<SearchQuery<S>, 'labels'>, transaction?: Transaction | string): Promise<import("../index.node.js").ApiResponse<{
|
|
69
197
|
message: string;
|
|
70
|
-
}
|
|
198
|
+
}>>;
|
|
199
|
+
/**
|
|
200
|
+
* Deletes one or more records by their IDs.
|
|
201
|
+
*
|
|
202
|
+
* @param idOrIds - Single ID or array of IDs to delete
|
|
203
|
+
* @param transaction - Optional transaction or transaction ID
|
|
204
|
+
* @returns Promise resolving to the result of the delete operation
|
|
205
|
+
*/
|
|
71
206
|
deleteById(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<import("../index.node.js").ApiResponse<{
|
|
72
207
|
message: string;
|
|
73
|
-
}
|
|
208
|
+
}>>;
|
|
74
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Helper type that infers the type structure from a Model instance.
|
|
212
|
+
*
|
|
213
|
+
* @typeParam M - The Model type to infer from
|
|
214
|
+
*/
|
|
75
215
|
export type InferType<M extends Model<any> = Model<any>> = FlattenTypes<InferSchemaTypesRead<M['schema']>>;
|
|
76
216
|
export {};
|
package/dist/sdk/record.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ExtractAggregateFields, FlattenTypes, InferSchemaTypesRead, InferSchemaTypesWrite, MaybeArray, OptionalKeysRead, PropertyDraft, RequiredKeysRead, Schema, SearchQuery } from '../types/index.js';
|
|
2
2
|
import type { Transaction } from './transaction.js';
|
|
3
3
|
import { RestApiProxy } from '../api/rest-api-proxy.js';
|
|
4
4
|
type DBRecordInternalProps<S extends Schema = Schema> = {
|
|
@@ -33,84 +33,40 @@ export type RelationOptions = {
|
|
|
33
33
|
};
|
|
34
34
|
export type RelationDetachOptions = {
|
|
35
35
|
direction?: RelationDirection;
|
|
36
|
-
typeOrTypes?: string
|
|
36
|
+
typeOrTypes?: MaybeArray<string>;
|
|
37
|
+
};
|
|
38
|
+
export type DBRecordCreationOptions = {
|
|
39
|
+
returnResult?: boolean;
|
|
40
|
+
suggestTypes?: boolean;
|
|
41
|
+
castNumberArraysToVectors?: boolean;
|
|
42
|
+
convertNumericValuesToNumbers?: boolean;
|
|
43
|
+
capitalizeLabels?: boolean;
|
|
44
|
+
relationshipType?: string;
|
|
37
45
|
};
|
|
38
|
-
export declare class DBRecordsBatchDraft {
|
|
39
|
-
label: string;
|
|
40
|
-
options?: {
|
|
41
|
-
returnResult?: boolean;
|
|
42
|
-
suggestTypes?: boolean;
|
|
43
|
-
};
|
|
44
|
-
payload: MaybeArray<AnyObject>;
|
|
45
|
-
constructor({ label, options, payload }: {
|
|
46
|
-
label: string;
|
|
47
|
-
options?: {
|
|
48
|
-
returnResult?: boolean;
|
|
49
|
-
suggestTypes?: boolean;
|
|
50
|
-
};
|
|
51
|
-
payload: AnyObject;
|
|
52
|
-
});
|
|
53
|
-
toJson(): {
|
|
54
|
-
label: string;
|
|
55
|
-
options: {
|
|
56
|
-
returnResult?: boolean;
|
|
57
|
-
suggestTypes?: boolean;
|
|
58
|
-
} | undefined;
|
|
59
|
-
payload: MaybeArray<AnyObject>;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
export declare class DBRecordDraft {
|
|
63
|
-
label: string;
|
|
64
|
-
properties?: Array<{
|
|
65
|
-
metadata?: string;
|
|
66
|
-
name: string;
|
|
67
|
-
type: PropertyType;
|
|
68
|
-
value: PropertyValue;
|
|
69
|
-
valueSeparator?: string;
|
|
70
|
-
}>;
|
|
71
|
-
constructor({ label, properties }: {
|
|
72
|
-
label: string;
|
|
73
|
-
properties?: Array<PropertyWithValue & {
|
|
74
|
-
metadata?: string;
|
|
75
|
-
valueSeparator?: string;
|
|
76
|
-
}>;
|
|
77
|
-
relation?: RelationOptions;
|
|
78
|
-
});
|
|
79
|
-
toJson(): {
|
|
80
|
-
label: string;
|
|
81
|
-
properties: {
|
|
82
|
-
metadata?: string;
|
|
83
|
-
name: string;
|
|
84
|
-
type: PropertyType;
|
|
85
|
-
value: PropertyValue;
|
|
86
|
-
valueSeparator?: string;
|
|
87
|
-
}[] | undefined;
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
46
|
export declare class DBRecordInstance<S extends Schema = Schema, Q extends SearchQuery<S> = SearchQuery<S>> extends RestApiProxy {
|
|
91
47
|
data?: DBRecordInferred<S, Q>;
|
|
92
48
|
constructor(data?: DBRecordInferred<S, Q>);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
49
|
+
id(): string;
|
|
50
|
+
label(): string;
|
|
51
|
+
proptypes(): FlattenTypes<FlattenTypes<{ [Key in RequiredKeysRead<S>]: S[Key]["type"]; } & { [Key_1 in OptionalKeysRead<S>]?: S[Key_1]["type"] | undefined; }>> | undefined;
|
|
52
|
+
date(): Date;
|
|
53
|
+
timestamp(): number;
|
|
98
54
|
delete(transaction?: Transaction | string): Promise<import("../index.node.js").ApiResponse<{
|
|
99
55
|
message: string;
|
|
100
|
-
}
|
|
101
|
-
update<S extends Schema = Schema>(
|
|
102
|
-
set<S extends Schema = Schema>(data:
|
|
56
|
+
}>>;
|
|
57
|
+
update<S extends Schema = Schema>(data: Partial<InferSchemaTypesWrite<S>> | Array<PropertyDraft>, transaction?: Transaction | string): Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
58
|
+
set<S extends Schema = Schema>(data: InferSchemaTypesWrite<S> | Array<PropertyDraft>, transaction?: Transaction | string): Promise<DBRecordInstance<S, SearchQuery<S>>>;
|
|
103
59
|
attach(target: RelationTarget, options?: RelationOptions, transaction?: Transaction | string): Promise<import("../index.node.js").ApiResponse<{
|
|
104
60
|
message: string;
|
|
105
|
-
}
|
|
61
|
+
}>>;
|
|
106
62
|
detach(target: RelationTarget, options?: RelationDetachOptions, transaction?: Transaction | string): Promise<import("../index.node.js").ApiResponse<{
|
|
107
63
|
message: string;
|
|
108
|
-
}
|
|
64
|
+
}>>;
|
|
109
65
|
}
|
|
110
66
|
export declare class DBRecordsArrayInstance<S extends Schema = Schema, Q extends SearchQuery<S> = SearchQuery<S>> extends RestApiProxy {
|
|
111
|
-
data?:
|
|
67
|
+
data?: Array<DBRecordInstance<S, Q>>;
|
|
112
68
|
total: number | undefined;
|
|
113
|
-
|
|
114
|
-
constructor(data?:
|
|
69
|
+
searchQuery?: SearchQuery<S>;
|
|
70
|
+
constructor(data?: Array<DBRecordInstance<S, Q>>, total?: number, searchQuery?: SearchQuery<S>);
|
|
115
71
|
}
|
|
116
72
|
export {};
|