@orion-js/mongodb 4.2.9 → 4.3.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/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as MongoDB from 'mongodb';
2
2
  import { MongoClient, Db, MongoClientOptions, EnhancedOmit, KMSProviders, AWSEncryptionKeyOptions, UUID } from 'mongodb';
3
3
  export { MongoDB };
4
- import { SchemaInAnyOrionForm, Schema, StrictInferSchemaType, TypedSchemaOnSchema, InferSchemaType, FieldType } from '@orion-js/schema';
4
+ import { Schema, SchemaInAnyOrionForm, StrictInferSchemaType, TypedSchemaOnSchema, InferSchemaType, FieldType } from '@orion-js/schema';
5
5
 
6
6
  interface OrionMongoClient {
7
7
  client: MongoClient;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as MongoDB from 'mongodb';
2
2
  import { MongoClient, Db, MongoClientOptions, EnhancedOmit, KMSProviders, AWSEncryptionKeyOptions, UUID } from 'mongodb';
3
3
  export { MongoDB };
4
- import { SchemaInAnyOrionForm, Schema, StrictInferSchemaType, TypedSchemaOnSchema, InferSchemaType, FieldType } from '@orion-js/schema';
4
+ import { Schema, SchemaInAnyOrionForm, StrictInferSchemaType, TypedSchemaOnSchema, InferSchemaType, FieldType } from '@orion-js/schema';
5
5
 
6
6
  interface OrionMongoClient {
7
7
  client: MongoClient;
package/dist/index.js CHANGED
@@ -261,9 +261,9 @@ function typedId(prefix) {
261
261
  }
262
262
 
263
263
  // src/service/index.ts
264
- import { Service } from "@orion-js/services";
264
+ import { addPendingFieldValidator, registerFieldFactories, Service } from "@orion-js/services";
265
265
 
266
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
266
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/type.js
267
267
  function type(input) {
268
268
  if (input === null) {
269
269
  return "Null";
@@ -276,21 +276,21 @@ function type(input) {
276
276
  return typeResult === "AsyncFunction" ? "Promise" : typeResult;
277
277
  }
278
278
 
279
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
279
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
280
280
  var { isArray } = Array;
281
281
 
282
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
282
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
283
283
  function _isInteger(n) {
284
284
  return n << 0 === n;
285
285
  }
286
286
  var isInteger = Number.isInteger || _isInteger;
287
287
 
288
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
288
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
289
289
  function createPath(path, delimiter = ".") {
290
290
  return typeof path === "string" ? path.split(delimiter).map((x) => isInteger(x) ? Number(x) : x) : path;
291
291
  }
292
292
 
293
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/equals.js
293
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/equals.js
294
294
  function _indexOf(valueToFind, list) {
295
295
  if (!isArray(list))
296
296
  throw new Error(`Cannot read property 'indexOf' of ${list}`);
@@ -395,7 +395,7 @@ function equals(a, b) {
395
395
  return false;
396
396
  }
397
397
 
398
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isType.js
398
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isType.js
399
399
  function isType(xType, x) {
400
400
  if (arguments.length === 1) {
401
401
  return (xHolder) => isType(xType, xHolder);
@@ -403,12 +403,12 @@ function isType(xType, x) {
403
403
  return type(x) === xType;
404
404
  }
405
405
 
406
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
406
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
407
407
  function compare(a, b) {
408
408
  return String(a) === String(b);
409
409
  }
410
410
 
411
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
411
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
412
412
  function includes(a, list) {
413
413
  let index = -1;
414
414
  const { length } = list;
@@ -418,7 +418,7 @@ function includes(a, list) {
418
418
  return false;
419
419
  }
420
420
 
421
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/omit.js
421
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/omit.js
422
422
  function omit(propsToOmit, obj) {
423
423
  if (arguments.length === 1) return (_obj) => omit(propsToOmit, _obj);
424
424
  if (obj === null || obj === void 0)
@@ -431,7 +431,7 @@ function omit(propsToOmit, obj) {
431
431
  return willReturn;
432
432
  }
433
433
 
434
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
434
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
435
435
  function isEmpty(input) {
436
436
  const inputType = type(input);
437
437
  if (["Undefined", "NaN", "Number", "Null"].includes(inputType))
@@ -446,7 +446,7 @@ function isEmpty(input) {
446
446
  return false;
447
447
  }
448
448
 
449
- // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isNil.js
449
+ // ../../node_modules/.bun/rambdax@11.3.1/node_modules/rambdax/src/isNil.js
450
450
  function isNil(x) {
451
451
  return x === void 0 || x === null;
452
452
  }
@@ -1372,7 +1372,7 @@ async function loadIndexes(collection) {
1372
1372
 
1373
1373
  // src/createCollection/getSchemaAndModel.ts
1374
1374
  import { clone as clone2 } from "@orion-js/helpers";
1375
- Symbol.metadata ?? (Symbol.metadata = Symbol("Symbol.metadata"));
1375
+ Symbol.metadata ?? (Symbol.metadata = /* @__PURE__ */ Symbol("Symbol.metadata"));
1376
1376
  function prepareShema(schema) {
1377
1377
  if (!schema._id) {
1378
1378
  schema._id = {
@@ -1554,26 +1554,37 @@ function createCollection(options) {
1554
1554
 
1555
1555
  // src/service/index.ts
1556
1556
  var serviceMetadata = /* @__PURE__ */ new WeakMap();
1557
+ var pendingCollectionOptions = {};
1558
+ var hasMongoCollectionFields = false;
1557
1559
  function Repository() {
1558
1560
  return (target, context) => {
1561
+ const options = pendingCollectionOptions;
1562
+ pendingCollectionOptions = {};
1563
+ hasMongoCollectionFields = false;
1559
1564
  Service()(target, context);
1560
- context.addInitializer(function() {
1561
- serviceMetadata.set(this, { _serviceType: "repo" });
1562
- });
1565
+ serviceMetadata.set(target, { _serviceType: "repo" });
1566
+ if (Object.keys(options).length > 0) {
1567
+ const factories = {};
1568
+ for (const [key, opts] of Object.entries(options)) {
1569
+ factories[key] = () => createCollection(opts);
1570
+ }
1571
+ registerFieldFactories(target, factories);
1572
+ }
1563
1573
  };
1564
1574
  }
1565
1575
  function MongoCollection(options) {
1566
1576
  return (_target, context) => {
1567
1577
  const propertyKey = String(context.name);
1568
- context.addInitializer(function() {
1569
- const repo = serviceMetadata.get(this.constructor);
1570
- if (!repo || repo._serviceType !== "repo") {
1578
+ pendingCollectionOptions[propertyKey] = options;
1579
+ hasMongoCollectionFields = true;
1580
+ addPendingFieldValidator(() => {
1581
+ if (hasMongoCollectionFields) {
1582
+ hasMongoCollectionFields = false;
1583
+ pendingCollectionOptions = {};
1571
1584
  throw new Error(
1572
1585
  "You must pass a class decorated with @Repository if you want to use @MongoCollection"
1573
1586
  );
1574
1587
  }
1575
- const collection = createCollection(options);
1576
- this[propertyKey] = collection;
1577
1588
  });
1578
1589
  };
1579
1590
  }