@event-driven-io/pongo 0.17.0-beta.4 → 0.17.0-beta.40
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/cli.cjs +311 -487
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +4 -4
- package/dist/cli.d.ts +4 -3
- package/dist/cli.js +279 -487
- package/dist/cli.js.map +1 -1
- package/dist/cloudflare.cjs +41 -0
- package/dist/cloudflare.cjs.map +1 -0
- package/dist/cloudflare.d.cts +12 -0
- package/dist/cloudflare.d.ts +12 -0
- package/dist/cloudflare.js +35 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/core-BHdOCUrr.js +1429 -0
- package/dist/core-BHdOCUrr.js.map +1 -0
- package/dist/core-C9SB3XMx.cjs +1717 -0
- package/dist/core-C9SB3XMx.cjs.map +1 -0
- package/dist/core-CH0SOCr3.js +361 -0
- package/dist/core-CH0SOCr3.js.map +1 -0
- package/dist/core-CkmE5dkK.cjs +373 -0
- package/dist/core-CkmE5dkK.cjs.map +1 -0
- package/dist/index-C3pnS1S_.d.cts +720 -0
- package/dist/index-CZOmOsQt.d.ts +10 -0
- package/dist/index-FXnldVnn.d.cts +10 -0
- package/dist/index-r7V4paf_.d.ts +720 -0
- package/dist/index.cjs +67 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -105
- package/dist/index.d.ts +16 -105
- package/dist/index.js +17 -73
- package/dist/index.js.map +1 -1
- package/dist/pg.cjs +319 -288
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +29 -25
- package/dist/pg.d.ts +29 -25
- package/dist/pg.js +309 -284
- package/dist/pg.js.map +1 -1
- package/dist/shim.cjs +291 -368
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +141 -137
- package/dist/shim.d.ts +141 -137
- package/dist/shim.js +285 -367
- package/dist/shim.js.map +1 -1
- package/dist/sqlite3.cjs +43 -62
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +12 -11
- package/dist/sqlite3.d.ts +12 -11
- package/dist/sqlite3.js +36 -61
- package/dist/sqlite3.js.map +1 -1
- package/package.json +42 -44
- package/dist/chunk-4BL6YWLW.cjs +0 -872
- package/dist/chunk-4BL6YWLW.cjs.map +0 -1
- package/dist/chunk-ECQ2CKZE.cjs +0 -330
- package/dist/chunk-ECQ2CKZE.cjs.map +0 -1
- package/dist/chunk-NCNRRYVE.js +0 -872
- package/dist/chunk-NCNRRYVE.js.map +0 -1
- package/dist/chunk-Y7LRKJLJ.js +0 -330
- package/dist/chunk-Y7LRKJLJ.js.map +0 -1
- package/dist/d1.cjs +0 -53
- package/dist/d1.cjs.map +0 -1
- package/dist/d1.d.cts +0 -11
- package/dist/d1.d.ts +0 -11
- package/dist/d1.js +0 -53
- package/dist/d1.js.map +0 -1
- package/dist/index-BJopB-em.d.cts +0 -7
- package/dist/index-G5DECNb_.d.ts +0 -7
- package/dist/pongoCollectionSchemaComponent-t_e9n2Wc.d.cts +0 -426
- package/dist/pongoCollectionSchemaComponent-t_e9n2Wc.d.ts +0 -426
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
import { AnyConnection, DatabaseDriverType, DatabaseTransaction, Dumbo, JSONSerializationOptions, JSONSerializer, MigrationStyle, QueryResult, QueryResultRow, RunSQLMigrationsResult, SQL, SQLCommandOptions, SQLExecutor, SQLQueryOptions, SchemaComponent, SchemaComponentOptions, WithDatabaseTransactionFactory } from "@event-driven-io/dumbo";
|
|
3
|
+
|
|
4
|
+
//#region src/core/typing/entries.d.ts
|
|
5
|
+
type Entry<T> = { [K in keyof Required<T>]: [K, Required<T>[K]] }[keyof Required<T>];
|
|
6
|
+
type IterableEntry<T> = Entry<T> & {
|
|
7
|
+
[Symbol.iterator](): Iterator<Entry<T>>;
|
|
8
|
+
};
|
|
9
|
+
declare const objectEntries: <T extends object>(obj: T) => IterableEntry<T>[];
|
|
10
|
+
type NonPartial<T> = { [K in keyof Required<T>]: T[K] };
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/core/collection/filters/filters.d.ts
|
|
13
|
+
declare const idFromFilter: <T>(filter: PongoFilter<T> | SQL | undefined) => string | undefined;
|
|
14
|
+
declare const getIdsFromIdOnlyFilter: <T>(filter: PongoFilter<T> | SQL | undefined) => string[] | undefined;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/core/collection/handle.d.ts
|
|
17
|
+
type DocumentCommandHandlerOptions<T extends PongoDocument> = {
|
|
18
|
+
collectionName: string;
|
|
19
|
+
serializer: JSONSerializer;
|
|
20
|
+
errors?: {
|
|
21
|
+
throwOnOperationFailures?: boolean;
|
|
22
|
+
} | undefined;
|
|
23
|
+
storage: {
|
|
24
|
+
ensureCollectionCreated: (options?: CollectionOperationOptions) => Promise<unknown>;
|
|
25
|
+
fetchByIds: (ids: string[], options?: CollectionOperationOptions) => Promise<(WithIdAndVersion<T> | null)[]>;
|
|
26
|
+
insertMany: (docs: OptionalUnlessRequiredIdAndVersion<T>[], options?: CollectionOperationOptions) => Promise<PongoInsertManyResult>;
|
|
27
|
+
replaceMany: (docs: Array<WithIdAndVersion<T>>, options?: CollectionOperationOptions) => Promise<PongoReplaceManyResult>;
|
|
28
|
+
deleteManyByIds: (ids: Array<{
|
|
29
|
+
_id: string;
|
|
30
|
+
_version?: bigint;
|
|
31
|
+
}>, options?: CollectionOperationOptions) => Promise<PongoDeleteResult & {
|
|
32
|
+
deletedIds: Set<string>;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
type DocumentCommandHandlerInput = {
|
|
37
|
+
_id: string;
|
|
38
|
+
expectedVersion?: ExpectedDocumentVersion;
|
|
39
|
+
};
|
|
40
|
+
declare function DocumentCommandHandler<T extends PongoDocument>(deps: DocumentCommandHandlerOptions<T>): {
|
|
41
|
+
(id: string | DocumentCommandHandlerInput, handler: DocumentHandler<T> | DocumentHandler<T>[], options?: HandleOptions): Promise<PongoHandleResult<T>>;
|
|
42
|
+
(ids: string[] | DocumentCommandHandlerInput[], handler: DocumentHandler<T> | DocumentHandler<T>[], options?: HandleOptions & BatchHandleOptions): Promise<PongoHandleResult<T>[]>;
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/core/collection/pongoCollection.d.ts
|
|
46
|
+
type PongoCollectionOptions<T extends PongoDocument = PongoDocument, DriverType extends DatabaseDriverType = DatabaseDriverType, Payload extends PongoDocument = T> = {
|
|
47
|
+
db: PongoDb<DriverType>;
|
|
48
|
+
collectionName: string;
|
|
49
|
+
pool: Dumbo<DatabaseDriverType>;
|
|
50
|
+
schemaComponent: PongoCollectionSchemaComponent;
|
|
51
|
+
schema?: {
|
|
52
|
+
autoMigration?: MigrationStyle;
|
|
53
|
+
versioning?: {
|
|
54
|
+
upcast?: (doc: Payload) => T;
|
|
55
|
+
downcast?: (doc: T) => Payload;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
errors?: {
|
|
59
|
+
throwOnOperationFailures?: boolean;
|
|
60
|
+
};
|
|
61
|
+
serializer: JSONSerializer;
|
|
62
|
+
cache?: CacheConfig | 'disabled' | PongoCache | undefined;
|
|
63
|
+
};
|
|
64
|
+
declare const transactionExecutorOrDefault: <DriverType extends DatabaseDriverType = DatabaseDriverType>(db: PongoDb<DriverType>, options: CollectionOperationOptions | undefined, defaultSqlExecutor: SQLExecutor) => Promise<SQLExecutor>;
|
|
65
|
+
declare const pongoCollection: <T extends PongoDocument, DriverType extends DatabaseDriverType = DatabaseDriverType, Payload extends PongoDocument = T>({
|
|
66
|
+
db,
|
|
67
|
+
collectionName,
|
|
68
|
+
pool,
|
|
69
|
+
schemaComponent,
|
|
70
|
+
schema,
|
|
71
|
+
errors,
|
|
72
|
+
serializer,
|
|
73
|
+
cache: cacheOptions
|
|
74
|
+
}: PongoCollectionOptions<T, DriverType, Payload>) => PongoCollection<T>;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/core/collection/pongoCollectionSchema.d.ts
|
|
77
|
+
type PongoCollectionSQLBuilder = {
|
|
78
|
+
createCollection: () => SQL;
|
|
79
|
+
insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
|
|
80
|
+
insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
|
|
81
|
+
insertOrReplace: <T>(documents: Array<WithId<T>>) => SQL;
|
|
82
|
+
updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
|
|
83
|
+
replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
|
|
84
|
+
updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
|
|
85
|
+
deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
|
|
86
|
+
deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
87
|
+
replaceMany: <T>(documents: Array<WithIdAndVersion<T>> | Array<WithId<T>>) => SQL;
|
|
88
|
+
deleteManyByIds: (ids: Array<{
|
|
89
|
+
_id: string;
|
|
90
|
+
_version?: bigint;
|
|
91
|
+
}>) => SQL;
|
|
92
|
+
findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
93
|
+
find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
|
|
94
|
+
countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
95
|
+
rename: (newName: string) => SQL;
|
|
96
|
+
drop: () => SQL;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/core/collection/pongoCollectionSchemaComponent.d.ts
|
|
100
|
+
type PongoCollectionURNType = 'sc:pongo:collection';
|
|
101
|
+
type PongoCollectionURN = `${PongoCollectionURNType}:${string}`;
|
|
102
|
+
type PongoCollectionSchemaComponent = SchemaComponent<PongoCollectionURN> & {
|
|
103
|
+
collectionName: string;
|
|
104
|
+
definition: PongoCollectionSchema;
|
|
105
|
+
sqlBuilder: PongoCollectionSQLBuilder;
|
|
106
|
+
};
|
|
107
|
+
type PongoCollectionSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType> = Readonly<{
|
|
108
|
+
driverType: DriverType;
|
|
109
|
+
definition: PongoCollectionSchema;
|
|
110
|
+
migrationsOrSchemaComponents: SchemaComponentOptions;
|
|
111
|
+
sqlBuilder: PongoCollectionSQLBuilder;
|
|
112
|
+
}>;
|
|
113
|
+
declare const PongoCollectionSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({
|
|
114
|
+
definition,
|
|
115
|
+
migrationsOrSchemaComponents,
|
|
116
|
+
sqlBuilder
|
|
117
|
+
}: PongoCollectionSchemaComponentOptions<DriverType>) => PongoCollectionSchemaComponent;
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/core/collection/query.d.ts
|
|
120
|
+
declare const QueryOperators: {
|
|
121
|
+
$eq: string;
|
|
122
|
+
$gt: string;
|
|
123
|
+
$gte: string;
|
|
124
|
+
$lt: string;
|
|
125
|
+
$lte: string;
|
|
126
|
+
$ne: string;
|
|
127
|
+
$in: string;
|
|
128
|
+
$nin: string;
|
|
129
|
+
$elemMatch: string;
|
|
130
|
+
$all: string;
|
|
131
|
+
$size: string;
|
|
132
|
+
};
|
|
133
|
+
declare const OperatorMap: {
|
|
134
|
+
$gt: string;
|
|
135
|
+
$gte: string;
|
|
136
|
+
$lt: string;
|
|
137
|
+
$lte: string;
|
|
138
|
+
$ne: string;
|
|
139
|
+
};
|
|
140
|
+
declare const isOperator: (key: string) => boolean;
|
|
141
|
+
declare const hasOperators: (value: Record<string, unknown>) => boolean;
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/core/schema/index.d.ts
|
|
144
|
+
interface PongoCollectionSchema<T extends PongoDocument = PongoDocument> {
|
|
145
|
+
name: string;
|
|
146
|
+
}
|
|
147
|
+
interface PongoDbSchema<T extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>> {
|
|
148
|
+
name?: string;
|
|
149
|
+
collections: T;
|
|
150
|
+
}
|
|
151
|
+
interface PongoClientSchema<T extends Record<string, PongoDbSchema> = Record<string, PongoDbSchema>> {
|
|
152
|
+
dbs: T;
|
|
153
|
+
}
|
|
154
|
+
type CollectionsMap<T extends Record<string, PongoCollectionSchema>> = { [K in keyof T]: PongoCollection<T[K] extends PongoCollectionSchema<infer U> ? U : PongoDocument> };
|
|
155
|
+
type PongoDbWithSchema<T extends Record<string, PongoCollectionSchema>, DriverType extends DatabaseDriverType = DatabaseDriverType> = CollectionsMap<T> & PongoDb<DriverType>;
|
|
156
|
+
type DBsMap<T extends Record<string, PongoDbSchema>, DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> = { [K in keyof T]: CollectionsMap<T[K]['collections']> & Database };
|
|
157
|
+
type PongoClientWithSchema<T extends PongoClientSchema, DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> = DBsMap<T['dbs'], DriverType, Database> & PongoClient<DriverType, Database>;
|
|
158
|
+
declare function pongoDbSchema<T extends Record<string, PongoCollectionSchema>>(collections: T): PongoDbSchema<T>;
|
|
159
|
+
declare function pongoDbSchema<T extends Record<string, PongoCollectionSchema>>(name: string, collections: T): PongoDbSchema<T>;
|
|
160
|
+
declare namespace pongoDbSchema {
|
|
161
|
+
var from: (databaseName: string | undefined, collectionNames: string[]) => PongoDbSchema;
|
|
162
|
+
}
|
|
163
|
+
declare const pongoSchema: {
|
|
164
|
+
client: <T extends Record<string, PongoDbSchema>>(dbs: T) => PongoClientSchema<T>;
|
|
165
|
+
db: typeof pongoDbSchema;
|
|
166
|
+
collection: {
|
|
167
|
+
<T extends PongoDocument>(name: string): PongoCollectionSchema<T>;
|
|
168
|
+
from(collectionNames: string[]): Record<string, PongoCollectionSchema>;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
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;
|
|
172
|
+
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>;
|
|
173
|
+
type PongoCollectionSchemaMetadata = {
|
|
174
|
+
name: string;
|
|
175
|
+
};
|
|
176
|
+
type PongoDbSchemaMetadata = {
|
|
177
|
+
name?: string | undefined;
|
|
178
|
+
collections: PongoCollectionSchemaMetadata[];
|
|
179
|
+
};
|
|
180
|
+
type PongoClientSchemaMetadata = {
|
|
181
|
+
databases: PongoDbSchemaMetadata[];
|
|
182
|
+
database: (name?: string) => PongoDbSchemaMetadata | undefined;
|
|
183
|
+
};
|
|
184
|
+
declare const toDbSchemaMetadata: <TypedDbSchema extends PongoDbSchema>(schema: TypedDbSchema) => PongoDbSchemaMetadata;
|
|
185
|
+
declare const toClientSchemaMetadata: <TypedClientSchema extends PongoClientSchema>(schema: TypedClientSchema) => PongoClientSchemaMetadata;
|
|
186
|
+
interface PongoSchemaConfig<TypedClientSchema extends PongoClientSchema = PongoClientSchema> {
|
|
187
|
+
schema: TypedClientSchema;
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/core/database/pongoDatabaseSchemaComponent.d.ts
|
|
191
|
+
type PongoDatabaseURNType = 'sc:dumbo:database';
|
|
192
|
+
type PongoDatabaseURN = `${PongoDatabaseURNType}:${string}`;
|
|
193
|
+
type PongoDatabaseSchemaComponent<DriverType extends DatabaseDriverType = DatabaseDriverType, T extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>> = SchemaComponent<PongoDatabaseURN> & {
|
|
194
|
+
definition: PongoDbSchema<T>;
|
|
195
|
+
collections: ReadonlyArray<PongoCollectionSchemaComponent>;
|
|
196
|
+
collection: <T extends PongoDocument = PongoDocument>(schema: PongoCollectionSchema<T>) => PongoCollectionSchemaComponent;
|
|
197
|
+
};
|
|
198
|
+
type PongoDatabaseSchemaComponentOptions<DriverType extends DatabaseDriverType = DatabaseDriverType, T extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>> = Readonly<{
|
|
199
|
+
driverType: DriverType;
|
|
200
|
+
definition: PongoDbSchema<T>;
|
|
201
|
+
collectionFactory: <T extends PongoDocument = PongoDocument>(schema: PongoCollectionSchema<T>) => PongoCollectionSchemaComponent;
|
|
202
|
+
}>;
|
|
203
|
+
declare const PongoDatabaseSchemaComponent: <DriverType extends DatabaseDriverType = DatabaseDriverType>({
|
|
204
|
+
definition,
|
|
205
|
+
collectionFactory
|
|
206
|
+
}: PongoDatabaseSchemaComponentOptions<DriverType>) => PongoDatabaseSchemaComponent;
|
|
207
|
+
type PongoDatabaseSQLBuilder<DriverType extends DatabaseDriverType = DatabaseDriverType> = {
|
|
208
|
+
driverType: DriverType;
|
|
209
|
+
collection: PongoCollectionSQLBuilder;
|
|
210
|
+
};
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/core/drivers/databaseDriver.d.ts
|
|
213
|
+
type PongoDriverOptions<ConnectionOptions = unknown> = {
|
|
214
|
+
connectionOptions?: ConnectionOptions | undefined;
|
|
215
|
+
} & JSONSerializationOptions;
|
|
216
|
+
type AnyPongoDriverOptions = PongoDriverOptions<any>;
|
|
217
|
+
type PongoDatabaseFactoryOptions<CollectionsSchema extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>, DriverOptions extends AnyPongoDriverOptions = AnyPongoDriverOptions> = {
|
|
218
|
+
databaseName?: string | undefined;
|
|
219
|
+
schema?: {
|
|
220
|
+
autoMigration?: MigrationStyle;
|
|
221
|
+
definition?: PongoDbSchema<CollectionsSchema>;
|
|
222
|
+
} | undefined;
|
|
223
|
+
serializer: JSONSerializer;
|
|
224
|
+
errors?: {
|
|
225
|
+
throwOnOperationFailures?: boolean;
|
|
226
|
+
} | undefined;
|
|
227
|
+
cache?: CacheConfig | 'disabled' | PongoCache | undefined;
|
|
228
|
+
} & DriverOptions;
|
|
229
|
+
interface PongoDriver<Database extends AnyPongoDb = AnyPongoDb, DriverOptions extends AnyPongoDriverOptions = AnyPongoDriverOptions> {
|
|
230
|
+
driverType: Database['driverType'];
|
|
231
|
+
databaseFactory<CollectionsSchema extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>>(options: PongoDatabaseFactoryOptions<CollectionsSchema, DriverOptions>): Database & PongoDb<Database['driverType']>;
|
|
232
|
+
}
|
|
233
|
+
type AnyPongoDriver = PongoDriver<AnyPongoDb, AnyPongoDriverOptions>;
|
|
234
|
+
type ExtractPongoDriverOptions<DatabaseDriver> = DatabaseDriver extends PongoDriver<any, infer O> ? O : never;
|
|
235
|
+
type ExtractPongoDatabaseTypeFromDriver<DatabaseDriver> = DatabaseDriver extends PongoDriver<infer D, any> ? D : never;
|
|
236
|
+
declare const PongoDriverRegistry: () => {
|
|
237
|
+
register: <Database extends AnyPongoDb = AnyPongoDb>(driverType: Database["driverType"], driver: PongoDriver<Database> | (() => Promise<PongoDriver<Database>>)) => void;
|
|
238
|
+
tryResolve: <Driver extends AnyPongoDriver = AnyPongoDriver>(driverType: Driver["driverType"]) => Promise<Driver | null>;
|
|
239
|
+
tryGet: <Driver extends AnyPongoDriver = AnyPongoDriver>(driverType: Driver["driverType"]) => Driver | null;
|
|
240
|
+
has: (driverType: DatabaseDriverType) => boolean;
|
|
241
|
+
readonly databaseDriverTypes: DatabaseDriverType[];
|
|
242
|
+
};
|
|
243
|
+
declare global {
|
|
244
|
+
var pongoDriverRegistry: ReturnType<typeof PongoDriverRegistry>;
|
|
245
|
+
}
|
|
246
|
+
declare const pongoDriverRegistry: {
|
|
247
|
+
register: <Database extends AnyPongoDb = AnyPongoDb>(driverType: Database["driverType"], driver: PongoDriver<Database> | (() => Promise<PongoDriver<Database>>)) => void;
|
|
248
|
+
tryResolve: <Driver extends AnyPongoDriver = AnyPongoDriver>(driverType: Driver["driverType"]) => Promise<Driver | null>;
|
|
249
|
+
tryGet: <Driver extends AnyPongoDriver = AnyPongoDriver>(driverType: Driver["driverType"]) => Driver | null;
|
|
250
|
+
has: (driverType: DatabaseDriverType) => boolean;
|
|
251
|
+
readonly databaseDriverTypes: DatabaseDriverType[];
|
|
252
|
+
};
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/core/typing/operations.d.ts
|
|
255
|
+
interface PongoClient<DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> {
|
|
256
|
+
driverType: DriverType;
|
|
257
|
+
connect(): Promise<this>;
|
|
258
|
+
close(): Promise<void>;
|
|
259
|
+
db(dbName?: string, options?: PongoDbOptions): Database;
|
|
260
|
+
startSession(): PongoSession<DriverType>;
|
|
261
|
+
withSession<T = unknown>(callback: (session: PongoSession<DriverType>) => Promise<T>): Promise<T>;
|
|
262
|
+
}
|
|
263
|
+
type PongoClientOptions<DatabaseDriver extends AnyPongoDriver = AnyPongoDriver, TypedClientSchema extends PongoClientSchema = PongoClientSchema> = ExtractPongoDriverOptions<DatabaseDriver> extends infer Options ? Options extends unknown ? {
|
|
264
|
+
driver: DatabaseDriver;
|
|
265
|
+
schema?: {
|
|
266
|
+
autoMigration?: MigrationStyle;
|
|
267
|
+
definition?: TypedClientSchema;
|
|
268
|
+
} | undefined;
|
|
269
|
+
errors?: {
|
|
270
|
+
throwOnOperationFailures?: boolean;
|
|
271
|
+
} | undefined;
|
|
272
|
+
cache?: CacheConfig | PongoCache | undefined;
|
|
273
|
+
} & JSONSerializationOptions & Omit<Options, 'driver'> : never : never;
|
|
274
|
+
declare interface PongoTransactionOptions {
|
|
275
|
+
get snapshotEnabled(): boolean;
|
|
276
|
+
maxCommitTimeMS?: number;
|
|
277
|
+
}
|
|
278
|
+
interface PongoDbTransaction<DriverType extends DatabaseDriverType = DatabaseDriverType, Database extends PongoDb<DriverType> = PongoDb<DriverType>> {
|
|
279
|
+
get databaseName(): string | null;
|
|
280
|
+
options: PongoTransactionOptions;
|
|
281
|
+
enlistDatabase: (database: Database) => Promise<DatabaseTransaction<AnyConnection>>;
|
|
282
|
+
commit: () => Promise<void>;
|
|
283
|
+
rollback: (error?: unknown) => Promise<void>;
|
|
284
|
+
get cache(): PongoTransactionCache | null;
|
|
285
|
+
get sqlExecutor(): SQLExecutor;
|
|
286
|
+
get isStarting(): boolean;
|
|
287
|
+
get isActive(): boolean;
|
|
288
|
+
get isCommitted(): boolean;
|
|
289
|
+
}
|
|
290
|
+
interface PongoSession<DriverType extends DatabaseDriverType = DatabaseDriverType> {
|
|
291
|
+
hasEnded: boolean;
|
|
292
|
+
explicit: boolean;
|
|
293
|
+
defaultTransactionOptions: PongoTransactionOptions;
|
|
294
|
+
transaction: PongoDbTransaction<DriverType> | null;
|
|
295
|
+
get snapshotEnabled(): boolean;
|
|
296
|
+
endSession(): Promise<void>;
|
|
297
|
+
incrementTransactionNumber(): void;
|
|
298
|
+
inTransaction(): boolean;
|
|
299
|
+
startTransaction(options?: PongoTransactionOptions): void;
|
|
300
|
+
commitTransaction(): Promise<void>;
|
|
301
|
+
abortTransaction(): Promise<void>;
|
|
302
|
+
withTransaction<T = unknown>(fn: (session: PongoSession<DriverType>) => Promise<T>, options?: PongoTransactionOptions): Promise<T>;
|
|
303
|
+
}
|
|
304
|
+
type PongoDBCollectionOptions<T extends PongoDocument, Payload extends PongoDocument = T> = {
|
|
305
|
+
schema?: {
|
|
306
|
+
versioning?: {
|
|
307
|
+
upcast?: (document: Payload) => T;
|
|
308
|
+
downcast?: (document: T) => Payload;
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
errors?: {
|
|
312
|
+
throwOnOperationFailures?: boolean;
|
|
313
|
+
};
|
|
314
|
+
cache?: CacheConfig | 'disabled' | PongoCache;
|
|
315
|
+
};
|
|
316
|
+
type PongoDbOptions = {
|
|
317
|
+
cache?: CacheConfig | PongoCache;
|
|
318
|
+
};
|
|
319
|
+
interface PongoDb<DriverType extends DatabaseDriverType = DatabaseDriverType> extends WithDatabaseTransactionFactory<AnyConnection> {
|
|
320
|
+
driverType: DriverType;
|
|
321
|
+
databaseName: string;
|
|
322
|
+
connect(): Promise<void>;
|
|
323
|
+
close(): Promise<void>;
|
|
324
|
+
collection<T extends PongoDocument, Payload extends PongoDocument = T>(name: string, options?: PongoDBCollectionOptions<T, Payload>): PongoCollection<T>;
|
|
325
|
+
collections(): ReadonlyArray<PongoCollection<PongoDocument>>;
|
|
326
|
+
readonly schema: Readonly<{
|
|
327
|
+
component: PongoDatabaseSchemaComponent<DriverType>;
|
|
328
|
+
migrate(options?: PongoMigrationOptions): Promise<RunSQLMigrationsResult>;
|
|
329
|
+
}>;
|
|
330
|
+
sql: {
|
|
331
|
+
query<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions & SQLQueryOptions): Promise<Result[]>;
|
|
332
|
+
command<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions & SQLCommandOptions): Promise<QueryResult<Result>>;
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
type AnyPongoDb = PongoDb<DatabaseDriverType>;
|
|
336
|
+
type PongoMigrationOptions = {
|
|
337
|
+
dryRun?: boolean | undefined;
|
|
338
|
+
ignoreMigrationHashMismatch?: boolean | undefined;
|
|
339
|
+
migrationTimeoutMs?: number | undefined;
|
|
340
|
+
};
|
|
341
|
+
type CollectionOperationOptions = {
|
|
342
|
+
session?: PongoSession;
|
|
343
|
+
skipCache?: boolean;
|
|
344
|
+
};
|
|
345
|
+
type InsertOneOptions = {
|
|
346
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
|
|
347
|
+
upsert?: boolean;
|
|
348
|
+
} & CollectionOperationOptions;
|
|
349
|
+
type InsertManyOptions = {
|
|
350
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK'>;
|
|
351
|
+
upsert?: boolean;
|
|
352
|
+
} & CollectionOperationOptions;
|
|
353
|
+
type UpdateOneOptions = {
|
|
354
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
355
|
+
} & CollectionOperationOptions;
|
|
356
|
+
type UpdateManyOptions = {
|
|
357
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
|
|
358
|
+
} & CollectionOperationOptions;
|
|
359
|
+
type HandleOptions = CollectionOperationOptions;
|
|
360
|
+
type BatchHandleOptions = {
|
|
361
|
+
parallel?: boolean;
|
|
362
|
+
} & CollectionOperationOptions;
|
|
363
|
+
type ReplaceOneOptions = {
|
|
364
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
365
|
+
upsert?: boolean;
|
|
366
|
+
} & CollectionOperationOptions;
|
|
367
|
+
type DeleteOneOptions = {
|
|
368
|
+
expectedVersion?: Exclude<ExpectedDocumentVersion, 'DOCUMENT_DOES_NOT_EXIST'>;
|
|
369
|
+
} & CollectionOperationOptions;
|
|
370
|
+
type ReplaceManyOptions = {
|
|
371
|
+
upsert?: boolean;
|
|
372
|
+
} & CollectionOperationOptions;
|
|
373
|
+
type DeleteManyOptions = {
|
|
374
|
+
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
|
|
375
|
+
} & CollectionOperationOptions;
|
|
376
|
+
type FindOptions = {
|
|
377
|
+
limit?: number;
|
|
378
|
+
skip?: number;
|
|
379
|
+
sort?: {
|
|
380
|
+
[field: string]: 1 | -1;
|
|
381
|
+
};
|
|
382
|
+
} & CollectionOperationOptions;
|
|
383
|
+
interface PongoCollection<T extends PongoDocument> {
|
|
384
|
+
readonly dbName: string;
|
|
385
|
+
readonly collectionName: string;
|
|
386
|
+
createCollection(options?: CollectionOperationOptions): Promise<void>;
|
|
387
|
+
insertOne(document: OptionalUnlessRequiredId<T>, options?: InsertOneOptions): Promise<PongoInsertOneResult>;
|
|
388
|
+
insertMany(documents: OptionalUnlessRequiredId<T>[], options?: InsertManyOptions): Promise<PongoInsertManyResult>;
|
|
389
|
+
updateOne(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions): Promise<PongoUpdateResult>;
|
|
390
|
+
replaceOne(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions): Promise<PongoUpdateResult>;
|
|
391
|
+
updateMany(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateManyOptions): Promise<PongoUpdateManyResult>;
|
|
392
|
+
deleteOne(filter?: PongoFilter<T> | SQL, options?: DeleteOneOptions): Promise<PongoDeleteResult>;
|
|
393
|
+
deleteMany(filter?: PongoFilter<T> | SQL, options?: DeleteManyOptions): Promise<PongoDeleteResult>;
|
|
394
|
+
findOne(filter?: PongoFilter<T> | SQL, options?: CollectionOperationOptions): Promise<WithIdAndVersion<T> | null>;
|
|
395
|
+
find(filter?: PongoFilter<T> | SQL, options?: FindOptions): Promise<WithIdAndVersion<T>[]>;
|
|
396
|
+
findOneAndDelete(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
397
|
+
findOneAndReplace(filter: PongoFilter<T> | SQL, replacement: WithoutId<T>, options?: ReplaceOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
398
|
+
findOneAndUpdate(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
399
|
+
countDocuments(filter?: PongoFilter<T> | SQL, options?: CollectionOperationOptions): Promise<number>;
|
|
400
|
+
drop(options?: CollectionOperationOptions): Promise<boolean>;
|
|
401
|
+
rename(newName: string, options?: CollectionOperationOptions): Promise<PongoCollection<T>>;
|
|
402
|
+
handle(id: string | DocumentCommandHandlerInput, handle: DocumentHandler<T>, options?: HandleOptions): Promise<PongoHandleResult<T>>;
|
|
403
|
+
handle(id: string[] | DocumentCommandHandlerInput[], handle: DocumentHandler<T>, options?: BatchHandleOptions): Promise<PongoHandleResult<T>[]>;
|
|
404
|
+
replaceMany(documents: Array<WithIdAndVersion<T>> | Array<WithId<T>>, options?: ReplaceManyOptions): Promise<PongoReplaceManyResult>;
|
|
405
|
+
readonly schema: Readonly<{
|
|
406
|
+
component: PongoCollectionSchemaComponent;
|
|
407
|
+
migrate(options?: PongoMigrationOptions): Promise<RunSQLMigrationsResult>;
|
|
408
|
+
}>;
|
|
409
|
+
close: () => MaybePromise<void>;
|
|
410
|
+
sql: {
|
|
411
|
+
query<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<Result[]>;
|
|
412
|
+
command<Result extends QueryResultRow = QueryResultRow>(sql: SQL, options?: CollectionOperationOptions): Promise<QueryResult<Result>>;
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
type ObjectId = string & {
|
|
416
|
+
__brandId: 'ObjectId';
|
|
417
|
+
};
|
|
418
|
+
declare const ObjectId: (value?: string) => string;
|
|
419
|
+
type HasId = {
|
|
420
|
+
_id: string;
|
|
421
|
+
};
|
|
422
|
+
declare type InferIdType<TSchema> = TSchema extends {
|
|
423
|
+
_id: infer IdType;
|
|
424
|
+
} ? Record<any, never> extends IdType ? never : IdType : TSchema extends {
|
|
425
|
+
_id?: infer IdType;
|
|
426
|
+
} ? unknown extends IdType ? ObjectId : IdType : ObjectId;
|
|
427
|
+
/** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
|
|
428
|
+
declare type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion ? TRecordOrUnion : TRecordOrUnion extends any ? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> : never;
|
|
429
|
+
declare type OptionalUnlessRequiredId<TSchema> = TSchema extends {
|
|
430
|
+
_id: string | ObjectId;
|
|
431
|
+
} ? TSchema : OptionalId<TSchema>;
|
|
432
|
+
declare type OptionalUnlessRequiredVersion<TSchema> = TSchema extends {
|
|
433
|
+
_version: bigint;
|
|
434
|
+
} ? TSchema : OptionalVersion<TSchema>;
|
|
435
|
+
declare type OptionalUnlessRequiredIdAndVersion<TSchema> = OptionalUnlessRequiredId<TSchema> & OptionalUnlessRequiredVersion<TSchema>;
|
|
436
|
+
declare type WithId<TSchema> = TSchema & {
|
|
437
|
+
_id: string | ObjectId;
|
|
438
|
+
};
|
|
439
|
+
type WithoutId<T> = Omit<T, '_id'>;
|
|
440
|
+
declare type WithVersion<TSchema> = TSchema & {
|
|
441
|
+
_version: bigint;
|
|
442
|
+
};
|
|
443
|
+
type WithoutVersion<T> = Omit<T, '_version'>;
|
|
444
|
+
type WithIdAndVersion<T> = WithId<T> & WithVersion<T>;
|
|
445
|
+
type WithoutIdAndVersion<T> = WithoutId<WithoutVersion<T>>;
|
|
446
|
+
/** @public */
|
|
447
|
+
declare type RegExpOrString<T> = T extends string ? RegExp | T : T;
|
|
448
|
+
declare interface Document {
|
|
449
|
+
[key: string]: any;
|
|
450
|
+
}
|
|
451
|
+
declare type OptionalId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
452
|
+
_id?: string | ObjectId;
|
|
453
|
+
};
|
|
454
|
+
declare type OptionalVersion<TSchema> = EnhancedOmit<TSchema, '_version'> & {
|
|
455
|
+
_version?: bigint;
|
|
456
|
+
};
|
|
457
|
+
declare interface ObjectIdLike {
|
|
458
|
+
__id?: string | ObjectId;
|
|
459
|
+
}
|
|
460
|
+
declare type NonObjectIdLikeDocument = { [key in keyof ObjectIdLike]?: never } & Document;
|
|
461
|
+
declare type AlternativeType<T> = T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>;
|
|
462
|
+
declare type Condition<T> = AlternativeType<T> | PongoFilterOperator<AlternativeType<T>>;
|
|
463
|
+
declare interface RootFilterOperators<TSchema> extends Document {
|
|
464
|
+
$and?: PongoFilter<TSchema>[];
|
|
465
|
+
$nor?: PongoFilter<TSchema>[];
|
|
466
|
+
$or?: PongoFilter<TSchema>[];
|
|
467
|
+
$text?: {
|
|
468
|
+
$search: string;
|
|
469
|
+
$language?: string;
|
|
470
|
+
$caseSensitive?: boolean;
|
|
471
|
+
$diacriticSensitive?: boolean;
|
|
472
|
+
};
|
|
473
|
+
$where?: string | ((this: TSchema) => boolean);
|
|
474
|
+
$comment?: string | Document;
|
|
475
|
+
}
|
|
476
|
+
declare type PongoFilter<TSchema> = ({ [P in keyof WithId<TSchema>]?: Condition<WithId<TSchema>[P]> } & Pick<RootFilterOperators<WithId<TSchema>>, '$and' | '$nor' | '$or'>) | (HasId & Pick<RootFilterOperators<WithId<TSchema>>, '$and' | '$nor' | '$or'>);
|
|
477
|
+
declare interface PongoFilterOperator<TValue> extends NonObjectIdLikeDocument {
|
|
478
|
+
$eq?: TValue;
|
|
479
|
+
$gt?: TValue;
|
|
480
|
+
$gte?: TValue;
|
|
481
|
+
$lt?: TValue;
|
|
482
|
+
$lte?: TValue;
|
|
483
|
+
$ne?: TValue;
|
|
484
|
+
$in?: TValue[];
|
|
485
|
+
$nin?: TValue[];
|
|
486
|
+
}
|
|
487
|
+
type $set<T> = Partial<T>;
|
|
488
|
+
type $unset<T> = { [P in keyof T]?: '' };
|
|
489
|
+
type $inc<T> = { [P in keyof T]?: number | bigint };
|
|
490
|
+
type $push<T> = { [P in keyof T]?: T[P] };
|
|
491
|
+
type ExpectedDocumentVersionGeneral = 'DOCUMENT_EXISTS' | 'DOCUMENT_DOES_NOT_EXIST' | 'NO_CONCURRENCY_CHECK';
|
|
492
|
+
type ExpectedDocumentVersionValue = bigint & {
|
|
493
|
+
__brand: 'sql';
|
|
494
|
+
};
|
|
495
|
+
type ExpectedDocumentVersion = (bigint & {
|
|
496
|
+
__brand: 'sql';
|
|
497
|
+
}) | bigint | ExpectedDocumentVersionGeneral;
|
|
498
|
+
declare const DOCUMENT_EXISTS: ExpectedDocumentVersionGeneral;
|
|
499
|
+
declare const DOCUMENT_DOES_NOT_EXIST: ExpectedDocumentVersionGeneral;
|
|
500
|
+
declare const NO_CONCURRENCY_CHECK: ExpectedDocumentVersionGeneral;
|
|
501
|
+
declare const isGeneralExpectedDocumentVersion: (version: ExpectedDocumentVersion) => version is ExpectedDocumentVersionGeneral;
|
|
502
|
+
declare const expectedVersionValue: (version: ExpectedDocumentVersion | undefined) => ExpectedDocumentVersionValue | null;
|
|
503
|
+
type ExpectedVersionPredicate = {
|
|
504
|
+
operator: 'none';
|
|
505
|
+
} | {
|
|
506
|
+
operator: '=';
|
|
507
|
+
value: bigint;
|
|
508
|
+
};
|
|
509
|
+
declare const expectedVersionPredicate: (version: ExpectedDocumentVersion | undefined) => ExpectedVersionPredicate;
|
|
510
|
+
declare const expectedVersion: (version: number | bigint | string | undefined | null) => ExpectedDocumentVersion;
|
|
511
|
+
type PongoUpdate<T> = {
|
|
512
|
+
$set?: Partial<T>;
|
|
513
|
+
$unset?: $unset<T>;
|
|
514
|
+
$inc?: $inc<T>;
|
|
515
|
+
$push?: $push<T>;
|
|
516
|
+
};
|
|
517
|
+
type OperationResult = {
|
|
518
|
+
acknowledged: boolean;
|
|
519
|
+
successful: boolean;
|
|
520
|
+
assertSuccessful: (errorMessage?: string) => void;
|
|
521
|
+
};
|
|
522
|
+
declare const operationResult: <T extends OperationResult>(result: Omit<T, "assertSuccess" | "acknowledged" | "assertSuccessful">, options: {
|
|
523
|
+
operationName: string;
|
|
524
|
+
collectionName: string;
|
|
525
|
+
serializer: JSONSerializer;
|
|
526
|
+
errors?: {
|
|
527
|
+
throwOnOperationFailures?: boolean;
|
|
528
|
+
} | undefined;
|
|
529
|
+
}) => T;
|
|
530
|
+
interface PongoInsertOneResult extends OperationResult {
|
|
531
|
+
insertedId: string | null;
|
|
532
|
+
nextExpectedVersion: bigint;
|
|
533
|
+
}
|
|
534
|
+
interface PongoInsertManyResult extends OperationResult {
|
|
535
|
+
insertedIds: string[];
|
|
536
|
+
insertedCount: number;
|
|
537
|
+
}
|
|
538
|
+
interface PongoUpdateResult extends OperationResult {
|
|
539
|
+
matchedCount: number;
|
|
540
|
+
modifiedCount: number;
|
|
541
|
+
upsertedId: string | null;
|
|
542
|
+
upsertedCount: number;
|
|
543
|
+
nextExpectedVersion: bigint;
|
|
544
|
+
}
|
|
545
|
+
interface PongoUpdateManyResult extends OperationResult {
|
|
546
|
+
matchedCount: number;
|
|
547
|
+
modifiedCount: number;
|
|
548
|
+
}
|
|
549
|
+
interface PongoDeleteResult extends OperationResult {
|
|
550
|
+
matchedCount: number;
|
|
551
|
+
deletedCount: number;
|
|
552
|
+
}
|
|
553
|
+
interface PongoDeleteManyResult extends OperationResult {
|
|
554
|
+
deletedCount: number;
|
|
555
|
+
}
|
|
556
|
+
interface PongoReplaceManyResult extends OperationResult {
|
|
557
|
+
modifiedCount: number;
|
|
558
|
+
matchedCount: number;
|
|
559
|
+
modifiedIds: string[];
|
|
560
|
+
conflictIds: string[];
|
|
561
|
+
nextExpectedVersions: Map<string, bigint>;
|
|
562
|
+
}
|
|
563
|
+
type PongoHandleResult<T> = (PongoInsertOneResult & {
|
|
564
|
+
document: T;
|
|
565
|
+
}) | (PongoUpdateResult & {
|
|
566
|
+
document: T;
|
|
567
|
+
}) | (PongoDeleteResult & {
|
|
568
|
+
document: null;
|
|
569
|
+
}) | (OperationResult & {
|
|
570
|
+
document: null;
|
|
571
|
+
});
|
|
572
|
+
type PongoDocument = Record<string, unknown>;
|
|
573
|
+
type DocumentHandler<T extends PongoDocument> = ((document: T | null, id: string) => T | null) | ((document: T | null, id: string) => Promise<T | null>);
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/core/typing/index.d.ts
|
|
576
|
+
type MaybePromise<T> = T | PromiseLike<T>;
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region src/core/cache/providers/identityMapCache.d.ts
|
|
579
|
+
declare const identityMapCache: () => PongoCache;
|
|
580
|
+
//#endregion
|
|
581
|
+
//#region src/core/cache/providers/lruCache.d.ts
|
|
582
|
+
type LRUCacheOptions = Omit<LRUCache.Options<string, {
|
|
583
|
+
doc: PongoDocument | null;
|
|
584
|
+
}, unknown>, 'max'> & {
|
|
585
|
+
max?: number;
|
|
586
|
+
};
|
|
587
|
+
declare const lruCache: (options?: LRUCacheOptions) => PongoCache;
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region src/core/cache/providers/noopCache.d.ts
|
|
590
|
+
declare const noopCacheProvider: PongoCache;
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/core/cache/pongoCache.d.ts
|
|
593
|
+
type PongoDocumentCacheKey = `${string}:${string}:${string}`;
|
|
594
|
+
type PongoCacheSetEntry<Doc extends PongoDocument = PongoDocument> = {
|
|
595
|
+
key: PongoDocumentCacheKey;
|
|
596
|
+
value: Doc | null;
|
|
597
|
+
};
|
|
598
|
+
type PongoCacheType<T extends string = string> = `pongo:cache:${T}`;
|
|
599
|
+
interface PongoCache<T extends string = string> {
|
|
600
|
+
cacheType: PongoCacheType<T>;
|
|
601
|
+
get<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey): MaybePromise<Doc | null | undefined>;
|
|
602
|
+
getMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[]): MaybePromise<(Doc | null | undefined)[]>;
|
|
603
|
+
set<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, value: Doc | null): MaybePromise<void>;
|
|
604
|
+
setMany(entries: PongoCacheSetEntry[]): MaybePromise<void>;
|
|
605
|
+
update<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, updater: PongoUpdate<Doc>): MaybePromise<void>;
|
|
606
|
+
updateMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[], updater: PongoUpdate<Doc>): MaybePromise<void>;
|
|
607
|
+
delete(key: PongoDocumentCacheKey): MaybePromise<void>;
|
|
608
|
+
deleteMany(keys: PongoDocumentCacheKey[]): MaybePromise<void>;
|
|
609
|
+
clear(): MaybePromise<void>;
|
|
610
|
+
close(): MaybePromise<void>;
|
|
611
|
+
}
|
|
612
|
+
type CacheHooks = {
|
|
613
|
+
onHit?(key: PongoDocumentCacheKey): void;
|
|
614
|
+
onMiss?(key: PongoDocumentCacheKey): void;
|
|
615
|
+
onEvict?(key: PongoDocumentCacheKey): void;
|
|
616
|
+
onError?(error: unknown, operation: string): void;
|
|
617
|
+
};
|
|
618
|
+
type CacheType = 'in-memory' | 'identity-map';
|
|
619
|
+
type CacheSettings = ({
|
|
620
|
+
type: 'in-memory';
|
|
621
|
+
} & LRUCacheOptions) | {
|
|
622
|
+
type: 'identity-map';
|
|
623
|
+
};
|
|
624
|
+
type CacheConfig = CacheSettings | 'disabled';
|
|
625
|
+
type CacheOptions = {
|
|
626
|
+
skipCache?: boolean;
|
|
627
|
+
};
|
|
628
|
+
declare const pongoCache: (options?: CacheConfig | "disabled" | PongoCache | undefined) => PongoCache;
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/core/cache/pongoCacheWrapper.d.ts
|
|
631
|
+
declare const pongoCacheWrapper: (options: {
|
|
632
|
+
provider: PongoCache;
|
|
633
|
+
hooks?: CacheHooks;
|
|
634
|
+
}) => PongoCache;
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region src/core/cache/transactions/pongoTransactionCache.d.ts
|
|
637
|
+
type PongoTransactionCacheOperationOptions = {
|
|
638
|
+
mainCache: PongoCache;
|
|
639
|
+
};
|
|
640
|
+
interface PongoTransactionCache<T extends string = string> {
|
|
641
|
+
type: PongoCacheType<T>;
|
|
642
|
+
get<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey): MaybePromise<Doc | null | undefined>;
|
|
643
|
+
set(key: PongoDocumentCacheKey, value: PongoDocument | null, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
|
|
644
|
+
update<Doc extends PongoDocument = PongoDocument>(key: PongoDocumentCacheKey, updater: PongoUpdate<Doc>, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
|
|
645
|
+
delete(key: PongoDocumentCacheKey, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
|
|
646
|
+
getMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[]): MaybePromise<(Doc | null | undefined)[]>;
|
|
647
|
+
setMany(entries: PongoCacheSetEntry[], options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
|
|
648
|
+
updateMany<Doc extends PongoDocument = PongoDocument>(keys: PongoDocumentCacheKey[], updater: PongoUpdate<Doc>, options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
|
|
649
|
+
deleteMany(keys: PongoDocumentCacheKey[], options: PongoTransactionCacheOperationOptions): MaybePromise<void>;
|
|
650
|
+
clear(): MaybePromise<void>;
|
|
651
|
+
commit(): Promise<void>;
|
|
652
|
+
}
|
|
653
|
+
declare const pongoTransactionCache: (options?: {
|
|
654
|
+
cache?: PongoCache;
|
|
655
|
+
}) => PongoTransactionCache;
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region src/core/database/pongoDatabaseCache.d.ts
|
|
658
|
+
declare const PongoDatabaseCache: <Database extends PongoDb<DatabaseDriverType> = PongoDb<DatabaseDriverType>, TypedClientSchema extends PongoClientSchema = PongoClientSchema>({
|
|
659
|
+
driver,
|
|
660
|
+
typedSchema
|
|
661
|
+
}: {
|
|
662
|
+
driver: PongoDriver<Database>;
|
|
663
|
+
typedSchema?: TypedClientSchema | undefined;
|
|
664
|
+
}) => {
|
|
665
|
+
getOrCreate: <CollectionsSchema extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema<PongoDocument>>>(createOptions: Omit<PongoDatabaseFactoryOptions<CollectionsSchema>, "schema"> & JSONSerializationOptions & {
|
|
666
|
+
schema?: {
|
|
667
|
+
autoMigration?: MigrationStyle;
|
|
668
|
+
};
|
|
669
|
+
}) => Database;
|
|
670
|
+
all: () => Database[];
|
|
671
|
+
forAll: (func: (db: Database) => Promise<void>) => Promise<void[]>;
|
|
672
|
+
};
|
|
673
|
+
//#endregion
|
|
674
|
+
//#region src/core/database/pongoDb.d.ts
|
|
675
|
+
type PongoDatabaseOptions<DumboType extends Dumbo<DatabaseDriverType, any> = Dumbo<DatabaseDriverType, any>, CollectionsSchema extends Record<string, PongoCollectionSchema> = Record<string, PongoCollectionSchema>> = {
|
|
676
|
+
databaseName: string;
|
|
677
|
+
pool: DumboType;
|
|
678
|
+
serializer: JSONSerializer;
|
|
679
|
+
schemaComponent: PongoDatabaseSchemaComponent<DumboType['driverType']>;
|
|
680
|
+
schema?: {
|
|
681
|
+
autoMigration?: MigrationStyle;
|
|
682
|
+
definition?: PongoDbSchema<CollectionsSchema>;
|
|
683
|
+
} | undefined;
|
|
684
|
+
errors?: {
|
|
685
|
+
throwOnOperationFailures?: boolean;
|
|
686
|
+
} | undefined;
|
|
687
|
+
cache?: CacheConfig | 'disabled' | PongoCache | undefined;
|
|
688
|
+
};
|
|
689
|
+
declare const PongoDatabase: <Database extends AnyPongoDb = AnyPongoDb, DumboType extends Dumbo<Database["driverType"], any> = Dumbo<Database["driverType"], any>>(options: PongoDatabaseOptions<DumboType>) => Database;
|
|
690
|
+
//#endregion
|
|
691
|
+
//#region src/core/errors/index.d.ts
|
|
692
|
+
declare const isNumber: (val: unknown) => val is number;
|
|
693
|
+
declare const isString: (val: unknown) => val is string;
|
|
694
|
+
declare class PongoError extends Error {
|
|
695
|
+
errorCode: number;
|
|
696
|
+
constructor(options?: {
|
|
697
|
+
errorCode: number;
|
|
698
|
+
message?: string;
|
|
699
|
+
} | string | number);
|
|
700
|
+
}
|
|
701
|
+
declare class ConcurrencyError extends PongoError {
|
|
702
|
+
constructor(message?: string);
|
|
703
|
+
}
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region src/core/pongoClient.d.ts
|
|
706
|
+
declare const pongoClient: <DatabaseDriver extends AnyPongoDriver, TypedClientSchema extends PongoClientSchema = PongoClientSchema>(options: PongoClientOptions<DatabaseDriver, TypedClientSchema>) => PongoClient<DatabaseDriver["driverType"], ExtractPongoDatabaseTypeFromDriver<DatabaseDriver>> & PongoClientWithSchema<TypedClientSchema>;
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region src/core/pongoSession.d.ts
|
|
709
|
+
type PongoSessionOptions = {
|
|
710
|
+
explicit?: boolean;
|
|
711
|
+
defaultTransactionOptions: PongoTransactionOptions;
|
|
712
|
+
cache?: CacheConfig | 'disabled' | PongoCache;
|
|
713
|
+
};
|
|
714
|
+
declare const pongoSession: (options?: PongoSessionOptions) => PongoSession;
|
|
715
|
+
//#endregion
|
|
716
|
+
//#region src/core/pongoTransaction.d.ts
|
|
717
|
+
declare const pongoTransaction: (options: PongoTransactionOptions) => PongoDbTransaction;
|
|
718
|
+
//#endregion
|
|
719
|
+
export { HasId as $, AnyPongoDriverOptions as $t, MaybePromise as A, hasOperators as An, PongoSession as At, DOCUMENT_DOES_NOT_EXIST as B, DocumentCommandHandler as Bn, UpdateOneOptions as Bt, PongoCacheType as C, pongoSchema as Cn, PongoFilter as Ct, LRUCacheOptions as D, toDbSchemaMetadata as Dn, PongoInsertOneResult as Dt, noopCacheProvider as E, toClientSchemaMetadata as En, PongoInsertManyResult as Et, AlternativeType as F, PongoCollectionURNType as Fn, RegExpOrString as Ft, DocumentHandler as G, NonPartial as Gn, WithoutIdAndVersion as Gt, DeleteManyOptions as H, DocumentCommandHandlerOptions as Hn, WithIdAndVersion as Ht, AnyPongoDb as I, PongoCollectionSQLBuilder as In, ReplaceManyOptions as It, ExpectedDocumentVersionGeneral as J, expectedVersionPredicate as Jt, EnhancedOmit as K, objectEntries as Kn, WithoutVersion as Kt, BatchHandleOptions as L, PongoCollectionOptions as Ln, ReplaceOneOptions as Lt, $push as M, PongoCollectionSchemaComponent as Mn, PongoUpdate as Mt, $set as N, PongoCollectionSchemaComponentOptions as Nn, PongoUpdateManyResult as Nt, lruCache as O, OperatorMap as On, PongoMigrationOptions as Ot, $unset as P, PongoCollectionURN as Pn, PongoUpdateResult as Pt, HandleOptions as Q, AnyPongoDriver as Qt, CollectionOperationOptions as R, pongoCollection as Rn, RootFilterOperators as Rt, PongoCacheSetEntry as S, PongoSchemaConfig as Sn, PongoDocument as St, pongoCache as T, proxyPongoDbWithSchema as Tn, PongoHandleResult as Tt, DeleteOneOptions as U, getIdsFromIdOnlyFilter as Un, WithVersion as Ut, DOCUMENT_EXISTS as V, DocumentCommandHandlerInput as Vn, WithId as Vt, Document as W, idFromFilter as Wn, WithoutId as Wt, ExpectedVersionPredicate as X, isGeneralExpectedDocumentVersion as Xt, ExpectedDocumentVersionValue as Y, expectedVersionValue as Yt, FindOptions as Z, operationResult as Zt, CacheHooks as _, PongoCollectionSchema as _n, PongoDb as _t, ConcurrencyError as a, PongoDriverRegistry as an, ObjectId as at, CacheType as b, PongoDbSchemaMetadata as bn, PongoDeleteManyResult as bt, isString as c, PongoDatabaseSchemaComponent as cn, OptionalId as ct, PongoDatabaseCache as d, PongoDatabaseURNType as dn, OptionalUnlessRequiredVersion as dt, ExtractPongoDatabaseTypeFromDriver as en, InferIdType as et, PongoTransactionCache as f, CollectionsMap as fn, OptionalVersion as ft, CacheConfig as g, PongoClientWithSchema as gn, PongoDBCollectionOptions as gt, pongoCacheWrapper as h, PongoClientSchemaMetadata as hn, PongoCollection as ht, pongoClient as i, PongoDriverOptions as in, NonObjectIdLikeDocument as it, $inc as j, isOperator as jn, PongoTransactionOptions as jt, identityMapCache as k, QueryOperators as kn, PongoReplaceManyResult as kt, PongoDatabase as l, PongoDatabaseSchemaComponentOptions as ln, OptionalUnlessRequiredId as lt, pongoTransactionCache as m, PongoClientSchema as mn, PongoClientOptions as mt, PongoSessionOptions as n, PongoDatabaseFactoryOptions as nn, InsertOneOptions as nt, PongoError as o, pongoDriverRegistry as on, ObjectIdLike as ot, PongoTransactionCacheOperationOptions as p, DBsMap as pn, PongoClient as pt, ExpectedDocumentVersion as q, expectedVersion as qt, pongoSession as r, PongoDriver as rn, NO_CONCURRENCY_CHECK as rt, isNumber as s, PongoDatabaseSQLBuilder as sn, OperationResult as st, pongoTransaction as t, ExtractPongoDriverOptions as tn, InsertManyOptions as tt, PongoDatabaseOptions as u, PongoDatabaseURN as un, OptionalUnlessRequiredIdAndVersion as ut, CacheOptions as v, PongoCollectionSchemaMetadata as vn, PongoDbOptions as vt, PongoDocumentCacheKey as w, proxyClientWithSchema as wn, PongoFilterOperator as wt, PongoCache as x, PongoDbWithSchema as xn, PongoDeleteResult as xt, CacheSettings as y, PongoDbSchema as yn, PongoDbTransaction as yt, Condition as z, transactionExecutorOrDefault as zn, UpdateManyOptions as zt };
|
|
720
|
+
//# sourceMappingURL=index-r7V4paf_.d.ts.map
|