@rushdb/javascript-sdk 1.19.1 → 2.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 +130 -97
- package/dist/api/api.d.ts +103 -8
- package/dist/api/index.d.ts +1 -1
- package/dist/api/types.d.ts +102 -0
- package/dist/common/constants.d.ts +1 -2
- package/dist/index.cjs +3 -1
- package/dist/index.mjs +3 -1
- package/dist/index.node.d.ts +2 -2
- package/dist/index.worker.d.ts +2 -2
- package/dist/sdk/constants.d.ts +0 -5
- package/dist/sdk/model.d.ts +32 -5
- package/dist/sdk/record.d.ts +48 -28
- package/dist/sdk/types.d.ts +0 -5
- package/dist/sdk/utils.d.ts +1 -2
- package/dist/types/expressions.d.ts +2 -11
- package/dist/types/query.d.ts +93 -3
- package/dist/types/schema.d.ts +0 -2
- package/dist/types/value.d.ts +5 -4
- package/package.json +32 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING
|
|
1
|
+
import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING } from '../common/constants.js';
|
|
2
2
|
import type { MaybeArray, RequireAtLeastOne } from './utils.js';
|
|
3
3
|
import type { BooleanValue, DatetimeObject, DatetimeValue, NullValue, NumberValue, PropertyType, StringValue } from './value.js';
|
|
4
4
|
export type DatetimeExpression = DatetimeValue | RequireAtLeastOne<Record<'$gt' | '$gte' | '$lt' | '$lte' | '$ne', DatetimeObject | DatetimeValue> & Record<'$in' | '$nin', Array<DatetimeObject | DatetimeValue>> & Record<'$exists', BooleanValue>>;
|
|
@@ -6,25 +6,16 @@ export type BooleanExpression = BooleanValue | Record<'$ne' | '$exists', Boolean
|
|
|
6
6
|
export type NullExpression = NullValue | Record<'$ne' | '$exists', NullValue | BooleanValue>;
|
|
7
7
|
export type NumberExpression = NumberValue | RequireAtLeastOne<Record<'$gt' | '$gte' | '$lt' | '$lte' | '$ne', NumberValue> & Record<'$in' | '$nin', Array<NumberValue>> & Record<'$exists', BooleanValue>>;
|
|
8
8
|
export type StringExpression = StringValue | RequireAtLeastOne<Record<'$contains' | '$endsWith' | '$ne' | '$startsWith', StringValue> & Record<'$in' | '$nin', Array<StringValue>> & Record<'$exists', BooleanValue>>;
|
|
9
|
-
export type VectorSearchFn = 'jaccard' | 'overlap' | 'cosine' | 'pearson' | 'euclideanDistance' | 'euclidean';
|
|
10
|
-
export type VectorExpression = {
|
|
11
|
-
$vector: {
|
|
12
|
-
fn: `gds.similarity.${VectorSearchFn}`;
|
|
13
|
-
query: Array<number>;
|
|
14
|
-
threshold: number | RequireAtLeastOne<Record<'$gt' | '$gte' | '$lt' | '$lte' | '$ne', number>>;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
9
|
export type TypeExpression = {
|
|
18
10
|
$type: PropertyType;
|
|
19
11
|
};
|
|
20
|
-
export type PropertyExpression = BooleanExpression | DatetimeExpression | NullExpression | NumberExpression | StringExpression | TypeExpression
|
|
12
|
+
export type PropertyExpression = BooleanExpression | DatetimeExpression | NullExpression | NumberExpression | StringExpression | TypeExpression;
|
|
21
13
|
export type PropertyExpressionByType = {
|
|
22
14
|
[PROPERTY_TYPE_BOOLEAN]: BooleanExpression | TypeExpression;
|
|
23
15
|
[PROPERTY_TYPE_DATETIME]: DatetimeExpression | TypeExpression;
|
|
24
16
|
[PROPERTY_TYPE_NULL]: NullExpression | TypeExpression;
|
|
25
17
|
[PROPERTY_TYPE_NUMBER]: NumberExpression | TypeExpression;
|
|
26
18
|
[PROPERTY_TYPE_STRING]: StringExpression | TypeExpression;
|
|
27
|
-
[PROPERTY_TYPE_VECTOR]: VectorExpression | TypeExpression;
|
|
28
19
|
};
|
|
29
20
|
export type LogicalGrouping<T> = Partial<{
|
|
30
21
|
$and: MaybeArray<T>;
|
package/dist/types/query.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Model, RelationOptions } from '../sdk/index.js';
|
|
2
|
-
import type { BooleanExpression, DatetimeExpression, LogicalGrouping, NullExpression, NumberExpression, PropertyExpression, PropertyExpressionByType, StringExpression
|
|
2
|
+
import type { BooleanExpression, DatetimeExpression, LogicalGrouping, NullExpression, NumberExpression, PropertyExpression, PropertyExpressionByType, StringExpression } from './expressions.js';
|
|
3
3
|
import type { Schema } from './schema.js';
|
|
4
4
|
import type { AnyObject, MaybeArray, RequireAtLeastOne } from './utils.js';
|
|
5
5
|
export type Related<M extends Record<string, Model['schema']> = Models> = keyof M extends never ? AnyObject : {
|
|
@@ -37,6 +37,9 @@ export type Expression<S extends Schema = Schema> = IdExpression | (S extends Sc
|
|
|
37
37
|
export type Where<S extends Schema = Schema> = ((Expression<S> & Related) & LogicalGrouping<Expression<S> & Related>) | LogicalGrouping<Expression<S> & Related>;
|
|
38
38
|
export type OrderDirection = 'asc' | 'desc';
|
|
39
39
|
export type Order<S extends Schema = Schema> = OrderDirection | Partial<Record<keyof S, OrderDirection>>;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated The aggregate clause is deprecated. Use select/groupBy for all metrics/analytics. Only use aggregate for vector similarity until select supports it.
|
|
42
|
+
*/
|
|
40
43
|
export type AggregateCollectFn = {
|
|
41
44
|
alias: string;
|
|
42
45
|
field?: string;
|
|
@@ -46,17 +49,26 @@ export type AggregateCollectFn = {
|
|
|
46
49
|
skip?: number;
|
|
47
50
|
unique?: boolean;
|
|
48
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated See AggregateCollectFn.
|
|
54
|
+
*/
|
|
49
55
|
export type AggregateCollectNestedFn = Omit<AggregateCollectFn, 'field'> & {
|
|
50
56
|
aggregate?: {
|
|
51
57
|
[field: string]: AggregateCollectNestedFn;
|
|
52
58
|
};
|
|
53
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated See AggregateCollectFn.
|
|
62
|
+
*/
|
|
54
63
|
export type AggregateCountFn = {
|
|
55
64
|
field?: string;
|
|
56
65
|
fn: 'count';
|
|
57
66
|
unique?: boolean;
|
|
58
67
|
alias?: string;
|
|
59
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated See AggregateCollectFn.
|
|
71
|
+
*/
|
|
60
72
|
export type AggregateTimeBucketFn = {
|
|
61
73
|
field: string;
|
|
62
74
|
fn: 'timeBucket';
|
|
@@ -64,6 +76,9 @@ export type AggregateTimeBucketFn = {
|
|
|
64
76
|
granularity: 'day' | 'week' | 'month' | 'quarter' | 'year' | 'months';
|
|
65
77
|
size?: number;
|
|
66
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated The aggregate clause is deprecated. Use select/groupBy for all metrics/analytics. Only use aggregate for vector similarity until select supports it.
|
|
81
|
+
*/
|
|
67
82
|
export type AggregateFn<S extends Schema = Schema> = {
|
|
68
83
|
field: string;
|
|
69
84
|
fn: 'avg';
|
|
@@ -83,10 +98,13 @@ export type AggregateFn<S extends Schema = Schema> = {
|
|
|
83
98
|
alias?: string;
|
|
84
99
|
} | {
|
|
85
100
|
field: string;
|
|
86
|
-
fn:
|
|
101
|
+
fn: 'vector.similarity.cosine' | 'vector.similarity.euclidean';
|
|
87
102
|
alias?: string;
|
|
88
103
|
query: number[];
|
|
89
104
|
} | AggregateTimeBucketFn | AggregateCollectFn;
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated See AggregateCollectFn.
|
|
107
|
+
*/
|
|
90
108
|
export type Aggregate = {
|
|
91
109
|
[field: string]: AggregateCollectNestedFn;
|
|
92
110
|
} | {
|
|
@@ -119,7 +137,79 @@ export type AggregateClause = {
|
|
|
119
137
|
export type GroupByClause = {
|
|
120
138
|
groupBy?: Array<string>;
|
|
121
139
|
};
|
|
122
|
-
export type
|
|
140
|
+
export type CollectExpr = {
|
|
141
|
+
from: string;
|
|
142
|
+
select?: SelectExprMap;
|
|
143
|
+
orderBy?: Order;
|
|
144
|
+
limit?: number;
|
|
145
|
+
skip?: number;
|
|
146
|
+
unique?: boolean;
|
|
147
|
+
};
|
|
148
|
+
export type TimeBucketExpr = {
|
|
149
|
+
/** Field reference, e.g. "$record.createdAt" */
|
|
150
|
+
field: string;
|
|
151
|
+
unit: 'day' | 'week' | 'month' | 'quarter' | 'year' | 'months' | 'hour' | 'minute' | 'second' | 'hours' | 'minutes' | 'seconds' | 'years';
|
|
152
|
+
/** Required when unit is months/hours/minutes/seconds/years */
|
|
153
|
+
size?: number;
|
|
154
|
+
};
|
|
155
|
+
export type Expr = string | number | boolean | {
|
|
156
|
+
$ref: string;
|
|
157
|
+
} | {
|
|
158
|
+
$sum: Expr;
|
|
159
|
+
} | {
|
|
160
|
+
$avg: Expr;
|
|
161
|
+
$precision?: number;
|
|
162
|
+
} | {
|
|
163
|
+
$count: '*' | Expr;
|
|
164
|
+
} | {
|
|
165
|
+
$min: Expr;
|
|
166
|
+
} | {
|
|
167
|
+
$max: Expr;
|
|
168
|
+
} | {
|
|
169
|
+
$divide: [Expr, Expr];
|
|
170
|
+
} | {
|
|
171
|
+
$multiply: [Expr, Expr];
|
|
172
|
+
} | {
|
|
173
|
+
$add: [Expr, Expr];
|
|
174
|
+
} | {
|
|
175
|
+
$subtract: [Expr, Expr];
|
|
176
|
+
} | {
|
|
177
|
+
$collect: CollectExpr;
|
|
178
|
+
} | {
|
|
179
|
+
$timeBucket: TimeBucketExpr;
|
|
180
|
+
};
|
|
181
|
+
/** Canonical output-shaping clause — replaces `aggregate` */
|
|
182
|
+
export type SelectExprMap = Record<string, Expr>;
|
|
183
|
+
type InferExprType<E extends Expr> = E extends string ? any : E extends number ? number : E extends boolean ? boolean : E extends {
|
|
184
|
+
$sum: any;
|
|
185
|
+
} ? number : E extends {
|
|
186
|
+
$avg: any;
|
|
187
|
+
} ? number : E extends {
|
|
188
|
+
$count: any;
|
|
189
|
+
} ? number : E extends {
|
|
190
|
+
$min: any;
|
|
191
|
+
} ? number : E extends {
|
|
192
|
+
$max: any;
|
|
193
|
+
} ? number : E extends {
|
|
194
|
+
$divide: any;
|
|
195
|
+
} ? number : E extends {
|
|
196
|
+
$multiply: any;
|
|
197
|
+
} ? number : E extends {
|
|
198
|
+
$add: any;
|
|
199
|
+
} ? number : E extends {
|
|
200
|
+
$subtract: any;
|
|
201
|
+
} ? number : E extends {
|
|
202
|
+
$collect: any;
|
|
203
|
+
} ? Array<any> : E extends {
|
|
204
|
+
$timeBucket: any;
|
|
205
|
+
} ? string : any;
|
|
206
|
+
export type ExtractSelectFields<S extends SelectExprMap> = {
|
|
207
|
+
[K in keyof S]: InferExprType<S[K]>;
|
|
208
|
+
};
|
|
209
|
+
export type SelectClause = {
|
|
210
|
+
select?: SelectExprMap;
|
|
211
|
+
};
|
|
212
|
+
export type SearchQuery<S extends Schema = any> = SearchQueryLabelsClause & PaginationClause & OrderClause<S> & WhereClause<S> & SelectClause & AggregateClause & GroupByClause;
|
|
123
213
|
/** Redeclare Models type in order to have suggestions over related records fields **/
|
|
124
214
|
export interface Models {
|
|
125
215
|
}
|
package/dist/types/schema.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ type TypeMappingWrite = {
|
|
|
15
15
|
null: null;
|
|
16
16
|
number: number;
|
|
17
17
|
string: string;
|
|
18
|
-
vector: Array<number>;
|
|
19
18
|
};
|
|
20
19
|
export type OptionalKeysWrite<S extends Schema = Schema> = {
|
|
21
20
|
[Key in keyof S]: S[Key]['required'] extends false ? Key : S[Key]['default'] extends SchemaDefaultValue ? Key : never;
|
|
@@ -34,7 +33,6 @@ type TypeMappingRead = {
|
|
|
34
33
|
null: null;
|
|
35
34
|
number: number;
|
|
36
35
|
string: string;
|
|
37
|
-
vector: Array<number>;
|
|
38
36
|
};
|
|
39
37
|
export type OptionalKeysRead<S extends Schema = Schema> = {
|
|
40
38
|
[Key in keyof S]: S[Key]['required'] extends false ? Key : never;
|
package/dist/types/value.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING
|
|
1
|
+
import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING } from '../common/constants.js';
|
|
2
2
|
import type { MaybeArray } from './utils.js';
|
|
3
3
|
export type DatetimeObject = {
|
|
4
4
|
$day?: number;
|
|
@@ -16,7 +16,7 @@ export type BooleanValue = boolean;
|
|
|
16
16
|
export type NullValue = null;
|
|
17
17
|
export type NumberValue = number;
|
|
18
18
|
export type StringValue = string;
|
|
19
|
-
export type PropertyType = typeof PROPERTY_TYPE_BOOLEAN | typeof PROPERTY_TYPE_DATETIME | typeof PROPERTY_TYPE_NULL | typeof PROPERTY_TYPE_NUMBER | typeof PROPERTY_TYPE_STRING
|
|
19
|
+
export type PropertyType = typeof PROPERTY_TYPE_BOOLEAN | typeof PROPERTY_TYPE_DATETIME | typeof PROPERTY_TYPE_NULL | typeof PROPERTY_TYPE_NUMBER | typeof PROPERTY_TYPE_STRING;
|
|
20
20
|
type WithId<T> = T & {
|
|
21
21
|
id: string;
|
|
22
22
|
};
|
|
@@ -27,6 +27,7 @@ export type Property = WithId<{
|
|
|
27
27
|
metadata?: string;
|
|
28
28
|
name: string;
|
|
29
29
|
type: PropertyType;
|
|
30
|
+
recordsCount?: number;
|
|
30
31
|
}>;
|
|
31
32
|
export type PropertyWithValue = WithValue<Property>;
|
|
32
33
|
export type PropertyValuesData = {
|
|
@@ -37,6 +38,6 @@ export type PropertyValuesData = {
|
|
|
37
38
|
export type PropertyDraft = Omit<PropertyWithValue, 'id'> & {
|
|
38
39
|
valueSeparator?: string;
|
|
39
40
|
};
|
|
40
|
-
export type PropertySingleValue<TType extends PropertyType = PropertyType> = TType extends typeof PROPERTY_TYPE_DATETIME ? DatetimeValue : TType extends typeof PROPERTY_TYPE_NUMBER ? NumberValue : TType extends typeof PROPERTY_TYPE_STRING ? StringValue : TType extends typeof PROPERTY_TYPE_NULL ? NullValue : TType extends typeof PROPERTY_TYPE_BOOLEAN ? BooleanValue :
|
|
41
|
-
export type PropertyValue<TType extends PropertyType = PropertyType> =
|
|
41
|
+
export type PropertySingleValue<TType extends PropertyType = PropertyType> = TType extends typeof PROPERTY_TYPE_DATETIME ? DatetimeValue : TType extends typeof PROPERTY_TYPE_NUMBER ? NumberValue : TType extends typeof PROPERTY_TYPE_STRING ? StringValue : TType extends typeof PROPERTY_TYPE_NULL ? NullValue : TType extends typeof PROPERTY_TYPE_BOOLEAN ? BooleanValue : StringValue;
|
|
42
|
+
export type PropertyValue<TType extends PropertyType = PropertyType> = MaybeArray<PropertySingleValue<TType>>;
|
|
42
43
|
export {};
|
package/package.json
CHANGED
|
@@ -1,39 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushdb/javascript-sdk",
|
|
3
|
-
"description": "RushDB
|
|
3
|
+
"description": "RushDB JavaScript SDK — memory layer for AI agents and modern apps",
|
|
4
4
|
"keywords": [
|
|
5
|
+
"rushdb",
|
|
5
6
|
"database",
|
|
6
7
|
"graph database",
|
|
7
|
-
"instant database",
|
|
8
|
-
"instant-database",
|
|
9
|
-
"instantdatabase",
|
|
10
|
-
"instant db",
|
|
11
|
-
"instant-db",
|
|
12
|
-
"instantdb",
|
|
13
|
-
"neo4j",
|
|
14
|
-
"cypher",
|
|
15
|
-
"ai",
|
|
16
|
-
"ai database",
|
|
17
|
-
"etl",
|
|
18
|
-
"data-pipeline",
|
|
19
|
-
"data science",
|
|
20
|
-
"data-science",
|
|
21
|
-
"data management",
|
|
22
|
-
"data-management",
|
|
23
|
-
"machine learning",
|
|
24
|
-
"machine-learning",
|
|
25
|
-
"persistence",
|
|
26
|
-
"db",
|
|
27
|
-
"graph",
|
|
28
|
-
"graphs",
|
|
29
8
|
"graph-database",
|
|
9
|
+
"ai memory",
|
|
10
|
+
"ai-memory",
|
|
11
|
+
"agent memory",
|
|
12
|
+
"agent-memory",
|
|
13
|
+
"memory layer",
|
|
14
|
+
"memory-layer",
|
|
15
|
+
"ai agents",
|
|
16
|
+
"ai-agents",
|
|
17
|
+
"llm memory",
|
|
18
|
+
"llm-memory",
|
|
19
|
+
"mcp",
|
|
20
|
+
"vector search",
|
|
21
|
+
"vector-search",
|
|
22
|
+
"rag",
|
|
23
|
+
"embedding",
|
|
24
|
+
"embeddings",
|
|
25
|
+
"knowledge graph",
|
|
26
|
+
"knowledge-graph",
|
|
27
|
+
"json normalization",
|
|
28
|
+
"json-normalization",
|
|
29
|
+
"schema-less",
|
|
30
|
+
"schemaless",
|
|
31
|
+
"no-schema",
|
|
30
32
|
"self-hosted",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
33
|
+
"rest api",
|
|
34
|
+
"rest-api",
|
|
35
|
+
"graph",
|
|
36
|
+
"relationships",
|
|
37
|
+
"persistence",
|
|
38
|
+
"rush-db"
|
|
34
39
|
],
|
|
35
40
|
"license": "Apache-2.0",
|
|
36
|
-
"version": "
|
|
41
|
+
"version": "2.0.0",
|
|
37
42
|
"type": "module",
|
|
38
43
|
"files": [
|
|
39
44
|
"dist"
|