@thisisagile/easy-mongo 15.8.4 → 15.8.6

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.
@@ -0,0 +1,361 @@
1
+ import * as _thisisagile_easy from '@thisisagile/easy';
2
+ import { Mapper, PropertyOptions, Field, Get, Json, MapOptions, Database, Condition, LogicalCondition, Text, Sort as Sort$1, SortDirection, FetchOptions, OneOrMore, PageList, Id, JsonValue, Gateway, List, Optional, Func, RequireAtLeastOne, DateTime, Filter as Filter$1, PartialRecord } from '@thisisagile/easy';
3
+ import { StrictFilter, MongoClient, Collection as Collection$1, FindOptions as FindOptions$1, IndexSpecification, CreateIndexesOptions, FindCursor, Document, AggregationCursor } from 'mongodb';
4
+
5
+ declare class Collection extends Mapper {
6
+ protected readonly map: {
7
+ field: <T = unknown>(name: string, options?: PropertyOptions<T> | undefined) => Field;
8
+ item: (property: string, options?: PropertyOptions<unknown> | undefined) => _thisisagile_easy.Property<unknown>;
9
+ ignore: (property?: string | undefined) => _thisisagile_easy.Mapping;
10
+ skipIn: (property: string) => _thisisagile_easy.Mapping;
11
+ skipOut: (property: string) => _thisisagile_easy.Mapping;
12
+ func: (property: string, funcIn: Get<_thisisagile_easy.Optional<_thisisagile_easy.JsonValue>, Json>, funcOut: Get<_thisisagile_easy.Optional<_thisisagile_easy.JsonValue>, Json>) => _thisisagile_easy.Mapping;
13
+ add: (funcIn: Get<_thisisagile_easy.JsonValue, Json>) => _thisisagile_easy.Mapping;
14
+ map: (mapper: _thisisagile_easy.Construct<Mapper, any>, property?: string | undefined) => _thisisagile_easy.Mapping;
15
+ propsToList: (...maps: _thisisagile_easy.Mapping[]) => _thisisagile_easy.Mapping;
16
+ list: (mapper: _thisisagile_easy.Mapping, property: string) => _thisisagile_easy.Mapping;
17
+ };
18
+ readonly id: Field;
19
+ constructor(options?: MapOptions);
20
+ get db(): Database;
21
+ get provider(): MongoProvider;
22
+ where: (...conditions: Get<Condition, this>[]) => Json;
23
+ match: (condition: Get<Condition | LogicalCondition, this>) => Json;
24
+ group: (...conditions: Get<Condition, this>[]) => Json;
25
+ google: (value: unknown) => Condition;
26
+ search: (key: Text) => Field;
27
+ sort: (...conditions: Sort$1[]) => Record<string, SortDirection>;
28
+ out(to?: Json): Json;
29
+ }
30
+
31
+ type Projection = Record<string, 0 | 1>;
32
+ type FindOptions = FetchOptions & {
33
+ projection?: Projection;
34
+ };
35
+ type Filter<T = unknown> = StrictFilter<T>;
36
+ type Query = Condition | LogicalCondition | Filter<any>;
37
+ type IndexOptions = {
38
+ unique?: boolean;
39
+ filter?: Query;
40
+ languageOverride?: string;
41
+ languageDefault?: string;
42
+ };
43
+ type Indexes = OneOrMore<string | Field | Sort$1 | Record<string, 1 | -1>>;
44
+ declare class MongoProvider {
45
+ readonly coll: Collection;
46
+ protected client?: Promise<MongoClient> | undefined;
47
+ protected static readonly clients: {
48
+ [key: string]: Promise<MongoClient>;
49
+ };
50
+ constructor(coll: Collection, client?: Promise<MongoClient> | undefined);
51
+ static client(db: Database): Promise<MongoClient>;
52
+ cluster(): Promise<MongoClient>;
53
+ toMongoJson(query: Query): Json;
54
+ find(query: Query, options?: FindOptions): Promise<PageList<Json>>;
55
+ all(options?: FindOptions): Promise<PageList<Json>>;
56
+ byId(id: Id, options?: FindOptions): Promise<Json>;
57
+ by(key: string, value: JsonValue, options?: FindOptions): Promise<PageList<Json>>;
58
+ group(qs: Filter<any>[]): Promise<PageList<Json>>;
59
+ aggregate(qs: Filter<any>[]): Promise<PageList<Json>>;
60
+ add(item: Json): Promise<Json>;
61
+ update(item: Json): Promise<Json>;
62
+ remove(id: Id): Promise<boolean>;
63
+ count(query?: Query): Promise<number>;
64
+ createIndex(indexes: Indexes, options?: IndexOptions): Promise<string>;
65
+ createPartialIndex(indexes: Indexes, filter: Query, options?: Omit<IndexOptions, 'filter'>): Promise<string>;
66
+ createTextIndex(indexes: OneOrMore<Field | string>, options?: IndexOptions): Promise<string>;
67
+ collection(): Promise<Collection$1>;
68
+ protected toFindOptions(options?: FindOptions): FindOptions$1 & {
69
+ total: boolean;
70
+ };
71
+ protected toIndexSpecification(index: Indexes): IndexSpecification;
72
+ protected toCreateIndexesOptions(options?: IndexOptions): CreateIndexesOptions;
73
+ protected toArray(cursor: FindCursor<Document> | AggregationCursor<Document>, options?: {
74
+ take?: number;
75
+ skip?: number;
76
+ total?: number;
77
+ }): Promise<PageList<Json>>;
78
+ }
79
+
80
+ declare class MongoGateway implements Gateway<FindOptions> {
81
+ readonly collection: Collection;
82
+ readonly provider: MongoProvider;
83
+ constructor(collection: Collection, provider?: MongoProvider);
84
+ all(options?: FindOptions): Promise<PageList<Json>>;
85
+ byId(id: Id): Promise<Json | undefined>;
86
+ by(key: string, value: JsonValue, options?: FindOptions): Promise<PageList<Json>>;
87
+ byIds(...ids: Id[]): Promise<List<Json>>;
88
+ find(q: JsonValue | Condition | LogicalCondition, options?: FindOptions): Promise<PageList<Json>>;
89
+ search(q: JsonValue, options?: FindOptions): Promise<PageList<Json>>;
90
+ filter(options?: FindOptions): Promise<PageList<Json>>;
91
+ exists(id: Id): Promise<boolean>;
92
+ aggregate(...filters: Optional<Filter>[]): Promise<PageList<Json>>;
93
+ count(...filters: Optional<Filter>[]): Promise<number>;
94
+ match(f: Filter): Promise<PageList<Json>>;
95
+ add(item: Json): Promise<Json>;
96
+ update(item: Json): Promise<Json>;
97
+ remove(id: Id): Promise<boolean>;
98
+ }
99
+
100
+ type FuzzyOptions = {
101
+ maxEdits: number;
102
+ prefixLength: number;
103
+ maxExpansions: number;
104
+ };
105
+ type Facet = {
106
+ path: string;
107
+ type: 'string';
108
+ numBuckets: number;
109
+ } | {
110
+ path: string;
111
+ type: 'number';
112
+ boundaries: number[];
113
+ default?: string;
114
+ } | {
115
+ path: string;
116
+ type: 'date';
117
+ boundaries: Date[];
118
+ default?: string;
119
+ };
120
+ type Operator = Func<Optional<object>, string>;
121
+ type Clause = object | Operator;
122
+ type Clauses = Record<string, Clause>;
123
+ type SearchDefinition = Record<string, (v: string | number) => RequireAtLeastOne<{
124
+ should?: Clauses;
125
+ filter?: Clauses;
126
+ must?: Clauses;
127
+ mustNot?: Clauses;
128
+ sort?: Record<string, 1 | -1>;
129
+ facet?: Facet;
130
+ }>>;
131
+ type Compound = {
132
+ must: OneOrMore<Clauses>;
133
+ should: OneOrMore<Clauses>;
134
+ mustNot: OneOrMore<Clauses>;
135
+ filter: OneOrMore<Clauses>;
136
+ };
137
+ declare const lucene: {
138
+ clause: (c: Clauses) => List<unknown>;
139
+ clauses: (cs: OneOrMore<Clauses>) => unknown[];
140
+ search: (c: Partial<Compound>, index?: string) => {
141
+ $search: {
142
+ compound: any;
143
+ index?: string | undefined;
144
+ };
145
+ };
146
+ searchWithDef: (query: Record<string, string | number>, options: SearchDefinition, index?: string) => {
147
+ $search: {
148
+ sort?: Record<string, 1 | -1> | undefined;
149
+ compound: Partial<Compound>;
150
+ index?: string | undefined;
151
+ };
152
+ };
153
+ searchMeta: (query: Record<string, string | number>, def: SearchDefinition, index?: string) => {
154
+ $searchMeta: {
155
+ facet: {
156
+ operator: {
157
+ compound: Partial<Compound>;
158
+ };
159
+ facets: {
160
+ [x: string]: Facet | undefined;
161
+ };
162
+ };
163
+ index?: string | undefined;
164
+ };
165
+ };
166
+ exists: () => Operator;
167
+ text: (value?: OneOrMore<unknown>, fuzzy?: Partial<FuzzyOptions>) => Operator;
168
+ wildcard: (value?: OneOrMore<unknown>) => Operator;
169
+ lt: (value: unknown) => Operator;
170
+ lte: (value: unknown) => Operator;
171
+ gt: (value: unknown) => Operator;
172
+ gte: (value: unknown) => Operator;
173
+ after: (date: unknown) => Operator;
174
+ before: (date: unknown) => Operator;
175
+ between: (after: unknown, before: unknown) => Operator;
176
+ facets: (def: SearchDefinition) => {
177
+ [x: string]: Facet | undefined;
178
+ };
179
+ facet: {
180
+ string: (path: string, numBuckets?: number) => Facet;
181
+ number: (path: string, boundaries: List<number>, alt?: string) => Facet;
182
+ date: (path: string, boundaries: List<DateTime>, alt?: string) => Facet;
183
+ };
184
+ };
185
+
186
+ declare const toFilters: (facets: unknown) => Filter$1[];
187
+ declare class AtlasSearchGateway extends MongoGateway {
188
+ readonly searchDef: SearchDefinition;
189
+ readonly sortDef: Record<string, Record<string, 1 | -1>>;
190
+ constructor(collection: Collection, searchDef: SearchDefinition, sortDef?: Record<string, Record<string, 1 | -1>>, provider?: MongoProvider);
191
+ query: (query: Record<keyof typeof this$1.searchDef, string | number>) => Promise<PageList<Json>>;
192
+ }
193
+
194
+ declare const asc = 1;
195
+ declare const desc = -1;
196
+ type Accumulators = '$sum' | '$count' | '$avg' | '$first' | '$last' | '$min' | '$max' | '$push';
197
+ type Accumulator = PartialRecord<Accumulators, Filter>;
198
+ declare class FilterBuilder<Options> {
199
+ private filters;
200
+ constructor(filters: {
201
+ [K in keyof Options]: (v: Options[K]) => Filter;
202
+ });
203
+ from: (q?: Partial<Options>) => Filter;
204
+ }
205
+ type Sort = Record<string, typeof asc | typeof desc>;
206
+ declare class SortBuilder {
207
+ private sorts;
208
+ constructor(sorts: Record<string, Sort>);
209
+ get keys(): string[];
210
+ from: (s?: {
211
+ s?: string | undefined;
212
+ }, alt?: string) => Optional<Filter>;
213
+ }
214
+ declare class IncludeBuilder {
215
+ private includes;
216
+ constructor(includes: Record<string, (string | Record<string, 1>)[]>);
217
+ get keys(): string[];
218
+ from: (i?: {
219
+ i?: string | undefined;
220
+ }, alt?: string) => Optional<Filter>;
221
+ }
222
+ declare const stages: {
223
+ root: string;
224
+ current: string;
225
+ id: string;
226
+ decode: {
227
+ fields: (f: Filter) => any;
228
+ fieldsArrays: (f: Filter) => any;
229
+ id: (f: Filter | string) => any;
230
+ };
231
+ match: {
232
+ match: (f: Record<string, Get<Optional<Filter>, string>>) => {
233
+ $match: any;
234
+ };
235
+ filter: <Options>(filters: { [K in keyof Options]: (v: Options[K]) => Filter; }) => FilterBuilder<Options>;
236
+ gt: (value: Filter) => {
237
+ $gt: Filter;
238
+ };
239
+ gte: (value: Filter) => {
240
+ $gte: Filter;
241
+ };
242
+ lt: (value: Filter) => {
243
+ $lt: Filter;
244
+ };
245
+ lte: (value: Filter) => {
246
+ $lte: Filter;
247
+ };
248
+ isIn: (value: OneOrMore<unknown>, separator?: string) => {
249
+ $in: unknown;
250
+ };
251
+ notIn: (value: OneOrMore<unknown>, separator?: string) => {
252
+ $nin: unknown;
253
+ };
254
+ after: (date: unknown) => {
255
+ $gte: Filter;
256
+ };
257
+ before: (date: unknown) => {
258
+ $lt: Filter;
259
+ };
260
+ anywhere: (q: string) => {
261
+ $regex: string;
262
+ $options: string;
263
+ };
264
+ };
265
+ sort: {
266
+ sort: ($sort: Sort) => {
267
+ $sort: Sort;
268
+ } | undefined;
269
+ sorter: (sorts: Record<string, Sort>) => SortBuilder;
270
+ asc: (key: string) => {
271
+ $sort: Sort;
272
+ } | undefined;
273
+ desc: (key: string) => {
274
+ $sort: Sort;
275
+ } | undefined;
276
+ };
277
+ group: {
278
+ group: (fields: Record<string, Accumulator>) => {
279
+ by: (by: Filter) => {
280
+ $group: any;
281
+ };
282
+ };
283
+ date: (format?: string) => (key: string) => {
284
+ $dateToString: {
285
+ date: string;
286
+ format: string;
287
+ };
288
+ };
289
+ count: () => Accumulator;
290
+ sum: (from?: string) => Accumulator;
291
+ avg: (from?: string) => {
292
+ $avg: string;
293
+ };
294
+ first: (from?: string) => Accumulator;
295
+ last: (from?: string) => Accumulator;
296
+ min: (from?: string) => Accumulator;
297
+ max: (from?: string) => Accumulator;
298
+ push: (from?: string) => Accumulator;
299
+ };
300
+ search: {
301
+ search: (f: Record<string, Get<Filter, string>>) => Optional<{
302
+ $search: any;
303
+ }>;
304
+ auto: (value?: Id) => (key: string) => Optional<{
305
+ autocomplete: {
306
+ path: string;
307
+ query: NonNullable<string | number>[];
308
+ };
309
+ }>;
310
+ fuzzy: (value?: string, maxEdits?: number) => (key?: string) => Optional<{
311
+ text: {
312
+ query: string;
313
+ path: string | {
314
+ wildcard: string;
315
+ } | undefined;
316
+ fuzzy: {
317
+ maxEdits: number;
318
+ };
319
+ };
320
+ }>;
321
+ };
322
+ set: {
323
+ set: (f: Record<string, Get<Filter, string>>) => {
324
+ $set: any;
325
+ };
326
+ score: () => {
327
+ $meta: string;
328
+ };
329
+ };
330
+ skip: {
331
+ skip: (o?: FindOptions) => Optional<Filter>;
332
+ take: (o?: FindOptions) => Optional<Filter>;
333
+ };
334
+ project: {
335
+ include: (...includes: (string | Record<string, 1>)[]) => Optional<Filter>;
336
+ exclude: (...excludes: (string | Record<string, 0>)[]) => Optional<Filter>;
337
+ includes: (includes: Record<string, (string | Record<string, 1>)[]>) => IncludeBuilder;
338
+ };
339
+ replaceWith: {
340
+ replaceWith: (f?: Filter) => Optional<Filter>;
341
+ merge: (...objects: Filter[]) => Optional<Filter>;
342
+ rootAnd: (...objects: Filter[]) => Optional<Filter>;
343
+ currentAnd: (...objects: Filter[]) => Optional<Filter>;
344
+ };
345
+ facet: {
346
+ facet: (f: Record<string, OneOrMore<Get<Optional<Filter>, string>>>) => {
347
+ $facet: any;
348
+ };
349
+ unwind: (from?: string) => (f?: string) => {
350
+ $unwind: string;
351
+ };
352
+ count: (from?: string) => (f?: string) => {
353
+ $sortByCount: string;
354
+ };
355
+ data: () => never[];
356
+ };
357
+ };
358
+
359
+ declare const toMongoType: (input: unknown) => Json;
360
+
361
+ export { Accumulator, Accumulators, AtlasSearchGateway, Clause, Clauses, Collection, Facet, Filter, FilterBuilder, FindOptions, IncludeBuilder, IndexOptions, Indexes, MongoGateway, MongoProvider, Operator, Projection, Query, SearchDefinition, SortBuilder, asc, desc, lucene, stages, toFilters, toMongoType };