@an5/adapters 0.2.5 → 0.2.6

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.
Files changed (82) hide show
  1. package/README.md +189 -305
  2. package/dist/an5Adapter.d.ts +85 -7
  3. package/dist/an5Adapter.js +736 -64
  4. package/dist/base/metadata.d.ts +10 -0
  5. package/dist/base/metadata.js +107 -0
  6. package/dist/base/sql.d.ts +19 -1
  7. package/dist/base/sql.js +152 -24
  8. package/dist/base/types.d.ts +4 -1
  9. package/dist/browser.d.ts +4 -1
  10. package/dist/browser.js +9 -2
  11. package/dist/googlesheets/adapter.d.ts +1 -0
  12. package/dist/googlesheets/adapter.js +9 -2
  13. package/dist/googlesheets/config.d.ts +4 -4
  14. package/dist/googlesheets/helpers.js +2 -0
  15. package/dist/googlesheets/parseConnectionString.js +5 -2
  16. package/dist/googlesheets/sqlExecutor.js +29 -24
  17. package/dist/googlesheets/tableClient.js +14 -5
  18. package/dist/index.d.ts +3 -1
  19. package/dist/index.js +7 -1
  20. package/dist/mssql/engine.js +8 -4
  21. package/dist/mysql/engine.js +1 -1
  22. package/dist/postgres/engine.js +1 -1
  23. package/dist/sqlite/browserEngine.d.ts +27 -0
  24. package/dist/sqlite/browserEngine.js +161 -0
  25. package/dist/sqlite/engine.js +15 -3
  26. package/dist/sqlite/index.d.ts +1 -0
  27. package/dist/sqlite/index.js +1 -0
  28. package/dist/typed.d.ts +5 -0
  29. package/dist/typed.js +2 -0
  30. package/dotnet/An5Adapter.cs +1089 -275
  31. package/dotnet/Base/Core.cs +340 -82
  32. package/dotnet/Mssql/MssqlEngine.cs +145 -144
  33. package/dotnet/Postgres/PostgresEngine.cs +121 -121
  34. package/golang/an5_adapter.go +314 -0
  35. package/golang/base/base.go +100 -0
  36. package/golang/base/metadata.go +116 -0
  37. package/golang/base/where.go +311 -0
  38. package/golang/go.mod +3 -0
  39. package/golang/mssql/mssql.go +32 -0
  40. package/golang/postgres/postgres.go +37 -0
  41. package/golang/sqlite/sqlite.go +14 -0
  42. package/golang/sqlite_test.go +42 -0
  43. package/golang/table_client.go +1329 -0
  44. package/package.json +17 -7
  45. package/python/an5_adapter.py +119 -97
  46. package/python/base/__init__.py +3 -3
  47. package/python/base/dialects.py +11 -8
  48. package/python/base/metadata.py +35 -10
  49. package/python/base/sql.py +172 -121
  50. package/python/mssql/__init__.py +1 -1
  51. package/python/mssql/provider.py +62 -62
  52. package/python/postgres/__init__.py +1 -1
  53. package/python/postgres/provider.py +15 -15
  54. package/python/table_client.py +619 -216
  55. package/typescript/src/an5Adapter.ts +1220 -505
  56. package/typescript/src/base/index.ts +3 -3
  57. package/typescript/src/base/metadata.ts +148 -28
  58. package/typescript/src/base/sql.ts +264 -98
  59. package/typescript/src/base/types.ts +27 -24
  60. package/typescript/src/browser.ts +10 -6
  61. package/typescript/src/config.ts +95 -95
  62. package/typescript/src/googlesheets/adapter.ts +269 -259
  63. package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
  64. package/typescript/src/googlesheets/config.ts +47 -47
  65. package/typescript/src/googlesheets/helpers.ts +144 -143
  66. package/typescript/src/googlesheets/index.ts +3 -3
  67. package/typescript/src/googlesheets/parseConnectionString.ts +48 -46
  68. package/typescript/src/googlesheets/retry.ts +126 -126
  69. package/typescript/src/googlesheets/sqlExecutor.ts +304 -301
  70. package/typescript/src/googlesheets/tableClient.ts +461 -455
  71. package/typescript/src/googlesheets/types.ts +6 -6
  72. package/typescript/src/index.ts +31 -27
  73. package/typescript/src/mssql/engine.ts +134 -132
  74. package/typescript/src/mssql/index.ts +1 -1
  75. package/typescript/src/mysql/engine.ts +80 -80
  76. package/typescript/src/mysql/index.ts +1 -1
  77. package/typescript/src/postgres/engine.ts +87 -87
  78. package/typescript/src/postgres/index.ts +1 -1
  79. package/typescript/src/sqlite/browserEngine.ts +192 -0
  80. package/typescript/src/sqlite/engine.ts +66 -55
  81. package/typescript/src/sqlite/index.ts +3 -1
  82. package/typescript/src/typed.ts +52 -0
@@ -1,95 +1,95 @@
1
- import { createAn5Adapter, type AnyAdapter } from './an5Adapter';
2
-
3
- export interface LlmConfigData {
4
- provider: string;
5
- apiKey: string;
6
- model?: string;
7
- endpoint?: string;
8
- }
9
-
10
- export interface EmbeddingConfigData {
11
- provider: string;
12
- apiKey: string;
13
- model?: string;
14
- endpoint?: string;
15
- }
16
-
17
- let _adapter: AnyAdapter | null = null;
18
-
19
- function getAdapter(): AnyAdapter | null {
20
- if (_adapter) return _adapter;
21
- const url = process.env.DATABASE_URL;
22
- if (!url) return null;
23
- try {
24
- _adapter = createAn5Adapter({ connectionString: url });
25
- return _adapter;
26
- } catch {
27
- return null;
28
- }
29
- }
30
-
31
- export function resetAdapter(): void {
32
- _adapter = null;
33
- }
34
-
35
- export async function getLlmConfig(): Promise<LlmConfigData | null> {
36
- const adapter = getAdapter();
37
- if (!adapter) return null;
38
- try {
39
- const rows = await adapter.table<LlmConfigData>('LlmConfig').findMany({
40
- where: { isActive: true },
41
- });
42
- if (rows.length > 0) {
43
- const c = rows[0] as any;
44
- return { provider: c.provider, apiKey: c.apiKey, model: c.model, endpoint: c.endpoint };
45
- }
46
- } catch {}
47
- return null;
48
- }
49
-
50
- export async function setLlmConfig(data: LlmConfigData): Promise<void> {
51
- const adapter = getAdapter();
52
- if (!adapter) throw new Error('DATABASE_URL not configured');
53
- const existing = await adapter.table('LlmConfig').findFirst({ where: { isActive: true } });
54
- if (existing) {
55
- await adapter.table('LlmConfig').update({
56
- where: { id: (existing as any).id },
57
- data: { ...data, updatedAt: new Date() },
58
- });
59
- } else {
60
- await adapter.table('LlmConfig').create({
61
- data: { ...data, isActive: true, createdAt: new Date(), updatedAt: new Date() },
62
- });
63
- }
64
- }
65
-
66
- export async function getEmbeddingConfig(): Promise<EmbeddingConfigData | null> {
67
- const adapter = getAdapter();
68
- if (!adapter) return null;
69
- try {
70
- const rows = await adapter.table<EmbeddingConfigData>('EmbeddingConfig').findMany({
71
- where: { isActive: true },
72
- });
73
- if (rows.length > 0) {
74
- const c = rows[0] as any;
75
- return { provider: c.provider, apiKey: c.apiKey, model: c.model, endpoint: c.endpoint };
76
- }
77
- } catch {}
78
- return null;
79
- }
80
-
81
- export async function setEmbeddingConfig(data: EmbeddingConfigData): Promise<void> {
82
- const adapter = getAdapter();
83
- if (!adapter) throw new Error('DATABASE_URL not configured');
84
- const existing = await adapter.table('EmbeddingConfig').findFirst({ where: { isActive: true } });
85
- if (existing) {
86
- await adapter.table('EmbeddingConfig').update({
87
- where: { id: (existing as any).id },
88
- data: { ...data, updatedAt: new Date() },
89
- });
90
- } else {
91
- await adapter.table('EmbeddingConfig').create({
92
- data: { ...data, isActive: true, createdAt: new Date(), updatedAt: new Date() },
93
- });
94
- }
95
- }
1
+ import { createAn5Adapter, type AnyAdapter } from './an5Adapter';
2
+
3
+ export interface LlmConfigData {
4
+ provider: string;
5
+ apiKey: string;
6
+ model?: string;
7
+ endpoint?: string;
8
+ }
9
+
10
+ export interface EmbeddingConfigData {
11
+ provider: string;
12
+ apiKey: string;
13
+ model?: string;
14
+ endpoint?: string;
15
+ }
16
+
17
+ let _adapter: AnyAdapter | null = null;
18
+
19
+ function getAdapter(): AnyAdapter | null {
20
+ if (_adapter) return _adapter;
21
+ const url = process.env.DATABASE_URL;
22
+ if (!url) return null;
23
+ try {
24
+ _adapter = createAn5Adapter({ connectionString: url });
25
+ return _adapter;
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ export function resetAdapter(): void {
32
+ _adapter = null;
33
+ }
34
+
35
+ export async function getLlmConfig(): Promise<LlmConfigData | null> {
36
+ const adapter = getAdapter();
37
+ if (!adapter) return null;
38
+ try {
39
+ const rows = await adapter.table<LlmConfigData>('LlmConfig').findMany({
40
+ where: { isActive: true },
41
+ });
42
+ if (rows.length > 0) {
43
+ const c = rows[0] as any;
44
+ return { provider: c.provider, apiKey: c.apiKey, model: c.model, endpoint: c.endpoint };
45
+ }
46
+ } catch {}
47
+ return null;
48
+ }
49
+
50
+ export async function setLlmConfig(data: LlmConfigData): Promise<void> {
51
+ const adapter = getAdapter();
52
+ if (!adapter) throw new Error('DATABASE_URL not configured');
53
+ const existing = await adapter.table('LlmConfig').findFirst({ where: { isActive: true } });
54
+ if (existing) {
55
+ await adapter.table('LlmConfig').update({
56
+ where: { id: (existing as any).id },
57
+ data: { ...data, updatedAt: new Date() },
58
+ });
59
+ } else {
60
+ await adapter.table('LlmConfig').create({
61
+ data: { ...data, isActive: true, createdAt: new Date(), updatedAt: new Date() },
62
+ });
63
+ }
64
+ }
65
+
66
+ export async function getEmbeddingConfig(): Promise<EmbeddingConfigData | null> {
67
+ const adapter = getAdapter();
68
+ if (!adapter) return null;
69
+ try {
70
+ const rows = await adapter.table<EmbeddingConfigData>('EmbeddingConfig').findMany({
71
+ where: { isActive: true },
72
+ });
73
+ if (rows.length > 0) {
74
+ const c = rows[0] as any;
75
+ return { provider: c.provider, apiKey: c.apiKey, model: c.model, endpoint: c.endpoint };
76
+ }
77
+ } catch {}
78
+ return null;
79
+ }
80
+
81
+ export async function setEmbeddingConfig(data: EmbeddingConfigData): Promise<void> {
82
+ const adapter = getAdapter();
83
+ if (!adapter) throw new Error('DATABASE_URL not configured');
84
+ const existing = await adapter.table('EmbeddingConfig').findFirst({ where: { isActive: true } });
85
+ if (existing) {
86
+ await adapter.table('EmbeddingConfig').update({
87
+ where: { id: (existing as any).id },
88
+ data: { ...data, updatedAt: new Date() },
89
+ });
90
+ } else {
91
+ await adapter.table('EmbeddingConfig').create({
92
+ data: { ...data, isActive: true, createdAt: new Date(), updatedAt: new Date() },
93
+ });
94
+ }
95
+ }