@event-driven-io/pongo 0.16.4-alpha.1 → 0.16.4-alpha.2

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/shim.js CHANGED
@@ -1,2 +1,333 @@
1
- import{H as p,s as a}from"./chunk-CYDDN3CZ.js";var s=class{findDocumentsPromise;documents=null;index=0;constructor(e){this.findDocumentsPromise=e}async toArray(){return this.findDocuments()}async forEach(e){let n=await this.findDocuments();for(let t of n)e(t);return Promise.resolve()}hasNext(){if(this.documents===null)throw Error("Error while fetching documents");return this.index<this.documents.length}async next(){let e=await this.findDocuments();return this.hasNext()?e[this.index++]??null:null}async findDocuments(){return this.documents=await this.findDocumentsPromise,this.documents}};import"mongodb";var o=r=>r?.session?{session:r.session}:void 0,d=class{collection;constructor(e){this.collection=e}get dbName(){return this.collection.dbName}get collectionName(){return this.collection.collectionName}get namespace(){return`${this.dbName}.${this.collectionName}`}get readConcern(){}get readPreference(){}get bsonOptions(){return{}}get writeConcern(){}get hint(){}set hint(e){throw new Error("Method not implemented.")}async insertOne(e,n){let t=await this.collection.insertOne(e,o(n));return{acknowledged:t.acknowledged,insertedId:t.insertedId}}async insertMany(e,n){let t=await this.collection.insertMany(e,o(n));return{acknowledged:t.acknowledged,insertedIds:t.insertedIds,insertedCount:t.insertedCount}}bulkWrite(e,n){throw new Error("Method not implemented.")}async updateOne(e,n,t){let i=await this.collection.updateOne(e,n,o(t));return{acknowledged:i.acknowledged,matchedCount:i.modifiedCount,modifiedCount:i.modifiedCount,upsertedCount:i.modifiedCount,upsertedId:null}}replaceOne(e,n,t){return this.collection.replaceOne(e,n,o(t))}async updateMany(e,n,t){let i=await this.collection.updateMany(e,n,o(t));return{acknowledged:i.acknowledged,matchedCount:i.modifiedCount,modifiedCount:i.modifiedCount,upsertedCount:i.modifiedCount,upsertedId:null}}async deleteOne(e,n){let t=await this.collection.deleteOne(e,o(n));return{acknowledged:t.acknowledged,deletedCount:t.deletedCount}}async deleteMany(e,n){let t=await this.collection.deleteMany(e,o(n));return{acknowledged:t.acknowledged,deletedCount:t.deletedCount}}async rename(e,n){return await this.collection.rename(e,o(n)),this}drop(e){return this.collection.drop(o(e))}async findOne(e,n){return await this.collection.findOne(e,o(n))}find(e,n){return new s(this.collection.find(e,o(n)))}options(e){throw new Error("Method not implemented.")}isCapped(e){throw new Error("Method not implemented.")}createIndex(e,n){throw new Error("Method not implemented.")}createIndexes(e,n){throw new Error("Method not implemented.")}dropIndex(e,n){throw new Error("Method not implemented.")}dropIndexes(e){throw new Error("Method not implemented.")}listIndexes(e){throw new Error("Method not implemented.")}indexExists(e,n){throw new Error("Method not implemented.")}indexInformation(e){throw new Error("Method not implemented.")}estimatedDocumentCount(e){return this.collection.countDocuments({},o(e))}countDocuments(e,n){return this.collection.countDocuments(e,o(n))}distinct(e,n,t){throw new Error("Method not implemented.")}indexes(e){throw new Error("Method not implemented.")}findOneAndDelete(e,n){return this.collection.findOneAndDelete(e,o(n))}findOneAndReplace(e,n,t){return this.collection.findOneAndReplace(e,n,o(t))}findOneAndUpdate(e,n,t){return this.collection.findOneAndUpdate(e,n,o(t))}aggregate(e,n){throw new Error("Method not implemented.")}watch(e,n){throw new Error("Method not implemented.")}initializeUnorderedBulkOp(e){throw new Error("Method not implemented.")}initializeOrderedBulkOp(e){throw new Error("Method not implemented.")}count(e,n){return this.collection.countDocuments(e??{},o(n))}listSearchIndexes(e,n){throw new Error("Method not implemented.")}createSearchIndex(e){throw new Error("Method not implemented.")}createSearchIndexes(e){throw new Error("Method not implemented.")}dropSearchIndex(e){throw new Error("Method not implemented.")}updateSearchIndex(e,n){throw new Error("Method not implemented.")}async createCollection(){await this.collection.createCollection()}async handle(e,n,t){return this.collection.handle(e.toString(),n,t)}};var l=class{constructor(e){this.pongoDb=e}get databaseName(){return this.pongoDb.databaseName}collection(e){return new d(this.pongoDb.collection(e))}};var u=class{pongoClient;constructor(e,n={}){this.pongoClient=p(e,n)}async connect(){return await this.pongoClient.connect(),this}async close(){await this.pongoClient.close()}db(e){return new l(this.pongoClient.db(e))}startSession(e){return a()}async withSession(e,n){let t=typeof e=="function"?e:n,i=a();try{return await t(i)}finally{await i.endSession()}}};export{d as Collection,l as Db,s as FindCursor,u as MongoClient};
1
+ import {
2
+ pongoClient,
3
+ pongoSession
4
+ } from "./chunk-IXL27BW5.js";
5
+
6
+ // src/mongo/findCursor.ts
7
+ var FindCursor = class {
8
+ findDocumentsPromise;
9
+ documents = null;
10
+ index = 0;
11
+ constructor(documents) {
12
+ this.findDocumentsPromise = documents;
13
+ }
14
+ async toArray() {
15
+ return this.findDocuments();
16
+ }
17
+ async forEach(callback) {
18
+ const docs = await this.findDocuments();
19
+ for (const doc of docs) {
20
+ callback(doc);
21
+ }
22
+ return Promise.resolve();
23
+ }
24
+ hasNext() {
25
+ if (this.documents === null) throw Error("Error while fetching documents");
26
+ return this.index < this.documents.length;
27
+ }
28
+ async next() {
29
+ const docs = await this.findDocuments();
30
+ return this.hasNext() ? docs[this.index++] ?? null : null;
31
+ }
32
+ async findDocuments() {
33
+ this.documents = await this.findDocumentsPromise;
34
+ return this.documents;
35
+ }
36
+ };
37
+
38
+ // src/mongo/mongoDb.ts
39
+ import "mongodb";
40
+
41
+ // src/mongo/mongoCollection.ts
42
+ var toCollectionOperationOptions = (options) => options?.session ? { session: options.session } : void 0;
43
+ var Collection = class {
44
+ collection;
45
+ constructor(collection) {
46
+ this.collection = collection;
47
+ }
48
+ get dbName() {
49
+ return this.collection.dbName;
50
+ }
51
+ get collectionName() {
52
+ return this.collection.collectionName;
53
+ }
54
+ get namespace() {
55
+ return `${this.dbName}.${this.collectionName}`;
56
+ }
57
+ get readConcern() {
58
+ return void 0;
59
+ }
60
+ get readPreference() {
61
+ return void 0;
62
+ }
63
+ get bsonOptions() {
64
+ return {};
65
+ }
66
+ get writeConcern() {
67
+ return void 0;
68
+ }
69
+ get hint() {
70
+ return void 0;
71
+ }
72
+ set hint(v) {
73
+ throw new Error("Method not implemented.");
74
+ }
75
+ async insertOne(doc, options) {
76
+ const result = await this.collection.insertOne(
77
+ doc,
78
+ toCollectionOperationOptions(options)
79
+ );
80
+ return {
81
+ acknowledged: result.acknowledged,
82
+ insertedId: result.insertedId
83
+ };
84
+ }
85
+ async insertMany(docs, options) {
86
+ const result = await this.collection.insertMany(
87
+ docs,
88
+ toCollectionOperationOptions(options)
89
+ );
90
+ return {
91
+ acknowledged: result.acknowledged,
92
+ insertedIds: result.insertedIds,
93
+ insertedCount: result.insertedCount
94
+ };
95
+ }
96
+ bulkWrite(_operations, _options) {
97
+ throw new Error("Method not implemented.");
98
+ }
99
+ async updateOne(filter, update, options) {
100
+ const result = await this.collection.updateOne(
101
+ filter,
102
+ update,
103
+ toCollectionOperationOptions(options)
104
+ );
105
+ return {
106
+ acknowledged: result.acknowledged,
107
+ matchedCount: result.modifiedCount,
108
+ modifiedCount: result.modifiedCount,
109
+ upsertedCount: result.modifiedCount,
110
+ upsertedId: null
111
+ };
112
+ }
113
+ replaceOne(filter, document, options) {
114
+ return this.collection.replaceOne(
115
+ filter,
116
+ document,
117
+ toCollectionOperationOptions(options)
118
+ );
119
+ }
120
+ async updateMany(filter, update, options) {
121
+ const result = await this.collection.updateMany(
122
+ filter,
123
+ update,
124
+ toCollectionOperationOptions(options)
125
+ );
126
+ return {
127
+ acknowledged: result.acknowledged,
128
+ matchedCount: result.modifiedCount,
129
+ modifiedCount: result.modifiedCount,
130
+ upsertedCount: result.modifiedCount,
131
+ upsertedId: null
132
+ };
133
+ }
134
+ async deleteOne(filter, options) {
135
+ const result = await this.collection.deleteOne(
136
+ filter,
137
+ toCollectionOperationOptions(options)
138
+ );
139
+ return {
140
+ acknowledged: result.acknowledged,
141
+ deletedCount: result.deletedCount
142
+ };
143
+ }
144
+ async deleteMany(filter, options) {
145
+ const result = await this.collection.deleteMany(
146
+ filter,
147
+ toCollectionOperationOptions(options)
148
+ );
149
+ return {
150
+ acknowledged: result.acknowledged,
151
+ deletedCount: result.deletedCount
152
+ };
153
+ }
154
+ async rename(newName, options) {
155
+ await this.collection.rename(
156
+ newName,
157
+ toCollectionOperationOptions(options)
158
+ );
159
+ return this;
160
+ }
161
+ drop(options) {
162
+ return this.collection.drop(toCollectionOperationOptions(options));
163
+ }
164
+ async findOne(filter, options) {
165
+ return await this.collection.findOne(
166
+ filter,
167
+ toCollectionOperationOptions(options)
168
+ );
169
+ }
170
+ find(filter, options) {
171
+ return new FindCursor(
172
+ this.collection.find(
173
+ filter,
174
+ toCollectionOperationOptions(options)
175
+ )
176
+ );
177
+ }
178
+ options(_options) {
179
+ throw new Error("Method not implemented.");
180
+ }
181
+ isCapped(_options) {
182
+ throw new Error("Method not implemented.");
183
+ }
184
+ createIndex(_indexSpec, _options) {
185
+ throw new Error("Method not implemented.");
186
+ }
187
+ createIndexes(_indexSpecs, _options) {
188
+ throw new Error("Method not implemented.");
189
+ }
190
+ dropIndex(_indexName, _options) {
191
+ throw new Error("Method not implemented.");
192
+ }
193
+ dropIndexes(_options) {
194
+ throw new Error("Method not implemented.");
195
+ }
196
+ listIndexes(_options) {
197
+ throw new Error("Method not implemented.");
198
+ }
199
+ indexExists(_indexes, _options) {
200
+ throw new Error("Method not implemented.");
201
+ }
202
+ indexInformation(_options) {
203
+ throw new Error("Method not implemented.");
204
+ }
205
+ estimatedDocumentCount(options) {
206
+ return this.collection.countDocuments(
207
+ {},
208
+ toCollectionOperationOptions(options)
209
+ );
210
+ }
211
+ countDocuments(filter, options) {
212
+ return this.collection.countDocuments(
213
+ filter,
214
+ toCollectionOperationOptions(options)
215
+ );
216
+ }
217
+ distinct(_key, _filter, _options) {
218
+ throw new Error("Method not implemented.");
219
+ }
220
+ indexes(_options) {
221
+ throw new Error("Method not implemented.");
222
+ }
223
+ findOneAndDelete(filter, options) {
224
+ return this.collection.findOneAndDelete(
225
+ filter,
226
+ toCollectionOperationOptions(options)
227
+ );
228
+ }
229
+ findOneAndReplace(filter, replacement, options) {
230
+ return this.collection.findOneAndReplace(
231
+ filter,
232
+ replacement,
233
+ toCollectionOperationOptions(options)
234
+ );
235
+ }
236
+ findOneAndUpdate(filter, update, options) {
237
+ return this.collection.findOneAndUpdate(
238
+ filter,
239
+ update,
240
+ toCollectionOperationOptions(options)
241
+ );
242
+ }
243
+ aggregate(_pipeline, _options) {
244
+ throw new Error("Method not implemented.");
245
+ }
246
+ watch(_pipeline, _options) {
247
+ throw new Error("Method not implemented.");
248
+ }
249
+ initializeUnorderedBulkOp(_options) {
250
+ throw new Error("Method not implemented.");
251
+ }
252
+ initializeOrderedBulkOp(_options) {
253
+ throw new Error("Method not implemented.");
254
+ }
255
+ count(filter, options) {
256
+ return this.collection.countDocuments(
257
+ filter ?? {},
258
+ toCollectionOperationOptions(options)
259
+ );
260
+ }
261
+ listSearchIndexes(_name, _options) {
262
+ throw new Error("Method not implemented.");
263
+ }
264
+ createSearchIndex(_description) {
265
+ throw new Error("Method not implemented.");
266
+ }
267
+ createSearchIndexes(_descriptions) {
268
+ throw new Error("Method not implemented.");
269
+ }
270
+ dropSearchIndex(_name) {
271
+ throw new Error("Method not implemented.");
272
+ }
273
+ updateSearchIndex(_name, _definition) {
274
+ throw new Error("Method not implemented.");
275
+ }
276
+ async createCollection() {
277
+ await this.collection.createCollection();
278
+ }
279
+ async handle(id, handle, options) {
280
+ return this.collection.handle(id.toString(), handle, options);
281
+ }
282
+ };
283
+
284
+ // src/mongo/mongoDb.ts
285
+ var Db = class {
286
+ constructor(pongoDb) {
287
+ this.pongoDb = pongoDb;
288
+ }
289
+ get databaseName() {
290
+ return this.pongoDb.databaseName;
291
+ }
292
+ collection(collectionName) {
293
+ return new Collection(this.pongoDb.collection(collectionName));
294
+ }
295
+ };
296
+
297
+ // src/mongo/mongoClient.ts
298
+ var MongoClient = class {
299
+ pongoClient;
300
+ constructor(connectionString, options = {}) {
301
+ this.pongoClient = pongoClient(connectionString, options);
302
+ }
303
+ async connect() {
304
+ await this.pongoClient.connect();
305
+ return this;
306
+ }
307
+ async close() {
308
+ await this.pongoClient.close();
309
+ }
310
+ db(dbName) {
311
+ return new Db(this.pongoClient.db(dbName));
312
+ }
313
+ startSession(_options) {
314
+ return pongoSession();
315
+ }
316
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
+ async withSession(optionsOrExecutor, executor) {
318
+ const callback = typeof optionsOrExecutor === "function" ? optionsOrExecutor : executor;
319
+ const session = pongoSession();
320
+ try {
321
+ return await callback(session);
322
+ } finally {
323
+ await session.endSession();
324
+ }
325
+ }
326
+ };
327
+ export {
328
+ Collection,
329
+ Db,
330
+ FindCursor,
331
+ MongoClient
332
+ };
2
333
  //# sourceMappingURL=shim.js.map
package/dist/shim.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mongo/findCursor.ts","../src/mongo/mongoDb.ts","../src/mongo/mongoCollection.ts","../src/mongo/mongoClient.ts"],"sourcesContent":["export class FindCursor<T> {\n private findDocumentsPromise: Promise<T[]>;\n private documents: T[] | null = null;\n private index: number = 0;\n\n constructor(documents: Promise<T[]>) {\n this.findDocumentsPromise = documents;\n }\n\n async toArray(): Promise<T[]> {\n return this.findDocuments();\n }\n\n async forEach(callback: (doc: T) => void): Promise<void> {\n const docs = await this.findDocuments();\n\n for (const doc of docs) {\n callback(doc);\n }\n return Promise.resolve();\n }\n\n hasNext(): boolean {\n if (this.documents === null) throw Error('Error while fetching documents');\n return this.index < this.documents.length;\n }\n\n async next(): Promise<T | null> {\n const docs = await this.findDocuments();\n return this.hasNext() ? (docs[this.index++] ?? null) : null;\n }\n\n private async findDocuments(): Promise<T[]> {\n this.documents = await this.findDocumentsPromise;\n return this.documents;\n }\n}\n","import {\n Collection as MongoCollection,\n ObjectId,\n type Document,\n} from 'mongodb';\nimport type {\n DocumentHandler,\n HandleOptions,\n PongoDb,\n PongoHandleResult,\n} from '../core';\nimport { Collection } from './mongoCollection';\n\nexport class Db {\n constructor(private pongoDb: PongoDb) {}\n\n get databaseName(): string {\n return this.pongoDb.databaseName;\n }\n\n collection<T extends Document>(\n collectionName: string,\n ): MongoCollection<T> & {\n handle(\n id: ObjectId,\n handle: DocumentHandler<T>,\n options?: HandleOptions,\n ): Promise<PongoHandleResult<T>>;\n } {\n return new Collection<T>(this.pongoDb.collection<T>(collectionName));\n }\n}\n","import type {\n AbstractCursorOptions,\n AggregateOptions,\n AggregationCursor,\n AnyBulkWriteOperation,\n BSONSerializeOptions,\n BulkWriteOptions,\n BulkWriteResult,\n ChangeStream,\n ChangeStreamDocument,\n ChangeStreamOptions,\n CommandOperationOptions,\n CountDocumentsOptions,\n CountOptions,\n CreateIndexesOptions,\n DeleteOptions,\n DeleteResult,\n Document,\n DropCollectionOptions,\n EnhancedOmit,\n EstimatedDocumentCountOptions,\n Filter,\n FindOneAndDeleteOptions,\n FindOneAndReplaceOptions,\n FindOneAndUpdateOptions,\n FindOptions,\n Flatten,\n Hint,\n IndexDescription,\n IndexDescriptionCompact,\n IndexDescriptionInfo,\n IndexInformationOptions,\n IndexSpecification,\n InferIdType,\n InsertManyResult,\n InsertOneOptions,\n InsertOneResult,\n ListIndexesCursor,\n ListSearchIndexesCursor,\n ListSearchIndexesOptions,\n ModifyResult,\n Collection as MongoCollection,\n FindCursor as MongoFindCursor,\n ObjectId,\n OperationOptions,\n OptionalUnlessRequiredId,\n OrderedBulkOperation,\n ReadConcern,\n ReadPreference,\n RenameOptions,\n ReplaceOptions,\n SearchIndexDescription,\n UnorderedBulkOperation,\n UpdateFilter,\n UpdateOptions,\n UpdateResult,\n WithId,\n WithoutId,\n WriteConcern,\n} from 'mongodb';\nimport type { Key } from 'readline';\nimport type {\n CollectionOperationOptions,\n DocumentHandler,\n HandleOptions,\n PongoCollection,\n PongoFilter,\n PongoHandleResult,\n OptionalUnlessRequiredId as PongoOptionalUnlessRequiredId,\n PongoSession,\n PongoUpdate,\n} from '../core';\nimport { FindCursor } from './findCursor';\n\nconst toCollectionOperationOptions = (\n options: OperationOptions | undefined,\n): CollectionOperationOptions | undefined =>\n options?.session\n ? { session: options.session as unknown as PongoSession }\n : undefined;\n\nexport class Collection<T extends Document> implements MongoCollection<T> {\n private collection: PongoCollection<T>;\n\n constructor(collection: PongoCollection<T>) {\n this.collection = collection;\n }\n get dbName(): string {\n return this.collection.dbName;\n }\n get collectionName(): string {\n return this.collection.collectionName;\n }\n get namespace(): string {\n return `${this.dbName}.${this.collectionName}`;\n }\n get readConcern(): ReadConcern | undefined {\n return undefined;\n }\n get readPreference(): ReadPreference | undefined {\n return undefined;\n }\n get bsonOptions(): BSONSerializeOptions {\n return {};\n }\n get writeConcern(): WriteConcern | undefined {\n return undefined;\n }\n get hint(): Hint | undefined {\n return undefined;\n }\n set hint(v: Hint | undefined) {\n throw new Error('Method not implemented.');\n }\n async insertOne(\n doc: OptionalUnlessRequiredId<T>,\n options?: InsertOneOptions | undefined,\n ): Promise<InsertOneResult<T>> {\n const result = await this.collection.insertOne(\n doc as unknown as PongoOptionalUnlessRequiredId<T>,\n toCollectionOperationOptions(options),\n );\n return {\n acknowledged: result.acknowledged,\n insertedId: result.insertedId as unknown as InferIdType<T>,\n };\n }\n async insertMany(\n docs: OptionalUnlessRequiredId<T>[],\n options?: BulkWriteOptions | undefined,\n ): Promise<InsertManyResult<T>> {\n const result = await this.collection.insertMany(\n docs as unknown as PongoOptionalUnlessRequiredId<T>[],\n toCollectionOperationOptions(options),\n );\n return {\n acknowledged: result.acknowledged,\n insertedIds: result.insertedIds as unknown as InferIdType<T>[],\n insertedCount: result.insertedCount,\n };\n }\n bulkWrite(\n _operations: AnyBulkWriteOperation<T>[],\n _options?: BulkWriteOptions | undefined,\n ): Promise<BulkWriteResult> {\n throw new Error('Method not implemented.');\n }\n async updateOne(\n filter: Filter<T>,\n update: Document[] | UpdateFilter<T>,\n options?: UpdateOptions | undefined,\n ): Promise<UpdateResult<T>> {\n const result = await this.collection.updateOne(\n filter as unknown as PongoFilter<T>,\n update as unknown as PongoUpdate<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n matchedCount: result.modifiedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.modifiedCount,\n upsertedId: null,\n };\n }\n replaceOne(\n filter: Filter<T>,\n document: WithoutId<T>,\n options?: ReplaceOptions | undefined,\n ): Promise<Document | UpdateResult<T>> {\n return this.collection.replaceOne(\n filter as unknown as PongoFilter<T>,\n document,\n toCollectionOperationOptions(options),\n );\n }\n async updateMany(\n filter: Filter<T>,\n update: Document[] | UpdateFilter<T>,\n options?: UpdateOptions | undefined,\n ): Promise<UpdateResult<T>> {\n const result = await this.collection.updateMany(\n filter as unknown as PongoFilter<T>,\n update as unknown as PongoUpdate<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n matchedCount: result.modifiedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.modifiedCount,\n upsertedId: null,\n };\n }\n async deleteOne(\n filter?: Filter<T> | undefined,\n options?: DeleteOptions | undefined,\n ): Promise<DeleteResult> {\n const result = await this.collection.deleteOne(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n deletedCount: result.deletedCount,\n };\n }\n async deleteMany(\n filter?: Filter<T> | undefined,\n options?: DeleteOptions | undefined,\n ): Promise<DeleteResult> {\n const result = await this.collection.deleteMany(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n deletedCount: result.deletedCount,\n };\n }\n async rename(\n newName: string,\n options?: RenameOptions | undefined,\n ): Promise<Collection<Document>> {\n await this.collection.rename(\n newName,\n toCollectionOperationOptions(options),\n );\n\n return this as unknown as Collection<Document>;\n }\n drop(options?: DropCollectionOptions | undefined): Promise<boolean> {\n return this.collection.drop(toCollectionOperationOptions(options));\n }\n findOne(): Promise<WithId<T> | null>;\n findOne(filter: Filter<T>): Promise<WithId<T> | null>;\n findOne(\n filter: Filter<T>,\n options: FindOptions<Document>,\n ): Promise<WithId<T> | null>;\n findOne<TS = T>(): Promise<TS | null>;\n findOne<TS = T>(filter: Filter<TS>): Promise<TS | null>;\n findOne<TS = T>(\n filter: Filter<TS>,\n options?: FindOptions<Document> | undefined,\n ): Promise<TS | null>;\n async findOne(\n filter?: unknown,\n options?: FindOptions<Document> | undefined,\n ): Promise<import('mongodb').WithId<T> | T | null> {\n return (await this.collection.findOne(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n )) as T;\n }\n find(): MongoFindCursor<WithId<T>>;\n find(\n filter: Filter<T>,\n options?: FindOptions<Document> | undefined,\n ): MongoFindCursor<WithId<T>>;\n find<T extends Document>(\n filter: Filter<T>,\n options?: FindOptions<Document> | undefined,\n ): MongoFindCursor<T>;\n find(\n filter?: unknown,\n options?: FindOptions<Document> | undefined,\n ): MongoFindCursor<WithId<T>> | MongoFindCursor<T> {\n return new FindCursor(\n this.collection.find(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n ),\n ) as unknown as MongoFindCursor<T>;\n }\n options(_options?: OperationOptions | undefined): Promise<Document> {\n throw new Error('Method not implemented.');\n }\n isCapped(_options?: OperationOptions | undefined): Promise<boolean> {\n throw new Error('Method not implemented.');\n }\n createIndex(\n _indexSpec: IndexSpecification,\n _options?: CreateIndexesOptions | undefined,\n ): Promise<string> {\n throw new Error('Method not implemented.');\n }\n createIndexes(\n _indexSpecs: IndexDescription[],\n _options?: CreateIndexesOptions | undefined,\n ): Promise<string[]> {\n throw new Error('Method not implemented.');\n }\n dropIndex(\n _indexName: string,\n _options?: CommandOperationOptions | undefined,\n ): Promise<Document> {\n throw new Error('Method not implemented.');\n }\n dropIndexes(\n _options?: CommandOperationOptions | undefined,\n ): Promise<boolean> {\n throw new Error('Method not implemented.');\n }\n listIndexes(_options?: AbstractCursorOptions | undefined): ListIndexesCursor {\n throw new Error('Method not implemented.');\n }\n indexExists(\n _indexes: string | string[],\n _options?: AbstractCursorOptions | undefined,\n ): Promise<boolean> {\n throw new Error('Method not implemented.');\n }\n indexInformation(\n options: IndexInformationOptions & { full: true },\n ): Promise<IndexDescriptionInfo[]>;\n indexInformation(\n options: IndexInformationOptions & { full?: false | undefined },\n ): Promise<IndexDescriptionCompact>;\n indexInformation(\n options: IndexInformationOptions,\n ): Promise<IndexDescriptionCompact | IndexDescriptionInfo[]>;\n indexInformation(): Promise<IndexDescriptionCompact>;\n indexInformation(\n _options?: unknown,\n ):\n | Promise<import('mongodb').IndexDescriptionInfo[]>\n | Promise<import('mongodb').IndexDescriptionCompact>\n | Promise<\n | import('mongodb').IndexDescriptionCompact\n | import('mongodb').IndexDescriptionInfo[]\n > {\n throw new Error('Method not implemented.');\n }\n estimatedDocumentCount(\n options?: EstimatedDocumentCountOptions | undefined,\n ): Promise<number> {\n return this.collection.countDocuments(\n {},\n toCollectionOperationOptions(options),\n );\n }\n countDocuments(\n filter?: Filter<T> | undefined,\n options?: CountDocumentsOptions | undefined,\n ): Promise<number> {\n return this.collection.countDocuments(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n );\n }\n distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(\n key: Key,\n ): Promise<Flatten<WithId<T>[Key]>[]>;\n distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(\n key: Key,\n filter: Filter<T>,\n ): Promise<Flatten<WithId<T>[Key]>[]>;\n distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(\n key: Key,\n filter: Filter<T>,\n options: CommandOperationOptions,\n ): Promise<Flatten<WithId<T>[Key]>[]>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n distinct(key: string): Promise<any[]>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n distinct(key: string, filter: Filter<T>): Promise<any[]>;\n distinct(\n key: string,\n filter: Filter<T>,\n options: CommandOperationOptions, // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any[]>;\n distinct(\n _key: unknown,\n _filter?: unknown,\n _options?: unknown,\n ): // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Promise<any[]>\n | Promise<import('mongodb').Flatten<import('mongodb').WithId<T>[Key]>[]> {\n throw new Error('Method not implemented.');\n }\n indexes(\n options: IndexInformationOptions & { full?: true | undefined },\n ): Promise<IndexDescriptionInfo[]>;\n indexes(\n options: IndexInformationOptions & { full: false },\n ): Promise<IndexDescriptionCompact>;\n indexes(\n options: IndexInformationOptions,\n ): Promise<IndexDescriptionCompact | IndexDescriptionInfo[]>;\n indexes(\n options?: AbstractCursorOptions | undefined,\n ): Promise<IndexDescriptionInfo[]>;\n indexes(\n _options?: unknown,\n ):\n | Promise<import('mongodb').IndexDescriptionInfo[]>\n | Promise<import('mongodb').IndexDescriptionCompact>\n | Promise<\n | import('mongodb').IndexDescriptionCompact\n | import('mongodb').IndexDescriptionInfo[]\n > {\n throw new Error('Method not implemented.');\n }\n findOneAndDelete(\n filter: Filter<T>,\n options: FindOneAndDeleteOptions & { includeResultMetadata: true },\n ): Promise<ModifyResult<T>>;\n findOneAndDelete(\n filter: Filter<T>,\n options: FindOneAndDeleteOptions & { includeResultMetadata: false },\n ): Promise<WithId<T> | null>;\n findOneAndDelete(\n filter: Filter<T>,\n options: FindOneAndDeleteOptions,\n ): Promise<WithId<T> | null>;\n findOneAndDelete(filter: Filter<T>): Promise<WithId<T> | null>;\n findOneAndDelete(\n filter: unknown,\n options?: FindOneAndDeleteOptions,\n ): Promise<WithId<T> | null | ModifyResult<T>> {\n return this.collection.findOneAndDelete(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n ) as Promise<WithId<T> | null>;\n }\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n options: FindOneAndReplaceOptions & { includeResultMetadata: true },\n ): Promise<ModifyResult<T>>;\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n options: FindOneAndReplaceOptions & { includeResultMetadata: false },\n ): Promise<WithId<T> | null>;\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n options: FindOneAndReplaceOptions,\n ): Promise<WithId<T> | null>;\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n ): Promise<WithId<T> | null>;\n findOneAndReplace(\n filter: unknown,\n replacement: unknown,\n options?: FindOneAndReplaceOptions | undefined,\n ): Promise<WithId<T> | null | ModifyResult<T>> {\n return this.collection.findOneAndReplace(\n filter as PongoFilter<T>,\n replacement as WithoutId<T>,\n toCollectionOperationOptions(options),\n ) as Promise<WithId<T> | null>;\n }\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n options: FindOneAndUpdateOptions & { includeResultMetadata: true },\n ): Promise<ModifyResult<T>>;\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n options: FindOneAndUpdateOptions & { includeResultMetadata: false },\n ): Promise<WithId<T> | null>;\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n options: FindOneAndUpdateOptions,\n ): Promise<WithId<T> | null>;\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n ): Promise<WithId<T> | null>;\n findOneAndUpdate(\n filter: unknown,\n update: unknown,\n options?: FindOneAndUpdateOptions | undefined,\n ): Promise<WithId<T> | null | ModifyResult<T>> {\n return this.collection.findOneAndUpdate(\n filter as PongoFilter<T>,\n update as PongoUpdate<T>,\n toCollectionOperationOptions(options),\n ) as Promise<WithId<T> | null>;\n }\n aggregate<T extends Document = Document>(\n _pipeline?: Document[] | undefined,\n _options?: AggregateOptions | undefined,\n ): AggregationCursor<T> {\n throw new Error('Method not implemented.');\n }\n watch<\n TLocal extends Document = T,\n TChange extends Document = ChangeStreamDocument<TLocal>,\n >(\n _pipeline?: Document[] | undefined,\n _options?: ChangeStreamOptions | undefined,\n ): ChangeStream<TLocal, TChange> {\n throw new Error('Method not implemented.');\n }\n initializeUnorderedBulkOp(\n _options?: BulkWriteOptions | undefined,\n ): UnorderedBulkOperation {\n throw new Error('Method not implemented.');\n }\n initializeOrderedBulkOp(\n _options?: BulkWriteOptions | undefined,\n ): OrderedBulkOperation {\n throw new Error('Method not implemented.');\n }\n count(\n filter?: Filter<T> | undefined,\n options?: CountOptions | undefined,\n ): Promise<number> {\n return this.collection.countDocuments(\n (filter as PongoFilter<T>) ?? {},\n toCollectionOperationOptions(options),\n );\n }\n listSearchIndexes(\n options?: ListSearchIndexesOptions | undefined,\n ): ListSearchIndexesCursor;\n listSearchIndexes(\n name: string,\n options?: ListSearchIndexesOptions | undefined,\n ): ListSearchIndexesCursor;\n listSearchIndexes(\n _name?: unknown,\n _options?: unknown,\n ): import('mongodb').ListSearchIndexesCursor {\n throw new Error('Method not implemented.');\n }\n createSearchIndex(_description: SearchIndexDescription): Promise<string> {\n throw new Error('Method not implemented.');\n }\n createSearchIndexes(\n _descriptions: SearchIndexDescription[],\n ): Promise<string[]> {\n throw new Error('Method not implemented.');\n }\n dropSearchIndex(_name: string): Promise<void> {\n throw new Error('Method not implemented.');\n }\n updateSearchIndex(_name: string, _definition: Document): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n async createCollection(): Promise<void> {\n await this.collection.createCollection();\n }\n async handle(\n id: ObjectId,\n handle: DocumentHandler<T>,\n options?: HandleOptions,\n ): Promise<PongoHandleResult<T>> {\n return this.collection.handle(id.toString(), handle, options);\n }\n}\n","import type { ClientSessionOptions } from 'http2';\nimport type { ClientSession, WithSessionCallback } from 'mongodb';\nimport {\n pongoClient,\n pongoSession,\n type PongoClient,\n type PongoClientOptions,\n} from '../core';\nimport { Db } from './mongoDb';\n\nexport class MongoClient {\n private pongoClient: PongoClient;\n\n constructor(connectionString: string, options: PongoClientOptions = {}) {\n this.pongoClient = pongoClient(connectionString, options);\n }\n\n async connect() {\n await this.pongoClient.connect();\n return this;\n }\n\n async close() {\n await this.pongoClient.close();\n }\n\n db(dbName?: string): Db {\n return new Db(this.pongoClient.db(dbName));\n }\n startSession(_options?: ClientSessionOptions): ClientSession {\n return pongoSession() as unknown as ClientSession;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n withSession<T = any>(_executor: WithSessionCallback<T>): Promise<T>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n withSession<T = any>(\n _options: ClientSessionOptions,\n _executor: WithSessionCallback<T>,\n ): Promise<T>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async withSession<T = any>(\n optionsOrExecutor: ClientSessionOptions | WithSessionCallback<T>,\n executor?: WithSessionCallback<T>,\n ): Promise<T> {\n const callback =\n typeof optionsOrExecutor === 'function' ? optionsOrExecutor : executor!;\n\n const session = pongoSession() as unknown as ClientSession;\n\n try {\n return await callback(session);\n } finally {\n await session.endSession();\n }\n }\n}\n"],"mappings":"+CAAO,IAAMA,EAAN,KAAoB,CACjB,qBACA,UAAwB,KACxB,MAAgB,EAExB,YAAYC,EAAyB,CACnC,KAAK,qBAAuBA,CAC9B,CAEA,MAAM,SAAwB,CAC5B,OAAO,KAAK,cAAc,CAC5B,CAEA,MAAM,QAAQC,EAA2C,CACvD,IAAMC,EAAO,MAAM,KAAK,cAAc,EAEtC,QAAWC,KAAOD,EAChBD,EAASE,CAAG,EAEd,OAAO,QAAQ,QAAQ,CACzB,CAEA,SAAmB,CACjB,GAAI,KAAK,YAAc,KAAM,MAAM,MAAM,gCAAgC,EACzE,OAAO,KAAK,MAAQ,KAAK,UAAU,MACrC,CAEA,MAAM,MAA0B,CAC9B,IAAMD,EAAO,MAAM,KAAK,cAAc,EACtC,OAAO,KAAK,QAAQ,EAAKA,EAAK,KAAK,OAAO,GAAK,KAAQ,IACzD,CAEA,MAAc,eAA8B,CAC1C,YAAK,UAAY,MAAM,KAAK,qBACrB,KAAK,SACd,CACF,ECpCA,MAIO,UCsEP,IAAME,EACJC,GAEAA,GAAS,QACL,CAAE,QAASA,EAAQ,OAAmC,EACtD,OAEOC,EAAN,KAAmE,CAChE,WAER,YAAYC,EAAgC,CAC1C,KAAK,WAAaA,CACpB,CACA,IAAI,QAAiB,CACnB,OAAO,KAAK,WAAW,MACzB,CACA,IAAI,gBAAyB,CAC3B,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C3C,CACA,kBAAkBA,EAAeG,EAAsC,CACrE,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,MAAM,kBAAkC,CACtC,MAAM,KAAK,WAAW,iBAAiB,CACzC,CACA,MAAM,OACJC,EACAC,EACA3B,EAC+B,CAC/B,OAAO,KAAK,WAAW,OAAO0B,EAAG,SAAS,EAAGC,EAAQ3B,CAAO,CAC9D,CACF,EDriBO,IAAM4B,EAAN,KAAS,CACd,YAAoBC,EAAkB,CAAlB,aAAAA,CAAmB,CAEvC,IAAI,cAAuB,CACzB,OAAO,KAAK,QAAQ,YACtB,CAEA,WACEC,EAOA,CACA,OAAO,IAAIC,EAAc,KAAK,QAAQ,WAAcD,CAAc,CAAC,CACrE,CACF,EErBO,IAAME,EAAN,KAAkB,CACf,YAER,YAAYC,EAA0BC,EAA8B,CAAC,EAAG,CACtE,KAAK,YAAcC,EAAYF,EAAkBC,CAAO,CAC1D,CAEA,MAAM,SAAU,CACd,aAAM,KAAK,YAAY,QAAQ,EACxB,IACT,CAEA,MAAM,OAAQ,CACZ,MAAM,KAAK,YAAY,MAAM,CAC/B,CAEA,GAAGE,EAAqB,CACtB,OAAO,IAAIC,EAAG,KAAK,YAAY,GAAGD,CAAM,CAAC,CAC3C,CACA,aAAaE,EAAgD,CAC3D,OAAOC,EAAa,CACtB,CASA,MAAM,YACJC,EACAC,EACY,CACZ,IAAMC,EACJ,OAAOF,GAAsB,WAAaA,EAAoBC,EAE1DE,EAAUJ,EAAa,EAE7B,GAAI,CACF,OAAO,MAAMG,EAASC,CAAO,CAC/B,QAAE,CACA,MAAMA,EAAQ,WAAW,CAC3B,CACF,CACF","names":["FindCursor","documents","callback","docs","doc","toCollectionOperationOptions","options","Collection","collection","v","doc","result","docs","_operations","_options","filter","update","document","newName","FindCursor","_indexSpec","_indexSpecs","_indexName","_indexes","_key","_filter","replacement","_pipeline","_name","_description","_descriptions","_definition","id","handle","Db","pongoDb","collectionName","Collection","MongoClient","connectionString","options","pongoClient","dbName","Db","_options","pongoSession","optionsOrExecutor","executor","callback","session"]}
1
+ {"version":3,"sources":["../src/mongo/findCursor.ts","../src/mongo/mongoDb.ts","../src/mongo/mongoCollection.ts","../src/mongo/mongoClient.ts"],"sourcesContent":["export class FindCursor<T> {\n private findDocumentsPromise: Promise<T[]>;\n private documents: T[] | null = null;\n private index: number = 0;\n\n constructor(documents: Promise<T[]>) {\n this.findDocumentsPromise = documents;\n }\n\n async toArray(): Promise<T[]> {\n return this.findDocuments();\n }\n\n async forEach(callback: (doc: T) => void): Promise<void> {\n const docs = await this.findDocuments();\n\n for (const doc of docs) {\n callback(doc);\n }\n return Promise.resolve();\n }\n\n hasNext(): boolean {\n if (this.documents === null) throw Error('Error while fetching documents');\n return this.index < this.documents.length;\n }\n\n async next(): Promise<T | null> {\n const docs = await this.findDocuments();\n return this.hasNext() ? (docs[this.index++] ?? null) : null;\n }\n\n private async findDocuments(): Promise<T[]> {\n this.documents = await this.findDocumentsPromise;\n return this.documents;\n }\n}\n","import {\n Collection as MongoCollection,\n ObjectId,\n type Document,\n} from 'mongodb';\nimport type {\n DocumentHandler,\n HandleOptions,\n PongoDb,\n PongoHandleResult,\n} from '../core';\nimport { Collection } from './mongoCollection';\n\nexport class Db {\n constructor(private pongoDb: PongoDb) {}\n\n get databaseName(): string {\n return this.pongoDb.databaseName;\n }\n\n collection<T extends Document>(\n collectionName: string,\n ): MongoCollection<T> & {\n handle(\n id: ObjectId,\n handle: DocumentHandler<T>,\n options?: HandleOptions,\n ): Promise<PongoHandleResult<T>>;\n } {\n return new Collection<T>(this.pongoDb.collection<T>(collectionName));\n }\n}\n","import type {\n AbstractCursorOptions,\n AggregateOptions,\n AggregationCursor,\n AnyBulkWriteOperation,\n BSONSerializeOptions,\n BulkWriteOptions,\n BulkWriteResult,\n ChangeStream,\n ChangeStreamDocument,\n ChangeStreamOptions,\n CommandOperationOptions,\n CountDocumentsOptions,\n CountOptions,\n CreateIndexesOptions,\n DeleteOptions,\n DeleteResult,\n Document,\n DropCollectionOptions,\n EnhancedOmit,\n EstimatedDocumentCountOptions,\n Filter,\n FindOneAndDeleteOptions,\n FindOneAndReplaceOptions,\n FindOneAndUpdateOptions,\n FindOptions,\n Flatten,\n Hint,\n IndexDescription,\n IndexDescriptionCompact,\n IndexDescriptionInfo,\n IndexInformationOptions,\n IndexSpecification,\n InferIdType,\n InsertManyResult,\n InsertOneOptions,\n InsertOneResult,\n ListIndexesCursor,\n ListSearchIndexesCursor,\n ListSearchIndexesOptions,\n ModifyResult,\n Collection as MongoCollection,\n FindCursor as MongoFindCursor,\n ObjectId,\n OperationOptions,\n OptionalUnlessRequiredId,\n OrderedBulkOperation,\n ReadConcern,\n ReadPreference,\n RenameOptions,\n ReplaceOptions,\n SearchIndexDescription,\n UnorderedBulkOperation,\n UpdateFilter,\n UpdateOptions,\n UpdateResult,\n WithId,\n WithoutId,\n WriteConcern,\n} from 'mongodb';\nimport type { Key } from 'readline';\nimport type {\n CollectionOperationOptions,\n DocumentHandler,\n HandleOptions,\n PongoCollection,\n PongoFilter,\n PongoHandleResult,\n OptionalUnlessRequiredId as PongoOptionalUnlessRequiredId,\n PongoSession,\n PongoUpdate,\n} from '../core';\nimport { FindCursor } from './findCursor';\n\nconst toCollectionOperationOptions = (\n options: OperationOptions | undefined,\n): CollectionOperationOptions | undefined =>\n options?.session\n ? { session: options.session as unknown as PongoSession }\n : undefined;\n\nexport class Collection<T extends Document> implements MongoCollection<T> {\n private collection: PongoCollection<T>;\n\n constructor(collection: PongoCollection<T>) {\n this.collection = collection;\n }\n get dbName(): string {\n return this.collection.dbName;\n }\n get collectionName(): string {\n return this.collection.collectionName;\n }\n get namespace(): string {\n return `${this.dbName}.${this.collectionName}`;\n }\n get readConcern(): ReadConcern | undefined {\n return undefined;\n }\n get readPreference(): ReadPreference | undefined {\n return undefined;\n }\n get bsonOptions(): BSONSerializeOptions {\n return {};\n }\n get writeConcern(): WriteConcern | undefined {\n return undefined;\n }\n get hint(): Hint | undefined {\n return undefined;\n }\n set hint(v: Hint | undefined) {\n throw new Error('Method not implemented.');\n }\n async insertOne(\n doc: OptionalUnlessRequiredId<T>,\n options?: InsertOneOptions | undefined,\n ): Promise<InsertOneResult<T>> {\n const result = await this.collection.insertOne(\n doc as unknown as PongoOptionalUnlessRequiredId<T>,\n toCollectionOperationOptions(options),\n );\n return {\n acknowledged: result.acknowledged,\n insertedId: result.insertedId as unknown as InferIdType<T>,\n };\n }\n async insertMany(\n docs: OptionalUnlessRequiredId<T>[],\n options?: BulkWriteOptions | undefined,\n ): Promise<InsertManyResult<T>> {\n const result = await this.collection.insertMany(\n docs as unknown as PongoOptionalUnlessRequiredId<T>[],\n toCollectionOperationOptions(options),\n );\n return {\n acknowledged: result.acknowledged,\n insertedIds: result.insertedIds as unknown as InferIdType<T>[],\n insertedCount: result.insertedCount,\n };\n }\n bulkWrite(\n _operations: AnyBulkWriteOperation<T>[],\n _options?: BulkWriteOptions | undefined,\n ): Promise<BulkWriteResult> {\n throw new Error('Method not implemented.');\n }\n async updateOne(\n filter: Filter<T>,\n update: Document[] | UpdateFilter<T>,\n options?: UpdateOptions | undefined,\n ): Promise<UpdateResult<T>> {\n const result = await this.collection.updateOne(\n filter as unknown as PongoFilter<T>,\n update as unknown as PongoUpdate<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n matchedCount: result.modifiedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.modifiedCount,\n upsertedId: null,\n };\n }\n replaceOne(\n filter: Filter<T>,\n document: WithoutId<T>,\n options?: ReplaceOptions | undefined,\n ): Promise<Document | UpdateResult<T>> {\n return this.collection.replaceOne(\n filter as unknown as PongoFilter<T>,\n document,\n toCollectionOperationOptions(options),\n );\n }\n async updateMany(\n filter: Filter<T>,\n update: Document[] | UpdateFilter<T>,\n options?: UpdateOptions | undefined,\n ): Promise<UpdateResult<T>> {\n const result = await this.collection.updateMany(\n filter as unknown as PongoFilter<T>,\n update as unknown as PongoUpdate<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n matchedCount: result.modifiedCount,\n modifiedCount: result.modifiedCount,\n upsertedCount: result.modifiedCount,\n upsertedId: null,\n };\n }\n async deleteOne(\n filter?: Filter<T> | undefined,\n options?: DeleteOptions | undefined,\n ): Promise<DeleteResult> {\n const result = await this.collection.deleteOne(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n deletedCount: result.deletedCount,\n };\n }\n async deleteMany(\n filter?: Filter<T> | undefined,\n options?: DeleteOptions | undefined,\n ): Promise<DeleteResult> {\n const result = await this.collection.deleteMany(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n );\n\n return {\n acknowledged: result.acknowledged,\n deletedCount: result.deletedCount,\n };\n }\n async rename(\n newName: string,\n options?: RenameOptions | undefined,\n ): Promise<Collection<Document>> {\n await this.collection.rename(\n newName,\n toCollectionOperationOptions(options),\n );\n\n return this as unknown as Collection<Document>;\n }\n drop(options?: DropCollectionOptions | undefined): Promise<boolean> {\n return this.collection.drop(toCollectionOperationOptions(options));\n }\n findOne(): Promise<WithId<T> | null>;\n findOne(filter: Filter<T>): Promise<WithId<T> | null>;\n findOne(\n filter: Filter<T>,\n options: FindOptions<Document>,\n ): Promise<WithId<T> | null>;\n findOne<TS = T>(): Promise<TS | null>;\n findOne<TS = T>(filter: Filter<TS>): Promise<TS | null>;\n findOne<TS = T>(\n filter: Filter<TS>,\n options?: FindOptions<Document> | undefined,\n ): Promise<TS | null>;\n async findOne(\n filter?: unknown,\n options?: FindOptions<Document> | undefined,\n ): Promise<import('mongodb').WithId<T> | T | null> {\n return (await this.collection.findOne(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n )) as T;\n }\n find(): MongoFindCursor<WithId<T>>;\n find(\n filter: Filter<T>,\n options?: FindOptions<Document> | undefined,\n ): MongoFindCursor<WithId<T>>;\n find<T extends Document>(\n filter: Filter<T>,\n options?: FindOptions<Document> | undefined,\n ): MongoFindCursor<T>;\n find(\n filter?: unknown,\n options?: FindOptions<Document> | undefined,\n ): MongoFindCursor<WithId<T>> | MongoFindCursor<T> {\n return new FindCursor(\n this.collection.find(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n ),\n ) as unknown as MongoFindCursor<T>;\n }\n options(_options?: OperationOptions | undefined): Promise<Document> {\n throw new Error('Method not implemented.');\n }\n isCapped(_options?: OperationOptions | undefined): Promise<boolean> {\n throw new Error('Method not implemented.');\n }\n createIndex(\n _indexSpec: IndexSpecification,\n _options?: CreateIndexesOptions | undefined,\n ): Promise<string> {\n throw new Error('Method not implemented.');\n }\n createIndexes(\n _indexSpecs: IndexDescription[],\n _options?: CreateIndexesOptions | undefined,\n ): Promise<string[]> {\n throw new Error('Method not implemented.');\n }\n dropIndex(\n _indexName: string,\n _options?: CommandOperationOptions | undefined,\n ): Promise<Document> {\n throw new Error('Method not implemented.');\n }\n dropIndexes(\n _options?: CommandOperationOptions | undefined,\n ): Promise<boolean> {\n throw new Error('Method not implemented.');\n }\n listIndexes(_options?: AbstractCursorOptions | undefined): ListIndexesCursor {\n throw new Error('Method not implemented.');\n }\n indexExists(\n _indexes: string | string[],\n _options?: AbstractCursorOptions | undefined,\n ): Promise<boolean> {\n throw new Error('Method not implemented.');\n }\n indexInformation(\n options: IndexInformationOptions & { full: true },\n ): Promise<IndexDescriptionInfo[]>;\n indexInformation(\n options: IndexInformationOptions & { full?: false | undefined },\n ): Promise<IndexDescriptionCompact>;\n indexInformation(\n options: IndexInformationOptions,\n ): Promise<IndexDescriptionCompact | IndexDescriptionInfo[]>;\n indexInformation(): Promise<IndexDescriptionCompact>;\n indexInformation(\n _options?: unknown,\n ):\n | Promise<import('mongodb').IndexDescriptionInfo[]>\n | Promise<import('mongodb').IndexDescriptionCompact>\n | Promise<\n | import('mongodb').IndexDescriptionCompact\n | import('mongodb').IndexDescriptionInfo[]\n > {\n throw new Error('Method not implemented.');\n }\n estimatedDocumentCount(\n options?: EstimatedDocumentCountOptions | undefined,\n ): Promise<number> {\n return this.collection.countDocuments(\n {},\n toCollectionOperationOptions(options),\n );\n }\n countDocuments(\n filter?: Filter<T> | undefined,\n options?: CountDocumentsOptions | undefined,\n ): Promise<number> {\n return this.collection.countDocuments(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n );\n }\n distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(\n key: Key,\n ): Promise<Flatten<WithId<T>[Key]>[]>;\n distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(\n key: Key,\n filter: Filter<T>,\n ): Promise<Flatten<WithId<T>[Key]>[]>;\n distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(\n key: Key,\n filter: Filter<T>,\n options: CommandOperationOptions,\n ): Promise<Flatten<WithId<T>[Key]>[]>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n distinct(key: string): Promise<any[]>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n distinct(key: string, filter: Filter<T>): Promise<any[]>;\n distinct(\n key: string,\n filter: Filter<T>,\n options: CommandOperationOptions, // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any[]>;\n distinct(\n _key: unknown,\n _filter?: unknown,\n _options?: unknown,\n ): // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Promise<any[]>\n | Promise<import('mongodb').Flatten<import('mongodb').WithId<T>[Key]>[]> {\n throw new Error('Method not implemented.');\n }\n indexes(\n options: IndexInformationOptions & { full?: true | undefined },\n ): Promise<IndexDescriptionInfo[]>;\n indexes(\n options: IndexInformationOptions & { full: false },\n ): Promise<IndexDescriptionCompact>;\n indexes(\n options: IndexInformationOptions,\n ): Promise<IndexDescriptionCompact | IndexDescriptionInfo[]>;\n indexes(\n options?: AbstractCursorOptions | undefined,\n ): Promise<IndexDescriptionInfo[]>;\n indexes(\n _options?: unknown,\n ):\n | Promise<import('mongodb').IndexDescriptionInfo[]>\n | Promise<import('mongodb').IndexDescriptionCompact>\n | Promise<\n | import('mongodb').IndexDescriptionCompact\n | import('mongodb').IndexDescriptionInfo[]\n > {\n throw new Error('Method not implemented.');\n }\n findOneAndDelete(\n filter: Filter<T>,\n options: FindOneAndDeleteOptions & { includeResultMetadata: true },\n ): Promise<ModifyResult<T>>;\n findOneAndDelete(\n filter: Filter<T>,\n options: FindOneAndDeleteOptions & { includeResultMetadata: false },\n ): Promise<WithId<T> | null>;\n findOneAndDelete(\n filter: Filter<T>,\n options: FindOneAndDeleteOptions,\n ): Promise<WithId<T> | null>;\n findOneAndDelete(filter: Filter<T>): Promise<WithId<T> | null>;\n findOneAndDelete(\n filter: unknown,\n options?: FindOneAndDeleteOptions,\n ): Promise<WithId<T> | null | ModifyResult<T>> {\n return this.collection.findOneAndDelete(\n filter as PongoFilter<T>,\n toCollectionOperationOptions(options),\n ) as Promise<WithId<T> | null>;\n }\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n options: FindOneAndReplaceOptions & { includeResultMetadata: true },\n ): Promise<ModifyResult<T>>;\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n options: FindOneAndReplaceOptions & { includeResultMetadata: false },\n ): Promise<WithId<T> | null>;\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n options: FindOneAndReplaceOptions,\n ): Promise<WithId<T> | null>;\n findOneAndReplace(\n filter: Filter<T>,\n replacement: WithoutId<T>,\n ): Promise<WithId<T> | null>;\n findOneAndReplace(\n filter: unknown,\n replacement: unknown,\n options?: FindOneAndReplaceOptions | undefined,\n ): Promise<WithId<T> | null | ModifyResult<T>> {\n return this.collection.findOneAndReplace(\n filter as PongoFilter<T>,\n replacement as WithoutId<T>,\n toCollectionOperationOptions(options),\n ) as Promise<WithId<T> | null>;\n }\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n options: FindOneAndUpdateOptions & { includeResultMetadata: true },\n ): Promise<ModifyResult<T>>;\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n options: FindOneAndUpdateOptions & { includeResultMetadata: false },\n ): Promise<WithId<T> | null>;\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n options: FindOneAndUpdateOptions,\n ): Promise<WithId<T> | null>;\n findOneAndUpdate(\n filter: Filter<T>,\n update: UpdateFilter<T>,\n ): Promise<WithId<T> | null>;\n findOneAndUpdate(\n filter: unknown,\n update: unknown,\n options?: FindOneAndUpdateOptions | undefined,\n ): Promise<WithId<T> | null | ModifyResult<T>> {\n return this.collection.findOneAndUpdate(\n filter as PongoFilter<T>,\n update as PongoUpdate<T>,\n toCollectionOperationOptions(options),\n ) as Promise<WithId<T> | null>;\n }\n aggregate<T extends Document = Document>(\n _pipeline?: Document[] | undefined,\n _options?: AggregateOptions | undefined,\n ): AggregationCursor<T> {\n throw new Error('Method not implemented.');\n }\n watch<\n TLocal extends Document = T,\n TChange extends Document = ChangeStreamDocument<TLocal>,\n >(\n _pipeline?: Document[] | undefined,\n _options?: ChangeStreamOptions | undefined,\n ): ChangeStream<TLocal, TChange> {\n throw new Error('Method not implemented.');\n }\n initializeUnorderedBulkOp(\n _options?: BulkWriteOptions | undefined,\n ): UnorderedBulkOperation {\n throw new Error('Method not implemented.');\n }\n initializeOrderedBulkOp(\n _options?: BulkWriteOptions | undefined,\n ): OrderedBulkOperation {\n throw new Error('Method not implemented.');\n }\n count(\n filter?: Filter<T> | undefined,\n options?: CountOptions | undefined,\n ): Promise<number> {\n return this.collection.countDocuments(\n (filter as PongoFilter<T>) ?? {},\n toCollectionOperationOptions(options),\n );\n }\n listSearchIndexes(\n options?: ListSearchIndexesOptions | undefined,\n ): ListSearchIndexesCursor;\n listSearchIndexes(\n name: string,\n options?: ListSearchIndexesOptions | undefined,\n ): ListSearchIndexesCursor;\n listSearchIndexes(\n _name?: unknown,\n _options?: unknown,\n ): import('mongodb').ListSearchIndexesCursor {\n throw new Error('Method not implemented.');\n }\n createSearchIndex(_description: SearchIndexDescription): Promise<string> {\n throw new Error('Method not implemented.');\n }\n createSearchIndexes(\n _descriptions: SearchIndexDescription[],\n ): Promise<string[]> {\n throw new Error('Method not implemented.');\n }\n dropSearchIndex(_name: string): Promise<void> {\n throw new Error('Method not implemented.');\n }\n updateSearchIndex(_name: string, _definition: Document): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n async createCollection(): Promise<void> {\n await this.collection.createCollection();\n }\n async handle(\n id: ObjectId,\n handle: DocumentHandler<T>,\n options?: HandleOptions,\n ): Promise<PongoHandleResult<T>> {\n return this.collection.handle(id.toString(), handle, options);\n }\n}\n","import type { ClientSessionOptions } from 'http2';\nimport type { ClientSession, WithSessionCallback } from 'mongodb';\nimport {\n pongoClient,\n pongoSession,\n type PongoClient,\n type PongoClientOptions,\n} from '../core';\nimport { Db } from './mongoDb';\n\nexport class MongoClient {\n private pongoClient: PongoClient;\n\n constructor(connectionString: string, options: PongoClientOptions = {}) {\n this.pongoClient = pongoClient(connectionString, options);\n }\n\n async connect() {\n await this.pongoClient.connect();\n return this;\n }\n\n async close() {\n await this.pongoClient.close();\n }\n\n db(dbName?: string): Db {\n return new Db(this.pongoClient.db(dbName));\n }\n startSession(_options?: ClientSessionOptions): ClientSession {\n return pongoSession() as unknown as ClientSession;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n withSession<T = any>(_executor: WithSessionCallback<T>): Promise<T>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n withSession<T = any>(\n _options: ClientSessionOptions,\n _executor: WithSessionCallback<T>,\n ): Promise<T>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async withSession<T = any>(\n optionsOrExecutor: ClientSessionOptions | WithSessionCallback<T>,\n executor?: WithSessionCallback<T>,\n ): Promise<T> {\n const callback =\n typeof optionsOrExecutor === 'function' ? optionsOrExecutor : executor!;\n\n const session = pongoSession() as unknown as ClientSession;\n\n try {\n return await callback(session);\n } finally {\n await session.endSession();\n }\n }\n}\n"],"m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AER,YAAY,kBAA0B,UAA8B,CAAC,GAAG;AACtE,SAAK,cAAc,YAAY,kBAAkB,OAAO;AAAA,EAC1D;AAAA,EAEA,MAAM,UAAU;AACd,UAAM,KAAK,YAAY,QAAQ;AAC/B,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAQ;AACZ,UAAM,KAAK,YAAY,MAAM;AAAA,EAC/B;AAAA,EAEA,GAAG,QAAqB;AACtB,WAAO,IAAI,GAAG,KAAK,YAAY,GAAG,MAAM,CAAC;AAAA,EAC3C;AAAA,EACA,aAAa,UAAgD;AAC3D,WAAO,aAAa;AAAA,EACtB;AAAA;AAAA,EASA,MAAM,YACJ,mBACA,UACY;AACZ,UAAM,WACJ,OAAO,sBAAsB,aAAa,oBAAoB;AAEhE,UAAM,UAAU,aAAa;AAE7B,QAAI;AACF,aAAO,MAAM,SAAS,OAAO;AAAA,IAC/B,UAAE;AACA,YAAM,QAAQ,WAAW;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@event-driven-io/pongo",
3
- "version": "0.16.4-alpha.1",
3
+ "version": "0.16.4-alpha.2",
4
4
  "description": "Pongo - Mongo with strong consistency on top of Postgres",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -87,7 +87,7 @@
87
87
  "pongo": "./dist/cli.js"
88
88
  },
89
89
  "peerDependencies": {
90
- "@event-driven-io/dumbo": "0.12.1-alpha.1",
90
+ "@event-driven-io/dumbo": "0.12.1-alpha.2",
91
91
  "@types/mongodb": "^4.0.7",
92
92
  "@types/pg": "^8.11.6",
93
93
  "@types/uuid": "^10.0.0",
@@ -1,76 +0,0 @@
1
- import{isSQL as b,JSONSerializer as W,rawSql as ve,sql as O,sqlMigration as je}from"@event-driven-io/dumbo";import{runPostgreSQLMigrations as Te,schemaComponent as ee,single as Oe}from"@event-driven-io/dumbo";import{v7 as Z}from"uuid";import{dumbo as de,getDatabaseNameOrDefault as ue,NodePostgresConnectorType as ge,runPostgreSQLMigrations as me,schemaComponent as B}from"@event-driven-io/dumbo";var K=e=>e.connectorType===ge,z=e=>{let{connectionString:n,dbName:t}=e,o=t??ue(n),s=de({connectionString:n,...e.connectionOptions}),r=new Map,g=async(d,p)=>(await _(P,p,s.execute)).command(d),u=async(d,p)=>(await _(P,p,s.execute)).query(d),P={connectorType:e.connectorType,databaseName:o,connect:()=>Promise.resolve(),close:()=>s.close(),collections:()=>[...r.values()],collection:d=>G({collectionName:d,db:P,pool:s,sqlBuilder:X(d),schema:e.schema?e.schema:{},errors:e.errors?e.errors:{}}),transaction:()=>s.transaction(),withTransaction:d=>s.withTransaction(d),schema:{get component(){return B("pongoDb",{components:[...r.values()].map(d=>d.schema.component)})},migrate:()=>me(s,[...r.values()].flatMap(d=>d.schema.component.migrations({connector:"PostgreSQL:pg"})))},sql:{async query(d,p){return(await u(d,p)).rows},async command(d,p){return g(d,p)}}},R=e?.schema?.definition?.dbs;if(R){let d=S(R).map(p=>p[1]).find(p=>p.name===t||p.name===o);if(d)return J(P,d,r)}return P},He=e=>{let n=e.length>0&&typeof e[0]=="string"?e.map(t=>Y(t)):e;return B("pongo:schema_component:db",{components:n})};var ye=async(e,n)=>{let t=n?.session?.transaction;return!t||!t.isActive?null:await t.enlistDatabase(e)},_=async(e,n,t)=>(await ye(e,n))?.execute??t,G=({db:e,collectionName:n,pool:t,sqlBuilder:o,schema:s,errors:r})=>{let g=t.execute,u=async(i,a)=>(await _(e,a,g)).command(i),P=async(i,a)=>(await _(e,a,g)).query(i),R=s?.autoMigration!=="None",d=i=>(R=!1,i?.session?u(o.createCollection(),i):u(o.createCollection())),p=i=>R?d(i):Promise.resolve(),m={dbName:e.databaseName,collectionName:n,createCollection:async i=>{await d(i)},insertOne:async(i,a)=>{await p(a);let c=i._id??Z(),l=i._version??1n,D=((await u(o.insertOne({...i,_id:c,_version:l}),a)).rowCount??0)>0;return x({successful:D,insertedId:D?c:null,nextExpectedVersion:l},{operationName:"insertOne",collectionName:n,errors:r})},insertMany:async(i,a)=>{await p(a);let c=i.map(C=>({...C,_id:C._id??Z(),_version:C._version??1n})),l=await u(o.insertMany(c),a);return x({successful:l.rowCount===c.length,insertedCount:l.rowCount??0,insertedIds:l.rows.map(C=>C._id)},{operationName:"insertMany",collectionName:n,errors:r})},updateOne:async(i,a,c)=>{await p(c);let l=await u(o.updateOne(i,a,c),c);return x({successful:l.rows.length>0&&l.rows[0].modified===l.rows[0].matched,modifiedCount:Number(l.rows[0]?.modified??0),matchedCount:Number(l.rows[0]?.matched??0),nextExpectedVersion:l.rows[0]?.version??0n},{operationName:"updateOne",collectionName:n,errors:r})},replaceOne:async(i,a,c)=>{await p(c);let l=await u(o.replaceOne(i,a,c),c);return x({successful:l.rows.length>0&&l.rows[0].modified>0,modifiedCount:Number(l.rows[0]?.modified??0),matchedCount:Number(l.rows[0]?.matched??0),nextExpectedVersion:l.rows[0]?.version??0n},{operationName:"replaceOne",collectionName:n,errors:r})},updateMany:async(i,a,c)=>{await p(c);let l=await u(o.updateMany(i,a),c);return x({successful:!0,modifiedCount:l.rowCount??0,matchedCount:l.rowCount??0},{operationName:"updateMany",collectionName:n,errors:r})},deleteOne:async(i,a)=>{await p(a);let c=await u(o.deleteOne(i??{},a),a);return x({successful:c.rows.length>0&&c.rows[0].deleted>0,deletedCount:Number(c.rows[0]?.deleted??0),matchedCount:Number(c.rows[0]?.matched??0)},{operationName:"deleteOne",collectionName:n,errors:r})},deleteMany:async(i,a)=>{await p(a);let c=await u(o.deleteMany(i??{}),a);return x({successful:(c.rowCount??0)>0,deletedCount:c.rowCount??0,matchedCount:c.rowCount??0},{operationName:"deleteMany",collectionName:n,errors:r})},findOne:async(i,a)=>(await p(a),(await P(o.findOne(i??{}),a)).rows[0]?.data??null),findOneAndDelete:async(i,a)=>{await p(a);let c=await m.findOne(i,a);return c===null?null:(await m.deleteOne(i,a),c)},findOneAndReplace:async(i,a,c)=>{await p(c);let l=await m.findOne(i,c);return l===null?null:(await m.replaceOne(i,a,c),l)},findOneAndUpdate:async(i,a,c)=>{await p(c);let l=await m.findOne(i,c);return l===null?null:(await m.updateOne(i,a,c),l)},handle:async(i,a,c)=>{let{expectedVersion:l,...C}=c??{};await p(c);let D={_id:i},y=await m.findOne(D,c),L=I(l);if(y==null&&l==="DOCUMENT_EXISTS"||y==null&&L!=null||y!=null&&l==="DOCUMENT_DOES_NOT_EXIST"||y!=null&&L!==null&&y._version!==L)return x({successful:!1,document:y},{operationName:"handle",collectionName:n,errors:r});let E=await a(y!==null?{...y}:null);if(N(y,E))return x({successful:!0,document:y},{operationName:"handle",collectionName:n,errors:r});if(!y&&E){let w={...E,_id:i},H=await m.insertOne({...w,_id:i},{...C,expectedVersion:"DOCUMENT_DOES_NOT_EXIST"});return{...H,document:{...w,_version:H.nextExpectedVersion}}}if(y&&!E)return{...await m.deleteOne(D,{...C,expectedVersion:L??"DOCUMENT_EXISTS"}),document:null};if(y&&E){let w=await m.replaceOne(D,E,{...C,expectedVersion:L??"DOCUMENT_EXISTS"});return{...w,document:{...E,_version:w.nextExpectedVersion}}}return x({successful:!0,document:y},{operationName:"handle",collectionName:n,errors:r})},find:async(i,a)=>(await p(a),(await P(o.find(i??{}))).rows.map(l=>l.data)),countDocuments:async(i,a)=>{await p(a);let{count:c}=await Oe(P(o.countDocuments(i??{})));return c},drop:async i=>(await p(i),((await u(o.drop()))?.rowCount??0)>0),rename:async(i,a)=>(await p(a),await u(o.rename(i)),n=i,m),sql:{async query(i,a){return await p(a),(await P(i,a)).rows},async command(i,a){return await p(a),u(i,a)}},schema:{get component(){return ee("pongo:schema_component:collection",{migrations:o.migrations})},migrate:()=>Te(t,o.migrations())}};return m},Y=e=>ee("pongo:schema_component:collection",{migrations:()=>A(e)});var ne={$eq:"$eq",$gt:"$gt",$gte:"$gte",$lt:"$lt",$lte:"$lte",$ne:"$ne",$in:"$in",$nin:"$nin",$elemMatch:"$elemMatch",$all:"$all",$size:"$size"},v={$gt:">",$gte:">=",$lt:"<",$lte:"<=",$ne:"!="},Pe=e=>e.startsWith("$"),te=e=>Object.keys(e).some(Pe);var Se=e=>typeof e=="number"&&e===e,xe=e=>typeof e=="string",j=class e extends Error{errorCode;constructor(n){let t=n&&typeof n=="object"&&"errorCode"in n?n.errorCode:Se(n)?n:500,o=n&&typeof n=="object"&&"message"in n?n.message:xe(n)?n:`Error with status code '${t}' ocurred during Pongo processing`;super(o),this.errorCode=t,Object.setPrototypeOf(this,e.prototype)}},U=class e extends j{constructor(n){super({errorCode:412,message:n??"Expected document state does not match current one!"}),Object.setPrototypeOf(this,e.prototype)}};import{NodePostgresConnectorType as Le}from"@event-driven-io/dumbo";import"pg";var F=e=>{let{connectorType:n}=e;if(!K(e))throw new Error(`Unsupported db type: ${n}`);return z(e)};var oe=e=>{let n=!1,t=!1,o=null,s=null;return{enlistDatabase:async r=>{if(s&&o!==r.databaseName)throw new Error("There's already other database assigned to transaction");return s&&o===r.databaseName||(o=r.databaseName,s=r.transaction(),await s.begin()),s},commit:async()=>{if(!s)throw new Error("No database transaction started!");if(!n){if(t)throw new Error("Transaction is not active!");n=!0,await s.commit(),s=null}},rollback:async r=>{if(!s)throw new Error("No database transaction started!");if(n)throw new Error("Cannot rollback commited transaction!");t||(t=!0,await s.rollback(r),s=null)},databaseName:o,isStarting:!1,isCommitted:n,get isActive(){return!n&&!t},get sqlExecutor(){if(s===null)throw new Error("No database transaction was started");return s.execute},options:e}};var M=e=>e?.isActive===!0;function se(e){if(!M(e))throw new Error("No active transaction exists!")}function Ce(e){if(M(e))throw new Error("Active transaction already exists!")}var k=e=>{let n=e?.explicit===!0,t=e?.defaultTransactionOptions??{get snapshotEnabled(){return!1}},o=null,s=!1,r=d=>{Ce(o),o=oe(d??t)},g=async()=>{se(o),await o.commit()},u=async()=>{se(o),await o.rollback()},R={get hasEnded(){return s},explicit:n,defaultTransactionOptions:t??{get snapshotEnabled(){return!1}},get transaction(){return o},get snapshotEnabled(){return t.snapshotEnabled},endSession:async()=>{s||(s=!0,M(o)&&await o.rollback())},incrementTransactionNumber:()=>{},inTransaction:()=>M(o),startTransaction:r,commitTransaction:g,abortTransaction:u,withTransaction:async(d,p)=>{r(p);try{let m=await d(R);return await g(),m}catch(m){throw await u(),m}}};return R};var S=e=>Object.entries(e).map(([n,t])=>[n,t]);import{JSONSerializer as be}from"@event-driven-io/dumbo";import{v7 as he}from"uuid";var On=e=>e??he(),yn="DOCUMENT_EXISTS",Pn="DOCUMENT_DOES_NOT_EXIST",Re="NO_CONCURRENCY_CHECK",fe=e=>e==="DOCUMENT_DOES_NOT_EXIST"||e==="DOCUMENT_EXISTS"||e==="NO_CONCURRENCY_CHECK",I=e=>e===void 0||fe(e)?null:e,Sn=e=>e?BigInt(e):Re,x=(e,n)=>{let t={...e,acknowledged:!0,successful:e.successful,assertSuccessful:o=>{let{successful:s}=e,{operationName:r,collectionName:g}=n;if(!s)throw new U(o??`${r} on ${g} failed. Expected document state does not match current one! Result: ${be.serialize(e)}!`)}};return n.errors?.throwOnOperationFailures&&t.assertSuccessful(),t};var Ee=e=>({name:e});function De(e,n){if(n===void 0){if(typeof e=="string")throw new Error("You need to provide colleciton definition");return{collections:e}}return e&&typeof e=="string"?{name:e,collections:n}:{collections:n}}var we=e=>({dbs:e}),fn={client:we,db:De,collection:Ee},J=(e,n,t)=>{let o=Object.keys(n.collections);for(let s of o)t.set(s,e.collection(s));return new Proxy(e,{get(s,r){return t.get(r)??s[r]}})},ie=(e,n)=>{if(!n)return e;let t=Object.keys(n.dbs);return new Proxy(e,{get(o,s){return t.includes(s)?e.db(n.dbs[s]?.name):o[s]}})},Ie=e=>({name:e.name,collections:S(e.collections).map(n=>({name:n[1].name}))}),En=e=>{let n=S(e.dbs).map(t=>Ie(t[1]));return{databases:n,database:t=>n.find(o=>o.name===t)}};var Un=(e,n={})=>{let t=new Map,o=F(re({connectionString:e,clientOptions:n}));t.set(o.databaseName,o);let s={connect:async()=>(await o.connect(),s),close:async()=>{for(let r of t.values())await r.close()},db:r=>r?t.get(r)??t.set(r,F(re({connectionString:e,dbName:r,clientOptions:n}))).get(r):o,startSession:k,withSession:async r=>{let g=k();try{return await r(g)}finally{await g.endSession()}}};return ie(s,n?.schema?.definition)},re=e=>({connectorType:Le,connectionString:e.connectionString,dbName:e.dbName,...e.clientOptions});var N=(e,n)=>{if(_e(e))return e.equals(n);if(Array.isArray(e))return Array.isArray(n)&&e.length===n.length&&e.every((s,r)=>N(s,n[r]));if(typeof e!="object"||typeof n!="object"||e===null||n===null)return e===n;if(Array.isArray(n))return!1;let t=Object.keys(e),o=Object.keys(n);if(t.length!==o.length||!t.every(s=>o.includes(s)))return!1;for(let s in e){if(e[s]instanceof Function&&n[s]instanceof Function)continue;if(!N(e[s],n[s]))return!1}return!0},_e=e=>e&&typeof e=="object"&&"equals"in e&&typeof e.equals=="function";import{JSONSerializer as $,sql as T}from"@event-driven-io/dumbo";var V=(e,n,t)=>{if(e==="_id"||e==="_version")return Qe(e,n,t);switch(n){case"$eq":return T("(data @> %L::jsonb OR jsonb_path_exists(data, '$.%s[*] ? (@ == %s)'))",$.serialize(ae(e,t)),e,$.serialize(t));case"$gt":case"$gte":case"$lt":case"$lte":case"$ne":return T(`data #>> %L ${v[n]} %L`,`{${e.split(".").join(",")}}`,t);case"$in":return T("data #>> %L IN (%s)",`{${e.split(".").join(",")}}`,t.map(o=>T("%L",o)).join(", "));case"$nin":return T("data #>> %L NOT IN (%s)",`{${e.split(".").join(",")}}`,t.map(o=>T("%L",o)).join(", "));case"$elemMatch":{let o=S(t).map(([s,r])=>T('@."%s" == %s',s,$.serialize(r))).join(" && ");return T("jsonb_path_exists(data, '$.%s[*] ? (%s)')",e,o)}case"$all":return T("data @> %L::jsonb",$.serialize(ae(e,t)));case"$size":return T("jsonb_array_length(data #> %L) = %L",`{${e.split(".").join(",")}}`,t);default:throw new Error(`Unsupported operator: ${n}`)}},Qe=(e,n,t)=>{switch(n){case"$eq":return T(`${e} = %L`,t);case"$gt":case"$gte":case"$lt":case"$lte":case"$ne":return T(`${e} ${v[n]} %L`,t);case"$in":return T(`${e} IN (%s)`,t.map(o=>T("%L",o)).join(", "));case"$nin":return T(`${e} NOT IN (%s)`,t.map(o=>T("%L",o)).join(", "));default:throw new Error(`Unsupported operator: ${n}`)}},ae=(e,n)=>e.split(".").reverse().reduce((t,o)=>({[o]:t}),n);var ce="AND",h=e=>Object.entries(e).map(([n,t])=>Ue(t)?Ne(n,t):V(n,"$eq",t)).join(` ${ce} `),Ne=(e,n)=>{let t=!te(n);return S(n).map(([o,s])=>t?V(`${e}.${o}`,ne.$eq,s):V(e,o,s)).join(` ${ce} `)},Ue=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);import{JSONSerializer as le,sql as Q}from"@event-driven-io/dumbo";var q=e=>S(e).reduce((n,[t,o])=>{switch(t){case"$set":return Me(o,n);case"$unset":return $e(o,n);case"$inc":return Ve(o,n);case"$push":return Ae(o,n);default:return n}},Q("data")),Me=(e,n)=>Q("%s || %L::jsonb",n,le.serialize(e)),$e=(e,n)=>Q("%s - %L",n,Object.keys(e).map(t=>`{${t}}`).join(", ")),Ve=(e,n)=>{for(let[t,o]of Object.entries(e))n=Q(typeof o=="bigint"?"jsonb_set(%s, '{%s}', to_jsonb((COALESCE((data->>'%s')::BIGINT, 0) + %L)::TEXT), true)":"jsonb_set(%s, '{%s}', to_jsonb(COALESCE((data->>'%s')::NUMERIC, 0) + %L), true)",n,t,t,o);return n},Ae=(e,n)=>{for(let[t,o]of Object.entries(e))n=Q("jsonb_set(%s, '{%s}', (coalesce(data->'%s', '[]'::jsonb) || %L::jsonb), true)",n,t,t,le.serialize([o]));return n};var pe=e=>O(`CREATE TABLE IF NOT EXISTS %I (
2
- _id TEXT PRIMARY KEY,
3
- data JSONB NOT NULL,
4
- metadata JSONB NOT NULL DEFAULT '{}',
5
- _version BIGINT NOT NULL DEFAULT 1,
6
- _partition TEXT NOT NULL DEFAULT 'png_global',
7
- _archived BOOLEAN NOT NULL DEFAULT FALSE,
8
- _created TIMESTAMPTZ NOT NULL DEFAULT now(),
9
- _updated TIMESTAMPTZ NOT NULL DEFAULT now()
10
- )`,e),A=e=>[je(`pongoCollection:${e}:001:createtable`,[pe(e)])],X=e=>({migrations:()=>A(e),createCollection:()=>pe(e),insertOne:n=>O("INSERT INTO %I (_id, data, _version) VALUES (%L, %L, %L) ON CONFLICT(_id) DO NOTHING;",e,n._id,W.serialize(n),n._version??1n),insertMany:n=>{let t=n.map(o=>O("(%L, %L, %L)",o._id,W.serialize(o),o._version??1n)).join(", ");return O(`INSERT INTO %I (_id, data, _version) VALUES %s
11
- ON CONFLICT(_id) DO NOTHING
12
- RETURNING _id;`,e,t)},updateOne:(n,t,o)=>{let s=I(o?.expectedVersion),r=s!=null?"AND %I._version = %L":"",g=s!=null?[e,s]:[],u=b(n)?n:h(n),P=b(t)?t:q(t);return O(`WITH existing AS (
13
- SELECT _id, _version as current_version
14
- FROM %I %s
15
- LIMIT 1
16
- ),
17
- updated AS (
18
- UPDATE %I
19
- SET
20
- data = %s || jsonb_build_object('_id', %I._id) || jsonb_build_object('_version', (_version + 1)::text),
21
- _version = _version + 1
22
- FROM existing
23
- WHERE %I._id = existing._id ${r}
24
- RETURNING %I._id, %I._version
25
- )
26
- SELECT
27
- existing._id,
28
- COALESCE(updated._version, existing.current_version) AS version,
29
- COUNT(existing._id) over() AS matched,
30
- COUNT(updated._id) over() AS modified
31
- FROM existing
32
- LEFT JOIN updated
33
- ON existing._id = updated._id;`,e,f(u),e,P,e,e,...g,e,e)},replaceOne:(n,t,o)=>{let s=I(o?.expectedVersion),r=s!=null?"AND %I._version = %L":"",g=s!=null?[e,s]:[],u=b(n)?n:h(n);return O(`WITH existing AS (
34
- SELECT _id, _version as current_version
35
- FROM %I %s
36
- LIMIT 1
37
- ),
38
- updated AS (
39
- UPDATE %I
40
- SET
41
- data = %L || jsonb_build_object('_id', %I._id) || jsonb_build_object('_version', (_version + 1)::text),
42
- _version = _version + 1
43
- FROM existing
44
- WHERE %I._id = existing._id ${r}
45
- RETURNING %I._id, %I._version
46
- )
47
- SELECT
48
- existing._id,
49
- COALESCE(updated._version, existing.current_version) AS version,
50
- COUNT(existing._id) over() AS matched,
51
- COUNT(updated._id) over() AS modified
52
- FROM existing
53
- LEFT JOIN updated
54
- ON existing._id = updated._id;`,e,f(u),e,W.serialize(t),e,e,...g,e,e)},updateMany:(n,t)=>{let o=b(n)?n:h(n),s=b(t)?t:q(t);return O(`UPDATE %I
55
- SET
56
- data = %s || jsonb_build_object('_version', (_version + 1)::text),
57
- _version = _version + 1
58
- %s;`,e,s,f(o))},deleteOne:(n,t)=>{let o=I(t?.expectedVersion),s=o!=null?"AND %I._version = %L":"",r=o!=null?[e,o]:[],g=b(n)?n:h(n);return O(`WITH existing AS (
59
- SELECT _id
60
- FROM %I %s
61
- LIMIT 1
62
- ),
63
- deleted AS (
64
- DELETE FROM %I
65
- USING existing
66
- WHERE %I._id = existing._id ${s}
67
- RETURNING %I._id
68
- )
69
- SELECT
70
- existing._id,
71
- COUNT(existing._id) over() AS matched,
72
- COUNT(deleted._id) over() AS deleted
73
- FROM existing
74
- LEFT JOIN deleted
75
- ON existing._id = deleted._id;`,e,f(g),e,e,...r,e)},deleteMany:n=>{let t=b(n)?n:h(n);return O("DELETE FROM %I %s",e,f(t))},findOne:n=>{let t=b(n)?n:h(n);return O("SELECT data FROM %I %s LIMIT 1;",e,f(t))},find:n=>{let t=b(n)?n:h(n);return O("SELECT data FROM %I %s;",e,f(t))},countDocuments:n=>{let t=b(n)?n:h(n);return O("SELECT COUNT(1) as count FROM %I %s;",e,f(t))},rename:n=>O("ALTER TABLE %I RENAME TO %I;",e,n),drop:(n=e)=>O("DROP TABLE IF EXISTS %I",n)}),f=e=>e.length>0?O("WHERE %s",e):ve("");export{A as a,X as b,K as c,z as d,He as e,_ as f,G as g,Y as h,ne as i,v as j,Pe as k,te as l,Se as m,xe as n,j as o,U as p,F as q,oe as r,k as s,S as t,On as u,yn as v,Pn as w,Re as x,fe as y,I as z,Sn as A,x as B,fn as C,J as D,ie as E,Ie as F,En as G,Un as H,re as I,N as J,_e as K};
76
- //# sourceMappingURL=chunk-CYDDN3CZ.js.map