flongo 1.5.0 → 1.7.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/dist/flongo.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { Db, MongoClient } from "mongodb";
1
+ import { Db, MongoClient, MongoClientOptions } from "mongodb";
2
2
  export declare let flongoClient: MongoClient;
3
3
  export declare let flongoDb: Db;
4
4
  export interface FlongoConfig {
5
5
  connectionString: string;
6
6
  dbName: string;
7
+ clientOptions?: MongoClientOptions;
7
8
  }
8
9
  export declare function initializeFlongo(config: FlongoConfig): void;
10
+ export declare function connectFlongo(config: FlongoConfig): Promise<void>;
9
11
  //# sourceMappingURL=flongo.d.ts.map
package/dist/flongo.js CHANGED
@@ -2,9 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flongoDb = exports.flongoClient = void 0;
4
4
  exports.initializeFlongo = initializeFlongo;
5
+ exports.connectFlongo = connectFlongo;
5
6
  const mongodb_1 = require("mongodb");
7
+ const defaultClientOptions = {
8
+ serverSelectionTimeoutMS: 10000,
9
+ heartbeatFrequencyMS: 15000,
10
+ socketTimeoutMS: 30000,
11
+ maxIdleTimeMS: 60000,
12
+ };
6
13
  function initializeFlongo(config) {
7
- exports.flongoClient = new mongodb_1.MongoClient(config.connectionString);
14
+ const options = { ...defaultClientOptions, ...config.clientOptions };
15
+ exports.flongoClient = new mongodb_1.MongoClient(config.connectionString, options);
8
16
  exports.flongoDb = exports.flongoClient.db(config.dbName);
9
17
  }
18
+ async function connectFlongo(config) {
19
+ initializeFlongo(config);
20
+ await exports.flongoClient.connect();
21
+ }
10
22
  //# sourceMappingURL=flongo.js.map
@@ -214,6 +214,15 @@ export declare class FlongoQuery implements ICollectionQuery {
214
214
  * @returns This query instance for chaining
215
215
  */
216
216
  geoWithin(bounds?: Bounds): FlongoQuery;
217
+ /**
218
+ * Performs a proximity query using MongoDB's $near operator
219
+ * Requires a 2dsphere index on the target field
220
+ * Results are automatically sorted by distance (nearest first)
221
+ * @param center - Center point coordinates
222
+ * @param maxDistanceMeters - Maximum distance in meters
223
+ * @returns This query instance for chaining
224
+ */
225
+ near(center: Coordinates, maxDistanceMeters: number): FlongoQuery;
217
226
  /**
218
227
  * Sets the field and direction for sorting results
219
228
  * @param field - Field name to sort by
@@ -330,6 +330,24 @@ class FlongoQuery {
330
330
  }
331
331
  return this;
332
332
  }
333
+ /**
334
+ * Performs a proximity query using MongoDB's $near operator
335
+ * Requires a 2dsphere index on the target field
336
+ * Results are automatically sorted by distance (nearest first)
337
+ * @param center - Center point coordinates
338
+ * @param maxDistanceMeters - Maximum distance in meters
339
+ * @returns This query instance for chaining
340
+ */
341
+ near(center, maxDistanceMeters) {
342
+ this.set("$near", {
343
+ $geometry: {
344
+ type: "Point",
345
+ coordinates: [center.longitude, center.latitude]
346
+ },
347
+ $maxDistance: maxDistanceMeters
348
+ });
349
+ return this;
350
+ }
333
351
  // ===========================================
334
352
  // SORTING
335
353
  // ===========================================
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { FlongoCollection, FlongoCollectionOptions } from "./flongoCollection";
2
2
  export { FlongoQuery, FlongoQueryBuilder } from "./flongoQuery";
3
- export { initializeFlongo, FlongoConfig, flongoClient, flongoDb } from "./flongo";
3
+ export { initializeFlongo, connectFlongo, FlongoConfig, flongoClient, flongoDb } from "./flongo";
4
4
  export { Error404, Error400 } from "./errors";
5
5
  export { Entity, DbRecord, Pagination, Coordinates, Bounds, Event, EventName, EventRecord, Logic, SortDirection, ColRange, ColExpression, ICollectionQuery, ICollection, Repository, CacheOptions, CachedCollectionOptions } from "./types";
6
6
  export { CacheStore, CacheEntry, CacheStats, CacheStoreOptions, BaseCacheStore, MemoryCache, MemoryCacheOptions, CacheKeyGenerator, CacheKeyOptions, InvalidationStrategy, InvalidationRule, InvalidationOptions, CacheInvalidator, TTLStrategy, LRUStrategy, CacheConfig, CacheProviderConfig, CacheConfiguration, createDefaultConfig, createProductionConfig, createDevelopmentConfig, DetailedCacheStats, CacheMetrics, CacheStatsCollector, CacheMonitor, getGlobalCacheMonitor, resetGlobalCacheMonitor } from "./cache";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Main exports for flongo package
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.resetGlobalCacheMonitor = exports.getGlobalCacheMonitor = exports.CacheMonitor = exports.CacheStatsCollector = exports.createDevelopmentConfig = exports.createProductionConfig = exports.createDefaultConfig = exports.CacheConfiguration = exports.LRUStrategy = exports.TTLStrategy = exports.CacheInvalidator = exports.InvalidationStrategy = exports.CacheKeyGenerator = exports.MemoryCache = exports.BaseCacheStore = exports.ColExpression = exports.ColRange = exports.SortDirection = exports.Logic = exports.EventName = exports.Error400 = exports.Error404 = exports.flongoDb = exports.flongoClient = exports.initializeFlongo = exports.FlongoQueryBuilder = exports.FlongoQuery = exports.FlongoCollection = void 0;
4
+ exports.resetGlobalCacheMonitor = exports.getGlobalCacheMonitor = exports.CacheMonitor = exports.CacheStatsCollector = exports.createDevelopmentConfig = exports.createProductionConfig = exports.createDefaultConfig = exports.CacheConfiguration = exports.LRUStrategy = exports.TTLStrategy = exports.CacheInvalidator = exports.InvalidationStrategy = exports.CacheKeyGenerator = exports.MemoryCache = exports.BaseCacheStore = exports.ColExpression = exports.ColRange = exports.SortDirection = exports.Logic = exports.EventName = exports.Error400 = exports.Error404 = exports.flongoDb = exports.flongoClient = exports.connectFlongo = exports.initializeFlongo = exports.FlongoQueryBuilder = exports.FlongoQuery = exports.FlongoCollection = void 0;
5
5
  var flongoCollection_1 = require("./flongoCollection");
6
6
  Object.defineProperty(exports, "FlongoCollection", { enumerable: true, get: function () { return flongoCollection_1.FlongoCollection; } });
7
7
  var flongoQuery_1 = require("./flongoQuery");
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "FlongoQuery", { enumerable: true, get: function
9
9
  Object.defineProperty(exports, "FlongoQueryBuilder", { enumerable: true, get: function () { return flongoQuery_1.FlongoQueryBuilder; } });
10
10
  var flongo_1 = require("./flongo");
11
11
  Object.defineProperty(exports, "initializeFlongo", { enumerable: true, get: function () { return flongo_1.initializeFlongo; } });
12
+ Object.defineProperty(exports, "connectFlongo", { enumerable: true, get: function () { return flongo_1.connectFlongo; } });
12
13
  Object.defineProperty(exports, "flongoClient", { enumerable: true, get: function () { return flongo_1.flongoClient; } });
13
14
  Object.defineProperty(exports, "flongoDb", { enumerable: true, get: function () { return flongo_1.flongoDb; } });
14
15
  var errors_1 = require("./errors");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flongo",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "Firestore-like fluent query API for MongoDB",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",