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