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.
Files changed (47) hide show
  1. package/README.md +97 -586
  2. package/dist/adapters/browser.d.ts +97 -0
  3. package/dist/adapters/browser.js +103 -0
  4. package/dist/adapters/browser.js.map +1 -0
  5. package/dist/adapters/cloudflare.d.ts +106 -0
  6. package/dist/adapters/cloudflare.js +94 -0
  7. package/dist/adapters/cloudflare.js.map +1 -0
  8. package/dist/changeStream.d.ts +2 -2
  9. package/dist/changeStream.js.map +1 -1
  10. package/dist/cloudflare.d.ts +39 -0
  11. package/dist/cloudflare.js +39 -0
  12. package/dist/cloudflare.js.map +1 -0
  13. package/dist/collection.d.ts +93 -6
  14. package/dist/collection.js +796 -6
  15. package/dist/collection.js.map +1 -1
  16. package/dist/cursors/findCursor.d.ts +19 -4
  17. package/dist/cursors/findCursor.js +136 -2
  18. package/dist/cursors/findCursor.js.map +1 -1
  19. package/dist/db.d.ts +16 -1
  20. package/dist/db.js +26 -0
  21. package/dist/db.js.map +1 -1
  22. package/dist/index.d.ts +17 -38
  23. package/dist/index.js +26 -46
  24. package/dist/index.js.map +1 -1
  25. package/dist/mongo-client.d.ts +56 -0
  26. package/dist/mongo-client.js +55 -0
  27. package/dist/mongo-client.js.map +1 -0
  28. package/dist/types.d.ts +109 -0
  29. package/package.json +17 -6
  30. package/dist/database-manager.d.ts +0 -1
  31. package/dist/database-manager.js +0 -2
  32. package/dist/database-manager.js.map +0 -1
  33. package/dist/document-utils.d.ts +0 -34
  34. package/dist/document-utils.js +0 -101
  35. package/dist/document-utils.js.map +0 -1
  36. package/dist/find-cursor.d.ts +0 -51
  37. package/dist/find-cursor.js +0 -204
  38. package/dist/find-cursor.js.map +0 -1
  39. package/dist/plugins/mongodbSync.d.ts +0 -128
  40. package/dist/plugins/mongodbSync.js +0 -339
  41. package/dist/plugins/mongodbSync.js.map +0 -1
  42. package/dist/query-builder.d.ts +0 -18
  43. package/dist/query-builder.js +0 -358
  44. package/dist/query-builder.js.map +0 -1
  45. package/dist/update-operations.d.ts +0 -17
  46. package/dist/update-operations.js +0 -147
  47. package/dist/update-operations.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-utils.js","sourceRoot":"","sources":["../src/document-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,8DAA8D;AAC9D,MAAM,UAAU,cAAc,CAAC,GAAQ,EAAE,IAAY,EAAE,KAAU;IAC/D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,OAAO,GAAG,GAAG,CAAC;IAElB,0CAA0C;IAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEpB,4CAA4C;QAC5C,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;YACxD,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACpB,CAAC;aAAM,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC5C,6DAA6D;YAC7D,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACpB,CAAC;QAED,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED,iCAAiC;IACjC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAAC,GAAQ,EAAE,IAAY;IACrD,MAAM,IAAI,GAAG,IAAI,CAA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AAc,GAAG,GAAG,EACpB,UAAU,GAAG,KAAK;IAElB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,OAAO,GAAG,cAAc,CAAC;IAE7B,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAK,KAA+B,CAAC,IAAI,KAAK,aAAa,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;gBACrF,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,CAAC,IAAI,CACV,kCAAkC,oBAAoB,eAAe,OAAO,GAAG,CAAC,IAAI,UAAU,MAAM,CACrG,CAAC;YAEF,8BAA8B;YAC9B,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAE7D,sDAAsD;YACtD,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;YAC5C,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,51 +0,0 @@
1
- import { DocumentWithId, Filter, SortCriteria, Projection } from './types.js';
2
- import { SQLiteDB } from './db.js';
3
- /**
4
- * Represents a cursor for find operations, allowing chaining of limit, skip, and sort.
5
- */
6
- export declare class FindCursor<T extends DocumentWithId> {
7
- private db;
8
- private collectionName;
9
- private readonly options;
10
- private queryParts;
11
- private limitCount;
12
- private skipCount;
13
- private sortCriteria;
14
- private projectionFields;
15
- private queryBuilder;
16
- constructor(db: SQLiteDB, collectionName: string, initialFilter: Filter<T>, options?: {
17
- verbose?: boolean;
18
- });
19
- private buildSelectQuery;
20
- /**
21
- * Specifies the maximum number of documents the cursor will return.
22
- * @param count The number of documents to limit to.
23
- * @returns The `FindCursor` instance for chaining.
24
- */
25
- limit(count: number): this;
26
- /**
27
- * Specifies the number of documents to skip.
28
- * @param count The number of documents to skip.
29
- * @returns The `FindCursor` instance for chaining.
30
- */
31
- skip(count: number): this;
32
- /**
33
- * Specifies the sorting order for the documents.
34
- * @param sortCriteria An object defining sort order (e.g., `{ age: -1, name: 1 }`).
35
- * @returns The `FindCursor` instance for chaining.
36
- */
37
- sort(sortCriteria: SortCriteria<T>): this;
38
- /**
39
- * Specifies the fields to return (projection).
40
- * @param projection An object where keys are field names and values are 1 (include) or 0 (exclude).
41
- * `_id` is included by default unless explicitly excluded.
42
- * @returns The `FindCursor` instance for chaining.
43
- */
44
- project(projection: Projection<T>): this;
45
- private applyProjection;
46
- /**
47
- * Executes the query and returns all matching documents as an array.
48
- * @returns A promise that resolves to an array of documents.
49
- */
50
- toArray(): Promise<Partial<T>[]>;
51
- }
@@ -1,204 +0,0 @@
1
- import { QueryBuilder } from './query-builder.js';
2
- /**
3
- * Represents a cursor for find operations, allowing chaining of limit, skip, and sort.
4
- */
5
- export class FindCursor {
6
- constructor(db, collectionName, initialFilter, options = {}) {
7
- this.db = db;
8
- this.collectionName = collectionName;
9
- this.options = options;
10
- this.limitCount = null;
11
- this.skipCount = null;
12
- this.sortCriteria = null;
13
- this.projectionFields = null;
14
- this.queryBuilder = new QueryBuilder(options);
15
- this.queryParts = this.buildSelectQuery(initialFilter);
16
- }
17
- buildSelectQuery(filter) {
18
- const params = [];
19
- const whereClause = this.queryBuilder.buildWhereClause(filter, params);
20
- const sql = `SELECT _id, data FROM "${this.collectionName}" WHERE ${whereClause}`;
21
- if (this.options.verbose) {
22
- console.log(`SQL Query: ${sql}`);
23
- console.log(`Parameters: ${JSON.stringify(params)}`);
24
- }
25
- return { sql, params };
26
- }
27
- /**
28
- * Specifies the maximum number of documents the cursor will return.
29
- * @param count The number of documents to limit to.
30
- * @returns The `FindCursor` instance for chaining.
31
- */
32
- limit(count) {
33
- if (count < 0)
34
- throw new Error('Limit must be a non-negative number.');
35
- this.limitCount = count;
36
- return this;
37
- }
38
- /**
39
- * Specifies the number of documents to skip.
40
- * @param count The number of documents to skip.
41
- * @returns The `FindCursor` instance for chaining.
42
- */
43
- skip(count) {
44
- if (count < 0)
45
- throw new Error('Skip must be a non-negative number.');
46
- this.skipCount = count;
47
- return this;
48
- }
49
- /**
50
- * Specifies the sorting order for the documents.
51
- * @param sortCriteria An object defining sort order (e.g., `{ age: -1, name: 1 }`).
52
- * @returns The `FindCursor` instance for chaining.
53
- */
54
- sort(sortCriteria) {
55
- this.sortCriteria = sortCriteria;
56
- return this;
57
- }
58
- /**
59
- * Specifies the fields to return (projection).
60
- * @param projection An object where keys are field names and values are 1 (include) or 0 (exclude).
61
- * `_id` is included by default unless explicitly excluded.
62
- * @returns The `FindCursor` instance for chaining.
63
- */
64
- project(projection) {
65
- this.projectionFields = projection;
66
- return this;
67
- }
68
- applyProjection(doc) {
69
- if (!this.projectionFields)
70
- return doc;
71
- const projectedDoc = {};
72
- let includeMode = true; // true if any field is 1, false if any field is 0 (excluding _id)
73
- let hasExplicitInclusion = false;
74
- // Determine if it's an inclusion or exclusion projection
75
- for (const key in this.projectionFields) {
76
- if (key === '_id')
77
- continue;
78
- if (this.projectionFields[key] === 1 ||
79
- this.projectionFields[key] === true) {
80
- hasExplicitInclusion = true;
81
- break;
82
- }
83
- if (this.projectionFields[key] === 0 ||
84
- this.projectionFields[key] === false) {
85
- includeMode = false;
86
- // No break here, need to check all for explicit inclusions if _id is also 0
87
- }
88
- }
89
- if ((this.projectionFields._id === 0 || this.projectionFields._id === false) &&
90
- !hasExplicitInclusion) {
91
- // If _id is excluded and no other fields are explicitly included,
92
- // it's an exclusion projection where other fields are implicitly included.
93
- includeMode = false;
94
- }
95
- else if (hasExplicitInclusion) {
96
- includeMode = true;
97
- }
98
- if (includeMode) {
99
- // Inclusion mode
100
- for (const key in this.projectionFields) {
101
- if (this.projectionFields[key] === 1 ||
102
- this.projectionFields[key] === true) {
103
- if (key.includes('.')) {
104
- // Handle nested paths for inclusion (basic implementation)
105
- const path = key.split('.');
106
- let current = doc;
107
- let target = projectedDoc;
108
- // Navigate to the last parent in the path
109
- for (let i = 0; i < path.length - 1; i++) {
110
- const segment = path[i];
111
- if (current[segment] === undefined)
112
- break;
113
- if (target[segment] === undefined) {
114
- target[segment] = {};
115
- }
116
- current = current[segment];
117
- target = target[segment];
118
- }
119
- // Set the final property if we reached it
120
- const lastSegment = path[path.length - 1];
121
- if (current && current[lastSegment] !== undefined) {
122
- target[lastSegment] = current[lastSegment];
123
- }
124
- }
125
- else if (key in doc) {
126
- projectedDoc[key] = doc[key];
127
- }
128
- }
129
- }
130
- // _id is included by default in inclusion mode, unless explicitly excluded
131
- if (this.projectionFields._id !== 0 && this.projectionFields._id !== false && '_id' in doc) {
132
- projectedDoc._id = doc._id;
133
- }
134
- }
135
- else {
136
- // Exclusion mode
137
- Object.assign(projectedDoc, doc);
138
- for (const key in this.projectionFields) {
139
- if (this.projectionFields[key] === 0 ||
140
- this.projectionFields[key] === false) {
141
- if (key.includes('.')) {
142
- // Handle nested paths for exclusion (basic implementation)
143
- const path = key.split('.');
144
- let current = projectedDoc;
145
- // Navigate to the parent of the property to exclude
146
- for (let i = 0; i < path.length - 1; i++) {
147
- const segment = path[i];
148
- if (current[segment] === undefined)
149
- break;
150
- current = current[segment];
151
- }
152
- // Delete the final property if we reached its parent
153
- const lastSegment = path[path.length - 1];
154
- if (current && current[lastSegment] !== undefined) {
155
- delete current[lastSegment];
156
- }
157
- }
158
- else {
159
- delete projectedDoc[key];
160
- }
161
- }
162
- }
163
- }
164
- return projectedDoc;
165
- }
166
- /**
167
- * Executes the query and returns all matching documents as an array.
168
- * @returns A promise that resolves to an array of documents.
169
- */
170
- async toArray() {
171
- let finalSql = this.queryParts.sql;
172
- const finalParams = [...this.queryParts.params];
173
- if (this.sortCriteria) {
174
- const sortClauses = Object.entries(this.sortCriteria).map(([field, order]) => {
175
- if (field === '_id') {
176
- return `_id ${order === 1 ? 'ASC' : 'DESC'}`;
177
- }
178
- return `json_extract(data, ${this.queryBuilder.parseJsonPath(field)}) ${order === 1 ? 'ASC' : 'DESC'}`;
179
- });
180
- if (sortClauses.length > 0) {
181
- finalSql += ` ORDER BY ${sortClauses.join(', ')}`;
182
- }
183
- }
184
- if (this.limitCount !== null) {
185
- finalSql += ` LIMIT ?`;
186
- finalParams.push(this.limitCount);
187
- }
188
- if (this.skipCount !== null) {
189
- if (this.limitCount === null) {
190
- // SQLite requires a LIMIT if OFFSET is used.
191
- // Use a very large number if no limit is specified.
192
- finalSql += ` LIMIT -1`; // Or a large number like 999999999
193
- }
194
- finalSql += ` OFFSET ?`;
195
- finalParams.push(this.skipCount);
196
- }
197
- const rows = await this.db.all(finalSql, finalParams);
198
- return rows.map((row) => {
199
- const doc = { _id: row._id, ...JSON.parse(row.data) };
200
- return this.applyProjection(doc);
201
- });
202
- }
203
- }
204
- //# sourceMappingURL=find-cursor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"find-cursor.js","sourceRoot":"","sources":["../src/find-cursor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,UAAU;IAWrB,YACU,EAAY,EACZ,cAAsB,EAC9B,aAAwB,EACP,UAAiC,EAAE;QAH5C,OAAE,GAAF,EAAE,CAAU;QACZ,mBAAc,GAAd,cAAc,CAAQ;QAEb,YAAO,GAAP,OAAO,CAA4B;QAV9C,eAAU,GAAkB,IAAI,CAAC;QACjC,cAAS,GAAkB,IAAI,CAAC;QAChC,iBAAY,GAA2B,IAAI,CAAC;QAC5C,qBAAgB,GAAyB,IAAI,CAAC;QASpD,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAI,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IACzD,CAAC;IAEO,gBAAgB,CAAC,MAAiB;QACxC,MAAM,MAAM,GAAc,EAAE,CAAC;QAC7B,MAA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,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAAY,QAAQ,EAAE,WAAW,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACtB,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAO,CAAC;YAC3D,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,128 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { DocumentWithId, Filter, UpdateFilter, InsertOneResult, UpdateResult, DeleteResult } from '../types.js';
3
- /**
4
- * Interface for MongoDB operations that can be performed
5
- */
6
- interface MongoDBOperation<T extends DocumentWithId = DocumentWithId> {
7
- type: 'insert' | 'update' | 'delete' | 'find';
8
- collection: string;
9
- data?: Partial<T> | Partial<T>[];
10
- filter?: Filter<T>;
11
- update?: UpdateFilter<T>;
12
- options?: Record<string, unknown>;
13
- timestamp: Date;
14
- localId?: string;
15
- }
16
- /**
17
- * Configuration options for the MongoDB sync plugin
18
- */
19
- export interface MongoDBSyncOptions {
20
- /** MongoDB connection string */
21
- connectionString: string;
22
- /** Database name to sync to (if different from local) */
23
- databaseName?: string;
24
- /** Whether to enable dirty reads from MongoDB */
25
- enableDirtyReads?: boolean;
26
- /** Retry configuration for failed operations */
27
- retryConfig?: {
28
- maxRetries?: number;
29
- initialDelayMs?: number;
30
- maxDelayMs?: number;
31
- };
32
- /** Whether to enable verbose logging */
33
- verbose?: boolean;
34
- /** Batch size for operations */
35
- batchSize?: number;
36
- /** Queue timeout for batching operations */
37
- queueTimeoutMs?: number;
38
- }
39
- /**
40
- * Result of a sync operation
41
- */
42
- export interface SyncResult {
43
- success: boolean;
44
- operation: MongoDBOperation;
45
- error?: Error;
46
- mongodbResult?: unknown;
47
- }
48
- /**
49
- * MongoDB Cloud Sync Plugin
50
- *
51
- * This plugin provides optional synchronization between MongoLite and MongoDB Cloud.
52
- * It hooks into MongoLite operations and replicates them to a MongoDB instance.
53
- */
54
- export declare class MongoDBSyncPlugin extends EventEmitter {
55
- private options;
56
- private operationQueue;
57
- private isProcessing;
58
- private queueTimer;
59
- private mongoClient;
60
- private mongoDb;
61
- private isConnected;
62
- constructor(options: MongoDBSyncOptions);
63
- /**
64
- * Initialize connection to MongoDB Cloud
65
- */
66
- initialize(): Promise<void>;
67
- /**
68
- * Disconnect from MongoDB
69
- */
70
- disconnect(): Promise<void>;
71
- /**
72
- * Check if the plugin is connected to MongoDB
73
- */
74
- get connected(): boolean;
75
- /**
76
- * Hook for insert operations
77
- */
78
- onInsert<T extends DocumentWithId>(collection: string, document: Partial<T>, result: InsertOneResult): Promise<void>;
79
- /**
80
- * Hook for update operations
81
- */
82
- onUpdate<T extends DocumentWithId>(collection: string, filter: Filter<T>, update: UpdateFilter<T>, _result: UpdateResult): Promise<void>;
83
- /**
84
- * Hook for delete operations
85
- */
86
- onDelete<T extends DocumentWithId>(collection: string, filter: Filter<T>, _result: DeleteResult): Promise<void>;
87
- /**
88
- * Perform a dirty read from MongoDB (optional functionality)
89
- */
90
- getDirtyRead<T>(collection: string, filter?: Record<string, unknown>): Promise<T[]>;
91
- /**
92
- * Queue an operation for batch processing
93
- */
94
- private queueOperation;
95
- /**
96
- * Process the operation queue
97
- */
98
- private processQueue;
99
- /**
100
- * Process a batch of operations
101
- */
102
- private processBatch;
103
- /**
104
- * Execute a single operation on MongoDB
105
- */
106
- private executeOperation;
107
- /**
108
- * Get queue status
109
- */
110
- getQueueStatus(): {
111
- queueLength: number;
112
- isProcessing: boolean;
113
- isConnected: boolean;
114
- };
115
- /**
116
- * Flush the queue (process immediately)
117
- */
118
- flush(): Promise<void>;
119
- /**
120
- * Log messages if verbose mode is enabled
121
- */
122
- private log;
123
- }
124
- /**
125
- * Factory function to create and initialize a MongoDB sync plugin
126
- */
127
- export declare function createMongoDBSyncPlugin(options: MongoDBSyncOptions): Promise<MongoDBSyncPlugin>;
128
- export {};