mongolite-ts 0.7.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 +75 -0
- 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 +2 -2
- package/dist/collection.js.map +1 -1
- package/dist/cursors/findCursor.d.ts +2 -2
- package/dist/cursors/findCursor.js.map +1 -1
- package/dist/db.d.ts +16 -1
- 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/package.json +11 -1
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/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
|
},
|