@event-driven-io/pongo 0.17.0-beta.32 → 0.17.0-beta.34

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 (46) hide show
  1. package/dist/{chunk-TTZGGAZV.js → chunk-OJVG4KXA.js} +69 -2
  2. package/dist/chunk-OJVG4KXA.js.map +1 -0
  3. package/dist/chunk-TYTEQJBC.cjs +1583 -0
  4. package/dist/chunk-TYTEQJBC.cjs.map +1 -0
  5. package/dist/{chunk-H637RRXS.js → chunk-U4NNEXNH.js} +1310 -632
  6. package/dist/chunk-U4NNEXNH.js.map +1 -0
  7. package/dist/{chunk-A4DCNQJR.cjs → chunk-UP6HTRMM.cjs} +79 -12
  8. package/dist/chunk-UP6HTRMM.cjs.map +1 -0
  9. package/dist/cli.cjs +13 -13
  10. package/dist/cli.cjs.map +1 -1
  11. package/dist/cli.js +2 -2
  12. package/dist/cli.js.map +1 -1
  13. package/dist/cloudflare.cjs +10 -10
  14. package/dist/cloudflare.d.cts +3 -2
  15. package/dist/cloudflare.d.ts +3 -2
  16. package/dist/cloudflare.js +2 -2
  17. package/dist/{index-gHRYr05w.d.ts → index-DHszkVjP.d.ts} +1 -1
  18. package/dist/{index-DxHXL62G.d.cts → index-DLDCIBgH.d.cts} +1 -1
  19. package/dist/index.cjs +26 -2
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +38 -16
  22. package/dist/index.d.ts +38 -16
  23. package/dist/index.js +25 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/pg.cjs +102 -16
  26. package/dist/pg.cjs.map +1 -1
  27. package/dist/pg.d.cts +2 -1
  28. package/dist/pg.d.ts +2 -1
  29. package/dist/pg.js +87 -1
  30. package/dist/pg.js.map +1 -1
  31. package/dist/{pongoCollectionSchemaComponent-B5Oatwu0.d.cts → pongoTransactionCache-BsigBOq1.d.cts} +154 -34
  32. package/dist/{pongoCollectionSchemaComponent-B5Oatwu0.d.ts → pongoTransactionCache-BsigBOq1.d.ts} +154 -34
  33. package/dist/shim.cjs +5 -5
  34. package/dist/shim.d.cts +2 -1
  35. package/dist/shim.d.ts +2 -1
  36. package/dist/shim.js +1 -1
  37. package/dist/sqlite3.cjs +10 -10
  38. package/dist/sqlite3.d.cts +3 -2
  39. package/dist/sqlite3.d.ts +3 -2
  40. package/dist/sqlite3.js +2 -2
  41. package/package.json +20 -18
  42. package/dist/chunk-A4DCNQJR.cjs.map +0 -1
  43. package/dist/chunk-BZRKCNRY.cjs +0 -905
  44. package/dist/chunk-BZRKCNRY.cjs.map +0 -1
  45. package/dist/chunk-H637RRXS.js.map +0 -1
  46. package/dist/chunk-TTZGGAZV.js.map +0 -1
@@ -1,4 +1,69 @@
1
- import { DatabaseDriverType, SchemaComponent, JSONSerializationOptions, MigrationStyle, JSONSerializer, WithDatabaseTransactionFactory, AnyConnection, DatabaseTransaction, SQLExecutor, SQL, RunSQLMigrationsResult, QueryResultRow, QueryResult, SQLQueryOptions, SQLCommandOptions, SchemaComponentOptions } from '@event-driven-io/dumbo';
1
+ import { JSONSerializer, SQL, SchemaComponent, DatabaseDriverType, SchemaComponentOptions, JSONSerializationOptions, MigrationStyle, WithDatabaseTransactionFactory, AnyConnection, DatabaseTransaction, SQLExecutor, RunSQLMigrationsResult, QueryResultRow, QueryResult, SQLQueryOptions, SQLCommandOptions } from '@event-driven-io/dumbo';
2
+ import { LRUCache } from 'lru-cache';
3
+
4
+ type DocumentCommandHandlerOptions<T extends PongoDocument> = {
5
+ collectionName: string;
6
+ serializer: JSONSerializer;
7
+ errors?: {
8
+ throwOnOperationFailures?: boolean;
9
+ } | undefined;
10
+ storage: {
11
+ ensureCollectionCreated: (options?: CollectionOperationOptions) => Promise<unknown>;
12
+ fetchByIds: (ids: string[], options?: CollectionOperationOptions) => Promise<(WithIdAndVersion<T> | null)[]>;
13
+ insertMany: (docs: OptionalUnlessRequiredIdAndVersion<T>[], options?: CollectionOperationOptions) => Promise<PongoInsertManyResult>;
14
+ replaceMany: (docs: Array<WithIdAndVersion<T>>, options?: CollectionOperationOptions) => Promise<PongoReplaceManyResult>;
15
+ deleteManyByIds: (ids: Array<{
16
+ _id: string;
17
+ _version?: bigint;
18
+ }>, options?: CollectionOperationOptions) => Promise<PongoDeleteResult & {
19
+ deletedIds: Set<string>;
20
+ }>;
21
+ };
22
+ };
23
+ type DocumentCommandHandlerInput = {
24
+ _id: string;
25
+ expectedVersion?: ExpectedDocumentVersion;
26
+ };
27
+ declare function DocumentCommandHandler<T extends PongoDocument>(deps: DocumentCommandHandlerOptions<T>): {
28
+ (id: string | DocumentCommandHandlerInput, handler: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
29
+ (ids: string[] | DocumentCommandHandlerInput[], handler: DocumentHandler<T>, options?: HandleOptions & BatchHandleOptions): Promise<PongoHandleResult<T>[]>;
30
+ };
31
+
32
+ type PongoCollectionSQLBuilder = {
33
+ createCollection: () => SQL;
34
+ insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
35
+ insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
36
+ updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
37
+ replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
38
+ updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
39
+ deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
40
+ deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
41
+ replaceMany: <T>(documents: Array<WithIdAndVersion<T> | WithId<T>>) => SQL;
42
+ deleteManyByIds: (ids: Array<{
43
+ _id: string;
44
+ _version?: bigint;
45
+ }>) => SQL;
46
+ findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
47
+ find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
48
+ countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
49
+ rename: (newName: string) => SQL;
50
+ drop: () => SQL;
51
+ };
52
+
53
+ type PongoCollectionURNType = 'sc:pongo:collection';
54
+ type PongoCollectionURN = `${PongoCollectionURNType}:${string}`;
55
+ type PongoCollectionSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType> = Readonly<{
56
+ driverType: DriverType;
57
+ definition: PongoCollectionSchema;
58
+ migrationsOrSchemaComponents: SchemaComponentOptions;
59
+ sqlBuilder: PongoCollectionSQLBuilder;
60
+ }>;
61
+ type PongoCollectionSchemaComponent = SchemaComponent<PongoCollectionURN> & {
62
+ collectionName: string;
63
+ definition: PongoCollectionSchema;
64
+ sqlBuilder: PongoCollectionSQLBuilder;
65
+ };
66
+ declare const PongoCollectionSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({ definition, migrationsOrSchemaComponents, sqlBuilder, }: PongoCollectionSchemaComponentOptions<DriverType>) => PongoCollectionSchemaComponent;
2
67
 
3
68
  interface PongoCollectionSchema<T extends PongoDocument = PongoDocument> {
4
69
  name: string;
@@ -82,6 +147,7 @@ type PongoDatabaseFactoryOptions<CollectionsSchema extends Record<string, PongoC
82
147
  errors?: {
83
148
  throwOnOperationFailures?: boolean;
84
149
  } | undefined;
150
+ cache?: CacheConfig | 'disabled' | PongoCache | undefined;
85
151
  } & DriverOptions;
86
152
  interface PongoDriver<Database extends AnyPongoDb = AnyPongoDb, DriverOptions extends AnyPongoDriverOptions = AnyPongoDriverOptions> {
87
153
  driverType: Database['driverType'];
@@ -112,7 +178,7 @@ interface PongoClient<DriverType extends DatabaseDriverType = DatabaseDriverType
112
178
  driverType: DriverType;
113
179
  connect(): Promise<this>;
114
180
  close(): Promise<void>;
115
- db(dbName?: string): Database;
181
+ db(dbName?: string, options?: PongoDbOptions): Database;
116
182
  startSession(): PongoSession<DriverType>;
117
183
  withSession<T = unknown>(callback: (session: PongoSession<DriverType>) => Promise<T>): Promise<T>;
118
184
  }
@@ -125,6 +191,7 @@ type PongoClientOptions<DatabaseDriver extends AnyPongoDriver = AnyPongoDriver,
125
191
  errors?: {
126
192
  throwOnOperationFailures?: boolean;
127
193
  } | undefined;
194
+ cache?: CacheConfig | PongoCache | undefined;
128
195
  } & JSONSerializationOptions & Omit<Options, 'driver'> : never : never;
129
196
  declare interface PongoTransactionOptions {
130
197
  get snapshotEnabled(): boolean;
@@ -136,6 +203,7 @@ interface PongoDbTransaction<DriverType extends DatabaseDriverType = DatabaseDri
136
203
  enlistDatabase: (database: Database) => Promise<DatabaseTransaction<AnyConnection>>;
137
204
  commit: () => Promise<void>;
138
205
  rollback: (error?: unknown) => Promise<void>;
206
+ get cache(): PongoTransactionCache | null;
139
207
  get sqlExecutor(): SQLExecutor;
140
208
  get isStarting(): boolean;
141
209
  get isActive(): boolean;
@@ -165,6 +233,10 @@ type PongoDBCollectionOptions<T extends PongoDocument, Payload extends PongoDocu
165
233
  errors?: {
166
234
  throwOnOperationFailures?: boolean;
167
235
  };
236
+ cache?: CacheConfig | 'disabled' | PongoCache;
237
+ };
238
+ type PongoDbOptions = {
239
+ cache?: CacheConfig | PongoCache;
168
240
  };
169
241
  interface PongoDb<DriverType extends DatabaseDriverType = DatabaseDriverType> extends WithDatabaseTransactionFactory<AnyConnection> {
170
242
  driverType: DriverType;
@@ -190,6 +262,7 @@ type PongoMigrationOptions = {
190
262
  };
191
263
  type CollectionOperationOptions = {
192
264
  session?: PongoSession;
265
+ skipCache?: boolean;
193
266
  };
194
267
  type InsertOneOptions = {
195
268
  expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
@@ -203,8 +276,9 @@ type UpdateOneOptions = {
203
276
  type UpdateManyOptions = {
204
277
  expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
205
278
  } & CollectionOperationOptions;
206
- type HandleOptions = {
207
- expectedVersion?: ExpectedDocumentVersion;
279
+ type HandleOptions = CollectionOperationOptions;
280
+ type BatchHandleOptions = {
281
+ parallel?: boolean;
208
282
  } & CollectionOperationOptions;
209
283
  type ReplaceOneOptions = {
210
284
  expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
@@ -212,6 +286,7 @@ type ReplaceOneOptions = {
212
286
  type DeleteOneOptions = {
213
287
  expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
214
288
  } & CollectionOperationOptions;
289
+ type ReplaceManyOptions = CollectionOperationOptions;
215
290
  type DeleteManyOptions = {
216
291
  expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
217
292
  } & CollectionOperationOptions;
@@ -238,11 +313,14 @@ interface PongoCollection<T extends PongoDocument> {
238
313
  countDocuments(filter?: PongoFilter<T> | SQL, options?: CollectionOperationOptions): Promise<number>;
239
314
  drop(options?: CollectionOperationOptions): Promise<boolean>;
240
315
  rename(newName: string, options?: CollectionOperationOptions): Promise<PongoCollection<T>>;
241
- handle(id: string, handle: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
316
+ handle(id: string | DocumentCommandHandlerInput, handle: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
317
+ handle(id: string[] | DocumentCommandHandlerInput[], handle: DocumentHandler<T>, options?: BatchHandleOptions): Promise<PongoHandleResult<T>[]>;
318
+ replaceMany(documents: Array<WithId<T> | WithIdAndVersion<T>>, options?: ReplaceManyOptions): Promise<PongoReplaceManyResult>;
242
319
  readonly schema: Readonly<{
243
320
  component: PongoCollectionSchemaComponent;
244
321
  migrate(options?: PongoMigrationOptions): Promise<RunSQLMigrationsResult>;
245
322
  }>;
323
+ close: () => MaybePromise<void>;
246
324
  sql: {
247
325
  query<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<Result[]>;
248
326
  command<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<QueryResult<Result>>;
@@ -277,7 +355,7 @@ declare type WithVersion<TSchema> = EnhancedOmit<TSchema, '_version'> & {
277
355
  _version: bigint;
278
356
  };
279
357
  type WithoutVersion<T> = Omit<T, '_version'>;
280
- type WithIdAndVersion<T> = WithId<WithVersion<T>>;
358
+ type WithIdAndVersion<T> = WithId<T> & WithVersion<T>;
281
359
  type WithoutIdAndVersion<T> = WithoutId<WithoutVersion<T>>;
282
360
  /** @public */
283
361
  declare type RegExpOrString<T> = T extends string ? RegExp | T : T;
@@ -390,6 +468,13 @@ interface PongoDeleteResult extends OperationResult {
390
468
  interface PongoDeleteManyResult extends OperationResult {
391
469
  deletedCount: number;
392
470
  }
471
+ interface PongoReplaceManyResult extends OperationResult {
472
+ modifiedCount: number;
473
+ matchedCount: number;
474
+ modifiedIds: string[];
475
+ conflictIds: string[];
476
+ nextExpectedVersions: Map<string, bigint>;
477
+ }
393
478
  type PongoHandleResult<T> = (PongoInsertOneResult & {
394
479
  document: T;
395
480
  }) | (PongoUpdateResult & {
@@ -402,35 +487,70 @@ type PongoHandleResult<T> = (PongoInsertOneResult & {
402
487
  type PongoDocument = Record<string, unknown>;
403
488
  type DocumentHandler<T extends PongoDocument> = ((document: T | null) => T | null) | ((document: T | null) => Promise<T | null>);
404
489
 
405
- type PongoCollectionSQLBuilder = {
406
- createCollection: () => SQL;
407
- insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
408
- insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
409
- updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
410
- replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
411
- updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
412
- deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
413
- deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
414
- findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
415
- find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
416
- countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
417
- rename: (newName: string) => SQL;
418
- drop: () => SQL;
490
+ type MaybePromise<T> = T | PromiseLike<T>;
491
+
492
+ type LRUCacheOptions = Omit<LRUCache.Options<string, {
493
+ doc: PongoDocument | null;
494
+ }, unknown>, 'max'> & {
495
+ max?: number;
419
496
  };
497
+ declare const lruCache: (options?: LRUCacheOptions) => PongoCache;
420
498
 
421
- type PongoCollectionURNType = 'sc:pongo:collection';
422
- type PongoCollectionURN = `${PongoCollectionURNType}:${string}`;
423
- type PongoCollectionSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType> = Readonly<{
424
- driverType: DriverType;
425
- definition: PongoCollectionSchema;
426
- migrationsOrSchemaComponents: SchemaComponentOptions;
427
- sqlBuilder: PongoCollectionSQLBuilder;
428
- }>;
429
- type PongoCollectionSchemaComponent = SchemaComponent<PongoCollectionURN> & {
430
- collectionName: string;
431
- definition: PongoCollectionSchema;
432
- sqlBuilder: PongoCollectionSQLBuilder;
499
+ type PongoDocumentCacheKey = `${string}:${string}:${string}`;
500
+ type PongoCacheSetEntry<Doc extends PongoDocument = PongoDocument> = {
501
+ key: PongoDocumentCacheKey;
502
+ value: Doc | null;
433
503
  };
434
- declare const PongoCollectionSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({ definition, migrationsOrSchemaComponents, sqlBuilder, }: PongoCollectionSchemaComponentOptions<DriverType>) => PongoCollectionSchemaComponent;
504
+ type PongoCacheType<T extends string = string> = `pongo:cache:${T}`;
505
+ interface PongoCache<T extends string = string> {
506
+ cacheType: PongoCacheType<T>;
507
+ get<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey): MaybePromise<Doc | null | undefined>;
508
+ getMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[]): MaybePromise<(Doc | null | undefined)[]>;
509
+ set<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, value: Doc | null): MaybePromise<void>;
510
+ setMany(entries: PongoCacheSetEntry[]): MaybePromise<void>;
511
+ update<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, updater: PongoUpdate<Doc>): MaybePromise<void>;
512
+ updateMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[], updater: PongoUpdate<Doc>): MaybePromise<void>;
513
+ delete(key: PongoDocumentCacheKey): MaybePromise<void>;
514
+ deleteMany(keys: PongoDocumentCacheKey[]): MaybePromise<void>;
515
+ clear(): MaybePromise<void>;
516
+ close(): MaybePromise<void>;
517
+ }
518
+ type CacheHooks = {
519
+ onHit?(key: PongoDocumentCacheKey): void;
520
+ onMiss?(key: PongoDocumentCacheKey): void;
521
+ onEvict?(key: PongoDocumentCacheKey): void;
522
+ onError?(error: unknown, operation: string): void;
523
+ };
524
+ type CacheType = 'in-memory' | 'identity-map';
525
+ type CacheSettings = ({
526
+ type: 'in-memory';
527
+ } & LRUCacheOptions) | {
528
+ type: 'identity-map';
529
+ };
530
+ type CacheConfig = CacheSettings | 'disabled';
531
+ type CacheOptions = {
532
+ skipCache?: boolean;
533
+ };
534
+ declare const pongoCache: (options?: CacheConfig | "disabled" | PongoCache | undefined) => PongoCache;
535
+
536
+ type PongoTransactionCacheOperationOptions = {
537
+ mainCache: PongoCache;
538
+ };
539
+ interface PongoTransactionCache<T extends string = string> {
540
+ type: PongoCacheType<T>;
541
+ get<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey): MaybePromise<Doc | null | undefined>;
542
+ set(key: PongoDocumentCacheKey, value: PongoDocument | null, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
543
+ update<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, updater: PongoUpdate<Doc>, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
544
+ delete(key: PongoDocumentCacheKey, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
545
+ getMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[]): MaybePromise<(Doc | null | undefined)[]>;
546
+ setMany(entries: PongoCacheSetEntry[], options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
547
+ updateMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[], updater: PongoUpdate<Doc>, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
548
+ deleteMany(keys: PongoDocumentCacheKey[], options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
549
+ clear(): MaybePromise<void>;
550
+ commit(): Promise<void>;
551
+ }
552
+ declare const pongoTransactionCache: (options?: {
553
+ cache?: PongoCache;
554
+ }) => PongoTransactionCache;
435
555
 
436
- export { type $inc as $, type AnyPongoDb as A, type DeleteManyOptions as B, type CollectionOperationOptions as C, type DBsMap as D, type ExtractPongoDatabaseTypeFromDriver as E, type DeleteOneOptions as F, type Document as G, type DocumentHandler as H, type EnhancedOmit as I, type ExpectedDocumentVersion as J, type ExpectedDocumentVersionGeneral as K, type ExpectedDocumentVersionValue as L, type ExtractPongoDriverOptions as M, type FindOptions as N, type HandleOptions as O, type PongoDriver as P, type HasId as Q, type InferIdType as R, type InsertManyOptions as S, type InsertOneOptions as T, NO_CONCURRENCY_CHECK as U, type NonObjectIdLikeDocument as V, ObjectId as W, type ObjectIdLike as X, type OperationResult as Y, type OptionalId as Z, type OptionalUnlessRequiredId as _, type PongoDb as a, type OptionalUnlessRequiredIdAndVersion as a0, type OptionalUnlessRequiredVersion as a1, type OptionalVersion as a2, type PongoClientSchemaMetadata as a3, type PongoCollectionSQLBuilder as a4, type PongoCollectionSchemaComponentOptions as a5, type PongoCollectionSchemaMetadata as a6, type PongoCollectionURN as a7, type PongoCollectionURNType as a8, type PongoDBCollectionOptions as a9, type WithVersion as aA, type WithoutId as aB, type WithoutIdAndVersion as aC, type WithoutVersion as aD, expectedVersion as aE, expectedVersionValue as aF, isGeneralExpectedDocumentVersion as aG, operationResult as aH, pongoDriverRegistry as aI, pongoSchema as aJ, proxyClientWithSchema as aK, proxyPongoDbWithSchema as aL, toClientSchemaMetadata as aM, toDbSchemaMetadata as aN, type PongoDatabaseSQLBuilder as aa, type PongoDatabaseSchemaComponentOptions as ab, type PongoDatabaseURN as ac, type PongoDatabaseURNType as ad, type PongoDbSchemaMetadata as ae, type PongoDbWithSchema as af, type PongoDeleteManyResult as ag, type PongoDeleteResult as ah, PongoDriverRegistry as ai, type PongoFilter as aj, type PongoFilterOperator as ak, type PongoHandleResult as al, type PongoInsertManyResult as am, type PongoInsertOneResult as an, type PongoMigrationOptions as ao, type PongoSchemaConfig as ap, type PongoUpdate as aq, type PongoUpdateManyResult as ar, type PongoUpdateResult as as, type RegExpOrString as at, type ReplaceOneOptions as au, type RootFilterOperators as av, type UpdateManyOptions as aw, type UpdateOneOptions as ax, type WithId as ay, type WithIdAndVersion as az, type PongoDriverOptions as b, type PongoDocument as c, PongoCollectionSchemaComponent as d, type PongoCollection as e, type PongoClientSchema as f, type PongoCollectionSchema as g, type PongoDatabaseFactoryOptions as h, PongoDatabaseSchemaComponent as i, type PongoDbSchema as j, type AnyPongoDriver as k, type PongoClientOptions as l, type PongoClient as m, type PongoClientWithSchema as n, type PongoTransactionOptions as o, type PongoSession as p, type PongoDbTransaction as q, type $push as r, type $set as s, type $unset as t, type AlternativeType as u, type AnyPongoDriverOptions as v, type CollectionsMap as w, type Condition as x, DOCUMENT_DOES_NOT_EXIST as y, DOCUMENT_EXISTS as z };
556
+ export { type $inc as $, type AnyPongoDb as A, type BatchHandleOptions as B, type CacheConfig as C, type CacheOptions as D, type ExtractPongoDatabaseTypeFromDriver as E, type CacheSettings as F, type CacheType as G, type CollectionsMap as H, type Condition as I, type DBsMap as J, DOCUMENT_DOES_NOT_EXIST as K, DOCUMENT_EXISTS as L, type DeleteManyOptions as M, type DeleteOneOptions as N, type Document as O, type PongoDriver as P, DocumentCommandHandler as Q, type DocumentCommandHandlerInput as R, type DocumentCommandHandlerOptions as S, type DocumentHandler as T, type EnhancedOmit as U, type ExpectedDocumentVersion as V, type ExpectedDocumentVersionGeneral as W, type ExpectedDocumentVersionValue as X, type ExtractPongoDriverOptions as Y, type FindOptions as Z, type HandleOptions as _, type PongoDb as a, lruCache as a$, type HasId as a0, type InferIdType as a1, type InsertManyOptions as a2, type InsertOneOptions as a3, type LRUCacheOptions as a4, type MaybePromise as a5, NO_CONCURRENCY_CHECK as a6, type NonObjectIdLikeDocument as a7, ObjectId as a8, type ObjectIdLike as a9, type PongoFilterOperator as aA, type PongoHandleResult as aB, type PongoInsertManyResult as aC, type PongoInsertOneResult as aD, type PongoMigrationOptions as aE, type PongoReplaceManyResult as aF, type PongoSchemaConfig as aG, type PongoTransactionCache as aH, type PongoTransactionCacheOperationOptions as aI, type PongoUpdate as aJ, type PongoUpdateManyResult as aK, type PongoUpdateResult as aL, type RegExpOrString as aM, type ReplaceManyOptions as aN, type ReplaceOneOptions as aO, type RootFilterOperators as aP, type UpdateManyOptions as aQ, type UpdateOneOptions as aR, type WithId as aS, type WithIdAndVersion as aT, type WithVersion as aU, type WithoutId as aV, type WithoutIdAndVersion as aW, type WithoutVersion as aX, expectedVersion as aY, expectedVersionValue as aZ, isGeneralExpectedDocumentVersion as a_, type OperationResult as aa, type OptionalId as ab, type OptionalUnlessRequiredId as ac, type OptionalUnlessRequiredIdAndVersion as ad, type OptionalUnlessRequiredVersion as ae, type OptionalVersion as af, type PongoCacheSetEntry as ag, type PongoCacheType as ah, type PongoClientSchemaMetadata as ai, type PongoCollectionSQLBuilder as aj, type PongoCollectionSchemaComponentOptions as ak, type PongoCollectionSchemaMetadata as al, type PongoCollectionURN as am, type PongoCollectionURNType as an, type PongoDBCollectionOptions as ao, type PongoDatabaseSQLBuilder as ap, type PongoDatabaseSchemaComponentOptions as aq, type PongoDatabaseURN as ar, type PongoDatabaseURNType as as, type PongoDbOptions as at, type PongoDbSchemaMetadata as au, type PongoDbWithSchema as av, type PongoDeleteManyResult as aw, type PongoDeleteResult as ax, type PongoDocumentCacheKey as ay, PongoDriverRegistry as az, type PongoDriverOptions as b, operationResult as b0, pongoCache as b1, pongoDriverRegistry as b2, pongoSchema as b3, pongoTransactionCache as b4, proxyClientWithSchema as b5, proxyPongoDbWithSchema as b6, toClientSchemaMetadata as b7, toDbSchemaMetadata as b8, type PongoFilter as c, type PongoDocument as d, PongoCollectionSchemaComponent as e, type PongoCache as f, type PongoCollection as g, type CollectionOperationOptions as h, type CacheHooks as i, type PongoClientSchema as j, type PongoCollectionSchema as k, type PongoDatabaseFactoryOptions as l, PongoDatabaseSchemaComponent as m, type PongoDbSchema as n, type AnyPongoDriver as o, type PongoClientOptions as p, type PongoClient as q, type PongoClientWithSchema as r, type PongoTransactionOptions as s, type PongoSession as t, type PongoDbTransaction as u, type $push as v, type $set as w, type $unset as x, type AlternativeType as y, type AnyPongoDriverOptions as z };
@@ -1,4 +1,69 @@
1
- import { DatabaseDriverType, SchemaComponent, JSONSerializationOptions, MigrationStyle, JSONSerializer, WithDatabaseTransactionFactory, AnyConnection, DatabaseTransaction, SQLExecutor, SQL, RunSQLMigrationsResult, QueryResultRow, QueryResult, SQLQueryOptions, SQLCommandOptions, SchemaComponentOptions } from '@event-driven-io/dumbo';
1
+ import { JSONSerializer, SQL, SchemaComponent, DatabaseDriverType, SchemaComponentOptions, JSONSerializationOptions, MigrationStyle, WithDatabaseTransactionFactory, AnyConnection, DatabaseTransaction, SQLExecutor, RunSQLMigrationsResult, QueryResultRow, QueryResult, SQLQueryOptions, SQLCommandOptions } from '@event-driven-io/dumbo';
2
+ import { LRUCache } from 'lru-cache';
3
+
4
+ type DocumentCommandHandlerOptions<T extends PongoDocument> = {
5
+ collectionName: string;
6
+ serializer: JSONSerializer;
7
+ errors?: {
8
+ throwOnOperationFailures?: boolean;
9
+ } | undefined;
10
+ storage: {
11
+ ensureCollectionCreated: (options?: CollectionOperationOptions) => Promise<unknown>;
12
+ fetchByIds: (ids: string[], options?: CollectionOperationOptions) => Promise<(WithIdAndVersion<T> | null)[]>;
13
+ insertMany: (docs: OptionalUnlessRequiredIdAndVersion<T>[], options?: CollectionOperationOptions) => Promise<PongoInsertManyResult>;
14
+ replaceMany: (docs: Array<WithIdAndVersion<T>>, options?: CollectionOperationOptions) => Promise<PongoReplaceManyResult>;
15
+ deleteManyByIds: (ids: Array<{
16
+ _id: string;
17
+ _version?: bigint;
18
+ }>, options?: CollectionOperationOptions) => Promise<PongoDeleteResult & {
19
+ deletedIds: Set<string>;
20
+ }>;
21
+ };
22
+ };
23
+ type DocumentCommandHandlerInput = {
24
+ _id: string;
25
+ expectedVersion?: ExpectedDocumentVersion;
26
+ };
27
+ declare function DocumentCommandHandler<T extends PongoDocument>(deps: DocumentCommandHandlerOptions<T>): {
28
+ (id: string | DocumentCommandHandlerInput, handler: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
29
+ (ids: string[] | DocumentCommandHandlerInput[], handler: DocumentHandler<T>, options?: HandleOptions & BatchHandleOptions): Promise<PongoHandleResult<T>[]>;
30
+ };
31
+
32
+ type PongoCollectionSQLBuilder = {
33
+ createCollection: () => SQL;
34
+ insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
35
+ insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
36
+ updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
37
+ replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
38
+ updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
39
+ deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
40
+ deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
41
+ replaceMany: <T>(documents: Array<WithIdAndVersion<T> | WithId<T>>) => SQL;
42
+ deleteManyByIds: (ids: Array<{
43
+ _id: string;
44
+ _version?: bigint;
45
+ }>) => SQL;
46
+ findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
47
+ find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
48
+ countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
49
+ rename: (newName: string) => SQL;
50
+ drop: () => SQL;
51
+ };
52
+
53
+ type PongoCollectionURNType = 'sc:pongo:collection';
54
+ type PongoCollectionURN = `${PongoCollectionURNType}:${string}`;
55
+ type PongoCollectionSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType> = Readonly<{
56
+ driverType: DriverType;
57
+ definition: PongoCollectionSchema;
58
+ migrationsOrSchemaComponents: SchemaComponentOptions;
59
+ sqlBuilder: PongoCollectionSQLBuilder;
60
+ }>;
61
+ type PongoCollectionSchemaComponent = SchemaComponent<PongoCollectionURN> & {
62
+ collectionName: string;
63
+ definition: PongoCollectionSchema;
64
+ sqlBuilder: PongoCollectionSQLBuilder;
65
+ };
66
+ declare const PongoCollectionSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({ definition, migrationsOrSchemaComponents, sqlBuilder, }: PongoCollectionSchemaComponentOptions<DriverType>) => PongoCollectionSchemaComponent;
2
67
 
3
68
  interface PongoCollectionSchema<T extends PongoDocument = PongoDocument> {
4
69
  name: string;
@@ -82,6 +147,7 @@ type PongoDatabaseFactoryOptions<CollectionsSchema extends Record<string, PongoC
82
147
  errors?: {
83
148
  throwOnOperationFailures?: boolean;
84
149
  } | undefined;
150
+ cache?: CacheConfig | 'disabled' | PongoCache | undefined;
85
151
  } & DriverOptions;
86
152
  interface PongoDriver<Database extends AnyPongoDb = AnyPongoDb, DriverOptions extends AnyPongoDriverOptions = AnyPongoDriverOptions> {
87
153
  driverType: Database['driverType'];
@@ -112,7 +178,7 @@ interface PongoClient<DriverType extends DatabaseDriverType = DatabaseDriverType
112
178
  driverType: DriverType;
113
179
  connect(): Promise<this>;
114
180
  close(): Promise<void>;
115
- db(dbName?: string): Database;
181
+ db(dbName?: string, options?: PongoDbOptions): Database;
116
182
  startSession(): PongoSession<DriverType>;
117
183
  withSession<T = unknown>(callback: (session: PongoSession<DriverType>) => Promise<T>): Promise<T>;
118
184
  }
@@ -125,6 +191,7 @@ type PongoClientOptions<DatabaseDriver extends AnyPongoDriver = AnyPongoDriver,
125
191
  errors?: {
126
192
  throwOnOperationFailures?: boolean;
127
193
  } | undefined;
194
+ cache?: CacheConfig | PongoCache | undefined;
128
195
  } & JSONSerializationOptions & Omit<Options, 'driver'> : never : never;
129
196
  declare interface PongoTransactionOptions {
130
197
  get snapshotEnabled(): boolean;
@@ -136,6 +203,7 @@ interface PongoDbTransaction<DriverType extends DatabaseDriverType = DatabaseDri
136
203
  enlistDatabase: (database: Database) => Promise<DatabaseTransaction<AnyConnection>>;
137
204
  commit: () => Promise<void>;
138
205
  rollback: (error?: unknown) => Promise<void>;
206
+ get cache(): PongoTransactionCache | null;
139
207
  get sqlExecutor(): SQLExecutor;
140
208
  get isStarting(): boolean;
141
209
  get isActive(): boolean;
@@ -165,6 +233,10 @@ type PongoDBCollectionOptions<T extends PongoDocument, Payload extends PongoDocu
165
233
  errors?: {
166
234
  throwOnOperationFailures?: boolean;
167
235
  };
236
+ cache?: CacheConfig | 'disabled' | PongoCache;
237
+ };
238
+ type PongoDbOptions = {
239
+ cache?: CacheConfig | PongoCache;
168
240
  };
169
241
  interface PongoDb<DriverType extends DatabaseDriverType = DatabaseDriverType> extends WithDatabaseTransactionFactory<AnyConnection> {
170
242
  driverType: DriverType;
@@ -190,6 +262,7 @@ type PongoMigrationOptions = {
190
262
  };
191
263
  type CollectionOperationOptions = {
192
264
  session?: PongoSession;
265
+ skipCache?: boolean;
193
266
  };
194
267
  type InsertOneOptions = {
195
268
  expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
@@ -203,8 +276,9 @@ type UpdateOneOptions = {
203
276
  type UpdateManyOptions = {
204
277
  expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
205
278
  } & CollectionOperationOptions;
206
- type HandleOptions = {
207
- expectedVersion?: ExpectedDocumentVersion;
279
+ type HandleOptions = CollectionOperationOptions;
280
+ type BatchHandleOptions = {
281
+ parallel?: boolean;
208
282
  } & CollectionOperationOptions;
209
283
  type ReplaceOneOptions = {
210
284
  expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
@@ -212,6 +286,7 @@ type ReplaceOneOptions = {
212
286
  type DeleteOneOptions = {
213
287
  expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
214
288
  } & CollectionOperationOptions;
289
+ type ReplaceManyOptions = CollectionOperationOptions;
215
290
  type DeleteManyOptions = {
216
291
  expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
217
292
  } & CollectionOperationOptions;
@@ -238,11 +313,14 @@ interface PongoCollection<T extends PongoDocument> {
238
313
  countDocuments(filter?: PongoFilter<T> | SQL, options?: CollectionOperationOptions): Promise<number>;
239
314
  drop(options?: CollectionOperationOptions): Promise<boolean>;
240
315
  rename(newName: string, options?: CollectionOperationOptions): Promise<PongoCollection<T>>;
241
- handle(id: string, handle: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
316
+ handle(id: string | DocumentCommandHandlerInput, handle: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
317
+ handle(id: string[] | DocumentCommandHandlerInput[], handle: DocumentHandler<T>, options?: BatchHandleOptions): Promise<PongoHandleResult<T>[]>;
318
+ replaceMany(documents: Array<WithId<T> | WithIdAndVersion<T>>, options?: ReplaceManyOptions): Promise<PongoReplaceManyResult>;
242
319
  readonly schema: Readonly<{
243
320
  component: PongoCollectionSchemaComponent;
244
321
  migrate(options?: PongoMigrationOptions): Promise<RunSQLMigrationsResult>;
245
322
  }>;
323
+ close: () => MaybePromise<void>;
246
324
  sql: {
247
325
  query<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<Result[]>;
248
326
  command<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<QueryResult<Result>>;
@@ -277,7 +355,7 @@ declare type WithVersion<TSchema> = EnhancedOmit<TSchema, '_version'> & {
277
355
  _version: bigint;
278
356
  };
279
357
  type WithoutVersion<T> = Omit<T, '_version'>;
280
- type WithIdAndVersion<T> = WithId<WithVersion<T>>;
358
+ type WithIdAndVersion<T> = WithId<T> & WithVersion<T>;
281
359
  type WithoutIdAndVersion<T> = WithoutId<WithoutVersion<T>>;
282
360
  /** @public */
283
361
  declare type RegExpOrString<T> = T extends string ? RegExp | T : T;
@@ -390,6 +468,13 @@ interface PongoDeleteResult extends OperationResult {
390
468
  interface PongoDeleteManyResult extends OperationResult {
391
469
  deletedCount: number;
392
470
  }
471
+ interface PongoReplaceManyResult extends OperationResult {
472
+ modifiedCount: number;
473
+ matchedCount: number;
474
+ modifiedIds: string[];
475
+ conflictIds: string[];
476
+ nextExpectedVersions: Map<string, bigint>;
477
+ }
393
478
  type PongoHandleResult<T> = (PongoInsertOneResult & {
394
479
  document: T;
395
480
  }) | (PongoUpdateResult & {
@@ -402,35 +487,70 @@ type PongoHandleResult<T> = (PongoInsertOneResult & {
402
487
  type PongoDocument = Record<string, unknown>;
403
488
  type DocumentHandler<T extends PongoDocument> = ((document: T | null) => T | null) | ((document: T | null) => Promise<T | null>);
404
489
 
405
- type PongoCollectionSQLBuilder = {
406
- createCollection: () => SQL;
407
- insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
408
- insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
409
- updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
410
- replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
411
- updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
412
- deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
413
- deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
414
- findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
415
- find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
416
- countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
417
- rename: (newName: string) => SQL;
418
- drop: () => SQL;
490
+ type MaybePromise<T> = T | PromiseLike<T>;
491
+
492
+ type LRUCacheOptions = Omit<LRUCache.Options<string, {
493
+ doc: PongoDocument | null;
494
+ }, unknown>, 'max'> & {
495
+ max?: number;
419
496
  };
497
+ declare const lruCache: (options?: LRUCacheOptions) => PongoCache;
420
498
 
421
- type PongoCollectionURNType = 'sc:pongo:collection';
422
- type PongoCollectionURN = `${PongoCollectionURNType}:${string}`;
423
- type PongoCollectionSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType> = Readonly<{
424
- driverType: DriverType;
425
- definition: PongoCollectionSchema;
426
- migrationsOrSchemaComponents: SchemaComponentOptions;
427
- sqlBuilder: PongoCollectionSQLBuilder;
428
- }>;
429
- type PongoCollectionSchemaComponent = SchemaComponent<PongoCollectionURN> & {
430
- collectionName: string;
431
- definition: PongoCollectionSchema;
432
- sqlBuilder: PongoCollectionSQLBuilder;
499
+ type PongoDocumentCacheKey = `${string}:${string}:${string}`;
500
+ type PongoCacheSetEntry<Doc extends PongoDocument = PongoDocument> = {
501
+ key: PongoDocumentCacheKey;
502
+ value: Doc | null;
433
503
  };
434
- declare const PongoCollectionSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({ definition, migrationsOrSchemaComponents, sqlBuilder, }: PongoCollectionSchemaComponentOptions<DriverType>) => PongoCollectionSchemaComponent;
504
+ type PongoCacheType<T extends string = string> = `pongo:cache:${T}`;
505
+ interface PongoCache<T extends string = string> {
506
+ cacheType: PongoCacheType<T>;
507
+ get<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey): MaybePromise<Doc | null | undefined>;
508
+ getMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[]): MaybePromise<(Doc | null | undefined)[]>;
509
+ set<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, value: Doc | null): MaybePromise<void>;
510
+ setMany(entries: PongoCacheSetEntry[]): MaybePromise<void>;
511
+ update<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, updater: PongoUpdate<Doc>): MaybePromise<void>;
512
+ updateMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[], updater: PongoUpdate<Doc>): MaybePromise<void>;
513
+ delete(key: PongoDocumentCacheKey): MaybePromise<void>;
514
+ deleteMany(keys: PongoDocumentCacheKey[]): MaybePromise<void>;
515
+ clear(): MaybePromise<void>;
516
+ close(): MaybePromise<void>;
517
+ }
518
+ type CacheHooks = {
519
+ onHit?(key: PongoDocumentCacheKey): void;
520
+ onMiss?(key: PongoDocumentCacheKey): void;
521
+ onEvict?(key: PongoDocumentCacheKey): void;
522
+ onError?(error: unknown, operation: string): void;
523
+ };
524
+ type CacheType = 'in-memory' | 'identity-map';
525
+ type CacheSettings = ({
526
+ type: 'in-memory';
527
+ } & LRUCacheOptions) | {
528
+ type: 'identity-map';
529
+ };
530
+ type CacheConfig = CacheSettings | 'disabled';
531
+ type CacheOptions = {
532
+ skipCache?: boolean;
533
+ };
534
+ declare const pongoCache: (options?: CacheConfig | "disabled" | PongoCache | undefined) => PongoCache;
535
+
536
+ type PongoTransactionCacheOperationOptions = {
537
+ mainCache: PongoCache;
538
+ };
539
+ interface PongoTransactionCache<T extends string = string> {
540
+ type: PongoCacheType<T>;
541
+ get<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey): MaybePromise<Doc | null | undefined>;
542
+ set(key: PongoDocumentCacheKey, value: PongoDocument | null, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
543
+ update<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, updater: PongoUpdate<Doc>, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
544
+ delete(key: PongoDocumentCacheKey, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
545
+ getMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[]): MaybePromise<(Doc | null | undefined)[]>;
546
+ setMany(entries: PongoCacheSetEntry[], options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
547
+ updateMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[], updater: PongoUpdate<Doc>, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
548
+ deleteMany(keys: PongoDocumentCacheKey[], options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
549
+ clear(): MaybePromise<void>;
550
+ commit(): Promise<void>;
551
+ }
552
+ declare const pongoTransactionCache: (options?: {
553
+ cache?: PongoCache;
554
+ }) => PongoTransactionCache;
435
555
 
436
- export { type $inc as $, type AnyPongoDb as A, type DeleteManyOptions as B, type CollectionOperationOptions as C, type DBsMap as D, type ExtractPongoDatabaseTypeFromDriver as E, type DeleteOneOptions as F, type Document as G, type DocumentHandler as H, type EnhancedOmit as I, type ExpectedDocumentVersion as J, type ExpectedDocumentVersionGeneral as K, type ExpectedDocumentVersionValue as L, type ExtractPongoDriverOptions as M, type FindOptions as N, type HandleOptions as O, type PongoDriver as P, type HasId as Q, type InferIdType as R, type InsertManyOptions as S, type InsertOneOptions as T, NO_CONCURRENCY_CHECK as U, type NonObjectIdLikeDocument as V, ObjectId as W, type ObjectIdLike as X, type OperationResult as Y, type OptionalId as Z, type OptionalUnlessRequiredId as _, type PongoDb as a, type OptionalUnlessRequiredIdAndVersion as a0, type OptionalUnlessRequiredVersion as a1, type OptionalVersion as a2, type PongoClientSchemaMetadata as a3, type PongoCollectionSQLBuilder as a4, type PongoCollectionSchemaComponentOptions as a5, type PongoCollectionSchemaMetadata as a6, type PongoCollectionURN as a7, type PongoCollectionURNType as a8, type PongoDBCollectionOptions as a9, type WithVersion as aA, type WithoutId as aB, type WithoutIdAndVersion as aC, type WithoutVersion as aD, expectedVersion as aE, expectedVersionValue as aF, isGeneralExpectedDocumentVersion as aG, operationResult as aH, pongoDriverRegistry as aI, pongoSchema as aJ, proxyClientWithSchema as aK, proxyPongoDbWithSchema as aL, toClientSchemaMetadata as aM, toDbSchemaMetadata as aN, type PongoDatabaseSQLBuilder as aa, type PongoDatabaseSchemaComponentOptions as ab, type PongoDatabaseURN as ac, type PongoDatabaseURNType as ad, type PongoDbSchemaMetadata as ae, type PongoDbWithSchema as af, type PongoDeleteManyResult as ag, type PongoDeleteResult as ah, PongoDriverRegistry as ai, type PongoFilter as aj, type PongoFilterOperator as ak, type PongoHandleResult as al, type PongoInsertManyResult as am, type PongoInsertOneResult as an, type PongoMigrationOptions as ao, type PongoSchemaConfig as ap, type PongoUpdate as aq, type PongoUpdateManyResult as ar, type PongoUpdateResult as as, type RegExpOrString as at, type ReplaceOneOptions as au, type RootFilterOperators as av, type UpdateManyOptions as aw, type UpdateOneOptions as ax, type WithId as ay, type WithIdAndVersion as az, type PongoDriverOptions as b, type PongoDocument as c, PongoCollectionSchemaComponent as d, type PongoCollection as e, type PongoClientSchema as f, type PongoCollectionSchema as g, type PongoDatabaseFactoryOptions as h, PongoDatabaseSchemaComponent as i, type PongoDbSchema as j, type AnyPongoDriver as k, type PongoClientOptions as l, type PongoClient as m, type PongoClientWithSchema as n, type PongoTransactionOptions as o, type PongoSession as p, type PongoDbTransaction as q, type $push as r, type $set as s, type $unset as t, type AlternativeType as u, type AnyPongoDriverOptions as v, type CollectionsMap as w, type Condition as x, DOCUMENT_DOES_NOT_EXIST as y, DOCUMENT_EXISTS as z };
556
+ export { type $inc as $, type AnyPongoDb as A, type BatchHandleOptions as B, type CacheConfig as C, type CacheOptions as D, type ExtractPongoDatabaseTypeFromDriver as E, type CacheSettings as F, type CacheType as G, type CollectionsMap as H, type Condition as I, type DBsMap as J, DOCUMENT_DOES_NOT_EXIST as K, DOCUMENT_EXISTS as L, type DeleteManyOptions as M, type DeleteOneOptions as N, type Document as O, type PongoDriver as P, DocumentCommandHandler as Q, type DocumentCommandHandlerInput as R, type DocumentCommandHandlerOptions as S, type DocumentHandler as T, type EnhancedOmit as U, type ExpectedDocumentVersion as V, type ExpectedDocumentVersionGeneral as W, type ExpectedDocumentVersionValue as X, type ExtractPongoDriverOptions as Y, type FindOptions as Z, type HandleOptions as _, type PongoDb as a, lruCache as a$, type HasId as a0, type InferIdType as a1, type InsertManyOptions as a2, type InsertOneOptions as a3, type LRUCacheOptions as a4, type MaybePromise as a5, NO_CONCURRENCY_CHECK as a6, type NonObjectIdLikeDocument as a7, ObjectId as a8, type ObjectIdLike as a9, type PongoFilterOperator as aA, type PongoHandleResult as aB, type PongoInsertManyResult as aC, type PongoInsertOneResult as aD, type PongoMigrationOptions as aE, type PongoReplaceManyResult as aF, type PongoSchemaConfig as aG, type PongoTransactionCache as aH, type PongoTransactionCacheOperationOptions as aI, type PongoUpdate as aJ, type PongoUpdateManyResult as aK, type PongoUpdateResult as aL, type RegExpOrString as aM, type ReplaceManyOptions as aN, type ReplaceOneOptions as aO, type RootFilterOperators as aP, type UpdateManyOptions as aQ, type UpdateOneOptions as aR, type WithId as aS, type WithIdAndVersion as aT, type WithVersion as aU, type WithoutId as aV, type WithoutIdAndVersion as aW, type WithoutVersion as aX, expectedVersion as aY, expectedVersionValue as aZ, isGeneralExpectedDocumentVersion as a_, type OperationResult as aa, type OptionalId as ab, type OptionalUnlessRequiredId as ac, type OptionalUnlessRequiredIdAndVersion as ad, type OptionalUnlessRequiredVersion as ae, type OptionalVersion as af, type PongoCacheSetEntry as ag, type PongoCacheType as ah, type PongoClientSchemaMetadata as ai, type PongoCollectionSQLBuilder as aj, type PongoCollectionSchemaComponentOptions as ak, type PongoCollectionSchemaMetadata as al, type PongoCollectionURN as am, type PongoCollectionURNType as an, type PongoDBCollectionOptions as ao, type PongoDatabaseSQLBuilder as ap, type PongoDatabaseSchemaComponentOptions as aq, type PongoDatabaseURN as ar, type PongoDatabaseURNType as as, type PongoDbOptions as at, type PongoDbSchemaMetadata as au, type PongoDbWithSchema as av, type PongoDeleteManyResult as aw, type PongoDeleteResult as ax, type PongoDocumentCacheKey as ay, PongoDriverRegistry as az, type PongoDriverOptions as b, operationResult as b0, pongoCache as b1, pongoDriverRegistry as b2, pongoSchema as b3, pongoTransactionCache as b4, proxyClientWithSchema as b5, proxyPongoDbWithSchema as b6, toClientSchemaMetadata as b7, toDbSchemaMetadata as b8, type PongoFilter as c, type PongoDocument as d, PongoCollectionSchemaComponent as e, type PongoCache as f, type PongoCollection as g, type CollectionOperationOptions as h, type CacheHooks as i, type PongoClientSchema as j, type PongoCollectionSchema as k, type PongoDatabaseFactoryOptions as l, PongoDatabaseSchemaComponent as m, type PongoDbSchema as n, type AnyPongoDriver as o, type PongoClientOptions as p, type PongoClient as q, type PongoClientWithSchema as r, type PongoTransactionOptions as s, type PongoSession as t, type PongoDbTransaction as u, type $push as v, type $set as w, type $unset as x, type AlternativeType as y, type AnyPongoDriverOptions as z };
package/dist/shim.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
2
 
3
3
 
4
- var _chunkBZRKCNRYcjs = require('./chunk-BZRKCNRY.cjs');
4
+ var _chunkTYTEQJBCcjs = require('./chunk-TYTEQJBC.cjs');
5
5
 
6
6
  // src/mongo/findCursor.ts
7
7
  var FindCursor = (_class = class {
@@ -327,7 +327,7 @@ var MongoClient = class {
327
327
 
328
328
  constructor(connectionStringOrOptions, options) {
329
329
  if (typeof connectionStringOrOptions !== "string") {
330
- this.pongoClient = _chunkBZRKCNRYcjs.pongoClient.call(void 0, connectionStringOrOptions);
330
+ this.pongoClient = _chunkTYTEQJBCcjs.pongoClient.call(void 0, connectionStringOrOptions);
331
331
  return;
332
332
  }
333
333
  const { databaseType, driverName } = _dumbo.parseConnectionString.call(void 0,
@@ -341,7 +341,7 @@ var MongoClient = class {
341
341
  `No database driver registered for ${databaseType} with name ${driverName}`
342
342
  );
343
343
  }
344
- this.pongoClient = _chunkBZRKCNRYcjs.pongoClient.call(void 0, {
344
+ this.pongoClient = _chunkTYTEQJBCcjs.pongoClient.call(void 0, {
345
345
  ..._nullishCoalesce(options, () => ( {})),
346
346
  ...{ connectionString: connectionStringOrOptions },
347
347
  driver
@@ -358,12 +358,12 @@ var MongoClient = class {
358
358
  return new Db(this.pongoClient.db(dbName));
359
359
  }
360
360
  startSession(_options) {
361
- return _chunkBZRKCNRYcjs.pongoSession.call(void 0, );
361
+ return _chunkTYTEQJBCcjs.pongoSession.call(void 0, );
362
362
  }
363
363
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
364
364
  async withSession(optionsOrExecutor, executor) {
365
365
  const callback = typeof optionsOrExecutor === "function" ? optionsOrExecutor : executor;
366
- const session = _chunkBZRKCNRYcjs.pongoSession.call(void 0, );
366
+ const session = _chunkTYTEQJBCcjs.pongoSession.call(void 0, );
367
367
  try {
368
368
  return await callback(session);
369
369
  } finally {
package/dist/shim.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ClientSessionOptions } from 'http2';
2
2
  import { Document, Collection as Collection$1, ObjectId, ClientSession, WithSessionCallback, Db as Db$1, ReadConcern, ReadPreference, BSONSerializeOptions, WriteConcern, Hint, OptionalUnlessRequiredId, InsertOneOptions, InsertOneResult, BulkWriteOptions, InsertManyResult, AnyBulkWriteOperation, BulkWriteResult, Filter, UpdateFilter, UpdateOptions, UpdateResult, WithoutId, ReplaceOptions, DeleteOptions, DeleteResult, RenameOptions, DropCollectionOptions, WithId, FindOptions, FindCursor as FindCursor$1, OperationOptions, IndexSpecification, CreateIndexesOptions, IndexDescription, CommandOperationOptions, AbstractCursorOptions, ListIndexesCursor, IndexInformationOptions, IndexDescriptionInfo, IndexDescriptionCompact, EstimatedDocumentCountOptions, CountDocumentsOptions, EnhancedOmit, Flatten, FindOneAndDeleteOptions, ModifyResult, FindOneAndReplaceOptions, FindOneAndUpdateOptions, AggregateOptions, AggregationCursor, ChangeStreamDocument, ChangeStreamOptions, ChangeStream, UnorderedBulkOperation, OrderedBulkOperation, CountOptions, ListSearchIndexesOptions, ListSearchIndexesCursor, SearchIndexDescription } from 'mongodb';
3
- import { a as PongoDb, a9 as PongoDBCollectionOptions, H as DocumentHandler, O as HandleOptions, al as PongoHandleResult, k as AnyPongoDriver, f as PongoClientSchema, l as PongoClientOptions, e as PongoCollection } from './pongoCollectionSchemaComponent-B5Oatwu0.cjs';
3
+ import { a as PongoDb, ao as PongoDBCollectionOptions, T as DocumentHandler, _ as HandleOptions, aB as PongoHandleResult, o as AnyPongoDriver, j as PongoClientSchema, p as PongoClientOptions, g as PongoCollection } from './pongoTransactionCache-BsigBOq1.cjs';
4
4
  import '@event-driven-io/dumbo';
5
+ import 'lru-cache';
5
6
 
6
7
  declare class FindCursor<T> {
7
8
  private findDocumentsPromise;