mongolite-ts 0.6.2 → 0.8.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/README.md +97 -586
- package/dist/adapters/browser.d.ts +97 -0
- package/dist/adapters/browser.js +103 -0
- package/dist/adapters/browser.js.map +1 -0
- package/dist/adapters/cloudflare.d.ts +106 -0
- package/dist/adapters/cloudflare.js +94 -0
- package/dist/adapters/cloudflare.js.map +1 -0
- package/dist/changeStream.d.ts +2 -2
- package/dist/changeStream.js.map +1 -1
- package/dist/cloudflare.d.ts +39 -0
- package/dist/cloudflare.js +39 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/collection.d.ts +93 -6
- package/dist/collection.js +796 -6
- package/dist/collection.js.map +1 -1
- package/dist/cursors/findCursor.d.ts +19 -4
- package/dist/cursors/findCursor.js +136 -2
- package/dist/cursors/findCursor.js.map +1 -1
- package/dist/db.d.ts +16 -1
- package/dist/db.js +26 -0
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +17 -38
- package/dist/index.js +26 -46
- package/dist/index.js.map +1 -1
- package/dist/mongo-client.d.ts +56 -0
- package/dist/mongo-client.js +55 -0
- package/dist/mongo-client.js.map +1 -0
- package/dist/types.d.ts +109 -0
- package/package.json +17 -6
- package/dist/database-manager.d.ts +0 -1
- package/dist/database-manager.js +0 -2
- package/dist/database-manager.js.map +0 -1
- package/dist/document-utils.d.ts +0 -34
- package/dist/document-utils.js +0 -101
- package/dist/document-utils.js.map +0 -1
- package/dist/find-cursor.d.ts +0 -51
- package/dist/find-cursor.js +0 -204
- package/dist/find-cursor.js.map +0 -1
- package/dist/plugins/mongodbSync.d.ts +0 -128
- package/dist/plugins/mongodbSync.js +0 -339
- package/dist/plugins/mongodbSync.js.map +0 -1
- package/dist/query-builder.d.ts +0 -18
- package/dist/query-builder.js +0 -358
- package/dist/query-builder.js.map +0 -1
- package/dist/update-operations.d.ts +0 -17
- package/dist/update-operations.js +0 -147
- package/dist/update-operations.js.map +0 -1
package/dist/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAuBtC;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAQnB;;;;OAIG;IACH,YAAY,eAA0C;QAZ9C,OAAE,GAA6B,IAAI,CAAC;QAKpC,gBAAW,GAAyB,IAAI,CAAC;QAQ/C,IAAI,OAAO,eAAe,KAAK,QAAQ,EAAE,CAAC;YACxC,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC;YAChC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;YACzC,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC,OAAO,IAAI,KAAK,CAAC;YAChD,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,QAAQ,IAAI,KAAK,CAAC;YAClD,IAAI,CAAC,GAAG,GAAG,eAAe,CAAC,GAAG,IAAI,IAAI,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QACD,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,kFAAkF;YAClF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,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import {
|
|
2
|
-
import {
|
|
3
|
-
import { DocumentWithId } from './types.js';
|
|
1
|
+
import { IDatabaseAdapter, MongoLiteOptions as DBMongoLiteOptions } from './db.js';
|
|
2
|
+
import { MongoLite as MongoLiteBase, MongoLiteBaseOptions } from './mongo-client.js';
|
|
4
3
|
export { MongoLiteCollection } from './collection.js';
|
|
5
4
|
export * from './types.js';
|
|
6
5
|
export { ChangeStream } from './changeStream.js';
|
|
7
6
|
export type { ChangeStreamDocument, ChangeStreamOptions, ChangeOperationType, } from './changeStream.js';
|
|
7
|
+
export type { IDatabaseAdapter } from './db.js';
|
|
8
|
+
export { CloudflareDurableObjectAdapter, } from './adapters/cloudflare.js';
|
|
9
|
+
export type { SqlStorage, SqlStorageCursor, SqlStorageValue, } from './adapters/cloudflare.js';
|
|
10
|
+
export { BrowserSqliteAdapter } from './adapters/browser.js';
|
|
11
|
+
export type { SqlJsDatabase, SqlJsStatement } from './adapters/browser.js';
|
|
8
12
|
export interface MongoLiteClientOptions extends DBMongoLiteOptions {
|
|
9
13
|
}
|
|
10
|
-
type MongoLiteOptions = {
|
|
11
|
-
verbose?: boolean;
|
|
12
|
-
};
|
|
13
14
|
/**
|
|
14
15
|
* MongoLite class is the main entry point for interacting with the SQLite-backed database.
|
|
16
|
+
*
|
|
17
|
+
* You can construct it with:
|
|
18
|
+
* - A file path string — uses the built-in `better-sqlite3` adapter.
|
|
19
|
+
* - A `MongoLiteClientOptions` object — uses the built-in adapter with options.
|
|
20
|
+
* - An `IDatabaseAdapter` instance — use a custom adapter such as
|
|
21
|
+
* `CloudflareDurableObjectAdapter` for Cloudflare Durable Objects.
|
|
15
22
|
*/
|
|
16
|
-
export declare class MongoLite {
|
|
17
|
-
private db;
|
|
18
|
-
private options;
|
|
23
|
+
export declare class MongoLite extends MongoLiteBase {
|
|
19
24
|
/**
|
|
20
25
|
* Creates a new MongoLite client instance.
|
|
21
|
-
* @param dbPathOrOptions Path to the SQLite database file
|
|
26
|
+
* @param dbPathOrOptions Path to the SQLite database file, an options object,
|
|
27
|
+
* or an `IDatabaseAdapter` for custom backends.
|
|
22
28
|
*/
|
|
23
|
-
constructor(dbPathOrOptions: string | MongoLiteClientOptions, options?:
|
|
24
|
-
/**
|
|
25
|
-
* Connects to the SQLite database.
|
|
26
|
-
* @returns {Promise<void>} A promise that resolves when connected.
|
|
27
|
-
*/
|
|
28
|
-
connect(): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Get the underlying SQLiteDB instance for advanced operations or testing.
|
|
31
|
-
* @returns {SQLiteDB} The SQLiteDB instance.
|
|
32
|
-
*/
|
|
33
|
-
get database(): SQLiteDB;
|
|
34
|
-
/**
|
|
35
|
-
* Closes the database connection.
|
|
36
|
-
*/
|
|
37
|
-
close(): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Lists all collections (tables) in the database.
|
|
40
|
-
* @returns An object with a toArray method that resolves to an array of collection names.
|
|
41
|
-
*/
|
|
42
|
-
listCollections(): {
|
|
43
|
-
toArray: () => Promise<string[]>;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Gets a collection (table) in the database.
|
|
47
|
-
* @param name The name of the collection.
|
|
48
|
-
* @returns A MongoLiteCollection instance.
|
|
49
|
-
*/
|
|
50
|
-
collection<T extends DocumentWithId = DocumentWithId>(name: string): MongoLiteCollection<T>;
|
|
29
|
+
constructor(dbPathOrOptions: string | MongoLiteClientOptions | IDatabaseAdapter, options?: MongoLiteBaseOptions);
|
|
51
30
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,40 @@
|
|
|
1
1
|
import { SQLiteDB } from './db.js';
|
|
2
|
-
import {
|
|
2
|
+
import { MongoLite as MongoLiteBase } from './mongo-client.js';
|
|
3
3
|
export { MongoLiteCollection } from './collection.js';
|
|
4
4
|
export * from './types.js';
|
|
5
5
|
export { ChangeStream } from './changeStream.js';
|
|
6
|
+
export { CloudflareDurableObjectAdapter, } from './adapters/cloudflare.js';
|
|
7
|
+
export { BrowserSqliteAdapter } from './adapters/browser.js';
|
|
6
8
|
/**
|
|
7
9
|
* MongoLite class is the main entry point for interacting with the SQLite-backed database.
|
|
10
|
+
*
|
|
11
|
+
* You can construct it with:
|
|
12
|
+
* - A file path string — uses the built-in `better-sqlite3` adapter.
|
|
13
|
+
* - A `MongoLiteClientOptions` object — uses the built-in adapter with options.
|
|
14
|
+
* - An `IDatabaseAdapter` instance — use a custom adapter such as
|
|
15
|
+
* `CloudflareDurableObjectAdapter` for Cloudflare Durable Objects.
|
|
8
16
|
*/
|
|
9
|
-
export class MongoLite {
|
|
17
|
+
export class MongoLite extends MongoLiteBase {
|
|
10
18
|
/**
|
|
11
19
|
* Creates a new MongoLite client instance.
|
|
12
|
-
* @param dbPathOrOptions Path to the SQLite database file
|
|
20
|
+
* @param dbPathOrOptions Path to the SQLite database file, an options object,
|
|
21
|
+
* or an `IDatabaseAdapter` for custom backends.
|
|
13
22
|
*/
|
|
14
23
|
constructor(dbPathOrOptions, options = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
get database() {
|
|
30
|
-
return this.db;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Closes the database connection.
|
|
34
|
-
*/
|
|
35
|
-
async close() {
|
|
36
|
-
return this.db.close();
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Lists all collections (tables) in the database.
|
|
40
|
-
* @returns An object with a toArray method that resolves to an array of collection names.
|
|
41
|
-
*/
|
|
42
|
-
listCollections() {
|
|
43
|
-
// Query the SQLite schema to get all user-created tables
|
|
44
|
-
return {
|
|
45
|
-
toArray: async () => {
|
|
46
|
-
const result = await this.db.all(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`);
|
|
47
|
-
return result.map((row) => row.name);
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Gets a collection (table) in the database.
|
|
53
|
-
* @param name The name of the collection.
|
|
54
|
-
* @returns A MongoLiteCollection instance.
|
|
55
|
-
*/
|
|
56
|
-
collection(name) {
|
|
57
|
-
return new MongoLiteCollection(this.db, name, this.options);
|
|
24
|
+
if (dbPathOrOptions &&
|
|
25
|
+
typeof dbPathOrOptions === 'object' &&
|
|
26
|
+
typeof dbPathOrOptions.connect === 'function' &&
|
|
27
|
+
typeof dbPathOrOptions.run === 'function' &&
|
|
28
|
+
typeof dbPathOrOptions.get === 'function' &&
|
|
29
|
+
typeof dbPathOrOptions.all === 'function' &&
|
|
30
|
+
typeof dbPathOrOptions.exec === 'function' &&
|
|
31
|
+
typeof dbPathOrOptions.close === 'function') {
|
|
32
|
+
// Custom adapter (e.g. CloudflareDurableObjectAdapter)
|
|
33
|
+
super(dbPathOrOptions, options);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
super(new SQLiteDB(dbPathOrOptions), options);
|
|
37
|
+
}
|
|
58
38
|
}
|
|
59
39
|
}
|
|
60
40
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA4D,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,SAAS,IAAI,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAErF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOjD,OAAO,EACL,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAK7D;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C;;;;OAIG;IACH,YACE,eAAmE,EACnE,UAAgC,EAAE;QAElC,IACE,eAAe;YACf,OAAO,eAAe,KAAK,QAAQ;YACnC,OAAQ,eAAoC,CAAC,OAAO,KAAK,UAAU;YACnE,OAAQ,eAAoC,CAAC,GAAG,KAAK,UAAU;YAC/D,OAAQ,eAAoC,CAAC,GAAG,KAAK,UAAU;YAC/D,OAAQ,eAAoC,CAAC,GAAG,KAAK,UAAU;YAC/D,OAAQ,eAAoC,CAAC,IAAI,KAAK,UAAU;YAChE,OAAQ,eAAoC,CAAC,KAAK,KAAK,UAAU,EACjE,CAAC;YACD,uDAAuD;YACvD,KAAK,CAAC,eAAmC,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,QAAQ,CAAC,eAAkD,CAAC,EAAE,OAAO,CAAC,CAAC;QACnF,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare-safe MongoLite client base class.
|
|
3
|
+
*
|
|
4
|
+
* This module does NOT import `better-sqlite3` and is safe to use inside
|
|
5
|
+
* Cloudflare Workers / Durable Objects. It exports the core `MongoLite` class
|
|
6
|
+
* that accepts any `IDatabaseAdapter` implementation.
|
|
7
|
+
*
|
|
8
|
+
* Node.js consumers should import from the package root (`mongolite-ts`) which
|
|
9
|
+
* provides additional constructor overloads accepting a file path or options object.
|
|
10
|
+
*/
|
|
11
|
+
import type { IDatabaseAdapter } from './db.js';
|
|
12
|
+
import { MongoLiteCollection } from './collection.js';
|
|
13
|
+
import { DocumentWithId } from './types.js';
|
|
14
|
+
export type { IDatabaseAdapter };
|
|
15
|
+
export type MongoLiteBaseOptions = {
|
|
16
|
+
verbose?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Core MongoLite client. Accepts any `IDatabaseAdapter` implementation.
|
|
20
|
+
*
|
|
21
|
+
* This class is intentionally free of `better-sqlite3` dependencies so that it
|
|
22
|
+
* can be bundled for Cloudflare Workers / Durable Objects. For Node.js use, prefer
|
|
23
|
+
* importing `MongoLite` from the package root, which adds convenient constructor
|
|
24
|
+
* overloads for file paths and options objects.
|
|
25
|
+
*/
|
|
26
|
+
export declare class MongoLite {
|
|
27
|
+
protected db: IDatabaseAdapter;
|
|
28
|
+
protected options: MongoLiteBaseOptions;
|
|
29
|
+
constructor(adapter: IDatabaseAdapter, options?: MongoLiteBaseOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Connects to the database.
|
|
32
|
+
* For most custom adapters (e.g. Cloudflare) this is a no-op.
|
|
33
|
+
*/
|
|
34
|
+
connect(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the underlying database adapter instance.
|
|
37
|
+
*/
|
|
38
|
+
get database(): IDatabaseAdapter;
|
|
39
|
+
/**
|
|
40
|
+
* Closes the database connection.
|
|
41
|
+
* For most custom adapters (e.g. Cloudflare) this is a no-op.
|
|
42
|
+
*/
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Lists all collections (tables) in the database.
|
|
46
|
+
* @returns An object with a `toArray` method that resolves to an array of collection names.
|
|
47
|
+
*/
|
|
48
|
+
listCollections(): {
|
|
49
|
+
toArray: () => Promise<string[]>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Returns a typed collection handle.
|
|
53
|
+
* @param name The collection (table) name.
|
|
54
|
+
*/
|
|
55
|
+
collection<T extends DocumentWithId = DocumentWithId>(name: string): MongoLiteCollection<T>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MongoLiteCollection } from './collection.js';
|
|
2
|
+
/**
|
|
3
|
+
* Core MongoLite client. Accepts any `IDatabaseAdapter` implementation.
|
|
4
|
+
*
|
|
5
|
+
* This class is intentionally free of `better-sqlite3` dependencies so that it
|
|
6
|
+
* can be bundled for Cloudflare Workers / Durable Objects. For Node.js use, prefer
|
|
7
|
+
* importing `MongoLite` from the package root, which adds convenient constructor
|
|
8
|
+
* overloads for file paths and options objects.
|
|
9
|
+
*/
|
|
10
|
+
export class MongoLite {
|
|
11
|
+
constructor(adapter, options = {}) {
|
|
12
|
+
this.db = adapter;
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Connects to the database.
|
|
17
|
+
* For most custom adapters (e.g. Cloudflare) this is a no-op.
|
|
18
|
+
*/
|
|
19
|
+
async connect() {
|
|
20
|
+
return this.db.connect();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns the underlying database adapter instance.
|
|
24
|
+
*/
|
|
25
|
+
get database() {
|
|
26
|
+
return this.db;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Closes the database connection.
|
|
30
|
+
* For most custom adapters (e.g. Cloudflare) this is a no-op.
|
|
31
|
+
*/
|
|
32
|
+
async close() {
|
|
33
|
+
return this.db.close();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Lists all collections (tables) in the database.
|
|
37
|
+
* @returns An object with a `toArray` method that resolves to an array of collection names.
|
|
38
|
+
*/
|
|
39
|
+
listCollections() {
|
|
40
|
+
return {
|
|
41
|
+
toArray: async () => {
|
|
42
|
+
const result = await this.db.all(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`);
|
|
43
|
+
return result.map((row) => row.name);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns a typed collection handle.
|
|
49
|
+
* @param name The collection (table) name.
|
|
50
|
+
*/
|
|
51
|
+
collection(name) {
|
|
52
|
+
return new MongoLiteCollection(this.db, name, this.options);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=mongo-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-client.js","sourceRoot":"","sources":["../src/mongo-client.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAStD;;;;;;;GAOG;AACH,MAAM,OAAO,SAAS;IAIpB,YAAY,OAAyB,EAAE,UAAgC,EAAE;QACvE,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,OAAO;YACL,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAC9B,gFAAgF,CACjF,CAAC;gBACF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvC,CAAC;SACF,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,UAAU,CAA4C,IAAY;QAChE,OAAO,IAAI,mBAAmB,CAAI,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACjE,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,14 @@ export interface InsertOneResult {
|
|
|
12
12
|
acknowledged: boolean;
|
|
13
13
|
insertedId: string;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Result of insertMany operation.
|
|
17
|
+
*/
|
|
18
|
+
export interface InsertManyResult {
|
|
19
|
+
acknowledged: boolean;
|
|
20
|
+
insertedCount: number;
|
|
21
|
+
insertedIds: Record<number, string>;
|
|
22
|
+
}
|
|
15
23
|
/**
|
|
16
24
|
* Result of updateOne operation.
|
|
17
25
|
*/
|
|
@@ -21,6 +29,13 @@ export interface UpdateResult {
|
|
|
21
29
|
modifiedCount: number;
|
|
22
30
|
upsertedId: string | null;
|
|
23
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of findOneAndUpdate/findOneAndReplace/findOneAndDelete operations.
|
|
34
|
+
*/
|
|
35
|
+
export interface ModifyResult<T> {
|
|
36
|
+
value: T | null;
|
|
37
|
+
ok: 1;
|
|
38
|
+
}
|
|
24
39
|
/**
|
|
25
40
|
* Result of deleteOne/deleteMany operations.
|
|
26
41
|
*/
|
|
@@ -28,6 +43,46 @@ export interface DeleteResult {
|
|
|
28
43
|
acknowledged: boolean;
|
|
29
44
|
deletedCount: number;
|
|
30
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Options for findOneAndUpdate operations.
|
|
48
|
+
*/
|
|
49
|
+
export interface FindOneAndUpdateOptions<TSchema = DocumentWithId> {
|
|
50
|
+
/** Whether to return the document before ('before') or after ('after') the update. Default is 'before'. */
|
|
51
|
+
returnDocument?: 'before' | 'after';
|
|
52
|
+
/** If true, insert a new document when no match is found. */
|
|
53
|
+
upsert?: boolean;
|
|
54
|
+
/** Field projection to apply. */
|
|
55
|
+
projection?: Projection<TSchema>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for findOneAndDelete operations.
|
|
59
|
+
*/
|
|
60
|
+
export interface FindOneAndDeleteOptions<TSchema = DocumentWithId> {
|
|
61
|
+
/** Field projection to apply. */
|
|
62
|
+
projection?: Projection<TSchema>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Options for findOneAndReplace operations.
|
|
66
|
+
*/
|
|
67
|
+
export interface FindOneAndReplaceOptions<TSchema = DocumentWithId> {
|
|
68
|
+
/** Whether to return the document before ('before') or after ('after') the replacement. Default is 'before'. */
|
|
69
|
+
returnDocument?: 'before' | 'after';
|
|
70
|
+
/** If true, insert a new document when no match is found. */
|
|
71
|
+
upsert?: boolean;
|
|
72
|
+
/** Field projection to apply. */
|
|
73
|
+
projection?: Projection<TSchema>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Options for replaceOne operations.
|
|
77
|
+
*/
|
|
78
|
+
export interface ReplaceOptions {
|
|
79
|
+
/** If true, insert a new document when no match is found. */
|
|
80
|
+
upsert?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Options for aggregate operations.
|
|
84
|
+
*/
|
|
85
|
+
export type AggregationPipeline = Record<string, unknown>[];
|
|
31
86
|
/**
|
|
32
87
|
* Operators for filtering documents.
|
|
33
88
|
* T is the type of the field being queried.
|
|
@@ -44,6 +99,16 @@ export interface QueryOperators<T> {
|
|
|
44
99
|
$all?: T extends unknown[] ? T : never;
|
|
45
100
|
$exists?: boolean;
|
|
46
101
|
$not?: QueryOperators<T>;
|
|
102
|
+
/** Regular expression pattern match. Can be a string pattern or RegExp object. */
|
|
103
|
+
$regex?: string | RegExp;
|
|
104
|
+
/** Regex options (flags). Used alongside $regex. E.g. 'i' for case-insensitive. */
|
|
105
|
+
$options?: string;
|
|
106
|
+
/** Matches arrays with the specified number of elements. */
|
|
107
|
+
$size?: number;
|
|
108
|
+
/** Selects documents where the value of the field is an instance of the specified BSON type. */
|
|
109
|
+
$type?: number | string | (number | string)[];
|
|
110
|
+
/** Matches documents where a field value divided by a divisor has a specified remainder. */
|
|
111
|
+
$mod?: [number, number];
|
|
47
112
|
}
|
|
48
113
|
/**
|
|
49
114
|
* Logical filter operators.
|
|
@@ -104,6 +169,50 @@ export interface UpdateOperators<T> {
|
|
|
104
169
|
} & {
|
|
105
170
|
[key: string]: unknown;
|
|
106
171
|
};
|
|
172
|
+
/** Adds a value to an array field only if the value is not already present. */
|
|
173
|
+
$addToSet?: {
|
|
174
|
+
[P in keyof T]?: unknown | {
|
|
175
|
+
$each: unknown[];
|
|
176
|
+
};
|
|
177
|
+
} & {
|
|
178
|
+
[key: string]: unknown | {
|
|
179
|
+
$each: unknown[];
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** Removes the first or last element from an array. Use 1 for last, -1 for first. */
|
|
183
|
+
$pop?: {
|
|
184
|
+
[P in keyof T]?: 1 | -1;
|
|
185
|
+
} & {
|
|
186
|
+
[key: string]: 1 | -1;
|
|
187
|
+
};
|
|
188
|
+
/** Multiplies the current value of a field by a number. */
|
|
189
|
+
$mul?: {
|
|
190
|
+
[P in keyof T]?: number;
|
|
191
|
+
} & {
|
|
192
|
+
[key: string]: number;
|
|
193
|
+
};
|
|
194
|
+
/** Updates the field value to the minimum of the current value and the specified value. */
|
|
195
|
+
$min?: {
|
|
196
|
+
[P in keyof T]?: T[P];
|
|
197
|
+
} & {
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
};
|
|
200
|
+
/** Updates the field value to the maximum of the current value and the specified value. */
|
|
201
|
+
$max?: {
|
|
202
|
+
[P in keyof T]?: T[P];
|
|
203
|
+
} & {
|
|
204
|
+
[key: string]: unknown;
|
|
205
|
+
};
|
|
206
|
+
/** Sets the value of a field to the current date. */
|
|
207
|
+
$currentDate?: {
|
|
208
|
+
[P in keyof T]?: true | {
|
|
209
|
+
$type: 'date' | 'timestamp';
|
|
210
|
+
};
|
|
211
|
+
} & {
|
|
212
|
+
[key: string]: true | {
|
|
213
|
+
$type: 'date' | 'timestamp';
|
|
214
|
+
};
|
|
215
|
+
};
|
|
107
216
|
}
|
|
108
217
|
/**
|
|
109
218
|
* UpdateFilter type for updating documents.
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongolite-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A MongoDB-like client using SQLite as a persistent store, written in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./cloudflare": {
|
|
14
|
+
"types": "./dist/cloudflare.d.ts",
|
|
15
|
+
"default": "./dist/cloudflare.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
8
18
|
"bin": {
|
|
9
19
|
"mongolite-debug": "dist/bin/mongolite-debug.js"
|
|
10
20
|
},
|
|
@@ -12,6 +22,7 @@
|
|
|
12
22
|
"build": "tsc",
|
|
13
23
|
"test": "node --import tsx --test tests/*.test.ts",
|
|
14
24
|
"test:coverage": "c8 --reporter=lcov --reporter=text node --import tsx --test tests/*.test.ts",
|
|
25
|
+
"test:coverage:check": "c8 --reporter=lcov --reporter=text --check-coverage --lines 80 --functions 80 --statements 80 --branches 70 node --import tsx --test tests/*.test.ts",
|
|
15
26
|
"prepare": "npm run build",
|
|
16
27
|
"prepublish": "npm run build",
|
|
17
28
|
"lint": "eslint src/**/*.ts tests/**/*.ts",
|
|
@@ -43,10 +54,10 @@
|
|
|
43
54
|
"homepage": "https://github.com/semics-tech/mongolite-ts#readme",
|
|
44
55
|
"devDependencies": {
|
|
45
56
|
"@types/better-sqlite3": "^7.6.13",
|
|
46
|
-
"@types/node": "^
|
|
57
|
+
"@types/node": "^25.5.0",
|
|
47
58
|
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
|
48
59
|
"@typescript-eslint/parser": "^7.9.0",
|
|
49
|
-
"c8": "^
|
|
60
|
+
"c8": "^11.0.0",
|
|
50
61
|
"eslint": "^8.57.0",
|
|
51
62
|
"eslint-config-prettier": "^9.1.0",
|
|
52
63
|
"eslint-plugin-prettier": "^5.1.3",
|
|
@@ -58,14 +69,14 @@
|
|
|
58
69
|
"dependencies": {
|
|
59
70
|
"@types/uuid": "^9.0.8",
|
|
60
71
|
"better-sqlite3": "^12.1.1",
|
|
61
|
-
"bson": "^
|
|
62
|
-
"uuid": "^
|
|
72
|
+
"bson": "^7.2.0",
|
|
73
|
+
"uuid": "^13.0.0"
|
|
63
74
|
},
|
|
64
75
|
"files": [
|
|
65
76
|
"dist/**/*",
|
|
66
77
|
"README.md"
|
|
67
78
|
],
|
|
68
79
|
"engines": {
|
|
69
|
-
"node": ">=
|
|
80
|
+
"node": ">=20.0.0"
|
|
70
81
|
}
|
|
71
82
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/database-manager.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database-manager.js","sourceRoot":"","sources":["../src/database-manager.ts"],"names":[],"mappings":""}
|
package/dist/document-utils.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for working with document objects
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Sets a nested value in an object using dot notation.
|
|
6
|
-
* @param obj The object to modify.
|
|
7
|
-
* @param path The dot notation path (e.g., 'user.profile.name').
|
|
8
|
-
* @param value The value to set.
|
|
9
|
-
*/
|
|
10
|
-
export declare function setNestedValue(obj: any, path: string, value: any): void;
|
|
11
|
-
/**
|
|
12
|
-
* Removes a nested property from an object using dot notation.
|
|
13
|
-
* @param obj The object to modify.
|
|
14
|
-
* @param path The dot notation path (e.g., 'user.profile.name').
|
|
15
|
-
*/
|
|
16
|
-
export declare function unsetNestedValue(obj: any, path: string): void;
|
|
17
|
-
/**
|
|
18
|
-
* Gets a nested value from an object using dot notation.
|
|
19
|
-
* @param obj The object to query.
|
|
20
|
-
* @param path The dot notation path (e.g., 'user.profile.name').
|
|
21
|
-
* @returns The value at the path, or undefined if the path doesn't exist.
|
|
22
|
-
*/
|
|
23
|
-
export declare function getNestedValue(obj: any, path: string): any;
|
|
24
|
-
/**
|
|
25
|
-
* Generate a retry function with exponential backoff
|
|
26
|
-
* @param operation The async operation to retry
|
|
27
|
-
* @param operationDescription Description for logging
|
|
28
|
-
* @param maxRetries Maximum number of retries
|
|
29
|
-
* @param initialDelayMs Initial delay between retries (ms)
|
|
30
|
-
* @param maxDelayMs Maximum delay between retries (ms)
|
|
31
|
-
* @returns The result of the operation if successful
|
|
32
|
-
* @throws The original error if all retries fail
|
|
33
|
-
*/
|
|
34
|
-
export declare function retryWithBackoff<R>(operation: () => Promise<R>, operationDescription: string, maxRetries?: number, initialDelayMs?: number, maxDelayMs?: number): Promise<R>;
|
package/dist/document-utils.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for working with document objects
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Sets a nested value in an object using dot notation.
|
|
6
|
-
* @param obj The object to modify.
|
|
7
|
-
* @param path The dot notation path (e.g., 'user.profile.name').
|
|
8
|
-
* @param value The value to set.
|
|
9
|
-
*/
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
export function setNestedValue(obj, path, value) {
|
|
12
|
-
const keys = path.split('.');
|
|
13
|
-
let current = obj;
|
|
14
|
-
// Navigate to the last parent in the path
|
|
15
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
16
|
-
const key = keys[i];
|
|
17
|
-
// Create nested objects if they don't exist
|
|
18
|
-
if (current[key] === undefined || current[key] === null) {
|
|
19
|
-
current[key] = {};
|
|
20
|
-
}
|
|
21
|
-
else if (typeof current[key] !== 'object') {
|
|
22
|
-
// If the path exists but is not an object, make it an object
|
|
23
|
-
current[key] = {};
|
|
24
|
-
}
|
|
25
|
-
current = current[key];
|
|
26
|
-
}
|
|
27
|
-
// Set the value at the final key
|
|
28
|
-
current[keys[keys.length - 1]] = value;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Removes a nested property from an object using dot notation.
|
|
32
|
-
* @param obj The object to modify.
|
|
33
|
-
* @param path The dot notation path (e.g., 'user.profile.name').
|
|
34
|
-
*/
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
export function unsetNestedValue(obj, path) {
|
|
37
|
-
const keys = path.split('.');
|
|
38
|
-
let current = obj;
|
|
39
|
-
// Navigate to the last parent in the path
|
|
40
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
41
|
-
const key = keys[i];
|
|
42
|
-
if (current[key] === undefined || current[key] === null) {
|
|
43
|
-
// If the path doesn't exist, nothing to unset
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
current = current[key];
|
|
47
|
-
}
|
|
48
|
-
// Delete the property at the final key
|
|
49
|
-
delete current[keys[keys.length - 1]];
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Gets a nested value from an object using dot notation.
|
|
53
|
-
* @param obj The object to query.
|
|
54
|
-
* @param path The dot notation path (e.g., 'user.profile.name').
|
|
55
|
-
* @returns The value at the path, or undefined if the path doesn't exist.
|
|
56
|
-
*/
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
export function getNestedValue(obj, path) {
|
|
59
|
-
const keys = path.split('.');
|
|
60
|
-
let current = obj;
|
|
61
|
-
// Navigate through the path
|
|
62
|
-
for (let i = 0; i < keys.length; i++) {
|
|
63
|
-
const key = keys[i];
|
|
64
|
-
if (current === undefined || current === null) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
current = current[key];
|
|
68
|
-
}
|
|
69
|
-
return current;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Generate a retry function with exponential backoff
|
|
73
|
-
* @param operation The async operation to retry
|
|
74
|
-
* @param operationDescription Description for logging
|
|
75
|
-
* @param maxRetries Maximum number of retries
|
|
76
|
-
* @param initialDelayMs Initial delay between retries (ms)
|
|
77
|
-
* @param maxDelayMs Maximum delay between retries (ms)
|
|
78
|
-
* @returns The result of the operation if successful
|
|
79
|
-
* @throws The original error if all retries fail
|
|
80
|
-
*/
|
|
81
|
-
export async function retryWithBackoff(operation, operationDescription, maxRetries = 5, initialDelayMs = 100, maxDelayMs = 10000) {
|
|
82
|
-
let retries = 0;
|
|
83
|
-
let delayMs = initialDelayMs;
|
|
84
|
-
while (true) {
|
|
85
|
-
try {
|
|
86
|
-
return await operation();
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (error.code !== 'SQLITE_BUSY' || retries >= maxRetries) {
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
console.warn(`SQLITE_BUSY encountered during ${operationDescription}, retrying (${retries + 1}/${maxRetries})...`);
|
|
93
|
-
// Wait for the backoff period
|
|
94
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
95
|
-
// Increase delay for next retry (exponential backoff)
|
|
96
|
-
delayMs = Math.min(delayMs * 2, maxDelayMs);
|
|
97
|
-
retries++;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=document-utils.js.map
|