@event-driven-io/pongo 0.17.0-alpha.6 → 0.17.0-beta.10
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/{chunk-OO7GMTMP.js → chunk-RBJRJFQY.js} +573 -876
- package/dist/chunk-RBJRJFQY.js.map +1 -0
- package/dist/chunk-TFE4LVVL.cjs +330 -0
- package/dist/chunk-TFE4LVVL.cjs.map +1 -0
- package/dist/chunk-TP73JUIX.cjs +872 -0
- package/dist/chunk-TP73JUIX.cjs.map +1 -0
- package/dist/chunk-XOVARYG4.js +330 -0
- package/dist/chunk-XOVARYG4.js.map +1 -0
- package/dist/cli.cjs +110 -35
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +109 -34
- package/dist/cli.js.map +1 -1
- package/dist/cloudflare.cjs +53 -0
- package/dist/cloudflare.cjs.map +1 -0
- package/dist/cloudflare.d.cts +11 -0
- package/dist/cloudflare.d.ts +11 -0
- package/dist/cloudflare.js +53 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/index-BJopB-em.d.cts +7 -0
- package/dist/index-G5DECNb_.d.ts +7 -0
- package/dist/index.cjs +2 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -18
- package/dist/index.d.ts +58 -18
- package/dist/index.js +13 -17
- package/dist/pg.cjs +347 -3
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +36 -6
- package/dist/pg.d.ts +36 -6
- package/dist/pg.js +354 -10
- package/dist/pg.js.map +1 -1
- package/dist/pongoCollectionSchemaComponent-t_e9n2Wc.d.cts +426 -0
- package/dist/pongoCollectionSchemaComponent-t_e9n2Wc.d.ts +426 -0
- package/dist/shim.cjs +41 -7
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +12 -9
- package/dist/shim.d.ts +12 -9
- package/dist/shim.js +39 -5
- package/dist/shim.js.map +1 -1
- package/dist/sqlite3.cjs +65 -1
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +13 -1
- package/dist/sqlite3.d.ts +13 -1
- package/dist/sqlite3.js +64 -0
- package/dist/sqlite3.js.map +1 -1
- package/package.json +53 -13
- package/README.md +0 -230
- package/dist/chunk-AV4SHJQB.cjs +0 -1175
- package/dist/chunk-AV4SHJQB.cjs.map +0 -1
- package/dist/chunk-OO7GMTMP.js.map +0 -1
- package/dist/pg-BfTNWLV9.d.ts +0 -39
- package/dist/pg-C9NmCQe7.d.cts +0 -39
- package/dist/pongoClient-D8jPedlZ.d.cts +0 -364
- package/dist/pongoClient-D8jPedlZ.d.ts +0 -364
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { DatabaseDriverType, SchemaComponent, MigrationStyle, WithDatabaseTransactionFactory, AnyConnection, DatabaseTransaction, SQLExecutor, SQL, QueryResultRow, QueryResult, SchemaComponentOptions } from '@event-driven-io/dumbo';
|
|
2
|
+
|
|
3
|
+
interface PongoCollectionSchema<T extends PongoDocument = PongoDocument> {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
interface PongoDbSchema<T extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>> {
|
|
7
|
+
name?: string;
|
|
8
|
+
collections: T;
|
|
9
|
+
}
|
|
10
|
+
interface PongoClientSchema<T extends Record<string, PongoDbSchema> = Record<string, PongoDbSchema>> {
|
|
11
|
+
dbs: T;
|
|
12
|
+
}
|
|
13
|
+
type CollectionsMap<T extends Record<string, PongoCollectionSchema>> = {
|
|
14
|
+
[K in keyof T]: PongoCollection<T[K] extends PongoCollectionSchema<infer U> ? U : PongoDocument>;
|
|
15
|
+
};
|
|
16
|
+
type PongoDbWithSchema<T extends Record<string, PongoCollectionSchema>, DriverType extends DatabaseDriverType = DatabaseDriverType> = CollectionsMap<T> & PongoDb<DriverType>;
|
|
17
|
+
type DBsMap<T extends Record<string, PongoDbSchema>, DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> = {
|
|
18
|
+
[K in keyof T]: CollectionsMap<T[K]['collections']> & Database;
|
|
19
|
+
};
|
|
20
|
+
type PongoClientWithSchema<T extends PongoClientSchema, DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> = DBsMap<T['dbs'], DriverType, Database> & PongoClient<DriverType, Database>;
|
|
21
|
+
declare function pongoDbSchema<T extends Record<string, PongoCollectionSchema>>(collections: T): PongoDbSchema<T>;
|
|
22
|
+
declare function pongoDbSchema<T extends Record<string, PongoCollectionSchema>>(name: string, collections: T): PongoDbSchema<T>;
|
|
23
|
+
declare namespace pongoDbSchema {
|
|
24
|
+
var from: (databaseName: string | undefined, collectionNames: string[]) => PongoDbSchema;
|
|
25
|
+
}
|
|
26
|
+
declare const pongoSchema: {
|
|
27
|
+
client: <T extends Record<string, PongoDbSchema>>(dbs: T) => PongoClientSchema<T>;
|
|
28
|
+
db: typeof pongoDbSchema;
|
|
29
|
+
collection: {
|
|
30
|
+
<T extends PongoDocument>(name: string): PongoCollectionSchema<T>;
|
|
31
|
+
from(collectionNames: string[]): Record<string, PongoCollectionSchema>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
declare const proxyPongoDbWithSchema: <Collections extends Record<string, PongoCollectionSchema>, DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>>(pongoDb: Database, dbSchema: PongoDbSchema<Collections>, collections: Map<string, PongoCollection<Document>>) => PongoDbWithSchema<Collections, DriverType> & Database;
|
|
35
|
+
declare const proxyClientWithSchema: <TypedClientSchema extends PongoClientSchema, DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>>(client: PongoClient<DriverType, Database>, schema: TypedClientSchema | undefined) => PongoClientWithSchema<TypedClientSchema, DriverType, Database>;
|
|
36
|
+
type PongoCollectionSchemaMetadata = {
|
|
37
|
+
name: string;
|
|
38
|
+
};
|
|
39
|
+
type PongoDbSchemaMetadata = {
|
|
40
|
+
name?: string | undefined;
|
|
41
|
+
collections: PongoCollectionSchemaMetadata[];
|
|
42
|
+
};
|
|
43
|
+
type PongoClientSchemaMetadata = {
|
|
44
|
+
databases: PongoDbSchemaMetadata[];
|
|
45
|
+
database: (name?: string) => PongoDbSchemaMetadata | undefined;
|
|
46
|
+
};
|
|
47
|
+
declare const toDbSchemaMetadata: <TypedDbSchema extends PongoDbSchema>(schema: TypedDbSchema) => PongoDbSchemaMetadata;
|
|
48
|
+
declare const toClientSchemaMetadata: <TypedClientSchema extends PongoClientSchema>(schema: TypedClientSchema) => PongoClientSchemaMetadata;
|
|
49
|
+
interface PongoSchemaConfig<TypedClientSchema extends PongoClientSchema = PongoClientSchema> {
|
|
50
|
+
schema: TypedClientSchema;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type PongoDatabaseURNType = 'sc:dumbo:database';
|
|
54
|
+
type PongoDatabaseURN = `${PongoDatabaseURNType}:${string}`;
|
|
55
|
+
type PongoDatabaseSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType, T extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>> = Readonly<{
|
|
56
|
+
driverType: DriverType;
|
|
57
|
+
definition: PongoDbSchema<T>;
|
|
58
|
+
collectionFactory: <T extends PongoDocument = PongoDocument>(schema: PongoCollectionSchema<T>) => PongoCollectionSchemaComponent;
|
|
59
|
+
}>;
|
|
60
|
+
type PongoDatabaseSchemaComponent<DriverType extends DatabaseDriverType = DatabaseDriverType, T extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>> = SchemaComponent<PongoDatabaseURN> & {
|
|
61
|
+
definition: PongoDbSchema<T>;
|
|
62
|
+
collections: ReadonlyArray<PongoCollectionSchemaComponent>;
|
|
63
|
+
collection: <T extends PongoDocument = PongoDocument>(schema: PongoCollectionSchema<T>) => PongoCollectionSchemaComponent;
|
|
64
|
+
};
|
|
65
|
+
declare const PongoDatabaseSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({ definition, collectionFactory, }: PongoDatabaseSchemaComponentOptions<DriverType>) => PongoDatabaseSchemaComponent;
|
|
66
|
+
type PongoDatabaseSQLBuilder<DriverType extends DatabaseDriverType = DatabaseDriverType> = {
|
|
67
|
+
driverType: DriverType;
|
|
68
|
+
collection: PongoCollectionSQLBuilder;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
interface PongoDatabaseDriverOptions<ConnectionOptions = unknown> {
|
|
72
|
+
connectionOptions?: ConnectionOptions | undefined;
|
|
73
|
+
}
|
|
74
|
+
type AnyPongoDatabaseDriverOptions = PongoDatabaseDriverOptions<any>;
|
|
75
|
+
type PongoDatabaseFactoryOptions<CollectionsSchema extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>, DriverOptions extends AnyPongoDatabaseDriverOptions = AnyPongoDatabaseDriverOptions> = {
|
|
76
|
+
databaseName?: string | undefined;
|
|
77
|
+
schema?: {
|
|
78
|
+
autoMigration?: MigrationStyle;
|
|
79
|
+
definition?: PongoDbSchema<CollectionsSchema>;
|
|
80
|
+
} | undefined;
|
|
81
|
+
errors?: {
|
|
82
|
+
throwOnOperationFailures?: boolean;
|
|
83
|
+
} | undefined;
|
|
84
|
+
} & DriverOptions;
|
|
85
|
+
type DatabaseDriverOptionsWithDatabaseName = {
|
|
86
|
+
databaseName?: string | undefined;
|
|
87
|
+
};
|
|
88
|
+
type DatabaseDriverOptionsWithConnectionString = {
|
|
89
|
+
connectionString?: string | undefined;
|
|
90
|
+
};
|
|
91
|
+
interface PongoDatabaseDriver<Database extends AnyPongoDb = AnyPongoDb, DriverOptions extends AnyPongoDatabaseDriverOptions = AnyPongoDatabaseDriverOptions> {
|
|
92
|
+
driverType: Database['driverType'];
|
|
93
|
+
databaseFactory<CollectionsSchema extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>>(options: PongoDatabaseFactoryOptions<CollectionsSchema, DriverOptions>): Database & PongoDb<Database['driverType']>;
|
|
94
|
+
getDatabaseNameOrDefault?<CollectionsSchema extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>>(options: PongoDatabaseFactoryOptions<CollectionsSchema, DriverOptions>): string;
|
|
95
|
+
defaultConnectionString: string;
|
|
96
|
+
}
|
|
97
|
+
type AnyPongoDatabaseDriver = PongoDatabaseDriver<AnyPongoDb, AnyPongoDatabaseDriverOptions>;
|
|
98
|
+
type ExtractPongoDatabaseDriverOptions<DatabaseDriver> = DatabaseDriver extends PongoDatabaseDriver<any, infer O> ? O : never;
|
|
99
|
+
type ExtractPongoDatabaseTypeFromDriver<DatabaseDriver> = DatabaseDriver extends PongoDatabaseDriver<infer D, any> ? D : never;
|
|
100
|
+
declare const PongoDatabaseDriverRegistry: () => {
|
|
101
|
+
register: <Database extends AnyPongoDb = AnyPongoDb>(driverType: Database["driverType"], driver: PongoDatabaseDriver<Database> | (() => Promise<PongoDatabaseDriver<Database>>)) => void;
|
|
102
|
+
tryResolve: <Driver extends AnyPongoDatabaseDriver = AnyPongoDatabaseDriver>(driverType: Driver["driverType"]) => Promise<Driver | null>;
|
|
103
|
+
tryGet: <Driver extends AnyPongoDatabaseDriver = AnyPongoDatabaseDriver>(driverType: Driver["driverType"]) => Driver | null;
|
|
104
|
+
has: (driverType: DatabaseDriverType) => boolean;
|
|
105
|
+
readonly databaseDriverTypes: DatabaseDriverType[];
|
|
106
|
+
};
|
|
107
|
+
declare global {
|
|
108
|
+
var pongoDatabaseDriverRegistry: ReturnType<typeof PongoDatabaseDriverRegistry>;
|
|
109
|
+
}
|
|
110
|
+
declare const pongoDatabaseDriverRegistry: {
|
|
111
|
+
register: <Database extends AnyPongoDb = AnyPongoDb>(driverType: Database["driverType"], driver: PongoDatabaseDriver<Database> | (() => Promise<PongoDatabaseDriver<Database>>)) => void;
|
|
112
|
+
tryResolve: <Driver extends AnyPongoDatabaseDriver = AnyPongoDatabaseDriver>(driverType: Driver["driverType"]) => Promise<Driver | null>;
|
|
113
|
+
tryGet: <Driver extends AnyPongoDatabaseDriver = AnyPongoDatabaseDriver>(driverType: Driver["driverType"]) => Driver | null;
|
|
114
|
+
has: (driverType: DatabaseDriverType) => boolean;
|
|
115
|
+
readonly databaseDriverTypes: DatabaseDriverType[];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
interface PongoClient<DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> {
|
|
119
|
+
driverType: DriverType;
|
|
120
|
+
connect(): Promise<this>;
|
|
121
|
+
close(): Promise<void>;
|
|
122
|
+
db(dbName?: string): Database;
|
|
123
|
+
startSession(): PongoSession<DriverType>;
|
|
124
|
+
withSession<T = unknown>(callback: (session: PongoSession<DriverType>) => Promise<T>): Promise<T>;
|
|
125
|
+
}
|
|
126
|
+
type PongoClientOptions<DatabaseDriver extends AnyPongoDatabaseDriver = AnyPongoDatabaseDriver, TypedClientSchema extends PongoClientSchema = PongoClientSchema> = ExtractPongoDatabaseDriverOptions<DatabaseDriver> extends infer Options ? Options extends unknown ? {
|
|
127
|
+
driver: DatabaseDriver;
|
|
128
|
+
schema?: {
|
|
129
|
+
autoMigration?: MigrationStyle;
|
|
130
|
+
definition?: TypedClientSchema;
|
|
131
|
+
} | undefined;
|
|
132
|
+
errors?: {
|
|
133
|
+
throwOnOperationFailures?: boolean;
|
|
134
|
+
} | undefined;
|
|
135
|
+
} & Omit<Options, 'driver'> : never : never;
|
|
136
|
+
declare interface PongoTransactionOptions {
|
|
137
|
+
get snapshotEnabled(): boolean;
|
|
138
|
+
maxCommitTimeMS?: number;
|
|
139
|
+
}
|
|
140
|
+
interface PongoDbTransaction<DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> {
|
|
141
|
+
get databaseName(): string | null;
|
|
142
|
+
options: PongoTransactionOptions;
|
|
143
|
+
enlistDatabase: (database: Database) => Promise<DatabaseTransaction<AnyConnection>>;
|
|
144
|
+
commit: () => Promise<void>;
|
|
145
|
+
rollback: (error?: unknown) => Promise<void>;
|
|
146
|
+
get sqlExecutor(): SQLExecutor;
|
|
147
|
+
get isStarting(): boolean;
|
|
148
|
+
get isActive(): boolean;
|
|
149
|
+
get isCommitted(): boolean;
|
|
150
|
+
}
|
|
151
|
+
interface PongoSession<DriverType extends DatabaseDriverType = DatabaseDriverType> {
|
|
152
|
+
hasEnded: boolean;
|
|
153
|
+
explicit: boolean;
|
|
154
|
+
defaultTransactionOptions: PongoTransactionOptions;
|
|
155
|
+
transaction: PongoDbTransaction<DriverType> | null;
|
|
156
|
+
get snapshotEnabled(): boolean;
|
|
157
|
+
endSession(): Promise<void>;
|
|
158
|
+
incrementTransactionNumber(): void;
|
|
159
|
+
inTransaction(): boolean;
|
|
160
|
+
startTransaction(options?: PongoTransactionOptions): void;
|
|
161
|
+
commitTransaction(): Promise<void>;
|
|
162
|
+
abortTransaction(): Promise<void>;
|
|
163
|
+
withTransaction<T = unknown>(fn: (session: PongoSession<DriverType>) => Promise<T>, options?: PongoTransactionOptions): Promise<T>;
|
|
164
|
+
}
|
|
165
|
+
interface PongoDb<DriverType extends DatabaseDriverType = DatabaseDriverType> extends WithDatabaseTransactionFactory<AnyConnection> {
|
|
166
|
+
driverType: DriverType;
|
|
167
|
+
databaseName: string;
|
|
168
|
+
connect(): Promise<void>;
|
|
169
|
+
close(): Promise<void>;
|
|
170
|
+
collection<T extends PongoDocument>(name: string): PongoCollection<T>;
|
|
171
|
+
collections(): ReadonlyArray<PongoCollection<PongoDocument>>;
|
|
172
|
+
readonly schema: Readonly<{
|
|
173
|
+
component: PongoDatabaseSchemaComponent<DriverType>;
|
|
174
|
+
migrate(): Promise<void>;
|
|
175
|
+
}>;
|
|
176
|
+
sql: {
|
|
177
|
+
query<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<Result[]>;
|
|
178
|
+
command<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<QueryResult<Result>>;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
type AnyPongoDb = PongoDb<DatabaseDriverType>;
|
|
182
|
+
type CollectionOperationOptions = {
|
|
183
|
+
session?: PongoSession;
|
|
184
|
+
};
|
|
185
|
+
type InsertOneOptions = {
|
|
186
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
|
|
187
|
+
} & CollectionOperationOptions;
|
|
188
|
+
type InsertManyOptions = {
|
|
189
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
|
|
190
|
+
} & CollectionOperationOptions;
|
|
191
|
+
type UpdateOneOptions = {
|
|
192
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
193
|
+
} & CollectionOperationOptions;
|
|
194
|
+
type UpdateManyOptions = {
|
|
195
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
|
|
196
|
+
} & CollectionOperationOptions;
|
|
197
|
+
type HandleOptions = {
|
|
198
|
+
expectedVersion?: ExpectedDocumentVersion;
|
|
199
|
+
} & CollectionOperationOptions;
|
|
200
|
+
type ReplaceOneOptions = {
|
|
201
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
202
|
+
} & CollectionOperationOptions;
|
|
203
|
+
type DeleteOneOptions = {
|
|
204
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
205
|
+
} & CollectionOperationOptions;
|
|
206
|
+
type DeleteManyOptions = {
|
|
207
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
|
|
208
|
+
} & CollectionOperationOptions;
|
|
209
|
+
type FindOptions = {
|
|
210
|
+
limit?: number;
|
|
211
|
+
skip?: number;
|
|
212
|
+
} & CollectionOperationOptions;
|
|
213
|
+
interface PongoCollection<T extends PongoDocument> {
|
|
214
|
+
readonly dbName: string;
|
|
215
|
+
readonly collectionName: string;
|
|
216
|
+
createCollection(options?: CollectionOperationOptions): Promise<void>;
|
|
217
|
+
insertOne(document: OptionalUnlessRequiredId<T>, options?: InsertOneOptions): Promise<PongoInsertOneResult>;
|
|
218
|
+
insertMany(documents: OptionalUnlessRequiredId<T>[], options?: CollectionOperationOptions): Promise<PongoInsertManyResult>;
|
|
219
|
+
updateOne(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions): Promise<PongoUpdateResult>;
|
|
220
|
+
replaceOne(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions): Promise<PongoUpdateResult>;
|
|
221
|
+
updateMany(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateManyOptions): Promise<PongoUpdateManyResult>;
|
|
222
|
+
deleteOne(filter?: PongoFilter<T> | SQL, options?: DeleteOneOptions): Promise<PongoDeleteResult>;
|
|
223
|
+
deleteMany(filter?: PongoFilter<T> | SQL, options?: DeleteManyOptions): Promise<PongoDeleteResult>;
|
|
224
|
+
findOne(filter?: PongoFilter<T> | SQL, options?: CollectionOperationOptions): Promise<WithIdAndVersion<T> | null>;
|
|
225
|
+
find(filter?: PongoFilter<T> | SQL, options?: FindOptions): Promise<WithIdAndVersion<T>[]>;
|
|
226
|
+
findOneAndDelete(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
227
|
+
findOneAndReplace(filter: PongoFilter<T> | SQL, replacement: WithoutId<T>, options?: ReplaceOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
228
|
+
findOneAndUpdate(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
229
|
+
countDocuments(filter?: PongoFilter<T> | SQL, options?: CollectionOperationOptions): Promise<number>;
|
|
230
|
+
drop(options?: CollectionOperationOptions): Promise<boolean>;
|
|
231
|
+
rename(newName: string, options?: CollectionOperationOptions): Promise<PongoCollection<T>>;
|
|
232
|
+
handle(id: string, handle: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
|
|
233
|
+
readonly schema: Readonly<{
|
|
234
|
+
component: PongoCollectionSchemaComponent;
|
|
235
|
+
migrate(): Promise<void>;
|
|
236
|
+
}>;
|
|
237
|
+
sql: {
|
|
238
|
+
query<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<Result[]>;
|
|
239
|
+
command<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<QueryResult<Result>>;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
type ObjectId = string & {
|
|
243
|
+
__brandId: 'ObjectId';
|
|
244
|
+
};
|
|
245
|
+
declare const ObjectId: (value?: string) => string;
|
|
246
|
+
type HasId = {
|
|
247
|
+
_id: string;
|
|
248
|
+
};
|
|
249
|
+
declare type InferIdType<TSchema> = TSchema extends {
|
|
250
|
+
_id: infer IdType;
|
|
251
|
+
} ? Record<any, never> extends IdType ? never : IdType : TSchema extends {
|
|
252
|
+
_id?: infer IdType;
|
|
253
|
+
} ? unknown extends IdType ? ObjectId : IdType : ObjectId;
|
|
254
|
+
/** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
|
|
255
|
+
declare type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion ? TRecordOrUnion : TRecordOrUnion extends any ? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> : never;
|
|
256
|
+
declare type OptionalUnlessRequiredId<TSchema> = TSchema extends {
|
|
257
|
+
_id: string | ObjectId;
|
|
258
|
+
} ? TSchema : OptionalId<TSchema>;
|
|
259
|
+
declare type OptionalUnlessRequiredVersion<TSchema> = TSchema extends {
|
|
260
|
+
_version: bigint;
|
|
261
|
+
} ? TSchema : OptionalVersion<TSchema>;
|
|
262
|
+
declare type OptionalUnlessRequiredIdAndVersion<TSchema> = OptionalUnlessRequiredId<TSchema> & OptionalUnlessRequiredVersion<TSchema>;
|
|
263
|
+
declare type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
264
|
+
_id: string | ObjectId;
|
|
265
|
+
};
|
|
266
|
+
type WithoutId<T> = Omit<T, '_id'>;
|
|
267
|
+
declare type WithVersion<TSchema> = EnhancedOmit<TSchema, '_version'> & {
|
|
268
|
+
_version: bigint;
|
|
269
|
+
};
|
|
270
|
+
type WithoutVersion<T> = Omit<T, '_version'>;
|
|
271
|
+
type WithIdAndVersion<T> = WithId<WithVersion<T>>;
|
|
272
|
+
type WithoutIdAndVersion<T> = WithoutId<WithoutVersion<T>>;
|
|
273
|
+
/** @public */
|
|
274
|
+
declare type RegExpOrString<T> = T extends string ? RegExp | T : T;
|
|
275
|
+
declare interface Document {
|
|
276
|
+
[key: string]: any;
|
|
277
|
+
}
|
|
278
|
+
declare type OptionalId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
279
|
+
_id?: string | ObjectId;
|
|
280
|
+
};
|
|
281
|
+
declare type OptionalVersion<TSchema> = EnhancedOmit<TSchema, '_version'> & {
|
|
282
|
+
_version?: bigint;
|
|
283
|
+
};
|
|
284
|
+
declare interface ObjectIdLike {
|
|
285
|
+
__id?: string | ObjectId;
|
|
286
|
+
}
|
|
287
|
+
declare type NonObjectIdLikeDocument = {
|
|
288
|
+
[key in keyof ObjectIdLike]?: never;
|
|
289
|
+
} & Document;
|
|
290
|
+
declare type AlternativeType<T> = T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>;
|
|
291
|
+
declare type Condition<T> = AlternativeType<T> | PongoFilterOperator<AlternativeType<T>>;
|
|
292
|
+
declare type PongoFilter<TSchema> = {
|
|
293
|
+
[P in keyof WithId<TSchema>]?: Condition<WithId<TSchema>[P]>;
|
|
294
|
+
} | HasId;
|
|
295
|
+
declare interface RootFilterOperators<TSchema> extends Document {
|
|
296
|
+
$and?: PongoFilter<TSchema>[];
|
|
297
|
+
$nor?: PongoFilter<TSchema>[];
|
|
298
|
+
$or?: PongoFilter<TSchema>[];
|
|
299
|
+
$text?: {
|
|
300
|
+
$search: string;
|
|
301
|
+
$language?: string;
|
|
302
|
+
$caseSensitive?: boolean;
|
|
303
|
+
$diacriticSensitive?: boolean;
|
|
304
|
+
};
|
|
305
|
+
$where?: string | ((this: TSchema) => boolean);
|
|
306
|
+
$comment?: string | Document;
|
|
307
|
+
}
|
|
308
|
+
declare interface PongoFilterOperator<TValue> extends NonObjectIdLikeDocument {
|
|
309
|
+
$eq?: TValue;
|
|
310
|
+
$gt?: TValue;
|
|
311
|
+
$gte?: TValue;
|
|
312
|
+
$lt?: TValue;
|
|
313
|
+
$lte?: TValue;
|
|
314
|
+
$ne?: TValue;
|
|
315
|
+
$in?: TValue[];
|
|
316
|
+
$nin?: TValue[];
|
|
317
|
+
}
|
|
318
|
+
type $set<T> = Partial<T>;
|
|
319
|
+
type $unset<T> = {
|
|
320
|
+
[P in keyof T]?: '';
|
|
321
|
+
};
|
|
322
|
+
type $inc<T> = {
|
|
323
|
+
[P in keyof T]?: number | bigint;
|
|
324
|
+
};
|
|
325
|
+
type $push<T> = {
|
|
326
|
+
[P in keyof T]?: T[P];
|
|
327
|
+
};
|
|
328
|
+
type ExpectedDocumentVersionGeneral = 'DOCUMENT_EXISTS' | 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK';
|
|
329
|
+
type ExpectedDocumentVersionValue = bigint & {
|
|
330
|
+
__brand: 'sql';
|
|
331
|
+
};
|
|
332
|
+
type ExpectedDocumentVersion = (bigint & {
|
|
333
|
+
__brand: 'sql';
|
|
334
|
+
}) | bigint | ExpectedDocumentVersionGeneral;
|
|
335
|
+
declare const DOCUMENT_EXISTS: ExpectedDocumentVersionGeneral;
|
|
336
|
+
declare const DOCUMENT_DOES_NOT_EXIST: ExpectedDocumentVersionGeneral;
|
|
337
|
+
declare const NO_CONCURRENCY_CHECK: ExpectedDocumentVersionGeneral;
|
|
338
|
+
declare const isGeneralExpectedDocumentVersion: (version: ExpectedDocumentVersion) => version is ExpectedDocumentVersionGeneral;
|
|
339
|
+
declare const expectedVersionValue: (version: ExpectedDocumentVersion | undefined) => ExpectedDocumentVersionValue | null;
|
|
340
|
+
declare const expectedVersion: (version: number | bigint | string | undefined | null) => ExpectedDocumentVersion;
|
|
341
|
+
type PongoUpdate<T> = {
|
|
342
|
+
$set?: Partial<T>;
|
|
343
|
+
$unset?: $unset<T>;
|
|
344
|
+
$inc?: $inc<T>;
|
|
345
|
+
$push?: $push<T>;
|
|
346
|
+
};
|
|
347
|
+
type OperationResult = {
|
|
348
|
+
acknowledged: boolean;
|
|
349
|
+
successful: boolean;
|
|
350
|
+
assertSuccessful: (errorMessage?: string) => void;
|
|
351
|
+
};
|
|
352
|
+
declare const operationResult: <T extends OperationResult>(result: Omit<T, "assertSuccess" | "acknowledged" | "assertSuccessful">, options: {
|
|
353
|
+
operationName: string;
|
|
354
|
+
collectionName: string;
|
|
355
|
+
errors?: {
|
|
356
|
+
throwOnOperationFailures?: boolean;
|
|
357
|
+
} | undefined;
|
|
358
|
+
}) => T;
|
|
359
|
+
interface PongoInsertOneResult extends OperationResult {
|
|
360
|
+
insertedId: string | null;
|
|
361
|
+
nextExpectedVersion: bigint;
|
|
362
|
+
}
|
|
363
|
+
interface PongoInsertManyResult extends OperationResult {
|
|
364
|
+
insertedIds: string[];
|
|
365
|
+
insertedCount: number;
|
|
366
|
+
}
|
|
367
|
+
interface PongoUpdateResult extends OperationResult {
|
|
368
|
+
matchedCount: number;
|
|
369
|
+
modifiedCount: number;
|
|
370
|
+
nextExpectedVersion: bigint;
|
|
371
|
+
}
|
|
372
|
+
interface PongoUpdateManyResult extends OperationResult {
|
|
373
|
+
matchedCount: number;
|
|
374
|
+
modifiedCount: number;
|
|
375
|
+
}
|
|
376
|
+
interface PongoDeleteResult extends OperationResult {
|
|
377
|
+
matchedCount: number;
|
|
378
|
+
deletedCount: number;
|
|
379
|
+
}
|
|
380
|
+
interface PongoDeleteManyResult extends OperationResult {
|
|
381
|
+
deletedCount: number;
|
|
382
|
+
}
|
|
383
|
+
type PongoHandleResult<T> = (PongoInsertOneResult & {
|
|
384
|
+
document: T;
|
|
385
|
+
}) | (PongoUpdateResult & {
|
|
386
|
+
document: T;
|
|
387
|
+
}) | (PongoDeleteResult & {
|
|
388
|
+
document: null;
|
|
389
|
+
}) | (OperationResult & {
|
|
390
|
+
document: null;
|
|
391
|
+
});
|
|
392
|
+
type PongoDocument = Record<string, unknown>;
|
|
393
|
+
type DocumentHandler<T extends PongoDocument> = ((document: T | null) => T | null) | ((document: T | null) => Promise<T | null>);
|
|
394
|
+
|
|
395
|
+
type PongoCollectionSQLBuilder = {
|
|
396
|
+
createCollection: () => SQL;
|
|
397
|
+
insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
|
|
398
|
+
insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
|
|
399
|
+
updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
|
|
400
|
+
replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
|
|
401
|
+
updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
|
|
402
|
+
deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
|
|
403
|
+
deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
404
|
+
findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
405
|
+
find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
|
|
406
|
+
countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
407
|
+
rename: (newName: string) => SQL;
|
|
408
|
+
drop: () => SQL;
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
type PongoCollectionURNType = 'sc:pongo:collection';
|
|
412
|
+
type PongoCollectionURN = `${PongoCollectionURNType}:${string}`;
|
|
413
|
+
type PongoCollectionSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType> = Readonly<{
|
|
414
|
+
driverType: DriverType;
|
|
415
|
+
definition: PongoCollectionSchema;
|
|
416
|
+
migrationsOrSchemaComponents: SchemaComponentOptions;
|
|
417
|
+
sqlBuilder: PongoCollectionSQLBuilder;
|
|
418
|
+
}>;
|
|
419
|
+
type PongoCollectionSchemaComponent = SchemaComponent<PongoCollectionURN> & {
|
|
420
|
+
collectionName: string;
|
|
421
|
+
definition: PongoCollectionSchema;
|
|
422
|
+
sqlBuilder: PongoCollectionSQLBuilder;
|
|
423
|
+
};
|
|
424
|
+
declare const PongoCollectionSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({ definition, migrationsOrSchemaComponents, sqlBuilder, }: PongoCollectionSchemaComponentOptions<DriverType>) => PongoCollectionSchemaComponent;
|
|
425
|
+
|
|
426
|
+
export { type DeleteOneOptions as $, type AnyPongoDb as A, type DatabaseDriverOptionsWithConnectionString as B, type CollectionOperationOptions as C, type DatabaseDriverOptionsWithDatabaseName as D, type ExtractPongoDatabaseTypeFromDriver as E, type ExtractPongoDatabaseDriverOptions as F, PongoDatabaseDriverRegistry as G, pongoDatabaseDriverRegistry as H, type CollectionsMap as I, type PongoDbWithSchema as J, type DBsMap as K, pongoSchema as L, proxyPongoDbWithSchema as M, proxyClientWithSchema as N, type PongoCollectionSchemaMetadata as O, type PongoDatabaseDriver as P, type PongoDbSchemaMetadata as Q, type PongoClientSchemaMetadata as R, toDbSchemaMetadata as S, toClientSchemaMetadata as T, type PongoSchemaConfig as U, type InsertOneOptions as V, type InsertManyOptions as W, type UpdateOneOptions as X, type UpdateManyOptions as Y, type HandleOptions as Z, type ReplaceOneOptions as _, type PongoDb as a, type DeleteManyOptions as a0, type FindOptions as a1, ObjectId as a2, type HasId as a3, type InferIdType as a4, type EnhancedOmit as a5, type OptionalUnlessRequiredId as a6, type OptionalUnlessRequiredVersion as a7, type OptionalUnlessRequiredIdAndVersion as a8, type WithId as a9, isGeneralExpectedDocumentVersion as aA, expectedVersionValue as aB, expectedVersion as aC, type PongoUpdate as aD, type OperationResult as aE, operationResult as aF, type PongoInsertOneResult as aG, type PongoInsertManyResult as aH, type PongoUpdateResult as aI, type PongoUpdateManyResult as aJ, type PongoDeleteResult as aK, type PongoDeleteManyResult as aL, type PongoHandleResult as aM, type DocumentHandler as aN, type WithoutId as aa, type WithVersion as ab, type WithoutVersion as ac, type WithIdAndVersion as ad, type WithoutIdAndVersion as ae, type RegExpOrString as af, type Document as ag, type OptionalId as ah, type OptionalVersion as ai, type ObjectIdLike as aj, type NonObjectIdLikeDocument as ak, type AlternativeType as al, type Condition as am, type PongoFilter as an, type RootFilterOperators as ao, type PongoFilterOperator as ap, type $set as aq, type $unset as ar, type $inc as as, type $push as at, type ExpectedDocumentVersionGeneral as au, type ExpectedDocumentVersionValue as av, type ExpectedDocumentVersion as aw, DOCUMENT_EXISTS as ax, DOCUMENT_DOES_NOT_EXIST as ay, NO_CONCURRENCY_CHECK as az, type PongoDatabaseDriverOptions as b, PongoCollectionSchemaComponent as c, type PongoDocument as d, type PongoCollection as e, type PongoClientSchema as f, type PongoCollectionSchema as g, type PongoDatabaseFactoryOptions as h, PongoDatabaseSchemaComponent as i, type PongoDbSchema as j, type AnyPongoDatabaseDriver as k, type PongoClientOptions as l, type PongoClient as m, type PongoClientWithSchema as n, type PongoTransactionOptions as o, type PongoSession as p, type PongoDbTransaction as q, type PongoCollectionSQLBuilder as r, type PongoCollectionURNType as s, type PongoCollectionURN as t, type PongoCollectionSchemaComponentOptions as u, type PongoDatabaseURNType as v, type PongoDatabaseURN as w, type PongoDatabaseSchemaComponentOptions as x, type PongoDatabaseSQLBuilder as y, type AnyPongoDatabaseDriverOptions as z };
|
package/dist/shim.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkTP73JUIXcjs = require('./chunk-TP73JUIX.cjs');
|
|
5
5
|
|
|
6
6
|
// src/mongo/findCursor.ts
|
|
7
7
|
var FindCursor = (_class = class {
|
|
@@ -35,6 +35,13 @@ var FindCursor = (_class = class {
|
|
|
35
35
|
}
|
|
36
36
|
}, _class);
|
|
37
37
|
|
|
38
|
+
// src/mongo/mongoClient.ts
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
var _dumbo = require('@event-driven-io/dumbo');
|
|
43
|
+
require('http2');
|
|
44
|
+
|
|
38
45
|
// src/mongo/mongoDb.ts
|
|
39
46
|
require('mongodb');
|
|
40
47
|
|
|
@@ -58,8 +65,13 @@ var toFindOptions = (options) => {
|
|
|
58
65
|
};
|
|
59
66
|
var Collection = class {
|
|
60
67
|
|
|
61
|
-
|
|
68
|
+
|
|
69
|
+
constructor(database, collection) {
|
|
62
70
|
this.collection = collection;
|
|
71
|
+
this.database = database;
|
|
72
|
+
}
|
|
73
|
+
get db() {
|
|
74
|
+
return this.database;
|
|
63
75
|
}
|
|
64
76
|
get dbName() {
|
|
65
77
|
return this.collection.dbName;
|
|
@@ -85,6 +97,9 @@ var Collection = class {
|
|
|
85
97
|
get hint() {
|
|
86
98
|
return void 0;
|
|
87
99
|
}
|
|
100
|
+
get timeoutMS() {
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
88
103
|
set hint(v) {
|
|
89
104
|
throw new Error("Method not implemented.");
|
|
90
105
|
}
|
|
@@ -304,15 +319,34 @@ var Db = class {
|
|
|
304
319
|
return this.pongoDb.databaseName;
|
|
305
320
|
}
|
|
306
321
|
collection(collectionName) {
|
|
307
|
-
return new Collection(this.pongoDb.collection(collectionName));
|
|
322
|
+
return new Collection(this, this.pongoDb.collection(collectionName));
|
|
308
323
|
}
|
|
309
324
|
};
|
|
310
325
|
|
|
311
326
|
// src/mongo/mongoClient.ts
|
|
312
327
|
var MongoClient = class {
|
|
313
328
|
|
|
314
|
-
constructor(
|
|
315
|
-
|
|
329
|
+
constructor(connectionStringOrOptions, options) {
|
|
330
|
+
if (typeof connectionStringOrOptions !== "string") {
|
|
331
|
+
this.pongoClient = _chunkTP73JUIXcjs.pongoClient.call(void 0, connectionStringOrOptions);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const { databaseType, driverName } = _dumbo.parseConnectionString.call(void 0,
|
|
335
|
+
connectionStringOrOptions
|
|
336
|
+
);
|
|
337
|
+
const driver = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.driver]), () => ( pongoDatabaseDriverRegistry.tryGet(
|
|
338
|
+
_dumbo.toDatabaseDriverType.call(void 0, databaseType, driverName)
|
|
339
|
+
)));
|
|
340
|
+
if (driver === null) {
|
|
341
|
+
throw new Error(
|
|
342
|
+
`No database driver registered for ${databaseType} with name ${driverName}`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
this.pongoClient = _chunkTP73JUIXcjs.pongoClient.call(void 0, {
|
|
346
|
+
..._nullishCoalesce(options, () => ( {})),
|
|
347
|
+
...{ connectionString: connectionStringOrOptions },
|
|
348
|
+
driver
|
|
349
|
+
});
|
|
316
350
|
}
|
|
317
351
|
async connect() {
|
|
318
352
|
await this.pongoClient.connect();
|
|
@@ -325,12 +359,12 @@ var MongoClient = class {
|
|
|
325
359
|
return new Db(this.pongoClient.db(dbName));
|
|
326
360
|
}
|
|
327
361
|
startSession(_options) {
|
|
328
|
-
return
|
|
362
|
+
return _chunkTP73JUIXcjs.pongoSession.call(void 0, );
|
|
329
363
|
}
|
|
330
364
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
331
365
|
async withSession(optionsOrExecutor, executor) {
|
|
332
366
|
const callback = typeof optionsOrExecutor === "function" ? optionsOrExecutor : executor;
|
|
333
|
-
const session =
|
|
367
|
+
const session = _chunkTP73JUIXcjs.pongoSession.call(void 0, );
|
|
334
368
|
try {
|
|
335
369
|
return await callback(session);
|
|
336
370
|
} finally {
|