@storecraft/database-mongodb 1.0.20 → 1.0.21

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/src/con.search.js CHANGED
@@ -2,11 +2,9 @@
2
2
  * @import { search as db_col, db_driver } from '@storecraft/core/database'
3
3
  * @import { QuickSearchResource, QuickSearchResult } from '@storecraft/core/api'
4
4
  */
5
-
6
5
  import { MongoDB } from '../index.js'
7
6
  import { query_to_mongo } from './utils.query.js';
8
7
 
9
-
10
8
  /**
11
9
  * @type {(keyof db_driver["resources"])[]}
12
10
  */
@@ -46,9 +44,7 @@ const prefix_to_resource = {
46
44
  }
47
45
 
48
46
  /**
49
- *
50
47
  * @param {string} id
51
- *
52
48
  * @returns {keyof db_driver["resources"]}
53
49
  */
54
50
  export const id_to_resource = id => {
@@ -65,8 +61,6 @@ export const id_to_resource = id => {
65
61
 
66
62
  /**
67
63
  * @param {MongoDB} driver
68
- *
69
- *
70
64
  * @returns {db_col["quicksearch"]}
71
65
  */
72
66
  export const quicksearch = (driver) => {
@@ -151,10 +145,8 @@ export const quicksearch = (driver) => {
151
145
 
152
146
  /**
153
147
  * @param {MongoDB} driver
154
- *
155
- *
156
148
  * @return {db_col}
157
- * */
149
+ */
158
150
  export const impl = (driver) => {
159
151
 
160
152
  return {
package/src/con.shared.js CHANGED
@@ -1,27 +1,28 @@
1
1
  /**
2
- * @import { db_crud, RegularGetOptions } from '@storecraft/core/database'
3
- * @import { ApiQuery, BaseType, Cursor, ExpandQuery, QuickSearchResource, QuickSearchResult, Tuple, withOptionalID } from '@storecraft/core/api'
4
- * @import { VQL } from '@storecraft/core/vql'
2
+ * @import { db_crud, withConcreteId, withConcreteIdAndHandle } from '@storecraft/core/database'
3
+ * @import {
4
+ * BaseType, ExpandQuery, withOptionalID
5
+ * } from '@storecraft/core/api'
5
6
  * @import { WithRelations } from './utils.types.js'
6
7
  * @import { WithId } from 'mongodb'
7
8
  */
8
-
9
9
  import { Collection } from 'mongodb'
10
10
  import { MongoDB } from '../index.js'
11
- import { handle_or_id, isUndef, sanitize_array,
12
- sanitize_one, to_objid } from './utils.funcs.js'
11
+ import {
12
+ handle_or_id, isUndef, sanitize_array,
13
+ sanitize_one, to_objid
14
+ } from './utils.funcs.js'
13
15
  import { query_to_mongo } from './utils.query.js'
14
16
  import { report_document_media } from './con.images.js'
15
17
  import { add_search_terms_relation_on } from './utils.relations.js'
16
18
 
17
19
 
18
20
  /**
19
- * @template {BaseType} T
20
- * @template {BaseType} G
21
- *
21
+ * @description Upsert function for MongoDB
22
+ * @template {Partial<withConcreteIdAndHandle<{}>>} T
23
+ * @template {Partial<withConcreteIdAndHandle<{}>>} G
22
24
  * @param {MongoDB} driver
23
25
  * @param {Collection<G>} col
24
- *
25
26
  * @returns {db_crud<T, G>["upsert"]}
26
27
  */
27
28
  export const upsert_regular = (driver, col) => {
@@ -72,20 +73,6 @@ export const upsert_regular = (driver, col) => {
72
73
 
73
74
  );
74
75
 
75
- // const res = await col.replaceOne(
76
- // // @ts-ignore
77
- // {
78
- // $or: [
79
- // data.id && { _id: to_objid(data.id) },
80
- // data.handle && { handle: data.handle }
81
- // ].filter(Boolean)
82
- // },
83
- // data,
84
- // {
85
- // session, upsert: true
86
- // }
87
- // );
88
-
89
76
  ////
90
77
  // REPORT IMAGES USAGE
91
78
  ////
@@ -105,7 +92,7 @@ export const upsert_regular = (driver, col) => {
105
92
  }
106
93
 
107
94
  /**
108
- * Extract relations names from item
95
+ * @description Extract relations names from item
109
96
  * @template {WithRelations<{}>} T
110
97
  * @param {T} item
111
98
  */
@@ -114,10 +101,8 @@ export const get_relations_names = item => {
114
101
  }
115
102
 
116
103
  /**
117
- * Expand relations in-place
118
- *
104
+ * @description Expand relations in-place
119
105
  * @template {any} T
120
- *
121
106
  * @param {WithRelations<T>[]} items
122
107
  * @param {ExpandQuery<T>} [expand_query]
123
108
  */
@@ -224,7 +209,7 @@ export const get_regular = (driver, col) => {
224
209
  }
225
210
 
226
211
  /**
227
- * get bulk of items, ordered, if something is missing, `undefined`
212
+ * @description get bulk of items, ordered, if something is missing, `undefined`
228
213
  * should be instead
229
214
  * @template {withOptionalID} T
230
215
  * @template {withOptionalID} G
@@ -234,11 +219,10 @@ export const get_regular = (driver, col) => {
234
219
  */
235
220
  export const get_bulk = (driver, col) => {
236
221
  return async (ids, options) => {
237
- const objids = ids.map(handle_or_id)
238
- .map(v => ('_id' in v) ? v._id : undefined)
239
- .filter(Boolean);
240
-
241
-
222
+ const objids = ids
223
+ .map(handle_or_id)
224
+ .map(v => ('_id' in v) ? v._id : undefined)
225
+ .filter(Boolean);
242
226
 
243
227
  const res = /** @type {(WithRelations<WithId<G>>)[]} */ (
244
228
  await col.find(
@@ -264,7 +248,6 @@ export const get_bulk = (driver, col) => {
264
248
  )
265
249
  );
266
250
 
267
-
268
251
  const sanitized = /** @type {G[]} */(
269
252
  /** @type {unknown} */(
270
253
  sanitize_array(res)
@@ -273,7 +256,9 @@ export const get_bulk = (driver, col) => {
273
256
 
274
257
  // now let's order them
275
258
  return ids.map(
276
- id => sanitized.find(s => s.id===id || s?.['handle']===id)
259
+ id => sanitized.find(
260
+ s => s.id===id || s?.['handle']===id
261
+ )
277
262
  );
278
263
 
279
264
  }
@@ -282,12 +267,8 @@ export const get_bulk = (driver, col) => {
282
267
 
283
268
  /**
284
269
  * @template T, G
285
- *
286
- *
287
270
  * @param {MongoDB} driver
288
271
  * @param {Collection<G>} col
289
- *
290
- *
291
272
  * @returns {db_crud<T, G>["remove"]}
292
273
  */
293
274
  export const remove_regular = (driver, col) => {
@@ -321,7 +302,8 @@ export const list_regular = (driver, col) => {
321
302
 
322
303
  /** @type {WithRelations<WithId<G>>[]} */
323
304
  const items = await col.find(
324
- filter, {
305
+ filter,
306
+ {
325
307
  sort,
326
308
  limit: reverse_sign==-1 ? query.limitToLast : query.limit,
327
309
  projection: expand_to_mongo_projection(query?.expand)
@@ -349,12 +331,8 @@ export const list_regular = (driver, col) => {
349
331
  /**
350
332
  * @template {any} T
351
333
  * @template {any} G
352
- *
353
- *
354
334
  * @param {MongoDB} driver
355
335
  * @param {Collection<G>} col
356
- *
357
- *
358
336
  * @returns {db_crud<T, G>["count"]}
359
337
  */
360
338
  export const count_regular = (driver, col) => {
@@ -2,7 +2,6 @@
2
2
  * @import { db_shipping as db_col } from '@storecraft/core/database'
3
3
  * @import { WithRelations } from './utils.types.js'
4
4
  */
5
-
6
5
  import { Collection } from 'mongodb'
7
6
  import { MongoDB } from '../index.js'
8
7
  import { count_regular, get_regular, list_regular } from './con.shared.js'
@@ -22,8 +21,6 @@ const col = (d) => d.collection('shipping_methods');
22
21
 
23
22
  /**
24
23
  * @param {MongoDB} driver
25
- *
26
- *
27
24
  * @returns {db_col["upsert"]}
28
25
  */
29
26
  const upsert = (driver) => {
@@ -79,8 +76,6 @@ const get = (driver) => get_regular(driver, col(driver));
79
76
 
80
77
  /**
81
78
  * @param {MongoDB} driver
82
- *
83
- *
84
79
  * @returns {db_col["remove"]}
85
80
  */
86
81
  const remove = (driver) => {
@@ -136,8 +131,6 @@ const count = (driver) => count_regular(driver, col(driver));
136
131
 
137
132
  /**
138
133
  * @param {MongoDB} driver
139
- *
140
- *
141
134
  * @return {db_col & { _col: ReturnType<col>}}
142
135
  */
143
136
  export const impl = (driver) => {
@@ -5,12 +5,13 @@
5
5
  * @import { StorefrontType } from '@storecraft/core/api'
6
6
  * @import { WithRelations } from './utils.types.js'
7
7
  */
8
-
9
8
  import { Collection } from 'mongodb'
10
9
  import { MongoDB } from '../index.js'
11
- import { count_regular, expand, get_regular, list_regular,
12
- remove_regular } from './con.shared.js'
13
- import { sanitize_array, sanitize_recursively, to_objid } from './utils.funcs.js'
10
+ import {
11
+ count_regular, expand, get_regular, list_regular,
12
+ remove_regular
13
+ } from './con.shared.js'
14
+ import { sanitize_recursively, to_objid } from './utils.funcs.js'
14
15
  import {
15
16
  add_search_terms_relation_on, create_explicit_relation, save_me
16
17
  } from './utils.relations.js';
@@ -24,8 +25,6 @@ const col = (d) => d.collection('storefronts');
24
25
 
25
26
  /**
26
27
  * @param {MongoDB} driver
27
- *
28
- *
29
28
  * @return {db_col["upsert"]}
30
29
  */
31
30
  const upsert = (driver) => {
@@ -223,10 +222,8 @@ const get_default_auto_generated_storefront = (driver) => {
223
222
 
224
223
  /**
225
224
  * @param {MongoDB} driver
226
- *
227
- *
228
225
  * @return {db_col & { _col: ReturnType<col>}}
229
- * */
226
+ */
230
227
  export const impl = (driver) => {
231
228
 
232
229
  return {
package/src/con.tags.js CHANGED
@@ -1,23 +1,21 @@
1
1
  /**
2
2
  * @import { db_tags as db_col } from '@storecraft/core/database'
3
3
  */
4
-
5
- import { Collection } from 'mongodb'
6
- import { MongoDB } from '../index.js'
7
- import { count_regular, get_regular, list_regular,
8
- remove_regular, upsert_regular } from './con.shared.js'
4
+ import { Collection } from 'mongodb';
5
+ import { MongoDB } from '../index.js';
6
+ import {
7
+ count_regular, get_regular, list_regular,
8
+ remove_regular, upsert_regular
9
+ } from './con.shared.js';
9
10
 
10
11
  /**
11
12
  * @param {MongoDB} d
12
- *
13
- *
14
13
  * @returns {Collection<db_col["$type_get"]>}
15
14
  */
16
15
  const col = (d) => d.collection('tags');
17
16
 
18
17
  /**
19
18
  * @param {MongoDB} driver
20
- *
21
19
  * @returns {db_col["upsert"]}
22
20
  */
23
21
  const upsert = (driver) => upsert_regular(driver, col(driver));
@@ -44,10 +42,8 @@ const count = (driver) => count_regular(driver, col(driver));
44
42
 
45
43
  /**
46
44
  * @param {MongoDB} driver
47
- *
48
- *
49
45
  * @return {db_col & { _col: ReturnType<col>}}
50
- * */
46
+ */
51
47
  export const impl = (driver) => {
52
48
 
53
49
  return {
@@ -1,23 +1,21 @@
1
1
  /**
2
2
  * @import { db_templates as db_col } from '@storecraft/core/database'
3
3
  */
4
-
5
4
  import { Collection } from 'mongodb'
6
5
  import { MongoDB } from '../index.js'
7
- import { count_regular, get_regular, list_regular,
8
- remove_regular, upsert_regular } from './con.shared.js'
6
+ import {
7
+ count_regular, get_regular, list_regular,
8
+ remove_regular, upsert_regular
9
+ } from './con.shared.js'
9
10
 
10
11
  /**
11
12
  * @param {MongoDB} d
12
- *
13
- *
14
13
  * @returns {Collection<db_col["$type_get"]>}
15
14
  */
16
15
  const col = (d) => d.collection('templates');
17
16
 
18
17
  /**
19
18
  * @param {MongoDB} driver
20
- *
21
19
  * @returns {db_col["upsert"]}
22
20
  */
23
21
  const upsert = (driver) => upsert_regular(driver, col(driver));
@@ -44,8 +42,6 @@ const count = (driver) => count_regular(driver, col(driver));
44
42
 
45
43
  /**
46
44
  * @param {MongoDB} driver
47
- *
48
- *
49
45
  * @return {db_col & { _col: ReturnType<col>}}
50
46
  * */
51
47
  export const impl = (driver) => {
@@ -11,7 +11,6 @@ export const isDef = v => v!==undefined && v!==null;
11
11
  export const isUndef = v => !isDef(v);
12
12
 
13
13
  /**
14
- *
15
14
  * @param {...any} keys
16
15
  */
17
16
  export const delete_keys = (...keys) => {
@@ -29,7 +28,7 @@ export const delete_keys = (...keys) => {
29
28
  }
30
29
 
31
30
  /**
32
- * Sanitize hidden properties in-place
31
+ * @description Sanitize hidden properties in-place
33
32
  * @template {object} T
34
33
  * @param {T} o
35
34
  * @return {Omit<T, '_id' | '_relations'>}
@@ -46,7 +45,7 @@ export const sanitize_hidden = o => {
46
45
  }
47
46
 
48
47
  /**
49
- * Sanitize hidden properties in-place recursively
48
+ * @description Sanitize hidden properties in-place recursively
50
49
  * @template {object} T
51
50
  * @param {T} o
52
51
  * @return {Omit<T, '_id' | '_relations'>}
@@ -63,7 +62,7 @@ export const sanitize_recursively = o => {
63
62
  }
64
63
 
65
64
  /**
66
- * Sanitize the mongo document before sending to client
65
+ * @description Sanitize the mongo document before sending to client
67
66
  * @template T
68
67
  * @param {WithRelations<T>} o
69
68
  */
@@ -72,7 +71,7 @@ export const sanitize_one = o => {
72
71
  }
73
72
 
74
73
  /**
75
- * Sanitize the mongo document before sending to client
74
+ * @description Sanitize the mongo document before sending to client
76
75
  * @template T
77
76
  * @param {WithRelations<T>[]} o
78
77
  */
@@ -109,7 +108,7 @@ export const to_objid_safe = id => {
109
108
  }
110
109
 
111
110
  /**
112
- * Create a `filter` for `object-id` or `handle`
111
+ * @description Create a `filter` for `object-id` or `handle`
113
112
  * @template {{handle?: string}} G
114
113
  * @param {string} handle_or_id
115
114
  * @returns {Filter<G>}