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