@an5/adapters 0.2.2 → 0.2.4

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 (99) hide show
  1. package/README.md +304 -263
  2. package/{typescript → dist}/an5Adapter.js +2 -2
  3. package/dist/base/uuid.d.ts +5 -0
  4. package/dist/base/uuid.js +17 -0
  5. package/{typescript → dist}/googlesheets/adapter.d.ts +1 -1
  6. package/{typescript → dist}/googlesheets/adapter.js +19 -8
  7. package/{typescript → dist}/googlesheets/config.d.ts +5 -1
  8. package/{typescript → dist}/googlesheets/config.js +2 -1
  9. package/{typescript → dist}/googlesheets/helpers.js +28 -9
  10. package/{typescript → dist}/googlesheets/parseConnectionString.js +4 -0
  11. package/dist/googlesheets/retry.d.ts +25 -0
  12. package/dist/googlesheets/retry.js +115 -0
  13. package/{typescript → dist}/googlesheets/tableClient.d.ts +1 -0
  14. package/{typescript → dist}/googlesheets/tableClient.js +59 -42
  15. package/dotnet/An5Adapter.cs +275 -275
  16. package/dotnet/Base/Core.cs +82 -82
  17. package/dotnet/Mssql/MssqlEngine.cs +144 -144
  18. package/dotnet/Postgres/PostgresEngine.cs +121 -121
  19. package/package.json +22 -10
  20. package/python/an5_adapter.py +97 -97
  21. package/python/base/__init__.py +3 -3
  22. package/python/base/dialects.py +8 -8
  23. package/python/base/metadata.py +10 -10
  24. package/python/base/sql.py +121 -121
  25. package/python/mssql/__init__.py +1 -1
  26. package/python/mssql/provider.py +62 -62
  27. package/python/postgres/__init__.py +1 -1
  28. package/python/postgres/provider.py +15 -15
  29. package/python/table_client.py +216 -216
  30. package/typescript/src/an5Adapter.ts +505 -505
  31. package/typescript/src/base/index.ts +3 -3
  32. package/typescript/src/base/metadata.ts +28 -28
  33. package/typescript/src/base/sql.ts +98 -98
  34. package/typescript/src/base/types.ts +24 -24
  35. package/typescript/src/base/uuid.ts +14 -0
  36. package/typescript/src/browser.ts +6 -6
  37. package/typescript/src/config.ts +95 -95
  38. package/typescript/src/googlesheets/adapter.ts +259 -242
  39. package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
  40. package/typescript/src/googlesheets/config.ts +47 -44
  41. package/typescript/src/googlesheets/helpers.ts +143 -124
  42. package/typescript/src/googlesheets/index.ts +3 -3
  43. package/typescript/src/googlesheets/parseConnectionString.ts +46 -44
  44. package/typescript/src/googlesheets/retry.ts +126 -32
  45. package/typescript/src/googlesheets/sqlExecutor.ts +301 -301
  46. package/typescript/src/googlesheets/tableClient.ts +455 -435
  47. package/typescript/src/googlesheets/types.ts +6 -6
  48. package/typescript/src/index.ts +18 -18
  49. package/typescript/src/mssql/engine.ts +132 -132
  50. package/typescript/src/mssql/index.ts +1 -1
  51. package/typescript/src/mysql/engine.ts +80 -80
  52. package/typescript/src/mysql/index.ts +1 -1
  53. package/typescript/src/postgres/engine.ts +87 -87
  54. package/typescript/src/postgres/index.ts +1 -1
  55. package/typescript/src/sqlite/engine.ts +55 -55
  56. package/typescript/src/sqlite/index.ts +1 -1
  57. package/typescript/googlesheets/retry.d.ts +0 -3
  58. package/typescript/googlesheets/retry.js +0 -39
  59. /package/{typescript → dist}/an5Adapter.d.ts +0 -0
  60. /package/{typescript → dist}/base/index.d.ts +0 -0
  61. /package/{typescript → dist}/base/index.js +0 -0
  62. /package/{typescript → dist}/base/metadata.d.ts +0 -0
  63. /package/{typescript → dist}/base/metadata.js +0 -0
  64. /package/{typescript → dist}/base/sql.d.ts +0 -0
  65. /package/{typescript → dist}/base/sql.js +0 -0
  66. /package/{typescript → dist}/base/types.d.ts +0 -0
  67. /package/{typescript → dist}/base/types.js +0 -0
  68. /package/{typescript → dist}/browser.d.ts +0 -0
  69. /package/{typescript → dist}/browser.js +0 -0
  70. /package/{typescript → dist}/config.d.ts +0 -0
  71. /package/{typescript → dist}/config.js +0 -0
  72. /package/{typescript → dist}/googlesheets/an5SheetsAdapter.d.ts +0 -0
  73. /package/{typescript → dist}/googlesheets/an5SheetsAdapter.js +0 -0
  74. /package/{typescript → dist}/googlesheets/helpers.d.ts +0 -0
  75. /package/{typescript → dist}/googlesheets/index.d.ts +0 -0
  76. /package/{typescript → dist}/googlesheets/index.js +0 -0
  77. /package/{typescript → dist}/googlesheets/parseConnectionString.d.ts +0 -0
  78. /package/{typescript → dist}/googlesheets/sqlExecutor.d.ts +0 -0
  79. /package/{typescript → dist}/googlesheets/sqlExecutor.js +0 -0
  80. /package/{typescript → dist}/googlesheets/types.d.ts +0 -0
  81. /package/{typescript → dist}/googlesheets/types.js +0 -0
  82. /package/{typescript → dist}/index.d.ts +0 -0
  83. /package/{typescript → dist}/index.js +0 -0
  84. /package/{typescript → dist}/mssql/engine.d.ts +0 -0
  85. /package/{typescript → dist}/mssql/engine.js +0 -0
  86. /package/{typescript → dist}/mssql/index.d.ts +0 -0
  87. /package/{typescript → dist}/mssql/index.js +0 -0
  88. /package/{typescript → dist}/mysql/engine.d.ts +0 -0
  89. /package/{typescript → dist}/mysql/engine.js +0 -0
  90. /package/{typescript → dist}/mysql/index.d.ts +0 -0
  91. /package/{typescript → dist}/mysql/index.js +0 -0
  92. /package/{typescript → dist}/postgres/engine.d.ts +0 -0
  93. /package/{typescript → dist}/postgres/engine.js +0 -0
  94. /package/{typescript → dist}/postgres/index.d.ts +0 -0
  95. /package/{typescript → dist}/postgres/index.js +0 -0
  96. /package/{typescript → dist}/sqlite/engine.d.ts +0 -0
  97. /package/{typescript → dist}/sqlite/engine.js +0 -0
  98. /package/{typescript → dist}/sqlite/index.d.ts +0 -0
  99. /package/{typescript → dist}/sqlite/index.js +0 -0
@@ -1 +1 @@
1
- export * from './engine';
1
+ export * from './engine';
@@ -1,55 +1,55 @@
1
- import type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from '../base/types';
2
-
3
- // ─── SQLite Engine ─────────────────────────────────────────────────────────────────
4
-
5
- let BetterSqlite3: any = null;
6
- try { BetterSqlite3 = require('better-sqlite3'); } catch { }
7
-
8
- export class SqliteEngine implements QueryEngine {
9
- dialect: Dialect = 'sqlite';
10
- private db: any = null;
11
- private readonly filePath: string;
12
-
13
- constructor(adapterConfig: An5AdapterConfig) {
14
- if (!BetterSqlite3) throw new Error('better-sqlite3 package is required for SQLite support. Run: npm install better-sqlite3');
15
- this.filePath = adapterConfig.connectionString
16
- .replace(/^sqlite:\/\/\//i, '/')
17
- .replace(/^sqlite:\/\//i, '');
18
- }
19
-
20
- private getDb(): any {
21
- if (!this.db) this.db = new BetterSqlite3(this.filePath);
22
- return this.db;
23
- }
24
-
25
- // better-sqlite3 natively supports @name parameters
26
- async exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]> {
27
- return this.getDb().prepare(query).all(params ?? {}) as T[];
28
- }
29
-
30
- async executeRaw(query: string, params?: Record<string, any>): Promise<number> {
31
- const info = this.getDb().prepare(query).run(params ?? {});
32
- return info.changes ?? 0;
33
- }
34
-
35
- async connect(): Promise<void> { this.getDb(); }
36
-
37
- async disconnect(): Promise<void> {
38
- if (this.db) { this.db.close(); this.db = null; }
39
- }
40
-
41
- async beginTransaction(): Promise<TransactionHandle> {
42
- const db = this.getDb();
43
- db.prepare('BEGIN').run();
44
- let done = false;
45
-
46
- return {
47
- exec: async <T>(q: string, p?: Record<string, any>) =>
48
- db.prepare(q).all(p ?? {}) as T[],
49
- executeRaw: async (q: string, p?: Record<string, any>) =>
50
- (db.prepare(q).run(p ?? {}).changes ?? 0),
51
- commit: async () => { if (!done) { db.prepare('COMMIT').run(); done = true; } },
52
- rollback: async () => { if (!done) { db.prepare('ROLLBACK').run(); done = true; } },
53
- };
54
- }
55
- }
1
+ import type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from '../base/types';
2
+
3
+ // ─── SQLite Engine ─────────────────────────────────────────────────────────────────
4
+
5
+ let BetterSqlite3: any = null;
6
+ try { BetterSqlite3 = require('better-sqlite3'); } catch { }
7
+
8
+ export class SqliteEngine implements QueryEngine {
9
+ dialect: Dialect = 'sqlite';
10
+ private db: any = null;
11
+ private readonly filePath: string;
12
+
13
+ constructor(adapterConfig: An5AdapterConfig) {
14
+ if (!BetterSqlite3) throw new Error('better-sqlite3 package is required for SQLite support. Run: npm install better-sqlite3');
15
+ this.filePath = adapterConfig.connectionString
16
+ .replace(/^sqlite:\/\/\//i, '/')
17
+ .replace(/^sqlite:\/\//i, '');
18
+ }
19
+
20
+ private getDb(): any {
21
+ if (!this.db) this.db = new BetterSqlite3(this.filePath);
22
+ return this.db;
23
+ }
24
+
25
+ // better-sqlite3 natively supports @name parameters
26
+ async exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]> {
27
+ return this.getDb().prepare(query).all(params ?? {}) as T[];
28
+ }
29
+
30
+ async executeRaw(query: string, params?: Record<string, any>): Promise<number> {
31
+ const info = this.getDb().prepare(query).run(params ?? {});
32
+ return info.changes ?? 0;
33
+ }
34
+
35
+ async connect(): Promise<void> { this.getDb(); }
36
+
37
+ async disconnect(): Promise<void> {
38
+ if (this.db) { this.db.close(); this.db = null; }
39
+ }
40
+
41
+ async beginTransaction(): Promise<TransactionHandle> {
42
+ const db = this.getDb();
43
+ db.prepare('BEGIN').run();
44
+ let done = false;
45
+
46
+ return {
47
+ exec: async <T>(q: string, p?: Record<string, any>) =>
48
+ db.prepare(q).all(p ?? {}) as T[],
49
+ executeRaw: async (q: string, p?: Record<string, any>) =>
50
+ (db.prepare(q).run(p ?? {}).changes ?? 0),
51
+ commit: async () => { if (!done) { db.prepare('COMMIT').run(); done = true; } },
52
+ rollback: async () => { if (!done) { db.prepare('ROLLBACK').run(); done = true; } },
53
+ };
54
+ }
55
+ }
@@ -1 +1 @@
1
- export * from './engine';
1
+ export * from './engine';
@@ -1,3 +0,0 @@
1
- export declare const MAX_RETRIES = 3;
2
- export declare const BASE_DELAY = 1000;
3
- export declare function withRetry<T>(fn: () => Promise<T>, attempt?: number): Promise<T>;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- // ─── Retry helper ─────────────────────────────────────────────────────────────
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BASE_DELAY = exports.MAX_RETRIES = void 0;
5
- exports.withRetry = withRetry;
6
- exports.MAX_RETRIES = 3;
7
- exports.BASE_DELAY = 1000;
8
- function isRateLimitError(err) {
9
- const code = err?.code || err?.status || err?.response?.status;
10
- if (code === 429)
11
- return true;
12
- if (code === 500 || code === 503)
13
- return true;
14
- if (code === 403) {
15
- const reason = err?.errors?.[0]?.reason || '';
16
- if (reason === 'rateLimitExceeded')
17
- return true;
18
- if (typeof err?.body === 'string' && err.body.includes('rateLimitExceeded'))
19
- return true;
20
- if (typeof err?.message === 'string' && err.message.includes('rateLimitExceeded'))
21
- return true;
22
- }
23
- return false;
24
- }
25
- async function withRetry(fn, attempt = 1) {
26
- try {
27
- return await fn();
28
- }
29
- catch (err) {
30
- if (isRateLimitError(err) && attempt <= exports.MAX_RETRIES) {
31
- const delay = err.retryAfter
32
- ? err.retryAfter * 1000
33
- : exports.BASE_DELAY * Math.pow(2, attempt - 1) + Math.random() * 500;
34
- await new Promise(r => setTimeout(r, delay));
35
- return withRetry(fn, attempt + 1);
36
- }
37
- throw err;
38
- }
39
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes