@storecraft/database-mongodb 1.0.13 → 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 +13 -14
- package/src/con.customers.js +8 -11
- package/src/con.discounts.js +8 -13
- package/src/con.discounts.utils.js +18 -10
- package/src/con.images.js +7 -6
- package/src/con.notifications.js +4 -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 +9 -9
- package/src/con.shared.js +30 -27
- 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 +10 -7
- 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.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;
|
@@ -103,7 +103,7 @@ export const quicksearch = (driver) => {
|
|
103
103
|
const db = driver.mongo_client.db(driver.name);
|
104
104
|
|
105
105
|
|
106
|
-
const items = /** @type {
|
106
|
+
const items = /** @type {QuickSearchResource[]} */ (
|
107
107
|
await db.collection(tables_filtered[0]).aggregate(
|
108
108
|
[
|
109
109
|
...pipeline,
|
@@ -124,7 +124,7 @@ export const quicksearch = (driver) => {
|
|
124
124
|
);
|
125
125
|
|
126
126
|
|
127
|
-
/** @type {
|
127
|
+
/** @type {QuickSearchResult} */
|
128
128
|
const result = {};
|
129
129
|
|
130
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,13 +16,13 @@ import { add_search_terms_relation_on } from './utils.relations.js'
|
|
8
16
|
|
9
17
|
|
10
18
|
/**
|
11
|
-
* @template {
|
12
|
-
* @template {
|
19
|
+
* @template {BaseType} T
|
20
|
+
* @template {BaseType} G
|
13
21
|
*
|
14
22
|
* @param {MongoDB} driver
|
15
23
|
* @param {Collection<G>} col
|
16
24
|
*
|
17
|
-
* @returns {
|
25
|
+
* @returns {db_crud<T, G>["upsert"]}
|
18
26
|
*/
|
19
27
|
export const upsert_regular = (driver, col) => {
|
20
28
|
|
@@ -80,13 +88,10 @@ export const get_relations_names = item => {
|
|
80
88
|
/**
|
81
89
|
* Expand relations in-place
|
82
90
|
*
|
83
|
-
*
|
84
91
|
* @template {any} T
|
85
92
|
*
|
86
|
-
*
|
87
|
-
* @param {
|
88
|
-
* @param {import('@storecraft/core/api').ExpandQuery} [expand_query]
|
89
|
-
*
|
93
|
+
* @param {WithRelations<T>[]} items
|
94
|
+
* @param {ExpandQuery<T>} [expand_query]
|
90
95
|
*/
|
91
96
|
export const expand = (items, expand_query=undefined) => {
|
92
97
|
|
@@ -98,9 +103,9 @@ export const expand = (items, expand_query=undefined) => {
|
|
98
103
|
const all = expand_query.includes('*');
|
99
104
|
|
100
105
|
for(const item of items) {
|
101
|
-
|
106
|
+
const what_to_expand = all ? get_relations_names(item) : expand_query;
|
102
107
|
|
103
|
-
for(const e of (
|
108
|
+
for(const e of (what_to_expand ?? [])) {
|
104
109
|
// try to find embedded documents relations
|
105
110
|
const rel = item?._relations?.[e];
|
106
111
|
if(rel===undefined || rel===null)
|
@@ -139,8 +144,8 @@ export const zeroed_relations = {
|
|
139
144
|
|
140
145
|
|
141
146
|
/**
|
142
|
-
*
|
143
|
-
* @param {
|
147
|
+
* @template T
|
148
|
+
* @param {ExpandQuery<T>} expand
|
144
149
|
*/
|
145
150
|
export const expand_to_mongo_projection = (expand) => {
|
146
151
|
let projection = {}
|
@@ -161,18 +166,16 @@ export const expand_to_mongo_projection = (expand) => {
|
|
161
166
|
/**
|
162
167
|
* @template T, G
|
163
168
|
*
|
164
|
-
*
|
165
169
|
* @param {MongoDB} driver
|
166
170
|
* @param {Collection<G>} col
|
167
171
|
*
|
168
|
-
*
|
169
|
-
* @returns {import('@storecraft/core/database').db_crud<T, G>["get"]}
|
172
|
+
* @returns {db_crud<T, G>["get"]}
|
170
173
|
*/
|
171
174
|
export const get_regular = (driver, col) => {
|
172
175
|
return async (id_or_handle, options) => {
|
173
176
|
const filter = handle_or_id(id_or_handle);
|
174
177
|
|
175
|
-
/** @type {
|
178
|
+
/** @type {WithRelations<WithId<G>>} */
|
176
179
|
const res = await col.findOne(
|
177
180
|
filter,
|
178
181
|
{
|
@@ -192,15 +195,15 @@ export const get_regular = (driver, col) => {
|
|
192
195
|
* should be instead
|
193
196
|
*
|
194
197
|
*
|
195
|
-
* @template {
|
196
|
-
* @template {
|
198
|
+
* @template {withOptionalID} T
|
199
|
+
* @template {withOptionalID} G
|
197
200
|
*
|
198
201
|
*
|
199
202
|
* @param {MongoDB} driver
|
200
203
|
* @param {Collection<G>} col
|
201
204
|
*
|
202
205
|
*
|
203
|
-
* @returns {
|
206
|
+
* @returns {db_crud<T, G>["getBulk"]}
|
204
207
|
*/
|
205
208
|
export const get_bulk = (driver, col) => {
|
206
209
|
return async (ids, options) => {
|
@@ -245,7 +248,7 @@ export const get_bulk = (driver, col) => {
|
|
245
248
|
* @param {Collection<G>} col
|
246
249
|
*
|
247
250
|
*
|
248
|
-
* @returns {
|
251
|
+
* @returns {db_crud<T, G>["remove"]}
|
249
252
|
*/
|
250
253
|
export const remove_regular = (driver, col) => {
|
251
254
|
return async (id_or_handle) => {
|
@@ -259,15 +262,15 @@ export const remove_regular = (driver, col) => {
|
|
259
262
|
}
|
260
263
|
|
261
264
|
/**
|
262
|
-
* @template
|
263
|
-
* @template
|
265
|
+
* @template T
|
266
|
+
* @template G
|
264
267
|
*
|
265
268
|
*
|
266
269
|
* @param {MongoDB} driver
|
267
270
|
* @param {Collection<G>} col
|
268
271
|
*
|
269
272
|
*
|
270
|
-
* @returns {
|
273
|
+
* @returns {db_crud<T, G>["list"]}
|
271
274
|
*/
|
272
275
|
export const list_regular = (driver, col) => {
|
273
276
|
return async (query) => {
|
@@ -276,11 +279,11 @@ export const list_regular = (driver, col) => {
|
|
276
279
|
|
277
280
|
// console.log('reverse_sign', reverse_sign)
|
278
281
|
// console.log('query', query)
|
279
|
-
console.log('filter', JSON.stringify(filter, null, 2))
|
282
|
+
// console.log('filter', JSON.stringify(filter, null, 2))
|
280
283
|
// console.log('sort', sort)
|
281
284
|
// console.log('expand', query?.expand)
|
282
285
|
|
283
|
-
/** @type {
|
286
|
+
/** @type {WithRelations<WithId<G>>[]} */
|
284
287
|
const items = await col.find(
|
285
288
|
filter, {
|
286
289
|
sort,
|
@@ -293,7 +296,7 @@ export const list_regular = (driver, col) => {
|
|
293
296
|
|
294
297
|
// try expand relations, that were asked
|
295
298
|
const items_expended = expand(items, query?.expand);
|
296
|
-
|
299
|
+
|
297
300
|
const sanitized = sanitize_array(items_expended);
|
298
301
|
|
299
302
|
// console.log('sanitized', sanitized)
|
@@ -311,7 +314,7 @@ export const list_regular = (driver, col) => {
|
|
311
314
|
* @param {Collection<G>} col
|
312
315
|
*
|
313
316
|
*
|
314
|
-
* @returns {
|
317
|
+
* @returns {db_crud<T, G>["count"]}
|
315
318
|
*/
|
316
319
|
export const count_regular = (driver, col) => {
|
317
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,9 +120,7 @@ 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<>} c a cursor record
|
120
|
-
*
|
123
|
+
* @param {Tuple} c a cursor record
|
121
124
|
*
|
122
125
|
* @returns {[k: string, v: any]}
|
123
126
|
*/
|
@@ -131,7 +134,7 @@ const transform = c => {
|
|
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
|
+
|