@orion-js/mongodb 4.0.0-next.5 → 4.0.0-next.6

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.js CHANGED
@@ -153,15 +153,215 @@ function typedId(prefix) {
153
153
  // src/service/index.ts
154
154
  import { Service } from "@orion-js/services";
155
155
 
156
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
157
+ function type(input) {
158
+ if (input === null) {
159
+ return "Null";
160
+ } else if (input === void 0) {
161
+ return "Undefined";
162
+ } else if (Number.isNaN(input)) {
163
+ return "NaN";
164
+ }
165
+ const typeResult = Object.prototype.toString.call(input).slice(8, -1);
166
+ return typeResult === "AsyncFunction" ? "Promise" : typeResult;
167
+ }
168
+
169
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
170
+ var { isArray } = Array;
171
+
172
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
173
+ function _isInteger(n) {
174
+ return n << 0 === n;
175
+ }
176
+ var isInteger = Number.isInteger || _isInteger;
177
+
178
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
179
+ function createPath(path, delimiter = ".") {
180
+ return typeof path === "string" ? path.split(delimiter).map((x) => isInteger(x) ? Number(x) : x) : path;
181
+ }
182
+
183
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/equals.js
184
+ function _indexOf(valueToFind, list) {
185
+ if (!isArray(list))
186
+ throw new Error(`Cannot read property 'indexOf' of ${list}`);
187
+ const typeOfValue = type(valueToFind);
188
+ if (!["Array", "NaN", "Object", "RegExp"].includes(typeOfValue))
189
+ return list.indexOf(valueToFind);
190
+ let index = -1;
191
+ let foundIndex = -1;
192
+ const { length } = list;
193
+ while (++index < length && foundIndex === -1)
194
+ if (equals(list[index], valueToFind))
195
+ foundIndex = index;
196
+ return foundIndex;
197
+ }
198
+ function _arrayFromIterator(iter) {
199
+ const list = [];
200
+ let next;
201
+ while (!(next = iter.next()).done)
202
+ list.push(next.value);
203
+ return list;
204
+ }
205
+ function _compareSets(a, b) {
206
+ if (a.size !== b.size)
207
+ return false;
208
+ const aList = _arrayFromIterator(a.values());
209
+ const bList = _arrayFromIterator(b.values());
210
+ const filtered = aList.filter((aInstance) => _indexOf(aInstance, bList) === -1);
211
+ return filtered.length === 0;
212
+ }
213
+ function compareErrors(a, b) {
214
+ if (a.message !== b.message) return false;
215
+ if (a.toString !== b.toString) return false;
216
+ return a.toString() === b.toString();
217
+ }
218
+ function parseDate(maybeDate) {
219
+ if (!maybeDate.toDateString) return [false];
220
+ return [true, maybeDate.getTime()];
221
+ }
222
+ function parseRegex(maybeRegex) {
223
+ if (maybeRegex.constructor !== RegExp) return [false];
224
+ return [true, maybeRegex.toString()];
225
+ }
226
+ function equals(a, b) {
227
+ if (arguments.length === 1) return (_b) => equals(a, _b);
228
+ if (Object.is(a, b)) return true;
229
+ const aType = type(a);
230
+ if (aType !== type(b)) return false;
231
+ if (aType === "Function")
232
+ return a.name === void 0 ? false : a.name === b.name;
233
+ if (["NaN", "Null", "Undefined"].includes(aType)) return true;
234
+ if (["BigInt", "Number"].includes(aType)) {
235
+ if (Object.is(-0, a) !== Object.is(-0, b)) return false;
236
+ return a.toString() === b.toString();
237
+ }
238
+ if (["Boolean", "String"].includes(aType))
239
+ return a.toString() === b.toString();
240
+ if (aType === "Array") {
241
+ const aClone = Array.from(a);
242
+ const bClone = Array.from(b);
243
+ if (aClone.toString() !== bClone.toString())
244
+ return false;
245
+ let loopArrayFlag = true;
246
+ aClone.forEach((aCloneInstance, aCloneIndex) => {
247
+ if (loopArrayFlag) {
248
+ if (aCloneInstance !== bClone[aCloneIndex] && !equals(aCloneInstance, bClone[aCloneIndex]))
249
+ loopArrayFlag = false;
250
+ }
251
+ });
252
+ return loopArrayFlag;
253
+ }
254
+ const aRegex = parseRegex(a);
255
+ const bRegex = parseRegex(b);
256
+ if (aRegex[0])
257
+ return bRegex[0] ? aRegex[1] === bRegex[1] : false;
258
+ else if (bRegex[0]) return false;
259
+ const aDate = parseDate(a);
260
+ const bDate = parseDate(b);
261
+ if (aDate[0])
262
+ return bDate[0] ? aDate[1] === bDate[1] : false;
263
+ else if (bDate[0]) return false;
264
+ if (a instanceof Error) {
265
+ if (!(b instanceof Error)) return false;
266
+ return compareErrors(a, b);
267
+ }
268
+ if (aType === "Set")
269
+ return _compareSets(a, b);
270
+ if (aType === "Object") {
271
+ const aKeys = Object.keys(a);
272
+ if (aKeys.length !== Object.keys(b).length)
273
+ return false;
274
+ let loopObjectFlag = true;
275
+ aKeys.forEach((aKeyInstance) => {
276
+ if (loopObjectFlag) {
277
+ const aValue = a[aKeyInstance];
278
+ const bValue = b[aKeyInstance];
279
+ if (aValue !== bValue && !equals(aValue, bValue))
280
+ loopObjectFlag = false;
281
+ }
282
+ });
283
+ return loopObjectFlag;
284
+ }
285
+ return false;
286
+ }
287
+
288
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isType.js
289
+ function isType(xType, x) {
290
+ if (arguments.length === 1) {
291
+ return (xHolder) => isType(xType, xHolder);
292
+ }
293
+ return type(x) === xType;
294
+ }
295
+
296
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
297
+ function compare(a, b) {
298
+ return String(a) === String(b);
299
+ }
300
+
301
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
302
+ function includes(a, list) {
303
+ let index = -1;
304
+ const { length } = list;
305
+ while (++index < length)
306
+ if (compare(list[index], a))
307
+ return true;
308
+ return false;
309
+ }
310
+
311
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/omit.js
312
+ function omit(propsToOmit, obj) {
313
+ if (arguments.length === 1) return (_obj) => omit(propsToOmit, _obj);
314
+ if (obj === null || obj === void 0)
315
+ return void 0;
316
+ const propsToOmitValue = createPath(propsToOmit, ",");
317
+ const willReturn = {};
318
+ for (const key in obj)
319
+ if (!includes(key, propsToOmitValue))
320
+ willReturn[key] = obj[key];
321
+ return willReturn;
322
+ }
323
+
324
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/flatten.js
325
+ function flatten(list, input) {
326
+ const willReturn = input === void 0 ? [] : input;
327
+ for (let i = 0; i < list.length; i++) {
328
+ if (isArray(list[i])) {
329
+ flatten(list[i], willReturn);
330
+ } else {
331
+ willReturn.push(list[i]);
332
+ }
333
+ }
334
+ return willReturn;
335
+ }
336
+
337
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
338
+ function isEmpty(input) {
339
+ const inputType = type(input);
340
+ if (["Undefined", "NaN", "Number", "Null"].includes(inputType))
341
+ return false;
342
+ if (!input) return true;
343
+ if (inputType === "Object") {
344
+ return Object.keys(input).length === 0;
345
+ }
346
+ if (inputType === "Array") {
347
+ return input.length === 0;
348
+ }
349
+ return false;
350
+ }
351
+
352
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isNil.js
353
+ function isNil(x) {
354
+ return x === void 0 || x === null;
355
+ }
356
+
156
357
  // src/createCollection/getMethods/getSelector.ts
157
- import isPlainObject from "lodash/isPlainObject";
158
358
  function getSelector(args) {
159
359
  if (args.length === 0) return {};
160
360
  const selector = args[0];
161
361
  if (typeof selector === "string") {
162
362
  return { _id: selector };
163
363
  }
164
- if (isPlainObject(selector)) {
364
+ if (type(selector) === "Object") {
165
365
  return selector;
166
366
  }
167
367
  return {
@@ -261,11 +461,14 @@ async function validateInc_default({ schema, operationDoc }) {
261
461
 
262
462
  // src/createCollection/getMethods/validateModifier/validateSet.ts
263
463
  import { validate as validate2 } from "@orion-js/schema";
264
- import mapKeys from "lodash/mapKeys";
265
464
  async function validateSet_default({ schema, operationDoc }) {
266
465
  let cleaned = toDot_default(operationDoc);
267
- cleaned = mapKeys(cleaned, (value, key) => key.replace("$.", "0."));
268
- cleaned = fromDot(cleaned);
466
+ const transformedObj = {};
467
+ Object.keys(cleaned).map((key) => {
468
+ const newKey = key.replace("$.", "0.");
469
+ transformedObj[newKey] = cleaned[key];
470
+ });
471
+ cleaned = fromDot(transformedObj);
269
472
  await validate2(schema, cleaned, { omitRequired: true });
270
473
  }
271
474
 
@@ -302,8 +505,7 @@ async function validateModifier(schema, modifier) {
302
505
 
303
506
  // src/createCollection/getMethods/validateModifier/validateUpsert.ts
304
507
  import { validate as validate3 } from "@orion-js/schema";
305
- import omit from "lodash/omit";
306
- var getPushSimulation = function($push) {
508
+ var getPushSimulation = ($push) => {
307
509
  if (!$push) return {};
308
510
  const simulation = {};
309
511
  for (const key of Object.keys($push)) {
@@ -316,31 +518,25 @@ var getPushSimulation = function($push) {
316
518
  }
317
519
  return simulation;
318
520
  };
319
- var simulateNewDoc = function(selector, modifier) {
320
- return fromDot({
321
- ...selector,
322
- ...modifier.$set,
323
- ...modifier.$inc,
324
- ...getPushSimulation(modifier.$push),
325
- ...getPushSimulation(modifier.$addToSet),
326
- ...modifier.$setOnInsert
327
- });
328
- };
329
- var validateNewDoc = async function(schema, selector, modifier) {
521
+ var simulateNewDoc = (selector, modifier) => fromDot({
522
+ ...selector,
523
+ ...modifier.$set,
524
+ ...modifier.$inc,
525
+ ...getPushSimulation(modifier.$push),
526
+ ...getPushSimulation(modifier.$addToSet),
527
+ ...modifier.$setOnInsert
528
+ });
529
+ var validateNewDoc = async (schema, selector, modifier) => {
330
530
  const doc = simulateNewDoc(selector, modifier);
331
531
  await validate3(schema, doc);
332
532
  };
333
533
  async function validateUpsert_default(schema, selector, modifier) {
334
534
  await validateNewDoc(schema, selector, modifier);
335
- await validateModifier(schema, omit(modifier, "$setOnInsert"));
535
+ await validateModifier(schema, omit(["$setOnInsert"], modifier));
336
536
  }
337
537
 
338
538
  // src/createCollection/getMethods/cleanModifier.ts
339
539
  import { cleanKey, clean } from "@orion-js/schema";
340
- import isEmpty from "lodash/isEmpty";
341
- import isNil from "lodash/isNil";
342
- import isUndefined from "lodash/isUndefined";
343
- import isEqual from "lodash/isEqual";
344
540
  var shouldCheck2 = (key) => {
345
541
  if (key === "$pushAll") throw new Error("$pushAll is not supported; use $push + $each");
346
542
  return ["$pull", "$pullAll", "$pop", "$slice"].indexOf(key) === -1;
@@ -382,7 +578,7 @@ async function cleanModifier(schema, modifier, { isUpsert } = { isUpsert: false
382
578
  const isPresent = await cleanKey(schema, key, "anyvalue", cleanOptions);
383
579
  cleaned = !isNil(isPresent) ? "" : null;
384
580
  }
385
- if (!isUndefined(cleaned)) {
581
+ if (cleaned !== void 0) {
386
582
  cleanedModifier[operation][key] = cleaned;
387
583
  }
388
584
  }
@@ -396,7 +592,7 @@ async function cleanModifier(schema, modifier, { isUpsert } = { isUpsert: false
396
592
  cleanedModifier.$setOnInsert = cleanedSetOnInsert;
397
593
  }
398
594
  }
399
- if (isEqual(cleanedModifier, {})) {
595
+ if (equals(cleanedModifier, {})) {
400
596
  throw new Error("After cleaning your modifier is empty");
401
597
  }
402
598
  return cleanedModifier;
@@ -562,13 +758,12 @@ function deleteMany_default(collection) {
562
758
  }
563
759
 
564
760
  // src/createCollection/getMethods/insertOne.ts
565
- import isPlainObject2 from "lodash/isPlainObject";
566
761
  import { clean as clean2, validate as validate4 } from "@orion-js/schema";
567
762
  var insertOne_default = (collection) => {
568
763
  const insertOne = async (insertDoc, options = {}) => {
569
764
  await collection.connectionPromise;
570
765
  let doc = insertDoc;
571
- if (!doc || !isPlainObject2(doc)) {
766
+ if (!doc || !isType("Object", doc)) {
572
767
  throw new Error("Insert must receive a document");
573
768
  }
574
769
  if (!doc._id) {
@@ -588,15 +783,14 @@ var insertOne_default = (collection) => {
588
783
  };
589
784
 
590
785
  // src/createCollection/getMethods/insertMany.ts
591
- import isPlainObject3 from "lodash/isPlainObject";
592
- import { cloneDeep, values } from "lodash";
786
+ import { clone } from "@orion-js/helpers";
593
787
  import { clean as clean3, validate as validate5 } from "@orion-js/schema";
594
788
  var insertMany_default = (collection) => {
595
789
  const insertMany = async (docs, options = {}) => {
596
790
  await collection.connectionPromise;
597
791
  for (let index = 0; index < docs.length; index++) {
598
- let doc = cloneDeep(docs[index]);
599
- if (!doc || !isPlainObject3(doc)) {
792
+ let doc = clone(docs[index]);
793
+ if (!doc || type(doc) !== "Object") {
600
794
  throw new Error(`Item at index ${index} is not a document`);
601
795
  }
602
796
  if (!doc._id) {
@@ -612,7 +806,7 @@ var insertMany_default = (collection) => {
612
806
  const { insertedIds } = await wrapErrors(() => {
613
807
  return collection.rawCollection.insertMany(docs, options.mongoOptions);
614
808
  });
615
- const ids = values(insertedIds);
809
+ const ids = Object.values(insertedIds);
616
810
  return ids.map((id) => id.toString());
617
811
  };
618
812
  return insertMany;
@@ -657,13 +851,12 @@ var estimatedDocumentCount_default = (collection) => {
657
851
  };
658
852
 
659
853
  // src/createCollection/getMethods/insertAndFind.ts
660
- import isPlainObject4 from "lodash/isPlainObject";
661
854
  import { clean as clean4, validate as validate6 } from "@orion-js/schema";
662
855
  var insertAndFind_default = (collection) => {
663
856
  const insertAndFind = async (insertDoc, options = {}) => {
664
857
  await collection.connectionPromise;
665
858
  let doc = insertDoc;
666
- if (!doc || !isPlainObject4(doc)) {
859
+ if (!doc || type(doc) !== "Object") {
667
860
  throw new Error("Insert must receive a document");
668
861
  }
669
862
  if (!doc._id) {
@@ -713,8 +906,7 @@ function loadOne_default(collection) {
713
906
  }
714
907
 
715
908
  // src/createCollection/getMethods/dataLoader/loadData.ts
716
- import { createMapArray } from "@orion-js/helpers";
717
- import cloneDeep2 from "lodash/cloneDeep";
909
+ import { createMapArray, clone as clone2 } from "@orion-js/helpers";
718
910
 
719
911
  // src/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.ts
720
912
  import DataLoader from "dataloader";
@@ -736,7 +928,6 @@ var getDataLoader = (params) => {
736
928
  };
737
929
 
738
930
  // src/createCollection/getMethods/dataLoader/dataLoad/index.ts
739
- import flatten from "lodash/flatten";
740
931
  import { hashObject } from "@orion-js/helpers";
741
932
  var dataLoad = async (options) => {
742
933
  const dataLoader = getDataLoader({
@@ -767,10 +958,10 @@ function loadData_default(collection) {
767
958
  id: options.value,
768
959
  ids: options.values,
769
960
  timeout: options.timeout,
770
- load: async (values2) => {
961
+ load: async (values) => {
771
962
  const query = {
772
- ...cloneDeep2(options.match),
773
- [options.key]: { $in: values2 }
963
+ ...clone2(options.match),
964
+ [options.key]: { $in: values }
774
965
  };
775
966
  const cursor = collection.find(query);
776
967
  if (options.sort) {
@@ -784,7 +975,7 @@ function loadData_default(collection) {
784
975
  }
785
976
  const items = await cursor.toArray();
786
977
  const itemsMap = createMapArray(items, options.key);
787
- return values2.map((value) => {
978
+ return values.map((value) => {
788
979
  return itemsMap[value] || [];
789
980
  });
790
981
  }
@@ -890,7 +1081,7 @@ async function loadIndexes(collection) {
890
1081
  }
891
1082
 
892
1083
  // src/createCollection/getSchemaAndModel.ts
893
- import { cloneDeep as cloneDeep3, isPlainObject as isPlainObject5 } from "lodash";
1084
+ import { clone as clone3 } from "@orion-js/helpers";
894
1085
  Symbol.metadata ?? (Symbol.metadata = Symbol("Symbol.metadata"));
895
1086
  function prepareShema(schema) {
896
1087
  if (!schema._id) {
@@ -912,10 +1103,10 @@ function getSchema(options) {
912
1103
  }
913
1104
  if (options.schema.getModel) {
914
1105
  const model = options.schema.getModel();
915
- const schema = model ? cloneDeep3(model.getSchema()) : {};
1106
+ const schema = model ? clone3(model.getSchema()) : {};
916
1107
  return prepareShema(schema);
917
1108
  }
918
- if (isPlainObject5(options.schema)) {
1109
+ if (type(options.schema) === "Object") {
919
1110
  return prepareShema(options.schema);
920
1111
  }
921
1112
  }