@an5/adapters 0.2.5 → 0.2.9
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 +283 -305
- package/dist/an5Adapter.d.ts +142 -7
- package/dist/an5Adapter.js +998 -68
- package/dist/base/metadata.d.ts +10 -0
- package/dist/base/metadata.js +107 -0
- package/dist/base/sql.d.ts +19 -1
- package/dist/base/sql.js +152 -24
- package/dist/base/types.d.ts +10 -1
- package/dist/browser.d.ts +4 -1
- package/dist/browser.js +9 -2
- package/dist/googlesheets/adapter.d.ts +1 -0
- package/dist/googlesheets/adapter.js +9 -2
- package/dist/googlesheets/config.d.ts +4 -4
- package/dist/googlesheets/helpers.js +2 -0
- package/dist/googlesheets/parseConnectionString.js +5 -2
- package/dist/googlesheets/sqlExecutor.js +29 -24
- package/dist/googlesheets/tableClient.js +14 -5
- package/dist/index.d.ts +5 -1
- package/dist/index.js +15 -1
- package/dist/mssql/engine.js +8 -4
- package/dist/mysql/engine.js +1 -1
- package/dist/nbase/client.d.ts +92 -0
- package/dist/nbase/client.js +147 -0
- package/dist/nbase/index.d.ts +47 -0
- package/dist/nbase/index.js +80 -0
- package/dist/postgres/engine.js +1 -1
- package/dist/sqlite/browserEngine.d.ts +27 -0
- package/dist/sqlite/browserEngine.js +161 -0
- package/dist/sqlite/engine.js +15 -3
- package/dist/sqlite/index.d.ts +1 -0
- package/dist/sqlite/index.js +1 -0
- package/dist/typed.d.ts +5 -0
- package/dist/typed.js +2 -0
- package/dotnet/An5Adapter.cs +1112 -275
- package/dotnet/Base/Core.cs +380 -82
- package/dotnet/Mssql/MssqlEngine.cs +145 -144
- package/dotnet/Postgres/PostgresEngine.cs +149 -121
- package/dotnet/Sqlite/SqliteEngine.cs +214 -0
- package/golang/an5_adapter.go +314 -0
- package/golang/base/base.go +100 -0
- package/golang/base/metadata.go +116 -0
- package/golang/base/where.go +311 -0
- package/golang/go.mod +3 -0
- package/golang/mssql/mssql.go +32 -0
- package/golang/postgres/postgres.go +37 -0
- package/golang/sqlite/sqlite.go +14 -0
- package/golang/sqlite_test.go +42 -0
- package/golang/table_client.go +1329 -0
- package/package.json +26 -9
- package/python/an5_adapter.py +184 -97
- package/python/base/__init__.py +3 -3
- package/python/base/dialects.py +11 -8
- package/python/base/metadata.py +59 -10
- package/python/base/sql.py +202 -121
- package/python/mssql/__init__.py +1 -1
- package/python/mssql/provider.py +62 -62
- package/python/postgres/__init__.py +1 -1
- package/python/postgres/provider.py +15 -15
- package/python/sqlite/__init__.py +3 -0
- package/python/sqlite/provider.py +83 -0
- package/python/table_client.py +636 -216
- package/rust/Cargo.toml +31 -0
- package/rust/README.md +71 -0
- package/rust/src/adapter.rs +1312 -0
- package/rust/src/base/dialect.rs +172 -0
- package/rust/src/base/metadata.rs +134 -0
- package/rust/src/base/mod.rs +17 -0
- package/rust/src/base/where_builder.rs +405 -0
- package/rust/src/lib.rs +75 -0
- package/typescript/src/an5Adapter.ts +1515 -505
- package/typescript/src/base/index.ts +3 -3
- package/typescript/src/base/metadata.ts +148 -28
- package/typescript/src/base/sql.ts +264 -98
- package/typescript/src/base/types.ts +33 -24
- package/typescript/src/browser.ts +10 -6
- package/typescript/src/config.ts +95 -95
- package/typescript/src/googlesheets/adapter.ts +269 -259
- package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
- package/typescript/src/googlesheets/config.ts +47 -47
- package/typescript/src/googlesheets/helpers.ts +144 -143
- package/typescript/src/googlesheets/index.ts +3 -3
- package/typescript/src/googlesheets/parseConnectionString.ts +48 -46
- package/typescript/src/googlesheets/retry.ts +126 -126
- package/typescript/src/googlesheets/sqlExecutor.ts +304 -301
- package/typescript/src/googlesheets/tableClient.ts +461 -455
- package/typescript/src/googlesheets/types.ts +6 -6
- package/typescript/src/index.ts +48 -27
- package/typescript/src/mssql/engine.ts +134 -132
- package/typescript/src/mssql/index.ts +1 -1
- package/typescript/src/mysql/engine.ts +80 -80
- package/typescript/src/mysql/index.ts +1 -1
- package/typescript/src/nbase/client.ts +214 -0
- package/typescript/src/nbase/index.ts +104 -0
- package/typescript/src/postgres/engine.ts +87 -87
- package/typescript/src/postgres/index.ts +1 -1
- package/typescript/src/sqlite/browserEngine.ts +192 -0
- package/typescript/src/sqlite/engine.ts +66 -55
- package/typescript/src/sqlite/index.ts +3 -1
- package/typescript/src/typed.ts +52 -0
package/dist/an5Adapter.d.ts
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import { An5SheetsAdapter, An5SheetsAdapterConfig, SheetsTableClient } from './googlesheets';
|
|
2
2
|
import type { An5AdapterConfig, Dialect, TransactionHandle } from './base/types';
|
|
3
|
+
import { type NBaseAdapterConfig, type NBaseVectorClient } from './nbase';
|
|
3
4
|
export type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from './base/types';
|
|
4
|
-
export { setAdapterMetadata, type AdapterMetadata } from './base/metadata';
|
|
5
|
+
export { setAdapterMetadata, createAdapterProxy, type AdapterMetadata } from './base/metadata';
|
|
6
|
+
export type { TypedAn5Adapter, AdapterAPI } from './typed';
|
|
5
7
|
export type AnyAdapter = An5Adapter | An5SheetsAdapter;
|
|
6
8
|
export type AnyAdapterConfig = An5AdapterConfig | An5SheetsAdapterConfig | {
|
|
7
9
|
connectionString: string;
|
|
8
10
|
};
|
|
9
11
|
export declare class An5Adapter {
|
|
12
|
+
[key: string]: any;
|
|
10
13
|
private _engine;
|
|
11
14
|
private _engineType;
|
|
12
15
|
private _engineConfig;
|
|
13
16
|
sheetsAdapter: An5SheetsAdapter | null;
|
|
17
|
+
private _nbase;
|
|
18
|
+
private _nbaseConfig;
|
|
19
|
+
private _nbaseOnly;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the NBase client for this adapter, if the project configured one.
|
|
22
|
+
* The connection string may also point straight at NBase, which keeps
|
|
23
|
+
* `DATABASE_URL=nbase://host:port` working on its own.
|
|
24
|
+
*/
|
|
25
|
+
nbaseClient(): {
|
|
26
|
+
client: NBaseVectorClient;
|
|
27
|
+
config: NBaseAdapterConfig;
|
|
28
|
+
} | null;
|
|
29
|
+
/**
|
|
30
|
+
* True when the adapter only knows about NBase, so there is no relational
|
|
31
|
+
* database to read rows from.
|
|
32
|
+
*/
|
|
33
|
+
get nbaseOnly(): boolean;
|
|
14
34
|
get dialect(): Dialect;
|
|
15
35
|
constructor(adapterConfig: An5AdapterConfig | An5SheetsAdapterConfig);
|
|
16
36
|
private requireEngine;
|
|
@@ -23,34 +43,107 @@ export declare class An5Adapter {
|
|
|
23
43
|
$executeRaw(query: string, ...values: any[]): Promise<number>;
|
|
24
44
|
$executeRawUnsafe(query: string, ...values: any[]): Promise<number>;
|
|
25
45
|
$connect(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Health check for the configured NBase instance, or the database when the
|
|
48
|
+
* adapter has none.
|
|
49
|
+
*/
|
|
50
|
+
$nbaseHealth(): Promise<{
|
|
51
|
+
connected: boolean;
|
|
52
|
+
endpoint?: string;
|
|
53
|
+
error?: string;
|
|
54
|
+
}>;
|
|
26
55
|
$disconnect(): Promise<void>;
|
|
27
56
|
/** Real transaction with BEGIN / COMMIT / ROLLBACK */
|
|
28
57
|
$transaction<R>(fn: (tx: An5AdapterTx) => Promise<R>, options?: {
|
|
29
58
|
timeout?: number;
|
|
30
59
|
}): Promise<R>;
|
|
31
60
|
$transaction<R>(list: Promise<R>[]): Promise<R[]>;
|
|
61
|
+
$begin(): Promise<An5AdapterTx>;
|
|
32
62
|
table<T = any>(modelName: string): AdapterTableClient<T> | SheetsTableClient<T>;
|
|
63
|
+
private _listeners;
|
|
64
|
+
private _middlewares;
|
|
65
|
+
$on(event: 'query' | 'error' | 'warn' | 'info' | string, callback: (...args: any[]) => void): this;
|
|
66
|
+
$off(event: string, callback: (...args: any[]) => void): this;
|
|
67
|
+
$emit(event: string, ...args: any[]): void;
|
|
68
|
+
$use(middleware: (params: {
|
|
69
|
+
model?: string;
|
|
70
|
+
action: string;
|
|
71
|
+
args: any;
|
|
72
|
+
run: (args: any) => Promise<any>;
|
|
73
|
+
}) => Promise<any>): this;
|
|
74
|
+
view<T = any>(viewName: string): ViewClient<T>;
|
|
75
|
+
$queryProc<T = any>(procName: string, params?: Record<string, any> | any[]): Promise<T[]>;
|
|
76
|
+
$executeProc(procName: string, params?: Record<string, any> | any[]): Promise<number>;
|
|
33
77
|
readRange<T = any>(range: string): Promise<T[][]>;
|
|
34
78
|
writeRange(range: string, values: any[][]): Promise<void>;
|
|
35
79
|
appendRange(range: string, values: any[][]): Promise<void>;
|
|
36
80
|
listSheets(): Promise<string[]>;
|
|
37
81
|
deleteSheet(name: string): Promise<void>;
|
|
38
82
|
}
|
|
83
|
+
export declare class ViewClient<T = any> {
|
|
84
|
+
readonly adapter: An5Adapter | An5AdapterTx;
|
|
85
|
+
readonly viewName: string;
|
|
86
|
+
private readonly tableClient;
|
|
87
|
+
constructor(adapter: An5Adapter | An5AdapterTx, viewName: string);
|
|
88
|
+
get dialect(): Dialect;
|
|
89
|
+
get tableName(): string;
|
|
90
|
+
findMany(args?: {
|
|
91
|
+
where?: any;
|
|
92
|
+
orderBy?: any;
|
|
93
|
+
skip?: number;
|
|
94
|
+
take?: number;
|
|
95
|
+
select?: any;
|
|
96
|
+
include?: any;
|
|
97
|
+
}): Promise<T[]>;
|
|
98
|
+
findFirst(args?: {
|
|
99
|
+
where?: any;
|
|
100
|
+
orderBy?: any;
|
|
101
|
+
select?: any;
|
|
102
|
+
include?: any;
|
|
103
|
+
}): Promise<T | null>;
|
|
104
|
+
findUnique(args: {
|
|
105
|
+
where: any;
|
|
106
|
+
select?: any;
|
|
107
|
+
include?: any;
|
|
108
|
+
}): Promise<T | null>;
|
|
109
|
+
count(args?: {
|
|
110
|
+
where?: any;
|
|
111
|
+
}): Promise<number>;
|
|
112
|
+
aggregate(args: any): Promise<any>;
|
|
113
|
+
groupBy(args: any): Promise<any[]>;
|
|
114
|
+
vectorSearch(args: any): Promise<(T & {
|
|
115
|
+
distance: number;
|
|
116
|
+
})[]>;
|
|
117
|
+
create(): Promise<never>;
|
|
118
|
+
createMany(): Promise<never>;
|
|
119
|
+
update(): Promise<never>;
|
|
120
|
+
updateMany(): Promise<never>;
|
|
121
|
+
delete(): Promise<never>;
|
|
122
|
+
deleteMany(): Promise<never>;
|
|
123
|
+
upsert(): Promise<never>;
|
|
124
|
+
}
|
|
39
125
|
export declare class An5AdapterTx {
|
|
40
126
|
private readonly handle;
|
|
41
127
|
readonly dialect: Dialect;
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
private closed;
|
|
42
130
|
constructor(handle: TransactionHandle, dialect: Dialect);
|
|
43
131
|
exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]>;
|
|
44
132
|
_executeRaw(query: string, params?: Record<string, any>): Promise<number>;
|
|
133
|
+
$commit(): Promise<void>;
|
|
134
|
+
$rollback(): Promise<void>;
|
|
45
135
|
table<T = any>(modelName: string): AdapterTableClient<T>;
|
|
136
|
+
private ensureOpen;
|
|
46
137
|
}
|
|
47
138
|
export declare class AdapterTableClient<T = any> {
|
|
48
|
-
|
|
49
|
-
|
|
139
|
+
readonly adapter: An5Adapter | An5AdapterTx;
|
|
140
|
+
readonly modelName: string;
|
|
50
141
|
constructor(adapter: An5Adapter | An5AdapterTx, modelName: string);
|
|
51
|
-
|
|
52
|
-
|
|
142
|
+
get dialect(): Dialect;
|
|
143
|
+
get tableName(): string;
|
|
53
144
|
private get nolock();
|
|
145
|
+
/** Build the shared context used by parseWhere to resolve relations and self references. */
|
|
146
|
+
private whereContext;
|
|
54
147
|
private doExec;
|
|
55
148
|
private doExecuteRaw;
|
|
56
149
|
findMany(args?: {
|
|
@@ -59,20 +152,26 @@ export declare class AdapterTableClient<T = any> {
|
|
|
59
152
|
skip?: number;
|
|
60
153
|
take?: number;
|
|
61
154
|
select?: any;
|
|
155
|
+
include?: any;
|
|
62
156
|
}): Promise<T[]>;
|
|
63
157
|
findFirst(args?: {
|
|
64
158
|
where?: any;
|
|
65
159
|
orderBy?: any;
|
|
66
160
|
select?: any;
|
|
161
|
+
include?: any;
|
|
67
162
|
}): Promise<T | null>;
|
|
68
163
|
findUnique(args: {
|
|
69
164
|
where: any;
|
|
165
|
+
select?: any;
|
|
166
|
+
include?: any;
|
|
70
167
|
}): Promise<T | null>;
|
|
71
168
|
count(args?: {
|
|
72
169
|
where?: any;
|
|
73
170
|
}): Promise<number>;
|
|
74
171
|
create(args: {
|
|
75
|
-
data: Partial<T
|
|
172
|
+
data: Partial<T> | any;
|
|
173
|
+
include?: any;
|
|
174
|
+
select?: any;
|
|
76
175
|
}): Promise<T>;
|
|
77
176
|
createMany(args: {
|
|
78
177
|
data: Partial<T>[];
|
|
@@ -82,7 +181,9 @@ export declare class AdapterTableClient<T = any> {
|
|
|
82
181
|
}>;
|
|
83
182
|
update(args: {
|
|
84
183
|
where: any;
|
|
85
|
-
data: Partial<T
|
|
184
|
+
data: Partial<T> | any;
|
|
185
|
+
include?: any;
|
|
186
|
+
select?: any;
|
|
86
187
|
}): Promise<T>;
|
|
87
188
|
updateMany(args: {
|
|
88
189
|
where?: any;
|
|
@@ -105,15 +206,49 @@ export declare class AdapterTableClient<T = any> {
|
|
|
105
206
|
}): Promise<T>;
|
|
106
207
|
aggregate(args: any): Promise<any>;
|
|
107
208
|
groupBy(args: any): Promise<any[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Runs similarity search in NBase and hydrates the matching rows from the
|
|
211
|
+
* relational table, keeping the `{ ...row, distance }` shape the other
|
|
212
|
+
* engines return.
|
|
213
|
+
*/
|
|
214
|
+
private searchViaNBase;
|
|
215
|
+
/**
|
|
216
|
+
* Vector search for an adapter configured with only an NBase connection
|
|
217
|
+
* string. The hit id and metadata are the result, since there is no
|
|
218
|
+
* relational row to hydrate.
|
|
219
|
+
*/
|
|
220
|
+
private searchViaNBaseOnly;
|
|
221
|
+
/** The primary key column registered for this model, falling back to `id`. */
|
|
222
|
+
private primaryKeyColumn;
|
|
223
|
+
/** Scalar column names known for this model from the generated metadata. */
|
|
224
|
+
private modelFields;
|
|
225
|
+
/**
|
|
226
|
+
* Pushes a table's embedding column into NBase so it can be searched there.
|
|
227
|
+
*
|
|
228
|
+
* Each vector keeps the row id in its metadata, which is what lets
|
|
229
|
+
* `vectorSearch` return real rows instead of bare vector ids.
|
|
230
|
+
*/
|
|
231
|
+
indexVectorsInNBase(args?: {
|
|
232
|
+
vectorField?: string;
|
|
233
|
+
where?: any;
|
|
234
|
+
take?: number;
|
|
235
|
+
batchSize?: number;
|
|
236
|
+
}): Promise<{
|
|
237
|
+
indexed: number;
|
|
238
|
+
}>;
|
|
108
239
|
vectorSearch(args: {
|
|
109
240
|
vector: number[];
|
|
110
241
|
take?: number;
|
|
111
242
|
where?: any;
|
|
112
243
|
vectorField?: string;
|
|
113
244
|
distanceMetric?: 'cosine' | 'euclidean' | 'dot';
|
|
245
|
+
vectorElementType?: 'float32' | 'float16' | 'uint8';
|
|
114
246
|
}): Promise<(T & {
|
|
115
247
|
distance: number;
|
|
116
248
|
})[]>;
|
|
117
249
|
}
|
|
118
250
|
export declare function createAn5Adapter(config: AnyAdapterConfig): AnyAdapter;
|
|
251
|
+
export declare function createAn5Adapter<TModels extends object>(config: AnyAdapterConfig): import('./typed').TypedAn5Adapter<TModels>;
|
|
119
252
|
export declare const createAdapter: typeof createAn5Adapter;
|
|
253
|
+
export declare function createBrowserSqliteAdapter(config: any): An5Adapter;
|
|
254
|
+
export declare function executorFromAdapter(adapterLike: any): any;
|