@orion-js/mongodb 4.0.0-next.3 → 4.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +326 -8807
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -65
- package/dist/index.d.ts +72 -65
- package/dist/index.js +292 -8798
- package/dist/index.js.map +1 -1
- package/package.json +13 -11
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as MongoDB from 'mongodb';
|
|
2
|
-
import { MongoClient, Db } from 'mongodb';
|
|
3
|
-
|
|
4
|
-
import {
|
|
2
|
+
import { MongoClient, Db, EnhancedOmit } from 'mongodb';
|
|
3
|
+
export { MongoDB };
|
|
4
|
+
import { Schema, StrictInferSchemaType, FieldType } from '@orion-js/schema';
|
|
5
5
|
|
|
6
6
|
interface OrionMongoClient {
|
|
7
7
|
client: MongoClient;
|
|
@@ -10,33 +10,29 @@ interface OrionMongoClient {
|
|
|
10
10
|
dbName: string;
|
|
11
11
|
connectionPromise: Promise<MongoClient>;
|
|
12
12
|
connectionName: string;
|
|
13
|
+
startConnection: () => Promise<MongoClient>;
|
|
13
14
|
}
|
|
14
15
|
interface OrionMongoConnectionsMap {
|
|
15
16
|
[key: string]: OrionMongoClient;
|
|
16
17
|
}
|
|
17
18
|
declare const connections: OrionMongoConnectionsMap;
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
declare const allConnectionPromises: any[];
|
|
21
|
+
interface MongoConnectOptions {
|
|
22
|
+
name: string;
|
|
23
|
+
uri?: string;
|
|
24
|
+
}
|
|
25
|
+
declare const getMongoConnection: ({ name, uri }: MongoConnectOptions) => OrionMongoClient;
|
|
26
|
+
|
|
27
|
+
declare type InferIdType<TSchema> = TSchema extends {
|
|
28
|
+
_id: infer IdType;
|
|
29
|
+
} ? Record<any, never> extends IdType ? never : IdType : TSchema extends {
|
|
30
|
+
_id?: infer IdType;
|
|
31
|
+
} ? unknown extends IdType ? string : IdType : string;
|
|
32
|
+
type DocumentWithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
33
|
+
_id: InferIdType<TSchema>;
|
|
32
34
|
};
|
|
33
|
-
type
|
|
34
|
-
type ModelToDocumentType<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
|
|
35
|
-
type ModelToDocumentTypeWithId<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
|
|
36
|
-
type ModelToDocumentTypeWithoutId<ModelClass extends ModelClassBase> = DocumentWithoutId<ModelToDocumentType<ModelClass>>;
|
|
37
|
-
type ModelToDocumentTypeWithIdOptional<ModelClass extends ModelClassBase> = DocumentWithIdOptional<ModelToDocumentType<ModelClass>>;
|
|
38
|
-
type ModelToMongoSelector<ModelClass extends ModelClassBase> = MongoSelector<ModelToDocumentType<ModelClass>>;
|
|
39
|
-
type ModelToUpdateFilter<ModelClass extends ModelClassBase> = MongoDB.UpdateFilter<ModelToDocumentTypeWithoutId<ModelClass>> | Partial<ModelToDocumentTypeWithoutId<ModelClass>>;
|
|
35
|
+
type ModelClassBase = DocumentWithId<MongoDB.Document>;
|
|
40
36
|
interface CollectionIndex {
|
|
41
37
|
keys: MongoDB.IndexSpecification;
|
|
42
38
|
options?: MongoDB.CreateIndexesOptions;
|
|
@@ -63,13 +59,7 @@ declare namespace DataLoader {
|
|
|
63
59
|
export type LoadById<ModelClass extends ModelClassBase> = (id: ModelClass['_id']) => Promise<ModelClass>;
|
|
64
60
|
export { };
|
|
65
61
|
}
|
|
66
|
-
type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass
|
|
67
|
-
_id?: ModelClass['_id'];
|
|
68
|
-
} | {
|
|
69
|
-
_id?: {
|
|
70
|
-
$in: ModelClass['_id'][];
|
|
71
|
-
};
|
|
72
|
-
});
|
|
62
|
+
type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass>;
|
|
73
63
|
type MongoSelector<ModelClass extends ModelClassBase = ModelClassBase> = ModelClass['_id'] | MongoFilter<ModelClass>;
|
|
74
64
|
interface FindCursor<ModelClass> extends MongoDB.FindCursor {
|
|
75
65
|
toArray: () => Promise<Array<ModelClass>>;
|
|
@@ -90,19 +80,20 @@ interface InsertOptions {
|
|
|
90
80
|
mongoOptions?: MongoDB.InsertOneOptions;
|
|
91
81
|
}
|
|
92
82
|
type InitItem<ModelClass extends ModelClassBase> = (doc: any) => ModelClass;
|
|
93
|
-
type
|
|
94
|
-
type
|
|
95
|
-
type
|
|
96
|
-
type
|
|
97
|
-
type
|
|
98
|
-
type
|
|
99
|
-
type
|
|
100
|
-
type
|
|
83
|
+
type ModelToMongoSelector<ModelClass extends ModelClassBase> = MongoDB.Filter<ModelClass> | DocumentWithId<ModelClass>['_id'];
|
|
84
|
+
type FindOne<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions<ModelClass>) => Promise<ModelClass>;
|
|
85
|
+
type Find<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions<ModelClass>) => FindCursor<ModelClass>;
|
|
86
|
+
type FindOneAndUpdate<ModelClass extends ModelClassBase> = <TSelector extends ModelToMongoSelector<ModelClass>, TFilter extends MongoDB.UpdateFilter<ModelClass>, TOptions extends FindOneAndUpdateUpdateOptions>(selector: TSelector, modifier: TFilter, options?: TOptions) => ReturnType<MongoDB.Collection<ModelClass>['findOneAndUpdate']>;
|
|
87
|
+
type UpdateAndFind<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
|
|
88
|
+
type UpdateItem<ModelClass extends ModelClassBase> = (item: ModelClass, modifier: MongoDB.UpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<void>;
|
|
89
|
+
type InsertOne<ModelClass extends ModelClassBase> = (doc: MongoDB.OptionalId<ModelClass>, options?: InsertOptions) => Promise<ModelClass['_id']>;
|
|
90
|
+
type InsertMany<ModelClass extends ModelClassBase> = (doc: Array<MongoDB.OptionalId<ModelClass>>, options?: InsertOptions) => Promise<Array<ModelClass['_id']>>;
|
|
91
|
+
type InsertAndFind<ModelClass extends ModelClassBase> = (doc: MongoDB.OptionalId<ModelClass>, options?: InsertOptions) => Promise<ModelClass>;
|
|
101
92
|
type DeleteMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
102
93
|
type DeleteOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
103
|
-
type UpdateOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier:
|
|
104
|
-
type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier:
|
|
105
|
-
type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier:
|
|
94
|
+
type UpdateOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
95
|
+
type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult | MongoDB.Document>;
|
|
96
|
+
type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
106
97
|
interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
107
98
|
/**
|
|
108
99
|
* The name of the collection on the Mongo Database
|
|
@@ -117,11 +108,7 @@ interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClass
|
|
|
117
108
|
/**
|
|
118
109
|
* The schema used for cleaning and validation of the documents
|
|
119
110
|
*/
|
|
120
|
-
schema?:
|
|
121
|
-
/**
|
|
122
|
-
* @deprecated Use schema instead. If you use model, all items will be initialized with the model to add resolvers (which are also deprecated)
|
|
123
|
-
*/
|
|
124
|
-
model?: any;
|
|
111
|
+
schema?: Schema;
|
|
125
112
|
/**
|
|
126
113
|
* The indexes to use
|
|
127
114
|
*/
|
|
@@ -135,24 +122,30 @@ interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClass
|
|
|
135
122
|
*/
|
|
136
123
|
idPrefix?: ModelClass['_id'];
|
|
137
124
|
}
|
|
138
|
-
type EstimatedDocumentCount<
|
|
125
|
+
type EstimatedDocumentCount<_ModelClass extends ModelClassBase> = (options?: MongoDB.EstimatedDocumentCountOptions) => Promise<number>;
|
|
139
126
|
type CountDocuments<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.CountDocumentsOptions) => Promise<number>;
|
|
140
|
-
type
|
|
127
|
+
type SchemaWithRequiredId = Schema & {
|
|
128
|
+
_id: {
|
|
129
|
+
type: any;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
type InferSchemaTypeWithId<TSchema extends SchemaWithRequiredId> = DocumentWithId<StrictInferSchemaType<TSchema>>;
|
|
133
|
+
type CreateCollectionOptionsWithSchemaType<T extends SchemaWithRequiredId> = {
|
|
134
|
+
schema: T;
|
|
135
|
+
} & Omit<CreateCollectionOptions<InferSchemaTypeWithId<T>>, 'schema'>;
|
|
136
|
+
type CreateCollectionOptionsWithTypedModel<T extends InstanceType<any>> = {
|
|
137
|
+
schema: any;
|
|
138
|
+
} & Omit<CreateCollectionOptions<DocumentWithId<T>>, 'schema'>;
|
|
141
139
|
declare class Collection<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
142
140
|
name: string;
|
|
143
141
|
connectionName?: string;
|
|
144
142
|
schema?: Schema;
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use schema instead. If you use model, all items will be initialized with the model to add resolvers (which are also deprecated)
|
|
147
|
-
*/
|
|
148
|
-
model?: Model;
|
|
149
143
|
indexes: Array<CollectionIndex>;
|
|
150
144
|
generateId: () => ModelClass['_id'];
|
|
151
145
|
getSchema: () => Schema;
|
|
152
146
|
db: MongoDB.Db;
|
|
153
147
|
client: OrionMongoClient;
|
|
154
148
|
rawCollection: MongoDB.Collection<ModelClass>;
|
|
155
|
-
initItem: InitItem<ModelClass>;
|
|
156
149
|
findOne: FindOne<ModelClass>;
|
|
157
150
|
find: Find<ModelClass>;
|
|
158
151
|
insertOne: InsertOne<ModelClass>;
|
|
@@ -185,22 +178,36 @@ declare class Collection<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
|
185
178
|
createIndexes: () => Promise<string[]>;
|
|
186
179
|
createIndexesPromise: Promise<string[]>;
|
|
187
180
|
connectionPromise: Promise<MongoDB.MongoClient>;
|
|
181
|
+
startConnection: () => Promise<MongoDB.MongoClient>;
|
|
188
182
|
}
|
|
189
183
|
type DistinctDocumentId<DistinctId extends string> = string & {
|
|
190
184
|
__TYPE__: `DistinctDocumentId<${DistinctId}>`;
|
|
191
185
|
};
|
|
186
|
+
type TypedId<TPrefix extends string> = `${TPrefix}-${string}`;
|
|
187
|
+
/**
|
|
188
|
+
* Use this function to create unique types for the ids of mongodb documents.
|
|
189
|
+
* You should set it as the type of the _id field in your schema.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* type UserId = TypedId<'user'>
|
|
194
|
+
*
|
|
195
|
+
* const userSchema = {
|
|
196
|
+
* _id: {
|
|
197
|
+
* type: TypedId('user'),
|
|
198
|
+
* },
|
|
199
|
+
* }
|
|
200
|
+
*
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function typedId<const TPrefix extends string>(prefix: TPrefix): FieldType<TypedId<TPrefix>>;
|
|
192
204
|
|
|
193
|
-
declare
|
|
194
|
-
declare
|
|
205
|
+
declare function Repository(): (target: any, context: ClassDecoratorContext<any>) => void;
|
|
206
|
+
declare function MongoCollection<ModelClass extends ModelClassBase = ModelClassBase>(options: CreateCollectionOptions<ModelClass>): (_target: any, context: ClassFieldDecoratorContext) => void;
|
|
195
207
|
|
|
196
|
-
declare const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
declare const getMongoConnection: ({ name, uri }: MongoConnectOptions) => OrionMongoClient;
|
|
202
|
-
|
|
203
|
-
declare function MongoCollection<ModelClass extends ModelClassBase = ModelClassBase>(options: CreateCollectionOptions<ModelClass>): (object: any, propertyName: string, index?: number) => void;
|
|
204
|
-
declare function Repository(): ClassDecorator;
|
|
208
|
+
declare const createIndexesPromises: any[];
|
|
209
|
+
declare function createCollection<T extends SchemaWithRequiredId>(options: CreateCollectionOptionsWithSchemaType<T>): Collection<InferSchemaTypeWithId<T>>;
|
|
210
|
+
declare function createCollection<T extends InstanceType<any>>(options: CreateCollectionOptionsWithTypedModel<T>): Collection<DocumentWithId<T>>;
|
|
211
|
+
declare function createCollection<T extends ModelClassBase>(options: CreateCollectionOptions<T>): Collection<T>;
|
|
205
212
|
|
|
206
|
-
export { Collection, type CollectionIndex, type CountDocuments, type
|
|
213
|
+
export { Collection, type CollectionIndex, type CountDocuments, type CreateCollectionOptions, type CreateCollectionOptionsWithSchemaType, type CreateCollectionOptionsWithTypedModel, DataLoader, type DeleteMany, type DeleteOne, type DistinctDocumentId, type DocumentWithId, type EstimatedDocumentCount, type Find, type FindCursor, type FindOne, type FindOneAndUpdate, type FindOneAndUpdateUpdateOptions, type InferIdType, type InferSchemaTypeWithId, type InitItem, type InsertAndFind, type InsertMany, type InsertOne, type InsertOptions, type ModelClassBase, type ModelToMongoSelector, MongoCollection, type MongoFilter, type MongoSelector, Repository, type SchemaWithRequiredId, type TypedId, type UpdateAndFind, type UpdateItem, type UpdateMany, type UpdateOne, type UpdateOptions, type Upsert, allConnectionPromises, connections, createCollection, createIndexesPromises, getMongoConnection, typedId };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as MongoDB from 'mongodb';
|
|
2
|
-
import { MongoClient, Db } from 'mongodb';
|
|
3
|
-
|
|
4
|
-
import {
|
|
2
|
+
import { MongoClient, Db, EnhancedOmit } from 'mongodb';
|
|
3
|
+
export { MongoDB };
|
|
4
|
+
import { Schema, StrictInferSchemaType, FieldType } from '@orion-js/schema';
|
|
5
5
|
|
|
6
6
|
interface OrionMongoClient {
|
|
7
7
|
client: MongoClient;
|
|
@@ -10,33 +10,29 @@ interface OrionMongoClient {
|
|
|
10
10
|
dbName: string;
|
|
11
11
|
connectionPromise: Promise<MongoClient>;
|
|
12
12
|
connectionName: string;
|
|
13
|
+
startConnection: () => Promise<MongoClient>;
|
|
13
14
|
}
|
|
14
15
|
interface OrionMongoConnectionsMap {
|
|
15
16
|
[key: string]: OrionMongoClient;
|
|
16
17
|
}
|
|
17
18
|
declare const connections: OrionMongoConnectionsMap;
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
declare const allConnectionPromises: any[];
|
|
21
|
+
interface MongoConnectOptions {
|
|
22
|
+
name: string;
|
|
23
|
+
uri?: string;
|
|
24
|
+
}
|
|
25
|
+
declare const getMongoConnection: ({ name, uri }: MongoConnectOptions) => OrionMongoClient;
|
|
26
|
+
|
|
27
|
+
declare type InferIdType<TSchema> = TSchema extends {
|
|
28
|
+
_id: infer IdType;
|
|
29
|
+
} ? Record<any, never> extends IdType ? never : IdType : TSchema extends {
|
|
30
|
+
_id?: infer IdType;
|
|
31
|
+
} ? unknown extends IdType ? string : IdType : string;
|
|
32
|
+
type DocumentWithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
33
|
+
_id: InferIdType<TSchema>;
|
|
32
34
|
};
|
|
33
|
-
type
|
|
34
|
-
type ModelToDocumentType<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
|
|
35
|
-
type ModelToDocumentTypeWithId<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
|
|
36
|
-
type ModelToDocumentTypeWithoutId<ModelClass extends ModelClassBase> = DocumentWithoutId<ModelToDocumentType<ModelClass>>;
|
|
37
|
-
type ModelToDocumentTypeWithIdOptional<ModelClass extends ModelClassBase> = DocumentWithIdOptional<ModelToDocumentType<ModelClass>>;
|
|
38
|
-
type ModelToMongoSelector<ModelClass extends ModelClassBase> = MongoSelector<ModelToDocumentType<ModelClass>>;
|
|
39
|
-
type ModelToUpdateFilter<ModelClass extends ModelClassBase> = MongoDB.UpdateFilter<ModelToDocumentTypeWithoutId<ModelClass>> | Partial<ModelToDocumentTypeWithoutId<ModelClass>>;
|
|
35
|
+
type ModelClassBase = DocumentWithId<MongoDB.Document>;
|
|
40
36
|
interface CollectionIndex {
|
|
41
37
|
keys: MongoDB.IndexSpecification;
|
|
42
38
|
options?: MongoDB.CreateIndexesOptions;
|
|
@@ -63,13 +59,7 @@ declare namespace DataLoader {
|
|
|
63
59
|
export type LoadById<ModelClass extends ModelClassBase> = (id: ModelClass['_id']) => Promise<ModelClass>;
|
|
64
60
|
export { };
|
|
65
61
|
}
|
|
66
|
-
type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass
|
|
67
|
-
_id?: ModelClass['_id'];
|
|
68
|
-
} | {
|
|
69
|
-
_id?: {
|
|
70
|
-
$in: ModelClass['_id'][];
|
|
71
|
-
};
|
|
72
|
-
});
|
|
62
|
+
type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass>;
|
|
73
63
|
type MongoSelector<ModelClass extends ModelClassBase = ModelClassBase> = ModelClass['_id'] | MongoFilter<ModelClass>;
|
|
74
64
|
interface FindCursor<ModelClass> extends MongoDB.FindCursor {
|
|
75
65
|
toArray: () => Promise<Array<ModelClass>>;
|
|
@@ -90,19 +80,20 @@ interface InsertOptions {
|
|
|
90
80
|
mongoOptions?: MongoDB.InsertOneOptions;
|
|
91
81
|
}
|
|
92
82
|
type InitItem<ModelClass extends ModelClassBase> = (doc: any) => ModelClass;
|
|
93
|
-
type
|
|
94
|
-
type
|
|
95
|
-
type
|
|
96
|
-
type
|
|
97
|
-
type
|
|
98
|
-
type
|
|
99
|
-
type
|
|
100
|
-
type
|
|
83
|
+
type ModelToMongoSelector<ModelClass extends ModelClassBase> = MongoDB.Filter<ModelClass> | DocumentWithId<ModelClass>['_id'];
|
|
84
|
+
type FindOne<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions<ModelClass>) => Promise<ModelClass>;
|
|
85
|
+
type Find<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions<ModelClass>) => FindCursor<ModelClass>;
|
|
86
|
+
type FindOneAndUpdate<ModelClass extends ModelClassBase> = <TSelector extends ModelToMongoSelector<ModelClass>, TFilter extends MongoDB.UpdateFilter<ModelClass>, TOptions extends FindOneAndUpdateUpdateOptions>(selector: TSelector, modifier: TFilter, options?: TOptions) => ReturnType<MongoDB.Collection<ModelClass>['findOneAndUpdate']>;
|
|
87
|
+
type UpdateAndFind<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
|
|
88
|
+
type UpdateItem<ModelClass extends ModelClassBase> = (item: ModelClass, modifier: MongoDB.UpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<void>;
|
|
89
|
+
type InsertOne<ModelClass extends ModelClassBase> = (doc: MongoDB.OptionalId<ModelClass>, options?: InsertOptions) => Promise<ModelClass['_id']>;
|
|
90
|
+
type InsertMany<ModelClass extends ModelClassBase> = (doc: Array<MongoDB.OptionalId<ModelClass>>, options?: InsertOptions) => Promise<Array<ModelClass['_id']>>;
|
|
91
|
+
type InsertAndFind<ModelClass extends ModelClassBase> = (doc: MongoDB.OptionalId<ModelClass>, options?: InsertOptions) => Promise<ModelClass>;
|
|
101
92
|
type DeleteMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
102
93
|
type DeleteOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
|
|
103
|
-
type UpdateOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier:
|
|
104
|
-
type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier:
|
|
105
|
-
type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier:
|
|
94
|
+
type UpdateOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
95
|
+
type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult | MongoDB.Document>;
|
|
96
|
+
type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: MongoDB.UpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
|
|
106
97
|
interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
107
98
|
/**
|
|
108
99
|
* The name of the collection on the Mongo Database
|
|
@@ -117,11 +108,7 @@ interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClass
|
|
|
117
108
|
/**
|
|
118
109
|
* The schema used for cleaning and validation of the documents
|
|
119
110
|
*/
|
|
120
|
-
schema?:
|
|
121
|
-
/**
|
|
122
|
-
* @deprecated Use schema instead. If you use model, all items will be initialized with the model to add resolvers (which are also deprecated)
|
|
123
|
-
*/
|
|
124
|
-
model?: any;
|
|
111
|
+
schema?: Schema;
|
|
125
112
|
/**
|
|
126
113
|
* The indexes to use
|
|
127
114
|
*/
|
|
@@ -135,24 +122,30 @@ interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClass
|
|
|
135
122
|
*/
|
|
136
123
|
idPrefix?: ModelClass['_id'];
|
|
137
124
|
}
|
|
138
|
-
type EstimatedDocumentCount<
|
|
125
|
+
type EstimatedDocumentCount<_ModelClass extends ModelClassBase> = (options?: MongoDB.EstimatedDocumentCountOptions) => Promise<number>;
|
|
139
126
|
type CountDocuments<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.CountDocumentsOptions) => Promise<number>;
|
|
140
|
-
type
|
|
127
|
+
type SchemaWithRequiredId = Schema & {
|
|
128
|
+
_id: {
|
|
129
|
+
type: any;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
type InferSchemaTypeWithId<TSchema extends SchemaWithRequiredId> = DocumentWithId<StrictInferSchemaType<TSchema>>;
|
|
133
|
+
type CreateCollectionOptionsWithSchemaType<T extends SchemaWithRequiredId> = {
|
|
134
|
+
schema: T;
|
|
135
|
+
} & Omit<CreateCollectionOptions<InferSchemaTypeWithId<T>>, 'schema'>;
|
|
136
|
+
type CreateCollectionOptionsWithTypedModel<T extends InstanceType<any>> = {
|
|
137
|
+
schema: any;
|
|
138
|
+
} & Omit<CreateCollectionOptions<DocumentWithId<T>>, 'schema'>;
|
|
141
139
|
declare class Collection<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
142
140
|
name: string;
|
|
143
141
|
connectionName?: string;
|
|
144
142
|
schema?: Schema;
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use schema instead. If you use model, all items will be initialized with the model to add resolvers (which are also deprecated)
|
|
147
|
-
*/
|
|
148
|
-
model?: Model;
|
|
149
143
|
indexes: Array<CollectionIndex>;
|
|
150
144
|
generateId: () => ModelClass['_id'];
|
|
151
145
|
getSchema: () => Schema;
|
|
152
146
|
db: MongoDB.Db;
|
|
153
147
|
client: OrionMongoClient;
|
|
154
148
|
rawCollection: MongoDB.Collection<ModelClass>;
|
|
155
|
-
initItem: InitItem<ModelClass>;
|
|
156
149
|
findOne: FindOne<ModelClass>;
|
|
157
150
|
find: Find<ModelClass>;
|
|
158
151
|
insertOne: InsertOne<ModelClass>;
|
|
@@ -185,22 +178,36 @@ declare class Collection<ModelClass extends ModelClassBase = ModelClassBase> {
|
|
|
185
178
|
createIndexes: () => Promise<string[]>;
|
|
186
179
|
createIndexesPromise: Promise<string[]>;
|
|
187
180
|
connectionPromise: Promise<MongoDB.MongoClient>;
|
|
181
|
+
startConnection: () => Promise<MongoDB.MongoClient>;
|
|
188
182
|
}
|
|
189
183
|
type DistinctDocumentId<DistinctId extends string> = string & {
|
|
190
184
|
__TYPE__: `DistinctDocumentId<${DistinctId}>`;
|
|
191
185
|
};
|
|
186
|
+
type TypedId<TPrefix extends string> = `${TPrefix}-${string}`;
|
|
187
|
+
/**
|
|
188
|
+
* Use this function to create unique types for the ids of mongodb documents.
|
|
189
|
+
* You should set it as the type of the _id field in your schema.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* type UserId = TypedId<'user'>
|
|
194
|
+
*
|
|
195
|
+
* const userSchema = {
|
|
196
|
+
* _id: {
|
|
197
|
+
* type: TypedId('user'),
|
|
198
|
+
* },
|
|
199
|
+
* }
|
|
200
|
+
*
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function typedId<const TPrefix extends string>(prefix: TPrefix): FieldType<TypedId<TPrefix>>;
|
|
192
204
|
|
|
193
|
-
declare
|
|
194
|
-
declare
|
|
205
|
+
declare function Repository(): (target: any, context: ClassDecoratorContext<any>) => void;
|
|
206
|
+
declare function MongoCollection<ModelClass extends ModelClassBase = ModelClassBase>(options: CreateCollectionOptions<ModelClass>): (_target: any, context: ClassFieldDecoratorContext) => void;
|
|
195
207
|
|
|
196
|
-
declare const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
declare const getMongoConnection: ({ name, uri }: MongoConnectOptions) => OrionMongoClient;
|
|
202
|
-
|
|
203
|
-
declare function MongoCollection<ModelClass extends ModelClassBase = ModelClassBase>(options: CreateCollectionOptions<ModelClass>): (object: any, propertyName: string, index?: number) => void;
|
|
204
|
-
declare function Repository(): ClassDecorator;
|
|
208
|
+
declare const createIndexesPromises: any[];
|
|
209
|
+
declare function createCollection<T extends SchemaWithRequiredId>(options: CreateCollectionOptionsWithSchemaType<T>): Collection<InferSchemaTypeWithId<T>>;
|
|
210
|
+
declare function createCollection<T extends InstanceType<any>>(options: CreateCollectionOptionsWithTypedModel<T>): Collection<DocumentWithId<T>>;
|
|
211
|
+
declare function createCollection<T extends ModelClassBase>(options: CreateCollectionOptions<T>): Collection<T>;
|
|
205
212
|
|
|
206
|
-
export { Collection, type CollectionIndex, type CountDocuments, type
|
|
213
|
+
export { Collection, type CollectionIndex, type CountDocuments, type CreateCollectionOptions, type CreateCollectionOptionsWithSchemaType, type CreateCollectionOptionsWithTypedModel, DataLoader, type DeleteMany, type DeleteOne, type DistinctDocumentId, type DocumentWithId, type EstimatedDocumentCount, type Find, type FindCursor, type FindOne, type FindOneAndUpdate, type FindOneAndUpdateUpdateOptions, type InferIdType, type InferSchemaTypeWithId, type InitItem, type InsertAndFind, type InsertMany, type InsertOne, type InsertOptions, type ModelClassBase, type ModelToMongoSelector, MongoCollection, type MongoFilter, type MongoSelector, Repository, type SchemaWithRequiredId, type TypedId, type UpdateAndFind, type UpdateItem, type UpdateMany, type UpdateOne, type UpdateOptions, type Upsert, allConnectionPromises, connections, createCollection, createIndexesPromises, getMongoConnection, typedId };
|