@event-driven-io/pongo 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +152 -79
- package/dist/index.d.ts +152 -79
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
+
import { SQLExecutor, SQL, PostgresConnector, PostgresPoolOptions, DatabaseTransaction, DatabaseTransactionFactory, NodePostgresConnection } from '@event-driven-io/dumbo';
|
|
1
2
|
import pg from 'pg';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { ClientSessionOptions } from 'http2';
|
|
4
|
+
import { Document, Collection as Collection$1, ObjectId as ObjectId$1, ClientSession, WithSessionCallback, ReadConcern, ReadPreference, BSONSerializeOptions, WriteConcern, Hint, OptionalUnlessRequiredId, InsertOneOptions, InsertOneResult, BulkWriteOptions, InsertManyResult, AnyBulkWriteOperation, BulkWriteResult, Filter, UpdateFilter, UpdateOptions, UpdateResult, WithoutId as WithoutId$1, ReplaceOptions, DeleteOptions, DeleteResult, RenameOptions, DropCollectionOptions, WithId as WithId$1, 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';
|
|
4
5
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
type PongoCollectionOptions<ConnectorType extends string = string> = {
|
|
7
|
+
db: PongoDb<ConnectorType>;
|
|
8
|
+
collectionName: string;
|
|
9
|
+
sqlExecutor: SQLExecutor;
|
|
10
|
+
sqlBuilder: PongoCollectionSQLBuilder;
|
|
11
|
+
};
|
|
12
|
+
declare const pongoCollection: <T extends PongoDocument, ConnectorType extends string = string>({ db, collectionName, sqlExecutor, sqlBuilder: SqlFor, }: PongoCollectionOptions<ConnectorType>) => PongoCollection<T>;
|
|
13
|
+
type PongoCollectionSQLBuilder = {
|
|
14
|
+
createCollection: () => SQL;
|
|
15
|
+
insertOne: <T>(document: WithId<T>) => SQL;
|
|
16
|
+
insertMany: <T>(documents: WithId<T>[]) => SQL;
|
|
17
|
+
updateOne: <T>(filter: PongoFilter<T>, update: PongoUpdate<T>) => SQL;
|
|
18
|
+
replaceOne: <T>(filter: PongoFilter<T>, document: WithoutId<T>) => SQL;
|
|
19
|
+
updateMany: <T>(filter: PongoFilter<T>, update: PongoUpdate<T>) => SQL;
|
|
20
|
+
deleteOne: <T>(filter: PongoFilter<T>) => SQL;
|
|
21
|
+
deleteMany: <T>(filter: PongoFilter<T>) => SQL;
|
|
22
|
+
findOne: <T>(filter: PongoFilter<T>) => SQL;
|
|
23
|
+
find: <T>(filter: PongoFilter<T>) => SQL;
|
|
24
|
+
countDocuments: <T>(filter: PongoFilter<T>) => SQL;
|
|
25
|
+
rename: (newName: string) => SQL;
|
|
26
|
+
drop: () => SQL;
|
|
9
27
|
};
|
|
10
|
-
declare const postgresClient: (options: PongoClientOptions) => DbClient;
|
|
11
28
|
|
|
12
|
-
declare const
|
|
29
|
+
declare const QueryOperators: {
|
|
13
30
|
$eq: string;
|
|
14
31
|
$gt: string;
|
|
15
32
|
$gte: string;
|
|
@@ -22,66 +39,88 @@ declare const Operators: {
|
|
|
22
39
|
$all: string;
|
|
23
40
|
$size: string;
|
|
24
41
|
};
|
|
42
|
+
declare const OperatorMap: {
|
|
43
|
+
$gt: string;
|
|
44
|
+
$gte: string;
|
|
45
|
+
$lt: string;
|
|
46
|
+
$lte: string;
|
|
47
|
+
$ne: string;
|
|
48
|
+
};
|
|
25
49
|
declare const isOperator: (key: string) => boolean;
|
|
26
50
|
declare const hasOperators: (value: Record<string, unknown>) => boolean;
|
|
27
|
-
declare const handleOperator: (path: string, operator: string, value: unknown) => string;
|
|
28
51
|
|
|
29
|
-
|
|
52
|
+
type PostgresDbClientOptions = PongoDbClientOptions<PostgresConnector> & PostgresPoolOptions;
|
|
53
|
+
declare const isPostgresClientOptions: (options: PongoDbClientOptions) => options is PostgresDbClientOptions;
|
|
54
|
+
declare const postgresDb: (options: PostgresDbClientOptions) => PongoDb<PostgresConnector>;
|
|
30
55
|
|
|
31
|
-
declare const
|
|
32
|
-
dbName: string;
|
|
33
|
-
poolOrClient: pg.Pool | pg.PoolClient | pg.Client;
|
|
34
|
-
}) => PongoCollection<T>;
|
|
35
|
-
declare const collectionSQLBuilder: (collectionName: string) => {
|
|
36
|
-
createCollection: () => SQL;
|
|
37
|
-
insertOne: <T>(document: WithId<T>) => SQL;
|
|
38
|
-
insertMany: <T_1>(documents: WithId<T_1>[]) => SQL;
|
|
39
|
-
updateOne: <T_2>(filter: PongoFilter<T_2>, update: PongoUpdate<T_2>) => SQL;
|
|
40
|
-
replaceOne: <T_3>(filter: PongoFilter<T_3>, document: WithoutId<T_3>) => SQL;
|
|
41
|
-
updateMany: <T_4>(filter: PongoFilter<T_4>, update: PongoUpdate<T_4>) => SQL;
|
|
42
|
-
deleteOne: <T_5>(filter: PongoFilter<T_5>) => SQL;
|
|
43
|
-
deleteMany: <T_6>(filter: PongoFilter<T_6>) => SQL;
|
|
44
|
-
findOne: <T_7>(filter: PongoFilter<T_7>) => SQL;
|
|
45
|
-
find: <T_8>(filter: PongoFilter<T_8>) => SQL;
|
|
46
|
-
countDocuments: <T_9>(filter: PongoFilter<T_9>) => SQL;
|
|
47
|
-
rename: (newName: string) => SQL;
|
|
48
|
-
drop: (targetName?: string) => SQL;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
declare const buildUpdateQuery: <T>(update: PongoUpdate<T>) => SQL;
|
|
52
|
-
declare const buildSetQuery: <T>(set: $set<T>, currentUpdateQuery: SQL) => SQL;
|
|
53
|
-
declare const buildUnsetQuery: <T>(unset: $unset<T>, currentUpdateQuery: SQL) => SQL;
|
|
54
|
-
declare const buildIncQuery: <T>(inc: $inc<T>, currentUpdateQuery: SQL) => SQL;
|
|
55
|
-
declare const buildPushQuery: <T>(push: $push<T>, currentUpdateQuery: SQL) => SQL;
|
|
56
|
+
declare const postgresSQLBuilder: (collectionName: string) => PongoCollectionSQLBuilder;
|
|
56
57
|
|
|
57
58
|
interface PongoClient {
|
|
58
59
|
connect(): Promise<this>;
|
|
59
60
|
close(): Promise<void>;
|
|
60
61
|
db(dbName?: string): PongoDb;
|
|
62
|
+
startSession(): PongoSession;
|
|
63
|
+
withSession<T = unknown>(callback: (session: PongoSession) => Promise<T>): Promise<T>;
|
|
64
|
+
}
|
|
65
|
+
declare interface PongoTransactionOptions {
|
|
66
|
+
get snapshotEnabled(): boolean;
|
|
67
|
+
maxCommitTimeMS?: number;
|
|
68
|
+
}
|
|
69
|
+
interface PongoDbTransaction {
|
|
70
|
+
get databaseName(): string | null;
|
|
71
|
+
options: PongoTransactionOptions;
|
|
72
|
+
enlistDatabase: (database: PongoDb) => Promise<DatabaseTransaction>;
|
|
73
|
+
commit: () => Promise<void>;
|
|
74
|
+
rollback: (error?: unknown) => Promise<void>;
|
|
75
|
+
get sqlExecutor(): SQLExecutor;
|
|
76
|
+
get isStarting(): boolean;
|
|
77
|
+
get isActive(): boolean;
|
|
78
|
+
get isCommitted(): boolean;
|
|
61
79
|
}
|
|
62
|
-
interface
|
|
80
|
+
interface PongoSession {
|
|
81
|
+
hasEnded: boolean;
|
|
82
|
+
explicit: boolean;
|
|
83
|
+
defaultTransactionOptions: PongoTransactionOptions;
|
|
84
|
+
transaction: PongoDbTransaction | null;
|
|
85
|
+
get snapshotEnabled(): boolean;
|
|
86
|
+
endSession(): Promise<void>;
|
|
87
|
+
incrementTransactionNumber(): void;
|
|
88
|
+
inTransaction(): boolean;
|
|
89
|
+
startTransaction(options?: PongoTransactionOptions): void;
|
|
90
|
+
commitTransaction(): Promise<void>;
|
|
91
|
+
abortTransaction(): Promise<void>;
|
|
92
|
+
withTransaction<T = unknown>(fn: (session: PongoSession) => Promise<T>, options?: PongoTransactionOptions): Promise<T>;
|
|
93
|
+
}
|
|
94
|
+
interface PongoDb<ConnectorType extends string = string> extends DatabaseTransactionFactory<ConnectorType> {
|
|
95
|
+
get connectorType(): ConnectorType;
|
|
96
|
+
get databaseName(): string;
|
|
97
|
+
connect(): Promise<void>;
|
|
98
|
+
close(): Promise<void>;
|
|
63
99
|
collection<T extends PongoDocument>(name: string): PongoCollection<T>;
|
|
64
100
|
}
|
|
101
|
+
type CollectionOperationOptions = {
|
|
102
|
+
session?: PongoSession;
|
|
103
|
+
};
|
|
65
104
|
interface PongoCollection<T extends PongoDocument> {
|
|
66
105
|
readonly dbName: string;
|
|
67
106
|
readonly collectionName: string;
|
|
68
|
-
createCollection(): Promise<void>;
|
|
69
|
-
insertOne(document: T): Promise<PongoInsertOneResult>;
|
|
70
|
-
insertMany(documents: T[]): Promise<PongoInsertManyResult>;
|
|
71
|
-
updateOne(filter: PongoFilter<T>, update: PongoUpdate<T
|
|
72
|
-
replaceOne(filter: PongoFilter<T>, document: WithoutId<T
|
|
73
|
-
updateMany(filter: PongoFilter<T>, update: PongoUpdate<T
|
|
74
|
-
deleteOne(filter?: PongoFilter<T
|
|
75
|
-
deleteMany(filter?: PongoFilter<T
|
|
76
|
-
findOne(filter?: PongoFilter<T
|
|
77
|
-
find(filter?: PongoFilter<T
|
|
78
|
-
findOneAndDelete(filter: PongoFilter<T
|
|
79
|
-
findOneAndReplace(filter: PongoFilter<T>, replacement: WithoutId<T
|
|
80
|
-
findOneAndUpdate(filter: PongoFilter<T>, update: PongoUpdate<T
|
|
81
|
-
countDocuments(filter?: PongoFilter<T
|
|
82
|
-
drop(): Promise<boolean>;
|
|
83
|
-
rename(newName: string): Promise<PongoCollection<T>>;
|
|
84
|
-
handle(id: string, handle: DocumentHandler<T
|
|
107
|
+
createCollection(options?: CollectionOperationOptions): Promise<void>;
|
|
108
|
+
insertOne(document: T, options?: CollectionOperationOptions): Promise<PongoInsertOneResult>;
|
|
109
|
+
insertMany(documents: T[], options?: CollectionOperationOptions): Promise<PongoInsertManyResult>;
|
|
110
|
+
updateOne(filter: PongoFilter<T>, update: PongoUpdate<T>, options?: CollectionOperationOptions): Promise<PongoUpdateResult>;
|
|
111
|
+
replaceOne(filter: PongoFilter<T>, document: WithoutId<T>, options?: CollectionOperationOptions): Promise<PongoUpdateResult>;
|
|
112
|
+
updateMany(filter: PongoFilter<T>, update: PongoUpdate<T>, options?: CollectionOperationOptions): Promise<PongoUpdateResult>;
|
|
113
|
+
deleteOne(filter?: PongoFilter<T>, options?: CollectionOperationOptions): Promise<PongoDeleteResult>;
|
|
114
|
+
deleteMany(filter?: PongoFilter<T>, options?: CollectionOperationOptions): Promise<PongoDeleteResult>;
|
|
115
|
+
findOne(filter?: PongoFilter<T>, options?: CollectionOperationOptions): Promise<T | null>;
|
|
116
|
+
find(filter?: PongoFilter<T>, options?: CollectionOperationOptions): Promise<T[]>;
|
|
117
|
+
findOneAndDelete(filter: PongoFilter<T>, options?: CollectionOperationOptions): Promise<T | null>;
|
|
118
|
+
findOneAndReplace(filter: PongoFilter<T>, replacement: WithoutId<T>, options?: CollectionOperationOptions): Promise<T | null>;
|
|
119
|
+
findOneAndUpdate(filter: PongoFilter<T>, update: PongoUpdate<T>, options?: CollectionOperationOptions): Promise<T | null>;
|
|
120
|
+
countDocuments(filter?: PongoFilter<T>, options?: CollectionOperationOptions): Promise<number>;
|
|
121
|
+
drop(options?: CollectionOperationOptions): Promise<boolean>;
|
|
122
|
+
rename(newName: string, options?: CollectionOperationOptions): Promise<PongoCollection<T>>;
|
|
123
|
+
handle(id: string, handle: DocumentHandler<T>, options?: CollectionOperationOptions): Promise<T | null>;
|
|
85
124
|
}
|
|
86
125
|
type HasId = {
|
|
87
126
|
_id: string;
|
|
@@ -145,16 +184,32 @@ interface PongoDeleteManyResult {
|
|
|
145
184
|
type PongoDocument = Record<string, unknown>;
|
|
146
185
|
type DocumentHandler<T extends PongoDocument> = ((document: T | null) => T | null) | ((document: T | null) => Promise<T | null>);
|
|
147
186
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
187
|
+
type PooledPongoClientOptions = {
|
|
188
|
+
pool: pg.Pool;
|
|
189
|
+
} | {
|
|
190
|
+
pooled: true;
|
|
191
|
+
} | {
|
|
192
|
+
pool: pg.Pool;
|
|
193
|
+
pooled: true;
|
|
194
|
+
} | {};
|
|
195
|
+
type NotPooledPongoOptions = {
|
|
196
|
+
client: pg.Client;
|
|
197
|
+
} | {
|
|
198
|
+
pooled: false;
|
|
199
|
+
} | {
|
|
200
|
+
client: pg.Client;
|
|
201
|
+
pooled: false;
|
|
202
|
+
} | {
|
|
203
|
+
connection: NodePostgresConnection;
|
|
204
|
+
pooled?: false;
|
|
205
|
+
};
|
|
206
|
+
type PongoClientOptions = PooledPongoClientOptions | NotPooledPongoOptions;
|
|
207
|
+
declare const pongoClient: <DbClientOptions extends PostgresDbClientOptions = PostgresDbClientOptions>(connectionString: string, options?: PongoClientOptions) => PongoClient;
|
|
208
|
+
declare const clientToDbOptions: <DbClientOptions extends PostgresDbClientOptions = PostgresDbClientOptions>(options: {
|
|
209
|
+
connectionString: string;
|
|
210
|
+
dbName?: string;
|
|
211
|
+
clientOptions: PongoClientOptions;
|
|
212
|
+
}) => DbClientOptions;
|
|
158
213
|
|
|
159
214
|
type Entry<T> = {
|
|
160
215
|
[K in keyof Required<T>]: [K, Required<T>[K]];
|
|
@@ -167,6 +222,22 @@ type NonPartial<T> = {
|
|
|
167
222
|
[K in keyof Required<T>]: T[K];
|
|
168
223
|
};
|
|
169
224
|
|
|
225
|
+
type PongoDbClientOptions<ConnectorType extends string = string> = {
|
|
226
|
+
connectorType: ConnectorType;
|
|
227
|
+
connectionString: string;
|
|
228
|
+
dbName: string | undefined;
|
|
229
|
+
};
|
|
230
|
+
type AllowedDbClientOptions = PostgresDbClientOptions;
|
|
231
|
+
declare const getPongoDb: <DbClientOptions extends PostgresDbClientOptions = PostgresDbClientOptions>(options: DbClientOptions) => PongoDb;
|
|
232
|
+
|
|
233
|
+
type PongoSessionOptions = {
|
|
234
|
+
explicit?: boolean;
|
|
235
|
+
defaultTransactionOptions: PongoTransactionOptions;
|
|
236
|
+
};
|
|
237
|
+
declare const pongoSession: (options?: PongoSessionOptions) => PongoSession;
|
|
238
|
+
|
|
239
|
+
declare const pongoTransaction: (options: PongoTransactionOptions) => PongoDbTransaction;
|
|
240
|
+
|
|
170
241
|
declare class FindCursor<T> {
|
|
171
242
|
private findDocumentsPromise;
|
|
172
243
|
private documents;
|
|
@@ -182,6 +253,7 @@ declare class FindCursor<T> {
|
|
|
182
253
|
declare class Db {
|
|
183
254
|
private pongoDb;
|
|
184
255
|
constructor(pongoDb: PongoDb);
|
|
256
|
+
get databaseName(): string;
|
|
185
257
|
collection<T extends Document>(collectionName: string): Collection$1<T> & {
|
|
186
258
|
handle(id: ObjectId$1, handle: DocumentHandler<T>): Promise<T | null>;
|
|
187
259
|
};
|
|
@@ -189,12 +261,13 @@ declare class Db {
|
|
|
189
261
|
|
|
190
262
|
declare class MongoClient {
|
|
191
263
|
private pongoClient;
|
|
192
|
-
constructor(connectionString: string, options?:
|
|
193
|
-
client?: pg.PoolClient | pg.Client;
|
|
194
|
-
});
|
|
264
|
+
constructor(connectionString: string, options?: PongoClientOptions);
|
|
195
265
|
connect(): Promise<this>;
|
|
196
266
|
close(): Promise<void>;
|
|
197
267
|
db(dbName?: string): Db;
|
|
268
|
+
startSession(_options?: ClientSessionOptions): ClientSession;
|
|
269
|
+
withSession<T = any>(_executor: WithSessionCallback<T>): Promise<T>;
|
|
270
|
+
withSession<T = any>(_options: ClientSessionOptions, _executor: WithSessionCallback<T>): Promise<T>;
|
|
198
271
|
}
|
|
199
272
|
|
|
200
273
|
declare class Collection<T extends Document> implements Collection$1<T> {
|
|
@@ -209,16 +282,16 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
209
282
|
get writeConcern(): WriteConcern | undefined;
|
|
210
283
|
get hint(): Hint | undefined;
|
|
211
284
|
set hint(v: Hint | undefined);
|
|
212
|
-
insertOne(doc: OptionalUnlessRequiredId<T>,
|
|
213
|
-
insertMany(docs: OptionalUnlessRequiredId<T>[],
|
|
285
|
+
insertOne(doc: OptionalUnlessRequiredId<T>, options?: InsertOneOptions | undefined): Promise<InsertOneResult<T>>;
|
|
286
|
+
insertMany(docs: OptionalUnlessRequiredId<T>[], options?: BulkWriteOptions | undefined): Promise<InsertManyResult<T>>;
|
|
214
287
|
bulkWrite(_operations: AnyBulkWriteOperation<T>[], _options?: BulkWriteOptions | undefined): Promise<BulkWriteResult>;
|
|
215
|
-
updateOne(filter: Filter<T>, update: Document[] | UpdateFilter<T>,
|
|
216
|
-
replaceOne(filter: Filter<T>, document: WithoutId$1<T>,
|
|
217
|
-
updateMany(filter: Filter<T>, update: Document[] | UpdateFilter<T>,
|
|
218
|
-
deleteOne(filter?: Filter<T> | undefined,
|
|
219
|
-
deleteMany(filter?: Filter<T> | undefined,
|
|
220
|
-
rename(newName: string,
|
|
221
|
-
drop(
|
|
288
|
+
updateOne(filter: Filter<T>, update: Document[] | UpdateFilter<T>, options?: UpdateOptions | undefined): Promise<UpdateResult<T>>;
|
|
289
|
+
replaceOne(filter: Filter<T>, document: WithoutId$1<T>, options?: ReplaceOptions | undefined): Promise<Document | UpdateResult<T>>;
|
|
290
|
+
updateMany(filter: Filter<T>, update: Document[] | UpdateFilter<T>, options?: UpdateOptions | undefined): Promise<UpdateResult<T>>;
|
|
291
|
+
deleteOne(filter?: Filter<T> | undefined, options?: DeleteOptions | undefined): Promise<DeleteResult>;
|
|
292
|
+
deleteMany(filter?: Filter<T> | undefined, options?: DeleteOptions | undefined): Promise<DeleteResult>;
|
|
293
|
+
rename(newName: string, options?: RenameOptions | undefined): Promise<Collection<Document>>;
|
|
294
|
+
drop(options?: DropCollectionOptions | undefined): Promise<boolean>;
|
|
222
295
|
findOne(): Promise<WithId$1<T> | null>;
|
|
223
296
|
findOne(filter: Filter<T>): Promise<WithId$1<T> | null>;
|
|
224
297
|
findOne(filter: Filter<T>, options: FindOptions<Document>): Promise<WithId$1<T> | null>;
|
|
@@ -244,8 +317,8 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
244
317
|
}): Promise<IndexDescriptionCompact>;
|
|
245
318
|
indexInformation(options: IndexInformationOptions): Promise<IndexDescriptionCompact | IndexDescriptionInfo[]>;
|
|
246
319
|
indexInformation(): Promise<IndexDescriptionCompact>;
|
|
247
|
-
estimatedDocumentCount(
|
|
248
|
-
countDocuments(filter?: Filter<T> | undefined,
|
|
320
|
+
estimatedDocumentCount(options?: EstimatedDocumentCountOptions | undefined): Promise<number>;
|
|
321
|
+
countDocuments(filter?: Filter<T> | undefined, options?: CountDocumentsOptions | undefined): Promise<number>;
|
|
249
322
|
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
250
323
|
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
251
324
|
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>, options: CommandOperationOptions): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
@@ -288,7 +361,7 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
288
361
|
watch<TLocal extends Document = T, TChange extends Document = ChangeStreamDocument<TLocal>>(_pipeline?: Document[] | undefined, _options?: ChangeStreamOptions | undefined): ChangeStream<TLocal, TChange>;
|
|
289
362
|
initializeUnorderedBulkOp(_options?: BulkWriteOptions | undefined): UnorderedBulkOperation;
|
|
290
363
|
initializeOrderedBulkOp(_options?: BulkWriteOptions | undefined): OrderedBulkOperation;
|
|
291
|
-
count(filter?: Filter<T> | undefined,
|
|
364
|
+
count(filter?: Filter<T> | undefined, options?: CountOptions | undefined): Promise<number>;
|
|
292
365
|
listSearchIndexes(options?: ListSearchIndexesOptions | undefined): ListSearchIndexesCursor;
|
|
293
366
|
listSearchIndexes(name: string, options?: ListSearchIndexesOptions | undefined): ListSearchIndexesCursor;
|
|
294
367
|
createSearchIndex(_description: SearchIndexDescription): Promise<string>;
|
|
@@ -303,4 +376,4 @@ type ObjectId = string & {
|
|
|
303
376
|
__brandId: 'ObjectId';
|
|
304
377
|
};
|
|
305
378
|
|
|
306
|
-
export { type $inc, type $push, type $set, type $unset,
|
|
379
|
+
export { type $inc, type $push, type $set, type $unset, type AllowedDbClientOptions, Collection, type CollectionOperationOptions, Db, type DocumentHandler, FindCursor, type HasId, MongoClient, type NonPartial, type NotPooledPongoOptions, type ObjectId, OperatorMap, type PongoClient, type PongoClientOptions, type PongoCollection, type PongoCollectionOptions, type PongoCollectionSQLBuilder, type PongoDb, type PongoDbClientOptions, type PongoDbTransaction, type PongoDeleteManyResult, type PongoDeleteResult, type PongoDocument, type PongoFilter, type PongoFilterOperator, type PongoInsertManyResult, type PongoInsertOneResult, type PongoSession, type PongoSessionOptions, type PongoTransactionOptions, type PongoUpdate, type PongoUpdateManyResult, type PongoUpdateResult, type PooledPongoClientOptions, type PostgresDbClientOptions, QueryOperators, type WithId, type WithoutId, clientToDbOptions, entries, getPongoDb, hasOperators, isOperator, isPostgresClientOptions, pongoClient, pongoCollection, pongoSession, pongoTransaction, postgresDb, postgresSQLBuilder };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{single as J}from"@event-driven-io/dumbo";import{v4 as k}from"uuid";var q=async(t,e)=>{let n=e?.session?.transaction;return!n||!n.isActive?null:await n.enlistDatabase(t)},R=async(t,e,n)=>(await q(t,e))?.execute??n,A=({db:t,collectionName:e,sqlExecutor:n,sqlBuilder:o})=>{let i=async(r,s)=>(await R(t,s,n)).command(r),d=async(r,s)=>(await R(t,s,n)).query(r),T=i(o.createCollection()),c=r=>r?.session?i(o.createCollection(),r):T,m={dbName:t.databaseName,collectionName:e,createCollection:async r=>{await c(r)},insertOne:async(r,s)=>{await c(s);let a=k();return(await i(o.insertOne({_id:a,...r}),s)).rowCount?{insertedId:a,acknowledged:!0}:{insertedId:null,acknowledged:!1}},insertMany:async(r,s)=>{await c(s);let a=r.map(f=>({_id:k(),...f})),l=await i(o.insertMany(a),s);return{acknowledged:l.rowCount===a.length,insertedCount:l.rowCount??0,insertedIds:a.map(f=>f._id)}},updateOne:async(r,s,a)=>{await c(a);let l=await i(o.updateOne(r,s),a);return l.rowCount?{acknowledged:!0,modifiedCount:l.rowCount}:{acknowledged:!1,modifiedCount:0}},replaceOne:async(r,s,a)=>{await c(a);let l=await i(o.replaceOne(r,s),a);return l.rowCount?{acknowledged:!0,modifiedCount:l.rowCount}:{acknowledged:!1,modifiedCount:0}},updateMany:async(r,s,a)=>{await c(a);let l=await i(o.updateMany(r,s),a);return l.rowCount?{acknowledged:!0,modifiedCount:l.rowCount}:{acknowledged:!1,modifiedCount:0}},deleteOne:async(r,s)=>{await c(s);let a=await i(o.deleteOne(r??{}),s);return a.rowCount?{acknowledged:!0,deletedCount:a.rowCount}:{acknowledged:!1,deletedCount:0}},deleteMany:async(r,s)=>{await c(s);let a=await i(o.deleteMany(r??{}),s);return a.rowCount?{acknowledged:!0,deletedCount:a.rowCount}:{acknowledged:!1,deletedCount:0}},findOne:async(r,s)=>(await c(s),(await d(o.findOne(r??{}),s)).rows[0]?.data??null),findOneAndDelete:async(r,s)=>{await c(s);let a=await m.findOne(r,s);return a===null?null:(await m.deleteOne(r,s),a)},findOneAndReplace:async(r,s,a)=>{await c(a);let l=await m.findOne(r,a);return l===null?null:(await m.replaceOne(r,s,a),l)},findOneAndUpdate:async(r,s,a)=>{await c(a);let l=await m.findOne(r,a);return l===null?null:(await m.updateOne(r,s,a),l)},handle:async(r,s,a)=>{await c(a);let l={_id:r},f=await m.findOne(l,a),P=await s(f);if(!f&&P){let L={...P,_id:r};return await m.insertOne({...L,_id:r},a),L}return f&&!P?(await m.deleteOne(l,a),null):(f&&P&&await m.replaceOne(l,P,a),P)},find:async(r,s)=>(await c(s),(await d(o.find(r??{}))).rows.map(l=>l.data)),countDocuments:async(r,s)=>{await c(s);let{count:a}=await J(d(o.countDocuments(r??{})));return a},drop:async r=>(await c(r),((await i(o.drop()))?.rowCount??0)>0),rename:async(r,s)=>(await c(s),await i(o.rename(r)),e=r,m)};return m};var M={$eq:"$eq",$gt:"$gt",$gte:"$gte",$lt:"$lt",$lte:"$lte",$ne:"$ne",$in:"$in",$nin:"$nin",$elemMatch:"$elemMatch",$all:"$all",$size:"$size"},S={$gt:">",$gte:">=",$lt:"<",$lte:"<=",$ne:"!="},z=t=>t.startsWith("$"),_=t=>Object.keys(t).some(z);import{NodePostgresConnectorType as ae}from"@event-driven-io/dumbo";import"pg";import{dumbo as oe,getDatabaseNameOrDefault as ie,NodePostgresConnectorType as re}from"@event-driven-io/dumbo";import{sql as g}from"@event-driven-io/dumbo";import te from"pg-format";import u from"pg-format";var h=(t,e,n)=>{if(t==="_id")return X(e,n);switch(e){case"$eq":return u("(data @> %L::jsonb OR jsonb_path_exists(data, '$.%s[*] ? (@ == %s)'))",JSON.stringify($(t,n)),t,JSON.stringify(n));case"$gt":case"$gte":case"$lt":case"$lte":case"$ne":return u(`data #>> %L ${S[e]} %L`,`{${t.split(".").join(",")}}`,n);case"$in":return u("data #>> %L IN (%s)",`{${t.split(".").join(",")}}`,n.map(o=>u("%L",o)).join(", "));case"$nin":return u("data #>> %L NOT IN (%s)",`{${t.split(".").join(",")}}`,n.map(o=>u("%L",o)).join(", "));case"$elemMatch":{let o=w(n).map(([i,d])=>u('@."%s" == %s',i,JSON.stringify(d))).join(" && ");return u("jsonb_path_exists(data, '$.%s[*] ? (%s)')",t,o)}case"$all":return u("data @> %L::jsonb",JSON.stringify($(t,n)));case"$size":return u("jsonb_array_length(data #> %L) = %L",`{${t.split(".").join(",")}}`,n);default:throw new Error(`Unsupported operator: ${e}`)}},X=(t,e)=>{switch(t){case"$eq":return u("_id = %L",e);case"$gt":case"$gte":case"$lt":case"$lte":case"$ne":return u(`_id ${S[t]} %L`,e);case"$in":return u("_id IN (%s)",e.map(n=>u("%L",n)).join(", "));case"$nin":return u("_id NOT IN (%s)",e.map(n=>u("%L",n)).join(", "));default:throw new Error(`Unsupported operator: ${t}`)}},$=(t,e)=>t.split(".").reverse().reduce((n,o)=>({[o]:n}),e);var W="AND",O=t=>Object.entries(t).map(([e,n])=>Y(n)?V(e,n):h(e,"$eq",n)).join(` ${W} `),V=(t,e)=>{let n=!_(e);return w(e).map(([o,i])=>n?h(`${t}.${o}`,M.$eq,i):h(t,o,i)).join(` ${W} `)},Y=t=>t!==null&&typeof t=="object"&&!Array.isArray(t);import{sql as y}from"@event-driven-io/dumbo";var E=t=>w(t).reduce((e,[n,o])=>{switch(n){case"$set":return Z(o,e);case"$unset":return G(o,e);case"$inc":return ee(o,e);case"$push":return ne(o,e);default:return e}},y("data")),Z=(t,e)=>y("%s || %L::jsonb",e,JSON.stringify(t)),G=(t,e)=>y("%s - %L",e,Object.keys(t).map(n=>`{${n}}`).join(", ")),ee=(t,e)=>{for(let[n,o]of Object.entries(t))e=y("jsonb_set(%s, '{%s}', to_jsonb((data->>'%s')::numeric + %L), true)",e,n,n,o);return e},ne=(t,e)=>{for(let[n,o]of Object.entries(t))e=y("jsonb_set(%s, '{%s}', (coalesce(data->'%s', '[]'::jsonb) || %L::jsonb), true)",e,n,n,JSON.stringify([o]));return e};var Q=t=>({createCollection:()=>g(`CREATE TABLE IF NOT EXISTS %I (
|
|
2
2
|
_id TEXT PRIMARY KEY,
|
|
3
3
|
data JSONB NOT NULL,
|
|
4
4
|
metadata JSONB NOT NULL DEFAULT '{}',
|
|
@@ -7,8 +7,8 @@ import{endPool as J,getDatabaseNameOrDefault as v,getPool as z}from"@event-drive
|
|
|
7
7
|
_archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
8
8
|
_created TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
9
9
|
_updated TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
10
|
-
)`,t),insertOne:e=>
|
|
10
|
+
)`,t),insertOne:e=>g("INSERT INTO %I (_id, data) VALUES (%L, %L)",t,e._id,JSON.stringify(e)),insertMany:e=>{let n=e.map(o=>te("(%L, %L)",o._id,JSON.stringify(o))).join(", ");return g("INSERT INTO %I (_id, data) VALUES %s",t,n)},updateOne:(e,n)=>{let o=O(e),i=E(n);return g(`WITH cte AS (
|
|
11
11
|
SELECT _id FROM %I WHERE %s LIMIT 1
|
|
12
12
|
)
|
|
13
|
-
UPDATE %I SET data = %s FROM cte WHERE %I._id = cte._id`,t,o,t,i,t)},replaceOne:(e,n)=>{let o=
|
|
13
|
+
UPDATE %I SET data = %s FROM cte WHERE %I._id = cte._id`,t,o,t,i,t)},replaceOne:(e,n)=>{let o=O(e);return g("UPDATE %I SET data = %L || jsonb_build_object('_id', data->>'_id') WHERE %s",t,JSON.stringify(n),o)},updateMany:(e,n)=>{let o=O(e),i=E(n);return g("UPDATE %I SET data = %s WHERE %s",t,i,o)},deleteOne:e=>{let n=O(e);return g("DELETE FROM %I WHERE %s",t,n)},deleteMany:e=>{let n=O(e);return g("DELETE FROM %I WHERE %s",t,n)},findOne:e=>{let n=O(e);return g("SELECT data FROM %I WHERE %s LIMIT 1",t,n)},find:e=>{let n=O(e);return g("SELECT data FROM %I WHERE %s",t,n)},countDocuments:e=>{let n=O(e);return g("SELECT COUNT(1) as count FROM %I WHERE %s",t,n)},rename:e=>g("ALTER TABLE %I RENAME TO %I",t,e),drop:(e=t)=>g("DROP TABLE IF EXISTS %I",e)});var U=t=>t.connectorType===re,N=t=>{let{connectionString:e,dbName:n}=t,o=n??ie(e),i=oe(t),d={connectorType:t.connectorType,databaseName:o,connect:()=>Promise.resolve(),close:()=>i.close(),collection:T=>A({collectionName:T,db:d,sqlExecutor:i.execute,sqlBuilder:Q(T)}),transaction:()=>i.transaction(),withTransaction:T=>i.withTransaction(T)};return d};var F=t=>{let{connectorType:e}=t;if(!U(t))throw new Error(`Unsupported db type: ${e}`);return N(t)};var j=t=>{let e=!1,n=!1,o=null,i=null;return{enlistDatabase:async d=>{if(i&&o!==d.databaseName)throw new Error("There's already other database assigned to transaction");return i&&o===d.databaseName||(o=d.databaseName,i=d.transaction(),await i.begin()),i},commit:async()=>{if(!i)throw new Error("No database transaction started!");if(!e){if(n)throw new Error("Transaction is not active!");e=!0,await i.commit(),i=null}},rollback:async d=>{if(!i)throw new Error("No database transaction started!");if(e)throw new Error("Cannot rollback commited transaction!");n||(n=!0,await i.rollback(d),i=null)},databaseName:o,isStarting:!1,isCommitted:e,get isActive(){return!e&&!n},get sqlExecutor(){if(i===null)throw new Error("No database transaction was started");return i.execute},options:t}};var I=t=>t?.isActive===!0;function B(t){if(!I(t))throw new Error("No active transaction exists!")}function se(t){if(I(t))throw new Error("Active transaction already exists!")}var C=t=>{let e=t?.explicit===!0,n=t?.defaultTransactionOptions??{get snapshotEnabled(){return!1}},o=null,i=!1,d=s=>{se(o),o=j(s??n)},T=async()=>{B(o),await o.commit()},c=async()=>{B(o),await o.rollback()},r={get hasEnded(){return i},explicit:e,defaultTransactionOptions:n??{get snapshotEnabled(){return!1}},get transaction(){return o},get snapshotEnabled(){return n.snapshotEnabled},endSession:async()=>{i||(i=!0,I(o)&&await o.rollback())},incrementTransactionNumber:()=>{},inTransaction:()=>I(o),startTransaction:d,commitTransaction:T,abortTransaction:c,withTransaction:async(s,a)=>{d(a);try{let l=await s(r);return await T(),l}catch(l){throw await c(),l}}};return r};var v=(t,e={})=>{let n=new Map,o=F(H({connectionString:t,clientOptions:e}));n.set(o.databaseName,o);let i={connect:async()=>(await o.connect(),i),close:async()=>{for(let d of n.values())await d.close()},db:d=>d?n.get(d)??n.set(d,F(H({connectionString:t,dbName:d,clientOptions:e}))).get(d):o,startSession:C,withSession:async d=>{let T=C();try{return await d(T)}finally{await T.endSession()}}};return i},H=t=>({connectorType:ae,connectionString:t.connectionString,dbName:t.dbName,...t.clientOptions});var w=t=>Object.entries(t).map(([e,n])=>[e,n]);var D=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 o of n)e(o);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 p=t=>t?.session?{session:t.session}:void 0,b=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 o=await this.collection.insertOne(e,p(n));return{acknowledged:o.acknowledged,insertedId:o.insertedId}}async insertMany(e,n){let o=await this.collection.insertMany(e,p(n));return{acknowledged:o.acknowledged,insertedIds:o.insertedIds,insertedCount:o.insertedCount}}bulkWrite(e,n){throw new Error("Method not implemented.")}async updateOne(e,n,o){let i=await this.collection.updateOne(e,n,p(o));return{acknowledged:i.acknowledged,matchedCount:i.modifiedCount,modifiedCount:i.modifiedCount,upsertedCount:i.modifiedCount,upsertedId:null}}replaceOne(e,n,o){return this.collection.replaceOne(e,n,p(o))}async updateMany(e,n,o){let i=await this.collection.updateMany(e,n,p(o));return{acknowledged:i.acknowledged,matchedCount:i.modifiedCount,modifiedCount:i.modifiedCount,upsertedCount:i.modifiedCount,upsertedId:null}}async deleteOne(e,n){let o=await this.collection.deleteOne(e,p(n));return{acknowledged:o.acknowledged,deletedCount:o.deletedCount}}async deleteMany(e,n){let o=await this.collection.deleteMany(e,p(n));return{acknowledged:o.acknowledged,deletedCount:o.deletedCount}}async rename(e,n){return await this.collection.rename(e,p(n)),this}drop(e){return this.collection.drop(p(e))}async findOne(e,n){return this.collection.findOne(e,p(n))}find(e,n){return new D(this.collection.find(e,p(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({},p(e))}countDocuments(e,n){return this.collection.countDocuments(e,p(n))}distinct(e,n,o){throw new Error("Method not implemented.")}indexes(e){throw new Error("Method not implemented.")}findOneAndDelete(e,n){return this.collection.findOneAndDelete(e,p(n))}findOneAndReplace(e,n,o){return this.collection.findOneAndReplace(e,n,p(o))}findOneAndUpdate(e,n,o){return this.collection.findOneAndUpdate(e,n,p(o))}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??{},p(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){return this.collection.handle(e.toString(),n)}};var x=class{constructor(e){this.pongoDb=e}get databaseName(){return this.pongoDb.databaseName}collection(e){return new b(this.pongoDb.collection(e))}};var K=class{pongoClient;constructor(e,n={}){this.pongoClient=v(e,n)}async connect(){return await this.pongoClient.connect(),this}async close(){await this.pongoClient.close()}db(e){return new x(this.pongoClient.db(e))}startSession(e){return C()}async withSession(e,n){let o=typeof e=="function"?e:n,i=C();try{return await o(i)}finally{await i.endSession()}}};export{b as Collection,x as Db,D as FindCursor,K as MongoClient,S as OperatorMap,M as QueryOperators,H as clientToDbOptions,w as entries,F as getPongoDb,_ as hasOperators,z as isOperator,U as isPostgresClientOptions,v as pongoClient,A as pongoCollection,C as pongoSession,j as pongoTransaction,N as postgresDb,Q as postgresSQLBuilder};
|
|
14
14
|
//# sourceMappingURL=index.js.map
|