@rushdb/javascript-sdk 0.17.1 → 1.0.1

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.
@@ -1,4 +1,4 @@
1
- import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING } from '../common/constants.js';
1
+ import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING, PROPERTY_TYPE_VECTOR } from '../common/constants.js';
2
2
  import type { MaybeArray, RequireAtLeastOne } from './utils.js';
3
3
  import type { BooleanValue, DatetimeObject, DatetimeValue, NullValue, NumberValue, 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>>>;
@@ -6,13 +6,22 @@ export type BooleanExpression = BooleanValue | Record<'$ne', BooleanValue>;
6
6
  export type NullExpression = NullValue | Record<'$ne', NullValue>;
7
7
  export type NumberExpression = NumberValue | RequireAtLeastOne<Record<'$gt' | '$gte' | '$lt' | '$lte' | '$ne', NumberValue> & Record<'$in' | '$nin', Array<NumberValue>>>;
8
8
  export type StringExpression = StringValue | RequireAtLeastOne<Record<'$contains' | '$endsWith' | '$ne' | '$startsWith', StringValue> & Record<'$in' | '$nin', Array<StringValue>>>;
9
- export type PropertyExpression = BooleanExpression | DatetimeExpression | NullExpression | NumberExpression | StringExpression;
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
+ export type PropertyExpression = BooleanExpression | DatetimeExpression | NullExpression | NumberExpression | StringExpression | VectorExpression;
10
18
  export type PropertyExpressionByType = {
11
19
  [PROPERTY_TYPE_BOOLEAN]: BooleanExpression;
12
20
  [PROPERTY_TYPE_DATETIME]: DatetimeExpression;
13
21
  [PROPERTY_TYPE_NULL]: NullExpression;
14
22
  [PROPERTY_TYPE_NUMBER]: NumberExpression;
15
23
  [PROPERTY_TYPE_STRING]: StringExpression;
24
+ [PROPERTY_TYPE_VECTOR]: VectorExpression;
16
25
  };
17
26
  export type LogicalGrouping<T> = Partial<{
18
27
  $and: MaybeArray<T>;
@@ -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 } from './expressions.js';
2
+ import type { BooleanExpression, DatetimeExpression, LogicalGrouping, NullExpression, NumberExpression, PropertyExpression, PropertyExpressionByType, StringExpression, VectorSearchFn } 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 : {
@@ -73,6 +73,11 @@ export type AggregateFn<S extends Schema = Schema> = {
73
73
  field?: string;
74
74
  fn: 'count';
75
75
  uniq?: boolean;
76
+ } | {
77
+ field: string;
78
+ fn: `gds.similarity.${VectorSearchFn}`;
79
+ alias: string;
80
+ query: number[];
76
81
  } | AggregateCollectFn;
77
82
  export type Aggregate = {
78
83
  [field: string]: AggregateCollectNestedFn;
@@ -83,7 +88,7 @@ type InferAggregateType<T extends AggregateFn | string> = T extends string ? any
83
88
  fn: 'sum' | 'avg' | 'min' | 'max' | 'count';
84
89
  } ? number : T extends {
85
90
  fn: 'collect';
86
- } ? any[] : never;
91
+ } ? Array<any> : never;
87
92
  export type ExtractAggregateFields<A extends Record<string, AggregateFn>> = {
88
93
  [K in keyof A]: InferAggregateType<A[K]>;
89
94
  };
@@ -95,7 +100,7 @@ export type PaginationClause = {
95
100
  skip?: number;
96
101
  };
97
102
  export type SearchQueryLabelsClause = {
98
- labels?: string[];
103
+ labels?: Array<string>;
99
104
  };
100
105
  export type OrderClause<S extends Schema = Schema> = {
101
106
  orderBy?: Order<S>;
@@ -15,6 +15,7 @@ type TypeMappingWrite = {
15
15
  null: null;
16
16
  number: number;
17
17
  string: string;
18
+ vector: Array<number>;
18
19
  };
19
20
  export type OptionalKeysWrite<S extends Schema = Schema> = {
20
21
  [Key in keyof S]: S[Key]['required'] extends false ? Key : S[Key]['default'] extends SchemaDefaultValue ? Key : never;
@@ -23,9 +24,9 @@ export type RequiredKeysWrite<S extends Schema = Schema> = {
23
24
  [Key in keyof S]: S[Key]['required'] extends false ? never : S[Key]['default'] extends SchemaDefaultValue ? never : Key;
24
25
  }[keyof S];
25
26
  export type InferSchemaTypesWrite<S extends Schema = Schema> = FlattenTypes<{
26
- [Key in RequiredKeysWrite<S>]: S[Key]['multiple'] extends true ? TypeMappingWrite[S[Key]['type']][] : TypeMappingWrite[S[Key]['type']];
27
+ [Key in RequiredKeysWrite<S>]: S[Key]['multiple'] extends true ? Array<TypeMappingWrite[S[Key]['type']]> : TypeMappingWrite[S[Key]['type']];
27
28
  } & {
28
- [Key in OptionalKeysWrite<S>]?: S[Key]['multiple'] extends true ? TypeMappingWrite[S[Key]['type']][] : TypeMappingWrite[S[Key]['type']];
29
+ [Key in OptionalKeysWrite<S>]?: S[Key]['multiple'] extends true ? Array<TypeMappingWrite[S[Key]['type']]> : TypeMappingWrite[S[Key]['type']];
29
30
  }>;
30
31
  type TypeMappingRead = {
31
32
  boolean: boolean;
@@ -33,6 +34,7 @@ type TypeMappingRead = {
33
34
  null: null;
34
35
  number: number;
35
36
  string: string;
37
+ vector: Array<number>;
36
38
  };
37
39
  export type OptionalKeysRead<S extends Schema = Schema> = {
38
40
  [Key in keyof S]: S[Key]['required'] extends false ? Key : never;
@@ -41,8 +43,8 @@ export type RequiredKeysRead<S extends Schema = Schema> = {
41
43
  [Key in keyof S]: S[Key]['required'] extends false ? never : Key;
42
44
  }[keyof S];
43
45
  export type InferSchemaTypesRead<S extends Schema = Schema> = FlattenTypes<{
44
- [Key in RequiredKeysRead<S>]: S[Key]['multiple'] extends true ? TypeMappingRead[S[Key]['type']][] : TypeMappingRead[S[Key]['type']];
46
+ [Key in RequiredKeysRead<S>]: S[Key]['multiple'] extends true ? Array<TypeMappingRead[S[Key]['type']]> : TypeMappingRead[S[Key]['type']];
45
47
  } & {
46
- [Key in OptionalKeysRead<S>]?: S[Key]['multiple'] extends true ? TypeMappingRead[S[Key]['type']][] : TypeMappingRead[S[Key]['type']];
48
+ [Key in OptionalKeysRead<S>]?: S[Key]['multiple'] extends true ? Array<TypeMappingRead[S[Key]['type']]> : TypeMappingRead[S[Key]['type']];
47
49
  }>;
48
50
  export {};
@@ -1,3 +1,4 @@
1
+ import type { PropertyValue } from './value';
1
2
  export type MaybePromise<T = any> = () => Promise<T> | T;
2
3
  export type RequireAtLeastOne<T> = {
3
4
  [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>;
@@ -7,3 +8,4 @@ export type FlattenTypes<T> = T extends object ? {
7
8
  [K in keyof T]: FlattenTypes<T[K]>;
8
9
  } : T;
9
10
  export type AnyObject = Record<string, any>;
11
+ export type FlatObject = Record<PropertyKey, PropertyValue>;
@@ -1,6 +1,6 @@
1
- import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING } from '../common/constants.js';
1
+ import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING, PROPERTY_TYPE_VECTOR } from '../common/constants.js';
2
2
  import type { MaybeArray } from './utils.js';
3
- import type { OrderDirection } from './query';
3
+ import type { OrderDirection } from './query.js';
4
4
  export type DatetimeObject = {
5
5
  $day?: number;
6
6
  $hour?: number;
@@ -17,20 +17,26 @@ export type BooleanValue = boolean;
17
17
  export type NullValue = null;
18
18
  export type NumberValue = number;
19
19
  export type StringValue = string;
20
- export type PropertyType = typeof PROPERTY_TYPE_BOOLEAN | typeof PROPERTY_TYPE_DATETIME | typeof PROPERTY_TYPE_NULL | typeof PROPERTY_TYPE_NUMBER | typeof PROPERTY_TYPE_STRING;
21
- export type Property = {
20
+ export type PropertyType = typeof PROPERTY_TYPE_BOOLEAN | typeof PROPERTY_TYPE_DATETIME | typeof PROPERTY_TYPE_NULL | typeof PROPERTY_TYPE_NUMBER | typeof PROPERTY_TYPE_STRING | typeof PROPERTY_TYPE_VECTOR;
21
+ type WithId<T> = T & {
22
22
  id: string;
23
- metadata?: string;
24
- name: string;
25
- type: PropertyType;
26
23
  };
27
- export type PropertyWithValue = Property & {
24
+ type WithValue<T> = T & {
28
25
  value: PropertyValue;
29
26
  };
27
+ export type Property = WithId<{
28
+ metadata?: string;
29
+ name: string;
30
+ type: PropertyType;
31
+ }>;
32
+ export type PropertyWithValue = WithValue<Property>;
30
33
  export type PropertyValuesData = {
31
34
  max?: number;
32
35
  min?: number;
33
- values: PropertyValue[];
36
+ values: Array<PropertyValue>;
37
+ };
38
+ export type PropertyDraft = Omit<PropertyWithValue, 'id'> & {
39
+ valueSeparator?: string;
34
40
  };
35
41
  export type PropertyValuesOptions = {
36
42
  sort?: OrderDirection;
@@ -38,5 +44,6 @@ export type PropertyValuesOptions = {
38
44
  limit?: number;
39
45
  query?: string;
40
46
  };
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>>;
47
+ 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 : TType extends typeof PROPERTY_TYPE_VECTOR ? Array<number> : StringValue;
48
+ export type PropertyValue<TType extends PropertyType = PropertyType> = TType extends typeof PROPERTY_TYPE_VECTOR ? Array<number> : MaybeArray<PropertySingleValue<TType>>;
49
+ export {};
package/package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  "rushdb"
34
34
  ],
35
35
  "license": "Apache-2.0",
36
- "version": "0.17.1",
36
+ "version": "1.0.1",
37
37
  "type": "module",
38
38
  "files": [
39
39
  "dist"
@@ -1,66 +0,0 @@
1
- import type { createFetcher } from '../network/index.js';
2
- import type { DBRecord, DBRecordInferred, DBRecordTarget, Relation, RelationDetachOptions, RelationOptions } from '../sdk/record.js';
3
- import type { Transaction } from '../sdk/transaction.js';
4
- import type { Property, PropertyValuesData, SearchQuery, Schema, MaybeArray, PropertyValuesOptions } from '../types/index.js';
5
- import type { ApiResponse } from './types.js';
6
- import { DBRecordsBatchDraft, DBRecordDraft } from '../sdk/record.js';
7
- import type { Logger } from '../sdk/types.js';
8
- export declare const createApi: (fetcher: ReturnType<typeof createFetcher>, logger?: Logger) => {
9
- labels: {
10
- find<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<Record<string, number>>>;
11
- };
12
- properties: {
13
- delete: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
14
- find: <S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<Property[]>>;
15
- findById: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
16
- values: (id: string, options?: PropertyValuesOptions, transaction?: Transaction | string) => Promise<ApiResponse<Property & PropertyValuesData>>;
17
- };
18
- records: {
19
- attach(source: DBRecordTarget, idOrIds: MaybeArray<string>, options?: RelationOptions, transaction?: Transaction | string): Promise<ApiResponse<{
20
- message: string;
21
- }>>;
22
- create<S extends Schema = any>(data: DBRecordDraft | S, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S> | undefined>>;
23
- createMany<S extends Schema = any>(data: DBRecordsBatchDraft | S[], transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>[]>>;
24
- delete<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
25
- message: string;
26
- }>>;
27
- deleteById(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<ApiResponse<{
28
- message: string;
29
- }>>;
30
- detach(source: DBRecordTarget, idOrIds: MaybeArray<string>, options?: RelationDetachOptions, transaction?: Transaction | string): Promise<ApiResponse<{
31
- message: string;
32
- }>>;
33
- export<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
34
- dateTime: string;
35
- fileContent: string;
36
- }>>;
37
- find<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(params?: {
38
- id?: string;
39
- searchParams: Q;
40
- }, transaction?: Transaction | string): Promise<ApiResponse<DBRecordInferred<S, Q>[]>>;
41
- findById<S extends Schema = any>(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S> | DBRecord<S>[]>>;
42
- findOne<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchParams: Q, transaction?: Transaction | string): Promise<ApiResponse<DBRecordInferred<S, Q>>>;
43
- findUniq<S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchParams: Q, transaction?: Transaction | string): Promise<ApiResponse<DBRecordInferred<S, Q>>>;
44
- properties(target: string, transaction?: Transaction | string): Promise<ApiResponse<Property[]>>;
45
- relations(target: DBRecordTarget, transaction?: Transaction | string): Promise<ApiResponse<Relation[]>>;
46
- set<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | S, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>>>;
47
- update<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | S, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>>>;
48
- };
49
- relations: {
50
- find<S extends Schema = any>(searchParams: SearchQuery<S>, pagination?: Pick<SearchQuery, "limit" | "skip">, transaction?: Transaction | string): Promise<ApiResponse<Relation[]>>;
51
- };
52
- tx: {
53
- begin(config?: Partial<{
54
- ttl: number;
55
- }>): Promise<ApiResponse<{
56
- id: string;
57
- }>>;
58
- commit(id: string): Promise<ApiResponse<{
59
- message: string;
60
- }>>;
61
- get(id: string): Promise<ApiResponse<{
62
- id: string;
63
- }>>;
64
- rollback(id: string): Promise<void>;
65
- };
66
- };