@orion-js/mongodb 3.11.15 → 4.0.0-alpha.2

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.
Files changed (172) hide show
  1. package/README.md +15 -0
  2. package/dist/index.cjs +81969 -0
  3. package/dist/index.d.ts +582 -0
  4. package/dist/index.js +81943 -0
  5. package/package.json +29 -27
  6. package/LICENSE +0 -21
  7. package/lib/connect/connections.d.ts +0 -13
  8. package/lib/connect/connections.js +0 -4
  9. package/lib/connect/getDBName.d.ts +0 -1
  10. package/lib/connect/getDBName.js +0 -23
  11. package/lib/connect/getMongoConnection.d.ts +0 -8
  12. package/lib/connect/getMongoConnection.js +0 -47
  13. package/lib/connect/getMongoConnection.test.d.ts +0 -1
  14. package/lib/connect/getMongoConnection.test.js +0 -43
  15. package/lib/connect/getMongoURLFromEnv.d.ts +0 -1
  16. package/lib/connect/getMongoURLFromEnv.js +0 -21
  17. package/lib/connect/index.d.ts +0 -4
  18. package/lib/connect/index.js +0 -8
  19. package/lib/createCollection/createIndexPromisesTest.d.ts +0 -1
  20. package/lib/createCollection/createIndexPromisesTest.js +0 -12
  21. package/lib/createCollection/createIndexes.d.ts +0 -3
  22. package/lib/createCollection/createIndexes.js +0 -67
  23. package/lib/createCollection/createIndexes.test.d.ts +0 -1
  24. package/lib/createCollection/createIndexes.test.js +0 -91
  25. package/lib/createCollection/createIndexesPromise.test.d.ts +0 -1
  26. package/lib/createCollection/createIndexesPromise.test.js +0 -32
  27. package/lib/createCollection/generateId.d.ts +0 -3
  28. package/lib/createCollection/generateId.js +0 -25
  29. package/lib/createCollection/generateId.test.d.ts +0 -1
  30. package/lib/createCollection/generateId.test.js +0 -108
  31. package/lib/createCollection/getMethods/aggregate.test.d.ts +0 -1
  32. package/lib/createCollection/getMethods/aggregate.test.js +0 -20
  33. package/lib/createCollection/getMethods/cleanModifier.d.ts +0 -4
  34. package/lib/createCollection/getMethods/cleanModifier.js +0 -75
  35. package/lib/createCollection/getMethods/cleanModifier.test.d.ts +0 -1
  36. package/lib/createCollection/getMethods/cleanModifier.test.js +0 -186
  37. package/lib/createCollection/getMethods/countDocuments.d.ts +0 -2
  38. package/lib/createCollection/getMethods/countDocuments.js +0 -16
  39. package/lib/createCollection/getMethods/countDocuments.test.d.ts +0 -1
  40. package/lib/createCollection/getMethods/countDocuments.test.js +0 -21
  41. package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.d.ts +0 -9
  42. package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.js +0 -25
  43. package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.test.d.ts +0 -1
  44. package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.test.js +0 -37
  45. package/lib/createCollection/getMethods/dataLoader/dataLoad/index.d.ts +0 -9
  46. package/lib/createCollection/getMethods/dataLoader/dataLoad/index.js +0 -21
  47. package/lib/createCollection/getMethods/dataLoader/index.d.ts +0 -5
  48. package/lib/createCollection/getMethods/dataLoader/index.js +0 -14
  49. package/lib/createCollection/getMethods/dataLoader/loadById.d.ts +0 -2
  50. package/lib/createCollection/getMethods/dataLoader/loadById.js +0 -13
  51. package/lib/createCollection/getMethods/dataLoader/loadById.test.d.ts +0 -1
  52. package/lib/createCollection/getMethods/dataLoader/loadById.test.js +0 -23
  53. package/lib/createCollection/getMethods/dataLoader/loadData.d.ts +0 -2
  54. package/lib/createCollection/getMethods/dataLoader/loadData.js +0 -49
  55. package/lib/createCollection/getMethods/dataLoader/loadMany.d.ts +0 -2
  56. package/lib/createCollection/getMethods/dataLoader/loadMany.js +0 -10
  57. package/lib/createCollection/getMethods/dataLoader/loadMany.test.d.ts +0 -1
  58. package/lib/createCollection/getMethods/dataLoader/loadMany.test.js +0 -85
  59. package/lib/createCollection/getMethods/dataLoader/loadOne.d.ts +0 -2
  60. package/lib/createCollection/getMethods/dataLoader/loadOne.js +0 -10
  61. package/lib/createCollection/getMethods/dataLoader/loadOne.test.d.ts +0 -1
  62. package/lib/createCollection/getMethods/dataLoader/loadOne.test.js +0 -76
  63. package/lib/createCollection/getMethods/deleteMany.d.ts +0 -2
  64. package/lib/createCollection/getMethods/deleteMany.js +0 -16
  65. package/lib/createCollection/getMethods/deleteOne.d.ts +0 -2
  66. package/lib/createCollection/getMethods/deleteOne.js +0 -16
  67. package/lib/createCollection/getMethods/estimatedDocumentCount.d.ts +0 -3
  68. package/lib/createCollection/getMethods/estimatedDocumentCount.js +0 -10
  69. package/lib/createCollection/getMethods/estimatedDocumentCount.test.d.ts +0 -1
  70. package/lib/createCollection/getMethods/estimatedDocumentCount.test.js +0 -15
  71. package/lib/createCollection/getMethods/find.d.ts +0 -2
  72. package/lib/createCollection/getMethods/find.js +0 -21
  73. package/lib/createCollection/getMethods/findOne.d.ts +0 -2
  74. package/lib/createCollection/getMethods/findOne.js +0 -18
  75. package/lib/createCollection/getMethods/findOneAndUpdate.d.ts +0 -3
  76. package/lib/createCollection/getMethods/findOneAndUpdate.js +0 -29
  77. package/lib/createCollection/getMethods/findOneAndUpdate.test.d.ts +0 -1
  78. package/lib/createCollection/getMethods/findOneAndUpdate.test.js +0 -15
  79. package/lib/createCollection/getMethods/getSelector.d.ts +0 -3
  80. package/lib/createCollection/getMethods/getSelector.js +0 -21
  81. package/lib/createCollection/getMethods/getSelector.test.d.ts +0 -1
  82. package/lib/createCollection/getMethods/getSelector.test.js +0 -46
  83. package/lib/createCollection/getMethods/index.d.ts +0 -16
  84. package/lib/createCollection/getMethods/index.js +0 -36
  85. package/lib/createCollection/getMethods/insertAndFind.d.ts +0 -3
  86. package/lib/createCollection/getMethods/insertAndFind.js +0 -31
  87. package/lib/createCollection/getMethods/insertAndFind.test.d.ts +0 -1
  88. package/lib/createCollection/getMethods/insertAndFind.test.js +0 -50
  89. package/lib/createCollection/getMethods/insertMany.d.ts +0 -3
  90. package/lib/createCollection/getMethods/insertMany.js +0 -36
  91. package/lib/createCollection/getMethods/insertMany.test.d.ts +0 -1
  92. package/lib/createCollection/getMethods/insertMany.test.js +0 -66
  93. package/lib/createCollection/getMethods/insertOne.d.ts +0 -3
  94. package/lib/createCollection/getMethods/insertOne.js +0 -31
  95. package/lib/createCollection/getMethods/insertOne.test.d.ts +0 -1
  96. package/lib/createCollection/getMethods/insertOne.test.js +0 -104
  97. package/lib/createCollection/getMethods/update.test.d.ts +0 -1
  98. package/lib/createCollection/getMethods/update.test.js +0 -287
  99. package/lib/createCollection/getMethods/updateAndFind.d.ts +0 -3
  100. package/lib/createCollection/getMethods/updateAndFind.js +0 -18
  101. package/lib/createCollection/getMethods/updateAndFind.test.d.ts +0 -1
  102. package/lib/createCollection/getMethods/updateAndFind.test.js +0 -38
  103. package/lib/createCollection/getMethods/updateItem.d.ts +0 -2
  104. package/lib/createCollection/getMethods/updateItem.js +0 -19
  105. package/lib/createCollection/getMethods/updateItem.test.d.ts +0 -1
  106. package/lib/createCollection/getMethods/updateItem.test.js +0 -38
  107. package/lib/createCollection/getMethods/updateMany.d.ts +0 -3
  108. package/lib/createCollection/getMethods/updateMany.js +0 -30
  109. package/lib/createCollection/getMethods/updateOne.d.ts +0 -3
  110. package/lib/createCollection/getMethods/updateOne.js +0 -30
  111. package/lib/createCollection/getMethods/upsert.d.ts +0 -3
  112. package/lib/createCollection/getMethods/upsert.js +0 -31
  113. package/lib/createCollection/getMethods/upsert.test.d.ts +0 -1
  114. package/lib/createCollection/getMethods/upsert.test.js +0 -92
  115. package/lib/createCollection/getMethods/validateModifier/index.d.ts +0 -1
  116. package/lib/createCollection/getMethods/validateModifier/index.js +0 -18
  117. package/lib/createCollection/getMethods/validateModifier/index.test.d.ts +0 -1
  118. package/lib/createCollection/getMethods/validateModifier/index.test.js +0 -74
  119. package/lib/createCollection/getMethods/validateModifier/validateInc.d.ts +0 -7
  120. package/lib/createCollection/getMethods/validateModifier/validateInc.js +0 -20
  121. package/lib/createCollection/getMethods/validateModifier/validateInc.test.d.ts +0 -1
  122. package/lib/createCollection/getMethods/validateModifier/validateInc.test.js +0 -12
  123. package/lib/createCollection/getMethods/validateModifier/validateOperator.d.ts +0 -5
  124. package/lib/createCollection/getMethods/validateModifier/validateOperator.js +0 -34
  125. package/lib/createCollection/getMethods/validateModifier/validatePush.d.ts +0 -8
  126. package/lib/createCollection/getMethods/validateModifier/validatePush.js +0 -27
  127. package/lib/createCollection/getMethods/validateModifier/validatePush.test.d.ts +0 -1
  128. package/lib/createCollection/getMethods/validateModifier/validatePush.test.js +0 -90
  129. package/lib/createCollection/getMethods/validateModifier/validateSet.d.ts +0 -7
  130. package/lib/createCollection/getMethods/validateModifier/validateSet.js +0 -19
  131. package/lib/createCollection/getMethods/validateModifier/validateSet.test.d.ts +0 -1
  132. package/lib/createCollection/getMethods/validateModifier/validateSet.test.js +0 -16
  133. package/lib/createCollection/getMethods/validateModifier/validateUnset.d.ts +0 -7
  134. package/lib/createCollection/getMethods/validateModifier/validateUnset.js +0 -19
  135. package/lib/createCollection/getMethods/validateModifier/validateUnset.test.d.ts +0 -1
  136. package/lib/createCollection/getMethods/validateModifier/validateUnset.test.js +0 -71
  137. package/lib/createCollection/getMethods/validateModifier/validateUpsert.d.ts +0 -1
  138. package/lib/createCollection/getMethods/validateModifier/validateUpsert.js +0 -43
  139. package/lib/createCollection/getMethods/validateModifier/validateUpsert.test.d.ts +0 -1
  140. package/lib/createCollection/getMethods/validateModifier/validateUpsert.test.js +0 -50
  141. package/lib/createCollection/getMethods/wrapErrors.d.ts +0 -1
  142. package/lib/createCollection/getMethods/wrapErrors.js +0 -29
  143. package/lib/createCollection/getSchemaAndModel.d.ts +0 -10
  144. package/lib/createCollection/getSchemaAndModel.js +0 -41
  145. package/lib/createCollection/handleError.d.ts +0 -1
  146. package/lib/createCollection/handleError.js +0 -25
  147. package/lib/createCollection/index.d.ts +0 -4
  148. package/lib/createCollection/index.js +0 -77
  149. package/lib/createCollection/initItem.d.ts +0 -2
  150. package/lib/createCollection/initItem.js +0 -13
  151. package/lib/createCollection/typedModel.test.d.ts +0 -1
  152. package/lib/createCollection/typedModel.test.js +0 -159
  153. package/lib/helpers/fromDot.d.ts +0 -1
  154. package/lib/helpers/fromDot.js +0 -12
  155. package/lib/helpers/fromDot.test.d.ts +0 -1
  156. package/lib/helpers/fromDot.test.js +0 -47
  157. package/lib/helpers/toDot.d.ts +0 -1
  158. package/lib/helpers/toDot.js +0 -11
  159. package/lib/helpers/toDot.test.d.ts +0 -1
  160. package/lib/helpers/toDot.test.js +0 -23
  161. package/lib/index.d.ts +0 -5
  162. package/lib/index.js +0 -35
  163. package/lib/service/index.d.ts +0 -3
  164. package/lib/service/index.js +0 -32
  165. package/lib/service/index.test.d.ts +0 -1
  166. package/lib/service/index.test.js +0 -73
  167. package/lib/tests/setup.d.ts +0 -1
  168. package/lib/tests/setup.js +0 -20
  169. package/lib/types/index.d.ts +0 -178
  170. package/lib/types/index.js +0 -2
  171. package/lib/types/types.test.d.ts +0 -1
  172. package/lib/types/types.test.js +0 -59
@@ -0,0 +1,582 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import * as MongoDB from 'mongodb';
4
+ import { Db, MongoClient } from 'mongodb';
5
+
6
+ // Generated by dts-bundle-generator v9.5.1
7
+ // Generated by dts-bundle-generator v9.5.1
8
+ // Generated by dts-bundle-generator v9.5.1
9
+ export interface StoredCacheData {
10
+ value: any;
11
+ expires?: Date;
12
+ }
13
+ export interface SetCacheOptions {
14
+ ttl?: number;
15
+ }
16
+ export interface GetCacheOptions {
17
+ ttl?: number;
18
+ fallback?(): Promise<any>;
19
+ }
20
+ export interface OrionCache {
21
+ /**
22
+ * Save data in the cache
23
+ */
24
+ set(key: string, value: any, options?: SetCacheOptions): Promise<void> | void;
25
+ /**
26
+ * Get data from the cache
27
+ */
28
+ get(key: string, options?: GetCacheOptions): Promise<StoredCacheData>;
29
+ /**
30
+ * Removes data from the cache
31
+ */
32
+ invalidate(key: string): Promise<void> | void;
33
+ }
34
+ export type Blackbox = {
35
+ [name: string]: any;
36
+ };
37
+ export type ModelResolverResolve = (item: any, params: any, viewer: any, info?: any) => Promise<any>;
38
+ export type GlobalCheckPermissions = (params: any, viewer: any, info?: any) => Promise<string | void>;
39
+ export type ModelCheckPermissions = (parent: any, params: any, viewer: any, info?: any) => Promise<string | void>;
40
+ export type GlobalGetCacheKey = (params: any, viewer: any, info: any) => Promise<any>;
41
+ export type ModelGetCacheKey = (parent: any, params: any, viewer: any, info: any) => Promise<any>;
42
+ export interface ExecuteOptions {
43
+ params: Blackbox;
44
+ viewer: any;
45
+ parent?: any;
46
+ info?: any;
47
+ options: ResolverOptions;
48
+ }
49
+ export type Parameters$1<T> = T extends (...args: infer P) => any ? P : never;
50
+ export type ReturnType$1<T> = T extends (...args: any) => infer R ? R : any;
51
+ export type ResolverParams<Resolve, IsModel> = IsModel extends undefined ? Parameters$1<Resolve>[0] : Parameters$1<Resolve>[1];
52
+ export interface ExecuteParams<Resolve = Function, IsModel = undefined> {
53
+ params?: ResolverParams<Resolve, IsModel>;
54
+ viewer?: any;
55
+ parent?: IsModel extends undefined ? undefined : Parameters$1<Resolve>[0];
56
+ info?: any;
57
+ }
58
+ export type Execute<Resolve = Function, IsModel = undefined> = (executeOptions: ExecuteParams<Resolve, IsModel>) => ReturnType$1<Resolve>;
59
+ export interface SharedResolverOptions {
60
+ resolverId?: string;
61
+ params?: any;
62
+ returns?: any;
63
+ mutation?: boolean;
64
+ private?: boolean;
65
+ checkPermission?: GlobalCheckPermissions | ModelCheckPermissions;
66
+ getCacheKey?: GlobalGetCacheKey | ModelGetCacheKey;
67
+ cache?: number;
68
+ cacheProvider?: OrionCache;
69
+ permissionsOptions?: any;
70
+ middlewares?: ResolverMiddleware[];
71
+ }
72
+ export interface ResolverOptions<Resolve = Function> extends SharedResolverOptions {
73
+ resolve: Resolve;
74
+ }
75
+ export type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
76
+ export interface Resolver<Resolve = Function, IsModel = undefined> extends SharedResolverOptions {
77
+ execute: Execute<Resolve, IsModel>;
78
+ resolve: Resolve;
79
+ modelResolve: IsModel extends undefined ? undefined : OmitFirstArg<Resolve>;
80
+ }
81
+ export type ModelResolver<Resolve = Function> = Resolver<Resolve, true>;
82
+ export type ResolverMiddleware = (executeOptions: ExecuteOptions, next: () => Promise<any>) => Promise<any>;
83
+ export interface FieldType {
84
+ name: string;
85
+ validate: ValidateFunction;
86
+ clean: CleanFunction;
87
+ meta?: any;
88
+ toGraphQLType?: (GraphQL: any) => any;
89
+ _isFieldType: boolean;
90
+ }
91
+ export type Constructor<T> = new (...args: any[]) => T;
92
+ export type FieldTypesList = "string" | "date" | "integer" | "number" | "ID" | "boolean" | "email" | "blackbox" | "any";
93
+ export type TypedModelOnSchema = Function;
94
+ export type ConstructorsTypesList = Constructor<String> | Constructor<Number> | Constructor<Boolean> | Constructor<Date>;
95
+ export type SchemaRecursiveNodeTypeExtras = {
96
+ _isFieldType?: boolean;
97
+ __clean?: CleanFunction;
98
+ __validate?: ValidateFunction;
99
+ __skipChildValidation?: (value: any, info: CurrentNodeInfo) => Promise<boolean>;
100
+ };
101
+ export interface Schema {
102
+ [key: string]: SchemaNode | Function;
103
+ }
104
+ export type SchemaRecursiveNodeType = Schema & SchemaRecursiveNodeTypeExtras;
105
+ export type SchemaMetaFieldTypeSingle = FieldTypesList | ConstructorsTypesList | SchemaRecursiveNodeType | FieldType | TypedModelOnSchema;
106
+ export type SchemaMetaFieldType = SchemaMetaFieldTypeSingle | SchemaMetaFieldTypeSingle[];
107
+ export type ValidateFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => object | string | void | Promise<object | string | void>;
108
+ export type CleanFunction = (value: any, info?: Partial<CurrentNodeInfo>, ...args: any[]) => any | Promise<any>;
109
+ export interface SchemaNode {
110
+ /**
111
+ * The type of the field. Used for type validations. Can also contain a subschema.
112
+ */
113
+ type: SchemaMetaFieldType;
114
+ /**
115
+ * Defaults to false
116
+ */
117
+ optional?: boolean;
118
+ allowedValues?: Array<any>;
119
+ defaultValue?: ((info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>) | any;
120
+ /**
121
+ * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
122
+ */
123
+ validate?: ValidateFunction;
124
+ /**
125
+ * Function that preprocesses a value before it is set.
126
+ */
127
+ clean?: CleanFunction;
128
+ autoValue?: (value: any, info: CurrentNodeInfo, ...args: any[]) => any | Promise<any>;
129
+ /**
130
+ * The minimum value if it's a number, the minimum length if it's a string or array.
131
+ */
132
+ min?: number;
133
+ /**
134
+ * The maximum value if it's a number, the maximum length if it's a string or array.
135
+ */
136
+ max?: number;
137
+ /**
138
+ * Internal use only.
139
+ */
140
+ isBlackboxChild?: boolean;
141
+ /**
142
+ * @deprecated
143
+ */
144
+ custom?: ValidateFunction;
145
+ /**
146
+ * Used in GraphQL. If true, the field will be omitted from the schema.
147
+ */
148
+ private?: boolean;
149
+ /**
150
+ * Used in GraphQL. When in GraphQL, this resolver will replace the static field.
151
+ */
152
+ graphQLResolver?: (...args: any) => any;
153
+ /**
154
+ * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
155
+ */
156
+ key?: string;
157
+ /**
158
+ * The name that would be displayed in a front-end form
159
+ */
160
+ label?: string;
161
+ /**
162
+ * The description that would be displayed in a front-end form
163
+ */
164
+ description?: string;
165
+ /**
166
+ * The placeholder that would be displayed in a front-end form
167
+ */
168
+ placeholder?: string;
169
+ /**
170
+ * The field type that would be used in a front-end form
171
+ */
172
+ fieldType?: string;
173
+ /**
174
+ * The field options that will be passed as props to the front-end field
175
+ */
176
+ fieldOptions?: any;
177
+ }
178
+ export interface CurrentNodeInfoOptions {
179
+ autoConvert?: boolean;
180
+ filter?: boolean;
181
+ trimStrings?: boolean;
182
+ removeEmptyStrings?: boolean;
183
+ forceDoc?: any;
184
+ omitRequired?: boolean;
185
+ }
186
+ export interface CurrentNodeInfo {
187
+ /**
188
+ * The global schema, prefaced by {type: {...}} to be compatible with subschemas
189
+ * Sometimes it's given without {type: {...}}. TODO: Normalize this.
190
+ */
191
+ schema?: SchemaNode | Schema;
192
+ /**
193
+ * The current node subschema
194
+ */
195
+ currentSchema?: Partial<SchemaNode>;
196
+ value: any;
197
+ doc?: any;
198
+ currentDoc?: any;
199
+ options?: CurrentNodeInfoOptions;
200
+ args?: any[];
201
+ type?: SchemaMetaFieldType;
202
+ keys?: string[];
203
+ addError?: (keys: string[], code: string | object) => void;
204
+ }
205
+ export interface ModelResolversMap {
206
+ [key: string]: ModelResolver<ModelResolverResolve>;
207
+ }
208
+ export interface CloneOptions {
209
+ name: string;
210
+ omitFields?: string[];
211
+ pickFields?: string[];
212
+ mapFields?: (field: any, key: string) => any;
213
+ extendSchema?: Schema;
214
+ extendResolvers?: ModelResolversMap;
215
+ }
216
+ export interface Model<TSchema = any> {
217
+ __isModel: boolean;
218
+ /**
219
+ * The name of the model, used for example for GraphQL
220
+ */
221
+ name: string;
222
+ /**
223
+ * Returns the schema of the model
224
+ */
225
+ getSchema: () => Schema & {
226
+ __model: Model;
227
+ };
228
+ /**
229
+ * Returns the schema without adding __model to the schema
230
+ */
231
+ getCleanSchema: () => Schema;
232
+ /**
233
+ * Returns the model resolvers
234
+ */
235
+ getResolvers: () => ModelResolversMap;
236
+ /**
237
+ * Adds the model resolvers to a item
238
+ */
239
+ initItem: (item: any) => any;
240
+ /**
241
+ * Validates an item using @orion-js/schema
242
+ */
243
+ validate: (item: any) => Promise<any>;
244
+ /**
245
+ * Cleans an item using @orion-js/schema
246
+ */
247
+ clean: (item: any) => Promise<TSchema>;
248
+ /**
249
+ * Cleans and validates an item using @orion-js/schema
250
+ */
251
+ cleanAndValidate: (item: any) => Promise<TSchema>;
252
+ /**
253
+ * Creates a new model using this one as a base
254
+ */
255
+ clone: (cloneOptions: CloneOptions) => Model;
256
+ /**
257
+ * The type of the model. Only use this in typescript
258
+ */
259
+ type: TSchema;
260
+ }
261
+ interface FieldType$1 {
262
+ name: string;
263
+ validate: ValidateFunction$1;
264
+ clean: CleanFunction$1;
265
+ meta?: any;
266
+ toGraphQLType?: (GraphQL: any) => any;
267
+ _isFieldType: boolean;
268
+ }
269
+ type Constructor$1<T> = new (...args: any[]) => T;
270
+ type Blackbox$1 = {
271
+ [name: string]: any;
272
+ };
273
+ type FieldTypesList$1 = "string" | "date" | "integer" | "number" | "ID" | "boolean" | "email" | "blackbox" | "any";
274
+ type TypedModelOnSchema$1 = Function;
275
+ type ConstructorsTypesList$1 = Constructor$1<String> | Constructor$1<Number> | Constructor$1<Boolean> | Constructor$1<Date>;
276
+ type SchemaRecursiveNodeTypeExtras$1 = {
277
+ _isFieldType?: boolean;
278
+ __clean?: CleanFunction$1;
279
+ __validate?: ValidateFunction$1;
280
+ __skipChildValidation?: (value: any, info: CurrentNodeInfo$1) => Promise<boolean>;
281
+ };
282
+ interface Schema$1 {
283
+ [key: string]: SchemaNode$1 | Function;
284
+ }
285
+ type SchemaRecursiveNodeType$1 = Schema$1 & SchemaRecursiveNodeTypeExtras$1;
286
+ type SchemaMetaFieldTypeSingle$1 = FieldTypesList$1 | ConstructorsTypesList$1 | SchemaRecursiveNodeType$1 | FieldType$1 | TypedModelOnSchema$1;
287
+ type SchemaMetaFieldType$1 = SchemaMetaFieldTypeSingle$1 | SchemaMetaFieldTypeSingle$1[];
288
+ type ValidateFunction$1 = (value: any, info?: Partial<CurrentNodeInfo$1>, ...args: any[]) => object | string | void | Promise<object | string | void>;
289
+ type CleanFunction$1 = (value: any, info?: Partial<CurrentNodeInfo$1>, ...args: any[]) => any | Promise<any>;
290
+ interface SchemaNode$1 {
291
+ /**
292
+ * The type of the field. Used for type validations. Can also contain a subschema.
293
+ */
294
+ type: SchemaMetaFieldType$1;
295
+ /**
296
+ * Defaults to false
297
+ */
298
+ optional?: boolean;
299
+ allowedValues?: Array<any>;
300
+ defaultValue?: ((info: CurrentNodeInfo$1, ...args: any[]) => any | Promise<any>) | any;
301
+ /**
302
+ * Function that takes a value and returns an error message if there are any errors. Must return null or undefined otherwise.
303
+ */
304
+ validate?: ValidateFunction$1;
305
+ /**
306
+ * Function that preprocesses a value before it is set.
307
+ */
308
+ clean?: CleanFunction$1;
309
+ autoValue?: (value: any, info: CurrentNodeInfo$1, ...args: any[]) => any | Promise<any>;
310
+ /**
311
+ * The minimum value if it's a number, the minimum length if it's a string or array.
312
+ */
313
+ min?: number;
314
+ /**
315
+ * The maximum value if it's a number, the maximum length if it's a string or array.
316
+ */
317
+ max?: number;
318
+ /**
319
+ * Internal use only.
320
+ */
321
+ isBlackboxChild?: boolean;
322
+ /**
323
+ * @deprecated
324
+ */
325
+ custom?: ValidateFunction$1;
326
+ /**
327
+ * Used in GraphQL. If true, the field will be omitted from the schema.
328
+ */
329
+ private?: boolean;
330
+ /**
331
+ * Used in GraphQL. When in GraphQL, this resolver will replace the static field.
332
+ */
333
+ graphQLResolver?: (...args: any) => any;
334
+ /**
335
+ * Used in GraphQL. Sets the key of the field in the GraphQL schema. You must set this value when building your schema.
336
+ */
337
+ key?: string;
338
+ /**
339
+ * The name that would be displayed in a front-end form
340
+ */
341
+ label?: string;
342
+ /**
343
+ * The description that would be displayed in a front-end form
344
+ */
345
+ description?: string;
346
+ /**
347
+ * The placeholder that would be displayed in a front-end form
348
+ */
349
+ placeholder?: string;
350
+ /**
351
+ * The field type that would be used in a front-end form
352
+ */
353
+ fieldType?: string;
354
+ /**
355
+ * The field options that will be passed as props to the front-end field
356
+ */
357
+ fieldOptions?: any;
358
+ }
359
+ interface CurrentNodeInfoOptions$1 {
360
+ autoConvert?: boolean;
361
+ filter?: boolean;
362
+ trimStrings?: boolean;
363
+ removeEmptyStrings?: boolean;
364
+ forceDoc?: any;
365
+ omitRequired?: boolean;
366
+ }
367
+ interface CurrentNodeInfo$1 {
368
+ /**
369
+ * The global schema, prefaced by {type: {...}} to be compatible with subschemas
370
+ * Sometimes it's given without {type: {...}}. TODO: Normalize this.
371
+ */
372
+ schema?: SchemaNode$1 | Schema$1;
373
+ /**
374
+ * The current node subschema
375
+ */
376
+ currentSchema?: Partial<SchemaNode$1>;
377
+ value: any;
378
+ doc?: any;
379
+ currentDoc?: any;
380
+ options?: CurrentNodeInfoOptions$1;
381
+ args?: any[];
382
+ type?: SchemaMetaFieldType$1;
383
+ keys?: string[];
384
+ addError?: (keys: string[], code: string | object) => void;
385
+ }
386
+ export interface OrionMongoClient {
387
+ client: MongoClient;
388
+ db: Db;
389
+ uri: string;
390
+ dbName: string;
391
+ connectionPromise: Promise<MongoClient>;
392
+ connectionName: string;
393
+ }
394
+ export interface OrionMongoConnectionsMap {
395
+ [key: string]: OrionMongoClient;
396
+ }
397
+ export declare const connections: OrionMongoConnectionsMap;
398
+ export type RemoveFunctions<T extends ModelClassBase> = Pick<T, {
399
+ [Key in keyof T]-?: T[Key] extends Function ? never : Key;
400
+ }[keyof T]> & {
401
+ _id: ModelClassBase["_id"];
402
+ };
403
+ export type ModelClassBase = {
404
+ _id: string;
405
+ } & Blackbox$1;
406
+ export type DocumentWithIdOptional<T extends ModelClassBase> = Omit<T, "_id"> & {
407
+ /**
408
+ * The ID of the document
409
+ */
410
+ _id?: T["_id"];
411
+ };
412
+ export type DocumentWithoutId<T> = Omit<T, "_id">;
413
+ export type ModelToDocumentType<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
414
+ export type ModelToDocumentTypeWithId<ModelClass extends ModelClassBase> = RemoveFunctions<ModelClass>;
415
+ export type ModelToDocumentTypeWithoutId<ModelClass extends ModelClassBase> = DocumentWithoutId<ModelToDocumentType<ModelClass>>;
416
+ export type ModelToDocumentTypeWithIdOptional<ModelClass extends ModelClassBase> = DocumentWithIdOptional<ModelToDocumentType<ModelClass>>;
417
+ export type ModelToMongoSelector<ModelClass extends ModelClassBase> = MongoSelector<ModelToDocumentType<ModelClass>>;
418
+ export type ModelToUpdateFilter<ModelClass extends ModelClassBase> = MongoDB.UpdateFilter<ModelToDocumentTypeWithoutId<ModelClass>> | Partial<ModelToDocumentTypeWithoutId<ModelClass>>;
419
+ export interface CollectionIndex {
420
+ keys: MongoDB.IndexSpecification;
421
+ options?: MongoDB.CreateIndexesOptions;
422
+ }
423
+ export declare namespace DataLoader {
424
+ interface LoadDataOptionsBase<ModelClass extends ModelClassBase> {
425
+ key: keyof ModelClass;
426
+ match?: MongoFilter<ModelClass>;
427
+ sort?: MongoDB.Sort;
428
+ project?: MongoDB.Document;
429
+ timeout?: number;
430
+ debug?: boolean;
431
+ }
432
+ export interface LoadDataOptions<ModelClass extends ModelClassBase> extends LoadDataOptionsBase<ModelClass> {
433
+ value?: any;
434
+ values?: Array<any>;
435
+ }
436
+ export interface LoadOneOptions<ModelClass extends ModelClassBase> extends LoadDataOptionsBase<ModelClass> {
437
+ value: any;
438
+ }
439
+ export type LoadData<ModelClass extends ModelClassBase> = (options: LoadDataOptions<ModelClass>) => Promise<Array<ModelClass>>;
440
+ export type LoadOne<ModelClass extends ModelClassBase> = (options: LoadOneOptions<ModelClass>) => Promise<ModelClass>;
441
+ export type LoadMany<ModelClass extends ModelClassBase> = (options: LoadDataOptions<ModelClass>) => Promise<Array<ModelClass>>;
442
+ export type LoadById<ModelClass extends ModelClassBase> = (id: ModelClass["_id"]) => Promise<ModelClass>;
443
+ export {};
444
+ }
445
+ export type MongoFilter<ModelClass extends ModelClassBase = ModelClassBase> = MongoDB.Filter<ModelClass> & ({
446
+ _id?: ModelClass["_id"];
447
+ } | {
448
+ _id?: {
449
+ $in: ModelClass["_id"][];
450
+ };
451
+ });
452
+ export type MongoSelector<ModelClass extends ModelClassBase = ModelClassBase> = ModelClass["_id"] | MongoFilter<ModelClass>;
453
+ export interface FindCursor<ModelClass> extends MongoDB.FindCursor {
454
+ toArray: () => Promise<Array<ModelClass>>;
455
+ }
456
+ export interface UpdateOptions {
457
+ clean?: boolean;
458
+ validate?: boolean;
459
+ mongoOptions?: MongoDB.UpdateOptions;
460
+ }
461
+ export interface FindOneAndUpdateUpdateOptions {
462
+ clean?: boolean;
463
+ validate?: boolean;
464
+ mongoOptions?: MongoDB.FindOneAndUpdateOptions;
465
+ }
466
+ export interface InsertOptions {
467
+ clean?: boolean;
468
+ validate?: boolean;
469
+ mongoOptions?: MongoDB.InsertOneOptions;
470
+ }
471
+ export type InitItem<ModelClass extends ModelClassBase> = (doc: any) => ModelClass;
472
+ export type FindOne<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions) => Promise<ModelClass>;
473
+ export type Find<ModelClass extends ModelClassBase> = (selector?: ModelToMongoSelector<ModelClass>, options?: MongoDB.FindOptions) => FindCursor<ModelClass>;
474
+ export type FindOneAndUpdate<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
475
+ export type UpdateAndFind<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<ModelClass>;
476
+ export type UpdateItem<ModelClass extends ModelClassBase> = (item: ModelClass, modifier: ModelToUpdateFilter<ModelClass>, options?: FindOneAndUpdateUpdateOptions) => Promise<void>;
477
+ export type InsertOne<ModelClass extends ModelClassBase> = (doc: ModelToDocumentTypeWithIdOptional<ModelClass>, options?: InsertOptions) => Promise<ModelClass["_id"]>;
478
+ export type InsertMany<ModelClass extends ModelClassBase> = (doc: Array<ModelToDocumentTypeWithIdOptional<ModelClass>>, options?: InsertOptions) => Promise<Array<ModelClass["_id"]>>;
479
+ export type InsertAndFind<ModelClass extends ModelClassBase> = (doc: ModelToDocumentTypeWithIdOptional<ModelClass>, options?: InsertOptions) => Promise<ModelClass>;
480
+ export type DeleteMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
481
+ export type DeleteOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.DeleteOptions) => Promise<MongoDB.DeleteResult>;
482
+ export type UpdateOne<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
483
+ export type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult | MongoDB.Document>;
484
+ export type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
485
+ export interface CreateCollectionOptions<ModelClass extends ModelClassBase = ModelClassBase> {
486
+ /**
487
+ * The name of the collection on the Mongo Database
488
+ */
489
+ name: string;
490
+ /**
491
+ * The name of the connection to use. The Mongo URL of this connection will be search on env variables.
492
+ * If not found, the connection url will be `env.mongo_url`
493
+ * If defined, the connection url will be `env.mongo_url_${name}`
494
+ */
495
+ connectionName?: string;
496
+ /**
497
+ * The schema used for cleaning and validation of the documents
498
+ */
499
+ schema?: any;
500
+ /**
501
+ * @deprecated Use schema instead. If you use model, all items will be initialized with the model to add resolvers (which are also deprecated)
502
+ */
503
+ model?: any;
504
+ /**
505
+ * The indexes to use
506
+ */
507
+ indexes?: Array<CollectionIndex>;
508
+ /**
509
+ * Select between random id generation o mongo (time based) id generation
510
+ */
511
+ idGeneration?: "mongo" | "random" | "uuid";
512
+ /**
513
+ * ID prefix. idGeneration will be forced to random. Recommended for type checking
514
+ */
515
+ idPrefix?: ModelClass["_id"];
516
+ }
517
+ export type EstimatedDocumentCount<ModelClass extends ModelClassBase> = (options?: MongoDB.EstimatedDocumentCountOptions) => Promise<number>;
518
+ export type CountDocuments<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.CountDocumentsOptions) => Promise<number>;
519
+ export type CreateCollection = <ModelClass extends ModelClassBase = any>(options: CreateCollectionOptions<ModelClass>) => Collection<ModelClass>;
520
+ export interface Collection<ModelClass extends ModelClassBase = ModelClassBase> {
521
+ name: string;
522
+ connectionName?: string;
523
+ schema?: Schema$1;
524
+ /**
525
+ * @deprecated Use schema instead. If you use model, all items will be initialized with the model to add resolvers (which are also deprecated)
526
+ */
527
+ model?: Model;
528
+ indexes: Array<CollectionIndex>;
529
+ generateId: () => ModelClass["_id"];
530
+ getSchema: () => Schema$1;
531
+ db: MongoDB.Db;
532
+ client: OrionMongoClient;
533
+ rawCollection: MongoDB.Collection<ModelClass>;
534
+ initItem: InitItem<ModelClass>;
535
+ findOne: FindOne<ModelClass>;
536
+ find: Find<ModelClass>;
537
+ insertOne: InsertOne<ModelClass>;
538
+ insertMany: InsertMany<ModelClass>;
539
+ insertAndFind: InsertAndFind<ModelClass>;
540
+ deleteMany: DeleteMany<ModelClass>;
541
+ deleteOne: DeleteOne<ModelClass>;
542
+ updateOne: UpdateOne<ModelClass>;
543
+ updateMany: UpdateMany<ModelClass>;
544
+ upsert: Upsert<ModelClass>;
545
+ findOneAndUpdate: FindOneAndUpdate<ModelClass>;
546
+ /**
547
+ * Updates a document and returns the updated document with the changes
548
+ */
549
+ updateAndFind: UpdateAndFind<ModelClass>;
550
+ updateItem: UpdateItem<ModelClass>;
551
+ estimatedDocumentCount: EstimatedDocumentCount<ModelClass>;
552
+ countDocuments: CountDocuments<ModelClass>;
553
+ aggregate: <T = MongoDB.Document>(pipeline?: MongoDB.Document[], options?: MongoDB.AggregateOptions) => MongoDB.AggregationCursor<T>;
554
+ watch: <T = MongoDB.Document>(pipeline?: MongoDB.Document[], options?: MongoDB.ChangeStreamOptions) => MongoDB.ChangeStream<T>;
555
+ loadData: DataLoader.LoadData<ModelClass>;
556
+ loadOne: DataLoader.LoadOne<ModelClass>;
557
+ loadMany: DataLoader.LoadMany<ModelClass>;
558
+ loadById: DataLoader.LoadById<ModelClass>;
559
+ /**
560
+ * Use this function if you are using tests and you pass the
561
+ * env var DONT_CREATE_INDEXES_AUTOMATICALLY and you need to
562
+ * create the indexes for this collection
563
+ */
564
+ createIndexes: () => Promise<string[]>;
565
+ createIndexesPromise: Promise<string[]>;
566
+ connectionPromise: Promise<MongoDB.MongoClient>;
567
+ }
568
+ export type DistinctDocumentId<DistinctId extends string> = string & {
569
+ __TYPE__: `DistinctDocumentId<${DistinctId}>`;
570
+ };
571
+ export declare const createIndexesPromises: any[];
572
+ export declare const createCollection: CreateCollection;
573
+ export declare const allConnectionPromises: any[];
574
+ export interface MongoConnectOptions {
575
+ name: string;
576
+ uri?: string;
577
+ }
578
+ export declare const getMongoConnection: ({ name, uri }: MongoConnectOptions) => OrionMongoClient;
579
+ export declare function MongoCollection<ModelClass extends ModelClassBase = ModelClassBase>(options: CreateCollectionOptions<ModelClass>): (object: any, propertyName: string, index?: number) => void;
580
+ export declare function Repository(): ClassDecorator;
581
+
582
+ export {};