@luxdb/sdk 1.4.2 → 1.4.3
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 +74 -1
- package/dist/cjs/project.js +292 -1
- package/dist/cjs/table.js +52 -61
- package/dist/esm/project.js +290 -0
- package/dist/esm/table.js +52 -61
- package/dist/types/auth.d.ts +84 -0
- package/dist/types/index.d.ts +5 -5
- package/dist/types/project.d.ts +102 -11
- package/dist/types/table.d.ts +17 -19
- package/dist/types/types.d.ts +9 -1
- package/package.json +1 -1
package/dist/types/project.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { LuxAuthClient, type LuxAuthOptions } from './auth';
|
|
2
|
-
import type { LuxResult } from './types';
|
|
2
|
+
import type { LuxResult, LuxTypedRow } from './types';
|
|
3
3
|
export interface LuxProjectOptions {
|
|
4
4
|
url: string;
|
|
5
5
|
key: string;
|
|
6
6
|
fetch?: typeof fetch;
|
|
7
|
+
websocket?: typeof WebSocket;
|
|
7
8
|
auth?: Omit<LuxAuthOptions, 'httpUrl' | 'apiKey' | 'fetch'>;
|
|
8
9
|
}
|
|
9
10
|
export interface LuxTableColumn {
|
|
10
11
|
name: string;
|
|
11
|
-
type: 'STR' | 'INT' | 'FLOAT' | 'BOOL' | 'TIMESTAMP' | 'UUID'
|
|
12
|
+
type: 'STR' | 'INT' | 'FLOAT' | 'BOOL' | 'TIMESTAMP' | 'UUID' | `VECTOR(${number})`;
|
|
12
13
|
primaryKey?: boolean;
|
|
13
14
|
unique?: boolean;
|
|
14
15
|
notNull?: boolean;
|
|
@@ -21,8 +22,10 @@ export interface LuxVectorSearchOptions {
|
|
|
21
22
|
filter?: string;
|
|
22
23
|
filter_value?: string;
|
|
23
24
|
}
|
|
24
|
-
type QueryValue = string | number | boolean | null;
|
|
25
|
+
type QueryValue = string | number | boolean | number[] | null;
|
|
25
26
|
type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'is';
|
|
27
|
+
type ProjectRowInput<T extends object> = Partial<T> & Record<string, QueryValue>;
|
|
28
|
+
type ProjectSelectSingle<TResult> = TResult extends readonly (infer Row)[] ? Row : TResult;
|
|
26
29
|
interface QueryFilter {
|
|
27
30
|
column: string;
|
|
28
31
|
operator: FilterOperator;
|
|
@@ -32,13 +35,51 @@ interface QueryOrder {
|
|
|
32
35
|
column: string;
|
|
33
36
|
ascending: boolean;
|
|
34
37
|
}
|
|
38
|
+
interface QueryJoin {
|
|
39
|
+
type: 'inner' | 'left';
|
|
40
|
+
table: string;
|
|
41
|
+
alias: string;
|
|
42
|
+
onLeft: string;
|
|
43
|
+
onRight: string;
|
|
44
|
+
}
|
|
45
|
+
interface QueryHaving {
|
|
46
|
+
column: string;
|
|
47
|
+
operator: FilterOperator;
|
|
48
|
+
value: QueryValue;
|
|
49
|
+
}
|
|
50
|
+
interface QueryNear {
|
|
51
|
+
field: string;
|
|
52
|
+
vector: number[];
|
|
53
|
+
k: number;
|
|
54
|
+
threshold?: number;
|
|
55
|
+
}
|
|
56
|
+
export type LuxProjectLiveEventType = 'snapshot' | 'insert' | 'update' | 'delete' | 'error';
|
|
57
|
+
export interface LuxProjectLiveEvent<T extends object = Record<string, unknown>> {
|
|
58
|
+
type: LuxProjectLiveEventType;
|
|
59
|
+
table: string;
|
|
60
|
+
pk?: string;
|
|
61
|
+
new: T | null;
|
|
62
|
+
old: T | null;
|
|
63
|
+
rows?: T[];
|
|
64
|
+
changed?: string[];
|
|
65
|
+
raw?: unknown;
|
|
66
|
+
error?: {
|
|
67
|
+
code?: string;
|
|
68
|
+
message?: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
type LiveEventHandler<T extends object> = (event: LuxProjectLiveEvent<T>) => void;
|
|
35
72
|
export declare class LuxProjectClient {
|
|
36
73
|
readonly url: string;
|
|
37
74
|
readonly key: string;
|
|
38
75
|
readonly auth: LuxAuthClient;
|
|
39
76
|
private fetchImpl;
|
|
77
|
+
private WebSocketImpl?;
|
|
78
|
+
private liveSocket;
|
|
79
|
+
private liveSubscriptions;
|
|
80
|
+
private livePending;
|
|
40
81
|
constructor(options: LuxProjectOptions);
|
|
41
|
-
table<T extends
|
|
82
|
+
table<T extends object | readonly object[] = Record<string, unknown>>(name: string): LuxProjectTable<LuxTypedRow<T>>;
|
|
42
83
|
ping(): Promise<LuxResult<unknown>>;
|
|
43
84
|
createTable(name: string, columns: Array<string | LuxTableColumn>): Promise<LuxResult<unknown>>;
|
|
44
85
|
exec(command: string | string[]): Promise<LuxResult<unknown>>;
|
|
@@ -55,15 +96,33 @@ export declare class LuxProjectClient {
|
|
|
55
96
|
count?: number;
|
|
56
97
|
}): Promise<LuxResult<unknown>>;
|
|
57
98
|
request<T = unknown>(method: string, path: string, body?: unknown): Promise<LuxResult<T>>;
|
|
99
|
+
_subscribeLive(spec: Record<string, unknown>, handler: (event: unknown) => void, error: (error: {
|
|
100
|
+
code?: string;
|
|
101
|
+
message?: string;
|
|
102
|
+
}) => void): Promise<() => void>;
|
|
103
|
+
private ensureLiveSocket;
|
|
104
|
+
private sendLive;
|
|
58
105
|
}
|
|
59
|
-
export declare class LuxProjectTable<T extends
|
|
106
|
+
export declare class LuxProjectTable<T extends object> {
|
|
60
107
|
private client;
|
|
61
108
|
private name;
|
|
62
109
|
constructor(client: LuxProjectClient, name: string);
|
|
63
|
-
select(columns?: string): LuxProjectSelectBuilder<T,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
110
|
+
select<TResult extends object = T>(columns?: string): LuxProjectSelectBuilder<T, TResult[]>;
|
|
111
|
+
eq(column: string, value: QueryValue): LuxProjectSelectBuilder<T, T[]>;
|
|
112
|
+
neq(column: string, value: QueryValue): LuxProjectSelectBuilder<T, T[]>;
|
|
113
|
+
gt(column: string, value: QueryValue): LuxProjectSelectBuilder<T, T[]>;
|
|
114
|
+
gte(column: string, value: QueryValue): LuxProjectSelectBuilder<T, T[]>;
|
|
115
|
+
lt(column: string, value: QueryValue): LuxProjectSelectBuilder<T, T[]>;
|
|
116
|
+
lte(column: string, value: QueryValue): LuxProjectSelectBuilder<T, T[]>;
|
|
117
|
+
near(column: string, vector: number[], options?: {
|
|
118
|
+
k?: number;
|
|
119
|
+
threshold?: number;
|
|
120
|
+
}): LuxProjectSelectBuilder<T, T[]>;
|
|
121
|
+
is(column: string, value: QueryValue): LuxProjectSelectBuilder<T, T[]>;
|
|
122
|
+
live(): LuxProjectLiveSubscription<T>;
|
|
123
|
+
insert(row: ProjectRowInput<T>): LuxProjectInsertBuilder<unknown>;
|
|
124
|
+
insert(rows: Array<ProjectRowInput<T>>): LuxProjectInsertBuilder<unknown[]>;
|
|
125
|
+
update(patch: ProjectRowInput<T>): LuxProjectMutationBuilder<unknown>;
|
|
67
126
|
delete(): LuxProjectMutationBuilder<unknown>;
|
|
68
127
|
count(): Promise<LuxResult<number>>;
|
|
69
128
|
}
|
|
@@ -78,6 +137,10 @@ declare abstract class LuxProjectFilterBuilder<TResult, TSelf> extends LuxProjec
|
|
|
78
137
|
protected tableName: string;
|
|
79
138
|
protected filters: QueryFilter[];
|
|
80
139
|
protected orderBy?: QueryOrder;
|
|
140
|
+
protected joins: QueryJoin[];
|
|
141
|
+
protected groupColumns: string[];
|
|
142
|
+
protected havingFilters: QueryHaving[];
|
|
143
|
+
protected nearQuery?: QueryNear;
|
|
81
144
|
protected limitCount?: number;
|
|
82
145
|
protected offsetCount?: number;
|
|
83
146
|
protected constructor(client: LuxProjectClient, tableName: string);
|
|
@@ -88,20 +151,48 @@ declare abstract class LuxProjectFilterBuilder<TResult, TSelf> extends LuxProjec
|
|
|
88
151
|
lt(column: string, value: QueryValue): TSelf;
|
|
89
152
|
lte(column: string, value: QueryValue): TSelf;
|
|
90
153
|
is(column: string, value: QueryValue): TSelf;
|
|
154
|
+
join(table: string, alias: string, onLeft: string, onRight: string): TSelf;
|
|
155
|
+
leftJoin(table: string, alias: string, onLeft: string, onRight: string): TSelf;
|
|
156
|
+
group(columns: string | string[]): TSelf;
|
|
157
|
+
having(column: string, operator: FilterOperator, value: QueryValue): TSelf;
|
|
91
158
|
protected addFilter(column: string, operator: FilterOperator, value: QueryValue): TSelf;
|
|
92
159
|
protected filteredQueryParams(): URLSearchParams;
|
|
93
160
|
}
|
|
94
|
-
export declare class LuxProjectSelectBuilder<T extends
|
|
161
|
+
export declare class LuxProjectSelectBuilder<T extends object, TResult> extends LuxProjectFilterBuilder<TResult, LuxProjectSelectBuilder<T, TResult>> {
|
|
95
162
|
private columns;
|
|
96
163
|
private expectSingle;
|
|
97
164
|
constructor(client: LuxProjectClient, tableName: string, columns: string);
|
|
98
165
|
order(column: string, options?: {
|
|
99
166
|
ascending?: boolean;
|
|
100
167
|
}): this;
|
|
168
|
+
near(column: string, vector: number[], options?: {
|
|
169
|
+
k?: number;
|
|
170
|
+
threshold?: number;
|
|
171
|
+
}): this;
|
|
101
172
|
limit(count: number): this;
|
|
102
173
|
range(from: number, to: number): this;
|
|
103
|
-
single(): LuxProjectSelectBuilder<T,
|
|
174
|
+
single(): LuxProjectSelectBuilder<T, ProjectSelectSingle<TResult>>;
|
|
104
175
|
execute(): Promise<LuxResult<TResult>>;
|
|
176
|
+
live(): LuxProjectLiveSubscription<LuxTypedRow<TResult>>;
|
|
177
|
+
}
|
|
178
|
+
export declare class LuxProjectLiveSubscription<T extends object> {
|
|
179
|
+
private client;
|
|
180
|
+
private table;
|
|
181
|
+
private columns;
|
|
182
|
+
private filters;
|
|
183
|
+
private nearQuery?;
|
|
184
|
+
private orderBy?;
|
|
185
|
+
private limitCount?;
|
|
186
|
+
private offsetCount?;
|
|
187
|
+
private handlers;
|
|
188
|
+
private unsubscribeFn;
|
|
189
|
+
constructor(client: LuxProjectClient, table: string, columns: string, filters: QueryFilter[], nearQuery?: QueryNear | undefined, orderBy?: QueryOrder | undefined, limitCount?: number | undefined, offsetCount?: number | undefined);
|
|
190
|
+
on(type: LuxProjectLiveEventType | 'change', handler: LiveEventHandler<T>): this;
|
|
191
|
+
unsubscribe(): Promise<void>;
|
|
192
|
+
private start;
|
|
193
|
+
private spec;
|
|
194
|
+
private handleEvent;
|
|
195
|
+
private emit;
|
|
105
196
|
}
|
|
106
197
|
export declare class LuxProjectInsertBuilder<TResult> extends LuxProjectThenable<TResult> {
|
|
107
198
|
private client;
|
package/dist/types/table.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KSubEvent, LuxError, LuxResult, TableChangeEvent, TableErrorEvent, TableRow, TableSchema
|
|
1
|
+
import type { KSubEvent, LuxError, LuxResult, TableChangeEvent, TableErrorEvent, TableRow, TableSchema } from './types';
|
|
2
2
|
type TableWhereOp = '=' | '!=' | '>' | '<' | '>=' | '<=';
|
|
3
3
|
type TableWhereValue = string | number | boolean;
|
|
4
4
|
interface TableWhereCondition {
|
|
@@ -10,19 +10,11 @@ interface TableClient {
|
|
|
10
10
|
call(command: string, ...args: Array<string | number>): Promise<unknown>;
|
|
11
11
|
_tselect(args: string[]): Promise<TableRow[]>;
|
|
12
12
|
_subscribePattern(pattern: string, handler: (event: KSubEvent) => void): Promise<() => void>;
|
|
13
|
-
vsearch(query: number[], options: {
|
|
14
|
-
k: number;
|
|
15
|
-
filter?: {
|
|
16
|
-
key: string;
|
|
17
|
-
value: string;
|
|
18
|
-
};
|
|
19
|
-
meta?: boolean;
|
|
20
|
-
}): Promise<VSearchResult[]>;
|
|
21
13
|
}
|
|
22
|
-
export interface TableQueryBuilderOptions<T extends
|
|
14
|
+
export interface TableQueryBuilderOptions<T extends object> {
|
|
23
15
|
schema?: TableSchema<T>;
|
|
24
16
|
}
|
|
25
|
-
export declare class TableSubscription<T extends
|
|
17
|
+
export declare class TableSubscription<T extends object> {
|
|
26
18
|
private client;
|
|
27
19
|
private table;
|
|
28
20
|
private selectArgsBuilder;
|
|
@@ -41,7 +33,7 @@ export declare class TableSubscription<T extends TableRow> {
|
|
|
41
33
|
private start;
|
|
42
34
|
private handleRawChange;
|
|
43
35
|
}
|
|
44
|
-
export declare class TableQueryBuilder<T extends
|
|
36
|
+
export declare class TableQueryBuilder<T extends object = TableRow> {
|
|
45
37
|
private client;
|
|
46
38
|
private name;
|
|
47
39
|
private conditions;
|
|
@@ -51,6 +43,8 @@ export declare class TableQueryBuilder<T extends TableRow = TableRow> {
|
|
|
51
43
|
private offsetCount?;
|
|
52
44
|
private joinClause?;
|
|
53
45
|
private similarityClause?;
|
|
46
|
+
private groupFields;
|
|
47
|
+
private havingConditions;
|
|
54
48
|
private selectClause;
|
|
55
49
|
private expectSingle;
|
|
56
50
|
private schema?;
|
|
@@ -73,14 +67,18 @@ export declare class TableQueryBuilder<T extends TableRow = TableRow> {
|
|
|
73
67
|
limit(n: number): this;
|
|
74
68
|
offset(n: number): this;
|
|
75
69
|
join(table: string, alias: string, onLeft: string, onRight: string): this;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
leftJoin(table: string, alias: string, onLeft: string, onRight: string): this;
|
|
71
|
+
group(fields: string | string[]): this;
|
|
72
|
+
groupBy(fields: string | string[]): this;
|
|
73
|
+
having(field: string, op: TableWhereOp, value: TableWhereValue): this;
|
|
74
|
+
near(field: string, vector: number[], options?: {
|
|
75
|
+
k?: number;
|
|
76
|
+
threshold?: number;
|
|
77
|
+
}): this;
|
|
78
|
+
similar(field: string, vector: number[], options?: {
|
|
79
|
+
k?: number;
|
|
80
|
+
threshold?: number;
|
|
82
81
|
}): this;
|
|
83
|
-
private parseSimilarityPk;
|
|
84
82
|
run(): Promise<LuxResult<T[] | T>>;
|
|
85
83
|
then<TFulfilled = LuxResult<T[] | T>, TRejected = never>(onfulfilled?: ((value: LuxResult<T[] | T>) => TFulfilled | PromiseLike<TFulfilled>) | null, onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null): Promise<TFulfilled | TRejected>;
|
|
86
84
|
insert(data: Record<string, unknown>): Promise<LuxResult<number>>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ export interface TableRow {
|
|
|
31
31
|
id?: number | string;
|
|
32
32
|
[field: string]: unknown;
|
|
33
33
|
}
|
|
34
|
+
export type LuxInferRow<T> = T extends readonly (infer Row)[] ? Row : T;
|
|
35
|
+
export type LuxTypedRow<T> = LuxInferRow<T> extends object ? LuxInferRow<T> : TableRow;
|
|
36
|
+
export type LuxAggregateValue = number | string;
|
|
37
|
+
export type LuxAggregateRow<Aliases extends string = string> = Record<Aliases, LuxAggregateValue>;
|
|
38
|
+
export interface LuxSimilarity {
|
|
39
|
+
_similarity: number | string;
|
|
40
|
+
}
|
|
41
|
+
export type LuxNearRow<T extends object = Record<string, unknown>> = T & LuxSimilarity;
|
|
34
42
|
export interface LuxError {
|
|
35
43
|
code: string;
|
|
36
44
|
message: string;
|
|
@@ -52,7 +60,7 @@ export interface TableSchema<T> {
|
|
|
52
60
|
safeParse?: (input: unknown) => SchemaSafeParse<T>;
|
|
53
61
|
}
|
|
54
62
|
export type TableChangeType = 'insert' | 'update' | 'delete' | 'change' | 'error';
|
|
55
|
-
export interface TableChangeEvent<T extends TableRow> {
|
|
63
|
+
export interface TableChangeEvent<T extends object = TableRow> {
|
|
56
64
|
type: Exclude<TableChangeType, 'error'>;
|
|
57
65
|
table: string;
|
|
58
66
|
pk: string;
|
package/package.json
CHANGED