defuss-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/LICENSE +21 -0
- package/README.md +152 -0
- package/dist/client.cjs +281 -0
- package/dist/client.d.cts +87 -0
- package/dist/client.d.mts +87 -0
- package/dist/client.d.ts +87 -0
- package/dist/client.mjs +278 -0
- package/dist/index.cjs +72 -0
- package/dist/index.d.cts +122 -0
- package/dist/index.d.mts +122 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.mjs +70 -0
- package/dist/server.cjs +777 -0
- package/dist/server.d.cts +243 -0
- package/dist/server.d.mts +243 -0
- package/dist/server.d.ts +243 -0
- package/dist/server.mjs +764 -0
- package/package.json +80 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
type RecordValue = string | bigint | number | boolean | null | ArrayBuffer | Blob;
|
|
2
|
+
type PrimaryKeyValue = bigint | number | string;
|
|
3
|
+
interface DefussRecord {
|
|
4
|
+
pk?: PrimaryKeyValue;
|
|
5
|
+
[key: string]: RecordValue | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Generic provider interface for Defuss microdb.
|
|
9
|
+
*/
|
|
10
|
+
interface DefussProvider<O> {
|
|
11
|
+
/**
|
|
12
|
+
* Connects to the database using the provided connection string.
|
|
13
|
+
* @param connectionString - The database connection string.
|
|
14
|
+
*/
|
|
15
|
+
connect(options: O): void;
|
|
16
|
+
/**
|
|
17
|
+
* Disconnects from the database.
|
|
18
|
+
*/
|
|
19
|
+
disconnect(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a table if it doesn't exist.
|
|
22
|
+
* @param table - The name of the table.
|
|
23
|
+
*/
|
|
24
|
+
createTable(table: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Inserts an item into the specified table with dynamic indices.
|
|
27
|
+
* @param table - The name of the table.
|
|
28
|
+
* @param value - The item to insert.
|
|
29
|
+
* @param indexData - A JSON object representing dynamic indices.
|
|
30
|
+
* @returns The primary key of the inserted row.
|
|
31
|
+
*/
|
|
32
|
+
insert<T extends DefussRecord>(table: string, value: T, indexData: Record<string, RecordValue>): Promise<PrimaryKeyValue>;
|
|
33
|
+
/**
|
|
34
|
+
* Finds items based on provided index data.
|
|
35
|
+
* @param table - The name of the table.
|
|
36
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
37
|
+
* @returns An array of matching items.
|
|
38
|
+
*/
|
|
39
|
+
find<T extends DefussRecord>(table: string, indexData: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Finds a single item based on provided index data.
|
|
42
|
+
* @param table - The name of the table.
|
|
43
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
44
|
+
* @returns The first matching item or null if not found.
|
|
45
|
+
*/
|
|
46
|
+
findOne<T extends DefussRecord>(table: string, indexData: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Updates items based on provided index data.
|
|
49
|
+
* @param table - The name of the table.
|
|
50
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
51
|
+
* @param dataToUpdate - A JSON object representing fields to update.
|
|
52
|
+
*/
|
|
53
|
+
update<T extends DefussRecord>(table: string, indexData: Partial<Record<string, RecordValue>>, dataToUpdate: Partial<T>): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Deletes items based on provided index data.
|
|
56
|
+
* @param table - The name of the table.
|
|
57
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
58
|
+
*/
|
|
59
|
+
delete(table: string, indexData: Partial<Record<string, RecordValue>>): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Upserts an item into the specified table based on index data.
|
|
62
|
+
* @param table - The name of the table.
|
|
63
|
+
* @param value - The item to insert or update.
|
|
64
|
+
* @param indexData - A JSON object representing dynamic indices used to identify the record.
|
|
65
|
+
* @returns The primary key of the upserted row.
|
|
66
|
+
*/
|
|
67
|
+
upsert<T extends DefussRecord>(table: string, value: T, indexData: Record<string, RecordValue>): Promise<PrimaryKeyValue>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare class DefussTable<T extends DefussRecord, O> {
|
|
71
|
+
provider: DefussProvider<O>;
|
|
72
|
+
tableName: string;
|
|
73
|
+
/**
|
|
74
|
+
* Initializes the DefussTable with the specified table name and provider.
|
|
75
|
+
* @param provider - The DefussProvider instance.
|
|
76
|
+
* @param tableName - The name of the table.
|
|
77
|
+
*/
|
|
78
|
+
constructor(provider: DefussProvider<O>, tableName: string);
|
|
79
|
+
/**
|
|
80
|
+
* Creates the table if it doesn't exist.
|
|
81
|
+
*/
|
|
82
|
+
init(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Inserts an item into the table with dynamic indices.
|
|
85
|
+
* @param value - The item to insert.
|
|
86
|
+
* @param indexData - A JSON object representing dynamic indices.
|
|
87
|
+
* @returns The primary key of the inserted row.
|
|
88
|
+
*/
|
|
89
|
+
insert(value: T, indexData: Record<string, RecordValue>): Promise<PrimaryKeyValue>;
|
|
90
|
+
/**
|
|
91
|
+
* Finds items based on provided index data.
|
|
92
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
93
|
+
* @returns An array of matching items.
|
|
94
|
+
*/
|
|
95
|
+
find(indexData?: Partial<Record<string, RecordValue>>): Promise<T[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Finds a single item based on provided index data.
|
|
98
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
99
|
+
* @returns The first matching item or null if not found.
|
|
100
|
+
*/
|
|
101
|
+
findOne(indexData?: Partial<Record<string, RecordValue>>): Promise<T | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Updates items based on provided index data.
|
|
104
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
105
|
+
* @param dataToUpdate - A JSON object representing fields to update.
|
|
106
|
+
*/
|
|
107
|
+
update(indexData: Partial<Record<string, RecordValue>>, dataToUpdate: Partial<T>): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Deletes items based on provided index data.
|
|
110
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
111
|
+
*/
|
|
112
|
+
delete(indexData: Partial<Record<string, RecordValue>>): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Upserts an item into the table based on index data.
|
|
115
|
+
* @param value - The item to insert or update.
|
|
116
|
+
* @param indexData - A JSON object representing dynamic indices used to identify the record.
|
|
117
|
+
* @returns The primary key of the upserted row.
|
|
118
|
+
*/
|
|
119
|
+
upsert(value: T, indexData: Record<string, RecordValue>): Promise<PrimaryKeyValue>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { type DefussProvider, type DefussRecord, DefussTable, type PrimaryKeyValue, type RecordValue };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
class DefussTable {
|
|
2
|
+
provider;
|
|
3
|
+
tableName;
|
|
4
|
+
/**
|
|
5
|
+
* Initializes the DefussTable with the specified table name and provider.
|
|
6
|
+
* @param provider - The DefussProvider instance.
|
|
7
|
+
* @param tableName - The name of the table.
|
|
8
|
+
*/
|
|
9
|
+
constructor(provider, tableName) {
|
|
10
|
+
this.provider = provider;
|
|
11
|
+
this.tableName = tableName;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates the table if it doesn't exist.
|
|
15
|
+
*/
|
|
16
|
+
async init() {
|
|
17
|
+
await this.provider.createTable(this.tableName);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Inserts an item into the table with dynamic indices.
|
|
21
|
+
* @param value - The item to insert.
|
|
22
|
+
* @param indexData - A JSON object representing dynamic indices.
|
|
23
|
+
* @returns The primary key of the inserted row.
|
|
24
|
+
*/
|
|
25
|
+
async insert(value, indexData) {
|
|
26
|
+
return this.provider.insert(this.tableName, value, indexData);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Finds items based on provided index data.
|
|
30
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
31
|
+
* @returns An array of matching items.
|
|
32
|
+
*/
|
|
33
|
+
async find(indexData = {}) {
|
|
34
|
+
return this.provider.find(this.tableName, indexData);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Finds a single item based on provided index data.
|
|
38
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
39
|
+
* @returns The first matching item or null if not found.
|
|
40
|
+
*/
|
|
41
|
+
async findOne(indexData = {}) {
|
|
42
|
+
return this.provider.findOne(this.tableName, indexData);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Updates items based on provided index data.
|
|
46
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
47
|
+
* @param dataToUpdate - A JSON object representing fields to update.
|
|
48
|
+
*/
|
|
49
|
+
async update(indexData, dataToUpdate) {
|
|
50
|
+
await this.provider.update(this.tableName, indexData, dataToUpdate);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Deletes items based on provided index data.
|
|
54
|
+
* @param indexData - A JSON object representing dynamic indices. All fields are optional.
|
|
55
|
+
*/
|
|
56
|
+
async delete(indexData) {
|
|
57
|
+
await this.provider.delete(this.tableName, indexData);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Upserts an item into the table based on index data.
|
|
61
|
+
* @param value - The item to insert or update.
|
|
62
|
+
* @param indexData - A JSON object representing dynamic indices used to identify the record.
|
|
63
|
+
* @returns The primary key of the upserted row.
|
|
64
|
+
*/
|
|
65
|
+
async upsert(value, indexData) {
|
|
66
|
+
return this.provider.upsert(this.tableName, value, indexData);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { DefussTable };
|