@event-driven-io/pongo 0.17.0-beta.2 → 0.17.0-beta.21

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 (68) hide show
  1. package/dist/{chunk-ECQ2CKZE.cjs → chunk-A4DCNQJR.cjs} +45 -43
  2. package/dist/chunk-A4DCNQJR.cjs.map +1 -0
  3. package/dist/{chunk-4BL6YWLW.cjs → chunk-BZRKCNRY.cjs} +105 -72
  4. package/dist/chunk-BZRKCNRY.cjs.map +1 -0
  5. package/dist/{chunk-NCNRRYVE.js → chunk-H637RRXS.js} +85 -52
  6. package/dist/chunk-H637RRXS.js.map +1 -0
  7. package/dist/{chunk-Y7LRKJLJ.js → chunk-TTZGGAZV.js} +40 -38
  8. package/dist/chunk-TTZGGAZV.js.map +1 -0
  9. package/dist/cli.cjs +43 -37
  10. package/dist/cli.cjs.map +1 -1
  11. package/dist/cli.js +34 -28
  12. package/dist/cli.js.map +1 -1
  13. package/dist/cloudflare.cjs +53 -0
  14. package/dist/cloudflare.cjs.map +1 -0
  15. package/dist/cloudflare.d.cts +11 -0
  16. package/dist/cloudflare.d.ts +11 -0
  17. package/dist/{d1.js → cloudflare.js} +19 -20
  18. package/dist/cloudflare.js.map +1 -0
  19. package/dist/{index-BJopB-em.d.cts → index-BAiq0hu3.d.cts} +3 -2
  20. package/dist/{index-G5DECNb_.d.ts → index-DF5J9nRH.d.ts} +3 -2
  21. package/dist/index.cjs +27 -3
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +17 -9
  24. package/dist/index.d.ts +17 -9
  25. package/dist/index.js +30 -6
  26. package/dist/index.js.map +1 -1
  27. package/dist/pg.cjs +344 -4
  28. package/dist/pg.cjs.map +1 -1
  29. package/dist/pg.d.cts +10 -9
  30. package/dist/pg.d.ts +10 -9
  31. package/dist/pg.js +350 -10
  32. package/dist/pg.js.map +1 -1
  33. package/dist/{pongoCollectionSchemaComponent-t_e9n2Wc.d.ts → pongoCollectionSchemaComponent-BhsINgDe.d.cts} +44 -34
  34. package/dist/{pongoCollectionSchemaComponent-t_e9n2Wc.d.cts → pongoCollectionSchemaComponent-BhsINgDe.d.ts} +44 -34
  35. package/dist/shim.cjs +12 -14
  36. package/dist/shim.cjs.map +1 -1
  37. package/dist/shim.d.cts +4 -4
  38. package/dist/shim.d.ts +4 -4
  39. package/dist/shim.js +7 -9
  40. package/dist/shim.js.map +1 -1
  41. package/dist/sqlite3.cjs +21 -26
  42. package/dist/sqlite3.cjs.map +1 -1
  43. package/dist/sqlite3.d.cts +6 -6
  44. package/dist/sqlite3.d.ts +6 -6
  45. package/dist/sqlite3.js +20 -25
  46. package/dist/sqlite3.js.map +1 -1
  47. package/package.json +50 -36
  48. package/dist/chunk-4BL6YWLW.cjs.map +0 -1
  49. package/dist/chunk-ECQ2CKZE.cjs.map +0 -1
  50. package/dist/chunk-EYQDS752.js +0 -364
  51. package/dist/chunk-EYQDS752.js.map +0 -1
  52. package/dist/chunk-NCNRRYVE.js.map +0 -1
  53. package/dist/chunk-WH26IXHN.js +0 -10
  54. package/dist/chunk-WH26IXHN.js.map +0 -1
  55. package/dist/chunk-WKW4LGF6.cjs +0 -10
  56. package/dist/chunk-WKW4LGF6.cjs.map +0 -1
  57. package/dist/chunk-Y7LRKJLJ.js.map +0 -1
  58. package/dist/chunk-ZPWKWNK2.cjs +0 -364
  59. package/dist/chunk-ZPWKWNK2.cjs.map +0 -1
  60. package/dist/d1.cjs +0 -54
  61. package/dist/d1.cjs.map +0 -1
  62. package/dist/d1.d.cts +0 -11
  63. package/dist/d1.d.ts +0 -11
  64. package/dist/d1.js.map +0 -1
  65. package/dist/pg-73DOKU64.js +0 -11
  66. package/dist/pg-73DOKU64.js.map +0 -1
  67. package/dist/pg-I267A7IL.cjs +0 -11
  68. package/dist/pg-I267A7IL.cjs.map +0 -1
@@ -3,12 +3,10 @@
3
3
 
4
4
 
5
5
 
6
+
6
7
  var _dumbo = require('@event-driven-io/dumbo');
7
8
  var _uuid = require('uuid');
8
9
 
9
- // src/core/collection/pongoCollectionSchema.ts
10
-
11
-
12
10
  // src/core/collection/pongoCollectionSchemaComponent.ts
13
11
 
14
12
 
@@ -52,6 +50,9 @@ var isOperator = (key) => key.startsWith("$");
52
50
  var hasOperators = (value) => Object.keys(value).some(isOperator);
53
51
 
54
52
  // src/core/database/pongoDatabaseCache.ts
53
+
54
+
55
+
55
56
  var PongoDatabaseCache = ({
56
57
  driver,
57
58
  typedSchema
@@ -60,7 +61,10 @@ var PongoDatabaseCache = ({
60
61
  const getDatabaseDefinition = (dbName) => Object.values(_nullishCoalesce(_optionalChain([typedSchema, 'optionalAccess', _ => _.dbs]), () => ( {}))).find((d) => d.name === dbName);
61
62
  return {
62
63
  getOrCreate: (createOptions) => {
63
- const dbName = _nullishCoalesce(createOptions.databaseName, () => ( (driver.getDatabaseNameOrDefault ? driver.getDatabaseNameOrDefault(createOptions) : "db:default")));
64
+ const metadata = _dumbo.getDatabaseMetadata.call(void 0, driver.driverType);
65
+ const dbName = _nullishCoalesce(_nullishCoalesce(createOptions.databaseName, () => ( _optionalChain([metadata, 'optionalAccess', _2 => _2.parseDatabaseName, 'optionalCall', _3 => _3(
66
+ "connectionString" in createOptions ? createOptions.connectionString : void 0
67
+ )]))), () => ( "db:default"));
64
68
  const existing = dbClients.get(dbName);
65
69
  if (existing) return existing;
66
70
  const definition = getDatabaseDefinition(createOptions.databaseName);
@@ -95,9 +99,6 @@ var objectEntries = (obj) => Object.entries(obj).map(([key, value]) => [key, val
95
99
  // src/core/typing/operations.ts
96
100
 
97
101
 
98
-
99
-
100
-
101
102
  // src/core/errors/index.ts
102
103
  var isNumber = (val) => typeof val === "number" && val === val;
103
104
  var isString = (val) => typeof val === "string";
@@ -141,11 +142,11 @@ var operationResult = (result, options) => {
141
142
  const { operationName, collectionName } = options;
142
143
  if (!successful)
143
144
  throw new ConcurrencyError(
144
- _nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${_dumbo.JSONSerializer.serialize(result)}!`))
145
+ _nullishCoalesce(errorMessage, () => ( `${operationName} on ${collectionName} failed. Expected document state does not match current one! Result: ${options.serializer.serialize(result)}!`))
145
146
  );
146
147
  }
147
148
  };
148
- if (_optionalChain([options, 'access', _2 => _2.errors, 'optionalAccess', _3 => _3.throwOnOperationFailures]))
149
+ if (_optionalChain([options, 'access', _4 => _4.errors, 'optionalAccess', _5 => _5.throwOnOperationFailures]))
149
150
  operationResult2.assertSuccessful();
150
151
  return operationResult2;
151
152
  };
@@ -203,7 +204,7 @@ var proxyClientWithSchema = (client, schema) => {
203
204
  client,
204
205
  {
205
206
  get(target, prop) {
206
- if (dbNames.includes(prop)) return client.db(_optionalChain([schema, 'access', _4 => _4.dbs, 'access', _5 => _5[prop], 'optionalAccess', _6 => _6.name]));
207
+ if (dbNames.includes(prop)) return client.db(_optionalChain([schema, 'access', _6 => _6.dbs, 'access', _7 => _7[prop], 'optionalAccess', _8 => _8.name]));
207
208
  return target[prop];
208
209
  }
209
210
  }
@@ -257,11 +258,12 @@ var PongoDatabaseSchemaComponent = ({
257
258
 
258
259
 
259
260
  var PongoDatabase = (options) => {
260
- const { databaseName, schemaComponent: schemaComponent3, pool } = options;
261
+ const { databaseName, schemaComponent: schemaComponent3, pool, serializer } = options;
261
262
  const collections = /* @__PURE__ */ new Map();
262
- const command = async (sql, options2) => (await transactionExecutorOrDefault(db, options2, pool.execute)).command(sql);
263
+ const command = async (sql, options2) => (await transactionExecutorOrDefault(db, options2, pool.execute)).command(sql, options2);
263
264
  const query = async (sql, options2) => (await transactionExecutorOrDefault(db, options2, pool.execute)).query(
264
- sql
265
+ sql,
266
+ options2
265
267
  );
266
268
  const driverType = pool.driverType;
267
269
  const db = {
@@ -270,21 +272,22 @@ var PongoDatabase = (options) => {
270
272
  connect: () => Promise.resolve(),
271
273
  close: () => pool.close(),
272
274
  collections: () => [...collections.values()],
273
- collection: (collectionName) => _nullishCoalesce(collections.get(collectionName), () => ( pongoCollection({
275
+ collection: (collectionName, collectionOptions) => _nullishCoalesce(collections.get(collectionName), () => ( pongoCollection({
274
276
  collectionName,
275
277
  db,
276
278
  pool,
277
279
  schemaComponent: schemaComponent3.collection(
278
280
  pongoSchema.collection(collectionName)
279
281
  ),
280
- schema: options.schema ? options.schema : {},
281
- errors: options.errors ? options.errors : {}
282
+ schema: { ...options.schema, ..._optionalChain([collectionOptions, 'optionalAccess', _9 => _9.schema]) },
283
+ serializer,
284
+ errors: { ...options.errors, ..._optionalChain([collectionOptions, 'optionalAccess', _10 => _10.errors]) }
282
285
  }))),
283
286
  transaction: () => pool.transaction(),
284
287
  withTransaction: (handle) => pool.withTransaction(handle),
285
288
  schema: {
286
289
  component: schemaComponent3,
287
- migrate: () => _dumbo.runSQLMigrations.call(void 0, pool, schemaComponent3.migrations)
290
+ migrate: (options2) => _dumbo.runSQLMigrations.call(void 0, pool, schemaComponent3.migrations, options2)
288
291
  },
289
292
  sql: {
290
293
  async query(sql, options2) {
@@ -296,7 +299,7 @@ var PongoDatabase = (options) => {
296
299
  }
297
300
  }
298
301
  };
299
- const dbSchema = _optionalChain([options, 'optionalAccess', _7 => _7.schema, 'optionalAccess', _8 => _8.definition]);
302
+ const dbSchema = _optionalChain([options, 'optionalAccess', _11 => _11.schema, 'optionalAccess', _12 => _12.definition]);
300
303
  if (dbSchema) {
301
304
  return proxyPongoDbWithSchema(db, dbSchema, collections);
302
305
  }
@@ -304,7 +307,7 @@ var PongoDatabase = (options) => {
304
307
  };
305
308
 
306
309
  // src/core/drivers/databaseDriver.ts
307
- var PongoDatabaseDriverRegistry = () => {
310
+ var PongoDriverRegistry = () => {
308
311
  const drivers = /* @__PURE__ */ new Map();
309
312
  const register = (driverType, driver) => {
310
313
  const entry = drivers.get(driverType);
@@ -336,7 +339,10 @@ var PongoDatabaseDriverRegistry = () => {
336
339
  }
337
340
  };
338
341
  };
339
- var pongoDatabaseDriverRegistry = globalThis.pongoDatabaseDriverRegistry = _nullishCoalesce(globalThis.pongoDatabaseDriverRegistry, () => ( PongoDatabaseDriverRegistry()));
342
+ var pongoDriverRegistry = globalThis.pongoDriverRegistry = _nullishCoalesce(globalThis.pongoDriverRegistry, () => ( PongoDriverRegistry()));
343
+
344
+ // src/core/pongoClient.ts
345
+
340
346
 
341
347
  // src/core/pongoTransaction.ts
342
348
  var pongoTransaction = (options) => {
@@ -388,7 +394,7 @@ var pongoTransaction = (options) => {
388
394
  };
389
395
 
390
396
  // src/core/pongoSession.ts
391
- var isActive = (transaction) => _optionalChain([transaction, 'optionalAccess', _9 => _9.isActive]) === true;
397
+ var isActive = (transaction) => _optionalChain([transaction, 'optionalAccess', _13 => _13.isActive]) === true;
392
398
  function assertInActiveTransaction(transaction) {
393
399
  if (!isActive(transaction)) throw new Error("No active transaction exists!");
394
400
  }
@@ -397,8 +403,8 @@ function assertNotInActiveTransaction(transaction) {
397
403
  throw new Error("Active transaction already exists!");
398
404
  }
399
405
  var pongoSession = (options) => {
400
- const explicit = _optionalChain([options, 'optionalAccess', _10 => _10.explicit]) === true;
401
- const defaultTransactionOptions = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.defaultTransactionOptions]), () => ( {
406
+ const explicit = _optionalChain([options, 'optionalAccess', _14 => _14.explicit]) === true;
407
+ const defaultTransactionOptions = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _15 => _15.defaultTransactionOptions]), () => ( {
402
408
  get snapshotEnabled() {
403
409
  return false;
404
410
  }
@@ -465,8 +471,9 @@ var pongoClient = (options) => {
465
471
  const { driver, schema, errors, ...connectionOptions } = options;
466
472
  const dbClients = PongoDatabaseCache({
467
473
  driver,
468
- typedSchema: _optionalChain([schema, 'optionalAccess', _12 => _12.definition])
474
+ typedSchema: _optionalChain([schema, 'optionalAccess', _16 => _16.definition])
469
475
  });
476
+ const serializer = _dumbo.JSONSerializer.from(options);
470
477
  const pongoClient2 = {
471
478
  driverType: driver.driverType,
472
479
  connect: async () => {
@@ -480,6 +487,7 @@ var pongoClient = (options) => {
480
487
  const db = dbClients.getOrCreate({
481
488
  ...connectionOptions,
482
489
  databaseName: dbName,
490
+ serializer,
483
491
  errors
484
492
  });
485
493
  return db;
@@ -494,7 +502,7 @@ var pongoClient = (options) => {
494
502
  }
495
503
  }
496
504
  };
497
- return proxyClientWithSchema(pongoClient2, _optionalChain([schema, 'optionalAccess', _13 => _13.definition]));
505
+ return proxyClientWithSchema(pongoClient2, _optionalChain([schema, 'optionalAccess', _17 => _17.definition]));
498
506
  };
499
507
 
500
508
  // src/core/utils/deepEquals.ts
@@ -529,20 +537,13 @@ var isEquatable = (left) => {
529
537
 
530
538
  // src/core/collection/pongoCollection.ts
531
539
  var enlistIntoTransactionIfActive = async (db, options) => {
532
- const transaction = _optionalChain([options, 'optionalAccess', _14 => _14.session, 'optionalAccess', _15 => _15.transaction]);
540
+ const transaction = _optionalChain([options, 'optionalAccess', _18 => _18.session, 'optionalAccess', _19 => _19.transaction]);
533
541
  if (!transaction || !transaction.isActive) return null;
534
542
  return await transaction.enlistDatabase(db);
535
543
  };
536
544
  var transactionExecutorOrDefault = async (db, options, defaultSqlExecutor) => {
537
545
  const existingTransaction = await enlistIntoTransactionIfActive(db, options);
538
- return _nullishCoalesce(_optionalChain([existingTransaction, 'optionalAccess', _16 => _16.execute]), () => ( defaultSqlExecutor));
539
- };
540
- var columnMapping = {
541
- mapping: {
542
- ..._dumbo.mapColumnToJSON.call(void 0, "data")
543
- //...mapColumnToJSON('metadata'),
544
- //...mapColumnToBigint('_version'),
545
- }
546
+ return _nullishCoalesce(_optionalChain([existingTransaction, 'optionalAccess', _20 => _20.execute]), () => ( defaultSqlExecutor));
546
547
  };
547
548
  var pongoCollection = ({
548
549
  db,
@@ -550,19 +551,27 @@ var pongoCollection = ({
550
551
  pool,
551
552
  schemaComponent: schemaComponent3,
552
553
  schema,
553
- errors
554
+ errors,
555
+ serializer
554
556
  }) => {
555
557
  const SqlFor = schemaComponent3.sqlBuilder;
556
558
  const sqlExecutor = pool.execute;
557
- const command = async (sql, options) => (await transactionExecutorOrDefault(db, options, sqlExecutor)).command(sql);
559
+ const columnMapping = {
560
+ mapping: {
561
+ ..._dumbo.mapColumnToJSON.call(void 0, "data", serializer),
562
+ //...mapColumnToJSON('metadata'),
563
+ ..._dumbo.mapColumnToBigint.call(void 0, "_version")
564
+ }
565
+ };
566
+ const command = async (sql, options) => (await transactionExecutorOrDefault(db, options, sqlExecutor)).command(sql, columnMapping);
558
567
  const query = async (sql, options) => (await transactionExecutorOrDefault(db, options, sqlExecutor)).query(
559
568
  sql,
560
569
  columnMapping
561
570
  );
562
- let shouldMigrate = _optionalChain([schema, 'optionalAccess', _17 => _17.autoMigration]) !== "None";
571
+ let shouldMigrate = _optionalChain([schema, 'optionalAccess', _21 => _21.autoMigration]) !== "None";
563
572
  const createCollection = (options) => {
564
573
  shouldMigrate = false;
565
- if (_optionalChain([options, 'optionalAccess', _18 => _18.session])) return command(SqlFor.createCollection(), options);
574
+ if (_optionalChain([options, 'optionalAccess', _22 => _22.session])) return command(SqlFor.createCollection(), options);
566
575
  else return command(SqlFor.createCollection());
567
576
  };
568
577
  const ensureCollectionCreated = (options) => {
@@ -571,6 +580,8 @@ var pongoCollection = ({
571
580
  }
572
581
  return createCollection(options);
573
582
  };
583
+ const upcast = _nullishCoalesce(_optionalChain([schema, 'optionalAccess', _23 => _23.versioning, 'optionalAccess', _24 => _24.upcast]), () => ( ((doc) => doc)));
584
+ const downcast = _nullishCoalesce(_optionalChain([schema, 'optionalAccess', _25 => _25.versioning, 'optionalAccess', _26 => _26.downcast]), () => ( ((doc) => doc)));
574
585
  const collection = {
575
586
  dbName: db.databaseName,
576
587
  collectionName,
@@ -581,9 +592,10 @@ var pongoCollection = ({
581
592
  await ensureCollectionCreated(options);
582
593
  const _id = _nullishCoalesce(document._id, () => ( _uuid.v7.call(void 0, )));
583
594
  const _version = _nullishCoalesce(document._version, () => ( 1n));
595
+ const downcasted = downcast(document);
584
596
  const result = await command(
585
597
  SqlFor.insertOne({
586
- ...document,
598
+ ...downcasted,
587
599
  _id,
588
600
  _version
589
601
  }),
@@ -596,18 +608,23 @@ var pongoCollection = ({
596
608
  insertedId: successful ? _id : null,
597
609
  nextExpectedVersion: _version
598
610
  },
599
- { operationName: "insertOne", collectionName, errors }
611
+ { operationName: "insertOne", collectionName, serializer, errors }
600
612
  );
601
613
  },
602
614
  insertMany: async (documents, options) => {
603
615
  await ensureCollectionCreated(options);
604
- const rows = documents.map((doc) => ({
605
- ...doc,
606
- _id: _nullishCoalesce(doc._id, () => ( _uuid.v7.call(void 0, ))),
607
- _version: _nullishCoalesce(doc._version, () => ( 1n))
608
- }));
616
+ const rows = documents.map((doc) => {
617
+ const downcasted = downcast(doc);
618
+ return {
619
+ ...downcasted,
620
+ _id: _nullishCoalesce(doc._id, () => ( _uuid.v7.call(void 0, ))),
621
+ _version: _nullishCoalesce(doc._version, () => ( 1n))
622
+ };
623
+ });
609
624
  const result = await command(
610
- SqlFor.insertMany(rows),
625
+ SqlFor.insertMany(
626
+ rows
627
+ ),
611
628
  options
612
629
  );
613
630
  return operationResult(
@@ -616,7 +633,7 @@ var pongoCollection = ({
616
633
  insertedCount: _nullishCoalesce(result.rowCount, () => ( 0)),
617
634
  insertedIds: result.rows.map((d) => d._id)
618
635
  },
619
- { operationName: "insertMany", collectionName, errors }
636
+ { operationName: "insertMany", collectionName, serializer, errors }
620
637
  );
621
638
  },
622
639
  updateOne: async (filter, update, options) => {
@@ -628,27 +645,28 @@ var pongoCollection = ({
628
645
  return operationResult(
629
646
  {
630
647
  successful: result.rows.length > 0 && result.rows[0].modified === result.rows[0].matched,
631
- modifiedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _19 => _19.rows, 'access', _20 => _20[0], 'optionalAccess', _21 => _21.modified]), () => ( 0))),
632
- matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _22 => _22.rows, 'access', _23 => _23[0], 'optionalAccess', _24 => _24.matched]), () => ( 0))),
633
- nextExpectedVersion: BigInt(_nullishCoalesce(_optionalChain([result, 'access', _25 => _25.rows, 'access', _26 => _26[0], 'optionalAccess', _27 => _27.version]), () => ( 0n)))
648
+ modifiedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _27 => _27.rows, 'access', _28 => _28[0], 'optionalAccess', _29 => _29.modified]), () => ( 0))),
649
+ matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _30 => _30.rows, 'access', _31 => _31[0], 'optionalAccess', _32 => _32.matched]), () => ( 0))),
650
+ nextExpectedVersion: BigInt(_nullishCoalesce(_optionalChain([result, 'access', _33 => _33.rows, 'access', _34 => _34[0], 'optionalAccess', _35 => _35.version]), () => ( 0n)))
634
651
  },
635
- { operationName: "updateOne", collectionName, errors }
652
+ { operationName: "updateOne", collectionName, serializer, errors }
636
653
  );
637
654
  },
638
655
  replaceOne: async (filter, document, options) => {
639
656
  await ensureCollectionCreated(options);
657
+ const downcasted = downcast(document);
640
658
  const result = await command(
641
- SqlFor.replaceOne(filter, document, options),
659
+ SqlFor.replaceOne(filter, downcasted, options),
642
660
  options
643
661
  );
644
662
  return operationResult(
645
663
  {
646
664
  successful: result.rows.length > 0 && result.rows[0].modified > 0,
647
- modifiedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _28 => _28.rows, 'access', _29 => _29[0], 'optionalAccess', _30 => _30.modified]), () => ( 0))),
648
- matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _31 => _31.rows, 'access', _32 => _32[0], 'optionalAccess', _33 => _33.matched]), () => ( 0))),
649
- nextExpectedVersion: BigInt(_nullishCoalesce(_optionalChain([result, 'access', _34 => _34.rows, 'access', _35 => _35[0], 'optionalAccess', _36 => _36.version]), () => ( 0n)))
665
+ modifiedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _36 => _36.rows, 'access', _37 => _37[0], 'optionalAccess', _38 => _38.modified]), () => ( 0))),
666
+ matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _39 => _39.rows, 'access', _40 => _40[0], 'optionalAccess', _41 => _41.matched]), () => ( 0))),
667
+ nextExpectedVersion: BigInt(_nullishCoalesce(_optionalChain([result, 'access', _42 => _42.rows, 'access', _43 => _43[0], 'optionalAccess', _44 => _44.version]), () => ( 0n)))
650
668
  },
651
- { operationName: "replaceOne", collectionName, errors }
669
+ { operationName: "replaceOne", collectionName, serializer, errors }
652
670
  );
653
671
  },
654
672
  updateMany: async (filter, update, options) => {
@@ -660,7 +678,7 @@ var pongoCollection = ({
660
678
  modifiedCount: _nullishCoalesce(result.rowCount, () => ( 0)),
661
679
  matchedCount: _nullishCoalesce(result.rowCount, () => ( 0))
662
680
  },
663
- { operationName: "updateMany", collectionName, errors }
681
+ { operationName: "updateMany", collectionName, serializer, errors }
664
682
  );
665
683
  },
666
684
  deleteOne: async (filter, options) => {
@@ -672,10 +690,10 @@ var pongoCollection = ({
672
690
  return operationResult(
673
691
  {
674
692
  successful: result.rows.length > 0 && result.rows[0].deleted > 0,
675
- deletedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _37 => _37.rows, 'access', _38 => _38[0], 'optionalAccess', _39 => _39.deleted]), () => ( 0))),
676
- matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _40 => _40.rows, 'access', _41 => _41[0], 'optionalAccess', _42 => _42.matched]), () => ( 0)))
693
+ deletedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _45 => _45.rows, 'access', _46 => _46[0], 'optionalAccess', _47 => _47.deleted]), () => ( 0))),
694
+ matchedCount: Number(_nullishCoalesce(_optionalChain([result, 'access', _48 => _48.rows, 'access', _49 => _49[0], 'optionalAccess', _50 => _50.matched]), () => ( 0)))
677
695
  },
678
- { operationName: "deleteOne", collectionName, errors }
696
+ { operationName: "deleteOne", collectionName, serializer, errors }
679
697
  );
680
698
  },
681
699
  deleteMany: async (filter, options) => {
@@ -687,13 +705,21 @@ var pongoCollection = ({
687
705
  deletedCount: _nullishCoalesce(result.rowCount, () => ( 0)),
688
706
  matchedCount: _nullishCoalesce(result.rowCount, () => ( 0))
689
707
  },
690
- { operationName: "deleteMany", collectionName, errors }
708
+ { operationName: "deleteMany", collectionName, serializer, errors }
691
709
  );
692
710
  },
693
711
  findOne: async (filter, options) => {
694
712
  await ensureCollectionCreated(options);
695
- const result = await query(SqlFor.findOne(_nullishCoalesce(filter, () => ( {}))), options);
696
- return _nullishCoalesce(_optionalChain([result, 'access', _43 => _43.rows, 'access', _44 => _44[0], 'optionalAccess', _45 => _45.data]), () => ( null));
713
+ const result = await query(
714
+ SqlFor.findOne(_nullishCoalesce(filter, () => ( {}))),
715
+ options
716
+ );
717
+ const row = result.rows[0];
718
+ if (row === void 0 || row === null) return null;
719
+ return upcast({
720
+ ...row.data,
721
+ _version: row._version
722
+ });
697
723
  },
698
724
  findOneAndDelete: async (filter, options) => {
699
725
  await ensureCollectionCreated(options);
@@ -731,7 +757,7 @@ var pongoCollection = ({
731
757
  successful: false,
732
758
  document: existing
733
759
  },
734
- { operationName: "handle", collectionName, errors }
760
+ { operationName: "handle", collectionName, serializer, errors }
735
761
  );
736
762
  }
737
763
  const result = await handle(
@@ -743,7 +769,7 @@ var pongoCollection = ({
743
769
  successful: true,
744
770
  document: existing
745
771
  },
746
- { operationName: "handle", collectionName, errors }
772
+ { operationName: "handle", collectionName, serializer, errors }
747
773
  );
748
774
  if (!existing && result) {
749
775
  const newDoc = { ...result, _id: id };
@@ -787,13 +813,20 @@ var pongoCollection = ({
787
813
  successful: true,
788
814
  document: existing
789
815
  },
790
- { operationName: "handle", collectionName, errors }
816
+ { operationName: "handle", collectionName, serializer, errors }
791
817
  );
792
818
  },
793
819
  find: async (filter, options) => {
794
820
  await ensureCollectionCreated(options);
795
- const result = await query(SqlFor.find(_nullishCoalesce(filter, () => ( {})), options));
796
- return result.rows.map((row) => row.data);
821
+ const result = await query(
822
+ SqlFor.find(_nullishCoalesce(filter, () => ( {})), options)
823
+ );
824
+ return result.rows.map(
825
+ (row) => upcast({
826
+ ...row.data,
827
+ _version: row._version
828
+ })
829
+ );
797
830
  },
798
831
  countDocuments: async (filter, options) => {
799
832
  await ensureCollectionCreated(options);
@@ -805,7 +838,7 @@ var pongoCollection = ({
805
838
  drop: async (options) => {
806
839
  await ensureCollectionCreated(options);
807
840
  const result = await command(SqlFor.drop());
808
- return (_nullishCoalesce(_optionalChain([result, 'optionalAccess', _46 => _46.rowCount]), () => ( 0))) > 0;
841
+ return (_nullishCoalesce(_optionalChain([result, 'optionalAccess', _51 => _51.rowCount]), () => ( 0))) > 0;
809
842
  },
810
843
  rename: async (newName, options) => {
811
844
  await ensureCollectionCreated(options);
@@ -826,7 +859,7 @@ var pongoCollection = ({
826
859
  },
827
860
  schema: {
828
861
  component: schemaComponent3,
829
- migrate: () => _dumbo.runSQLMigrations.call(void 0, pool, schemaComponent3.migrations)
862
+ migrate: (options) => _dumbo.runSQLMigrations.call(void 0, pool, schemaComponent3.migrations, options)
830
863
  }
831
864
  };
832
865
  return collection;
@@ -868,5 +901,5 @@ var pongoCollection = ({
868
901
 
869
902
 
870
903
 
871
- exports.transactionExecutorOrDefault = transactionExecutorOrDefault; exports.pongoCollection = pongoCollection; exports.PongoCollectionSchemaComponent = PongoCollectionSchemaComponent; exports.QueryOperators = QueryOperators; exports.OperatorMap = OperatorMap; exports.isOperator = isOperator; exports.hasOperators = hasOperators; exports.PongoDatabaseCache = PongoDatabaseCache; exports.objectEntries = objectEntries; exports.isNumber = isNumber; exports.isString = isString; exports.PongoError = PongoError; exports.ConcurrencyError = ConcurrencyError; exports.ObjectId = ObjectId; exports.DOCUMENT_EXISTS = DOCUMENT_EXISTS; exports.DOCUMENT_DOES_NOT_EXIST = DOCUMENT_DOES_NOT_EXIST; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.isGeneralExpectedDocumentVersion = isGeneralExpectedDocumentVersion; exports.expectedVersionValue = expectedVersionValue; exports.expectedVersion = expectedVersion; exports.operationResult = operationResult; exports.pongoSchema = pongoSchema; exports.proxyPongoDbWithSchema = proxyPongoDbWithSchema; exports.proxyClientWithSchema = proxyClientWithSchema; exports.toDbSchemaMetadata = toDbSchemaMetadata; exports.toClientSchemaMetadata = toClientSchemaMetadata; exports.PongoDatabaseSchemaComponent = PongoDatabaseSchemaComponent; exports.PongoDatabase = PongoDatabase; exports.PongoDatabaseDriverRegistry = PongoDatabaseDriverRegistry; exports.pongoDatabaseDriverRegistry = pongoDatabaseDriverRegistry; exports.pongoTransaction = pongoTransaction; exports.pongoSession = pongoSession; exports.pongoClient = pongoClient; exports.deepEquals = deepEquals; exports.isEquatable = isEquatable;
872
- //# sourceMappingURL=chunk-4BL6YWLW.cjs.map
904
+ exports.transactionExecutorOrDefault = transactionExecutorOrDefault; exports.pongoCollection = pongoCollection; exports.PongoCollectionSchemaComponent = PongoCollectionSchemaComponent; exports.QueryOperators = QueryOperators; exports.OperatorMap = OperatorMap; exports.isOperator = isOperator; exports.hasOperators = hasOperators; exports.PongoDatabaseCache = PongoDatabaseCache; exports.objectEntries = objectEntries; exports.isNumber = isNumber; exports.isString = isString; exports.PongoError = PongoError; exports.ConcurrencyError = ConcurrencyError; exports.ObjectId = ObjectId; exports.DOCUMENT_EXISTS = DOCUMENT_EXISTS; exports.DOCUMENT_DOES_NOT_EXIST = DOCUMENT_DOES_NOT_EXIST; exports.NO_CONCURRENCY_CHECK = NO_CONCURRENCY_CHECK; exports.isGeneralExpectedDocumentVersion = isGeneralExpectedDocumentVersion; exports.expectedVersionValue = expectedVersionValue; exports.expectedVersion = expectedVersion; exports.operationResult = operationResult; exports.pongoSchema = pongoSchema; exports.proxyPongoDbWithSchema = proxyPongoDbWithSchema; exports.proxyClientWithSchema = proxyClientWithSchema; exports.toDbSchemaMetadata = toDbSchemaMetadata; exports.toClientSchemaMetadata = toClientSchemaMetadata; exports.PongoDatabaseSchemaComponent = PongoDatabaseSchemaComponent; exports.PongoDatabase = PongoDatabase; exports.PongoDriverRegistry = PongoDriverRegistry; exports.pongoDriverRegistry = pongoDriverRegistry; exports.pongoTransaction = pongoTransaction; exports.pongoSession = pongoSession; exports.pongoClient = pongoClient; exports.deepEquals = deepEquals; exports.isEquatable = isEquatable;
905
+ //# sourceMappingURL=chunk-BZRKCNRY.cjs.map