@frogfish/k2db 1.0.1 → 1.0.3
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/data.d.ts +92 -0
- package/data.js +118 -0
- package/db.d.ts +1 -1
- package/db.js +1 -1
- package/package.json +1 -1
- package/config.d.ts +0 -0
- package/config.js +0 -1
package/data.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { DB, BaseDocument } from "./db";
|
|
2
|
+
export declare class Data {
|
|
3
|
+
private db;
|
|
4
|
+
private owner;
|
|
5
|
+
constructor(db: DB, owner: string);
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves a single document by UUID.
|
|
8
|
+
* @param collectionName - Name of the collection.
|
|
9
|
+
* @param uuid - UUID of the document.
|
|
10
|
+
*/
|
|
11
|
+
get(collectionName: string, uuid: string): Promise<BaseDocument>;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves a single document matching the criteria.
|
|
14
|
+
* @param collectionName - Name of the collection.
|
|
15
|
+
* @param criteria - Search criteria.
|
|
16
|
+
* @param fields - Optional fields to include.
|
|
17
|
+
*/
|
|
18
|
+
findOne(collectionName: string, criteria: any, fields?: Array<string>): Promise<BaseDocument | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Finds documents based on filter with optional parameters and pagination.
|
|
21
|
+
*/
|
|
22
|
+
find(collectionName: string, filter: any, params?: any, skip?: number, limit?: number): Promise<BaseDocument[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Aggregates documents based on criteria with pagination support.
|
|
25
|
+
*/
|
|
26
|
+
aggregate(collectionName: string, criteria: any[], skip?: number, limit?: number): Promise<BaseDocument[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new document in the collection.
|
|
29
|
+
*/
|
|
30
|
+
create(collectionName: string, data: Partial<BaseDocument>): Promise<{
|
|
31
|
+
id: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Updates multiple documents based on criteria.
|
|
35
|
+
*/
|
|
36
|
+
updateAll(collectionName: string, criteria: any, values: Partial<BaseDocument>, replace?: boolean): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Updates a single document by UUID.
|
|
39
|
+
*/
|
|
40
|
+
update(collectionName: string, id: string, data: Partial<BaseDocument>, replace?: boolean, objectTypeName?: string): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Removes (soft deletes) multiple documents based on criteria.
|
|
43
|
+
*/
|
|
44
|
+
deleteAll(collectionName: string, criteria: any): Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Removes (soft deletes) a single document by UUID.
|
|
47
|
+
*/
|
|
48
|
+
delete(collectionName: string, id: string): Promise<{
|
|
49
|
+
id: string;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Permanently deletes a document that has been soft-deleted.
|
|
53
|
+
*/
|
|
54
|
+
purge(collectionName: string, id: string): Promise<{
|
|
55
|
+
id: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Restores a soft-deleted document.
|
|
59
|
+
*/
|
|
60
|
+
restore(collectionName: string, criteria: any): Promise<{
|
|
61
|
+
status: string;
|
|
62
|
+
modified: number;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Counts documents based on criteria.
|
|
66
|
+
*/
|
|
67
|
+
count(collectionName: string, criteria: any): Promise<{
|
|
68
|
+
count: number;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Drops an entire collection.
|
|
72
|
+
*/
|
|
73
|
+
drop(collectionName: string): Promise<{
|
|
74
|
+
status: string;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Executes a transaction with the provided operations.
|
|
78
|
+
*/
|
|
79
|
+
executeTransaction(operations: (session: any) => Promise<void>): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates an index on the specified collection.
|
|
82
|
+
*/
|
|
83
|
+
createIndex(collectionName: string, indexSpec: any, options?: any): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Drops the entire database.
|
|
86
|
+
*/
|
|
87
|
+
dropDatabase(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Checks the health of the database connection.
|
|
90
|
+
*/
|
|
91
|
+
isHealthy(): Promise<boolean>;
|
|
92
|
+
}
|
package/data.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/Data.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Data = void 0;
|
|
5
|
+
class Data {
|
|
6
|
+
constructor(db, owner) {
|
|
7
|
+
this.db = db;
|
|
8
|
+
this.owner = owner;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves a single document by UUID.
|
|
12
|
+
* @param collectionName - Name of the collection.
|
|
13
|
+
* @param uuid - UUID of the document.
|
|
14
|
+
*/
|
|
15
|
+
async get(collectionName, uuid) {
|
|
16
|
+
return this.db.get(collectionName, uuid);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves a single document matching the criteria.
|
|
20
|
+
* @param collectionName - Name of the collection.
|
|
21
|
+
* @param criteria - Search criteria.
|
|
22
|
+
* @param fields - Optional fields to include.
|
|
23
|
+
*/
|
|
24
|
+
async findOne(collectionName, criteria, fields) {
|
|
25
|
+
return this.db.findOne(collectionName, criteria, fields);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Finds documents based on filter with optional parameters and pagination.
|
|
29
|
+
*/
|
|
30
|
+
async find(collectionName, filter, params, skip, limit) {
|
|
31
|
+
return this.db.find(collectionName, filter, params, skip, limit);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Aggregates documents based on criteria with pagination support.
|
|
35
|
+
*/
|
|
36
|
+
async aggregate(collectionName, criteria, skip, limit) {
|
|
37
|
+
return this.db.aggregate(collectionName, criteria, skip, limit);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new document in the collection.
|
|
41
|
+
*/
|
|
42
|
+
async create(collectionName, data) {
|
|
43
|
+
return this.db.create(collectionName, this.owner, data);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Updates multiple documents based on criteria.
|
|
47
|
+
*/
|
|
48
|
+
async updateAll(collectionName, criteria, values, replace) {
|
|
49
|
+
return this.db.updateAll(collectionName, criteria, values, replace);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Updates a single document by UUID.
|
|
53
|
+
*/
|
|
54
|
+
async update(collectionName, id, data, replace, objectTypeName) {
|
|
55
|
+
return this.db.update(collectionName, id, data, replace, objectTypeName);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Removes (soft deletes) multiple documents based on criteria.
|
|
59
|
+
*/
|
|
60
|
+
async deleteAll(collectionName, criteria) {
|
|
61
|
+
return this.db.deleteAll(collectionName, criteria);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Removes (soft deletes) a single document by UUID.
|
|
65
|
+
*/
|
|
66
|
+
async delete(collectionName, id) {
|
|
67
|
+
return this.db.delete(collectionName, id);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Permanently deletes a document that has been soft-deleted.
|
|
71
|
+
*/
|
|
72
|
+
async purge(collectionName, id) {
|
|
73
|
+
return this.db.purge(collectionName, id);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Restores a soft-deleted document.
|
|
77
|
+
*/
|
|
78
|
+
async restore(collectionName, criteria) {
|
|
79
|
+
return this.db.restore(collectionName, criteria);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Counts documents based on criteria.
|
|
83
|
+
*/
|
|
84
|
+
async count(collectionName, criteria) {
|
|
85
|
+
return this.db.count(collectionName, criteria);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Drops an entire collection.
|
|
89
|
+
*/
|
|
90
|
+
async drop(collectionName) {
|
|
91
|
+
return this.db.drop(collectionName);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Executes a transaction with the provided operations.
|
|
95
|
+
*/
|
|
96
|
+
async executeTransaction(operations) {
|
|
97
|
+
return this.db.executeTransaction(operations);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates an index on the specified collection.
|
|
101
|
+
*/
|
|
102
|
+
async createIndex(collectionName, indexSpec, options) {
|
|
103
|
+
return this.db.createIndex(collectionName, indexSpec, options);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Drops the entire database.
|
|
107
|
+
*/
|
|
108
|
+
async dropDatabase() {
|
|
109
|
+
return this.db.dropDatabase();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Checks the health of the database connection.
|
|
113
|
+
*/
|
|
114
|
+
async isHealthy() {
|
|
115
|
+
return this.db.isHealthy();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.Data = Data;
|
package/db.d.ts
CHANGED
|
@@ -167,7 +167,7 @@ export declare class DB {
|
|
|
167
167
|
* @param collectionName - The name of the collection to validate.
|
|
168
168
|
* @throws {K2Error} - If the collection name is invalid.
|
|
169
169
|
*/
|
|
170
|
-
|
|
170
|
+
validateCollectionName(collectionName: string): void;
|
|
171
171
|
/**
|
|
172
172
|
* Optional: Checks the health of the database connection.
|
|
173
173
|
*/
|
package/db.js
CHANGED
package/package.json
CHANGED
package/config.d.ts
DELETED
|
File without changes
|
package/config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|