fluxor-cloud-db 1.0.0
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/.github/workflows/npm-publish.yml +34 -0
- package/README.md +296 -0
- package/dist/index.d.mts +347 -0
- package/dist/index.d.ts +347 -0
- package/dist/index.js +1844 -0
- package/dist/index.mjs +1811 -0
- package/jest.config.ts +12 -0
- package/package.json +33 -0
- package/src/contracts/database-adapter.ts +161 -0
- package/src/dynamo/dynamo.ts +859 -0
- package/src/dynamo/dynamo.types.ts +8 -0
- package/src/fluentapi.ts +71 -0
- package/src/index.ts +39 -0
- package/src/mongo/mongo.ts +690 -0
- package/src/types/error.ts +13 -0
- package/src/types/query.ts +53 -0
- package/tests/dynamodb.test.ts +547 -0
- package/tests/mongodb.test.ts +486 -0
- package/tsconfig.json +23 -0
package/jest.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config } from '@jest/types';
|
|
2
|
+
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
preset: 'ts-jest',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
roots: ['<rootDir>/tests'],
|
|
7
|
+
moduleFileExtensions: ['ts', 'js'],
|
|
8
|
+
testMatch: ['<rootDir>/tests/**/*.test.ts'],
|
|
9
|
+
verbose: true
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default config;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fluxor-cloud-db",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Cloud-agnostic event framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/jest": "^30.0.0",
|
|
10
|
+
"cross-env": "^10.1.0",
|
|
11
|
+
"jest": "^30.3.0",
|
|
12
|
+
"ts-jest": "^29.4.6",
|
|
13
|
+
"ts-node": "^10.9.2",
|
|
14
|
+
"tsup": "^8.5.1",
|
|
15
|
+
"typescript": "^5.9.3"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
|
19
|
+
"test:watch": "jest --watch",
|
|
20
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --out-dir dist --clean"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"new": "bin/create-app/create-app.js"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@aws-sdk/client-dynamodb": "^3.1012.0",
|
|
27
|
+
"@aws-sdk/lib-dynamodb": "^3.1012.0",
|
|
28
|
+
"@types/mongodb": "^4.0.6",
|
|
29
|
+
"fluxor-cloud": "^1.0.61",
|
|
30
|
+
"mongodb": "^7.1.0",
|
|
31
|
+
"reflect-metadata": "^0.2.2"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { WhereClause, QueryOptions, PaginatedResult, BatchResult, UpdateClause } from "../types/query";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unified database adapter interface
|
|
5
|
+
* Supports DynamoDB, MongoDB, SQL databases, and other data stores
|
|
6
|
+
*/
|
|
7
|
+
export interface DatabaseAdapter {
|
|
8
|
+
/**
|
|
9
|
+
* Establish connection to the database
|
|
10
|
+
* Implementation varies by backend (DynamoDB, MongoDB, etc.)
|
|
11
|
+
*/
|
|
12
|
+
connect(): Promise<void>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Close connection to the database
|
|
16
|
+
*/
|
|
17
|
+
disconnect(): Promise<void>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if adapter is connected
|
|
21
|
+
*/
|
|
22
|
+
isConnected(): boolean;
|
|
23
|
+
|
|
24
|
+
// ============ SELECT Operations ============
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Fetch a single record matching the where conditions
|
|
28
|
+
* @param tableName - Table/collection name
|
|
29
|
+
* @param where - Query conditions
|
|
30
|
+
* @param options - Query options (projection, consistency, etc.)
|
|
31
|
+
* @returns Single record or null if not found
|
|
32
|
+
*/
|
|
33
|
+
selectOne<T = Record<string, any>>(
|
|
34
|
+
tableName: string,
|
|
35
|
+
where: WhereClause,
|
|
36
|
+
options?: QueryOptions
|
|
37
|
+
): Promise<T | null>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Fetch multiple records matching the where conditions
|
|
41
|
+
* @param tableName - Table/collection name
|
|
42
|
+
* @param where - Query conditions
|
|
43
|
+
* @param options - Query options (limit, offset, orderBy, projection, etc.)
|
|
44
|
+
* @returns Array of matching records with pagination info
|
|
45
|
+
*/
|
|
46
|
+
selectMany<T = Record<string, any>>(
|
|
47
|
+
tableName: string,
|
|
48
|
+
where?: WhereClause,
|
|
49
|
+
options?: QueryOptions
|
|
50
|
+
): Promise<PaginatedResult<T>>;
|
|
51
|
+
|
|
52
|
+
// ============ CREATE Operations ============
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Insert a single record
|
|
56
|
+
* @param tableName - Table/collection name
|
|
57
|
+
* @param data - Record to insert
|
|
58
|
+
* @returns Created record with any server-generated fields
|
|
59
|
+
*/
|
|
60
|
+
createOne<T = Record<string, any>>(
|
|
61
|
+
tableName: string,
|
|
62
|
+
data: Record<string, any>
|
|
63
|
+
): Promise<T>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Insert multiple records in a batch operation
|
|
67
|
+
* @param tableName - Table/collection name
|
|
68
|
+
* @param data - Array of records to insert
|
|
69
|
+
* @param options - Batch options (e.g., stopOnError)
|
|
70
|
+
* @returns Batch operation result with success/failure counts
|
|
71
|
+
*/
|
|
72
|
+
createMany<T = Record<string, any>>(
|
|
73
|
+
tableName: string,
|
|
74
|
+
data: Record<string, any>[],
|
|
75
|
+
options?: { stopOnError?: boolean }
|
|
76
|
+
): Promise<{ items: T[]; result: BatchResult }>;
|
|
77
|
+
|
|
78
|
+
// ============ UPDATE Operations ============
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Update a single record matching the where conditions
|
|
82
|
+
* @param tableName - Table/collection name
|
|
83
|
+
* @param update - Fields to update
|
|
84
|
+
* @param where - Query conditions to identify record
|
|
85
|
+
* @returns Updated record
|
|
86
|
+
*/
|
|
87
|
+
updateOne<T = Record<string, any>>(
|
|
88
|
+
tableName: string,
|
|
89
|
+
update: UpdateClause,
|
|
90
|
+
where: WhereClause
|
|
91
|
+
): Promise<T>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Update multiple records matching the where conditions
|
|
95
|
+
* @param tableName - Table/collection name
|
|
96
|
+
* @param update - Fields to update
|
|
97
|
+
* @param where - Query conditions to identify records
|
|
98
|
+
* @param options - Update options (e.g., limit)
|
|
99
|
+
* @returns Batch operation result with updated count
|
|
100
|
+
*/
|
|
101
|
+
updateMany<T = Record<string, any>>(
|
|
102
|
+
tableName: string,
|
|
103
|
+
update: UpdateClause,
|
|
104
|
+
where?: WhereClause,
|
|
105
|
+
options?: { limit?: number }
|
|
106
|
+
): Promise<{ items: T[]; result: BatchResult }>;
|
|
107
|
+
|
|
108
|
+
// ============ DELETE Operations ============
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Delete a single record matching the where conditions
|
|
112
|
+
* @param tableName - Table/collection name
|
|
113
|
+
* @param where - Query conditions to identify record
|
|
114
|
+
* @returns Deleted record or confirmation
|
|
115
|
+
*/
|
|
116
|
+
deleteOne(
|
|
117
|
+
tableName: string,
|
|
118
|
+
where: WhereClause
|
|
119
|
+
): Promise<{ success: boolean; deletedCount: number }>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Delete multiple records matching the where conditions
|
|
123
|
+
* @param tableName - Table/collection name
|
|
124
|
+
* @param where - Query conditions to identify records
|
|
125
|
+
* @param options - Delete options (e.g., limit)
|
|
126
|
+
* @returns Batch operation result with deleted count
|
|
127
|
+
*/
|
|
128
|
+
deleteMany(
|
|
129
|
+
tableName: string,
|
|
130
|
+
where?: WhereClause,
|
|
131
|
+
options?: { limit?: number }
|
|
132
|
+
): Promise<{ success: boolean; deletedCount: number; result: BatchResult }>;
|
|
133
|
+
|
|
134
|
+
// ============ Advanced Operations ============
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Execute a raw query specific to the database backend
|
|
138
|
+
* Use sparingly for complex queries not supported by the adapter
|
|
139
|
+
*/
|
|
140
|
+
executeRaw<T = any>(query: string, params?: Record<string, any>): Promise<T>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Start a transaction (if supported by the backend)
|
|
144
|
+
*/
|
|
145
|
+
beginTransaction?(): Promise<void>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Commit an active transaction
|
|
149
|
+
*/
|
|
150
|
+
commitTransaction?(): Promise<void>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Rollback an active transaction
|
|
154
|
+
*/
|
|
155
|
+
rollbackTransaction?(): Promise<void>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Check the health/status of the database connection
|
|
159
|
+
*/
|
|
160
|
+
healthCheck(): Promise<boolean>;
|
|
161
|
+
}
|