defuss-db 1.1.2 → 1.1.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.
- package/dist/client.cjs +0 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.mjs +0 -0
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +0 -0
- package/dist/server.cjs +0 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.mjs +1 -1
- package/package.json +24 -14
- package/dist/client.d.cts +0 -92
- package/dist/client.d.mts +0 -92
- package/dist/server.d.cts +0 -253
- package/dist/server.d.mts +0 -253
package/dist/client.cjs
CHANGED
|
File without changes
|
package/dist/client.d.ts
CHANGED
|
@@ -89,4 +89,5 @@ declare class DexieProvider implements DefussProvider<DexieOptions> {
|
|
|
89
89
|
private normalizeRecord;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export { DefussProvider, DefussRecord, DexieProvider,
|
|
92
|
+
export { DefussProvider, DefussRecord, DexieProvider, PrimaryKeyValue, RecordValue };
|
|
93
|
+
export type { DexieProviderOptions };
|
package/dist/client.mjs
CHANGED
|
File without changes
|
package/dist/index.cjs
CHANGED
|
File without changes
|
package/dist/index.d.cts
CHANGED
|
@@ -124,4 +124,5 @@ declare class DefussTable<T extends DefussRecord, O> {
|
|
|
124
124
|
upsert(value: T, indexData: Record<string, RecordValue>): Promise<PrimaryKeyValue>;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export {
|
|
127
|
+
export { DefussTable };
|
|
128
|
+
export type { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue };
|
package/dist/index.d.mts
CHANGED
|
@@ -124,4 +124,5 @@ declare class DefussTable<T extends DefussRecord, O> {
|
|
|
124
124
|
upsert(value: T, indexData: Record<string, RecordValue>): Promise<PrimaryKeyValue>;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export {
|
|
127
|
+
export { DefussTable };
|
|
128
|
+
export type { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -124,4 +124,5 @@ declare class DefussTable<T extends DefussRecord, O> {
|
|
|
124
124
|
upsert(value: T, indexData: Record<string, RecordValue>): Promise<PrimaryKeyValue>;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export {
|
|
127
|
+
export { DefussTable };
|
|
128
|
+
export type { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue };
|
package/dist/index.mjs
CHANGED
|
File without changes
|
package/dist/server.cjs
CHANGED
|
File without changes
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue } from './index.js';
|
|
2
2
|
export { DefussTable } from './index.js';
|
|
3
3
|
import { Config, Client } from '@libsql/client';
|
|
4
|
-
import { MongoClient, Db,
|
|
4
|
+
import { MongoClient, Db, Collection, Document, ObjectId } from 'mongodb';
|
|
5
5
|
|
|
6
6
|
type LibsqlProviderOptions = Config;
|
|
7
7
|
/**
|
|
@@ -250,4 +250,5 @@ declare class MongoProvider implements DefussProvider<MongoProviderOptions> {
|
|
|
250
250
|
declare function closeAllConnections(): Promise<void>;
|
|
251
251
|
declare function clearMongoConnections(): void;
|
|
252
252
|
|
|
253
|
-
export {
|
|
253
|
+
export { DefussProvider, DefussRecord, LibsqlProvider, MongoProvider, PrimaryKeyValue, RecordValue, clearMongoConnections, closeAllConnections, connectToMongo, getCollectionByName, isConnected, isValidObjectId, parseMongoConnectionString, ping, toObjectId };
|
|
254
|
+
export type { DbClientMap, DbMap, LibsqlProviderOptions, MongoProviderOptions };
|
package/dist/server.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "defuss-db",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"description": "Isomorphic database abstraction, defussed.",
|
|
10
|
-
"keywords": [
|
|
10
|
+
"keywords": [
|
|
11
|
+
"db",
|
|
12
|
+
"database",
|
|
13
|
+
"abstraction",
|
|
14
|
+
"dexie",
|
|
15
|
+
"libsql",
|
|
16
|
+
"mongodb"
|
|
17
|
+
],
|
|
11
18
|
"repository": {
|
|
12
19
|
"url": "git+https://github.com/kyr0/defuss.git",
|
|
13
20
|
"type": "git"
|
|
14
21
|
},
|
|
15
22
|
"scripts": {
|
|
16
|
-
"clean": "rm -rf ./dist && rm -rf ./node_modules/.
|
|
17
|
-
"pretest": "
|
|
18
|
-
"prebuild": "
|
|
23
|
+
"clean": "rm -rf ./dist && rm -rf ./node_modules/.bun",
|
|
24
|
+
"pretest": "bun run build",
|
|
25
|
+
"prebuild": "bun run clean",
|
|
19
26
|
"build": "pkgroll",
|
|
20
27
|
"mongodb:start": "tsx scripts/mongo-start.ts",
|
|
21
28
|
"mongodb:stop": "tsx scripts/mongo-stop.ts",
|
|
22
|
-
"test": "vitest --run
|
|
29
|
+
"test": "tsx ./scripts/readiness.ts && vitest --run --coverage"
|
|
23
30
|
},
|
|
24
31
|
"author": "Aron Homberg <info@aron-homberg.de>",
|
|
25
32
|
"sideEffects": false,
|
|
@@ -58,23 +65,26 @@
|
|
|
58
65
|
"main": "./dist/index.cjs",
|
|
59
66
|
"module": "./dist/index.mjs",
|
|
60
67
|
"types": "./dist/index.d.cts",
|
|
61
|
-
"files": [
|
|
68
|
+
"files": [
|
|
69
|
+
"dist"
|
|
70
|
+
],
|
|
62
71
|
"engines": {
|
|
63
72
|
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|
|
64
73
|
},
|
|
65
74
|
"dependencies": {
|
|
66
75
|
"@libsql/client": "^0.15.7",
|
|
76
|
+
"defuss-env": "^1.0.2",
|
|
67
77
|
"dexie": "^4.0.11",
|
|
68
|
-
"defuss-env": "^1.0.1",
|
|
69
78
|
"fake-indexeddb": "^6.0.1",
|
|
70
79
|
"mongodb": "^6.16.0"
|
|
71
80
|
},
|
|
72
81
|
"devDependencies": {
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
82
|
+
"@types/node": "^25.1.0",
|
|
83
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
84
|
+
"happy-dom": "^20.3.1",
|
|
85
|
+
"pkgroll": "^2.21.5",
|
|
86
|
+
"tsx": "^4.21.0",
|
|
87
|
+
"typescript": "^5.9.3",
|
|
88
|
+
"vitest": "^4.0.17"
|
|
79
89
|
}
|
|
80
90
|
}
|
package/dist/client.d.cts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue } from './index.cjs';
|
|
2
|
-
export { DefussTable } from './index.cjs';
|
|
3
|
-
import { DexieOptions, Dexie, Table, IndexableType } from 'dexie';
|
|
4
|
-
|
|
5
|
-
type DexieProviderOptions = DexieOptions;
|
|
6
|
-
/**
|
|
7
|
-
* DexieProvider implements DefussProvider for IndexedDB using Dexie.js.
|
|
8
|
-
*/
|
|
9
|
-
declare class DexieProvider implements DefussProvider<DexieOptions> {
|
|
10
|
-
db: Dexie;
|
|
11
|
-
tables: Map<string, Table<any, IndexableType>>;
|
|
12
|
-
databaseName: string;
|
|
13
|
-
schema: Map<string, Record<string, string>>;
|
|
14
|
-
schemaVersion: number;
|
|
15
|
-
isOpen: boolean;
|
|
16
|
-
constructor(databaseName: string);
|
|
17
|
-
/**
|
|
18
|
-
* Connects to IndexedDB. Dexie.js manages connections internally.
|
|
19
|
-
* @param options - Dexie-specific configuration options.
|
|
20
|
-
*/
|
|
21
|
-
connect(options?: DexieOptions): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Disconnects from IndexedDB.
|
|
24
|
-
*/
|
|
25
|
-
disconnect(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Checks if the provider is currently connected to the database.
|
|
28
|
-
* @returns True if connected, false otherwise.
|
|
29
|
-
*/
|
|
30
|
-
isConnected(): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a table if it doesn't exist with dynamic schema support.
|
|
33
|
-
* @param table - The name of the table.
|
|
34
|
-
*/
|
|
35
|
-
createTable(table: string): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Adds columns to the schema if they don't exist, with proper indexing.
|
|
38
|
-
* @param table - The name of the table.
|
|
39
|
-
* @param record - The record with properties to consider adding.
|
|
40
|
-
*/
|
|
41
|
-
private ensureColumnsForRecord;
|
|
42
|
-
/**
|
|
43
|
-
* Inserts a record into a table.
|
|
44
|
-
* @param table - The name of the table.
|
|
45
|
-
* @param record - The record to insert.
|
|
46
|
-
* @returns The primary key of the inserted record.
|
|
47
|
-
*/
|
|
48
|
-
insert<T extends DefussRecord>(table: string, record: T): Promise<PrimaryKeyValue>;
|
|
49
|
-
/**
|
|
50
|
-
* Finds records in the table based on query.
|
|
51
|
-
* @param table - The name of the table.
|
|
52
|
-
* @param query - Query criteria.
|
|
53
|
-
* @returns An array of matching records.
|
|
54
|
-
*/
|
|
55
|
-
find<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Finds a single record in the table based on query.
|
|
58
|
-
* @param table - The name of the table.
|
|
59
|
-
* @param query - Query criteria.
|
|
60
|
-
* @returns The first matching record or null.
|
|
61
|
-
*/
|
|
62
|
-
findOne<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
63
|
-
/**
|
|
64
|
-
* Updates records in the table based on query.
|
|
65
|
-
* @param table - The name of the table.
|
|
66
|
-
* @param query - Query criteria.
|
|
67
|
-
* @param update - Fields to update.
|
|
68
|
-
*/
|
|
69
|
-
update<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>, update: Partial<T>): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Deletes records from the table based on query.
|
|
72
|
-
* @param table - The name of the table.
|
|
73
|
-
* @param query - Query criteria.
|
|
74
|
-
*/
|
|
75
|
-
delete(table: string, query: Partial<DefussRecord>): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Upserts a record into the table based on query.
|
|
78
|
-
* @param table - The name of the table.
|
|
79
|
-
* @param record - The record to upsert.
|
|
80
|
-
* @param query - Query criteria.
|
|
81
|
-
* @returns The primary key of the upserted record.
|
|
82
|
-
*/
|
|
83
|
-
upsert<T extends DefussRecord>(table: string, record: T, query: Partial<Record<string, RecordValue>>): Promise<PrimaryKeyValue>;
|
|
84
|
-
/**
|
|
85
|
-
* Normalizes a database record to match DefussRecord structure.
|
|
86
|
-
* @param record - The record from the database.
|
|
87
|
-
* @returns A normalized DefussRecord.
|
|
88
|
-
*/
|
|
89
|
-
private normalizeRecord;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { DefussProvider, DefussRecord, DexieProvider, type DexieProviderOptions, PrimaryKeyValue, RecordValue };
|
package/dist/client.d.mts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue } from './index.mjs';
|
|
2
|
-
export { DefussTable } from './index.mjs';
|
|
3
|
-
import { DexieOptions, Dexie, Table, IndexableType } from 'dexie';
|
|
4
|
-
|
|
5
|
-
type DexieProviderOptions = DexieOptions;
|
|
6
|
-
/**
|
|
7
|
-
* DexieProvider implements DefussProvider for IndexedDB using Dexie.js.
|
|
8
|
-
*/
|
|
9
|
-
declare class DexieProvider implements DefussProvider<DexieOptions> {
|
|
10
|
-
db: Dexie;
|
|
11
|
-
tables: Map<string, Table<any, IndexableType>>;
|
|
12
|
-
databaseName: string;
|
|
13
|
-
schema: Map<string, Record<string, string>>;
|
|
14
|
-
schemaVersion: number;
|
|
15
|
-
isOpen: boolean;
|
|
16
|
-
constructor(databaseName: string);
|
|
17
|
-
/**
|
|
18
|
-
* Connects to IndexedDB. Dexie.js manages connections internally.
|
|
19
|
-
* @param options - Dexie-specific configuration options.
|
|
20
|
-
*/
|
|
21
|
-
connect(options?: DexieOptions): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Disconnects from IndexedDB.
|
|
24
|
-
*/
|
|
25
|
-
disconnect(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Checks if the provider is currently connected to the database.
|
|
28
|
-
* @returns True if connected, false otherwise.
|
|
29
|
-
*/
|
|
30
|
-
isConnected(): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a table if it doesn't exist with dynamic schema support.
|
|
33
|
-
* @param table - The name of the table.
|
|
34
|
-
*/
|
|
35
|
-
createTable(table: string): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Adds columns to the schema if they don't exist, with proper indexing.
|
|
38
|
-
* @param table - The name of the table.
|
|
39
|
-
* @param record - The record with properties to consider adding.
|
|
40
|
-
*/
|
|
41
|
-
private ensureColumnsForRecord;
|
|
42
|
-
/**
|
|
43
|
-
* Inserts a record into a table.
|
|
44
|
-
* @param table - The name of the table.
|
|
45
|
-
* @param record - The record to insert.
|
|
46
|
-
* @returns The primary key of the inserted record.
|
|
47
|
-
*/
|
|
48
|
-
insert<T extends DefussRecord>(table: string, record: T): Promise<PrimaryKeyValue>;
|
|
49
|
-
/**
|
|
50
|
-
* Finds records in the table based on query.
|
|
51
|
-
* @param table - The name of the table.
|
|
52
|
-
* @param query - Query criteria.
|
|
53
|
-
* @returns An array of matching records.
|
|
54
|
-
*/
|
|
55
|
-
find<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
56
|
-
/**
|
|
57
|
-
* Finds a single record in the table based on query.
|
|
58
|
-
* @param table - The name of the table.
|
|
59
|
-
* @param query - Query criteria.
|
|
60
|
-
* @returns The first matching record or null.
|
|
61
|
-
*/
|
|
62
|
-
findOne<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
63
|
-
/**
|
|
64
|
-
* Updates records in the table based on query.
|
|
65
|
-
* @param table - The name of the table.
|
|
66
|
-
* @param query - Query criteria.
|
|
67
|
-
* @param update - Fields to update.
|
|
68
|
-
*/
|
|
69
|
-
update<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>, update: Partial<T>): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Deletes records from the table based on query.
|
|
72
|
-
* @param table - The name of the table.
|
|
73
|
-
* @param query - Query criteria.
|
|
74
|
-
*/
|
|
75
|
-
delete(table: string, query: Partial<DefussRecord>): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Upserts a record into the table based on query.
|
|
78
|
-
* @param table - The name of the table.
|
|
79
|
-
* @param record - The record to upsert.
|
|
80
|
-
* @param query - Query criteria.
|
|
81
|
-
* @returns The primary key of the upserted record.
|
|
82
|
-
*/
|
|
83
|
-
upsert<T extends DefussRecord>(table: string, record: T, query: Partial<Record<string, RecordValue>>): Promise<PrimaryKeyValue>;
|
|
84
|
-
/**
|
|
85
|
-
* Normalizes a database record to match DefussRecord structure.
|
|
86
|
-
* @param record - The record from the database.
|
|
87
|
-
* @returns A normalized DefussRecord.
|
|
88
|
-
*/
|
|
89
|
-
private normalizeRecord;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { DefussProvider, DefussRecord, DexieProvider, type DexieProviderOptions, PrimaryKeyValue, RecordValue };
|
package/dist/server.d.cts
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue } from './index.cjs';
|
|
2
|
-
export { DefussTable } from './index.cjs';
|
|
3
|
-
import { Config, Client } from '@libsql/client';
|
|
4
|
-
import { MongoClient, Db, Document, Collection, ObjectId } from 'mongodb';
|
|
5
|
-
|
|
6
|
-
type LibsqlProviderOptions = Config;
|
|
7
|
-
/**
|
|
8
|
-
* LibsqlProvider implements DefussProvider using libsql for SQLite databases.
|
|
9
|
-
*/
|
|
10
|
-
declare class LibsqlProvider implements DefussProvider<Config> {
|
|
11
|
-
db: Client;
|
|
12
|
-
/**
|
|
13
|
-
* Connects to the SQLite database using libsql.
|
|
14
|
-
* @param config - The libsql connection configuration.
|
|
15
|
-
*/
|
|
16
|
-
connect(config: Config): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* Disconnects from the SQLite database.
|
|
19
|
-
*/
|
|
20
|
-
disconnect(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Checks if the provider is currently connected to the database.
|
|
23
|
-
* @returns True if connected, false otherwise.
|
|
24
|
-
*/
|
|
25
|
-
isConnected(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a table if it doesn't exist.
|
|
28
|
-
* Sets up the primary key and any initial structure needed.
|
|
29
|
-
* @param table - The name of the table.
|
|
30
|
-
*/
|
|
31
|
-
createTable(table: string): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Ensures all necessary columns exist in the table
|
|
34
|
-
* @param table - The name of the table
|
|
35
|
-
* @param record - DefussRecord containing fields to ensure
|
|
36
|
-
*/
|
|
37
|
-
private ensureColumnsExist;
|
|
38
|
-
/**
|
|
39
|
-
* Gets the SQLite data type for a JavaScript value
|
|
40
|
-
* @param value The JavaScript value to map to SQLite type
|
|
41
|
-
* @returns The SQLite type string
|
|
42
|
-
*/
|
|
43
|
-
private getSqliteType;
|
|
44
|
-
/**
|
|
45
|
-
* Retrieves existing columns in the specified table.
|
|
46
|
-
* @param table - The name of the table.
|
|
47
|
-
* @returns An array of column names.
|
|
48
|
-
*/
|
|
49
|
-
private getExistingColumns;
|
|
50
|
-
/**
|
|
51
|
-
* Converts a DefussRecord to SQLite values
|
|
52
|
-
* @param record The DefussRecord to convert
|
|
53
|
-
* @returns Object with column names and values for SQLite
|
|
54
|
-
*/
|
|
55
|
-
private toSqliteValues;
|
|
56
|
-
/**
|
|
57
|
-
* Convert JavaScript value to SQLite-compatible value
|
|
58
|
-
*/
|
|
59
|
-
private convertValueForSqlite;
|
|
60
|
-
/**
|
|
61
|
-
* Convert SQLite row to DefussRecord
|
|
62
|
-
*/
|
|
63
|
-
private fromSqliteRow;
|
|
64
|
-
/**
|
|
65
|
-
* Inserts a record into the table.
|
|
66
|
-
* @param table - The name of the table.
|
|
67
|
-
* @param record - The record to insert.
|
|
68
|
-
* @returns The primary key of the inserted record.
|
|
69
|
-
*/
|
|
70
|
-
insert<T extends DefussRecord>(table: string, record: T): Promise<PrimaryKeyValue>;
|
|
71
|
-
/**
|
|
72
|
-
* Finds records in the table based on query.
|
|
73
|
-
* @param table - The name of the table.
|
|
74
|
-
* @param query - Query criteria.
|
|
75
|
-
* @returns An array of matching records.
|
|
76
|
-
*/
|
|
77
|
-
find<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
78
|
-
/**
|
|
79
|
-
* Finds a single record in the table based on query.
|
|
80
|
-
* @param table - The name of the table.
|
|
81
|
-
* @param query - Query criteria.
|
|
82
|
-
* @returns The first matching record or null.
|
|
83
|
-
*/
|
|
84
|
-
findOne<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
85
|
-
/**
|
|
86
|
-
* Updates records in the table based on query.
|
|
87
|
-
* @param table - The name of the table.
|
|
88
|
-
* @param query - Query criteria.
|
|
89
|
-
* @param update - Fields to update.
|
|
90
|
-
*/
|
|
91
|
-
update<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>, update: Partial<T>): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Deletes records from the table based on query.
|
|
94
|
-
* @param table - The name of the table.
|
|
95
|
-
* @param query - Query criteria.
|
|
96
|
-
*/
|
|
97
|
-
delete(table: string, query: Partial<DefussRecord>): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Upserts a record into the table based on query.
|
|
100
|
-
* @param table - The name of the table.
|
|
101
|
-
* @param record - The record to upsert.
|
|
102
|
-
* @param query - Query criteria.
|
|
103
|
-
* @returns The primary key of the upserted record.
|
|
104
|
-
*/
|
|
105
|
-
upsert<T extends DefussRecord>(table: string, record: T, query: Partial<Record<string, RecordValue>>): Promise<PrimaryKeyValue>;
|
|
106
|
-
/**
|
|
107
|
-
* Ensures that the specified table exists.
|
|
108
|
-
* @param table - The name of the table.
|
|
109
|
-
*/
|
|
110
|
-
private ensureTableExists;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
interface MongoProviderOptions {
|
|
114
|
-
connectionString: string;
|
|
115
|
-
databaseName: string;
|
|
116
|
-
}
|
|
117
|
-
type DbClientMap = {
|
|
118
|
-
[clientKey: string]: MongoClient | null;
|
|
119
|
-
};
|
|
120
|
-
type DbMap = {
|
|
121
|
-
[dbName: string]: Db | null;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Parses a MongoDB connection string into its components
|
|
125
|
-
* @param connectionString - MongoDB connection string
|
|
126
|
-
* @returns Object containing databaseName and clientKey
|
|
127
|
-
*/
|
|
128
|
-
declare const parseMongoConnectionString: (connectionString: string) => {
|
|
129
|
-
databaseName: string;
|
|
130
|
-
clientKey: string;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Core connection function to be used by all parts of the system
|
|
134
|
-
* @param connectionString MongoDB connection string
|
|
135
|
-
* @returns Object containing the MongoClient and Db instances
|
|
136
|
-
*/
|
|
137
|
-
declare function connectToMongo(connectionString: string): Promise<{
|
|
138
|
-
client: MongoClient;
|
|
139
|
-
db: Db;
|
|
140
|
-
}>;
|
|
141
|
-
/** Returns true if both dbClient and database are initialized */
|
|
142
|
-
declare const isConnected: (connectionString: string) => boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Pings the MongoDB server to check connectivity
|
|
145
|
-
* @param connectionString MongoDB connection string
|
|
146
|
-
*/
|
|
147
|
-
declare const ping: (connectionString: string) => Promise<unknown>;
|
|
148
|
-
/**
|
|
149
|
-
* Gets a collection by name, connecting if necessary
|
|
150
|
-
*/
|
|
151
|
-
declare const getCollectionByName: <T extends Document>(collectionName: string, connectionString: string) => Promise<Collection<T>>;
|
|
152
|
-
declare function isValidObjectId(id: string): boolean;
|
|
153
|
-
declare const toObjectId: (id: string | ObjectId) => ObjectId;
|
|
154
|
-
interface MongoDefussDocument extends Document {
|
|
155
|
-
type?: "json" | "blob";
|
|
156
|
-
json?: string;
|
|
157
|
-
blob?: ArrayBuffer;
|
|
158
|
-
[key: string]: any;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* MongoProvider implements DefussProvider for MongoDB.
|
|
162
|
-
*/
|
|
163
|
-
declare class MongoProvider implements DefussProvider<MongoProviderOptions> {
|
|
164
|
-
client: MongoClient | null;
|
|
165
|
-
db: Db | null;
|
|
166
|
-
collections: Map<string, Collection<Document>>;
|
|
167
|
-
connectionString: string;
|
|
168
|
-
constructor(options: MongoProviderOptions);
|
|
169
|
-
/**
|
|
170
|
-
* Connects to MongoDB using the shared connection function.
|
|
171
|
-
*/
|
|
172
|
-
connect(options?: MongoProviderOptions): Promise<void>;
|
|
173
|
-
/**
|
|
174
|
-
* Disconnects from MongoDB.
|
|
175
|
-
*/
|
|
176
|
-
disconnect(): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Checks if the provider is currently connected to the database.
|
|
179
|
-
* @returns True if connected, false otherwise.
|
|
180
|
-
*/
|
|
181
|
-
isConnected(): boolean;
|
|
182
|
-
/**
|
|
183
|
-
* Creates a collection if it doesn't exist.
|
|
184
|
-
*/
|
|
185
|
-
createTable(table: string): Promise<void>;
|
|
186
|
-
/**
|
|
187
|
-
* Converts DefussRecord to MongoDB document
|
|
188
|
-
* @param record DefussRecord to convert
|
|
189
|
-
* @returns MongoDB document
|
|
190
|
-
*/
|
|
191
|
-
private toMongoDoc;
|
|
192
|
-
/**
|
|
193
|
-
* Converts MongoDB document to DefussRecord
|
|
194
|
-
* @param doc MongoDB document to convert
|
|
195
|
-
* @returns DefussRecord
|
|
196
|
-
*/
|
|
197
|
-
private fromMongoDoc;
|
|
198
|
-
/**
|
|
199
|
-
* Inserts a new document into the collection.
|
|
200
|
-
* @param table - The name of the collection.
|
|
201
|
-
* @param record - The record to insert.
|
|
202
|
-
* @returns The primary key of the inserted document.
|
|
203
|
-
*/
|
|
204
|
-
insert<T extends DefussRecord>(table: string, record: T): Promise<PrimaryKeyValue>;
|
|
205
|
-
/**
|
|
206
|
-
* Finds documents in the collection based on query.
|
|
207
|
-
* @param table - The name of the collection.
|
|
208
|
-
* @param query - Query criteria.
|
|
209
|
-
* @returns An array of matching documents.
|
|
210
|
-
*/
|
|
211
|
-
find<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
212
|
-
/**
|
|
213
|
-
* Finds a single document in the collection based on query.
|
|
214
|
-
* @param table - The name of the collection.
|
|
215
|
-
* @param query - Query criteria.
|
|
216
|
-
* @returns The first matching document or null.
|
|
217
|
-
*/
|
|
218
|
-
findOne<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
219
|
-
/**
|
|
220
|
-
* Updates documents in the collection based on query.
|
|
221
|
-
* @param table - The name of the collection.
|
|
222
|
-
* @param query - Query criteria.
|
|
223
|
-
* @param update - Fields to update.
|
|
224
|
-
*/
|
|
225
|
-
update<T extends DefussRecord>(table: string, query: Partial<T>, update: Partial<T>): Promise<void>;
|
|
226
|
-
/**
|
|
227
|
-
* Deletes documents from the collection based on query.
|
|
228
|
-
* @param table - The name of the collection.
|
|
229
|
-
* @param query - Query criteria.
|
|
230
|
-
*/
|
|
231
|
-
delete(table: string, query: Partial<DefussRecord>): Promise<void>;
|
|
232
|
-
/**
|
|
233
|
-
* Upserts a document into the collection based on query.
|
|
234
|
-
* @param table - The name of the collection.
|
|
235
|
-
* @param record - The record to upsert.
|
|
236
|
-
* @param query - Query criteria.
|
|
237
|
-
* @returns The primary key of the upserted document.
|
|
238
|
-
*/
|
|
239
|
-
upsert<T extends DefussRecord>(table: string, record: T, query: Partial<Record<string, RecordValue>>): Promise<PrimaryKeyValue>;
|
|
240
|
-
/**
|
|
241
|
-
* Deserializes a MongoDB document into a JavaScript object.
|
|
242
|
-
* @param row - The document to deserialize.
|
|
243
|
-
* @returns The deserialized JavaScript object.
|
|
244
|
-
*/
|
|
245
|
-
deserializeRow(row: MongoDefussDocument): any;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Closes all MongoDB connections - useful for test cleanup
|
|
249
|
-
*/
|
|
250
|
-
declare function closeAllConnections(): Promise<void>;
|
|
251
|
-
declare function clearMongoConnections(): void;
|
|
252
|
-
|
|
253
|
-
export { type DbClientMap, type DbMap, DefussProvider, DefussRecord, LibsqlProvider, type LibsqlProviderOptions, MongoProvider, type MongoProviderOptions, PrimaryKeyValue, RecordValue, clearMongoConnections, closeAllConnections, connectToMongo, getCollectionByName, isConnected, isValidObjectId, parseMongoConnectionString, ping, toObjectId };
|
package/dist/server.d.mts
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { DefussProvider, DefussRecord, PrimaryKeyValue, RecordValue } from './index.mjs';
|
|
2
|
-
export { DefussTable } from './index.mjs';
|
|
3
|
-
import { Config, Client } from '@libsql/client';
|
|
4
|
-
import { MongoClient, Db, Document, Collection, ObjectId } from 'mongodb';
|
|
5
|
-
|
|
6
|
-
type LibsqlProviderOptions = Config;
|
|
7
|
-
/**
|
|
8
|
-
* LibsqlProvider implements DefussProvider using libsql for SQLite databases.
|
|
9
|
-
*/
|
|
10
|
-
declare class LibsqlProvider implements DefussProvider<Config> {
|
|
11
|
-
db: Client;
|
|
12
|
-
/**
|
|
13
|
-
* Connects to the SQLite database using libsql.
|
|
14
|
-
* @param config - The libsql connection configuration.
|
|
15
|
-
*/
|
|
16
|
-
connect(config: Config): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* Disconnects from the SQLite database.
|
|
19
|
-
*/
|
|
20
|
-
disconnect(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Checks if the provider is currently connected to the database.
|
|
23
|
-
* @returns True if connected, false otherwise.
|
|
24
|
-
*/
|
|
25
|
-
isConnected(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a table if it doesn't exist.
|
|
28
|
-
* Sets up the primary key and any initial structure needed.
|
|
29
|
-
* @param table - The name of the table.
|
|
30
|
-
*/
|
|
31
|
-
createTable(table: string): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Ensures all necessary columns exist in the table
|
|
34
|
-
* @param table - The name of the table
|
|
35
|
-
* @param record - DefussRecord containing fields to ensure
|
|
36
|
-
*/
|
|
37
|
-
private ensureColumnsExist;
|
|
38
|
-
/**
|
|
39
|
-
* Gets the SQLite data type for a JavaScript value
|
|
40
|
-
* @param value The JavaScript value to map to SQLite type
|
|
41
|
-
* @returns The SQLite type string
|
|
42
|
-
*/
|
|
43
|
-
private getSqliteType;
|
|
44
|
-
/**
|
|
45
|
-
* Retrieves existing columns in the specified table.
|
|
46
|
-
* @param table - The name of the table.
|
|
47
|
-
* @returns An array of column names.
|
|
48
|
-
*/
|
|
49
|
-
private getExistingColumns;
|
|
50
|
-
/**
|
|
51
|
-
* Converts a DefussRecord to SQLite values
|
|
52
|
-
* @param record The DefussRecord to convert
|
|
53
|
-
* @returns Object with column names and values for SQLite
|
|
54
|
-
*/
|
|
55
|
-
private toSqliteValues;
|
|
56
|
-
/**
|
|
57
|
-
* Convert JavaScript value to SQLite-compatible value
|
|
58
|
-
*/
|
|
59
|
-
private convertValueForSqlite;
|
|
60
|
-
/**
|
|
61
|
-
* Convert SQLite row to DefussRecord
|
|
62
|
-
*/
|
|
63
|
-
private fromSqliteRow;
|
|
64
|
-
/**
|
|
65
|
-
* Inserts a record into the table.
|
|
66
|
-
* @param table - The name of the table.
|
|
67
|
-
* @param record - The record to insert.
|
|
68
|
-
* @returns The primary key of the inserted record.
|
|
69
|
-
*/
|
|
70
|
-
insert<T extends DefussRecord>(table: string, record: T): Promise<PrimaryKeyValue>;
|
|
71
|
-
/**
|
|
72
|
-
* Finds records in the table based on query.
|
|
73
|
-
* @param table - The name of the table.
|
|
74
|
-
* @param query - Query criteria.
|
|
75
|
-
* @returns An array of matching records.
|
|
76
|
-
*/
|
|
77
|
-
find<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
78
|
-
/**
|
|
79
|
-
* Finds a single record in the table based on query.
|
|
80
|
-
* @param table - The name of the table.
|
|
81
|
-
* @param query - Query criteria.
|
|
82
|
-
* @returns The first matching record or null.
|
|
83
|
-
*/
|
|
84
|
-
findOne<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
85
|
-
/**
|
|
86
|
-
* Updates records in the table based on query.
|
|
87
|
-
* @param table - The name of the table.
|
|
88
|
-
* @param query - Query criteria.
|
|
89
|
-
* @param update - Fields to update.
|
|
90
|
-
*/
|
|
91
|
-
update<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>, update: Partial<T>): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Deletes records from the table based on query.
|
|
94
|
-
* @param table - The name of the table.
|
|
95
|
-
* @param query - Query criteria.
|
|
96
|
-
*/
|
|
97
|
-
delete(table: string, query: Partial<DefussRecord>): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Upserts a record into the table based on query.
|
|
100
|
-
* @param table - The name of the table.
|
|
101
|
-
* @param record - The record to upsert.
|
|
102
|
-
* @param query - Query criteria.
|
|
103
|
-
* @returns The primary key of the upserted record.
|
|
104
|
-
*/
|
|
105
|
-
upsert<T extends DefussRecord>(table: string, record: T, query: Partial<Record<string, RecordValue>>): Promise<PrimaryKeyValue>;
|
|
106
|
-
/**
|
|
107
|
-
* Ensures that the specified table exists.
|
|
108
|
-
* @param table - The name of the table.
|
|
109
|
-
*/
|
|
110
|
-
private ensureTableExists;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
interface MongoProviderOptions {
|
|
114
|
-
connectionString: string;
|
|
115
|
-
databaseName: string;
|
|
116
|
-
}
|
|
117
|
-
type DbClientMap = {
|
|
118
|
-
[clientKey: string]: MongoClient | null;
|
|
119
|
-
};
|
|
120
|
-
type DbMap = {
|
|
121
|
-
[dbName: string]: Db | null;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Parses a MongoDB connection string into its components
|
|
125
|
-
* @param connectionString - MongoDB connection string
|
|
126
|
-
* @returns Object containing databaseName and clientKey
|
|
127
|
-
*/
|
|
128
|
-
declare const parseMongoConnectionString: (connectionString: string) => {
|
|
129
|
-
databaseName: string;
|
|
130
|
-
clientKey: string;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Core connection function to be used by all parts of the system
|
|
134
|
-
* @param connectionString MongoDB connection string
|
|
135
|
-
* @returns Object containing the MongoClient and Db instances
|
|
136
|
-
*/
|
|
137
|
-
declare function connectToMongo(connectionString: string): Promise<{
|
|
138
|
-
client: MongoClient;
|
|
139
|
-
db: Db;
|
|
140
|
-
}>;
|
|
141
|
-
/** Returns true if both dbClient and database are initialized */
|
|
142
|
-
declare const isConnected: (connectionString: string) => boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Pings the MongoDB server to check connectivity
|
|
145
|
-
* @param connectionString MongoDB connection string
|
|
146
|
-
*/
|
|
147
|
-
declare const ping: (connectionString: string) => Promise<unknown>;
|
|
148
|
-
/**
|
|
149
|
-
* Gets a collection by name, connecting if necessary
|
|
150
|
-
*/
|
|
151
|
-
declare const getCollectionByName: <T extends Document>(collectionName: string, connectionString: string) => Promise<Collection<T>>;
|
|
152
|
-
declare function isValidObjectId(id: string): boolean;
|
|
153
|
-
declare const toObjectId: (id: string | ObjectId) => ObjectId;
|
|
154
|
-
interface MongoDefussDocument extends Document {
|
|
155
|
-
type?: "json" | "blob";
|
|
156
|
-
json?: string;
|
|
157
|
-
blob?: ArrayBuffer;
|
|
158
|
-
[key: string]: any;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* MongoProvider implements DefussProvider for MongoDB.
|
|
162
|
-
*/
|
|
163
|
-
declare class MongoProvider implements DefussProvider<MongoProviderOptions> {
|
|
164
|
-
client: MongoClient | null;
|
|
165
|
-
db: Db | null;
|
|
166
|
-
collections: Map<string, Collection<Document>>;
|
|
167
|
-
connectionString: string;
|
|
168
|
-
constructor(options: MongoProviderOptions);
|
|
169
|
-
/**
|
|
170
|
-
* Connects to MongoDB using the shared connection function.
|
|
171
|
-
*/
|
|
172
|
-
connect(options?: MongoProviderOptions): Promise<void>;
|
|
173
|
-
/**
|
|
174
|
-
* Disconnects from MongoDB.
|
|
175
|
-
*/
|
|
176
|
-
disconnect(): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Checks if the provider is currently connected to the database.
|
|
179
|
-
* @returns True if connected, false otherwise.
|
|
180
|
-
*/
|
|
181
|
-
isConnected(): boolean;
|
|
182
|
-
/**
|
|
183
|
-
* Creates a collection if it doesn't exist.
|
|
184
|
-
*/
|
|
185
|
-
createTable(table: string): Promise<void>;
|
|
186
|
-
/**
|
|
187
|
-
* Converts DefussRecord to MongoDB document
|
|
188
|
-
* @param record DefussRecord to convert
|
|
189
|
-
* @returns MongoDB document
|
|
190
|
-
*/
|
|
191
|
-
private toMongoDoc;
|
|
192
|
-
/**
|
|
193
|
-
* Converts MongoDB document to DefussRecord
|
|
194
|
-
* @param doc MongoDB document to convert
|
|
195
|
-
* @returns DefussRecord
|
|
196
|
-
*/
|
|
197
|
-
private fromMongoDoc;
|
|
198
|
-
/**
|
|
199
|
-
* Inserts a new document into the collection.
|
|
200
|
-
* @param table - The name of the collection.
|
|
201
|
-
* @param record - The record to insert.
|
|
202
|
-
* @returns The primary key of the inserted document.
|
|
203
|
-
*/
|
|
204
|
-
insert<T extends DefussRecord>(table: string, record: T): Promise<PrimaryKeyValue>;
|
|
205
|
-
/**
|
|
206
|
-
* Finds documents in the collection based on query.
|
|
207
|
-
* @param table - The name of the collection.
|
|
208
|
-
* @param query - Query criteria.
|
|
209
|
-
* @returns An array of matching documents.
|
|
210
|
-
*/
|
|
211
|
-
find<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
212
|
-
/**
|
|
213
|
-
* Finds a single document in the collection based on query.
|
|
214
|
-
* @param table - The name of the collection.
|
|
215
|
-
* @param query - Query criteria.
|
|
216
|
-
* @returns The first matching document or null.
|
|
217
|
-
*/
|
|
218
|
-
findOne<T extends DefussRecord>(table: string, query: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
219
|
-
/**
|
|
220
|
-
* Updates documents in the collection based on query.
|
|
221
|
-
* @param table - The name of the collection.
|
|
222
|
-
* @param query - Query criteria.
|
|
223
|
-
* @param update - Fields to update.
|
|
224
|
-
*/
|
|
225
|
-
update<T extends DefussRecord>(table: string, query: Partial<T>, update: Partial<T>): Promise<void>;
|
|
226
|
-
/**
|
|
227
|
-
* Deletes documents from the collection based on query.
|
|
228
|
-
* @param table - The name of the collection.
|
|
229
|
-
* @param query - Query criteria.
|
|
230
|
-
*/
|
|
231
|
-
delete(table: string, query: Partial<DefussRecord>): Promise<void>;
|
|
232
|
-
/**
|
|
233
|
-
* Upserts a document into the collection based on query.
|
|
234
|
-
* @param table - The name of the collection.
|
|
235
|
-
* @param record - The record to upsert.
|
|
236
|
-
* @param query - Query criteria.
|
|
237
|
-
* @returns The primary key of the upserted document.
|
|
238
|
-
*/
|
|
239
|
-
upsert<T extends DefussRecord>(table: string, record: T, query: Partial<Record<string, RecordValue>>): Promise<PrimaryKeyValue>;
|
|
240
|
-
/**
|
|
241
|
-
* Deserializes a MongoDB document into a JavaScript object.
|
|
242
|
-
* @param row - The document to deserialize.
|
|
243
|
-
* @returns The deserialized JavaScript object.
|
|
244
|
-
*/
|
|
245
|
-
deserializeRow(row: MongoDefussDocument): any;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Closes all MongoDB connections - useful for test cleanup
|
|
249
|
-
*/
|
|
250
|
-
declare function closeAllConnections(): Promise<void>;
|
|
251
|
-
declare function clearMongoConnections(): void;
|
|
252
|
-
|
|
253
|
-
export { type DbClientMap, type DbMap, DefussProvider, DefussRecord, LibsqlProvider, type LibsqlProviderOptions, MongoProvider, type MongoProviderOptions, PrimaryKeyValue, RecordValue, clearMongoConnections, closeAllConnections, connectToMongo, getCollectionByName, isConnected, isValidObjectId, parseMongoConnectionString, ping, toObjectId };
|