@bedrockio/model 0.5.2 → 0.5.4
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/README.md +5 -5
- package/dist/cjs/search.js +5 -3
- package/package.json +1 -1
- package/src/search.js +5 -4
package/README.md
CHANGED
|
@@ -653,22 +653,22 @@ schema.pre('save', function () {
|
|
|
653
653
|
});
|
|
654
654
|
```
|
|
655
655
|
|
|
656
|
-
##### Syncing
|
|
656
|
+
##### Syncing Cache Fields
|
|
657
657
|
|
|
658
658
|
When first applying or making changes to defined cached search fields, existing
|
|
659
|
-
documents will be out of sync. The static method `
|
|
659
|
+
documents will be out of sync. The static method `syncCacheFields` is provided
|
|
660
660
|
to synchronize them:
|
|
661
661
|
|
|
662
662
|
```js
|
|
663
663
|
// Find and update any documents that do not have
|
|
664
664
|
// existing cached fields. Generally called when
|
|
665
665
|
// adding a cached field.
|
|
666
|
-
await Model.
|
|
666
|
+
await Model.syncCacheFields();
|
|
667
667
|
|
|
668
668
|
// Force an update on ALL documents to resync their
|
|
669
669
|
// cached fields. Generally called to force a cache
|
|
670
670
|
// refresh.
|
|
671
|
-
await Model.
|
|
671
|
+
await Model.syncCacheFields({
|
|
672
672
|
force: true,
|
|
673
673
|
});
|
|
674
674
|
```
|
|
@@ -702,7 +702,7 @@ Lazy cached fields will not update themselves once set. They can only be updated
|
|
|
702
702
|
by forcing a sync:
|
|
703
703
|
|
|
704
704
|
```js
|
|
705
|
-
await Model.
|
|
705
|
+
await Model.syncCacheFields({
|
|
706
706
|
force: true,
|
|
707
707
|
});
|
|
708
708
|
```
|
package/dist/cjs/search.js
CHANGED
|
@@ -305,7 +305,7 @@ function applySearchCache(schema, definition) {
|
|
|
305
305
|
}
|
|
306
306
|
createCacheFields(schema, definition);
|
|
307
307
|
applyCacheHook(schema, definition);
|
|
308
|
-
schema.static('
|
|
308
|
+
schema.static('syncCacheFields', async function syncCacheFields(options = {}) {
|
|
309
309
|
assertIncludeModule(this);
|
|
310
310
|
const {
|
|
311
311
|
force
|
|
@@ -362,14 +362,16 @@ function createCacheFields(schema, definition) {
|
|
|
362
362
|
for (let [cachedField, def] of Object.entries(definition.search.cache)) {
|
|
363
363
|
// Fall back to string type for virtuals or not defined.
|
|
364
364
|
const {
|
|
365
|
-
type = 'String'
|
|
365
|
+
type = 'String',
|
|
366
|
+
path,
|
|
367
|
+
...rest
|
|
366
368
|
} = def;
|
|
367
369
|
schema.add({
|
|
368
370
|
[cachedField]: type
|
|
369
371
|
});
|
|
370
372
|
schema.obj[cachedField] = {
|
|
371
373
|
type,
|
|
372
|
-
|
|
374
|
+
...rest
|
|
373
375
|
};
|
|
374
376
|
}
|
|
375
377
|
}
|
package/package.json
CHANGED
package/src/search.js
CHANGED
|
@@ -319,8 +319,8 @@ function applySearchCache(schema, definition) {
|
|
|
319
319
|
applyCacheHook(schema, definition);
|
|
320
320
|
|
|
321
321
|
schema.static(
|
|
322
|
-
'
|
|
323
|
-
async function
|
|
322
|
+
'syncCacheFields',
|
|
323
|
+
async function syncCacheFields(options = {}) {
|
|
324
324
|
assertIncludeModule(this);
|
|
325
325
|
|
|
326
326
|
const { force } = options;
|
|
@@ -384,13 +384,14 @@ function validateSearchFields(schema, definition) {
|
|
|
384
384
|
function createCacheFields(schema, definition) {
|
|
385
385
|
for (let [cachedField, def] of Object.entries(definition.search.cache)) {
|
|
386
386
|
// Fall back to string type for virtuals or not defined.
|
|
387
|
-
const { type = 'String' } = def;
|
|
387
|
+
const { type = 'String', path, ...rest } = def;
|
|
388
|
+
|
|
388
389
|
schema.add({
|
|
389
390
|
[cachedField]: type,
|
|
390
391
|
});
|
|
391
392
|
schema.obj[cachedField] = {
|
|
392
393
|
type,
|
|
393
|
-
|
|
394
|
+
...rest,
|
|
394
395
|
};
|
|
395
396
|
}
|
|
396
397
|
}
|