@storecraft/database-mongodb 1.0.12 → 1.0.14
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/index.js +54 -61
 - package/jsconfig.json +1 -0
 - package/migrate.js +1 -0
 - package/migrations/00001_seed_email_templates.js +1 -0
 - package/migrations/00002_seed_email_templates.js +36 -0
 - package/package.json +6 -2
 - package/src/con.auth_users.js +8 -10
 - package/src/con.collections.js +15 -14
 - package/src/con.customers.js +8 -12
 - package/src/con.discounts.js +8 -13
 - package/src/con.discounts.utils.js +36 -21
 - package/src/con.images.js +7 -6
 - package/src/con.notifications.js +5 -4
 - package/src/con.orders.js +4 -4
 - package/src/con.posts.js +6 -1
 - package/src/con.products.js +12 -17
 - package/src/con.search.js +26 -25
 - package/src/con.shared.js +30 -29
 - package/src/con.shipping.js +6 -5
 - package/src/con.storefronts.js +13 -14
 - package/src/con.tags.js +4 -5
 - package/src/con.templates.js +4 -5
 - package/src/utils.funcs.js +2 -0
 - package/src/utils.query.js +11 -8
 - package/src/utils.relations.js +11 -7
 - package/types.public.d.ts +4 -2
 - package/vector-store/index.js +289 -0
 - package/vector-store/types.d.ts +44 -0
 - package/vector-store/types.private.d.ts +44 -0
 
    
        package/src/con.posts.js
    CHANGED
    
    | 
         @@ -1,3 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { db_posts as db_col } from '@storecraft/core/database'
         
     | 
| 
      
 3 
     | 
    
         
            +
             * @import { WithRelations } from './utils.relations.js'
         
     | 
| 
      
 4 
     | 
    
         
            +
             */
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       1 
6 
     | 
    
         
             
            import { Collection } from 'mongodb'
         
     | 
| 
       2 
7 
     | 
    
         
             
            import { MongoDB } from '../index.js'
         
     | 
| 
       3 
8 
     | 
    
         
             
            import { count_regular, get_regular, list_regular } from './con.shared.js'
         
     | 
| 
         @@ -18,7 +23,7 @@ import { 
     | 
|
| 
       18 
23 
     | 
    
         
             
             * @param {MongoDB} d 
         
     | 
| 
       19 
24 
     | 
    
         
             
             * 
         
     | 
| 
       20 
25 
     | 
    
         
             
             * 
         
     | 
| 
       21 
     | 
    
         
            -
             * @returns {Collection< 
     | 
| 
      
 26 
     | 
    
         
            +
             * @returns {Collection<WithRelations<db_col["$type_get"]>>}
         
     | 
| 
       22 
27 
     | 
    
         
             
             */
         
     | 
| 
       23 
28 
     | 
    
         
             
            const col = (d) => d.collection('posts');
         
     | 
| 
       24 
29 
     | 
    
         | 
    
        package/src/con.products.js
    CHANGED
    
    | 
         @@ -1,3 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { db_products as db_col, RegularGetOptions } from '@storecraft/core/database'
         
     | 
| 
      
 3 
     | 
    
         
            +
             * @import { ProductType, VariantType } from '@storecraft/core/api'
         
     | 
| 
      
 4 
     | 
    
         
            +
             * @import { WithRelations } from './utils.relations.js'
         
     | 
| 
      
 5 
     | 
    
         
            +
             * @import { Filter, AnyBulkWriteOperation } from 'mongodb'
         
     | 
| 
      
 6 
     | 
    
         
            +
             */
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       1 
8 
     | 
    
         
             
            import { Collection } from 'mongodb'
         
     | 
| 
       2 
9 
     | 
    
         
             
            import { MongoDB } from '../index.js'
         
     | 
| 
       3 
10 
     | 
    
         
             
            import { 
         
     | 
| 
         @@ -25,18 +32,11 @@ import { 
     | 
|
| 
       25 
32 
     | 
    
         
             
              test_product_filters_against_product 
         
     | 
| 
       26 
33 
     | 
    
         
             
            } from '@storecraft/core/api/con.pricing.logic.js'
         
     | 
| 
       27 
34 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
            /**
         
     | 
| 
       29 
     | 
    
         
            -
             * @typedef {import('@storecraft/core/database').db_products} db_col
         
     | 
| 
       30 
     | 
    
         
            -
             */
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
35 
     | 
    
         
             
            /**
         
     | 
| 
       33 
36 
     | 
    
         
             
             * @param {MongoDB} d 
         
     | 
| 
       34 
37 
     | 
    
         
             
             * 
         
     | 
| 
       35 
38 
     | 
    
         
             
             * 
         
     | 
| 
       36 
     | 
    
         
            -
             * @returns {Collection<
         
     | 
| 
       37 
     | 
    
         
            -
             *  import('./utils.relations.js').WithRelations<db_col["$type_get"]>
         
     | 
| 
       38 
     | 
    
         
            -
             * >}
         
     | 
| 
       39 
     | 
    
         
            -
             * 
         
     | 
| 
      
 39 
     | 
    
         
            +
             * @returns {Collection<WithRelations<db_col["$type_get"]>>}
         
     | 
| 
       40 
40 
     | 
    
         
             
             */
         
     | 
| 
       41 
41 
     | 
    
         
             
            const col = (d) => d.collection('products');
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
         @@ -304,7 +304,7 @@ const count = (driver) => count_regular(driver, col(driver)); 
     | 
|
| 
       304 
304 
     | 
    
         
             
             */
         
     | 
| 
       305 
305 
     | 
    
         
             
            const list_product_collections = (driver) => {
         
     | 
| 
       306 
306 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       307 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 307 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       308 
308 
     | 
    
         
             
                const options = {
         
     | 
| 
       309 
309 
     | 
    
         
             
                  expand: ['collections']
         
     | 
| 
       310 
310 
     | 
    
         
             
                };
         
     | 
| 
         @@ -329,7 +329,7 @@ const list_product_collections = (driver) => { 
     | 
|
| 
       329 
329 
     | 
    
         
             
             */
         
     | 
| 
       330 
330 
     | 
    
         
             
            const list_product_variants = (driver) => {
         
     | 
| 
       331 
331 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       332 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 332 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       333 
333 
     | 
    
         
             
                const options = {
         
     | 
| 
       334 
334 
     | 
    
         
             
                  expand: ['variants']
         
     | 
| 
       335 
335 
     | 
    
         
             
                };
         
     | 
| 
         @@ -380,7 +380,7 @@ const list_related_products = (driver) => { 
     | 
|
| 
       380 
380 
     | 
    
         
             
             */
         
     | 
| 
       381 
381 
     | 
    
         
             
            const list_product_discounts = (driver) => {
         
     | 
| 
       382 
382 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       383 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 383 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       384 
384 
     | 
    
         
             
                const options = {
         
     | 
| 
       385 
385 
     | 
    
         
             
                  expand: ['discounts']
         
     | 
| 
       386 
386 
     | 
    
         
             
                };
         
     | 
| 
         @@ -462,12 +462,7 @@ const changeStockOfBy = (driver) => { 
     | 
|
| 
       462 
462 
     | 
    
         
             
              return async (product_ids_or_handles, deltas) => {
         
     | 
| 
       463 
463 
     | 
    
         | 
| 
       464 
464 
     | 
    
         
             
                /** 
         
     | 
| 
       465 
     | 
    
         
            -
                 * @type { 
     | 
| 
       466 
     | 
    
         
            -
                 *  import('./utils.relations.js').WithRelations<
         
     | 
| 
       467 
     | 
    
         
            -
                 *    import('@storecraft/core/api').ProductType | 
         
     | 
| 
       468 
     | 
    
         
            -
                 *    import('@storecraft/core/api').VariantType
         
     | 
| 
       469 
     | 
    
         
            -
                 *  >
         
     | 
| 
       470 
     | 
    
         
            -
                 * >[]} 
         
     | 
| 
      
 465 
     | 
    
         
            +
                 * @type {AnyBulkWriteOperation<WithRelations<ProductType | VariantType>>[]}
         
     | 
| 
       471 
466 
     | 
    
         
             
                 */
         
     | 
| 
       472 
467 
     | 
    
         
             
                let ops = []
         
     | 
| 
       473 
468 
     | 
    
         | 
    
        package/src/con.search.js
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import { MongoDB } from '../index.js'
         
     | 
| 
       2 
     | 
    
         
            -
            import { query_to_mongo } from './utils.query.js';
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
1 
     | 
    
         
             
            /**
         
     | 
| 
       5 
     | 
    
         
            -
             * @ 
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { search as db_col, db_driver } from '@storecraft/core/database'
         
     | 
| 
      
 3 
     | 
    
         
            +
             * @import { QuickSearchResource, QuickSearchResult } from '@storecraft/core/api'
         
     | 
| 
       6 
4 
     | 
    
         
             
             */
         
     | 
| 
       7 
5 
     | 
    
         | 
| 
      
 6 
     | 
    
         
            +
            import { MongoDB } from '../index.js'
         
     | 
| 
      
 7 
     | 
    
         
            +
            import { query_to_mongo } from './utils.query.js';
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            /**
         
     | 
| 
       11 
     | 
    
         
            -
             * @type {(keyof  
     | 
| 
      
 11 
     | 
    
         
            +
             * @type {(keyof db_driver["resources"])[]}
         
     | 
| 
       12 
12 
     | 
    
         
             
             */
         
     | 
| 
       13 
13 
     | 
    
         
             
            const tables = [
         
     | 
| 
       14 
14 
     | 
    
         
             
              'tags',
         
     | 
| 
         @@ -26,7 +26,7 @@ const tables = [ 
     | 
|
| 
       26 
26 
     | 
    
         
             
            ]
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
            /**
         
     | 
| 
       29 
     | 
    
         
            -
             * @type {Record<string, keyof  
     | 
| 
      
 29 
     | 
    
         
            +
             * @type {Record<string, keyof db_driver["resources"]>}
         
     | 
| 
       30 
30 
     | 
    
         
             
             */
         
     | 
| 
       31 
31 
     | 
    
         
             
            const prefix_to_resource = {
         
     | 
| 
       32 
32 
     | 
    
         
             
              'au': 'auth_users',
         
     | 
| 
         @@ -49,7 +49,7 @@ const prefix_to_resource = { 
     | 
|
| 
       49 
49 
     | 
    
         
             
             * 
         
     | 
| 
       50 
50 
     | 
    
         
             
             * @param {string} id 
         
     | 
| 
       51 
51 
     | 
    
         
             
             * 
         
     | 
| 
       52 
     | 
    
         
            -
             * @returns {keyof  
     | 
| 
      
 52 
     | 
    
         
            +
             * @returns {keyof db_driver["resources"]}
         
     | 
| 
       53 
53 
     | 
    
         
             
             */
         
     | 
| 
       54 
54 
     | 
    
         
             
            export const id_to_resource = id => {
         
     | 
| 
       55 
55 
     | 
    
         
             
              let result = undefined;
         
     | 
| 
         @@ -102,28 +102,29 @@ export const quicksearch = (driver) => { 
     | 
|
| 
       102 
102 
     | 
    
         | 
| 
       103 
103 
     | 
    
         
             
                const db = driver.mongo_client.db(driver.name);
         
     | 
| 
       104 
104 
     | 
    
         | 
| 
       105 
     | 
    
         
            -
                 
     | 
| 
       106 
     | 
    
         
            -
                const items =  
     | 
| 
       107 
     | 
    
         
            -
                  [
         
     | 
| 
       108 
     | 
    
         
            -
                     
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
                       
     | 
| 
       111 
     | 
    
         
            -
                         
     | 
| 
       112 
     | 
    
         
            -
                           
     | 
| 
       113 
     | 
    
         
            -
                             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
                
         
     | 
| 
      
 106 
     | 
    
         
            +
                const items = /** @type {QuickSearchResource[]} */ (
         
     | 
| 
      
 107 
     | 
    
         
            +
                  await db.collection(tables_filtered[0]).aggregate(
         
     | 
| 
      
 108 
     | 
    
         
            +
                    [
         
     | 
| 
      
 109 
     | 
    
         
            +
                      ...pipeline,
         
     | 
| 
      
 110 
     | 
    
         
            +
                      ...tables_filtered.slice(1).map(
         
     | 
| 
      
 111 
     | 
    
         
            +
                        t => (
         
     | 
| 
      
 112 
     | 
    
         
            +
                          {
         
     | 
| 
      
 113 
     | 
    
         
            +
                            $unionWith: {
         
     | 
| 
      
 114 
     | 
    
         
            +
                              coll: t,
         
     | 
| 
      
 115 
     | 
    
         
            +
                              pipeline: pipeline
         
     | 
| 
      
 116 
     | 
    
         
            +
                            }
         
     | 
| 
       115 
117 
     | 
    
         
             
                          }
         
     | 
| 
       116 
     | 
    
         
            -
                         
     | 
| 
      
 118 
     | 
    
         
            +
                        )
         
     | 
| 
       117 
119 
     | 
    
         
             
                      )
         
     | 
| 
       118 
     | 
    
         
            -
                     
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                ).toArray();
         
     | 
| 
      
 120 
     | 
    
         
            +
                    ], 
         
     | 
| 
      
 121 
     | 
    
         
            +
                    {
         
     | 
| 
      
 122 
     | 
    
         
            +
                    }
         
     | 
| 
      
 123 
     | 
    
         
            +
                  ).toArray()
         
     | 
| 
      
 124 
     | 
    
         
            +
                );
         
     | 
| 
       124 
125 
     | 
    
         | 
| 
       125 
126 
     | 
    
         | 
| 
       126 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 127 
     | 
    
         
            +
                /** @type {QuickSearchResult} */
         
     | 
| 
       127 
128 
     | 
    
         
             
                const result = {};
         
     | 
| 
       128 
129 
     | 
    
         | 
| 
       129 
130 
     | 
    
         
             
                items.reduce(
         
     | 
    
        package/src/con.shared.js
    CHANGED
    
    | 
         @@ -1,3 +1,11 @@ 
     | 
|
| 
      
 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'
         
     | 
| 
      
 5 
     | 
    
         
            +
             * @import { WithRelations } from './utils.relations.js'
         
     | 
| 
      
 6 
     | 
    
         
            +
             * @import { WithId } from 'mongodb'
         
     | 
| 
      
 7 
     | 
    
         
            +
             */
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       1 
9 
     | 
    
         
             
            import { Collection } from 'mongodb'
         
     | 
| 
       2 
10 
     | 
    
         
             
            import { MongoDB } from '../index.js'
         
     | 
| 
       3 
11 
     | 
    
         
             
            import { handle_or_id, isUndef, sanitize_array, 
         
     | 
| 
         @@ -8,18 +16,16 @@ import { add_search_terms_relation_on } from './utils.relations.js' 
     | 
|
| 
       8 
16 
     | 
    
         | 
| 
       9 
17 
     | 
    
         | 
| 
       10 
18 
     | 
    
         
             
            /**
         
     | 
| 
       11 
     | 
    
         
            -
             * @template { 
     | 
| 
       12 
     | 
    
         
            -
             * @template { 
     | 
| 
       13 
     | 
    
         
            -
             * 
         
     | 
| 
      
 19 
     | 
    
         
            +
             * @template {BaseType} T
         
     | 
| 
      
 20 
     | 
    
         
            +
             * @template {BaseType} G
         
     | 
| 
       14 
21 
     | 
    
         
             
             * 
         
     | 
| 
       15 
22 
     | 
    
         
             
             * @param {MongoDB} driver 
         
     | 
| 
       16 
23 
     | 
    
         
             
             * @param {Collection<G>} col 
         
     | 
| 
       17 
24 
     | 
    
         
             
             * 
         
     | 
| 
       18 
     | 
    
         
            -
             * 
         
     | 
| 
       19 
     | 
    
         
            -
             * @returns {import('@storecraft/core/database').db_crud<T, G>["upsert"]}
         
     | 
| 
       20 
     | 
    
         
            -
             * 
         
     | 
| 
      
 25 
     | 
    
         
            +
             * @returns {db_crud<T, G>["upsert"]}
         
     | 
| 
       21 
26 
     | 
    
         
             
             */
         
     | 
| 
       22 
27 
     | 
    
         
             
            export const upsert_regular = (driver, col) => {
         
     | 
| 
      
 28 
     | 
    
         
            +
              
         
     | 
| 
       23 
29 
     | 
    
         
             
              return async (data, search_terms=[]) => {
         
     | 
| 
       24 
30 
     | 
    
         | 
| 
       25 
31 
     | 
    
         
             
                data = {...data};
         
     | 
| 
         @@ -82,13 +88,10 @@ export const get_relations_names = item => { 
     | 
|
| 
       82 
88 
     | 
    
         
             
            /**
         
     | 
| 
       83 
89 
     | 
    
         
             
             * Expand relations in-place
         
     | 
| 
       84 
90 
     | 
    
         
             
             * 
         
     | 
| 
       85 
     | 
    
         
            -
             * 
         
     | 
| 
       86 
91 
     | 
    
         
             
             * @template {any} T
         
     | 
| 
       87 
92 
     | 
    
         
             
             * 
         
     | 
| 
       88 
     | 
    
         
            -
             * 
         
     | 
| 
       89 
     | 
    
         
            -
             * @param { 
     | 
| 
       90 
     | 
    
         
            -
             * @param {import('@storecraft/core/api').ExpandQuery} [expand_query] 
         
     | 
| 
       91 
     | 
    
         
            -
             * 
         
     | 
| 
      
 93 
     | 
    
         
            +
             * @param {WithRelations<T>[]} items
         
     | 
| 
      
 94 
     | 
    
         
            +
             * @param {ExpandQuery<T>} [expand_query] 
         
     | 
| 
       92 
95 
     | 
    
         
             
             */
         
     | 
| 
       93 
96 
     | 
    
         
             
            export const expand = (items, expand_query=undefined) => {
         
     | 
| 
       94 
97 
     | 
    
         | 
| 
         @@ -100,9 +103,9 @@ export const expand = (items, expand_query=undefined) => { 
     | 
|
| 
       100 
103 
     | 
    
         
             
              const all = expand_query.includes('*');
         
     | 
| 
       101 
104 
     | 
    
         | 
| 
       102 
105 
     | 
    
         
             
              for(const item of items) {
         
     | 
| 
       103 
     | 
    
         
            -
                 
     | 
| 
      
 106 
     | 
    
         
            +
                const what_to_expand = all ? get_relations_names(item) : expand_query;
         
     | 
| 
       104 
107 
     | 
    
         | 
| 
       105 
     | 
    
         
            -
                for(const e of ( 
     | 
| 
      
 108 
     | 
    
         
            +
                for(const e of (what_to_expand ?? [])) {
         
     | 
| 
       106 
109 
     | 
    
         
             
                  // try to find embedded documents relations
         
     | 
| 
       107 
110 
     | 
    
         
             
                  const rel = item?._relations?.[e];
         
     | 
| 
       108 
111 
     | 
    
         
             
                  if(rel===undefined || rel===null)
         
     | 
| 
         @@ -141,8 +144,8 @@ export const zeroed_relations = { 
     | 
|
| 
       141 
144 
     | 
    
         | 
| 
       142 
145 
     | 
    
         | 
| 
       143 
146 
     | 
    
         
             
            /**
         
     | 
| 
       144 
     | 
    
         
            -
             * 
         
     | 
| 
       145 
     | 
    
         
            -
             * @param { 
     | 
| 
      
 147 
     | 
    
         
            +
             * @template T
         
     | 
| 
      
 148 
     | 
    
         
            +
             * @param {ExpandQuery<T>} expand 
         
     | 
| 
       146 
149 
     | 
    
         
             
             */
         
     | 
| 
       147 
150 
     | 
    
         
             
            export const expand_to_mongo_projection = (expand) => {
         
     | 
| 
       148 
151 
     | 
    
         
             
              let projection = {}
         
     | 
| 
         @@ -163,18 +166,16 @@ export const expand_to_mongo_projection = (expand) => { 
     | 
|
| 
       163 
166 
     | 
    
         
             
            /**
         
     | 
| 
       164 
167 
     | 
    
         
             
             * @template T, G
         
     | 
| 
       165 
168 
     | 
    
         
             
             * 
         
     | 
| 
       166 
     | 
    
         
            -
             * 
         
     | 
| 
       167 
169 
     | 
    
         
             
             * @param {MongoDB} driver 
         
     | 
| 
       168 
170 
     | 
    
         
             
             * @param {Collection<G>} col 
         
     | 
| 
       169 
171 
     | 
    
         
             
             * 
         
     | 
| 
       170 
     | 
    
         
            -
             * 
         
     | 
| 
       171 
     | 
    
         
            -
             * @returns {import('@storecraft/core/database').db_crud<T, G>["get"]}
         
     | 
| 
      
 172 
     | 
    
         
            +
             * @returns {db_crud<T, G>["get"]}
         
     | 
| 
       172 
173 
     | 
    
         
             
             */
         
     | 
| 
       173 
174 
     | 
    
         
             
            export const get_regular = (driver, col) => {
         
     | 
| 
       174 
175 
     | 
    
         
             
              return async (id_or_handle, options) => {
         
     | 
| 
       175 
176 
     | 
    
         
             
                const filter = handle_or_id(id_or_handle);
         
     | 
| 
       176 
177 
     | 
    
         | 
| 
       177 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 178 
     | 
    
         
            +
                /** @type {WithRelations<WithId<G>>} */
         
     | 
| 
       178 
179 
     | 
    
         
             
                const res = await col.findOne(
         
     | 
| 
       179 
180 
     | 
    
         
             
                  filter,
         
     | 
| 
       180 
181 
     | 
    
         
             
                  {
         
     | 
| 
         @@ -194,15 +195,15 @@ export const get_regular = (driver, col) => { 
     | 
|
| 
       194 
195 
     | 
    
         
             
             * should be instead
         
     | 
| 
       195 
196 
     | 
    
         
             
             * 
         
     | 
| 
       196 
197 
     | 
    
         
             
             * 
         
     | 
| 
       197 
     | 
    
         
            -
             * @template { 
     | 
| 
       198 
     | 
    
         
            -
             * @template { 
     | 
| 
      
 198 
     | 
    
         
            +
             * @template {withOptionalID} T
         
     | 
| 
      
 199 
     | 
    
         
            +
             * @template {withOptionalID} G
         
     | 
| 
       199 
200 
     | 
    
         
             
             * 
         
     | 
| 
       200 
201 
     | 
    
         
             
             * 
         
     | 
| 
       201 
202 
     | 
    
         
             
             * @param {MongoDB} driver 
         
     | 
| 
       202 
203 
     | 
    
         
             
             * @param {Collection<G>} col 
         
     | 
| 
       203 
204 
     | 
    
         
             
             * 
         
     | 
| 
       204 
205 
     | 
    
         
             
             * 
         
     | 
| 
       205 
     | 
    
         
            -
             * @returns { 
     | 
| 
      
 206 
     | 
    
         
            +
             * @returns {db_crud<T, G>["getBulk"]}
         
     | 
| 
       206 
207 
     | 
    
         
             
             */
         
     | 
| 
       207 
208 
     | 
    
         
             
            export const get_bulk = (driver, col) => {
         
     | 
| 
       208 
209 
     | 
    
         
             
              return async (ids, options) => {
         
     | 
| 
         @@ -247,7 +248,7 @@ export const get_bulk = (driver, col) => { 
     | 
|
| 
       247 
248 
     | 
    
         
             
             * @param {Collection<G>} col 
         
     | 
| 
       248 
249 
     | 
    
         
             
             * 
         
     | 
| 
       249 
250 
     | 
    
         
             
             * 
         
     | 
| 
       250 
     | 
    
         
            -
             * @returns { 
     | 
| 
      
 251 
     | 
    
         
            +
             * @returns {db_crud<T, G>["remove"]}
         
     | 
| 
       251 
252 
     | 
    
         
             
             */
         
     | 
| 
       252 
253 
     | 
    
         
             
            export const remove_regular = (driver, col) => {
         
     | 
| 
       253 
254 
     | 
    
         
             
              return async (id_or_handle) => {
         
     | 
| 
         @@ -261,15 +262,15 @@ export const remove_regular = (driver, col) => { 
     | 
|
| 
       261 
262 
     | 
    
         
             
            }
         
     | 
| 
       262 
263 
     | 
    
         | 
| 
       263 
264 
     | 
    
         
             
            /**
         
     | 
| 
       264 
     | 
    
         
            -
             * @template  
     | 
| 
       265 
     | 
    
         
            -
             * @template  
     | 
| 
      
 265 
     | 
    
         
            +
             * @template T
         
     | 
| 
      
 266 
     | 
    
         
            +
             * @template G
         
     | 
| 
       266 
267 
     | 
    
         
             
             * 
         
     | 
| 
       267 
268 
     | 
    
         
             
             * 
         
     | 
| 
       268 
269 
     | 
    
         
             
             * @param {MongoDB} driver 
         
     | 
| 
       269 
270 
     | 
    
         
             
             * @param {Collection<G>} col 
         
     | 
| 
       270 
271 
     | 
    
         
             
             * 
         
     | 
| 
       271 
272 
     | 
    
         
             
             * 
         
     | 
| 
       272 
     | 
    
         
            -
             * @returns { 
     | 
| 
      
 273 
     | 
    
         
            +
             * @returns {db_crud<T, G>["list"]}
         
     | 
| 
       273 
274 
     | 
    
         
             
             */
         
     | 
| 
       274 
275 
     | 
    
         
             
            export const list_regular = (driver, col) => {
         
     | 
| 
       275 
276 
     | 
    
         
             
              return async (query) => {
         
     | 
| 
         @@ -282,7 +283,7 @@ export const list_regular = (driver, col) => { 
     | 
|
| 
       282 
283 
     | 
    
         
             
                // console.log('sort', sort)
         
     | 
| 
       283 
284 
     | 
    
         
             
                // console.log('expand', query?.expand)
         
     | 
| 
       284 
285 
     | 
    
         | 
| 
       285 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 286 
     | 
    
         
            +
                /** @type {WithRelations<WithId<G>>[]} */
         
     | 
| 
       286 
287 
     | 
    
         
             
                const items = await col.find(
         
     | 
| 
       287 
288 
     | 
    
         
             
                  filter,  {
         
     | 
| 
       288 
289 
     | 
    
         
             
                    sort, 
         
     | 
| 
         @@ -295,7 +296,7 @@ export const list_regular = (driver, col) => { 
     | 
|
| 
       295 
296 
     | 
    
         | 
| 
       296 
297 
     | 
    
         
             
                // try expand relations, that were asked
         
     | 
| 
       297 
298 
     | 
    
         
             
                const items_expended = expand(items, query?.expand);
         
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
      
 299 
     | 
    
         
            +
                
         
     | 
| 
       299 
300 
     | 
    
         
             
                const sanitized = sanitize_array(items_expended);
         
     | 
| 
       300 
301 
     | 
    
         | 
| 
       301 
302 
     | 
    
         
             
                // console.log('sanitized', sanitized)
         
     | 
| 
         @@ -313,7 +314,7 @@ export const list_regular = (driver, col) => { 
     | 
|
| 
       313 
314 
     | 
    
         
             
             * @param {Collection<G>} col 
         
     | 
| 
       314 
315 
     | 
    
         
             
             * 
         
     | 
| 
       315 
316 
     | 
    
         
             
             * 
         
     | 
| 
       316 
     | 
    
         
            -
             * @returns { 
     | 
| 
      
 317 
     | 
    
         
            +
             * @returns {db_crud<T, G>["count"]}
         
     | 
| 
       317 
318 
     | 
    
         
             
             */
         
     | 
| 
       318 
319 
     | 
    
         
             
            export const count_regular = (driver, col) => {
         
     | 
| 
       319 
320 
     | 
    
         
             
              return async (query) => {
         
     | 
    
        package/src/con.shipping.js
    CHANGED
    
    | 
         @@ -1,3 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { db_shipping as db_col } from '@storecraft/core/database'
         
     | 
| 
      
 3 
     | 
    
         
            +
             * @import { WithRelations } from './utils.relations.js'
         
     | 
| 
      
 4 
     | 
    
         
            +
             */
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       1 
6 
     | 
    
         
             
            import { Collection } from 'mongodb'
         
     | 
| 
       2 
7 
     | 
    
         
             
            import { MongoDB } from '../index.js'
         
     | 
| 
       3 
8 
     | 
    
         
             
            import { count_regular, get_regular, list_regular } from './con.shared.js'
         
     | 
| 
         @@ -9,15 +14,11 @@ import { 
     | 
|
| 
       9 
14 
     | 
    
         
             
              update_entry_on_all_connection_of_relation 
         
     | 
| 
       10 
15 
     | 
    
         
             
            } from './utils.relations.js';
         
     | 
| 
       11 
16 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            /**
         
     | 
| 
       13 
     | 
    
         
            -
             * @typedef {import('@storecraft/core/database').db_shipping} db_col
         
     | 
| 
       14 
     | 
    
         
            -
             */
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
17 
     | 
    
         
             
            /**
         
     | 
| 
       17 
18 
     | 
    
         
             
             * @param {MongoDB} d 
         
     | 
| 
       18 
19 
     | 
    
         
             
             * 
         
     | 
| 
       19 
20 
     | 
    
         
             
             * 
         
     | 
| 
       20 
     | 
    
         
            -
             * @returns {Collection< 
     | 
| 
      
 21 
     | 
    
         
            +
             * @returns {Collection<WithRelations<db_col["$type_get"]>>}
         
     | 
| 
       21 
22 
     | 
    
         
             
             */
         
     | 
| 
       22 
23 
     | 
    
         
             
            const col = (d) => d.collection('shipping_methods');
         
     | 
| 
       23 
24 
     | 
    
         | 
    
        package/src/con.storefronts.js
    CHANGED
    
    | 
         @@ -1,3 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { 
         
     | 
| 
      
 3 
     | 
    
         
            +
             *  db_storefronts as db_col, RegularGetOptions 
         
     | 
| 
      
 4 
     | 
    
         
            +
             * } from '@storecraft/core/database'
         
     | 
| 
      
 5 
     | 
    
         
            +
             * @import { WithRelations } from './utils.relations.js'
         
     | 
| 
      
 6 
     | 
    
         
            +
             */
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       1 
8 
     | 
    
         
             
            import { Collection } from 'mongodb'
         
     | 
| 
       2 
9 
     | 
    
         
             
            import { MongoDB } from '../index.js'
         
     | 
| 
       3 
10 
     | 
    
         
             
            import { count_regular, get_regular, list_regular, 
         
     | 
| 
         @@ -8,18 +15,10 @@ import { 
     | 
|
| 
       8 
15 
     | 
    
         
             
            } from './utils.relations.js';
         
     | 
| 
       9 
16 
     | 
    
         
             
            import { report_document_media } from './con.images.js';
         
     | 
| 
       10 
17 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
            /**
         
     | 
| 
       12 
     | 
    
         
            -
             * @typedef {import('@storecraft/core/database').db_storefronts} db_col
         
     | 
| 
       13 
     | 
    
         
            -
             */
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
18 
     | 
    
         
             
            /**
         
     | 
| 
       16 
19 
     | 
    
         
             
             * @param {MongoDB} d 
         
     | 
| 
       17 
20 
     | 
    
         
             
             * 
         
     | 
| 
       18 
     | 
    
         
            -
             * 
         
     | 
| 
       19 
     | 
    
         
            -
             * @returns {Collection<
         
     | 
| 
       20 
     | 
    
         
            -
             *  import('./utils.relations.js').WithRelations<db_col["$type_get"]>>
         
     | 
| 
       21 
     | 
    
         
            -
             * }
         
     | 
| 
       22 
     | 
    
         
            -
             * 
         
     | 
| 
      
 21 
     | 
    
         
            +
             * @returns {Collection<WithRelations<db_col["$type_get"]>>}
         
     | 
| 
       23 
22 
     | 
    
         
             
             */
         
     | 
| 
       24 
23 
     | 
    
         
             
            const col = (d) => d.collection('storefronts');
         
     | 
| 
       25 
24 
     | 
    
         | 
| 
         @@ -113,7 +112,7 @@ const count = (driver) => count_regular(driver, col(driver)); 
     | 
|
| 
       113 
112 
     | 
    
         
             
             */
         
     | 
| 
       114 
113 
     | 
    
         
             
            const list_storefront_products = (driver) => {
         
     | 
| 
       115 
114 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       116 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 115 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       117 
116 
     | 
    
         
             
                const options = {
         
     | 
| 
       118 
117 
     | 
    
         
             
                  expand: ['products']
         
     | 
| 
       119 
118 
     | 
    
         
             
                };
         
     | 
| 
         @@ -132,7 +131,7 @@ const list_storefront_products = (driver) => { 
     | 
|
| 
       132 
131 
     | 
    
         
             
             */
         
     | 
| 
       133 
132 
     | 
    
         
             
            const list_storefront_collections = (driver) => {
         
     | 
| 
       134 
133 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       135 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 134 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       136 
135 
     | 
    
         
             
                const options = {
         
     | 
| 
       137 
136 
     | 
    
         
             
                  expand: ['collections']
         
     | 
| 
       138 
137 
     | 
    
         
             
                };
         
     | 
| 
         @@ -151,7 +150,7 @@ const list_storefront_collections = (driver) => { 
     | 
|
| 
       151 
150 
     | 
    
         
             
             */
         
     | 
| 
       152 
151 
     | 
    
         
             
            const list_storefront_discounts = (driver) => {
         
     | 
| 
       153 
152 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       154 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 153 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       155 
154 
     | 
    
         
             
                const options = {
         
     | 
| 
       156 
155 
     | 
    
         
             
                  expand: ['discounts']
         
     | 
| 
       157 
156 
     | 
    
         
             
                };
         
     | 
| 
         @@ -169,7 +168,7 @@ const list_storefront_discounts = (driver) => { 
     | 
|
| 
       169 
168 
     | 
    
         
             
             */
         
     | 
| 
       170 
169 
     | 
    
         
             
            const list_storefront_shipping_methods = (driver) => {
         
     | 
| 
       171 
170 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       172 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 171 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       173 
172 
     | 
    
         
             
                const options = {
         
     | 
| 
       174 
173 
     | 
    
         
             
                  expand: ['shipping_methods']
         
     | 
| 
       175 
174 
     | 
    
         
             
                };
         
     | 
| 
         @@ -188,7 +187,7 @@ const list_storefront_shipping_methods = (driver) => { 
     | 
|
| 
       188 
187 
     | 
    
         
             
             */
         
     | 
| 
       189 
188 
     | 
    
         
             
            const list_storefront_posts = (driver) => {
         
     | 
| 
       190 
189 
     | 
    
         
             
              return async (product) => {
         
     | 
| 
       191 
     | 
    
         
            -
                /** @type { 
     | 
| 
      
 190 
     | 
    
         
            +
                /** @type {RegularGetOptions} */
         
     | 
| 
       192 
191 
     | 
    
         
             
                const options = {
         
     | 
| 
       193 
192 
     | 
    
         
             
                  expand: ['posts']
         
     | 
| 
       194 
193 
     | 
    
         
             
                };
         
     | 
    
        package/src/con.tags.js
    CHANGED
    
    | 
         @@ -1,13 +1,12 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { db_tags as db_col } from '@storecraft/core/database'
         
     | 
| 
      
 3 
     | 
    
         
            +
             */
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       1 
5 
     | 
    
         
             
            import { Collection } from 'mongodb'
         
     | 
| 
       2 
6 
     | 
    
         
             
            import { MongoDB } from '../index.js'
         
     | 
| 
       3 
7 
     | 
    
         
             
            import { count_regular, get_regular, list_regular, 
         
     | 
| 
       4 
8 
     | 
    
         
             
              remove_regular, upsert_regular } from './con.shared.js'
         
     | 
| 
       5 
9 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            /**
         
     | 
| 
       7 
     | 
    
         
            -
             * @typedef {import('@storecraft/core/database').db_tags} db_col
         
     | 
| 
       8 
     | 
    
         
            -
             */
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
10 
     | 
    
         
             
            /**
         
     | 
| 
       12 
11 
     | 
    
         
             
             * @param {MongoDB} d 
         
     | 
| 
       13 
12 
     | 
    
         
             
             * 
         
     | 
    
        package/src/con.templates.js
    CHANGED
    
    | 
         @@ -1,13 +1,12 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { db_templates as db_col } from '@storecraft/core/database'
         
     | 
| 
      
 3 
     | 
    
         
            +
             */
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       1 
5 
     | 
    
         
             
            import { Collection } from 'mongodb'
         
     | 
| 
       2 
6 
     | 
    
         
             
            import { MongoDB } from '../index.js'
         
     | 
| 
       3 
7 
     | 
    
         
             
            import { count_regular, get_regular, list_regular, 
         
     | 
| 
       4 
8 
     | 
    
         
             
              remove_regular, upsert_regular } from './con.shared.js'
         
     | 
| 
       5 
9 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            /**
         
     | 
| 
       7 
     | 
    
         
            -
             * @typedef {import('@storecraft/core/database').db_templates} db_col
         
     | 
| 
       8 
     | 
    
         
            -
             */
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
10 
     | 
    
         
             
            /**
         
     | 
| 
       12 
11 
     | 
    
         
             
             * @param {MongoDB} d 
         
     | 
| 
       13 
12 
     | 
    
         
             
             * 
         
     | 
    
        package/src/utils.funcs.js
    CHANGED
    
    | 
         @@ -140,10 +140,12 @@ export const handle_or_id = (handle_or_id) => { 
     | 
|
| 
       140 
140 
     | 
    
         
             
             */
         
     | 
| 
       141 
141 
     | 
    
         
             
            export const objid_or_else_filter = (id_or_else, else_key='handle') => {
         
     | 
| 
       142 
142 
     | 
    
         
             
              try {
         
     | 
| 
      
 143 
     | 
    
         
            +
                // @ts-ignore
         
     | 
| 
       143 
144 
     | 
    
         
             
                return {
         
     | 
| 
       144 
145 
     | 
    
         
             
                  _id: to_objid(id_or_else)
         
     | 
| 
       145 
146 
     | 
    
         
             
                }
         
     | 
| 
       146 
147 
     | 
    
         
             
              } catch (e) {
         
     | 
| 
      
 148 
     | 
    
         
            +
                // @ts-ignore
         
     | 
| 
       147 
149 
     | 
    
         
             
                return {
         
     | 
| 
       148 
150 
     | 
    
         
             
                  [else_key]: id_or_else
         
     | 
| 
       149 
151 
     | 
    
         
             
                }
         
     | 
    
        package/src/utils.query.js
    CHANGED
    
    | 
         @@ -1,3 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { ApiQuery, Cursor, Tuple } from '@storecraft/core/api'
         
     | 
| 
      
 3 
     | 
    
         
            +
             * @import { VQL } from '@storecraft/core/vql'
         
     | 
| 
      
 4 
     | 
    
         
            +
             */
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       1 
6 
     | 
    
         
             
            import { to_objid } from "./utils.funcs.js";
         
     | 
| 
       2 
7 
     | 
    
         
             
            import { parse } from "@storecraft/core/vql";
         
     | 
| 
       3 
8 
     | 
    
         | 
| 
         @@ -17,7 +22,7 @@ let a = { 
     | 
|
| 
       17 
22 
     | 
    
         
             
             * 4. (a1, a2, a3) >= (b1, b2, b3) ==> (a1 > b1) || (a1=b1 & a2>b2) || (a1=b1 & a2=b2 & a3>=b3)
         
     | 
| 
       18 
23 
     | 
    
         
             
             * 
         
     | 
| 
       19 
24 
     | 
    
         
             
             * 
         
     | 
| 
       20 
     | 
    
         
            -
             * @param { 
     | 
| 
      
 25 
     | 
    
         
            +
             * @param {Cursor} c 
         
     | 
| 
       21 
26 
     | 
    
         
             
             * @param {'>' | '>=' | '<' | '<='} relation 
         
     | 
| 
       22 
27 
     | 
    
         
             
             * @param {(x: [k: string, v: any]) => [k: string, v: any]} transformer 
         
     | 
| 
       23 
28 
     | 
    
         
             
             * Your chance to change key and value
         
     | 
| 
         @@ -70,7 +75,7 @@ export const query_cursor_to_mongo = (c, relation, transformer=(x)=>x) => { 
     | 
|
| 
       70 
75 
     | 
    
         
             
            }
         
     | 
| 
       71 
76 
     | 
    
         | 
| 
       72 
77 
     | 
    
         
             
            /**
         
     | 
| 
       73 
     | 
    
         
            -
             * @param { 
     | 
| 
      
 78 
     | 
    
         
            +
             * @param {VQL.Node} node 
         
     | 
| 
       74 
79 
     | 
    
         
             
             */
         
     | 
| 
       75 
80 
     | 
    
         
             
            export const query_vql_node_to_mongo = node => {
         
     | 
| 
       76 
81 
     | 
    
         
             
              if(node.op==='LEAF') {
         
     | 
| 
         @@ -106,7 +111,7 @@ export const query_vql_node_to_mongo = node => { 
     | 
|
| 
       106 
111 
     | 
    
         | 
| 
       107 
112 
     | 
    
         
             
            /**
         
     | 
| 
       108 
113 
     | 
    
         
             
             * 
         
     | 
| 
       109 
     | 
    
         
            -
             * @param { 
     | 
| 
      
 114 
     | 
    
         
            +
             * @param {VQL.Node} root 
         
     | 
| 
       110 
115 
     | 
    
         
             
             */
         
     | 
| 
       111 
116 
     | 
    
         
             
            export const query_vql_to_mongo = root => {
         
     | 
| 
       112 
117 
     | 
    
         
             
              return root ? query_vql_node_to_mongo(root) : undefined;
         
     | 
| 
         @@ -115,23 +120,21 @@ export const query_vql_to_mongo = root => { 
     | 
|
| 
       115 
120 
     | 
    
         
             
            /**
         
     | 
| 
       116 
121 
     | 
    
         
             
             * Let's transform ids into mongo ids
         
     | 
| 
       117 
122 
     | 
    
         
             
             * 
         
     | 
| 
       118 
     | 
    
         
            -
             * 
         
     | 
| 
       119 
     | 
    
         
            -
             * @param {import("@storecraft/core/api").Tuple<string>} c a cursor record
         
     | 
| 
       120 
     | 
    
         
            -
             * 
         
     | 
| 
      
 123 
     | 
    
         
            +
             * @param {Tuple} c a cursor record
         
     | 
| 
       121 
124 
     | 
    
         
             
             * 
         
     | 
| 
       122 
125 
     | 
    
         
             
             * @returns {[k: string, v: any]}
         
     | 
| 
       123 
126 
     | 
    
         
             
             */
         
     | 
| 
       124 
127 
     | 
    
         
             
            const transform = c => {
         
     | 
| 
       125 
128 
     | 
    
         
             
              if(c[0]!=='id') 
         
     | 
| 
       126 
129 
     | 
    
         
             
                return c;
         
     | 
| 
       127 
     | 
    
         
            -
              return [ '_id', to_objid(c[1]) ];
         
     | 
| 
      
 130 
     | 
    
         
            +
              return [ '_id', to_objid(String(c[1])) ];
         
     | 
| 
       128 
131 
     | 
    
         
             
            }
         
     | 
| 
       129 
132 
     | 
    
         | 
| 
       130 
133 
     | 
    
         
             
            /**
         
     | 
| 
       131 
134 
     | 
    
         
             
             * Convert an API Query into mongo dialect, also sanitize.
         
     | 
| 
       132 
135 
     | 
    
         
             
             * 
         
     | 
| 
       133 
136 
     | 
    
         
             
             * 
         
     | 
| 
       134 
     | 
    
         
            -
             * @param { 
     | 
| 
      
 137 
     | 
    
         
            +
             * @param {ApiQuery<any>} q 
         
     | 
| 
       135 
138 
     | 
    
         
             
             */
         
     | 
| 
       136 
139 
     | 
    
         
             
            export const query_to_mongo = (q) => {
         
     | 
| 
       137 
140 
     | 
    
         
             
              try {
         
     | 
    
        package/src/utils.relations.js
    CHANGED
    
    | 
         @@ -1,3 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /**
         
     | 
| 
      
 2 
     | 
    
         
            +
             * @import { ID } from '@storecraft/core/database'
         
     | 
| 
      
 3 
     | 
    
         
            +
             * @import { BaseType } from '@storecraft/core/api'
         
     | 
| 
      
 4 
     | 
    
         
            +
             * @import { WithRelations } from './utils.relations.js'
         
     | 
| 
      
 5 
     | 
    
         
            +
             * @import { Filter } from 'mongodb'
         
     | 
| 
      
 6 
     | 
    
         
            +
             */
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       1 
8 
     | 
    
         
             
            import { ClientSession, ObjectId } from 'mongodb';
         
     | 
| 
       2 
9 
     | 
    
         
             
            import { isDef, isUndef, to_objid } from './utils.funcs.js';
         
     | 
| 
       3 
10 
     | 
    
         
             
            import { MongoDB } from '../index.js';
         
     | 
| 
         @@ -6,12 +13,9 @@ import { zeroed_relations } from './con.shared.js'; 
     | 
|
| 
       6 
13 
     | 
    
         
             
            /**
         
     | 
| 
       7 
14 
     | 
    
         
             
             * @template {any} T
         
     | 
| 
       8 
15 
     | 
    
         
             
             * 
         
     | 
| 
       9 
     | 
    
         
            -
             * 
         
     | 
| 
       10 
16 
     | 
    
         
             
             * @typedef {Object} Relation
         
     | 
| 
       11 
17 
     | 
    
         
             
             * @property {ObjectId[]} [ids]
         
     | 
| 
       12 
     | 
    
         
            -
             * @property {Record<
         
     | 
| 
       13 
     | 
    
         
            -
             *  import('@storecraft/core/database').ID, T>
         
     | 
| 
       14 
     | 
    
         
            -
             * } [entries]
         
     | 
| 
      
 18 
     | 
    
         
            +
             * @property {Record<ID, T>} [entries]
         
     | 
| 
       15 
19 
     | 
    
         
             
             */
         
     | 
| 
       16 
20 
     | 
    
         | 
| 
       17 
21 
     | 
    
         
             
            /**
         
     | 
| 
         @@ -27,7 +31,7 @@ import { zeroed_relations } from './con.shared.js'; 
     | 
|
| 
       27 
31 
     | 
    
         
             
             * Basically creates an ids array and embedded documents for fast retrival.
         
     | 
| 
       28 
32 
     | 
    
         
             
             * 
         
     | 
| 
       29 
33 
     | 
    
         
             
             * 
         
     | 
| 
       30 
     | 
    
         
            -
             * @template { 
     | 
| 
      
 34 
     | 
    
         
            +
             * @template {BaseType} T
         
     | 
| 
       31 
35 
     | 
    
         
             
             * 
         
     | 
| 
       32 
36 
     | 
    
         
             
             * 
         
     | 
| 
       33 
37 
     | 
    
         
             
             * @param {MongoDB} driver our driver
         
     | 
| 
         @@ -50,7 +54,7 @@ export const create_explicit_relation = async ( 
     | 
|
| 
       50 
54 
     | 
    
         
             
              if(isUndef(value))
         
     | 
| 
       51 
55 
     | 
    
         
             
                return data;
         
     | 
| 
       52 
56 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
              /** @type { 
     | 
| 
      
 57 
     | 
    
         
            +
              /** @type {BaseType[]} */
         
     | 
| 
       54 
58 
     | 
    
         
             
              const items = Array.isArray(value) ? value : [value];
         
     | 
| 
       55 
59 
     | 
    
         | 
| 
       56 
60 
     | 
    
         
             
              /** @type {WithRelations<any>} */
         
     | 
| 
         @@ -328,7 +332,7 @@ export const remove_specific_connection_of_relation = ( 
     | 
|
| 
       328 
332 
     | 
    
         
             
             * @param {MongoDB} driver mongodb driver instance
         
     | 
| 
       329 
333 
     | 
    
         
             
             * @param {string} collection the collection from which the `relation` is from
         
     | 
| 
       330 
334 
     | 
    
         
             
             * @param {string} relation_name the `relation` name
         
     | 
| 
       331 
     | 
    
         
            -
             * @param { 
     | 
| 
      
 335 
     | 
    
         
            +
             * @param {Filter<any>} from_object_filter 
         
     | 
| 
       332 
336 
     | 
    
         
             
             * `mongodb` Filter to locate the first document, the from part of the connection
         
     | 
| 
       333 
337 
     | 
    
         
             
             * @param {ObjectId} entry_objid the proper `ObjectId` of the entry
         
     | 
| 
       334 
338 
     | 
    
         
             
             * @param {ClientSession} [session] client `session` for atomicity purposes
         
     | 
    
        package/types.public.d.ts
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { MongoClientOptions } from 'mongodb';
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            export { MongoDB, migrateToLatest } from './index.js';
         
     | 
| 
      
 3 
     | 
    
         
            +
            export { MongoDB, migrateToLatest, MongoVectorStore } from './index.js';
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            export type Config = {
         
     | 
| 
       6 
6 
     | 
    
         
             
              /**
         
     | 
| 
         @@ -12,6 +12,7 @@ export type Config = { 
     | 
|
| 
       12 
12 
     | 
    
         
             
              /** 
         
     | 
| 
       13 
13 
     | 
    
         
             
               * @description the name of the database, if absent, will be infered at init
         
     | 
| 
       14 
14 
     | 
    
         
             
               * with env `app.platform.env.MONGODB_NAME` 
         
     | 
| 
      
 15 
     | 
    
         
            +
               * @default 'main'
         
     | 
| 
       15 
16 
     | 
    
         
             
               */
         
     | 
| 
       16 
17 
     | 
    
         
             
              db_name?: string;
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
         @@ -19,4 +20,5 @@ export type Config = { 
     | 
|
| 
       19 
20 
     | 
    
         
             
               * @description mongo client options 
         
     | 
| 
       20 
21 
     | 
    
         
             
               */
         
     | 
| 
       21 
22 
     | 
    
         
             
              options?: MongoClientOptions;
         
     | 
| 
       22 
     | 
    
         
            -
            }
         
     | 
| 
      
 23 
     | 
    
         
            +
            }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     |