@luxdb/sdk 1.2.1 → 1.4.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.
- package/dist/cjs/auth.js +504 -0
- package/dist/cjs/browser.js +14 -0
- package/dist/{index.js → cjs/index.js} +73 -109
- package/dist/cjs/namespaces.js +46 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/project.js +313 -0
- package/dist/cjs/realtime.js +88 -0
- package/dist/cjs/ssr.js +40 -0
- package/dist/cjs/table.js +396 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.js +17 -0
- package/dist/esm/auth.js +500 -0
- package/dist/esm/browser.js +11 -0
- package/dist/esm/index.js +273 -0
- package/dist/esm/namespaces.js +41 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/project.js +303 -0
- package/dist/esm/realtime.js +84 -0
- package/dist/esm/ssr.js +37 -0
- package/dist/esm/table.js +391 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.js +12 -0
- package/dist/types/auth.d.ts +163 -0
- package/dist/types/browser.d.ts +4 -0
- package/dist/types/index.d.ts +62 -0
- package/dist/types/namespaces.d.ts +56 -0
- package/dist/types/project.d.ts +121 -0
- package/dist/types/realtime.d.ts +16 -0
- package/dist/types/ssr.d.ts +22 -0
- package/dist/types/table.d.ts +92 -0
- package/dist/types/types.d.ts +70 -0
- package/dist/types/utils.d.ts +4 -0
- package/package.json +38 -4
- package/dist/index.d.ts +0 -121
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Redis, { type RedisOptions } from 'ioredis';
|
|
2
|
+
import { LuxAuthClient, type LuxAuthOptions } from './auth';
|
|
3
|
+
import { createProjectClient, LuxProjectClient, type LuxProjectOptions } from './project';
|
|
4
|
+
import { TimeSeriesNamespace, VectorNamespace } from './namespaces';
|
|
5
|
+
import { TableQueryBuilder, type TableQueryBuilderOptions } from './table';
|
|
6
|
+
import type { KSubEvent, TableRow, TSAddOptions, TSMRangeResult, TSRangeOptions, TSSample, VSearchResult } from './types';
|
|
7
|
+
export type { LuxAuthKey, LuxAuthChangeEvent, LuxAuthOptions, LuxAuthSession, LuxAuthStateChangeCallback, LuxAuthStorage, LuxAuthSubscription, LuxAuthUser, LuxOAuthProvider, LuxOAuthUrl, LuxSignInWithOAuthOptions, LuxCreateApiKeyOptions, LuxSignInOptions, LuxSignUpOptions, } from './auth';
|
|
8
|
+
export { createProjectClient, LuxProjectClient, };
|
|
9
|
+
export { createBrowserClient } from './browser';
|
|
10
|
+
export type { LuxBrowserClientOptions } from './browser';
|
|
11
|
+
export { createServerClient } from './ssr';
|
|
12
|
+
export type { LuxCookieMethods, LuxCookieOptions, LuxServerClientOptions } from './ssr';
|
|
13
|
+
export type { LuxProjectOptions, LuxTableColumn, LuxVectorSearchOptions, } from './project';
|
|
14
|
+
export type { KSubEvent, LuxError, LuxResult, TableChangeEvent, TableChangeType, TableErrorEvent, TableRow, TableSchema, TSAddOptions, TSMRangeResult, TSRangeOptions, TSSample, VSearchResult, } from './types';
|
|
15
|
+
export { TableQueryBuilder, TableSubscription } from './table';
|
|
16
|
+
export type { TableQueryBuilderOptions } from './table';
|
|
17
|
+
export type LuxClientOptions = RedisOptions & LuxAuthOptions;
|
|
18
|
+
export type LuxAuthNamespace = Redis['auth'] & LuxAuthClient;
|
|
19
|
+
export declare class Lux extends Redis {
|
|
20
|
+
vectors: VectorNamespace;
|
|
21
|
+
timeseries: TimeSeriesNamespace;
|
|
22
|
+
auth: LuxAuthNamespace;
|
|
23
|
+
authApi: LuxAuthClient;
|
|
24
|
+
private realtimeManager?;
|
|
25
|
+
constructor(options?: LuxClientOptions | RedisOptions | string);
|
|
26
|
+
table<T extends TableRow = TableRow>(name: string, options?: TableQueryBuilderOptions<T>): TableQueryBuilder<T>;
|
|
27
|
+
_subscribePattern(pattern: string, handler: (event: KSubEvent) => void): Promise<() => void>;
|
|
28
|
+
_tselect(args: string[]): Promise<TableRow[]>;
|
|
29
|
+
vset(key: string, vector: number[], options?: {
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
ex?: number;
|
|
32
|
+
px?: number;
|
|
33
|
+
}): Promise<'OK'>;
|
|
34
|
+
vget(key: string): Promise<{
|
|
35
|
+
dims: number;
|
|
36
|
+
vector: number[];
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
} | null>;
|
|
39
|
+
vsearch(query: number[], options: {
|
|
40
|
+
k: number;
|
|
41
|
+
filter?: {
|
|
42
|
+
key: string;
|
|
43
|
+
value: string;
|
|
44
|
+
};
|
|
45
|
+
meta?: boolean;
|
|
46
|
+
}): Promise<VSearchResult[]>;
|
|
47
|
+
vcard(): Promise<number>;
|
|
48
|
+
tsadd(key: string, timestamp: number | '*', value: number, options?: TSAddOptions): Promise<number>;
|
|
49
|
+
tsmadd(...entries: [string, number | '*', number][]): Promise<string>;
|
|
50
|
+
tsget(key: string): Promise<TSSample | null>;
|
|
51
|
+
tsrange(key: string, from: number | '-', to: number | '+', options?: TSRangeOptions): Promise<TSSample[]>;
|
|
52
|
+
tsmrange(from: number | '-', to: number | '+', filter: string, options?: TSRangeOptions): Promise<TSMRangeResult[]>;
|
|
53
|
+
tsinfo(key: string): Promise<Record<string, unknown>>;
|
|
54
|
+
ksub(patterns: string[], handler: (event: KSubEvent) => void): {
|
|
55
|
+
unsubscribe: () => void;
|
|
56
|
+
connection: Redis;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export declare function createClient(url: string, key: string, options?: Omit<LuxProjectOptions, 'url' | 'key'>): LuxProjectClient;
|
|
60
|
+
export declare function createClient(options?: LuxClientOptions | RedisOptions | string): Lux;
|
|
61
|
+
export declare function createAuthClient(options: LuxAuthOptions): LuxAuthClient;
|
|
62
|
+
export default Lux;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { TSAddOptions, TSMRangeResult, TSRangeOptions, TSSample, VSearchResult } from './types';
|
|
2
|
+
interface NamespaceClient {
|
|
3
|
+
call(command: string, ...args: Array<string | number>): Promise<unknown>;
|
|
4
|
+
vget(key: string): Promise<{
|
|
5
|
+
dims: number;
|
|
6
|
+
vector: number[];
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
} | null>;
|
|
9
|
+
vsearch(query: number[], options: {
|
|
10
|
+
k: number;
|
|
11
|
+
filter?: {
|
|
12
|
+
key: string;
|
|
13
|
+
value: string;
|
|
14
|
+
};
|
|
15
|
+
meta?: boolean;
|
|
16
|
+
}): Promise<VSearchResult[]>;
|
|
17
|
+
vcard(): Promise<number>;
|
|
18
|
+
tsadd(key: string, timestamp: number | '*', value: number, options?: TSAddOptions): Promise<number>;
|
|
19
|
+
tsget(key: string): Promise<TSSample | null>;
|
|
20
|
+
tsrange(key: string, from: number | '-', to: number | '+', options?: TSRangeOptions): Promise<TSSample[]>;
|
|
21
|
+
tsmrange(from: number | '-', to: number | '+', filter: string, options?: TSRangeOptions): Promise<TSMRangeResult[]>;
|
|
22
|
+
tsinfo(key: string): Promise<Record<string, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
export declare class VectorNamespace {
|
|
25
|
+
private client;
|
|
26
|
+
constructor(client: NamespaceClient);
|
|
27
|
+
set(key: string, vector: number[], metadata?: Record<string, unknown>): Promise<string>;
|
|
28
|
+
get(key: string): Promise<{
|
|
29
|
+
dims: number;
|
|
30
|
+
vector: number[];
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
} | null>;
|
|
33
|
+
search(query: number[], options: {
|
|
34
|
+
topK: number;
|
|
35
|
+
filter?: {
|
|
36
|
+
key: string;
|
|
37
|
+
value: string;
|
|
38
|
+
};
|
|
39
|
+
meta?: boolean;
|
|
40
|
+
}): Promise<VSearchResult[]>;
|
|
41
|
+
count(): Promise<number>;
|
|
42
|
+
}
|
|
43
|
+
export declare class TimeSeriesNamespace {
|
|
44
|
+
private client;
|
|
45
|
+
constructor(client: NamespaceClient);
|
|
46
|
+
add(key: string, value: number, options?: {
|
|
47
|
+
timestamp?: number | '*';
|
|
48
|
+
retention?: number;
|
|
49
|
+
labels?: Record<string, string>;
|
|
50
|
+
}): Promise<number>;
|
|
51
|
+
get(key: string): Promise<TSSample | null>;
|
|
52
|
+
range(key: string, from: number | '-', to: number | '+', options?: TSRangeOptions): Promise<TSSample[]>;
|
|
53
|
+
mrange(from: number | '-', to: number | '+', filter: string, options?: TSRangeOptions): Promise<TSMRangeResult[]>;
|
|
54
|
+
info(key: string): Promise<Record<string, unknown>>;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { LuxAuthClient, type LuxAuthOptions } from './auth';
|
|
2
|
+
import type { LuxResult } from './types';
|
|
3
|
+
export interface LuxProjectOptions {
|
|
4
|
+
url: string;
|
|
5
|
+
key: string;
|
|
6
|
+
fetch?: typeof fetch;
|
|
7
|
+
auth?: Omit<LuxAuthOptions, 'httpUrl' | 'apiKey' | 'fetch'>;
|
|
8
|
+
}
|
|
9
|
+
export interface LuxTableColumn {
|
|
10
|
+
name: string;
|
|
11
|
+
type: 'STR' | 'INT' | 'FLOAT' | 'BOOL' | 'TIMESTAMP' | 'UUID';
|
|
12
|
+
primaryKey?: boolean;
|
|
13
|
+
unique?: boolean;
|
|
14
|
+
notNull?: boolean;
|
|
15
|
+
references?: string;
|
|
16
|
+
onDelete?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface LuxVectorSearchOptions {
|
|
19
|
+
vector: number[];
|
|
20
|
+
k?: number;
|
|
21
|
+
filter?: string;
|
|
22
|
+
filter_value?: string;
|
|
23
|
+
}
|
|
24
|
+
type QueryValue = string | number | boolean | null;
|
|
25
|
+
type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'is';
|
|
26
|
+
interface QueryFilter {
|
|
27
|
+
column: string;
|
|
28
|
+
operator: FilterOperator;
|
|
29
|
+
value: QueryValue;
|
|
30
|
+
}
|
|
31
|
+
interface QueryOrder {
|
|
32
|
+
column: string;
|
|
33
|
+
ascending: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare class LuxProjectClient {
|
|
36
|
+
readonly url: string;
|
|
37
|
+
readonly key: string;
|
|
38
|
+
readonly auth: LuxAuthClient;
|
|
39
|
+
private fetchImpl;
|
|
40
|
+
constructor(options: LuxProjectOptions);
|
|
41
|
+
table<T extends Record<string, unknown> = Record<string, unknown>>(name: string): LuxProjectTable<T>;
|
|
42
|
+
ping(): Promise<LuxResult<unknown>>;
|
|
43
|
+
createTable(name: string, columns: Array<string | LuxTableColumn>): Promise<LuxResult<unknown>>;
|
|
44
|
+
exec(command: string | string[]): Promise<LuxResult<unknown>>;
|
|
45
|
+
vectorSet(key: string, vector: number[], metadata?: Record<string, unknown>): Promise<LuxResult<unknown>>;
|
|
46
|
+
vectorSearch(options: LuxVectorSearchOptions): Promise<LuxResult<unknown>>;
|
|
47
|
+
tsAdd(key: string, value: number, options?: {
|
|
48
|
+
timestamp?: number | '*';
|
|
49
|
+
labels?: Record<string, string>;
|
|
50
|
+
retention?: number;
|
|
51
|
+
}): Promise<LuxResult<unknown>>;
|
|
52
|
+
tsRange(key: string, options?: {
|
|
53
|
+
from?: number | '-';
|
|
54
|
+
to?: number | '+';
|
|
55
|
+
count?: number;
|
|
56
|
+
}): Promise<LuxResult<unknown>>;
|
|
57
|
+
request<T = unknown>(method: string, path: string, body?: unknown): Promise<LuxResult<T>>;
|
|
58
|
+
}
|
|
59
|
+
export declare class LuxProjectTable<T extends Record<string, unknown>> {
|
|
60
|
+
private client;
|
|
61
|
+
private name;
|
|
62
|
+
constructor(client: LuxProjectClient, name: string);
|
|
63
|
+
select(columns?: string): LuxProjectSelectBuilder<T, T[]>;
|
|
64
|
+
insert(row: Partial<T> & Record<string, QueryValue>): LuxProjectInsertBuilder<unknown>;
|
|
65
|
+
insert(rows: Array<Partial<T> & Record<string, QueryValue>>): LuxProjectInsertBuilder<unknown[]>;
|
|
66
|
+
update(patch: Partial<T> & Record<string, QueryValue>): LuxProjectMutationBuilder<unknown>;
|
|
67
|
+
delete(): LuxProjectMutationBuilder<unknown>;
|
|
68
|
+
count(): Promise<LuxResult<number>>;
|
|
69
|
+
}
|
|
70
|
+
declare abstract class LuxProjectThenable<TResult> implements PromiseLike<LuxResult<TResult>> {
|
|
71
|
+
then<TFulfilled = LuxResult<TResult>, TRejected = never>(onfulfilled?: ((value: LuxResult<TResult>) => TFulfilled | PromiseLike<TFulfilled>) | null, onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null): Promise<TFulfilled | TRejected>;
|
|
72
|
+
catch<TRejected = never>(onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null): Promise<LuxResult<TResult> | TRejected>;
|
|
73
|
+
finally(onfinally?: (() => void) | null): Promise<LuxResult<TResult>>;
|
|
74
|
+
abstract execute(): Promise<LuxResult<TResult>>;
|
|
75
|
+
}
|
|
76
|
+
declare abstract class LuxProjectFilterBuilder<TResult, TSelf> extends LuxProjectThenable<TResult> {
|
|
77
|
+
protected client: LuxProjectClient;
|
|
78
|
+
protected tableName: string;
|
|
79
|
+
protected filters: QueryFilter[];
|
|
80
|
+
protected orderBy?: QueryOrder;
|
|
81
|
+
protected limitCount?: number;
|
|
82
|
+
protected offsetCount?: number;
|
|
83
|
+
protected constructor(client: LuxProjectClient, tableName: string);
|
|
84
|
+
eq(column: string, value: QueryValue): TSelf;
|
|
85
|
+
neq(column: string, value: QueryValue): TSelf;
|
|
86
|
+
gt(column: string, value: QueryValue): TSelf;
|
|
87
|
+
gte(column: string, value: QueryValue): TSelf;
|
|
88
|
+
lt(column: string, value: QueryValue): TSelf;
|
|
89
|
+
lte(column: string, value: QueryValue): TSelf;
|
|
90
|
+
is(column: string, value: QueryValue): TSelf;
|
|
91
|
+
protected addFilter(column: string, operator: FilterOperator, value: QueryValue): TSelf;
|
|
92
|
+
protected filteredQueryParams(): URLSearchParams;
|
|
93
|
+
}
|
|
94
|
+
export declare class LuxProjectSelectBuilder<T extends Record<string, unknown>, TResult> extends LuxProjectFilterBuilder<TResult, LuxProjectSelectBuilder<T, TResult>> {
|
|
95
|
+
private columns;
|
|
96
|
+
private expectSingle;
|
|
97
|
+
constructor(client: LuxProjectClient, tableName: string, columns: string);
|
|
98
|
+
order(column: string, options?: {
|
|
99
|
+
ascending?: boolean;
|
|
100
|
+
}): this;
|
|
101
|
+
limit(count: number): this;
|
|
102
|
+
range(from: number, to: number): this;
|
|
103
|
+
single(): LuxProjectSelectBuilder<T, T>;
|
|
104
|
+
execute(): Promise<LuxResult<TResult>>;
|
|
105
|
+
}
|
|
106
|
+
export declare class LuxProjectInsertBuilder<TResult> extends LuxProjectThenable<TResult> {
|
|
107
|
+
private client;
|
|
108
|
+
private tableName;
|
|
109
|
+
private rowOrRows;
|
|
110
|
+
constructor(client: LuxProjectClient, tableName: string, rowOrRows: Record<string, QueryValue> | Array<Record<string, QueryValue>>);
|
|
111
|
+
execute(): Promise<LuxResult<TResult>>;
|
|
112
|
+
}
|
|
113
|
+
export declare class LuxProjectMutationBuilder<TResult> extends LuxProjectFilterBuilder<TResult, LuxProjectMutationBuilder<TResult>> {
|
|
114
|
+
private method;
|
|
115
|
+
private body?;
|
|
116
|
+
constructor(client: LuxProjectClient, tableName: string, method: 'PATCH' | 'DELETE', body?: Record<string, QueryValue> | undefined);
|
|
117
|
+
execute(): Promise<LuxResult<TResult>>;
|
|
118
|
+
}
|
|
119
|
+
export declare function createProjectClient(options: LuxProjectOptions): LuxProjectClient;
|
|
120
|
+
export declare function createClient(url: string, key: string, options?: Omit<LuxProjectOptions, 'url' | 'key'>): LuxProjectClient;
|
|
121
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type Redis from 'ioredis';
|
|
2
|
+
import type { KSubEvent } from './types';
|
|
3
|
+
interface RealtimeClient {
|
|
4
|
+
duplicate(): Redis;
|
|
5
|
+
}
|
|
6
|
+
export declare class LuxRealtimeManager {
|
|
7
|
+
private client;
|
|
8
|
+
private connection;
|
|
9
|
+
private initPromise;
|
|
10
|
+
private nextHandlerId;
|
|
11
|
+
private handlersByPattern;
|
|
12
|
+
constructor(client: RealtimeClient);
|
|
13
|
+
private ensureConnection;
|
|
14
|
+
subscribe(pattern: string, handler: (event: KSubEvent) => void): Promise<() => void>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type LuxProjectOptions } from './project';
|
|
2
|
+
export interface LuxCookieOptions {
|
|
3
|
+
domain?: string;
|
|
4
|
+
expires?: Date;
|
|
5
|
+
httpOnly?: boolean;
|
|
6
|
+
maxAge?: number;
|
|
7
|
+
path?: string;
|
|
8
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface LuxCookieMethods {
|
|
12
|
+
get(name: string): string | null | undefined | Promise<string | null | undefined>;
|
|
13
|
+
set?(name: string, value: string, options?: LuxCookieOptions): void | Promise<void>;
|
|
14
|
+
remove?(name: string, options?: LuxCookieOptions): void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface LuxServerClientOptions extends Omit<LuxProjectOptions, 'url' | 'key' | 'auth'> {
|
|
17
|
+
auth?: Omit<NonNullable<LuxProjectOptions['auth']>, 'storage'> & {
|
|
18
|
+
cookieOptions?: LuxCookieOptions;
|
|
19
|
+
};
|
|
20
|
+
cookies: LuxCookieMethods;
|
|
21
|
+
}
|
|
22
|
+
export declare function createServerClient(url: string, key: string, options: LuxServerClientOptions): import("./project").LuxProjectClient;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { KSubEvent, LuxError, LuxResult, TableChangeEvent, TableErrorEvent, TableRow, TableSchema, VSearchResult } from './types';
|
|
2
|
+
type TableWhereOp = '=' | '!=' | '>' | '<' | '>=' | '<=';
|
|
3
|
+
type TableWhereValue = string | number | boolean;
|
|
4
|
+
interface TableWhereCondition {
|
|
5
|
+
field: string;
|
|
6
|
+
op: TableWhereOp;
|
|
7
|
+
value: TableWhereValue;
|
|
8
|
+
}
|
|
9
|
+
interface TableClient {
|
|
10
|
+
call(command: string, ...args: Array<string | number>): Promise<unknown>;
|
|
11
|
+
_tselect(args: string[]): Promise<TableRow[]>;
|
|
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
|
+
}
|
|
22
|
+
export interface TableQueryBuilderOptions<T extends TableRow> {
|
|
23
|
+
schema?: TableSchema<T>;
|
|
24
|
+
}
|
|
25
|
+
export declare class TableSubscription<T extends TableRow> {
|
|
26
|
+
private client;
|
|
27
|
+
private table;
|
|
28
|
+
private selectArgsBuilder;
|
|
29
|
+
private handlers;
|
|
30
|
+
private knownRows;
|
|
31
|
+
private unsubscribeFn;
|
|
32
|
+
private initError;
|
|
33
|
+
constructor(client: TableClient, table: string, selectArgsBuilder: (extra?: TableWhereCondition[]) => string[], initError?: LuxError | null);
|
|
34
|
+
on(event: 'insert' | 'update' | 'delete' | 'change', handler: (event: TableChangeEvent<T>) => void): this;
|
|
35
|
+
on(event: 'error', handler: (event: TableErrorEvent) => void): this;
|
|
36
|
+
unsubscribe(): Promise<void>;
|
|
37
|
+
private emitError;
|
|
38
|
+
private emitChange;
|
|
39
|
+
private extractPkFromKey;
|
|
40
|
+
private fetchMatches;
|
|
41
|
+
private start;
|
|
42
|
+
private handleRawChange;
|
|
43
|
+
}
|
|
44
|
+
export declare class TableQueryBuilder<T extends TableRow = TableRow> {
|
|
45
|
+
private client;
|
|
46
|
+
private name;
|
|
47
|
+
private conditions;
|
|
48
|
+
private orderField?;
|
|
49
|
+
private orderDir?;
|
|
50
|
+
private limitCount?;
|
|
51
|
+
private offsetCount?;
|
|
52
|
+
private joinClause?;
|
|
53
|
+
private similarityClause?;
|
|
54
|
+
private selectClause;
|
|
55
|
+
private expectSingle;
|
|
56
|
+
private schema?;
|
|
57
|
+
constructor(client: TableClient, name: string, options?: TableQueryBuilderOptions<T>);
|
|
58
|
+
private validateRow;
|
|
59
|
+
private buildSelectArgs;
|
|
60
|
+
select(columns?: string): this;
|
|
61
|
+
single(): this;
|
|
62
|
+
where(field: string, op: TableWhereOp, value: TableWhereValue): this;
|
|
63
|
+
eq(field: string, value: TableWhereValue): this;
|
|
64
|
+
neq(field: string, value: TableWhereValue): this;
|
|
65
|
+
gt(field: string, value: TableWhereValue): this;
|
|
66
|
+
gte(field: string, value: TableWhereValue): this;
|
|
67
|
+
lt(field: string, value: TableWhereValue): this;
|
|
68
|
+
lte(field: string, value: TableWhereValue): this;
|
|
69
|
+
orderBy(field: string, dir?: 'asc' | 'desc'): this;
|
|
70
|
+
order(field: string, options?: {
|
|
71
|
+
ascending?: boolean;
|
|
72
|
+
}): this;
|
|
73
|
+
limit(n: number): this;
|
|
74
|
+
offset(n: number): this;
|
|
75
|
+
join(table: string, alias: string, onLeft: string, onRight: string): this;
|
|
76
|
+
similar(field: string, vector: number[], options: {
|
|
77
|
+
k: number;
|
|
78
|
+
filter?: {
|
|
79
|
+
key: string;
|
|
80
|
+
value: string;
|
|
81
|
+
};
|
|
82
|
+
}): this;
|
|
83
|
+
private parseSimilarityPk;
|
|
84
|
+
run(): Promise<LuxResult<T[] | T>>;
|
|
85
|
+
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
|
+
insert(data: Record<string, unknown>): Promise<LuxResult<number>>;
|
|
87
|
+
update(id: number | string, data: Record<string, unknown>): Promise<LuxResult<number>>;
|
|
88
|
+
update(data: Record<string, unknown>): Promise<LuxResult<number>>;
|
|
89
|
+
delete(...ids: Array<number | string>): Promise<LuxResult<number>>;
|
|
90
|
+
subscribe(): TableSubscription<T>;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface VSearchResult {
|
|
2
|
+
key: string;
|
|
3
|
+
similarity: number;
|
|
4
|
+
metadata?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface TSSample {
|
|
7
|
+
timestamp: number;
|
|
8
|
+
value: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TSAddOptions {
|
|
11
|
+
retention?: number;
|
|
12
|
+
labels?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export interface TSRangeOptions {
|
|
15
|
+
aggregation?: {
|
|
16
|
+
type: 'avg' | 'sum' | 'min' | 'max' | 'count' | 'first' | 'last' | 'range' | 'std.p' | 'std.s' | 'var.p' | 'var.s';
|
|
17
|
+
bucketSize: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface TSMRangeResult {
|
|
21
|
+
key: string;
|
|
22
|
+
labels: Record<string, string>;
|
|
23
|
+
samples: TSSample[];
|
|
24
|
+
}
|
|
25
|
+
export interface KSubEvent {
|
|
26
|
+
pattern: string;
|
|
27
|
+
key: string;
|
|
28
|
+
operation: string;
|
|
29
|
+
}
|
|
30
|
+
export interface TableRow {
|
|
31
|
+
id?: number | string;
|
|
32
|
+
[field: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface LuxError {
|
|
35
|
+
code: string;
|
|
36
|
+
message: string;
|
|
37
|
+
details?: unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface LuxResult<T> {
|
|
40
|
+
data: T | null;
|
|
41
|
+
error: LuxError | null;
|
|
42
|
+
}
|
|
43
|
+
type SchemaSafeParse<T> = {
|
|
44
|
+
success: true;
|
|
45
|
+
data: T;
|
|
46
|
+
} | {
|
|
47
|
+
success: false;
|
|
48
|
+
error: unknown;
|
|
49
|
+
};
|
|
50
|
+
export interface TableSchema<T> {
|
|
51
|
+
parse?: (input: unknown) => T;
|
|
52
|
+
safeParse?: (input: unknown) => SchemaSafeParse<T>;
|
|
53
|
+
}
|
|
54
|
+
export type TableChangeType = 'insert' | 'update' | 'delete' | 'change' | 'error';
|
|
55
|
+
export interface TableChangeEvent<T extends TableRow> {
|
|
56
|
+
type: Exclude<TableChangeType, 'error'>;
|
|
57
|
+
table: string;
|
|
58
|
+
pk: string;
|
|
59
|
+
operation: string;
|
|
60
|
+
new: T | null;
|
|
61
|
+
old: T | null;
|
|
62
|
+
changed?: string[];
|
|
63
|
+
raw?: KSubEvent;
|
|
64
|
+
}
|
|
65
|
+
export interface TableErrorEvent {
|
|
66
|
+
type: 'error';
|
|
67
|
+
table: string;
|
|
68
|
+
error: LuxError;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LuxError, LuxResult } from './types';
|
|
2
|
+
export declare function ok<T>(data: T): LuxResult<T>;
|
|
3
|
+
export declare function err<T>(code: string, message: string, details?: unknown): LuxResult<T>;
|
|
4
|
+
export declare function toLuxError(error: unknown, fallbackCode?: string): LuxError;
|
package/package.json
CHANGED
|
@@ -1,12 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxdb/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Lux SDK - ioredis extended with vector search, time series, and realtime key subscriptions",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"default": "./dist/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./project": {
|
|
16
|
+
"types": "./dist/types/project.d.ts",
|
|
17
|
+
"import": "./dist/esm/project.js",
|
|
18
|
+
"require": "./dist/cjs/project.js",
|
|
19
|
+
"default": "./dist/esm/project.js"
|
|
20
|
+
},
|
|
21
|
+
"./auth": {
|
|
22
|
+
"types": "./dist/types/auth.d.ts",
|
|
23
|
+
"import": "./dist/esm/auth.js",
|
|
24
|
+
"require": "./dist/cjs/auth.js",
|
|
25
|
+
"default": "./dist/esm/auth.js"
|
|
26
|
+
},
|
|
27
|
+
"./browser": {
|
|
28
|
+
"types": "./dist/types/browser.d.ts",
|
|
29
|
+
"import": "./dist/esm/browser.js",
|
|
30
|
+
"require": "./dist/cjs/browser.js",
|
|
31
|
+
"default": "./dist/esm/browser.js"
|
|
32
|
+
},
|
|
33
|
+
"./ssr": {
|
|
34
|
+
"types": "./dist/types/ssr.d.ts",
|
|
35
|
+
"import": "./dist/esm/ssr.js",
|
|
36
|
+
"require": "./dist/cjs/ssr.js",
|
|
37
|
+
"default": "./dist/esm/ssr.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
7
40
|
"files": ["dist"],
|
|
8
41
|
"scripts": {
|
|
9
|
-
"build": "
|
|
42
|
+
"build": "bun scripts/build.ts",
|
|
43
|
+
"test": "bun test tests",
|
|
10
44
|
"prepublishOnly": "bun run build"
|
|
11
45
|
},
|
|
12
46
|
"dependencies": {
|
package/dist/index.d.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import Redis, { type RedisOptions } from 'ioredis';
|
|
2
|
-
export interface VSearchResult {
|
|
3
|
-
key: string;
|
|
4
|
-
similarity: number;
|
|
5
|
-
metadata?: Record<string, unknown>;
|
|
6
|
-
}
|
|
7
|
-
export interface TSSample {
|
|
8
|
-
timestamp: number;
|
|
9
|
-
value: number;
|
|
10
|
-
}
|
|
11
|
-
export interface TSAddOptions {
|
|
12
|
-
retention?: number;
|
|
13
|
-
labels?: Record<string, string>;
|
|
14
|
-
}
|
|
15
|
-
export interface TSRangeOptions {
|
|
16
|
-
aggregation?: {
|
|
17
|
-
type: 'avg' | 'sum' | 'min' | 'max' | 'count' | 'first' | 'last' | 'range' | 'std.p' | 'std.s' | 'var.p' | 'var.s';
|
|
18
|
-
bucketSize: number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export interface TSMRangeResult {
|
|
22
|
-
key: string;
|
|
23
|
-
labels: Record<string, string>;
|
|
24
|
-
samples: TSSample[];
|
|
25
|
-
}
|
|
26
|
-
export interface KSubEvent {
|
|
27
|
-
pattern: string;
|
|
28
|
-
key: string;
|
|
29
|
-
operation: string;
|
|
30
|
-
}
|
|
31
|
-
export interface TableRow {
|
|
32
|
-
id: number;
|
|
33
|
-
[field: string]: unknown;
|
|
34
|
-
}
|
|
35
|
-
declare class TableQueryBuilder {
|
|
36
|
-
private client;
|
|
37
|
-
private name;
|
|
38
|
-
private conditions;
|
|
39
|
-
private orderField?;
|
|
40
|
-
private orderDir?;
|
|
41
|
-
private limitCount?;
|
|
42
|
-
private joinTable?;
|
|
43
|
-
constructor(client: Lux, name: string);
|
|
44
|
-
where(field: string, op: '=' | '!=' | '>' | '<' | '>=' | '<=', value: string | number | boolean): this;
|
|
45
|
-
orderBy(field: string, dir?: 'asc' | 'desc'): this;
|
|
46
|
-
limit(n: number): this;
|
|
47
|
-
join(table: string): this;
|
|
48
|
-
run(): Promise<TableRow[]>;
|
|
49
|
-
insert(data: Record<string, unknown>): Promise<number>;
|
|
50
|
-
update(id: number, data: Record<string, unknown>): Promise<string>;
|
|
51
|
-
delete(...ids: number[]): Promise<number>;
|
|
52
|
-
}
|
|
53
|
-
declare class VectorNamespace {
|
|
54
|
-
private client;
|
|
55
|
-
constructor(client: Lux);
|
|
56
|
-
set(key: string, vector: number[], metadata?: Record<string, unknown>): Promise<string>;
|
|
57
|
-
get(key: string): Promise<{
|
|
58
|
-
dims: number;
|
|
59
|
-
vector: number[];
|
|
60
|
-
metadata?: Record<string, unknown>;
|
|
61
|
-
} | null>;
|
|
62
|
-
search(query: number[], options: {
|
|
63
|
-
topK: number;
|
|
64
|
-
filter?: {
|
|
65
|
-
key: string;
|
|
66
|
-
value: string;
|
|
67
|
-
};
|
|
68
|
-
meta?: boolean;
|
|
69
|
-
}): Promise<VSearchResult[]>;
|
|
70
|
-
count(): Promise<number>;
|
|
71
|
-
}
|
|
72
|
-
declare class TimeSeriesNamespace {
|
|
73
|
-
private client;
|
|
74
|
-
constructor(client: Lux);
|
|
75
|
-
add(key: string, value: number, options?: {
|
|
76
|
-
timestamp?: number | '*';
|
|
77
|
-
retention?: number;
|
|
78
|
-
labels?: Record<string, string>;
|
|
79
|
-
}): Promise<number>;
|
|
80
|
-
get(key: string): Promise<TSSample | null>;
|
|
81
|
-
range(key: string, from: number | '-', to: number | '+', options?: TSRangeOptions): Promise<TSSample[]>;
|
|
82
|
-
mrange(from: number | '-', to: number | '+', filter: string, options?: TSRangeOptions): Promise<TSMRangeResult[]>;
|
|
83
|
-
info(key: string): Promise<Record<string, unknown>>;
|
|
84
|
-
}
|
|
85
|
-
export declare class Lux extends Redis {
|
|
86
|
-
vectors: VectorNamespace;
|
|
87
|
-
timeseries: TimeSeriesNamespace;
|
|
88
|
-
constructor(options?: RedisOptions | string);
|
|
89
|
-
table(name: string): TableQueryBuilder;
|
|
90
|
-
_tquery(args: string[]): Promise<TableRow[]>;
|
|
91
|
-
vset(key: string, vector: number[], options?: {
|
|
92
|
-
metadata?: Record<string, unknown>;
|
|
93
|
-
ex?: number;
|
|
94
|
-
px?: number;
|
|
95
|
-
}): Promise<'OK'>;
|
|
96
|
-
vget(key: string): Promise<{
|
|
97
|
-
dims: number;
|
|
98
|
-
vector: number[];
|
|
99
|
-
metadata?: Record<string, unknown>;
|
|
100
|
-
} | null>;
|
|
101
|
-
vsearch(query: number[], options: {
|
|
102
|
-
k: number;
|
|
103
|
-
filter?: {
|
|
104
|
-
key: string;
|
|
105
|
-
value: string;
|
|
106
|
-
};
|
|
107
|
-
meta?: boolean;
|
|
108
|
-
}): Promise<VSearchResult[]>;
|
|
109
|
-
vcard(): Promise<number>;
|
|
110
|
-
tsadd(key: string, timestamp: number | '*', value: number, options?: TSAddOptions): Promise<number>;
|
|
111
|
-
tsmadd(...entries: [string, number | '*', number][]): Promise<string>;
|
|
112
|
-
tsget(key: string): Promise<TSSample | null>;
|
|
113
|
-
tsrange(key: string, from: number | '-', to: number | '+', options?: TSRangeOptions): Promise<TSSample[]>;
|
|
114
|
-
tsmrange(from: number | '-', to: number | '+', filter: string, options?: TSRangeOptions): Promise<TSMRangeResult[]>;
|
|
115
|
-
tsinfo(key: string): Promise<Record<string, unknown>>;
|
|
116
|
-
ksub(patterns: string[], handler: (event: KSubEvent) => void): {
|
|
117
|
-
unsubscribe: () => void;
|
|
118
|
-
connection: Redis;
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
export default Lux;
|